# MEDparameterValueWr.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  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
    00038 med_err
    00039 MEDparameterValueWr(const med_idt              fid,
    00040                     const char*  const         paramname,
    00041                     const med_int              numdt,
    00042                     const med_int              numit,
    00043                     const med_float            dt,
    00044                     const unsigned char* const value)
    00045 {
    00046   med_err _ret = -1;
    00047   med_idt _paramidt = 0;
    00048   med_idt _cpstidt = 0;
    00049   char _parampath [MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1] = "";
    00050   char _cpstpath[MED_TAILLE_SUP_MAA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]="";
    00051   char _cpstname [2*MED_MAX_PARA+1]="";
    00052   med_access_mode       _MED_ACCESS_MODE;
    00053   med_int _intparamtype = 0;
    00054   med_parameter_type _paramtype;
    00055
    00056   _MEDmodeErreurVerrouiller();
    00057  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    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   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00065     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00066     ISCRUTE_int(_MED_ACCESS_MODE);
    00067     goto ERROR;
    00068   }
    00069
    00070   /* Si le group HDF correspondant au parametre n'existe pas => erreur
    00071      Sinon on l'ouvre */
    00072   NOFINALBLANK(paramname,ERROR);
    00073   strcpy(_parampath, MED_NUM_DATA);
    00074   strcat(_parampath, paramname);
    00075   if ((_paramidt = _MEDdatagroupOuvrir(fid,_parampath)) < 0) {
    00076     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_PARAM_MSG);
    00077     SSCRUTE(paramname);SSCRUTE(_parampath); goto ERROR;
    00078   }
    00079
    00080   /* On construit le nom du datagroup du pas de temps */
    00081   _MEDgetComputationStepName(MED_SORT_DTIT,numdt,numit,_cpstname);
    00082   strcpy( _cpstpath, _parampath);
    00083   strcat( _cpstpath, "/");
    00084   strcat( _cpstpath, _cpstname);
    00085
    00086   /* Si l'etape de calcul n'existe pas, on la cr�e */
    00087   if ((_cpstidt = _MEDdatagroupOuvrir(_paramidt, _cpstname)) < 0 )
    00088     if ((_cpstidt = _MEDdatagroupCreer(_paramidt,_cpstname)) < 0 ) {
    00089       MED_ERR_(_ret, MED_ERR_EXIST, MED_ERR_COMPUTINGSTEP, _cpstname);
    00090       SSCRUTE(paramname);goto ERROR;
    00091     }
    00092
    00093   /* ecriture de l'attribut MED_NOM_NDT pour �criture */
    00094   if ( _MEDattributeIntWr(_cpstidt,MED_NOM_NDT,&numdt) < 0) {
    00095     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00096     SSCRUTE(paramname);SSCRUTE(_cpstname);SSCRUTE(MED_NOM_NDT);
    00097     ISCRUTE(numdt);goto ERROR;
    00098   }
    00099   /* ecriture de l'attribut MED_NOM_PDT */
    00100   if ( _MEDattrFloatEcrire(_cpstidt,MED_NOM_PDT,&dt) < 0) {
    00101     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00102     SSCRUTE(paramname);SSCRUTE(_cpstname);SSCRUTE(MED_NOM_PDT);
    00103     RSCRUTE(dt);goto ERROR;
    00104   }
    00105   /* ecriture de l'attribut MED_NOM_NOR  */
    00106   if ( _MEDattributeIntWr(_cpstidt,MED_NOM_NOR,&numit) < 0) {
    00107     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00108     SSCRUTE(paramname);SSCRUTE(_cpstname);SSCRUTE(MED_NOM_NOR);
    00109     ISCRUTE(numit); goto ERROR;
    00110   }
    00111
    00112   /* on ecrit la valeur du parametre */
    00113   if ( _MEDattrEntierLire(_paramidt,MED_NOM_TYP,&_intparamtype) < 0) {
    00114     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00115     SSCRUTE(paramname);SSCRUTE(MED_NOM_TYP);
    00116     goto ERROR;
    00117   }
    00118   _paramtype = (med_field_type) (_intparamtype);
    00119   if (_paramtype == MED_FLOAT64)
    00120     if (_MEDattrFloatEcrire(_cpstidt, MED_NOM_VAL, value) < 0) {
    00121       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00122       SSCRUTE(paramname);SSCRUTE(MED_NOM_VAL);
    00123     }
    00124   if (_paramtype != MED_FLOAT64)
    00125     if (_MEDattributeIntWr(_cpstidt, MED_NOM_VAL, value) < 0) {
    00126       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    00127       SSCRUTE(paramname);SSCRUTE(MED_NOM_VAL);
    00128     }
    00129
    00130   _ret = 0;
    00131  ERROR:
    00132
    00133   /* on ferme tout */
    00134
    00135   if (_cpstidt > 0)
    00136     if (_MEDdatagroupFermer(_cpstidt) < 0) {
    00137       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_cpstname);
    00138       ISCRUTE_id(_cpstidt);
    00139   }
    00140
    00141   if (_paramidt > 0)
    00142     if (_MEDdatagroupFermer(_paramidt) < 0) {
    00143       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_parampath);
    00144       ISCRUTE_id(_paramidt);
    00145     }
    00146
    00147   return _ret;
    00148 }