# MAJ_236_300_string_datasets.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_config.h"
    00020 #include "med_outils.h"
    00021 #include <string.h>
    00022
    00023 #include <2.3.6/med23v30.h>
    00024 #include <2.3.6/med23v30_proto.h>
    00025 #include "2.3.6/med23v30_misc.h"
    00026
    00027 #include "MAJ_236_300.h"
    00028
    00029 extern MEDC_EXPORT
    00030 med_err _MEDdatasetStringLire(med_idt pere,char *nom,char *val);
    00031
    00032 int MAJ_236_300_string_datasets(med_idt fid,
    00033                                 const char * const absdatagrouppath,
    00034                                 const char * const datasetname,
    00035                                 int           isubstringsize,
    00036                                 int           fsubstringsize,
    00037                                 int           nsubstring) {
    00038
    00039   med_err     _ret       = -1;
    00040   char *      _itmpbuff  = NULL;
    00041   char *      _ftmpbuff  = NULL;
    00042   med_idt     _datagroup = 0;
    00043   med_filter  _filter    = MED_FILTER_INIT;
    00044   char        _pathi[MED_TAILLE_MAA+MED_NAME_SIZE+1+2*MED_TAILLE_NOM_ENTITE+1+3+1]="";
    00045   int         _itmplen   = 0;
    00046   med_internal_type _medinternaltype=MED_INTERNAL_UNDEF;
    00047
    00048   strcpy(_pathi,absdatagrouppath);
    00049   _itmplen=strlen(_pathi);
    00050
    00051
    00052   /* Ouverture du datagroup */
    00053   if ((_datagroup = _MEDdatagroupOuvrir(fid,_pathi)) < 0) {
    00054     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_pathi);
    00055     goto ERROR;
    00056   }
    00057
    00058   _pathi[_itmplen]='/';
    00059   strcpy(&_pathi[_itmplen+1],datasetname);
    00060
    00061 /*   SSCRUTE(_pathi); */
    00062
    00063
    00064   _itmpbuff = (char *) malloc(nsubstring*sizeof(char)*isubstringsize+1);
    00065
    00066   if ( _MEDdatasetStringLire(_datagroup,(char*)datasetname,_itmpbuff) < 0) {
    00067     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_DATASET,_pathi);
    00068     goto ERROR;
    00069
    00070   };
    00071 /*   SSCRUTE(_itmpbuff); */
    00072
    00073   if ( _MEDselectAllEntitiesNoI(fid, nsubstring, 1, 1,
    00074                                 MED_ALL_CONSTITUENT, &_filter) < 0) {
    00075     MED_ERR_(_ret,MED_ERR_SELECT,MED_ERR_FILTER,MED_ERR_MODE_MSG);
    00076     MESSAGE("MED_NO_INTERLACE, MED_NO_PROFILE, MED_NO_FILTER");
    00077     goto ERROR;
    00078   };
    00079
    00080   if ( isubstringsize != fsubstringsize ) {
    00081     _ftmpbuff = (char *) malloc(nsubstring*sizeof(char)*fsubstringsize+1);
    00082     _MED23v30stringConvert(_ftmpbuff,fsubstringsize,_itmpbuff,isubstringsize,nsubstring);
    00083   } else
    00084     _ftmpbuff  = _itmpbuff;
    00085
    00086
    00087   switch(fsubstringsize)
    00088     {
    00089     case MED_NAME_SIZE:
    00090       _medinternaltype=MED_INTERNAL_NAME;
    00091       break;
    00092     case MED_SNAME_SIZE:
    00093       _medinternaltype=MED_INTERNAL_SNAME;
    00094       break;
    00095     case MED_LNAME_SIZE:
    00096       _medinternaltype=MED_INTERNAL_LNAME;
    00097       break;
    00098     case MED_IDENT_SIZE:
    00099       _medinternaltype=MED_INTERNAL_IDENT;
    00100       break;
    00101     default:
    00102       MED_ERR_EXIT_IF(1,MED_ERR_RANGE,MED_ERR_PARAMETER,"fsubstringsize");
    00103
    00104     }
    00105 /*   SSCRUTE(_ftmpbuff); */
    00106
    00107 /*   if ( H5Ldelete(_datagroup,datasetname,H5P_DEFAULT) < 0 ) { */
    00108 /*     MED_ERR_(_ret,MED_ERR_DELETE,MED_ERR_LINK,datasetname); */
    00109 /*     H5Eprint1(stderr); */
    00110 /*     goto ERROR; */
    00111 /*   } */
    00112
    00113   if ( _MEDdatasetWr(_datagroup,datasetname,_medinternaltype,&_filter,_ftmpbuff) < 0) {
    00114     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,datasetname);
    00115     goto ERROR;
    00116   }
    00117
    00118   MEDfilterClose(&_filter);
    00119
    00120   if (_datagroup>0) {
    00121     if (_MEDdatagroupFermer(_datagroup) < 0) {
    00122       _pathi[_itmplen]='\0';
    00123       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathi);
    00124       goto ERROR;
    00125     } else {
    00126       _datagroup=0;
    00127     }
    00128   }
    00129
    00130   /*
    00131    * Creation/Ecriture de l'attribut MED_NOM_NBR sur le dataset
    00132    */
    00133
    00134   if ( _MEDattributeNumWrByName(fid,_pathi,MED_NOM_NBR,MED_INTERNAL_INT,
    00135                                 (const unsigned char * const) &nsubstring ) < 0 ) {
    00136     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_NBR);
    00137     SSCRUTE(_pathi);
    00138     goto ERROR;
    00139   }
    00140
    00141   _ret=0;
    00142  ERROR:
    00143
    00144   if (_datagroup>0)
    00145     if (_MEDdatagroupFermer(_datagroup) < 0) {
    00146       _pathi[_itmplen]='\0';
    00147       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathi);
    00148     }
    00149
    00150   if (_itmpbuff ) {free(_itmpbuff);}
    00151
    00152   if ( isubstringsize != fsubstringsize ) {
    00153     if (_ftmpbuff ) { free(_ftmpbuff);};
    00154   }
    00155
    00156   return (int) _ret;
    00157 }