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
MEDstructureCoordEcr(med_idt fid,char * maillage,med_int mdim,med_int * structure)27 MEDstructureCoordEcr(med_idt fid,char *maillage,med_int mdim,med_int *structure)
28 {
29   med_idt maaid, noeid, dataset;
30   med_err ret;
31   med_size dimd[1];
32   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
33   char nom_dataset[MED_TAILLE_NOM_ENTITE+1];
34   char nom_attribut[MED_TAILLE_NOM_ENTITE+1];
35   med_int att;
36   med_maillage maillage_type;
37   med_type_grille type;
38   med_int i;
39 
40   /*
41    * On inhibe le gestionnaire d'erreur HDF
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,maillage);
52   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
53       return -1;
54 
55   /*
56    * Si le maillage est de type MED_NON_STRUCTURE => erreur
57    */
58   if ((ret = _MEDattrEntierLire(maaid,MED_NOM_TYP,&att)) < 0)
59     return -1;
60   maillage_type = (med_maillage) att;
61   if (maillage_type == MED_NON_STRUCTURE)
62     return -1;
63 
64   /*
65    * Si la grille n'est pas de type MED_GRILLE_STANDARD
66    * => erreur
67    */
68   if ((ret = _MEDattrEntierLire(maaid,MED_NOM_GTY,&att)) < 0)
69     return -1;
70   type = (med_type_grille) att;
71   if (type != MED_GRILLE_STANDARD)
72     return -1;
73 
74   /*
75    * Si le groupe HDF "NOE" n'existe pas on le cree
76    */
77   if ((noeid = _MEDdatagroupOuvrir(maaid,MED_NOM_NOE)) < 0)
78     if ((noeid = _MEDdatagroupCreer(maaid,MED_NOM_NOE)) < 0)
79       return -1;
80 
81   /*
82    * On ouvre le dataset HDF pour y placer les attributs
83    * (taille de chaque dimension)
84    */
85   strcpy(nom_dataset,MED_NOM_COO);
86   if ((dataset = _MEDdatasetOuvrir(noeid,nom_dataset)) < 0)
87     return -1;
88 
89 
90   /*
91    * Attribut NBR (taille du tableau d'indices)
92    */
93   for (i=0;i<mdim;i++) {
94 
95     switch(i) {
96     case 0 :
97       strcpy(nom_attribut,MED_NOM_IN1);
98       break;
99 
100     case 1 :
101       strcpy(nom_attribut,MED_NOM_IN2);
102       break;
103 
104     case 2 :
105       strcpy(nom_attribut,MED_NOM_IN3);
106       break;
107 
108     default :
109       return -1;
110     }
111 
112     att = *(structure+i);
113     if ((ret = _MEDattrEntierEcrire(dataset,nom_attribut,&att)) < 0)
114       return -1;
115   }
116 
117   /*
118    * On ferme tout
119    */
120   if ((ret = _MEDdatasetFermer(dataset)) < 0)
121     return -1;
122   if ((ret = _MEDdatagroupFermer(noeid)) < 0)
123     return -1;
124   if ((ret = _MEDdatagroupFermer(maaid)) < 0)
125     return -1;
126 
127   return 0;
128 }
129