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 #include <stdlib.h>
24 
25 
_MEDfieldValueAdvancedWr30(int dummy,...)26 void  _MEDfieldValueAdvancedWr30(int dummy,...) {
27 
28   med_access_mode       _MED_ACCESS_MODE;
29   med_err               _ret=-1;
30   med_idt               _gid=0,_locgid=0,_datagroup1=0,_datagroup2=0,_datagroup3=0;
31   med_int               _nconstituentpervalue=0, _profilearraysize=0;
32   med_bool              _defaultprofileexist=MED_FALSE,_defaultlocalizationexist=MED_FALSE;
33   med_bool              _attexist=MED_FALSE;
34 /*   med_bool              _profilparameterexist=MED_FALSE; */
35   med_bool              _profilehaschanged=MED_FALSE,_filterparameterexist=MED_FALSE;
36   med_int               _nvaluesperentity=0,_nsectioncell=1;
37   med_field_type        _fieldtype=0;
38   med_int               _intfieldtype=0;
39   med_geometry_type     _locgeotype=0;
40   med_int               _intlocgeotype=0;
41   char _gidname           [MED_FIELD_GRP_SIZE+MED_NAME_SIZE+1]="";
42   char _datagroupname1    [2*MED_MAX_PARA+1]="";
43   char _datagroupname2    [2*MED_TAILLE_NOM_ENTITE+2]="";
44   char _profilename       [MED_NAME_SIZE+1]="";
45   char _locgidname        [MED_LOCALIZATION_GRP_SIZE+MED_NAME_SIZE+1]=MED_LOCALIZATION_GRP;
46   char _sectionmeshname      [MED_NAME_SIZE+1]="";
47   char _sectiongeotypename   [MED_NAME_SIZE+1]="";
48   char _geotypename       [MED_TAILLE_NOM_ENTITE+1]="";
49   char _defaultprofilename[MED_NAME_SIZE+1]=MED_NO_PROFILE;
50   char _defaultlocalizationname[MED_NAME_SIZE+1]=MED_NO_LOCALIZATION;
51   med_filter *               _filter           = NULL;
52   med_filter                 _tmpfilter        = MED_FILTER_INIT;
53   med_filter                 _paramfilter      = MED_FILTER_INIT;
54   med_int                    _MED_NO_DT = MED_NO_DT;
55   med_int                    _MED_NO_IT = MED_NO_IT;
56   med_bool                   _chgt=MED_FALSE,_trsf=MED_FALSE;
57 
58 
59   MED_VARGS_DECL(const, med_idt               , , fid              );
60   MED_VARGS_DECL(const, char * , const          , fieldname        );
61   MED_VARGS_DECL(const, med_int               , , numdt            );
62   MED_VARGS_DECL(const, med_int               , , numit            );
63   MED_VARGS_DECL(const, med_float             , , dt               );
64   MED_VARGS_DECL(const, med_entity_type       , , entitytype       );
65   MED_VARGS_DECL(const, med_geometry_type     , , geotype          );
66   MED_VARGS_DECL(const, med_storage_mode      , , storagemode      );
67   MED_VARGS_DECL(const, char * , const          , profilename      );
68   MED_VARGS_DECL(const, char * , const          , localizationname );
69   MED_VARGS_DECL(const, med_switch_mode       , , switchmode       );
70   MED_VARGS_DECL(const, med_int               , , componentselect  );
71   MED_VARGS_DECL(const, med_filter* , const     , filter           );
72   MED_VARGS_DECL(const, med_int               , , nentity       );
73   MED_VARGS_DECL(const, unsigned char*, const   , value            );
74   MED_VARGS_DECL(, med_err *                   ,, fret             );
75 
76   va_list params;
77   va_start(params,dummy);
78 
79   MED_VARGS_DEF(const, med_idt               , , fid              );
80   MED_VARGS_DEF(const, char * , const          , fieldname        );
81   MED_VARGS_DEF(const, med_int               , , numdt            );
82   MED_VARGS_DEF(const, med_int               , , numit            );
83   MED_VARGS_DEF(const, med_float             , , dt               );
84   MED_VARGS_DEF(const, med_entity_type       , , entitytype       );
85   MED_VARGS_DEF(const, med_geometry_type     , , geotype          );
86   MED_VARGS_DEF(const, med_storage_mode      , , storagemode      );
87   MED_VARGS_DEF(const, char * , const          , profilename      );
88   MED_VARGS_DEF(const, char * , const          , localizationname );
89   MED_VARGS_DEF(const, med_switch_mode       , , switchmode       );
90   MED_VARGS_DEF(const, med_int               , , componentselect  );
91   MED_VARGS_DEF(const, med_filter* , const     , filter           );
92   MED_VARGS_DEF(const, med_int               , , nentity       );
93   MED_VARGS_DEF(const, unsigned char*, const   , value            );
94   MED_VARGS_DEF(, med_err *                   ,, fret             );
95 
96 
97 
98 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
99 
100   if (filter) {
101     _filter=(med_filter*)(filter); _filterparameterexist=MED_TRUE;
102   }
103   else {
104     _filter=&_tmpfilter;
105     (*_filter).nentity              = nentity;
106 /*   (*_filter).nvaluesperentity     = nvaluesperentity; */
107 /*   (*_filter).nconstituentpervalue = nconstituentpervalue; */
108     (*_filter).constituentselect       = componentselect;
109     (*_filter).switchmode              = switchmode;
110     (*_filter).storagemode             = storagemode;
111     strcpy((*_filter).profilename,profilename);
112 /*   (*_filter).profilearraysize        = profilearraysize; */
113   }
114 
115   /*
116    * On inhibe le gestionnaire d'erreur HDF 5
117    */
118   _MEDmodeErreurVerrouiller();
119 
120   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
121     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
122     goto ERROR;
123   }
124 
125   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
126     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
127     ISCRUTE_int(_MED_ACCESS_MODE);
128     goto ERROR;
129   }
130 
131   /*
132    * Si le DataGroup MED_FIELD_GRP n'existe pas => erreur
133    */
134   NOFINALBLANK(fieldname,ERROR);
135 
136   strcpy(_gidname,MED_FIELD_GRP);
137   strcat(_gidname,fieldname);
138   if ((_gid = _MEDdatagroupOuvrir(fid,_gidname)) < 0) {
139     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
140     SSCRUTE(fieldname);SSCRUTE(_gidname); goto ERROR;
141   }
142 
143 
144   /* Lecture de l'attribut MED_NOM_NCO */
145   /* Cohérence de l'attribut MED_NOM_NCO avec le filtre*/
146   if (_MEDattrEntierLire(_gid,MED_NOM_NCO,&_nconstituentpervalue) < 0) {
147     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
148     SSCRUTE(fieldname);SSCRUTE(MED_NOM_NCO);goto ERROR;
149   }
150 
151   if (_filterparameterexist) {
152     if ((*_filter).nconstituentpervalue != _nconstituentpervalue ) {
153       MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_VALUE_MSG);
154       ISCRUTE((*_filter).nconstituentpervalue); ISCRUTE(_nconstituentpervalue );
155       goto ERROR;
156     }
157   } else {
158     (*_filter).nconstituentpervalue = _nconstituentpervalue;
159   }
160 
161   /* Lecture de l'attribut MED_NOM_TYP */
162 
163   if ( _MEDattrEntierLire(_gid,MED_NOM_TYP,&_intfieldtype) < 0) {
164     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
165     SSCRUTE(fieldname);SSCRUTE(MED_NOM_TYP);
166     goto ERROR;
167   }
168   _fieldtype = (med_field_type) (_intfieldtype);
169 
170 
171   /*
172    * Creation/Ouverture du datagroup de niveau 2 <numdt>.<numit>
173    */
174   _MEDgetComputationStepName(MED_SORT_DTIT,numdt,numit,_datagroupname1);
175 
176   _datagroup1 = 0;
177   if ( (_datagroup1 = _MEDdatagroupOuvrir(_gid,_datagroupname1)) < 0 )
178     if ((_datagroup1 = _MEDdatagroupCreer(_gid,_datagroupname1)) < 0 ) {
179       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
180       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);goto ERROR;
181     }
182 
183   /*Cree ou ouvre l'attribut MED_NOM_NDT pour écriture */
184   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NDT,&numdt) < 0) {
185     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
186     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NDT);
187     ISCRUTE(numdt);goto ERROR;
188   }
189 
190   /*Cree ou ouvre l'attribut MED_NOM_PDT pour écriture */
191   if ( _MEDattrFloatEcrire(_datagroup1,MED_NOM_PDT,&dt) < 0) {
192     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
193     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_PDT);
194     RSCRUTE(dt);goto ERROR;
195   }
196 
197   /*Cree ou ouvre l'attribut MED_NOM_NOR pour écriture */
198   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NOR,&numit) < 0) {
199     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
200     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOR);
201     ISCRUTE(numit); goto ERROR;
202   }
203 
204   /*Cree l'attribut MED_NOM_RDT s'il n'exite pas déjà*/
205   _MEDattributeExist(_datagroup1,".",MED_NOM_RDT,&_attexist);
206   if (!_attexist )
207     if ( _MEDattributeIntWr(_datagroup1,MED_NOM_RDT,&_MED_NO_DT) < 0) {
208       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
209       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_RDT);
210       ISCRUTE_int(MED_NO_DT);goto ERROR;
211     }
212 
213   /*Cree l'attribut MED_NOM_ROR s'il n'exite pas déjà*/
214   _MEDattributeExist(_datagroup1,".",MED_NOM_ROR,&_attexist);
215   if (!_attexist )
216     if ( _MEDattributeIntWr(_datagroup1,MED_NOM_ROR,&_MED_NO_IT) < 0) {
217       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
218       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_ROR);
219       ISCRUTE_int(MED_NO_IT);goto ERROR;
220     }
221 
222   /*MODEL : MED_NOM_UNI est remonte à la création du champ  */
223   /*Cree ou ouvre l'attribut  MED_NOM_UNI pour écriture */
224 /*   if ( numdt == MED_NO_DT ) { */
225 /*     if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,MED_SNAME_SIZE,MED_PNOM_BLANC) < 0) { */
226 /*       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_UNI); */
227 /*       goto ERROR; */
228 /*     } */
229 /*   } else */
230 /*     if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,MED_SNAME_SIZE,dt_unit) < 0) { */
231 /*       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_UNI); */
232 /*       SSCRUTE(dt_unit); */
233 /*       goto ERROR; */
234 /*     } */
235 
236   /* MODEL : Descente du datagroup1 en datagroup2 */
237   /*
238    *  Creation/Ouverture du datagroup de niveau 2 <entitytype>[.<geotype>]
239    */
240 
241   if (_MEDgetEntityTypeName(_datagroupname2,entitytype) < 0) {
242     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
243     ISCRUTE_int(entitytype);SSCRUTE(fieldname);goto ERROR;
244   }
245 
246 
247   if ( entitytype != MED_NODE ) {
248 
249     if ( entitytype == MED_STRUCT_ELEMENT ) {
250       if ( MEDstructElementName(fid, geotype,_geotypename) < 0 ) {
251 	MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDstructElementName");
252 	ISCRUTE_int(geotype);goto ERROR;
253       }
254     } else {
255       if ( _MEDgetInternalGeometryTypeName(fid,_geotypename,geotype) < 0) {
256 	MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
257 	ISCRUTE_int(geotype);SSCRUTE(fieldname);goto ERROR;
258       }
259     }
260     strcat(_datagroupname2,".");
261     strcat(_datagroupname2,_geotypename);
262   }
263 
264   _datagroup2 = 0;
265   if ( (_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,_datagroupname2)) < 0)
266     if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,_datagroupname2)) < 0) {
267       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
268       SSCRUTE(fieldname);goto ERROR;
269     }
270 
271   /* MODEL : déplacement de l'attribut MED_NOM_PFL */
272 
273   /*Cree ou ouvre  l'attribut MED_NOM_PFL   */
274   /* Lit le nom du profil associé s'il en existe déjà un */
275   if ( _MEDattrStringLire(_datagroup2,MED_NOM_PFL,MED_NAME_SIZE,_defaultprofilename) < 0 ) {
276     strncpy(_defaultprofilename,MED_NO_PROFILE,MED_NAME_SIZE+1);
277     _defaultprofileexist = MED_FALSE;
278   } else
279     _defaultprofileexist = MED_TRUE;
280 
281   NOFINALBLANK(profilename,ERROR);
282 
283   if ( strlen((*_filter).profilename) == 0 ) {  /* idem MED_NOPFL*/
284     /*Ecriture de MED_NO_PROFILE_INTERNAL car un datagroup ne peut pas être de nom ""*/
285     strncpy(_profilename,MED_NO_PROFILE_INTERNAL,MED_NAME_SIZE+1);
286 /*     strncpy(_profilename,MED_NO_PROFILE,MED_NAME_SIZE+1); */
287 /*     _profilparameterexist=MED_FALSE; */
288     _profilearraysize = MED_UNDEF_SIZE;
289   } else {
290     strncpy(_profilename,(*_filter).profilename,MED_NAME_SIZE+1);
291     _profilename[MED_NAME_SIZE]='\0'; /*On tronque les eventuels noms trop long*/
292 /*     _profilparameterexist=MED_TRUE; */
293     if ( ( _profilearraysize = MEDprofileSizeByName( fid,_profilename) ) < 0 ) {
294       MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,MED_ERR_FIELD_MSG);
295       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);
296       SSCRUTE(_profilename);SSCRUTE("MEDprofileSizeByName");goto ERROR;
297     }
298   }
299 
300   /*INUTILE : le paramètre est positionné dans  MEDfilterEntityCr */
301   if (!_filterparameterexist) (*_filter).profilearraysize =  _profilearraysize;
302 
303 
304   /*Cree ou ouvre  l'attribut MED_NOM_GAU   */
305   /* Lit le nom de la localisation associée s'il en existe déjà une */
306   if ( _MEDattrStringLire(_datagroup2,MED_NOM_GAU,MED_NAME_SIZE,_defaultlocalizationname) < 0 ) {
307     strncpy(_defaultlocalizationname,MED_NO_LOCALIZATION,MED_NAME_SIZE+1);
308     _defaultlocalizationexist = MED_FALSE;
309   } else {
310     _defaultlocalizationexist = MED_TRUE;
311   }
312   NOFINALBLANK(localizationname,ERROR);
313 
314 
315   /*
316    * Cree ou ouvre le _datagroup de niveau 3 <profilename>
317    */
318 
319   _datagroup3 = 0;
320   if (((_datagroup3 = _MEDdatagroupOuvrir(_datagroup2,_profilename)) > 0)
321       && ( _MED_ACCESS_MODE == MED_ACC_RDEXT )) {
322     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_DATAGROUP_MSG);
323     SSCRUTE(_profilename);
324     ISCRUTE_int(_MED_ACCESS_MODE);
325     goto ERROR;
326   } else
327     if ( _datagroup3 < 0)
328       if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_profilename)) < 0) {
329 	MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_profilename);
330 	SSCRUTE(fieldname);SSCRUTE(_profilename);goto ERROR;
331       }
332 
333   /*L'attribut MED_NOM_PFL du datagroup2 est crée après le datagroup profilename
334    en cas d'erreur de création */
335   /*TODO: IL faudra gérer la suppression d'un profil si nentity==0 et *val=0
336     TODO: Vérifier alors qu'il n'est pas le profil par défaut sinon proposer une API
337     TODO: pour changer le profil par défaut.*/
338   if ( !_defaultprofileexist )
339     if ( _MEDattributeStringWr(_datagroup2,MED_NOM_PFL,MED_NAME_SIZE,_profilename) < 0) {
340       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
341       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);
342       SSCRUTE(MED_NOM_PFL);SSCRUTE(_profilename);goto ERROR;
343     }
344 
345   if ( !_defaultlocalizationexist ) {
346     if ( _MEDattributeStringWr(_datagroup2,MED_NOM_GAU,MED_NAME_SIZE,localizationname) < 0) {
347       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
348       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);
349       SSCRUTE(MED_NOM_GAU);SSCRUTE(localizationname);goto ERROR;
350     }
351   }
352   /*Cree ou ouvre l'attribut MED_NOM_NBR */
353   if ( _MEDattributeIntWr(_datagroup3,MED_NOM_NBR,&((*_filter).nentity)) < 0) {
354     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
355     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
356     SSCRUTE(MED_NOM_NBR);ISCRUTE((*_filter).nentity);goto ERROR;
357   }
358 
359   /* Lit le nombre de points d'intégation et vérifie   */
360   /* que la localisation porte sur le meme type géométrique  */
361 
362   /* Dans le cas de champs aux noeuds par element, on stocke
363    * une localisation vide, et le nombre de noeuds dans l'attribut NGA
364    */
365   /*
366     TODO : ? SYMETRISATION MED_NODE_ELEMENT POUR MAILLAGE ?
367     TODO : DEUX MT CLES RESERVES POUR DES LOCALISATIONS PARTICULIERES
368     TODO : MED_NODESOFCELL_WITHOUTWEIGHT sans élément de réf & sans poids
369     TODO : MED_NODESOFCELL_WITHWEIGHT ?
370   */
371   if (entitytype == MED_NODE_ELEMENT ) {
372     if ( strlen(localizationname) != 0) {
373       MED_ERR_(_ret,MED_ERR_NOTNULL,MED_ERR_PARAMETER,localizationname);
374       ISCRUTE_int(entitytype);goto ERROR;
375     }
376     _nvaluesperentity = geotype % 100;
377   } else if (! strcmp(localizationname,MED_GAUSS_ELNO)) {
378     /* TODO: générer une erreur si on est en présence d'un élément de structure.*/
379     /* Les points de Gauss sont définis sur les noeuds de l'element (mot cle) */
380     /* le nombre de points de Gauss est egal au nombre de noeuds de l'element */
381     _nvaluesperentity = geotype % 100;
382     /*Impose t'on une localisation, sinon test si "" ?*/
383   } else if (strlen(localizationname))  {
384     strcat(_locgidname,localizationname);
385 
386     if ((_locgid = _MEDdatagroupOuvrir(fid,_locgidname)) < 0) {
387       MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_locgidname);
388       goto ERROR;
389     }
390 
391     if (_MEDattrEntierLire(_locgid,MED_NOM_NBR,&_nvaluesperentity) < 0) {
392       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
393       SSCRUTE(localizationname);SSCRUTE(MED_NOM_NBR);ISCRUTE(_nvaluesperentity);goto ERROR;
394     }
395 
396 
397     if ( entitytype == MED_STRUCT_ELEMENT ) {
398 
399       /*
400        * Lecture de l'attribut MED_NOM_NOM (nom du maillage support de section)
401        */
402       if ( _MEDattrStringLire(_locgid,MED_NOM_NOM,MED_NAME_SIZE,_sectionmeshname) < 0) {
403 	MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_locgidname);
404 	SSCRUTE(MED_NOM_NOM);SSCRUTE(_sectionmeshname);
405 	goto ERROR;
406       }
407 
408       if (strlen(_sectionmeshname) ) {
409 
410 	if ( _MEDgetSupportMeshNbOfEntities(fid,_sectionmeshname,NULL,NULL,NULL,
411 					    &_nsectioncell) < 0) {
412 	  MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDgetSupportMeshNbOfEntities");
413 	  SSCRUTE(_sectionmeshname);ISCRUTE(_nsectioncell);goto ERROR;
414 	}
415       }
416     }
417 
418     _nvaluesperentity*=_nsectioncell;
419 
420     if (_MEDattrEntierLire(_locgid,MED_NOM_GEO,&_intlocgeotype) < 0) {
421       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
422       SSCRUTE(localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE_int(_locgeotype);goto ERROR;
423     }
424     _locgeotype = (med_geometry_type) _intlocgeotype;
425 
426     if ( _locgeotype != geotype ) {
427       MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
428       SSCRUTE(localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE_int(_locgeotype);
429       ISCRUTE_int(geotype);goto ERROR;
430     }
431   }  else  {
432     _nvaluesperentity = MED_NO_IPOINT_INTERNAL ;
433   }
434 /*   strcpy(_localizationname,localizationname); */
435 
436   if (!_filterparameterexist) (*_filter).nvaluesperentity=_nvaluesperentity;
437 
438 
439 
440   /* Cree ou ouvre l'attribut MED_NOM_GAU         */
441   /* Ecriture de la localisation des pts de gauss  */
442   if ( _MEDattributeStringWr(_datagroup3,MED_NOM_GAU,MED_NAME_SIZE,localizationname) < 0) {
443       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
444       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
445       SSCRUTE(MED_NOM_GAU);SSCRUTE(localizationname);goto ERROR;
446   }
447 
448   /* Cree ou ouvre l'attribut MED_NOM_NGA         */
449   /* Ecriture de l'attribut portant le nombre de points de gauss  */
450   if ( _MEDattributeIntWr(_datagroup3,MED_NOM_NGA,&_nvaluesperentity) < 0) {
451     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
452     SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
453     SSCRUTE(MED_NOM_NGA);ISCRUTE(_nvaluesperentity);goto ERROR;
454   }
455 
456   /* TODO : ?MODE ECRASEMENT ?*/
457   /* Si une localisation par défaut existe déjà <=> Un profil par défaut existe déjà :
458      Si le profil courant est le profil par défaut met à jour la localisation par défaut */
459   if ( _defaultprofileexist && !strcmp((*_filter).profilename,_defaultprofilename) ) {
460     if ( _MEDattributeStringWr(_datagroup2,MED_NOM_GAU,MED_NAME_SIZE,localizationname) < 0) {
461 	  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
462 	  SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
463 	  SSCRUTE(MED_NOM_GAU);SSCRUTE(localizationname);goto ERROR;
464 	}
465       }
466 
467   if (!_filterparameterexist) {
468 
469 #ifdef _DEBUG_
470     ISCRUTE((*_filter).nentity              );
471     ISCRUTE((*_filter).nvaluesperentity     );
472     ISCRUTE((*_filter).nconstituentpervalue );
473     ISCRUTE((*_filter).constituentselect       );
474     ISCRUTE_int((*_filter).switchmode              );
475     ISCRUTE((*_filter).filterarraysize         );
476     ISCRUTE((*_filter).profilearraysize        );
477     ISCRUTE_int((*_filter).storagemode             );
478     SSCRUTE((*_filter).profilename             );
479 #endif
480 
481     if ( MEDfilterEntityCr(fid, (*_filter).nentity,         (*_filter).nvaluesperentity,
482 			   (*_filter).nconstituentpervalue, (*_filter).constituentselect,
483 			   (*_filter).switchmode,              (*_filter).storagemode,
484 			   (*_filter).profilename, MED_UNDEF_SIZE, NULL, &_paramfilter) < 0 ) {
485       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
486       goto ERROR;
487     }
488     _filter = &_paramfilter;
489   }
490 
491   /*CELA N'A PLUS DE SENS AVEC LE MODELE INTERNE 3.0*/
492   /* Vérifie si le profil a changé (l'API MED ne permet pas de modifier un profil existant) */
493   /*   if (strcmp(_profilename, _defaultprofilename)) */
494   /*     _profilehaschanged = 1;               le profil a changé*/
495   /*   else */
496   /*     _profilehaschanged = 0;               le profil n'a pas changé*/
497 
498 
499   /*
500    * Ecriture du champ
501    */
502 
503 
504   /* Tous les types med_field_type sont autorisés dans MEDfieldCr mais :
505      Avant la 3.3.0 seuls les types : MED_FLOAT64,MED_INT32 et MED_INT64 étaient autorisés dans MEDfieldValueAdvancedWr et seul le type med_int et med_float64 pouvaient être utilisés en C.
506       A l'écriture, si med_int=int  les champs MED_INT32 étaient stockés en interne en HDFINT32bits
507       A l'écriture, si med_int=long les champs MED_INT32 étaient stockés en interne en HDFINT64bits
508       A la lecture : - si med_int=int  le champ MED_INT32 est relu en en HDFINT32bit avec conversion 64->32 si necessaire
509                     - si med_int=long le champ MED_INT32 est relu en en HDFINT64bit avec conversion 32->64 si necessaire
510       A l'écriture, si med_int=int les champs MED_INT64 étaient interdits
511       A l'écriture, si med_int=long les champs MED_INT64 étaient stockés en interne en HDFINT64bits
512       A la lecture : - si med_int=int  le champ MED_INT64 ne pouvait pas être relu (pour prevenir la perte d'information)
513                     - si med_int=long le champ MED_INT64 est relu sans conversion
514   */
515 
516   switch(_fieldtype)
517     {
518     case MED_FLOAT64 :
519       if ( _MEDdatasetWr(_datagroup3,MED_NOM_CO,MED_FLOAT64,_filter,value) < 0) {
520 	MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_CO);
521 	SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
522 	goto ERROR;
523       }
524       break;
525 
526     case MED_INT32 :
527 #if defined(HAVE_F77INT64)
528       if ( _MEDdatasetWr(_datagroup3,MED_NOM_CO,MED_INT64,_filter,value) < 0) {
529 	MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_CO);
530 	SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
531 	goto ERROR;
532       }
533 #else
534       if ( _MEDdatasetWr(_datagroup3,MED_NOM_CO,MED_INT32,_filter,value) < 0){
535 	MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_CO);
536 	SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
537 	goto ERROR;
538       }
539 #endif
540       break;
541 
542     case MED_INT64 :
543 #if defined(HAVE_F77INT64)
544       if ( _MEDdatasetWr(_datagroup3,MED_NOM_CO,MED_INT64,_filter,value) < 0){
545 	MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_CO);
546 	SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
547 	goto ERROR;
548       }
549 #else
550       MESSAGE("Impossible d'ecrire le dataset de type MED_INT64 sur une plateforme dépourvue de int64 !");
551       goto ERROR;
552 #endif
553       break;
554 
555     default :
556       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_RANGE,MED_ERR_FIELD_MSG);
557       SSCRUTE(fieldname);ISCRUTE_int(_fieldtype);
558       goto ERROR;
559     }
560 
561 
562   /*
563    * On ferme tout
564    */
565 
566   _ret = 0;
567 
568  ERROR:
569 
570   if (!_filterparameterexist) {
571     if ( MEDfilterClose(_filter) < 0 ) {
572       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_FIELD_MSG);
573       SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
574       goto ERROR;
575     }
576   }
577 
578   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
579     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_profilename);
580     ISCRUTE_id(_datagroup3);
581   }
582 
583   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
584     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
585     ISCRUTE_id(_datagroup2);
586   }
587 
588   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
589     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
590     ISCRUTE_id(_datagroup1);
591   }
592 
593   if (_gid>0)            if (_MEDdatagroupFermer(_gid) < 0) {
594     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_gidname);
595     ISCRUTE_id(_gid);
596   }
597 
598   if (_locgid>0)     if (_MEDdatagroupFermer(_locgid) < 0) {
599     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_locgidname);
600     ISCRUTE_id(_locgid);
601   }
602 
603   va_end(params);
604   *fret = _ret;
605   return;
606 }
607 
608