1 #ifndef GIBI_MESH_DRIVER_HXX
2 #define GIBI_MESH_DRIVER_HXX
10 #include "MEDMEM_define.hxx"
11 #include "MEDMEM_GenDriver.hxx"
13 #include "MEDMEM_STRING.hxx"
14 #include "MEDMEM_Exception.hxx"
15 #include "utilities.h"
26 Generic part : implement the readopen and close methods.
38 class _intermediateMED;
39 class GIBI_MESH_DRIVER : public GENDRIVER
44 // A VOIR FILE DESCRIPTEUR ? MED_FR::med_idt _medIdt;
48 // tableau de correspondance des types géométriques de CASTEM -> MED
49 static const size_t nb_geometrie_gibi=47;
50 static const MED_EN::medGeometryElement geomGIBItoMED[nb_geometrie_gibi];
62 GIBI_MESH_DRIVER(const string & fileName,
64 MED_EN::med_mode_acces accessMode) ;
68 GIBI_MESH_DRIVER(const GIBI_MESH_DRIVER & driver) ;
73 virtual ~GIBI_MESH_DRIVER() ;
75 virtual void write( void ) const = 0 ;
76 virtual void read ( void ) = 0 ;
79 Set the name of the MESH asked in file.
81 It could be different than the name of the MESH object.
83 void setMeshName(const string & meshName) ;
85 Get the name of the MESH asked in file.
87 string getMeshName() const ;
89 static MED_EN::medGeometryElement gibi2medGeom( size_t gibiTypeNb );
90 static int med2gibiGeom( MED_EN::medGeometryElement medGeomType );
93 virtual GENDRIVER * copy ( void ) const = 0 ;
98 class GIBI_MESH_RDONLY_DRIVER : public virtual GIBI_MESH_DRIVER
105 GIBI_MESH_RDONLY_DRIVER() ;
109 GIBI_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
113 GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver) ;
118 virtual ~GIBI_MESH_RDONLY_DRIVER() ;
121 Return a MEDEXCEPTION : it is the read-only driver.
123 void write( void ) const throw (MEDEXCEPTION);
125 Read MESH in the specified file.
127 void read ( void ) throw (MEDEXCEPTION);
134 bool readFile(_intermediateMED* medi, bool readFields );
136 void fillMesh(_intermediateMED* medi);
140 GENDRIVER * copy ( void ) const ;
142 // fields and methods for file reading
144 bool getLine(char* & line);
145 bool getNextLine (char* & line, bool raiseIfNot = true ) throw (MEDEXCEPTION)
147 if ( getLine( line )) return true;
148 if ( raiseIfNot ) throw MEDEXCEPTION(LOCALIZED(STRING("Unexpected EOF on ln ")<<_lineNb));
151 void initNameReading(int nbValues, int width = 8) // FORMAT(8(1X,A8))
152 { init( nbValues, 72 / ( width + 1 ), width, 1 ); }
153 void initIntReading(int nbValues) // FORMAT(10I8)
154 { init( nbValues, 10, 8 ); }
155 void initDoubleReading(int nbValues) // FORMAT(1P,3E22.14)
156 { init( nbValues, 3, 22 ); }
157 void init( int nbToRead, int nbPosInLine, int width, int shift = 0 );
158 bool more() const { return ( _iRead < _nbToRead && _curPos ); }
160 char* str() const { return _curPos; }
161 int index() const { return _iRead; }
162 int getInt() const { return atoi( str() ); }
163 double getDouble() const { return atof( str() ); }
164 string getName() const;
174 int _iPos, _nbPosInLine, _width, _shift;
175 int _iRead, _nbToRead;
181 Driver Med for MESH : Write only.
183 Implement write method.
187 class GIBI_MESH_WRONLY_DRIVER : public virtual GIBI_MESH_DRIVER {
194 GIBI_MESH_WRONLY_DRIVER() ;
198 GIBI_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
202 GIBI_MESH_WRONLY_DRIVER(const GIBI_MESH_WRONLY_DRIVER & driver) ;
207 virtual ~GIBI_MESH_WRONLY_DRIVER() ;
210 Write MESH in the specified file.
212 void write( void ) const throw (MEDEXCEPTION);
214 Return a MEDEXCEPTION : it is the write-only driver.
216 void read ( void ) throw (MEDEXCEPTION);
226 Add a support to write. Return true if a support will be written
228 bool addSupport( const SUPPORT * support );
230 return submesh id and size for a support. Call it after writeSupportsAndMesh()
232 int getSubMeshIdAndSize(const SUPPORT * support,
233 list<pair<int,int> > & idsAndSizes ) const;
235 Write MESH and _supports.
237 void writeSupportsAndMesh();
239 Write the record closing file
241 void writeLastRecord();
243 static void addName( map<string,int>& nameMap, string& name, int index, string prefix );
245 void writeNames( map<string,int>& nameMap );
252 const int * _ptrElemIDs; // elem ids or
253 int _elemID1; // first elem id if isOnAllElements()
254 typeData(): _nbElems(0), _ptrElemIDs(NULL), _elemID1(0) {}
255 typeData( int nbElems, const int * ptrElemIDs, int elemID1 )
256 : _nbElems(nbElems), _ptrElemIDs(ptrElemIDs), _elemID1(elemID1) {}
260 typedef map< MED_EN::medGeometryElement, list< typeData > >::iterator typeIterator;
263 map< MED_EN::medGeometryElement, list< typeData > > _types;
264 supportData(): _id(0) {}
265 int getNumberOfTypes() const { return _types.size(); }
266 int getNumberObjects() const
267 { return _types.size() < 2 ? _types.size() : _types.size() + !_cleanName.empty(); }
268 void addTypeData(MED_EN::medGeometryElement type, int nbElems,
269 const int * ptrElemIDs, int elemID1 )
270 { _types[type].push_back( typeData( nbElems, ptrElemIDs, elemID1 )); }
273 void writeElements (MED_EN::medGeometryElement geomType,
274 list< typeData >& typeDataList,
275 const int * nodalConnect,
276 const int * nodalConnectIndex);
278 map<const SUPPORT*, supportData> _supports;
280 GENDRIVER * copy ( void ) const ;
286 Driver GIBI for MESH : Read write.
287 - Use read method from GIBI_MESH_RDONLY_DRIVER
288 - Use write method from GIBI_MESH_WRONLY_DRIVER
292 class GIBI_MESH_RDWR_DRIVER : public GIBI_MESH_RDONLY_DRIVER, public GIBI_MESH_WRONLY_DRIVER {
299 GIBI_MESH_RDWR_DRIVER() ;
303 GIBI_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) ;
307 GIBI_MESH_RDWR_DRIVER(const GIBI_MESH_RDWR_DRIVER & driver) ;
312 ~GIBI_MESH_RDWR_DRIVER() ;
315 Write MESH in the specified file.
317 void write(void) const throw (MEDEXCEPTION);
319 Read MESH in the specified file.
321 void read (void) throw (MEDEXCEPTION);
327 GENDRIVER * copy(void) const ;
331 class GIBI_MED_RDONLY_DRIVER : public GIBI_MESH_RDONLY_DRIVER {
340 GIBI_MED_RDONLY_DRIVER() ;
344 GIBI_MED_RDONLY_DRIVER(const string & fileName, MED * ptrMed) ;
348 GIBI_MED_RDONLY_DRIVER(const GIBI_MED_RDONLY_DRIVER & driver) ;
353 virtual ~GIBI_MED_RDONLY_DRIVER() ;
356 Read MESH in the specified file.
358 void read ( void ) throw (MEDEXCEPTION);
362 GENDRIVER * copy ( void ) const ;
368 Driver Med for MESH : Write only.
370 Implement write method.
374 class GIBI_MED_WRONLY_DRIVER : public GIBI_MESH_WRONLY_DRIVER {
383 GIBI_MED_WRONLY_DRIVER() ;
385 Constructor. To write a mesh and all fields on it
387 GIBI_MED_WRONLY_DRIVER(const string & fileName, MED * ptrMed, MESH * ptrMesh) ;
391 GIBI_MED_WRONLY_DRIVER(const GIBI_MED_WRONLY_DRIVER & driver) ;
396 virtual ~GIBI_MED_WRONLY_DRIVER() ;
399 Write MESH in the specified file.
401 void write( void ) const throw (MEDEXCEPTION);
403 //int getSupports(const FIELD_* field, list<const SUPPORT*>& supList) const;
407 GENDRIVER * copy ( void ) const ;
413 Driver GIBI for MESH : Read write.
414 - Use read method from GIBI_MED_RDONLY_DRIVER
415 - Use write method from GIBI_MED_WRONLY_DRIVER
419 // class GIBI_MED_RDWR_DRIVER : public GIBI_MED_RDONLY_DRIVER, public GIBI_MED_WRONLY_DRIVER {
426 // GIBI_MED_RDWR_DRIVER() ;
430 // GIBI_MED_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) ;
434 // GIBI_MED_RDWR_DRIVER(const GIBI_MED_RDWR_DRIVER & driver) ;
439 // ~GIBI_MED_RDWR_DRIVER() ;
442 // Write MESH in the specified file.
444 // void write(void) const throw (MEDEXCEPTION);
446 // Read MESH in the specified file.
448 // void read (void) throw (MEDEXCEPTION);
451 // GENDRIVER * copy(void) const ;
457 #endif /* GIBI_MESH_DRIVER_HXX */