MAJ_300_310_champs.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_config.h"
00020 #include "med_outils.h"
00021 #include "med.h"
00022 
00023 #include <string.h>
00024 
00025 #include "MAJ_300_310.h"
00026 #include "MAJ_version.h"
00027 
00028 void MAJ_300_310_champs(med_idt fid)
00029 {
00030   med_err ret;
00031   med_field_type   typcha;
00032   char nomcha    [MED_NAME_SIZE+1]="";
00033   char _meshname [MED_NAME_SIZE+1]="";
00034   char _dtunit   [MED_SNAME_SIZE+1]="";
00035   char *comp= NULL, *unit= NULL;
00036   med_int   ncomp,ncha;
00037   med_int  _ncstp=0;
00038   med_bool _local=MED_FALSE;
00039   htri_t   _datasetexist;
00040   char _pathi[(MED_TAILLE_CHA+MED_NAME_SIZE+1)+2*MED_MAX_PARA+1  ] = MED_CHA;
00041   char _pathf[(MED_TAILLE_CHA+1+MED_NAME_SIZE+1)+2*MED_MAX_PARA+1] = "/CHA_/";
00042   char _pathtmp[MED_TAILLE_CHA+3]="/CHA__/";
00043   int i=0,_num=0;
00044   med_size _sizei=0,_sizef=0;
00045   char    _cstpname[2*MED_MAX_PARA+1]="";
00046 
00047   MAJ_version_num(fid,3,0,8);
00048 
00049   /* combien de champs dans le fichier */
00050   ncha = MEDnField(fid);
00051   EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL);
00052 
00053   /* MAJ des champs */
00054   for (i=0;i<ncha;i++) {
00055 
00056     /* Lecture du nombre de composantes */
00057     ncomp = MEDfieldnComponent(fid,i+1);
00058     if (ncomp < 0) {
00059       MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp);
00060       exit(1);
00061     }
00062 
00063     /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/
00064     comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
00065     EXIT_IF(comp == NULL,NULL,NULL);
00066     unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
00067     EXIT_IF(unit == NULL,NULL,NULL);
00068 
00069     ret = MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp);
00070     MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha);
00071 
00072     /* Création du champ destination */
00073     /* ATTENTION appel de MAJ_version avec fid,num 
00074        et non juste fid --> futures procédures de MAJ_310_... */
00075     /* MAJ_version(fid); */
00076     MAJ_version_num(fid,3,1,0);
00077 
00078     EXIT_IF( H5Gmove(fid, _pathi, _pathtmp  ) < 0,"Switch to ",_pathtmp);
00079     /* Nous sommes dans une boucle sur les champs : 
00080        On récupère donc les champs en cours de transformation
00081     */
00082     _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00083     if (_datasetexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathi); }
00084     /* Ajout du champ au nouveau format dans le _pathi */
00085     MED_ERR_EXIT_IF( MEDfieldCr(fid,nomcha,typcha,ncomp,comp,unit,_dtunit,_meshname ) < 0,
00086                      MED_ERR_CREATE,MED_ERR_FIELD,_pathf);
00087 
00088     EXIT_IF( H5Gmove(fid, _pathi  , _pathf  ) < 0,"Switch to ",_pathf);
00089     EXIT_IF( H5Gmove(fid, _pathtmp, _pathi  ) < 0,"Switch to ",_pathi);
00090 
00091     strncpy(&_pathi[MED_TAILLE_CHA]  ,nomcha,MED_NAME_SIZE+1);
00092     strncpy(&_pathf[MED_TAILLE_CHA+1],nomcha,MED_NAME_SIZE+1);
00093     _sizei = MED_TAILLE_CHA+strlen(nomcha);
00094     _sizef = _sizei+1;
00095     _pathi[_sizei]='/';++_sizei; 
00096     _pathf[_sizef]='/';++_sizef; 
00097   
00098  
00099     for (_num=0; _num<_ncstp; ++_num) {
00100  
00101       _pathi[_sizei]='\0';
00102       _pathf[_sizef]='\0';
00103       /* SSCRUTE(_pathi); */
00104       /* SSCRUTE(_pathf); */
00105    
00106       /*
00107        * On recupere le nom de la séquence de calcul 
00108        */
00109 
00110       /* Attention : On enlève les groupes DTIT au fur et à mesure,
00111          il ne faut pas utiliser _num mais 0.
00112         ret =  _MEDobjectGetName(fid, _pathi ,_num, &_pathi[_sizei]) < 0;
00113       */
00114       ret =  _MEDobjectGetName(fid, _pathi ,0, &_pathi[_sizei]) < 0;
00115       MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathi);
00116 
00117       strncpy(&_pathf[_sizef],&_pathi[_sizei],2*MED_MAX_PARA+1);
00118 
00119       /* SSCRUTE(_pathi); */
00120       /* SSCRUTE(_pathf); */
00121       EXIT_IF(  H5Lmove( fid, _pathi, fid, _pathf, H5P_DEFAULT, H5P_DEFAULT ) < 0, "Failed to move field ",_pathi); 
00122     }
00123 
00124     _pathi[MED_TAILLE_CHA]='\0';
00125     _pathf[MED_TAILLE_CHA+1]='\0';
00126 
00127     
00128     MAJ_version_num(fid,3,0,8);
00129     
00130     free(comp);
00131     free(unit);
00132 
00133   }
00134   
00135   _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00136 
00137   if (_datasetexist ) {
00138     EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
00139     EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathf);
00140   }
00141 
00142    /* _MEDobjetsOuverts(fid); */
00143 
00144 }

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