]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_medimport_src.cxx
Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MEDMEM / MEDMEM_medimport_src.cxx
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.
7 *  
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.
12 *
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
16 *
17 *************************************************************************/
18 #include "MEDMEM_medimport_src.hxx"
19
20 using namespace med_2_2;
21 using namespace MEDMEM;
22
23 extern "C" {
24   extern med_err MEDgaussInfo(med_idt fid, int indice, char * locname,
25                               med_geometrie_element * type_geo,
26                               med_int * ngauss );
27
28   extern void _MEDmodeErreurVerrouiller(void);
29
30   extern med_err _MEDnomGeometrie(char *nom_geo,
31                                   med_geometrie_element type_geo);
32 }
33
34 med_err med_2_2::OLD_MEDattrNumLire(med_idt pere, med_type_champ type,
35                                     char *nom, unsigned char *val,
36                                     hid_t hdf_file)
37 {
38   med_idt attid;
39   med_err ret;
40   int type_hdf;
41
42   if ((attid = H5Aopen_name(pere,nom)) < 0)
43     return -1;
44
45   switch(type) 
46     {
47     case MED_FLOAT64 :
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;
54 #else 
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;
60 #endif
61       break;
62       
63     case MED_INT :
64 #if defined(IRIX64) || defined(OSF1)
65       type_hdf = H5T_NATIVE_LONG; 
66 #else
67       type_hdf = H5T_NATIVE_INT;
68 #endif
69       break;
70       
71     default :
72       return -1;
73     }
74
75   if ((ret = H5Aread(attid,type_hdf,val)) < 0)
76     return -1;
77
78   if ((ret = H5Aclose(attid)) < 0)
79     return -1;
80
81   return 0;
82 }
83
84
85 med_err med_2_2::OLD_MEDdatasetNumLire(med_idt pere, char *nom,
86                                        med_type_champ type,
87                                        med_mode_switch interlace,
88                                        med_size nbdim, med_size fixdim, 
89                                        med_size psize, med_ssize * pfltab,
90                                        med_int ngauss,
91                                        unsigned char *val,hid_t hdf_file)
92 {
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];
96   med_err    ret;
97   int        i,j,index,type_hdf;
98   hid_t      datatype;
99   size_t     typesize;
100   int        dim, firstdim, dimutil, lastdim;
101   med_mode_profil pflmod;
102
103   /* Verify fixdim is between [0, nbdim] ( 0 is MED_ALL ) */
104   if ( ( fixdim < 0 ) || ( fixdim > nbdim ) ) 
105     return -1;
106  
107   /* block pflmod to MED_COMPACT (until med2.2) */
108   pflmod = MED_COMPACT;
109
110   switch(type)
111     {
112     case MED_FLOAT64 :
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;
123 #else 
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;
129 #endif
130       break;
131
132     case MED_INT32 :
133       type_hdf = H5T_NATIVE_INT;
134       break;
135
136     case MED_INT64 :
137       type_hdf = H5T_NATIVE_LONG;
138       break;
139
140     default :
141       return -1;
142     }
143
144   /* Ouverture du Dataset à lire */
145   if ((dataset = H5Dopen(pere,nom)) < 0)
146     return -1;
147
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;
153
154   /* Create dataspace */
155   if ((dataspace = H5Screate_simple(1,size,NULL)) < 0)
156     return -1;
157   
158   switch(interlace)
159     {
160     case MED_FULL_INTERLACE :
161
162       /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/
163       if ( fixdim != MED_ALL) 
164         { 
165           firstdim = fixdim-1;
166           lastdim  = fixdim;
167           dimutil  = 1;
168         } else  {
169           firstdim = 0;
170           lastdim = nbdim;
171           dimutil  = nbdim; 
172         }
173
174       count [0] = (*size)/(nbdim);
175       
176
177       /*rem: Pas de vérification de l'assertion (*size)=n*nbdim */
178       if ( psize == MED_NOPF ) {  
179
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)
182         return -1;
183
184         stride[0] = nbdim;  
185
186         for (dim=firstdim; dim < lastdim; dim++) {
187                   
188           start_mem[0] = dim;
189           if ( (ret = H5Sselect_hyperslab (memspace, H5S_SELECT_SET, start_mem, stride, 
190                                            count, NULL)) <0)
191             return -1; 
192           
193           start_data[0] = dim*count[0];
194           if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL, 
195                                            count, NULL)) <0)
196             return -1; 
197           
198           if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,
199                              H5P_DEFAULT, val)) < 0)
200             return -1;
201         }
202         
203       } else {
204
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]);
209         
210         switch(pflmod)
211           { /* switch pflmod pour FULL_INTERLACE*/
212           case MED_GLOBAL :
213
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)
216               return -1;
217
218             for (dim=firstdim; dim < lastdim; dim++) {
219               
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;             
225                 }
226             }
227             
228             if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) 
229               return -1; 
230             
231             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) 
232               return -1; 
233             
234             break;
235         
236           case MED_COMPACT :
237         
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 */ 
241             
242             if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0)
243               return -1;
244             
245             for (dim=firstdim; dim < lastdim; dim++) {
246               
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;             
252                 }             
253             }
254             
255             if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) 
256               return -1; 
257             
258             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) 
259               return -1; 
260             
261             break;
262
263           default :
264             return -1; 
265           }
266         
267         if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0)
268           return -1;
269         
270         free(pflmem);
271         free(pfldsk);
272       }
273       
274       break;
275       
276     case MED_NO_INTERLACE :
277
278       /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/
279
280       count[0] = (*size)/nbdim;
281       
282       if ( psize == MED_NOPF ) {  
283         
284         if ( fixdim != MED_ALL) 
285           start_data[0] = (fixdim-1)*count[0];
286         else {
287           count[0] = *size;
288           start_data[0] =  0;
289         };
290         
291         if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL, 
292                                          count, NULL)) <0)
293           return -1; 
294         
295         if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,
296                            H5P_DEFAULT, val)) < 0)
297           return -1;
298         
299       } else {
300
301         if ( fixdim != MED_ALL) 
302           { 
303             firstdim = fixdim-1;
304             lastdim  = fixdim;
305             dimutil  = 1;
306           } else        {
307             firstdim = 0;
308             lastdim  = nbdim;
309             dimutil  = nbdim; 
310           }
311
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]);
315         
316         switch(pflmod)
317           { /*switch plfmod pour NO_INTERLACE */
318           case MED_GLOBAL :
319             
320             for (dim=firstdim; dim < lastdim; dim++) {
321               
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;      
326                 }
327             }
328             
329             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) 
330               return -1;
331             
332             if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,H5P_DEFAULT, val)) < 0)
333               return -1;
334               
335             break;
336             
337           case MED_COMPACT :
338             
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 */ 
342
343             if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0)
344               return -1;
345
346             pflmem     = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]);
347             
348             /* Le profil COMPACT est contigüe, mais il est possible que l'on selectionne uniquemenent une dimension*/
349
350             for (dim=firstdim; dim < lastdim; dim++) {
351               
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;           
357                 }
358             }
359             
360             if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) 
361               return -1; 
362             
363             if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) 
364               return -1;          
365             
366             if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0)
367               return -1;
368             
369             break;
370             
371           default :
372             return -1;      
373             
374           }
375         
376         free(pfldsk);
377         
378       };
379       
380       break;
381       
382     default :
383       return -1;
384     }
385   
386   
387
388   if (memspace) 
389     if ((ret = H5Sclose(memspace)) < 0)
390       return -1;
391
392   if ((ret = H5Sclose(dataspace)) < 0)
393     return -1;
394   
395   if ((ret = H5Dclose(dataset)) < 0)
396     return -1;      
397
398   return 0;
399 }
400
401
402 void med_2_2::conversion_chaine(char *ancienne_chaine,
403                                char *nouvelle_chaine,
404                                med_int n)
405 {
406   int i;
407   int j;
408   char tmp[MED_TAILLE_PNOM+1];
409
410   for (i=0;i<n;i++) {
411     if (i == n-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++) 
415           tmp[j] = ' ';
416     }
417     else
418       strncpy(tmp,ancienne_chaine+i*ANCIEN_MED_TAILLE_PNOM,ANCIEN_MED_TAILLE_PNOM);
419     tmp[ANCIEN_MED_TAILLE_PNOM] = '\0';
420     /*          12345678 */
421     strcat(tmp,"        ");
422     /*     printf("[%s]\n",tmp); */
423     if (i == 0)
424       strcpy(nouvelle_chaine,tmp);
425     else
426       strcat(nouvelle_chaine,tmp);
427   }
428   *(nouvelle_chaine+MED_TAILLE_PNOM*n) = '\0';
429
430
431 void med_2_2::MAJ_version(med_idt fid) throw (MEDEXCEPTION)
432 {
433   med_err ret;
434   med_idt gid;
435   med_int majeur, mineur, release;
436
437   /* On ecrit le bon numero de version */
438   majeur = 2;
439   mineur = 2;
440   release = 1;
441   gid = _MEDdatagroupOuvrir(fid,MED_NOM_INFOS);
442   if (gid < 0)
443     gid = _MEDdatagroupCreer(fid,MED_NOM_INFOS);
444
445 //   EXIT_IF(gid < 0,"Ouverture du groupe HDF MED_NOM_INFOS",NULL);
446
447   if (gid < 0)
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");
449
450   ret = _MEDattrEntierEcrire(gid,MED_NOM_MAJEUR,&majeur);
451
452 //   EXIT_IF(ret < 0,"Ecriture du numéro majeur",NULL);
453
454   if (ret < 0)
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");
456
457   ret = _MEDattrEntierEcrire(gid,MED_NOM_MINEUR,&mineur);
458
459 //   EXIT_IF(ret < 0,"Ecriture du numéro mineur",NULL);
460
461   if (ret < 0)
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");
463
464   ret = _MEDattrEntierEcrire(gid,MED_NOM_RELEASE,&release);
465
466 //   EXIT_IF(ret < 0,"Ecrriture du numéro de release",NULL);
467
468   if (ret < 0)
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");
470
471   ret = _MEDdatagroupFermer(gid);
472
473 //   EXIT_IF(ret < 0,"Fermeture du groupe HDF MED_NOM_INFOS",NULL);
474
475   if (ret < 0)
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");
477   
478 }
479
480 void med_2_2::MAJ_noeuds_maillage(med_idt mid, med_int dimension)
481   throw (MEDEXCEPTION)
482 {
483   med_idt nid, gid, tid;
484   med_float *coo;
485   char *nom, *unit;
486   char tmp[MED_TAILLE_PNOM+1];
487   char *nouvelle_chaine;
488   med_int n;
489   med_size dimd[1];
490   med_err ret;
491   int i;
492   hid_t hdf_type;
493   med_repere repere;
494
495   /* Accès aux noeuds du maillage */
496   nid = _MEDdatagroupOuvrir(mid,MED_NOM_NOE);
497
498 //   EXIT_IF(nid < 0,"Ouverture du groupe HDF MED_NOM_NOE",NULL);
499
500   if(nid < 0)
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");
502
503   /* Lecture du nombre de noeuds */
504   gid = _MEDdatasetOuvrir(nid,MED_NOM_COO);
505   if (gid > 0) 
506      ret = _MEDattrEntierLire(gid,MED_NOM_NBR,&n);
507
508 //   EXIT_IF(gid < 0,"Lecture du nombre de noeuds",NULL);
509
510   if(gid < 0)
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");
512   
513   /* Mise a jour des coordonnees */
514   /* On cree un groupe HDF tampon */
515   /* Lecture des coordonnées */
516   hdf_type = H5Dget_type(gid);
517
518 //   EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des coordonnées",NULL);
519
520   if(hdf_type < 0)
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");
522
523   coo = (med_float *) malloc(sizeof(med_float)*n*dimension);
524
525 //   EXIT_IF(coo == NULL,NULL,NULL);
526
527   if(coo == 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");
529
530   ret = OLD_MEDdatasetNumLire(nid,MED_NOM_COO,MED_FLOAT64, 
531                               MED_FULL_INTERLACE,dimension,MED_ALL, 
532                               0,NULL,MED_NOPG, 
533                               (unsigned char*) coo,hdf_type); 
534
535 //   EXIT_IF(ret < 0,"Lecture des coordonnées des noeuds",NULL);
536
537   if(ret < 0)
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");
539
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)); */
546
547 //     EXIT_IF(ret < 0,"Conversion des coordonnées des noeuds",NULL);
548
549   if(ret < 0)
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");
551   }
552   ret = H5Tclose(hdf_type);
553
554 //   EXIT_IF(ret < 0,"Fermeture du data type HDF",NULL);
555
556   if(ret < 0)
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");
558
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);
563
564 //   EXIT_IF(ret < 0,"Ecriture des coordonnées des noeuds après conversion",NULL);
565
566   if(ret < 0)
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");
568
569   free(coo);
570
571   /* Ecriture du nombre de noeuds et du type du repertoire dans le dataset TMP */
572   tid = _MEDdatasetOuvrir(nid,"TMP");
573
574 //   EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL);
575
576   if(tid < 0)
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");
578
579   ret = _MEDattrEntierEcrire(tid,MED_NOM_NBR,&n);
580
581 //   EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL);
582
583   if(ret < 0)
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");
585
586   ret = _MEDattrEntierLire(gid,MED_NOM_REP,&repere);
587
588 //   EXIT_IF(ret < 0,"Lecture du type de repere des coordonnées", NULL);
589
590   if(ret < 0)
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");
592
593   ret = _MEDattrEntierEcrire(tid,MED_NOM_REP,&repere);
594
595 //   EXIT_IF(ret < 0,"Ecriture du type de répertoire dans le dataset HDF TMP",NULL);
596
597   if(ret < 0)
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");
599
600   /* Mise a jour des noms et types des unités des coordonnees */
601   nom = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1);
602
603 //   EXIT_IF(nom == NULL,NULL,NULL);
604
605   if(nom == 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");
607
608   unit = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1);
609
610 //   EXIT_IF(unit == NULL,NULL,NULL);
611
612   if(unit == 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");
614
615   nouvelle_chaine = (char *) malloc(dimension*MED_TAILLE_PNOM+1);
616
617 //   EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
618
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");
621
622   ret = _MEDattrStringLire(gid,MED_NOM_NOM,dimension*ANCIEN_MED_TAILLE_PNOM,nom);
623
624 //   EXIT_IF(ret < 0,"Lecture des noms des coordonnées des noeuds",NULL);
625
626   if(ret < 0)
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");
628
629   ret = _MEDattrStringLire(gid,MED_NOM_UNI,dimension*ANCIEN_MED_TAILLE_PNOM,unit);
630
631 //   EXIT_IF(ret < 0,"Lecture des unités des coordonnées des noeuds",NULL);
632
633   if(ret < 0)
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");
635
636   conversion_chaine(nom,nouvelle_chaine,dimension);
637   ret = _MEDattrStringEcrire(tid,MED_NOM_NOM,dimension*MED_TAILLE_PNOM,nouvelle_chaine);
638
639 //   EXIT_IF(ret < 0,"Ecriture des nouveaux noms des coordonnées des noeuds",NULL);
640
641   if(ret < 0)
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");
643
644   conversion_chaine(unit,nouvelle_chaine,dimension);
645   ret = _MEDattrStringEcrire(tid,MED_NOM_UNI,dimension*MED_TAILLE_PNOM,nouvelle_chaine);
646
647 //   EXIT_IF(ret < 0,"Ecriture des nouvelles unités des coordonnées des noeuds",NULL);
648
649   if(ret < 0)
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");
651
652   free(nom);
653   free(unit);
654   free(nouvelle_chaine);
655
656   /* Fermeture de l'accès aux coordonnées */
657   ret = _MEDdatasetFermer(gid);
658
659 //   EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_COO",NULL);
660
661   if(ret < 0)
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");
663
664   ret = H5Gunlink(nid,MED_NOM_COO);
665
666 //   EXIT_IF(ret < 0,"Suppression des anciennes coordonnées",NULL);
667
668   if(ret < 0)
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");
670
671   ret = _MEDdatasetFermer(tid);
672
673 //   EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL);
674
675   if(ret < 0)
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");
677
678   ret = H5Gmove(nid,"TMP",MED_NOM_COO);
679
680 //   EXIT_IF(ret < 0,"Mise en place des nouvelles coordonnées",NULL);
681
682   if(ret < 0)
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");
684
685   /* Mise a jour des noms des noeuds */
686   nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1);
687
688 //   EXIT_IF(nom == NULL,NULL,NULL);
689
690   if(nom == 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");
692
693   nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1);
694
695 //   EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
696
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");
699
700   ret = _MEDdatasetStringLire(nid,MED_NOM_NOM,nom);
701   if (ret == 0) {
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);  
706
707 //     EXIT_IF(ret < 0,"Ecriture des nouveaux noms des noeuds",NULL);  
708
709     if(ret < 0)
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");
711
712     gid = _MEDdatasetOuvrir(nid,MED_NOM_NOM);
713     ret = _MEDattrEntierEcrire(gid,MED_NOM_NBR,&n);
714     ret = _MEDdatasetFermer(gid);
715   }
716   free(nom);
717   free(nouvelle_chaine);
718
719   /* on ferme tout */
720   ret = _MEDdatagroupFermer(nid);
721
722 //   EXIT_IF(ret < 0,"Fermeture de l'accès aux noeuds",NULL);
723
724   if(ret < 0)
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");
726 }
727
728 void med_2_2::MAJ_elements_maillage(med_idt mid, med_int dimension)
729   throw (MEDEXCEPTION)
730 {
731   med_idt eid,gid,did,tid;
732   med_err ret;
733   int i,j;
734   med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE] = {MED_POINT1,MED_SEG2, 
735                                                             MED_SEG3,MED_TRIA3,
736                                                             MED_TRIA6,MED_QUAD4,
737                                                             MED_QUAD8,MED_TETRA4,
738                                                             MED_TETRA10,MED_HEXA8,
739                                                             MED_HEXA20,MED_PENTA6,
740                                                             MED_PENTA15,MED_PYRA5,
741                                                             MED_PYRA13};
742   int taille, edim;
743   char *nom, *nouvelle_chaine;
744   char nomgroup[MED_TAILLE_NOM_ENTITE+1];
745   med_int n;
746   med_size dimd[1];
747   med_int *old_conn,*conn;
748   
749   /* On ne regarde que les mailles et la connectivité nodale */
750   eid = _MEDdatagroupOuvrir(mid,MED_NOM_MAI);
751
752 //   EXIT_IF(eid < 0,"Ouverture du groupe HDF MED_NOM_MAI",NULL);
753
754   if(eid < 0)
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");
756
757   /* On normalise selon tous les types geometriques */
758   for (i=0;i<MED_NBR_GEOMETRIE_MAILLE;i++) {
759     
760     /* On recupere le nom du groupe HDF */
761     _MEDnomGeometrie(nomgroup,typmai[i]);
762
763     /* On accède au type s'il existe dans le fichier */
764     gid = _MEDdatagroupOuvrir(eid,nomgroup);
765     if (gid < 0)
766       continue;
767
768     /* Nombre d'element ? */
769     did = _MEDdatasetOuvrir(gid,MED_NOM_NOD);
770
771 //     EXIT_IF(did < 0,"Ouverture du dataset HDF MED_NOM_NOD",NULL);
772
773     if(did < 0)
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");
775
776     ret = _MEDattrEntierLire(did,MED_NOM_NBR,&n);
777
778 //     EXIT_IF(ret < 0,"Lecture du nombre d'elements",NULL);
779
780     if(ret < 0)
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");
782
783     ret = _MEDdatasetFermer(did);
784
785 //     EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_NOD",NULL);
786
787     if(ret < 0)
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");
789
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);
795
796 //       EXIT_IF(old_conn == NULL,NULL,NULL);
797
798       if(old_conn == 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");
800
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,
804                                   0,NULL,MED_NOPG,
805                                   (unsigned char*) old_conn,H5T_NATIVE_INT);
806 #else
807       ret = OLD_MEDdatasetNumLire(gid,MED_NOM_NOD,MED_INT32,
808                                   MED_NO_INTERLACE,(med_size) taille,MED_ALL,
809                                   0,NULL,MED_NOPG,
810                                   (unsigned char*) old_conn,H5T_NATIVE_INT);
811 #endif 
812       /* On recopie dans le bon tableau */
813       taille --;
814       conn = (med_int *) malloc(sizeof(med_int)*taille*n);
815
816 //       EXIT_IF(conn == NULL,NULL,NULL);
817
818       if(conn == 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");
820
821       for (j=0;j<n*taille;j++)
822         *(conn+j) = *(old_conn+j);
823       dimd[0] = n*taille;
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);
828 #else
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);
832 #endif
833
834 //       EXIT_IF(ret < 0,"Ecriture de la nouvelle connectivité des mailles",NULL);
835
836       if(ret < 0)
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");
838       
839       /* Ecriture du nombre de mailles dans le dataset HDF TMP */
840       tid = _MEDdatasetOuvrir(gid,"TMP");
841
842 //       EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL);
843
844       if(tid < 0)
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");
846
847       ret = _MEDattrEntierEcrire(tid,MED_NOM_NBR,&n);
848
849 //       EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL);
850
851       if(ret < 0)
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");
853
854       ret = _MEDdatasetFermer(tid);
855
856 //       EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL);
857
858       if(ret < 0)
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");
860
861       /* Fermeture de l'accès aux connectivites */
862       ret = H5Gunlink(gid,MED_NOM_NOD);
863
864 //       EXIT_IF(ret < 0,"Suppression des anciennes connectivités",NULL);
865
866       if(ret < 0)
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");
868
869       ret = H5Gmove(gid,"TMP",MED_NOM_NOD);
870
871 //       EXIT_IF(ret < 0,"Mise en place des nouvelles connectivités",NULL);
872
873       if(ret < 0)
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");
875
876       /* on libere la memoire */
877       free(old_conn);
878       free(conn);
879     }
880      
881     /* Mise a niveau des noms */
882     nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1);
883
884 //     EXIT_IF(nom == NULL,NULL,NULL);
885
886     if(nom == 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");
888
889     nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1);
890
891 //     EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
892
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");
895
896     ret = _MEDdatasetStringLire(gid,MED_NOM_NOM,nom);
897     if (ret == 0) {
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);  
902
903 //       EXIT_IF(ret < 0,"Ecriture des nouveaux noms des éléments",NULL);  
904
905       if(ret < 0)
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");
907
908       did = _MEDdatasetOuvrir(gid,MED_NOM_NOM);
909       ret = _MEDattrEntierEcrire(did,MED_NOM_NBR,&n);
910       ret = _MEDdatasetFermer(did);
911     }
912     free(nom);
913     free(nouvelle_chaine);
914
915     /* on ferme avant de passer au type geometrique suivant */
916     ret = _MEDdatagroupFermer(gid);
917
918 //     EXIT_IF(ret < 0,"Fermeture de l'accès aux mailles",NULL);
919
920     if(ret < 0)
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");
922   }
923
924   /* On ferme tout */
925   ret = _MEDdatagroupFermer(eid);
926
927 //   EXIT_IF(ret < 0,"Fermeture de l'accès aux mailles",NULL);
928
929   if(ret < 0)
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");
931 }
932
933 void med_2_2::MAJ_familles_maillage(med_idt mid) throw (MEDEXCEPTION)
934 {
935   med_idt fid, gid;
936   char *nouvelle_chaine;
937   int n;
938   med_size dimd[1];
939   med_err ret;
940   int i;
941   char chemin[MED_TAILLE_FAS+2*MED_TAILLE_NOM+1];
942   char nom[MED_TAILLE_NOM+1];
943   char *noeuds, *elements;
944   int nnoeuds = 0;
945   int nelements = 0;
946   med_int numero;
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];
953   med_float *valr;
954
955   /* Combien de famille ? */
956   fid = _MEDdatagroupOuvrir(mid,"FAS");
957
958 //   EXIT_IF(fid < 0,"Ouverture du groupe HDF 'FAS'",NULL);
959
960   if(fid < 0)
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");
962
963   n = 0;
964   _MEDnObjets(fid,".",&n);
965
966 //   EXIT_IF(n < 0,"Lecture du nombre de famille",NULL);
967
968   if(n < 0)
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");
970
971   noeuds = (char *) malloc(n*MED_TAILLE_NOM+1);
972
973 //   EXIT_IF(noeuds == NULL,NULL,NULL);
974
975   if(noeuds == 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");
977
978   index_noeuds = (int *) malloc(sizeof(int)*(n+1));
979
980 //   EXIT_IF(index_noeuds == NULL,NULL,NULL);
981
982   if(index_noeuds < 0)
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");
984   
985   elements = (char *) malloc(n*MED_TAILLE_NOM+1);
986
987 //   EXIT_IF(elements == NULL,NULL,NULL);
988
989   if(elements == 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");
991
992   index_elements = (int *) malloc(sizeof(int)*(n+1));
993
994 //   EXIT_IF(index_elements == NULL,NULL,NULL);
995   
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");
998
999   /* On recupere les familles une par une et on les
1000      normalise */
1001   for (i=0;i<n;i++) {
1002     ret = _MEDobjetIdentifier(fid,".",i,nom);
1003
1004 //     EXIT_IF(ret < 0,"Identification d'une famille",NULL);
1005
1006     if(ret < 0)
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");
1008
1009     /* On accede a la famille */
1010     gid = _MEDdatagroupOuvrir(fid,nom);
1011
1012 //     EXIT_IF(gid < 0,"Ouverture de l'accès à la famille",nom);
1013
1014     if(gid < 0)
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");
1016
1017     /* On lit le numero de la famille */
1018     ret = _MEDattrEntierLire(gid,MED_NOM_NUM,&numero);
1019
1020 //     EXIT_IF(ret < 0,"Lecture du numéro de la famille",nom);
1021      
1022     if(ret < 0)
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");
1024
1025     /* On ferme l'acces a la famille */
1026     ret = _MEDdatagroupFermer(gid);
1027
1028 //     EXIT_IF(ret < 0,"Fermeture de l'accès a la famille",nom);
1029
1030     if(ret < 0)
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");
1032
1033     if (numero == 0) 
1034       strcpy(famille0,nom);
1035
1036     if (numero < 0) {
1037       if (nelements == 0) { 
1038         *(index_elements) = 0;
1039         strcpy(elements,nom);
1040       }
1041       else
1042         strcat(elements,nom);
1043       nelements ++;
1044       *(index_elements+nelements) = strlen(nom) + *(index_elements+nelements-1);
1045     }
1046
1047     if (numero > 0) {
1048       if (nnoeuds == 0) {
1049         strcpy(noeuds,nom);
1050         *(index_noeuds) = 0;
1051       }
1052       else
1053         strcat(noeuds,nom);
1054       nnoeuds++;
1055       *(index_noeuds+nnoeuds) = strlen(nom) + *(index_noeuds+nnoeuds-1);
1056     }
1057   }
1058
1059   /* Normalisation de la famille 0 */
1060   ret = H5Gmove(fid,famille0,nom_famille_zero);
1061
1062 //   EXIT_IF(ret < 0,"Normalisation de la famille ZERO",NULL);
1063
1064   if(ret < 0)
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");
1066
1067   /* On cree les groupes HDF pour les familles de noeuds et d'elements */
1068   gid = _MEDdatagroupCreer(fid,groupe_noeuds); 
1069
1070 //   EXIT_IF(gid < 0,"Creation du grupe HDF pour les familles de noeuds",NULL); 
1071
1072   if(gid < 0)
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");
1074
1075   ret = _MEDdatagroupFermer(gid); 
1076
1077 //   EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles de noeuds",NULL); 
1078
1079   if(ret < 0)
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");
1081
1082   gid = _MEDdatagroupCreer(fid,groupe_elements); 
1083
1084 //   EXIT_IF(gid < 0,"Creation du groupe HDF pour les familles d'éléments",NULL); 
1085
1086   if(gid < 0)
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");
1088
1089   ret = _MEDdatagroupFermer(gid); 
1090
1091 //   EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles d'éléments",NULL); 
1092
1093   if(ret < 0)
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");
1095
1096   /* On deplace les groupes HDF des familles en fonction de la nature de 
1097      chaque famille */
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); 
1105
1106 //     EXIT_IF(ret < 0,"Normalisation de la famille",nom); 
1107
1108     if(ret < 0)
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");
1110   }
1111
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);  
1119
1120 //     EXIT_IF(ret < 0,"Normalisation de la famille",nom);  
1121
1122     if(ret < 0)
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");
1124   }
1125
1126   /* On libere la memoire */
1127   free(noeuds);
1128   free(index_noeuds);
1129   free(elements);
1130   free(index_elements);
1131
1132   /* On ferme tout */
1133   ret = _MEDdatagroupFermer(fid);
1134
1135 //   EXIT_IF(ret < 0,"Fermeture du groupe HDF 'FAS'",NULL);
1136
1137   if(ret < 0)
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");
1139 }
1140
1141 void med_2_2::MAJ_maillages(med_idt fid) throw (MEDEXCEPTION)
1142 {
1143   med_idt gid;
1144   med_err ret;
1145   int n,i;
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;
1150   med_int dimension;
1151   
1152   /* Lecture du nombre de maillages */
1153   n = 0;
1154   _MEDnObjets(fid,MED_MAA,&n);
1155
1156 //   EXIT_IF(n < 0,"Erreur a la lecture du nombre de maillage",NULL);
1157
1158   if(n < 0)
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");
1160
1161   /* 
1162    * Mise a jour des maillages :
1163    *  - type : MED_NON_STRUCTURE
1164    *  - description : "Maillage converti au format V2.2"
1165    */
1166   for (i=0;i<n;i++) {
1167     /* on recupere le nom du maillage */
1168     ret = _MEDobjetIdentifier(fid,MED_MAA,i,nom);
1169
1170 //     EXIT_IF(ret < 0,"Identification d'un maillage",NULL);
1171
1172     if(ret < 0)
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");
1174
1175 //     fprintf(stdout,"  >>> Normalisation du maillage [%s] \n",nom);
1176
1177     MESSAGE("med File convertor 2.1 to 2.2 :: >>> Normalisation du maillage [" << nom << "]");
1178
1179     /* on accede au maillage */
1180     strcpy(chemin,MED_MAA);
1181     strcat(chemin,nom);
1182     gid = _MEDdatagroupOuvrir(fid,chemin); 
1183
1184 //     EXIT_IF(gid < 0,"Accès au maillage",nom);
1185
1186     if(gid < 0)
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");
1188
1189     /* lecture de la dimension du maillage */
1190     ret = _MEDattrEntierLire(gid,MED_NOM_DIM,&dimension);
1191
1192 //     EXIT_IF(ret < 0,"Lecture de la dimension du maillage",nom);
1193
1194     if(ret < 0)
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");
1196
1197     /* Ecriture du type et de la description */
1198     ret = _MEDattrStringEcrire(gid,MED_NOM_DES,MED_TAILLE_DESC,description);
1199
1200 //     EXIT_IF(ret < 0,"Ecriture de la description du maillage ",nom);
1201
1202     if(ret < 0)
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");
1204
1205     ret = _MEDattrEntierEcrire(gid,MED_NOM_TYP,&type);
1206
1207 //     EXIT_IF(ret < 0,"Ecriture de la dimension du maillage ",nom);
1208
1209     if(ret < 0)
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");
1211     
1212     /* Mise a jour des noeuds du maillage */ 
1213     MAJ_noeuds_maillage(gid,dimension);  
1214
1215 //     fprintf(stdout,"  ... Normalisation des noeuds effectuée ... \n");
1216
1217     MESSAGE("med File convertor 2.1 to 2.2 ::  ... Normalisation des noeuds effectuée ...");
1218
1219     /* Mise a jour des éléments du maillage */ 
1220     MAJ_elements_maillage(gid,dimension);  
1221
1222 //     fprintf(stdout,"  ... Normalisation des éléments effectuée ... \n");
1223
1224     MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des éléments effectuée ...");
1225
1226     /* Mise a jour des familles du maillage */
1227     MAJ_familles_maillage(gid);
1228
1229 //     fprintf(stdout,"  ... Normalisation des familles effectuée ... \n");
1230
1231     MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des familles effectuée ...");
1232     
1233     /* On ferme tout */
1234     ret = _MEDdatagroupFermer(gid);
1235
1236 //     EXIT_IF(ret < 0,"Fermeture de l'accès au maillage",NULL);
1237
1238     if(ret < 0)
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");
1240
1241 //     fprintf(stdout,"  >>> Normalisation du maillage [%s] ... OK ... \n",nom);
1242
1243     MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du maillage [" << nom << "] ... OK ... ");
1244   }
1245 }
1246
1247 void med_2_2::MAJ_localisation_Gauss(med_idt fid,char *nom_modele,
1248                                      med_int ngauss)
1249   throw (MEDEXCEPTION)
1250 {
1251   med_err ret;
1252   med_geometrie_element type;
1253   med_float *refcoo, *gaucoo, *poids;
1254   char nom_type[4];
1255   med_int edim, nsom,n,nlu;
1256   int i;
1257   char nom[MED_TAILLE_NOM+1];
1258
1259   /* On regarde si la localisation bidon existe deja 
1260      Si oui on s'en va */
1261   n = MEDnGauss(fid);
1262   if (n > 0)
1263     for (i=1;i<=n;i++) {
1264       ret = MEDgaussInfo(fid,i,nom,&type,&nlu);
1265       if (! strcmp(nom,nom_modele)) return;
1266     }
1267   
1268   /* On deduit le type en fonction de nom_modele */
1269   strncpy(nom_type,nom_modele,3);
1270   nom_type[3] = '\0';
1271   if (! strcmp(nom_type,MED_NOM_SE2))
1272     type = MED_SEG2;
1273   if (! strcmp(nom_type,MED_NOM_SE3))
1274     type = MED_SEG3; 
1275   if (! strcmp(nom_type,MED_NOM_TR3))
1276     type = MED_TRIA3; 
1277   if (! strcmp(nom_type,MED_NOM_TR6))
1278     type = MED_TRIA6;
1279   if (! strcmp(nom_type,MED_NOM_QU4))
1280     type = MED_QUAD4; 
1281   if (! strcmp(nom_type,MED_NOM_QU8))
1282     type = MED_QUAD8;
1283   if (! strcmp(nom_type,MED_NOM_TE4))
1284     type = MED_TETRA4; 
1285   if (! strcmp(nom_type,MED_NOM_T10))
1286     type = MED_TETRA10; 
1287     if (! strcmp(nom_type,MED_NOM_HE8))
1288     type = MED_HEXA8; 
1289   if (! strcmp(nom_type,MED_NOM_H20))
1290     type = MED_HEXA20;
1291   if (! strcmp(nom_type,MED_NOM_PE6))
1292     type = MED_PENTA6; 
1293   if (! strcmp(nom_type,MED_NOM_P15))
1294     type = MED_PENTA15;
1295   if (! strcmp(nom_type,MED_NOM_PY5))
1296     type = MED_PYRA5; 
1297   if (! strcmp(nom_type,MED_NOM_P13))
1298     type = MED_PYRA13;
1299
1300   /* Dimension de la maille */
1301   edim = type / 100;
1302   nsom = type % 100;
1303
1304   /* On definit des coordonnées et des poids bidon */
1305   refcoo = (med_float*) malloc(sizeof(med_float)*edim*nsom);
1306
1307 //   EXIT_IF(refcoo == NULL,NULL,NULL);
1308
1309   if(refcoo == 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");
1311
1312   for (i=0;i<edim*nsom;i++) *(refcoo+i) = 0.;
1313   gaucoo = (med_float*) malloc(sizeof(med_float)*edim*ngauss);
1314
1315 //   EXIT_IF(gaucoo == NULL,NULL,NULL);
1316
1317   if(gaucoo == 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");
1319
1320   for (i=0;i<edim*ngauss;i++) *(gaucoo+i) = 0.;
1321   poids  = (med_float*) malloc(sizeof(med_float)*ngauss);
1322
1323 //   EXIT_IF(poids == NULL,NULL,NULL);
1324
1325   if(poids == 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");
1327
1328   for (i=0;i<ngauss;i++) *(poids+i) = 0.;
1329
1330   /* On ecrit la localisation bidon */
1331   ret = MEDgaussEcr(fid,type,refcoo,MED_FULL_INTERLACE,ngauss,gaucoo,poids,nom_modele);
1332
1333 //   EXIT_IF(ret < 0,"Ecriture de la localisation des points de Gauss",nom_modele);
1334
1335   if(ret < 0)
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");
1337
1338   /* On libere la memoire */
1339   free(refcoo);
1340   free(gaucoo);
1341   free(poids);
1342 }
1343
1344 void med_2_2::MAJ_champs(med_idt fid) throw (MEDEXCEPTION)
1345 {
1346   med_idt gid,eid,pid,mid,did,aid;
1347   med_err ret;
1348   int n,i,j,k;
1349   char nom[MED_TAILLE_NOM+1];
1350   char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1];
1351   char maillage[MED_TAILLE_NOM+1];
1352   med_int type;
1353   char *comp, *unit;
1354   char *nouvelle_chaine;
1355   med_int ncomp;
1356   int nent, npdt;
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];
1362   med_int att;
1363   char profil[MED_TAILLE_NOM+1];
1364   char gauss[MED_TAILLE_NOM+1];
1365   med_float *valr;
1366   med_int nval;
1367   hid_t hdf_type;
1368   med_size dimd[1];
1369   med_float pdt;
1370   
1371   /* Lecture du nombre de champs */
1372   n = 0;
1373   _MEDnObjets(fid,MED_CHA,&n);
1374
1375 //   EXIT_IF(n < 0,"Erreur a la lecture du nombre de champ",NULL);
1376
1377   if(n < 0)
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");
1379
1380   for (i=0;i<n;i++) {
1381     /* on recupere le nom du champ */
1382     ret = _MEDobjetIdentifier(fid,MED_CHA,i,nom);
1383
1384 //     EXIT_IF(ret < 0,"Identification d'un champ",NULL);
1385
1386     if(ret < 0)
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");
1388
1389 //     fprintf(stdout,"  >>> Normalisation du champ [%s] \n",nom);
1390
1391     MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du champ [" << nom << "]");
1392
1393     /* on accede au champ */
1394     strcpy(chemin,MED_CHA);
1395     strcat(chemin,nom);
1396     gid = _MEDdatagroupOuvrir(fid,chemin); 
1397
1398 //     EXIT_IF(gid < 0,"Accès au champ",nom);
1399
1400     if(gid < 0)
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");
1402
1403     /* Lecture du nombre de composantes */ 
1404     ret = _MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp);
1405
1406 //     EXIT_IF(ret < 0,"Lecture du nombre de composante",NULL);
1407
1408     if(ret < 0)
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");
1410
1411     /* Lecture du type du champ */
1412     ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&type);
1413
1414 //     EXIT_IF(ret < 0,"Lecture du type du champ",NULL);
1415
1416     if(ret < 0)
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");
1418
1419     /* Normalisation des nom et unites des composantes */
1420     comp = (char *) malloc(ncomp*ANCIEN_MED_TAILLE_PNOM+1);
1421
1422 //     EXIT_IF(comp == NULL,NULL,NULL);
1423
1424     if(comp == 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");
1426
1427     unit = (char *) malloc(ncomp*ANCIEN_MED_TAILLE_PNOM+1);
1428
1429 //     EXIT_IF(unit == NULL,NULL,NULL);
1430
1431     if(unit == 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");
1433
1434     nouvelle_chaine = (char *) malloc(ncomp*MED_TAILLE_PNOM+1);
1435
1436 //     EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
1437
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");
1440
1441     ret = _MEDattrStringLire(gid,MED_NOM_NOM,ncomp*ANCIEN_MED_TAILLE_PNOM,comp);
1442
1443 //     EXIT_IF(ret < 0,"Lecture des noms des composantes du champ",NULL);
1444
1445     if(ret < 0)
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");
1447
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);
1451
1452 //     EXIT_IF(ret < 0,"Ecriture des nouveaux noms des composantes du champ",NULL);  
1453
1454     if(ret < 0)
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");
1456
1457     free(comp);
1458
1459     ret = _MEDattrStringLire(gid,MED_NOM_UNI,ncomp*ANCIEN_MED_TAILLE_PNOM,unit);
1460
1461 //     EXIT_IF(ret < 0,"Lecture des unités des composantes du champ",NULL);
1462
1463     if(ret < 0)
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");
1465
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);
1469
1470 //     EXIT_IF(ret < 0,"Ecriture des nouvelles unités des composantes du champ",NULL);  
1471
1472     if(ret < 0)
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");
1474
1475     free(unit);
1476
1477     free(nouvelle_chaine);
1478
1479 //     fprintf(stdout,"  ... Normalisation des noms et unités des composantes effectuée...\n");
1480
1481     MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des noms et unités des composantes effectuée...");
1482
1483     /* On ajoute le groupe HDF correspondant au maillage */
1484     /* On recupere le nom du maillage par defaut */
1485     nent = 0;
1486     _MEDnObjets(gid,"./",&nent);
1487
1488 //     EXIT_IF(nent < 0,"Erreur a la lecture du nombre d'entité dans un champ",NULL);
1489
1490     if(nent < 0)
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");
1492
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);
1496
1497 //       EXIT_IF(ret < 0,"Identification des objets de niveau 1 dans le champ",NULL);
1498
1499       if(ret < 0)
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");
1501
1502       /* On ouvre le groupe HDF */
1503       eid = _MEDdatagroupOuvrir(gid,noment);
1504
1505 //       EXIT_IF(eid < 0,"Ouverture du groupe HDF de niveau 1",NULL);
1506
1507       if(eid < 0)
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");
1509
1510       /* On recupere le nombre de pas de temps */
1511       npdt = 0;
1512       _MEDnObjets(eid,"./",&npdt);
1513
1514 //       EXIT_IF(nent < 0,"Erreur a la lecture du nombre de pas de temps",NULL);
1515       
1516       if(nent < 0)
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");
1518
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);
1523
1524 //      EXIT_IF(ret < 0,"Identification des objets de niveau 2 dans le champ",NULL);
1525         
1526         if(ret < 0)
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");
1528
1529         /* On ouvre le groupe HDF correspondant au pas de temps */
1530         pid = _MEDdatagroupOuvrir(eid,nompdt);
1531
1532 //      EXIT_IF(pid < 0,"Ouverture du groupe HDF de niveau 2",NULL);
1533
1534         if(pid < 0)
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");
1536
1537         /* On lit le pas de temps */
1538         aid = H5Aopen_name(pid,MED_NOM_PDT);
1539
1540 //      EXIT_IF(aid < 0,"Ouverture de l'attribut HDF MED_NOM_PDT",NULL);
1541
1542         if(aid < 0)
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");
1544
1545         hdf_type = H5Aget_type(aid);
1546
1547 //      EXIT_IF(hdf_type < 0,"Lecture du type de l'attribut HDF MED_NOM_PDT",NULL);
1548
1549         if(hdf_type < 0)
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");
1551
1552         ret = H5Aclose(aid);
1553
1554 //      EXIT_IF(ret < 0,"Fermeture de l'attribut MED_NOM_PDT",NULL);
1555
1556         if(ret < 0)
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");
1558
1559         ret = OLD_MEDattrNumLire(pid,MED_FLOAT64,MED_NOM_PDT,(unsigned char*)(&pdt),hdf_type);
1560
1561 //      EXIT_IF(ret < 0,"Lecture du pas de temps dans MED_NOM_PDT",NULL);
1562
1563         if(ret < 0)
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");
1565
1566         dimd[0] = 1;
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); */
1572
1573 //        EXIT_IF(ret < 0,"Conversion du pas de temps",NULL);
1574
1575           if(ret < 0)
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");
1577         }
1578         H5Tclose(hdf_type);
1579         /*      printf("pdt = %f\n",pdt); */
1580         H5Adelete(pid,MED_NOM_PDT);
1581         ret = _MEDattrFloatEcrire(pid,MED_NOM_PDT,&pdt);
1582
1583 //      EXIT_IF(ret < 0,"Ecriture du nouveau pas de temps",NULL);
1584
1585         if(ret < 0)
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");
1587
1588         /* On met a jour l'unité du pas de temps : 8 -> 16 caractères 
1589            Si on rencontre "        " => on ecrit "" 
1590         */
1591         ret = _MEDattrStringLire(pid,MED_NOM_UNI,ANCIEN_MED_TAILLE_PNOM,oldunidt);
1592
1593 //      EXIT_IF(ret < 0,"Lecture de l'unite du pas de temps",NULL);
1594
1595         if(ret < 0)
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");
1597
1598         if (! strcmp(oldunidt,ANCIEN_MED_BLANC_PNOM))
1599           strcpy(unitdt,"");
1600         else
1601           conversion_chaine(oldunidt,unitdt,1);
1602         H5Adelete(pid,MED_NOM_UNI);
1603         ret = _MEDattrStringEcrire(pid,MED_NOM_UNI,MED_TAILLE_PNOM,unitdt);
1604
1605 //      EXIT_IF(ret < 0,"Ecriture de la nouvelle unité du pas de temps",NULL);  
1606         if(ret < 0)
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");
1608
1609         /* On recupere le nom du maillage */
1610         ret = _MEDattrStringLire(pid,MED_NOM_MAI,MED_TAILLE_NOM,maillage);
1611
1612 //      EXIT_IF(ret < 0,"Lecture du nom du maillage du pas de temps",NULL);
1613
1614         if(ret < 0)
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");
1616
1617         /* On cree le groupe HDF de niveau 3 qui porte le nom du maillage */
1618         mid = _MEDdatagroupCreer(pid,maillage);
1619
1620 //      EXIT_IF(mid < 0,"Creation du groupe HDF de niveau 3",NULL);
1621
1622         if(mid < 0)
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");
1624
1625         /* Déplacement de l'attribut MED_NOM_NBR */
1626         ret = _MEDattrEntierLire(pid,MED_NOM_NBR,&nval);
1627
1628 //      EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_NBR",NULL);
1629
1630         if(ret < 0)
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");
1632
1633         ret = H5Adelete(pid,MED_NOM_NBR);
1634
1635 //      EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_NBR",NULL);
1636
1637         if(ret < 0)
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");
1639
1640         ret = _MEDattrEntierEcrire(mid,MED_NOM_NBR,&nval);
1641
1642 //      EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NBR au niveau 3",NULL);
1643
1644         if(ret < 0)
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");
1646
1647         /* Deplacement de l'attribut MED_NOM_NGA */
1648         ret = _MEDattrEntierLire(pid,MED_NOM_NGA,&att);
1649
1650 //      EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_NGA",NULL);
1651
1652         if(ret < 0)
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");
1654
1655         ret = H5Adelete(pid,MED_NOM_NGA);
1656
1657 //      EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_NGA",NULL);
1658
1659         if(ret < 0)
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");
1661
1662         ret = _MEDattrEntierEcrire(mid,MED_NOM_NGA,&att);
1663
1664 //      EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NGA au niveau 3",NULL);
1665
1666         if(ret < 0)
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");
1668
1669         /* Ecriture de l'attribut MED_NOM_GAU : localisation des points de Gauss */
1670         if (att < 2)
1671           strcpy(gauss,MED_NOM_BLANC);
1672         else {
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);
1679         }
1680         ret = _MEDattrStringEcrire(mid,MED_NOM_GAU,MED_TAILLE_NOM,gauss);
1681
1682 //      EXIT_IF(ret < 0,"Ecriture de la localisation des points de Gauss",NULL);
1683         if(ret < 0)
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");
1685
1686         /* Deplacement de l'attribut MED_NOM_PFL */
1687         ret = _MEDattrStringLire(pid,MED_NOM_PFL,MED_TAILLE_NOM,profil);
1688
1689 //      EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_PFL",NULL);
1690
1691         if(ret < 0)
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");
1693
1694         if(ret < 0)
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");
1696
1697         ret = H5Adelete(pid,MED_NOM_PFL);
1698
1699 //      EXIT_IF(ret < 0,"Desctruction de l'attribut MED_NOM_PFL",NULL);
1700
1701         if(ret < 0)
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");
1703
1704         ret = _MEDattrStringEcrire(mid,MED_NOM_PFL,MED_TAILLE_NOM,profil);
1705
1706 //      EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_PFL au niveau 3",NULL);
1707
1708         if(ret < 0)
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");
1710
1711         /* On ferme le groupe HDF de niveau 3 */
1712         ret = _MEDdatagroupFermer(mid);
1713
1714 //      EXIT_IF(ret < 0,"fermeture du groupe HDF de niveau 3",NULL);
1715
1716         if(ret < 0)
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");
1718
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);
1722         strcat(tmp,"/");
1723         strcat(tmp,MED_NOM_CO);
1724         if (type != MED_FLOAT64) {
1725           ret = H5Gmove(pid,MED_NOM_CO,tmp);
1726
1727 //        EXIT_IF(ret < 0,"Transfert du dataset MED_NOM_CO",NULL);
1728
1729           if(ret < 0)
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");
1731         } else {
1732           did = _MEDdatasetOuvrir(pid,MED_NOM_CO);
1733
1734 //        EXIT_IF(did < 0,"Ouverture du dataset HDF des valeurs",NULL);
1735
1736           if(did < 0)
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");
1738
1739           hdf_type = H5Dget_type(did);
1740
1741 //        EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des valeurs",NULL);
1742
1743           if(hdf_type < 0)
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");
1745
1746           ret = _MEDdatasetFermer(did);
1747
1748 //        EXIT_IF(ret < 0,"Fermeture du dataset HDF des valeurs",NULL);
1749
1750           if(ret < 0)
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");
1752
1753           valr = (med_float *) malloc(sizeof(med_float)*ncomp*nval);
1754
1755 //        EXIT_IF(valr == NULL,NULL,NULL);
1756
1757           if(valr == 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");
1759
1760           ret = OLD_MEDdatasetNumLire(pid,MED_NOM_CO,MED_FLOAT64,
1761                                       MED_FULL_INTERLACE,ncomp,MED_ALL,
1762                                       0,NULL,MED_NOPG,
1763                                       (unsigned char*) valr,hdf_type);
1764
1765 //        EXIT_IF(ret < 0,"Lecture des valeurs du champ",NULL);
1766
1767           if(ret < 0)
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");
1769
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);
1773
1774 //        EXIT_IF(ret < 0,"Conversion des valeurs",NULL);
1775
1776           if(ret < 0)
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");
1778
1779           H5Tclose(hdf_type);
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);
1784
1785 //        EXIT_IF(ret < 0,"Ecriture des valeurs après conversion",NULL);
1786
1787           if(ret < 0)
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");
1789
1790           free(valr);
1791         }
1792           
1793         /* On ferme le groupe HDF de niveau 2*/
1794         ret = _MEDdatagroupFermer(pid);
1795
1796 //      EXIT_IF(ret < 0,"Fermeture du groupe HDF de niveau 2",NULL);
1797
1798         if(ret < 0)
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");
1800       }
1801
1802       /* On ferme le groupe HDF */
1803       ret = _MEDdatagroupFermer(eid);
1804
1805  //      EXIT_IF(ret < 0,"Fermeture du groupe HDF de niveau 1",NULL);
1806
1807       if(ret < 0)
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");
1809     }
1810
1811 //     fprintf(stdout,"  ... Normalisation de tous les pas de temps effectuée...\n");
1812
1813     MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation de tous les pas de temps effectuée...\n");
1814
1815     /* On ferme tout */
1816     ret = _MEDdatagroupFermer(gid);
1817
1818 //     EXIT_IF(ret < 0,"Fermeture de l'accès au champ",NULL);
1819     
1820     if(ret < 0)
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");
1822
1823 //     fprintf(stdout,"  >>> Normalisation du champ [%s] : ... OK ... \n",nom);
1824
1825     MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du champ [" << nom << "] : ... OK ... ");
1826   }
1827 }
1828
1829 void med_2_2::MAJ_profils(med_idt fid,med_int nprofil) throw (MEDEXCEPTION)
1830 {
1831   med_err ret;
1832   med_int i;
1833   char nom[MED_TAILLE_NOM+1];
1834   char chemin[MED_TAILLE_DESC+1];
1835   med_idt gid;
1836   med_int att;
1837
1838   for (i=0;i<nprofil;i++)
1839     {    
1840       /* on recupere le nom du profil */
1841       ret = _MEDobjetIdentifier(fid,MED_PROFILS,i,nom);
1842
1843  //      EXIT_IF(ret < 0,"Identification d'un profil",NULL);
1844
1845       if(ret < 0)
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");
1847
1848 //       fprintf(stdout,"  >>> Normalisation du profil [%s] \n",nom);
1849
1850       MESSAGE("med File convertor 2.1 to 2.2 ::  Normalisation du profil [" << nom << "] ");
1851
1852       /* on accede au profil */
1853       strcpy(chemin,MED_PROFILS);
1854       strcat(chemin,nom);
1855       gid = _MEDdatagroupOuvrir(fid,chemin); 
1856
1857 //       EXIT_IF(gid < 0,"Accès au profil",nom);
1858
1859       if(gid < 0)
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");
1861
1862
1863       /* On change l'attribut MED_NOM_N => MED_NOM_NBR */
1864       ret = _MEDattrEntierLire(gid,"N",&att);
1865
1866 //       EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_N",NULL);
1867
1868       if(ret < 0)
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");
1870
1871       ret = H5Adelete(gid,"N");
1872
1873 //       EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_N",NULL);
1874
1875       if(ret < 0)
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");
1877
1878       ret = _MEDattrEntierEcrire(gid,MED_NOM_NBR,&att);
1879
1880 //       EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NBR dans le profil ",nom);
1881
1882       if(ret < 0)
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");
1884
1885       /* on ferme le profil */
1886       ret = _MEDdatagroupFermer(gid);
1887
1888 //       EXIT_IF(ret < 0,"Fermeture de l'acces au profil",nom);
1889
1890       if(ret < 0)
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");
1892
1893 //       fprintf(stdout,"  >>> Normalisation du profil [%s] effectuée \n",nom);
1894
1895       MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du profil [" << nom << "]");
1896     }
1897 }
1898
1899 char * MEDMEM::med2_1_To_med2_2(char * fileNameIn) throw (MEDEXCEPTION)
1900 {
1901   med_idt fid, gid;
1902   med_err ret;
1903   med_int majeur, mineur, release;
1904 /*   char *nom; */
1905   char *commande;
1906   med_int nprofil;
1907   char chemin_profils[MED_TAILLE_PROFILS+1];
1908   char chemin_liens[MED_TAILLE_LIENS+1];
1909
1910   char * InternalFileNameOut;
1911
1912   char * envHome = (char *) malloc(sizeof(char)*(strlen("HOME")+1));
1913
1914   strcpy(envHome,"HOME");
1915
1916   char * envHomeChar = getenv(envHome);
1917
1918   /* Test du nombre d'argument */
1919 //   EXIT_IF(argc != 2,"Nombre de parametre incorrect",NULL);
1920
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]); */
1924
1925 //   EXIT_IF(MEDformatConforme(fileNameIn) < 0,
1926 //        "Le fichier n'est pas au format HDF 5 : ", fileNameIn);
1927
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");
1930
1931   /* opening the old file to check the versions (Med File and HDF) */
1932
1933   fid = MEDouvrir(fileNameIn,MED_LECTURE);
1934
1935 /*   EXIT_IF(fid < 0,"Ouverture du fichier : ", */
1936 /*        nom); */
1937
1938 //   EXIT_IF(fid < 0,"Ouverture du fichier : ",
1939 //        InternalFileNameOut);
1940
1941   MESSAGE("med File convertor 2.1 to 2.2 ::  opening of the old file id " << fid);
1942
1943   if(fid < 0)
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");
1945
1946   /* Verification du numero de version */
1947   ret = MEDversionLire(fid,&majeur,&mineur,&release); 
1948
1949 //   EXIT_IF(ret < 0,"Lecture du numero de version de MED-fichier",NULL);  
1950
1951   if(ret < 0)
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");
1953
1954   if (majeur == 2 && mineur == 2) {  
1955 /*     fprintf(stdout,"Le fichier %s est déjà au format V2.2 !!! \n",nom);   */
1956
1957 //     fprintf(stdout,"Le fichier %s est déjà au format V2.2 !!! \n",InternalFileNameOut);  
1958
1959     MESSAGE("med File convertor 2.1 to 2.2 :: the file " << fileNameIn << " is already a med 2.2 file");
1960
1961     ret = MEDfermer(fid);  
1962 /*     EXIT_IF(ret < 0,"Fermeture du fichier",argv[1]);  */
1963
1964 //     EXIT_IF(ret < 0,"Fermeture du fichier",fileNameIn); 
1965
1966     if(ret < 0)
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");
1968
1969     return fileNameIn ;
1970   }
1971
1972   ret = MEDfermer(fid); 
1973
1974   /*
1975     we are sure now that the file is an old version one
1976     creation of the directory if it does not existe
1977   */
1978
1979   commande = (char *) malloc(sizeof(char)*(strlen("mkdir ")+
1980                                            strlen(envHomeChar)+
1981                                            strlen("/TMP_Med2_2Files/")+1));
1982
1983 //   EXIT_IF(commande == NULL,NULL,NULL);
1984
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");
1987
1988   strcpy(commande,"ls ");
1989   strcat(commande,envHomeChar);
1990   strcat(commande,"/TMP_Med2_2Files/");
1991
1992   int systemReturn = system(commande);
1993
1994   if (systemReturn != 0)
1995     {
1996       strcpy(commande,"mkdir ");
1997       strcat(commande,envHomeChar);
1998       strcat(commande,"/TMP_Med2_2Files/");
1999
2000       systemReturn = system(commande);
2001     }
2002
2003   free(commande);
2004
2005   free(envHome);
2006
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));
2012
2013   strcpy(InternalFileNameOut,envHomeChar);
2014   strcat(InternalFileNameOut,"/TMP_Med2_2Files/");
2015   strcat(InternalFileNameOut,string(fileNameIn,pos1+1,pos-pos1-1).c_str());
2016
2017   MESSAGE("med File convertor 2.1 to 2.2 :: " << InternalFileNameOut);
2018
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)); */
2021
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));
2027
2028 //   EXIT_IF(commande == NULL,NULL,NULL);
2029
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");
2032
2033 /*   nom = (char *) malloc(sizeof(char)*(strlen(argv[1])+strlen("2.2")+1)); */
2034
2035 /*   nom = (char *) malloc(sizeof(char)*(strlen(fileNameIn)+strlen("2.2")+1)); */
2036
2037 /*   EXIT_IF(nom == NULL,NULL,NULL); */
2038 /*   strcpy(nom,argv[1]); */
2039
2040 /*   strcpy(nom,fileNameIn); */
2041
2042 /*   strcat(nom,"2.2"); */
2043
2044 //   strcpy(fileNameOut,fileNameIn);
2045
2046 //   strcat(fileNameOut,"2.2");
2047
2048   strcpy(commande,"cp -f ");
2049 /*   strcat(commande,argv[1]); */
2050
2051   strcat(commande,fileNameIn);
2052
2053   strcat(commande," ");
2054 /*   strcat(commande,nom); */
2055
2056   strcat(commande,InternalFileNameOut);
2057
2058   strcat(commande," ; chmod ug+rw ");
2059
2060   strcat(commande,InternalFileNameOut);
2061
2062   system(commande);
2063 /*   fprintf(stdout,">>> Creation du fichier %s : %s \n",nom,commande); */
2064
2065 //   fprintf(stdout,">>> Creation du fichier %s : %s \n",InternalFileNameOut,commande);
2066
2067   MESSAGE("med File convertor 2.1 to 2.2 ::  Creation du fichier " << InternalFileNameOut << " with the commande " << commande);
2068
2069   free(commande);
2070
2071 /*   fid = MEDouvrir(nom,MED_LECTURE_ECRITURE); */
2072
2073   fid = MEDouvrir(InternalFileNameOut,MED_LECTURE_ECRITURE);
2074
2075 /*   EXIT_IF(fid < 0,"Ouverture du fichier : ", */
2076 /*        nom); */
2077
2078 //   EXIT_IF(fid < 0,"Ouverture du fichier : ",
2079 //        InternalFileNameOut);
2080
2081   MESSAGE("med File convertor 2.1 to 2.2 ::  opening of the new file id " << fid);
2082
2083   if(fid < 0)
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");
2085
2086   /* On avertit qu'on commence la conversion */
2087
2088 //   fprintf(stdout,">>> Lancement de la normalisation du fichier selon le format MED V2.2 ...\n");
2089
2090   MESSAGE("med File convertor 2.1 to 2.2 :: Running the convertor fromV 2.1 to V2.2");
2091
2092   /* On inhibe le gestionnaire d'erreur HDF5 */
2093   _MEDmodeErreurVerrouiller();  
2094
2095   /* Mise a jour du numero de version */
2096
2097 //   fprintf(stdout,"- Lancement de la mise à jour du numéro de version ... \n");
2098
2099   MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of the version number");
2100
2101   MAJ_version(fid);
2102
2103 //   fprintf(stdout,"  Numéro de version : ... OK ... \n");
2104
2105   MESSAGE("med File convertor 2.1 to 2.2 :: Version number OK ...");
2106
2107   /* Mise a jour des maillages : type = MED_NON_STRUCTURE, description, ... */
2108
2109 //   fprintf(stdout,"- Lancement de la mise à jour des maillages ... \n"); 
2110
2111   MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of all meshes");
2112
2113   MAJ_maillages(fid); 
2114
2115 //   fprintf(stdout,"  Maillage(s) : ... OK ...\n"); 
2116
2117   MESSAGE("med File convertor 2.1 to 2.2 :: meshes are OK....");
2118
2119   /* Mise a jour des champs */
2120
2121 //   fprintf(stdout,"- Lancement de la mise à jour des champs de résultats ... \n");
2122
2123   MESSAGE("med File convertor 2.1 to 2.2 :: Running of the update of all fields ..");
2124
2125   MAJ_champs(fid);
2126
2127 //   fprintf(stdout,"  Champs(s) : ... OK ...\n");
2128
2129   MESSAGE("med File convertor 2.1 to 2.2 :: Fields are OK ..");
2130
2131   /* Mise a jour des profils eventuels */
2132   nprofil = MEDnProfil(fid);
2133   if (nprofil > 0) {
2134 //     fprintf(stdout,"- Lancement de la mise à jour des profils ... \n");
2135
2136     MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of all profils");
2137
2138     MAJ_profils(fid,nprofil);
2139
2140 //     fprintf(stdout,"  Profils(s) : ... OK ...\n");
2141
2142     MESSAGE("med File convertor 2.1 to 2.2 :: Profils are OK ... ");
2143   } else {
2144     strncpy(chemin_profils,MED_PROFILS,MED_TAILLE_PROFILS-1);
2145     chemin_profils[MED_TAILLE_PROFILS-1] = '\0';
2146     gid = _MEDdatagroupCreer(fid,chemin_profils);
2147
2148 //     EXIT_IF(gid < 0,"Creation du groupe HDF sur les profils",chemin_profils);
2149
2150     if(gid < 0)
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");
2152
2153     ret = _MEDdatagroupFermer(gid);
2154
2155 //     EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les profils",chemin_profils);
2156
2157     if(ret < 0)
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");
2159
2160   }
2161
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);
2166
2167 //   EXIT_IF(gid < 0,"Creation du groupe HDF sur les liens",chemin_liens);
2168
2169   if(gid < 0)
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");
2171
2172   ret = _MEDdatagroupFermer(gid);
2173
2174 //   EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les liens",chemin_liens);
2175  
2176   if(ret < 0)
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");
2178
2179   /* Fermeture du fichier */
2180   ret = MEDfermer(fid);
2181 /*   EXIT_IF(ret < 0,"Fermeture du fichier",nom); */
2182
2183 //   EXIT_IF(ret < 0,"Fermeture du fichier",InternalFileNameOut);
2184
2185   if(ret < 0)
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");
2187
2188   /* On avertit que c'est fini */
2189 /*   fprintf(stdout,">>> Conversion du fichier %s au format MED V2.2. terminée\n", */
2190 /*        nom); */
2191
2192 //   fprintf(stdout,">>> Conversion du fichier %s au format MED V2.2. terminée\n",
2193 //        InternalFileNameOut);
2194
2195   /* On libere la memoire */
2196 /*   free(nom); */
2197
2198   char * fileNameOut = new char[strlen(InternalFileNameOut)+1];
2199
2200   fileNameOut = strcpy(fileNameOut,InternalFileNameOut);
2201
2202   free(InternalFileNameOut);
2203
2204   MESSAGE("med File convertor 2.1 to 2.2 :: Convertion of the med file " << fileNameOut << " has run OK");
2205
2206   return fileNameOut;
2207 }