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 1000000
28
29
30 /* ToDo:
31 */
32
33
freeDataset(Datasets * lcase,int nr)34 void freeDataset(Datasets *lcase, int nr)
35 {
36 int i;
37
38 printf(" free lc[%d] ncomps:%d\n",nr,lcase[nr].ncomps);
39 if(lcase[nr].loaded)
40 {
41 for(i=0; i<lcase[nr].ncomps; i++) free(lcase[nr].dat[i]);
42 }
43 /* always allocated */
44 free(lcase[nr].dat);
45 lcase[nr].dat=NULL;
46
47 if(lcase[nr].npheader)
48 {
49 for(i=0; i<lcase[nr].npheader; i++) free(lcase[nr].pheader[i]);
50 free(lcase[nr].pheader);
51 lcase[nr].pheader=NULL;
52 }
53 for(i=0; i<lcase[nr].ncomps; i++)
54 {
55 free(lcase[nr].compName[i]);
56 free(lcase[nr].icname[i]);
57 }
58 /* always allocated */
59 free(lcase[nr].compName);
60 free(lcase[nr].icname);
61 lcase[nr].compName=NULL;
62 lcase[nr].icname=NULL;
63
64 free(lcase[nr].ictype);
65 free(lcase[nr].icind1);
66 free(lcase[nr].icind2);
67 free(lcase[nr].iexist);
68 free(lcase[nr].max);
69 free(lcase[nr].menu);
70 free(lcase[nr].min);
71 free(lcase[nr].nmax);
72 free(lcase[nr].nmin);
73 free(lcase[nr].fileptr);
74 lcase[nr].fileptr=NULL;
75 lcase[nr].loaded=0;
76
77 /* edat not propper implemented or deleted */
78 // for(i=0; i<3; i++) for(e=0; e<anz->e; e++) free(lcase[nr].edat[i][e]);
79 }
80
81
82 /* read_mode=0: jump '100C' data-blocks and read them later on demand */
83 /* in any case for each results of a new step the first data-block is readed to see how much nodes are included */
84
readfrd(char * datin,Summen * anz,Nodes ** nptr,Elements ** eptr,Datasets ** lptr,int read_mode)85 int readfrd( char *datin, Summen *anz, Nodes **nptr, Elements **eptr, Datasets **lptr, int read_mode )
86 {
87 FILE *handle;
88 int i=0, j=0;
89 int nodeflag=0, elemflag=0, errFlag=0, firsttime=1;
90 int n; /* used in format_flag */
91 long offset=0;
92 fpos_t *filepntr=NULL;
93 int elem_data=0,nod_data=0, nod_1st_block=0; /* nodes in resultblock, nodes in 1st block (if no "nr of nodes" are given in frd file, 100C-line) */
94
95 int ncomps, indx, maxcomps=0, nvals, nentities;
96 char rec_str[MAX_LINE_LENGTH];
97 int node_field_size, elem_field_size;
98 int e_nmax=1, e_nmin=1;
99 int length, flag, format_flag;
100 int ipuf, nodenr=0;
101 static float *value=NULL;
102 static double *dvalue=NULL;
103
104 char **dat, **compName;
105 int *menu, *ictype, *icind1, *icind2, *iexist;
106
107 int anz_p=-1;
108 char **pheader=NULL;
109
110 Nodes *node=NULL;
111 Elements *elem=NULL;
112 Datasets *lcase=NULL;
113
114
115 if ( (lcase = (Datasets *)malloc( 1 * sizeof(Datasets))) == NULL )
116 printf("\n\n ERROR: malloc failed\n\n") ;
117
118 anz->u=anz->n=anz->e=anz->l=-1;
119 anz->nmax=0; anz->nmin=MAX_INTEGER;
120 anz->emax=0; anz->emin=MAX_INTEGER;
121 length = 1;
122 format_flag=0;
123
124 /* Open the files and check to see that it was opened correctly */
125 handle = fopen (datin, "rb");
126 if ( handle== NULL ) { printf ("ERROR in readfrd: The input file \"%s\" could not be opened.\n\n", datin); return(-1); }
127 else printf (" file:%s opened\n", datin);
128
129
130 printf (" reading frd format\n");
131 length = frecord( handle, rec_str);
132 rec_str[length]='\0';
133 flag = stoi(rec_str,4,5);
134 if (flag == 1 )
135 {
136 stos(rec_str,7,12,anz->model);
137 printf (" MODEL NAME: %s", anz->model);
138 }
139 else
140 {
141 printf ("\n\nFATAL ERROR: no proper file-format found.\n\n");
142 return (-1);
143 }
144
145 while(length)
146 {
147
148 /* store the beginning of the data-block for later reading */
149 if(filepntr==NULL)
150 { if( (filepntr=(fpos_t *)malloc(1*sizeof(fpos_t))) == NULL ) printf(" ERROR: malloc failed\n"); }
151
152 if(fgetpos( handle, (fpos_t *)filepntr)!=0) { printf("error in fgetpos"); return(-1); }
153
154 read_again:;
155 length = frecord( handle, rec_str);
156 if (rec_str[length] == (char)EOF) break;
157 else rec_str[length] =(char)0;
158 printf ("record:%s\n", rec_str);
159
160
161 flag = stoi(rec_str,1,5);
162 format_flag = stoi(rec_str,74,75);
163 //printf ("OPCODE:%d IFORMT:%d\n", flag, format_flag );
164
165 if(flag == 9999) goto read_again;
166 if(( (nodeflag==1)&&(flag == 2) ) || ( (elemflag==1)&&(flag == 3) ))
167 {
168 printf ("found a second mesh. This mesh will be ignored\n");
169 if(format_flag < 2) flag=-1;
170 else flag*=-1;
171 }
172 if(flag == 1)
173 {
174 /* User Header used to store general information */
175 if(rec_str[5]=='U')
176 {
177 anz->u++;
178 if(!anz->u)
179 { if(( anz->uheader=(char **)malloc( sizeof(char *))) == NULL )
180 printf("\n\n ERROR: malloc failed\n\n") ; }
181 else if(( anz->uheader=(char **)realloc((char **)anz->uheader, (anz->u+1)*sizeof(char *))) == NULL )
182 printf("\n\n ERROR: realloc failed\n\n") ;
183 if(( anz->uheader[anz->u]=(char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
184 printf("\n\n ERROR: malloc failed\n\n") ;
185 strcpy(anz->uheader[anz->u],rec_str);
186 }
187
188 /* Project Header used to store additional Dataset information */
189 if(rec_str[5]=='P')
190 {
191 anz_p++;
192 if(!anz_p)
193 { if(( pheader=(char **)malloc( sizeof(char *))) == NULL )
194 printf("\n\n ERROR: malloc failed\n\n") ; }
195 else if(( pheader=(char **)realloc((char **)pheader, (anz_p+1)*sizeof(char *))) == NULL )
196 printf("\n\n ERROR: realloc failed\n\n") ;
197 if(( pheader[anz_p]=(char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
198 printf("\n\n ERROR: malloc failed\n\n") ;
199 strcpy(pheader[anz_p],rec_str);
200 }
201 }
202
203 else if(flag == 2)
204 {
205 /* store the pheaders which are leading this block */
206 anz->p=anz_p+1;
207 anz->pheader=pheader;
208 anz_p=-1;
209 pheader=NULL;
210
211 printf ("reading Nodes\n");
212 nodeflag=1;
213
214 /* nr of nodes per block can be read from the frd file, this is not documented in the original frd-spec. */
215 nod_data=stoi( rec_str, 25, 36 );
216 if(nod_data>0) node_field_size=nod_data;
217 else node_field_size=INI_FIELD_SIZE;
218 do
219 {
220 if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
221 {
222 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
223 node_field_size/=2;
224 }
225 if(node_field_size<0)
226 {
227 printf("\n\n ERROR: not enough memory in readfrd()\n\n");
228 exit(-1);
229 }
230 }while(!node);
231 for(i=0; i<node_field_size; i++) node[i].indx=-1;
232
233 if (format_flag < 2)
234 {
235 do
236 {
237 length = frecord( handle, rec_str);
238 if (rec_str[length] == (char)EOF) break;
239 flag = stoi(rec_str,1,3);
240 anz->n++;
241 if (flag == -3) break;
242 if (!format_flag) node[anz->n].nr = stoi(rec_str,4,8);
243 else node[anz->n].nr = stoi(rec_str,4,13);
244 if (node[anz->n].nr>=node_field_size)
245 {
246 if(node[anz->n].nr<MAX_INTEGER/2) node_field_size=node[anz->n].nr*2+1; else node_field_size=MAX_INTEGER-2;
247 nodenr=node[anz->n].nr;
248 do
249 {
250 if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
251 {
252 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
253 node_field_size=nodenr+(node_field_size-nodenr)/2;
254 }
255 if(node_field_size<=nodenr)
256 {
257 printf("\n\n ERROR: not enough memory in readfrd() for node-nr:%d available\n\n", nodenr);
258 exit(-1);
259 }
260 }while(!node);
261 for(i=anz->nmax+1; i<node_field_size; i++) node[i].indx=-1;
262 }
263 /* save only nodes which are not already stored */
264 if(node[node[anz->n].nr].indx<0)
265 {
266 node[node[anz->n].nr].indx=anz->n;
267 if (!format_flag)
268 {
269 node[node[anz->n].nr].nx = stof(&rec_str[8],1,12);
270 node[node[anz->n].nr].ny = stof(&rec_str[20],1,12);
271 node[node[anz->n].nr].nz = stof(&rec_str[32],1,12);
272 }
273 else
274 {
275 node[node[anz->n].nr].nx = stof(&rec_str[13],1,12);
276 node[node[anz->n].nr].ny = stof(&rec_str[25],1,12);
277 node[node[anz->n].nr].nz = stof(&rec_str[37],1,12);
278 }
279 if (node[anz->n].nr > anz->nmax) anz->nmax=node[anz->n].nr;
280 if (node[anz->n].nr < anz->nmin) anz->nmin=node[anz->n].nr;
281 #if TEST
282 printf (" n=%d x=%lf y=%lf z=%lf \n", node[anz->n].nr,
283 node[node[anz->n].nr].nx, node[node[anz->n].nr].ny,
284 node[node[anz->n].nr].nz);
285 #endif
286 }
287 } while(flag != -3);
288 }
289
290 /* binary format */
291 else
292 {
293 if ( (value = (float *)realloc((float *)value, (3) * sizeof(float))) == NULL )
294 printf("\n\n ERROR: realloc failed, value\n\n") ;
295 for(i=0; i<nod_data; i++)
296 {
297 anz->n++;
298 length=fread((int *)&node[anz->n].nr,sizeof(int),1,handle);
299 //printf("n:%d\n", node[anz->n].nr);
300 if (node[anz->n].nr>=node_field_size)
301 {
302 if(node[anz->n].nr<MAX_INTEGER/2) node_field_size=node[anz->n].nr*2+1; else node_field_size=MAX_INTEGER-2;
303 nodenr= node[anz->n].nr;
304 do
305 {
306 if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
307 {
308 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
309 node_field_size=nodenr+(node_field_size-nodenr)/2;
310 }
311 if(node_field_size<=nodenr)
312 {
313 printf("\n\n ERROR: not enough memory in readfrd() for the node-nr:%d available\n\n", nodenr);
314 exit(-1);
315 }
316 }while(!node);
317 for(n=anz->nmax+1; n<node_field_size; n++) node[n].indx=-1;
318 }
319 /* save only nodes which are not already stored */
320 if (format_flag == 2)
321 {
322 length=fread((float *)value,sizeof(float),3,handle);
323 //printf("n:%f %f %f\n", value[0],value[1],value[2]);
324 if(node[node[anz->n].nr].indx<0)
325 {
326 node[node[anz->n].nr].indx=anz->n;
327 node[node[anz->n].nr].nx = value[0];
328 node[node[anz->n].nr].ny = value[1];
329 node[node[anz->n].nr].nz = value[2];
330 }
331 else fseeko(handle, 3*sizeof(float), SEEK_CUR);
332 }
333 else
334 {
335 if(node[node[anz->n].nr].indx<0)
336 {
337 length=fread((double *)&node[node[anz->n].nr].nx,sizeof(double),3,handle);
338 node[node[anz->n].nr].indx=anz->n;
339 }
340 else fseeko(handle, 3*sizeof(double), SEEK_CUR);
341 }
342 if (node[anz->n].nr > anz->nmax) anz->nmax=node[anz->n].nr;
343 if (node[anz->n].nr < anz->nmin) anz->nmin=node[anz->n].nr;
344 #if TEST
345 printf (" n=%d x=%lf y=%lf z=%lf \n", node[anz->n].nr,
346 node[node[anz->n].nr].nx, node[node[anz->n].nr].ny,
347 node[node[anz->n].nr].nz);
348 #endif
349 }
350 anz->n++;
351 }
352 node_field_size=anz->nmax+1;
353 if((node = (Nodes *)realloc( (Nodes *)node, node_field_size * sizeof(Nodes))) == NULL )
354 printf("\n\n ERROR: realloc failed\n\n") ;
355 else
356 printf ("\n %d nodes reallocated \n",anz->nmax);
357 //nod_1st_block=anz->n;
358 }
359
360 else if(flag == 3)
361 {
362 printf ("reading Elements\n");
363 // anz->emax=-MAX_INTEGER; anz->emin=MAX_INTEGER;
364 elemflag=1;
365 e_nmax=-MAX_INTEGER; e_nmin=MAX_INTEGER;
366
367 /* nr of elems per block can be read from the frd file, this is not documented in the original frd-spec. */
368 elem_data=stoi( rec_str, 25, 36 );
369 if(elem_data>0) elem_field_size=elem_data;
370 else elem_field_size=INI_FIELD_SIZE;
371 do
372 {
373 if((elem = (Elements *)realloc( (Elements *)elem, (elem_field_size+1) * sizeof(Elements))) == NULL )
374 {
375 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size );
376 elem_field_size/=2;
377 }
378 if(elem_field_size<0)
379 {
380 printf("\n\n ERROR: not enough memory in readfrd()\n\n");
381 exit(-1);
382 }
383 }while(!elem);
384
385 /* binary format */
386 if (format_flag == 2)
387 {
388 if ( (elem = (Elements *)realloc((Elements *)elem, elem_data * sizeof(Elements))) == NULL )
389 printf("\n\n ERROR: in readfrd realloc failed\n\n") ;
390 else
391 printf ("\n %d elements allocated \n", elem_data);
392 for (i=0; i<elem_data; i++)
393 {
394 anz->e++;
395 length=fread((int *)&elem[anz->e].nr,sizeof(int),1,handle);
396 length=fread((int *)&elem[anz->e].type,sizeof(int),1,handle);
397 length=fread((int *)&elem[anz->e].group,sizeof(int),1,handle);
398 length=fread((int *)&elem[anz->e].mat,sizeof(int),1,handle);
399 elem[anz->e].attr = 0;
400 anz->etype[elem[anz->e].type]++;
401 if (elem[anz->e].nr > anz->emax) anz->emax=elem[anz->e].nr;
402 if (elem[anz->e].nr < anz->emin) anz->emin=elem[anz->e].nr;
403 if (elem[anz->e].type == 1) ipuf = 8; /* HEXA8 */
404 else if (elem[anz->e].type == 2) ipuf = 6; /* PE6 */
405 else if (elem[anz->e].type == 3) ipuf = 4; /* TET4 */
406 else if (elem[anz->e].type == 4) ipuf = 20; /* HEXA20 */
407 else if (elem[anz->e].type == 5) ipuf = 15; /* PE15 */
408 else if (elem[anz->e].type == 6) ipuf = 10; /* TET10 */
409 else if (elem[anz->e].type == 7) ipuf = 3; /* TRI3 */
410 else if (elem[anz->e].type == 8) ipuf = 6; /* TRI6 */
411 else if (elem[anz->e].type == 9) ipuf = 4; /* QUAD4 */
412 else if (elem[anz->e].type == 10) ipuf = 8; /* QUAD8 */
413 else if (elem[anz->e].type == 11) ipuf = 2; /* BEAM2 */
414 else if (elem[anz->e].type == 12) ipuf = 3; /* BEAM3 */
415 //printf("el:%d t:%d g:%d m:%d n:%d\n", elem[anz->e].nr, elem[anz->e].type,elem[anz->e].group,elem[anz->e].mat, ipuf);
416 length=fread((int *)elem[anz->e].nod,sizeof(int),ipuf,handle);
417 //for(j=0;j<ipuf; j++) printf(" %d",elem[anz->e].nod[j]); printf("\n");
418 }
419 anz->e++;
420 }
421 else
422 {
423 do
424 {
425 length = frecord( handle, rec_str);
426 if (rec_str[length] == (char)EOF) break;
427 flag = stoi(rec_str,1,3);
428 anz->e++;
429
430 if (flag == -3) break;
431 else if ((flag == -1)||(flag == -2))
432 {
433 if (anz->e>=elem_field_size)
434 {
435 if(anz->e<MAX_INTEGER/2) elem_field_size=anz->e*2+1; else elem_field_size=MAX_INTEGER-2;
436 do
437 {
438 if((elem = (Elements *)realloc( (Elements *)elem, (elem_field_size+1) * sizeof(Elements))) == NULL )
439 {
440 printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size );
441 elem_field_size=anz->e+(elem_field_size-anz->e)/2;
442 }
443 if(elem_field_size<=anz->e)
444 {
445 printf("\n\n ERROR: not enough memory in readfrd()\n\n");
446 exit(-1);
447 }
448 }while(!elem);
449 }
450 if (!format_flag)
451 {
452 elem[anz->e].nr = stoi(&rec_str[3], 1, 5);
453 elem[anz->e].type = stoi(&rec_str[8], 1, 5);
454 elem[anz->e].group = stoi(&rec_str[13], 1, 5);
455 elem[anz->e].mat = stoi(&rec_str[18], 1, 5);
456 }
457 else
458 {
459 elem[anz->e].nr = stoi(&rec_str[3], 1, 10);
460 elem[anz->e].type = stoi(&rec_str[13], 1, 5);
461 elem[anz->e].group = stoi(&rec_str[18], 1, 5);
462 elem[anz->e].mat = stoi(&rec_str[23], 1, 5);
463 }
464 elem[anz->e].attr = 0;
465 ipuf=0;
466 if (elem[anz->e].nr > anz->emax) anz->emax=elem[anz->e].nr;
467 if (elem[anz->e].nr < anz->emin) anz->emin=elem[anz->e].nr;
468 if (elem[anz->e].type == 1) ipuf = 8; /* HEXA8 */
469 else if (elem[anz->e].type == 2) ipuf = 6; /* PE6 */
470 else if (elem[anz->e].type == 3) ipuf = 4; /* TET4 */
471 else if (elem[anz->e].type == 4) ipuf = 20; /* HEXA20 */
472 else if (elem[anz->e].type == 5) ipuf = 15; /* PE15 */
473 else if (elem[anz->e].type == 6) ipuf = 10; /* TET10 */
474 else if (elem[anz->e].type == 7) ipuf = 3; /* TRI3 */
475 else if (elem[anz->e].type == 8) ipuf = 6; /* TRI6 */
476 else if (elem[anz->e].type == 9) ipuf = 4; /* QUAD4 */
477 else if (elem[anz->e].type == 10) ipuf = 8; /* QUAD8 */
478 else if (elem[anz->e].type == 11) ipuf = 2; /* BEAM2 */
479 else if (elem[anz->e].type == 12) ipuf = 3; /* BEAM3 */
480 #if TEST
481 printf ("\n%d e=%d typ=%d grp=%d mat=%d \n", flag, elem[anz->e].nr,
482 elem[anz->e].type, elem[anz->e].group, elem[anz->e].mat );
483 #endif
484 length = frecord( handle, rec_str );
485 if (ipuf==0)
486 {
487 printf (" element:%d is from unknown type:%d\n", elem[anz->e].nr, elem[anz->e].type);
488 }
489 else
490 {
491 anz->etype[elem[anz->e].type]++;
492 /* read the node-lines */
493 if (!format_flag)
494 {
495 j=0;
496 for (i=0; i<ipuf; i++)
497 {
498 elem[anz->e].nod[i] = stoi(&rec_str[3+j*5], 1, 5);
499 if (j<14) j++;
500 else
501 {
502 if (i<ipuf-1) length = frecord( handle, rec_str ); j=0;
503 }
504 }
505 }
506 else
507 {
508 j=0;
509 for (i=0; i<ipuf; i++)
510 {
511 elem[anz->e].nod[i] = stoi(&rec_str[3+j*10], 1, 10);
512 if (j<9) j++;
513 else
514 {
515 if (i<ipuf-1) length = frecord( handle, rec_str ); j=0;
516 }
517 }
518 }
519 }
520 }
521 else
522 {
523 printf ("ERROR: flag:%d is not expected, must be -1 or -2!\n%s", flag, rec_str );
524 exit(-1);
525 }
526 } while(flag != -3);
527 elem_field_size=anz->e+1;
528 if ( (elem = (Elements *)realloc((Elements *)elem, elem_field_size * sizeof(Elements))) == NULL )
529 printf("\n\n ERROR: in readfrd realloc failed\n\n") ;
530 else
531 printf ("\n %d elements reallocated \n", anz->e);
532 }
533 }
534
535 else if(flag == 100)
536 {
537 anz->l++;
538
539 printf ("reading Dataset No:%d\n",anz->l+1);
540 if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
541 { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
542
543 lcase[anz->l].handle=(FILE *)NULL;
544
545 /* store the pheaders which are leading this block */
546 lcase[anz->l].npheader=anz_p+1;
547 lcase[anz->l].pheader=pheader;
548 lcase[anz->l].fileptr=NULL;
549 lcase[anz->l].loaded=1;
550 lcase[anz->l].format_flag=format_flag;
551 anz_p=-1;
552 pheader=NULL;
553 offset=0;
554
555 stos( rec_str, 7, 12, lcase[anz->l].dataset_name);
556 lcase[anz->l].value=stof( rec_str, 13, 24 );
557
558 /* nr of nodes per block can be read from the frd file, this is not documented in the original frd-spec. */
559 nod_data=stoi( rec_str, 25, 36 );
560 /* because of a bug in ccx2.0 this nr can be wrong. In this case it is higher than the actual nr of nodes. */
561 if(nod_data>anz->n)
562 {
563 printf(" WARNING: in this result-block are more nodes announced:%d than in the model defined:%d\n Please inform the program-admin of the originator of the frd-file\n\n", nod_data, anz->n);
564 //exit(0);
565 nod_data=anz->n;
566 }
567 #ifdef DEVEL
568 if(!nod_data)
569 {
570 nod_data=nod_1st_block;
571 printf("nods in block assumed:%d\n",nod_data );
572 }
573 #endif
574 stos( rec_str, 37, 56, lcase[anz->l].dataset_text);
575 lcase[anz->l].analysis_type=stoi( rec_str, 57, 58 );
576 lcase[anz->l].step_number=stoi( rec_str, 59, 63 );
577 if(strlen(rec_str)>72 )
578 {
579 stos(rec_str,64,73,lcase[anz->l].analysis_name);
580 }
581 else
582 {
583 strcpy(lcase[anz->l].analysis_name,"");
584 }
585 ncomps=nentities=indx=0;
586 if (!format_flag) n=8;
587 else n=13;
588 errFlag=0;
589 firsttime=1;
590
591 ipuf=-1;
592 //if(lcase[anz->l].analysis_type==2) //in the moment ccx writes the wrong number, therefore:
593 if(lcase[anz->l].analysis_type>=2)
594 {
595 for(i=0;i<lcase[anz->l].npheader; i++)
596 {
597 if(compare(&lcase[anz->l].pheader[i][5],"PHID", 4)==4)
598 {
599 sscanf(lcase[anz->l].pheader[i],"%*s %d", &ipuf);
600 if(ipuf>-1) sprintf(lcase[anz->l].dataset_text,"ND:%d",ipuf);
601 }
602 }
603 if(ipuf!=-1) for(i=0;i<lcase[anz->l].npheader; i++)
604 {
605 if(compare(&lcase[anz->l].pheader[i][5],"PMODE", 5)==5)
606 {
607 sscanf(lcase[anz->l].pheader[i],"%*s %d", &ipuf);
608 if(ipuf>-1) sprintf(&lcase[anz->l].dataset_text[strlen(lcase[anz->l].dataset_text)]," MODE:%d",ipuf);
609 }
610 }
611 }
612
613 /* initialize */
614 lcase[anz->l].ncomps=0;
615 do
616 {
617 /* bin mode, active after last column definition was read (-5 lines). Attention flag:-6 not permitted so far! */
618 if (( format_flag>=2)&&(lcase[anz->l].ncomps>0)&&(ncomps==lcase[anz->l].ncomps))
619 {
620 //printf("format_flag=%d ncomps:%d lcncomps:%d\n",format_flag,ncomps,lcase[anz->l].ncomps);
621
622 /* if offset is known jump the filepointer before the next block or else continue reading assuming values for all nodes are provided */
623 if(offset)
624 {
625 lcase[anz->l].loaded=0;
626 if (firsttime)
627 {
628 firsttime=0;
629
630 /* store the beginning of the data-block for later reading */
631 lcase[anz->l].fileptr=filepntr;
632 filepntr=NULL;
633 lcase[anz->l].handle=handle;
634 strcpy(lcase[anz->l].filename,datin);
635
636 if( fseeko( handle, offset, SEEK_CUR )!=0) printf("error in fseeko\n");
637 }
638 }
639 else if(format_flag==2)
640 {
641 if ( (value = (float *)realloc((float *)value, (lcase[anz->l].ncomps) * sizeof(float))) == NULL )
642 printf("\n\n ERROR: realloc failed, value\n\n") ;
643 for(n=0; n<nod_data; n++)
644 {
645 length=fread((int *)&nodenr,sizeof(int),1,handle);
646 length=fread((float *)value,sizeof(float),lcase[anz->l].ncomps,handle);
647 // printf("n:%d N:%d ",n+1, nodenr);
648 for(i=0; i<lcase[anz->l].ncomps; i++)
649 {
650 // printf(" %f",value[i]);
651 lcase[anz->l].dat[i][nodenr]= value[i];
652 }
653 // printf("\n");
654 }
655 }
656 else if(format_flag==3)
657 {
658 if ( (dvalue = (double *)realloc((double *)dvalue, (lcase[anz->l].ncomps) * sizeof(double))) == NULL )
659 printf("\n\n ERROR: realloc failed, dvalue\n\n") ;
660 for(n=0; n<nod_data; n++)
661 {
662 length=fread((int *)&nodenr,sizeof(int),1,handle);
663 length=fread((double *)dvalue,sizeof(double),lcase[anz->l].ncomps,handle);
664 // printf("n:%d N:%d ",n+1, nodenr);
665 for(i=0; i<lcase[anz->l].ncomps; i++)
666 {
667 // printf(" %f",dvalue[i]);
668 lcase[anz->l].dat[i][nodenr]= dvalue[i];
669 }
670 // printf("\n");
671 }
672 }
673 break;
674 }
675
676 length = frecord( handle, rec_str);
677 if (rec_str[length] == (char)EOF) break;
678 flag = stoi(rec_str,1,3);
679 //printf("flag:%d\n", flag);
680 //printf("rec in block:%s\n", rec_str);
681
682 if(flag == -1)
683 {
684 /* if offset is known jump the filepointer before the next block and continue reading until flag=-3 */
685 if(offset)
686 {
687 lcase[anz->l].loaded=0;
688 if (firsttime)
689 {
690 firsttime=0;
691
692 /* store the beginning of the data-block for later reading */
693 lcase[anz->l].fileptr=filepntr;
694 filepntr=NULL;
695 lcase[anz->l].handle=handle;
696 strcpy(lcase[anz->l].filename,datin);
697
698 /* reduce the offset by the current record */
699 if( fseeko( handle, offset-length, SEEK_CUR )!=0) printf("error in fseeko\n");
700 }
701 }
702 else
703 {
704 nod_1st_block++;
705 if (format_flag) nodenr = stoi(rec_str,4,13); else nodenr = stoi(rec_str,4,8);
706 if (nodenr>anz->nmax)
707 {
708 if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
709 }
710 else if ( lcase[anz->l].irtype == 1 )
711 {
712 if(maxcomps==6)
713 {
714 i=6;
715 if ( format_flag)
716 {
717 lcase[anz->l].dat[0][nodenr]= stof(&rec_str[ 13 ], 1, 12);
718 lcase[anz->l].dat[1][nodenr]= stof(&rec_str[ 25 ], 1, 12);
719 lcase[anz->l].dat[2][nodenr]= stof(&rec_str[ 37 ], 1, 12);
720 lcase[anz->l].dat[3][nodenr]= stof(&rec_str[ 49 ], 1, 12);
721 lcase[anz->l].dat[4][nodenr]= stof(&rec_str[ 61 ], 1, 12);
722 lcase[anz->l].dat[5][nodenr]= stof(&rec_str[ 73 ], 1, 12);
723 }
724 else
725 {
726 lcase[anz->l].dat[0][nodenr]= stof(&rec_str[ 8 ], 1, 12);
727 lcase[anz->l].dat[1][nodenr]= stof(&rec_str[ 20 ], 1, 12);
728 lcase[anz->l].dat[2][nodenr]= stof(&rec_str[ 32 ], 1, 12);
729 lcase[anz->l].dat[3][nodenr]= stof(&rec_str[ 44 ], 1, 12);
730 lcase[anz->l].dat[4][nodenr]= stof(&rec_str[ 56 ], 1, 12);
731 lcase[anz->l].dat[5][nodenr]= stof(&rec_str[ 68 ], 1, 12);
732 }
733 }
734 else
735 {
736 for(i=0; i<maxcomps; i++) lcase[anz->l].dat[i][nodenr]= stof(&rec_str[n+i*12], 1, 12);
737 }
738 /* printf("%d", nodenr); for (i=0; i<maxcomps; i++) printf(" %f",lcase[anz->l].dat[i][nodenr] ); printf("\n"); */
739 }
740 else i=0;
741 }
742 }
743 else if(flag == -2)
744 {
745 if (!format_flag) n=8;
746 else n=13;
747 j=0;
748
749 /* in case the data should be read directly and not on demand */
750 if(!offset)
751 {
752 do
753 {
754 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[n+j*12], 1, 12);
755 i++;j++;
756 }while((j<6)&&(i<lcase[anz->l].ncomps));
757 }
758 }
759 else if (flag == -4)
760 {
761 stos( rec_str, 6, 13, lcase[anz->l].name);
762 lcase[anz->l].ncomps = stoi(rec_str,14,18);
763 lcase[anz->l].irtype = stoi(rec_str,19,23);
764
765 if( lcase[anz->l].irtype > 2 )
766 {
767 printf(" Found ELEMENT DATA, this is not suported!\n");
768 anz->l--;
769 goto next;
770 }
771
772 if ( (lcase[anz->l].nmax = (int *)malloc( (lcase[anz->l].ncomps) * sizeof(int))) == NULL )
773 printf("\n\n ERROR: malloc failure\n\n" );
774 if ( (lcase[anz->l].nmin = (int *)malloc( (lcase[anz->l].ncomps) * sizeof(int))) == NULL )
775 printf("\n\n ERROR: malloc failure\n\n" );
776 if ( (lcase[anz->l].max = (CGXFLOAT *)malloc( (lcase[anz->l].ncomps) * sizeof(CGXFLOAT))) == NULL )
777 printf("\n\n ERROR: malloc failure\n\n" );
778 if ( (lcase[anz->l].min = (CGXFLOAT *)malloc( (lcase[anz->l].ncomps) * sizeof(CGXFLOAT))) == NULL )
779 printf("\n\n ERROR: malloc failure\n\n" );
780 if ( (lcase[anz->l].compName = (char **)malloc( (lcase[anz->l].ncomps) * sizeof(char *))) == NULL )
781 printf("\n\n ERROR: malloc failure\n\n" );
782 if ( (lcase[anz->l].icname = (char **)malloc( (lcase[anz->l].ncomps) * sizeof(char *))) == NULL )
783 printf("\n\n ERROR: malloc failure\n\n" );
784 if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
785 printf("\n\n ERROR: malloc failure\n\n" );
786 if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
787 printf("\n\n ERROR: malloc failure\n\n" );
788 if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
789 printf("\n\n ERROR: malloc failure\n\n" );
790 if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
791 printf("\n\n ERROR: malloc failure\n\n" );
792 if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
793 printf("\n\n ERROR: malloc failure\n\n" );
794 if ( (lcase[anz->l].dat = (CGXFLOAT **)malloc( (lcase[anz->l].ncomps) * sizeof(CGXFLOAT *))) == NULL )
795 printf("\n\n ERROR: malloc failure\n\n" );
796 printf(" gen lc[%d] ncomps:%d\n",anz->l,lcase[anz->l].ncomps);
797 for(i=0; i<(lcase[anz->l].ncomps); i++)
798 {
799 if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
800 printf("\n\n ERROR: malloc failed\n\n" );
801 if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
802 printf("\n\n ERROR: malloc failed\n\n" );
803 lcase[anz->l].max[i]=-MAX_FLOAT;
804 lcase[anz->l].min[i]=MAX_FLOAT;
805 lcase[anz->l].nmax[i]=0;
806 lcase[anz->l].nmin[i]=0;
807 }
808 }
809 else if(flag == -5)
810 {
811 if(indx<lcase[anz->l].ncomps)
812 {
813 stos(rec_str, 6, 13, lcase[anz->l].compName[indx]);
814 lcase[anz->l].menu[indx] = stoi(rec_str,14,18);
815 lcase[anz->l].ictype[indx] = stoi(rec_str,19,23);
816 lcase[anz->l].icind1[indx] = stoi(rec_str,24,28);
817 lcase[anz->l].icind2[indx] = stoi(rec_str,29,33);
818 lcase[anz->l].iexist[indx] = stoi(rec_str,34,38);
819
820 /* requests for additional components are not supported so far */
821 if(lcase[anz->l].iexist[indx]==1)
822 {
823 free(lcase[anz->l].compName[indx]); lcase[anz->l].compName[indx]=NULL;
824 free(lcase[anz->l].icname[indx]); lcase[anz->l].icname[indx]=NULL;
825 }
826 else ncomps++;
827 indx++;
828 }
829 else
830 {
831 rec_str[14]='\0';
832 printf(" WARNING: unallocated component:%d \"%s\" %d\n", ncomps, &rec_str[5],lcase[anz->l].ncomps);
833 exit(0);
834 }
835 nentities++;
836
837 /* this is the last -5 line, try to figure out an offset (length of data-block) for the file-pointer */
838 /* and allocate data if no offset is defined (first time) */
839 if(nentities==lcase[anz->l].ncomps)
840 {
841 lcase[anz->l].ncomps=ncomps;
842 if(lcase[anz->l].ncomps<6) maxcomps=lcase[anz->l].ncomps;
843 else maxcomps=6;
844
845 nvals=0;
846 for (i=0; i<ncomps; i++) if(lcase[anz->l].iexist[i]!=1) nvals++;
847 printf("ncomps:%d nvals:%d\n", ncomps, nvals);
848
849 if(!read_mode)
850 {
851 if(nod_data)
852 {
853 if (format_flag==2)
854 {
855 offset= nod_data * (4+nvals*4);
856 }
857 else if (format_flag==3)
858 {
859 offset= nod_data * (4+nvals*8);
860 }
861 else
862 {
863 /* just to get an approximate offset: */
864 if (!format_flag) n=8;
865 else n=13;
866 if(nvals<=6) offset= nod_data * (n+nvals*12+1);
867 else
868 {
869 offset=0;
870 for(i=0; i<nvals/6; i++)
871 offset+= nod_data * (n+6*12+1);
872 if(nvals%6)
873 offset+= nod_data * (n+(nvals%6)*12+1);
874 }
875 //printf("offset:%d nod_data:%d n:%d nvals:%d\n", offset,nod_data,n,nvals);
876 }
877 }
878 }
879
880 if(!offset)
881 {
882 /* in case the data should be read directly and not on demand */
883 for(i=0; i<(lcase[anz->l].ncomps); i++)
884 {
885 if ( (lcase[anz->l].dat[i] = (CGXFLOAT *)malloc( (anz->nmax+1) * sizeof(CGXFLOAT))) == NULL )
886 printf("\n\n ERROR: malloc failure\n\n" );
887 for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
888 }
889 }
890 }
891
892 }
893 else if(flag == -6)
894 {
895 length= strsplt( rec_str, ' ', &dat);
896 ipuf=atoi(dat[2]);
897 if ( (compName = (char **)malloc( ipuf * sizeof(char *))) == NULL )
898 printf("\n\n ERROR: malloc failure\n\n" );
899 for(i=0; i<ipuf; i++)
900 {
901 if ( (compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
902 printf("\n\n ERROR: malloc failed\n\n" );
903 }
904 for (i=0; i<ipuf; i++) strcpy(compName[i], lcase[anz->l].compName[ atoi(dat[i+3])-1 ]);
905 for (i=0; i<ipuf; i++) strcpy(lcase[anz->l].compName[i],compName[i]);
906 if ( (menu = (int *)malloc( ipuf * sizeof(int))) == NULL )
907 printf("\n\n ERROR: malloc failure\n\n" );
908 if ( (ictype = (int *)malloc( ipuf * sizeof(int))) == NULL )
909 printf("\n\n ERROR: malloc failure\n\n" );
910 if ( (icind1 = (int *)malloc( ipuf * sizeof(int))) == NULL )
911 printf("\n\n ERROR: malloc failure\n\n" );
912 if ( (icind2 = (int *)malloc( ipuf * sizeof(int))) == NULL )
913 printf("\n\n ERROR: malloc failure\n\n" );
914 if ( (iexist = (int *)malloc( ipuf * sizeof(int))) == NULL )
915 printf("\n\n ERROR: malloc failure\n\n" );
916 for (i=0; i<ipuf; i++) menu[i] = lcase[anz->l].menu[atoi(dat[i+3])-1];
917 for (i=0; i<ipuf; i++) lcase[anz->l].menu[i] =menu[i];
918 for (i=0; i<ipuf; i++) ictype[i] = lcase[anz->l].ictype[atoi(dat[i+3])-1];
919 for (i=0; i<ipuf; i++) lcase[anz->l].ictype[i] =ictype[i];
920 for (i=0; i<ipuf; i++) icind1[i] = lcase[anz->l].icind1[atoi(dat[i+3])-1];
921 for (i=0; i<ipuf; i++) lcase[anz->l].icind1[i] =icind1[i];
922 for (i=0; i<ipuf; i++) icind2[i] = lcase[anz->l].icind2[atoi(dat[i+3])-1];
923 for (i=0; i<ipuf; i++) lcase[anz->l].icind2[i] =icind2[i];
924 for (i=0; i<ipuf; i++) iexist[i] = lcase[anz->l].iexist[atoi(dat[i+3])-1];
925 for (i=0; i<ipuf; i++) lcase[anz->l].iexist[i] =iexist[i];
926
927 for(i=0; i<length; i++) free(dat[i]);
928 free(dat);
929
930 for(i=0; i<ipuf; i++) free(compName[i]);
931 free(compName);
932 free(menu);
933 free(ictype);
934 free(icind1);
935 free(icind2);
936 free(iexist);
937 }
938 }while(flag!=-3);
939
940 /* in case the data should be read directly and not on demand */
941 if(!offset)
942 {
943 for(j=0; j<anz->n; j++)
944 {
945 for(i=0; i<lcase[anz->l].ncomps; i++)
946 {
947 if(lcase[anz->l].dat[i][node[j].nr] > lcase[anz->l].max[i])
948 {
949 lcase[anz->l].max[i]=lcase[anz->l].dat[i][node[j].nr];
950 lcase[anz->l].nmax[i]=node[j].nr;
951 }
952 if(lcase[anz->l].dat[i][node[j].nr] < lcase[anz->l].min[i])
953 {
954 lcase[anz->l].min[i]=lcase[anz->l].dat[i][node[j].nr];
955 lcase[anz->l].nmin[i]=node[j].nr;
956 }
957 }
958 }
959 }
960 }
961
962 else if(flag == 4)
963 {
964 anz->l++;
965 printf ("reading Dataset No:%d\n",anz->l+1);
966 if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
967 { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
968
969 lcase[anz->l].value=stof( rec_str, 13, 25 );
970 strcpy(lcase[anz->l].name,"DISP ");
971 lcase[anz->l].ncomps = 3;
972 lcase[anz->l].irtype = 1;
973 lcase[anz->l].loaded = 1;
974 lcase[anz->l].format_flag=format_flag;
975
976 if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
977 printf("\n\n ERROR: malloc failure\n\n" );
978 if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
979 printf("\n\n ERROR: malloc failure\n\n" );
980 if ( (lcase[anz->l].max = (CGXFLOAT *)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT))) == NULL )
981 printf("\n\n ERROR: malloc failure\n\n" );
982 if ( (lcase[anz->l].min = (CGXFLOAT *)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT))) == NULL )
983 printf("\n\n ERROR: malloc failure\n\n" );
984 if ( (lcase[anz->l].dat = (CGXFLOAT **)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT *))) == NULL )
985 printf("\n\n ERROR: malloc failure\n\n" );
986 if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
987 printf("\n\n ERROR: malloc failure\n\n" );
988 if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
989 printf("\n\n ERROR: malloc failure\n\n" );
990 for(i=0; i<lcase[anz->l].ncomps; i++)
991 {
992 if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
993 printf("\n\n ERROR: malloc failed\n\n" );
994 if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
995 printf("\n\n ERROR: malloc failed\n\n" );
996 lcase[anz->l].max[i]=-MAX_FLOAT;
997 lcase[anz->l].min[i]=MAX_FLOAT;
998 if ( (lcase[anz->l].dat[i] = (CGXFLOAT *)malloc( (anz->nmax+1) * sizeof(CGXFLOAT))) == NULL )
999 printf("\n\n ERROR: malloc failure\n\n" );
1000 for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
1001 }
1002 if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1003 printf("\n\n ERROR: malloc failure\n\n" );
1004 if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1005 printf("\n\n ERROR: malloc failure\n\n" );
1006 if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1007 printf("\n\n ERROR: malloc failure\n\n" );
1008 if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1009 printf("\n\n ERROR: malloc failure\n\n" );
1010 if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1011 printf("\n\n ERROR: malloc failure\n\n" );
1012
1013 for(i=0; i<lcase[anz->l].ncomps; i++)
1014 {
1015 lcase[anz->l].menu[i] = 1;
1016 lcase[anz->l].ictype[i] = 2;
1017 lcase[anz->l].icind1[i] = i+1;
1018 lcase[anz->l].icind2[i] = 0;
1019 lcase[anz->l].iexist[i] = 0;
1020 }
1021
1022 strcpy(lcase[anz->l].compName[0], "x ");
1023 strcpy(lcase[anz->l].compName[1], "y ");
1024 strcpy(lcase[anz->l].compName[2], "z ");
1025 errFlag=0;
1026 do
1027 {
1028 length = frecord( handle, rec_str);
1029 if (rec_str[length] == (char)EOF) break;
1030 flag = stoi(rec_str,1,3);
1031 if(flag == -1)
1032 {
1033 if (!format_flag) nodenr = stoi(rec_str,4,8);
1034 else nodenr = stoi(rec_str,4,13);
1035 if (nodenr>anz->nmax)
1036 {
1037 if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1038 }
1039 else if (!format_flag)
1040 {
1041 for(i=0; i<lcase[anz->l].ncomps; i++)
1042 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[8+i*12], 1, 12);
1043 }
1044 else
1045 {
1046 for(i=0; i<lcase[anz->l].ncomps; i++)
1047 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[13+i*12], 1, 12);
1048 }
1049 }
1050 }while(flag!=-3);
1051 for(n=0; n<anz->n; n++)
1052 {
1053 nodenr=node[n].nr;
1054 for(i=0; i<lcase[anz->l].ncomps; i++)
1055 {
1056 if(lcase[anz->l].dat[i][nodenr] > lcase[anz->l].max[i])
1057 {
1058 lcase[anz->l].max[i]=lcase[anz->l].dat[i][nodenr];
1059 lcase[anz->l].nmax[i]=nodenr;
1060 }
1061 if(lcase[anz->l].dat[i][nodenr] < lcase[anz->l].min[i])
1062 {
1063 lcase[anz->l].min[i]=lcase[anz->l].dat[i][nodenr];
1064 lcase[anz->l].nmin[i]=nodenr;
1065 }
1066 }
1067 }
1068 }
1069
1070 else if(flag == 5)
1071 {
1072 anz->l++;
1073 printf ("reading Dataset No:%d\n",anz->l+1);
1074 if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
1075 { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
1076
1077 lcase[anz->l].value=stof( rec_str, 13, 25 );
1078 strcpy(lcase[anz->l].name,"STRESS ");
1079 lcase[anz->l].ncomps = 6;
1080 lcase[anz->l].irtype = 1;
1081 lcase[anz->l].loaded = 1;
1082 lcase[anz->l].format_flag=format_flag;
1083
1084 if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1085 printf("\n\n ERROR: malloc failure\n\n" );
1086 if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1087 printf("\n\n ERROR: malloc failure\n\n" );
1088 if ( (lcase[anz->l].max = (CGXFLOAT *)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT))) == NULL )
1089 printf("\n\n ERROR: malloc failure\n\n" );
1090 if ( (lcase[anz->l].min = (CGXFLOAT *)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT))) == NULL )
1091 printf("\n\n ERROR: malloc failure\n\n" );
1092 if ( (lcase[anz->l].dat = (CGXFLOAT **)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT *))) == NULL )
1093 printf("\n\n ERROR: malloc failure\n\n" );
1094 if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1095 printf("\n\n ERROR: malloc failure\n\n" );
1096 if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1097 printf("\n\n ERROR: malloc failure\n\n" );
1098 for(i=0; i<lcase[anz->l].ncomps; i++)
1099 {
1100 if ( (lcase[anz->l].dat[i] = (CGXFLOAT *)malloc( (anz->nmax+1) * sizeof(CGXFLOAT))) == NULL )
1101 printf("\n\n ERROR: malloc failure\n\n" );
1102 if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1103 printf("\n\n ERROR: malloc failed\n\n" );
1104 if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1105 printf("\n\n ERROR: malloc failed\n\n" );
1106 lcase[anz->l].max[i]=-MAX_FLOAT;
1107 lcase[anz->l].min[i]=MAX_FLOAT;
1108 lcase[anz->l].nmax[i]=0;
1109 lcase[anz->l].nmin[i]=0;
1110 for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
1111 }
1112 if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1113 printf("\n\n ERROR: malloc failure\n\n" );
1114 if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1115 printf("\n\n ERROR: malloc failure\n\n" );
1116 if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1117 printf("\n\n ERROR: malloc failure\n\n" );
1118 if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1119 printf("\n\n ERROR: malloc failure\n\n" );
1120 if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1121 printf("\n\n ERROR: malloc failure\n\n" );
1122
1123 for(i=0; i<lcase[anz->l].ncomps; i++)
1124 {
1125 lcase[anz->l].menu[i] = 1;
1126 lcase[anz->l].ictype[i] = 4;
1127 lcase[anz->l].iexist[i] = 0;
1128 }
1129 lcase[anz->l].icind1[0] = 1;
1130 lcase[anz->l].icind2[0] = 1;
1131 lcase[anz->l].icind1[1] = 2;
1132 lcase[anz->l].icind2[1] = 2;
1133 lcase[anz->l].icind1[2] = 3;
1134 lcase[anz->l].icind2[2] = 3;
1135 lcase[anz->l].icind1[3] = 1;
1136 lcase[anz->l].icind2[3] = 2;
1137 lcase[anz->l].icind1[4] = 2;
1138 lcase[anz->l].icind2[4] = 3;
1139 lcase[anz->l].icind1[5] = 3;
1140 lcase[anz->l].icind2[5] = 1;
1141
1142 strcpy(lcase[anz->l].compName[0], "xx ");
1143 strcpy(lcase[anz->l].compName[1], "yy ");
1144 strcpy(lcase[anz->l].compName[2], "zz ");
1145 strcpy(lcase[anz->l].compName[3], "xy ");
1146 strcpy(lcase[anz->l].compName[4], "yz ");
1147 strcpy(lcase[anz->l].compName[5], "zx ");
1148 errFlag=0;
1149 do
1150 {
1151 length = frecord( handle, rec_str);
1152 if (rec_str[length] == (char)EOF) break;
1153 flag = stoi(rec_str,1,3);
1154 if(flag == -1)
1155 {
1156 if (!format_flag) nodenr = stoi(rec_str,4,8);
1157 else nodenr = stoi(rec_str,4,13);
1158 if (nodenr>anz->nmax)
1159 {
1160 if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1161 }
1162 else
1163 {
1164 /* new line */
1165 length = frecord( handle, rec_str);
1166 if (rec_str[length] == (char)EOF) break;
1167 if (!format_flag)
1168 {
1169 for(i=0; i<lcase[anz->l].ncomps; i++)
1170 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[8+i*12], 1, 12);
1171 }
1172 else
1173 {
1174 for(i=0; i<lcase[anz->l].ncomps; i++)
1175 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[13+i*12], 1, 12);
1176 }
1177 }
1178 }
1179 }while(flag!=-3);
1180 for(n=0; n<anz->n; n++)
1181 {
1182 nodenr=node[n].nr;
1183 for(i=0; i<lcase[anz->l].ncomps; i++)
1184 {
1185 if(lcase[anz->l].dat[i][nodenr] > lcase[anz->l].max[i])
1186 {
1187 lcase[anz->l].max[i]=lcase[anz->l].dat[i][nodenr];
1188 lcase[anz->l].nmax[i]=nodenr;
1189 }
1190 if(lcase[anz->l].dat[i][nodenr] < lcase[anz->l].min[i])
1191 {
1192 lcase[anz->l].min[i]=lcase[anz->l].dat[i][nodenr];
1193 lcase[anz->l].nmin[i]=nodenr;
1194 }
1195 }
1196 }
1197 }
1198
1199 else if((flag == 7)||(flag == 9))
1200 {
1201 anz->l++;
1202 printf ("reading Dataset No:%d\n",anz->l+1);
1203 if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
1204 { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
1205
1206 lcase[anz->l].value=stof( rec_str, 13, 25 );
1207 strcpy(lcase[anz->l].name,"TEMP ");
1208 lcase[anz->l].ncomps = 1;
1209 lcase[anz->l].irtype = 1;
1210 lcase[anz->l].loaded = 1;
1211 lcase[anz->l].format_flag=format_flag;
1212
1213 if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1214 printf("\n\n ERROR: malloc failure\n\n" );
1215 if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1216 printf("\n\n ERROR: malloc failure\n\n" );
1217 if ( (lcase[anz->l].max = (CGXFLOAT *)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT))) == NULL )
1218 printf("\n\n ERROR: malloc failure\n\n" );
1219 if ( (lcase[anz->l].min = (CGXFLOAT *)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT))) == NULL )
1220 printf("\n\n ERROR: malloc failure\n\n" );
1221 if ( (lcase[anz->l].dat = (CGXFLOAT **)malloc( lcase[anz->l].ncomps * sizeof(CGXFLOAT *))) == NULL )
1222 printf("\n\n ERROR: malloc failure\n\n" );
1223 if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1224 printf("\n\n ERROR: malloc failure\n\n" );
1225 if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1226 printf("\n\n ERROR: malloc failure\n\n" );
1227 for(i=0; i<lcase[anz->l].ncomps; i++)
1228 {
1229 if ( (lcase[anz->l].dat[i] = (CGXFLOAT *)malloc( (anz->nmax+1) * sizeof(CGXFLOAT))) == NULL )
1230 printf("\n\n ERROR: malloc failure\n\n" );
1231 if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1232 printf("\n\n ERROR: malloc failed\n\n" );
1233 if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1234 printf("\n\n ERROR: malloc failed\n\n" );
1235 lcase[anz->l].max[i]=-MAX_FLOAT;
1236 lcase[anz->l].min[i]=MAX_FLOAT;
1237 for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
1238 }
1239 if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1240 printf("\n\n ERROR: malloc failure\n\n" );
1241 if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1242 printf("\n\n ERROR: malloc failure\n\n" );
1243 if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1244 printf("\n\n ERROR: malloc failure\n\n" );
1245 if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1246 printf("\n\n ERROR: malloc failure\n\n" );
1247 if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1248 printf("\n\n ERROR: malloc failure\n\n" );
1249
1250 for(i=0; i<lcase[anz->l].ncomps; i++)
1251 {
1252 lcase[anz->l].menu[i] = 1;
1253 lcase[anz->l].ictype[i] = 1;
1254 lcase[anz->l].icind1[i] = i+1;
1255 lcase[anz->l].icind2[i] = 0;
1256 lcase[anz->l].iexist[i] = 0;
1257 }
1258
1259 strcpy(lcase[anz->l].compName[0], "Value ");
1260 errFlag=0;
1261 do
1262 {
1263 length = frecord( handle, rec_str);
1264 if (rec_str[length] == (char)EOF) break;
1265 flag = stoi(rec_str,1,3);
1266 if(flag == -1)
1267 {
1268 if (!format_flag) nodenr = stoi(rec_str,4,8);
1269 else nodenr = stoi(rec_str,4,13);
1270 if (nodenr>anz->nmax)
1271 {
1272 if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1273 }
1274 else if (!format_flag)
1275 {
1276 for(i=0; i<lcase[anz->l].ncomps; i++)
1277 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[8+i*12], 1, 12);
1278 }
1279 else
1280 {
1281 for(i=0; i<lcase[anz->l].ncomps; i++)
1282 lcase[anz->l].dat[i][nodenr]= stof(&rec_str[13+i*12], 1, 12);
1283 }
1284 }
1285 }while(flag!=-3);
1286 for(n=0; n<anz->n; n++)
1287 {
1288 nodenr=node[n].nr;
1289 for(i=0; i<lcase[anz->l].ncomps; i++)
1290 {
1291 if(lcase[anz->l].dat[i][nodenr] > lcase[anz->l].max[i])
1292 {
1293 lcase[anz->l].max[i]=lcase[anz->l].dat[i][nodenr];
1294 lcase[anz->l].nmax[i]=nodenr;
1295 }
1296 if(lcase[anz->l].dat[i][nodenr] < lcase[anz->l].min[i])
1297 {
1298 lcase[anz->l].min[i]=lcase[anz->l].dat[i][nodenr];
1299 lcase[anz->l].nmin[i]=nodenr;
1300 }
1301 }
1302 }
1303 }
1304
1305 else if(flag == -1)
1306 {
1307 next:;
1308 printf (" overread Block: %s\n", rec_str);
1309 do
1310 {
1311 length = frecord( handle, rec_str);
1312 if (rec_str[length] == (char)EOF) break;
1313 /* printf ("\n record:%d %s\n", length, rec_str); */
1314 if (length != 0)
1315 {
1316 flag = stoi(rec_str,1,5);
1317 }
1318 } while(flag != -3);
1319 }
1320 else if(flag == -2)
1321 {
1322 /* nr of nodes per block can be read from the frd file, this is not documented in the original frd-spec. */
1323 nod_data=stoi( rec_str, 25, 36 );
1324 printf ("scip %d nodes\n",nod_data);
1325 if(format_flag == 2) fseeko(handle, nod_data*(sizeof(int)+3*sizeof(float)), SEEK_CUR);
1326 else fseeko(handle, nod_data*(sizeof(int)+3*sizeof(double)), SEEK_CUR);
1327 }
1328 else if(flag == -3)
1329 {
1330 /* nr of elems per block can be read from the frd file, this is not documented in the original frd-spec. */
1331 elem_data=stoi( rec_str, 25, 36 );
1332 printf ("scip %d elements\n",elem_data);
1333 for (i=0; i<elem_data; i++)
1334 {
1335 fseeko(handle, sizeof(int), SEEK_CUR);
1336 length=fread((int *)&j,sizeof(int),1,handle);
1337 fseeko(handle, 2*sizeof(int), SEEK_CUR);
1338 if (j == 1) ipuf = 8; /* HEXA8 */
1339 else if (j == 2) ipuf = 6; /* PE6 */
1340 else if (j == 3) ipuf = 4; /* TET4 */
1341 else if (j == 4) ipuf = 20; /* HEXA20 */
1342 else if (j == 5) ipuf = 15; /* PE15 */
1343 else if (j == 6) ipuf = 10; /* TET10 */
1344 else if (j == 7) ipuf = 3; /* TRI3 */
1345 else if (j == 8) ipuf = 6; /* TRI6 */
1346 else if (j == 9) ipuf = 4; /* QUAD4 */
1347 else if (j == 10) ipuf = 8; /* QUAD8 */
1348 else if (j == 11) ipuf = 2; /* BEAM2 */
1349 else if (j == 12) ipuf = 3; /* BEAM3 */
1350 fseeko(handle, ipuf*sizeof(int), SEEK_CUR);
1351 }
1352 }
1353 else
1354 {
1355 printf (" overread Block: %s\n", rec_str);
1356 do
1357 {
1358 length = frecord( handle, rec_str);
1359 if (rec_str[length] == (char)EOF) break;
1360 /* printf ("\n record:%d %s\n", length, rec_str); */
1361 if (length != 0)
1362 {
1363 flag = stoi(rec_str,1,5);
1364 }
1365 } while(flag != -3);
1366 }
1367 }
1368
1369 for(i=0; i<anz_p; i++) free(pheader[i]); free(pheader);
1370 free( filepntr);
1371
1372 anz->u++;
1373 anz->l++;
1374 if(anz->n<0) anz->n=0;
1375 if(anz->e<0) anz->e=0;
1376
1377 if ( e_nmax > (anz->nmax) )
1378 {
1379 printf ("\nWARNING: element requestes a nodename higher than allocated\n\n");
1380 printf (" e_nmax=%d e_nmin=%d\n", e_nmax, e_nmin );
1381 }
1382 if ( e_nmin < 1 )
1383 {
1384 printf ("\nWARNING: element requestes a nodename lower than allocated\n\n");
1385 printf (" e_nmax=%d e_nmin=%d\n", e_nmax, e_nmin );
1386 }
1387
1388 anz->orign = anz->n;
1389 anz->orignmax = anz->nmax;
1390 anz->olc = anz->l;
1391
1392 *nptr = node; *eptr = elem; *lptr = lcase;
1393 return(1);
1394 }
1395
1396
1397
1398 /* if a block was skipped during first read of frd-file read it now */
1399 /* return -1 if failure */
readfrdblock(int lc,Summen * anz,Nodes * node,Datasets * lcase)1400 int readfrdblock(int lc, Summen *anz, Nodes *node, Datasets *lcase )
1401 {
1402 register int i,j, n;
1403 int length, flag, format_flag, nodenr=0, ncomps;
1404 int nod_data=0, maxcomps=0;
1405 int errFlag=0;
1406 char rec_str[MAX_LINE_LENGTH];
1407 static float *value=NULL;
1408 static double *dvalue=NULL;
1409 FILE *handle;
1410
1411 // printf("readfrdblock for file:%s\n", lcase[lc].filename);
1412
1413 /* Open the files and check to see that it was opened correctly */
1414 handle = lcase[lc].handle;
1415 if ( handle== NULL ) { printf ("ERROR in readfrdblock: The input file \"%s\" could not be opened.\n\n", lcase[lc].filename); return(-1); }
1416
1417 if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1418 lcase[lc].loaded=1;
1419
1420 length = frecord( handle, rec_str);
1421 if (rec_str[length] == (char)EOF) return(-1);
1422
1423 flag = stoi(rec_str,1,5);
1424 format_flag = stoi(rec_str,74,75);
1425
1426 if(lcase[lc].ncomps<6) maxcomps=lcase[lc].ncomps;
1427 else maxcomps=6;
1428
1429 if( lcase[lc].irtype > 2 )
1430 {
1431 printf(" ERROR: Found ELEMENT DATA, this is not suported!\n");
1432 return(-1);
1433 }
1434
1435 if ( (lcase[lc].dat = (CGXFLOAT **)malloc( (lcase[lc].ncomps) * sizeof(CGXFLOAT *))) == NULL )
1436 printf("\n\n ERROR: malloc failure\n\n" );
1437 for(i=0; i<(lcase[lc].ncomps); i++)
1438 {
1439 if ( (lcase[lc].dat[i] = (CGXFLOAT *)malloc( (anz->nmax+1) * sizeof(CGXFLOAT))) == NULL )
1440 printf("\n\n ERROR: malloc failure\n\n" );
1441 for(j=0; j<=anz->nmax; j++) lcase[lc].dat[i][j]=0.;
1442 }
1443
1444
1445 if(flag == 100)
1446 {
1447 nod_data=stoi( rec_str, 25, 36 );
1448 if (!format_flag) n=8;
1449 else n=13;
1450 do
1451 {
1452 length = frecord( handle, rec_str);
1453 if (rec_str[length] == (char)EOF) break;
1454 flag = stoi(rec_str,1,3);
1455
1456 /* bin mode, active after last column definition was read (-5 lines). Attention flag:-6 not permitted so far! */
1457 if ( format_flag>=2)
1458 {
1459 if (flag == -4)
1460 {
1461 ncomps = stoi(rec_str,14,18);
1462 }
1463 else continue;
1464
1465 //printf("format_flag=%d ncomps:%d\n",format_flag,ncomps);
1466
1467 /* skip the meta-data */
1468 for(i=0; i<ncomps; i++) length = frecord( handle, rec_str);
1469
1470 if ( format_flag==2)
1471 {
1472 if ( (value = (float *)realloc((float *)value, (lcase[lc].ncomps) * sizeof(float))) == NULL )
1473 printf("\n\n ERROR: realloc failed, value\n\n") ;
1474 for(n=0; n<nod_data; n++)
1475 {
1476 length=fread((int *)&nodenr,sizeof(int),1,handle);
1477 length=fread((float *)value,sizeof(float),lcase[lc].ncomps,handle);
1478 // printf("N:%d ",nodenr);
1479 for(i=0; i<lcase[lc].ncomps; i++)
1480 {
1481 // printf(" %f",value[i]);
1482 lcase[lc].dat[i][nodenr]= value[i];
1483 }
1484 // printf("\n");
1485 }
1486 }
1487 if ( format_flag==3)
1488 {
1489 if ( (dvalue = (double *)realloc((double *)dvalue, (lcase[lc].ncomps) * sizeof(double))) == NULL )
1490 printf("\n\n ERROR: realloc failed, dvalue\n\n") ;
1491 for(n=0; n<nod_data; n++)
1492 {
1493 length=fread((int *)&nodenr,sizeof(int),1,handle);
1494 length=fread((double *)dvalue,sizeof(double),lcase[lc].ncomps,handle);
1495 // printf("N:%d ",nodenr);
1496 for(i=0; i<lcase[lc].ncomps; i++)
1497 {
1498 // printf(" %f",dvalue[i]);
1499 lcase[lc].dat[i][nodenr]= dvalue[i];
1500 }
1501 // printf("\n");
1502 }
1503 }
1504 break;
1505 }
1506
1507 else if(flag == -1)
1508 {
1509 if (format_flag) nodenr = stoi(rec_str,4,13); else nodenr = stoi(rec_str,4,8);
1510 if (nodenr>anz->nmax)
1511 {
1512 if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1513 }
1514 else if ( lcase[lc].irtype == 1 )
1515 {
1516 if(maxcomps==6)
1517 {
1518 i=6;
1519 if ( format_flag)
1520 {
1521 lcase[lc].dat[0][nodenr]= stof(&rec_str[ 13 ], 1, 12);
1522 lcase[lc].dat[1][nodenr]= stof(&rec_str[ 25 ], 1, 12);
1523 lcase[lc].dat[2][nodenr]= stof(&rec_str[ 37 ], 1, 12);
1524 lcase[lc].dat[3][nodenr]= stof(&rec_str[ 49 ], 1, 12);
1525 lcase[lc].dat[4][nodenr]= stof(&rec_str[ 61 ], 1, 12);
1526 lcase[lc].dat[5][nodenr]= stof(&rec_str[ 73 ], 1, 12);
1527 }
1528 else
1529 {
1530 lcase[lc].dat[0][nodenr]= stof(&rec_str[ 8 ], 1, 12);
1531 lcase[lc].dat[1][nodenr]= stof(&rec_str[ 20 ], 1, 12);
1532 lcase[lc].dat[2][nodenr]= stof(&rec_str[ 32 ], 1, 12);
1533 lcase[lc].dat[3][nodenr]= stof(&rec_str[ 44 ], 1, 12);
1534 lcase[lc].dat[4][nodenr]= stof(&rec_str[ 56 ], 1, 12);
1535 lcase[lc].dat[5][nodenr]= stof(&rec_str[ 68 ], 1, 12);
1536 }
1537 }
1538 else for(i=0; i<maxcomps; i++) lcase[lc].dat[i][nodenr]= stof(&rec_str[n+i*12], 1, 12);
1539 }
1540 else i=0;
1541 }
1542 else if(flag == -2)
1543 {
1544 if (!format_flag) n=8;
1545 else n=13;
1546 j=0;
1547 do
1548 {
1549 lcase[lc].dat[i][nodenr]= stof(&rec_str[n+j*12], 1, 12);
1550 i++;j++;
1551 }while((j<6)&&(i<lcase[lc].ncomps));
1552 }
1553 }while(flag!=-3);
1554
1555 for(j=0; j<anz->orign; j++)
1556 {
1557 for(i=0; i<lcase[lc].ncomps; i++)
1558 {
1559 if(lcase[lc].dat[i][node[j].nr] > lcase[lc].max[i])
1560 {
1561 lcase[lc].max[i]=lcase[lc].dat[i][node[j].nr];
1562 lcase[lc].nmax[i]=node[j].nr;
1563 }
1564 if(lcase[lc].dat[i][node[j].nr] < lcase[lc].min[i])
1565 {
1566 lcase[lc].min[i]=lcase[lc].dat[i][node[j].nr];
1567 lcase[lc].nmin[i]=node[j].nr;
1568 }
1569 }
1570 }
1571 }
1572
1573 return(0);
1574 }
1575
1576
1577 /* regula falsi to find the matching record fast */
1578 /* not finished */
getRecord(FILE * handle,int n,int x0)1579 char *getRecord(FILE *handle, int n, int x0 )
1580 {
1581 int ii, m, n1,n2, x=0, offset=0;
1582
1583 /* search the intersection */
1584 n1=0;
1585 n2=n;
1586 for(ii=0; ii<n; ii++)
1587 {
1588 m=(n2+n1)/2;
1589
1590
1591 if( fseeko( handle, offset, SEEK_CUR )!=0) printf("error in fseeko\n");
1592
1593 if(x0>= x ) n1=m;
1594 if(x0 < x ) n2=m;
1595 if((n2-n1) == 1) break;
1596 }
1597 #if TEST
1598 printf("x:%d x0:%d\n", x,x0);
1599 #endif
1600 return(NULL);
1601 }
1602
1603
1604 /* return -1 if failure */
1605 /* return 0 if successfull */
readOneNode(int lc,Summen * anz,Datasets * lcase,int nodenr,double ** vptr,long * byte_offset)1606 int readOneNode( int lc, Summen *anz, Datasets *lcase, int nodenr, double **vptr, long *byte_offset )
1607 {
1608 register int i=0,j, n;
1609 int length, flag, inodenr=0;
1610 int maxcomps=0, ncomps;
1611 long offset=0;
1612 int errFlag=0, readFlag=0, bailout=0;
1613 char rec_str[MAX_LINE_LENGTH];
1614 FILE *handle;
1615 static float *value=NULL;
1616 static double *dvalue=NULL;
1617 double *dat;
1618 int nod_data=0, nvals=0;
1619
1620 // printf("readOneNode for file:%s *byte_offset:%d\n", lcase[lc].filename, *byte_offset);
1621
1622 /* Open the files and check to see that it was opened correctly */
1623 handle = lcase[lc].handle;
1624 if ( handle== NULL ) { printf ("ERROR in readOneNode: The input file \"%s\" could not be opened.\n\n", lcase[lc].filename); return(-1); }
1625
1626 if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1627
1628 /* the header-lines must be skipped in case byte_offset==0 and format == 2(bin) */
1629 if((lcase[lc].format_flag>=2)&&(!*byte_offset))
1630 {
1631 do
1632 {
1633 length = frecord( handle, rec_str);
1634 if (rec_str[length] == (char)EOF) return(-1);
1635 *byte_offset+=length+1;
1636 printf ("record:%s\n", rec_str);
1637 flag = stoi(rec_str,1,5);
1638 if (flag == -4)
1639 {
1640 ncomps = stoi(rec_str,14,18);
1641 }
1642 else continue;
1643
1644 /* skip the meta-data */
1645 for(i=0; i<ncomps; i++) *byte_offset+= frecord( handle, rec_str)+1;
1646 break;
1647 }while(1);
1648 }
1649 else{ if( fseeko( handle, *byte_offset, SEEK_CUR )!=0) printf("error in fseeko\n"); }
1650
1651 offset=*byte_offset;
1652
1653 if ( (dat = (double *)malloc( (lcase[lc].ncomps) * sizeof(double ))) == NULL )
1654 printf("\n\n ERROR: malloc failure\n\n" );
1655 *vptr=dat;
1656
1657 /* if bin mode */
1658 if(lcase[lc].format_flag==2)
1659 {
1660 if ( (value = (float *)realloc((float *)value, (lcase[lc].ncomps) * sizeof(float))) == NULL )
1661 printf("\n\n ERROR: realloc failed, value\n\n") ;
1662 do
1663 {
1664 length=fread((int *)&inodenr,sizeof(int),1,handle)*sizeof(int);
1665 length+=fread((float *)value,sizeof(float),lcase[lc].ncomps,handle)*sizeof(float);
1666 //printf("N:%d ",inodenr);
1667 //for(i=0; i<lcase[lc].ncomps; i++) printf(" %f",value[i]);
1668 //printf("\n");
1669 if(inodenr==nodenr) break;
1670 else offset+=length;
1671 }while(1);
1672 for(i=0; i<lcase[lc].ncomps; i++)
1673 {
1674 //printf(" %f",value[i]);
1675 dat[i]= value[i];
1676 }
1677
1678 *byte_offset=offset;
1679 //printf("offset:%d\n", offset);
1680 return(0);
1681 }
1682 if(lcase[lc].format_flag==3)
1683 {
1684 if ( (dvalue = (double *)realloc((double *)dvalue, (lcase[lc].ncomps) * sizeof(double))) == NULL )
1685 printf("\n\n ERROR: realloc failed, dvalue\n\n") ;
1686 do
1687 {
1688 length=fread((int *)&inodenr,sizeof(int),1,handle)*sizeof(int);
1689 length+=fread((double *)dvalue,sizeof(double),lcase[lc].ncomps,handle)*sizeof(double);
1690 //printf("N:%d ",inodenr);
1691 //for(i=0; i<lcase[lc].ncomps; i++) printf(" %f",dvalue[i]);
1692 //printf("\n");
1693 if(inodenr==nodenr) break;
1694 else offset+=length;
1695 }while(1);
1696 for(i=0; i<lcase[lc].ncomps; i++)
1697 {
1698 //printf(" %f",dvalue[i]);
1699 dat[i]= dvalue[i];
1700 }
1701
1702 *byte_offset=offset;
1703 //printf("offset:%d\n", offset);
1704 return(0);
1705 }
1706
1707 if(lcase[lc].ncomps<6) maxcomps=lcase[lc].ncomps;
1708 else maxcomps=6;
1709 if (!lcase[lc].format_flag) n=8;
1710 else n=13;
1711
1712 if( lcase[lc].irtype > 2 )
1713 {
1714 printf(" ERROR: Found ELEMENT DATA, this is not suported!\n");
1715 return(-1);
1716 }
1717
1718 repeat_search:;
1719 do
1720 {
1721 length = frecord( handle, rec_str);
1722 if (rec_str[length] == (char)EOF)
1723 {
1724 /* offset obviously false */
1725 offset=0;
1726 if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1727 }
1728 flag = stoi(rec_str,1,3);
1729
1730 if((readFlag)&&(flag == -2))
1731 {
1732 //printf("-2 node found:%d %d at pos:%d\n", inodenr,nodenr, nod_data);
1733 if (!lcase[lc].format_flag) n=8;
1734 else n=13;
1735 j=0;
1736 do
1737 {
1738 dat[i]= stof(&rec_str[n+j*12], 1, 12);
1739 i++;j++;
1740 }while((j<6)&&(i<lcase[lc].ncomps));
1741 }
1742 else if(readFlag)
1743 {
1744 /* leave after all records of that node are read */
1745
1746 nod_data--;
1747
1748 /* get the offset for the next call: */
1749 for (i=0; i<lcase[lc].ncomps; i++) if(lcase[lc].iexist[i]!=1) nvals++;
1750
1751 if (!lcase[lc].format_flag) n=8;
1752 else n=13;
1753 if(nvals<=6) offset+= nod_data * (n+nvals*12);
1754 else
1755 {
1756 for(i=0; i<nvals/6; i++)
1757 offset+= nod_data * (n+6*12+1);
1758 if(nvals%6)
1759 offset+= nod_data * (n+(nvals%6)*12+1);
1760 }
1761 *byte_offset=offset;
1762 //printf("offset:%d nod_data:%d n:%d nvals:%d dat:%f\n", offset,nod_data,n,nvals, dat[0]);
1763 return(0);
1764 }
1765 else if(flag == -1)
1766 {
1767 if (lcase[lc].format_flag) inodenr = stoi(rec_str,4,13); else inodenr = stoi(rec_str,4,8);
1768 nod_data++;
1769 //printf("node:%d %d at pos:%d ir:%d\n", inodenr,nodenr, nod_data, lcase[lc].irtype);
1770 if (inodenr>anz->nmax)
1771 {
1772 if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", inodenr, anz->nmax); }
1773 }
1774 else if (( inodenr==nodenr)&&(lcase[lc].irtype == 1 ))
1775 {
1776 //printf("node found:%d %d at pos:%d\n", inodenr,nodenr, nod_data);
1777 readFlag=1;
1778 if(maxcomps==6)
1779 {
1780 i=6;
1781 if ( lcase[lc].format_flag)
1782 {
1783 dat[0]= stof(&rec_str[ 13 ], 1, 12);
1784 dat[1]= stof(&rec_str[ 25 ], 1, 12);
1785 dat[2]= stof(&rec_str[ 37 ], 1, 12);
1786 dat[3]= stof(&rec_str[ 49 ], 1, 12);
1787 dat[4]= stof(&rec_str[ 61 ], 1, 12);
1788 dat[5]= stof(&rec_str[ 73 ], 1, 12);
1789 }
1790 else
1791 {
1792 dat[0]= stof(&rec_str[ 8 ], 1, 12);
1793 dat[1]= stof(&rec_str[ 20 ], 1, 12);
1794 dat[2]= stof(&rec_str[ 32 ], 1, 12);
1795 dat[3]= stof(&rec_str[ 44 ], 1, 12);
1796 dat[4]= stof(&rec_str[ 56 ], 1, 12);
1797 dat[5]= stof(&rec_str[ 68 ], 1, 12);
1798 }
1799 }
1800 else for(i=0; i<maxcomps; i++) dat[i]= stof(&rec_str[n+i*12], 1, 12);
1801 }
1802 else i=0;
1803 }
1804
1805 }while(flag!=-3);
1806
1807 if(!bailout)
1808 {
1809 bailout=1;
1810 offset=0;
1811 //printf("repeat search\n");
1812 if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1813 goto repeat_search;
1814 }
1815 return(-1);
1816 }
1817
1818