# MED30linkWr.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_config.h>
    00020 #include <med_outils.h>
    00021 #include <med.h>
    00022
    00023 #include <string.h>
    00024 #include <stdlib.h>
    00025
    00026 #include "MAJ_236_300.h"
    00027
    00028
    00029 med_err
    00030 MED30linkWr(const med_idt        fid,
    00031             const char   * const meshname,
    00032             const char   * const link)
    00033 {
    00034   med_access_mode _MED_ACCESS_MODE;
    00035   med_idt        _lid=0, _root=0;
    00036   med_err        _ret=-1;
    00037   char           _path[MED_TAILLE_LIENS+MED_NAME_SIZE+1]=MED_LIENS;
    00038   med_int        _n=0;
    00039   med_filter     _filter        = MED_FILTER_INIT;
    00040   htri_t   _datasetexist;
    00041
    00042   /*
    00043    * On inhibe le gestionnaire d'erreur HDF 5
    00044    */
    00045   _MEDmodeErreurVerrouiller();
    00046 /*  if (_MEDcheckVersion30(fid) < 0) goto ERROR; */
    00047
    00048   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00049     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00050     goto ERROR;
    00051   }
    00052
    00053   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00054     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00055     ISCRUTE_int(_MED_ACCESS_MODE);
    00056     goto ERROR;
    00057   }
    00058
    00059   /*
    00060    * Si le DataGroup /LIENS/ n'existe pas, on le cree
    00061    */
    00062   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
    00063     if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
    00064       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
    00065       goto ERROR;
    00066     }
    00067
    00068   NOFINALBLANK(link,ERROR);
    00069   /*
    00070    * Si le DataGroup /LIENS/<meshname> n'existe pas, on le cree
    00071    */
    00072   if ((_lid = _MEDdatagroupOuvrir(_root,meshname)) < 0)
    00073     if ((_lid = _MEDdatagroupCreer(_root,meshname)) < 0) {
    00074       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
    00075       SSCRUTE(_path);goto ERROR;
    00076     }
    00077
    00078   strcat(_path,meshname);
    00079
    00080
    00081   /*
    00082    * On stocke <n> sous forme d'attribut
    00083    */
    00084   _n = strlen(link);
    00085   if (_MEDattributeIntWr(_lid,MED_NOM_NBR,&_n) < 0) {
    00086     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LINK_MSG);
    00087     SSCRUTE(_path);SSCRUTE(MED_NOM_NBR);ISCRUTE(_n);
    00088     goto ERROR;
    00089   }
    00090
    00091   /*
    00092    * On stocke le link dans un dataset
    00093    */
    00094   if ( MEDfilterEntityCr(fid,_n, 1, 1, MED_ALL_CONSTITUENT,
    00095                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00096                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00097     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00098     goto ERROR;
    00099   }
    00100
    00101 /*   SSCRUTE(link); */
    00102   _datasetexist=H5Lexists( _lid, MED_NOM_LIE, H5P_DEFAULT );
    00103   if (_datasetexist ) {
    00104     EXIT_IF( (H5Ldelete(_lid,MED_NOM_LIE, H5P_DEFAULT) < 0) ,"Delete ",MED_NOM_LIE);
    00105   }
    00106
    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 }