MAJ_310_320_familles.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2016  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 
00025 #include "MAJ_310_320.h"
00026 #include "MAJ_version.h"
00027 
00028 static  void _move_families(med_idt fid, char * const _pathi,char * const _pathf) {
00029   med_err _ret=0;
00030   med_int _nfam=0;
00031   med_int _sizei,_sizef;
00032   med_size _size=0;
00033   int i=0;
00034 
00035   _ret=_MEDnObjects(fid,_pathi,&_size);
00036   MED_ERR_EXIT_IF(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_pathi);
00037   _nfam = (med_int ) _size;
00038   
00039   _sizef=strlen(_pathf); _sizei =_sizef-1;
00040     
00041   /* MAJ des familles */
00042   for (i=0;i<_nfam;i++) {
00043 
00044     _pathi[_sizei]='/';
00045     _pathf[_sizef]='/';
00046     _pathi[++_sizei]='\0';
00047     _pathf[++_sizef]='\0';
00048     /* SSCRUTE(_pathi); */
00049     /* SSCRUTE(_pathf); */
00050       
00051     /*
00052      * On recupere le nom de la famille 
00053      */
00054 
00055     /* Attention : On enlève les groupes fam au fur et à mesure,
00056        il ne faut pas utiliser _num mais 0.
00057        ret =  _MEDobjectGetName(fid, _pathi ,_num, &_pathi[_sizei]) < 0;
00058     */
00059     _ret =  _MEDobjectGetName(fid, _pathi ,0, &_pathi[_sizei]) < 0;
00060     MED_ERR_EXIT_IF(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathi);
00061 
00062     strncpy(&_pathf[_sizef],&_pathi[_sizei],MED_NAME_SIZE+1);
00063 
00064     /* SSCRUTE(_pathi); */
00065     /* SSCRUTE(_pathf); */
00066 
00067     EXIT_IF(  H5Lmove( fid, _pathi, fid, _pathf, H5P_DEFAULT, H5P_DEFAULT ) < 0, "Failed to move family ",_pathi);
00068     --_sizei;--_sizef;
00069   }
00070 }
00071 
00072 
00073 void MAJ_310_320_familles(med_idt fid)
00074 {
00075   med_err  _ret=0;
00076   htri_t   _datasetexist;
00077   char     _pathi[(MED_TAILLE_FAS+MED_NAME_SIZE+1)  + MED_TAILLE_FAS_ENTITE+MED_NAME_SIZE+1] = MED_FAS;
00078   char     _pathf[(MED_TAILLE_FAS+1+MED_NAME_SIZE+1)+ MED_TAILLE_FAS_ENTITE+MED_NAME_SIZE+1] = "/FAS_/";
00079   /* char _pathtmp[MED_TAILLE_FAS+3]="/FAS__/"; */
00080   int      _meshi=0;
00081   med_size _sizei=0,_sizef=0,_size=0,_nmesh=0;
00082   med_idt  _famId=0,_famMeshId=0,_famZeId=0,_famElId=0,_famNoeId=0;
00083   MAJ_version_num(fid,3,1,0);
00084 
00085   /*Itération sur les différents maillages présents dans le groupe famille*/
00086   _ret=_MEDnObjects(fid,_pathi,&_nmesh);
00087   MED_ERR_EXIT_IF(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_pathi);
00088 
00089   for (_meshi=0;_meshi<_nmesh;_meshi++) {
00090 
00091     /*
00092      * On recupere le nom du maillage
00093      */
00094     _pathi[MED_TAILLE_FAS  ]='\0';
00095     _pathf[MED_TAILLE_FAS+1]='\0';
00096 
00097    _ret =  _MEDobjectGetName(fid, _pathi ,_meshi, &_pathi[MED_TAILLE_FAS]) < 0;
00098     MED_ERR_EXIT_IF(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathi);
00099     /* SSCRUTE(_pathi); */
00100 
00101     /*Création du chemin cible _pathf s'il n'existe pas dans le fichier*/
00102     _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00103     if(!_datasetexist) {
00104       _famId = _MEDdatagroupCreer(fid,_pathf);
00105       MED_ERR_EXIT_IF(_famId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
00106       if (_famId>0) _ret=_MEDdatagroupFermer(_famId);
00107       MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
00108     }
00109     /*Création de la famille sur le maillage courant*/
00110     strncpy(&_pathf[MED_TAILLE_FAS+1],&_pathi[MED_TAILLE_FAS],MED_NAME_SIZE+1);
00111     _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00112     if(!_datasetexist) {
00113       _famMeshId = _MEDdatagroupCreer(fid,_pathf);
00114       MED_ERR_EXIT_IF(_famMeshId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
00115       if (_famMeshId>0) _ret=_MEDdatagroupFermer(_famMeshId);
00116       MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
00117     }
00118 
00119     _sizef=strlen(_pathf);_sizei =_sizef-1;
00120 
00121     /* Si une famille d'éléments existe ds pathi crée la dans _path */
00122     strncpy(&_pathi[_sizei],MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE-1);
00123     _pathi[_sizei+(MED_TAILLE_FAS_ENTITE-1)]='\0';
00124     _datasetexist=H5Lexists( fid, _pathi, H5P_DEFAULT );
00125     if (_datasetexist) {
00126       strncpy(&_pathf[_sizef],MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE-1);
00127       _pathf[_sizef+(MED_TAILLE_FAS_ENTITE-1)]='\0';
00128      _famNoeId = _MEDdatagroupCrOrderCr(fid,_pathf);
00129       MED_ERR_EXIT_IF(_famNoeId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
00130       if (_famNoeId>0) _ret=_MEDdatagroupFermer(_famNoeId);
00131       MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
00132       _move_families( fid, _pathi,_pathf);
00133     }
00134   
00135 
00136     /* Si une famille de noeud existe crée la dans _path */
00137     strncpy(&_pathi[_sizei],MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE-1);
00138     _pathi[_sizei+(MED_TAILLE_FAS_ENTITE-1)]='\0';
00139     _datasetexist=H5Lexists( fid, _pathi, H5P_DEFAULT );
00140     if (_datasetexist) {
00141       strncpy(&_pathf[_sizef],MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE-1);
00142       _pathf[_sizef+(MED_TAILLE_FAS_ENTITE-1)]='\0';
00143      _famElId = _MEDdatagroupCrOrderCr(fid,_pathf);
00144       MED_ERR_EXIT_IF(_famElId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
00145       if (_famElId>0) _ret=_MEDdatagroupFermer(_famElId);
00146       MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
00147       _move_families( fid, _pathi,_pathf);
00148     }
00149 
00150     /* Création de la famille zéro dans _pathf */
00151     strncpy(&_pathf[_sizef],MED_FAS_ZERO,MED_TAILLE_FAS_ZERO-1);
00152     _pathf[_sizef+(MED_TAILLE_FAS_ZERO-1)]='\0';
00153     _famZeId = _MEDdatagroupCrOrderCr(fid,_pathf);
00154     MED_ERR_EXIT_IF(_famZeId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
00155     if (_famZeId>0) _ret=_MEDdatagroupFermer(_famZeId);
00156     MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
00157   }
00158 
00159   _pathi[MED_TAILLE_FAS  ]='\0';
00160   _pathf[MED_TAILLE_FAS+1]='\0';
00161   _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00162 
00163   if (_datasetexist ) {
00164     EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
00165     EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathf);
00166   }
00167 
00168    /* _MEDobjetsOuverts(fid); */
00169 
00170    /* MAJ_version_num(fid,3,1,0); */
00171 
00172 }

Généré le Thu Jan 21 18:06:07 2016 pour MED fichier par  doxygen 1.6.1