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_MedMedDriver22.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"
36 using namespace MED_EN;
37 using namespace MEDMEM;
39 MED_MED_DRIVER22::MED_MED_DRIVER22(): _medIdt(MED_INVALID)
42 MED_MED_DRIVER22::MED_MED_DRIVER22(const string & fileName, MED * const ptrMed):
43 MED_MED_DRIVER(fileName,ptrMed), _medIdt(MED_INVALID)
45 //_ptrMed->addDriver(*this); // The specific MED driver id is set within the addDriver method.
48 MED_MED_DRIVER22::MED_MED_DRIVER22(const string & fileName,
50 MED_EN::med_mode_acces accessMode):
51 MED_MED_DRIVER(fileName,ptrMed,accessMode), _medIdt(MED_INVALID)
54 //REM : As t'on besoin du champ _status : _medIdt <-> _status ? Oui
56 MED_MED_DRIVER22::MED_MED_DRIVER22(const MED_MED_DRIVER22 & driver):
57 MED_MED_DRIVER(driver), _medIdt(MED_INVALID)
61 MED_MED_DRIVER22::~MED_MED_DRIVER22()
63 MESSAGE_MED("MED_MED_DRIVER22::~MED_MED_DRIVER22() has been destroyed");
66 // GENDRIVER * MED_MED_DRIVER::copy(void) const
68 // return new MED_MED_DRIVER(*this) ;
70 void MED_MED_DRIVER22::read()
73 void MED_MED_DRIVER22::readFileStruct()
76 void MED_MED_DRIVER22::write() const
79 GENDRIVER * MED_MED_DRIVER22::copy(void) const
81 return new MED_MED_DRIVER22(*this) ;
83 void MED_MED_DRIVER22::writeFrom() const
89 void MED_MED_DRIVER22::open()
93 const char * LOC ="MED_MED_DRIVER22::open() : ";
96 // REFLECHIR SUR CE TEST PAR RAPPORT A L'OUVERTURE/FERMETURE
97 // if ( _medIdt != MED_INVALID )
98 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
99 // << "_medIdt is already in use, please close the file |"
100 // << _fileName << "| before calling open()"
104 // if ( _status != MED_CLOSED )
105 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
106 // << "_status is closed, please close the file |"
107 // << _fileName << "| before calling open()"
111 if ( _fileName == "" )
112 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
113 << "_fileName is |\"\"|, please set a correct fileName before calling open()"
117 int accessMode = getMedAccessMode( _accessMode, MED_EN::V22 );
118 MESSAGE_MED(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode);
120 _medIdt = med_2_3::MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_3::med_mode_acces) accessMode);
121 MESSAGE_MED(LOC<<" _medIdt = "<<_medIdt);
126 _status = MED_CLOSED;
127 _medIdt = MED_INVALID;
128 throw MED_EXCEPTION (LOCALIZED( STRING(LOC)
129 << "Can't open |" << _fileName
130 << "|, _medIdt : " << _medIdt
139 void MED_MED_DRIVER22::close()
141 med_2_3::med_int err = 0;
144 // if ( _status == MED_CLOSED)
145 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": the file |"
146 // << _fileName << "| is already closed"
150 // if ( _medIdt == MED_INVALID )
151 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "_medIdt invalid, but the file |"
152 // << _fileName << "| seems to be openned !"
156 if ( _medIdt != MED_INVALID )
157 err=med_2_3::MEDfermer(_medIdt);
159 // if (err != MED_VALID)
160 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |"
161 // << _fileName << "| couldn't be closed"
165 _status = MED_CLOSED;
166 _medIdt = MED_INVALID;
172 // ------------- Read Only Part --------------
174 MED_MED_RDONLY_DRIVER22::MED_MED_RDONLY_DRIVER22()
176 this->GENDRIVER::_accessMode = MED_EN::RDONLY;
179 MED_MED_RDONLY_DRIVER22::MED_MED_RDONLY_DRIVER22(const string & fileName, MED * const ptrMed):
180 IMED_MED_RDONLY_DRIVER(fileName,ptrMed),
181 MED_MED_DRIVER22(fileName,ptrMed,MED_EN::RDONLY),
182 MED_MED_DRIVER(fileName,ptrMed,MED_EN::RDONLY)
184 MESSAGE_MED("MED_MED_RDONLY_DRIVER22::MED_MED_RDONLY_DRIVER22(const string & fileName, MED * const ptrMed) Constructeur read only");
187 MED_MED_RDONLY_DRIVER22::MED_MED_RDONLY_DRIVER22(const MED_MED_RDONLY_DRIVER22 & driver):
188 IMED_MED_RDONLY_DRIVER(driver) ,MED_MED_DRIVER22(driver),MED_MED_DRIVER(driver)
192 MED_MED_RDONLY_DRIVER22::~MED_MED_RDONLY_DRIVER22()
194 MESSAGE_MED("MED_MED_RDONLY_DRIVER22::~MED_MED_RDONLY_DRIVER22() has been destroyed");
197 GENDRIVER * MED_MED_RDONLY_DRIVER22::copy(void) const
199 return new MED_MED_RDONLY_DRIVER22(*this) ;
202 void MED_MED_RDONLY_DRIVER22::write ( void ) const throw (MEDEXCEPTION)
204 IMED_MED_RDONLY_DRIVER::write();
207 void MED_MED_RDONLY_DRIVER22::writeFrom ( void ) const throw (MEDEXCEPTION)
209 IMED_MED_RDONLY_DRIVER::writeFrom();
212 void MED_MED_RDONLY_DRIVER22::readFileStruct( void )
215 const char * LOC = "MED_MED_DRIVER22::readFileStruct() : ";
219 if ( IMED_MED_RDONLY_DRIVER::_fileStructIsRead )
222 IMED_MED_RDONLY_DRIVER::_fileStructIsRead = true;
226 if ( _medIdt == MED_INVALID )
227 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
228 << "_medIdt is invalid, please open the file |"
229 << _fileName << "| before calling readFileStruct()"
232 // Read number of meshes and their associated name
235 char meshName[MED_TAILLE_NOM+1]="";
236 char meshDescription[MED_TAILLE_DESC+1]="";
238 med_2_3::med_int meshDim;
239 med_2_3::med_maillage meshType;
242 // MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
244 numberOfMeshes = med_2_3::MEDnMaa(_medIdt) ;
245 if ( numberOfMeshes <= 0 )
246 MESSAGE_MED(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
248 MESH_ENTITIES::const_iterator currentEntity;
249 for (i=1;i<=numberOfMeshes;i++)
251 //get infoamation on the i^th mesh
253 err = MEDmaaInfo(_medIdt, i ,meshName, &meshDim, &meshType,
256 if (err != MED_VALID)
257 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get information about the mesh n°" << i << " of the file |" << _fileName << "| !"));
261 case med_2_3::MED_STRUCTURE:
262 MESSAGE_MED(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
264 med_2_3::med_type_grille type;
266 err = MEDnatureGrilleLire(_medIdt, meshName, &type);
268 if (err != MED_VALID)
269 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get the nature of the grid which is the mesh n°" << i << " of the file |" << _fileName << "| !"));
271 ptrMesh = new GRID((MED_EN::med_grid_type) type);
273 case med_2_3::MED_NON_STRUCTURE:
274 MESSAGE_MED(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is not structured");
276 ptrMesh = new MESH();
279 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mesh type !"));
282 bool isAGrid = ptrMesh->getIsAGrid();
285 MED_EN::med_mode_acces myMode = getAccessMode();
286 // MED_MESH_DRIVER * ptrDriver ;
288 // case MED_EN::MED_LECT: // V2_1->V2_2
289 // ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
291 // case MED_EN::MED_REMP: // V2_1->V2_2
292 // ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
294 // case MED_EN::MED_ECRI: // should never append !! V2_1->V2_2
295 // ptrDriver = new MED_MESH_WRONLY_DRIVER(_fileName, ptrMesh);
298 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
301 GENDRIVER * ptrDriver =
302 DRIVERFACTORY::buildConcreteMedDriverForMesh(_fileName, ptrMesh,
303 meshName, myMode, V22);
305 ptrDriver->setId ( getId() );
306 ptrDriver->setMeshName ( meshName );
307 ptrMesh->addDriver(*ptrDriver);
311 _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
313 _ptrMed->_meshes[meshName] = ptrMesh;
315 // _ptrMed->_meshes[meshName] = ptrMesh;
317 ptrMesh->setName( healName( meshName ));
319 ptrMesh->setDescription(meshDescription);
321 // add by B. Secher for filter module
322 ptrMesh->setMeshDimension(meshDim);
326 MESSAGE_MED(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
328 // we create all global support (for each entity type :
330 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
331 string supportName="SupportOnAll_" ;
332 supportName+=entNames[(MED_EN::medEntityMesh)(*currentEntity).first] ;
333 SUPPORT* mySupport = new SUPPORT() ;
334 mySupport->setName(supportName);
335 mySupport->setMesh(ptrMesh);
336 mySupport->setEntity((MED_EN::medEntityMesh) (*currentEntity).first);
337 mySupport->setAll(true);
338 (_ptrMed->_support)[meshName][(MED_EN::medEntityMesh)(*currentEntity).first] = mySupport ;
339 MESSAGE_MED(LOC<< "The support " << supportName.c_str() << " on entity " << (*currentEntity).first << " is built");
342 MESSAGE_MED(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
345 map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::iterator itSupportOnMesh ;
349 vector<SUPPORT *> vectSupp;
350 for (itSupportOnMesh=_ptrMed->_support.begin();
351 itSupportOnMesh != _ptrMed->_support.end();
354 map<MED_EN::medEntityMesh,SUPPORT *>::iterator itSupport ;
355 for (itSupport=(*itSupportOnMesh).second.begin();
356 itSupport!=(*itSupportOnMesh).second.end();
363 MESSAGE_MED(LOC << "In this MED object there is(are) " << index << " support(s):");
365 vectSupp.resize(index);
367 map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
370 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
371 const_itSupportOnMesh++ )
373 map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ;
374 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
375 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++)
377 vectSupp[index] = (*const_itSupport).second;
378 SCRUTE_MED(vectSupp[index]);
379 MESSAGE_MED(LOC << "Support number " << index << " is "<< *vectSupp[index]);
387 // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
389 int numberOfFields = 0; //MED_INVALID
390 // char fieldName[MED_TAILLE_NOM+1] = "";
391 char fieldName[MED_TAILLE_LNOM+1] ; // to avoid a crash if the field name is longer than MED_TAILLE_NOM
392 int numberOfComponents = 0;
393 char * componentName = (char *) MED_NULL;
394 char * unitName = (char *) MED_NULL;
395 // char meshName[MED_TAILLE_NOM+1] = "";
396 char meshName[MED_TAILLE_NOM+1] ;
397 med_2_3::med_type_champ type;
398 MESH * ptrMesh = (MESH *) MED_NULL;
399 FIELD_ * ptrField = (FIELD_ *) MED_NULL;
400 //MED_FIELD_RDWR_DRIVER * ptrDriver = (MED_FIELD_RDWR_DRIVER * ) MED_NULL;
401 GENDRIVER * ptrDriver = (GENDRIVER * ) MED_NULL;
402 SUPPORT * ptrSupport = (SUPPORT * ) MED_NULL;
403 MESH_ENTITIES::const_iterator currentEntity;
404 list<MED_EN::medGeometryElement>::const_iterator currentGeometry;
405 med_2_3::med_int NbOfGaussPts = 0;
406 int numberOfTimeSteps = -1;
407 med_2_3::med_int timeStepNumber = -1;
408 // char timeStepUnit[MED_TAILLE_PNOM]= "";
409 char timeStepUnit[MED_TAILLE_PNOM22+1] ;
410 double timeStep = 0.0;
411 //CCRT int orderNumber = -1; //???init?????
412 med_2_3::med_int orderNumber = -1; //???init?????
413 //CCRT int numberOfRefMesh = 0;
414 med_2_3::med_int numberOfRefMesh = 0;
415 med_2_3::med_booleen meshLink;
416 map<MESH_NAME_,MESH*> & _meshes = _ptrMed->_meshes;
417 map<FIELD_NAME_,MAP_DT_IT_> & _fields = _ptrMed->_fields;
418 map<FIELD_ *, MESH_NAME_> & _meshName = _ptrMed->_meshName;
419 map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> > & support = _ptrMed->_support;
421 numberOfFields = med_2_3::MEDnChamp(_medIdt,0) ;
422 if ( numberOfFields <= 0 )
423 MESSAGE_MED(LOC << "Be careful there is no field in file |"<<
426 for (i=1;i<=numberOfFields;i++)
428 numberOfComponents = med_2_3::MEDnChamp(_medIdt,i) ;
430 if ( numberOfComponents <= 0 )
431 if (err != MED_VALID)
432 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Be careful there is no compound for field n°" << i << "in file |"<<_fileName<<"| !"));
434 componentName = new char[numberOfComponents*MED_TAILLE_PNOM22+1] ;
435 unitName = new char[numberOfComponents*MED_TAILLE_PNOM22+1] ;
437 err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName,
438 unitName, numberOfComponents) ;
440 MESSAGE_MED("Field n°" << i << " nammed " << fieldName << endl
441 << "Name real length = " << strlen(fieldName)
442 << ", while reserved " << MED_TAILLE_NOM);
444 if (err != MED_VALID)
445 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get information about the field n°" << i <<" of the file |" << _fileName << "| !"));
447 MESSAGE_MED(LOC << "Field n°"<<i<<" nammed "<< fieldName
448 << " ,component(s) : " << componentName
449 <<" ,unit(s) : " << unitName);
451 // Loop on all (entity type,geometry type) until you find an existing
452 // one then get the (n°dt,n°it) pairs list for the current
453 // (field,entity type,geometry type) We suppose there is the same list
454 // whatever the existing (entity type,geometry type) pair
458 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++)
460 // numberOfTimeSteps MUST be given by MEDchampInfo !!!!!
461 for (currentGeometry = (*currentEntity).second.begin();
462 currentGeometry != (*currentEntity).second.end();
465 MESSAGE_MED("Field information with Entity,Geom = "<<
466 (*currentEntity).first<<","<<(*currentGeometry));
469 MEDnPasdetemps(_medIdt, fieldName,
470 (med_2_3::med_entite_maillage)(*currentEntity).first,
471 (med_2_3::med_geometrie_element) (*currentGeometry) );
473 MESSAGE_MED("Field information 2 : NumberOfTimeStep :"<<
476 if ( numberOfTimeSteps > MED_VALID )
478 // There are value for some med_geometrie_element of this
479 // med_entite_maillage.
481 if (numberOfTimeSteps>0) // we have at least one
483 for (currentGeometry = (*currentEntity).second.begin();
484 currentGeometry != (*currentEntity).second.end();
487 MESSAGE_MED("Field information 3 : Geom : "<<(*currentGeometry));
489 for (j=1;j <= numberOfTimeSteps; j++)
491 MESSAGE_MED("Field information 4 : time step j = "<<j);
493 // err = MEDpasdetempsInfo( _medIdt, fieldName,
494 // (med_2_3::med_entite_maillage) (*currentEntity).first,
495 // (*currentGeometry),j, meshName,
496 // &NbOfGaussPts, &timeStepNumber,
497 // timeStepUnit, &timeStep, &orderNumber);
499 err = MEDpasdetempsInfo(_medIdt, fieldName,
500 (med_2_3::med_entite_maillage)
501 (*currentEntity).first,
502 (med_2_3::med_geometrie_element)
503 (*currentGeometry),j,
504 &NbOfGaussPts, &timeStepNumber,
505 &orderNumber, timeStepUnit,
506 &timeStep, meshName, &meshLink,
509 if (err == MED_VALID)
510 { // we have found for (*currentEntity).first and
511 // (*currentGeometry)
512 MESSAGE_MED("Field information 5 ;: NumberOfGaussPoint : " << NbOfGaussPts << ", timeStepNumber : " << timeStepNumber << ", orderNumber : " << orderNumber);
513 // CORRECT a bug in MEDpasdetempsInfo :
514 // we get a value n'importe quoi in NbOfGaussPts !!!!
516 if (timeStepNumber<0) timeStepNumber=-1 ;
517 if ((numberOfRefMesh != 1) ||
518 (meshLink != med_2_3::MED_VRAI) ||
523 MESSAGE_MED("This field is Med Memory compliant because NumberOfGaussPoint : " << NbOfGaussPts << ", or numberOfRefMesh : " << numberOfRefMesh << ", or meshLink : " << meshLink);
526 // ATTENTION TRAITER L'EXCEPTION CI DESSUS !!!!!!!!
528 // Il faudra traiter le cas d'un champ qui utilise
529 // +sieurs (entity,geom) voir le travail de patrick
530 // Il faudra traiter le cas des profils...
531 // ptrField = new FIELD();
532 // _ptrDriver = new MED_FIELD_RDWR_DRIVER(_fileName,
534 // ptrField->addDriver(_ptrDriver);
535 // _fields[fieldName]=ptrField;
537 map<MESH_NAME_,MESH*>::iterator _meshesIt =
538 _meshes.find(meshName);
540 if ( _meshesIt == _meshes.end() ) {
541 MESSAGE_MED(LOC << "There is no mesh |" << meshName <<
542 "| in the file |" << _fileName <<
543 "|, but |" << meshName <<
544 "| is referenced by field |" <<
545 fieldName <<"|, entity : |" <<
546 entNames[ (med_2_3::med_entite_maillage)
547 (*currentEntity).first] <<
548 "|, geometric element of type |" <<
549 geoNames [(*currentGeometry)] <<"|");
551 // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE
552 // ERROR : PG : c'est la macro MESSAGE_MED qui fait ca !
554 ptrMesh = _meshes[meshName];
556 ptrSupport = support[meshName][(MED_EN::medEntityMesh) (*currentEntity).first];
557 if (NbOfGaussPts != 1)
558 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ;
560 // init to null to prevent some error if not
561 // correctly allocated !
563 ptrField = (FIELD_*)NULL ;
564 ptrDriver = (GENDRIVER*)NULL ;
567 case med_2_3::MED_INT64 :
568 if ( sizeof(med_2_3::med_int) != 8 )
569 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) <<" The Field type of |" << fieldName <<"|, entity : |" << entNames[(med_2_3::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(*currentGeometry)] << "| is MED_INT64 but size of med_int is not equal to 8 bytes !"));
571 case med_2_3::MED_INT32 : {
572 ptrField = new FIELD<int> ( );
573 // Les valeurs du champ ne doivent pas être lue
576 ptrField)->setSupport(ptrSupport);
578 ptrField)->setNumberOfComponents(numberOfComponents);
580 ptrField)->setName(fieldName) ;
581 //provisoire, pour debug
582 MESSAGE_MED("#### SET NAME in FIELD : "<<fieldName);
584 MED_EN::med_mode_acces myMode = getAccessMode();
586 // case MED_EN::MED_LECT: // V2_1->V2_2
588 // MED_FIELD_RDONLY_DRIVER<int>
589 // (_fileName, (FIELD<int> *)
592 // case MED_EN::MED_REMP: // V2_1->V2_2
594 // MED_FIELD_RDWR_DRIVER<int>
595 // (_fileName, (FIELD<int> *)
598 // case MED_EN::MED_ECRI: // should never append !! V2_1->V2_2
600 // MED_FIELD_WRONLY_DRIVER<int>
601 // (_fileName, (FIELD<int> *)
605 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
608 ptrDriver = DRIVERFACTORY::buildConcreteMedDriverForField<int>(_fileName, (FIELD<int> *)ptrField, myMode, V22);
610 SCRUTE_MED(ptrDriver);
615 case MED_EN::MED_REEL64 : {
616 ptrField = new FIELD<double> ( );
617 // Les valeurs du champ ne doivent pas être lue
620 ptrField)->setSupport(ptrSupport);
622 ptrField)->setNumberOfComponents(numberOfComponents);
624 ptrField)->setName(fieldName) ;
625 //provisoire, pour debug
626 MESSAGE_MED("#### SET NAME in FIELD : "<<fieldName);
628 MED_EN::med_mode_acces myMode = getAccessMode();
630 // case MED_EN::MED_LECT: // V2_1->V2_2
632 // MED_FIELD_RDONLY_DRIVER<double>
633 // (_fileName, (FIELD<double> *)
636 // case MED_EN::MED_REMP: // V2_1->V2_2
638 // MED_FIELD_RDWR_DRIVER<double>
639 // (_fileName, (FIELD<double> *)
642 // case MED_EN::MED_ECRI: // should never append !! V2_1->V2_2
644 // MED_FIELD_WRONLY_DRIVER<double>
645 // (_fileName, (FIELD<double> *)
649 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
652 ptrDriver = DRIVERFACTORY::buildConcreteMedDriverForField<double>(_fileName, (FIELD<double> *)ptrField, myMode, V22);
653 SCRUTE_MED(ptrDriver);
658 if ( numberOfTimeSteps > 1)
659 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << " The Field type of |" << fieldName <<"|, entity : |" << entNames[(med_2_3::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(*currentGeometry)] <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !"));
663 // need to write field !
665 MESSAGE_MED("timeStepNumber :"<<timeStepNumber<<
666 ",orderNumber :"<<orderNumber);
667 ptrField->setIterationNumber ( timeStepNumber);
668 // A ajouter dans la classe FIELD
669 ptrField->setOrderNumber ( orderNumber);
670 ptrField->setTime ( timeStep);
672 // Create a driver for this (field n°dt,n°it)
673 ptrDriver->setId ( getId() );
674 MESSAGE_MED("###### ptrDriver->setFieldName : #"<<
676 ptrDriver->setFieldName(fieldName);
677 ptrField->addDriver(*ptrDriver);
678 // driver is duplicated : remove it
682 dtIt.dt = timeStepNumber;
683 dtIt.it = orderNumber;
685 (_fields [fieldName])[dtIt] = ptrField;
686 _meshName[ptrField ] = meshName;
691 delete[] componentName ;
696 // read profil count and their names
697 // int support_count_= 0 ; !! UNUSED VARIABLE !!
698 // il faut lire les champs pour avoir les profils stockes !!!
699 // il faudrait implémenter la lecture des profils dans med !!!
705 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
706 // to read themselves
707 void MED_MED_RDONLY_DRIVER22::read( void )
708 throw (MEDEXCEPTION) // from objects method read !
711 const char* LOC = "MED_MED_DRIVER22::read() : ";
714 // For PAL12192: assure that file structure is already read
716 this->readFileStruct();
719 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
720 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
722 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
723 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
725 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ )
726 //(*currentMesh).second->read(*this); -> crash in MEDMEMTest_TopLevel.cxx
727 (*currentMesh).second->read(); // default reader, from readFileStruct
730 _ptrMed->updateSupport() ;
732 for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
733 //(*currentField).first->read(*this);
734 (*currentField).first->read(); // default reader, from readFileStruct
739 // ------------- Write Only Part --------------
741 MED_MED_WRONLY_DRIVER22::MED_MED_WRONLY_DRIVER22()
743 this->GENDRIVER::_accessMode = MED_EN::WRONLY;
746 MED_MED_WRONLY_DRIVER22::MED_MED_WRONLY_DRIVER22(const string & fileName, MED * const ptrMed):
747 IMED_MED_WRONLY_DRIVER(fileName,ptrMed),
748 MED_MED_DRIVER22(fileName,ptrMed),
749 MED_MED_DRIVER(fileName,ptrMed,MED_EN::WRONLY)
752 MED_MED_WRONLY_DRIVER22::MED_MED_WRONLY_DRIVER22(const MED_MED_WRONLY_DRIVER22 & driver):
753 IMED_MED_WRONLY_DRIVER(driver),
754 MED_MED_DRIVER(driver),
755 MED_MED_DRIVER22(driver)
758 MED_MED_WRONLY_DRIVER22::~MED_MED_WRONLY_DRIVER22()
760 MESSAGE_MED("MED_MED_WRONLY_DRIVER22::~MED_MED_WRONLY_DRIVER22() has been destroyed");
763 GENDRIVER * MED_MED_WRONLY_DRIVER22::copy(void) const
765 return new MED_MED_WRONLY_DRIVER22(*this) ;
768 void MED_MED_WRONLY_DRIVER22::read(void)
771 IMED_MED_WRONLY_DRIVER::read();
774 void MED_MED_WRONLY_DRIVER22::readFileStruct(void)
777 IMED_MED_WRONLY_DRIVER::readFileStruct();
780 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
781 // to write themselves
782 void MED_MED_WRONLY_DRIVER22::writeFrom( void) const
783 throw (MEDEXCEPTION) //from object method write !
786 const char* LOC = "MED_MED_DRIVER22::writeFrom() : ";
789 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
790 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
792 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
793 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
795 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
797 (*currentMesh).second->write(*this);
798 // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id
800 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) {
805 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
807 (*currentField).first->write(*this);
809 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) {
818 void MED_MED_WRONLY_DRIVER22::write(void ) const
819 throw (MEDEXCEPTION) // from object method write !
823 const char* LOC = "MED_MED_DRIVER22::write() : ";
826 // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
828 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
829 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
831 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
832 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
834 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
835 //current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName);
836 MESSAGE_MED((*currentMesh).second->getName());
837 current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName,(*currentMesh).second->getName());
838 // put right _id in Mesh driver (same as this._id)
839 (*currentMesh).second->_drivers[current]->setId( getId() );
840 (*currentMesh).second->write(current) ;
843 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
844 //current = (*currentField).first->addDriver(MED_DRIVER,_fileName);getName())
845 MESSAGE_MED((*currentField).first->getName());
846 FIELD_* myField = (*currentField).first;
847 current = (*currentField).first->addDriver(MED_DRIVER,_fileName,myField->getName());
848 // put right _id in Field driver (same as this._id)
849 (*currentField).first->_drivers[current]->setId( getId() );
850 (*currentField).first->write(current) ;
853 // that's work, but it is more efficenty to write directly when we had driver, no ?
860 // ------------- Read Write Part --------------
862 MED_MED_RDWR_DRIVER22::MED_MED_RDWR_DRIVER22()
864 this->GENDRIVER::_accessMode = MED_EN::RDWR;
867 MED_MED_RDWR_DRIVER22::MED_MED_RDWR_DRIVER22(const string & fileName, MED * const ptrMed):
868 MED_MED_RDONLY_DRIVER22(fileName,ptrMed),
869 MED_MED_WRONLY_DRIVER22(fileName,ptrMed),
870 IMED_MED_RDWR_DRIVER(fileName,ptrMed),
871 MED_MED_DRIVER22(fileName,ptrMed,RDWR),
872 IMED_MED_WRONLY_DRIVER(fileName,ptrMed),
873 IMED_MED_RDONLY_DRIVER(fileName,ptrMed),
874 MED_MED_DRIVER(fileName,ptrMed,RDWR)
877 MED_MED_RDWR_DRIVER22::MED_MED_RDWR_DRIVER22(const MED_MED_RDWR_DRIVER22 & driver):
878 MED_MED_RDONLY_DRIVER22(driver),
879 MED_MED_WRONLY_DRIVER22(driver),
880 IMED_MED_RDWR_DRIVER(driver),
881 MED_MED_DRIVER22(driver),
882 IMED_MED_WRONLY_DRIVER(driver),
883 IMED_MED_RDONLY_DRIVER(driver),
884 MED_MED_DRIVER(driver)
887 MED_MED_RDWR_DRIVER22::~MED_MED_RDWR_DRIVER22() {
888 MESSAGE_MED("MED_MED_RDWR_DRIVER22::~MED_MED_RDWR_DRIVER22() has been destroyed");
891 GENDRIVER * MED_MED_RDWR_DRIVER22::copy(void) const
893 return new MED_MED_RDWR_DRIVER22(*this) ;
896 void MED_MED_RDWR_DRIVER22::read(void)
897 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
899 const char* LOC = "MED_MED_RDWR_DRIVER22::read(void)";
901 MED_MED_RDONLY_DRIVER22::read();
905 void MED_MED_RDWR_DRIVER22::readFileStruct(void)
906 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
908 const char* LOC = "MED_MED_RDWR_DRIVER22::readFileStruct(void)";
910 MED_MED_RDONLY_DRIVER22::readFileStruct();
914 void MED_MED_RDWR_DRIVER22::write(void) const
915 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
917 const char* LOC = "MED_MED_RDWR_DRIVER22::write(void) const";
919 MED_MED_WRONLY_DRIVER22::write();
923 void MED_MED_RDWR_DRIVER22::writeFrom(void) const
924 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
926 const char* LOC = "MED_MED_RDWR_DRIVER22::writeFrom(void) const";
928 MED_MED_WRONLY_DRIVER22::writeFrom();