1 /*----------------------------------------------------------------------------
2 MED MEDMEM : MED files in memory
4 Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
27 ----------------------------------------------------------------------------*/
32 #define MED_NOPG 1 /* -> pas de point de Gauss */
33 #define MED_NOPFL "" /* -> pas de profils utilisateur */
34 #define MED_NOPFLi " " /* Variable Interne */
35 #define MED_NOPF 0 /* -> pas de profils pour _MEDdataseNnumEcrire */
36 #define MED_NOPDT -1 /* rem: pas de pas de temps negatifs */
37 #define MED_NONOR -1 /* rem: pas de n°ordre negatif */
38 #define MED_DIM1 1 /* PAS */
42 int main (int argc, char **argv)
46 char maa[MED_TAILLE_NOM+1] = "maa1";
70 char nomcoo[3*MED_TAILLE_PNOM+1] = "x y z ";
71 char unicoo[3*MED_TAILLE_PNOM+1] = "cm cm cm ";
72 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
74 med_int numnoe[19] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
75 med_int nufano[19] = {1,1,3,3,0,0,2,0,4,0,4,2,4,2,4,2,4,1,3};
78 med_int tet4[12*4] = {
93 med_int numtet4[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
94 med_int nufatet4[12] = {-1,-1,-1,-1,0,0,0,0,0,0,-2,-3};
97 med_int pyra5[5*2] = {
101 char nompyra5[MED_TAILLE_PNOM*2+1] = "pyra1 pyra2 ";
102 med_int numpyra5[2] = {13,16};
103 med_int nufapyra5[2] = {0,-3};
106 med_int hexa8[8*2] = {
107 11,12,13,14,7,8,9,10,
108 15,16,17,18,11,12,13,14
110 char nomhexa8[MED_TAILLE_PNOM*2+1] = "hexa1 hexa2 ";
111 med_int numhexa8[2] = {14,15};
112 med_int nufahexa8[2] = {0,0};
114 char nomfam[MED_TAILLE_NOM+1];
116 char attdes[MED_TAILLE_DESC+1];
121 char gro[MED_TAILLE_LNOM+1];
122 char gro2[MED_TAILLE_LNOM*2+1];
123 char gro3[MED_TAILLE_LNOM*3+1];
130 Some fields : 2 on nodes : one int and one double , one on cells : double
132 char champ1[MED_TAILLE_NOM+1]="fieldnodeint" ;
133 char champ1_comp[MED_TAILLE_PNOM+1]="comp1 " ;
134 char champ1_unit[MED_TAILLE_PNOM+1]="M " ;
135 med_int fieldnodeint[19] = {1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7};
137 char champ2[MED_TAILLE_NOM+1]="fieldnodedouble" ;
138 char champ2_comp[MED_TAILLE_PNOM+1]="comp1 " ;
139 char champ2_unit[MED_TAILLE_PNOM+1]="J " ;
140 med_float fieldnodedouble1[19] = {1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.};
141 med_float fieldnodedouble2[19] = {1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,5.,5.,5.,6.,6.,6.,7.,7.,7.};
143 char champ3[MED_TAILLE_NOM+1]="fieldcelldoublevector" ;
144 char champ3_comp[MED_TAILLE_PNOM*3+1]="comp1 comp2 comp3 " ;
145 char champ3_unit[MED_TAILLE_PNOM*3+1]="m/s m/s m/s " ;
146 med_float fieldcelldouble1[12*3] = {1.,1.,1.,2.,2.,2.,3.,3.,3.,4.,4.,4.,0.,0.,0.,1.,1.,1.,0.,0.,0.,1.,1.,1.,1.,1.,1.,0.,0.,0.,1.,1.,1.,0.,0.,0.};
147 med_float fieldcelldouble2[2*3] = {5.,5.,0.,1.,0.,1.};
148 med_float fieldcelldouble3[2*3] = {6.,6.,1.,0.,1.,0.};
150 char champ4[MED_TAILLE_NOM+1]="fieldcelldoublescalar" ;
151 char champ4_comp[MED_TAILLE_PNOM+1]="comp1 " ;
152 char champ4_unit[MED_TAILLE_PNOM+1]="m/s " ;
153 med_float fieldcelldouble4[12] = {1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
154 med_float fieldcelldouble5[2] = {2.,2.};
155 med_float fieldcelldouble6[2] = {3.,3.};
157 /***************************************************************************/
158 fid = MEDouvrir("pointe.med",MED_REMP);
163 printf("MEDouvrir : %d\n",ret);
165 /***************************************************************************/
167 ret = MEDmaaCr(fid,maa,mdim);
168 printf("MEDmaaCr : %d\n",ret);
170 ret = MEDunvCr(fid,maa);
171 printf("MEDunvCr : %d\n",ret);
173 /***************************************************************************/
175 ret = MEDnoeudsEcr(fid,maa,mdim,coo,MED_FULL_INTERLACE,MED_CART,
176 nomcoo,unicoo,nomnoe,MED_FAUX,numnoe,MED_VRAI,
177 nufano,nnoe,MED_ECRI);
178 printf("MEDnoeudsEcr : %d\n",ret);
181 /***************************************************************************/
182 /* ecriture des mailles MED_TETRA4 :
185 - numeros (optionnel)
186 - numeros des familles */
188 ret = MEDelementsEcr(fid,maa,mdim,tet4,MED_FULL_INTERLACE,
189 nomtet4,MED_FAUX,numtet4,MED_VRAI,nufatet4,ntet4,
190 MED_MAILLE,MED_TETRA4,MED_NOD,MED_ECRI);
191 printf("MEDelementsEcr : %d \n",ret);
193 /* ecriture des mailles MED_PYRA5 :
196 - numeros (optionnel)
197 - numeros des familles */
199 ret = MEDelementsEcr(fid,maa,mdim,pyra5,MED_FULL_INTERLACE,
200 nompyra5,MED_VRAI,numpyra5,MED_VRAI,nufapyra5,npyra5,
201 MED_MAILLE,MED_PYRA5,MED_NOD,MED_ECRI);
202 printf("MEDelementsEcr : %d \n",ret);
204 /* ecriture des mailles MED_HEXA8 :
207 - numeros (optionnel)
208 - numeros des familles */
210 ret = MEDelementsEcr(fid,maa,mdim,hexa8,MED_FULL_INTERLACE,
211 nomhexa8,MED_FAUX,numhexa8,MED_VRAI,nufahexa8,nhexa8,
212 MED_MAILLE,MED_HEXA8,MED_NOD,MED_ECRI);
213 printf("MEDelementsEcr : %d \n",ret);
215 /***************************************************************************/
216 /* ecriture des familles */
218 - toujours creer une famille de numero 0 ne comportant aucun attribut
219 ni groupe (famille de reference pour les noeuds ou les elements
220 qui ne sont rattaches a aucun groupe ni attribut)
221 - les numeros de familles de noeuds sont > 0
222 - les numeros de familles des elements sont < 0
223 - rien d'imposer sur les noms de familles
229 strcpy(nomfam,"FAMILLE_0");
231 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
234 printf("MEDfamCr : %d \n",ret);
237 - 3 familles d'elements (-1,-2,-3) et
238 - 2 familles de noeuds (1,2)
243 for (i=0;i<nfame;i++)
247 strcpy(nomfam,"FAMILLE_ELEMENT_");
249 sprintf(nomfam,"%s%d",nomfam,-numfam);
253 strcpy(attdes,"description attribut");
254 strcpy(gro,"groupe1");
256 /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
257 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
259 printf("MEDfamCr : %d\n",ret);
266 strcpy(nomfam,"FAMILLE_NOEUD_1");
271 strcpy(attdes,"description attribut");
272 strcpy(gro2,"groupe2");
273 strcpy(gro2+MED_TAILLE_LNOM,"groupe3");
275 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
277 printf("MEDfamCr : %d\n",ret);
281 strcpy(nomfam,"FAMILLE_NOEUD_2");
286 strcpy(attdes,"description attribut");
287 strcpy(gro2,"groupe3");
288 strcpy(gro2+MED_TAILLE_LNOM,"groupe4");
290 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
292 printf("MEDfamCr : %d\n",ret);
296 strcpy(nomfam,"FAMILLE_NOEUD_3");
301 strcpy(attdes,"description attribut");
302 strcpy(gro2,"groupe2");
303 strcpy(gro2+MED_TAILLE_LNOM,"groupe4");
305 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
307 printf("MEDfamCr : %d\n",ret);
311 strcpy(nomfam,"FAMILLE_NOEUD_4");
316 strcpy(attdes,"description attribut");
317 strcpy(gro,"groupe5");
319 ret = MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
321 printf("MEDfamCr : %d\n",ret);
324 /***************************************************************************/
330 ret = MEDchampCr(fid,champ1,MED_INT32,champ1_comp,champ1_unit,1);
331 printf("MEDchampCr : %d \n",ret);
333 ret = MEDchampEcr(fid, maa, champ1, (unsigned char *)fieldnodeint,
334 MED_NO_INTERLACE, nnoe,
335 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD,
336 0, MED_NOPDT," ", 0., MED_NONOR);
338 printf("MEDchampEcr : %d \n",ret);
344 ret = MEDchampCr(fid,champ2,MED_REEL64,champ2_comp,champ2_unit,1);
345 printf("MEDchampCr : %d \n",ret);
347 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
348 MED_NO_INTERLACE, nnoe,
349 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD,
350 0, 1,"S ", 1.1 , MED_NONOR);
351 printf("MEDchampEcr1 : %d \n",ret);
352 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble2,
353 MED_NO_INTERLACE, nnoe,
354 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD,
355 0, 2,"S ", 1.2 , MED_NONOR);
356 printf("MEDchampEcr2 : %d \n",ret);
360 // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
363 /* ret = MEDchampCr(fid,champ2,MED_REEL64,champ2_comp,champ2_unit,1); */
364 /* printf("MEDchampCr : %d \n",ret); */
366 ret = MEDchampEcr(fid, maa, champ2, (unsigned char *)fieldnodedouble1,
367 MED_NO_INTERLACE, nnoe,
368 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_NOEUD,
369 0, MED_NOPDT," ", 0. , MED_NONOR);
370 printf("MEDchampEcr : %d \n",ret);
376 ret = MEDchampCr(fid,champ3,MED_REEL64,champ3_comp,champ3_unit,3);
377 printf("MEDchampCr : %d \n",ret);
379 ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble1,
380 MED_NO_INTERLACE, ntet4,
381 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE,
382 MED_TETRA4, MED_NOPDT," ", 0., MED_NONOR);
383 printf("MEDchampEcr : %d \n",ret);
384 ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble3,
385 MED_NO_INTERLACE, nhexa8,
386 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE,
387 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
388 printf("MEDchampEcr : %d \n",ret);
389 ret = MEDchampEcr(fid, maa, champ3, (unsigned char *)fieldcelldouble2,
390 MED_NO_INTERLACE, npyra5,
391 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE,
392 MED_PYRA5, MED_NOPDT," ", 0., MED_NONOR);
393 printf("MEDchampEcr : %d \n",ret);
399 ret = MEDchampCr(fid,champ4,MED_REEL64,champ4_comp,champ4_unit,1);
400 printf("MEDchampCr : %d \n",ret);
402 ret = MEDchampEcr(fid, maa, champ4, (unsigned char *)fieldcelldouble4,
403 MED_NO_INTERLACE, ntet4,
404 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE,
405 MED_TETRA4, MED_NOPDT," ", 0., MED_NONOR);
406 printf("MEDchampEcr : %d \n",ret);
407 ret = MEDchampEcr(fid, maa, champ4, (unsigned char *)fieldcelldouble6,
408 MED_NO_INTERLACE, nhexa8,
409 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE,
410 MED_HEXA8, MED_NOPDT," ", 0., MED_NONOR);
411 printf("MEDchampEcr : %d \n",ret);
412 ret = MEDchampEcr(fid, maa, champ4, (unsigned char *)fieldcelldouble5,
413 MED_NO_INTERLACE, npyra5,
414 MED_NOPG, MED_ALL, MED_NOPFL, MED_ECRI, MED_MAILLE,
415 MED_PYRA5, MED_NOPDT," ", 0., MED_NONOR);
416 printf("MEDchampEcr : %d \n",ret);
420 /***************************************************************************/
421 ret = MEDfermer(fid);
422 printf("MEDfermer : %d\n",ret);