ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_rmos.cpp
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Original Path: magic/lib/diamesh/diamesh/src/m3d_rmos.cpp
File size: 11114 byte(s)
Log Message:

File Contents

# User Rev Content
1 5 /* lecture des fichiers */
2     #include <stdio.h>
3     #include <string.h>
4     #include <stdlib.h>
5     #include "m3d_const.h"
6     #include "m3d_hotes.h"
7     #include "m3d_struct.h"
8     #include "m3d_erreur.h"
9     #include "prototype.h"
10     extern int format ;
11     extern GEST_MEM *gest ;
12     extern int nb_max_noe ;
13     void m3d_rmos(int *nb_noeud,int *nb_ele,float *coord,int *numele,int *ierr)
14     {
15     FILE *stream ;
16     char line[MAX_LINE] ;
17     char temp[MAX_LINE] ;
18     char tabel[MAX_LINE] ;
19     int j,i, num, itype ;
20     /* declaration des fonctions */
21     char *ext_noe, *ext_ele ;
22     int *old, *neww, *tablin, *numele2 ;
23     float *coord2 ;
24    
25     *ierr = FAUX ;
26     j = 0 ;
27     itype = 0 ;
28    
29    
30     if (format == MOSAIC)
31     {
32     ext_noe = EXT_NOE_MOSAIC ;
33     ext_ele = EXT_ELE_MOSAIC ;
34    
35     /* le maillage est il quadratique ou lineaire */
36     temp[0] = 0 ;
37     strcpy(temp,gest->buffer) ;
38     strncat(temp,ext_ele,4) ;
39    
40     /* ouverture du fichier des elements */
41     if (!(stream = fopen(temp,"r")))
42     {
43     *ierr = VRAI ;
44     m3d_erreur(ERR_OPEN);
45     return ;
46     }
47    
48     if (!fgets(line,MAX_LINE,stream))
49     {
50     *ierr = VRAI ;
51     m3d_erreur(ERR_FORMAT);
52     return ;
53     }
54     tabel[0] = 0 ;
55     strncat(tabel,line+5,5) ;
56     itype = atoi(tabel) ;
57     if (itype == 3) gest->is_qua = FAUX ;
58     else if (itype == 6) gest->is_qua = VRAI ;
59     else
60     {
61     *ierr = VRAI ;
62     m3d_erreur(ERR_TYPE_ELE);
63     return ;
64     }
65     fclose(stream) ;
66     /* traitement maillage lineaire */
67     if (gest->is_qua == FAUX)
68     {
69     temp[0] = 0 ;
70     strcpy(temp,gest->buffer) ;
71     strncat(temp,ext_noe,4) ;
72    
73     /* ouverture du fichier des noeuds */
74     if (!(stream = fopen(temp,"r")))
75     {
76     *ierr = VRAI ;
77     m3d_erreur(ERR_OPEN);
78     return ;
79     }
80    
81     if (!fgets(line,MAX_LINE,stream))
82     {
83     *ierr = VRAI ;
84     m3d_erreur(ERR_FORMAT);
85     return ;
86     }
87     /* lecture du nombre de noeuds */
88     tabel[0] = 0 ;
89     strncat(tabel,line,5) ;/* 5 premiers caracteres */
90     *nb_noeud = atoi(tabel) ;
91     if (*nb_noeud>=nb_max_noe)
92     {
93     *ierr = VRAI ;
94     m3d_erreur(ERR_NB_NOE);
95     return ;
96     }
97     /* dernier noeud mosaic */
98     tabel[0] = 0 ;
99     strncat(tabel,line+45,5) ;
100     gest->numax = atoi(tabel) ;
101     gest->numax = max(gest->numax,*nb_noeud) ;
102    
103     gest->tabcor = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
104     if (gest->tabcor == NULL)
105     {
106     *ierr = VRAI ;
107     m3d_erreur(ERR_ALLOC);
108     return ;
109     }
110     /* lecture des coordonnes des noeuds */
111     /* lecture en format libre */
112     for (i=0;i<*nb_noeud;i++)
113     {
114     if (fgets(line,6,stream)==NULL)
115     {
116     *ierr = VRAI ;
117     m3d_erreur(ERR_FORMAT);
118     return ;
119     }
120     num = atoi(line);
121     if (num == 0)
122     {
123     *ierr = VRAI;
124     m3d_erreur(ERR_FORMAT);
125     return ;
126     }
127    
128     gest->tabcor[i+1] = num ;
129     for (j=0;j<3;j++)
130     {
131     if (fgets(line,11,stream)==NULL)
132     {
133     *ierr = VRAI ;
134     m3d_erreur(ERR_FORMAT);
135     return ;
136     }
137     if (sscanf(line,"%f",coord+3*i+j)!=1)
138     {
139     *ierr = VRAI ;
140     m3d_erreur(ERR_FORMAT);
141     return ;
142     }
143    
144     }
145     if (!fgets(line,MAX_LINE,stream))
146     {
147     *ierr = VRAI ;
148     m3d_erreur(ERR_FORMAT);
149     return ;
150     }
151     }
152     fclose(stream) ;
153     /* ouverture du fichier des elements */
154     temp[0] = 0 ;
155     strcpy(temp,gest->buffer) ;
156     strncat(temp,ext_ele,4) ;
157    
158     /* ouverture du fichier */
159     if (!(stream = fopen(temp,"r")))
160     {
161     *ierr = VRAI ;
162     m3d_erreur(ERR_OPEN);
163     return ;
164     }
165     if (!fgets(line,MAX_LINE,stream))
166     {
167     *ierr = VRAI ;
168     m3d_erreur(ERR_FORMAT);
169     return ;
170     }
171    
172     /* lecture du nombre d'elements */
173     tabel[0] = 0 ;
174     strncat(tabel,line,5) ;
175     *nb_ele = atoi(tabel) ;
176     tabel[0] = 0 ;
177     strncat(tabel,line+25,5) ;
178     gest->numael = atoi(tabel) ;
179     /* lecture des elements */
180     for (i=0;i<*nb_ele;i++)
181     {
182     if (!fgets(line,MAX_LINE,stream))
183     {
184     *ierr = VRAI ;
185     m3d_erreur(ERR_FORMAT);
186     return ;
187     }
188     /* lecture des numeros */
189     tabel[0] = 0 ;
190     strncat(tabel,line+30,5) ;
191     numele[3*i] = atoi(tabel) ;
192     tabel[0] = 0 ;
193     strncat(tabel,line+35,5) ;
194     numele[3*i+1] = atoi(tabel) ;
195     tabel[0] = 0 ;
196     strncat(tabel,line+40,5) ;
197     numele[3*i+2] = atoi(tabel) ;
198     }
199     fclose(stream) ;
200     }
201     else /* mailles quadratiques */
202     {
203     /* tableau des coordonnees des noeuds quadratiques,
204     le maillage se fait evidemment en lineaire puis on fait un simple
205     post-traitement */
206     /* lecture du nombre de noeuds */
207     temp[0] = 0 ;
208     strcpy(temp,gest->buffer) ;
209     strncat(temp,ext_noe,4) ;
210    
211     /* ouverture du fichier des noeuds */
212     if (!(stream = fopen(temp,"r")))
213     {
214     *ierr = VRAI ;
215     m3d_erreur(ERR_OPEN);
216     return ;
217     }
218    
219     if (!fgets(line,MAX_LINE,stream))
220     {
221     *ierr = VRAI ;
222     m3d_erreur(ERR_FORMAT);
223     return ;
224     }
225     tabel[0] = 0 ;
226     strncat(tabel,line,5) ;/* 5 premiers caracteres */
227     *nb_noeud = atoi(tabel) ;
228     gest->nb_noe_qua = *nb_noeud ;
229     /* dernier noeud mosaic */
230     tabel[0] = 0 ;
231     strncat(tabel,line+45,5) ;
232     gest->numax = atoi(tabel) ;
233    
234     gest->tabcor = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
235     if (gest->tabcor == NULL)
236     {
237     *ierr = VRAI ;
238     m3d_erreur(ERR_ALLOC);
239     return ;
240     }
241    
242     /* le fichier des noeuds est ouvert */
243     /* lecture des noeuds ->on remplit coord2 */
244     gest->coord2 = (float*)calloc(3*(*nb_noeud),sizeof(float)) ;
245     if (gest->coord2 == NULL)
246     {
247     *ierr = VRAI ;
248     m3d_erreur(ERR_ALLOC);
249     return ;
250     }
251     coord2 = gest->coord2 ;
252     gest->tablin = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
253     /* les noeuds sont ils des noeuds du maillage */
254     if (gest->tablin == NULL)
255     {
256     *ierr = VRAI ;
257     m3d_erreur(ERR_ALLOC);
258     return ;
259     }
260     tablin = gest->tablin ;
261     for (i=0;i<=*nb_noeud;i++) tablin[i] = VRAI ;
262     gest->neww = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
263     if (gest->neww == NULL)
264     {
265     *ierr = VRAI ;
266     m3d_erreur(ERR_ALLOC);
267     return ;
268     }
269     neww = gest->neww ;
270     gest->old = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
271     if (gest->old == NULL)
272     {
273     *ierr = VRAI ;
274     m3d_erreur(ERR_ALLOC);
275     return ;
276     }
277     old = gest->old ;
278    
279     /* lecture en format libre */
280     for (i=0;i<*nb_noeud;i++)
281     {
282     if (!fgets(line,6,stream))
283     {
284     *ierr = VRAI ;
285     m3d_erreur(ERR_FORMAT);
286     return ;
287     }
288    
289     if (sscanf(line,"%d",&num)!=1)
290     {
291     *ierr = VRAI ;
292     m3d_erreur(ERR_FORMAT);
293     return ;
294     }
295     gest->tabcor[i+1] = num ;
296     for (j=0;j<3;j++)
297     {
298     if (!fgets(line,11,stream))
299     {
300     *ierr = VRAI ;
301     m3d_erreur(ERR_FORMAT);
302     return ;
303     }
304     if (sscanf(line,"%f",coord2+3*i+j)!=1)
305     {
306     *ierr = VRAI ;
307     m3d_erreur(ERR_FORMAT);
308     return ;
309     }
310     }
311     if (!fgets(line,MAX_LINE,stream))
312     {
313     *ierr = VRAI ;
314     m3d_erreur(ERR_FORMAT);
315     return ;
316     }
317     }
318     fclose(stream) ;
319     /* on a rempli le tableau des noeuds quadratiques */
320     /* parcours des elements gestions des noeuds quadratiques */
321     /* reperer les numeros de noeuds quadratiques */
322    
323     /* ouverture du fichier des elements */
324     temp[0] = 0 ;
325     strcpy(temp,gest->buffer) ;
326     strncat(temp,ext_ele,4) ;
327    
328     /* ouverture du fichier */
329     if (!(stream = fopen(temp,"r")))
330     {
331     *ierr = VRAI ;
332     m3d_erreur(ERR_OPEN);
333     return ;
334     }
335     if (!fgets(line,MAX_LINE,stream))
336     {
337     *ierr = VRAI ;
338     m3d_erreur(ERR_FORMAT);
339     return ;
340     }
341    
342     /* lecture du nombre d'elements */
343     tabel[0] = 0 ;
344     strncat(tabel,line,5) ;
345     *nb_ele = atoi(tabel) ;
346     tabel[0] = 0 ;
347     strncat(tabel,line+25,5) ;
348     gest->numael = atoi(tabel) ;
349    
350     gest->numele2 = (int*)calloc(6 * (*nb_ele),sizeof(int)) ;
351     if (gest->numele2 == NULL)
352     {
353     *ierr = VRAI ;
354     m3d_erreur(ERR_ALLOC);
355     return ;
356     }
357     numele2 = gest->numele2 ;
358     /* lecture des elements */
359     for (i=0;i<*nb_ele;i++)
360     {
361     if (!fgets(line,MAX_LINE,stream))
362     {
363     *ierr = VRAI ;
364     m3d_erreur(ERR_FORMAT);
365     return ;
366     }
367     tabel[0] = 0 ;
368     strncat(tabel,line+30,5) ;/* 5 premiers caracteres */
369     numele[3*i] = atoi(tabel) ;
370     numele2[6*i] = numele[3*i] ;
371     tabel[0] = 0 ;
372     strncat(tabel,line+35,5) ;/* 5 premiers caracteres */
373     numele2[6*i+1] = atoi(tabel) ;
374     tablin[atoi(tabel)] = FAUX ;
375     tabel[0] = 0 ;
376     strncat(tabel,line+40,5) ;/* 5 premiers caracteres */
377     numele[3*i+1] = atoi(tabel) ;
378     numele2[6*i+2] = numele[3*i+1] ;
379     tabel[0] = 0 ;
380     strncat(tabel,line+45,5) ;/* 5 premiers caracteres */
381     numele2[6*i+3] = atoi(tabel) ;
382     tablin[atoi(tabel)] = FAUX ;
383     tabel[0] = 0 ;
384     strncat(tabel,line+50,5) ;/* 5 premiers caracteres */
385     numele[3*i+2] = atoi(tabel) ;
386     numele2[6*i+4] = numele[3*i+2] ;
387     tabel[0] = 0 ;
388     strncat(tabel,line+55,5) ;/* 5 premiers caracteres */
389     numele2[6*i+5] = atoi(tabel) ;
390     tablin[atoi(tabel)] = FAUX ;
391     }
392     /* fermeture du fichier */
393     fclose(stream) ;
394     /* parcours du tableau des coordonnees coord2 */
395     *nb_noeud = 0 ;
396     for (i=1;i<=gest->nb_noe_qua;i++)/* numeros fortran */
397     {
398     if (tablin[i]==VRAI)
399     {
400     coord[x(*nb_noeud)] = coord2[x(i-1)] ;
401     coord[y(*nb_noeud)] = coord2[y(i-1)] ;
402     coord[z(*nb_noeud)] = coord2[z(i-1)] ;
403     *nb_noeud = *nb_noeud + 1 ;
404     /* correspondance */
405     neww[i] = *nb_noeud ;
406     old[*nb_noeud] = i ;
407     }
408     }
409     /* renumerotation des elements */
410     for (i=0;i<*nb_ele;i++)/* numeros fortran */
411     {
412     numele[3*i] = neww[numele[3*i]] ;
413     numele[3*i+1] = neww[numele[3*i+1]] ;
414     numele[3*i+2] = neww[numele[3*i+2]] ;
415     }
416     }
417     }
418     else
419     {
420     *ierr = VRAI ;
421     m3d_erreur(ERR_FORMAT);
422     return ;
423     }
424     return ;
425     }