]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MEDMEMchampLire.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_MEDMEMchampLire.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_MEDMEMchampLire.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     /*
63      * - Nom de la fonction : MEDchampLire
64      * - Description : Lecture d'un Champ Résultat
65      * - Parametres :
66      *     - fid      (IN)  : ID du fichier HDF courant
67      *     - maa      (IN)  : le nom du maillage sur lequel s'applique le champ
68      *     - cha      (IN)  : le nom du champ
69      *     - val      (OUT) : valeurs du champ à lire
70      *     - interlace(IN)  : entrelacement voulu en mémoire {MED_FULL_INTERLACE,MED_NO_INTERLACE}
71      *     - numco    (IN)  : n° de la composante à lire (MED_ALL si toutes)
72      *     - profil   (OUT) : nom du profil utilisé (MED_NOPFL si inutilisé)
73      *     - pflmod   (IN)  : Indique comment lire les informations en mémoire { MED_COMPACT, MED_GLOBALE }.
74      *     - type_ent (IN)  : entité concerné par le champ {MED_NOEUD,MED_ARETE,MED_FACE,MED_MAILLE}
75      *     - type_geo (IN)  : type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
76      *     - numdt    (IN)  : n° du pas de temps (MED_NOPDT si aucun)
77      *     - numo     (IN)  : n° d'ordre utilisé MED_NONOR si inutile
78      * - Resultat : 0 en cas de succes, -1 sinon
79      */
80
81     /* REM : La taille de val allouée par l'utilisateur doit prendre en compte le nbre de points de gauss et le nbre de composantes*/
82
83     med_err
84     MEDMEMchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switch interlace,med_int numco,
85                  char * locname, char *profil, med_mode_profil pflmod,
86                  med_entite_maillage type_ent, med_geometrie_element type_geo,
87                  med_int numdt, med_int numo)
88
89     {
90       med_err ret=-1;
91       med_idt gid=0, datagroup1=0, datagroup2=0,datagroup3=0;
92       med_int ncomp=0, chtype=0, ngauss=0, i=0, pfluse=0;
93       char nomdatagroup1[2*MED_TAILLE_NOM_ENTITE+2]="",nomdatagroup2[2*MED_MAX_PARA+1]="";
94       char tmp1[MED_TAILLE_NOM_ENTITE+1]="", pfltmp[MED_TAILLE_NOM+1]="";
95       char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1]="";
96       med_size   psize=0;
97       med_int   *pfltabtmp=0;
98       med_ssize *pfltab=0;
99
100       /*
101        * On inhibe le gestionnaire d'erreur HDF 5
102        */
103       _MEDmodeErreurVerrouiller();
104
105       /*
106        * Si le Data Group cha n'existe pas => erreur
107        */
108       strcpy(chemin,MED_CHA);
109       strcat(chemin,cha);
110       if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
111         goto ERROR;
112
113       /* Lecture du nbre de composantes du champ */
114
115       if (_MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp) < 0)
116         goto ERROR;
117
118       /*
119        * Si le Data Group  de niveau 1 <type_ent>[.<type_geo>] n'existe pas => erreur
120        */
121       if (_MEDnomEntite(nomdatagroup1,type_ent) < 0)
122         goto ERROR;
123       if ((type_ent != MED_NOEUD))
124         {
125           if (_MEDnomGeometrie(tmp1,type_geo) < 0)
126             goto ERROR;
127           strcat(nomdatagroup1,".");
128           strcat(nomdatagroup1,tmp1);
129         }
130       datagroup1 = 0;
131       if ( (datagroup1 = _MEDdatagroupOuvrir(gid,nomdatagroup1)) < 0 )
132         goto ERROR;
133
134       /*
135        * Si le Data Group de niveau 2 <numdt>.<numoo> n'existe pas => erreur
136        */
137       sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
138
139       datagroup2 = 0;
140       if ( (datagroup2 = _MEDdatagroupOuvrir(datagroup1,nomdatagroup2)) < 0)
141         goto ERROR;
142
143       /*
144        * Ouvre le datagroup de niveau 3 <maa>
145        */
146
147       if ( ! strcmp(maa,MED_NOREF) )
148         if (_MEDattrStringLire(datagroup2,MED_NOM_MAI,MED_TAILLE_NOM,maa) < 0)
149           goto ERROR;
150
151       datagroup3 = 0;
152       if ( (datagroup3 = _MEDdatagroupOuvrir(datagroup2,maa)) < 0 )
153         goto ERROR;
154
155       /* Gestion des profils*/
156
157       /*
158        * Lire le profil
159        */
160
161       if (_MEDattrStringLire(datagroup3,MED_NOM_PFL,MED_TAILLE_NOM,pfltmp) < 0)
162         goto ERROR;
163
164       if ( pfluse = (strcmp(pfltmp,MED_NOPFLi) && strcmp(pfltmp,"")) ) /* le test MED_NOPFLi pour des raisons de compatibilité */
165         {
166           strcpy(profil,pfltmp);
167           if ( (i = MEDnValProfil(fid,profil)) < 0 )
168             goto ERROR;
169           else
170             psize = i;
171
172           pfltabtmp = (med_int *)   malloc (sizeof(med_int)*psize);
173           pfltab = (med_ssize *) malloc (sizeof(med_ssize)*psize);
174           if (MEDprofilLire(fid,pfltabtmp,profil) < 0)
175             goto ERROR;
176           for (i=0;i<psize;i++)
177             pfltab[i] = (med_ssize) pfltabtmp[i];
178
179         }
180       else {
181         psize = MED_NOPF;
182         strcpy(profil,MED_NOPFL);
183       }
184
185
186       /* Lire le nbre des points de GAUSS*/
187       if (_MEDattrEntierLire(datagroup3,MED_NOM_NGA,&ngauss) < 0) {
188         MESSAGE_MED("Erreur à la lecture de l'attribut MED_NOM_NGA : ");
189         ISCRUTE_MED(ngauss);goto ERROR;
190       };
191
192       /* Lire l'identificateur de localisation des points de GAUSS*/
193       if ( _MEDattrStringLire(datagroup3,MED_NOM_GAU,MED_TAILLE_NOM,locname) < 0) {
194         MESSAGE_MED("Erreur à la lecture de l'attribut MED_NOM_GAU : ");
195         SSCRUTE_MED(locname); goto ERROR;
196       }
197
198       /*
199        * Lecture du champ
200        */
201
202       if (_MEDattrEntierLire(gid,MED_NOM_TYP,&chtype) < 0)
203         goto ERROR;
204
205       switch(chtype)
206         {
207         case MED_FLOAT64 :
208           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_FLOAT64,
209                                   interlace,ncomp,numco,
210                                   psize,pflmod,pfltab,ngauss,val)< 0)
211             goto ERROR;
212           break;
213
214         case MED_INT32 :
215 #if defined(F77INT64)
216           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT64,
217                                   interlace,ncomp,numco,
218                                   psize,pflmod,pfltab,ngauss,val)< 0)
219             goto ERROR;
220 #else
221           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT32,
222                                   interlace,ncomp,numco,
223                                   psize,pflmod,pfltab,ngauss,val)< 0)
224             goto ERROR;
225 #endif
226           break;
227
228         case MED_INT64 :
229 #if defined(F77INT64)
230           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT64,
231                                   interlace,ncomp,numco,
232                                   psize,pflmod,pfltab,ngauss,val)< 0)
233             goto ERROR;
234 #else
235           goto ERROR;
236 #endif
237           break;
238
239         default :
240           goto ERROR;
241         }
242
243       /*
244        * On ferme tout
245        */
246
247       ret = 0;
248
249     ERROR:
250
251       if ( pfluse ) { free(pfltab); free(pfltabtmp);}
252
253       if (datagroup3>0)     if (_MEDdatagroupFermer(datagroup3) < 0) {
254         MESSAGE_MED("Impossible de fermer le datagroup : ");
255         ISCRUTE_MED(datagroup3); ret = -1;
256       }
257
258       if (datagroup2>0)     if (_MEDdatagroupFermer(datagroup2) < 0) {
259         MESSAGE_MED("Impossible de fermer le datagroup : ");
260         ISCRUTE_MED(datagroup2); ret = -1;
261       }
262
263       if (datagroup1>0)     if (_MEDdatagroupFermer(datagroup1) < 0) {
264         MESSAGE_MED("Impossible de fermer le datagroup : ");
265         ISCRUTE_MED(datagroup1); ret = -1;
266       }
267
268       if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
269         MESSAGE_MED("Impossible de fermer le datagroup : ");
270         ISCRUTE_MED(gid); ret = -1;
271       }
272
273       return ret;
274     }
275
276
277 #undef MESSAGE_MED
278 #undef SSCRUTE_MED
279 #undef ISCRUTE_MED
280
281   }
282 }
283
284