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