1 #ifndef MED_FIELD_DRIVER_HXX
2 #define MED_FIELD_DRIVER_HXX
6 #include "MEDMEM_define.hxx"
8 #include "MEDMEM_GenDriver.hxx"
11 #include "MEDMEM_STRING.hxx"
12 #include "MEDMEM_Exception.hxx"
13 #include "MEDMEM_Unit.hxx"
14 #include "MEDMEM_Array.hxx"
15 #include "MEDMEM_Support.hxx"
16 //#include "MEDMEM_Field.hxx"
17 #include "MEDMEM_Mesh.hxx"
20 template <class T> class FIELD;
22 // A QD LA CLASSE MED_ALL_ELEMENTS_DRIVER.... :) pour mutualiser le open ..... avec led _medIdt...
28 Generic part : implement open and close methods.
32 template <class T> class MED_FIELD_DRIVER : public GENDRIVER
37 med_2_1::med_idt _medIdt;
45 // all MED cell type ?? Classe de Définition ??
46 // static const medGeometryElement all_cell_type[MED_NBR_GEOMETRIE_MAILLE];
48 // static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE];
53 MED_FIELD_DRIVER():GENDRIVER(),
54 _ptrField((FIELD<T> *)MED_NULL),_medIdt(MED_INVALID),
55 _fieldName(""),_fieldNum(MED_INVALID) {}
59 MED_FIELD_DRIVER(const string & fileName, FIELD<T> * ptrField,
60 MED_EN::med_mode_acces accessMode)
61 : GENDRIVER(fileName,accessMode),
62 _ptrField((FIELD<T> *) ptrField),_medIdt(MED_INVALID),
63 _fieldName(fileName),_fieldNum(MED_INVALID)
70 MED_FIELD_DRIVER(const MED_FIELD_DRIVER & fieldDriver):
71 GENDRIVER(fieldDriver),
72 _ptrField(fieldDriver._ptrField),
74 _fieldName(fieldDriver._fieldName),
75 _fieldNum(fieldDriver._fieldNum)
82 virtual ~MED_FIELD_DRIVER() {
85 void open() throw (MEDEXCEPTION)
87 const char * LOC = "MED_FIELD_DRIVER::open() ";
90 // we must set fieldname before open, because we must find field number in file (if it exist !!!)
91 if ( _fileName == "" )
92 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
93 << "_fileName is |\"\"|, please set a correct fileName before calling open()"
97 MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
98 _medIdt = med_2_1::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_1::med_mode_acces) _accessMode);
99 MESSAGE(LOC<<"_medIdt : "<< _medIdt );
103 _status = MED_INVALID;
104 _medIdt = MED_INVALID;
105 throw MED_EXCEPTION (LOCALIZED( STRING(LOC)
106 << "Can't open |" << _fileName
107 << "|, _medIdt : " << _medIdt
116 BEGIN_OF("MED_FIELD_DRIVER::close()");
117 med_2_1::med_int err = 0;
118 if (_status == MED_OPENED) {
119 err=med_2_1::MEDfermer(_medIdt);
120 //H5close(); // If we call H5close() all the files are closed.
121 _status = MED_CLOSED;
122 _medIdt = MED_INVALID;
123 MESSAGE(" MED_FIELD_DRIVER::close() : MEDfermer : _medIdt= " << _medIdt );
124 MESSAGE(" MED_FIELD_DRIVER::close() : MEDfermer : err = " << err );
126 END_OF("MED_FIELD_DRIVER::close()");
129 virtual void write( void ) const = 0 ;
130 virtual void read ( void ) = 0 ;
133 Set the name of the FIELD asked in file.
135 It could be different than the name of the FIELD object.
137 void setFieldName(const string & fieldName) ;
139 Get the name of the FIELD asked in file.
141 string getFieldName() const ;
144 virtual GENDRIVER * copy ( void ) const = 0 ;
150 Driver Med for FIELD : Read only.
152 Implement read method.
156 template <class T> class MED_FIELD_RDONLY_DRIVER : public virtual MED_FIELD_DRIVER<T>
164 MED_FIELD_RDONLY_DRIVER():MED_FIELD_DRIVER<T>() {};
169 MED_FIELD_RDONLY_DRIVER(const string & fileName, FIELD<T> * ptrField):
170 MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_RDONLY) {
171 BEGIN_OF("MED_FIELD_RDONLY_DRIVER::MED_FIELD_RDONLY_DRIVER(const string & fileName, const FIELD<T> * ptrField)");
172 END_OF("MED_FIELD_RDONLY_DRIVER::MED_FIELD_RDONLY_DRIVER(const string & fileName, const FIELD<T> * ptrField)");
178 MED_FIELD_RDONLY_DRIVER(const MED_FIELD_RDONLY_DRIVER & fieldDriver):
179 MED_FIELD_DRIVER<T>(fieldDriver) {};
184 virtual ~MED_FIELD_RDONLY_DRIVER() {};
186 // CREER UNE METHODE POUR LIRE LA LISTE DES MAILLAGES .....
189 Return a MEDEXCEPTION : it is the read-only driver.
191 void write( void ) const throw (MEDEXCEPTION) ;
193 Read FIELD in the specified file.
195 void read ( void ) throw (MEDEXCEPTION) ;
198 GENDRIVER * copy( void ) const ;
204 Driver Med for FIELD : Write only.
206 Implement write method.
210 template <class T> class MED_FIELD_WRONLY_DRIVER : public virtual MED_FIELD_DRIVER<T> {
217 MED_FIELD_WRONLY_DRIVER():MED_FIELD_DRIVER<T>() {}
222 MED_FIELD_WRONLY_DRIVER(const string & fileName, FIELD<T> * ptrField):
223 MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_WRONLY)
225 BEGIN_OF("MED_FIELD_WRONLY_DRIVER::MED_FIELD_WRONLY_DRIVER(const string & fileName, const FIELD<T> * ptrField)");
226 END_OF("MED_FIELD_WRONLY_DRIVER::MED_FIELD_WRONLY_DRIVER(const string & fileName, const FIELD<T> * ptrField)");
232 MED_FIELD_WRONLY_DRIVER(const MED_FIELD_WRONLY_DRIVER & fieldDriver):
233 MED_FIELD_DRIVER<T>(fieldDriver) {};
238 virtual ~MED_FIELD_WRONLY_DRIVER() {};
241 Write FIELD in the specified file.
243 void write( void ) const throw (MEDEXCEPTION) ;
245 Return a MEDEXCEPTION : it is the write-only driver.
247 void read ( void ) throw (MEDEXCEPTION) ;
250 GENDRIVER * copy( void ) const ;
257 Driver Med for FIELD : Read write.
258 - Use read method from MED_FIELD_RDONLY_DRIVER
259 - Use write method from MED_FIELD_WDONLY_DRIVER
263 template <class T> class MED_FIELD_RDWR_DRIVER : public MED_FIELD_RDONLY_DRIVER<T>, public MED_FIELD_WRONLY_DRIVER<T> {
270 MED_FIELD_RDWR_DRIVER():MED_FIELD_DRIVER<T>() {}
275 MED_FIELD_RDWR_DRIVER(const string & fileName, FIELD<T> * ptrField):
276 MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_RDWR)
278 BEGIN_OF("MED_FIELD_RDWR_DRIVER::MED_FIELD_RDWR_DRIVER(const string & fileName, const FIELD<T> * ptrField)");
279 //_accessMode = MED_RDWR ;
280 END_OF("MED_FIELD_RDWR_DRIVER::MED_FIELD_RDWR_DRIVER(const string & fileName, const FIELD<T> * ptrField)");
286 MED_FIELD_RDWR_DRIVER(const MED_FIELD_RDWR_DRIVER & fieldDriver):
287 MED_FIELD_DRIVER<T>(fieldDriver) {};
292 ~MED_FIELD_RDWR_DRIVER() {};
295 Write FIELD in the specified file.
297 void write(void) const throw (MEDEXCEPTION) ;
299 Read FIELD in the specified file.
301 void read (void) throw (MEDEXCEPTION) ;
304 GENDRIVER * copy( void ) const ;
309 /*-------------------------*/
310 /* template implementation */
311 /*-------------------------*/
312 /*--------------------- DRIVER PART -------------------------------*/
314 template <class T> void MED_FIELD_DRIVER<T>::setFieldName(const string & fieldName)
316 _fieldName = fieldName;
319 template <class T> string MED_FIELD_DRIVER<T>::getFieldName() const
324 // template <class T> void MED_FIELD_DRIVER<T>::search_field() {
325 // const char * LOC = "template <class T> class MED_FIELD_DRIVER::search_field() :";
327 // // we search the field number !!!!
328 // if (_status==MED_OPENED)
329 // if (_fieldNum==MED_INVALID) {
331 // int numberOfFields = 0; //MED_INVALID
332 // // char fieldName[MED_TAILLE_NOM+1] = "";
333 // char fieldName[MED_TAILLE_NOM+1] ;
334 // int numberOfComponents = 0;
335 // char * componentName = (char *) MED_NULL;
336 // char * unitName = (char *) MED_NULL;
337 // med_2_1::med_type_champ type ;
338 // numberOfFields = med_2_1::MEDnChamp(_medIdt,0) ;
339 // if ( numberOfFields <= 0 )
340 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": No Field found !"));
341 // for (int i=1;i<=numberOfFields;i++) {
343 // numberOfComponents = med_2_1::MEDnChamp(_medIdt,i) ;
344 // if ( numberOfComponents <= 0 )
345 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
346 // << "Be careful there is no compound for field n°"
347 // << i << "in file |"<<_fileName<<"| !"));
349 // componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
350 // unitName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
352 // err = med_2_1::MEDchampInfo(_medIdt, i, fieldName, &type, componentName,
353 // unitName, numberOfComponents) ;
355 // delete[] componentName ;
356 // delete[] unitName ;
357 // MESSAGE("Champ "<<i<<" : #" << fieldName <<"# et recherche #"<<_fieldName.c_str()<<"#");
358 // if ( !strcmp(fieldName,_fieldName.c_str()) ) {
359 // MESSAGE("FOUND FIELD "<< fieldName <<" : "<<i);
367 /*--------------------- RDONLY PART -------------------------------*/
369 template <class T> GENDRIVER * MED_FIELD_RDONLY_DRIVER<T>::copy(void) const
371 MED_FIELD_RDONLY_DRIVER<T> * myDriver =
372 new MED_FIELD_RDONLY_DRIVER<T>(*this);
376 template <class T> void MED_FIELD_RDONLY_DRIVER<T>::read(void)
379 const char * LOC = " MED_FIELD_RDONLY_DRIVER::read() " ;
382 if (MED_FIELD_DRIVER<T>::_ptrField->_name=="")
383 MED_FIELD_DRIVER<T>::_ptrField->_name = MED_FIELD_DRIVER<T>::_fieldName ;
385 MED_FIELD_DRIVER<T>::_fieldName = MED_FIELD_DRIVER<T>::_ptrField->_name; // bug indetermine ! apres avoir fait readfilestruct, lorsque je recupere le champ, tout est bon sauf le nom du champ dans le driver !!!!!
387 MESSAGE("###### "<<LOC<<" fieldNameDRIVER : "<<MED_FIELD_DRIVER<T>::_fieldName<<" fieldName : "<<MED_FIELD_DRIVER<T>::_ptrField->_name);
389 string MeshName = MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getMesh()->getName() ;
391 if (MED_FIELD_DRIVER<T>::_status==MED_OPENED)
397 fieldName = new char[MED_TAILLE_NOM+1] ;
399 int numberOfComponents = 0;
400 char * componentName = (char *) MED_NULL;
401 char * unitName = (char *) MED_NULL;
402 med_2_1::med_type_champ type ;
404 // we search the field number !!!!
405 if (MED_FIELD_DRIVER<T>::_fieldNum==MED_INVALID) {
406 int numberOfFields = 0; //MED_INVALID
407 numberOfFields = med_2_1::MEDnChamp(MED_FIELD_DRIVER<T>::_medIdt,0) ;
408 if ( numberOfFields <= 0 )
409 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": No Field found !"));
410 for (int i=1;i<=numberOfFields;i++) {
412 numberOfComponents = med_2_1::MEDnChamp(MED_FIELD_DRIVER<T>::_medIdt,i) ;
413 if ( numberOfComponents <= 0 )
414 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
415 // << "Be careful there is no compound for field n°"
416 // << i << "in file |"<<_fileName<<"| !"));
417 MESSAGE(LOC<<"Be careful there is no compound for field n°"<<i<<"in file |"<<_fileName<<"| !");
419 componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
420 unitName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
422 err = med_2_1::MEDchampInfo(MED_FIELD_DRIVER<T>::_medIdt, i, fieldName, &type, componentName,
423 unitName, numberOfComponents) ;
425 MESSAGE("Champ "<<i<<" : #" << fieldName <<"# et recherche #"<<MED_FIELD_DRIVER<T>::_fieldName.c_str()<<"#");
426 if ( !strcmp(fieldName,MED_FIELD_DRIVER<T>::_fieldName.c_str()) ) {
427 MESSAGE("FOUND FIELD "<< fieldName <<" : "<<i);
428 MED_FIELD_DRIVER<T>::_fieldNum = i ;
431 // not found : release memory and search next field !
432 delete[] componentName ;
439 if (MED_FIELD_DRIVER<T>::_fieldNum==MED_INVALID)
440 throw MEDEXCEPTION(LOCALIZED( STRING(LOC) << ": Field "<<MED_FIELD_DRIVER<T>::_fieldName << " not found in file " << MED_FIELD_DRIVER<T>::_fileName ) );
441 MESSAGE ("FieldNum : "<<MED_FIELD_DRIVER<T>::_fieldNum);
444 // int NumberOfComponents = med_2_1::MEDnChamp(MED_FIELD_DRIVER<T>::_medIdt,MED_FIELD_DRIVER<T>::_fieldNum) ;
445 if (numberOfComponents < 1)
446 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no component")) ; // use iostring !
447 // test type to check if it is rigth !!!???
448 MED_FIELD_DRIVER<T>::_ptrField->_numberOfComponents = numberOfComponents ;
449 MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes = new int[numberOfComponents] ;
450 MED_FIELD_DRIVER<T>::_ptrField->_componentsNames = new string[numberOfComponents] ;
451 MED_FIELD_DRIVER<T>::_ptrField->_componentsUnits = new UNIT[numberOfComponents] ;
452 MED_FIELD_DRIVER<T>::_ptrField->_componentsDescriptions = new string[numberOfComponents] ;
453 MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits = new string[numberOfComponents] ;
454 for (int i=0; i<numberOfComponents; i++) {
455 MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes[i] = 1 ;
457 // PG : what about space !!!
458 MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i] = string(componentName,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
459 SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i]);
460 MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i] = string(unitName,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
461 SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i]);
463 delete[] componentName;
466 // read values for each geometric type in _support
467 int NumberOfTypes = MED_FIELD_DRIVER<T>::_ptrField->_support->getNumberOfTypes() ;
468 const MED_EN::medGeometryElement *Types = MED_FIELD_DRIVER<T>::_ptrField->_support->getTypes() ;
469 T ** myValues = new T*[NumberOfTypes] ;
470 int * NumberOfValues = new int[NumberOfTypes] ;
471 int TotalNumberOfValues = 0 ;
472 MESSAGE ("NumberOfTypes :"<< NumberOfTypes);
473 _ptrField->_numberOfValues=0 ;
474 for (int i=0; i<NumberOfTypes; i++) {
475 MESSAGE ("Type["<<i+1<<"] :"<< Types[i]);
476 MESSAGE ("Entity :"<<MED_FIELD_DRIVER<T>::_ptrField->_support->getEntity());
478 MEDnVal(MED_FIELD_DRIVER<T>::_medIdt,
479 const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()),
480 (med_2_1::med_entite_maillage)MED_FIELD_DRIVER<T>::_ptrField->_support->getEntity(),
481 (med_2_1::med_geometrie_element)Types[i],
482 MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber,
483 MED_FIELD_DRIVER<T>::_ptrField->_orderNumber) ; // no time step ! prend en compte le nbre de pt de gauss
484 // test if NumberOfValues is the same in _support !!! TODO that !!
486 // we could allocate array
487 myValues[i] = new T[ NumberOfValues[i]*numberOfComponents ] ;
488 TotalNumberOfValues+=NumberOfValues[i] ;// diviser par le nombre de point de gauss
489 char * ProfilName = new char[MED_TAILLE_NOM+1];
490 MESSAGE ("NumberOfValues :"<< NumberOfValues[i]);
491 MESSAGE ("NumberOfComponents :"<< numberOfComponents);
492 MESSAGE ("MESH_NAME :"<< MeshName.c_str());
493 MESSAGE ("FIELD_NAME :"<< MED_FIELD_DRIVER<T>::_fieldName.c_str());
494 MESSAGE ("MED_ENTITE :"<< (med_2_1::med_entite_maillage) MED_FIELD_DRIVER<T>::_ptrField->_support->getEntity());
495 MESSAGE("MED_GEOM :"<<(med_2_1::med_geometrie_element)Types[i]);
496 MESSAGE("Iteration :"<<MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber());
497 MESSAGE("Order :"<<MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber());
498 MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues+=NumberOfValues[i]; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!!
499 med_2_1::med_err ret;
500 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
501 int lgth2=NumberOfValues[i]*numberOfComponents;
502 if(_ptrField->getValueType()==MED_EN::MED_INT32)
504 med_2_1::med_int *temp=new med_2_1::med_int[lgth2];
505 ret=med_2_1::MEDchampLire(MED_FIELD_DRIVER<T>::_medIdt,const_cast <char*> (MeshName.c_str()),
506 const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()),
507 (unsigned char*) temp,
508 med_2_1::MED_NO_INTERLACE,
511 (med_2_1::med_entite_maillage) MED_FIELD_DRIVER<T>::_ptrField->_support->getEntity(),(med_2_1::med_geometrie_element)Types[i],
512 MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(),
513 MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber()
515 for(int i2=0;i2<lgth2;i2++)
516 myValues[i][i2]=(int)(temp[i2]);
521 ret=med_2_1::MEDchampLire(MED_FIELD_DRIVER<T>::_medIdt,const_cast <char*> (MeshName.c_str()),
522 const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()),
523 (unsigned char*) myValues[i],
524 med_2_1::MED_NO_INTERLACE,
527 (med_2_1::med_entite_maillage) MED_FIELD_DRIVER<T>::_ptrField->_support->getEntity(),(med_2_1::med_geometrie_element)Types[i],
528 MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(),
529 MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber()
532 // we must do some delete !!!
533 for(int j=0; j<=i;j++)
534 delete[] myValues[j];
536 delete[] NumberOfValues ;
538 delete[] MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes ;
539 delete[] MED_FIELD_DRIVER<T>::_ptrField->_componentsNames ;
540 delete[] MED_FIELD_DRIVER<T>::_ptrField->_componentsUnits ;
541 delete[] MED_FIELD_DRIVER<T>::_ptrField->_componentsDescriptions ;
542 delete[] MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits ;
543 MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes = NULL ;
544 MED_FIELD_DRIVER<T>::_ptrField->_componentsNames = NULL ;
545 MED_FIELD_DRIVER<T>::_ptrField->_componentsUnits = NULL ;
546 MED_FIELD_DRIVER<T>::_ptrField->_componentsDescriptions = NULL ;
547 MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits = NULL ;
548 MED_FIELD_DRIVER<T>::_fieldNum = MED_INVALID ; // we have not found right field, so reset the field number
549 throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": ERROR when read value")) ;
552 delete[] ProfilName ;
555 // probleme avec les points de gauss : voir lorsqu-il y en a (!= 1)
556 // MEDARRAY<T> * Values = new MEDARRAY<T>(MED_FIELD_DRIVER<T>::_ptrField->getNumberOfComponents(),TotalNumberOfValues/MED_FIELD_DRIVER<T>::_ptrField->getNumberOfComponents(),MED_EN::MED_NO_INTERLACE);
558 if (MED_FIELD_DRIVER<T>::_ptrField->_value==NULL)
559 MED_FIELD_DRIVER<T>::_ptrField->_value=new MEDARRAY<T>(numberOfComponents,TotalNumberOfValues,MED_EN::MED_NO_INTERLACE);
561 MEDARRAY<T> * Values = MED_FIELD_DRIVER<T>::_ptrField->_value ; // create by constructor ???
562 // check if dimensions are right : inutile : c'est dans le constructeur !!!
563 //if (Values->getLeadingValue() != numberOfComponents)
564 // throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": leading dimension are false : "<<Values->getLeadingValue()<<" and "<<numberOfComponents) ) ;
565 //if (Values->getLengthValue() != TotalNumberOfValues)
566 // throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": length dimension are false : "<<Values->getLengthValue()<<" and "<<TotalNumberOfValues) ) ;
568 for (int i=0; i<numberOfComponents; i++) {
569 //T * ValuesT = Values->getRow(i+1) ;
571 for (int j=0; j<NumberOfTypes; j++) {
572 T * myValue = myValues[j] ;
573 int NumberOf = NumberOfValues[j] ;
574 // MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues+=NumberOf; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!!
575 int offset = NumberOf*i ;
576 for (int k=0 ; k<NumberOf; k++) {
577 //ValuesT[Count]=myValue[k+offset] ;
578 Values->setIJ(Count,i+1,myValue[k+offset]);
580 SCRUTE(Values->getIJ(Count,i+1));
586 for (int j=0; j<NumberOfTypes; j++)
587 delete[] myValues[j] ;
589 delete[] NumberOfValues ;
591 MED_FIELD_DRIVER<T>::_ptrField->_isRead = true ;
597 template <class T> void MED_FIELD_RDONLY_DRIVER<T>::write( void ) const
600 throw MEDEXCEPTION("MED_FIELD_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
603 /*--------------------- WRONLY PART -------------------------------*/
605 template <class T> GENDRIVER * MED_FIELD_WRONLY_DRIVER<T>::copy(void) const
607 MED_FIELD_WRONLY_DRIVER<T> * myDriver =
608 new MED_FIELD_WRONLY_DRIVER<T>(*this);
612 template <class T> void MED_FIELD_WRONLY_DRIVER<T>::read (void)
615 throw MEDEXCEPTION("MED_FIELD_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
618 template <class T> void MED_FIELD_WRONLY_DRIVER<T>::write(void) const
621 const char * LOC = "MED_FIELD_WRONLY_DRIVER::write(void) const " ;
623 if (MED_FIELD_DRIVER<T>::_status==MED_OPENED)
627 int component_count=MED_FIELD_DRIVER<T>::_ptrField->getNumberOfComponents();
628 string component_name(component_count*MED_TAILLE_PNOM,' ') ;
629 string component_unit(component_count*MED_TAILLE_PNOM,' ') ;
631 const string * listcomponent_name=MED_FIELD_DRIVER<T>::_ptrField->getComponentsNames() ;
632 const string * listcomponent_unit=MED_FIELD_DRIVER<T>::_ptrField->getMEDComponentsUnits() ;
634 for (int i=0; i < component_count ; i++) {
635 length = min(MED_TAILLE_PNOM,(int)listcomponent_name[i].size());
636 component_name.replace(i*MED_TAILLE_PNOM,length,
637 listcomponent_name[i],0,length);
638 length = min(MED_TAILLE_PNOM,(int)listcomponent_unit[i].size());
639 component_unit.replace(i*MED_TAILLE_PNOM,length,
640 listcomponent_unit[i],0,length);
643 MESSAGE("component_name=|"<<component_name<<"|");
644 MESSAGE("component_unit=|"<<component_unit<<"|");
646 MED_EN::med_type_champ ValueType=MED_FIELD_DRIVER<T>::_ptrField->getValueType() ;
648 MESSAGE("Template Type =|"<<ValueType<<"|");
650 // le champ existe deja ???
651 char * champName = new char[MED_TAILLE_NOM+1] ;
652 med_2_1::med_type_champ type ;
656 int n = med_2_1::MEDnChamp(MED_FIELD_DRIVER<T>::_medIdt,0);
658 for (int i=1; i<=n; i++) {
659 nbComp = med_2_1::MEDnChamp(MED_FIELD_DRIVER<T>::_medIdt,i);
660 compName = new char[MED_TAILLE_PNOM*nbComp+1];
661 compUnit = new char[MED_TAILLE_PNOM*nbComp+1];
662 err = med_2_1::MEDchampInfo(MED_FIELD_DRIVER<T>::_medIdt,i,champName,&type,compName,compUnit,nbComp);
664 if (strcmp(champName,MED_FIELD_DRIVER<T>::_ptrField->getName().c_str())==0) { // Found !
674 if (nbComp != component_count)
675 throw MEDEXCEPTION( LOCALIZED (STRING(LOC)
676 <<": Field exist in file, but number of component are different : "<<nbComp<<" in file and "<<component_count<<" in memory."
679 // component name and unit
680 MESSAGE(LOC<<" Component name in file : "<<compName);
681 MESSAGE(LOC<<" Component name in memory : "<<component_name);
682 MESSAGE(LOC<<" Component unit in file : "<<compUnit);
683 MESSAGE(LOC<<" Component unit in memory : "<<component_unit);
688 // Verify the field doesn't exist
690 string dataGroupName = "/CHA/";
691 dataGroupName += MED_FIELD_DRIVER<T>::_ptrField->getName();
692 MESSAGE(LOC << "|" << dataGroupName << "|" );
693 MED_EN::med_idt gid = H5Gopen(MED_FIELD_DRIVER<T>::_medIdt, dataGroupName.c_str() );
697 err=med_2_1::MEDchampCr(MED_FIELD_DRIVER<T>::_medIdt,
698 const_cast <char*> ((MED_FIELD_DRIVER<T>::_ptrField->getName()).c_str()),
699 (med_2_1::med_type_champ) ValueType,
700 const_cast <char*> ( component_name.c_str() ),
701 const_cast <char*> ( component_unit.c_str() ),
704 throw MEDEXCEPTION( LOCALIZED (STRING(LOC)
705 << ": Error MEDchampCr : "<<err
712 const SUPPORT * mySupport = MED_FIELD_DRIVER<T>::_ptrField->getSupport() ;
714 if (! mySupport->isOnAllElements())
715 throw MEDEXCEPTION( LOCALIZED (STRING(LOC)
716 <<": Field must be on all entity"
720 MESH * myMesh = mySupport->getMesh() ;
721 string MeshName = myMesh->getName() ;
722 //MED_EN::medModeSwitch Mode = MED_FIELD_DRIVER<T>::_ptrField->_value->getMode() ;
723 // on boucle sur tout les types pour ecrire les tableaux de valeur
724 int NumberOfType = mySupport->getNumberOfTypes() ;
726 const MED_EN::medGeometryElement * Types = mySupport->getTypes() ;
727 const int * NumberOfGaussPoint = mySupport->getNumberOfGaussPoint() ;
728 for (int i=0;i<NumberOfType;i++) {
729 int NumberOfElements = mySupport->getNumberOfElements(Types[i]) ;
731 const T * value = MED_FIELD_DRIVER<T>::_ptrField->getValueI(MED_EN::MED_FULL_INTERLACE,Index) ;
733 MESSAGE("MED_FIELD_DRIVER<T>::_medIdt : "<<MED_FIELD_DRIVER<T>::_medIdt);
734 MESSAGE("MeshName.c_str() : "<<MeshName.c_str());
735 MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getName() : "<<MED_FIELD_DRIVER<T>::_ptrField->getName());
736 MESSAGE("value : "<<value);
737 MESSAGE("NumberOfElements : "<<NumberOfElements);
738 MESSAGE("NumberOfGaussPoint[i] : "<<NumberOfGaussPoint[i]);
739 MESSAGE("mySupport->getEntity() : "<<mySupport->getEntity());
740 MESSAGE("Types[i] : "<<Types[i]);
741 MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber() : "<<MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber());
742 MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getTime() : "<<MED_FIELD_DRIVER<T>::_ptrField->getTime());
743 MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber() : "<<MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber());
745 /* char chanom[MED_TAILLE_NOM+1];
746 char chacomp[MED_TAILLE_NOM+1];
747 char chaunit[MED_TAILLE_NOM+1];
748 med_2_1::med_type_champ chatype;
751 err=med_2_1::MEDchampInfo(MED_FIELD_DRIVER<T>::_medIdt,1,chanom,&chatype,chacomp,chaunit,chancomp);
755 cout<<"=======================================================================> gros probleme"<<endl;
758 cout<<"==================> nom lu = "<<chanom<<endl;
759 cout<<"==================> type lu = "<<chatype<<endl;
760 cout<<"==================> nom composante lu = "<<chacomp<<endl;
761 cout<<"==================> nom unit lu = "<<chaunit<<endl;
762 cout<<"==================> valeur de med_2_1::MED_REEL64 = "<<med_2_1::MED_REEL64<<endl;
764 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
765 if(_ptrField->getValueType()==MED_EN::MED_INT32)
767 int lgth2=_ptrField->getNumberOfValues();
768 med_2_1::med_int *temp=new med_2_1::med_int[lgth2];
769 for(int i2=0;i2<lgth2;i2++)
770 temp[i2]=(int)(value[i2]);
771 err=med_2_1::MEDchampEcr(MED_FIELD_DRIVER<T>::_medIdt,
772 const_cast <char*> ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str())
773 const_cast <char*> ( (MED_FIELD_DRIVER<T>::_ptrField->getName()).c_str()),
774 (unsigned char*)temp,
775 med_2_1::MED_FULL_INTERLACE,
777 NumberOfGaussPoint[i],
780 med_2_1::MED_REMP, // PROFIL NON GERE, mode de remplacement non géré
781 (med_2_1::med_entite_maillage)mySupport->getEntity(),
782 (med_2_1::med_geometrie_element)Types[i],
783 MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(),
785 MED_FIELD_DRIVER<T>::_ptrField->getTime(),
786 MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber()
792 err=med_2_1::MEDchampEcr(MED_FIELD_DRIVER<T>::_medIdt,
793 const_cast <char*> ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str())
794 const_cast <char*> ( (MED_FIELD_DRIVER<T>::_ptrField->getName()).c_str()),
795 (unsigned char*)value,
796 med_2_1::MED_FULL_INTERLACE,
798 NumberOfGaussPoint[i],
801 med_2_1::MED_REMP, // PROFIL NON GERE, mode de remplacement non géré
802 (med_2_1::med_entite_maillage)mySupport->getEntity(),
803 (med_2_1::med_geometrie_element)Types[i],
804 MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(),
806 MED_FIELD_DRIVER<T>::_ptrField->getTime(),
807 MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber()
809 if (err < MED_VALID )
810 throw MEDEXCEPTION(LOCALIZED( STRING(LOC)
811 <<": Error in writing Field "<< MED_FIELD_DRIVER<T>::_ptrField->getName() <<", type "<<Types[i]
815 Index += NumberOfElements ;
823 /*--------------------- RDWR PART -------------------------------*/
825 template <class T> GENDRIVER * MED_FIELD_RDWR_DRIVER<T>::copy(void) const
827 MED_FIELD_RDWR_DRIVER<T> * myDriver =
828 new MED_FIELD_RDWR_DRIVER<T>(*this);
832 template <class T> void MED_FIELD_RDWR_DRIVER<T>::write(void) const
835 BEGIN_OF("MED_FIELD_RDWR_DRIVER::write(void)");
836 MED_FIELD_WRONLY_DRIVER<T>::write();
837 END_OF("MED_FIELD_RDWR_DRIVER::write(void)");
840 template <class T> void MED_FIELD_RDWR_DRIVER<T>::read (void)
843 BEGIN_OF("MED_FIELD_RDWR_DRIVER::read(void)");
844 MED_FIELD_RDONLY_DRIVER<T>::read();
845 END_OF("MED_FIELD_RDWR_DRIVER::read(void)");
847 }//End namespace MEDMEM
848 /*-----------------------------------------------------------------*/
850 #endif /* MED_FIELD_DRIVER_HXX */