MED fichier
Test_MEDinterpBaseFunctionRd.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2021 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 #include <med.h>
19 #define MESGERR 1
20 #include <med_utils.h>
21 #include <string.h>
22 
23 #ifdef DEF_LECT_ECR
24 #define MODE_ACCES MED_ACC_RDWR
25 #elif DEF_LECT_AJOUT
26 #define MODE_ACCES MED_ACC_RDEXT
27 #else
28 #define MODE_ACCES MED_ACC_CREAT
29 #endif
30 
31 int main (int argc, char **argv)
32 
33 {
34  med_err _ret=-1;
35  med_idt _fid=0;
36 
37  med_int _ninterp=0;
38  int _interpit =0;
39  char _interpname[MED_NAME_SIZE+1]="";
40  med_geometry_type _geotype =MED_NONE;
41  med_bool _cellnodes =MED_FALSE;
42  med_int _nbasisfunc =0;
43  med_int _nvariable =0;
44  med_int _maxdegree =0;
45  med_int _nmaxcoefficient =0;
46  int _basisfuncit =0;
47  int _powerit =0;
48  med_int _ncoefficient =0;
49  med_int* _power =NULL;
50  med_float* _coefficient =NULL;
51  int _coefficientit =0;
52 
53 
54  /* Ouverture en mode creation du fichier "current.med" */
55  _fid = MEDfileOpen("current.med",MED_ACC_RDONLY);
56  if (_fid < 0) {
57  MESSAGE("Erreur a la creation du fichier current.med");
58  return -1;
59  }
60 
61  if ( (_ninterp = MEDnInterp(_fid)) <0) _ret=_ninterp;
62 
63  ISCRUTE(_ninterp);
64 
65  for ( _interpit=1; _interpit<= _ninterp; ++_interpit) {
66 
67  if ( (_ret = MEDinterpInfo(_fid,
68  _interpit,
69  _interpname,
70  &_geotype,
71  &_cellnodes,
72  &_nbasisfunc,
73  &_nvariable,
74  &_maxdegree,
75  &_nmaxcoefficient
76  ) <0) ) {
77  MESSAGE("Erreur à la demande d'information de la fonction d'interpolation n°");
78  ISCRUTE(_interpit);
79  goto ERROR;
80  }
81 
82  fprintf(stdout,"Fonction d'interpolation n° %d |%s| sur le type géométrique n° %d\n",
83  _interpit,_interpname, _geotype);
84 
85  if ( _cellnodes )
86  if ( _nbasisfunc == (_geotype % 100) )
87  fprintf(stdout,"\t Les noeuds de construction sont les noeuds de la maille de référence.\n");
88  else {
89  MESSAGE("Erreur : le nombre de noeuds de construction "\
90  "est différent du nombre de noeuds de la maille de référence.\n");
91  ISCRUTE(_nbasisfunc); ISCRUTE(_geotype % 100);
92  }
93 
94  if ( _nvariable != (_geotype / 100) ) {
95  MESSAGE("Erreur : le nombre de variables "\
96  "est différent de la dimension de l'espace de la maille de référence.\n");
97  ISCRUTE(_nvariable); ISCRUTE (_geotype / 100);
98  } else
99  fprintf(stdout,"\t Il y a %d fonctions de base avec %d variables\n ",_nbasisfunc,_nvariable);
100  fprintf(stdout,"\t Le degré maximum des fonctions de base est %d et possèdent au maximum %d coefficients\n"
101  ,_maxdegree,_nmaxcoefficient);
102 
103 
104  _coefficient = (med_float*) calloc(sizeof(med_float),_nmaxcoefficient);
105  _power = (med_int*) calloc(sizeof(med_int),_nvariable*_nmaxcoefficient);
106 
107  for ( _basisfuncit=1; _basisfuncit<= _nbasisfunc; ++_basisfuncit) {
108 
109 
110  if ( (_ret = MEDinterpBaseFunctionRd( _fid,
111  _interpname,
112  _basisfuncit,
113  &_ncoefficient,
114  _power,
115  _coefficient
116  ) <0) ) {
117  MESSAGE("Erreur à la lecture de la fonction de base n°");ISCRUTE(_basisfuncit);goto ERROR;
118  } else {
119  fprintf(stdout,"\n\t Tableau de coefficients de la fonctions de base n° %d :\n\t",_basisfuncit);
120  for ( _coefficientit=0; _coefficientit< _ncoefficient; ++_coefficientit)
121  fprintf(stdout," %4f ",_coefficient[_coefficientit]);
122 
123  fprintf(stdout,"\n\t Tableau de puissances de la fonctions de base n° %d :\n\t",_basisfuncit);
124  for ( _powerit=0; _powerit< _nvariable*_ncoefficient; ++_powerit)
125  fprintf(stdout," %4d ",_power[_powerit]);
126  }
127  }
128  fprintf(stdout,"\n");
129  free(_coefficient);
130  free(_power);
131 
132  }
133 
134  _ret=0;
135  ERROR:
136  if (MEDfileClose(_fid) < 0) {
137  MESSAGE("ERROR : file closing");
138  return -1;
139  }
140 
141  return _ret;
142 
143 }
144 
MEDnInterp
MEDC_EXPORT med_int MEDnInterp(const med_idt fid)
Cette routine renvoie le nombre d'interpolations disponibles dans le fichier.
Definition: MEDnInterp.c:34
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
med_geometry_type
int med_geometry_type
Definition: med.h:194
med_idt
hid_t med_idt
Definition: med.h:331
MED_ACC_RDONLY
Definition: med.h:120
med_err
herr_t med_err
Definition: med.h:332
MED_FALSE
Definition: med.h:260
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
med.h
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
med_bool
med_bool
Definition: med.h:260
med_float
double med_float
Definition: med.h:336
main
int main(int argc, char **argv)
Definition: Test_MEDinterpBaseFunctionRd.c:31
MED_NONE
#define MED_NONE
Definition: med.h:231
MEDinterpInfo
MEDC_EXPORT med_err MEDinterpInfo(const med_idt fid, const int interpit, char *const interpname, med_geometry_type *const geotype, med_bool *const cellnode, med_int *const nbasisfunc, med_int *const nvariable, med_int *const maxdegree, med_int *const nmaxcoef)
Cette fonction informe des caractéristiques de la fonction d'interpolation n° interpit.
Definition: MEDinterpInfo.c:43
MEDinterpBaseFunctionRd
MEDC_EXPORT med_err MEDinterpBaseFunctionRd(const med_idt fid, const char *const interpname, const int basisfuncit, med_int *const ncoef, med_int *const power, med_float *const coefficient)
Cette routine permet la lecture d'une fonction de base/forme de l'interpolation interpname.
Definition: MEDinterpBaseFunctionRd.c:41
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
med_utils.h