MED fichier
c/test34b.c
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2023 EDF R&D, CEA/DEN
* MED is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MED is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MED. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
* - Nom du fichier : test34b.c
*
* - Description : Tests d'existences des descriptions des objets med ayant
* créés une description par l'API de création de l'objet
*
*****************************************************************************/
#include <med.h>
#define MESGERR 1
#include "med_utils.h"
#include <string.h>
#ifdef DEF_LECT_ECR
#define MODE_ACCES MED_ACC_RDWR
#elif DEF_LECT_AJOUT
#define MODE_ACCES MED_ACC_RDEXT
#else
#define MODE_ACCES MED_ACC_CREAT
#endif
#define _a 0.446948490915965
#define _b 0.091576213509771
#define _p1 0.11169079483905
#define _p2 0.0549758718227661
int main (int argc, char **argv)
{
med_idt fid = 0;
char meshname [MED_NAME_SIZE+1] = "maa1";
char familyname [MED_NAME_SIZE+1] = "famille1";
char supportmeshname [MED_NAME_SIZE+1] = "supportmaa1";
char fieldname [MED_NAME_SIZE+1] = "field1";
char jointname [MED_NAME_SIZE+1] = "joint1";
med_int meshdim = 2;
char axisname[2*MED_SNAME_SIZE+1] = "x y ";
char axisunit[2*MED_SNAME_SIZE+1] = "cm cm ";
med_bool objectexist = MED_FALSE;
med_bool descriptionexist = MED_FALSE;
char description0[MED_COMMENT_SIZE+1] = "un maillage pour test34b";
char description1[MED_COMMENT_SIZE+1] = "++UN MAILLAGE POUR TEST34B++";
char description2[MED_COMMENT_SIZE+1] = "";
/* Caractéristiques du model n° 1 de localisation des points de gauss pour le champ n°1*/
med_int ngauss1_1 = 6;
char locname[MED_NAME_SIZE+1] = "Model n1";
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 };
/* Constantes */
med_float gscoo1_1[12] = { 2*_b-1, 1-4*_b, 2*_b-1, 2*_b-1, 1-4*_b,
2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
med_float wg1_1[6] = { 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
char profilename[MED_NAME_SIZE+1] = "PROFIL(test34b)";
med_int profil1[2] = { 2, 3 };
char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
const med_int nvariable=2;
const med_int maxdegree=1;
const med_int nmaxcoefficient=3;
char parametername[MED_NAME_SIZE+1] = "parametre1";
med_path medpath;
/* Creation du fichier "test34b.med" */
if ((fid = MEDfileOpen("test34b.med",MED_ACC_RDWR)) < 0) {
MESSAGE("Erreur a la creation du fichier test34b.med");
return -1;
}
/* Si le fichier test34b.med a déjà été généré par test34b */
medpath.medclass=MED_MESH;medpath.nname=1; medpath.name[0]=meshname;
if( MEDfileObjectExist(fid,MED_MESH,meshname,&objectexist) < 0) {
if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
MESSAGE("Erreur inattendue du fait de l'existence du maillage : ");
SSCRUTE(meshname);
}
if ( descriptionexist == MED_FALSE ) {
MESSAGE("Erreur d'absence anormale de la description du maillage : ");
SSCRUTE(meshname);
return -1;
}
}
if (MEDmeshCr( fid, meshname, meshdim, meshdim, MED_UNSTRUCTURED_MESH,
description0,"s", MED_SORT_DTIT,
MED_CARTESIAN, axisname, axisunit) < 0) {
MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(meshname);
return -1;
}
if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
MESSAGE("Erreur au test d'existence de la description du maillage : ");
SSCRUTE(meshname);
return -1;
}
if ( descriptionexist != MED_TRUE ) {
MESSAGE("Erreur d'absence de la description du maillage : ");
SSCRUTE(meshname);
return -1;
} else {
if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
MESSAGE("Erreur à la lecture de la description du maillage : ");
SSCRUTE(meshname);
return -1;
}
SSCRUTE(description2);
description2[0]='\0';
}
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écrasement de la description du maillage : ");
SSCRUTE(meshname);
return -1;
}
if ( MEDfieldCr(fid,fieldname,MED_INT,1,"comp1","unit1","dtunit1", meshname ) < 0) {
MESSAGE("Erreur à la création du champ : ");SSCRUTE(fieldname);
return -1;
}
strncpy(description1,"un champ pour test34b",MED_COMMENT_SIZE+1);
medpath.medclass=MED_FIELD;medpath.nname=1; medpath.name[0]=fieldname;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description du champ : ");
SSCRUTE(fieldname);
return -1;
}
if (MEDsupportMeshCr( fid, supportmeshname, meshdim, meshdim, "un maillage support pour test34b",
MED_CARTESIAN,axisname, axisunit) < 0) {
MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(supportmeshname);
return -1;
}
medpath.medclass=MED_MESH_SUPPORT;medpath.nname=1; medpath.name[0]=supportmeshname;
if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
MESSAGE("Erreur à la lecture de la description du maillage support: ");
SSCRUTE(supportmeshname);
return -1;
}
SSCRUTE(description2);
description2[0]='\0';
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,"++un maillage support pour test34b++") < 0) {
MESSAGE("Erreur à l'écrasement de la description du maillage support : ");
SSCRUTE(supportmeshname);
return -1;
}
MESSAGE("ERROR : creating struct element");
return -1;
}
medpath.medclass=MED_ELSTRUCT;medpath.nname=1; medpath.name[0]=MED_PARTICLE_NAME;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,"++un élément de structure pour test34b++") < 0) {
MESSAGE("Erreur à l'écritue de la description de l'élémnent de structure : ");
return -1;
}
if (MEDlocalizationWr(fid, locname, MED_TRIA6, MED_TRIA6/100, refcoo1, MED_FULL_INTERLACE,
ngauss1_1, gscoo1_1, wg1_1,
MESSAGE("Erreur à la création du modèle de localisation n°1 : ");
return -1;
};
strncpy(description1,"une localisation de points d'intégration pour test34b",MED_COMMENT_SIZE+1);
medpath.medclass=MED_LOCALIZATION;medpath.nname=1; medpath.name[0]=locname;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description de localisation de points d'intégration : ");
SSCRUTE(locname);
return -1;
}
/* Creation d'un profil (selection du deuxieme élément de valr1_1) */
/* On n'utilise que la première valeur (2) du profil */
if ( MEDprofileWr(fid,profilename,1,profil1) < 0) {
MESSAGE("Erreur à l'écriture du profile : ");
SSCRUTE(profilename);
return -1;
};
strncpy(description1,"un profil de champ pour test34b",MED_COMMENT_SIZE+1);
medpath.medclass=MED_PROFILE;medpath.nname=1; medpath.name[0]=profilename;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description de profile : ");
SSCRUTE(profilename);
return -1;
}
if (MEDinterpCr(fid, interpname, MED_TRIA3, MED_FALSE,
nvariable, maxdegree, nmaxcoefficient) < 0) {
MESSAGE("ERROR : interpolation family creation ...");
return -1;
}
strncpy(description1,"une interpolation de champ pour test34b",MED_COMMENT_SIZE+1);
medpath.medclass=MED_INTERPOLATION;medpath.nname=1; medpath.name[0]=interpname;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description de profile : ");
SSCRUTE(interpname);
return -1;
}
/* Creation d'un variable scalaire flottante */
strncpy(description1,"un parametre scalaire pour test34b",MED_COMMENT_SIZE+1);
if (MEDparameterCr(fid,parametername,MED_FLOAT64,description1,"ms") < 0) {
MESSAGE("Erreur a la creation d'une variable scalaire flottante");
return -1;
}
medpath.medclass=MED_NUMERICAL_DATA;medpath.nname=1; medpath.name[0]=parametername;
if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
MESSAGE("Erreur au test d'existence de la description du paramètre scalaire : ");
SSCRUTE(parametername);
return -1;
}
if ( descriptionexist != MED_TRUE ) {
MESSAGE("Erreur d'absence de la description du paramètre scalaire : ");
SSCRUTE(parametername);
return -1;
} else {
if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
MESSAGE("Erreur à la lecture de la description du paramètre scalaire : ");
SSCRUTE(parametername);
return -1;
}
SSCRUTE(description2);
description2[0]='\0';
}
strncpy(description1,"++un parametre scalaire pour test34b++",MED_COMMENT_SIZE+1);
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description de profile : ");
SSCRUTE(interpname);
return -1;
}
strncpy(&groupname[0] ,"groupe1",strlen("groupe1"));
strncpy(&groupname[MED_LNAME_SIZE],"groupe2",strlen("groupe2"));
SSCRUTE(groupname);
if ( MEDfamilyCr(fid, meshname, familyname, 1, 2, groupname) < 0) {
MESSAGE("ERROR : family creation ...");
return -1;
}
strncpy(description1,"une famille de noeuds pour test34b",MED_COMMENT_SIZE+1);
medpath.medclass=MED_FAMILY_NODE;medpath.nname=2;
medpath.name[0]=meshname;medpath.name[1]=familyname;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description d'une famille de noeuds : ");
SSCRUTE(familyname);
return -1;
}
strncpy(description1,"deux groupes pour la famille de noeuds pour test34b",MED_COMMENT_SIZE+1);
medpath.medclass=MED_GROUP;medpath.nname=2;
medpath.name[0]=meshname;medpath.name[1]=familyname;
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,description1) < 0) {
MESSAGE("Erreur à l'écriture de la description d'une liste de groupes d'une famille de noeuds : ");
SSCRUTE(familyname);
return -1;
}
/* Creation du joint */
if (MEDsubdomainJointCr(fid, meshname, jointname, "un joint pour test34b", 2, meshname) < 0) {
MESSAGE("Erreur a la creation du joint");
return -1;
}
medpath.medclass=MED_JOINT;medpath.nname=2;
medpath.name[0]=meshname;medpath.name[1]=jointname;
if( MEDfileObjectDescriptionExistByPath(fid,&medpath,&descriptionexist) < 0) {
MESSAGE("Erreur au test d'existence de la description du maillage : ");
SSCRUTE(jointname);
return -1;
}
if ( descriptionexist != MED_TRUE ) {
MESSAGE("Erreur d'absence de la description du maillage : ");
SSCRUTE(jointname);
return -1;
} else {
if( MEDfileObjectDescriptionRdByPath(fid,&medpath,description2) < 0) {
MESSAGE("Erreur à la lecture de la description du maillage : ");
SSCRUTE(jointname);
return -1;
}
SSCRUTE(description2);
description2[0]='\0';
}
if( MEDfileObjectDescriptionWrByPath(fid,&medpath,"++un joint pour test34b++") < 0) {
MESSAGE("Erreur à l'écriture de la description d'joint : ");
SSCRUTE(jointname);
return -1;
}
/* Fermeture du fichier */
if (MEDfileClose(fid) < 0) {
MESSAGE("Erreur a la fermeture du fichier :");
return -1;
}
return 0;
}
MEDfamilyCr
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
MED_TRIA6
#define MED_TRIA6
Definition: med.h:209
main
int main(int argc, char **argv)
Definition: 3.0.8/test10.c:50
MED_PARTICLE_NAME
#define MED_PARTICLE_NAME
Definition: med.h:474
med_path
Aggrégation de noms medfichier pour définir un chemin d'accès aux objets med de type class med_class.
Definition: med.h:356
MED_TRIA3
#define MED_TRIA3
Definition: med.h:207
MEDfileObjectDescriptionExistByPath
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 ...
Definition: MEDfileObjectDescriptionExistByPath.c:38
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:80
MED_JOINT
Definition: med.h:192
MED_MESH_SUPPORT
Definition: med.h:192
MEDprofileWr
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.
Definition: MEDprofileWr.c:40
MED_FLOAT64
Definition: med.h:169
MED_GROUP
Definition: med.h:192
MED_TRUE
Definition: med.h:264
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:83
MEDinterpCr
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
MED_FAMILY_NODE
Definition: med.h:194
MEDsubdomainJointCr
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.
Definition: MEDsubdomainJointCr.c:43
med_idt
hid_t med_idt
Definition: med.h:335
med_path::nname
med_int nname
Definition: med.h:359
med_path::medclass
med_class medclass
Definition: med.h:358
MED_NUMERICAL_DATA
Definition: med.h:193
MED_FULL_INTERLACE
Definition: med.h:99
MED_NO_MESHNAME
#define MED_NO_MESHNAME
Definition: med.h:274
med_float
double med_float
Definition: med.h:340
med_bool
med_bool
Definition: med.h:264
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
MED_FIELD
Definition: med.h:191
med_utils.h
_p1
#define _p1
Definition: 3.0.8/test10.c:19
MEDparameterCr
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.
Definition: MEDparameterCr.c:38
_b
#define _b
Definition: 3.0.8/test10.c:18
MEDfileObjectDescriptionWrByPath
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 .
Definition: MEDfileObjectDescriptionWrByPath.c:38
med_int
int med_int
Definition: med.h:346
MEDfieldCr
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
MED_NO_MESH_SUPPORT
#define MED_NO_MESH_SUPPORT
Definition: med.h:277
MED_INTERPOLATION
Definition: med.h:193
MEDsupportMeshCr
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.
Definition: MEDsupportMeshCr.c:46
MED_NONE
#define MED_NONE
Definition: med.h:235
MED_LOCALIZATION
Definition: med.h:193
MED_UNSTRUCTURED_MESH
Definition: med.h:134
MEDfileObjectDescriptionRdByPath
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...
Definition: MEDfileObjectDescriptionRdByPath.c:38
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_MESH
Definition: med.h:191
med.h
MED_INT
Definition: med.h:173
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_NO_INTERPOLATION
#define MED_NO_INTERPOLATION
Definition: med.h:281
MED_ACC_RDWR
Definition: med.h:124
MED_LNAME_BLANK
#define MED_LNAME_BLANK
Definition: med.h:89
_a
#define _a
Definition: 3.0.8/test10.c:17
med_path::name
const char * name[MED_MAX_NAME_IN_PATH]
Definition: med.h:360
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:82
MEDmeshCr
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
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:84
MEDstructElementCr
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.
Definition: MEDstructElementCr.c:50
MEDlocalizationWr
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...
Definition: MEDlocalizationWr.c:49
MED_CARTESIAN
Definition: med.h:262
MED_PROFILE
Definition: med.h:193
MED_FALSE
Definition: med.h:264
MED_SORT_DTIT
Definition: med.h:313
MED_ELSTRUCT
Definition: med.h:192
_p2
#define _p2
Definition: 3.0.8/test10.c:20
MEDfileObjectExist
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.
Definition: MEDfileObjectExist.c:47