Gems3k
3.1
GEMS3K standalone solver for geochemical equilibria
|
00001 //------------------------------------------------------------------- 00002 // $Id: io_arrays.h 761 2012-11-30 09:12:20Z dmitrieva $ 00005 // 00006 // Copyright (C) 2006-2012 S.Dmytriyeva 00007 // <GEMS Development Team, mailto:gems2.support@psi.ch> 00008 // 00009 // This file is part of the GEMS3K code for thermodynamic modelling 00010 // by Gibbs energy minimization <http://gems.web.psi.ch/GEMS3K/> 00011 // 00012 // GEMS3K is free software: you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as 00014 // published by the Free Software Foundation, either version 3 of 00015 // the License, or (at your option) any later version. 00016 00017 // GEMS3K is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU Lesser General Public License for more details. 00021 00022 // You should have received a copy of the GNU General Public License 00023 // along with GEMS3K code. If not, see <http://www.gnu.org/licenses/>. 00024 //------------------------------------------------------------------- 00025 00026 #include <fstream> 00027 00028 #include "verror.h" 00029 00030 struct outField 00031 { 00032 gstring name; 00033 long int alws; 00034 long int readed; 00035 long int indexation; 00036 gstring comment; 00037 00038 }; 00039 00040 class TRWArrays 00041 { 00042 protected: 00043 fstream& ff; 00044 long int numFlds; 00045 outField* flds; 00046 00047 public: 00048 00050 TRWArrays( short aNumFlds, outField* aFlds, fstream& fin ): 00051 ff( fin ), numFlds(aNumFlds), flds(aFlds) 00052 {} 00053 00055 virtual long int findFld( const char *Name ); 00056 00060 void setNoAlws( long int ii ) 00061 { flds[ii].alws = 0; } 00062 00066 void setNoAlws( const char *Name ) 00067 { 00068 long int ii = findFld( Name ); 00069 if( ii >=0 ) 00070 setNoAlws(ii); 00071 } 00072 00075 void setAlws( long int ii ) 00076 { flds[ii].alws = 1; } 00077 00080 void setAlws( const char *Name ) 00081 { 00082 long int ii = findFld( Name ); 00083 if( ii >=0 ) 00084 setAlws(ii); 00085 } 00086 00089 bool getAlws( long int ii ) 00090 { return (flds[ii].alws == 1); } 00091 00094 bool getAlws( const char *Name ) 00095 { 00096 long int ii = findFld( Name ); 00097 if( ii >=0 ) 00098 return getAlws(ii); 00099 else 00100 return false; 00101 } 00102 00103 }; 00104 00106 class TPrintArrays: public TRWArrays 00107 { 00108 00109 public: 00110 00111 /*inline*/ void writeValue(float val); 00112 /*inline*/ void writeValue(double val); 00113 /*inline*/ void writeValue(long val); 00114 00119 void writeField(long f_num, long value, bool with_comments, bool brief_mode ); 00120 00125 void writeField(long f_num, short value, bool with_comments, bool brief_mode ); 00126 00131 void writeField(long f_num, char value, bool with_comments, bool brief_mode ); 00132 00137 void writeField(long f_num, double value, bool with_comments, bool brief_mode ); 00138 00144 void writeArray( long f_num, double* arr, long int size, long int l_size, 00145 bool with_comments = false, bool brief_mode = false ); 00146 00152 void writeArray( long f_num, long* arr, long int size, long int l_size, 00153 bool with_comments = false, bool brief_mode = false ); 00154 00160 void writeArray( long f_num, short* arr, long int size, long int l_size, 00161 bool with_comments = false, bool brief_mode = false ); 00162 00168 void writeArrayF( long f_num, char* arr, long int size, long int l_size, 00169 bool with_comments = false, bool brief_mode = false ); 00170 00171 00173 TPrintArrays( short aNumFlds, outField* aFlds, fstream& fout ): 00174 TRWArrays( aNumFlds, aFlds, fout) 00175 {} 00176 00178 void writeArray( const char *name, char* arr, long int size, long int arr_size ); 00180 void writeArray( const char *name, float* arr, long int size, long int l_size=-1L ); 00182 void writeArray( const char *name, double* arr, long int size, long int l_size=-1L ); 00184 void writeArray( const char *name, long* arr, long int size, long int l_size=-1L ); 00185 00187 void writeArray( const char *name, char* arr, int size, int arr_size ); 00189 void writeArray( const char *name, float* arr, int size, int l_size=-1 ); 00191 void writeArray( const char *name, double* arr, int size, int l_size=-1 ); 00193 void writeArray( const char *name, short* arr, int size, int l_size=-1 ); 00194 00196 void writeArray( const char *name, float* arr, long int size, long int* selAr, 00197 long int nColumns=1L, long int l_size=-1L ); 00199 void writeArray( const char *name, double* arr, long int size, long int* selAr, 00200 long int nColumns=1L, long int l_size=-1L ); 00202 void writeArray( const char *name, long* arr, long int size, long int* selAr, 00203 long int nColumns=1L, long int l_size=-1L ); 00204 00206 void writeArray( const char *name, float* arr, int size, long int* selAr, 00207 int nColumns=1, int l_size=-1 ); 00209 void writeArray( const char *name, double* arr, int size, long int* selAr, 00210 int nColumns=1, int l_size=-1 ); 00212 void writeArray( const char *name, short* arr, int size, long int* selAr, 00213 int nColumns=1, int l_size=-1 ); 00214 00215 }; 00216 00217 00218 class TReadArrays : public TRWArrays 00219 { 00220 gstring curArray; 00221 00222 protected: 00224 inline void readValue(float& val); 00226 inline void readValue(double& val); 00227 inline void setCurrentArray( const char* name, long int size ); 00228 00229 public: 00230 00232 TReadArrays( short aNumFlds, outField* aFlds, fstream& fin ): 00233 TRWArrays( aNumFlds, aFlds, fin ), curArray("") 00234 {} 00235 00236 void skipSpace(); 00237 void reset(); 00238 00239 long int findFld( const char *Name ); 00240 long int findNext(); 00241 void readNext( const char* label); 00242 00243 gstring testRead(); 00244 00246 void readArray( const char *name, short* arr, long int size ); 00248 void readArray( const char *name, int* arr, long int size ); 00250 void readArray( const char *name, long int* arr, long int size ); 00252 void readArray( const char *name, float* arr, long int size ); 00254 void readArray( const char *name, double* arr, long int size ); 00256 void readArray( const char *name, char* arr, long int size, long int el_size ); 00257 00258 }; 00259 00260 //=============================================================================