MEDchampCr.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 MEDchampCr( med_idt fid,  char *  champ,  med_type_champ type,  char *  comp,
00027                     char *  unit, med_int ncomp)
00028 {
00029   med_err ret=-1;
00030   med_idt root=0,gid=0;
00031   char chemin[MED_TAILLE_CHA+1];
00032   med_size dimd[1];
00033   med_int _type = (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     goto ERROR;
00046   }
00047 
00048   if ( MED_MODE_ACCES == MED_LECTURE ) {
00049     MESSAGE("Impossible de créer un champ en mode MED_LECTURE.");
00050     goto ERROR;
00051   };
00052   
00053   /* 
00054    * Si le Data Group "/CHA/" n'existe pas, on le cree
00055    */
00056   strncpy(chemin,MED_CHA,MED_TAILLE_CHA-1);
00057   chemin[MED_TAILLE_CHA-1] = '\0';
00058   if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00059     if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
00060       MESSAGE("Erreur à la création du datagroup : ");
00061       SSCRUTE(chemin);
00062       goto ERROR;
00063     }
00064 
00065   /* 
00066    * Si le Data Group cha n'existe pas, on le cree
00067    * Sinon => erreur
00068    */
00069 
00070   NOFINALBLANK(champ,ERROR);
00071 
00072   if ((gid = _MEDdatagroupCreer(root,champ)) < 0) {
00073     MESSAGE("Erreur à la création du champ : ");
00074     SSCRUTE(champ);
00075     goto ERROR;
00076   }
00077 
00078   /*
00079    * Les infos sur les composants du champ
00080    */
00081   if ( _MEDattrEntierEcrire(gid,MED_NOM_NCO,&ncomp) < 0 ) {
00082     MESSAGE("Erreur à l'écriture du nombre de composantes : ");
00083     ISCRUTE(ncomp);
00084     goto ERROR;
00085   }
00086   if ( _MEDattrEntierEcrire(gid,MED_NOM_TYP,&_type) < 0) {
00087     MESSAGE("Erreur à l'écriture du type du champ : ");
00088     ISCRUTE(_type);
00089     goto ERROR;
00090   }
00091   if ( _MEDattrStringEcrire(gid,MED_NOM_NOM,MED_TAILLE_PNOM*ncomp,comp) < 0) {
00092     MESSAGE("Erreur à l'écriture des noms des composantes : ");
00093     SSCRUTE(comp);
00094     goto ERROR;
00095   }
00096   if ( _MEDattrStringEcrire(gid,MED_NOM_UNI,MED_TAILLE_PNOM*ncomp,unit) < 0) {
00097     MESSAGE("Erreur à l'écriture des unités : ");
00098     SSCRUTE(unit);
00099     goto ERROR;
00100   }
00101   /*
00102    * On ferme tout
00103    */
00104   
00105   ret=0;
00106  ERROR:
00107   if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
00108     MESSAGE("Impossible de fermer le datagroup : ");
00109     ISCRUTE_id(gid);ret = -1; 
00110   }
00111   
00112   if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
00113     MESSAGE("Impossible de fermer le datagroup : ");
00114     ISCRUTE_id(root); ret = -1; 
00115   }
00116 
00117   return ret;
00118 }

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