MEDscalaireCr.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 
00025 med_err
00026 MEDscalaireCr(med_idt fid,char *scalaire, med_type_champ type, char *desc)
00027 {
00028   med_err ret=-1;
00029   med_idt root=0,gid=0;
00030   char chemin[MED_TAILLE_NUM_DATA+1];
00031   med_int _type = (med_int) type;
00032   med_mode_acces MED_MODE_ACCES;
00033 
00034   /*
00035    * On inhibe le gestionnaire d'erreur
00036    */
00037   _MEDmodeErreurVerrouiller();
00038 if (MEDcheckVersion(fid) < 0) return -1;
00039 
00040 
00041   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00042     MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
00043     goto ERROR;
00044   }
00045 
00046   if ( MED_MODE_ACCES == MED_LECTURE ) {
00047     MESSAGE("Impossible de créer une variable scalaire en mode MED_LECTURE.");
00048     goto ERROR;
00049   };
00050 
00051   /* 
00052    * Si le Groupe  HDF "/NUM_DATA" n'existe pas, on le cree
00053    */
00054   strncpy(chemin,MED_NUM_DATA,MED_TAILLE_NUM_DATA-1);
00055   chemin[MED_TAILLE_NUM_DATA-1] = '\0';
00056   if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00057     if ((root = _MEDdatagroupCreer(fid,chemin)) < 0){
00058       MESSAGE("Erreur à la création du datagroup : ");
00059       SSCRUTE(chemin);
00060       goto ERROR;
00061     }
00062 
00063   /* 
00064    * Si le groupe HDF "scalaire" n'existe pas, on le cree
00065    * Sinon => erreur
00066    */
00067   NOFINALBLANK(scalaire,ERROR);
00068   if ((gid = _MEDdatagroupCreer(root,scalaire)) < 0) {
00069     MESSAGE("Erreur à la création de la variable scalaire : ");
00070     SSCRUTE(scalaire);
00071     goto ERROR;
00072   }
00073 
00074   /* 
00075    * On stocke l'unite, et le type de la valeur scalaire
00076    */
00077   if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_TYP,&_type)) < 0) {
00078     MESSAGE("Erreur à l'écriture du type de la varaible scalaire : ");
00079     ISCRUTE(_type);
00080     goto ERROR;
00081   }
00082   if ((ret = _MEDattrStringEcrire(gid,MED_NOM_DES,MED_TAILLE_DESC,desc)) < 0) {
00083     MESSAGE("Erreur à l'écriture de la description de la variable scalaire : ");
00084     SSCRUTE(desc);
00085     goto ERROR;
00086   }
00087 
00088   /*
00089    * On ferme tout
00090    */
00091   ret = 0;
00092  ERROR:
00093   if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
00094     MESSAGE("Impossible de fermer le datagroup : ");
00095     ISCRUTE_id(gid);ret=-1; 
00096   }
00097   
00098   if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
00099     MESSAGE("Impossible de fermer le datagroup : ");
00100     ISCRUTE_id(root);ret=-1; 
00101   }
00102 
00103   return ret;
00104 }

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