+
+ bool isFileExist( const std::string& fName )
+ {
+ return SMESH_File( fName ).exists();
+ }
+
+ // =======================================================================
+ med_idt openMedFile(const std::string aFile)
+ // =======================================================================
+ // renvoie le medId associe au fichier Med apres ouverture
+ {
+ med_idt medIdt = MEDfileOpen(aFile.c_str(),MED_ACC_RDONLY);
+ if (medIdt <0)
+ {
+ THROW_SALOME_EXCEPTION("\nThe med file " << aFile << " cannot be opened.\n");
+ }
+ return medIdt;
+ }
+
+ // =======================================================================
+ void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit, std::string fieldName)
+ // =======================================================================
+ {
+ // Il faut voir si plusieurs maillages
+
+ herr_t erreur = 0 ;
+ med_idt medIdt ;
+
+ // Ouverture du fichier
+ //~SCRUTE(aFile.toStdString());
+ medIdt = openMedFile(aFile);
+ if ( medIdt < 0 ) return ;
+ // Lecture du nombre de champs
+ med_int ncha = MEDnField(medIdt) ;
+ if (ncha < 1 )
+ {
+ //~addMessage( ToComment(" error: there is no field in ") << aFile, /*fatal=*/true );
+ return;
+ }
+ // Lecture des caracteristiques du champs
+
+ // Lecture du type du champ, des noms des composantes et du nom de l'unite
+ char nomcha [MED_NAME_SIZE+1];
+ strcpy(nomcha, fieldName.c_str());
+ // Lecture du nombre de composantes
+ med_int ncomp = MEDfieldnComponentByName(medIdt, nomcha);
+ char meshname[MED_NAME_SIZE+1];
+ char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
+ char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
+ char dtunit[MED_SNAME_SIZE+1];
+ med_bool local;
+ med_field_type typcha;
+ med_int nbofcstp;
+ erreur = MEDfieldInfoByName (medIdt, nomcha, meshname,&local,&typcha,comp,unit,dtunit, &nbofcstp);
+ free(comp);
+ free(unit);
+ if ( erreur < 0 )
+ {
+ //~addMessage( ToComment(" error: error while reading field ") << nomcha << " in file " << aFile , /*fatal=*/true );
+ return;
+ }
+
+ med_float dt;
+ med_int tmp_numdt, tmp_numit;
+
+ //~med_int step = data->myUseLastTimeStep ? nbofcstp : data->myTimeStep+1;
+ //~myPrint("step ", step);
+ erreur = MEDfieldComputingStepInfo ( medIdt, nomcha, 1, &numdt, &numit, &dt );
+ for( int step = 1; step <= nbofcstp; step++ )
+ {
+ erreur = MEDfieldComputingStepInfo ( medIdt, nomcha, step, &tmp_numdt, &tmp_numit, &dt );
+ if(tmp_numdt > numdt)
+ {
+ numdt = tmp_numdt;
+ numit = tmp_numit;
+ }
+ }
+ if ( erreur < 0 )
+ {
+ //~addMessage( ToComment(" error: error while reading field ") << nomcha << "step (numdt, numit) = " <<"("<< numdt<< ", "
+ //numit<< ")" <<" in file " << aFile , /*fatal=*/true );
+ return;
+ }
+
+ // Fermeture du fichier
+ if ( medIdt > 0 ) MEDfileClose(medIdt);
+
+ }
+
+ struct GET_DEFAULT // struct used to get default value from GetOptionValue()
+ {