MAJ_236_300_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_236_300.h"
00026 #include "MAJ_version.h"
00027 
00028 void MAJ_236_300_champs(med_idt fid)
00029 {
00030   med_err lret,ret;
00031   /*   med_idt         _datagroup=0; */
00032   med_field_type   typcha;
00033   char nomcha    [MED_NAME_SIZE+1]="";
00034   char _meshname [MED_NAME_SIZE+1]="";
00035   char _dtunit   [MED_SNAME_SIZE+1]="";
00036   char *comp= NULL, *unit= NULL;
00037   med_int   ncomp,ncha;
00038   med_int  _ncstp=0;
00039   med_bool _local=MED_FALSE;
00040   htri_t   _datasetexist;
00041   char _pathi[MED_TAILLE_CHA+1+MED_NAME_SIZE+1]=MED_CHA;
00042   char _pathf[MED_TAILLE_CHA+2+MED_NAME_SIZE+1]="/CHA_/";
00043   char _pathtmp[MED_TAILLE_CHA+3]="/CHA__/";
00044   int i,j;
00045 
00046   char nomlien[MED_NAME_SIZE+1]="";
00047   char * lien = NULL;
00048   med_int nln,nval;
00049 
00050   med_int  _nloc,_intgeotype,_sdim;
00051   char     _pathloc[MED_TAILLE_GAUSS+MED_NAME_SIZE+1]=MED_GAUSS;
00052 
00053   med_int  _npar,_numdt,_numit;
00054   char     _pathpari[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA;
00055   char     _pathparf[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA;
00056   int      _pathparlen;
00057   med_size _n=0;
00058   char     _cpstnamei[2*MED_MAX_PARA+1]="";
00059   char     _cpstnamef[2*MED_MAX_PARA+1]="";
00060   char     _uniname[MED_SNAME_SIZE+1]="";
00061 /*   hid_t    _lac_plist_id; */
00062   hid_t    _lcp_plist_id;
00063   hid_t    _ocp_plist_id;
00064   med_bool _createunt = MED_TRUE;
00065 
00066   MAJ_version_num(fid,2,3,6);
00067 
00068   /* MAJ des varaibles scalaires */
00069   _npar = MEDnParameter(fid);
00070   if (_npar > 0) {
00071     fprintf(stdout,"  >>> Normalisation des paramètres scalaires\n");
00072     _pathparf[MED_TAILLE_NUM_DATA-2]='_';
00073 /*     _lac_plist_id = H5Pcreate( H5P_LINK_ACCESS ); */
00074     _ocp_plist_id = H5Pcreate( H5P_OBJECT_COPY );
00075     _lcp_plist_id = H5Pcreate( H5P_LINK_CREATE );
00076     H5Pset_create_intermediate_group( _lcp_plist_id, 1 );
00077     H5Pset_copy_object( _ocp_plist_id, H5O_COPY_SHALLOW_HIERARCHY_FLAG);
00078   }
00079 
00080   for (i=0 ; i < _npar ; i++ ) {
00081 
00082     MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,i, &_pathpari[MED_TAILLE_NUM_DATA]) < 0,
00083                      MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari);
00084 
00085 
00086     strcpy(&_pathparf[MED_TAILLE_NUM_DATA],&_pathpari[MED_TAILLE_NUM_DATA]);
00087 /*     SSCRUTE(_pathparf); */
00088 /*     SSCRUTE(_pathpari); */
00089 
00090     /*Copie le group avec ses attributs et les objets de premier niveau.*/
00091     ret =  H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id);
00092 /*     ret =  H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */
00093     EXIT_IF(ret < 0,"Copie du datagroup",_pathpari);
00094 
00095     _pathparlen=strlen(_pathpari);
00096     _pathpari[_pathparlen]='/';_pathparf[_pathparlen]='/';
00097     ++_pathparlen;
00098     _pathpari[_pathparlen]='\0';_pathparf[_pathparlen]='\0';
00099 
00100 /*     SSCRUTE(_pathparf); */
00101 /*     SSCRUTE(_pathpari); */
00102 
00103     ret =_MEDnObjects(fid,_pathpari, &_n);
00104     MED_ERR_EXIT_IF( (ret == (MED_ERR_COUNT + MED_ERR_DATAGROUP)), MED_ERR_COUNT,MED_ERR_PARAMETER,_pathpari);
00105 
00106     for (j=0 ; j < _n ; ++j ) {
00107       MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,j, &_pathpari[_pathparlen]) < 0,
00108                        MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari);
00109 
00110       MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NOR,
00111                                                 MED_INTERNAL_INT,(unsigned char * const ) &_numit) < 0,
00112                        MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NOR);
00113 
00114       MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NDT,
00115                                                 MED_INTERNAL_INT,(unsigned char * const ) &_numdt) < 0,
00116                        MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT);
00117       
00118       MED_ERR_EXIT_IF (_MEDattributeStringRdByName(fid,_pathpari,MED_NOM_UNI,
00119                                                 MED_SNAME_SIZE,_uniname) < 0,
00120                        MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT);
00121       
00122       _MEDgetComputationStepName(MED_SORT_DTIT,_numdt,_numit,&_pathparf[_pathparlen]);
00123 /*       strcat(_pathpari,"/"); */
00124 /*       strcat(_pathparf,"/"); */
00125 /*       SSCRUTE(_pathparf); */
00126 /*       SSCRUTE(_pathpari); */
00127 
00128 /*       ret =  H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id); */
00129 /*       ret =  H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */
00130 /*       H5Eprint1(stderr); */
00131 /*       EXIT_IF(ret < 0,"Copie d'une étape de calcul du paramètre scalaire ",_pathpari); */
00132 
00133       /*On modifie temporairement _pathpari pour pointer dans _pathparf*/
00134       _pathpari[MED_TAILLE_NUM_DATA-2]='_';
00135 /*       SSCRUTE(_pathparf); */
00136 /*       SSCRUTE(_pathpari); */
00137       ret = H5Gmove(fid, _pathpari, _pathparf  );
00138       EXIT_IF(ret < 0,"Renommage de l'étape de calcul",_pathpari);
00139       _pathpari[MED_TAILLE_NUM_DATA-2]='A';
00140 
00141 
00142       MED_ERR_EXIT_IF(H5Adelete_by_name( fid, _pathparf, MED_NOM_UNI, H5P_DEFAULT ) < 0,
00143                       MED_ERR_DELETE,MED_ERR_ATTRIBUTE,_pathparf);
00144 
00145       _pathparf[_pathparlen]='\0';
00146       _pathpari[_pathparlen]='\0';
00147       if ( _createunt ) {
00148         MED_ERR_EXIT_IF (_MEDattributeStringWrByName(fid,_pathparf,MED_NOM_UNT, MED_SNAME_SIZE,_uniname) < 0,
00149                          MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_UNT);
00150         _createunt = MED_FALSE;
00151       }
00152     }
00153     _createunt = MED_TRUE;
00154     _pathpari[MED_TAILLE_NUM_DATA]='\0';
00155   }
00156 
00157   if ( _npar > 0 ) {
00158 
00159     _pathpari[MED_TAILLE_NUM_DATA]='\0';
00160     _pathparf[MED_TAILLE_NUM_DATA]='\0';
00161     MED_ERR_EXIT_IF ( H5Ldelete(fid,_pathpari,H5P_DEFAULT) < 0 ,
00162                       MED_ERR_DELETE,MED_ERR_LINK,_pathpari);
00163 
00164     ret = H5Gmove(fid, _pathparf, _pathpari  );
00165     EXIT_IF(ret < 0,"Renommage du group de paramètres scalaires",_pathparf);
00166 
00167   }
00168 
00169   /* MAJ des localisations */
00170   _nloc = MEDnLocalization(fid);
00171 /*   ISCRUTE(_nloc); */
00172   if (_nloc > 0)
00173     fprintf(stdout,"  >>> Normalisation des localisations des points d'intégration\n");
00174   for (i=0 ; i < _nloc ; i++ ) {
00175 
00176 /*     SSCRUTE(_pathloc); */
00177     MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathloc ,i, &_pathloc[MED_TAILLE_GAUSS]) < 0,
00178                      MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathloc);
00179 /*     SSCRUTE(_pathloc); */
00180     MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathloc,MED_NOM_GEO,
00181                                               MED_INTERNAL_INT,(unsigned char * const ) &_intgeotype) < 0,
00182                      MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
00183     _sdim = (_intgeotype/100);
00184 
00185     MED_ERR_EXIT_IF (_MEDattributeNumWrByName(fid,_pathloc,MED_NOM_DIM,
00186                                               MED_INTERNAL_INT,(const unsigned char * const) &_sdim) < 0,
00187                      MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_DIM);
00188 
00189     MED_ERR_EXIT_IF ( _MEDattributeStringWrByName(fid,_pathloc,MED_NOM_INM,MED_NAME_SIZE,"") < 0,
00190                       MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_INM);
00191     _pathloc[MED_TAILLE_GAUSS]='\0';
00192 
00193   }
00194 
00195   /* MAJ des liens */
00196   nln = MEDnLink(fid);
00197   if (nln > 0)
00198     fprintf(stdout,"  >>> Normalisation des liens\n");
00199   for (i=1 ; i <= nln ; i++ ) {
00200 
00201 
00202     ret =  MEDlinkInfo(fid, i, nomlien, &nval);
00203     EXIT_IF(ret,"Erreur a la demande d'information sur le lien",NULL);
00204 
00205 /*     printf("\t- Lien n°%i de nom |%s| et de taille "IFORMAT"\n",i,nomlien,nval); */
00206 
00207     lien = (char *) malloc((nval+1)*sizeof(char));
00208     EXIT_IF(lien == NULL,NULL,NULL);
00209 
00210     ret = MEDlinkRd(fid, nomlien, lien );
00211     EXIT_IF(ret,"Erreur a la lecture du lien : ",nomlien);
00212 
00213     MAJ_version_num(fid,3,0,8);
00214     ret = MED30linkWr(fid,nomlien,lien);
00215     EXIT_IF(ret,"Erreur a l'écrtiure du lien : ",nomlien);
00216     MAJ_version_num(fid,2,3,6);
00217  
00218     lien[nval] = '\0';
00219 /*     printf("\t\t|%s|\n\n",lien); */
00220 
00221     free(lien);
00222   }
00223 
00224   /* combien de champs dans le fichier */
00225   ncha = MEDnField(fid);
00226   EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL);
00227 
00228   /* MAJ des champs */
00229   for (i =0;i<ncha;i++) {
00230     lret = 0;
00231 
00232     /* Lecture du nombre de composantes */
00233     ncomp = MEDfieldnComponent(fid,i+1);
00234     if (ncomp < 0) {
00235       MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp);
00236       exit(1);
00237     }
00238 
00239     /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/
00240     comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
00241     EXIT_IF(comp == NULL,NULL,NULL);
00242     unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
00243     EXIT_IF(unit == NULL,NULL,NULL);
00244 
00245     /*     ret = MED231champInfoEtRen(fid,i+1,nomcha,&typcha,comp,unit,ncomp); */
00246     ret = MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp);
00247     MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha);
00248 
00249     /* creation du champ destination */
00250     MAJ_version_num(fid,3,0,8);
00251 
00252     EXIT_IF( H5Gmove(fid, _pathi, _pathtmp  ) < 0,"Switch to ",_pathtmp);
00253     _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00254     if (_datasetexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathi); }
00255 
00256     MED_ERR_EXIT_IF( MEDfieldCr(fid,nomcha,typcha,ncomp,comp,unit,_dtunit,_meshname ) < 0,
00257                      MED_ERR_CREATE,MED_ERR_FIELD,_pathf);
00258     EXIT_IF( H5Gmove(fid, _pathi  , _pathf  ) < 0,"Switch to ",_pathf);
00259     EXIT_IF( H5Gmove(fid, _pathtmp, _pathi  ) < 0,"Switch to ",_pathi);
00260 
00261     MAJ_version_num(fid,2,3,6);
00262 
00263     free(comp);
00264     free(unit);
00265 
00266     lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE,_ncstp, _pathi, _pathf);
00267     if (lret != 0) {
00268       MESSAGE("Erreur à la lecture des champs aux noeuds "); exit(1);
00269     }
00270 
00271     lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_CELL,_ncstp, _pathi, _pathf);
00272     if (lret != 0) {
00273       MESSAGE("Erreur à la lecture des champs aux mailles "); exit(1);
00274     }
00275 
00276     lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_FACE,_ncstp, _pathi, _pathf);
00277     if (lret != 0) {
00278       MESSAGE("Erreur à la lecture des champs aux faces "); exit(1);
00279     }
00280 
00281     lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_EDGE,_ncstp, _pathi, _pathf);
00282     if (lret != 0) {
00283       MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1);
00284     }
00285 
00286     lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE_ELEMENT,_ncstp, _pathi, _pathf);
00287     if (lret != 0) {
00288       MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1);
00289     }
00290 
00291   }
00292   _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
00293 
00294   if (_datasetexist ) {
00295     EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
00296     EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathf);
00297   }
00298 
00299 
00300 }

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