MEDmeshGridIndexCoordinateWr.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.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 #include <string.h>
00023 #include <stdlib.h>
00024 
00042 med_err
00043 MEDmeshGridIndexCoordinateWr(const med_idt               fid,
00044                              const char*  const          meshname,
00045                              const med_int               numdt,
00046                              const med_int               numit,
00047                              const med_float             dt,
00048                              const med_int               axis,
00049                              const med_int               indexsize,
00050                              const med_float * const     gridindex)
00051 {
00052   med_access_mode _MED_ACCESS_MODE;
00053   med_idt         _meshid=0;
00054   med_idt         _datagroup1=0,_datagroup2=0,_datagroup3=0;
00055   med_err         _ret         = -1;
00056   med_data_type   _datatype    = MED_UNDEF_DATATYPE;
00057   med_grid_type   _gridtype    = MED_UNDEF_GRID_TYPE;
00058   med_int         _intgridtype = 0;
00059   med_int         _intaxistype = 0;
00060   med_int         _meshdim     = 0;
00061   char            _meshpath[MED_TAILLE_MAA+MED_NAME_SIZE+1]=MED_MAA;
00062   char            _geotypename[MED_TAILLE_NOM_ENTITE+1]="";
00063   med_int         _0=0;
00064   med_int         _medintgeotype = MED_NO_GEOTYPE;
00065   char            _profilename      [MED_NAME_SIZE+1]=MED_SAME_PROFILE_INTERNAL;
00066   
00067 
00068   /*
00069    * On inhibe le gestionnaire d'erreur HDF 5
00070    */
00071   _MEDmodeErreurVerrouiller();
00072  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00073 
00074   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00075     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00076     goto ERROR;
00077   }
00078 
00079   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00080     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00081     ISCRUTE_int(_MED_ACCESS_MODE);
00082     goto ERROR;
00083   }
00084 
00085   strcat(_meshpath,meshname);
00086   if ((_meshid = _MEDdatagroupOuvrir(fid,_meshpath)) < 0) {
00087     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
00088     SSCRUTE(meshname);SSCRUTE(_meshpath); goto ERROR;
00089   }
00090 
00091 
00092   /*
00093    * Lecture du type de grille (attribut MED_NOM_GTY)
00094    */
00095   if (_MEDattrEntierLire(_meshid,MED_NOM_GTY,&_intgridtype) < 0) {
00096     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00097     SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;
00098   }
00099   _gridtype=(med_grid_type) _intgridtype;
00100 
00101   /*
00102    * Les grilles MED_CURVILINEAR ne sont pas définies en utilisant 
00103    * cette fonction, elles doivent définir leurs coordonnées des noeuds
00104    * comme pour les maillages non structurés.
00105    */
00106   if ((_gridtype != MED_CARTESIAN_GRID) && (_gridtype != MED_POLAR_GRID)) {
00107     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00108     SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00109   }
00110 
00111  /* Lecture de l'attribut MED_NOM_REP */
00112   if ( _MEDattrEntierLire(_meshid,MED_NOM_REP,&_intaxistype) < 0) {
00113     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00114     SSCRUTE(meshname);SSCRUTE(MED_NOM_REP);
00115     ISCRUTE(_intaxistype);goto ERROR;
00116   }
00117 
00118 
00119   /* Lecture de l'attribut MED_NOM_DIM  */
00120   if (_MEDattrEntierLire(_meshid,MED_NOM_DIM,&_meshdim) < 0) {
00121     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00122     SSCRUTE(meshname);SSCRUTE(MED_NOM_DIM);ISCRUTE(_meshdim);goto ERROR;
00123   }
00124 
00125   if (axis > _meshdim ) {
00126     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00127     SSCRUTE(meshname);ISCRUTE(_meshdim);ISCRUTE(axis);goto ERROR;
00128   }
00129 
00130   if ( (_datagroup1 =_MEDmeshAssociatedGroupCr(fid, MED_MAA,
00131                                                meshname, numdt, numit, dt, MED_FALSE,
00132                                                "." ) ) < 0 ) {
00133     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr");
00134     goto ERROR;
00135   }
00136 
00137   if ((_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,MED_NOM_MAI)) < 0) {
00138 
00139     if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) {
00140       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NOM_MAI);
00141       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00142       goto ERROR;
00143     }
00144 
00145     if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_0) < 0) {
00146       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00147       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
00148       goto ERROR;
00149     }
00150 
00151     /* 
00152        Le type géométrique de maille utilisé pour les grilles est fonction
00153        de la dimension de la grille == nombre d'axes 
00154     */
00155     switch ( _meshdim )  {
00156     case 1 : 
00157       strcpy(_geotypename,MED_NOM_SE2);
00158       _medintgeotype = MED_SEG2;
00159       break;
00160     case 2 : 
00161       strcpy(_geotypename,MED_NOM_QU4);
00162       _medintgeotype = MED_QUAD4;
00163       break;
00164     case 3 : 
00165       strcpy(_geotypename,MED_NOM_HE8);
00166       _medintgeotype = MED_HEXA8;
00167       break;
00168     case 0 : strcpy(_geotypename,MED_NOM_PO1);
00169       _medintgeotype = MED_POINT1;
00170       break;
00171     default :
00172       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
00173       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00174       goto ERROR;
00175     }
00176 
00177     if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) {
00178       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename);
00179       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00180       goto ERROR;
00181     }
00182 
00183     if ( _MEDattributeStringWr(_datagroup3,MED_NOM_PFL,MED_NAME_SIZE,MED_NO_PROFILE_INTERNAL) < 0) {
00184       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00185       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);
00186       goto ERROR;
00187     }
00188 
00189     if (_MEDattributeIntWr(_datagroup3,MED_NOM_GEO,&_medintgeotype) < 0) {
00190       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
00191       ISCRUTE(_medintgeotype);
00192       goto ERROR;
00193     }
00194 
00195     if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGT,&_0) < 0) {
00196       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00197       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
00198       goto ERROR;
00199     }
00200 
00201     if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGS,&_0) < 0) {
00202       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00203       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGS);
00204       goto ERROR;
00205     }
00206 
00207   }
00208 
00209 
00210   /*
00211    * On ecrit le tableau d'indice dans un dataset HDF
00212    */
00213   switch(axis)
00214     {
00215     case 1 :
00216       _datatype    = MED_COORDINATE_AXIS1;
00217       _profilename[0] = '\0';
00218       break;
00219     case 2 :
00220       _datatype = MED_COORDINATE_AXIS2;
00221       break;
00222     case 3 :
00223       _datatype = MED_COORDINATE_AXIS3;
00224       break;
00225     default :
00226       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00227       SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00228     }
00229 
00230   if (_MEDmeshAdvancedWr(fid,
00231                          meshname,
00232                          _datatype,
00233                          MED_NO_NAME,
00234                          MED_INTERNAL_UNDEF,
00235                          numdt,
00236                          numit,
00237                          dt,
00238                          MED_NODE,
00239                          MED_NONE,
00240                          MED_NO_CMODE,
00241                          MED_UNDEF_PFLMODE,
00242                          _profilename,
00243                          MED_FULL_INTERLACE,
00244                          MED_ALL_CONSTITUENT,
00245                          NULL,
00246                          indexsize,
00247                          gridindex) < 0 ) {
00248     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAdvancedWr");
00249     goto ERROR;
00250   }
00251 
00252   _ret = 0;
00253 
00254  ERROR:
00255 
00256   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
00257     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename);
00258     ISCRUTE_id(_datagroup3);
00259   }
00260 
00261   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
00262     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI);
00263     ISCRUTE_id(_datagroup2);
00264   }
00265 
00266   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
00267     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
00268     ISCRUTE_id(_datagroup1);
00269   }
00270 
00271   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
00272     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
00273     ISCRUTE_id(_meshid);
00274   }
00275 
00276   return _ret;
00277 
00278 }

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