Changeset 2798
- Timestamp:
- 01/12/10 11:57:04 (15 years ago)
- Location:
- issm/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/Mesh2.h
r2797 r2798 61 61 62 62 class MeshIstream; 63 class OFortranUnFormattedFile;64 class IFortranUnFormattedFile;65 63 66 64 extern int hinterpole; -
issm/trunk/src/c/Bamgx/Meshio.cpp
r2740 r2798 33 33 long int verbosity=2; 34 34 35 const char *OFortranUnFormattedFile::unkown("unkown file name");36 35 void (*MeshIstreamErrorHandler)(ios & ) =0; 37 36 /////////////////////////////////////////////////////////// … … 48 47 out << '"' ; 49 48 } 50 ///////////////////////////////////////////////////////////51 double * ReadbbFile(const char * file,long & nbsol,long & lsol,const int typesol,const int dim)52 {53 54 MeshIstream frbb(file);55 int dimlu,typesollu;56 long i;57 double *sol =0;58 frbb >> dimlu >> nbsol >> lsol >> typesollu ;59 if(typesol != typesollu )60 {61 cerr << " incorrect type of solution (read) " << typesollu << " != (wanted) " << typesol << endl;62 cerr << " or dim of solution (read) " << dimlu << " != (wanted) " << dim << endl;63 nbsol=0;64 lsol=0;65 }66 else67 {68 sol = new double[lsol*nbsol];69 double *s=sol;70 for( i=0;i<lsol;i++)71 for (long j=0;j<nbsol;j++)72 frbb >> *s++ ;73 // frbb.close();74 }75 76 77 return sol;78 }79 80 ///////////////////////////////////////////////////////////81 double * ReadBBFile(const char * file,long & nbsol,long & lsol,int *& typesols,82 const int dim,const int typesol)83 {84 85 MeshIstream frbb(file);86 int dimlu,typesollu;87 typesols = 0;88 long i,n=0;89 double *sol =0;90 int sizeoftype[] = { 1, dim ,dim * (dim+1) / 2, dim * dim } ;91 // char * charoftype[] = { "Scalar" , "dim Vector" ,"dim x dim Sym-Matric","dim x dim Full-Matric" } ;92 frbb >> dimlu >> nbsol ;93 typesols = new int [nbsol] ;94 for (i=0;i<nbsol;i++)95 {96 frbb >> typesols[i];97 typesols[i]--;98 if (typesols[i]<0 || typesols[i]>= 4)99 {100 cerr << " Error reading BBFile the type solution " << i+1 << " is " << typesols[i]+1101 << " is not in [1..4] " << endl;102 frbb.ShowIoErr(998);103 nbsol=0;104 lsol=0;105 delete [] typesols;106 typesols=0;107 return 0;108 }109 n += sizeoftype[ typesols[i]];110 }111 frbb >> lsol >> typesollu ;112 if(typesol != typesollu )113 {114 cerr << " incorrect type of solution (read) " << typesollu << " != (wanted) " << typesol << endl;115 cerr << " or dim of solution (read) " << dimlu << " != (wanted) " << dim << endl;116 frbb.ShowIoErr(999);117 nbsol=0;118 lsol=0;119 }120 else121 {122 if (verbosity> 5)123 cout << " read BB file " << file << " with nbsol " << nbsol << " total nb of field = " << n << endl;124 if (verbosity>9)125 for (i=0;i<nbsol;i++)126 cout << " the type of solution " << i+1 << " is " << sizeoftype[ typesols[i]]127 << " and the number of sub-field are " << sizeoftype[ typesols[i]] << endl;128 sol = new double[lsol*n];129 double *s=sol;130 for( i=0;i<lsol;i++)131 for (long j=0;j<n;j++)132 frbb >> *s++ ;133 // frbb.close();134 }135 136 137 return sol;138 }139 140 49 141 50 void MeshIstream::ShowIoErr(int s) { … … 229 138 return r ; 230 139 } 231 ///////////////////////////////////////////////////////////232 OFortranUnFormattedFile::~OFortranUnFormattedFile()233 {234 // save the last record235 if (l==0) { // l rec no set --236 l=where();237 if (verbosity>9)238 cout << " size of last record = "239 << l << " n = " << nb_rec << " i= " << i << endl;240 if (!f->good()) Error(3);241 f->seekp(i-sizeof(long));242 if (!f->good()) Error(3);243 f->write((char*)&l,sizeof(l));244 if (!f->good()) Error(3);245 n=j;246 }247 248 f->seekp(n);249 if (!f->good()) Error(3);250 f->write((char*) &l,sizeof(l));251 if (!f->good()) Error(3);252 253 if (f && to_close) {254 if (verbosity>9)255 cout << "delete OFortranUnFormattedFile " << file_name256 << " @end = " << n << endl;257 delete f;} f=0;258 }259 260 IFortranUnFormattedFile::~IFortranUnFormattedFile()261 {262 if (f && to_close) {263 if (verbosity>9)264 cout << " delete IFortranUnFormattedFile" << file_name265 << " @end = " << n << endl;266 delete f;} f=0;267 }268 269 long IFortranUnFormattedFile::Record()270 {271 nb_rec++;272 n += sizeof(long);273 f->seekg(n);274 f->read((char*)&l,sizeof(l));275 if (!f->good()) Error(3);276 i=j= n+sizeof(l);277 n += l + sizeof(l) ; // end278 if (verbosity>9)279 cout << " Read rec end =" << n << " l= " << l280 << " current= " << j << " begin= " << i << endl;281 return l;282 }283 284 long OFortranUnFormattedFile::Record(long ll) //285 {286 if (j==4 && l==0)287 {288 l=ll;289 f->seekp(0);290 f->write((char*)&ll,sizeof(l));291 if (!f->good()) Error(3);292 return 0;293 }294 if (n>=0)295 {296 if (l==0)297 { // l rec no set --298 l=where();299 if (verbosity>9)300 cout << " set len of rec " << nb_rec << " = " << l301 << " @ " << i-sizeof(long) << endl;302 303 f->seekp(i-sizeof(long));304 f->write((char*)&l,sizeof(l));305 n=j;306 }307 f->seekp(n);308 f->write((char*)&l,sizeof(l));309 if (!f->good()) Error(3);310 }311 else312 f->seekp(0);313 n += sizeof(long);314 nb_rec++;315 f->write((char*)&ll,sizeof(l));316 if (!f->good()) Error(3);317 318 l=ll;319 n += sizeof(long);320 j = n;321 i = n;322 n += l;323 if (verbosity>9)324 cout << " Write rec end =" << n << " l= " << l325 << " current= " << j << " begin= " << i << endl;326 return l;327 }328 void OFortranUnFormattedFile::Error(int err)329 {330 cerr << "Fatal Error Output FortranUnFormattedFile " << endl;331 if (err==0)332 cerr << "-- Error openning ";333 else if (err==1)334 cerr<< "-- OverFlow write ";335 else if (err==2)336 cerr<< "-- Erreur write " ;337 else if (err==3)338 cerr<< "-- Erreur write record info " ;339 else340 cerr << " unkown err " << err ;341 342 cerr << " Record number = " << nb_rec << endl343 << " read position in file " << j << " < " << n344 << " = end on record " << endl;345 cerr << " position in the record = " << where()346 << " length of record = " << l <<endl;347 cerr << " file = " << file_name<< endl ;348 MeshError(900);349 // throw(ErrorMesh("exit",1));350 }351 void IFortranUnFormattedFile::Error(int err)352 {353 cerr << "Fatal Error Input FortranUnFormattedFile " << endl;354 if (err==0)355 cerr << " Error openning ";356 else if (err==1)357 cerr<< " OverFlow read";358 else if (err==2)359 cerr<< " Erreur read" ;360 else if (err==3)361 cerr<< " Erreur read record info " ;362 else363 cerr << " unkown err " << err ;364 365 cerr << " Record number = " << nb_rec << endl366 << " read position in file " << j << " < " << n367 << " = end on record " << endl;368 cerr << " position in the record = " << where()369 << " length of record = " << l <<endl;370 cerr << " file = " << file_name<< endl ;371 MeshError(900);372 // throw(ErrorMesh("exit",1));373 }374 375 140 }// end of namespace bamg -
issm/trunk/src/c/Bamgx/Meshio.h
r2740 r2798 48 48 49 49 void WriteStr(ostream & out,char * str); 50 51 double * ReadbbFile(const char * file,long & nbsol,long & lsol,const int dim=2,const int typesol=2);52 double * ReadBBFile(const char * file,long & nbsol,long & lsol,int *& typesols,const int dim=2,const int typesol=2);53 // solution at vertex (P1)54 50 55 51 union Char4orLong { char c[4]; long l;} ; … … 114 110 115 111 }; 116 // Fortran unformatted file interface ----------117 118 class IFortranUnFormattedFile {119 // template<class T> friend IFortranUnFormattedFile & operator>>(IFortranUnFormattedFile &f,T & l);120 istream * f;121 long i,l,n,j,nb_rec;122 const char * file_name;123 int to_close;124 public:125 IFortranUnFormattedFile(char *name)126 : f(new ifstream(name)),i(0),l(0),n((long)-sizeof(long)),127 nb_rec(0),file_name(name), to_close(1)128 { if(!*f) Error(0);}129 130 IFortranUnFormattedFile(MeshIstream & ff)131 : f(&ff.in),i(0),l(0),n((long)-sizeof(long)),nb_rec(0),132 file_name(ff.CurrentFile), to_close(0)133 { if(! *f) Error(0);}134 135 ~IFortranUnFormattedFile();136 long Record();137 long where(){return j-i;}138 void read4(char *c,int );// for the fortran 77 char4139 void read(char * p,const size_t lg);140 void Error(int);141 };142 143 class OFortranUnFormattedFile {144 // template<class T> friend OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const T & l);145 ostream * f;146 long i,l,n,j,nb_rec;147 const static char * unkown;148 const char * file_name;149 int to_close;150 public:151 152 OFortranUnFormattedFile(const char *name,IOS_OPENMODE mm=ios::trunc)153 : f(new ofstream(name,mm)),i(0),l(0),n((long) -sizeof(long)),nb_rec(0),file_name(name), to_close(1)154 { if(!*f) Error(0);}155 OFortranUnFormattedFile(ostream &ff)156 : f(&ff),i(0),l(0),n((long) -sizeof(long)),nb_rec(0),file_name(unkown), to_close(0)157 { if(!*f) Error(0);}158 159 ~OFortranUnFormattedFile();160 161 long Record(long ll=0);162 long where(){return j-i;}163 void write4(const char *c,int );// for the fortran 77 char4164 void write(const char * p,const size_t lg);165 void Error(int );166 };167 112 168 113 /// ---------- inline ------------------------- 169 114 170 inline void IFortranUnFormattedFile::read(char * p,const size_t lg){171 f->read(p,lg);172 j+=lg;173 if (j>n) Error(1);174 else if (!f->good()) Error(2) ;175 115 } 176 177 inline void OFortranUnFormattedFile::write(const char * p,const size_t lg){178 f->write(p,lg);179 j+=lg;180 if (l && j>n) Error(1);181 else if (!f->good()) Error(2);182 }183 184 template<class T> inline185 IFortranUnFormattedFile & operator>>(IFortranUnFormattedFile &f,T & l)186 {187 f.read((char *) &l,sizeof(l));return f;188 }189 /* bug sur sun190 template inline191 OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const T & l)192 {193 f.write((char *) &l,sizeof(l));return f;194 }195 on ex les template */196 197 inline198 OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const int & l)199 {200 f.write((char *) &l,sizeof(l));return f;201 }202 inline203 OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const long & l)204 {205 f.write((char *) &l,sizeof(l));return f;206 }207 inline208 OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const double & l)209 {210 f.write((char *) &l,sizeof(l));return f;211 }212 inline213 OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const float & l)214 {215 f.write((char *) &l,sizeof(l));return f;216 }217 218 inline void OFortranUnFormattedFile::write4(const char *c,int ll)219 {220 int i,j;221 Char4orLong ch4;222 for ( i=0;i<ll;i++)223 {224 ch4.l=0;225 for (j=0;j<4;j++)226 ch4.c[j]=*c? *c++:' ';227 *this << ch4.l;228 }229 }230 inline void IFortranUnFormattedFile::read4(char *c,int ll)231 {232 int i,j;233 Char4orLong ch4;234 235 for ( i=0;i<ll;i++)236 {237 *this >> ch4.l;238 for (j=0;j<4;j++)239 *c++= ch4.c[j];240 }241 *c=0;// end of string242 }243 244 } -
issm/trunk/src/c/objects/BamgGeom.h
r2794 r2798 30 30 double* RequiredEdges; 31 31 32 int NumCrackedEdges; 33 double* CrackedEdges; 34 32 35 int NumSubDomains; 33 36 double* SubDomains; -
issm/trunk/src/mex/Bamg/Bamg.cpp
r2794 r2798 63 63 bamggeom.NumRequiredEdges=0; 64 64 bamggeom.RequiredEdges=NULL; 65 bamggeom.NumCrackedEdges=0; 66 bamggeom.CrackedEdges=NULL; 65 67 FetchData(&NumSubDomainsGeom,mxGetField(BAMGGEOMETRY,0,"NumSubDomains")); 66 68 bamggeom.NumSubDomains=NumSubDomainsGeom; … … 125 127 126 128 /*Free ressources: */ 127 xfree((void**)&VerticesGeom); 128 xfree((void**)&EdgesGeom); 129 xfree((void**)&hVerticesGeom); 130 xfree((void**)&SubDomainsGeom); 131 //xfree((void**)&TrianglesMesh); 132 //xfree((void**)&VerticesMesh); 129 //do not free any fields of bamgmesh or bamggeom as it has been freed in bamgx 133 130 134 131 /*end module: */
Note:
See TracChangeset
for help on using the changeset viewer.