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 <string.h>
24 #include <stdlib.h>
25 
26 extern int mode_interlace;
27 
28 med_err
MEDcoordLire(med_idt fid,char * maa,med_int mdim,med_float * coo,med_mode_switch mode_coo,med_int numco,med_int * pfltabtmp,med_size psize,med_repere * type_rep,char * nom,char * unit)29 MEDcoordLire(med_idt fid, char *maa, med_int mdim, med_float *coo,
30 	     med_mode_switch mode_coo,med_int numco,
31 	     med_int * pfltabtmp, med_size psize, med_repere *type_rep, char *nom, char *unit)
32 {
33   med_idt   maaid, noeid, dataset;
34   med_err   ret;
35   char      chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
36   int       i,j;
37   med_float *new_coo;
38   med_int   type_rep_int;
39   med_size * pfltab;
40 
41   /*
42    * On inhibe le gestionnaire d'erreur
43    */
44   _MEDmodeErreurVerrouiller();
45 if (MEDcheckVersion(fid) < 0) return -1;
46 
47 
48   /*
49    * Si le maillage n'existe pas => erreur
50    * Sinon on recupere sa dimension au passage
51    */
52   strcpy(chemin,MED_MAA);
53   strcat(chemin,maa);
54   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
55       return -1;
56 
57   /*
58    * Si le Data Group "NOE" n'existe pas => erreur
59    */
60   if ((noeid = _MEDdatagroupOuvrir(maaid,MED_NOM_NOE)) < 0)
61       return -1;
62 
63   /*
64    * Convertion de med_int en med_size
65    */
66   if ( psize != MED_NOPF ) {
67     pfltab = (med_size *) malloc (sizeof(med_size)*psize);
68     for (i=0;i<psize;i++)
69       pfltab[i] = (med_size) pfltabtmp[i];
70   }
71 
72   /*
73    * Lecture du Data Set "COO"
74    */
75   if ((ret = _MEDdatasetNumLire(noeid,MED_NOM_COO,MED_FLOAT64,
76 				mode_coo,mdim,numco,
77 				psize,MED_COMPACT,MED_PFL_NON_COMPACT,pfltab,MED_NOPG,0,
78 				(unsigned char*) coo)) < 0)
79     return -1;
80 
81 
82   /*
83    * On re-ouvre le Data Set "COO" pour y lire des attributs
84    */
85   if ((dataset = _MEDdatasetOuvrir(noeid,MED_NOM_COO)) < 0)
86     return -1;
87 
88   /*
89    * L'attribut "REP"
90    */
91   if ((ret = _MEDattrEntierLire(dataset,MED_NOM_REP,&type_rep_int)) < 0)
92     return -1;
93   else
94     *type_rep = (med_repere) type_rep_int;
95 
96   /*
97    * Attribut "NOM"
98    */
99   if ((ret = _MEDattrStringLire(dataset,MED_NOM_NOM,mdim*MED_TAILLE_PNOM,
100 				nom)) < 0)
101     return -1;
102 
103   /*
104    * Attribut "UNI"
105    */
106   if ((ret = _MEDattrStringLire(dataset,MED_NOM_UNI,mdim*MED_TAILLE_PNOM,
107 				unit)) < 0)
108     return -1;
109 
110   /*
111    * On ferme tout
112    */
113   if ( psize != MED_NOPF ) free(pfltab);
114 
115   if ((ret = _MEDdatasetFermer(dataset)) < 0)
116     return -1;
117   if ((ret = _MEDdatagroupFermer(noeid)) < 0)
118     return -1;
119   if ((ret = _MEDdatagroupFermer(maaid)) < 0)
120     return -1;
121 
122   return 0;
123 }
124