MEDscalaireEntierEcr.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 
00026 med_err
00027 MEDscalaireEntierEcr(med_idt fid, char *scalaire,med_int val, med_int numdt, char *dt_unit, med_float dt, med_int numo)
00028 {
00029   med_err ret = 0;
00030   med_idt gid,datagroup;
00031   char nomdatagroup[2*MED_MAX_PARA+1];
00032   char chemin[MED_TAILLE_NUM_DATA+MED_TAILLE_NOM+1];
00033   med_int type;
00034   med_mode_acces MED_MODE_ACCES;
00035 
00036   /*
00037    * On inhibe le gestionnaire d'erreur HDF 5
00038    */
00039   _MEDmodeErreurVerrouiller();
00040 if (MEDcheckVersion(fid) < 0) return -1;
00041 
00042 
00043   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00044     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
00045     return -1;
00046   }
00047 
00048   /* 
00049    * Si le groupe HDF "scalaire"  n'existe pas => erreur
00050    */
00051   strcpy(chemin,MED_NUM_DATA);
00052   strcat(chemin,scalaire);
00053   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00054     return -1;
00055 
00056   /* Creation du groupe HDF correspondant au couple <numdt>.<numoo> */
00057   sprintf(nomdatagroup,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
00058 
00059   /* Cree ou ouvre le datagroup nomdatagroup */
00060   datagroup = 0;   
00061   if (((datagroup = _MEDdatagroupOuvrir(gid,nomdatagroup)) > 0)    
00062       && ( MED_MODE_ACCES == MED_LECTURE_AJOUT ))   
00063     return -1;   
00064   else   
00065     if (datagroup < 0)
00066       if ((datagroup = _MEDdatagroupCreer(gid,nomdatagroup)) < 0)   
00067         return -1;   
00068   
00069   /* Cree ou ouvre l'attribut MED_NOM_NDT */
00070   if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NDT,&numdt)) < 0)
00071     return -1;
00072   
00073   /* Cree ou ouvre l'attribut MED_NOM_PDT */
00074   if ((ret = _MEDattrFloatEcrire(datagroup,MED_NOM_PDT,&dt)) < 0)
00075     return -1;
00076     
00077   /* Cree ou ouvre l'attribut MED_NOM_NOR */
00078   if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NOR,&numo)) < 0)
00079     return -1;
00080 
00081   /* Cree ou ouvre l'attribut  MED_NOM_UNI */ 
00082   if ( numdt == MED_NOPDT ) {
00083     if ((ret = _MEDattrStringEcrire(datagroup,MED_NOM_UNI,MED_TAILLE_PNOM,MED_PNOM_BLANC)) < 0)
00084       return -1;
00085   } else
00086     if ((ret = _MEDattrStringEcrire(datagroup,MED_NOM_UNI,MED_TAILLE_PNOM,dt_unit)) < 0)
00087       return -1;
00088 
00089   /*
00090    * Ecriture de la valeur scalaire
00091    */
00092   if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&type)) < 0)
00093     return -1;
00094   switch(type) 
00095     {
00096     case MED_INT :
00097     case MED_INT32 :
00098     case MED_INT64 :
00099       if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_VAL,&val)) < 0)
00100         return -1;      
00101       break;
00102 
00103     default :
00104       return -1;
00105     }
00106 
00107   /*
00108    * On ferme tout 
00109    */
00110   if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
00111     return -1;
00112   if ((ret = _MEDdatagroupFermer(gid)) < 0)
00113     return -1;
00114 
00115   return ret;
00116 }

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