MED fichier
test34.c
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2025 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 * - Nom du fichier : test34.c
20 *
21 * - Description : Tests d'existences des descriptions des objets med ayant
22 * créés une description par l'API de création de l'objet
23 *
24 *****************************************************************************/
25
26#include <med.h>
27#define MESGERR 1
28#include "med_utils.h"
29#include <string.h>
30
31#ifdef DEF_LECT_ECR
32#define MODE_ACCES MED_ACC_RDWR
33#elif DEF_LECT_AJOUT
34#define MODE_ACCES MED_ACC_RDEXT
35#else
36#define MODE_ACCES MED_ACC_CREAT
37#endif
38
39#define _a 0.446948490915965
40#define _b 0.091576213509771
41#define _p1 0.11169079483905
42#define _p2 0.0549758718227661
43
44int main (int argc, char **argv)
45{
46 med_idt fid = 0;
47 char meshname [MED_NAME_SIZE+1] = "maa1";
48 char supportmeshname [MED_NAME_SIZE+1] = "supportmaa1";
49 char fieldname [MED_NAME_SIZE+1] = "field1";
50 char jointname [MED_NAME_SIZE+1] = "joint1";
51 med_int meshdim = 2;
52 char axisname[2*MED_SNAME_SIZE+1] = "x y ";
53 char axisunit[2*MED_SNAME_SIZE+1] = "cm cm ";
54 med_bool objectexist = MED_FALSE;
55 med_bool descriptionexist = MED_FALSE;
56 char description0[MED_COMMENT_SIZE+1] = "un maillage pour test34";
57 char description1[MED_COMMENT_SIZE+1] = "++UN MAILLAGE POUR TEST34++";
58 char description2[MED_COMMENT_SIZE+1] = "";
59
60 /* Caractéristiques du model n° 1 de localisation des points de gauss pour le champ n°1*/
61 med_int ngauss1_1 = 6;
62 char locname[MED_NAME_SIZE+1] = "Model n1";
63 med_float refcoo1[12] = { -1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 };
64
65 /* Constantes */
66 med_float gscoo1_1[12] = { 2*_b-1, 1-4*_b, 2*_b-1, 2*_b-1, 1-4*_b,
67 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
68 med_float wg1_1[6] = { 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
69
70 char profilename[MED_NAME_SIZE+1] = "PROFIL(test34)";
71 med_int profil1[2] = { 2, 3 };
72
73 char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
74 const med_int nvariable=2;
75 const med_int maxdegree=1;
76 const med_int nmaxcoefficient=3;
77
78 char parametername[MED_NAME_SIZE+1] = "parametre1";
79
80 /* Creation du fichier "test34.med" */
81 if ((fid = MEDfileOpen("test34.med",MED_ACC_RDWR)) < 0) {
82 MESSAGE("Erreur a la creation du fichier test34.med");
83 return -1;
84 }
85
86 /* Si le fichier test34.med a déjà été généré par test34 */
87 if( MEDfileObjectExist(fid,MED_MESH,meshname,&objectexist) < 0) {
88 MESSAGE("Erreur inattendue de test de l'existence du maillage : ");
89 SSCRUTE(meshname);
90 }
91 if (objectexist) {
92 if( MEDfileObjectDescriptionExist(fid,MED_MESH,meshname,&descriptionexist) < 0) {
93 MESSAGE("Erreur inattendue de test de l'existence d'une description de maillage : ");
94 SSCRUTE(meshname);
95 }
96 if ( descriptionexist == MED_FALSE ) {
97 MESSAGE("Erreur d'absence anormale de la description du maillage : ");
98 SSCRUTE(meshname);
99 return -1;
100 }
101 }
102
103 if (MEDmeshCr( fid, meshname, meshdim, meshdim, MED_UNSTRUCTURED_MESH,
104 description0,"s", MED_SORT_DTIT,
105 MED_CARTESIAN, axisname, axisunit) < 0) {
106 MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(meshname);
107 return -1;
108 }
109
110 if( MEDfileObjectDescriptionExist(fid,MED_MESH,meshname,&descriptionexist) < 0) {
111 MESSAGE("Erreur au test d'existence de la description du maillage : ");
112 SSCRUTE(meshname);
113 return -1;
114 }
115 if ( descriptionexist != MED_TRUE ) {
116 MESSAGE("Erreur d'absence de la description du maillage : ");
117 SSCRUTE(meshname);
118 return -1;
119 } else {
120 if( MEDfileObjectDescriptionRd(fid,MED_MESH,meshname,description2) < 0) {
121 MESSAGE("Erreur à la lecture de la description du maillage : ");
122 SSCRUTE(meshname);
123 return -1;
124 }
125 SSCRUTE(description2);
126 description2[0]='\0';
127 }
128
129 if( MEDfileObjectDescriptionWr(fid,MED_MESH,meshname,description1) < 0) {
130 MESSAGE("Erreur à l'écrasement de la description du maillage : ");
131 SSCRUTE(meshname);
132 return -1;
133 }
134
135
136 if ( MEDfieldCr(fid,fieldname,MED_INT,1,"comp1","unit1","dtunit1", meshname ) < 0) {
137 MESSAGE("Erreur à la création du champ : ");SSCRUTE(fieldname);
138 return -1;
139 }
140
141 strncpy(description1,"un champ pour test34",MED_COMMENT_SIZE+1);
142 if( MEDfileObjectDescriptionWr(fid,MED_FIELD,fieldname,description1) < 0) {
143 MESSAGE("Erreur à l'écriture de la description du champ : ");
144 SSCRUTE(fieldname);
145 return -1;
146 }
147
148 if (MEDsupportMeshCr( fid, supportmeshname, meshdim, meshdim, "un maillage support pour test34",
149 MED_CARTESIAN,axisname, axisunit) < 0) {
150 MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(supportmeshname);
151 return -1;
152 }
153
154 if( MEDfileObjectDescriptionRd(fid,MED_MESH_SUPPORT,supportmeshname,description2) < 0) {
155 MESSAGE("Erreur à la lecture de la description du maillage support: ");
156 SSCRUTE(supportmeshname);
157 return -1;
158 }
159 SSCRUTE(description2);
160 description2[0]='\0';
161
162 if( MEDfileObjectDescriptionWr(fid,MED_MESH_SUPPORT,supportmeshname,"++un maillage support pour test34++") < 0) {
163 MESSAGE("Erreur à l'écrasement de la description du maillage support : ");
164 SSCRUTE(supportmeshname);
165 return -1;
166 }
167
169 MESSAGE("ERROR : creating struct element");
170 return -1;
171 }
172
173 if( MEDfileObjectDescriptionWr(fid,MED_ELSTRUCT,MED_PARTICLE_NAME,"++un élément de structure pour test34++") < 0) {
174 MESSAGE("Erreur à l'écritue de la description de l'élémnent de structure : ");
176 return -1;
177 }
178
179
180 if (MEDlocalizationWr(fid, locname, MED_TRIA6, MED_TRIA6/100, refcoo1, MED_FULL_INTERLACE,
181 ngauss1_1, gscoo1_1, wg1_1,
183 MESSAGE("Erreur à la création du modèle de localisation n°1 : ");
184 return -1;
185 };
186
187 strncpy(description1,"une localisation de points d'intégration pour test34",MED_COMMENT_SIZE+1);
188 if( MEDfileObjectDescriptionWr(fid,MED_LOCALIZATION,locname,description1) < 0) {
189 MESSAGE("Erreur à l'écriture de la description de localisation de points d'intégration : ");
190 SSCRUTE(locname);
191 return -1;
192 }
193
194 /* Creation d'un profil (selection du deuxieme élément de valr1_1) */
195 /* On n'utilise que la première valeur (2) du profil */
196 if ( MEDprofileWr(fid,profilename,1,profil1) < 0) {
197 MESSAGE("Erreur à l'écriture du profile : ");
198 SSCRUTE(profilename);
199 return -1;
200 };
201
202 strncpy(description1,"un profil de champ pour test34",MED_COMMENT_SIZE+1);
203 if( MEDfileObjectDescriptionWr(fid,MED_PROFILE,profilename,description1) < 0) {
204 MESSAGE("Erreur à l'écriture de la description de profile : ");
205 SSCRUTE(profilename);
206 return -1;
207 }
208
209
210 if (MEDinterpCr(fid, interpname, MED_TRIA3, MED_FALSE,
211 nvariable, maxdegree, nmaxcoefficient) < 0) {
212 MESSAGE("ERROR : interpolation family creation ...");
213 return -1;
214 }
215
216 strncpy(description1,"une interpolation de champ pour test34",MED_COMMENT_SIZE+1);
217 if( MEDfileObjectDescriptionWr(fid,MED_INTERPOLATION,interpname,description1) < 0) {
218 MESSAGE("Erreur à l'écriture de la description de profile : ");
219 SSCRUTE(interpname);
220 return -1;
221 }
222
223 /* Creation d'un variable scalaire flottante */
224 strncpy(description1,"un parametre scalaire pour test34",MED_COMMENT_SIZE+1);
225 if (MEDparameterCr(fid,parametername,MED_FLOAT64,description1,"ms") < 0) {
226 MESSAGE("Erreur a la creation d'une variable scalaire flottante");
227 return -1;
228 }
229
230 if( MEDfileObjectDescriptionExist(fid,MED_NUMERICAL_DATA,parametername,&descriptionexist) < 0) {
231 MESSAGE("Erreur au test d'existence de la description du paramètre scalaire : ");
232 SSCRUTE(parametername);
233 return -1;
234 }
235 if ( descriptionexist != MED_TRUE ) {
236 MESSAGE("Erreur d'absence de la description du paramètre scalaire : ");
237 SSCRUTE(parametername);
238 return -1;
239 } else {
240 if( MEDfileObjectDescriptionRd(fid,MED_NUMERICAL_DATA,parametername,description2) < 0) {
241 MESSAGE("Erreur à la lecture de la description du paramètre scalaire : ");
242 SSCRUTE(parametername);
243 return -1;
244 }
245 SSCRUTE(description2);
246 description2[0]='\0';
247 }
248 if( MEDfileObjectDescriptionWr(fid,MED_NUMERICAL_DATA,parametername,"++un paramètre scalaire pour test34++") < 0) {
249 MESSAGE("Erreur à l'écritue de la description d'un paramètre scalaire : ");
250 SSCRUTE(parametername);
251 return -1;
252 }
253
254 /* Fermeture du fichier */
255 if (MEDfileClose(fid) < 0) {
256 MESSAGE("Erreur a la fermeture du fichier :");
257 return -1;
258 }
259
260 return 0;
261}
#define _b
#define _p2
#define _p1
#define _a
#define MED_NAME_SIZE
#define MED_SNAME_SIZE
#define MED_NO_INTERPOLATION
#define MED_PARTICLE_NAME
#define MED_COMMENT_SIZE
#define MED_NO_MESH_SUPPORT
#define MED_NO_MESHNAME
#define SSCRUTE(chaine)
#define MESSAGE(chaine)
MEDC_EXPORT med_err MEDfieldCr(const med_idt fid, const char *const fieldname, const med_field_type fieldtype, const med_int ncomponent, const char *const componentname, const char *const componentunit, const char *const dtunit, const char *const meshname)
Cette fonction crée un champ dans un fichier.
Definition MEDfieldCr.c:44
MEDC_EXPORT med_err MEDfileObjectDescriptionExist(const med_idt fid, const med_class medclass, const char *const objectname, med_bool *const descriptionexist)
Interroge le fichier fid pour tester l'existence d'une description associée à l'objet objectname de t...
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
MEDC_EXPORT med_err MEDfileObjectDescriptionWr(const med_idt fid, const med_class medclass, const char *const objectname, const char *const description)
Ecrit une description associée à l'objet objectname de type med_class dans le fichier fid .
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition MEDfileOpen.c:42
MEDC_EXPORT med_err MEDfileObjectExist(const med_idt fid, const med_class medclass, const char *const objectname, med_bool *const objectexist)
Interroge le fichier fid pour tester l'existence de l'objet objectname de type med_class.
MEDC_EXPORT med_err MEDfileObjectDescriptionRd(const med_idt fid, const med_class medclass, const char *const objectname, char *const description)
Lit une description associée à l'objet objectname de type med_class dans le fichier fid .
MEDC_EXPORT med_err MEDinterpCr(const med_idt fid, const char *const interpname, const med_geometry_type geotype, const med_bool cellnodes, const med_int nvariable, const med_int maxdegree, const med_int nmaxcoef)
Cette routine permet de créer une nouvelle fonction d'interpolation polynômiale nommée interpname.
Definition MEDinterpCr.c:43
MEDC_EXPORT med_err MEDlocalizationWr(const med_idt fid, const char *const localizationname, const med_geometry_type geotype, const med_int spacedimension, const med_float *const elementcoordinate, const med_switch_mode switchmode, const med_int nipoint, const med_float *const ipointcoordinate, const med_float *const weight, const char *const geointerpname, const char *const ipointstructmeshname)
Cette routine permet l'écriture d'une localisation localizationname de points d'intégration dans/auto...
MEDC_EXPORT med_err MEDmeshCr(const med_idt fid, const char *const meshname, const med_int spacedim, const med_int meshdim, const med_mesh_type meshtype, const char *const description, const char *const dtunit, const med_sorting_type sortingtype, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage dans un fichier.
Definition MEDmeshCr.c:45
MEDC_EXPORT med_err MEDparameterCr(const med_idt fid, const char *const paramname, const med_parameter_type paramtype, const char *const description, const char *const dtunit)
Cette routine permet la création d'un paramètre numérique scalaire.
MEDC_EXPORT med_err MEDprofileWr(const med_idt fid, const char *const profilename, const med_int profilesize, const med_int *const profilearray)
Cette routine permet d'écrire un profil dans un fichier MED.
MEDC_EXPORT med_geometry_type MEDstructElementCr(const med_idt fid, const char *const modelname, const med_int modeldim, const char *const supportmeshname, const med_entity_type sentitytype, const med_geometry_type sgeotype)
Cette routine permet de créer un nouveau modèle d'éléments de structure dans un fichier MED.
MEDC_EXPORT med_err MEDsupportMeshCr(const med_idt fid, const char *const supportmeshname, const med_int spacedim, const med_int meshdim, const char *const description, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage support.
int main(int argc, char **argv)
Definition test34.c:44