MEDstructElementVarAttCr.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 
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                  nbofcomponent
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   strcat(_path,modelname);
00072 
00073   /*
00074    * Si le DataGroup /STRUCT/<modelname> n'existe pas => erreur
00075    */
00076   if ((_elemid = _MEDdatagroupOpen(fid,_path)) < 0)  {
00077     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
00078     goto ERROR;
00079   }
00080 
00081   /*
00082    * Si le DataGroup /STRUCT/<modelname>/VARATR/ n'existe pas on le crée
00083    */
00084   if ((_varid = _MEDdatagroupOpen(_elemid,MED_VARATR_NOM)) < 0)
00085     if ((_varid = _MEDdatagroupCreer(_elemid,MED_VARATR_NOM)) < 0) {
00086       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_VARATR_NOM);
00087       SSCRUTE(_path);goto ERROR;
00088     }
00089   strcat(_path,MED_VARATR);
00090 
00091   /*
00092    * Si le DataGroup /STRUCT/<modelname>/VARATR/<varattname> n'existe pas on le crée
00093    */
00094   if ((_attid = _MEDdatagroupOpen(_varid,varattname)) < 0)
00095     if ((_attid = _MEDdatagroupCreer(_varid,varattname)) < 0) {
00096       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,varattname);
00097       SSCRUTE(_path);goto ERROR;
00098     }
00099   strcat(_path,varattname);
00100 
00101   /*
00102    * Creation/Ecriture de l'attribut MED_NOM_ATT (type des valeurs de l'attribut.)
00103    */
00104   if ( _MEDattributeIntWr(_attid,MED_NOM_ATT,&_medintvaratttype) < 0 ) {
00105     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00106     SSCRUTE(MED_NOM_ATT);ISCRUTE(_medintvaratttype);
00107     goto ERROR;
00108   }
00109 
00110   /*
00111    * Creation/Ecriture de l'attribut MED_NOM_NCO (nombre de composantes des valeurs de l'attribut.)
00112    */
00113   if ( _MEDattributeIntWr(_attid,MED_NOM_NCO,&nbofcomponent) < 0 ) {
00114     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00115     SSCRUTE(MED_NOM_NCO);ISCRUTE(nbofcomponent);
00116     goto ERROR;
00117   }
00118 
00119 
00120   _ret=0;
00121  ERROR:
00122 
00123   if (_attid>0)            if (_MEDdatagroupFermer(_attid) < 0) {
00124     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00125     ISCRUTE_id(_attid);
00126   }
00127 
00128   if (_varid>0)            if (_MEDdatagroupFermer(_varid) < 0) {
00129     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_VARATR_NOM);
00130     ISCRUTE_id(_varid);
00131   }
00132 
00133   if (_elemid>0)            if (_MEDdatagroupFermer(_elemid) < 0) {
00134     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,modelname);
00135     ISCRUTE_id(_elemid);
00136   }
00137 
00138   return _ret;
00139 }

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