Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_MEDMEMprofilEcr.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_MEDMEMprofilEcr.hxx"
23 /*
24  * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier
25  * on intègre la correction ici.
26  */
27
28 namespace med_2_3 {
29   extern "C" {
30
31 # define ICI                    {                       \
32       fflush(stdout);                                                   \
33       fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;            \
34       fflush(stderr) ;                                                  \
35     }
36
37 # define ISCRUTE_MED(entier)        {           \
38       ICI ;                                                             \
39       fprintf(stderr,"%s = %d\n",#entier,entier) ;                      \
40       fflush(stderr) ;                                                  \
41     }
42
43 # define SSCRUTE_MED(chaine)        {           \
44       ICI ;                                                             \
45       fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;                  \
46       fflush(stderr) ;                                                  \
47     }
48 # define MESSAGE_MED(chaine)        {           \
49       ICI ;                                                             \
50       fprintf(stderr,"%s\n",chaine) ;                                   \
51       fflush(stderr) ;                                                  \
52     }
53
54     extern void _MEDmodeErreurVerrouiller(void);
55
56 #include <med.h>
57 #include <med_outils.h>
58
59 #include <string.h>
60 #include <stdlib.h>
61
62     med_err
63     MEDMEMprofilEcr(med_idt fid,med_int *pflval,med_int n,char *profilname)
64     {
65       med_idt gid, chid;
66       med_size dimd[1];
67       med_err ret;
68       char chemin[MED_TAILLE_PROFILS+1];
69
70       /*
71        * On inhibe le gestionnaire d'erreur HDF 5
72        */
73       _MEDmodeErreurVerrouiller();
74
75       /*
76        * Si le groupe "PROFILS" n'existe pas, on le cree
77        */
78       strncpy(chemin,MED_PROFILS,MED_TAILLE_PROFILS-1);
79       chemin[MED_TAILLE_PROFILS-1] = '\0';
80       if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
81         if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
82           MESSAGE_MED("Impossible de creer le groupe MED_PROFILS : ");
83           SSCRUTE_MED(chemin); goto ERROR;
84         }
85
86       /*
87        * Si le groupe "profilname" n'existe pas, on le cree
88        * Sinon => erreur
89        */
90       if ((chid = _MEDdatagroupOuvrir(gid,profilname)) >= 0) {
91         if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE )
92   {
93           MESSAGE_MED("Le profil existe déjà : ");
94           SSCRUTE_MED(profilname); goto ERROR;
95         }
96       } else
97         if ((chid = _MEDdatagroupCreer(gid,profilname)) < 0)
98           goto ERROR;
99
100       /*
101        * On stocke "n" sous forme d'attribut
102        */
103       if ((ret = _MEDattrEntierEcrire(chid,MED_NOM_NBR,&n)) < 0) {
104         MESSAGE_MED("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
105         ISCRUTE_MED(n); goto ERROR;
106       };
107
108       /*
109        * On stocke le profil dans un dataset
110        */
111       dimd[0] = n;
112 #if defined(F77INT64)
113       ret =  _MEDdatasetNumEcrire(chid,MED_NOM_PFL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
114                                   (unsigned char*) pflval);
115 #else
116       ret =  _MEDdatasetNumEcrire(chid,MED_NOM_PFL,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
117                                   (unsigned char*) pflval);
118 #endif
119       if (ret < 0 ) {
120         MESSAGE_MED("Impossible d'ecrire le dataset pflval de taille  : ");
121         ISCRUTE_MED(n); goto ERROR;
122       }
123
124       ret = 0;
125     ERROR:
126       /*
127        * On ferme tout
128        */
129       if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
130         MESSAGE_MED("Impossible de fermer le datagroup : ");
131         ISCRUTE_MED(chid); ret = -1;
132       }
133
134       if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
135         MESSAGE_MED("Impossible de fermer le datagroup : ");
136         ISCRUTE_MED(gid); ret = -1;
137       }
138
139       return ret;
140     }
141
142 #undef MESSAGE_MED
143 #undef SSCRUTE_MED
144 #undef ISCRUTE_MED
145
146   }
147 }
148
149
150
151