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 * - Nom du fichier : test15.c
20 *
21 * - Description : lecture des noeuds d'un maillage MED
22 * a l'aide des routines de niveau 2
23 * - equivalent a test5.c
24 *
25 *****************************************************************************/
26
27 #include <med.h>
28 #define MESGERR 1
29 #include "med_utils.h"
30 #include <string.h>
31
32 #ifdef DEF_LECT_ECR
33 #define MODE_ACCES MED_LECTURE_ECRITURE
34 #elif DEF_LECT_AJOUT
35 #define MODE_ACCES MED_LECTURE_AJOUT
36 #else
37 #define MODE_ACCES MED_CREATION
38 #endif
39
main(int argc,char ** argv)40 int main (int argc, char **argv)
41
42
43 {
44 med_err ret = 0;
45 med_idt fid;
46 /* la dimension du maillage */
47 med_int mdim;
48 /* nom du maillage de longueur maxi MED_TAILLE_NOM */
49 char maa[MED_TAILLE_NOM+1];
50 /* le nombre de noeuds */
51 med_int nnoe = 0;
52 /* table des coordonnees */
53 med_float *coo;
54 /* tables des noms et des unites des coordonnees
55 profil : (dimension*MED_TAILLE_PNOM+1) */
56 char nomcoo[3*MED_TAILLE_PNOM+1];
57 char unicoo[3*MED_TAILLE_PNOM+1];
58 /* tables des noms, numeros, numeros de familles des noeuds
59 autant d'elements que de noeuds - les noms ont pout longueur
60 MED_TAILLE_PNOM */
61 char *nomnoe;
62 med_int *numnoe;
63 med_int *nufano;
64 med_repere rep;
65 med_booleen inonoe,inunoe;
66 char str[MED_TAILLE_PNOM+1];
67 med_int i;
68 char desc[MED_TAILLE_DESC+1];
69 med_maillage type;
70
71 /* Ouverture du fichier passe en argument en lecture seule */
72 if ((fid= MEDouvrir(argv[1],MED_LECTURE)) < 0) {
73 MESSAGE("Erreur a l'ouverture du fichier :");
74 SSCRUTE(argv[1]);
75 return -1;
76 }
77
78 /* Lecture des infos concernant le premier maillage */
79 if (MEDmaaInfo(fid,1,maa,&mdim,&type,desc) < 0) {
80 MESSAGE("Erreur a la lecture des informations du 1er maillage");
81 return -1;
82 }
83 printf("Maillage de nom : %s et de dimension : "IFORMAT" \n",maa,mdim);
84
85 /* Lecture du nombre de noeuds */
86 if ((nnoe = MEDnEntMaa(fid,maa,MED_COOR,MED_NOEUD,0,0)) < 0) {
87 MESSAGE("Erreur a la lecture du nombre de noeuds ");
88 return -1;
89 }
90 printf("Nombre de noeuds : %d \n",nnoe);
91
92 /* Allocations memoires */
93 /* table des coordonnees
94 profil : (dimension * nombre de noeuds ) */
95 if (nnoe > 0) {
96 coo = (med_float*) malloc(sizeof(med_float)*nnoe*mdim);
97 /* table des des numeros, des numeros de familles des noeuds
98 profil : (nombre de noeuds) */
99 numnoe = (med_int*) malloc(sizeof(med_int)*nnoe);
100 nufano = (med_int*) malloc(sizeof(med_int)*nnoe);
101 /* table des noms des noeuds
102 profil : (nnoe*MED_TAILLE_PNOM+1) */
103 nomnoe = (char*) malloc(MED_TAILLE_PNOM*nnoe+1);
104
105 /* Lecture des noeuds :
106 - Coordonnees
107 - Noms (optionnel dans un fichier MED)
108 - Numeros (optionnel dans un fichier MED)
109 - Numeros de familles */
110 if (MEDnoeudsLire(fid,maa,mdim,coo,MED_FULL_INTERLACE,&rep,nomcoo,unicoo,
111 nomnoe,&inonoe,numnoe,&inunoe,nufano,nnoe) < 0) {
112 MESSAGE("Erreur a la lecture des noeuds du maillage");
113 ret = -1;
114 }
115
116 /* Affichage */
117 if (ret == 0) {
118 printf("Type de repere : %d \n",rep);
119 printf("Nom des coordonnees : \n");
120 for (i=0;i<mdim;i++) {
121 strncpy(str,nomcoo+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
122 str[MED_TAILLE_PNOM] = '\0';
123 printf("%s ",str);
124 }
125 printf("\nUnites des coordonnees : \n");
126 for (i=0;i<mdim;i++) {
127 strncpy(str,unicoo+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
128 str[MED_TAILLE_PNOM] = '\0';
129 printf("%s ",str);
130 }
131 printf("\nCoordonnees des noeuds : \n");
132 for (i=0;i<nnoe*mdim;i++)
133 printf("%f ",*(coo+i));
134 if (inonoe) {
135 printf("\nNoms des noeuds : \n");
136 for (i=0;i<nnoe;i++) {
137 strncpy(str,nomnoe+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
138 str[MED_TAILLE_PNOM] = '\0';
139 printf(" %s ",str);
140 }
141 }
142 if (inunoe) {
143 printf("\nNumeros des noeuds : \n");
144 for (i=0;i<nnoe;i++)
145 printf("%d ",*(numnoe+i));
146 }
147 printf("\nNumeros des familles des noeuds : \n");
148 for (i=0;i<nnoe;i++)
149 printf(IFORMAT" ",*(nufano+i));
150 printf("\n");
151 }
152
153 /* Liberation memoire */
154 free(coo);
155 free(nomnoe);
156 free(numnoe);
157 free(nufano);
158 }
159
160 /* Fermeture du fichier */
161 if (MEDfermer(fid) < 0) {
162 MESSAGE("Erreur a la fermeture du fichier");
163 return -1;
164 }
165
166 return ret;
167 }
168
169
170
171
172