1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HomardMedCommun.h"
33 #include "utilities.h"
34 // =======================================================================
35 int MEDFileExist( const char * aFile )
36 // Retourne 1 si le fichier existe, 0 sinon
37 // =======================================================================
40 med_idt medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
41 if ( medIdt < 0 ) { existe = 0 ; }
42 else { MEDfileClose(medIdt);
46 // =======================================================================
47 std::set<std::string> GetListeGroupesInMedFile(const char * aFile)
48 // =======================================================================
50 std::set<std::string> ListeGroupes;
55 // Ouverture du fichier
56 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
62 // Caracteristiques du maillage
63 char meshname[MED_NAME_SIZE+1];
64 med_int spacedim,meshdim;
65 med_mesh_type meshtype;
66 char descriptionription[MED_COMMENT_SIZE+1];
67 char dtunit[MED_SNAME_SIZE+1];
68 med_sorting_type sortingtype;
70 med_axis_type axistype;
71 int naxis = MEDmeshnAxis(medIdt,1);
72 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
73 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
74 erreur = MEDmeshInfo(medIdt,
89 if ( erreur < 0 ) { break ; }
92 nfam = MEDnFamily(medIdt,meshname) ;
98 // Lecture des caracteristiques des familles
99 for (int i=0;i<nfam;i++)
101 // Lecture du nombre de groupes
102 med_int ngro = MEDnFamilyGroup(medIdt,meshname,i+1);
108 // Lecture de la famille
111 char familyname[MED_NAME_SIZE+1];
113 char* gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
114 erreur = MEDfamilyInfo(medIdt,
125 // Lecture des groupes pour une famille de mailles
128 for (int j=0;j<ngro;j++)
130 char str2[MED_LNAME_SIZE+1];
131 strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
132 str2[MED_LNAME_SIZE] = '\0';
133 ListeGroupes.insert(std::string(str2));
141 // Fermeture du fichier
142 if ( medIdt > 0 ) MEDfileClose(medIdt);
147 // =======================================================================
148 std::vector<double> GetBoundingBoxInMedFile(const char * aFile)
149 // =======================================================================
151 // Le vecteur en retour contiendra les informations suivantes :
152 // en position 0 et 1 Xmin, Xmax et en position 2 Dx si < 0 2D
153 // en position 3 et 4 Ymin, Ymax et en position 5 Dy si < 0 2D
154 // en position 6 et 7 Zmin, Zmax et en position 8 Dz si < 0 2D
155 // 9 distance max dans le maillage
157 std::vector<double> LesExtremes;
160 while ( erreur == 0 )
162 // Ouverture du fichier
163 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
169 //Nombre de maillage : on ne peut en lire qu'un seul
170 med_int numberOfMeshes = MEDnMesh(medIdt) ;
171 if (numberOfMeshes != 1 )
176 // Caracteristiques du maillage
177 char meshname[MED_NAME_SIZE+1];
178 med_int spacedim,meshdim;
179 med_mesh_type meshtype;
180 char descriptionription[MED_COMMENT_SIZE+1];
181 char dtunit[MED_SNAME_SIZE+1];
182 med_sorting_type sortingtype;
184 med_axis_type axistype;
185 int naxis = MEDmeshnAxis(medIdt,1);
186 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
187 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
188 erreur = MEDmeshInfo(medIdt,
203 if ( erreur < 0 ) { break ; }
207 med_int nnoe = MEDmeshnEntity(medIdt,
224 med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim);
226 erreur = MEDmeshNodeCoordinateRd(medIdt,
238 // Calcul des extremes
239 med_float xmin,xmax,ymin,ymax,zmin,zmax;
243 for (int i=1;i<nnoe;i++)
245 xmin = std::min(xmin,coo[i]);
246 xmax = std::max(xmax,coo[i]);
251 ymin=coo[nnoe]; ymax=coo[nnoe];
252 for (int i=nnoe+1;i<2*nnoe;i++)
254 ymin = std::min(ymin,coo[i]);
255 ymax = std::max(ymax,coo[i]);
268 zmin=coo[2*nnoe]; zmax=coo[2*nnoe];
269 for (int i=2*nnoe+1;i<3*nnoe;i++)
271 zmin = std::min(zmin,coo[i]);
272 zmax = std::max(zmax,coo[i]);
281 MESSAGE( "_______________________________________");
282 MESSAGE( "xmin : " << xmin << " xmax : " << xmax );
283 MESSAGE( "ymin : " << ymin << " ymax : " << ymax );
284 MESSAGE( "zmin : " << zmin << " zmax : " << zmax );
285 MESSAGE( "_______________________________________" );
286 double epsilon = 1.e-6 ;
287 LesExtremes.push_back(xmin);
288 LesExtremes.push_back(xmax);
289 LesExtremes.push_back(0);
290 LesExtremes.push_back(ymin);
291 LesExtremes.push_back(ymax);
292 LesExtremes.push_back(0);
293 LesExtremes.push_back(zmin);
294 LesExtremes.push_back(zmax);
295 LesExtremes.push_back(0);
298 double max1=std::max ( LesExtremes[1] - LesExtremes[0] , LesExtremes[4] - LesExtremes[3] ) ;
299 double max2=std::max ( max1 , LesExtremes[7] - LesExtremes[6] ) ;
300 LesExtremes.push_back(max2);
302 // LesExtremes[0] = Xmini du maillage
303 // LesExtremes[1] = Xmaxi du maillage
304 // LesExtremes[2] = increment de progression en X
305 // LesExtremes[3,4,5] : idem pour Y
306 // LesExtremes[6,7,8] : idem pour Z
307 // LesExtremes[9] = ecart maximal entre coordonnees
308 // On fait un traitement pour dans le cas d'une coordonnee constante
309 // inhiber ce cas en mettant un increment negatif
311 double diff = LesExtremes[1] - LesExtremes[0];
312 if ( fabs(diff) > epsilon*max2 ) { LesExtremes[2] = diff/100.; }
313 else { LesExtremes[2] = -1. ; }
315 diff = LesExtremes[4] - LesExtremes[3];
316 if ( fabs(diff) > epsilon*max2 ) { LesExtremes[5]=diff/100.; }
317 else { LesExtremes[5] = -1. ; }
319 diff = LesExtremes[7] - LesExtremes[6];
320 if ( fabs(diff) > epsilon*max2 ) { LesExtremes[8]=diff/100.; }
321 else { LesExtremes[8] = -1. ; }
323 MESSAGE ( "_______________________________________" );
324 MESSAGE ( "xmin : " << LesExtremes[0] << " xmax : " << LesExtremes[1] << " xincr : " << LesExtremes[2] );
325 MESSAGE ( "ymin : " << LesExtremes[3] << " ymax : " << LesExtremes[4] << " yincr : " << LesExtremes[5] );
326 MESSAGE ( "zmin : " << LesExtremes[6] << " zmax : " << LesExtremes[7] << " zincr : " << LesExtremes[8] );
327 MESSAGE ( "dmax : " << LesExtremes[9] );
328 MESSAGE ( "_______________________________________" );
333 // Fermeture du fichier
334 if ( medIdt > 0 ) MEDfileClose(medIdt);