1 /*  This file is part of MED.
2  *
3  *  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4  *  MED is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  MED is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22 #include <string.h>
23 
24 /*
25  * - Nom de la fonction : MEDchampRefInfo
26  * - Description : Itérateur renvoyant les maillages associés au champ <cha>
27  *                 avec le lien eventuel à un fichier externe.
28  * - Parametres :
29  *     - fid        (IN) : ID du fichier HDF courant
30  *     - cha        (IN) : le nom du champ
31  *     - type_ent   (IN) : entité du champ concernée  {MED_NOEUD,MED_ARETE,MED_FACE,MED_MAILLE}
32  *      - type_geo  (IN) : type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
33  *       - indice   (IN) : itérateur commançant à 1.
34  *       - numdt    (IN) : n° du pas de temps (MED_NOPDT si aucun)
35  *       - numo     (IN) : n° d'ordre utilisé (MED_NONOR si aucun)
36  *        - maa    (OUT) : le nom du  maillage  sur lequel le champ résultat s'applique au couple (numdt,numo) donné.
37  *        - local  (OUT) : MED_VRAI si le lien est local, MED_FAUX sinon.
38  *        - ngauss (OUT) : nombre de points de GAUSS, MED_NOGAUSS si pas de points de gauss
39  * - Resultat : 0 en cas de succes, -1 sinon
40  */
41 
42 med_err
MEDchampRefInfo(med_idt fid,char * champ,med_entite_maillage type_ent,med_geometrie_element type_geo,int indice,med_int numdt,med_int numo,char * maa,med_booleen * local,med_int * ngauss)43 MEDchampRefInfo(med_idt fid,char *champ,
44 		med_entite_maillage type_ent, med_geometrie_element type_geo,
45 		int indice, med_int numdt, med_int numo,
46 		char * maa, med_booleen * local, med_int *ngauss)
47 {
48 
49   med_err ret=-1;
50   int num;
51   med_idt datagroup3=0,gid_maa=0,gid_lien=0;
52   char chemin[(MED_TAILLE_CHA+MED_TAILLE_NOM+1)+(2*MED_TAILLE_NOM_ENTITE+2)+(2*MED_MAX_PARA+1)+(MED_TAILLE_NOM)+1]="";
53   char chemin_maa[MED_TAILLE_MAA+MED_TAILLE_NOM+1]="";
54   char chemin_lien[MED_TAILLE_LIENS+MED_TAILLE_NOM+1]="";
55   char nomdatagroup1[2*MED_TAILLE_NOM_ENTITE+2]="";
56   char nomdatagroup2[2*MED_MAX_PARA+1]="";
57   char tmp1         [MED_TAILLE_NOM_ENTITE+1]="";
58 
59   /*
60    * On inhibe le gestionnaire d'erreur HDF 5
61    */
62   _MEDmodeErreurVerrouiller();
63 if (MEDcheckVersion(fid) < 0) return -1;
64 
65 
66   /*
67    * On construit le nom du datagroup
68    */
69   strcpy(chemin,MED_CHA);
70   strcat(chemin,champ);
71   strcat(chemin,"/");
72 
73   /*
74    * Si le Data Group  de niveau 1 <type_ent>[.<type_geo>] n'existe pas => erreur
75    */
76   /* modif pour la version 2.3.3 */
77 
78   if (_MEDnomEntite(nomdatagroup1,type_ent) < 0)
79     goto ERROR;
80   if ((type_ent != MED_NOEUD)) {
81     if (_MEDnomGeometrie30(tmp1,type_geo) < 0)
82       goto ERROR;
83     strcat(nomdatagroup1,".");
84     strcat(nomdatagroup1,tmp1);
85   }
86   strcat(chemin,nomdatagroup1);
87   strcat(chemin,"/");
88 
89   /*
90    * Si le Data Group de niveau 2 <numdtt>.<numoo> n'existe pas => erreur
91    */
92   sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
93 
94   strcat(chemin,nomdatagroup2);
95   strcat(chemin,"/");
96 
97 
98   /*
99    * Cherche le datagroup de niveau 3 <maa> correspondant à l'indice <num>
100    */
101   num = indice - 1;
102   if (_MEDobjetIdentifier(fid,chemin,num,maa) < 0) {
103     MESSAGE("Impossible de trouver un groupe à l'indice spécifié : ");
104     SSCRUTE(chemin); ISCRUTE_int(num); goto ERROR;
105   };
106   strcat(chemin,maa);
107 
108 
109   /*
110    * Si le Data Group de niveau 3 <maa> n'existe pas => erreur
111    */
112 
113   if ((datagroup3 = _MEDdatagroupOuvrir(fid,chemin)) < 0) {
114     MESSAGE("Erreur d'ouverture du datagroup lien au maillage : ");
115     SSCRUTE(chemin); goto ERROR;
116   };
117 
118 
119   /* Lire le nbre des points de GAUSS*/
120   if (_MEDattrEntierLire(datagroup3,MED_NOM_NGA,ngauss) < 0) {
121     MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NGA : ");
122     ISCRUTE(*ngauss);goto ERROR;
123   };
124 
125 
126   /* Maillage local ou distant */
127   strcpy(chemin_maa,MED_MAA);
128   strcat(chemin_maa,maa);
129   /* Le maillage est il distant */
130   if ( (gid_maa = _MEDdatagroupOuvrir(fid,chemin_maa)) < 0)  {
131 
132     /* Verifie que le maillage est bien référencé comme distant */
133     strcpy(chemin_lien,MED_LIENS);
134     strcat(chemin_lien,maa);
135     if ((gid_lien = _MEDdatagroupOuvrir(fid,chemin_lien)) < 0) {
136 /*       MESSAGE("Le maillage n'est ni local, ni distant : "); */
137 /*        SSCRUTE(chemin_maa);SSCRUTE(chemin_lien); goto ERROR; */
138       *local = MED_FAUX;
139     }
140 
141     *local = MED_FAUX;
142 
143   } else
144     *local = MED_VRAI;
145 
146 
147   /*
148    * On ferme tout
149    */
150 
151   ret = 0;
152 
153  ERROR:
154 
155   if (datagroup3>0)     if (_MEDdatagroupFermer(datagroup3) < 0) {
156       MESSAGE("Impossible de fermer le datagroup : ");
157       ISCRUTE_int(datagroup3); ret = -1;
158   }
159 
160   if (gid_maa>0)  if (_MEDdatagroupFermer(gid_maa) < 0) {
161       MESSAGE("Impossible de fermer le datagroup : ");
162       ISCRUTE_id(gid_maa); ret = -1;
163   }
164 
165   if (gid_lien>0) if (_MEDdatagroupFermer(gid_lien) < 0) {
166       MESSAGE("Impossible de fermer le datagroup : ");
167       SSCRUTE(chemin_lien); ret = -1;
168   }
169 
170   return ret;
171 }
172