1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MEDMEM_Compatibility21_22.hxx"
23 #include "MEDMEM_MedMedDriver21.hxx"
24 #include "MEDMEM_MedMeshDriver.hxx"
25 #include "MEDMEM_DriversDef.hxx"
27 #include "MEDMEM_Mesh.hxx"
28 #include "MEDMEM_Grid.hxx"
29 #include "MEDMEM_Field.hxx"
30 // EN ATTENDANT L'utilisation de MedFieldDriver.hxx ds Field.hxx
31 #include "MEDMEM_MedFieldDriver.hxx"
32 #include "MEDMEM_Med.hxx"
33 #include "MEDMEM_define.hxx"
38 using namespace MED_EN;
39 using namespace MEDMEM;
41 MED_MED_DRIVER21::MED_MED_DRIVER21(): _medIdt(MED_INVALID)
44 MED_MED_DRIVER21::MED_MED_DRIVER21(const string & fileName, MED * const ptrMed):
45 MED_MED_DRIVER(fileName,ptrMed), _medIdt(MED_INVALID)
47 //_ptrMed->addDriver(*this); // The specific MED driver id is set within the addDriver method.
50 MED_MED_DRIVER21::MED_MED_DRIVER21(const string & fileName,
52 MED_EN::med_mode_acces accessMode):
53 MED_MED_DRIVER(fileName,ptrMed,accessMode), _medIdt(MED_INVALID)
56 //REM : As t'on besoin du champ _status : _medIdt <-> _status ? Oui
58 MED_MED_DRIVER21::MED_MED_DRIVER21(const MED_MED_DRIVER21 & driver):
59 MED_MED_DRIVER(driver),_medIdt(driver._medIdt)
63 MED_MED_DRIVER21::~MED_MED_DRIVER21()
65 MESSAGE_MED("MED_MED_DRIVER21::~MED_MED_DRIVER21() has been destroyed");
68 void MED_MED_DRIVER21::read()
71 void MED_MED_DRIVER21::readFileStruct()
74 void MED_MED_DRIVER21::write() const
77 GENDRIVER * MED_MED_DRIVER21::copy(void) const
79 return new MED_MED_DRIVER21(*this) ;
81 void MED_MED_DRIVER21::writeFrom() const
85 void MED_MED_DRIVER21::open()
89 const char * LOC ="MED_MED_DRIVER21::open() : ";
92 // REFLECHIR SUR CE TEST PAR RAPPORT A L'OUVERTURE/FERMETURE
93 // if ( _medIdt != MED_INVALID )
94 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
95 // << "_medIdt is already in use, please close the file |"
96 // << _fileName << "| before calling open()"
100 // if ( _status != MED_CLOSED )
101 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
102 // << "_status is closed, please close the file |"
103 // << _fileName << "| before calling open()"
107 if ( _fileName == "" )
108 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
109 << "_fileName is |\"\"|, please set a correct fileName before calling open()"
112 int accessMode = getMedAccessMode( _accessMode, MED_EN::V21 );
113 MESSAGE_MED(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode);
114 _medIdt = med_2_1::MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_1::med_mode_acces) accessMode);
115 MESSAGE_MED(LOC<<" _medIdt = "<<_medIdt);
120 _status = MED_CLOSED;
121 _medIdt = MED_INVALID;
122 throw MED_EXCEPTION (LOCALIZED( STRING(LOC)
123 << "Can't open |" << _fileName
124 << "|, _medIdt : " << _medIdt
133 void MED_MED_DRIVER21::close()
135 med_2_1::med_int err = 0;
136 const char* LOC = "MED_MED_DRIVER21::close() : ";
140 // if ( _status == MED_CLOSED)
141 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": the file |"
142 // << _fileName << "| is already closed"
146 // if ( _medIdt == MED_INVALID )
147 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "_medIdt invalid, but the file |"
148 // << _fileName << "| seems to be openned !"
152 if ( _medIdt != MED_INVALID )
153 err=med_2_1::MEDfermer(_medIdt);
155 // if (err != MED_VALID)
156 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |"
157 // << _fileName << "| couldn't be closed"
161 _status = MED_CLOSED;
162 _medIdt = MED_INVALID;
168 // ------------- Read Only Part --------------
170 MED_MED_RDONLY_DRIVER21::MED_MED_RDONLY_DRIVER21()
172 this->GENDRIVER::_accessMode = MED_EN::RDONLY;
175 MED_MED_RDONLY_DRIVER21::MED_MED_RDONLY_DRIVER21(const string & fileName, MED * const ptrMed):
176 IMED_MED_RDONLY_DRIVER(fileName,ptrMed),
177 MED_MED_DRIVER21(fileName,ptrMed,MED_EN::RDONLY),
178 MED_MED_DRIVER(fileName,ptrMed,MED_EN::RDONLY)
180 MESSAGE_MED("MED_MED_RDONLY_DRIVER21::MED_MED_RDONLY_DRIVER21(const string & fileName, MED * const ptrMed) Constructeur read only");
183 MED_MED_RDONLY_DRIVER21::MED_MED_RDONLY_DRIVER21(const MED_MED_RDONLY_DRIVER21 & driver):
184 IMED_MED_RDONLY_DRIVER(driver) ,MED_MED_DRIVER21(driver),MED_MED_DRIVER(driver)
188 MED_MED_RDONLY_DRIVER21::~MED_MED_RDONLY_DRIVER21()
190 MESSAGE_MED("MED_MED_RDONLY_DRIVER21::~MED_MED_RDONLY_DRIVER21() has been destroyed");
193 GENDRIVER * MED_MED_RDONLY_DRIVER21::copy(void) const
195 return new MED_MED_RDONLY_DRIVER21(*this) ;
198 void MED_MED_RDONLY_DRIVER21::write ( void ) const throw (MEDEXCEPTION)
200 IMED_MED_RDONLY_DRIVER::write();
203 void MED_MED_RDONLY_DRIVER21::writeFrom ( void ) const throw (MEDEXCEPTION)
205 IMED_MED_RDONLY_DRIVER::writeFrom();
208 void MED_MED_RDONLY_DRIVER21::readFileStruct( void )
211 const char * LOC = "MED_MED_DRIVER21::readFileStruct() : ";
215 if ( IMED_MED_RDONLY_DRIVER::_fileStructIsRead )
218 IMED_MED_RDONLY_DRIVER::_fileStructIsRead = true;
222 if ( _medIdt == MED_INVALID )
223 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
224 << "_medIdt is invalid, please open the file |"
225 << _fileName << "| before calling readFileStruct()"
228 // Read number of meshes and their associated name
231 char meshName[MED_TAILLE_NOM+1]="";
232 char meshDescription[MED_TAILLE_DESC+1]="";
233 med_2_1::med_int meshDim;
235 // MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
237 numberOfMeshes = med_2_1::MEDnMaa(_medIdt) ;
238 if ( numberOfMeshes <= 0 )
239 MESSAGE_MED(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
241 MESH_ENTITIES::const_iterator currentEntity;
242 for (i=1;i<=numberOfMeshes;i++) {
244 // find out if the mesh is a Grid
246 med_2_1::med_int isAGrid = false;
247 med_2_1::med_grid_type type;
249 err = MEDgridInfo (_medIdt, i, &isAGrid, &type);
250 if (err != MED_VALID)
251 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "error in MEDgridInfo()") );
253 err = med_2_1::MEDmaaInfo(_medIdt, i ,meshName, &meshDim) ;
255 strcpy(meshDescription,"Mesh from Med 2.2 format");
257 if (err != MED_VALID)
258 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": can't get information about the mesh n°"
259 << i <<" of the file |" << _fileName << "| !"
262 MESSAGE_MED(LOC<<": Mesh n°"<<i<<" nammed "<<meshName);
265 ptrMesh = new GRID((MED_EN::med_grid_type) type);
267 ptrMesh = new MESH();
269 //MED_MESH_RDWR_DRIVER * _ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
270 MED_EN::med_mode_acces myMode = getAccessMode();
271 // MED_MESH_DRIVER * ptrDriver ;
273 // case MED_EN::MED_LECT:
274 // ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
276 // case MED_EN::MED_REMP:
277 // ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
279 // case MED_EN::MED_ECRI: // should never append !!
280 // ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
283 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
286 GENDRIVER * ptrDriver =
287 DRIVERFACTORY::buildConcreteMedDriverForMesh(_fileName, ptrMesh,
288 meshName, myMode, V21);
290 ptrDriver->setId ( getId() );
291 ptrDriver->setMeshName ( meshName );
292 ptrMesh->setDescription(meshDescription);
294 SCRUTE_MED(ptrDriver);
296 ptrMesh->addDriver(*ptrDriver);
300 _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
302 _ptrMed->_meshes[meshName] = ptrMesh;
304 ptrMesh->setName(meshName);
306 // add by B. Secher for filter module
307 ptrMesh->setMeshDimension(meshDim);
311 MESSAGE_MED(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
313 // we create all global support (for each entity type :
315 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
316 string supportName="SupportOnAll_" ;
317 supportName+=entNames[(*currentEntity).first] ;
318 //(_ptrMed->_support)[meshName][(MED_EN::medEntityMesh)(*currentEntity).first]=new SUPPORT(ptrMesh,supportName,(MED_EN::medEntityMesh) (*currentEntity).first) ;
319 SUPPORT* mySupport = new SUPPORT() ;
320 mySupport->setName(supportName);
321 mySupport->setMesh(ptrMesh);
322 mySupport->setEntity((MED_EN::medEntityMesh) (*currentEntity).first);
323 mySupport->setAll(true);
324 (_ptrMed->_support)[meshName][(MED_EN::medEntityMesh)(*currentEntity).first] = mySupport ;
325 MESSAGE_MED(LOC<< "The support " << supportName.c_str() << " on entity " << (*currentEntity).first << " is built");
328 MESSAGE_MED(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
331 map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
335 vector<SUPPORT *> vectSupp;
336 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
337 const_itSupportOnMesh++ )
339 map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ;
340 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
341 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++;
344 MESSAGE_MED(LOC << "In this MED object there is(are) " << index << " support(s):");
346 vectSupp.resize(index);
349 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
350 const_itSupportOnMesh++ )
352 map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ;
353 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
354 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++)
356 vectSupp[index] = (*const_itSupport).second;
357 SCRUTE_MED(vectSupp[index]);
358 // comment the next line for PAL19767 Modification for icc and icpc (INTEL compilators)
359 //MESSAGE_MED(STRING(LOC) << "Support number " << index << " is "<< *vectSupp[index]));
367 // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
369 int numberOfFields = 0; //MED_INVALID
370 // char fieldName[MED_TAILLE_NOM+1] = "";
371 // char fieldName[MED_TAILLE_NOM+1] ;
372 char fieldName[MED_TAILLE_LNOM+1] ; //SRN: to avoid a crash if the field name is longer than MED_TAILLE_NOM
373 int numberOfComponents = 0;
374 char * componentName = (char *) MED_NULL;
375 char * unitName = (char *) MED_NULL;
376 // char meshName[MED_TAILLE_NOM+1] = "";
377 char meshName[MED_TAILLE_NOM+1] ;
378 med_2_1::med_type_champ type;
379 MESH * ptrMesh = (MESH *) MED_NULL;
380 FIELD_ * ptrField = (FIELD_ *) MED_NULL;
381 //MED_FIELD_RDWR_DRIVER * ptrDriver = (MED_FIELD_RDWR_DRIVER * ) MED_NULL;
382 GENDRIVER * ptrDriver = (GENDRIVER * ) MED_NULL;
383 SUPPORT * ptrSupport = (SUPPORT * ) MED_NULL;
384 MESH_ENTITIES::const_iterator currentEntity;
385 list<MED_EN::medGeometryElement>::const_iterator currentGeometry;
386 med_2_1::med_int NbOfGaussPts = 0;
387 int numberOfTimeSteps = -1;
388 med_2_1::med_int timeStepNumber = -1;
389 // char timeStepUnit[MED_TAILLE_PNOM]= "";
390 char timeStepUnit[MED_TAILLE_PNOM21+1] ;
391 double timeStep = 0.0;
392 med_2_1::med_int orderNumber = -1; //???init?????
393 map<MESH_NAME_,MESH*> & _meshes = _ptrMed->_meshes;
394 map<FIELD_NAME_,MAP_DT_IT_> & _fields = _ptrMed->_fields;
395 map<FIELD_ *, MESH_NAME_> & _meshName = _ptrMed->_meshName;
396 map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> > & support = _ptrMed->_support;
399 numberOfFields = med_2_1::MEDnChamp(_medIdt,0) ;
400 if ( numberOfFields <= 0 )
401 MESSAGE_MED(LOC << "Be careful there is no field in file |"<<_fileName<<"| !");
403 for (i=1;i<=numberOfFields;i++) {
405 numberOfComponents = med_2_1::MEDnChamp(_medIdt,i) ;
406 if ( numberOfComponents <= 0 )
407 if (err != MED_VALID)
408 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Be careful there is no compound for field n°"
409 << i << "in file |"<<_fileName<<"| !"));
411 componentName = new char[numberOfComponents*MED_TAILLE_PNOM21+1] ;
412 unitName = new char[numberOfComponents*MED_TAILLE_PNOM21+1] ;
414 err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName,
415 unitName, numberOfComponents) ;
417 if (err != MED_VALID)
418 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
419 << ": can't get information about the field n°"
420 << i <<" of the file |" << _fileName << "| !"));
422 MESSAGE_MED(LOC << "Field n°"<<i<<" nammed "<< fieldName
423 << " ,component(s) : " << componentName
424 <<" ,unit(s) : " << unitName);
427 // Loop on all (entity type,geometry type) until you find an existing one then
428 // get the (n°dt,n°it) pairs list for the current (field,entity type,geometry type)
429 // We suppose there is the same list whatever the existing (entity type,geometry type) pair
431 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
432 // numberOfTimeSteps MUST be given by MEDchampInfo !!!!!
433 for (currentGeometry = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {
434 MESSAGE_MED("Field information with Entity,Geom = "<<(*currentEntity).first<<","<<(*currentGeometry));
435 numberOfTimeSteps = MEDnPasdetemps(_medIdt, fieldName,
436 (med_2_1::med_entite_maillage)(*currentEntity).first,
437 (med_2_1::med_geometrie_element) (*currentGeometry) );
438 MESSAGE_MED("Field information 2 : NumberOfTimeStep :"<<numberOfTimeSteps);
439 if ( numberOfTimeSteps > MED_VALID )
440 break ; // There are value for some med_geometrie_element of this med_entite_maillage.
442 if (numberOfTimeSteps>0) // we have at least one
444 for (currentGeometry = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {
446 MESSAGE_MED("Field information 3 : Geom : "<<(*currentGeometry));
447 for (j=1;j <= numberOfTimeSteps; j++) {
449 MESSAGE_MED("Field information 4 : time step j = "<<j);
450 err = MEDpasdetempsInfo( _medIdt, fieldName,
451 (med_2_1::med_entite_maillage) (*currentEntity).first,
452 (med_2_1::med_geometrie_element) (*currentGeometry),j,
453 meshName, &NbOfGaussPts,
454 &timeStepNumber, timeStepUnit, &timeStep,
456 if (err == MED_VALID) { // we have found for (*currentEntity).first and (*currentGeometry)
458 MESSAGE_MED("Field information 5 ;: NumberOfGaussPoint : "<<NbOfGaussPts<<", timeStepNumber : "<<timeStepNumber);
459 // CORRECT a bug in MEDpasdetempsInfo :
460 // we get a value n'importe quoi in NbOfGaussPts !!!!
462 if (NbOfGaussPts>100)
464 if (timeStepNumber<0)
468 // ATTENTION TRAITER L'EXCEPTION !!!!!!!!!!!!
470 // Il faudra traiter le cas d'un champ qui utilise +sieurs (entity,geom) voir le travail de patrick
471 // Il faudra traiter le cas des profils...
472 // ptrField = new FIELD();
473 // _ptrDriver = new MED_FIELD_RDWR_DRIVER(_fileName, ptrField);
474 // ptrField->addDriver(_ptrDriver);
475 // _fields[fieldName]=ptrField;
477 // Verify meshName is already known
479 map<MESH_NAME_,MESH*>::iterator _meshesIt = _meshes.find(meshName);
480 if ( _meshesIt == _meshes.end() ) {
481 MESSAGE_MED(LOC << "There is no mesh |"
482 << meshName <<"| in the file |"
483 << _fileName <<"|, but |" << meshName <<"| is referenced by field |"
484 << fieldName <<"|, entity : |"
485 << entNames [(*currentEntity).first] <<"|, geometric element of type |"
486 << geoNames [(*currentGeometry)] <<"|"
488 } // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE ERROR : PG : c'est la macro MESSAGE_MED qui fait ca !
490 ptrMesh = _meshes[meshName];
492 ptrSupport = support[meshName][(MED_EN::medEntityMesh) (*currentEntity).first];
493 // if (NbOfGaussPts != 1)
494 // throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ;
496 // init to null to prevent some error if not correctly allocated !
497 ptrField = (FIELD_*)NULL ;
498 // ptrDriver = (GENDRIVER*)NULL ;
501 case med_2_1::MED_INT64 :
502 if ( sizeof(med_2_1::med_int) != 8 )
503 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
504 " The Field type of |"
505 << fieldName <<"|, entity : |"
506 << entNames [(*currentEntity).first] <<"|, geometric element of type |"
507 << geoNames [(*currentGeometry) ] <<
508 "| is MED_INT64 but size of med_int is not equal to 8 bytes !"
512 case med_2_1::MED_INT32 : {
513 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
514 // "NOT IMPLEMENTED : BUG IN STL !")
516 // ptrField = new FIELD<med_2_1::med_int> ( ptrSupport,numberOfComponents ); // Les valeurs du champ ne doivent pas être lue pour l'instant
518 ptrField = new FIELD<int> ( ); // Les valeurs du champ ne doivent pas être lue pour l'instant
519 ((FIELD<int>*) ptrField)->setSupport(ptrSupport);
520 ((FIELD<int>*) ptrField)->setNumberOfComponents(numberOfComponents);
521 ((FIELD<int>*) ptrField)->setName(fieldName) ; //provisoire, pour debug
522 MESSAGE_MED("#### SET NAME in FIELD : "<<fieldName);
524 MED_EN::med_mode_acces myMode = getAccessMode();
526 // case MED_EN::MED_LECT:
527 // ptrDriver = new MED_FIELD_RDONLY_DRIVER<int>(_fileName, (FIELD<int> *)ptrField);
529 // case MED_EN::MED_REMP:
530 // ptrDriver = new MED_FIELD_RDWR_DRIVER<int>(_fileName, (FIELD<int> *)ptrField);
532 // case MED_EN::MED_ECRI: // should never append !!
533 // ptrDriver = new MED_FIELD_RDONLY_DRIVER<int>(_fileName, (FIELD<int> *)ptrField);
536 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
539 ptrDriver = DRIVERFACTORY::buildConcreteMedDriverForField<int>(_fileName, (FIELD<int> *)ptrField, myMode, V21);
541 SCRUTE_MED(ptrDriver);
545 case med_2_1::MED_REEL64 : {
546 // ptrField = new FIELD<med_2_1::med_float> ( ptrSupport,numberOfComponents ); // Les valeurs du champ ne doivent pas être lue pour l'instant
547 ptrField = new FIELD<double> ( ); // Les valeurs du champ ne doivent pas être lue pour l'instant
548 ((FIELD<med_2_1::med_float>*) ptrField)->setSupport(ptrSupport);
549 ((FIELD<med_2_1::med_float>*) ptrField)->setNumberOfComponents(numberOfComponents);
550 ((FIELD<med_2_1::med_float>*) ptrField)->setName(fieldName) ; //provisoire, pour debug
551 MESSAGE_MED("#### SET NAME in FIELD : "<<fieldName);
553 MED_EN::med_mode_acces myMode = getAccessMode();
555 // case MED_EN::MED_LECT:
556 // ptrDriver = new MED_FIELD_RDONLY_DRIVER<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField);
558 // case MED_EN::MED_REMP:
559 // ptrDriver = new MED_FIELD_RDWR_DRIVER<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField);
561 // case MED_EN::MED_ECRI: // should never append !!
562 // ptrDriver = new MED_FIELD_RDONLY_DRIVER<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField);
565 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
568 ptrDriver = DRIVERFACTORY::buildConcreteMedDriverForField<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField, myMode, V21);
569 SCRUTE_MED(ptrDriver);
574 if ( numberOfTimeSteps > 1)
575 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
576 " The Field type of |"
577 << fieldName <<"|, entity : |"
578 << entNames [(*currentEntity).first]
579 <<"|, geometric element of type |"
580 << geoNames [(*currentGeometry)]
581 <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !"
588 MESSAGE_MED("timeStepNumber :"<<timeStepNumber<<",orderNumber :"<<orderNumber);
589 ptrField->setIterationNumber ( timeStepNumber); // A ajouter dans la classe FIELD
590 ptrField->setOrderNumber ( orderNumber);
591 ptrField->setTime ( timeStep);
593 // Create a driver for this (field n°dt,n°it)
594 ptrDriver->setId ( getId() );
595 MESSAGE_MED("###### ptrDriver->setFieldName : #"<<fieldName<<"#");
596 ptrDriver->setFieldName(fieldName);
597 ptrField->addDriver(*ptrDriver);
598 // driver is duplicated : remove it
602 dtIt.dt = timeStepNumber;
603 dtIt.it = orderNumber;
605 (_fields [fieldName])[dtIt] = ptrField;
606 _meshName[ptrField ] = meshName;
611 delete[] componentName ;
616 // read profil count and their names
617 // int support_count_= 0 ; !! UNUSED VARIABLE !!
618 // il faut lire les champs pour avoir les profils stockes !!!
619 // il faudrait implémenter la lecture des profils dans med !!!
625 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
626 // to read themselves
627 void MED_MED_RDONLY_DRIVER21::read( void )
628 throw (MEDEXCEPTION) // from objects method read !
630 const char* LOC = "MED_MED_DRIVER21::read() : ";
633 // For PAL12192: assure that file structure is already read
635 this->readFileStruct();
638 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
639 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
641 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
642 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
644 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ )
645 (*currentMesh).second->read(*this);
646 //(*currentMesh).second->read(); // default reader, from readFileStruct
649 _ptrMed->updateSupport() ;
651 for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
652 (*currentField).first->read(*this);
653 //(*currentField).first->read(); // default reader, from readFileStruct
658 // ------------- Write Only Part --------------
660 MED_MED_WRONLY_DRIVER21::MED_MED_WRONLY_DRIVER21()
662 this->GENDRIVER::_accessMode = MED_EN::WRONLY;
665 MED_MED_WRONLY_DRIVER21::MED_MED_WRONLY_DRIVER21(const string & fileName, MED * const ptrMed):
666 IMED_MED_WRONLY_DRIVER(fileName,ptrMed),
667 MED_MED_DRIVER21(fileName,ptrMed),
668 MED_MED_DRIVER(fileName,ptrMed,MED_EN::WRONLY)
671 MED_MED_WRONLY_DRIVER21::MED_MED_WRONLY_DRIVER21(const MED_MED_WRONLY_DRIVER21 & driver):
672 IMED_MED_WRONLY_DRIVER(driver),MED_MED_DRIVER(driver),MED_MED_DRIVER21(driver)
675 MED_MED_WRONLY_DRIVER21::~MED_MED_WRONLY_DRIVER21()
677 MESSAGE_MED("MED_MED_WRONLY_DRIVER21::~MED_MED_WRONLY_DRIVER21() has been destroyed");
680 GENDRIVER * MED_MED_WRONLY_DRIVER21::copy(void) const
682 return new MED_MED_WRONLY_DRIVER21(*this) ;
685 void MED_MED_WRONLY_DRIVER21::read ( void ) throw (MEDEXCEPTION)
687 IMED_MED_WRONLY_DRIVER::read();
690 void MED_MED_WRONLY_DRIVER21::readFileStruct ( void ) throw (MEDEXCEPTION)
692 IMED_MED_WRONLY_DRIVER::readFileStruct();
695 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
696 // to write themselves
697 void MED_MED_WRONLY_DRIVER21::writeFrom( void) const
698 throw (MEDEXCEPTION) //from object method write !
700 const char* LOC = "MED_MED_DRIVER21::writeFrom() : ";
703 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
704 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
706 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
707 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
709 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
711 (*currentMesh).second->write(*this);
712 // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id
714 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) {
719 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
721 (*currentField).first->write(*this);
723 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) {
732 void MED_MED_WRONLY_DRIVER21::write(void ) const
733 throw (MEDEXCEPTION) // from object method write !
736 const char* LOC = "MED_MED_DRIVER21::write() : ";
739 // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
741 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
742 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
744 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
745 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
747 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
748 //current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName);
749 current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName,(*currentMesh).second->getName());
750 // put right _id in Mesh driver (same as this._id)
751 (*currentMesh).second->_drivers[current]->setId( getId() );
752 (*currentMesh).second->write(current) ;
755 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
756 //current = (*currentField).first->addDriver(MED_DRIVER,_fileName);
757 current = (*currentField).first->addDriver(MED_DRIVER,_fileName,(*currentField).first->getName());
758 // put right _id in Field driver (same as this._id)
759 (*currentField).first->_drivers[current]->setId( getId() );
760 (*currentField).first->write(current) ;
763 // that's work, but it is more efficenty to write directly when we had driver, no ?
770 // ------------- Read Write Part --------------
772 MED_MED_RDWR_DRIVER21::MED_MED_RDWR_DRIVER21()
774 this->GENDRIVER::_accessMode = MED_EN::RDWR;
777 MED_MED_RDWR_DRIVER21::MED_MED_RDWR_DRIVER21(const string & fileName, MED * const ptrMed):
778 MED_MED_RDONLY_DRIVER21(fileName,ptrMed),
779 MED_MED_WRONLY_DRIVER21(fileName,ptrMed),
780 IMED_MED_RDWR_DRIVER(fileName,ptrMed),
781 MED_MED_DRIVER21(fileName,ptrMed,RDWR),
782 IMED_MED_WRONLY_DRIVER(fileName,ptrMed),
783 IMED_MED_RDONLY_DRIVER(fileName,ptrMed),
784 MED_MED_DRIVER(fileName,ptrMed,RDWR)
787 MED_MED_RDWR_DRIVER21::MED_MED_RDWR_DRIVER21(const MED_MED_RDWR_DRIVER21 & driver):
788 MED_MED_RDONLY_DRIVER21(driver),
789 MED_MED_WRONLY_DRIVER21(driver),
790 IMED_MED_RDWR_DRIVER(driver),
791 MED_MED_DRIVER21(driver),
792 IMED_MED_WRONLY_DRIVER(driver),
793 IMED_MED_RDONLY_DRIVER(driver),
794 MED_MED_DRIVER(driver)
797 MED_MED_RDWR_DRIVER21::~MED_MED_RDWR_DRIVER21() {
798 MESSAGE_MED("MED_MED_RDWR_DRIVER21::~MED_MED_RDWR_DRIVER21() has been destroyed");
801 GENDRIVER * MED_MED_RDWR_DRIVER21::copy(void) const
803 return new MED_MED_RDWR_DRIVER21(*this) ;
806 void MED_MED_RDWR_DRIVER21::read(void)
807 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
809 const char* LOC = "MED_MED_RDWR_DRIVER21::read(void)";
811 MED_MED_RDONLY_DRIVER21::read();
815 void MED_MED_RDWR_DRIVER21::readFileStruct(void)
816 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
818 const char* LOC = "MED_MED_RDWR_DRIVER21::readFileStruct(void)";
820 MED_MED_RDONLY_DRIVER21::readFileStruct();
824 void MED_MED_RDWR_DRIVER21::write(void) const
825 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
827 const char* LOC = "MED_MED_RDWR_DRIVER21::write(void) const";
829 MED_MED_WRONLY_DRIVER21::write();
833 void MED_MED_RDWR_DRIVER21::writeFrom(void) const
834 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
836 const char* LOC = "MED_MED_RDWR_DRIVER21::writeFrom(void) const";
838 MED_MED_WRONLY_DRIVER21::writeFrom();