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 : test31.c
20 *
21 * - Description : ecriture d'une numerotation globale dans un maillage MED
22 *
23 *****************************************************************************/
24
25 #include <med.h>
26 #define MESGERR 1
27 #include <med_utils.h>
28
29
30 #ifdef DEF_LECT_ECR
31 #define MODE_ACCES MED_ACC_RDWR
32 #elif DEF_LECT_AJOUT
33 #define MODE_ACCES MED_ACC_RDEXT
34 #else
35 #define MODE_ACCES MED_ACC_CREAT
36 #endif
37
main(int argc,char ** argv)38 int main (int argc, char **argv)
39
40
41 {
42 med_err ret = 0;
43 med_idt fid;
44 med_int mdim,sdim;
45 /* nom du maillage de longueur maxi MED_NAME_SIZE */
46 char maa[MED_NAME_SIZE+1];
47 /* le nombre de noeuds */
48 med_int nnoe = 0;
49 /* table des numeros global */
50 med_int *numglobalnoe=NULL;
51
52 /* variable de stockage pour reperer le maillage */
53 med_int i;
54 char des[MED_COMMENT_SIZE+1]="";
55 char dtunit[MED_SNAME_SIZE+1]="";
56 char nomcoo[3*MED_SNAME_SIZE+1]="";
57 char unicoo[3*MED_SNAME_SIZE+1]="";
58 med_axis_type rep;
59 med_mesh_type type;
60 med_sorting_type sort;
61 med_int nstep=0;
62 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
63
64
65
66 if (argc != 2) {
67 MESSAGE("Il faut passer un fichier MED en param�tre");
68 return -1;
69 }
70
71 /* Ouverture du fichier passe en argument */
72 if ((fid = MEDfileOpen(argv[1],MED_ACC_RDWR)) < 0) {
73 MESSAGE("Erreur a l'ouverture du fichier : "); SSCRUTE(argv[1]);
74 return -1;
75 }
76
77
78 if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
79 MESSAGE("Erreur � la lecture de la dimension de l'espace du maillage :");
80 SSCRUTE(maa);
81 return -1;
82 }
83
84 /* Lecture des infos concernant le premier maillage */
85 if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, des, dtunit, &sort,
86 &nstep, &rep, nomcoo,unicoo) < 0 ) {
87 MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
88 return -1;
89 } else {
90 printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
91 printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
92 printf("\t -Description du maillage : %s\n",des);
93 printf("\t -Noms des axes : %s\n",nomcoo);
94 printf("\t -Unit�s des axes : %s\n",unicoo);
95 printf("\t -Type de rep�re : %d\n",rep);
96 printf("\t -Nombre d'�tapes de calcul : "IFORMAT"\n",nstep);
97 printf("\t -Unit� des dates : %s\n\n",dtunit);
98 }
99
100 /* Lecture du nombre de noeuds */
101 if ( (nnoe = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
102 MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
103 &chgt,&trsf)) < 0) {
104 MESSAGE("Erreur a la lecture du nombre de noeuds ");
105 return -1;
106 }
107 printf("Nombre de noeuds : "IFORMAT" \n",nnoe);
108
109 /* Allocations memoires */
110
111 /* table de la numerotation globale
112 profil : (nombre de noeuds ) */
113 if (nnoe > 0) {
114 numglobalnoe = (med_int*) malloc(sizeof(med_int)*nnoe);
115 for (i=0;i<nnoe;i++) {
116 numglobalnoe[i]=i+100;
117 }
118 }
119
120 /* ecriture de la numerotation globale */
121
122 if (MEDmeshGlobalNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numglobalnoe)<0) {
123 MESSAGE("Erreur a l''ecriture de la numerotation globale");
124 return -1;
125 }
126
127 free(numglobalnoe);
128
129 /* Fermeture du fichier */
130 if (MEDfileClose(fid) < 0) {
131 MESSAGE("Erreur a la fermeture du fichier");
132 return -1;
133 }
134
135 return 0;
136 }
137
138
139
140
141