1 /* -------------------------------------------------------------------- */
2 /* CALCULIX */
3 /* - GRAPHICAL INTERFACE - */
4 /* */
5 /* A 3-dimensional pre- and post-processor for finite elements */
6 /* Copyright (C) 1996 Klaus Wittig */
7 /* */
8 /* This program is free software; you can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License as */
10 /* published by the Free Software Foundation; version 2 of */
11 /* the License. */
12 /* */
13 /* This program is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU General Public License */
19 /* along with this program; if not, write to the Free Software */
20 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* -------------------------------------------------------------------- */
22
23 #include <extUtil.h>
24
25 #define TEST 0
26
27 #define INI_FIELD_SIZE 100000
28
29
30
readEdges(char * datin,Summen * anz,Nodes ** nptr,Elements ** eptr)31 int readEdges( char *datin, Summen *anz, Nodes **nptr, Elements **eptr )
32 {
33 FILE *handle;
34
35 char rec_str[MAX_LINE_LENGTH];
36 int node_field_size, elem_field_size;
37 int e_nmax=1, e_nmin=1;
38 int length;
39 int ipuf;
40
41 Nodes *node=NULL;
42 Elements *elem=NULL;
43
44
45
46 node_field_size=INI_FIELD_SIZE;
47 do
48 {
49 if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
50 {
51 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
52 node_field_size/=2;
53 }
54 if(node_field_size<100)
55 {
56 printf("\n\n ERROR: not enough memory in readfrd()\n\n");
57 exit(-1);
58 }
59 }while(!node);
60
61 elem_field_size=INI_FIELD_SIZE;
62 do
63 {
64 if((elem = (Elements *)realloc( (Elements *)elem, (elem_field_size+1) * sizeof(Elements))) == NULL )
65 {
66 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size );
67 elem_field_size/=2;
68 }
69 if(elem_field_size<100)
70 {
71 printf("\n\n ERROR: not enough memory in readfrd()\n\n");
72 exit(-1);
73 }
74 }while(!elem);
75
76 anz->n=anz->e=anz->l=-1;
77
78 /* Open the files and check to see that it was opened correctly */
79 handle = fopen (datin, "r");
80 if ( handle== NULL ) { printf ("ERROR: The input file \"%s\" could not be opened.\n\n", datin); return(-1); }
81 else printf (" file:%s opened\n", datin);
82
83 printf (" reading nedgen edge format\n");
84
85 strcpy(anz->model, "EDGE");
86 printf (" MODEL NAME: %s", anz->model);
87
88 anz->emax=0; anz->emin=MAX_INTEGER;
89 anz->nmax=0; anz->nmin=MAX_INTEGER;
90
91 length = frecord( handle, rec_str);
92 while(length)
93 {
94 nextEdge:; length = frecord( handle, rec_str);
95 if (rec_str[length] == (char)EOF) break;
96
97 if (rec_str[0]=='3') goto nextEdge;
98
99 anz->n++;
100 node[anz->n].nr = anz->n+1;
101 if (node[anz->n].nr>=node_field_size)
102 {
103 node_field_size=node[anz->n].nr+100;
104 if ( (node = (Nodes *)realloc((Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
105 {
106 printf("\n\n ERROR: realloc failed, nodenr:%d\n\n", node[anz->n].nr) ;
107 return(-1);
108 }
109 }
110 node[node[anz->n].nr].indx=anz->n;
111
112 anz->n++;
113 node[anz->n].nr = anz->n+1;
114 if (node[anz->n].nr>=node_field_size)
115 {
116 node_field_size=node[anz->n].nr+100;
117 if ( (node = (Nodes *)realloc((Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
118 {
119 printf("\n\n ERROR: realloc failed, nodenr:%d\n\n", node[anz->n].nr) ;
120 return(-1);
121 }
122 }
123 node[node[anz->n].nr].indx=anz->n;
124
125 sscanf(rec_str,"%d %lf %lf %lf %lf %lf %lf", &ipuf, &node[node[anz->n-1].nr].nx,&node[node[anz->n-1].nr].ny,&node[node[anz->n-1].nr].nz, &node[node[anz->n].nr].nx,&node[node[anz->n].nr].ny,&node[node[anz->n].nr].nz);
126 if (node[anz->n-1].nr > anz->nmax) anz->nmax=node[anz->n-1].nr;
127 if (node[anz->n-1].nr < anz->nmin) anz->nmin=node[anz->n-1].nr;
128 if (node[anz->n].nr > anz->nmax) anz->nmax=node[anz->n].nr;
129 if (node[anz->n].nr < anz->nmin) anz->nmin=node[anz->n].nr;
130
131 #if TEST
132 printf (" n=%d x=%lf y=%lf z=%lf \n", node[anz->n-1].nr,
133 node[node[anz->n-1].nr].nx, node[node[anz->n-1].nr].ny,
134 node[node[anz->n-1].nr].nz);
135 printf (" n=%d x=%lf y=%lf z=%lf \n", node[anz->n].nr,
136 node[node[anz->n].nr].nx, node[node[anz->n].nr].ny,
137 node[node[anz->n].nr].nz);
138 #endif
139
140 anz->e++;
141 if (anz->e>=elem_field_size)
142 {
143 elem_field_size=anz->e+100;
144 if((elem=(Elements *)realloc((Elements *)elem,(elem_field_size+1)*sizeof(Elements)))==NULL)
145 {
146 printf("\n\n ERROR: realloc failed, elem-index:%d\n\n", anz->e);
147 return(-1);
148 }
149 }
150 elem[anz->e].nr = anz->e+1;
151 elem[anz->e].type = 11;
152 elem[anz->e].group = 1;
153 elem[anz->e].mat = 1;
154 anz->etype[elem[anz->e].type]++;
155 if (elem[anz->e].nr > anz->emax) anz->emax=elem[anz->e].nr;
156 if (elem[anz->e].nr < anz->emin) anz->emin=elem[anz->e].nr;
157 elem[anz->e].nod[0]=node[anz->n-1].nr;
158 elem[anz->e].nod[1]=node[anz->n].nr;
159 #if TEST
160 printf (" e=%d typ=%d mat=%d n:%d %d\n", elem[anz->e].nr, elem[anz->e].type, elem[anz->e].group, elem[anz->e].mat,elem[anz->e].nod[0],elem[anz->e].nod[1] );
161 #endif
162 }
163 anz->n++;
164 anz->e++;
165 anz->l++;
166 fclose(handle);
167
168 node_field_size=anz->nmax+1;
169 if((node =(Nodes *)realloc( (Nodes *)node, node_field_size*sizeof(Nodes)))==NULL)
170 printf("\n\n ERROR: realloc failed\n\n") ;
171 else
172 printf ("\n %d nodes reallocated \n",anz->nmax);
173
174 elem_field_size=anz->e+1;
175 if ( (elem = (Elements *)realloc((Elements *)elem, elem_field_size * sizeof(Elements))) == NULL )
176 printf("\n\n ERROR: in readfrd realloc failed\n\n") ;
177 else
178 printf ("\n %d elements reallocated \n", anz->e);
179
180 if ( e_nmax > (anz->nmax) )
181 {
182 printf ("\nWARNING: element requestes a nodename higher than allocated\n\n");
183 printf (" e_nmax=%d e_nmin=%d\n", e_nmax, e_nmin );
184 }
185 if ( e_nmin < 1 )
186 {
187 printf ("\nWARNING: element requestes a nodename lower than allocated\n\n");
188 printf (" e_nmax=%d e_nmin=%d\n", e_nmax, e_nmin );
189 }
190
191 *nptr = node; *eptr = elem;
192 return(1);
193 }
194
195