1 /*************************************************************************
2 * COPYRIGHT (C) 1999 - 2003 EDF R&D
3 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
4 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE
5 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
6 * EITHER 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, BUT
9 * 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 LICENSE
14 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
15 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
17 *************************************************************************/
18 #include "MEDMEM_medimport_src.hxx"
20 using namespace med_2_2;
21 using namespace MEDMEM;
24 extern med_err MEDgaussInfo(med_idt fid, int indice, char * locname,
25 med_geometrie_element * type_geo,
28 extern void _MEDmodeErreurVerrouiller(void);
30 extern med_err _MEDnomGeometrie(char *nom_geo,
31 med_geometrie_element type_geo);
34 med_err med_2_2::OLD_MEDattrNumLire(med_idt pere, med_type_champ type,
35 char *nom, unsigned char *val,
42 if ((attid = H5Aopen_name(pere,nom)) < 0)
48 #if defined(PCLINUX) || defined(OSF1)
49 /* type_hdf = H5T_IEEE_F64BE; */
50 if (H5Tequal(hdf_file,H5T_IEEE_F64BE))
51 type_hdf = H5T_IEEE_F64LE;
52 if (H5Tequal(hdf_file,H5T_IEEE_F64LE))
53 type_hdf = H5T_IEEE_F64BE;
55 /* type_hdf = H5T_IEEE_F64LE; */
56 if (H5Tequal(hdf_file,H5T_IEEE_F64BE))
57 type_hdf = H5T_IEEE_F64LE;
58 if (H5Tequal(hdf_file,H5T_IEEE_F64LE))
59 type_hdf = H5T_IEEE_F64BE;
64 #if defined(IRIX64) || defined(OSF1)
65 type_hdf = H5T_NATIVE_LONG;
67 type_hdf = H5T_NATIVE_INT;
75 if ((ret = H5Aread(attid,type_hdf,val)) < 0)
78 if ((ret = H5Aclose(attid)) < 0)
85 med_err med_2_2::OLD_MEDdatasetNumLire(med_idt pere, char *nom,
87 med_mode_switch interlace,
88 med_size nbdim, med_size fixdim,
89 med_size psize, med_ssize * pfltab,
91 unsigned char *val,hid_t hdf_file)
93 med_idt dataset, dataspace = 0, memspace = 0;
94 med_ssize start_mem[1],start_data[1],*pflmem=0,*pfldsk=0;
95 med_size stride[1],count[1],pcount[1],size[1],pflsize[1];
97 int i,j,index,type_hdf;
100 int dim, firstdim, dimutil, lastdim;
101 med_mode_profil pflmod;
103 /* Verify fixdim is between [0, nbdim] ( 0 is MED_ALL ) */
104 if ( ( fixdim < 0 ) || ( fixdim > nbdim ) )
107 /* block pflmod to MED_COMPACT (until med2.2) */
108 pflmod = MED_COMPACT;
113 /* 1) IA32 is LE but due to an (?HDF convertion BUG?) when using H5T_NATIVE_DOUBLE/MED_REEL64? under PCLINUX
114 the file read under SGI is incorrect
115 2) Compaq OSF/1 is LE, since we force SGI64,SUN4SOL2,HP to write double in LE even if they are BE, mips OSF/1 must be BE
116 REM : Be careful of compatibility between MED files when changing this (med2.2) */
117 #if defined(PCLINUX) || defined(OSF1)
118 /* type_hdf = H5T_IEEE_F64BE; */
119 if (H5Tequal(hdf_file,H5T_IEEE_F64BE))
120 type_hdf = H5T_IEEE_F64LE;
121 if (H5Tequal(hdf_file,H5T_IEEE_F64LE))
122 type_hdf = H5T_IEEE_F64BE;
124 /* type_hdf = H5T_IEEE_F64LE; */
125 if (H5Tequal(hdf_file,H5T_IEEE_F64BE))
126 type_hdf = H5T_IEEE_F64LE;
127 if (H5Tequal(hdf_file,H5T_IEEE_F64LE))
128 type_hdf = H5T_IEEE_F64BE;
133 type_hdf = H5T_NATIVE_INT;
137 type_hdf = H5T_NATIVE_LONG;
144 /* Ouverture du Dataset à lire */
145 if ((dataset = H5Dopen(pere,nom)) < 0)
148 /* Interrogation de la taille du dataset */
149 if ( (datatype = H5Dget_type(dataset )) < 0) return -1;
150 if ( (typesize = H5Tget_size(datatype)) < 0) return -1;
151 size[0] = H5Dget_storage_size(dataset) / typesize;
152 if ( H5Tclose(datatype) < 0) return -1;
154 /* Create dataspace */
155 if ((dataspace = H5Screate_simple(1,size,NULL)) < 0)
160 case MED_FULL_INTERLACE :
162 /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/
163 if ( fixdim != MED_ALL)
174 count [0] = (*size)/(nbdim);
177 /*rem: Pas de vérification de l'assertion (*size)=n*nbdim */
178 if ( psize == MED_NOPF ) {
180 /* Creation d'un data space mémoire de dimension 1, de longeur size, et de longeur maxi size */
181 if ( (memspace = H5Screate_simple (1, size, NULL)) <0)
186 for (dim=firstdim; dim < lastdim; dim++) {
189 if ( (ret = H5Sselect_hyperslab (memspace, H5S_SELECT_SET, start_mem, stride,
193 start_data[0] = dim*count[0];
194 if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL,
198 if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,
199 H5P_DEFAULT, val)) < 0)
205 pflsize [0] = psize*ngauss*nbdim;
206 pcount [0] = psize*ngauss*dimutil;
207 pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]);
208 pfldsk = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]);
211 { /* switch pflmod pour FULL_INTERLACE*/
214 /* Creation d'un data space mémoire de dimension 1, de longeur size, et de longeur maxi size */
215 if ( (memspace = H5Screate_simple (1, size, NULL)) <0)
218 for (dim=firstdim; dim < lastdim; dim++) {
220 for (i=0; i < psize; i++) /* i balaye les élements du profil */
221 for (j=0; j < ngauss; j++) {
222 index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
223 pflmem[index] = (pfltab[i]-1)*ngauss*nbdim + j*nbdim+dim;
224 pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j;
228 if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0)
231 if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0)
238 /* Creation d'un data space mémoire de dimension 1, de la longeur du profil */
239 /* La dimension utilisée est ici nbdim, même pour un profil compact on suppose */
240 /* que l'utilisateur a toutes les coordonées stockées, même si il en demande qu'une */
242 if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0)
245 for (dim=firstdim; dim < lastdim; dim++) {
247 for (i=0; i < psize; i++) /* i balaye les élements du profil */
248 for (j=0; j < ngauss; j++) {
249 index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
250 pflmem[index] = i*ngauss*nbdim + j*nbdim+dim;
251 pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j;
255 if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0)
258 if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0)
267 if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0)
276 case MED_NO_INTERLACE :
278 /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/
280 count[0] = (*size)/nbdim;
282 if ( psize == MED_NOPF ) {
284 if ( fixdim != MED_ALL)
285 start_data[0] = (fixdim-1)*count[0];
291 if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL,
295 if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,
296 H5P_DEFAULT, val)) < 0)
301 if ( fixdim != MED_ALL)
312 pflsize [0] = psize*ngauss*nbdim;
313 pcount [0] = psize*ngauss*dimutil; /* nom pas très coherent avec count !!! A revoir */
314 pfldsk = (med_ssize *) malloc(sizeof(med_ssize)*pcount[0]);
317 { /*switch plfmod pour NO_INTERLACE */
320 for (dim=firstdim; dim < lastdim; dim++) {
322 for (i=0; i < psize; i++) /* i balaye le nbre d'élements du profil */
323 for (j=0; j < ngauss; j++) {
324 index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
325 pfldsk[index] = dim*count[0]+(pfltab[i]-1)*ngauss+j;
329 if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0)
332 if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,H5P_DEFAULT, val)) < 0)
339 /* Creation d'un data space mémoire de dimension 1, de la longeur du profil */
340 /* La dimension utilisée est ici nbdim, même pour un profil compact on suppose */
341 /* que l'utilisateur a toutes les coordonées stockées, même si il en demande qu'une */
343 if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0)
346 pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]);
348 /* Le profil COMPACT est contigüe, mais il est possible que l'on selectionne uniquemenent une dimension*/
350 for (dim=firstdim; dim < lastdim; dim++) {
352 for (i=0; i < psize; i++) /* i balaye le nbre d'élements du profil */
353 for (j=0; j < ngauss; j++) {
354 index = i*ngauss+j + (dim-firstdim)*(psize*ngauss);
355 pflmem[index] = dim*(psize*ngauss) + (pfltab[i]-1)*ngauss+j;
356 pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j;
360 if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0)
363 if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0)
366 if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0)
389 if ((ret = H5Sclose(memspace)) < 0)
392 if ((ret = H5Sclose(dataspace)) < 0)
395 if ((ret = H5Dclose(dataset)) < 0)
402 void med_2_2::conversion_chaine(char *ancienne_chaine,
403 char *nouvelle_chaine,
408 char tmp[MED_TAILLE_PNOM+1];
412 strcpy(tmp,ancienne_chaine+i*ANCIEN_MED_TAILLE_PNOM);
413 if (strlen(tmp) < ANCIEN_MED_TAILLE_PNOM)
414 for(j=strlen(tmp);j<ANCIEN_MED_TAILLE_PNOM;j++)
418 strncpy(tmp,ancienne_chaine+i*ANCIEN_MED_TAILLE_PNOM,ANCIEN_MED_TAILLE_PNOM);
419 tmp[ANCIEN_MED_TAILLE_PNOM] = '\0';
422 /* printf("[%s]\n",tmp); */
424 strcpy(nouvelle_chaine,tmp);
426 strcat(nouvelle_chaine,tmp);
428 *(nouvelle_chaine+MED_TAILLE_PNOM*n) = '\0';
431 void med_2_2::MAJ_version(med_idt fid) throw (MEDEXCEPTION)
435 med_int majeur, mineur, release;
437 /* On ecrit le bon numero de version */
441 gid = _MEDdatagroupOuvrir(fid,MED_NOM_INFOS);
443 gid = _MEDdatagroupCreer(fid,MED_NOM_INFOS);
445 // EXIT_IF(gid < 0,"Ouverture du groupe HDF MED_NOM_INFOS",NULL);
448 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
450 ret = _MEDattrEntierEcrire(gid,MED_NOM_MAJEUR,&majeur);
452 // EXIT_IF(ret < 0,"Ecriture du numéro majeur",NULL);
455 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
457 ret = _MEDattrEntierEcrire(gid,MED_NOM_MINEUR,&mineur);
459 // EXIT_IF(ret < 0,"Ecriture du numéro mineur",NULL);
462 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
464 ret = _MEDattrEntierEcrire(gid,MED_NOM_RELEASE,&release);
466 // EXIT_IF(ret < 0,"Ecrriture du numéro de release",NULL);
469 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
471 ret = _MEDdatagroupFermer(gid);
473 // EXIT_IF(ret < 0,"Fermeture du groupe HDF MED_NOM_INFOS",NULL);
476 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
480 void med_2_2::MAJ_noeuds_maillage(med_idt mid, med_int dimension)
483 med_idt nid, gid, tid;
486 char tmp[MED_TAILLE_PNOM+1];
487 char *nouvelle_chaine;
495 /* Accès aux noeuds du maillage */
496 nid = _MEDdatagroupOuvrir(mid,MED_NOM_NOE);
498 // EXIT_IF(nid < 0,"Ouverture du groupe HDF MED_NOM_NOE",NULL);
501 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
503 /* Lecture du nombre de noeuds */
504 gid = _MEDdatasetOuvrir(nid,MED_NOM_COO);
506 ret = _MEDattrEntierLire(gid,MED_NOM_NBR,&n);
508 // EXIT_IF(gid < 0,"Lecture du nombre de noeuds",NULL);
511 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
513 /* Mise a jour des coordonnees */
514 /* On cree un groupe HDF tampon */
515 /* Lecture des coordonnées */
516 hdf_type = H5Dget_type(gid);
518 // EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des coordonnées",NULL);
521 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
523 coo = (med_float *) malloc(sizeof(med_float)*n*dimension);
525 // EXIT_IF(coo == NULL,NULL,NULL);
528 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
530 ret = OLD_MEDdatasetNumLire(nid,MED_NOM_COO,MED_FLOAT64,
531 MED_FULL_INTERLACE,dimension,MED_ALL,
533 (unsigned char*) coo,hdf_type);
535 // EXIT_IF(ret < 0,"Lecture des coordonnées des noeuds",NULL);
538 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
540 dimd[0] = n*dimension;
541 /* printf("EGALITE des types : %d \n",H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)); */
542 /* printf("Avant conversion : [%f] [%f] [%f] \n",*(coo),*(coo+1),*(coo+2)); */
543 if (! H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)) {
544 ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)coo,NULL,0);
545 /* printf("Après conversion éventuelle : [%f] [%f] [%f] \n",*(coo),*(coo+1),*(coo+2)); */
547 // EXIT_IF(ret < 0,"Conversion des coordonnées des noeuds",NULL);
550 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
552 ret = H5Tclose(hdf_type);
554 // EXIT_IF(ret < 0,"Fermeture du data type HDF",NULL);
557 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
559 /* On reporte les coordonnées dans le groupe HDF TMP */
560 ret = _MEDdatasetNumEcrire(nid,"TMP",MED_FLOAT64,MED_FULL_INTERLACE,
561 dimension,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
562 (unsigned char*) coo);
564 // EXIT_IF(ret < 0,"Ecriture des coordonnées des noeuds après conversion",NULL);
567 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
571 /* Ecriture du nombre de noeuds et du type du repertoire dans le dataset TMP */
572 tid = _MEDdatasetOuvrir(nid,"TMP");
574 // EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL);
577 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
579 ret = _MEDattrEntierEcrire(tid,MED_NOM_NBR,&n);
581 // EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL);
584 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
586 ret = _MEDattrEntierLire(gid,MED_NOM_REP,&repere);
588 // EXIT_IF(ret < 0,"Lecture du type de repere des coordonnées", NULL);
591 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
593 ret = _MEDattrEntierEcrire(tid,MED_NOM_REP,&repere);
595 // EXIT_IF(ret < 0,"Ecriture du type de répertoire dans le dataset HDF TMP",NULL);
598 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
600 /* Mise a jour des noms et types des unités des coordonnees */
601 nom = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1);
603 // EXIT_IF(nom == NULL,NULL,NULL);
606 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
608 unit = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1);
610 // EXIT_IF(unit == NULL,NULL,NULL);
613 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
615 nouvelle_chaine = (char *) malloc(dimension*MED_TAILLE_PNOM+1);
617 // EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
619 if(nouvelle_chaine == NULL)
620 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
622 ret = _MEDattrStringLire(gid,MED_NOM_NOM,dimension*ANCIEN_MED_TAILLE_PNOM,nom);
624 // EXIT_IF(ret < 0,"Lecture des noms des coordonnées des noeuds",NULL);
627 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
629 ret = _MEDattrStringLire(gid,MED_NOM_UNI,dimension*ANCIEN_MED_TAILLE_PNOM,unit);
631 // EXIT_IF(ret < 0,"Lecture des unités des coordonnées des noeuds",NULL);
634 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
636 conversion_chaine(nom,nouvelle_chaine,dimension);
637 ret = _MEDattrStringEcrire(tid,MED_NOM_NOM,dimension*MED_TAILLE_PNOM,nouvelle_chaine);
639 // EXIT_IF(ret < 0,"Ecriture des nouveaux noms des coordonnées des noeuds",NULL);
642 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
644 conversion_chaine(unit,nouvelle_chaine,dimension);
645 ret = _MEDattrStringEcrire(tid,MED_NOM_UNI,dimension*MED_TAILLE_PNOM,nouvelle_chaine);
647 // EXIT_IF(ret < 0,"Ecriture des nouvelles unités des coordonnées des noeuds",NULL);
650 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
654 free(nouvelle_chaine);
656 /* Fermeture de l'accès aux coordonnées */
657 ret = _MEDdatasetFermer(gid);
659 // EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_COO",NULL);
662 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
664 ret = H5Gunlink(nid,MED_NOM_COO);
666 // EXIT_IF(ret < 0,"Suppression des anciennes coordonnées",NULL);
669 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
671 ret = _MEDdatasetFermer(tid);
673 // EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL);
676 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
678 ret = H5Gmove(nid,"TMP",MED_NOM_COO);
680 // EXIT_IF(ret < 0,"Mise en place des nouvelles coordonnées",NULL);
683 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
685 /* Mise a jour des noms des noeuds */
686 nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1);
688 // EXIT_IF(nom == NULL,NULL,NULL);
691 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
693 nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1);
695 // EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
697 if(nouvelle_chaine == NULL)
698 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
700 ret = _MEDdatasetStringLire(nid,MED_NOM_NOM,nom);
702 conversion_chaine(nom,nouvelle_chaine,n);
703 H5Gunlink(nid,MED_NOM_NOM);
704 dimd[0] = n*MED_TAILLE_PNOM+1;
705 ret = _MEDdatasetStringEcrire(nid,MED_NOM_NOM,dimd,nouvelle_chaine);
707 // EXIT_IF(ret < 0,"Ecriture des nouveaux noms des noeuds",NULL);
710 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
712 gid = _MEDdatasetOuvrir(nid,MED_NOM_NOM);
713 ret = _MEDattrEntierEcrire(gid,MED_NOM_NBR,&n);
714 ret = _MEDdatasetFermer(gid);
717 free(nouvelle_chaine);
720 ret = _MEDdatagroupFermer(nid);
722 // EXIT_IF(ret < 0,"Fermeture de l'accès aux noeuds",NULL);
725 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
728 void med_2_2::MAJ_elements_maillage(med_idt mid, med_int dimension)
731 med_idt eid,gid,did,tid;
734 med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE] = {MED_POINT1,MED_SEG2,
737 MED_QUAD8,MED_TETRA4,
738 MED_TETRA10,MED_HEXA8,
739 MED_HEXA20,MED_PENTA6,
740 MED_PENTA15,MED_PYRA5,
743 char *nom, *nouvelle_chaine;
744 char nomgroup[MED_TAILLE_NOM_ENTITE+1];
747 med_int *old_conn,*conn;
749 /* On ne regarde que les mailles et la connectivité nodale */
750 eid = _MEDdatagroupOuvrir(mid,MED_NOM_MAI);
752 // EXIT_IF(eid < 0,"Ouverture du groupe HDF MED_NOM_MAI",NULL);
755 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
757 /* On normalise selon tous les types geometriques */
758 for (i=0;i<MED_NBR_GEOMETRIE_MAILLE;i++) {
760 /* On recupere le nom du groupe HDF */
761 _MEDnomGeometrie(nomgroup,typmai[i]);
763 /* On accède au type s'il existe dans le fichier */
764 gid = _MEDdatagroupOuvrir(eid,nomgroup);
768 /* Nombre d'element ? */
769 did = _MEDdatasetOuvrir(gid,MED_NOM_NOD);
771 // EXIT_IF(did < 0,"Ouverture du dataset HDF MED_NOM_NOD",NULL);
774 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
776 ret = _MEDattrEntierLire(did,MED_NOM_NBR,&n);
778 // EXIT_IF(ret < 0,"Lecture du nombre d'elements",NULL);
781 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
783 ret = _MEDdatasetFermer(did);
785 // EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_NOD",NULL);
788 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
790 /* on normalise la connectivité si edim < dimension */
791 edim = typmai[i] / 100;
792 if (edim < dimension) {
793 taille = typmai[i]%100 + 1;
794 old_conn = (med_int *) malloc(sizeof(med_int)*taille*n);
796 // EXIT_IF(old_conn == NULL,NULL,NULL);
799 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
801 #if defined(IRIX64)||defined(OSF1)
802 ret = OLD_MEDdatasetNumLire(gid,MED_NOM_NOD,MED_INT64,
803 MED_NO_INTERLACE,(med_size)taille,MED_ALL,
805 (unsigned char*) old_conn,H5T_NATIVE_INT);
807 ret = OLD_MEDdatasetNumLire(gid,MED_NOM_NOD,MED_INT32,
808 MED_NO_INTERLACE,(med_size) taille,MED_ALL,
810 (unsigned char*) old_conn,H5T_NATIVE_INT);
812 /* On recopie dans le bon tableau */
814 conn = (med_int *) malloc(sizeof(med_int)*taille*n);
816 // EXIT_IF(conn == NULL,NULL,NULL);
819 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
821 for (j=0;j<n*taille;j++)
822 *(conn+j) = *(old_conn+j);
824 #if defined(IRIX64)||defined(OSF1)
825 ret = _MEDdatasetNumEcrire(gid,"TMP",MED_INT64,MED_NO_INTERLACE,
826 taille,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
827 (unsigned char*) conn);
829 ret = _MEDdatasetNumEcrire(gid,"TMP",MED_INT32,MED_NO_INTERLACE,
830 taille,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
831 (unsigned char*) conn);
834 // EXIT_IF(ret < 0,"Ecriture de la nouvelle connectivité des mailles",NULL);
837 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
839 /* Ecriture du nombre de mailles dans le dataset HDF TMP */
840 tid = _MEDdatasetOuvrir(gid,"TMP");
842 // EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL);
845 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
847 ret = _MEDattrEntierEcrire(tid,MED_NOM_NBR,&n);
849 // EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL);
852 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
854 ret = _MEDdatasetFermer(tid);
856 // EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL);
859 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
861 /* Fermeture de l'accès aux connectivites */
862 ret = H5Gunlink(gid,MED_NOM_NOD);
864 // EXIT_IF(ret < 0,"Suppression des anciennes connectivités",NULL);
867 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
869 ret = H5Gmove(gid,"TMP",MED_NOM_NOD);
871 // EXIT_IF(ret < 0,"Mise en place des nouvelles connectivités",NULL);
874 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
876 /* on libere la memoire */
881 /* Mise a niveau des noms */
882 nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1);
884 // EXIT_IF(nom == NULL,NULL,NULL);
887 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
889 nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1);
891 // EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
893 if(nouvelle_chaine == NULL)
894 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
896 ret = _MEDdatasetStringLire(gid,MED_NOM_NOM,nom);
898 conversion_chaine(nom,nouvelle_chaine,n);
899 H5Gunlink(gid,MED_NOM_NOM);
900 dimd[0] = n*MED_TAILLE_PNOM+1;
901 ret = _MEDdatasetStringEcrire(gid,MED_NOM_NOM,dimd,nouvelle_chaine);
903 // EXIT_IF(ret < 0,"Ecriture des nouveaux noms des éléments",NULL);
906 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
908 did = _MEDdatasetOuvrir(gid,MED_NOM_NOM);
909 ret = _MEDattrEntierEcrire(did,MED_NOM_NBR,&n);
910 ret = _MEDdatasetFermer(did);
913 free(nouvelle_chaine);
915 /* on ferme avant de passer au type geometrique suivant */
916 ret = _MEDdatagroupFermer(gid);
918 // EXIT_IF(ret < 0,"Fermeture de l'accès aux mailles",NULL);
921 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
925 ret = _MEDdatagroupFermer(eid);
927 // EXIT_IF(ret < 0,"Fermeture de l'accès aux mailles",NULL);
930 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
933 void med_2_2::MAJ_familles_maillage(med_idt mid) throw (MEDEXCEPTION)
936 char *nouvelle_chaine;
941 char chemin[MED_TAILLE_FAS+2*MED_TAILLE_NOM+1];
942 char nom[MED_TAILLE_NOM+1];
943 char *noeuds, *elements;
947 char *groupe_noeuds = "NOEUD";
948 char *groupe_elements = "ELEME";
949 char *nom_famille_zero = "FAMILLE_ZERO";
950 char famille0[MED_TAILLE_NOM+1];
951 int *index_noeuds, *index_elements;
952 char stockage[MED_TAILLE_DESC];
955 /* Combien de famille ? */
956 fid = _MEDdatagroupOuvrir(mid,"FAS");
958 // EXIT_IF(fid < 0,"Ouverture du groupe HDF 'FAS'",NULL);
961 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
964 _MEDnObjets(fid,".",&n);
966 // EXIT_IF(n < 0,"Lecture du nombre de famille",NULL);
969 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
971 noeuds = (char *) malloc(n*MED_TAILLE_NOM+1);
973 // EXIT_IF(noeuds == NULL,NULL,NULL);
976 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
978 index_noeuds = (int *) malloc(sizeof(int)*(n+1));
980 // EXIT_IF(index_noeuds == NULL,NULL,NULL);
983 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
985 elements = (char *) malloc(n*MED_TAILLE_NOM+1);
987 // EXIT_IF(elements == NULL,NULL,NULL);
990 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
992 index_elements = (int *) malloc(sizeof(int)*(n+1));
994 // EXIT_IF(index_elements == NULL,NULL,NULL);
996 if(index_elements == NULL)
997 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
999 /* On recupere les familles une par une et on les
1002 ret = _MEDobjetIdentifier(fid,".",i,nom);
1004 // EXIT_IF(ret < 0,"Identification d'une famille",NULL);
1007 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1009 /* On accede a la famille */
1010 gid = _MEDdatagroupOuvrir(fid,nom);
1012 // EXIT_IF(gid < 0,"Ouverture de l'accès à la famille",nom);
1015 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1017 /* On lit le numero de la famille */
1018 ret = _MEDattrEntierLire(gid,MED_NOM_NUM,&numero);
1020 // EXIT_IF(ret < 0,"Lecture du numéro de la famille",nom);
1023 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1025 /* On ferme l'acces a la famille */
1026 ret = _MEDdatagroupFermer(gid);
1028 // EXIT_IF(ret < 0,"Fermeture de l'accès a la famille",nom);
1031 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1034 strcpy(famille0,nom);
1037 if (nelements == 0) {
1038 *(index_elements) = 0;
1039 strcpy(elements,nom);
1042 strcat(elements,nom);
1044 *(index_elements+nelements) = strlen(nom) + *(index_elements+nelements-1);
1050 *(index_noeuds) = 0;
1055 *(index_noeuds+nnoeuds) = strlen(nom) + *(index_noeuds+nnoeuds-1);
1059 /* Normalisation de la famille 0 */
1060 ret = H5Gmove(fid,famille0,nom_famille_zero);
1062 // EXIT_IF(ret < 0,"Normalisation de la famille ZERO",NULL);
1065 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1067 /* On cree les groupes HDF pour les familles de noeuds et d'elements */
1068 gid = _MEDdatagroupCreer(fid,groupe_noeuds);
1070 // EXIT_IF(gid < 0,"Creation du grupe HDF pour les familles de noeuds",NULL);
1073 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1075 ret = _MEDdatagroupFermer(gid);
1077 // EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles de noeuds",NULL);
1080 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1082 gid = _MEDdatagroupCreer(fid,groupe_elements);
1084 // EXIT_IF(gid < 0,"Creation du groupe HDF pour les familles d'éléments",NULL);
1087 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1089 ret = _MEDdatagroupFermer(gid);
1091 // EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles d'éléments",NULL);
1094 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1096 /* On deplace les groupes HDF des familles en fonction de la nature de
1098 for (i=0;i<nnoeuds;i++) {
1099 strncpy(nom,noeuds+*(index_noeuds+i),*(index_noeuds+i+1)-*(index_noeuds+i));
1100 nom[*(index_noeuds+i+1)-*(index_noeuds+i)] = '\0';
1101 strcpy(stockage,groupe_noeuds);
1102 strcat(stockage,"/");
1103 strcat(stockage,nom);
1104 ret = H5Gmove(fid,nom,stockage);
1106 // EXIT_IF(ret < 0,"Normalisation de la famille",nom);
1109 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1112 for (i=0;i<nelements;i++) {
1113 strncpy(nom,elements+*(index_elements+i),*(index_elements+i+1)-*(index_elements+i));
1114 nom[*(index_elements+i+1)-*(index_elements+i)] = '\0';
1115 strcpy(stockage,groupe_elements);
1116 strcat(stockage,"/");
1117 strcat(stockage,nom);
1118 ret = H5Gmove(fid,nom,stockage);
1120 // EXIT_IF(ret < 0,"Normalisation de la famille",nom);
1123 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1126 /* On libere la memoire */
1130 free(index_elements);
1133 ret = _MEDdatagroupFermer(fid);
1135 // EXIT_IF(ret < 0,"Fermeture du groupe HDF 'FAS'",NULL);
1138 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1141 void med_2_2::MAJ_maillages(med_idt fid) throw (MEDEXCEPTION)
1146 char nom[MED_TAILLE_NOM+1];
1147 char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
1148 char description[MED_TAILLE_DESC+1] = "Maillage converti au format MED V2.2";
1149 med_int type = (med_int) MED_NON_STRUCTURE;
1152 /* Lecture du nombre de maillages */
1154 _MEDnObjets(fid,MED_MAA,&n);
1156 // EXIT_IF(n < 0,"Erreur a la lecture du nombre de maillage",NULL);
1159 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1162 * Mise a jour des maillages :
1163 * - type : MED_NON_STRUCTURE
1164 * - description : "Maillage converti au format V2.2"
1167 /* on recupere le nom du maillage */
1168 ret = _MEDobjetIdentifier(fid,MED_MAA,i,nom);
1170 // EXIT_IF(ret < 0,"Identification d'un maillage",NULL);
1173 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1175 // fprintf(stdout," >>> Normalisation du maillage [%s] \n",nom);
1177 MESSAGE("med File convertor 2.1 to 2.2 :: >>> Normalisation du maillage [" << nom << "]");
1179 /* on accede au maillage */
1180 strcpy(chemin,MED_MAA);
1182 gid = _MEDdatagroupOuvrir(fid,chemin);
1184 // EXIT_IF(gid < 0,"Accès au maillage",nom);
1187 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1189 /* lecture de la dimension du maillage */
1190 ret = _MEDattrEntierLire(gid,MED_NOM_DIM,&dimension);
1192 // EXIT_IF(ret < 0,"Lecture de la dimension du maillage",nom);
1195 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1197 /* Ecriture du type et de la description */
1198 ret = _MEDattrStringEcrire(gid,MED_NOM_DES,MED_TAILLE_DESC,description);
1200 // EXIT_IF(ret < 0,"Ecriture de la description du maillage ",nom);
1203 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1205 ret = _MEDattrEntierEcrire(gid,MED_NOM_TYP,&type);
1207 // EXIT_IF(ret < 0,"Ecriture de la dimension du maillage ",nom);
1210 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1212 /* Mise a jour des noeuds du maillage */
1213 MAJ_noeuds_maillage(gid,dimension);
1215 // fprintf(stdout," ... Normalisation des noeuds effectuée ... \n");
1217 MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des noeuds effectuée ...");
1219 /* Mise a jour des éléments du maillage */
1220 MAJ_elements_maillage(gid,dimension);
1222 // fprintf(stdout," ... Normalisation des éléments effectuée ... \n");
1224 MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des éléments effectuée ...");
1226 /* Mise a jour des familles du maillage */
1227 MAJ_familles_maillage(gid);
1229 // fprintf(stdout," ... Normalisation des familles effectuée ... \n");
1231 MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des familles effectuée ...");
1234 ret = _MEDdatagroupFermer(gid);
1236 // EXIT_IF(ret < 0,"Fermeture de l'accès au maillage",NULL);
1239 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1241 // fprintf(stdout," >>> Normalisation du maillage [%s] ... OK ... \n",nom);
1243 MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du maillage [" << nom << "] ... OK ... ");
1247 void med_2_2::MAJ_localisation_Gauss(med_idt fid,char *nom_modele,
1249 throw (MEDEXCEPTION)
1252 med_geometrie_element type;
1253 med_float *refcoo, *gaucoo, *poids;
1255 med_int edim, nsom,n,nlu;
1257 char nom[MED_TAILLE_NOM+1];
1259 /* On regarde si la localisation bidon existe deja
1260 Si oui on s'en va */
1263 for (i=1;i<=n;i++) {
1264 ret = MEDgaussInfo(fid,i,nom,&type,&nlu);
1265 if (! strcmp(nom,nom_modele)) return;
1268 /* On deduit le type en fonction de nom_modele */
1269 strncpy(nom_type,nom_modele,3);
1271 if (! strcmp(nom_type,MED_NOM_SE2))
1273 if (! strcmp(nom_type,MED_NOM_SE3))
1275 if (! strcmp(nom_type,MED_NOM_TR3))
1277 if (! strcmp(nom_type,MED_NOM_TR6))
1279 if (! strcmp(nom_type,MED_NOM_QU4))
1281 if (! strcmp(nom_type,MED_NOM_QU8))
1283 if (! strcmp(nom_type,MED_NOM_TE4))
1285 if (! strcmp(nom_type,MED_NOM_T10))
1287 if (! strcmp(nom_type,MED_NOM_HE8))
1289 if (! strcmp(nom_type,MED_NOM_H20))
1291 if (! strcmp(nom_type,MED_NOM_PE6))
1293 if (! strcmp(nom_type,MED_NOM_P15))
1295 if (! strcmp(nom_type,MED_NOM_PY5))
1297 if (! strcmp(nom_type,MED_NOM_P13))
1300 /* Dimension de la maille */
1304 /* On definit des coordonnées et des poids bidon */
1305 refcoo = (med_float*) malloc(sizeof(med_float)*edim*nsom);
1307 // EXIT_IF(refcoo == NULL,NULL,NULL);
1310 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1312 for (i=0;i<edim*nsom;i++) *(refcoo+i) = 0.;
1313 gaucoo = (med_float*) malloc(sizeof(med_float)*edim*ngauss);
1315 // EXIT_IF(gaucoo == NULL,NULL,NULL);
1318 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1320 for (i=0;i<edim*ngauss;i++) *(gaucoo+i) = 0.;
1321 poids = (med_float*) malloc(sizeof(med_float)*ngauss);
1323 // EXIT_IF(poids == NULL,NULL,NULL);
1326 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1328 for (i=0;i<ngauss;i++) *(poids+i) = 0.;
1330 /* On ecrit la localisation bidon */
1331 ret = MEDgaussEcr(fid,type,refcoo,MED_FULL_INTERLACE,ngauss,gaucoo,poids,nom_modele);
1333 // EXIT_IF(ret < 0,"Ecriture de la localisation des points de Gauss",nom_modele);
1336 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1338 /* On libere la memoire */
1344 void med_2_2::MAJ_champs(med_idt fid) throw (MEDEXCEPTION)
1346 med_idt gid,eid,pid,mid,did,aid;
1349 char nom[MED_TAILLE_NOM+1];
1350 char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1];
1351 char maillage[MED_TAILLE_NOM+1];
1354 char *nouvelle_chaine;
1357 char noment[MED_TAILLE_NOM+1];
1358 char nompdt[2*MED_MAX_PARA+1];
1359 char oldunidt[ANCIEN_MED_TAILLE_PNOM+1];
1360 char unitdt[MED_TAILLE_PNOM+1];
1361 char tmp[MED_TAILLE_DESC+1];
1363 char profil[MED_TAILLE_NOM+1];
1364 char gauss[MED_TAILLE_NOM+1];
1371 /* Lecture du nombre de champs */
1373 _MEDnObjets(fid,MED_CHA,&n);
1375 // EXIT_IF(n < 0,"Erreur a la lecture du nombre de champ",NULL);
1378 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1381 /* on recupere le nom du champ */
1382 ret = _MEDobjetIdentifier(fid,MED_CHA,i,nom);
1384 // EXIT_IF(ret < 0,"Identification d'un champ",NULL);
1387 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1389 // fprintf(stdout," >>> Normalisation du champ [%s] \n",nom);
1391 MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du champ [" << nom << "]");
1393 /* on accede au champ */
1394 strcpy(chemin,MED_CHA);
1396 gid = _MEDdatagroupOuvrir(fid,chemin);
1398 // EXIT_IF(gid < 0,"Accès au champ",nom);
1401 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1403 /* Lecture du nombre de composantes */
1404 ret = _MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp);
1406 // EXIT_IF(ret < 0,"Lecture du nombre de composante",NULL);
1409 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1411 /* Lecture du type du champ */
1412 ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&type);
1414 // EXIT_IF(ret < 0,"Lecture du type du champ",NULL);
1417 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1419 /* Normalisation des nom et unites des composantes */
1420 comp = (char *) malloc(ncomp*ANCIEN_MED_TAILLE_PNOM+1);
1422 // EXIT_IF(comp == NULL,NULL,NULL);
1425 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1427 unit = (char *) malloc(ncomp*ANCIEN_MED_TAILLE_PNOM+1);
1429 // EXIT_IF(unit == NULL,NULL,NULL);
1432 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1434 nouvelle_chaine = (char *) malloc(ncomp*MED_TAILLE_PNOM+1);
1436 // EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
1438 if(nouvelle_chaine == NULL)
1439 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1441 ret = _MEDattrStringLire(gid,MED_NOM_NOM,ncomp*ANCIEN_MED_TAILLE_PNOM,comp);
1443 // EXIT_IF(ret < 0,"Lecture des noms des composantes du champ",NULL);
1446 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1448 conversion_chaine(comp,nouvelle_chaine,ncomp);
1449 H5Adelete(gid,MED_NOM_NOM);
1450 ret = _MEDattrStringEcrire(gid,MED_NOM_NOM,MED_TAILLE_PNOM*ncomp,nouvelle_chaine);
1452 // EXIT_IF(ret < 0,"Ecriture des nouveaux noms des composantes du champ",NULL);
1455 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1459 ret = _MEDattrStringLire(gid,MED_NOM_UNI,ncomp*ANCIEN_MED_TAILLE_PNOM,unit);
1461 // EXIT_IF(ret < 0,"Lecture des unités des composantes du champ",NULL);
1464 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1466 conversion_chaine(unit,nouvelle_chaine,ncomp);
1467 H5Adelete(gid,MED_NOM_UNI);
1468 ret = _MEDattrStringEcrire(gid,MED_NOM_UNI,MED_TAILLE_PNOM*ncomp,nouvelle_chaine);
1470 // EXIT_IF(ret < 0,"Ecriture des nouvelles unités des composantes du champ",NULL);
1473 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1477 free(nouvelle_chaine);
1479 // fprintf(stdout," ... Normalisation des noms et unités des composantes effectuée...\n");
1481 MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des noms et unités des composantes effectuée...");
1483 /* On ajoute le groupe HDF correspondant au maillage */
1484 /* On recupere le nom du maillage par defaut */
1486 _MEDnObjets(gid,"./",&nent);
1488 // EXIT_IF(nent < 0,"Erreur a la lecture du nombre d'entité dans un champ",NULL);
1491 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1493 for (j=0;j<nent;j++) {
1494 /* on recupere le nom du groupe HDF correspondant a l'entite */
1495 ret = _MEDobjetIdentifier(gid,"./",j,noment);
1497 // EXIT_IF(ret < 0,"Identification des objets de niveau 1 dans le champ",NULL);
1500 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1502 /* On ouvre le groupe HDF */
1503 eid = _MEDdatagroupOuvrir(gid,noment);
1505 // EXIT_IF(eid < 0,"Ouverture du groupe HDF de niveau 1",NULL);
1508 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1510 /* On recupere le nombre de pas de temps */
1512 _MEDnObjets(eid,"./",&npdt);
1514 // EXIT_IF(nent < 0,"Erreur a la lecture du nombre de pas de temps",NULL);
1517 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1519 /* On traite chaque pas de temps */
1520 for (k=0;k<npdt;k++) {
1521 /* On recupere le nom du groupe HDF correspondant au pas de temps */
1522 ret = _MEDobjetIdentifier(eid,"./",k,nompdt);
1524 // EXIT_IF(ret < 0,"Identification des objets de niveau 2 dans le champ",NULL);
1527 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1529 /* On ouvre le groupe HDF correspondant au pas de temps */
1530 pid = _MEDdatagroupOuvrir(eid,nompdt);
1532 // EXIT_IF(pid < 0,"Ouverture du groupe HDF de niveau 2",NULL);
1535 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1537 /* On lit le pas de temps */
1538 aid = H5Aopen_name(pid,MED_NOM_PDT);
1540 // EXIT_IF(aid < 0,"Ouverture de l'attribut HDF MED_NOM_PDT",NULL);
1543 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1545 hdf_type = H5Aget_type(aid);
1547 // EXIT_IF(hdf_type < 0,"Lecture du type de l'attribut HDF MED_NOM_PDT",NULL);
1550 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1552 ret = H5Aclose(aid);
1554 // EXIT_IF(ret < 0,"Fermeture de l'attribut MED_NOM_PDT",NULL);
1557 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1559 ret = OLD_MEDattrNumLire(pid,MED_FLOAT64,MED_NOM_PDT,(unsigned char*)(&pdt),hdf_type);
1561 // EXIT_IF(ret < 0,"Lecture du pas de temps dans MED_NOM_PDT",NULL);
1564 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1567 /* printf("EGALITE des types : %d \n",H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)); */
1568 /* printf("Avant conversion : [%f]\n",pdt); */
1569 if (! H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)) {
1570 ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)(&pdt),NULL,0);
1571 /* printf("Après conversion éventuelle : [%f] \n",pdt); */
1573 // EXIT_IF(ret < 0,"Conversion du pas de temps",NULL);
1576 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1579 /* printf("pdt = %f\n",pdt); */
1580 H5Adelete(pid,MED_NOM_PDT);
1581 ret = _MEDattrFloatEcrire(pid,MED_NOM_PDT,&pdt);
1583 // EXIT_IF(ret < 0,"Ecriture du nouveau pas de temps",NULL);
1586 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1588 /* On met a jour l'unité du pas de temps : 8 -> 16 caractères
1589 Si on rencontre " " => on ecrit ""
1591 ret = _MEDattrStringLire(pid,MED_NOM_UNI,ANCIEN_MED_TAILLE_PNOM,oldunidt);
1593 // EXIT_IF(ret < 0,"Lecture de l'unite du pas de temps",NULL);
1596 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1598 if (! strcmp(oldunidt,ANCIEN_MED_BLANC_PNOM))
1601 conversion_chaine(oldunidt,unitdt,1);
1602 H5Adelete(pid,MED_NOM_UNI);
1603 ret = _MEDattrStringEcrire(pid,MED_NOM_UNI,MED_TAILLE_PNOM,unitdt);
1605 // EXIT_IF(ret < 0,"Ecriture de la nouvelle unité du pas de temps",NULL);
1607 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1609 /* On recupere le nom du maillage */
1610 ret = _MEDattrStringLire(pid,MED_NOM_MAI,MED_TAILLE_NOM,maillage);
1612 // EXIT_IF(ret < 0,"Lecture du nom du maillage du pas de temps",NULL);
1615 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1617 /* On cree le groupe HDF de niveau 3 qui porte le nom du maillage */
1618 mid = _MEDdatagroupCreer(pid,maillage);
1620 // EXIT_IF(mid < 0,"Creation du groupe HDF de niveau 3",NULL);
1623 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1625 /* Déplacement de l'attribut MED_NOM_NBR */
1626 ret = _MEDattrEntierLire(pid,MED_NOM_NBR,&nval);
1628 // EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_NBR",NULL);
1631 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1633 ret = H5Adelete(pid,MED_NOM_NBR);
1635 // EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_NBR",NULL);
1638 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1640 ret = _MEDattrEntierEcrire(mid,MED_NOM_NBR,&nval);
1642 // EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NBR au niveau 3",NULL);
1645 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1647 /* Deplacement de l'attribut MED_NOM_NGA */
1648 ret = _MEDattrEntierLire(pid,MED_NOM_NGA,&att);
1650 // EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_NGA",NULL);
1653 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1655 ret = H5Adelete(pid,MED_NOM_NGA);
1657 // EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_NGA",NULL);
1660 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1662 ret = _MEDattrEntierEcrire(mid,MED_NOM_NGA,&att);
1664 // EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NGA au niveau 3",NULL);
1667 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1669 /* Ecriture de l'attribut MED_NOM_GAU : localisation des points de Gauss */
1671 strcpy(gauss,MED_NOM_BLANC);
1673 /* on prend en compte que les 3 dernières lettres de noment :
1674 Exemple : "MAI.QU4" => gauss="QU4_LocalisationDefaut_MEDIMPORT */
1675 strcpy(gauss,noment+4);
1676 strcat(gauss,"_LocalisationDefaut_MEDIMPORT");
1677 /* On ecrit en plus la localisation bidon des points de Gauss */
1678 MAJ_localisation_Gauss(fid,gauss,att);
1680 ret = _MEDattrStringEcrire(mid,MED_NOM_GAU,MED_TAILLE_NOM,gauss);
1682 // EXIT_IF(ret < 0,"Ecriture de la localisation des points de Gauss",NULL);
1684 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1686 /* Deplacement de l'attribut MED_NOM_PFL */
1687 ret = _MEDattrStringLire(pid,MED_NOM_PFL,MED_TAILLE_NOM,profil);
1689 // EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_PFL",NULL);
1692 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1695 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1697 ret = H5Adelete(pid,MED_NOM_PFL);
1699 // EXIT_IF(ret < 0,"Desctruction de l'attribut MED_NOM_PFL",NULL);
1702 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1704 ret = _MEDattrStringEcrire(mid,MED_NOM_PFL,MED_TAILLE_NOM,profil);
1706 // EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_PFL au niveau 3",NULL);
1709 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1711 /* On ferme le groupe HDF de niveau 3 */
1712 ret = _MEDdatagroupFermer(mid);
1714 // EXIT_IF(ret < 0,"fermeture du groupe HDF de niveau 3",NULL);
1717 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1719 /* On deplace du niveau 2 -> 3, le dataset MED_NOM_CO
1720 avec si type==MED_FLOAT_64 une conversion au passage */
1721 strcpy(tmp,maillage);
1723 strcat(tmp,MED_NOM_CO);
1724 if (type != MED_FLOAT64) {
1725 ret = H5Gmove(pid,MED_NOM_CO,tmp);
1727 // EXIT_IF(ret < 0,"Transfert du dataset MED_NOM_CO",NULL);
1730 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1732 did = _MEDdatasetOuvrir(pid,MED_NOM_CO);
1734 // EXIT_IF(did < 0,"Ouverture du dataset HDF des valeurs",NULL);
1737 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1739 hdf_type = H5Dget_type(did);
1741 // EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des valeurs",NULL);
1744 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1746 ret = _MEDdatasetFermer(did);
1748 // EXIT_IF(ret < 0,"Fermeture du dataset HDF des valeurs",NULL);
1751 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1753 valr = (med_float *) malloc(sizeof(med_float)*ncomp*nval);
1755 // EXIT_IF(valr == NULL,NULL,NULL);
1758 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1760 ret = OLD_MEDdatasetNumLire(pid,MED_NOM_CO,MED_FLOAT64,
1761 MED_FULL_INTERLACE,ncomp,MED_ALL,
1763 (unsigned char*) valr,hdf_type);
1765 // EXIT_IF(ret < 0,"Lecture des valeurs du champ",NULL);
1768 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1770 H5Gunlink(pid,MED_NOM_CO);
1771 dimd[0] = ncomp*nval;
1772 ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)valr,NULL,0);
1774 // EXIT_IF(ret < 0,"Conversion des valeurs",NULL);
1777 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1780 /* On reporte les valeurs dans le groupe HDF TMP */
1781 ret = _MEDdatasetNumEcrire(pid,tmp,MED_FLOAT64,MED_FULL_INTERLACE,
1782 ncomp,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
1783 (unsigned char*) valr);
1785 // EXIT_IF(ret < 0,"Ecriture des valeurs après conversion",NULL);
1788 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1793 /* On ferme le groupe HDF de niveau 2*/
1794 ret = _MEDdatagroupFermer(pid);
1796 // EXIT_IF(ret < 0,"Fermeture du groupe HDF de niveau 2",NULL);
1799 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1802 /* On ferme le groupe HDF */
1803 ret = _MEDdatagroupFermer(eid);
1805 // EXIT_IF(ret < 0,"Fermeture du groupe HDF de niveau 1",NULL);
1808 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1811 // fprintf(stdout," ... Normalisation de tous les pas de temps effectuée...\n");
1813 MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation de tous les pas de temps effectuée...\n");
1816 ret = _MEDdatagroupFermer(gid);
1818 // EXIT_IF(ret < 0,"Fermeture de l'accès au champ",NULL);
1821 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1823 // fprintf(stdout," >>> Normalisation du champ [%s] : ... OK ... \n",nom);
1825 MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du champ [" << nom << "] : ... OK ... ");
1829 void med_2_2::MAJ_profils(med_idt fid,med_int nprofil) throw (MEDEXCEPTION)
1833 char nom[MED_TAILLE_NOM+1];
1834 char chemin[MED_TAILLE_DESC+1];
1838 for (i=0;i<nprofil;i++)
1840 /* on recupere le nom du profil */
1841 ret = _MEDobjetIdentifier(fid,MED_PROFILS,i,nom);
1843 // EXIT_IF(ret < 0,"Identification d'un profil",NULL);
1846 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1848 // fprintf(stdout," >>> Normalisation du profil [%s] \n",nom);
1850 MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du profil [" << nom << "] ");
1852 /* on accede au profil */
1853 strcpy(chemin,MED_PROFILS);
1855 gid = _MEDdatagroupOuvrir(fid,chemin);
1857 // EXIT_IF(gid < 0,"Accès au profil",nom);
1860 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1863 /* On change l'attribut MED_NOM_N => MED_NOM_NBR */
1864 ret = _MEDattrEntierLire(gid,"N",&att);
1866 // EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_N",NULL);
1869 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1871 ret = H5Adelete(gid,"N");
1873 // EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_N",NULL);
1876 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1878 ret = _MEDattrEntierEcrire(gid,MED_NOM_NBR,&att);
1880 // EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NBR dans le profil ",nom);
1883 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1885 /* on ferme le profil */
1886 ret = _MEDdatagroupFermer(gid);
1888 // EXIT_IF(ret < 0,"Fermeture de l'acces au profil",nom);
1891 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1893 // fprintf(stdout," >>> Normalisation du profil [%s] effectuée \n",nom);
1895 MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du profil [" << nom << "]");
1899 char * MEDMEM::med2_1_To_med2_2(char * fileNameIn) throw (MEDEXCEPTION)
1903 med_int majeur, mineur, release;
1907 char chemin_profils[MED_TAILLE_PROFILS+1];
1908 char chemin_liens[MED_TAILLE_LIENS+1];
1910 char * InternalFileNameOut;
1912 char * envHome = (char *) malloc(sizeof(char)*(strlen("HOME")+1));
1914 strcpy(envHome,"HOME");
1916 char * envHomeChar = getenv(envHome);
1918 /* Test du nombre d'argument */
1919 // EXIT_IF(argc != 2,"Nombre de parametre incorrect",NULL);
1921 /* Test du format du fichier */
1922 /* EXIT_IF(MEDformatConforme(argv[1]) < 0, */
1923 /* "Le fichier n'est pas au format HDF 5 : ", argv[1]); */
1925 // EXIT_IF(MEDformatConforme(fileNameIn) < 0,
1926 // "Le fichier n'est pas au format HDF 5 : ", fileNameIn);
1928 if(MEDformatConforme(fileNameIn) < 0)
1929 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory");
1931 /* opening the old file to check the versions (Med File and HDF) */
1933 fid = MEDouvrir(fileNameIn,MED_LECTURE);
1935 /* EXIT_IF(fid < 0,"Ouverture du fichier : ", */
1938 // EXIT_IF(fid < 0,"Ouverture du fichier : ",
1939 // InternalFileNameOut);
1941 MESSAGE("med File convertor 2.1 to 2.2 :: opening of the old file id " << fid);
1944 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file : openning of the file");
1946 /* Verification du numero de version */
1947 ret = MEDversionLire(fid,&majeur,&mineur,&release);
1949 // EXIT_IF(ret < 0,"Lecture du numero de version de MED-fichier",NULL);
1952 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
1954 if (majeur == 2 && mineur == 2) {
1955 /* fprintf(stdout,"Le fichier %s est déjà au format V2.2 !!! \n",nom); */
1957 // fprintf(stdout,"Le fichier %s est déjà au format V2.2 !!! \n",InternalFileNameOut);
1959 MESSAGE("med File convertor 2.1 to 2.2 :: the file " << fileNameIn << " is already a med 2.2 file");
1961 ret = MEDfermer(fid);
1962 /* EXIT_IF(ret < 0,"Fermeture du fichier",argv[1]); */
1964 // EXIT_IF(ret < 0,"Fermeture du fichier",fileNameIn);
1967 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
1972 ret = MEDfermer(fid);
1975 we are sure now that the file is an old version one
1976 creation of the directory if it does not existe
1979 commande = (char *) malloc(sizeof(char)*(strlen("mkdir ")+
1980 strlen(envHomeChar)+
1981 strlen("/TMP_Med2_2Files/")+1));
1983 // EXIT_IF(commande == NULL,NULL,NULL);
1985 if(commande == NULL)
1986 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
1988 strcpy(commande,"ls ");
1989 strcat(commande,envHomeChar);
1990 strcat(commande,"/TMP_Med2_2Files/");
1992 int systemReturn = system(commande);
1994 if (systemReturn != 0)
1996 strcpy(commande,"mkdir ");
1997 strcat(commande,envHomeChar);
1998 strcat(commande,"/TMP_Med2_2Files/");
2000 systemReturn = system(commande);
2007 string::size_type pos1 = string(fileNameIn).rfind('/');
2008 string::size_type pos = strlen(fileNameIn);
2009 InternalFileNameOut = (char *) malloc(sizeof(char)*(strlen(envHomeChar)+
2010 strlen("/TMP_Med2_2Files/")
2011 +strlen(string(fileNameIn,pos1+1,pos-pos1-1).c_str())+1));
2013 strcpy(InternalFileNameOut,envHomeChar);
2014 strcat(InternalFileNameOut,"/TMP_Med2_2Files/");
2015 strcat(InternalFileNameOut,string(fileNameIn,pos1+1,pos-pos1-1).c_str());
2017 MESSAGE("med File convertor 2.1 to 2.2 :: " << InternalFileNameOut);
2019 /* Creation et ouverture du fichier que l'on va convertire au format MED V2.2 */
2020 /* commande = (char *) malloc(sizeof(char)*(strlen("cp ")+2*strlen(argv[1])+strlen(" ")+strlen("2.2")+1)); */
2022 commande = (char *) malloc(sizeof(char)*(strlen("cp -f ") +
2023 strlen(fileNameIn) + strlen(" ") +
2024 strlen(InternalFileNameOut) +
2025 strlen(" ; chmod ug+rw ") +
2026 strlen(InternalFileNameOut) + 1));
2028 // EXIT_IF(commande == NULL,NULL,NULL);
2030 if(commande == NULL)
2031 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
2033 /* nom = (char *) malloc(sizeof(char)*(strlen(argv[1])+strlen("2.2")+1)); */
2035 /* nom = (char *) malloc(sizeof(char)*(strlen(fileNameIn)+strlen("2.2")+1)); */
2037 /* EXIT_IF(nom == NULL,NULL,NULL); */
2038 /* strcpy(nom,argv[1]); */
2040 /* strcpy(nom,fileNameIn); */
2042 /* strcat(nom,"2.2"); */
2044 // strcpy(fileNameOut,fileNameIn);
2046 // strcat(fileNameOut,"2.2");
2048 strcpy(commande,"cp -f ");
2049 /* strcat(commande,argv[1]); */
2051 strcat(commande,fileNameIn);
2053 strcat(commande," ");
2054 /* strcat(commande,nom); */
2056 strcat(commande,InternalFileNameOut);
2058 strcat(commande," ; chmod ug+rw ");
2060 strcat(commande,InternalFileNameOut);
2063 /* fprintf(stdout,">>> Creation du fichier %s : %s \n",nom,commande); */
2065 // fprintf(stdout,">>> Creation du fichier %s : %s \n",InternalFileNameOut,commande);
2067 MESSAGE("med File convertor 2.1 to 2.2 :: Creation du fichier " << InternalFileNameOut << " with the commande " << commande);
2071 /* fid = MEDouvrir(nom,MED_LECTURE_ECRITURE); */
2073 fid = MEDouvrir(InternalFileNameOut,MED_LECTURE_ECRITURE);
2075 /* EXIT_IF(fid < 0,"Ouverture du fichier : ", */
2078 // EXIT_IF(fid < 0,"Ouverture du fichier : ",
2079 // InternalFileNameOut);
2081 MESSAGE("med File convertor 2.1 to 2.2 :: opening of the new file id " << fid);
2084 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file : openning of the file");
2086 /* On avertit qu'on commence la conversion */
2088 // fprintf(stdout,">>> Lancement de la normalisation du fichier selon le format MED V2.2 ...\n");
2090 MESSAGE("med File convertor 2.1 to 2.2 :: Running the convertor fromV 2.1 to V2.2");
2092 /* On inhibe le gestionnaire d'erreur HDF5 */
2093 _MEDmodeErreurVerrouiller();
2095 /* Mise a jour du numero de version */
2097 // fprintf(stdout,"- Lancement de la mise à jour du numéro de version ... \n");
2099 MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of the version number");
2103 // fprintf(stdout," Numéro de version : ... OK ... \n");
2105 MESSAGE("med File convertor 2.1 to 2.2 :: Version number OK ...");
2107 /* Mise a jour des maillages : type = MED_NON_STRUCTURE, description, ... */
2109 // fprintf(stdout,"- Lancement de la mise à jour des maillages ... \n");
2111 MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of all meshes");
2115 // fprintf(stdout," Maillage(s) : ... OK ...\n");
2117 MESSAGE("med File convertor 2.1 to 2.2 :: meshes are OK....");
2119 /* Mise a jour des champs */
2121 // fprintf(stdout,"- Lancement de la mise à jour des champs de résultats ... \n");
2123 MESSAGE("med File convertor 2.1 to 2.2 :: Running of the update of all fields ..");
2127 // fprintf(stdout," Champs(s) : ... OK ...\n");
2129 MESSAGE("med File convertor 2.1 to 2.2 :: Fields are OK ..");
2131 /* Mise a jour des profils eventuels */
2132 nprofil = MEDnProfil(fid);
2134 // fprintf(stdout,"- Lancement de la mise à jour des profils ... \n");
2136 MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of all profils");
2138 MAJ_profils(fid,nprofil);
2140 // fprintf(stdout," Profils(s) : ... OK ...\n");
2142 MESSAGE("med File convertor 2.1 to 2.2 :: Profils are OK ... ");
2144 strncpy(chemin_profils,MED_PROFILS,MED_TAILLE_PROFILS-1);
2145 chemin_profils[MED_TAILLE_PROFILS-1] = '\0';
2146 gid = _MEDdatagroupCreer(fid,chemin_profils);
2148 // EXIT_IF(gid < 0,"Creation du groupe HDF sur les profils",chemin_profils);
2151 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
2153 ret = _MEDdatagroupFermer(gid);
2155 // EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les profils",chemin_profils);
2158 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
2162 /* On cree le groupe HDF pour les liens */
2163 strncpy(chemin_liens,MED_LIENS,MED_TAILLE_LIENS-1);
2164 chemin_liens[MED_TAILLE_LIENS-1] = '\0';
2165 gid = _MEDdatagroupCreer(fid,chemin_liens);
2167 // EXIT_IF(gid < 0,"Creation du groupe HDF sur les liens",chemin_liens);
2170 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
2172 ret = _MEDdatagroupFermer(gid);
2174 // EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les liens",chemin_liens);
2177 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
2179 /* Fermeture du fichier */
2180 ret = MEDfermer(fid);
2181 /* EXIT_IF(ret < 0,"Fermeture du fichier",nom); */
2183 // EXIT_IF(ret < 0,"Fermeture du fichier",InternalFileNameOut);
2186 throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file");
2188 /* On avertit que c'est fini */
2189 /* fprintf(stdout,">>> Conversion du fichier %s au format MED V2.2. terminée\n", */
2192 // fprintf(stdout,">>> Conversion du fichier %s au format MED V2.2. terminée\n",
2193 // InternalFileNameOut);
2195 /* On libere la memoire */
2198 char * fileNameOut = new char[strlen(InternalFileNameOut)+1];
2200 fileNameOut = strcpy(fileNameOut,InternalFileNameOut);
2202 free(InternalFileNameOut);
2204 MESSAGE("med File convertor 2.1 to 2.2 :: Convertion of the med file " << fileNameOut << " has run OK");