MAJ_236_300_maillages.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_versioned.h"
00022 #include <string.h>
00023 
00024 #include <2.3.6/med23v30.h>
00025 #include <2.3.6/med23v30_proto.h>
00026 #include <2.3.6/med_proto.h>
00027 #include "2.3.6/med23v30_misc.h"
00028 
00029 #include "MAJ_236_300.h"
00030 #include "MAJ_version.h"
00031 
00032 #define MAX_SPACE_DIM 3
00033 
00034 void MAJ_236_300_maillages(med_idt fid)
00035 {
00036   med_err _ret  = -1;
00037   med_err  ret  = -1;
00038   med_err _fret = -1;
00039   med_err _err  = -1;
00040   int     dummy=0;
00041   char _pathi[MED_TAILLE_MAA+MED_NAME_SIZE+1+2*MED_TAILLE_NOM_ENTITE+1+3+1]=MED_MAA;
00042   char _pathf[MED_TAILLE_MAA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+2*MED_TAILLE_NOM_ENTITE+1+1]=MED_MAA;
00043   char _pathgridf[MED_TAILLE_MAA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+2*MED_TAILLE_NOM_ENTITE+1+1]=MED_MAA;
00044   char _pathgridi[MED_TAILLE_MAA+MED_NAME_SIZE+1+2*MED_TAILLE_NOM_ENTITE+1+3+1]=MED_MAA;
00045   char _pathfam[MED_TAILLE_FAS+MED_NAME_SIZE+1+MED_NAME_SIZE+1]=MED_FAS;
00046   med_size _n=0;
00047   med_idt            _datagroup=0;
00048   int                _meshit=0;
00049   char               _imeshname[MED_NAME_SIZE+1];
00050   char               _fmeshname[MED_NAME_SIZE+1];
00051   char *             _meshname=_imeshname;
00052   med_int            _spacedim=0;
00053   med_int            _meshdim=0;
00054   med_mesh_type      _meshtype=MED_UNDEF_MESH_TYPE;
00055   char               _description[MED_COMMENT_SIZE+1]="";
00056   char               _dtunit[MED_SNAME_SIZE+1]="";
00057   med_sorting_type   _sortingtype=MED_SORT_UNDEF;
00058   med_int            _nstep=0;
00059   med_axis_type      _axistype=MED_UNDEF_AXIS_TYPE;
00060   char               _axisname[3*MED_SNAME_SIZE+1];
00061   char               _axisunit[3*MED_SNAME_SIZE+1];
00062   int                _itmplen=0;
00063   int                _ftmplen=0;
00064   int                _gitmplen=0;
00065   int                _gftmplen=0;
00066   med_int            _1=1;
00067   med_bool           _datagroupexist=MED_FALSE,_isasoftlink=MED_FALSE;
00068   med_type_grille    _gridtype;
00069   med_int            _gridstruct[MAX_SPACE_DIM] = {0,0,0};
00070   med_bool           _mustwrite_gridstruct= MED_FALSE;
00071   hid_t              _ocp_plist_id;
00072   hid_t              _lcp_plist_id;
00073   htri_t  _groupexist;
00074 
00075   /*
00076    *  nombre de maillages
00077    */
00078 
00079   ret=_MEDnObjects(fid,MED_MAA,&_n);
00080   MED_ERR_EXIT_IF( ( ret == (MED_ERR_COUNT + MED_ERR_DATAGROUP)),
00081                      MED_ERR_COUNT,MED_ERR_MESH,MED_MAA);
00082 
00083   /*
00084    * Mise a jour des maillages :
00085    *
00086    */
00087 /*   SSCRUTE(_pathi); */
00088   _groupexist= H5Aexists_by_name( fid, _pathi, MED_COMMENT_NAME, H5P_DEFAULT  );
00089   if (_groupexist > 0) {
00090     MED_ERR_EXIT_IF( _MEDattributeStringRdByName(fid,_pathi,MED_COMMENT_NAME,MED_COMMENT_SIZE,
00091                                                  _description ) < 0 ,
00092                      MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_COMMENT_NAME);
00093     
00094     H5Adelete_by_name( fid, _pathi,MED_COMMENT_NAME, H5P_DEFAULT );
00095     
00096     MED_ERR_EXIT_IF( _MEDattributeStringWrByName(fid,"/",MED_COMMENT_NAME,MED_COMMENT_SIZE,
00097                                                  _description ) < 0 ,
00098                      MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_COMMENT_NAME);
00099   }
00100 
00101   for (_meshit=0;_meshit<_n;++_meshit) {
00102 
00103     /*
00104      * On recupere le nom du maillage
00105      */
00106     MED_ERR_EXIT_IF( _MEDobjectGetName(fid, MED_MAA ,_meshit, _imeshname) < 0 ,
00107                      MED_ERR_ACCESS,MED_ERR_DATAGROUP,_imeshname);
00108 
00109     MAJ_version_num(fid,2,3,6);
00110     _MEDmeshInfoByName236(dummy,fid, _imeshname, &_spacedim, &_meshdim, &_meshtype,
00111                           _description, _dtunit, &_sortingtype, &_nstep,
00112                           &_axistype, _axisname, _axisunit, &_fret);
00113     MED_ERR_EXIT_IF(_fret < 0, MED_ERR_CALL, MED_ERR_API, "MEDmeshInfoByName236");
00114     MAJ_version_num(fid,3,0,8);
00115 
00116     MED_ERR_EXIT_IF( _spacedim > MAX_SPACE_DIM ,
00117                      MED_ERR_INVALID,MED_ERR_PARAMETER,"_spacedim");
00118 
00119     if ( MAJ_236_300_chaine(_imeshname,_fmeshname) ) {
00120 
00121       fprintf(stdout,"  >>> Normalisation du nom de maillage [%s] \n",_imeshname);
00122       /* on accede au maillage */
00123       strcpy(&_pathi[MED_TAILLE_MAA],_imeshname);
00124       strcpy(&_pathf[MED_TAILLE_MAA],_fmeshname);
00125 
00126       ret = H5Gmove(fid, _pathi, _pathf  );
00127       EXIT_IF(ret < 0,"Renommage du maillage en",_fmeshname);
00128       _meshname=_fmeshname;
00129       fprintf(stdout,"  >>> Normalisation du nom du maillage [%s] ... OK ... \n",_fmeshname);
00130     } else {
00131       strcpy(&_pathf[MED_TAILLE_MAA],_meshname);
00132       strcpy(&_pathi[MED_TAILLE_MAA],_meshname);
00133     }
00134     /*     SSCRUTE(_pathf); */
00135     /*     SSCRUTE(_pathi); */
00136 
00137 
00138     /*
00139      * MAJ des attributs sur le datagroup <_meshname>
00140      */
00141     MED_ERR_EXIT_IF( MEDmeshCr(fid, _meshname, _spacedim, _meshdim, _meshtype,
00142                                _description, _dtunit, MED_SORT_DTIT,
00143                                _axistype, _axisname, _axisunit)  < 0,
00144                      MED_ERR_CALL,MED_ERR_API,"MEDmeshCr");
00145 
00146     /*Normalisation des grilles */
00147     if (  _meshtype != MED_UNSTRUCTURED_MESH ) {
00148       MAJ_version_num(fid,2,3,6);
00149       MED_ERR_EXIT_IF( MEDnatureGrilleLire(fid, _meshname, &_gridtype) < 0
00150                        ,MED_ERR_CALL,MED_ERR_API," MEDnatureGrilleLire");
00151 
00152 /*       strcpy(&_pathgridf[MED_TAILLE_MAA],_meshname); */
00153       strcpy(&_pathgridi[MED_TAILLE_MAA],_meshname);
00154 /*       strcat(_pathgridf,"/-0000000000000000001-0000000000000000001/NOE/"); */
00155       strcat(_pathgridi,"/NOE/");
00156       _gitmplen=strlen(_pathgridi);
00157 /*       _gftmplen=strlen(_pathgridf); */
00158 
00159       if ( (_gridtype == MED_GRILLE_CARTESIENNE) || (_gridtype == MED_GRILLE_POLAIRE) ) {
00160 
00161         strcpy(&_pathgridi[_gitmplen],"IN1");
00162 /*      SSCRUTE(_pathgridi); */
00163         H5Adelete_by_name( fid, _pathgridi,MED_NOM_UNI, H5P_DEFAULT  );
00164         H5Adelete_by_name( fid, _pathgridi,MED_NOM_NOM, H5P_DEFAULT  );
00165         strcpy(&_pathgridi[_gitmplen],"IN2");
00166 /*      SSCRUTE(_pathgridi); */
00167         H5Adelete_by_name( fid, _pathgridi,MED_NOM_UNI, H5P_DEFAULT  );
00168         H5Adelete_by_name( fid, _pathgridi,MED_NOM_NOM, H5P_DEFAULT  );
00169         strcpy(&_pathgridi[_gitmplen],"IN3");
00170 /*      SSCRUTE(_pathgridi); */
00171         H5Adelete_by_name( fid, _pathgridi,MED_NOM_UNI, H5P_DEFAULT  );
00172         H5Adelete_by_name( fid, _pathgridi,MED_NOM_NOM, H5P_DEFAULT  );
00173 
00174         MAJ_version_num(fid,3,0,8);
00175 
00176       } else {
00177         MED_ERR_EXIT_IF( MEDstructureCoordLire(fid,_meshname,_meshdim,_gridstruct) < 0
00178                          ,MED_ERR_CALL,MED_ERR_API,"MEDstructureCoordLire");
00179         strcpy(&_pathgridi[_gitmplen],"COO");
00180         H5Adelete_by_name( fid, _pathgridi,MED_NOM_IN1, H5P_DEFAULT  );
00181         H5Adelete_by_name( fid, _pathgridi,MED_NOM_IN2, H5P_DEFAULT  );
00182         H5Adelete_by_name( fid, _pathgridi,MED_NOM_IN3, H5P_DEFAULT  );
00183 
00184         MAJ_version_num(fid,3,0,8);
00185 
00186         _mustwrite_gridstruct= MED_TRUE;
00187 
00188       }
00189     }
00190 
00191     /*     SSCRUTE(_meshname); */
00192     MED_ERR_EXIT_IF( MEDmeshComputationStepCr(fid,_meshname,MED_NO_DT,MED_NO_IT,
00193                                               MED_NO_DT,MED_NO_IT,0) < 0
00194                      ,MED_ERR_CALL,MED_ERR_API,"MEDmeshComputationStepCr");
00195     _ftmplen=strlen(_pathf);
00196     _pathf[_ftmplen]='/'; ++_ftmplen;
00197     _MEDgetComputationStepName(MED_SORT_DTIT,MED_NO_DT,MED_NO_IT,&_pathf[_ftmplen]);
00198     _ftmplen+=2*MED_MAX_PARA;
00199     
00200 
00201     /*     SSCRUTE(_pathf); */
00202     /*     H5Fflush(fid, H5F_SCOPE_GLOBAL  ); */
00203     /*     _MEDobjetsOuverts(fid); */
00204 
00205     /*
00206      * MAJ de l'attribut MED_NOM_CGT sur le datagroup d'étape de calcul
00207      */
00208     /* Le modify ne fonctionne pas dans _MEDattributeNumWrByName à cause hdf5 ? */
00209     H5Adelete_by_name( fid, _pathf,MED_NOM_CGT, H5P_DEFAULT  );
00210     MED_ERR_EXIT_IF( _MEDattributeNumWrByName(fid,_pathf,MED_NOM_CGT,MED_INTERNAL_INT,
00211                                               (const unsigned char * const) &_1 ) < 0,
00212                      MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_CGT);
00213 
00214     _pathf[_ftmplen]='/';
00215     ++_ftmplen;
00216     _pathf[_ftmplen]='\0';
00217 
00218     strcat(_pathi,"/");
00219     _itmplen=strlen(_pathi);
00220 
00221     /*     SSCRUTE(_pathi); */
00222     /*     SSCRUTE(_pathf); */
00223 
00224     /* Normalisation des familles */
00225     strcpy(&_pathi[_itmplen-1],MED_FAS);
00226 /*     SSCRUTE(_pathi); */
00227     MED_ERR_EXIT_IF( _MEDdatagroupExist(fid,_pathi,&_datagroupexist,&_isasoftlink) < 0 ,
00228                      MED_ERR_CALL,MED_ERR_API,"_MEDdatagroupExist");
00229 
00230     fprintf(stdout,"  >>> Normalisation des familles du maillage [%s] \n",_imeshname);
00231 
00232     _datagroup = _MEDdatagroupCreer(fid,_pathfam);
00233     MED_ERR_EXIT_IF(_datagroup < 0 ,MED_ERR_CREATE,MED_ERR_DATAGROUP,_pathfam);
00234     if (_datagroup>0) {
00235       _ret= _MEDdatagroupFermer(_datagroup);
00236       MED_ERR_EXIT_IF(_ret < 0,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathfam);
00237     }
00238 
00239     strcpy(&_pathfam[MED_TAILLE_FAS],_meshname);strcat(_pathfam,"/");
00240 
00241     if( _datagroupexist) {
00242 
00243       _ocp_plist_id = H5Pcreate( H5P_OBJECT_COPY );
00244       _lcp_plist_id = H5Pcreate( H5P_LINK_CREATE );
00245 
00246       ret =  H5Ocopy(fid,_pathi,fid,_pathfam,_ocp_plist_id,_lcp_plist_id);
00247       EXIT_IF(ret < 0,"Copie des familles dans ","/");
00248 
00249       MED_ERR_EXIT_IF ( _MEDvisit(fid,_pathi,_pathfam,(medvisitorfunc) _MEDconvertStringDatasets ) < 0,
00250                         MED_ERR_VISIT,MED_ERR_DATAGROUP,_pathfam);
00251       MED_ERR_EXIT_IF ( H5Ldelete(fid,_pathi,H5P_DEFAULT) < 0, MED_ERR_DELETE,MED_ERR_LINK,_pathi);
00252 
00253     }
00254 
00255     strcat(_pathfam,"FAMILLE_ZERO");
00256     MED_ERR_EXIT_IF( _MEDdatagroupExist(fid,_pathfam,&_datagroupexist,&_isasoftlink) < 0 ,
00257                      MED_ERR_CALL,MED_ERR_API,"_MEDdatagroupExist");
00258 
00259     if( !_datagroupexist) {
00260       MED_ERR_EXIT_IF ( (MEDfamilyCr(fid,_meshname,FAMILLE_ZERO, 0, 0, "") < 0),
00261                         MED_ERR_CREATE,MED_ERR_FAMILY,"MEDfamilyCr");
00262     }
00263 
00264     /* Normalisation des equivalences */
00265     strcpy(&_pathi[_itmplen-1],MED_EQS);
00266 
00267     MED_ERR_EXIT_IF( MAJ_236_300_equivalence(fid,_meshname) < 0,
00268                      MED_ERR_CALL,MED_ERR_API,"MAJ_236_300_equivalence");
00269     _groupexist=H5Lexists(fid, _pathi, H5P_DEFAULT  );
00270     if (_groupexist) {
00271       MED_ERR_EXIT_IF( H5Ldelete(fid,_pathi,H5P_DEFAULT) < 0,
00272                        MED_ERR_DELETE,MED_ERR_LINK,_pathi);
00273     }
00274 
00275     /* Normalisation des joint */
00276     strcpy(&_pathi[_itmplen-1],MED_JNT);
00277 
00278     MED_ERR_EXIT_IF( MAJ_236_300_joint(fid,_meshname) < 0,
00279                      MED_ERR_CALL,MED_ERR_API,"MAJ_236_300_joint");
00280     _groupexist=H5Lexists(fid, _pathi, H5P_DEFAULT  );
00281     if (_groupexist) {
00282       MED_ERR_EXIT_IF( H5Ldelete(fid,_pathi,H5P_DEFAULT) < 0,
00283                        MED_ERR_DELETE,MED_ERR_JOINT,_pathi);
00284     }
00285 
00286     _pathi[_itmplen]='\0';
00287 /*     SSCRUTE(_pathi); */
00288 
00289     /*Normalisation des entités*/
00290     fprintf(stdout,"  >>> Normalisation des entites [%s] du maillage [%s] \n",
00291             MED_GET_ENTITY_TYPENAME[MED_NODE+1],_meshname);
00292     MED_ERR_EXIT_IF( MAJ_236_300_entites( fid,_pathi, _pathf,_meshname, MED_NODE) < 0 ,
00293                      MED_ERR_CALL,MED_ERR_API,"MAJ_236_300_entites");
00294 
00295     /*On ne peut écrire la structure de la grille qu'une fois le datagroup NOE déplacé*/
00296     if (_mustwrite_gridstruct) {
00297       MED_ERR_EXIT_IF( MEDmeshGridStructWr(fid,_meshname,MED_NO_DT,MED_NO_IT, MED_UNDEF_DT, _gridstruct ) < 0
00298                        ,MED_ERR_CALL,MED_ERR_API,"MEDmeshGridStructWr");
00299       _mustwrite_gridstruct = MED_FALSE;
00300     }
00301 
00302     /*On annule les modifications de _pathi et _pathf effectuées dans MAJ_236_300_entites */
00303     _pathf[_ftmplen]='\0';
00304     _pathi[_itmplen]='\0';
00305 
00306     fprintf(stdout,"  >>> Normalisation des entites [%s] du maillage [%s] \n",
00307             MED_GET_ENTITY_TYPENAME[MED_CELL+1],_meshname);
00308     MED_ERR_EXIT_IF( MAJ_236_300_entites( fid,_pathi, _pathf,_meshname, MED_CELL) < 0,
00309                      MED_ERR_CALL,MED_ERR_API,"MAJ_236_300_entites");
00310 
00311     _pathf[_ftmplen]='\0';
00312     _pathi[_itmplen]='\0';
00313 
00314     fprintf(stdout,"  >>> Normalisation des entites [%s] du maillage [%s] \n",
00315             MED_GET_ENTITY_TYPENAME[MED_DESCENDING_FACE+1],_meshname);
00316     MED_ERR_EXIT_IF( MAJ_236_300_entites( fid,_pathi, _pathf,_meshname, MED_DESCENDING_FACE) < 0,
00317                      MED_ERR_CALL,MED_ERR_API,"MAJ_236_300_entites");
00318     _pathf[_ftmplen]='\0';
00319     _pathi[_itmplen]='\0';
00320 
00321     fprintf(stdout,"  >>> Normalisation des entites [%s] du maillage [%s] \n",
00322             MED_GET_ENTITY_TYPENAME[MED_DESCENDING_EDGE+1],_meshname);
00323     MED_ERR_EXIT_IF( MAJ_236_300_entites( fid,_pathi, _pathf,_meshname, MED_DESCENDING_EDGE) < 0,
00324                      MED_ERR_CALL,MED_ERR_API,"MAJ_236_300_entites");
00325 
00326   }
00327 
00328 /*   _MEDobjetsOuverts(fid); */
00329 
00330 /*   _ret=0; */
00331 /*  ERROR: */
00332 /*   return (int) _ret; */
00333 }

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