ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_rstar.cpp
Revision: 283
Committed: Tue Sep 13 21:11:20 2011 UTC (13 years, 8 months ago) by francois
File size: 5463 byte(s)
Log Message:
structure de l'écriture

File Contents

# User Rev Content
1 francois 283 /* 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 debug ;
13     extern int nb_max_noe ;
14     void m3d_rstar(int *nb_noeud,int *nb_ele,float *coord,int *numele,int *ierr)
15     {
16     FILE *stream, *output ;
17     char line[MAX_LINE] ;
18     char temp[MAX_LINE] ;
19     int j,i;
20     int j1,j2,j3,j4 ;
21     /* declaration des fonctions */
22     char *ext_noe, *ext_ele ;
23     int *corresp, itype ;
24     float crit, crit1, crit2 ;
25    
26     *ierr = FAUX ;
27     j = 0 ;
28     itype = 0 ;
29    
30     if (format == STARCD)
31     {
32     ext_noe = (char*)EXT_NOE_STAR ;
33     ext_ele = (char*)EXT_ELE_STAR ;
34     temp[0] = 0 ;
35     strcpy(temp,gest->buffer) ;
36     strncat(temp,ext_noe,8) ;
37    
38     /* ouverture du fichier des noeuds */
39     if (!(stream = fopen(temp,"r")))
40     {
41     *ierr = VRAI ;
42     m3d_erreur(ERR_OPEN);
43     return ;
44     }
45     /* lecture du plus grand numero i de noeud + nombre de noeud */
46     i = 0 ;
47     *nb_noeud = 0 ;
48     while (fgets(line,MAX_LINE,stream))
49     {
50     if (sscanf(line,"%d",&j)!=1)
51     {
52     *ierr = VRAI ;
53     m3d_erreur(ERR_FORMAT);
54     return ;
55     }
56     (*nb_noeud)++ ;
57     if (j>i) i = j ;
58     }
59     if (*nb_noeud>=nb_max_noe)
60     {
61     *ierr = VRAI ;
62     m3d_erreur(ERR_NB_NOE);
63     return ;
64     }
65     gest->numax = i ;
66     corresp = (int*)calloc(i+1,sizeof(int)) ;
67     if (corresp == NULL)
68     {
69     *ierr = VRAI ;
70     m3d_erreur(ERR_ALLOC);
71     return ;
72     }
73     /* plus grand numero */
74     gest->tabcor = (int*)calloc((*nb_noeud)+1,sizeof(int)) ;
75     if (gest->tabcor == NULL)
76     {
77     *ierr = VRAI ;
78     m3d_erreur(ERR_ALLOC);
79     return ;
80     }
81     rewind(stream) ;
82     j = 0 ;
83     while (fgets(line,MAX_LINE,stream))
84     {
85     if (sscanf(line,"%d %f %f %f",&i,coord+3*j,coord+3*j+1,coord+3*j+2)!=4)
86     {
87     *ierr = VRAI ;
88     m3d_erreur(ERR_FORMAT);
89     return ;
90     }
91     j++ ;
92     corresp[i] = j ;
93     gest->tabcor[j] = i ;
94     }
95    
96     fclose(stream) ;
97     *nb_noeud = j ;
98     /* ouverture du fichier des elements */
99     temp[0] = 0 ;
100     strcpy(temp,gest->buffer) ;
101     strncat(temp,ext_ele,8) ;
102    
103     /* ouverture du fichier */
104     if (!(stream = fopen(temp,"r")))
105     {
106     *ierr = VRAI ;
107     m3d_erreur(ERR_OPEN);
108     return ;
109     }
110     j = 0 ;
111     while (fgets(line,MAX_LINE,stream))
112     {
113     if (sscanf(line,"%d %d %d %d %d",&i,&j1,&j2,&j3,&j4)!=5)
114     {
115     *ierr = VRAI ;
116     m3d_erreur(ERR_FORMAT);
117     return ;
118     }
119     if (j3 == j4)
120     {
121     numele[3*j] = corresp[j1] ;
122     numele[3*j+1] = corresp[j2] ;
123     numele[3*j+2] = corresp[j3] ;
124     /* examen de la qualite */
125     crit = m3d_cal2d(coord,numele[3*j],numele[3*j+1],numele[3*j+2]) ;
126     if ((crit<0.1) && (debug)) printf("%s %f\n",line,crit) ;
127     j++ ;
128     }
129     else
130     {
131     crit = m3d_cal2d(coord,corresp[j1],corresp[j2],corresp[j3]) ;
132     crit1 = m3d_cal2d(coord,corresp[j1],corresp[j3],corresp[j4]) ;
133     crit1 = min(crit,crit1) ;
134    
135     crit = m3d_cal2d(coord,corresp[j1],corresp[j2],corresp[j4]) ;
136     crit2 = m3d_cal2d(coord,corresp[j2],corresp[j3],corresp[j4]) ;
137     crit2 = min(crit,crit2) ;
138    
139     if (crit1 > crit2)
140     {
141     numele[3*j] = corresp[j1] ;
142     numele[3*j+1] = corresp[j2] ;
143     numele[3*j+2] = corresp[j3] ;
144     /* examen de la qualite */
145     crit = m3d_cal2d(coord,numele[3*j],numele[3*j+1],numele[3*j+2]) ;
146     j++ ;
147     numele[3*j] = corresp[j1] ;
148     numele[3*j+1] = corresp[j3] ;
149     numele[3*j+2] = corresp[j4] ;
150     /* examen de la qualite */
151     crit = m3d_cal2d(coord,numele[3*j],numele[3*j+1],numele[3*j+2]) ;
152     j++ ;
153     }
154     else
155     {
156     numele[3*j] = corresp[j1] ;
157     numele[3*j+1] = corresp[j2] ;
158     numele[3*j+2] = corresp[j4] ;
159     /* examen de la qualite */
160     crit = m3d_cal2d(coord,numele[3*j],numele[3*j+1],numele[3*j+2]) ;
161     j++ ;
162     numele[3*j] = corresp[j2] ;
163     numele[3*j+1] = corresp[j3] ;
164     numele[3*j+2] = corresp[j4] ;
165     /* examen de la qualite */
166     crit = m3d_cal2d(coord,numele[3*j],numele[3*j+1],numele[3*j+2]) ;
167     j++ ;
168     }
169     }
170     }
171     *nb_ele = j ;
172     free(corresp) ;
173     fclose(stream) ;
174     }
175     else
176     {
177     *ierr = VRAI ;
178     m3d_erreur(ERR_FORMAT);
179     return ;
180     }
181     return ;
182     }