]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MEDMEMchampLire.cxx
Salome HOME
Integration of EDF work
[modules/med.git] / src / MEDMEM / MEDMEM_MEDMEMchampLire.cxx
1 #include "MEDMEM_MEDMEMchampLire.hxx"
2 /*
3  * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier
4  * on intègre la correction ici.
5  */
6
7 namespace med_2_2 {
8   extern "C" {
9
10 # define ICI                    {                                       \
11       fflush(stdout);                                                   \
12       fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;            \
13       fflush(stderr) ;                                                  \
14     }
15
16 # define ISCRUTE(entier)        {                                       \
17       ICI ;                                                             \
18       fprintf(stderr,"%s = %d\n",#entier,entier) ;                      \
19       fflush(stderr) ;                                                  \
20     }
21
22 # define SSCRUTE(chaine)        {                                       \
23       ICI ;                                                             \
24       fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;                  \
25       fflush(stderr) ;                                                  \
26     }
27 # define MESSAGE(chaine)        {                                       \
28       ICI ;                                                             \
29       fprintf(stderr,"%s\n",chaine) ;                                   \
30       fflush(stderr) ;                                                  \
31     }
32
33     extern void _MEDmodeErreurVerrouiller(void);
34
35     /*************************************************************************
36      * COPYRIGHT (C) 1999 - 2003  EDF R&D
37      * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
38      * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE
39      * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
40      * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
41      *
42      * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
43      * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
44      * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
45      * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
46      *
47      * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
48      * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
49      * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
50      *
51      *************************************************************************/
52
53 #include <med.h>
54 #include <med_outils.h>
55
56 #include <string.h>
57 #include <stdlib.h>
58
59     /*
60      * - Nom de la fonction : MEDchampLire
61      * - Description : Lecture d'un Champ Résultat
62      * - Parametres :
63      *     - fid      (IN)  : ID du fichier HDF courant
64      *     - maa      (IN)  : le nom du maillage sur lequel s'applique le champ
65      *     - cha      (IN)  : le nom du champ
66      *     - val      (OUT) : valeurs du champ à lire
67      *     - interlace(IN)  : entrelacement voulu en mémoire {MED_FULL_INTERLACE,MED_NO_INTERLACE}
68      *     - numco    (IN)  : n° de la composante à lire (MED_ALL si toutes)
69      *     - profil   (OUT) : nom du profil utilisé (MED_NOPFL si inutilisé)
70      *     - pflmod   (IN)  : Indique comment lire les informations en mémoire { MED_COMPACT, MED_GLOBALE }.
71      *     - type_ent (IN)  : entité concerné par le champ {MED_NOEUD,MED_ARETE,MED_FACE,MED_MAILLE}
72      *     - type_geo (IN)  : type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
73      *     - numdt    (IN)  : n° du pas de temps (MED_NOPDT si aucun)
74      *     - numo     (IN)  : n° d'ordre utilisé MED_NONOR si inutile
75      * - Resultat : 0 en cas de succes, -1 sinon
76      */
77
78     /* 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*/
79
80     med_err
81     MEDMEMchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switch interlace,med_int numco,
82                  char * locname, char *profil, med_mode_profil pflmod,
83                  med_entite_maillage type_ent, med_geometrie_element type_geo,
84                  med_int numdt, med_int numo)
85
86     {
87       med_err ret=-1;
88       med_idt gid=0, datagroup1=0, datagroup2=0,datagroup3=0;
89       med_int ncomp=0, chtype=0, ngauss=0, i=0, pfluse=0;
90       char nomdatagroup1[2*MED_TAILLE_NOM_ENTITE+2]="",nomdatagroup2[2*MED_MAX_PARA+1]="";
91       char tmp1[MED_TAILLE_NOM_ENTITE+1]="", pfltmp[MED_TAILLE_NOM+1]="";
92       char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1]="";
93       med_size   psize=0;
94       med_int   *pfltabtmp=0;
95       med_ssize *pfltab=0;
96
97       /*
98        * On inhibe le gestionnaire d'erreur HDF 5
99        */
100       _MEDmodeErreurVerrouiller();
101
102       /*
103        * Si le Data Group cha n'existe pas => erreur
104        */
105       strcpy(chemin,MED_CHA);
106       strcat(chemin,cha);
107       if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
108         goto ERROR;
109
110       /* Lecture du nbre de composantes du champ */
111
112       if (_MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp) < 0)
113         goto ERROR;
114
115       /*
116        * Si le Data Group  de niveau 1 <type_ent>[.<type_geo>] n'existe pas => erreur
117        */
118       if (_MEDnomEntite(nomdatagroup1,type_ent) < 0)
119         goto ERROR;
120       if ((type_ent != MED_NOEUD))
121         {
122           if (_MEDnomGeometrie(tmp1,type_geo) < 0)
123             goto ERROR;
124           strcat(nomdatagroup1,".");
125           strcat(nomdatagroup1,tmp1);
126         }
127       datagroup1 = 0;
128       if ( (datagroup1 = _MEDdatagroupOuvrir(gid,nomdatagroup1)) < 0 )
129         goto ERROR;
130
131       /*
132        * Si le Data Group de niveau 2 <numdt>.<numoo> n'existe pas => erreur
133        */
134       sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
135
136       datagroup2 = 0;
137       if ( (datagroup2 = _MEDdatagroupOuvrir(datagroup1,nomdatagroup2)) < 0)
138         goto ERROR;
139
140       /*
141        * Ouvre le datagroup de niveau 3 <maa>
142        */
143
144       if ( ! strcmp(maa,MED_NOREF) )
145         if (_MEDattrStringLire(datagroup2,MED_NOM_MAI,MED_TAILLE_NOM,maa) < 0)
146           goto ERROR;
147
148       datagroup3 = 0;
149       if ( (datagroup3 = _MEDdatagroupOuvrir(datagroup2,maa)) < 0 )
150         goto ERROR;
151
152       /* Gestion des profils*/
153
154       /*
155        * Lire le profil
156        */
157
158       if (_MEDattrStringLire(datagroup3,MED_NOM_PFL,MED_TAILLE_NOM,pfltmp) < 0)
159         goto ERROR;
160
161       if ( pfluse = (strcmp(pfltmp,MED_NOPFLi) && strcmp(pfltmp,"")) ) /* le test MED_NOPFLi pour des raisons de compatibilité */
162         {
163           strcpy(profil,pfltmp);
164           if ( (i = MEDnValProfil(fid,profil)) < 0 )
165             goto ERROR;
166           else
167             psize = i;
168
169           pfltabtmp = (med_int *)   malloc (sizeof(med_int)*psize);
170           pfltab = (med_ssize *) malloc (sizeof(med_ssize)*psize);
171           if (MEDprofilLire(fid,pfltabtmp,profil) < 0)
172             goto ERROR;
173           for (i=0;i<psize;i++)
174             pfltab[i] = (med_ssize) pfltabtmp[i];
175
176         }
177       else {
178         psize = MED_NOPF;
179         strcpy(profil,MED_NOPFL);
180       }
181
182
183       /* Lire le nbre des points de GAUSS*/
184       if (_MEDattrEntierLire(datagroup3,MED_NOM_NGA,&ngauss) < 0) {
185         MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NGA : ");
186         ISCRUTE(ngauss);goto ERROR;
187       };
188
189       /* Lire l'identificateur de localisation des points de GAUSS*/
190       if ( _MEDattrStringLire(datagroup3,MED_NOM_GAU,MED_TAILLE_NOM,locname) < 0) {
191         MESSAGE("Erreur à la lecture de l'attribut MED_NOM_GAU : ");
192         SSCRUTE(locname); goto ERROR;
193       }
194
195       /*
196        * Lecture du champ
197        */
198
199       if (_MEDattrEntierLire(gid,MED_NOM_TYP,&chtype) < 0)
200         goto ERROR;
201
202       switch(chtype)
203         {
204         case MED_FLOAT64 :
205           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_FLOAT64,
206                                   interlace,ncomp,numco,
207                                   psize,pflmod,pfltab,ngauss,val)< 0)
208             goto ERROR;
209           break;
210
211         case MED_INT32 :
212 #if defined(F77INT64)
213           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT64,
214                                   interlace,ncomp,numco,
215                                   psize,pflmod,pfltab,ngauss,val)< 0)
216             goto ERROR;
217 #else
218           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT32,
219                                   interlace,ncomp,numco,
220                                   psize,pflmod,pfltab,ngauss,val)< 0)
221             goto ERROR;
222 #endif
223           break;
224
225         case MED_INT64 :
226 #if defined(F77INT64)
227           if ( _MEDdatasetNumLire(datagroup3,MED_NOM_CO,MED_INT64,
228                                   interlace,ncomp,numco,
229                                   psize,pflmod,pfltab,ngauss,val)< 0)
230             goto ERROR;
231 #else
232           goto ERROR;
233 #endif
234           break;
235
236         default :
237           goto ERROR;
238         }
239
240       /*
241        * On ferme tout
242        */
243
244       ret = 0;
245
246     ERROR:
247
248       if ( pfluse ) { free(pfltab); free(pfltabtmp);}
249
250       if (datagroup3>0)     if (_MEDdatagroupFermer(datagroup3) < 0) {
251         MESSAGE("Impossible de fermer le datagroup : ");
252         ISCRUTE(datagroup3); ret = -1;
253       }
254
255       if (datagroup2>0)     if (_MEDdatagroupFermer(datagroup2) < 0) {
256         MESSAGE("Impossible de fermer le datagroup : ");
257         ISCRUTE(datagroup2); ret = -1;
258       }
259
260       if (datagroup1>0)     if (_MEDdatagroupFermer(datagroup1) < 0) {
261         MESSAGE("Impossible de fermer le datagroup : ");
262         ISCRUTE(datagroup1); ret = -1;
263       }
264
265       if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
266         MESSAGE("Impossible de fermer le datagroup : ");
267         ISCRUTE(gid); ret = -1;
268       }
269
270       return ret;
271     }
272
273
274 #undef MESSAGE
275 #undef SSCRUTE
276 #undef ISCRUTE
277
278   }
279 }
280
281