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 void
_MEDfield23nProfile30(int dummy,...)25 _MEDfield23nProfile30(int dummy, ...) {
26 
27 
28   med_int  _ret=-1,_err=-1;
29   med_idt  _gid=0,_datagroup1=0;
30   char     _path[(MED_FIELD_GRP_SIZE+MED_NAME_SIZE+1)+(2*MED_MAX_PARA+1)+1]=MED_FIELD_GRP;
31   char     _datagroupname1[2*MED_TAILLE_NOM_ENTITE+2]="";
32   char     _geotypename      [MED_TAILLE_NOM_ENTITE+1]="";
33   char     _profilename  [MED_NAME_SIZE+1]="";
34   med_int  _numdt=0, _numit=0;
35   med_size _n=0;
36 
37 
38   MED_VARGS_DECL(const, med_idt           , , fid                     );
39   MED_VARGS_DECL(const, char * , const      , fieldname               );
40   MED_VARGS_DECL(const, med_int           , , numdt                   );
41   MED_VARGS_DECL(const, med_int           , , numit                   );
42   MED_VARGS_DECL(const, med_entity_type   , , entitype                );
43   MED_VARGS_DECL(const, med_geometry_type , , geotype                 );
44   MED_VARGS_DECL(const, int               , , meshit                  );
45   MED_VARGS_DECL(, char *, const      , meshname                      );
46   MED_VARGS_DECL(, char *, const      , defaultprofilename            );
47   MED_VARGS_DECL(, char *, const      , defaultlocalizationname       );
48   MED_VARGS_DECL(, med_int *         ,, fret                          );
49 
50   va_list params;
51   va_start(params,dummy);
52 
53   MED_VARGS_DEF(const, med_idt           , , fid                     );
54   MED_VARGS_DEF(const, char * , const      , fieldname               );
55   MED_VARGS_DEF(const, med_int           , , numdt                   );
56   MED_VARGS_DEF(const, med_int           , , numit                   );
57   MED_VARGS_DEF(const, med_entity_type   , , entitype                );
58   MED_VARGS_DEF(const, med_geometry_type , , geotype                 );
59   MED_VARGS_DEF(const, int               , , meshit                  );
60   MED_VARGS_DEF(, char *, const      , meshname                      );
61   MED_VARGS_DEF(, char *, const      , defaultprofilename            );
62   MED_VARGS_DEF(, char *, const      , defaultlocalizationname       );
63   MED_VARGS_DEF(, med_int *         ,, fret                          );
64 
65   /*
66    * On inhibe le gestionnaire d'erreur HDF 5
67    */
68   _MEDmodeErreurVerrouiller();
69 
70   NOFINALBLANK(fieldname,ERROR);
71 
72   if (meshit != 1 ) {
73     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,"meshit");
74     ISCRUTE_int(meshit);
75     goto ERROR;
76   }
77 
78   /*
79    * On construit le chemin d'acc�s jusqu'aux groupes <type_ent>[.<type_geo>]
80    */
81   strcat(_path,fieldname);
82 
83   /* Lecture de l'attribut MED_NOM_MAI */
84   if ( _MEDattributeStringRdByName(fid,_path,MED_NOM_MAI,MED_NAME_SIZE,meshname) < 0) {
85     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
86     SSCRUTE(_path);SSCRUTE(MED_NOM_MAI);SSCRUTE(meshname);
87     goto ERROR;
88   }
89 
90   strcat(_path,"/");
91   _MEDgetComputationStepName(MED_SORT_DTIT,numdt,numit,&_path[strlen(_path)]);
92   strcat(_path,"/");
93 
94   if ((_gid = _MEDdatagroupOuvrir(fid,_path)) < 0) {
95     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
96     SSCRUTE(fieldname);SSCRUTE(_path); goto ERROR;
97   }
98 
99 
100   /*Lit l'attribut MED_NOM_NDT  */
101   if ( _MEDattrEntierLire(_gid,MED_NOM_NDT, &_numdt) < 0) {
102     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
103     SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(MED_NOM_NDT);
104     ISCRUTE(_numdt);goto ERROR;
105   }
106 
107   if ( _numdt != numdt) {
108     MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
109     SSCRUTE(fieldname);ISCRUTE(_numdt);ISCRUTE(numdt);goto ERROR;
110   }
111 
112   /*Lit l'attribut MED_NOM_NOR */
113   if ( _MEDattrEntierLire(_gid,MED_NOM_NOR, &_numit) < 0) {
114     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
115     SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(MED_NOM_NOR);
116     ISCRUTE(_numit); goto ERROR;
117   }
118 
119   if ( _numit != numit) {
120     MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
121     SSCRUTE(fieldname);ISCRUTE(_numit);ISCRUTE(numit);goto ERROR;
122   }
123 
124   /*
125    * Si le Data Group  de niveau <type_ent>[.<type_geo>] n'existe pas retroune 0
126    */
127 
128   if (_MEDgetEntityTypeName(_datagroupname1,entitype) < 0) {
129     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ENTITY,_datagroupname1);
130     goto ERROR;
131   }
132 
133   if (entitype != MED_NODE) {
134     if ( (entitype == MED_STRUCT_ELEMENT) && (geotype != MED_NO_GEOTYPE )) {
135       if ( MEDstructElementName(fid,geotype,_geotypename) < 0 ) {
136 	MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDstructElementName");
137 	ISCRUTE_int(geotype);goto ERROR;
138       }
139     } else {
140       if (_MEDgetInternalGeometryTypeName(0,_geotypename,geotype) < 0) {
141 	MED_ERR_(_ret,MED_ERR_READ,MED_ERR_GEOMETRIC,_geotypename);
142 	goto ERROR;
143       }
144     }
145     strcat(_datagroupname1,".");
146     strcat(_datagroupname1,_geotypename);
147   }
148 /*   strcat(_path,_datagroupname1); */
149 /*   strcat(_path,"/"); */
150 
151 
152   if ((_datagroup1 = _MEDdatagroupOuvrir(_gid,_datagroupname1)) < 0) {
153     *defaultprofilename='\0';
154     *defaultlocalizationname='\0';
155     _ret = 0;
156     goto ERROR;
157   }
158 
159   if ((_err=_MEDnObjects(_datagroup1,".",&_n)) <0)
160     if ( _err == (MED_ERR_COUNT + MED_ERR_DATAGROUP) ) {
161       MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_datagroupname1);
162       goto ERROR;
163     }
164 
165   /* Lit le nom du profil associ� s'il en existe d�j� un */
166   if ( _MEDattrStringLire(_datagroup1,MED_NOM_PFL,MED_NAME_SIZE,_profilename) < 0 ) {
167     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
168     SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(MED_NOM_PFL);
169     goto ERROR;
170   }
171 
172   if ( strcmp(_profilename,MED_NO_PROFILE_INTERNAL) ) {
173     strncpy(defaultprofilename,_profilename,MED_NAME_SIZE+1);
174     defaultprofilename[MED_NAME_SIZE]='\0';
175   } else {
176     defaultprofilename[0]='\0';
177   }
178 
179   /* Lit le nom de la localization associ� s'il en existe d�j� une */
180   if ( _MEDattrStringLire(_datagroup1,MED_NOM_GAU,MED_NAME_SIZE,defaultlocalizationname) < 0 ) {
181     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
182     SSCRUTE(fieldname);SSCRUTE(_path);SSCRUTE(MED_NOM_GAU);
183     goto ERROR;
184   }
185 
186   _ret = (med_int) _n;
187 
188  ERROR:
189 
190 
191   if (_datagroup1>0)            if (_MEDdatagroupFermer(_datagroup1) < 0) {
192     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
193     SSCRUTE(_datagroupname1); ISCRUTE_id(_datagroup1);
194   }
195 
196   if (_gid>0)            if (_MEDdatagroupFermer(_gid) < 0) {
197     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
198     ISCRUTE_id(_gid);
199   }
200 
201   va_end(params);
202   *fret = _ret;
203   return;
204 }
205