# MEDlinkWr.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
    00023 #include <string.h>
    00024 #include <stdlib.h>
    00025
    00035 med_err
    00036 MEDlinkWr(const med_idt        fid,
    00037           const char   * const meshname,
    00038           const char   * const link)
    00039 {
    00040   med_access_mode _MED_ACCESS_MODE;
    00041   med_idt        _lid=0, _root=0;
    00042   med_err        _ret=-1;
    00043   char           _path[MED_TAILLE_LIENS+MED_NAME_SIZE+1]=MED_LIENS;
    00044   med_int        _n=0;
    00045   med_filter     _filter        = MED_FILTER_INIT;
    00046
    00047   /*
    00048    * On inhibe le gestionnaire d'erreur HDF 5
    00049    */
    00050   _MEDmodeErreurVerrouiller();
    00051  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00052
    00053   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00054     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00055     goto ERROR;
    00056   }
    00057
    00058   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00059     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00060     ISCRUTE_int(_MED_ACCESS_MODE);
    00061     goto ERROR;
    00062   }
    00063
    00064   /*
    00065    * Si le DataGroup /LIENS/ n'existe pas, on le cree
    00066    */
    00067   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
    00068     if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
    00069       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
    00070       goto ERROR;
    00071     }
    00072
    00073   NOFINALBLANK(link,ERROR);
    00074   /*
    00075    * Si le DataGroup /LIENS/<meshname> n'existe pas, on le cree
    00076    */
    00077   if ((_lid = _MEDdatagroupOuvrir(_root,meshname)) < 0)
    00078     if ((_lid = _MEDdatagroupCreer(_root,meshname)) < 0) {
    00079       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
    00080       SSCRUTE(_path);goto ERROR;
    00081     }
    00082
    00083   strcat(_path,meshname);
    00084
    00085
    00086   /*
    00087    * On stocke <n> sous forme d'attribut
    00088    */
    00089   _n = strlen(link);
    00090   if (_MEDattributeIntWr(_lid,MED_NOM_NBR,&_n) < 0) {
    00091     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LINK_MSG);
    00092     SSCRUTE(_path);SSCRUTE(MED_NOM_NBR);ISCRUTE(_n);
    00093     goto ERROR;
    00094   }
    00095
    00096   /*
    00097    * On stocke le link dans un dataset
    00098    */
    00099   if ( MEDfilterEntityCr(fid,_n, 1, 1, MED_ALL_CONSTITUENT,
    00100                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00101                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00102     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00103     goto ERROR;
    00104   }
    00105
    00106 /*   SSCRUTE(link); */
    00107   if ( _MEDdatasetWr(_lid,MED_NOM_LIE,MED_INTERNAL_CHAR,&_filter, link) < 0) {
    00108     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_LIE);SSCRUTE(_path);
    00109     goto ERROR;
    00110   }
    00111
    00112   if ( MEDfilterClose(&_filter) < 0 ) {
    00113     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LINK_MSG); SSCRUTE(_path);
    00114     goto ERROR;
    00115   }
    00116
    00117
    00118   _ret = 0;
    00119
    00120  ERROR:
    00121
    00122   if (_lid>0)            if (_MEDdatagroupFermer(_lid) < 0) {
    00123     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
    00124     ISCRUTE_id(_lid);
    00125   }
    00126
    00127   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    00128     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_LIENS);
    00129     ISCRUTE_id(_root);
    00130   }
    00131
    00132   return _ret;
    00133
    00134 }