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 
23 #include <stdlib.h>
24 #include <string.h>
25 
26 med_err
MEDnumEcr(med_idt fid,char * maa,med_int * num,med_int n,med_entite_maillage type_ent,med_geometrie_element type_geo)27 MEDnumEcr(med_idt fid,char *maa, med_int *num, med_int n,
28 	  med_entite_maillage type_ent,med_geometrie_element type_geo)
29 {
30   med_idt root, maaid, entid, geoid, dataset;
31   med_err ret;
32   med_size dimd[1];
33   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
34   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
35   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
36   med_entite_maillage _type_ent=type_ent;
37 
38   if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
39 
40   /*
41    * On inhibe le gestionnaire d'erreur HDF 5
42    */
43   _MEDmodeErreurVerrouiller();
44 if (MEDcheckVersion(fid) < 0) return -1;
45 
46 
47   /*
48    * Si le maillage n'existe pas => erreur
49    */
50   strcpy(chemin,MED_MAA);
51   strcat(chemin,maa);
52   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
53       return -1;
54 
55   /*
56    * On met a jour le nom du Data Group representant
57    * le type des entites
58    */
59    if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
60      return -1;
61 
62    /*
63     * Si le Data Group des entites n'existe pas on le cree
64     */
65    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
66      if ((root = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
67        return -1;
68 
69    /*
70     * Pour les mailles, les faces et le aretes, on cree
71     * s'il n'existe pas le Data Group du type geometrique
72     */
73    if ((_type_ent==MED_MAILLE)||(_type_ent==MED_FACE)||(_type_ent==MED_ARETE))
74      {
75        if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
76 	 return -1;
77 
78        if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
79 	 if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
80 	   return -1;
81      }
82    else
83      geoid = -1;
84 
85    /*
86     * Creation du Data Set "NUM"
87     */
88    if (geoid == -1)
89      root = entid;
90    else
91      root = geoid;
92    dimd[0] = n;
93 #if defined(HAVE_F77INT64)
94    if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
95 				(unsigned char*) num)) < 0)
96      return -1;
97 #else
98    if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
99 				(unsigned char*) num)) < 0)
100      return -1;
101 #endif
102 
103   /*
104    * Attribut NBR (nombre de noeuds)
105    */
106    if ((dataset = _MEDdatasetOuvrir(root,MED_NOM_NUM)) < 0)
107      return -1;
108    if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
109      return -1;
110 
111    /*
112     * On ferme tout
113     */
114    if ((ret = _MEDdatasetFermer(dataset)) < 0)
115      return -1;
116    if (geoid != -1)
117      if ((ret = _MEDdatagroupFermer(geoid)) < 0)
118        return -1;
119    if ((ret = _MEDdatagroupFermer(entid)) < 0)
120      return -1;
121    if ((ret = _MEDdatagroupFermer(maaid)) < 0)
122      return -1;
123 
124   return 0;
125 }
126 
127 
128 
129