MEDlocalizationWr.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 
00023 #include <string.h>
00024 #include <stdlib.h>
00025 
00048 med_err
00049 MEDlocalizationWr(const med_idt           fid,
00050                   const char *     const  localizationname,
00051                   const med_geometry_type geotype,
00052                   const med_int           spacedimension,
00053                   const med_float* const  elementcoordinate,
00054                   const med_switch_mode   switchmode,
00055                   const med_int           nipoint,
00056                   const med_float* const  ipointcoordinate,
00057                   const med_float* const  weight,
00058                   const char *     const  geointerpname,
00059                   const char *     const  sectionmeshname
00060                   )
00061 {
00062   med_access_mode _MED_ACCESS_MODE;
00063   med_err _ret = -1;
00064   med_idt _lzid=0, _root=0;
00065   med_int _nentity=0;
00066   med_int _intgeotype = -1;
00067   char    _path[MED_TAILLE_GAUSS+MED_NAME_SIZE+1]=MED_GAUSS;
00068   med_filter     _filter        = MED_FILTER_INIT;
00069 
00070   /*
00071    * On inhibe le gestionnaire d'erreur HDF 5
00072    */
00073   _MEDmodeErreurVerrouiller();
00074  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00075 
00076   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00077     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00078     goto ERROR;
00079   }
00080 
00081   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00082     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00083     ISCRUTE_int(_MED_ACCESS_MODE);
00084     goto ERROR;
00085   }
00086 
00087   /*
00088    * MED_GAUSS_ELNO est un mot cle reserve
00089    */
00090   if (! strcmp(localizationname,MED_GAUSS_ELNO)) {
00091     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_LOCALIZATION,localizationname);
00092     goto ERROR;
00093   }
00094 
00095   /*
00096    * Si le DataGroup /GAUSS/ n'existe pas, on le cree
00097    */
00098   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
00099     if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
00100       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
00101      goto ERROR;
00102     }
00103 
00104   NOFINALBLANK(localizationname,ERROR);
00105   /*
00106    * Si le DataGroup /GAUSS/<localizationname> n'existe pas, on le cree
00107    */
00108   if ((_lzid = _MEDdatagroupOuvrir(_root,localizationname)) < 0)
00109     if ((_lzid = _MEDdatagroupCreer(_root,localizationname)) < 0) {
00110       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,localizationname);
00111       SSCRUTE(_path);goto ERROR;
00112     }
00113 
00114   strcat(_path,localizationname);
00115 
00116 
00117   /*
00118    * On stocke <nipoint> sous forme d'attribut
00119    */
00120   if (_MEDattributeIntWr(_lzid,MED_NOM_NBR,&nipoint) < 0) {
00121     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00122     SSCRUTE(localizationname);SSCRUTE(MED_NOM_NBR);ISCRUTE(nipoint);
00123     goto ERROR;
00124   }
00125 
00126 
00127   /*
00128    * On stocke <typgeo> sous forme d'attribut
00129    */
00130   _intgeotype = (med_int) geotype;
00131   /* sizeof(enum) tjrs = sizeof(int) en C, or
00132      sur machines 64 bits par d�faut med_int==long,
00133      du coup sur  machines 64 bits _MEDattributeIntWr utilise 
00134      le type hdf NATIVE_LONG, ce qui pose un probl�me qd on passe
00135      un enum.
00136   */
00137   if (_MEDattributeIntWr(_lzid,MED_NOM_GEO,&_intgeotype) < 0) {
00138     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00139     SSCRUTE(localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE(_intgeotype);
00140     goto ERROR;
00141   };
00142 
00143   /*
00144    * On stocke <spacedimension> sous forme d'attribut
00145    */
00146   if (_MEDattributeIntWr(_lzid,MED_NOM_DIM,&spacedimension) < 0) {
00147     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00148     SSCRUTE(localizationname);SSCRUTE(MED_NOM_DIM);ISCRUTE(spacedimension);
00149     goto ERROR;
00150   };
00151 
00152 
00153   if ( ! ((geotype > MED_STRUCT_GEO_INTERNAL    ) &&
00154           (geotype < MED_STRUCT_GEO_SUP_INTERNAL)    ) ) {
00155     /*
00156      * On stocke les coordonn�es de r�f�rence dans un dataset
00157      */
00158     _nentity = (geotype%100);
00159 
00160     if ( MEDfilterEntityCr(fid,_nentity, 1, spacedimension, MED_ALL_CONSTITUENT,
00161                            switchmode,MED_UNDEF_PFLMODE,
00162                            MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
00163       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
00164       goto ERROR;
00165     }
00166 
00167     if ( _MEDdatasetWr(_lzid,MED_NOM_COO,MED_INTERNAL_FLOAT64,&_filter, elementcoordinate) < 0) {
00168       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COO);SSCRUTE(_path);
00169       goto ERROR;
00170     }
00171 
00172     if ( MEDfilterClose(&_filter) < 0 ) {
00173       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LOCALIZATION_MSG); SSCRUTE(_path);
00174       goto ERROR;
00175     }
00176   } else {
00177 
00178     /*
00179      * Creation/Ecriture de l'attribut MED_NOM_NOM (nom du maillage de section)
00180      */
00181     if ( _MEDattributeStringWr(_lzid,MED_NOM_NOM,MED_NAME_SIZE,sectionmeshname) < 0) {
00182       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00183       SSCRUTE(localizationname);SSCRUTE(MED_NOM_NOM);SSCRUTE(sectionmeshname);
00184       goto ERROR;
00185     }
00186   }
00187 
00188   /*
00189    * Creation/Ecriture de l'attribut MED_NOM_INM (nom de l'interpolation géométrique)
00190    */
00191   if ( _MEDattributeStringWr(_lzid,MED_NOM_INM,MED_NAME_SIZE,geointerpname) < 0) {
00192     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00193     SSCRUTE(localizationname);SSCRUTE(MED_NOM_INM);SSCRUTE(geointerpname);
00194     goto ERROR;
00195   }
00196 
00197 
00198   /*
00199    * On stocke les points d'int�gration dans un dataset
00200    */
00201 
00202   _nentity = nipoint;
00203   if ( MEDfilterEntityCr(fid,_nentity, 1, spacedimension, MED_ALL_CONSTITUENT,
00204                          switchmode,MED_UNDEF_PFLMODE,
00205                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
00206     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
00207     goto ERROR;
00208   }
00209 
00210   if ( _MEDdatasetWr(_lzid,MED_NOM_GAU,MED_INTERNAL_FLOAT64,&_filter, ipointcoordinate) < 0) {
00211     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_GAU);SSCRUTE(_path);
00212     goto ERROR;
00213   }
00214 
00215   if ( MEDfilterClose(&_filter) < 0 ) {
00216     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LOCALIZATION_MSG); SSCRUTE(_path);
00217     goto ERROR;
00218   }
00219 
00220   /*
00221    * On stocke les poids dans un dataset
00222    */
00223 
00224   _nentity = nipoint;
00225   if ( MEDfilterEntityCr(fid,_nentity, 1, 1, MED_ALL_CONSTITUENT,
00226                          switchmode,MED_UNDEF_PFLMODE,
00227                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
00228     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
00229     goto ERROR;
00230   }
00231 
00232   if ( _MEDdatasetWr(_lzid,MED_NOM_VAL,MED_INTERNAL_FLOAT64,&_filter, weight) < 0) {
00233     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_VAL);SSCRUTE(_path);
00234     goto ERROR;
00235   }
00236 
00237   if ( MEDfilterClose(&_filter) < 0 ) {
00238     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LOCALIZATION_MSG); SSCRUTE(_path);
00239     goto ERROR;
00240   }
00241 
00242 
00243   _ret = 0;
00244 
00245  ERROR:
00246 
00247   if (_lzid>0)            if (_MEDdatagroupFermer(_lzid) < 0) {
00248     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,localizationname);
00249     ISCRUTE_id(_lzid);
00250   }
00251 
00252   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
00253     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_GAUSS);
00254     ISCRUTE_id(_root);
00255   }
00256 
00257   return _ret;
00258 
00259 }
00260 

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