MEDmeshGridIndexCoordinateWr.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.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   if ((_gridtype != MED_CARTESIAN_GRID) && (_gridtype != MED_POLAR_GRID)) {
00102     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00103     SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00104   }
00105 
00106  /* Lecture de l'attribut MED_NOM_REP */
00107   if ( _MEDattrEntierLire(_meshid,MED_NOM_REP,&_intaxistype) < 0) {
00108     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00109     SSCRUTE(meshname);SSCRUTE(MED_NOM_REP);
00110     ISCRUTE(_intaxistype);goto ERROR;
00111   }
00112 
00113   if ((med_mesh_type)( _intaxistype) != MED_CARTESIAN ) {
00114     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_AXISTYPE,MED_ERR_MESH_MSG);
00115     SSCRUTE(meshname);ISCRUTE(_intaxistype);goto ERROR;
00116   }
00117 
00118   /* Lecture de l'attribut MED_NOM_DIM  */
00119   if (_MEDattrEntierLire(_meshid,MED_NOM_DIM,&_meshdim) < 0) {
00120     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00121     SSCRUTE(meshname);SSCRUTE(MED_NOM_DIM);ISCRUTE(_meshdim);goto ERROR;
00122   }
00123 
00124   if (axis > _meshdim ) {
00125     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00126     SSCRUTE(meshname);ISCRUTE(_meshdim);ISCRUTE(axis);goto ERROR;
00127   }
00128 
00129   if ( (_datagroup1 =_MEDmeshAssociatedGroupCr(fid, MED_MAA,
00130                                                meshname, numdt, numit, dt, MED_FALSE,
00131                                                "." ) ) < 0 ) {
00132     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr");
00133     goto ERROR;
00134   }
00135 
00136   if ((_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,MED_NOM_MAI)) < 0) {
00137 
00138     if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) {
00139       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NOM_MAI);
00140       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00141       goto ERROR;
00142     }
00143 
00144     if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_0) < 0) {
00145       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00146       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
00147       goto ERROR;
00148     }
00149 
00150     switch ( _meshdim )  {
00151     case 1 : 
00152       strcpy(_geotypename,MED_NOM_SE2);
00153       _medintgeotype = MED_SEG2;
00154       break;
00155     case 2 : 
00156       strcpy(_geotypename,MED_NOM_QU4);
00157       _medintgeotype = MED_QUAD4;
00158       break;
00159     case 3 : 
00160       strcpy(_geotypename,MED_NOM_HE8);
00161       _medintgeotype = MED_HEXA8;
00162       break;
00163     case 0 : strcpy(_geotypename,MED_NOM_PO1);
00164       _medintgeotype = MED_POINT1;
00165       break;
00166     default :
00167       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
00168       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00169       goto ERROR;
00170     }
00171 
00172     if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) {
00173       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename);
00174       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00175       goto ERROR;
00176     }
00177 
00178     if ( _MEDattributeStringWr(_datagroup3,MED_NOM_PFL,MED_NAME_SIZE,MED_NO_PROFILE_INTERNAL) < 0) {
00179       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00180       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);
00181       goto ERROR;
00182     }
00183 
00184     if (_MEDattributeIntWr(_datagroup3,MED_NOM_GEO,&_medintgeotype) < 0) {
00185       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
00186       ISCRUTE(_medintgeotype);
00187       goto ERROR;
00188     }
00189 
00190     if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGT,&_0) < 0) {
00191       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00192       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
00193       goto ERROR;
00194     }
00195 
00196     if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGS,&_0) < 0) {
00197       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00198       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGS);
00199       goto ERROR;
00200     }
00201 
00202   }
00203 
00204 
00205   /*
00206    * On ecrit le tableau d'indice dans un dataset HDF
00207    */
00208   switch(axis)
00209     {
00210     case 1 :
00211       _datatype    = MED_COORDINATE_AXIS1;
00212       _profilename[0] = '\0';
00213       break;
00214     case 2 :
00215       _datatype = MED_COORDINATE_AXIS2;
00216       break;
00217     case 3 :
00218       _datatype = MED_COORDINATE_AXIS3;
00219       break;
00220     default :
00221       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00222       SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00223     }
00224 
00225   if (_MEDmeshAdvancedWr(fid,
00226                          meshname,
00227                          _datatype,
00228                          MED_NO_NAME,
00229                          MED_INTERNAL_UNDEF,
00230                          numdt,
00231                          numit,
00232                          dt,
00233                          MED_NODE,
00234                          MED_NONE,
00235                          MED_NO_CMODE,
00236                          MED_UNDEF_PFLMODE,
00237                          _profilename,
00238                          MED_FULL_INTERLACE,
00239                          MED_ALL_CONSTITUENT,
00240                          NULL,
00241                          indexsize,
00242                          gridindex) < 0 ) {
00243     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAdvancedWr");
00244     goto ERROR;
00245   }
00246 
00247   _ret = 0;
00248 
00249  ERROR:
00250 
00251   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
00252     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename);
00253     ISCRUTE_id(_datagroup3);
00254   }
00255 
00256   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
00257     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI);
00258     ISCRUTE_id(_datagroup2);
00259   }
00260 
00261   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
00262     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
00263     ISCRUTE_id(_datagroup1);
00264   }
00265 
00266   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
00267     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
00268     ISCRUTE_id(_meshid);
00269   }
00270 
00271   return _ret;
00272 
00273 }

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