# MEDinterpBaseFunctionWr.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2011  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 MEDinterpBaseFunctionWr( const med_idt          fid,
    00042                          const char*      const interpname,
    00043                          const med_int          basisfuncit,
    00044                          const med_int          nbofcoef,
    00045                          const med_int*   const power,
    00046                          const med_float* const coefficient)
    00047 {
    00048  med_access_mode   _MED_ACCESS_MODE;
    00049  med_idt           _root=0,_interpid=0,_bid=0;
    00050   med_int           _ret=-1;
    00051   char              _path[MED_TAILLE_INTERP+MED_NAME_SIZE+1]=MED_INTERP;
    00052   char              _basisfuncname[MED_MAX_PARA+1]="";
    00053   med_int           _nbofvariable  =0;
    00054   med_filter        _filter        = MED_FILTER_INIT;
    00055
    00056   /*
    00057    * On inhibe le gestionnaire d'erreur
    00058    */
    00059   _MEDmodeErreurVerrouiller();
    00060  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00061
    00062   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00063     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00064     goto ERROR;
    00065   }
    00066
    00067   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00068     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00069     ISCRUTE_int(_MED_ACCESS_MODE);
    00070     goto ERROR;
    00071   }
    00072
    00073   if (basisfuncit < 1 ) {
    00074     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
    00075     ISCRUTE(basisfuncit);
    00076     goto ERROR;
    00077   }
    00078
    00079   NOFINALBLANK(interpname,ERROR);
    00080   strcat(_path,interpname);
    00081   /*
    00082    * Ouverture du  DataGroup /INTERP/<interpname>
    00083    */
    00084   if ((_interpid = _MEDdatagroupOpen(fid,_path)) < 0) {
    00085     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,interpname);
    00086     SSCRUTE(_path);goto ERROR;
    00087   }
    00088
    00089   /*
    00090    * Lecture de l'attribut MED_NOM_NBV
    00091    */
    00092   if ( _MEDattrEntierLire(_interpid,MED_NOM_NBV,&_nbofvariable) < 0 ) {
    00093     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
    00094     SSCRUTE(MED_NOM_NBV);ISCRUTE(_nbofvariable);
    00095     goto ERROR;
    00096   }
    00097
    00098
    00099   sprintf(_basisfuncname,"%0*li",MED_MAX_PARA,(long ) basisfuncit);
    00100   /*
    00101    * Si le DataGroup /INTERP/<interpname>/<basisfuncit> n'existe pas, on le cree
    00102    */
    00103   if ((_bid = _MEDdatagroupOpen(_interpid,_basisfuncname)) < 0)
    00104     if ((_bid = _MEDdatagroupCreer(_interpid,_basisfuncname)) < 0) {
    00105       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);SSCRUTE(_basisfuncname);
    00106       goto ERROR;
    00107     }
    00108
    00109   /*
    00110    * Creation/Ecriture de l'attribut MED_NOM_MCF
    00111    */
    00112   if ( _MEDattributeIntWr(_bid,MED_NOM_MCF,&nbofcoef) < 0 ) {
    00113     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);SSCRUTE(_basisfuncname);
    00114     SSCRUTE(MED_NOM_MCF);ISCRUTE(nbofcoef);
    00115     goto ERROR;
    00116   }
    00117
    00118   /*TODO : Créer un _MEDdatasetSimpleWr */
    00119   if ( MEDfilterEntityCr(fid, nbofcoef, 1, 1, MED_ALL_CONSTITUENT,
    00120                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00121                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00122     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00123     goto ERROR;
    00124   }
    00125
    00126   if ( _MEDdatasetWr(_bid,MED_NOM_COE,MED_INTERNAL_FLOAT64,&_filter, coefficient) < 0) {
    00127     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COE);
    00128     SSCRUTE(_path);SSCRUTE(_basisfuncname);
    00129     goto ERROR;
    00130   }
    00131
    00132   if ( MEDfilterClose(&_filter) < 0 ) {
    00133     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_STRUCT_ELEMENT_MSG);
    00134     SSCRUTE(_path);
    00135     goto ERROR;
    00136   }
    00137
    00138
    00139   if ( MEDfilterEntityCr(fid, nbofcoef*_nbofvariable, 1, 1, MED_ALL_CONSTITUENT,
    00140                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00141                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00142     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00143     goto ERROR;
    00144   }
    00145
    00146   if ( _MEDdatasetWr(_bid,MED_NOM_POW,MED_INTERNAL_INT,&_filter, power) < 0) {
    00147     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_POW);
    00148     SSCRUTE(_path);SSCRUTE(_basisfuncname);
    00149     goto ERROR;
    00150   }
    00151
    00152   if ( MEDfilterClose(&_filter) < 0 ) {
    00153     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_STRUCT_ELEMENT_MSG);
    00154     SSCRUTE(_path);
    00155     goto ERROR;
    00156   }
    00157
    00158
    00159   _ret=0;
    00160  ERROR:
    00161
    00162   if (_interpid>0)            if (_MEDdatagroupFermer(_interpid) < 0) {
    00163     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
    00164     ISCRUTE_id(_interpid);
    00165   }
    00166
    00167   if (_bid>0)            if (_MEDdatagroupFermer(_bid) < 0) {
    00168     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_basisfuncname);
    00169     ISCRUTE_id(_bid);SSCRUTE(_path);
    00170   }
    00171
    00172   return _ret;
    00173 }