src/MEDMEM/MEDMEM_MedFieldDriver22.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00002 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00003 // 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either 
00007 // version 2.1 of the License.
00008 // 
00009 // This library is distributed in the hope that it will be useful 
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public  
00015 // License along with this library; if not, write to the Free Software 
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 //
00018 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 //
00020 #ifndef MED_FIELD_DRIVER22_HXX
00021 #define MED_FIELD_DRIVER22_HXX
00022 
00023 #include <string>
00024 #include <algorithm>
00025 
00026 #include "MEDMEM_FieldConvert.hxx"
00027 #include "MEDMEM_ArrayInterface.hxx"
00028 #include "MEDMEM_ArrayConvert.hxx"
00029 
00030 #include "MEDMEM_define.hxx"
00031 #include "MEDMEM_Utilities.hxx"
00032 #include "MEDMEM_STRING.hxx"
00033 #include "MEDMEM_Exception.hxx"
00034 
00035 #include "MEDMEM_DriversDef.hxx"
00036 #include "MEDMEM_MedFieldDriver.hxx"
00037 #include "MEDMEM_Unit.hxx"
00038 #include "MEDMEM_Support.hxx"
00039 #include "MEDMEM_GaussLocalization.hxx"
00040 
00041 //includes temporaires (attente release med fichier 2.3.1)
00042 #include "MEDMEM_MEDMEMgaussEcr.hxx"
00043 #include "MEDMEM_MEDMEMprofilEcr.hxx"
00044 #include "MEDMEM_MEDMEMchampLire.hxx"
00045 
00046 namespace MEDMEM {
00047 
00056 template <class T> class MED_FIELD_DRIVER22 : public virtual MED_FIELD_DRIVER<T>
00057 {
00058 protected:
00059 
00060   med_2_2::med_idt        _medIdt;
00061 
00062   bool createFieldSupportPart1(med_2_2::med_idt id,
00063                  const string & fieldName,
00064                  med_2_2::med_int ndt,
00065                  med_2_2::med_int od,
00066                  SUPPORT & support,
00067                  string & meshName,
00068                  vector<int> & numberOfElementsOfTypeC,
00069                  vector<int> & numberOfGaussPoint,
00070                  int & totalNumberOfElWg
00071                  ) const throw (MEDEXCEPTION);
00072 
00073   void getMeshGeometricTypeFromFile(med_2_2::med_idt id,
00074                    string & meshName,
00075                    MED_EN::medEntityMesh  entite,
00076                    vector<MED_EN::medGeometryElement> & geoType,
00077                    vector<int> &nbOfElOfType,
00078                    vector<int> &nbOfElOfTypeC) const throw(MEDEXCEPTION);
00079 
00080   void getMeshGeometricTypeFromMESH( MESH * meshPtr,
00081                          MED_EN::medEntityMesh  entity,
00082                          vector<MED_EN::medGeometryElement> & geoType,
00083                          vector<int> &nbOfElOfType,
00084                          vector<int> &nbOfElOfTypeC) const throw(MEDEXCEPTION);
00085 
00086 public :
00087 
00091   MED_FIELD_DRIVER22():MED_FIELD_DRIVER<T>(),_medIdt(MED_INVALID)
00092   {}
00096   template <class INTERLACING_TAG>
00097   MED_FIELD_DRIVER22(const string & fileName,
00098                FIELD<T, INTERLACING_TAG> * ptrField,
00099                MED_EN::med_mode_acces accessMode)
00100     : MED_FIELD_DRIVER<T>(fileName,ptrField,accessMode),_medIdt(MED_INVALID)
00101   {
00102   }
00103 
00107   MED_FIELD_DRIVER22(const MED_FIELD_DRIVER22 & fieldDriver):
00108     MED_FIELD_DRIVER<T>(fieldDriver),
00109     _medIdt(fieldDriver._medIdt)
00110   {
00111   }
00112 
00116   virtual ~MED_FIELD_DRIVER22() {
00117   }
00118 
00119   void open() throw (MEDEXCEPTION)
00120   {
00121     const char * LOC = "MED_FIELD_DRIVER22::open() ";
00122     BEGIN_OF(LOC);
00123 
00124     // we must set fieldname before open, because we must find field number in file (if it exist !!!)
00125     if ( MED_FIELD_DRIVER<T>::_fileName == "" )
00126       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
00127                            << "_fileName is |\"\"|, please set a correct fileName before calling open()"
00128                            )
00129                    );
00130 
00131     MESSAGE(LOC<<"_fileName.c_str : "<< MED_FIELD_DRIVER<T>::_fileName.c_str()<<",mode : "<< MED_FIELD_DRIVER<T>::_accessMode);
00132     MED_FIELD_DRIVER22<T>::_medIdt = med_2_2::MEDouvrir( (const_cast <char *> (MED_FIELD_DRIVER<T>::_fileName.c_str())),(med_2_2::med_mode_acces) MED_FIELD_DRIVER<T>::_accessMode);
00133     MESSAGE(LOC<<"_medIdt : "<< MED_FIELD_DRIVER22<T>::_medIdt );
00134     if (MED_FIELD_DRIVER22<T>::_medIdt > 0)
00135       MED_FIELD_DRIVER<T>::_status=MED_OPENED;
00136     else {
00137       MED_FIELD_DRIVER<T>::_status = MED_INVALID;
00138       MED_FIELD_DRIVER22<T>::_medIdt = MED_INVALID;
00139       throw MED_EXCEPTION (LOCALIZED( STRING(LOC)
00140                           << "Can't open |"  << MED_FIELD_DRIVER<T>::_fileName
00141                           << "|, _medIdt : " << MED_FIELD_DRIVER22<T>::_medIdt
00142                           )
00143                   );
00144     }
00145 
00146     END_OF(LOC);
00147   }
00148 
00149   void close() {
00150     BEGIN_OF("MED_FIELD_DRIVER22::close()");
00151     med_2_2::med_int err = 0;
00152     if (MED_FIELD_DRIVER<T>::_status == MED_OPENED) {
00153       err=med_2_2::MEDfermer(MED_FIELD_DRIVER22<T>::_medIdt);
00154       //H5close(); // If we call H5close() all the files are closed.
00155       MED_FIELD_DRIVER<T>::_status = MED_CLOSED;
00156       MED_FIELD_DRIVER22<T>::_medIdt = MED_INVALID;
00157       MESSAGE(" MED_FIELD_DRIVER22::close() : MEDfermer : _medIdt= " << MED_FIELD_DRIVER22<T>::_medIdt );
00158       MESSAGE(" MED_FIELD_DRIVER22::close() : MEDfermer : err    = " << err );
00159     }
00160     END_OF("MED_FIELD_DRIVER22::close()");
00161   }
00162 };
00163 
00172   template <class T> class MED_FIELD_RDONLY_DRIVER22 : public virtual MED_FIELD_DRIVER22<T>, public virtual IMED_FIELD_RDONLY_DRIVER<T>
00173 {
00174 
00175 public :
00176 
00180   MED_FIELD_RDONLY_DRIVER22():MED_FIELD_DRIVER<T>() {};
00181 
00185   template <class INTERLACING_TAG>
00186   MED_FIELD_RDONLY_DRIVER22(const string & fileName,
00187                    FIELD<T, INTERLACING_TAG> * ptrField):
00188     IMED_FIELD_RDONLY_DRIVER<T>(fileName,ptrField),
00189     MED_FIELD_DRIVER22<T>(fileName,ptrField,MED_EN::MED_RDONLY),
00190     MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_RDONLY)
00191   {
00192     BEGIN_OF("MED_FIELD_RDONLY_DRIVER22::MED_FIELD_RDONLY_DRIVER22(const string & fileName, const FIELD<T,INTERLACING_TAG> * ptrField)");
00193     END_OF("MED_FIELD_RDONLY_DRIVER22::MED_FIELD_RDONLY_DRIVER22(const string & fileName, const FIELD<T,INTERLACING_TAG> * ptrField)");
00194   }
00195 
00199   MED_FIELD_RDONLY_DRIVER22(const MED_FIELD_RDONLY_DRIVER22 & fieldDriver):
00200     IMED_FIELD_RDONLY_DRIVER<T>(fieldDriver),
00201     MED_FIELD_DRIVER22<T>(fieldDriver),
00202     MED_FIELD_DRIVER<T>(fieldDriver)
00203   {}
00204 
00208   virtual ~MED_FIELD_RDONLY_DRIVER22() {};
00209 
00210   // CREER UNE METHODE POUR LIRE LA LISTE DES MAILLAGES .....
00211 
00215   void write( void ) const throw (MEDEXCEPTION) ;
00219   void read ( void ) throw (MEDEXCEPTION) ;
00220 
00221 private:
00222   GENDRIVER * copy( void ) const ;
00223 
00224 };
00225 
00234 template <class T> class MED_FIELD_WRONLY_DRIVER22 : public virtual MED_FIELD_DRIVER22<T>, public virtual IMED_FIELD_WRONLY_DRIVER<T> {
00235 
00236 public :
00237 
00241   MED_FIELD_WRONLY_DRIVER22():MED_FIELD_DRIVER<T>() {}
00242 
00246   template <class INTERLACING_TAG>
00247   MED_FIELD_WRONLY_DRIVER22(const string & fileName,
00248                    FIELD<T, INTERLACING_TAG> * ptrField):
00249     IMED_FIELD_WRONLY_DRIVER<T>(fileName,ptrField),
00250     MED_FIELD_DRIVER22<T>(fileName,ptrField,MED_EN::MED_WRONLY),
00251     MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_WRONLY)
00252   {
00253     BEGIN_OF("MED_FIELD_WRONLY_DRIVER22::MED_FIELD_WRONLY_DRIVER22(const string & fileName, const FIELD<T,INTERLACING_TAG> * ptrField)");
00254     END_OF("MED_FIELD_WRONLY_DRIVER22::MED_FIELD_WRONLY_DRIVER22(const string & fileName, const FIELD<T,INTERLACING_TAG> * ptrField)");
00255   }
00256 
00260   MED_FIELD_WRONLY_DRIVER22(const MED_FIELD_WRONLY_DRIVER22 & fieldDriver):
00261     IMED_FIELD_WRONLY_DRIVER<T>(fieldDriver),
00262     MED_FIELD_DRIVER22<T>(fieldDriver),
00263     MED_FIELD_DRIVER<T>(fieldDriver)
00264   {}
00265 
00269   virtual ~MED_FIELD_WRONLY_DRIVER22() {};
00270 
00274   void write( void ) const throw (MEDEXCEPTION) ;
00278   void read ( void ) throw (MEDEXCEPTION) ;
00279 
00280 private:
00281   GENDRIVER * copy( void ) const ;
00282 
00283 };
00284 
00285 
00294 template <class T> class MED_FIELD_RDWR_DRIVER22 : public MED_FIELD_RDONLY_DRIVER22<T>, public MED_FIELD_WRONLY_DRIVER22<T>, public IMED_FIELD_RDWR_DRIVER<T> {
00295 
00296 public :
00297 
00301   MED_FIELD_RDWR_DRIVER22():MED_FIELD_DRIVER22<T>() {}
00302 
00306   template <class INTERLACING_TAG>
00307   MED_FIELD_RDWR_DRIVER22(const string & fileName,
00308                  FIELD<T, INTERLACING_TAG> * ptrField):
00309     MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField),
00310     MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField),
00311     IMED_FIELD_RDONLY_DRIVER<T>(fileName,ptrField),
00312     IMED_FIELD_WRONLY_DRIVER<T>(fileName,ptrField),
00313     MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_RDWR),
00314     IMED_FIELD_RDWR_DRIVER<T>(fileName,ptrField)
00315   {
00316     BEGIN_OF("MED_FIELD_RDWR_DRIVER22::MED_FIELD_RDWR_DRIVER22(const string & fileName, const FIELD<T,INTERLACING_TAG> * ptrField)");
00317     //_accessMode = MED_RDWR ;
00318     END_OF("MED_FIELD_RDWR_DRIVER22::MED_FIELD_RDWR_DRIVER22(const string & fileName, const FIELD<T,INTERLACING_TAG> * ptrField)");
00319   }
00320 
00324   MED_FIELD_RDWR_DRIVER22(const MED_FIELD_RDWR_DRIVER22 & fieldDriver):
00325     MED_FIELD_WRONLY_DRIVER22<T>(fieldDriver),
00326     MED_FIELD_RDONLY_DRIVER22<T>(fieldDriver),
00327     IMED_FIELD_RDWR_DRIVER<T>(fieldDriver),
00328     IMED_FIELD_RDONLY_DRIVER<T>(fieldDriver),
00329     IMED_FIELD_WRONLY_DRIVER<T>(fieldDriver),
00330     MED_FIELD_DRIVER<T>(fieldDriver)
00331   {};
00332 
00336   ~MED_FIELD_RDWR_DRIVER22() {};
00337 
00341   void write(void) const throw (MEDEXCEPTION) ;
00345   void read (void) throw (MEDEXCEPTION) ;
00346 
00347 private:
00348   GENDRIVER * copy( void ) const ;
00349 
00350 };
00351 
00352 
00353 /*-------------------------*/
00354 /* template implementation */
00355 /*-------------------------*/
00356 
00357 /*--------------------- DRIVER PART -------------------------------*/
00358 
00359 
00385 template <class T> bool
00386 MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id,
00387                                 const string & fieldName,
00388                                 med_2_2::med_int ndt,
00389                                 med_2_2::med_int od,
00390                                 SUPPORT & support,
00391                                 string & meshName,
00392                                 vector<int> & numberOfElementsOfTypeC,
00393                                 vector<int> & numberOfGaussPoint,
00394                                 int & totalNumberOfElWg
00395                                 ) const throw (MEDEXCEPTION)
00396 {
00397 
00398   //EF : Gérer le meshName pour le driver 2.2
00399   const char * LOC="MED_FIELD_DRIVER<T>::createFieldSupportPart1(...)";
00400 
00401   BEGIN_OF(LOC);
00402 
00403   map<int, list<MED_EN::medGeometryElement> > CellAndNodeEntities;
00404   map<int, list<MED_EN::medGeometryElement> >::iterator currentEntity;
00405   CellAndNodeEntities[MED_EN::MED_CELL]  = MED_EN::meshEntities[MED_EN::MED_CELL];
00406   CellAndNodeEntities[MED_EN::MED_NODE] = MED_EN::meshEntities[MED_EN::MED_NODE];
00407   list< MED_EN::medGeometryElement >::const_iterator currentGeometry;
00408 
00409   MED_EN::medEntityMesh entityCurrent;
00410   MED_EN::medGeometryElement geometryCurrent;
00411 
00412   MED_EN::medEntityMesh entity;
00413   bool alreadyFoundAnEntity=false,alreadyFoundPdtIt = false;
00414   int  numberOfElements = 0;
00415   int  numberOfGeometricType = 0;
00416   MED_EN::medGeometryElement geometricType[MED_NBR_GEOMETRIE_MAILLE];
00417   int numberOfElementsOfType[MED_NBR_GEOMETRIE_MAILLE];
00418   numberOfElementsOfTypeC.clear();numberOfGaussPoint.clear();
00419   numberOfElementsOfTypeC.resize(MED_NBR_GEOMETRIE_MAILLE+1);
00420   numberOfGaussPoint.resize(MED_NBR_GEOMETRIE_MAILLE+1);
00421 
00422   med_2_2::med_int nmaa=0, ngauss=0, numdt=-1, numo=-1, nbPdtIt=0, nbPdtIt1=0, nbPdtIt2=0;
00423   char dtunit[MED_TAILLE_PNOM22+1];
00424   char maa[MED_TAILLE_NOM+1];
00425   med_2_2::med_float   dt=-1.0;
00426   med_2_2::med_booleen local;
00427   med_2_2::med_err     ret=1;
00428   numberOfElementsOfTypeC[0] = 1;
00429   numberOfGaussPoint[0] = 1;
00430   totalNumberOfElWg = 0;
00431 
00432   /* Détermine le type d'entité et la liste des types géométriques associés
00433      au champ <fieldName> */
00434   for (currentEntity = CellAndNodeEntities.begin();
00435        currentEntity != CellAndNodeEntities.end(); currentEntity++) {
00436     for (currentGeometry  = (*currentEntity).second.begin();
00437       currentGeometry != (*currentEntity).second.end(); currentGeometry++) {
00438 
00439       entityCurrent = (*currentEntity).first ;
00440       geometryCurrent = (*currentGeometry) ;
00441 
00442       // That is a difference between Med File and Med Memory (NB)
00443       if (geometryCurrent == MED_EN::MED_SEG2 || geometryCurrent == MED_EN::MED_SEG3)
00444      entityCurrent = MED_EN::MED_EDGE;
00445 
00446       if (geometryCurrent == MED_EN::MED_TRIA3 || geometryCurrent == MED_EN::MED_QUAD4 ||
00447        geometryCurrent == MED_EN::MED_TRIA6 || geometryCurrent == MED_EN::MED_QUAD8)
00448      entityCurrent = MED_EN::MED_FACE;
00449 
00450       nbPdtIt1 = med_2_2::MEDnPasdetemps(id, const_cast <char*> ( fieldName.c_str() ),
00451                           (med_2_2::med_entite_maillage)   (*currentEntity).first,
00452                           (med_2_2::med_geometrie_element)  *currentGeometry );
00453 
00454       nbPdtIt2 = med_2_2::MEDnPasdetemps(id, const_cast <char*> ( fieldName.c_str() ),
00455                           (med_2_2::med_entite_maillage)   entityCurrent,
00456                           (med_2_2::med_geometrie_element)  geometryCurrent );
00457 
00458       if (nbPdtIt2 < nbPdtIt1) entityCurrent = (*currentEntity).first ;
00459 
00460       nbPdtIt = (nbPdtIt1>nbPdtIt2)?nbPdtIt1:nbPdtIt2;
00461 
00462       if ( nbPdtIt <=  0 )
00463      continue;
00464 
00465       /* Verifie que le champ n'est pas défini sur un autre type d'entité */
00466       if ( alreadyFoundAnEntity )
00467      {
00468        //if (entity != (*currentEntity).first )  (NB)
00469        if ( entity != entityCurrent )
00470          throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field |"  << fieldName
00471                           << "| with (ndt,or) = (" << ndt << ","
00472                           << od << ") must not be defined on nodes and cells" ));
00473 
00474      }
00475       else
00476      { 
00477        //entity=(*currentEntity).first; (NB)
00478        entity=entityCurrent;
00479        alreadyFoundAnEntity = true;
00480      };
00481 
00482 
00483       /* Cherche le champ pour le <ndt>,<ot> demandé et détermine le nombre de points de Gauss*/
00484       ret = 0; alreadyFoundPdtIt = false; ngauss =0;
00485       for ( med_2_2::med_int j=1; j <= nbPdtIt; j++ ) {
00486 
00487      // Search how many <ngauss> (<fieldName>,<ndt>,<ot>) has   (NB)
00488      //ret += med_2_2::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ),
00489      //                   (med_2_2::med_entite_maillage)   (*currentEntity).first,
00490      //                   (med_2_2::med_geometrie_element)  *currentGeometry,
00491      //                   j, &ngauss,  &numdt,  &numo, dtunit, &dt,
00492      //                    maa, &local, &nmaa);
00493 
00494      ret += med_2_2::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ),
00495                            (med_2_2::med_entite_maillage)   entityCurrent,
00496                            (med_2_2::med_geometrie_element)  *currentGeometry,
00497                            j, &ngauss,  &numdt,  &numo, dtunit, &dt,
00498                            maa, &local, &nmaa);
00499 
00500      if ( ndt == numdt && numo == od ) {
00501        alreadyFoundPdtIt = true;
00502 
00503        if ( nmaa > 1 ) {
00504          MESSAGE(LOC<<" Field |" << fieldName << "| with (ndt,or) = ("
00505               << ndt << "," << od << ") for (entityType,geometricType)=("
00506               << MED_EN::entNames[entityCurrent] << ","
00507               << MED_EN::geoNames[*currentGeometry] << ")"
00508               << "is defined on multiple meshes, using dafault mesh  |" << maa << "|" );
00509        }
00510 
00511        if ( !local) {
00512          MESSAGE(" Field |" << fieldName << "| with (ndt,or) = ("
00513               << ndt << "," << od << ") for (entityType,geometricType)=("
00514               << MED_EN::entNames[entityCurrent] << ","
00515               << MED_EN::geoNames[*currentGeometry] << ")"
00516               << "is using a mesh on a distant file (ignored)" );
00517 
00518 //         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field |" << fieldName << "| with (ndt,or) = ("
00519 //                          << ndt << "," << od << ") for (entityType,geometricType)=("
00520 //                          << MED_EN::entNames[(*currentEntity).first] << ","
00521 //                          << MED_EN::geoNames[*currentGeometry] << ")"
00522 //                          << "is using a mesh on a different file which is not yet supported" ));
00523        }
00524 
00525        if ( ! meshName.empty() )
00526          if ( meshName != maa ) {
00527            throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field |" << fieldName << "| with (ndt,or) = ("
00528                             << ndt << "," << od << ") for (entityType,geometricType)=("
00529                             << MED_EN::entNames[entityCurrent] << ","
00530                             << MED_EN::geoNames[*currentGeometry] << ")"
00531                             << "is defined on mesh |" << maa << "| not on mesh |" << meshName ));
00532          }
00533        break;
00534      }
00535 
00536       }
00537 
00538       MESSAGE(LOC << " a (dt,it) is found ?? " << alreadyFoundPdtIt);
00539 
00540       if ( !alreadyFoundPdtIt )
00541      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field |" << fieldName << "| with (ndt,or) = ("
00542                          << ndt << "," << od << ") should be defined for (entityType,geometricType)=("
00543                          << MED_EN::entNames[entityCurrent] << ","
00544                          << MED_EN::geoNames[*currentGeometry] << ")" ));
00545 
00546       if ( (ret != 0)  || (ngauss < 1 ) )
00547      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Error in MEDpasdetempsInfo for  Field |" << fieldName 
00548                          << "| with (ndt,or) = ("
00549                          << ndt << "," << od << ") for (entityType,geometricType)=("
00550                          << MED_EN::entNames[entityCurrent] << ","
00551                          << MED_EN::geoNames[*currentGeometry] << ")" )); ;
00552 
00553       if ( (numberOfElements =  med_2_2::MEDnVal(id, const_cast <char*> ( fieldName.c_str() ),
00554                               (med_2_2::med_entite_maillage)   entityCurrent,
00555                               (med_2_2::med_geometrie_element) *currentGeometry,
00556                                numdt, numo, maa, med_2_2::MED_COMPACT))  <=  0 )
00557      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Error in MEDnVal for  Field |" << fieldName
00558                          << "| with (ndt,or) = ("
00559                          << ndt << "," << od << ") for (entityType,geometricType)=("
00560                          << MED_EN::entNames[entityCurrent] << ","
00561                          << MED_EN::geoNames[*currentGeometry] << ")" )); ;
00562 
00563       numberOfElementsOfType[numberOfGeometricType] = numberOfElements/ngauss;
00564       numberOfElementsOfTypeC[numberOfGeometricType+1]=
00565      numberOfElementsOfTypeC[numberOfGeometricType]
00566      +  numberOfElementsOfType[numberOfGeometricType];
00567       numberOfGaussPoint[numberOfGeometricType+1] = ngauss;
00568       geometricType[numberOfGeometricType]= *currentGeometry;
00569       numberOfGeometricType++;
00570       totalNumberOfElWg+=numberOfElements;
00571 
00572     } // End Second For
00573 
00574   } // End Premier For
00575 
00576   if ( alreadyFoundAnEntity) {
00577     support.setName(fieldName+"Support");
00578     support.setMeshName(string(maa)); // Vérifier que les différents noms de maillages lus soient identiques
00579     support.setEntity(entity);
00580     // REM : Le nombre <numberOfGeometricType> dans la précédente version du Driver 
00581     //       était erronée pour un champ qui ne reposait pas sur toutes les entités géométriques 
00582     //       du maillage mais dont le SUPPORT a été crée à partir des informations du maillage
00583     //       ( méthode qui était largement utilisée pour construire un SUPPORT).
00584     support.setNumberOfGeometricType(numberOfGeometricType);
00585     support.setGeometricType(geometricType); // Utile uniquement si setAll == false ?
00586     support.setNumberOfElements(numberOfElementsOfType);    //setNumberOfElements effectue une copie 
00587     // Par défaut considère que le champ repose sur tous les type géométriques du maillage
00588     // Si ce n'est pas le cas les champs geometricType et numberOfElementsOfType du SUPPORT sont corrects
00589     support.setAll(true);
00590     numberOfElementsOfTypeC.resize(numberOfGeometricType+1);
00591     numberOfGaussPoint.resize(numberOfGeometricType+1);
00592 
00593     return alreadyFoundAnEntity;
00594   } else
00595     return false;
00596 }
00597 
00607 template <class T> void
00608 MED_FIELD_DRIVER22<T>::getMeshGeometricTypeFromFile(med_2_2::med_idt id,
00609                            string & meshName,
00610                            MED_EN::medEntityMesh  entity,
00611                            vector<MED_EN::medGeometryElement> & geoType,
00612                            vector<int> &nbOfElOfType,
00613                            vector<int> &nbOfElOfTypeC
00614                           ) const throw(MEDEXCEPTION)
00615 {
00616   const char LOC[] = "MED_FIELD_DRIVER<T>::getMeshGeometricTypeFromFile(...)";
00617 
00618   int numberOfGeometricType=0;
00619   MED_EN::medGeometryElement geometricType[MED_NBR_GEOMETRIE_MAILLE];
00620   int numberOfElementsOfType [MED_NBR_GEOMETRIE_MAILLE];
00621   int numberOfElementsOfTypeC[MED_NBR_GEOMETRIE_MAILLE+1];
00622   med_2_2::med_int   numberOfElements=0;
00623   med_2_2::med_table quoi;
00624   if (entity == MED_EN::MED_CELL) quoi=med_2_2::MED_CONN;
00625   else
00626     if (entity == MED_EN::MED_NODE) quoi=med_2_2::MED_COOR;
00627     else
00628       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Support Creation from Mesh |"  << meshName
00629                        << "| on entity " << MED_EN::entNames[entity]
00630                        << "| is impossible,  must be  on MED_NODE or MED_CELL" ));
00631 
00632   list<MED_EN::medGeometryElement>::const_iterator currentGeometry;
00633   bool alreadyFoundAnEntity = false;
00634   numberOfElementsOfTypeC[0]=0;
00635 
00636   for (currentGeometry  = (MED_EN::meshEntities[entity]).begin();
00637        currentGeometry != (MED_EN::meshEntities[entity]).end(); currentGeometry++) {
00638 
00639 
00640     if ( (numberOfElements =
00641        med_2_2::MEDnEntMaa(id,
00642                      const_cast<char*> (meshName.c_str()),
00643                      quoi,
00644                      (med_2_2::med_entite_maillage)   entity,
00645                      (med_2_2::med_geometrie_element)  *currentGeometry,
00646                      med_2_2::MED_NOD) ) <= 0)
00647       continue;
00648 
00649     alreadyFoundAnEntity = true;
00650     numberOfElementsOfType[numberOfGeometricType] = numberOfElements;
00651     numberOfElementsOfTypeC[numberOfGeometricType+1] =
00652       numberOfElementsOfTypeC[numberOfGeometricType]+numberOfElements;
00653     geometricType[numberOfGeometricType] = *currentGeometry;
00654     numberOfGeometricType++;
00655 
00656   }
00657 
00658   geoType = vector<MED_EN::medGeometryElement>(geometricType,geometricType+numberOfGeometricType);
00659   nbOfElOfType = vector<int> (numberOfElementsOfType,numberOfElementsOfType+numberOfGeometricType);
00660   nbOfElOfTypeC = vector<int> (numberOfElementsOfTypeC,numberOfElementsOfTypeC+numberOfGeometricType+1);
00661 
00662 //   for (int j =0 ; j<= numberOfGeometricType;++j)
00663 //       cout << "nbOfElOfTypeC["<<j<<"]="<<nbOfElOfTypeC[j]<<endl;
00664 
00665 }
00666 
00667 template <class T> void
00668 MED_FIELD_DRIVER22<T>::getMeshGeometricTypeFromMESH( MESH * meshPtr,
00669                            MED_EN::medEntityMesh  entity,
00670                            vector<MED_EN::medGeometryElement> & geoType,
00671                            vector<int> &nbOfElOfType,
00672                            vector<int> &nbOfElOfTypeC) const throw(MEDEXCEPTION)
00673 {
00674   const char LOC[] = "MED_FIELD_DRIVER<T>::getMeshGeometricTypeFromMESH(...) : ";
00675   BEGIN_OF(LOC);
00676 
00677   if (!meshPtr)
00678     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"ptrMesh must be non null" )); ;
00679 
00680   // Il est plus pratique de créer un support "onAll"
00681   // pour calculer les tableaux du nombre d'entités cumulées
00682 
00683   SUPPORT mySupportFromMesh = SUPPORT(meshPtr,"Temporary Support From Associated Mesh",
00684                           entity);
00685   geoType = vector<MED_EN::medGeometryElement>(mySupportFromMesh.getTypes(),
00686                      mySupportFromMesh.getTypes()+mySupportFromMesh.getNumberOfTypes());
00687   nbOfElOfType.resize(mySupportFromMesh.getNumberOfTypes());
00688   nbOfElOfTypeC.resize(mySupportFromMesh.getNumberOfTypes()+1);
00689   nbOfElOfTypeC[0]=0;
00690 
00691   for (int j=1; j<=mySupportFromMesh.getNumberOfTypes(); ++j) {
00692     nbOfElOfType[j-1]=mySupportFromMesh.getNumberOfElements(geoType[j-1]);
00693     nbOfElOfTypeC[j]+=nbOfElOfTypeC[j-1]+nbOfElOfType[j-1];
00694   }
00695 
00696   END_OF(LOC);
00697 }
00698 
00699 /*--------------------- RDONLY PART -------------------------------*/
00700 
00701 template <class T> GENDRIVER * MED_FIELD_RDONLY_DRIVER22<T>::copy(void) const
00702 {
00703   return new MED_FIELD_RDONLY_DRIVER22<T>(*this);
00704 }
00705 
00706 template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void)
00707   throw (MEDEXCEPTION)
00708 {
00709   const char * LOC = " MED_FIELD_RDONLY_DRIVER22::read() " ;
00710   BEGIN_OF(LOC);
00711 
00712   typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array   ArrayNo;
00713   typedef typename MEDMEM_ArrayInterface<T,NoInterlace,Gauss>::Array     ArrayNoWg;
00714   typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array ArrayFull;
00715   typedef typename MEDMEM_ArrayInterface<T,FullInterlace,Gauss>::Array   ArrayFullWg;
00716 
00717   if (MED_FIELD_DRIVER<T>::_status!=MED_OPENED)
00718     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": Method open must be called before method read.")) ;
00719 
00720   if ( ( MED_FIELD_DRIVER<T>::_fieldName.empty()       ) &&
00721        ( MED_FIELD_DRIVER<T>::_ptrField->_name.empty() )    )
00722     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
00723                      <<" neither <fieldName> is set in driver nor in object FIELD.")) ;
00724 
00725   // If _fieldName is not set in driver, try to use _ptrfield->_fieldName
00726   if ( ( MED_FIELD_DRIVER<T>::_fieldName.empty()       ) &&
00727        ( !MED_FIELD_DRIVER<T>::_ptrField->_name.empty() )    )
00728     MED_FIELD_DRIVER<T>::_fieldName=MED_FIELD_DRIVER<T>::_ptrField->_name;
00729 
00730   if ( MED_FIELD_DRIVER<T>::_fieldName.size() > MED_TAILLE_NOM )
00731     {
00732       SCRUTE(MED_FIELD_DRIVER<T>::_fieldName.size());
00733       SCRUTE(MED_TAILLE_NOM);
00734 
00735 //       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
00736 //                     <<" <fieldName> size in object driver FIELD is > MED_TAILLE_NOM ."));
00737 
00738       MESSAGE(LOC << "Warning <fieldName> size in object driver FIELD is > MED_TAILLE_NOM .");
00739     }
00740 
00741   const string & fieldName = MED_FIELD_DRIVER<T>::_fieldName;
00742 
00743   MED_EN::medModeSwitch interlacingType = MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType();
00744   bool isFullInterlace = ( interlacingType == MED_EN::MED_FULL_INTERLACE );
00745 
00746   MESSAGE("###### "<<LOC<<" fieldNameDRIVER : "<< fieldName << " fieldName : "<< MED_FIELD_DRIVER<T>::_ptrField->_name);
00747 
00748 // EF :
00749 //   Si un support a été donnée au champ, pour des raisons de compatibilité avec
00750 //   les versions précédentes, ce support sera utilisé pour
00751 //   - Obtenir le nom du maillage sur lequel on veut lire le champ
00752 //     (eventuellement on pourrait l'utiliser pour selectionner un champ qui
00753 //      repose sur plusieurs maillages cf HOMARD-ASTER, ce qui n'est pas géré dans MEDMEM)
00754 //   -  vérifier le type d'entité (MED_NOEUD xor MED_MAILLE xor MED_FACE xor MED_ARETE ) sur lequel
00755 //      il faut lire le champ qui est également retouvé.
00756 //   - Si le support défini une liste d'entité ( différente de MED_ALL_ELEMENTS), celle-ci est ignorée
00757 //     à la lecture et écrasé par soit :
00758 //            - onall, après avoir vérifié que la liste des types géométriques utilisés par le champ
00759 //               est égale à la liste des type géométriques définis dans le maillage associé
00760 //                     pour tous le même type d'entité.
00761 //            - La sous liste des types géométriques utilisés (onAll quand même, cf commenataire ci-dessous )  
00762 //            - les listes de profils lus s'il en existe pour une sous liste de types
00763 //              géométriques
00764 
00765 //   Si aucun support n'a été donné au champ :
00766 //   - A la lecture : Un support est crée et le type d'entité unique est lu
00767 //                    (cf decision gt MED qu'un champ repose sur une entité unique ?),
00768 //                    l'ensemble des types géométriques est lu,
00769 //                    l'ensemble des profils par type géométrique est lu
00770 //                    Le nom du maillage associé est lu mais le pointeur SUPPORT-MESH non initialisé
00771 
00772 
00773   char tmpFieldName[MED_TAILLE_NOM+1] ;
00774   int err ;
00775   int    numberOfComponents          = 0;
00776   char * componentName               = (char *) MED_NULL;
00777   char * unitName                    = (char *) MED_NULL;
00778   med_2_2::med_type_champ type ;
00779   med_2_2::med_idt id = MED_FIELD_DRIVER22<T>::_medIdt;
00780   bool needConversionToDouble = false,needConversionToInt64 = false;
00781 
00782   // we search for the "field med number" of <fieldName>
00783   // Having found <fieldName>, variables <numberOfComponents>,
00784   // <componentName>, <unitname>, <type> and attribute <_fieldNum> are set.
00785   if (MED_FIELD_DRIVER<T>::_fieldNum==MED_INVALID)
00786     {
00787       int numberOfFields = med_2_2::MEDnChamp(id,0) ;
00788       if ( numberOfFields <= 0 )
00789      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": There is no field found in the file !"));
00790 
00791       for (int i=1;i<=numberOfFields;i++)
00792      {
00793        numberOfComponents = med_2_2::MEDnChamp(id,i) ;
00794 
00795        if ( numberOfComponents <= 0 )
00796          MESSAGE(LOC<<"Be careful there is no compound for field n°"<<i<<"in file |"<<MED_FIELD_DRIVER<T>::_fileName<<"| !");
00797 
00798        componentName = new char[numberOfComponents*MED_TAILLE_PNOM22+1] ;
00799        unitName      = new char[numberOfComponents*MED_TAILLE_PNOM22+1] ;
00800 
00801        err = med_2_2::MEDchampInfo(id, i, tmpFieldName, &type, componentName,
00802                           unitName, numberOfComponents) ;
00803 
00804        MESSAGE("Field "<<i<<" : #" << tmpFieldName <<"# et recherche #"<<fieldName.c_str()<<"#");
00805        if ( !strcmp(tmpFieldName,fieldName.c_str()) ) {
00806          MESSAGE("FOUND FIELD "<< tmpFieldName <<" : "<<i);
00807          MED_FIELD_DRIVER<T>::_fieldNum = i ;
00808          break ;
00809        }
00810        // not found : release memory and search next field !
00811        delete[] componentName ;
00812        delete[] unitName ;
00813      }
00814     }
00815 
00816   //delete[] tmpFieldName ;
00817 
00818   // Si aucun champ ne correspond les variables <componentName> et <unitName> ont été correctement
00819   // désallouées dans la boucle de recherche
00820   if (MED_FIELD_DRIVER<T>::_fieldNum==MED_INVALID)
00821     throw MEDEXCEPTION(LOCALIZED( STRING(LOC) << ": Field "<<  fieldName
00822                        << " not found in file " << MED_FIELD_DRIVER<T>::_fileName) );
00823 
00824   MESSAGE ("FieldNum : "<<MED_FIELD_DRIVER<T>::_fieldNum);
00825 
00826   if (numberOfComponents < 1) {
00827     delete[] componentName; delete[] unitName;
00828     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" no component found for field "
00829                      << fieldName)) ;
00830   }
00831 
00832   // Verifie que l'on essaye pas de lire un champ double dans un FIELD<int>
00833   switch ( (med_2_2::med_type_champ) MED_FIELD_DRIVER<T>::_ptrField->_valueType ) {
00834   case  med_2_2::MED_INT :
00835   case  med_2_2::MED_INT32 :
00836   case  med_2_2::MED_INT64 :
00837     if ( type == ( med_2_2::MED_FLOAT64 ) ) {
00838       delete[] componentName; delete[] unitName;
00839       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field Type in file (" << type
00840                        <<") differs from FIELD object type (" <<
00841                        MED_FIELD_DRIVER<T>::_ptrField->_valueType << ")" )) ;
00842     }
00843 #if defined(IRIX64) || defined(OSF1) ||defined(VPP5000)
00844     if (_ptrField->_valueType==MED_EN::MED_INT32 )
00845       needConversionToInt64=true;
00846 #endif
00847     break;
00848   case med_2_2::MED_FLOAT64 :
00849     if (type != med_2_2::MED_FLOAT64)
00850       needConversionToDouble=true;
00851     break;
00852   default:
00853     break;
00854   }
00855 
00856   string meshName="";
00857   MESH * ptrMesh = 0;
00858   bool   haveSupport = false;
00859   bool   haveMesh    = false;
00860   if ( MED_FIELD_DRIVER<T>::_ptrField->getSupport() ) {
00861     // Verif à faire sur la taille du meshName
00862     ptrMesh = MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getMesh();
00863     if ( ptrMesh) {
00864       meshName =  MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getMesh()->getName() ;
00865       haveMesh = true;
00866     }
00867     haveSupport = true;
00868   }
00869 
00870   // Cherche le type d'entité, le nombre d'entité  par type géométrique sur le type d'entité
00871   // (MED_MAILLE ou MED_NOEUD uniquement car MEDMEMOIRE ne gère pas la connectivité descendante).
00872   // et crée le support correspondant.
00873   SUPPORT *   mySupport = new SUPPORT();
00874   vector<int> numberOfElementsOfTypeC;
00875   vector<int> numberOfGaussPoint;
00876   int         totalNumberOfElWg=0;
00877 
00878   bool found = createFieldSupportPart1(id,fieldName,
00879                            MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber,
00880                            MED_FIELD_DRIVER<T>::_ptrField->_orderNumber,
00881                            *mySupport, meshName,
00882                            numberOfElementsOfTypeC, numberOfGaussPoint,totalNumberOfElWg);
00883 
00884   if ( !found ) {
00885     delete mySupport; delete[] componentName; delete[] unitName;
00886     MED_FIELD_DRIVER<T>::_fieldNum = MED_INVALID ;
00887      throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"  Can't find any entity for field |"
00888                      << fieldName
00889                      << "| with (it,or) = ("
00890                       << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << ","
00891                      << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << "), on mesh "
00892                      << meshName << "|" ));
00893   }
00894 
00895 
00896   MED_EN::medEntityMesh entityType = mySupport->getEntity();
00897   //Si un SUPPORT était donné, récupère son nom, sa description et
00898   //  le pointeur du maillage associé
00899   if (! haveSupport)
00900     meshName = mySupport->getMeshName();
00901   else {
00902     if ( mySupport->getEntity() != MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getEntity() ) {
00903       delete mySupport; delete[] componentName; delete[] unitName;
00904       MED_FIELD_DRIVER<T>::_fieldNum = MED_INVALID ;
00905       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Given entity |"
00906                        << MED_EN::entNames[MED_FIELD_DRIVER<T>::_ptrField->
00907                                      getSupport()->getEntity()]
00908                        << "| for field |"
00909                        << fieldName
00910                        << "| with (it,or) = ("
00911                        << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << ","
00912                        << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << "), on mesh "
00913                        << meshName << "| differs from found entity |"
00914                        << MED_EN::entNames[entityType] << "|."
00915                        ));
00916     }
00917     mySupport->setName( MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getName() );
00918     mySupport->setMesh( MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getMesh() );
00919     mySupport->setDescription(MED_FIELD_DRIVER<T>::_ptrField->getSupport()->getDescription());
00920   }
00921 
00922   vector< MED_EN::medGeometryElement >  MESHgeoType;
00923   vector< int >  MESHnbOfElOfType;
00924   vector< int >  MESHnbOfElOfTypeC;
00925   if ( haveMesh )
00926     this->getMeshGeometricTypeFromMESH(ptrMesh,entityType,MESHgeoType,
00927                                        MESHnbOfElOfType,MESHnbOfElOfTypeC);
00928 
00929   int fileHasMesh = ( med_2_2::MEDdimLire(id, const_cast<char *>(meshName.c_str())) > 0);
00930   vector< MED_EN::medGeometryElement >  meshGeoType;
00931   vector< int >  meshNbOfElOfType;
00932   vector< int >  meshNbOfElOfTypeC;
00933   // Si le maillage n'est pas trouvé les tableaux renvoyés sont vides
00934   if (fileHasMesh)
00935     {
00936       MED_EN::medEntityMesh entityTypeLoc = entityType;
00937       if (entityType == MED_EN::MED_FACE || entityType == MED_EN::MED_EDGE) entityTypeLoc = MED_EN::MED_CELL;
00938 
00939       this->getMeshGeometricTypeFromFile(id,meshName,entityTypeLoc,meshGeoType,
00940                           meshNbOfElOfType,meshNbOfElOfTypeC);
00941     }
00942 
00943   SCRUTE(meshGeoType.size());
00944   SCRUTE(MESHgeoType.size());
00945   SCRUTE(meshNbOfElOfTypeC.size());
00946   SCRUTE(MESHnbOfElOfTypeC.size());
00947 
00948   if (meshGeoType.size() != MESHgeoType.size())
00949     {
00950       for (int i = 0; i<meshGeoType.size();i++)
00951      MESSAGE("debug meshGeotype " << meshGeoType[i]);
00952 
00953       for (int i = 0; i<MESHgeoType.size();i++)
00954      MESSAGE("debug MESHgeoType. " << MESHgeoType[i]);
00955     }
00956 
00957   if (meshNbOfElOfTypeC.size() == MESHnbOfElOfTypeC.size())
00958     {
00959       for (int i = 0; i<meshNbOfElOfTypeC.size();i++)
00960      MESSAGE("debug meshNbOfElOfTypeC " << meshNbOfElOfTypeC[i]);
00961 
00962       for (int i = 0; i<MESHnbOfElOfTypeC.size();i++)
00963      MESSAGE("debug MESHnbOfElOfTypeC " << MESHnbOfElOfTypeC[i]);
00964     }
00965 
00966   if (fileHasMesh && haveSupport )
00967     if ( ( meshGeoType != MESHgeoType ) || (meshNbOfElOfTypeC != MESHnbOfElOfTypeC) )
00968       {
00969      MESSAGE("Warning MedField driver 21 while getting mesh information from file for FIELD "<< fieldName
00970           << " on entity " << MED_EN::entNames[entityType]
00971           << " with (it,or) = ("
00972           << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << ","
00973           << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << ")"
00974           << " on mesh " << meshName
00975           << " : geometric types or number of elements by type differs from MESH object !");
00976 
00977 //   throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error while getting mesh information from file for FIELD "<< fieldName
00978 //                        << " on entity " << MED_EN::entNames[entityType]
00979 //                        << " with (it,or) = ("
00980 //                        << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << ","
00981 //                        << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << ")"
00982 //                        << " on mesh " << meshName
00983 //                        << " : geometric types or number of elements by type differs from MESH object !"
00984 //                        )
00985 //                );
00986       }
00987 
00988   if ( !fileHasMesh && !haveSupport )
00989     throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error while getting mesh information for FIELD "<< fieldName
00990                       << " on entity " << MED_EN::entNames[entityType]
00991                       << " with (it,or) = ("
00992                       << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << ","
00993                       << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << ")"
00994                       << " on mesh " << meshName
00995                       << " : SUPPORT must contain a valid MESH reference or file must contain the associated MESH."
00996                       )
00997                  );
00998 
00999 
01000   if (!fileHasMesh && haveSupport) {
01001     meshNbOfElOfTypeC = MESHnbOfElOfTypeC;
01002     meshGeoType       = MESHgeoType;
01003     meshNbOfElOfType  = MESHnbOfElOfType;
01004   }
01005 
01006 
01007   // Test si le Support du Champ repose ou non sur toutes les entités géométriques
01008   // du maillage associé et positionne ou non l'attribut onAll du SUPPORT.
01009   // Il ne s'agit pas de la gestion des profils
01010   vector < MED_EN::medGeometryElement > v1(  mySupport->getTypes(),
01011                               mySupport->getTypes()+mySupport->getNumberOfTypes() );
01012   vector<int> v2(numberOfElementsOfTypeC.size());
01013   transform(numberOfElementsOfTypeC.begin(),
01014          numberOfElementsOfTypeC.end(),v2.begin(), bind2nd(plus<int>(),1));
01015 
01016   if ( ( meshGeoType != v1 )  || meshNbOfElOfTypeC != v2 ) {
01017     // ATTENTION : mySupport->setAll(false);
01018     // Pb : On a envie de positionner onAll à faux si le champ n'est pas défini sur tous les
01019     //      types géométriques du maillage associé.
01020     //      Mais si onAll est false et si aucun profil n'est détecté par la suite,
01021     //      l'attribut SUPPORT->_number est censé être positionné quand même ! Que faire ?
01022     // Si on veut être compatible avec la signification première de onAll,
01023     //  il faudrait créer des profils contenant toutes les entités pour chaque type géométrique
01024     //  du SUPPORT  mais d'une part c'est dommage d'un point de vue de l'emcombrement mémoire
01025     //  et d'autre part, à la réécriture du fichier MED on stockera des profils 
01026     //  alors qu'il n'y en avait pas à l'origine (fichier MED différent après lecture/écriture) !
01027     // Si on laisse setAll à vrai il faut être sûr que les utilisateurs prennent les
01028     //  informations sur les types gémétrique au niveau du support et non pas du maillage.
01029     // Solution : Signification du onAll -> onAllElements des type géométriques définis
01030     // dans le SUPPORT et non du maillage associé (dans la plupart des cas si le fichier ne
01031     // contient pas de profil, le champ est défini sur toutes les entités de tous les types
01032     // géométriques définis dans le maillage).
01033   }
01034 
01035 
01036   // If an error occurs while reading the field, these allocated FIELD member will be deleted
01037 
01038   MED_FIELD_DRIVER<T>::_ptrField->_name                   = fieldName;
01039   MED_FIELD_DRIVER<T>::_ptrField->_numberOfComponents     = numberOfComponents ;
01040   MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes        = new int   [numberOfComponents] ;
01041   MED_FIELD_DRIVER<T>::_ptrField->_componentsNames        = new string[numberOfComponents] ;
01042   MED_FIELD_DRIVER<T>::_ptrField->_componentsUnits        = new UNIT  [numberOfComponents] ;
01043   MED_FIELD_DRIVER<T>::_ptrField->_componentsDescriptions = new string[numberOfComponents] ;
01044   MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits     = new string[numberOfComponents] ;
01045   for (int i=0; i<numberOfComponents; i++) {
01046       MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes[i] = 1 ;
01047       MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i] = string(componentName,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
01048       SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i]);
01049       MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i] = string(unitName,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
01050       SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i]);
01051   }
01052   delete[] componentName;
01053   delete[] unitName;
01054 
01055   int NumberOfTypes                       = mySupport->getNumberOfTypes() ;
01056   const MED_EN::medGeometryElement *types = mySupport->getTypes() ;
01057   T * myValues = new T[totalNumberOfElWg*numberOfComponents];
01058   const int * nbOfElOfType = mySupport->getNumberOfElements() ;
01059   bool anyProfil = false;
01060   int  pflSize=0,index=0;
01061   // Le vecteur de profil est dimensionné par rapport aux nombres de types
01062   // géométriques du champ même si le champ n'a pas de profil MED FICHIER sur
01063   // tous ses types géométriques car dans MEDMEM si onAllElement 
01064   // du SUPPORT est false il faut positionner un profil pour tous les types géo