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

Généré le Mon May 16 17:10:23 2011 pour MED fichier par  doxygen 1.6.1