# MEDinterpBaseFunctionRd.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 <hdf5.h>
    00023 #include <string.h>
    00024
    00040 med_err
    00041 MEDinterpBaseFunctionRd( const med_idt          fid,
    00042                          const char*      const interpname,
    00043                          const int              basisfuncit,
    00044                                med_int*         ncoef,
    00045                                med_int*   const power,
    00046                                med_float* const coefficient)
    00047 {
    00048   med_idt           _interpid=0,_bid=0;
    00049   med_err           _ret=-1;
    00050   char              _path[MED_TAILLE_INTERP+MED_NAME_SIZE+1]=MED_INTERP;
    00051   char              _basisfuncname[MED_MAX_PARA+1]="";
    00052   med_int           _nvariable  =0;
    00053   med_filter        _filter        = MED_FILTER_INIT;
    00054
    00055   /*
    00056    * On inhibe le gestionnaire d'erreur
    00057    */
    00058   _MEDmodeErreurVerrouiller();
    00059
    00060   if (basisfuncit < 1 ) {
    00061     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
    00062     ISCRUTE_int(basisfuncit);
    00063     goto ERROR;
    00064   }
    00065
    00066   NOFINALBLANK(interpname,ERROR);
    00067   strcat(_path,interpname);
    00068   /*
    00069    * Ouverture du DataGroup /INTERP/<interpname>
    00070    */
    00071   if ((_interpid = _MEDdatagroupOpen(fid,_path)) < 0) {
    00072     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,interpname);
    00073     SSCRUTE(_path);goto ERROR;
    00074   }
    00075
    00076   /*
    00077    * Lecture de l'attribut MED_NOM_NBV
    00078    */
    00079   if ( _MEDattrEntierLire(_interpid,MED_NOM_NBV,&_nvariable) < 0 ) {
    00080     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
    00081     SSCRUTE(MED_NOM_NBV);ISCRUTE(_nvariable);
    00082     goto ERROR;
    00083   }
    00084
    00085
    00086   sprintf(_basisfuncname,"%0*li",MED_MAX_PARA,(long ) basisfuncit);
    00087   /*
    00088    * Ouverture du DataGroup /INTERP/<interpname>/<basisfuncit>
    00089    */
    00090   if ((_bid = _MEDdatagroupOpen(_interpid,_basisfuncname)) < 0) {
    00091     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);SSCRUTE(_basisfuncname);
    00092     goto ERROR;
    00093   }
    00094
    00095   /*
    00096    * Lecture de l'attribut MED_NOM_MCF
    00097    */
    00098   if ( _MEDattrEntierLire(_bid,MED_NOM_MCF,ncoef) < 0 ) {
    00099     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);SSCRUTE(_basisfuncname);
    00100     SSCRUTE(MED_NOM_MCF);ISCRUTE(*ncoef);
    00101     goto ERROR;
    00102   }
    00103
    00104   /*TODO : Créer un _MEDdatasetSimpleWr */
    00105   if ( MEDfilterEntityCr(fid, *ncoef, 1, 1, MED_ALL_CONSTITUENT,
    00106                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00107                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00108     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00109     goto ERROR;
    00110   }
    00111
    00112   if ( _MEDdatasetRd(_bid,MED_NOM_COE,MED_INTERNAL_FLOAT64,&_filter, (unsigned char * const) coefficient) < 0) {
    00113     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COE);
    00114     SSCRUTE(_path);SSCRUTE(_basisfuncname);
    00115     goto ERROR;
    00116   }
    00117
    00118   if ( MEDfilterClose(&_filter) < 0 ) {
    00119     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_STRUCT_ELEMENT_MSG);
    00120     SSCRUTE(_path);
    00121     goto ERROR;
    00122   }
    00123
    00124
    00125   if ( MEDfilterEntityCr(fid, (*ncoef)*_nvariable, 1, 1, MED_ALL_CONSTITUENT,
    00126                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00127                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00128     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00129     goto ERROR;
    00130   }
    00131
    00132   if ( _MEDdatasetRd(_bid,MED_NOM_POW,MED_INTERNAL_INT,&_filter, (unsigned char * const) power) < 0) {
    00133     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_POW);
    00134     SSCRUTE(_path);SSCRUTE(_basisfuncname);
    00135     goto ERROR;
    00136   }
    00137
    00138   if ( MEDfilterClose(&_filter) < 0 ) {
    00139     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_STRUCT_ELEMENT_MSG);
    00140     SSCRUTE(_path);
    00141     goto ERROR;
    00142   }
    00143
    00144
    00145   _ret=0;
    00146  ERROR:
    00147
    00148   if (_interpid>0)            if (_MEDdatagroupFermer(_interpid) < 0) {
    00149     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
    00150     ISCRUTE_id(_interpid);
    00151   }
    00152
    00153   if (_bid>0)            if (_MEDdatagroupFermer(_bid) < 0) {
    00154     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_basisfuncname);
    00155     ISCRUTE_id(_bid);SSCRUTE(_path);
    00156   }
    00157
    00158   return _ret;
    00159 }