MAJ_21_22_noeuds_maillage.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2011  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #ifndef MESGERR
00020 #define MESGERR 1
00021 #endif
00022 
00023 
00024 #include "med_config.h"
00025 #include "med_outils.h"
00026 
00027 /* #ifdef __cplusplus */
00028 /* } */
00029 /* #endif */
00030 
00031 #include "med_hdfi21.h"
00032 #include "med21.h"
00033 #include "med_hdfi231.h"
00034 #include "MAJ_21_22.h"
00035 
00036 void MAJ_21_22_noeuds_maillage(med_idt mid, med_int dimension)
00037 {
00038   med_idt nid, gid, tid;
00039   med_float *coo;
00040   char *nom, *unit;
00041   char tmp[MED_TAILLE_PNOM+1];
00042   char *nouvelle_chaine;
00043   med_int n;
00044   med_size dimd[1];
00045   med_err ret;
00046   int i;
00047   hid_t hdf_type;
00048   med_repere repere;
00049 
00050   /* Accès aux noeuds du maillage */
00051   nid = _MEDdatagroupOuvrir(mid,(char *)(MED_NOM_NOE));
00052   EXIT_IF(nid < 0,"Ouverture du groupe HDF MED_NOM_NOE",NULL);
00053 
00054   /* Lecture du nombre de noeuds */
00055   /* Attention sur les grilles en version 2.1.6-OCC, cet attribut n'existait pas ! */
00056   /* Ces fichiers n'ont jamais été officiellement supportés par MED */
00057   gid = _MEDdatasetOuvrir(nid,(char *)(MED_NOM_COO));
00058   if (gid > 0) 
00059      ret = _MEDattrEntierLire(gid,(char *)(MED_NOM_NBR),&n);
00060   EXIT_IF(gid < 0,"Lecture du nombre de noeuds",NULL);
00061   
00062   /* Mise a jour des coordonnees */
00063   /* On cree un groupe HDF tampon */
00064   /* Lecture des coordonnées */
00065   hdf_type = H5Dget_type(gid);
00066   EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des coordonnées",NULL);
00067   coo = (med_float *) malloc(sizeof(med_float)*n*dimension);
00068   EXIT_IF(coo == NULL,NULL,NULL);
00069   ret = _MED21datasetNumLire(nid,(char *)(MED_NOM_COO),MED_FLOAT64, 
00070                               MED_FULL_INTERLACE,dimension,MED_ALL, 
00071                               0,NULL,MED_NOPG, 
00072                               (unsigned char*) coo,hdf_type); 
00073   EXIT_IF(ret < 0,"Lecture des coordonnées des noeuds",NULL);
00074   dimd[0] = n*dimension;
00075   /*   printf("EGALITE des types : %d \n",H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)); */
00076   /*   printf("Avant conversion : [%f] [%f] [%f] \n",*(coo),*(coo+1),*(coo+2)); */
00077   if (! H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)) {
00078     ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)coo,NULL,0);
00079     /*   printf("Après conversion éventuelle : [%f] [%f] [%f] \n",*(coo),*(coo+1),*(coo+2)); */
00080     EXIT_IF(ret < 0,"Conversion des coordonnées des noeuds",NULL);
00081   }
00082   ret = H5Tclose(hdf_type);
00083   EXIT_IF(ret < 0,"Fermeture du data type HDF",NULL);
00084   /* On reporte les coordonnées dans le groupe HDF TMP */
00085   ret = _MED231datasetNumEcrire(nid,"TMP",MED_FLOAT64,MED_FULL_INTERLACE,
00086                                 dimension,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
00087                                 (unsigned char*) coo);
00088   EXIT_IF(ret < 0,"Ecriture des coordonnées des noeuds après conversion",NULL);
00089   free(coo);
00090 
00091   /* Ecriture du nombre de noeuds et du type du repertoire dans le dataset TMP */
00092   tid = _MEDdatasetOuvrir(nid,"TMP");
00093   EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL);
00094   ret = _MEDattrEntierEcrire(tid,(char *)(MED_NOM_NBR),&n);
00095   EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL);
00096   ret = _MEDattrEntierLire(gid,(char *)(MED_NOM_REP),&repere);
00097   EXIT_IF(ret < 0,"Lecture du type de repere des coordonnées", NULL);
00098   ret = _MEDattrEntierEcrire(tid,(char *)(MED_NOM_REP),&repere);
00099   EXIT_IF(ret < 0,"Ecriture du type de répertoire dans le dataset HDF TMP",NULL);
00100 
00101   /* Mise a jour des noms et types des unités des coordonnees */
00102   nom = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1);
00103   EXIT_IF(nom == NULL,NULL,NULL);
00104   unit = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1);
00105   EXIT_IF(unit == NULL,NULL,NULL);
00106   nouvelle_chaine = (char *) malloc(dimension*MED_TAILLE_PNOM+1);
00107   EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
00108   ret = _MEDattrStringLire(gid,(char *)(MED_NOM_NOM),dimension*ANCIEN_MED_TAILLE_PNOM,nom);
00109   EXIT_IF(ret < 0,"Lecture des noms des coordonnées des noeuds",NULL);
00110   ret = _MEDattrStringLire(gid,(char *)(MED_NOM_UNI),dimension*ANCIEN_MED_TAILLE_PNOM,unit);
00111   EXIT_IF(ret < 0,"Lecture des unités des coordonnées des noeuds",NULL);
00112 
00113 /*   MAJ_21_22_chaine(nom,nouvelle_chaine,dimension); */
00114   _MED23v30stringConvert(nouvelle_chaine, MED_TAILLE_PNOM,
00115                          nom, ANCIEN_MED_TAILLE_PNOM, dimension );
00116   ret = _MEDattrStringEcrire(tid,(char *)(MED_NOM_NOM),dimension*MED_TAILLE_PNOM,nouvelle_chaine);
00117   EXIT_IF(ret < 0,"Ecriture des nouveaux noms des coordonnées des noeuds",NULL);
00118   _MED23v30stringConvert(nouvelle_chaine, MED_TAILLE_PNOM,
00119                          unit, ANCIEN_MED_TAILLE_PNOM, dimension );
00120 /*   MAJ_21_22_chaine(unit,nouvelle_chaine,dimension); */
00121   ret = _MEDattrStringEcrire(tid,(char *)(MED_NOM_UNI),dimension*MED_TAILLE_PNOM,nouvelle_chaine);
00122   EXIT_IF(ret < 0,"Ecriture des nouvelles unités des coordonnées des noeuds",NULL);
00123   free(nom);
00124   free(unit);
00125   free(nouvelle_chaine);
00126 
00127   /* Fermeture de l'accès aux coordonnées */
00128   ret = _MEDdatasetFermer(gid);
00129   EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_COO",NULL);
00130   ret = H5Gunlink(nid,(char *)(MED_NOM_COO));
00131   EXIT_IF(ret < 0,"Suppression des anciennes coordonnées",NULL);
00132   ret = _MEDdatasetFermer(tid);
00133   EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL);
00134   ret = H5Gmove(nid,"TMP",(char *)(MED_NOM_COO));
00135   EXIT_IF(ret < 0,"Mise en place des nouvelles coordonnées",NULL);
00136 
00137   /* Mise a jour des noms des noeuds */
00138   nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1);
00139   EXIT_IF(nom == NULL,NULL,NULL);
00140   nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1);
00141   EXIT_IF(nouvelle_chaine == NULL,NULL,NULL);
00142   ret = _MEDdatasetStringLire(nid,(char *)(MED_NOM_NOM),nom);
00143   if (ret == 0) {
00144     MAJ_21_22_chaine(nom,nouvelle_chaine,n);
00145     H5Gunlink(nid,(char *)(MED_NOM_NOM));
00146     dimd[0] = n*MED_TAILLE_PNOM+1;
00147     ret = _MEDdatasetStringEcrire(nid,(char *)(MED_NOM_NOM),dimd,nouvelle_chaine);  
00148     EXIT_IF(ret < 0,"Ecriture des nouveaux noms des noeuds",NULL);  
00149     gid = _MEDdatasetOuvrir(nid,(char *)(MED_NOM_NOM));
00150     ret = _MEDattrEntierEcrire(gid,(char *)(MED_NOM_NBR),&n);
00151     ret = _MEDdatasetFermer(gid);
00152   }
00153   free(nom);
00154   free(nouvelle_chaine);
00155 
00156   /* on ferme tout */
00157   ret = _MEDdatagroupFermer(nid);
00158   EXIT_IF(ret < 0,"Fermeture de l'accès aux noeuds",NULL);
00159 }

Généré le Mon May 16 17:10:23 2011 pour MED fichier par  doxygen 1.6.1