MED fichier
test34b.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 : test34b.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 familyname [MED_NAME_SIZE+1] = "famille1";
49 char groupname [2*MED_LNAME_SIZE+1] = MED_LNAME_BLANK MED_LNAME_BLANK;
50 char supportmeshname [MED_NAME_SIZE+1] = "supportmaa1";
51 char fieldname [MED_NAME_SIZE+1] = "field1";
52 char jointname [MED_NAME_SIZE+1] = "joint1";
53 med_int meshdim = 2;
54 char axisname[2*MED_SNAME_SIZE+1] = "x y ";
55 char axisunit[2*MED_SNAME_SIZE+1] = "cm cm ";
56 med_bool objectexist = MED_FALSE;
57 med_bool descriptionexist = MED_FALSE;
58 char description0[MED_COMMENT_SIZE+1] = "un maillage pour test34b";
59 char description1[MED_COMMENT_SIZE+1] = "++UN MAILLAGE POUR TEST34B++";
60 char description2[MED_COMMENT_SIZE+1] = "";
61
62 /* Caractéristiques du model n° 1 de localisation des points de gauss pour le champ n°1*/
63 med_int ngauss1_1 = 6;
64 char locname[MED_NAME_SIZE+1] = "Model n1";
65 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 };
66
67 /* Constantes */
68 med_float gscoo1_1[12] = { 2*_b-1, 1-4*_b, 2*_b-1, 2*_b-1, 1-4*_b,
69 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
70 med_float wg1_1[6] = { 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
71
72 char profilename[MED_NAME_SIZE+1] = "PROFIL(test34b)";
73 med_int profil1[2] = { 2, 3 };
74
75 char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
76 const med_int nvariable=2;
77 const med_int maxdegree=1;
78 const med_int nmaxcoefficient=3;
79
80 char parametername[MED_NAME_SIZE+1] = "parametre1";
81 med_path medpath;
82
83 /* Creation du fichier "test34b.med" */
84 if ((fid = MEDfileOpen("test34b.med",MED_ACC_RDWR)) < 0) {
85 MESSAGE("Erreur a la creation du fichier test34b.med");
86 return -1;
87 }
88
89 /* Si le fichier test34b.med a déjà été généré par test34b */
90 medpath.medclass=MED_MESH;medpath.nname=1; medpath.name[0]=meshname;
91 if( MEDfileObjectExist(fid,MED_MESH,meshname,&objectexist) < 0) {
92 if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
93 MESSAGE("Erreur inattendue du fait de l'existence du 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( MEDfileObjectDescriptionExistByPath(fid,&medpath,&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( MEDfileObjectDescriptionRdByPath(fid,&medpath,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( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
130 MESSAGE("Erreur à l'écrasement de la description du maillage : ");
131 SSCRUTE(meshname);
132 return -1;
133 }
134
135 if ( MEDfieldCr(fid,fieldname,MED_INT,1,"comp1","unit1","dtunit1", meshname ) < 0) {
136 MESSAGE("Erreur à la création du champ : ");SSCRUTE(fieldname);
137 return -1;
138 }
139
140 strncpy(description1,"un champ pour test34b",MED_COMMENT_SIZE+1);
141 medpath.medclass=MED_FIELD;medpath.nname=1; medpath.name[0]=fieldname;
142 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,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 test34b",
149 MED_CARTESIAN,axisname, axisunit) < 0) {
150 MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(supportmeshname);
151 return -1;
152 }
153
154 medpath.medclass=MED_MESH_SUPPORT;medpath.nname=1; medpath.name[0]=supportmeshname;
155 if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
156 MESSAGE("Erreur à la lecture de la description du maillage support: ");
157 SSCRUTE(supportmeshname);
158 return -1;
159 }
160 SSCRUTE(description2);
161 description2[0]='\0';
162
163 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,"++un maillage support pour test34b++") < 0) {
164 MESSAGE("Erreur à l'écrasement de la description du maillage support : ");
165 SSCRUTE(supportmeshname);
166 return -1;
167 }
168
170 MESSAGE("ERROR : creating struct element");
171 return -1;
172 }
173
174 medpath.medclass=MED_ELSTRUCT;medpath.nname=1; medpath.name[0]=MED_PARTICLE_NAME;
175 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,"++un élément de structure pour test34b++") < 0) {
176 MESSAGE("Erreur à l'écritue de la description de l'élémnent de structure : ");
178 return -1;
179 }
180
181
182 if (MEDlocalizationWr(fid, locname, MED_TRIA6, MED_TRIA6/100, refcoo1, MED_FULL_INTERLACE,
183 ngauss1_1, gscoo1_1, wg1_1,
185 MESSAGE("Erreur à la création du modèle de localisation n°1 : ");
186 return -1;
187 };
188
189 strncpy(description1,"une localisation de points d'intégration pour test34b",MED_COMMENT_SIZE+1);
190 medpath.medclass=MED_LOCALIZATION;medpath.nname=1; medpath.name[0]=locname;
191 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
192 MESSAGE("Erreur à l'écriture de la description de localisation de points d'intégration : ");
193 SSCRUTE(locname);
194 return -1;
195 }
196
197 /* Creation d'un profil (selection du deuxieme élément de valr1_1) */
198 /* On n'utilise que la première valeur (2) du profil */
199 if ( MEDprofileWr(fid,profilename,1,profil1) < 0) {
200 MESSAGE("Erreur à l'écriture du profile : ");
201 SSCRUTE(profilename);
202 return -1;
203 };
204
205 strncpy(description1,"un profil de champ pour test34b",MED_COMMENT_SIZE+1);
206 medpath.medclass=MED_PROFILE;medpath.nname=1; medpath.name[0]=profilename;
207 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
208 MESSAGE("Erreur à l'écriture de la description de profile : ");
209 SSCRUTE(profilename);
210 return -1;
211 }
212
213
214 if (MEDinterpCr(fid, interpname, MED_TRIA3, MED_FALSE,
215 nvariable, maxdegree, nmaxcoefficient) < 0) {
216 MESSAGE("ERROR : interpolation family creation ...");
217 return -1;
218 }
219
220 strncpy(description1,"une interpolation de champ pour test34b",MED_COMMENT_SIZE+1);
221 medpath.medclass=MED_INTERPOLATION;medpath.nname=1; medpath.name[0]=interpname;
222 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
223 MESSAGE("Erreur à l'écriture de la description de profile : ");
224 SSCRUTE(interpname);
225 return -1;
226 }
227
228 /* Creation d'un variable scalaire flottante */
229 strncpy(description1,"un parametre scalaire pour test34b",MED_COMMENT_SIZE+1);
230 if (MEDparameterCr(fid,parametername,MED_FLOAT64,description1,"ms") < 0) {
231 MESSAGE("Erreur a la creation d'une variable scalaire flottante");
232 return -1;
233 }
234
235 medpath.medclass=MED_NUMERICAL_DATA;medpath.nname=1; medpath.name[0]=parametername;
236 if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
237 MESSAGE("Erreur au test d'existence de la description du paramètre scalaire : ");
238 SSCRUTE(parametername);
239 return -1;
240 }
241 if ( descriptionexist != MED_TRUE ) {
242 MESSAGE("Erreur d'absence de la description du paramètre scalaire : ");
243 SSCRUTE(parametername);
244 return -1;
245 } else {
246 if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
247 MESSAGE("Erreur à la lecture de la description du paramètre scalaire : ");
248 SSCRUTE(parametername);
249 return -1;
250 }
251 SSCRUTE(description2);
252 description2[0]='\0';
253 }
254
255 strncpy(description1,"++un parametre scalaire pour test34b++",MED_COMMENT_SIZE+1);
256 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
257 MESSAGE("Erreur à l'écriture de la description de profile : ");
258 SSCRUTE(interpname);
259 return -1;
260 }
261
262
263 strncpy(&groupname[0] ,"groupe1",strlen("groupe1"));
264 strncpy(&groupname[MED_LNAME_SIZE],"groupe2",strlen("groupe2"));
265 SSCRUTE(groupname);
266 if ( MEDfamilyCr(fid, meshname, familyname, 1, 2, groupname) < 0) {
267 MESSAGE("ERROR : family creation ...");
268 return -1;
269 }
270
271 strncpy(description1,"une famille de noeuds pour test34b",MED_COMMENT_SIZE+1);
272 medpath.medclass=MED_FAMILY_NODE;medpath.nname=2;
273 medpath.name[0]=meshname;medpath.name[1]=familyname;
274 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
275 MESSAGE("Erreur à l'écriture de la description d'une famille de noeuds : ");
276 SSCRUTE(familyname);
277 return -1;
278 }
279
280 strncpy(description1,"deux groupes pour la famille de noeuds pour test34b",MED_COMMENT_SIZE+1);
281 medpath.medclass=MED_GROUP;medpath.nname=2;
282 medpath.name[0]=meshname;medpath.name[1]=familyname;
283 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
284 MESSAGE("Erreur à l'écriture de la description d'une liste de groupes d'une famille de noeuds : ");
285 SSCRUTE(familyname);
286 return -1;
287 }
288
289
290 /* Creation du joint */
291 if (MEDsubdomainJointCr(fid, meshname, jointname, "un joint pour test34b", 2, meshname) < 0) {
292 MESSAGE("Erreur a la creation du joint");
293 return -1;
294 }
295
296 medpath.medclass=MED_JOINT;medpath.nname=2;
297 medpath.name[0]=meshname;medpath.name[1]=jointname;
298 if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
299 MESSAGE("Erreur au test d'existence de la description du maillage : ");
300 SSCRUTE(jointname);
301 return -1;
302 }
303 if ( descriptionexist != MED_TRUE ) {
304 MESSAGE("Erreur d'absence de la description du maillage : ");
305 SSCRUTE(jointname);
306 return -1;
307 } else {
308 if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
309 MESSAGE("Erreur à la lecture de la description du maillage : ");
310 SSCRUTE(jointname);
311 return -1;
312 }
313 SSCRUTE(description2);
314 description2[0]='\0';
315 }
316
317 if( MEDfileObjectDescriptionWrByPath(fid,&medpath,"++un joint pour test34b++") < 0) {
318 MESSAGE("Erreur à l'écriture de la description d'joint : ");
319 SSCRUTE(jointname);
320 return -1;
321 }
322
323 /* Fermeture du fichier */
324 if (MEDfileClose(fid) < 0) {
325 MESSAGE("Erreur a la fermeture du fichier :");
326 return -1;
327 }
328
329 return 0;
330}
#define _b
#define _p2
#define _p1
#define _a
#define MED_NAME_SIZE
#define MED_LNAME_SIZE
#define MED_SNAME_SIZE
#define MED_NO_INTERPOLATION
#define MED_PARTICLE_NAME
#define MED_COMMENT_SIZE
#define MED_LNAME_BLANK
#define MED_NO_MESH_SUPPORT
#define MED_NO_MESHNAME
#define SSCRUTE(chaine)
#define MESSAGE(chaine)
MEDC_EXPORT med_err MEDfamilyCr(const med_idt fid, const char *const meshname, const char *const familyname, const med_int familynumber, const med_int ngroup, const char *const groupname)
Cette routine permet la création d'une famille portant sur les entités d'un maillage.
Definition MEDfamilyCr.c:40
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 MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
MEDC_EXPORT med_err MEDfileObjectDescriptionRdByPath(const med_idt fid, med_path *const medpath, char *const description)
Lit une description associée à l'objet objectname accessible par le chemin med_path dans le fichier f...
MEDC_EXPORT med_err MEDfileObjectDescriptionWrByPath(const med_idt fid, med_path *const medpath, const char *const description)
Ecrit une description associée à l'objet accessible par le chemin med_path 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 MEDfileObjectDescriptionExistByPath(const med_idt fid, med_path *const medpath, med_bool *const descriptionexist)
Interroge le fichier fid pour tester l'existence d'une description associée à l'objet accessible par ...
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 MEDsubdomainJointCr(const med_idt fid, const char *const localmeshname, const char *const jointname, const char *const description, const med_int domainnumber, const char *const remotemeshname)
Cette routine permet de créer un joint dans un maillage.
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.
const char * name[MED_MAX_NAME_IN_PATH]
Aggrégation de noms medfichier pour définir un chemin d'accès aux objets med de type class med_class.
int main(int argc, char **argv)
Definition test34b.c:44