_MEDfieldnValue30.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 #include <med.h>
00020 #include <med_config.h>
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include <med_outils.h>
00024 
00025 
00026 void
00027 _MEDfieldnValue30(int dummy, ...)
00028 {
00029   va_list params;
00030   va_start(params,dummy);
00031 
00032   const med_idt           fid                        = va_arg(params,const med_idt            );
00033   const char * const      fieldname                  = va_arg(params,const char * const       );
00034   const med_int           numdt                      = va_arg(params,const med_int            );
00035   const med_int           numit                      = va_arg(params,const med_int            );
00036   const med_entity_type   entitytype                 = va_arg(params,const med_entity_type    );
00037   const med_geometry_type geotype                    = va_arg(params,const med_geometry_type  );
00038   char * const      profilename                = va_arg(params,char * const             );
00039   const int               profileit                  = va_arg(params,const int                );
00040   const med_storage_mode  storagemode                = va_arg(params,const med_storage_mode   );
00041   med_int * const   profilesize                = va_arg(params,med_int * const          );
00042   char * const      localizationname           = va_arg(params,char * const             );
00043   med_int * const   nbofintegrationpoint       = va_arg(params,med_int * const          );
00044   med_int *         fret                       = va_arg(params,        med_int *);
00045 
00046   med_int  _ret=-1;
00047   med_idt  _gid=0,_locgid=0,_datagroup1=0,_datagroup2=0;
00048   char     _path[(MED_TAILLE_CHA+MED_NAME_SIZE+1)+(2*MED_MAX_PARA+1)+1]=MED_CHA;
00049   char     _datagroupname1[2*MED_TAILLE_NOM_ENTITE+2]="";
00050   char     _datagroupname2[MED_NAME_SIZE+1]="";
00051   char     _tmpprofilename[MED_NAME_SIZE+1]="", *_profilename=0;
00052   char     _geotypename      [MED_TAILLE_NOM_ENTITE+1]="";
00053   char     _locgidname        [MED_TAILLE_GAUSS+MED_NAME_SIZE+1]="";
00054   char     _sectionmeshname      [MED_NAME_SIZE+1]="";
00055   char     _sectiongeotypename   [MED_NAME_SIZE+1]="";
00056   char     _localizationname  [MED_NAME_SIZE+1]=""; /*TODO DEFAULT? */
00057   med_int  _nbofconstituentpervalue=0,_nbofvaluesperentityfromloc=0;
00058   med_int  _numdt=0, _numit=0;
00059   med_int  _profilearraysize=0,_nbofvaluesperentity=0;
00060   med_int  _nbofsectiongeotype=0,_nbofsectioncell=1;
00061   med_size _n=0;
00062   med_geometry_type    _locgeotype   =0,_sectiongeotype=0;;
00063   med_int              _intlocgeotype=0;
00064   int      _num = profileit -1;
00065   med_bool _anyprofile=MED_FALSE;
00066   med_bool _chgt=MED_FALSE,_trsf=MED_FALSE;
00067 
00068   /*
00069    * On inhibe le gestionnaire d'erreur HDF 5
00070    */
00071   _MEDmodeErreurVerrouiller();
00072 
00073   NOFINALBLANK(fieldname,ERROR);
00074 
00075   /*
00076    * On construit le chemin d'acc�s jusqu'aux groupes <type_ent>[.<type_geo>]
00077    */
00078   strcat(_path,fieldname);
00079   strcat(_path,"/");
00080   _MEDgetComputationStepName(MED_SORT_DTIT,numdt,numit,&_path[strlen(_path)]);
00081   strcat(_path,"/");
00082 
00083   if ((_gid = _MEDdatagroupOuvrir(fid,_path)) < 0) {
00084     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
00085     SSCRUTE(_path); goto ERROR;
00086   }
00087 
00088 
00089   /*Lit l'attribut MED_NOM_NDT  */
00090   if ( _MEDattrEntierLire(_gid,MED_NOM_NDT, &_numdt) < 0) {
00091     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00092     SSCRUTE(_path);SSCRUTE(MED_NOM_NDT);
00093     ISCRUTE(_numdt);goto ERROR;
00094   }
00095 
00096   if ( _numdt != numdt ) {
00097     MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00098     SSCRUTE(_path);ISCRUTE(_numdt);ISCRUTE(numdt);goto ERROR;
00099   }
00100 
00101   /*Lit l'attribut MED_NOM_NOR */
00102   if ( _MEDattrEntierLire(_gid,MED_NOM_NOR, &_numit) < 0) {
00103     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00104     SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(MED_NOM_NOR);
00105     ISCRUTE(_numit); goto ERROR;
00106   }
00107 
00108   if ( _numit != numit) {
00109     MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00110     SSCRUTE(fieldname);ISCRUTE(_numit);ISCRUTE(numit);goto ERROR;
00111   }
00112 
00113   /*
00114    * Si le Data Group  de niveau <type_ent>[.<type_geo>] n'existe pas retroune 0
00115    */
00116 
00117   if (_MEDgetEntityTypeName(_datagroupname1,entitytype) < 0) {
00118     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ENTITY,_datagroupname1);
00119     goto ERROR;
00120   }
00121 
00122   if (entitytype != MED_NODE) {
00123     if ( entitytype == MED_STRUCT_ELEMENT ) {
00124       if ( MEDstructElementName(fid, geotype,_geotypename) < 0 ) {
00125         MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDstructElementName");
00126         ISCRUTE_int(geotype);goto ERROR;
00127       }
00128     } else {
00129       if (_MEDgetGeometryTypeName(_geotypename,geotype) < 0) {
00130         MED_ERR_(_ret,MED_ERR_READ,MED_ERR_GEOMETRIC,_geotypename);
00131         goto ERROR;
00132       }
00133     }
00134     strcat(_datagroupname1,".");
00135     strcat(_datagroupname1,_geotypename);
00136   }
00137   /*   strcat(_path,_datagroupname1); */
00138   /*   strcat(_path,"/"); */
00139 
00140 
00141   if ((_datagroup1 = _MEDdatagroupOuvrir(_gid,_datagroupname1)) < 0) {
00142     _n=0;
00143   } else {
00144     if (strlen(profilename) && (profileit >=0))  {
00145       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,MED_ERR_FIELD_MSG);
00146       SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(_datagroupname1);
00147       SSCRUTE(profilename); ISCRUTE_int(profileit); goto ERROR;
00148     }
00149 
00150     if ( profileit <0 ) {
00151       /* PATCH : UsesCase_MEDfield2.c ! */
00152       if ( !strlen(profilename)) {
00153         _profilename = MED_NO_PROFILE_INTERNAL;
00154       }
00155       else {
00156         _profilename=profilename;
00157         _anyprofile=MED_TRUE;
00158       }
00159     } else {
00160       _profilename=_tmpprofilename;
00161       if ( _MEDobjectGetName(_datagroup1, "." ,_num, _profilename) < 0 ) {
00162         MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_path);
00163         SSCRUTE(_datagroupname1);ISCRUTE_int(profileit);
00164         goto ERROR;
00165       }
00166       if ( strcmp(_profilename,MED_NO_PROFILE_INTERNAL) ) {
00167         strncpy(profilename,_profilename,MED_NAME_SIZE+1);
00168         profilename[MED_NAME_SIZE]='\0';
00169         _anyprofile=MED_TRUE;
00170       } else {
00171         profilename[0]='\0';
00172       }
00173     }
00174     
00175     if ((_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,_profilename)) < 0) {
00176       MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
00177       SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(_datagroupname1); SSCRUTE(_profilename);goto ERROR;
00178       goto ERROR;
00179     }
00180     
00181     
00182     if ( _MEDattrEntierLire(_datagroup2,MED_NOM_NBR,&_n) < 0) {
00183       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00184       SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(_datagroupname1); SSCRUTE(_profilename);
00185       SSCRUTE(MED_NOM_NBR);ISCRUTE_size(_n);goto ERROR;
00186     }
00187     
00188     if ( _anyprofile ) {
00189       if ( (_profilearraysize=MEDprofileSizeByName(fid, _profilename)) < 0)  {
00190         MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,MED_ERR_FIELD_MSG);
00191         SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(_datagroupname1); SSCRUTE(_profilename);
00192         SSCRUTE("MEDprofileSizeByName");goto ERROR;
00193       }
00194     } else {
00195       _profilearraysize = _n;
00196     }
00197     
00198     *profilesize=_profilearraysize;
00199 
00200     switch(storagemode) {
00201       
00202     case MED_GLOBAL_PFLMODE :
00203       
00204       break;
00205       
00206     case MED_COMPACT_PFLMODE :
00207       
00208       _n=_profilearraysize;
00209       
00210       break;
00211       
00212     default :
00213       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_STORAGEMODE,MED_ERR_VALUE_MSG);
00214       ISCRUTE_int(storagemode);goto ERROR;
00215       break;
00216       
00217     }
00218 
00219     /* Lecture du nom de la localization  */
00220     if ( _MEDattrStringLire(_datagroup2,MED_NOM_GAU,MED_NAME_SIZE,_localizationname) < 0) {
00221       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00222       SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(_datagroupname1);SSCRUTE(_profilename);
00223       SSCRUTE(MED_NOM_GAU);SSCRUTE(_localizationname);goto ERROR;
00224     }
00225     strncpy(localizationname,_localizationname,MED_NAME_SIZE+1);
00226     localizationname[MED_NAME_SIZE]='\0';
00227 
00228     /* Lire le nbre de valeurs pas entit�*/
00229     if ( _MEDattrEntierLire(_datagroup2,MED_NOM_NGA,&_nbofvaluesperentity) < 0) {
00230       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00231       SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(_datagroupname1);
00232       SSCRUTE(_profilename); SSCRUTE(MED_NOM_NGA);ISCRUTE(_nbofvaluesperentity);goto ERROR;
00233     }
00234 
00235 
00236     /* V�rification de la coh�rence du  nombre de valeurs pas entit�*/
00237     if (entitytype == MED_NODE_ELEMENT ) {
00238       if ( strlen( _localizationname) ) {
00239         MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_PARAMETER,_localizationname);
00240         SSCRUTE(MED_NO_LOCALIZATION);ISCRUTE_int(entitytype);goto ERROR;
00241       }
00242       _nbofvaluesperentityfromloc = geotype % 100;
00243     } else if (! strcmp(_localizationname,MED_GAUSS_ELNO)) {
00244       /* Les points de Gauss sont d�finis sur les noeuds de l'element (mot cle) */
00245       /* le nombre de points de Gauss est egal au nombre de noeuds de l'element */
00246       _nbofvaluesperentityfromloc = geotype % 100;
00247     } else if ( strlen( _localizationname) ) {
00248       strcpy(_locgidname,MED_GAUSS);
00249       strcat(_locgidname,_localizationname);
00250       
00251       if ((_locgid = _MEDdatagroupOuvrir(fid,_locgidname)) < 0) {
00252         MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_locgidname);
00253         goto ERROR;
00254       }
00255       
00256       if (_MEDattrEntierLire(_locgid,MED_NOM_NBR,&_nbofvaluesperentityfromloc) < 0) {
00257         MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00258         SSCRUTE(_localizationname);SSCRUTE(MED_NOM_NBR);ISCRUTE(_nbofvaluesperentity);goto ERROR;
00259       }
00260       
00261       if ( entitytype == MED_STRUCT_ELEMENT ) {
00262      
00263         /*
00264          * Lecture de l'attribut MED_NOM_NOM (nom du maillage support de section)
00265          */
00266         if ( _MEDattrStringLire(_locgid,MED_NOM_NOM,MED_NAME_SIZE,_sectionmeshname) < 0) {
00267           MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_locgidname);
00268           SSCRUTE(MED_NOM_NOM);SSCRUTE(_sectionmeshname);
00269           goto ERROR;
00270         }
00271 
00272         if (strlen(_sectionmeshname) ) {
00273 
00274           if ( (_nbofsectiongeotype = MEDmeshnEntity(fid,_sectionmeshname,MED_NO_DT,MED_NO_IT,
00275                                                     MED_CELL,MED_ALL_GEOTYPE,MED_CONNECTIVITY,MED_NODAL,
00276                                                     &_chgt,&_trsf) )  < 0) {
00277             MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00278             ISCRUTE(_nbofsectiongeotype);goto ERROR;
00279           }
00280         
00281           if ( (_nbofsectiongeotype != 1 ) ) {
00282             MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_RANGE,""); ISCRUTE(_nbofsectiongeotype); goto ERROR;
00283           }
00284 
00285 
00286           if ( MEDmeshEntityInfo( fid,_sectionmeshname,MED_NO_DT,MED_NO_IT,
00287                                   MED_CELL, 1, _sectiongeotypename,
00288                                   &_sectiongeotype ) < 0 ) {
00289             MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshEntityInfo");
00290             SSCRUTE(_sectiongeotypename);ISCRUTE_int(_sectiongeotype);goto ERROR;
00291           }
00292 
00293           if ( (_nbofsectioncell = MEDmeshnEntity(fid,_sectionmeshname,MED_NO_DT,MED_NO_IT,
00294                                                  MED_CELL,_sectiongeotype,MED_CONNECTIVITY,MED_NODAL,
00295                                                  &_chgt,&_trsf) )  < 0) {
00296             MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00297             ISCRUTE(_nbofsectioncell);goto ERROR;
00298           }
00299         }
00300       }
00301 
00302       _nbofvaluesperentityfromloc*=_nbofsectioncell;
00303 
00304       if (_MEDattrEntierLire(_locgid,MED_NOM_GEO,&_intlocgeotype) < 0) {
00305         MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00306         SSCRUTE(_localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE(_intlocgeotype);goto ERROR;
00307       }
00308       _locgeotype = (med_geometry_type) _intlocgeotype;
00309       
00310       if ( _locgeotype != geotype ) {
00311         MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00312         SSCRUTE(_localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE_int(_locgeotype);ISCRUTE_int(geotype);
00313         goto ERROR;
00314       }
00315       
00316     } else {
00317       _nbofvaluesperentityfromloc = 1;
00318     }
00319     
00320     if ( _nbofvaluesperentityfromloc != _nbofvaluesperentity ) {
00321       MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00322       SSCRUTE(_localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE(_nbofvaluesperentityfromloc);
00323       ISCRUTE(_nbofvaluesperentity);goto ERROR;
00324     }
00325     
00326     *nbofintegrationpoint = _nbofvaluesperentity;
00327 
00328     /* PATCH (fin) : UsesCase_MEDfield3.c ! */
00329   }
00330 
00331   _ret = _n;
00332  ERROR:
00333 
00334   if (_datagroup2>0)            if (_MEDdatagroupFermer(_datagroup2) < 0) {
00335     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00336     SSCRUTE(_datagroupname1); SSCRUTE(_profilename); ISCRUTE_id(_datagroup2);
00337   }
00338 
00339   if (_datagroup1>0)            if (_MEDdatagroupFermer(_datagroup1) < 0) {
00340     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00341     SSCRUTE(_datagroupname1); ISCRUTE_id(_datagroup1);
00342   }
00343 
00344   if (_gid>0)            if (_MEDdatagroupFermer(_gid) < 0) {
00345     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00346     ISCRUTE_id(_gid);
00347   }
00348 
00349   if (_locgid>0)     if (_MEDdatagroupFermer(_locgid) < 0) {
00350     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_locgidname);
00351     ISCRUTE_id(_locgid);
00352   }
00353 
00354   va_end(params);
00355   *fret = _ret;
00356 
00357   return;
00358 }

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