MEDchampCr.c
Aller à la documentation de ce fichier.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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
00067
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
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
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 }