1 // Copyright (C) 2011-2023 CEA, EDF
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, or (at your option) any later version.
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"
30 #include "utilities.h"
31 // =======================================================================
32 int MEDFileExist( const char * aFile )
33 // Retourne 1 si le fichier existe, 0 sinon
34 // =======================================================================
37 med_idt medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
38 if ( medIdt < 0 ) { existe = 0 ; }
39 else { MEDfileClose(medIdt);
43 // =======================================================================
44 std::set<std::string> GetListeGroupesInMedFile(const char * aFile)
45 // =======================================================================
47 std::set<std::string> ListeGroupes;
52 // Ouverture du fichier
53 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
59 // Caracteristiques du maillage
60 char meshname[MED_NAME_SIZE+1];
61 med_int spacedim,meshdim;
62 med_mesh_type meshtype;
63 char descriptionription[MED_COMMENT_SIZE+1];
64 char dtunit[MED_SNAME_SIZE+1];
65 med_sorting_type sortingtype;
67 med_axis_type axistype;
68 int naxis = MEDmeshnAxis(medIdt,1);
69 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
70 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
71 erreur = MEDmeshInfo(medIdt,
86 if ( erreur < 0 ) { break ; }
89 nfam = MEDnFamily(medIdt,meshname) ;
95 // Lecture des caracteristiques des familles
96 for (int i=0;i<nfam;i++)
98 // Lecture du nombre de groupes
99 med_int ngro = MEDnFamilyGroup(medIdt,meshname,i+1);
105 // Lecture de la famille
108 char familyname[MED_NAME_SIZE+1];
110 char* gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
111 erreur = MEDfamilyInfo(medIdt,
122 // Lecture des groupes pour une famille de mailles
125 for (int j=0;j<ngro;j++)
127 char str2[MED_LNAME_SIZE+1];
128 strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
129 str2[MED_LNAME_SIZE] = '\0';
130 ListeGroupes.insert(std::string(str2));
138 // Fermeture du fichier
139 if ( medIdt > 0 ) MEDfileClose(medIdt);
144 // =======================================================================
145 std::vector<double> GetBoundingBoxInMedFile(const char * aFile)
146 // =======================================================================
148 // Le vecteur en retour contiendra les informations suivantes :
149 // en position 0 et 1 Xmin, Xmax et en position 2 Dx si < 0 2D
150 // en position 3 et 4 Ymin, Ymax et en position 5 Dy si < 0 2D
151 // en position 6 et 7 Zmin, Zmax et en position 8 Dz si < 0 2D
152 // 9 distance max dans le maillage
154 std::vector<double> LesExtremes;
157 while ( erreur == 0 )
159 // Ouverture du fichier
160 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
166 //Nombre de maillage : on ne peut en lire qu'un seul
167 med_int numberOfMeshes = MEDnMesh(medIdt) ;
168 if (numberOfMeshes != 1 )
173 // Caracteristiques du maillage
174 char meshname[MED_NAME_SIZE+1];
175 med_int spacedim,meshdim;
176 med_mesh_type meshtype;
177 char descriptionription[MED_COMMENT_SIZE+1];
178 char dtunit[MED_SNAME_SIZE+1];
179 med_sorting_type sortingtype;
181 med_axis_type axistype;
182 int naxis = MEDmeshnAxis(medIdt,1);
183 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
184 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
185 erreur = MEDmeshInfo(medIdt,
200 if ( erreur < 0 ) { break ; }
204 med_int nnoe = MEDmeshnEntity(medIdt,
221 med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim);
223 erreur = MEDmeshNodeCoordinateRd(medIdt,
235 // Calcul des extremes
236 med_float xmin,xmax,ymin,ymax,zmin,zmax;
240 for (int i=1;i<nnoe;i++)
242 xmin = std::min(xmin,coo[i]);
243 xmax = std::max(xmax,coo[i]);
248 ymin=coo[nnoe]; ymax=coo[nnoe];
249 for (int i=nnoe+1;i<2*nnoe;i++)
251 ymin = std::min(ymin,coo[i]);
252 ymax = std::max(ymax,coo[i]);
265 zmin=coo[2*nnoe]; zmax=coo[2*nnoe];
266 for (int i=2*nnoe+1;i<3*nnoe;i++)
268 zmin = std::min(zmin,coo[i]);
269 zmax = std::max(zmax,coo[i]);
278 MESSAGE( "_______________________________________");
279 MESSAGE( "xmin : " << xmin << " xmax : " << xmax );
280 MESSAGE( "ymin : " << ymin << " ymax : " << ymax );
281 MESSAGE( "zmin : " << zmin << " zmax : " << zmax );
282 MESSAGE( "_______________________________________" );
283 double epsilon = 1.e-6 ;
284 LesExtremes.push_back(xmin);
285 LesExtremes.push_back(xmax);
286 LesExtremes.push_back(0);
287 LesExtremes.push_back(ymin);
288 LesExtremes.push_back(ymax);
289 LesExtremes.push_back(0);
290 LesExtremes.push_back(zmin);
291 LesExtremes.push_back(zmax);
292 LesExtremes.push_back(0);
295 double max1=std::max ( LesExtremes[1] - LesExtremes[0] , LesExtremes[4] - LesExtremes[3] ) ;
296 double max2=std::max ( max1 , LesExtremes[7] - LesExtremes[6] ) ;
297 LesExtremes.push_back(max2);
299 // LesExtremes[0] = Xmini du maillage
300 // LesExtremes[1] = Xmaxi du maillage
301 // LesExtremes[2] = increment de progression en X
302 // LesExtremes[3,4,5] : idem pour Y
303 // LesExtremes[6,7,8] : idem pour Z
304 // LesExtremes[9] = ecart maximal entre coordonnees
305 // On fait un traitement pour dans le cas d'une coordonnee constante
306 // inhiber ce cas en mettant un increment negatif
308 double diff = LesExtremes[1] - LesExtremes[0];
309 if ( fabs(diff) > epsilon*max2 ) { LesExtremes[2] = diff/100.; }
310 else { LesExtremes[2] = -1. ; }
312 diff = LesExtremes[4] - LesExtremes[3];
313 if ( fabs(diff) > epsilon*max2 ) { LesExtremes[5]=diff/100.; }
314 else { LesExtremes[5] = -1. ; }
316 diff = LesExtremes[7] - LesExtremes[6];
317 if ( fabs(diff) > epsilon*max2 ) { LesExtremes[8]=diff/100.; }
318 else { LesExtremes[8] = -1. ; }
320 MESSAGE ( "_______________________________________" );
321 MESSAGE ( "xmin : " << LesExtremes[0] << " xmax : " << LesExtremes[1] << " xincr : " << LesExtremes[2] );
322 MESSAGE ( "ymin : " << LesExtremes[3] << " ymax : " << LesExtremes[4] << " yincr : " << LesExtremes[5] );
323 MESSAGE ( "zmin : " << LesExtremes[6] << " zmax : " << LesExtremes[7] << " zincr : " << LesExtremes[8] );
324 MESSAGE ( "dmax : " << LesExtremes[9] );
325 MESSAGE ( "_______________________________________" );
330 // Fermeture du fichier
331 if ( medIdt > 0 ) MEDfileClose(medIdt);