MEDprofileWr.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 
00039 med_err
00040 MEDprofileWr(const med_idt        fid,
00041              const char* const    profilename,
00042              const med_int        profilesize,
00043              const med_int* const profilearray)
00044 {
00045   med_access_mode _MED_ACCESS_MODE;
00046   med_idt        _root=0,_pfid=0;
00047   med_err        _ret=-1;
00048   char           _path[MED_TAILLE_PROFILS+MED_NAME_SIZE+1]=MED_PROFILS;
00049   med_filter     _filter        = MED_FILTER_INIT;
00050 
00051   /*
00052    * On inhibe le gestionnaire d'erreur
00053    */
00054   _MEDmodeErreurVerrouiller();
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  /*
00069    * Si le DataGroup /PROFILS/ n'existe pas, on le cree
00070    */
00071   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
00072     if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
00073       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
00074      goto ERROR;
00075     }
00076 
00077   NOFINALBLANK(profilename,ERROR);
00078   /*
00079    * Si le DataGroup /PROFILS/<profilename> n'existe pas, on le cree
00080    */
00081   if ((_pfid = _MEDdatagroupOuvrir(_root,profilename)) < 0)
00082     if ((_pfid = _MEDdatagroupCreer(_root,profilename)) < 0) {
00083       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,profilename);
00084       SSCRUTE(_path);goto ERROR;
00085     }
00086 
00087   strcat(_path,profilename);
00088 
00089 
00090   /*
00091    * On stocke "profilesize" sous forme d'attribut
00092    */
00093   if (_MEDattributeIntWr(_pfid,MED_NOM_NBR,&profilesize) < 0) {
00094     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PROFILE_MSG);
00095     SSCRUTE(profilename);SSCRUTE(MED_NOM_NBR);ISCRUTE(profilesize);
00096     goto ERROR;
00097   }
00098 
00099   /*
00100    * On stocke le profil dans un dataset
00101    */
00102   if ( MEDfilterEntityCr(fid, profilesize, 1, 1, MED_ALL_CONSTITUENT,
00103                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
00104                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
00105     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
00106     goto ERROR;
00107   }
00108 
00109   if ( _MEDdatasetWr(_pfid,MED_NOM_PFL,MED_INTERNAL_INT,&_filter, profilearray) < 0) {
00110     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_PFL);SSCRUTE(_path);
00111     goto ERROR;
00112   }
00113 
00114   if ( MEDfilterClose(&_filter) < 0 ) {
00115     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_PROFILE_MSG); SSCRUTE(_path);
00116     goto ERROR;
00117   }
00118 
00119   _ret = 0;
00120 
00121  ERROR:
00122 
00123   if (_pfid>0)            if (_MEDdatagroupFermer(_pfid) < 0) {
00124     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,profilename);
00125     ISCRUTE_id(_pfid);
00126   }
00127 
00128   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
00129     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_PROFILS);
00130     ISCRUTE_id(_root);
00131   }
00132 
00133   return _ret;
00134 }
00135 
00136 
00137 
00138 

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