MEDstructElementConstAttWithProfileWr.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 
00043 med_err
00044 MEDstructElementConstAttWithProfileWr(const med_idt                  fid,
00045                                       const char*              const modelname,
00046                                       const char*              const constattname,
00047                                       const med_attribute_type       constatttype,
00048                                       const med_int                  ncomponent,
00049                                       const med_entity_type          sentitytype,
00050                                       const char*              const profilename,
00051                                       const void*              const value
00052                                       )
00053 {
00054   med_access_mode   _MED_ACCESS_MODE;
00055   med_err           _ret=-1;
00056   med_idt           _attid=0, _elemid=0, _cstid=0;
00057   char              _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1+MED_TAILLE_CSTATR+MED_NAME_SIZE+1]=MED_STRCT;
00058   char              _supportmeshname[MED_NAME_SIZE+1]="";
00059   med_int           _intentitytype                   = sentitytype;
00060   med_int           _nentity                         = 0;
00061   med_filter        _filter                          = MED_FILTER_INIT;
00062   med_int           _false=0,_true=1,_true_or_false  = _false;
00063   med_bool          _chgt=MED_FALSE,_trsf=MED_FALSE;
00064   med_int           _medintsgeotype                  =MED_NONE;
00065   med_geometry_type _sgeotype                        =MED_NONE;
00066   med_int           _medintconstatttype= (med_int) constatttype;
00067 
00068 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00069 
00070   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00071     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00072     goto ERROR;
00073   }
00074 
00075   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00076     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00077     ISCRUTE_int(_MED_ACCESS_MODE);
00078     goto ERROR;
00079   }
00080 
00081   NOFINALBLANK(modelname,ERROR);
00082   NOFINALBLANK(constattname,ERROR);
00083   NOFINALBLANK(profilename,ERROR);
00084 
00085   strcat(_path,modelname);
00086 
00087   /*
00088    * Si le DataGroup /STRUCT/<modelname> n'existe pas => erreur
00089    */
00090   if ((_elemid = _MEDdatagroupOpen(fid,_path)) < 0)  {
00091     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
00092     goto ERROR;
00093   }
00094 
00095   /*
00096    * Lecture de l'attribut MED_NOM_NOM (nom du maillage support)
00097    */
00098   if ( _MEDattrStringLire(_elemid,MED_NOM_NOM,MED_NAME_SIZE,_supportmeshname) < 0) {
00099     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
00100     SSCRUTE(MED_NOM_NOM);SSCRUTE(_supportmeshname);
00101     goto ERROR;
00102   }
00103 
00104   if (strlen(_supportmeshname) ) {
00105 
00106     if (sentitytype == MED_CELL ) {
00107       /*
00108        * Lecture de l'attribut MED_NOM_GEO (type géométrique des mailles support)
00109        */
00110       if ( _MEDattrEntierLire(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) {
00111         MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
00112         SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype);
00113         goto ERROR;
00114       }
00115 
00116       _sgeotype= (med_geometry_type) _medintsgeotype;
00117     }
00118 
00119     if ( (_nentity = MEDmeshnEntity(fid,_supportmeshname,MED_NO_DT,MED_NO_IT,
00120                                     MED_CELL,_sgeotype,MED_CONNECTIVITY,MED_NODAL,
00121                                     &_chgt,&_trsf) )  < 0) {
00122       MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00123       ISCRUTE(_nentity);goto ERROR;
00124     }
00125 
00126     if (sentitytype == MED_NODE )
00127       if ( (_nentity = MEDmeshnEntity(fid,_supportmeshname,MED_NO_DT,MED_NO_IT,
00128                                       MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
00129                                       &_chgt,&_trsf) )  <= 0) {
00130         MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00131         ISCRUTE(_nentity);goto ERROR;
00132       }
00133   } else
00134     _nentity = 1;
00135 
00136   /*
00137    * Si le DataGroup /STRUCT/<modelname>/CSTATR/ n'existe pas on le crée
00138    */
00139   if ((_cstid = _MEDdatagroupOpen(_elemid,MED_CSTATR_NOM)) < 0)
00140     if ((_cstid = _MEDdatagroupCreer(_elemid,MED_CSTATR_NOM)) < 0) {
00141       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_CSTATR_NOM);
00142       SSCRUTE(_path);goto ERROR;
00143     }
00144   strcat(_path,MED_CSTATR);
00145 
00146   /*
00147    * Si le DataGroup /STRUCT/<modelname>/CSTATR/<constattname> n'existe pas on le crée
00148    */
00149   if ((_attid = _MEDdatagroupOpen(_cstid,constattname)) < 0)
00150     if ((_attid = _MEDdatagroupCreer(_cstid,constattname)) < 0) {
00151       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,constattname);
00152       SSCRUTE(_path);goto ERROR;
00153     }
00154   strcat(_path,constattname);
00155 
00156   /*
00157    * Creation/Ecriture de l'attribut MED_NOM_ATT (type des valeurs de l'attribut.)
00158    */
00159   if ( _MEDattributeIntWr(_attid,MED_NOM_ATT,&_medintconstatttype) < 0 ) {
00160     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00161     SSCRUTE(MED_NOM_ATT);ISCRUTE(_medintconstatttype);
00162     goto ERROR;
00163   }
00164 
00165   /*
00166    * Creation/Ecriture de l'attribut MED_NOM_NCO (nombre de composantes des valeurs de l'attribut.)
00167    */
00168   if ( _MEDattributeIntWr(_attid,MED_NOM_NCO,&ncomponent) < 0 ) {
00169     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00170     SSCRUTE(MED_NOM_NCO);ISCRUTE(ncomponent);
00171     goto ERROR;
00172   }
00173 
00174   /*
00175    * Creation/Ecriture de l'attribut MED_NOM_ENT (type d'entité support concerné par l'attribut)
00176    */
00177   if ( _MEDattributeIntWr(_attid,MED_NOM_ENT,&_intentitytype) < 0 ) {
00178     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00179     SSCRUTE(MED_NOM_ENT);ISCRUTE(_intentitytype);
00180     goto ERROR;
00181   }
00182 
00183   /*
00184    * Creation/Ecriture de l'attribut MED_NOM_PFL (nom de profil sur le maillage support)
00185    */
00186   if ( strlen(profilename) ) {
00187 /*     _profilename=(const char *)profilename; */
00188     _true_or_false=_true;
00189   }
00190 
00191   if ( _MEDattributeIntWr(_cstid,MED_NOM_PFU,&_true_or_false) < 0) {
00192     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_STRUCT_MSG);
00193     SSCRUTE(modelname);;SSCRUTE(MED_NOM_PFU);
00194     goto ERROR;
00195   }
00196 
00197   if ( _MEDattributeStringWr(_attid,MED_NOM_PFL,MED_NAME_SIZE,profilename) < 0) {
00198     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00199     SSCRUTE(MED_NOM_PFL);SSCRUTE(profilename);
00200     goto ERROR;
00201   }
00202 
00203   if ( MEDfilterEntityCr(fid, _nentity, 1, ncomponent, MED_ALL_CONSTITUENT,
00204                          MED_FULL_INTERLACE,MED_COMPACT_PFLMODE,
00205                          profilename, 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(_attid,MED_NOM_COR,constatttype,&_filter, value) < 0) {
00211     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
00212     SSCRUTE(_path);
00213     goto ERROR;
00214   }
00215 
00216   if ( MEDfilterClose(&_filter) < 0 ) {
00217     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_STRUCT_ELEMENT_MSG);
00218     SSCRUTE(_path);
00219     goto ERROR;
00220   }
00221 
00222   /* ??? */
00223 /*   if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) { */
00224 /*     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATASET,MED_NOM_COR); */
00225 /*     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2); */
00226 /*     goto ERROR; */
00227 /*   } */
00228 
00229 /*   if ( _MEDattributeIntWr(_dataset,MED_NOM_NBR,&nentity) < 0) { */
00230 /*     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG); */
00231 /*     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2); */
00232 /*     SSCRUTE(MED_NOM_NBR);ISCRUTE(nentity);goto ERROR; */
00233 /*   } */
00234   /* ??? */
00235 
00236 
00237   _ret=0;
00238  ERROR:
00239 
00240   if (_attid>0)            if (_MEDdatagroupFermer(_attid) < 0) {
00241     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00242     ISCRUTE_id(_attid);
00243   }
00244 
00245   if (_cstid>0)            if (_MEDdatagroupFermer(_cstid) < 0) {
00246     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_CSTATR_NOM);
00247     ISCRUTE_id(_cstid);
00248   }
00249 
00250   if (_elemid>0)            if (_MEDdatagroupFermer(_elemid) < 0) {
00251     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,modelname);
00252     ISCRUTE_id(_elemid);
00253   }
00254 
00255   return _ret;
00256 }

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