MEDstructElementVarAttCr.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 
00041 med_err
00042 MEDstructElementVarAttCr(const med_idt                  fid,
00043                          const char*              const modelname,
00044                          const char*              const varattname,
00045                          const med_attribute_type       varatttype,
00046                          const med_int                  ncomponent
00047                          )
00048 {
00049   med_access_mode   _MED_ACCESS_MODE;
00050   med_err           _ret=-1;
00051   med_idt           _attid=0, _elemid=0, _varid=0;
00052   char              _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1+MED_TAILLE_VARATR+MED_NAME_SIZE+1]=MED_STRCT;
00053   med_int           _medintvaratttype=varatttype;
00054 
00055 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00056 
00057   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00058     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00059     goto ERROR;
00060   }
00061 
00062   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00063     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00064     ISCRUTE_int(_MED_ACCESS_MODE);
00065     goto ERROR;
00066   }
00067 
00068   NOFINALBLANK(modelname,ERROR);
00069   NOFINALBLANK(varattname,ERROR);
00070 
00071   if ( _medintvaratttype == MED_ATT_UNDEF ) {
00072     MED_ERR_(_ret,MED_ERR_INVALID, MED_ERR_PARAMETER, MED_ERR_TYPEOF_MSG MED_ERR_ATTRIBUTE);
00073     SSCRUTE(MED_NOM_ATT);SSCRUTE(varattname);ISCRUTE_int(varatttype);
00074     goto ERROR;
00075   }
00076 
00077   strcat(_path,modelname);
00078 
00079   /*
00080    * Si le DataGroup /STRUCT/<modelname> n'existe pas => erreur
00081    */
00082   if ((_elemid = _MEDdatagroupOpen(fid,_path)) < 0)  {
00083     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
00084     goto ERROR;
00085   }
00086 
00087   /*
00088    * Si le DataGroup /STRUCT/<modelname>/VARATR/ n'existe pas on le crée
00089    */
00090   if ((_varid = _MEDdatagroupOpen(_elemid,MED_VARATR_NOM)) < 0)
00091     if ((_varid = _MEDdatagroupCreer(_elemid,MED_VARATR_NOM)) < 0) {
00092       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_VARATR_NOM);
00093       SSCRUTE(_path);goto ERROR;
00094     }
00095   strcat(_path,MED_VARATR);
00096 
00097   /*
00098    * Si le DataGroup /STRUCT/<modelname>/VARATR/<varattname> n'existe pas on le crée
00099    */
00100   if ((_attid = _MEDdatagroupOpen(_varid,varattname)) < 0)
00101     if ((_attid = _MEDdatagroupCreer(_varid,varattname)) < 0) {
00102       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,varattname);
00103       SSCRUTE(_path);goto ERROR;
00104     }
00105   strcat(_path,varattname);
00106 
00107   /*
00108    * Creation/Ecriture de l'attribut MED_NOM_ATT (type des valeurs de l'attribut.)
00109    */
00110   if ( _MEDattributeIntWr(_attid,MED_NOM_ATT,&_medintvaratttype) < 0 ) {
00111     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00112     SSCRUTE(MED_NOM_ATT);ISCRUTE(_medintvaratttype);
00113     goto ERROR;
00114   }
00115 
00116   /*
00117    * Creation/Ecriture de l'attribut MED_NOM_NCO (nombre de composantes des valeurs de l'attribut.)
00118    */
00119   if ( _MEDattributeIntWr(_attid,MED_NOM_NCO,&ncomponent) < 0 ) {
00120     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00121     SSCRUTE(MED_NOM_NCO);ISCRUTE(ncomponent);
00122     goto ERROR;
00123   }
00124 
00125 
00126   _ret=0;
00127  ERROR:
00128 
00129   if (_attid>0)            if (_MEDdatagroupFermer(_attid) < 0) {
00130     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00131     ISCRUTE_id(_attid);
00132   }
00133 
00134   if (_varid>0)            if (_MEDdatagroupFermer(_varid) < 0) {
00135     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_VARATR_NOM);
00136     ISCRUTE_id(_varid);
00137   }
00138 
00139   if (_elemid>0)            if (_MEDdatagroupFermer(_elemid) < 0) {
00140     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,modelname);
00141     ISCRUTE_id(_elemid);
00142   }
00143 
00144   return _ret;
00145 }

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