MEDnVal.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 <string.h>
00022 #include <stdlib.h>
00023 #include <med_outils.h>
00024 
00025 /*
00026  * - Nom de la fonction : MEDnVal
00027  * - Description :Renvoie le nbre d'�l�ment d'un champ
00028  * - Parametres :
00029  *     - fid      (IN)  : ID du fichier HDF courant
00030  *     - cha      (IN)  : le nom du champ 
00031  *     - type_ent (IN)  : entit� concern� par le champ {MED_NOEUD,MED_ARETE,MED_FACE,MED_MAILLE}
00032  *     - type_geo (IN)  : type g�om�trique de l'entit� concern� {MED_POINT,MED_SEG2 ......}
00033  *     - numdt    (IN)  : n� du pas de temps (MED_NOPDT si aucun)
00034  *     - numo     (IN)  : n� d'ordre utilis� MED_NONOR si inutile
00035  *     - maa      (IN)  : le nom du maillage sur lequel s'applique le champ, eventuellemnt MED_NOREF 
00036  *     - pflmod   (IN)  : Indique s'il faut calculer la taille m�moire pour un mode MED_COMPACT ou MED_GLOBAL . 
00037  * - Resultat : 0 en cas de succes, -1 sinon
00038  */ 
00039 
00040 med_int 
00041 MEDnVal(med_idt fid, char *cha, med_entite_maillage type_ent, 
00042         med_geometrie_element type_geo,med_int numdt, med_int numo, char * maa, med_mode_profil pflmod)
00043 {
00044   med_int n=-1, ngauss=0, pfluse=0;
00045   med_idt datagroup3=0;
00046   char nomdatagroup1[2*MED_TAILLE_NOM_ENTITE+2]="";
00047   char nomdatagroup2[2*MED_MAX_PARA+1]="";
00048   char tmp1   [MED_TAILLE_NOM_ENTITE+1]="";
00049   char chemin [MED_TAILLE_CHA+(MED_TAILLE_NOM+1)+(2*MED_TAILLE_NOM_ENTITE+2)+(2*MED_MAX_PARA+1)+(MED_TAILLE_NOM)+1]="";
00050   char chemin_i [MED_TAILLE_CHA+(MED_TAILLE_NOM+1)+(2*MED_TAILLE_NOM_ENTITE+2)+(2*MED_MAX_PARA+1)+(MED_TAILLE_NOM)+1]="";  
00051   char pfltmp[MED_TAILLE_NOM+1]="";
00052   char maa_i [MED_TAILLE_NOM+1]="";
00053   med_int   psize=0;
00054   
00055   /*
00056    * On inhibe le gestionnaire d'erreur HDF 
00057    */
00058   _MEDmodeErreurVerrouiller();
00059 if (MEDcheckVersion(fid) < 0) return -1;
00060 
00061 
00062   /*
00063    * On cree le chemin d'acc�s
00064    */
00065   strcpy(chemin,MED_CHA);
00066   strcat(chemin,cha);
00067   strcat(chemin,"/");
00068 
00069   /* On cree le nom du datagroup de niveau 1  <type_ent>[.<type_geo>] */
00070   /* modif pour la version 2.3.3 */
00071   
00072   if ( _MEDnomEntite(nomdatagroup1,type_ent) < 0 )
00073     goto ERROR;
00074   if ((type_ent != MED_NOEUD)) {
00075     if ( _MEDnomGeometrie30(tmp1,type_geo) < 0)
00076       goto ERROR;
00077     strcat(nomdatagroup1,".");
00078     strcat(nomdatagroup1,tmp1);
00079   }
00080   strcat(chemin,nomdatagroup1);
00081   strcat(chemin,"/");
00082 
00083   /* Creation du nom du datagroup de niveau 2 <numdt>.<numoo> */
00084   sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
00085   strcat(chemin,nomdatagroup2);
00086   strcat(chemin,"/");
00087 
00088   /* Creation du nom du datagroup de niveau 3 <maa> */
00089   if ( strcmp(maa,MED_NOREF) ) 
00090     strcat(chemin,maa);
00091   else {
00092     strcpy(chemin_i,chemin);
00093 
00094     if ((datagroup3 = _MEDdatagroupOuvrir(fid,chemin_i)) < 0) return 0;
00095 
00096     if (_MEDattrStringLire(datagroup3,MED_NOM_MAI,MED_TAILLE_NOM,maa_i) < 0)
00097       goto ERROR;
00098 
00099     strcat(chemin,maa_i);
00100 
00101     if ( _MEDdatagroupFermer(datagroup3) < 0) {
00102       MESSAGE("Impossible de fermer le datagroup : ");
00103       ISCRUTE_int(datagroup3); goto ERROR;
00104     }
00105   }
00106 
00107   /*
00108    *  Acces au champ
00109    */
00110   if ((datagroup3 = _MEDdatagroupOuvrir(fid,chemin)) < 0) 
00111     return 0;
00112 
00113   switch(pflmod) {
00114     
00115   case MED_GLOBAL :
00116     
00117     if ( _MEDattrEntierLire(datagroup3,MED_NOM_NBR,&n) < 0) {
00118       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NBR : ");
00119       ISCRUTE(n);goto ERROR;
00120     };    
00121     break;
00122     
00123   case MED_COMPACT :
00124  
00125     /* Vérifier l'existence d'un profil*/
00126     
00127     if (_MEDattrStringLire(datagroup3,MED_NOM_PFL,MED_TAILLE_NOM,pfltmp) < 0){
00128       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_PFL : ");
00129       SSCRUTE(pfltmp);goto ERROR;
00130     };   
00131 
00132     /* Si un profil est trouv� la taille est calcul�e en fonction du nbre d'�l�ments du profil*/
00133     /* Sinon l'appel est �quivalent au mode MED_GLOBAL ); */
00134     if ( (pfluse = (strcmp(pfltmp,MED_NOPFLi) && strcmp(pfltmp,"")) ) ) {
00135       if ( (psize = MEDnValProfil(fid,pfltmp)) < 0 ) {
00136         MESSAGE("Erreur à l'appel de MEDnValProfil : ");
00137         SSCRUTE(pfltmp);goto ERROR;
00138       };
00139     } else {
00140       if ( _MEDattrEntierLire(datagroup3,MED_NOM_NBR,&n) < 0) {
00141         MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NBR : ");
00142         ISCRUTE(n);goto ERROR;
00143       };    
00144        break;     
00145     };
00146     
00147     /* Lire le nbre des points de GAUSS*/
00148     if (_MEDattrEntierLire(datagroup3,MED_NOM_NGA,&ngauss) < 0) {
00149       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NGA : ");
00150       ISCRUTE(ngauss);goto ERROR;
00151     };   
00152 
00153     /* NE PAS REMPLACER ICI type_ent par type_ent */
00154     if (type_ent == MED_NOEUD_MAILLE )
00155       ngauss = type_geo % 100;
00156 
00157     n= ngauss * psize;
00158     
00159     break;
00160     
00161   default :
00162       MESSAGE("Erreur : <pflmod> doit etre positionné soit à MED_GLOBAL soit à MED_COMPACT ");
00163     break;
00164     
00165   }
00166   
00167   ERROR :
00168     
00169     if (datagroup3>0) 
00170       if ( _MEDdatagroupFermer(datagroup3) < 0) {
00171         MESSAGE("Impossible de fermer le datagroup : ");
00172         ISCRUTE_int(datagroup3); n = -1; 
00173       } 
00174   
00175   return n;
00176 }
00177 
00178 
00179 

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