# _MEDparameterValueRd236.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 <med_outils.h>
    00022 #include <string.h>
    00023 #include <stdlib.h>
    00024
    00025 void _MEDparameterValueRd236(int dummy, ...) {
    00026
    00027
    00028   med_err _ret=-1;
    00029
    00030   med_idt _paramidt = 0;
    00031   med_idt _cpstidt = 0;
    00032   char _parampath [MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1] = "";
    00033   char _cpstpath[MED_TAILLE_SUP_MAA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]="";
    00034   char _cpstname [2*MED_MAX_PARA+1]="";
    00035   med_access_mode       _MED_ACCESS_MODE;
    00036   med_int _intparamtype = 0;
    00037   med_parameter_type _paramtype;
    00038
    00039   MED_VARGS_DECL(const, med_idt              , , fid       );
    00040   MED_VARGS_DECL(const, char*  , const         , paramname );
    00041   MED_VARGS_DECL(const, med_int              , , numdt     );
    00042   MED_VARGS_DECL(const, med_int              , , numit     );
    00043   MED_VARGS_DECL(,unsigned char*, const        , value     );
    00044   MED_VARGS_DECL(, med_err *                  ,, fret      );
    00045
    00046   va_list params;
    00047   va_start(params,dummy);
    00048
    00049   MED_VARGS_DEF(const, med_idt              , , fid       );
    00050   MED_VARGS_DEF(const, char*  , const         , paramname );
    00051   MED_VARGS_DEF(const, med_int              , , numdt     );
    00052   MED_VARGS_DEF(const, med_int              , , numit     );
    00053   MED_VARGS_DEF(,unsigned char*, const        , value     );
    00054   MED_VARGS_DEF(, med_err *                  ,, fret      );
    00055
    00056
    00057   _MEDmodeErreurVerrouiller();
    00058
    00059   /* Verification du mode d'acces aux données */
    00060   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00061     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00062     goto ERROR;
    00063   }
    00064
    00065   /* Si le group HDF correspondant au parametre n'existe pas => erreur
    00066      Sinon on l'ouvre */
    00067   NOFINALBLANK(paramname,ERROR);
    00068   strcpy(_parampath, MED_NUM_DATA);
    00069   strcat(_parampath, paramname);
    00070   if ((_paramidt = _MEDdatagroupOuvrir(fid,_parampath)) < 0) {
    00071     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_PARAM_MSG);
    00072     SSCRUTE(paramname);SSCRUTE(_parampath); goto ERROR;
    00073   }
    00074
    00075
    00076   /* On construit le nom du datagroup du pas de temps */
    00077   sprintf(_cpstname,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numit);
    00078
    00079   strcpy( _cpstpath, _parampath);
    00080   strcat( _cpstpath, "/");
    00081   strcat( _cpstpath, _cpstname);
    00082
    00083   /* On ouvre le groupe de la sequence de calcul et on lit la
    00084      valeur du paramètre */
    00085   if ((_cpstidt = _MEDdatagroupOuvrir(_paramidt, _cpstname)) < 0 )  {
    00086       MED_ERR_(_ret, MED_ERR_OPEN, MED_ERR_COMPUTINGSTEP, _cpstname);
    00087       SSCRUTE(paramname);goto ERROR;
    00088   }
    00089   if ( _MEDattrEntierLire(_paramidt,MED_NOM_TYP,&_intparamtype) < 0) {
    00090     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00091     SSCRUTE(paramname);SSCRUTE(MED_NOM_TYP);
    00092     goto ERROR;
    00093   }
    00094   _paramtype = (med_field_type) (_intparamtype);
    00095   if (_paramtype == MED_FLOAT64)
    00096     if (_MEDattrFloatLire(_cpstidt, MED_NOM_VAL, value) < 0) {
    00097       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00098       SSCRUTE(paramname);SSCRUTE(MED_NOM_VAL);
    00099     }
    00100   if (_paramtype != MED_FLOAT64)
    00101     if (_MEDattrEntierLire(_cpstidt, MED_NOM_VAL, value) < 0) {
    00102       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00103       SSCRUTE(paramname);SSCRUTE(MED_NOM_VAL);
    00104     }
    00105
    00106   _ret = 0;
    00107  ERROR :
    00108
    00109   if (_cpstidt > 0)
    00110     if (_MEDdatagroupFermer(_cpstidt) < 0) {
    00111       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_cpstname);
    00112       ISCRUTE_id(_cpstidt);
    00113   }
    00114
    00115   if (_paramidt > 0)
    00116     if (_MEDdatagroupFermer(_paramidt) < 0) {
    00117       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_parampath);
    00118       ISCRUTE_id(_paramidt);
    00119     }
    00120
    00121   va_end(params);
    00122   *fret = _ret;
    00123   return;
    00124 }