]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MEDMEMprofilEcr.cxx
Salome HOME
Fix problem of make distcheck
[modules/med.git] / src / MEDMEM / MEDMEM_MEDMEMprofilEcr.cxx
1 // Copyright (C) 2007-2012  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
23 #include "MEDMEM_MEDMEMprofilEcr.hxx"
24 /*
25  * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier
26  * on intègre la correction ici.
27  */
28
29 namespace med_2_3 {
30   extern "C" {
31
32 # define ICI                    {                       \
33       fflush(stdout);                                                   \
34       fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;            \
35       fflush(stderr) ;                                                  \
36     }
37
38 # define ISCRUTE_MED(entier)        {           \
39       ICI ;                                                             \
40       fprintf(stderr,"%s = %d\n",#entier,entier) ;                      \
41       fflush(stderr) ;                                                  \
42     }
43
44 # define SSCRUTE_MED(chaine)        {           \
45       ICI ;                                                             \
46       fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;                  \
47       fflush(stderr) ;                                                  \
48     }
49 # define MESSAGE_MED(chaine)        {           \
50       ICI ;                                                             \
51       fprintf(stderr,"%s\n",chaine) ;                                   \
52       fflush(stderr) ;                                                  \
53     }
54
55     extern void _MEDmodeErreurVerrouiller(void);
56
57 #include <med.h>
58 #include <med_outils.h>
59
60 #include <string.h>
61 #include <stdlib.h>
62
63     med_err
64     MEDMEMprofilEcr(med_idt fid,med_int *pflval,med_int n,char *profilname)
65     {
66       med_idt gid, chid;
67       med_size dimd[1];
68       med_err ret;
69       char chemin[MED_TAILLE_PROFILS+1];
70
71       /*
72        * On inhibe le gestionnaire d'erreur HDF 5
73        */
74       _MEDmodeErreurVerrouiller();
75
76       /*
77        * Si le groupe "PROFILS" n'existe pas, on le cree
78        */
79       strncpy(chemin,MED_PROFILS,MED_TAILLE_PROFILS-1);
80       chemin[MED_TAILLE_PROFILS-1] = '\0';
81       if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
82         if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
83           MESSAGE_MED("Impossible de creer le groupe MED_PROFILS : ");
84           SSCRUTE_MED(chemin); goto ERROR;
85         }
86
87       /*
88        * Si le groupe "profilname" n'existe pas, on le cree
89        * Sinon => erreur
90        */
91       if ((chid = _MEDdatagroupOuvrir(gid,profilname)) >= 0) {
92         if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE )
93   {
94           MESSAGE_MED("Le profil existe déjà : ");
95           SSCRUTE_MED(profilname); goto ERROR;
96         }
97       } else
98         if ((chid = _MEDdatagroupCreer(gid,profilname)) < 0)
99           goto ERROR;
100
101       /*
102        * On stocke "n" sous forme d'attribut
103        */
104       if ((ret = _MEDattrEntierEcrire(chid,MED_NOM_NBR,&n)) < 0) {
105         MESSAGE_MED("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
106         ISCRUTE_MED(n); goto ERROR;
107       };
108
109       /*
110        * On stocke le profil dans un dataset
111        */
112       dimd[0] = n;
113 #if defined(F77INT64)
114       ret =  _MEDdatasetNumEcrire(chid,MED_NOM_PFL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
115                                   (unsigned char*) pflval);
116 #else
117       ret =  _MEDdatasetNumEcrire(chid,MED_NOM_PFL,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
118                                   (unsigned char*) pflval);
119 #endif
120       if (ret < 0 ) {
121         MESSAGE_MED("Impossible d'ecrire le dataset pflval de taille  : ");
122         ISCRUTE_MED(n); goto ERROR;
123       }
124
125       ret = 0;
126     ERROR:
127       /*
128        * On ferme tout
129        */
130       if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
131         MESSAGE_MED("Impossible de fermer le datagroup : ");
132         ISCRUTE_MED(chid); ret = -1;
133       }
134
135       if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
136         MESSAGE_MED("Impossible de fermer le datagroup : ");
137         ISCRUTE_MED(gid); ret = -1;
138       }
139
140       return ret;
141     }
142
143 #undef MESSAGE_MED
144 #undef SSCRUTE_MED
145 #undef ISCRUTE_MED
146
147   }
148 }
149
150
151
152