MED fichier: Fichier source de UsesCase_MEDinterp_2.c

MED fichier

UsesCase_MEDinterp_2.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2023 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 2 : read an interpolation family with a direct access by name
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 const char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
33 med_geometry_type geotype =MED_NONE;
34 med_bool cellnodes =MED_FALSE;
35 med_int nbasisfunc =0;
36 med_int nvariable =0;
37 med_int maxdegree =0;
38 med_int nmaxcoefficient =0;
39 int basisfuncit =0;
40 int powerit =0;
41 med_int ncoefficient =0;
42 med_int* power =NULL;
43 med_float* coefficient =NULL;
44 int coefficientit =0;
45 int ret=-1;
46
47
48 /* file creation */
49 fid = MEDfileOpen("UsesCase_MEDinterp_1.med",MED_ACC_RDONLY);
50 if (fid < 0) {
51 MESSAGE("ERROR : file creation ...");
52 goto ERROR;
53 }
54
55 /* with direct access by the family name */
56 if (MEDinterpInfoByName(fid,interpname,&geotype,&cellnodes,&nbasisfunc,
57 &nvariable,&maxdegree,&nmaxcoefficient) < 0) {
58 MESSAGE("ERROR : interpolation function information ...");
59 goto ERROR;
60 }
61
62 /* read each basis function */
63 for ( basisfuncit=1; basisfuncit<= nbasisfunc; ++basisfuncit) {
64
65 if ((ncoefficient = MEDinterpBaseFunctionCoefSize(fid,interpname,basisfuncit) ) <0 ) {
66 MESSAGE("ERROR : read number of coefficient in the base function ...");
67 goto ERROR;
68 }
69
70 coefficient = (med_float*) calloc(sizeof(med_float),ncoefficient);
71 power = (med_int*) calloc(sizeof(med_int),nvariable*ncoefficient);
72
73 if (MEDinterpBaseFunctionRd(fid,interpname,basisfuncit,&ncoefficient,power,coefficient) < 0) {
74 MESSAGE("ERROR : read base function ...");
75 free(coefficient); free(power);
76 goto ERROR;
77 }
78
79 free(coefficient);
80 free(power);
81 }
82
83 ret=0;
84 ERROR:
85
86
87 /* close file */
88 if (MEDfileClose(fid) < 0) {
89 MESSAGE("ERROR : close file ...");
90 ret=-1;
91 }
92
93 return ret;
94 }
MED_ACC_RDONLY
Definition: med.h:122
med_geometry_type
int med_geometry_type
Definition: med.h:196
med_idt
hid_t med_idt
Definition: med.h:333
MED_FALSE
Definition: med.h:262
MEDinterpInfoByName
MEDC_EXPORT med_err MEDinterpInfoByName(const med_idt fid, const 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 nommée interpname.
Definition: MEDinterpInfoByName.c:41
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:344
med_bool
med_bool
Definition: med.h:262
med_float
double med_float
Definition: med.h:338
MED_NONE
#define MED_NONE
Definition: med.h:233
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
main
int main(int argc, char **argv)
Definition: UsesCase_MEDinterp_2.c:30
med_utils.h
med.h
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
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
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