MEDfamilyCr.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 <string.h>
00022 #include <stdlib.h>
00023 #include <med_outils.h>
00024 
00037 med_err
00038 MEDfamilyCr(const med_idt      fid,
00039             const char * const meshname,
00040             const char * const familyname,
00041             const med_int      familynumber,
00042             const med_int      ngroup,
00043             const char * const groupname)
00044 {
00045   med_access_mode       _MED_ACCESS_MODE;
00046   med_err               _ret=-1;
00047   med_idt               _root=0,_famid=0, _datagroup=0,_datagroup2=0,_datagroup3=0;
00048   char                  _fampath         [MED_TAILLE_FAS+MED_NAME_SIZE+1]=MED_FAS;
00049   const char*           _datagroupname2="";
00050   med_filter            _filter        = MED_FILTER_INIT;
00051   const char * const    _MED_FAS_NOEUD_NOM = MED_FAS_NOEUD_NOM;
00052   const char * const    _MED_FAS_ELEME_NOM = MED_FAS_ELEME_NOM;
00053   const char * const    _FAMILLE_ZERO      = FAMILLE_ZERO;
00054 
00055 
00056   /*
00057    * On inhibe le gestionnaire d'erreur HDF 5
00058    */
00059   _MEDmodeErreurVerrouiller();
00060  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00061 
00062   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00063     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00064     goto ERROR;
00065   }
00066 
00067   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00068     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00069     ISCRUTE_int(_MED_ACCESS_MODE);
00070     goto ERROR;
00071   }
00072 
00073   NOFINALBLANK(meshname,ERROR);
00074   NOFINALBLANK(familyname,ERROR);
00075 
00076   /*
00077    * Si le DataGroup root n'existe pas, on le cree
00078    */
00079   if ((_root = _MEDdatagroupOuvrir(fid,_fampath)) < 0)
00080     if ((_root = _MEDdatagroupCreer(fid,_fampath)) < 0) {
00081       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_fampath);
00082      goto ERROR;
00083     }
00084 
00085   strcat(_fampath,meshname);
00086 /*   SSCRUTE(_fampath); */
00087   if ((_famid = _MEDdatagroupOuvrir(fid,_fampath)) < 0)
00088     if ((_famid = _MEDdatagroupCreer(fid,_fampath)) < 0 ) {
00089       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
00090       SSCRUTE(_fampath);
00091       goto ERROR;
00092     }
00093 
00094   if (familynumber > 0)
00095     _datagroupname2=_MED_FAS_NOEUD_NOM;
00096   else if (familynumber < 0)
00097     _datagroupname2=_MED_FAS_ELEME_NOM;
00098   else
00099     _datagroupname2=_FAMILLE_ZERO;
00100 
00101  if ((_datagroup2 = _MEDdatagroupOuvrir(_famid,_datagroupname2)) < 0)
00102     if ((_datagroup2 = _MEDdatagroupCreer(_famid,_datagroupname2)) < 0 ) {
00103       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_ERR_FAMILY_MSG);
00104       SSCRUTE(_datagroupname2);SSCRUTE(_fampath);SSCRUTE(MED_FAS);
00105       goto ERROR;
00106   }
00107 
00108  if (familynumber != 0) {
00109 
00110    if ((_datagroup = _MEDdatagroupCreer(_datagroup2,familyname)) < 0 ) {
00111       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_ERR_FAMILY_MSG);
00112       SSCRUTE(familyname);SSCRUTE(_fampath);SSCRUTE(MED_FAS);
00113       goto ERROR;
00114    }
00115  } else {
00116    _datagroup=_datagroup2;
00117  }
00118 
00119 
00120  if ( _MEDattributeIntWr(_datagroup,MED_NOM_NUM,&familynumber) < 0) {
00121    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FAMILY_MSG);
00122    SSCRUTE(familyname);SSCRUTE(MED_NOM_NUM);ISCRUTE(familynumber);
00123    SSCRUTE(_fampath);SSCRUTE(MED_FAS);SSCRUTE(_datagroupname2);
00124    goto ERROR;
00125  }
00126 
00127  if ( (familynumber != 0) && (ngroup > 0) ) {
00128 
00129    if ((_datagroup3 = _MEDdatagroupCreer(_datagroup,MED_NOM_GRO)) < 0 ) {
00130      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_ERR_FAMILY_MSG);
00131      SSCRUTE(familyname);SSCRUTE(_fampath);SSCRUTE(MED_FAS);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_GRO);
00132      goto ERROR;
00133    }
00134 
00135    if ( MEDfilterEntityCr(fid, ngroup, 1, 1, MED_ALL_CONSTITUENT,
00136                           MED_FULL_INTERLACE,MED_UNDEF_PFLMODE,
00137                           MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
00138      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
00139      goto ERROR;
00140    }
00141 
00142    if ( _MEDdatasetWr(_datagroup3,MED_NOM_NOM,MED_INTERNAL_LNAME,&_filter, groupname) < 0) {
00143      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_NOM);
00144      SSCRUTE(_fampath);SSCRUTE(MED_FAS);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_GRO);
00145      SSCRUTE(familyname);goto ERROR;
00146    }
00147 
00148    if ( MEDfilterClose(&_filter) < 0 ) {
00149      MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_FAMILY_MSG);
00150      SSCRUTE(familyname);SSCRUTE(_fampath);SSCRUTE(MED_FAS);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_GRO);
00151      goto ERROR;
00152    }
00153 
00154    if ( _MEDattributeIntWr(_datagroup3,MED_NOM_NBR,&ngroup) < 0) {
00155      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FAMILY_MSG);
00156      SSCRUTE(familyname);SSCRUTE(_fampath);SSCRUTE(MED_FAS);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_GRO);
00157      SSCRUTE(MED_NOM_NBR);
00158      goto ERROR;
00159    }
00160 
00161  }
00162  _ret = 0;
00163 
00164  ERROR:
00165 
00166  if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
00167    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_GRO);
00168    ISCRUTE_id(_datagroup3);
00169  }
00170 
00171  if ( _datagroup != _datagroup2 )
00172    if (_datagroup > 0 )   if (_MEDdatagroupFermer(_datagroup) < 0) {
00173    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,familyname);
00174    ISCRUTE_id(_datagroup);
00175  }
00176 
00177  if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
00178    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
00179    ISCRUTE_id(_datagroup2);
00180  }
00181 
00182  if (_famid>0)         if (_MEDdatagroupFermer(_famid) < 0) {
00183    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_fampath);
00184    ISCRUTE_id(_famid);
00185  }
00186 
00187  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
00188    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_FAS);
00189    ISCRUTE_id(_root);
00190  }
00191 
00192  return _ret;
00193 }

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