MED fichier: Fichier source de UsesCase_MEDinterp_3.c

MED fichier

- Documentation MED
- Guides d'utilisation
- Guides de référence

UsesCase_MEDinterp_3.c
Aller à la documentation de ce fichier.
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 * Interp use case 1 : read an interpolation family with a generic access by an iterator.
20 * In this example, the interpolation family can be used with
21 * the TEMPERATURE field of UsesCase_MEDfield_10 use case
22 */
23
24 #include <med.h>
25 #define MESGERR 1
26 #include <med_utils.h>
27
28 #include <string.h>
29
30 int main (int argc, char **argv) {
31 med_idt fid;
32 char interpname[MED_NAME_SIZE+1]="";
33 med_int ninterp =0;
34 int it =0;
35 med_geometry_type geotype =MED_NONE;
36 med_bool cellnodes =MED_FALSE;
37 med_int nbasisfunc =0;
38 med_int nvariable =0;
39 med_int maxdegree =0;
40 med_int nmaxcoefficient =0;
41 int basisfuncit =0;
42 int powerit =0;
43 med_int ncoefficient =0;
44 med_int* power =NULL;
45 med_float* coefficient =NULL;
46 int coefficientit =0;
47 int ret=-1;
48
49
50 /* file creation */
51 fid = MEDfileOpen("UsesCase_MEDinterp_1.med",MED_ACC_RDONLY);
52 if (fid < 0) {
53 MESSAGE("ERROR : file creation ...");
54 goto ERROR;
55 }
56
57 /* how many interpolation family in the file ? */
58 if ((ninterp = MEDnInterp(fid)) < 0) {
59 MESSAGE("ERROR : read number of interpolation ...");
60 goto ERROR;
61 }
62
63 /* read each interpolation family */
64 /* with an access by an iterator */
65 for (it=1; it<= ninterp; it++) {
66
67 if (MEDinterpInfo(fid,it,interpname,&geotype,&cellnodes,&nbasisfunc,
68 &nvariable,&maxdegree,&nmaxcoefficient) < 0) {
69 MESSAGE("ERROR : interpolation function information ...");
70 goto ERROR;
71 }
72
73 /* read each basis function */
74 for ( basisfuncit=1; basisfuncit<= nbasisfunc; ++basisfuncit) {
75 if ((ncoefficient = MEDinterpBaseFunctionCoefSize(fid,interpname,basisfuncit) ) <0 ) {
76 MESSAGE("ERROR : read number of coefficient in the base function ...");
77 goto ERROR;
78 }
79
80 coefficient = (med_float*) calloc(sizeof(med_float),ncoefficient);
81 power = (med_int*) calloc(sizeof(med_int),nvariable*ncoefficient);
82
83 if (MEDinterpBaseFunctionRd(fid,interpname,basisfuncit,&ncoefficient,power,coefficient) < 0) {
84 MESSAGE("ERROR : read base function ...");
85 free(coefficient); free(power);
86 goto ERROR;
87 }
88
89 free(coefficient);
90 free(power);
91 }
92
93 }
94
95 ret=0;
96 ERROR:
97
98 /* close file */
99 if (MEDfileClose(fid) < 0) {
100 MESSAGE("ERROR : close file ...");
101 ret=-1;
102 }
103
104 return ret;
105 }
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
med_utils.h
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:41
med_float
double med_float
Definition: med.h:331
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
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
MEDinterpBaseFunctionCoefSize
MEDC_EXPORT med_int MEDinterpBaseFunctionCoefSize(const med_idt fid, const char *const interpname, const med_int basisfuncit)
Cette routine retourne ne nombre de coefficients/monômes de la fonction de base/forme n° basisfunctit...
Definition: MEDinterpBaseFunctionCoeffSize.c:37
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
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_NONE
#define MED_NONE
Definition: med.h:228
med_int
int med_int
Definition: med.h:337
MED_FALSE
Definition: med.h:257
main
int main(int argc, char **argv)
Definition: UsesCase_MEDinterp_3.c:30
med_idt
hid_t med_idt
Definition: med.h:326
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:79
med.h
med_bool
med_bool
Definition: med.h:257
med_geometry_type
int med_geometry_type
Definition: med.h:191
MED_ACC_RDONLY
Definition: med.h:118