MEDmeshGridIndexCoordinateWr.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2012  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   
00066 
00067   /*
00068    * On inhibe le gestionnaire d'erreur HDF 5
00069    */
00070   _MEDmodeErreurVerrouiller();
00071  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00072 
00073   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00074     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00075     goto ERROR;
00076   }
00077 
00078   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00079     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00080     ISCRUTE_int(_MED_ACCESS_MODE);
00081     goto ERROR;
00082   }
00083 
00084   strcat(_meshpath,meshname);
00085   if ((_meshid = _MEDdatagroupOuvrir(fid,_meshpath)) < 0) {
00086     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
00087     SSCRUTE(meshname);SSCRUTE(_meshpath); goto ERROR;
00088   }
00089 
00090 
00091   /*
00092    * Lecture du type de grille (attribut MED_NOM_GTY)
00093    */
00094   if (_MEDattrEntierLire(_meshid,MED_NOM_GTY,&_intgridtype) < 0) {
00095     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00096     SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;
00097   }
00098   _gridtype=(med_grid_type) _intgridtype;
00099 
00100   if ((_gridtype != MED_CARTESIAN_GRID) && (_gridtype != MED_POLAR_GRID)) {
00101     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00102     SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00103   }
00104 
00105  /* Lecture de l'attribut MED_NOM_REP */
00106   if ( _MEDattrEntierLire(_meshid,MED_NOM_REP,&_intaxistype) < 0) {
00107     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00108     SSCRUTE(meshname);SSCRUTE(MED_NOM_REP);
00109     ISCRUTE(_intaxistype);goto ERROR;
00110   }
00111 
00112   if ((med_mesh_type)( _intaxistype) != MED_CARTESIAN ) {
00113     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_AXISTYPE,MED_ERR_MESH_MSG);
00114     SSCRUTE(meshname);ISCRUTE(_intaxistype);goto ERROR;
00115   }
00116 
00117   /* Lecture de l'attribut MED_NOM_DIM  */
00118   if (_MEDattrEntierLire(_meshid,MED_NOM_DIM,&_meshdim) < 0) {
00119     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00120     SSCRUTE(meshname);SSCRUTE(MED_NOM_DIM);ISCRUTE(_meshdim);goto ERROR;
00121   }
00122 
00123   if (axis > _meshdim ) {
00124     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00125     SSCRUTE(meshname);ISCRUTE(_meshdim);ISCRUTE(axis);goto ERROR;
00126   }
00127 
00128   if ( (_datagroup1 =_MEDmeshAssociatedGroupCr(fid, MED_MAA,
00129                                                meshname, numdt, numit, dt, MED_FALSE,
00130                                                "." ) ) < 0 ) {
00131     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr");
00132     goto ERROR;
00133   }
00134 
00135   if ((_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,MED_NOM_MAI)) < 0) {
00136 
00137     if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) {
00138       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NOM_MAI);
00139       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00140       goto ERROR;
00141     }
00142 
00143     if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_0) < 0) {
00144       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00145       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
00146       goto ERROR;
00147     }
00148 
00149     switch ( _meshdim )  {
00150     case 1 : 
00151       strcpy(_geotypename,MED_NOM_SE2);
00152       _medintgeotype = MED_SEG2;
00153       break;
00154     case 2 : 
00155       strcpy(_geotypename,MED_NOM_QU4);
00156       _medintgeotype = MED_QUAD4;
00157       break;
00158     case 3 : 
00159       strcpy(_geotypename,MED_NOM_HE8);
00160       _medintgeotype = MED_HEXA8;
00161       break;
00162     case 0 : strcpy(_geotypename,MED_NOM_PO1);
00163       _medintgeotype = MED_POINT1;
00164       break;
00165     default :
00166       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
00167       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00168       goto ERROR;
00169     }
00170 
00171     if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) {
00172       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename);
00173       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
00174       goto ERROR;
00175     }
00176 
00177     if ( _MEDattributeStringWr(_datagroup3,MED_NOM_PFL,MED_NAME_SIZE,MED_NO_PROFILE_INTERNAL) < 0) {
00178       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00179       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);
00180       goto ERROR;
00181     }
00182 
00183     if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGT,&_0) < 0) {
00184       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00185       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
00186       goto ERROR;
00187     }
00188 
00189     if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGS,&_0) < 0) {
00190       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00191       SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGS);
00192       goto ERROR;
00193     }
00194 
00195     if (_MEDattributeIntWr(_datagroup3,MED_NOM_GEO,&_medintgeotype) < 0) {
00196       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
00197       ISCRUTE(_medintgeotype);
00198       goto ERROR;
00199     }
00200 
00201   }
00202 
00203 
00204   /*
00205    * On ecrit le tableau d'indice dans un dataset HDF
00206    */
00207   switch(axis)
00208     {
00209     case 1 :
00210       _datatype = MED_COORDINATE_AXIS1;
00211       break;
00212     case 2 :
00213       _datatype = MED_COORDINATE_AXIS2;
00214       break;
00215     case 3 :
00216       _datatype = MED_COORDINATE_AXIS3;
00217       break;
00218     default :
00219       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00220       SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00221     }
00222 
00223   if (_MEDmeshAdvancedWr(fid,
00224                          meshname,
00225                          _datatype,
00226                          MED_NO_NAME,
00227                          MED_INTERNAL_UNDEF,
00228                          numdt,
00229                          numit,
00230                          dt,
00231                          MED_NODE,
00232                          MED_NONE,
00233                          MED_NO_CMODE,
00234                          MED_UNDEF_PFLMODE,
00235                          MED_NO_PROFILE,
00236                          MED_FULL_INTERLACE,
00237                          MED_ALL_CONSTITUENT,
00238                          NULL,
00239                          indexsize,
00240                          gridindex) < 0 ) {
00241     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAdvancedWr");
00242     goto ERROR;
00243   }
00244 
00245   _ret = 0;
00246 
00247  ERROR:
00248 
00249   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
00250     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename);
00251     ISCRUTE_id(_datagroup3);
00252   }
00253 
00254   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
00255     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI);
00256     ISCRUTE_id(_datagroup2);
00257   }
00258 
00259   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
00260     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
00261     ISCRUTE_id(_datagroup1);
00262   }
00263 
00264   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
00265     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
00266     ISCRUTE_id(_meshid);
00267   }
00268 
00269   return _ret;
00270 
00271 }

Généré le Mon Nov 19 15:43:34 2012 pour MED fichier par  doxygen 1.6.1