MEDchampLire.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  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 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 
00023 #include <string.h>
00024 #include <stdlib.h>
00025 
00026 /*
00027  * - Nom de la fonction : MEDchampLire
00028  * - Description : Lecture d'un Champ Résultat
00029  * - Parametres :
00030  *     - fid      (IN)  : ID du fichier HDF courant
00031  *     - maa      (IN)  : le nom du maillage sur lequel s'applique le champ 
00032  *     - cha      (IN)  : le nom du champ 
00033  *     - val      (OUT) : valeurs du champ à lire
00034  *     - interlace(IN)  : entrelacement voulu en mémoire {MED_FULL_INTERLACE,MED_NO_INTERLACE} 
00035  *     - locname  (OUT) : nom de la localisation des points de Gauss
00036  *                        (MED_NOGAUSS en absence de localisation, MED_GAUSS_ELNO si les noeuds
00037  *                        et les points de Gauss se confondent)
00038  *     - numco    (IN)  : n° de la composante à lire (MED_ALL si toutes)
00039  *     - profil   (OUT) : nom du profil utilisé (MED_NOPFL si inutilisé)
00040  *     - pflmod   (IN)  : Indique comment lire les informations en mémoire { MED_COMPACT, MED_GLOBALE }. 
00041  *     - type_ent (IN)  : entité concerné par le champ {MED_NOEUD,MED_ARETE,MED_FACE,MED_MAILLE}
00042  *     - type_geo (IN)  : type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
00043  *     - numdt    (IN)  : n° du pas de temps (MED_NOPDT si aucun)
00044  *     - numo     (IN)  : n° d'ordre utilisé MED_NONOR si inutile
00045  * - Resultat : 0 en cas de succes, -1 sinon
00046  */ 
00047 
00048 /* REM : La taille de val allouée par l'utilisateur doit prendre en compte le nbre de points de gauss et le nbre de composantes*/
00049 
00050 med_err
00051 MEDchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switch interlace,med_int numco,
00052              char * locname, char *profil, med_mode_profil pflmod,
00053              med_entite_maillage type_ent, med_geometrie_element type_geo,
00054              med_int numdt, med_int numo)
00055 
00056 {
00057   med_err ret=-1;
00058   med_idt gid=0, datagroup1=0, datagroup2=0,datagroup3=0;
00059   med_int ncomp=0, chtype=0, ngauss=0, i=0, pfluse=0, nbelem = 0;
00060   char nomdatagroup1[2*MED_TAILLE_NOM_ENTITE+2]="",nomdatagroup2[2*MED_MAX_PARA+1]="";
00061   char tmp1[MED_TAILLE_NOM_ENTITE+1]="", pfltmp[MED_TAILLE_NOM+1]="";
00062   char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1]="";
00063   med_size   psize=0;
00064   med_int   *pfltabtmp=0;
00065   med_size  *pfltab=0;
00066   char       _tmpmaa[MED_TAILLE_NOM+1]="";
00067   char      *_maa=maa;
00068   /*
00069    * On inhibe le gestionnaire d'erreur HDF 5
00070    */
00071   _MEDmodeErreurVerrouiller();
00072 if (MEDcheckVersion(fid) < 0) return -1;
00073 
00074 
00075   /* 
00076    * Si le Data Group cha n'existe pas => erreur
00077    */
00078   strcpy(chemin,MED_CHA);
00079   strcat(chemin,cha);
00080   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00081     goto ERROR;
00082 
00083   /* Lecture du nbre de composantes du champ */
00084 
00085   if (_MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp) < 0)
00086     goto ERROR;
00087   
00088   /* 
00089    * Si le Data Group  de niveau 1 <type_ent>[.<type_geo>] n'existe pas => erreur
00090    */
00091   
00092   if (_MEDnomEntite(nomdatagroup1,type_ent) < 0)
00093     goto ERROR;
00094   if ( type_ent != MED_NOEUD ) {
00095     if (_MEDnomGeometrie30(tmp1,type_geo) < 0)
00096       goto ERROR;
00097     strcat(nomdatagroup1,".");
00098     strcat(nomdatagroup1,tmp1);
00099   }
00100   datagroup1 = 0;
00101   if ( (datagroup1 = _MEDdatagroupOuvrir(gid,nomdatagroup1)) < 0 )
00102     goto ERROR;
00103 
00104   /*
00105    * Si le Data Group de niveau 2 <numdt>.<numoo> n'existe pas => erreur
00106    */
00107   sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
00108 
00109   datagroup2 = 0;
00110   if ( (datagroup2 = _MEDdatagroupOuvrir(datagroup1,nomdatagroup2)) < 0)
00111     goto ERROR;
00112 
00113   /*
00114    * Ouvre le datagroup de niveau 3 <maa>
00115    */
00116 
00117   if ( ! strcmp(maa,MED_NOREF) ) {
00118     if (_MEDattrStringLire(datagroup2,MED_NOM_MAI,MED_TAILLE_NOM,_tmpmaa) < 0)
00119       goto ERROR;
00120     _maa=_tmpmaa;
00121   }
00122   datagroup3 = 0;
00123   if ( (datagroup3 = _MEDdatagroupOuvrir(datagroup2,_maa)) < 0 )
00124     goto ERROR;
00125 
00126   /* Gestion des profils*/
00127 
00128   /*
00129    * Lire le profil
00130    */
00131 
00132   if (_MEDattrStringLire(datagroup3,MED_NOM_PFL,MED_TAILLE_NOM,pfltmp) < 0)
00133     goto ERROR;
00134 
00135   if ( (pfluse = (strcmp(pfltmp,MED_NOPFLi) && strcmp(pfltmp,""))) ) /* le test MED_NOPFLi pour des raisons de compatibilité */
00136     {
00137       strcpy(profil,pfltmp);
00138       if ( (i = MEDnValProfil(fid,profil)) < 0 )
00139         goto ERROR;
00140       else
00141         psize = i;
00142 
00143       pfltabtmp = (med_int *)   malloc (sizeof(med_int)*psize);
00144       pfltab = (med_size *) malloc (sizeof(med_size)*psize);
00145       if (MEDprofilLire(fid,pfltabtmp,profil) < 0)
00146         goto ERROR;
00147       for (i=0;i<psize;i++)
00148         pfltab[i] = (med_size) pfltabtmp[i];
00149        
00150     }
00151   else {
00152     psize = MED_NOPF;
00153     strcpy(profil,MED_NOPFL);
00154   }
00155   
00156   
00157   /* Lire le nbre des points de GAUSS*/
00158   if (_MEDattrEntierLire(datagroup3,MED_NOM_NGA,&ngauss) < 0) {
00159     MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NGA : ");
00160     ISCRUTE(ngauss);goto ERROR;
00161   };
00162 
00163   /* Lire l'identificateur de localisation des points de GAUSS*/
00164   if ( _MEDattrStringLire(datagroup3,MED_NOM_GAU,MED_TAILLE_NOM,locname) < 0) {
00165     MESSAGE("Erreur à la lecture de l'attribut MED_NOM_GAU : ");
00166     SSCRUTE(locname); goto ERROR;
00167   }
00168 
00169   /* FT 108 : on rétablit la bonne valeur externe de locname : MED_NOGAUSS */
00170   if ( ! strcmp(locname,MED_NOGAUSSi))
00171     strcpy(locname,MED_NOGAUSS);
00172 
00173   /* Lire le nbre d'elements */
00174   if (_MEDattrEntierLire(datagroup3,MED_NOM_NBR,&nbelem) < 0) {
00175     MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NBR : ");
00176     ISCRUTE(nbelem);goto ERROR;
00177   };
00178 
00179   /*
00180    * Lecture du champ
00181    */
00182 
00183 
00184   if (_MEDattrEntierLire(gid,MED_NOM_TYP,&chtype) < 0)
00185     goto ERROR;
00186 
00187   switch(chtype)
00188     {
00189     case MED_FLOAT64 :
00190       if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_FLOAT64,
00191                                      interlace,ncomp,numco,
00192                                      psize,pflmod,MED_PFL_COMPACT,pfltab,ngauss,nbelem,val)< 0)
00193         goto ERROR;
00194       break;
00195 
00196     case MED_INT32 :
00197 #if defined(HAVE_F77INT64) 
00198      if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT64,
00199                                      interlace,ncomp,numco,
00200                                      psize,pflmod,MED_PFL_COMPACT,pfltab,ngauss,nbelem,val)< 0)
00201         goto ERROR;
00202 #else
00203      if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT32,
00204                                      interlace,ncomp,numco,
00205                                      psize,pflmod,MED_PFL_COMPACT,pfltab,ngauss,nbelem,val)< 0)
00206         goto ERROR;
00207 #endif
00208      break;
00209 
00210     case MED_INT64 :
00211 #if defined(HAVE_F77INT64) 
00212      if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT64,
00213                                      interlace,ncomp,numco,
00214                                      psize,pflmod,MED_PFL_COMPACT,pfltab,ngauss,nbelem,val)< 0)
00215         goto ERROR;
00216 #else
00217      goto ERROR;
00218 #endif
00219       break;      
00220 
00221     default :
00222       goto ERROR;
00223     }
00224 
00225   /*
00226    * On ferme tout 
00227    */
00228 
00229   ret = 0;
00230 
00231  ERROR:
00232   
00233   if ( pfluse ) { free(pfltab); free(pfltabtmp);}
00234  
00235   if (datagroup3>0)     if (_MEDdatagroupFermer(datagroup3) < 0) {
00236     MESSAGE("Impossible de fermer le datagroup : ");
00237     ISCRUTE_int(datagroup3); ret = -1; 
00238   }
00239   
00240   if (datagroup2>0)     if (_MEDdatagroupFermer(datagroup2) < 0) {
00241     MESSAGE("Impossible de fermer le datagroup : ");
00242     ISCRUTE_int(datagroup2); ret = -1; 
00243   }
00244 
00245   if (datagroup1>0)     if (_MEDdatagroupFermer(datagroup1) < 0) {
00246     MESSAGE("Impossible de fermer le datagroup : ");
00247     ISCRUTE_int(datagroup1); ret = -1; 
00248   }
00249   
00250   if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
00251     MESSAGE("Impossible de fermer le datagroup : ");
00252     ISCRUTE_id(gid); ret = -1; 
00253   }
00254 
00255   return ret; 
00256 }
00257 
00258 
00259 
00260 

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1