CalculiX  2.13
A Free Software Three-Dimensional Structural Finite Element Program
readfrd.h File Reference
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
Include dependency graph for readfrd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Summen
 
struct  Nodes
 
struct  Elements
 
struct  Datasets
 

Macros

#define MAX_LINE_LENGTH   256
 
#define MAX_INTEGER   2147483647
 
#define MAX_FLOAT   1.e32
 

Functions

void freeDatasets (Datasets *lcase, int nr)
 
int readfrd (char *datin, Summen *anz, Nodes **nptr, Elements **eptr, Datasets **lptr, int read_mode)
 
int readfrdblock (int lc, Summen *anz, Nodes *node, Datasets *lcase)
 
int stoi (char *string, int a, int b)
 
double stof (char *string, int a, int b)
 
void stos (char *string, int a, int b, char *puffer)
 
int compare (char *str1, char *str2, int length)
 
int frecord (FILE *handle1, char *string)
 
int elemChecker (int sum_e, Nodes *node, Elements *elem)
 
void v_result (double *A, double *B, double *C)
 
void v_prod (double *A, double *B, double *C)
 
double v_betrag (double *a)
 
int strsplt (char *rec_str, char breakchar, char ***ptr)
 

Macro Definition Documentation

◆ MAX_FLOAT

#define MAX_FLOAT   1.e32

◆ MAX_INTEGER

#define MAX_INTEGER   2147483647

◆ MAX_LINE_LENGTH

#define MAX_LINE_LENGTH   256

Function Documentation

◆ compare()

int compare ( char *  str1,
char *  str2,
int  length 
)
14 {
15  int i;
16 
17  i = 0;
18  while ((str1[i]==str2[i]) && (i<length))
19  i++;
20 
21  return i; /* Return how far we got before a difference occurred, or the variable */
22  /* length, whichever is the smaller */
23 }

◆ elemChecker()

int elemChecker ( int  sum_e,
Nodes node,
Elements elem 
)
18 {
19  int i, j;
20  double v12[3], v13[3], v15[3], v15n[3], vn[3];
21  double bv15, bvn, bv15n, bgrenz;
22  int epuf[27];
23  int e_korr=0;
24 
25  for (i=0; i<sum_e; i++)
26  {
27  if( (elem[i].type == 1)||(elem[i].type == 4) ) /* HEXA */
28  {
29  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[1]].nx, v12);
30  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[3]].nx, v13);
31  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[4]].nx, v15);
32  v_prod(v12,v13,vn);
33  v_result(v15,vn,v15n);
34  bvn=v_betrag(vn);
35  bv15=v_betrag(v15);
36  bgrenz=sqrt(bvn*bvn+bv15*bv15);
37  bv15n=v_betrag(v15n);
38 
39  /* printf ("elemcheck:%" intFORMAT " vn x=%e y=%e z=%e\n",elem[i].nr,vn[0],vn[1],vn[2]); */
40  if (bv15n > bgrenz)
41  {
42  /* printf ("elem %" intFORMAT " wrong defined, v15n=%e vgrenz=%e\n", elem[i].nr,bv15n,bgrenz); */
43  for (j=0; j<8; j++)
44  {
45  epuf[j] = elem[i].nod[j];
46  }
47  elem[i].nod[0] = epuf[4];
48  elem[i].nod[1] = epuf[5];
49  elem[i].nod[2] = epuf[6];
50  elem[i].nod[3] = epuf[7];
51  elem[i].nod[4] = epuf[0];
52  elem[i].nod[5] = epuf[1];
53  elem[i].nod[6] = epuf[2];
54  elem[i].nod[7] = epuf[3];
55  e_korr++;
56  if (elem[i].type == 4)
57  {
58  for (j=0; j<4; j++)
59  {
60  epuf[j] = elem[i].nod[j+8];
61  epuf[j+4] = elem[i].nod[j+16];
62  }
63  elem[i].nod[8] = epuf[4];
64  elem[i].nod[9] = epuf[5];
65  elem[i].nod[10] = epuf[6];
66  elem[i].nod[11] = epuf[7];
67  elem[i].nod[16] = epuf[0];
68  elem[i].nod[17] = epuf[1];
69  elem[i].nod[18] = epuf[2];
70  elem[i].nod[19] = epuf[3];
71  }
72 
73  }
74  }
75 
76  else if( (elem[i].type == 2)||(elem[i].type == 5) ) /* PENTA */
77  {
78  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[1]].nx, v12);
79  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[2]].nx, v13);
80  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[3]].nx, v15);
81  v_prod(v12,v13,vn);
82  v_result(v15,vn,v15n);
83  bvn=v_betrag(vn);
84  bv15=v_betrag(v15);
85  bgrenz=sqrt(bvn*bvn+bv15*bv15);
86  bv15n=v_betrag(v15n);
87 
88  /* printf ("elemcheck:%" intFORMAT " vn x=%e y=%e z=%e\n",elem[i].nr,vn[0],vn[1],vn[2]); */
89  if (bv15n > bgrenz)
90  {
91  /* printf ("elem %" intFORMAT " wrong defined, v15n=%e vgrenz=%e\n", elem[i].nr,bv15n,bgrenz); */
92  for (j=0; j<6; j++)
93  {
94  epuf[j] = elem[i].nod[j];
95  }
96  elem[i].nod[0] = epuf[3];
97  elem[i].nod[1] = epuf[4];
98  elem[i].nod[2] = epuf[5];
99  elem[i].nod[3] = epuf[0];
100  elem[i].nod[4] = epuf[1];
101  elem[i].nod[5] = epuf[2];
102  e_korr++;
103  if (elem[i].type == 5)
104  {
105  for (j=0; j<3; j++)
106  {
107  epuf[j] = elem[i].nod[j+6];
108  epuf[j+3] = elem[i].nod[j+12];
109  }
110  elem[i].nod[6] = epuf[3];
111  elem[i].nod[7] = epuf[4];
112  elem[i].nod[8] = epuf[5];
113  elem[i].nod[12] = epuf[0];
114  elem[i].nod[13] = epuf[1];
115  elem[i].nod[14] = epuf[2];
116  }
117 
118  }
119  }
120 
121  else if( (elem[i].type == 3)||(elem[i].type == 6) ) /* TET */
122  {
123  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[1]].nx, v12);
124  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[2]].nx, v13);
125  v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[3]].nx, v15);
126  v_prod(v12,v13,vn);
127  v_result(v15,vn,v15n);
128  bvn=v_betrag(vn);
129  bv15=v_betrag(v15);
130  bgrenz=sqrt(bvn*bvn+bv15*bv15);
131  bv15n=v_betrag(v15n);
132 
133  /* printf ("elemcheck:%" intFORMAT " vn x=%e y=%e z=%e\n",elem[i].nr,vn[0],vn[1],vn[2]); */
134  if (bv15n > bgrenz)
135  {
136  /* printf ("elem %" intFORMAT " wrong defined, v15n=%e vgrenz=%e\n", elem[i].nr,bv15n,bgrenz); */
137  for (j=0; j<4; j++) epuf[j] = elem[i].nod[j];
138  elem[i].nod[0] = epuf[1];
139  elem[i].nod[1] = epuf[2];
140  elem[i].nod[2] = epuf[3];
141  elem[i].nod[3] = epuf[0];
142  e_korr++;
143  if (elem[i].type == 6)
144  {
145  for (j=4; j<10; j++) epuf[j] = elem[i].nod[j];
146  elem[i].nod[4] = epuf[5];
147  elem[i].nod[5] = epuf[9];
148  elem[i].nod[6] = epuf[8];
149  elem[i].nod[7] = epuf[4];
150  elem[i].nod[8] = epuf[6];
151  elem[i].nod[9] = epuf[7];
152  }
153 
154  }
155  }
156 
157  }
158  return (e_korr);
159 }
void v_result(double *A, double *B, double *C)
double v_betrag(double *a)
Definition: v_betrag.c:9
void v_prod(double *A, double *B, double *C)
Definition: v_prod.c:2
int nod[27]
Definition: readfrd.h:71

◆ frecord()

int frecord ( FILE *  handle1,
char *  string 
)
18 {
19  register int i, n, c;
20 
21  for (i=0; i<MAX_LINE_LENGTH-1; i++)
22  {
23  string[i] = getc(handle1);
24  if (string[i] == '\n')
25  {
26  for (n=i+1; n<MAX_LINE_LENGTH; ++n) string[n] = '\0';
27  return(i);
28  }
29  if (string[i] == '\r')
30  {
31  c = getc(handle1);
32  if (c != '\n')
33  ungetc(c, handle1);
34 
35  for (n=i+1; n<MAX_LINE_LENGTH; ++n) string[n] = '\0';
36  return(i);
37  }
38  else if (string[i] == (char)EOF)
39  {
40  for (n=i+1; n<MAX_LINE_LENGTH; ++n) string[n] = '\0';
41  return(i);
42  }
43  }
44  string[MAX_LINE_LENGTH-1] = '\0';
45  return(MAX_LINE_LENGTH-1);
46 }
#define MAX_LINE_LENGTH
Definition: readfrd.h:10

◆ freeDatasets()

void freeDatasets ( Datasets lcase,
int  nr 
)
47 {
48  register int i;
49 
50  printf(" free lc[%d] ncomps:%d\n",nr,lcase[nr].ncomps);
51  if(lcase[nr].loaded)
52  {
53  for(i=0; i<lcase[nr].ncomps; i++) SFREE(lcase[nr].dat[i]);
54  }
55  if(lcase[nr].npheader)
56  {
57  for(i=0; i<lcase[nr].npheader; i++) SFREE(lcase[nr].pheader[i]);
58  SFREE(lcase[nr].pheader);
59  }
60  for(i=0; i<lcase[nr].ncomps; i++)
61  {
62  SFREE(lcase[nr].compName[i]);
63  SFREE(lcase[nr].icname[i]);
64  }
65  SFREE(lcase[nr].compName);
66  SFREE(lcase[nr].icname);
67  SFREE(lcase[nr].ictype);
68  SFREE(lcase[nr].icind1);
69  SFREE(lcase[nr].icind2);
70  SFREE(lcase[nr].iexist);
71  SFREE(lcase[nr].max);
72  SFREE(lcase[nr].menu);
73  SFREE(lcase[nr].min);
74  SFREE(lcase[nr].nmax);
75  SFREE(lcase[nr].nmin);
76  SFREE(lcase[nr].dat);
77  SFREE(lcase[nr].fileptr);
78 
79  /* edat not propper implemented or deleted */
80  // for(i=0; i<3; i++) for(e=0; e<anz->e; e++) SFREE(lcase[nr].edat[i][e]);
81 }
int npheader
Definition: readfrd.h:77
#define max(a, b)
Definition: cascade.c:32
#define min(a, b)
Definition: cascade.c:31
#define SFREE(a)
Definition: CalculiX.h:41
int ncomps
Definition: readfrd.h:92

◆ readfrd()

int readfrd ( char *  datin,
Summen anz,
Nodes **  nptr,
Elements **  eptr,
Datasets **  lptr,
int  read_mode 
)
88 {
89  FILE *handle;
90  register int i=0, j=0;
91  int nodeflag=0, elemflag=0, errFlag=0, firsttime=1;
92  int n; /* used in format_flag */
93  long offset=0;
94  fpos_t *filepntr=NULL;
95  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) */
96 
97  int ncomps, maxcomps=0, nvals, nentities;
98  char rec_str[MAX_LINE_LENGTH];
99  int node_field_size, elem_field_size;
100  int e_nmax=1, e_nmin=1;
101  int length, flag, format_flag;
102  int ipuf, nodenr=0;
103  static float *value=NULL;
104 
105  char **dat, **compName;
106  int *menu, *ictype, *icind1, *icind2, *iexist;
107 
108  int anz_p=-1;
109  char **pheader=NULL;
110 
111  Nodes *node=NULL;
112  Elements *elem=NULL;
113  Datasets *lcase=NULL;
114 
115 
116  if ( (lcase = (Datasets *)malloc( 1 * sizeof(Datasets))) == NULL )
117  printf("\n\n ERROR: malloc failed\n\n") ;
118 
119  anz->u=anz->n=anz->e=anz->l=-1;
120  length = 1;
121  format_flag=0;
122 
123  /* Open the files and check to see that it was opened correctly */
124  handle = fopen (datin, "r");
125  if ( handle== NULL ) { printf ("ERROR: The input file \"%s\" could not be opened.\n\n", datin); return(-1); }
126  else printf (" file:%s opened\n", datin);
127 
128 
129  printf (" reading frd format\n");
130  length = frecord( handle, rec_str);
131  rec_str[length]='\0';
132  flag = stoi(rec_str,4,5);
133  if (flag == 1 )
134  {
135  stos(rec_str,7,12,anz->model);
136  printf (" MODEL NAME: %s", anz->model);
137  }
138  else
139  {
140  printf ("\n\nFATAL ERROR: no proper file-format found.\n\n");
141  return (-1);
142  }
143 
144  while(length)
145  {
146 
147  /* store the beginning of the data-block for later reading */
148  if(filepntr==NULL)
149  { if( (filepntr=(fpos_t *)malloc(1*sizeof(fpos_t))) == NULL ) printf(" ERROR: malloc failed\n"); }
150 
151  if(fgetpos( handle, (fpos_t *)filepntr)!=0) { printf("error in fgetpos"); return(-1); }
152 
153  read_again:;
154  length = frecord( handle, rec_str);
155  if (rec_str[length] == (char)EOF) break;
156  else rec_str[length] =(char)0;
157  printf ("record:%s\n", rec_str);
158 
159 
160  flag = stoi(rec_str,1,5);
161  format_flag = stoi(rec_str,74,75);
162  //printf ("OPCODE:%d IFORMT:%d\n", flag, format_flag );
163 
164  if(flag == 9999) goto read_again;
165  if(( (nodeflag==1)&&(flag == 2) ) || ( (elemflag==1)&&(flag == 3) ))
166  {
167  printf ("found a second mesh. This mesh will be ignored\n");
168  flag=-1;
169  }
170  if(flag == 1)
171  {
172  /* User Header used to store general information */
173  if(rec_str[5]=='U')
174  {
175  anz->u++;
176  if(!anz->u)
177  { if(( anz->uheader=(char **)malloc( sizeof(char *))) == NULL )
178  printf("\n\n ERROR: malloc failed\n\n") ; }
179  else if(( anz->uheader=(char **)realloc((char **)anz->uheader, (anz->u+1)*sizeof(char *))) == NULL )
180  printf("\n\n ERROR: realloc failed\n\n") ;
181  if(( anz->uheader[anz->u]=(char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
182  printf("\n\n ERROR: malloc failed\n\n") ;
183  strcpy(anz->uheader[anz->u],rec_str);
184  }
185 
186  /* Project Header used to store additional Dataset information */
187  if(rec_str[5]=='P')
188  {
189  anz_p++;
190  if(!anz_p)
191  { if(( pheader=(char **)malloc( sizeof(char *))) == NULL )
192  printf("\n\n ERROR: malloc failed\n\n") ; }
193  else if(( pheader=(char **)realloc((char **)pheader, (anz_p+1)*sizeof(char *))) == NULL )
194  printf("\n\n ERROR: realloc failed\n\n") ;
195  if(( pheader[anz_p]=(char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
196  printf("\n\n ERROR: malloc failed\n\n") ;
197  strcpy(pheader[anz_p],rec_str);
198  }
199  }
200 
201  else if(flag == 2)
202  {
203  /* store the pheaders which are leading this block */
204  anz->p=anz_p+1;
205  anz->pheader=pheader;
206  anz_p=-1;
207  pheader=NULL;
208 
209  printf ("reading Nodes\n");
210  // anz->nmax=-MAX_INTEGER; anz->nmin= MAX_INTEGER;
211  nodeflag=1;
212 
213  /* nr of nodes per block can be read from the frd file, this is not documented in the original frd-spec. */
214  nod_data=stoi( rec_str, 25, 36 );
215  if(nod_data>0) node_field_size=nod_data;
216  else node_field_size=INI_FIELD_SIZE;
217  do
218  {
219  if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
220  {
221  printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
222  node_field_size/=2;
223  }
224  if(node_field_size<0)
225  {
226  printf("\n\n ERROR: not enough memory in readfrd()\n\n");
227  exit(-1);
228  }
229  }while(!node);
230  for(i=0; i<node_field_size; i++) node[i].indx=-1;
231 
232  if (format_flag < 2)
233  {
234  do
235  {
236  length = frecord( handle, rec_str);
237  if (rec_str[length] == (char)EOF) break;
238  flag = stoi(rec_str,1,3);
239  anz->n++;
240  if (flag == -3) break;
241  if (!format_flag) node[anz->n].nr = stoi(rec_str,4,8);
242  else node[anz->n].nr = stoi(rec_str,4,13);
243  if (node[anz->n].nr>=node_field_size)
244  {
245  if(node[anz->n].nr<MAX_INTEGER/2) node_field_size=node[anz->n].nr*2+1; else node_field_size=MAX_INTEGER-2;
246  nodenr=node[anz->n].nr;
247  do
248  {
249  if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
250  {
251  printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
252  node_field_size=nodenr+(node_field_size-nodenr)/2;
253  }
254  if(node_field_size<=nodenr)
255  {
256  printf("\n\n ERROR: not enough memory in readfrd() for node-nr:%d available\n\n", nodenr);
257  exit(-1);
258  }
259  }while(!node);
260  for(i=anz->nmax+1; i<node_field_size; i++) node[i].indx=-1;
261  }
262  /* save only nodes which are not already stored */
263  if(node[node[anz->n].nr].indx<0)
264  {
265  node[node[anz->n].nr].indx=anz->n;
266  if (!format_flag)
267  {
268  node[node[anz->n].nr].nx = stof(&rec_str[8],1,12);
269  node[node[anz->n].nr].ny = stof(&rec_str[20],1,12);
270  node[node[anz->n].nr].nz = stof(&rec_str[32],1,12);
271  }
272  else
273  {
274  node[node[anz->n].nr].nx = stof(&rec_str[13],1,12);
275  node[node[anz->n].nr].ny = stof(&rec_str[25],1,12);
276  node[node[anz->n].nr].nz = stof(&rec_str[37],1,12);
277  }
278  if (node[anz->n].nr > anz->nmax) anz->nmax=node[anz->n].nr;
279  if (node[anz->n].nr < anz->nmin) anz->nmin=node[anz->n].nr;
280 #if TEST
281  printf (" n=%d x=%lf y=%lf z=%lf \n", node[anz->n].nr,
282  node[node[anz->n].nr].nx, node[node[anz->n].nr].ny,
283  node[node[anz->n].nr].nz);
284 #endif
285  }
286  } while(flag != -3);
287  }
288 
289  /* binary format */
290  else
291  {
292  if ( (value = (float *)realloc((float *)value, (3) * sizeof(float))) == NULL )
293  printf("\n\n ERROR: realloc failed, value\n\n") ;
294  for(i=0; i<nod_data; i++)
295  {
296  anz->n++;
297  length=fread((int *)&node[anz->n].nr,sizeof(int),1,handle);
298  //printf("n:%d\n", node[anz->n].nr);
299  if (node[anz->n].nr>=node_field_size)
300  {
301  if(node[anz->n].nr<MAX_INTEGER/2) node_field_size=node[anz->n].nr*2+1; else node_field_size=MAX_INTEGER-2;
302  nodenr= node[anz->n].nr;
303  do
304  {
305  if ( (node = (Nodes *)realloc( (Nodes *)node, (node_field_size+1) * sizeof(Nodes))) == NULL )
306  {
307  printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
308  node_field_size=nodenr+(node_field_size-nodenr)/2;
309  }
310  if(node_field_size<=nodenr)
311  {
312  printf("\n\n ERROR: not enough memory in readfrd() for the node-nr:%d available\n\n", nodenr);
313  exit(-1);
314  }
315  }while(!node);
316  for(n=node[anz->n].nr; n<node_field_size; n++) node[n].indx=-1;
317  }
318  /* save only nodes which are not already stored */
319  if (format_flag == 2)
320  {
321  length=fread((float *)value,sizeof(float),3,handle);
322  //printf("n:%f %f %f\n", value[0],value[1],value[2]);
323  if(node[node[anz->n].nr].indx<0)
324  {
325  node[node[anz->n].nr].indx=anz->n;
326  node[node[anz->n].nr].nx = value[0];
327  node[node[anz->n].nr].ny = value[1];
328  node[node[anz->n].nr].nz = value[2];
329  }
330  }
331  else
332  {
333  if(node[node[anz->n].nr].indx<0)
334  {
335  length=fread((double *)&node[node[anz->n].nr].nx,sizeof(double),3,handle);
336  node[node[anz->n].nr].indx=anz->n;
337  }
338  else fseek(handle, 3*sizeof(double), SEEK_CUR);
339  }
340  if (node[anz->n].nr > anz->nmax) anz->nmax=node[anz->n].nr;
341  if (node[anz->n].nr < anz->nmin) anz->nmin=node[anz->n].nr;
342 #if TEST
343  printf (" n=%d x=%lf y=%lf z=%lf \n", node[anz->n].nr,
344  node[node[anz->n].nr].nx, node[node[anz->n].nr].ny,
345  node[node[anz->n].nr].nz);
346 #endif
347  }
348  anz->n++;
349  }
350  node_field_size=anz->nmax+1;
351  if((node = (Nodes *)realloc( (Nodes *)node, node_field_size * sizeof(Nodes))) == NULL )
352  printf("\n\n ERROR: realloc failed\n\n") ;
353  else
354  printf ("\n %d nodes reallocated \n",anz->nmax);
355  }
356 
357  else if(flag == 3)
358  {
359  printf ("reading Elements\n");
360  // anz->emax=-MAX_INTEGER; anz->emin=MAX_INTEGER;
361  elemflag=1;
362  e_nmax=-MAX_INTEGER; e_nmin=MAX_INTEGER;
363 
364  /* nr of nodes per block can be read from the frd file, this is not documented in the original frd-spec. */
365  elem_data=stoi( rec_str, 25, 36 );
366  if(elem_data>0) elem_field_size=elem_data;
367  else elem_field_size=INI_FIELD_SIZE;
368  do
369  {
370  if((elem = (Elements *)realloc( (Elements *)elem, (elem_field_size+1) * sizeof(Elements))) == NULL )
371  {
372  printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size );
373  elem_field_size/=2;
374  }
375  if(elem_field_size<0)
376  {
377  printf("\n\n ERROR: not enough memory in readfrd()\n\n");
378  exit(-1);
379  }
380  }while(!elem);
381 
382  /* binary format */
383  if (format_flag == 2)
384  {
385  if ( (elem = (Elements *)realloc((Elements *)elem, elem_data * sizeof(Elements))) == NULL )
386  printf("\n\n ERROR: in readfrd realloc failed\n\n") ;
387  else
388  printf ("\n %d elements allocated \n", elem_data);
389  for (i=0; i<elem_data; i++)
390  {
391  anz->e++;
392  length=fread((int *)&elem[anz->e].nr,sizeof(int),1,handle);
393  length=fread((int *)&elem[anz->e].type,sizeof(int),1,handle);
394  length=fread((int *)&elem[anz->e].group,sizeof(int),1,handle);
395  length=fread((int *)&elem[anz->e].mat,sizeof(int),1,handle);
396  elem[anz->e].attr = 0;
397  anz->etype[elem[anz->e].type]++;
398  if (elem[anz->e].nr > anz->emax) anz->emax=elem[anz->e].nr;
399  if (elem[anz->e].nr < anz->emin) anz->emin=elem[anz->e].nr;
400  if (elem[anz->e].type == 1) ipuf = 8; /* HEXA8 */
401  else if (elem[anz->e].type == 2) ipuf = 6; /* PE6 */
402  else if (elem[anz->e].type == 3) ipuf = 4; /* TET4 */
403  else if (elem[anz->e].type == 4) ipuf = 20; /* HEXA20 */
404  else if (elem[anz->e].type == 5) ipuf = 15; /* PE15 */
405  else if (elem[anz->e].type == 6) ipuf = 10; /* TET10 */
406  else if (elem[anz->e].type == 7) ipuf = 3; /* TRI3 */
407  else if (elem[anz->e].type == 8) ipuf = 6; /* TRI6 */
408  else if (elem[anz->e].type == 9) ipuf = 4; /* QUAD4 */
409  else if (elem[anz->e].type == 10) ipuf = 8; /* QUAD8 */
410  else if (elem[anz->e].type == 11) ipuf = 2; /* BEAM2 */
411  else if (elem[anz->e].type == 12) ipuf = 3; /* BEAM3 */
412  //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);
413  length=fread((int *)elem[anz->e].nod,sizeof(int),ipuf,handle);
414  //for(j=0;j<ipuf; j++) printf(" %d",elem[anz->e].nod[j]); printf("\n");
415  }
416  anz->e++;
417  }
418  else
419  {
420  do
421  {
422  length = frecord( handle, rec_str);
423  if (rec_str[length] == (char)EOF) break;
424  flag = stoi(rec_str,1,3);
425  anz->e++;
426 
427  if (flag == -3) break;
428  else if ((flag == -1)||(flag == -2))
429  {
430  if (anz->e>=elem_field_size)
431  {
432  if(anz->e<MAX_INTEGER/2) elem_field_size=anz->e*2+1; else elem_field_size=MAX_INTEGER-2;
433  do
434  {
435  if((elem = (Elements *)realloc( (Elements *)elem, (elem_field_size+1) * sizeof(Elements))) == NULL )
436  {
437  printf("WARNING: in readfrd() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size );
438  elem_field_size=anz->e+(elem_field_size-anz->e)/2;
439  }
440  if(elem_field_size<=anz->e)
441  {
442  printf("\n\n ERROR: not enough memory in readfrd()\n\n");
443  exit(-1);
444  }
445  }while(!elem);
446  }
447  if (!format_flag)
448  {
449  elem[anz->e].nr = stoi(&rec_str[3], 1, 5);
450  elem[anz->e].type = stoi(&rec_str[8], 1, 5);
451  elem[anz->e].group = stoi(&rec_str[13], 1, 5);
452  elem[anz->e].mat = stoi(&rec_str[18], 1, 5);
453  }
454  else
455  {
456  elem[anz->e].nr = stoi(&rec_str[3], 1, 10);
457  elem[anz->e].type = stoi(&rec_str[13], 1, 5);
458  elem[anz->e].group = stoi(&rec_str[18], 1, 5);
459  elem[anz->e].mat = stoi(&rec_str[23], 1, 5);
460  }
461  elem[anz->e].attr = 0;
462  ipuf=0;
463  if (elem[anz->e].nr > anz->emax) anz->emax=elem[anz->e].nr;
464  if (elem[anz->e].nr < anz->emin) anz->emin=elem[anz->e].nr;
465  if (elem[anz->e].type == 1) ipuf = 8; /* HEXA8 */
466  else if (elem[anz->e].type == 2) ipuf = 6; /* PE6 */
467  else if (elem[anz->e].type == 3) ipuf = 4; /* TET4 */
468  else if (elem[anz->e].type == 4) ipuf = 20; /* HEXA20 */
469  else if (elem[anz->e].type == 5) ipuf = 15; /* PE15 */
470  else if (elem[anz->e].type == 6) ipuf = 10; /* TET10 */
471  else if (elem[anz->e].type == 7) ipuf = 3; /* TRI3 */
472  else if (elem[anz->e].type == 8) ipuf = 6; /* TRI6 */
473  else if (elem[anz->e].type == 9) ipuf = 4; /* QUAD4 */
474  else if (elem[anz->e].type == 10) ipuf = 8; /* QUAD8 */
475  else if (elem[anz->e].type == 11) ipuf = 2; /* BEAM2 */
476  else if (elem[anz->e].type == 12) ipuf = 3; /* BEAM3 */
477 #if TEST
478  printf ("\n%d e=%d typ=%d grp=%d mat=%d \n", flag, elem[anz->e].nr,
479  elem[anz->e].type, elem[anz->e].group, elem[anz->e].mat );
480 #endif
481  length = frecord( handle, rec_str );
482  if (ipuf==0)
483  {
484  printf (" element:%d is from unknown type:%d\n", elem[anz->e].nr, elem[anz->e].type);
485  }
486  else
487  {
488  anz->etype[elem[anz->e].type]++;
489  /* read the node-lines */
490  if (!format_flag)
491  {
492  j=0;
493  for (i=0; i<ipuf; i++)
494  {
495  elem[anz->e].nod[i] = stoi(&rec_str[3+j*5], 1, 5);
496  if (j<14) j++;
497  else
498  {
499  if (i<ipuf-1) length = frecord( handle, rec_str ); j=0;
500  }
501  }
502  }
503  else
504  {
505  j=0;
506  for (i=0; i<ipuf; i++)
507  {
508  elem[anz->e].nod[i] = stoi(&rec_str[3+j*10], 1, 10);
509  if (j<9) j++;
510  else
511  {
512  if (i<ipuf-1) length = frecord( handle, rec_str ); j=0;
513  }
514  }
515  }
516  }
517  }
518  else
519  {
520  printf ("ERROR: flag:%d is not expected, must be -1 or -2!\n%s", flag, rec_str );
521  exit(-1);
522  }
523  } while(flag != -3);
524  elem_field_size=anz->e+1;
525  if ( (elem = (Elements *)realloc((Elements *)elem, elem_field_size * sizeof(Elements))) == NULL )
526  printf("\n\n ERROR: in readfrd realloc failed\n\n") ;
527  else
528  printf ("\n %d elements reallocated \n", anz->e);
529  }
530  }
531 
532  else if(flag == 100)
533  {
534  anz->l++;
535 
536  printf ("reading Dataset No:%d\n",anz->l+1);
537  if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
538  { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
539 
540  lcase[anz->l].handle=(FILE *)NULL;
541 
542  /* store the pheaders which are leading this block */
543  lcase[anz->l].npheader=anz_p+1;
544  lcase[anz->l].pheader=pheader;
545  lcase[anz->l].fileptr=NULL;
546  lcase[anz->l].loaded=1;
547  lcase[anz->l].format_flag=format_flag;
548  anz_p=-1;
549  pheader=NULL;
550  offset=0;
551 
552  stos( rec_str, 7, 12, lcase[anz->l].dataset_name);
553  lcase[anz->l].value=stof( rec_str, 13, 24 );
554 
555  /* nr of nodes per block can be read from the frd file, this is not documented in the original frd-spec. */
556  nod_data=stoi( rec_str, 25, 36 );
557  /* because of a bug in ccx2.0 this nr can be wrong. In this case it is higher than the actual nr of nodes. */
558  if(nod_data>anz->n)
559  {
560  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);
561  //exit(0);
562  nod_data=anz->n;
563  }
564 #ifdef DEVEL
565  if(!nod_data)
566  {
567  nod_data=nod_1st_block;
568  printf("nods in block assumed:%d\n",nod_data );
569  }
570 #endif
571  stos( rec_str, 37, 56, lcase[anz->l].dataset_text);
572  lcase[anz->l].analysis_type=stoi( rec_str, 57, 58 );
573  lcase[anz->l].step_number=stoi( rec_str, 59, 63 );
574  if(strlen(rec_str)>72 )
575  {
576  stos(rec_str,64,73,lcase[anz->l].analysis_name);
577  }
578  else
579  {
580  strcpy(lcase[anz->l].analysis_name,"");
581  }
582  ncomps=nentities=0;
583  if (!format_flag) n=8;
584  else n=13;
585  errFlag=0;
586  firsttime=1;
587 
588  ipuf=-1;
589  //if(lcase[anz->l].analysis_type==2) //in the moment ccx writes the wrong number, therefore:
590  if(lcase[anz->l].analysis_type>=2)
591  {
592  for(i=0;i<lcase[anz->l].npheader; i++)
593  {
594  if(compare(&lcase[anz->l].pheader[i][5],"PHID", 4)==4)
595  {
596  sscanf(lcase[anz->l].pheader[i],"%*s %d", &ipuf);
597  if(ipuf>-1) sprintf(lcase[anz->l].dataset_text,"ND:%d",ipuf);
598  }
599  }
600  if(ipuf!=-1) for(i=0;i<lcase[anz->l].npheader; i++)
601  {
602  if(compare(&lcase[anz->l].pheader[i][5],"PMODE", 5)==5)
603  {
604  sscanf(lcase[anz->l].pheader[i],"%*s %d", &ipuf);
605  if(ipuf>-1) sprintf(&lcase[anz->l].dataset_text[strlen(lcase[anz->l].dataset_text)]," MODE:%d",ipuf);
606  }
607  }
608  }
609 
610  do
611  {
612  /* bin mode, active after last column definition was read (-5 lines). Attention flag:-6 not permitted so far! */
613  if (( format_flag==2)&&(lcase[anz->l].ncomps>0)&&(ncomps==lcase[anz->l].ncomps))
614  {
615  //printf("format_flag=%d ncomps:%d lcncomps:%d\n",format_flag,ncomps,lcase[anz->l].ncomps);
616 
617  /* if offset is known jump the filepointer before the next block or else continue reading assuming values for all nodes are provided */
618  if(offset)
619  {
620  lcase[anz->l].loaded=0;
621  if (firsttime)
622  {
623  firsttime=0;
624 
625  /* store the beginning of the data-block for later reading */
626  lcase[anz->l].fileptr=filepntr;
627  filepntr=NULL;
628  lcase[anz->l].handle=handle;
629  strcpy(lcase[anz->l].filename,datin);
630 
631  if( fseek( handle, offset, SEEK_CUR )!=0) printf("error in fseek\n");
632  }
633  }
634  else
635  {
636  if ( (value = (float *)realloc((float *)value, (lcase[anz->l].ncomps) * sizeof(float))) == NULL )
637  printf("\n\n ERROR: realloc failed, value\n\n") ;
638  for(n=0; n<nod_data; n++)
639  {
640  length=fread((int *)&nodenr,sizeof(int),1,handle);
641  length=fread((float *)value,sizeof(float),lcase[anz->l].ncomps,handle);
642  // printf("n:%d N:%d ",n+1, nodenr);
643  for(i=0; i<lcase[anz->l].ncomps; i++)
644  {
645  // printf(" %f",value[i]);
646  lcase[anz->l].dat[i][nodenr]= value[i];
647  }
648  // printf("\n");
649  }
650  }
651  break;
652  }
653 
654  length = frecord( handle, rec_str);
655  if (rec_str[length] == (char)EOF) break;
656  flag = stoi(rec_str,1,3);
657  //printf("flag:%d\n", flag);
658  //printf("rec in block:%s\n", rec_str);
659 
660  if(flag == -1)
661  {
662  /* if offset is known jump the filepointer before the next block and continue reading until flag=-3 */
663  if(offset)
664  {
665  lcase[anz->l].loaded=0;
666  if (firsttime)
667  {
668  firsttime=0;
669 
670  /* store the beginning of the data-block for later reading */
671  lcase[anz->l].fileptr=filepntr;
672  filepntr=NULL;
673  lcase[anz->l].handle=handle;
674  strcpy(lcase[anz->l].filename,datin);
675 
676  /* reduce the offset by the current record */
677  if( fseek( handle, offset-length, SEEK_CUR )!=0) printf("error in fseek\n");
678  }
679  }
680  else
681  {
682  nod_1st_block++;
683  if (format_flag) nodenr = stoi(rec_str,4,13); else nodenr = stoi(rec_str,4,8);
684  if (nodenr>anz->nmax)
685  {
686  if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
687  }
688  else if ( lcase[anz->l].irtype == 1 )
689  {
690  if(maxcomps==6)
691  {
692  i=6;
693  if ( format_flag)
694  {
695  lcase[anz->l].dat[0][nodenr]= stof(&rec_str[ 13 ], 1, 12);
696  lcase[anz->l].dat[1][nodenr]= stof(&rec_str[ 25 ], 1, 12);
697  lcase[anz->l].dat[2][nodenr]= stof(&rec_str[ 37 ], 1, 12);
698  lcase[anz->l].dat[3][nodenr]= stof(&rec_str[ 49 ], 1, 12);
699  lcase[anz->l].dat[4][nodenr]= stof(&rec_str[ 61 ], 1, 12);
700  lcase[anz->l].dat[5][nodenr]= stof(&rec_str[ 73 ], 1, 12);
701  }
702  else
703  {
704  lcase[anz->l].dat[0][nodenr]= stof(&rec_str[ 8 ], 1, 12);
705  lcase[anz->l].dat[1][nodenr]= stof(&rec_str[ 20 ], 1, 12);
706  lcase[anz->l].dat[2][nodenr]= stof(&rec_str[ 32 ], 1, 12);
707  lcase[anz->l].dat[3][nodenr]= stof(&rec_str[ 44 ], 1, 12);
708  lcase[anz->l].dat[4][nodenr]= stof(&rec_str[ 56 ], 1, 12);
709  lcase[anz->l].dat[5][nodenr]= stof(&rec_str[ 68 ], 1, 12);
710  }
711  }
712  else
713  {
714  for(i=0; i<maxcomps; i++) lcase[anz->l].dat[i][nodenr]= stof(&rec_str[n+i*12], 1, 12);
715  }
716  /* printf("%d", nodenr); for (i=0; i<maxcomps; i++) printf(" %f",lcase[anz->l].dat[i][nodenr] ); printf("\n"); */
717  }
718  else i=0;
719  }
720  }
721  else if(flag == -2)
722  {
723  if (!format_flag) n=8;
724  else n=13;
725  j=0;
726 
727  /* in case the data should be read directly and not on demand */
728  if(!offset)
729  {
730  do
731  {
732  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[n+j*12], 1, 12);
733  i++;j++;
734  }while((j<6)&&(i<lcase[anz->l].ncomps));
735  }
736  }
737  else if (flag == -4)
738  {
739  stos( rec_str, 6, 13, lcase[anz->l].name);
740  lcase[anz->l].ncomps = stoi(rec_str,14,18);
741  lcase[anz->l].irtype = stoi(rec_str,19,23);
742 
743  if( lcase[anz->l].irtype > 2 )
744  {
745  printf(" Found ELEMENT DATA, this is not suported!\n");
746  anz->l--;
747  goto next;
748  }
749 
750  if ( (lcase[anz->l].nmax = (int *)malloc( (lcase[anz->l].ncomps) * sizeof(int))) == NULL )
751  printf("\n\n ERROR: malloc failure\n\n" );
752  if ( (lcase[anz->l].nmin = (int *)malloc( (lcase[anz->l].ncomps) * sizeof(int))) == NULL )
753  printf("\n\n ERROR: malloc failure\n\n" );
754  if ( (lcase[anz->l].max = (float *)malloc( (lcase[anz->l].ncomps) * sizeof(float))) == NULL )
755  printf("\n\n ERROR: malloc failure\n\n" );
756  if ( (lcase[anz->l].min = (float *)malloc( (lcase[anz->l].ncomps) * sizeof(float))) == NULL )
757  printf("\n\n ERROR: malloc failure\n\n" );
758  if ( (lcase[anz->l].compName = (char **)malloc( (lcase[anz->l].ncomps) * sizeof(char *))) == NULL )
759  printf("\n\n ERROR: malloc failure\n\n" );
760  if ( (lcase[anz->l].icname = (char **)malloc( (lcase[anz->l].ncomps) * sizeof(char *))) == NULL )
761  printf("\n\n ERROR: malloc failure\n\n" );
762  if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
763  printf("\n\n ERROR: malloc failure\n\n" );
764  if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
765  printf("\n\n ERROR: malloc failure\n\n" );
766  if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
767  printf("\n\n ERROR: malloc failure\n\n" );
768  if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
769  printf("\n\n ERROR: malloc failure\n\n" );
770  if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
771  printf("\n\n ERROR: malloc failure\n\n" );
772  if ( (lcase[anz->l].dat = (float **)malloc( (lcase[anz->l].ncomps) * sizeof(float *))) == NULL )
773  printf("\n\n ERROR: malloc failure\n\n" );
774  printf(" gen lc[%d] ncomps:%d\n",anz->l,lcase[anz->l].ncomps);
775  for(i=0; i<(lcase[anz->l].ncomps); i++)
776  {
777  if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
778  printf("\n\n ERROR: malloc failed\n\n" );
779  if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
780  printf("\n\n ERROR: malloc failed\n\n" );
781  lcase[anz->l].max[i]=-MAX_FLOAT;
782  lcase[anz->l].min[i]=MAX_FLOAT;
783  }
784  }
785  else if(flag == -5)
786  {
787  if(ncomps<lcase[anz->l].ncomps)
788  {
789  stos(rec_str, 6, 13, lcase[anz->l].compName[ncomps]);
790  lcase[anz->l].menu[ncomps] = stoi(rec_str,14,18);
791  lcase[anz->l].ictype[ncomps] = stoi(rec_str,19,23);
792  lcase[anz->l].icind1[ncomps] = stoi(rec_str,24,28);
793  lcase[anz->l].icind2[ncomps] = stoi(rec_str,29,33);
794  lcase[anz->l].iexist[ncomps] = stoi(rec_str,34,38);
795 
796  /* requests for additional components are not supported so far */
797  if(!lcase[anz->l].iexist[ncomps]) ncomps++;
798  else
799  {
800  SFREE(lcase[anz->l].compName[ncomps]); lcase[anz->l].compName[ncomps]=NULL;
801  SFREE(lcase[anz->l].icname[ncomps]); lcase[anz->l].icname[ncomps]=NULL;
802  }
803  }
804  else
805  {
806  rec_str[14]='\0';
807  printf(" WARNING: unallocated component:%d \"%s\" %d\n", ncomps, &rec_str[5],lcase[anz->l].ncomps);
808  exit(0);
809  }
810  nentities++;
811 
812  /* this is the last -5 line, try to figure out an offset (length of data-block) for the file-pointer */
813  /* and allocate data if no offset is defined (first time) */
814  if(nentities==lcase[anz->l].ncomps)
815  {
816  lcase[anz->l].ncomps=ncomps;
817  if(lcase[anz->l].ncomps<6) maxcomps=lcase[anz->l].ncomps;
818  else maxcomps=6;
819 
820  nvals=0;
821  for (i=0; i<ncomps; i++) if(lcase[anz->l].iexist[i]!=1) nvals++;
822  printf("ncomps:%d nvals:%d\n", ncomps, nvals);
823 
824  if(!read_mode)
825  {
826  if(nod_data)
827  {
828  if (format_flag==2)
829  {
830  offset= nod_data * (4+nvals*4);
831  }
832  else
833  {
834  /* just to get an approximate offset: */
835  if (!format_flag) n=8;
836  else n=13;
837  if(nvals<=6) offset= nod_data * (n+nvals*12+1);
838  else
839  {
840  offset=0;
841  for(i=0; i<nvals/6; i++)
842  offset+= nod_data * (n+6*12+1);
843  if(nvals%6)
844  offset+= nod_data * (n+(nvals%6)*12+1);
845  }
846  //printf("offset:%d nod_data:%d n:%d nvals:%d\n", offset,nod_data,n,nvals);
847  }
848  }
849  }
850 
851  if(!offset)
852  {
853  /* in case the data should be read directly and not on demand */
854  for(i=0; i<(lcase[anz->l].ncomps); i++)
855  {
856  if ( (lcase[anz->l].dat[i] = (float *)malloc( (anz->nmax+1) * sizeof(float))) == NULL )
857  printf("\n\n ERROR: malloc failure\n\n" );
858  for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
859  }
860  }
861  }
862 
863  }
864  else if(flag == -6)
865  {
866  length= strsplt( rec_str, ' ', &dat);
867  ipuf=atoi(dat[2]);
868  if ( (compName = (char **)malloc( ipuf * sizeof(char *))) == NULL )
869  printf("\n\n ERROR: malloc failure\n\n" );
870  for(i=0; i<ipuf; i++)
871  {
872  if ( (compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
873  printf("\n\n ERROR: malloc failed\n\n" );
874  }
875  for (i=0; i<ipuf; i++) strcpy(compName[i], lcase[anz->l].compName[ atoi(dat[i+3])-1 ]);
876  for (i=0; i<ipuf; i++) strcpy(lcase[anz->l].compName[i],compName[i]);
877  if ( (menu = (int *)malloc( ipuf * sizeof(int))) == NULL )
878  printf("\n\n ERROR: malloc failure\n\n" );
879  if ( (ictype = (int *)malloc( ipuf * sizeof(int))) == NULL )
880  printf("\n\n ERROR: malloc failure\n\n" );
881  if ( (icind1 = (int *)malloc( ipuf * sizeof(int))) == NULL )
882  printf("\n\n ERROR: malloc failure\n\n" );
883  if ( (icind2 = (int *)malloc( ipuf * sizeof(int))) == NULL )
884  printf("\n\n ERROR: malloc failure\n\n" );
885  if ( (iexist = (int *)malloc( ipuf * sizeof(int))) == NULL )
886  printf("\n\n ERROR: malloc failure\n\n" );
887  for (i=0; i<ipuf; i++) menu[i] = lcase[anz->l].menu[atoi(dat[i+3])-1];
888  for (i=0; i<ipuf; i++) lcase[anz->l].menu[i] =menu[i];
889  for (i=0; i<ipuf; i++) ictype[i] = lcase[anz->l].ictype[atoi(dat[i+3])-1];
890  for (i=0; i<ipuf; i++) lcase[anz->l].ictype[i] =ictype[i];
891  for (i=0; i<ipuf; i++) icind1[i] = lcase[anz->l].icind1[atoi(dat[i+3])-1];
892  for (i=0; i<ipuf; i++) lcase[anz->l].icind1[i] =icind1[i];
893  for (i=0; i<ipuf; i++) icind2[i] = lcase[anz->l].icind2[atoi(dat[i+3])-1];
894  for (i=0; i<ipuf; i++) lcase[anz->l].icind2[i] =icind2[i];
895  for (i=0; i<ipuf; i++) iexist[i] = lcase[anz->l].iexist[atoi(dat[i+3])-1];
896  for (i=0; i<ipuf; i++) lcase[anz->l].iexist[i] =iexist[i];
897 
898  for(i=0; i<length; i++) SFREE(dat[i]);
899  SFREE(dat);
900 
901  for(i=0; i<ipuf; i++) SFREE(compName[i]);
902  SFREE(compName);
903  SFREE(menu);
904  SFREE(ictype);
905  SFREE(icind1);
906  SFREE(icind2);
907  SFREE(iexist);
908  }
909  }while(flag!=-3);
910 
911  /* in case the data should be read directly and not on demand */
912  if(!offset)
913  {
914  for(j=0; j<anz->n; j++)
915  {
916  for(i=0; i<lcase[anz->l].ncomps; i++)
917  {
918  if(lcase[anz->l].dat[i][node[j].nr] > lcase[anz->l].max[i])
919  {
920  lcase[anz->l].max[i]=lcase[anz->l].dat[i][node[j].nr];
921  lcase[anz->l].nmax[i]=node[j].nr;
922  }
923  if(lcase[anz->l].dat[i][node[j].nr] < lcase[anz->l].min[i])
924  {
925  lcase[anz->l].min[i]=lcase[anz->l].dat[i][node[j].nr];
926  lcase[anz->l].nmin[i]=node[j].nr;
927  }
928  }
929  }
930  }
931  }
932 
933  else if(flag == 4)
934  {
935  anz->l++;
936  printf ("reading Dataset No:%d\n",anz->l+1);
937  if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
938  { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
939 
940  lcase[anz->l].value=stof( rec_str, 13, 25 );
941  strcpy(lcase[anz->l].name,"DISP ");
942  lcase[anz->l].ncomps = 3;
943  lcase[anz->l].irtype = 1;
944  lcase[anz->l].loaded = 1;
945  lcase[anz->l].format_flag=format_flag;
946 
947  if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
948  printf("\n\n ERROR: malloc failure\n\n" );
949  if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
950  printf("\n\n ERROR: malloc failure\n\n" );
951  if ( (lcase[anz->l].max = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
952  printf("\n\n ERROR: malloc failure\n\n" );
953  if ( (lcase[anz->l].min = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
954  printf("\n\n ERROR: malloc failure\n\n" );
955  if ( (lcase[anz->l].dat = (float **)malloc( lcase[anz->l].ncomps * sizeof(float *))) == NULL )
956  printf("\n\n ERROR: malloc failure\n\n" );
957  if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
958  printf("\n\n ERROR: malloc failure\n\n" );
959  if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
960  printf("\n\n ERROR: malloc failure\n\n" );
961  for(i=0; i<lcase[anz->l].ncomps; i++)
962  {
963  if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
964  printf("\n\n ERROR: malloc failed\n\n" );
965  if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
966  printf("\n\n ERROR: malloc failed\n\n" );
967  lcase[anz->l].max[i]=-MAX_FLOAT;
968  lcase[anz->l].min[i]=MAX_FLOAT;
969  if ( (lcase[anz->l].dat[i] = (float *)malloc( (anz->nmax+1) * sizeof(float))) == NULL )
970  printf("\n\n ERROR: malloc failure\n\n" );
971  for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
972  }
973  if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
974  printf("\n\n ERROR: malloc failure\n\n" );
975  if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
976  printf("\n\n ERROR: malloc failure\n\n" );
977  if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
978  printf("\n\n ERROR: malloc failure\n\n" );
979  if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
980  printf("\n\n ERROR: malloc failure\n\n" );
981  if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
982  printf("\n\n ERROR: malloc failure\n\n" );
983 
984  for(i=0; i<lcase[anz->l].ncomps; i++)
985  {
986  lcase[anz->l].menu[i] = 1;
987  lcase[anz->l].ictype[i] = 2;
988  lcase[anz->l].icind1[i] = i+1;
989  lcase[anz->l].icind2[i] = 0;
990  lcase[anz->l].iexist[i] = 0;
991  }
992 
993  strcpy(lcase[anz->l].compName[0], "x ");
994  strcpy(lcase[anz->l].compName[1], "y ");
995  strcpy(lcase[anz->l].compName[2], "z ");
996  errFlag=0;
997  do
998  {
999  length = frecord( handle, rec_str);
1000  if (rec_str[length] == (char)EOF) break;
1001  flag = stoi(rec_str,1,3);
1002  if(flag == -1)
1003  {
1004  if (!format_flag) nodenr = stoi(rec_str,4,8);
1005  else nodenr = stoi(rec_str,4,13);
1006  if (nodenr>anz->nmax)
1007  {
1008  if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1009  }
1010  else if (!format_flag)
1011  {
1012  for(i=0; i<lcase[anz->l].ncomps; i++)
1013  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[8+i*12], 1, 12);
1014  }
1015  else
1016  {
1017  for(i=0; i<lcase[anz->l].ncomps; i++)
1018  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[13+i*12], 1, 12);
1019  }
1020  }
1021  }while(flag!=-3);
1022  for(n=0; n<anz->n; n++)
1023  {
1024  nodenr=node[n].nr;
1025  for(i=0; i<lcase[anz->l].ncomps; i++)
1026  {
1027  if(lcase[anz->l].dat[i][nodenr] > lcase[anz->l].max[i])
1028  {
1029  lcase[anz->l].max[i]=lcase[anz->l].dat[i][nodenr];
1030  lcase[anz->l].nmax[i]=nodenr;
1031  }
1032  if(lcase[anz->l].dat[i][nodenr] < lcase[anz->l].min[i])
1033  {
1034  lcase[anz->l].min[i]=lcase[anz->l].dat[i][nodenr];
1035  lcase[anz->l].nmin[i]=nodenr;
1036  }
1037  }
1038  }
1039  }
1040 
1041  else if(flag == 5)
1042  {
1043  anz->l++;
1044  printf ("reading Dataset No:%d\n",anz->l+1);
1045  if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
1046  { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
1047 
1048  lcase[anz->l].value=stof( rec_str, 13, 25 );
1049  strcpy(lcase[anz->l].name,"STRESS ");
1050  lcase[anz->l].ncomps = 6;
1051  lcase[anz->l].irtype = 1;
1052  lcase[anz->l].loaded = 1;
1053  lcase[anz->l].format_flag=format_flag;
1054 
1055  if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1056  printf("\n\n ERROR: malloc failure\n\n" );
1057  if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1058  printf("\n\n ERROR: malloc failure\n\n" );
1059  if ( (lcase[anz->l].max = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
1060  printf("\n\n ERROR: malloc failure\n\n" );
1061  if ( (lcase[anz->l].min = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
1062  printf("\n\n ERROR: malloc failure\n\n" );
1063  if ( (lcase[anz->l].dat = (float **)malloc( lcase[anz->l].ncomps * sizeof(float *))) == NULL )
1064  printf("\n\n ERROR: malloc failure\n\n" );
1065  if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1066  printf("\n\n ERROR: malloc failure\n\n" );
1067  if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1068  printf("\n\n ERROR: malloc failure\n\n" );
1069  for(i=0; i<lcase[anz->l].ncomps; i++)
1070  {
1071  if ( (lcase[anz->l].dat[i] = (float *)malloc( (anz->nmax+1) * sizeof(float))) == NULL )
1072  printf("\n\n ERROR: malloc failure\n\n" );
1073  if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1074  printf("\n\n ERROR: malloc failed\n\n" );
1075  if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1076  printf("\n\n ERROR: malloc failed\n\n" );
1077  lcase[anz->l].max[i]=-MAX_FLOAT;
1078  lcase[anz->l].min[i]=MAX_FLOAT;
1079  for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
1080  }
1081  if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1082  printf("\n\n ERROR: malloc failure\n\n" );
1083  if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1084  printf("\n\n ERROR: malloc failure\n\n" );
1085  if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1086  printf("\n\n ERROR: malloc failure\n\n" );
1087  if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1088  printf("\n\n ERROR: malloc failure\n\n" );
1089  if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1090  printf("\n\n ERROR: malloc failure\n\n" );
1091 
1092  for(i=0; i<lcase[anz->l].ncomps; i++)
1093  {
1094  lcase[anz->l].menu[i] = 1;
1095  lcase[anz->l].ictype[i] = 4;
1096  lcase[anz->l].iexist[i] = 0;
1097  }
1098  lcase[anz->l].icind1[0] = 1;
1099  lcase[anz->l].icind2[0] = 1;
1100  lcase[anz->l].icind1[1] = 2;
1101  lcase[anz->l].icind2[1] = 2;
1102  lcase[anz->l].icind1[2] = 3;
1103  lcase[anz->l].icind2[2] = 3;
1104  lcase[anz->l].icind1[3] = 1;
1105  lcase[anz->l].icind2[3] = 2;
1106  lcase[anz->l].icind1[4] = 2;
1107  lcase[anz->l].icind2[4] = 3;
1108  lcase[anz->l].icind1[5] = 3;
1109  lcase[anz->l].icind2[5] = 1;
1110 
1111  strcpy(lcase[anz->l].compName[0], "xx ");
1112  strcpy(lcase[anz->l].compName[1], "yy ");
1113  strcpy(lcase[anz->l].compName[2], "zz ");
1114  strcpy(lcase[anz->l].compName[3], "xy ");
1115  strcpy(lcase[anz->l].compName[4], "yz ");
1116  strcpy(lcase[anz->l].compName[5], "zx ");
1117  errFlag=0;
1118  do
1119  {
1120  length = frecord( handle, rec_str);
1121  if (rec_str[length] == (char)EOF) break;
1122  flag = stoi(rec_str,1,3);
1123  if(flag == -1)
1124  {
1125  if (!format_flag) nodenr = stoi(rec_str,4,8);
1126  else nodenr = stoi(rec_str,4,13);
1127  if (nodenr>anz->nmax)
1128  {
1129  if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1130  }
1131  else
1132  {
1133  /* new line */
1134  length = frecord( handle, rec_str);
1135  if (rec_str[length] == (char)EOF) break;
1136  if (!format_flag)
1137  {
1138  for(i=0; i<lcase[anz->l].ncomps; i++)
1139  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[8+i*12], 1, 12);
1140  }
1141  else
1142  {
1143  for(i=0; i<lcase[anz->l].ncomps; i++)
1144  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[13+i*12], 1, 12);
1145  }
1146  }
1147  }
1148  }while(flag!=-3);
1149  for(n=0; n<anz->n; n++)
1150  {
1151  nodenr=node[n].nr;
1152  for(i=0; i<lcase[anz->l].ncomps; i++)
1153  {
1154  if(lcase[anz->l].dat[i][nodenr] > lcase[anz->l].max[i])
1155  {
1156  lcase[anz->l].max[i]=lcase[anz->l].dat[i][nodenr];
1157  lcase[anz->l].nmax[i]=nodenr;
1158  }
1159  if(lcase[anz->l].dat[i][nodenr] < lcase[anz->l].min[i])
1160  {
1161  lcase[anz->l].min[i]=lcase[anz->l].dat[i][nodenr];
1162  lcase[anz->l].nmin[i]=nodenr;
1163  }
1164  }
1165  }
1166  }
1167 
1168  else if((flag == 7)||(flag == 9))
1169  {
1170  anz->l++;
1171  printf ("reading Dataset No:%d\n",anz->l+1);
1172  if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+2) * sizeof(Datasets))) == NULL )
1173  { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
1174 
1175  lcase[anz->l].value=stof( rec_str, 13, 25 );
1176  strcpy(lcase[anz->l].name,"TEMP ");
1177  lcase[anz->l].ncomps = 1;
1178  lcase[anz->l].irtype = 1;
1179  lcase[anz->l].loaded = 1;
1180  lcase[anz->l].format_flag=format_flag;
1181 
1182  if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1183  printf("\n\n ERROR: malloc failure\n\n" );
1184  if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1185  printf("\n\n ERROR: malloc failure\n\n" );
1186  if ( (lcase[anz->l].max = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
1187  printf("\n\n ERROR: malloc failure\n\n" );
1188  if ( (lcase[anz->l].min = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
1189  printf("\n\n ERROR: malloc failure\n\n" );
1190  if ( (lcase[anz->l].dat = (float **)malloc( lcase[anz->l].ncomps * sizeof(float *))) == NULL )
1191  printf("\n\n ERROR: malloc failure\n\n" );
1192  if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1193  printf("\n\n ERROR: malloc failure\n\n" );
1194  if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
1195  printf("\n\n ERROR: malloc failure\n\n" );
1196  for(i=0; i<lcase[anz->l].ncomps; i++)
1197  {
1198  if ( (lcase[anz->l].dat[i] = (float *)malloc( (anz->nmax+1) * sizeof(float))) == NULL )
1199  printf("\n\n ERROR: malloc failure\n\n" );
1200  if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1201  printf("\n\n ERROR: malloc failed\n\n" );
1202  if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
1203  printf("\n\n ERROR: malloc failed\n\n" );
1204  lcase[anz->l].max[i]=-MAX_FLOAT;
1205  lcase[anz->l].min[i]=MAX_FLOAT;
1206  for(j=0; j<=anz->nmax; j++) lcase[anz->l].dat[i][j]=0.;
1207  }
1208  if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1209  printf("\n\n ERROR: malloc failure\n\n" );
1210  if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1211  printf("\n\n ERROR: malloc failure\n\n" );
1212  if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1213  printf("\n\n ERROR: malloc failure\n\n" );
1214  if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1215  printf("\n\n ERROR: malloc failure\n\n" );
1216  if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
1217  printf("\n\n ERROR: malloc failure\n\n" );
1218 
1219  for(i=0; i<lcase[anz->l].ncomps; i++)
1220  {
1221  lcase[anz->l].menu[i] = 1;
1222  lcase[anz->l].ictype[i] = 1;
1223  lcase[anz->l].icind1[i] = i+1;
1224  lcase[anz->l].icind2[i] = 0;
1225  lcase[anz->l].iexist[i] = 0;
1226  }
1227 
1228  strcpy(lcase[anz->l].compName[0], "Value ");
1229  errFlag=0;
1230  do
1231  {
1232  length = frecord( handle, rec_str);
1233  if (rec_str[length] == (char)EOF) break;
1234  flag = stoi(rec_str,1,3);
1235  if(flag == -1)
1236  {
1237  if (!format_flag) nodenr = stoi(rec_str,4,8);
1238  else nodenr = stoi(rec_str,4,13);
1239  if (nodenr>anz->nmax)
1240  {
1241  if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1242  }
1243  else if (!format_flag)
1244  {
1245  for(i=0; i<lcase[anz->l].ncomps; i++)
1246  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[8+i*12], 1, 12);
1247  }
1248  else
1249  {
1250  for(i=0; i<lcase[anz->l].ncomps; i++)
1251  lcase[anz->l].dat[i][nodenr]= stof(&rec_str[13+i*12], 1, 12);
1252  }
1253  }
1254  }while(flag!=-3);
1255  for(n=0; n<anz->n; n++)
1256  {
1257  nodenr=node[n].nr;
1258  for(i=0; i<lcase[anz->l].ncomps; i++)
1259  {
1260  if(lcase[anz->l].dat[i][nodenr] > lcase[anz->l].max[i])
1261  {
1262  lcase[anz->l].max[i]=lcase[anz->l].dat[i][nodenr];
1263  lcase[anz->l].nmax[i]=nodenr;
1264  }
1265  if(lcase[anz->l].dat[i][nodenr] < lcase[anz->l].min[i])
1266  {
1267  lcase[anz->l].min[i]=lcase[anz->l].dat[i][nodenr];
1268  lcase[anz->l].nmin[i]=nodenr;
1269  }
1270  }
1271  }
1272  }
1273 
1274  else
1275  {
1276  next:;
1277  printf (" overread Block: %s\n", rec_str);
1278  do
1279  {
1280  length = frecord( handle, rec_str);
1281  if (rec_str[length] == (char)EOF) break;
1282  /* printf ("\n record:%d %s\n", length, rec_str); */
1283  if (length != 0)
1284  {
1285  flag = stoi(rec_str,1,5);
1286  }
1287  } while(flag != -3);
1288  }
1289  }
1290 
1291  for(i=0; i<anz_p; i++) SFREE(pheader[i]); SFREE(pheader);
1292  SFREE( filepntr);
1293 
1294  anz->u++;
1295  anz->l++;
1296  if(anz->n<0) anz->n=0;
1297  if(anz->e<0) anz->e=0;
1298 
1299  if ( e_nmax > (anz->nmax) )
1300  {
1301  printf ("\nWARNING: element requestes a nodename higher than allocated\n\n");
1302  printf (" e_nmax=%d e_nmin=%d\n", e_nmax, e_nmin );
1303  }
1304  if ( e_nmin < 1 )
1305  {
1306  printf ("\nWARNING: element requestes a nodename lower than allocated\n\n");
1307  printf (" e_nmax=%d e_nmin=%d\n", e_nmax, e_nmin );
1308  }
1309  elemChecker( anz->e, node, elem);
1310 
1311  anz->orign = anz->n;
1312  anz->orignmax = anz->nmax;
1313  anz->olc = anz->l;
1314 
1315  *nptr = node; *eptr = elem; *lptr = lcase;
1316  return(1);
1317 }
int npheader
Definition: readfrd.h:77
char ** compName
Definition: readfrd.h:78
char ** pheader
Definition: readfrd.h:76
int * nmin
Definition: readfrd.h:104
char analysis_name[MAX_LINE_LENGTH]
Definition: readfrd.h:83
#define MAX_FLOAT
Definition: readfrd.h:12
char ** icname
Definition: readfrd.h:79
char dataset_text[MAX_LINE_LENGTH]
Definition: readfrd.h:82
int nmax
Definition: readfrd.h:32
int emax
Definition: readfrd.h:34
int analysis_type
Definition: readfrd.h:90
int u
Definition: readfrd.h:18
fpos_t * fileptr
Definition: readfrd.h:87
double stof(char *string, int a, int b)
Definition: stof.c:15
int mat
Definition: readfrd.h:60
char ** pheader
Definition: readfrd.h:17
char dataset_name[MAX_LINE_LENGTH]
Definition: readfrd.h:81
char model[MAX_LINE_LENGTH]
Definition: readfrd.h:15
int nmin
Definition: readfrd.h:33
int emin
Definition: readfrd.h:35
int nod[27]
Definition: readfrd.h:71
int n
Definition: readfrd.h:20
#define MAX_LINE_LENGTH
Definition: readfrd.h:10
FILE * handle
Definition: readfrd.h:86
int etype[100]
Definition: readfrd.h:31
void stos(char *string, int a, int b, char *puffer)
Definition: stos.c:16
int nr
Definition: readfrd.h:45
double nz
Definition: readfrd.h:52
int strsplt(char *rec_str, char breakchar, char ***ptr)
Definition: strsplt.c:13
int nr
Definition: readfrd.h:56
int * menu
Definition: readfrd.h:94
int indx
Definition: readfrd.h:46
float * min
Definition: readfrd.h:102
int orignmax
Definition: readfrd.h:36
double ny
Definition: readfrd.h:51
char name[MAX_LINE_LENGTH]
Definition: readfrd.h:80
int * nmax
Definition: readfrd.h:103
int p
Definition: readfrd.h:19
int olc
Definition: readfrd.h:38
int elemChecker(int sum_e, Nodes *node, Elements *elem)
Definition: elemChecker.c:17
int l
Definition: readfrd.h:28
#define SFREE(a)
Definition: CalculiX.h:41
int e
Definition: readfrd.h:21
#define MAX_INTEGER
Definition: readfrd.h:11
int ncomps
Definition: readfrd.h:92
int group
Definition: readfrd.h:59
char filename[MAX_LINE_LENGTH]
Definition: readfrd.h:85
int irtype
Definition: readfrd.h:93
float * max
Definition: readfrd.h:101
int orign
Definition: readfrd.h:37
char ** uheader
Definition: readfrd.h:16
float value
Definition: readfrd.h:84
int compare(char *str1, char *str2, int length)
Definition: compare.c:13
#define INI_FIELD_SIZE
Definition: readfrd.c:39
int format_flag
Definition: readfrd.h:89
int frecord(FILE *handle1, char *string)
Definition: frecord.c:17
float ** dat
Definition: readfrd.h:99
int loaded
Definition: readfrd.h:88
Definition: readfrd.h:44
int * iexist
Definition: readfrd.h:98
int * icind2
Definition: readfrd.h:97
int stoi(char *string, int a, int b)
Definition: stoi.c:15
int attr
Definition: readfrd.h:61
int step_number
Definition: readfrd.h:91
Definition: readfrd.h:75
Definition: readfrd.h:55
int * ictype
Definition: readfrd.h:95
int type
Definition: readfrd.h:58
double nx
Definition: readfrd.h:50
int * icind1
Definition: readfrd.h:96

◆ readfrdblock()

int readfrdblock ( int  lc,
Summen anz,
Nodes node,
Datasets lcase 
)
1324 {
1325  register int i,j, n;
1326  int length, flag, format_flag, nodenr=0, ncomps;
1327  int nod_data=0, maxcomps=0;
1328  int errFlag=0;
1329  char rec_str[MAX_LINE_LENGTH];
1330  static float *value=NULL;
1331  FILE *handle;
1332 
1333  // printf("readfrdblock for file:%s\n", lcase[lc].filename);
1334 
1335  /* Open the files and check to see that it was opened correctly */
1336  handle = lcase[lc].handle;
1337  if ( handle== NULL ) { printf ("ERROR: The input file \"%s\" could not be opened.\n\n", lcase[lc].filename); return(-1); }
1338 
1339  if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1340  lcase[lc].loaded=1;
1341 
1342  length = frecord( handle, rec_str);
1343  if (rec_str[length] == (char)EOF) return(-1);
1344 
1345  flag = stoi(rec_str,1,5);
1346  format_flag = stoi(rec_str,74,75);
1347 
1348  if(lcase[lc].ncomps<6) maxcomps=lcase[lc].ncomps;
1349  else maxcomps=6;
1350 
1351  if( lcase[lc].irtype > 2 )
1352  {
1353  printf(" ERROR: Found ELEMENT DATA, this is not suported!\n");
1354  return(-1);
1355  }
1356 
1357  if ( (lcase[lc].dat = (float **)malloc( (lcase[lc].ncomps) * sizeof(float *))) == NULL )
1358  printf("\n\n ERROR: malloc failure\n\n" );
1359  for(i=0; i<(lcase[lc].ncomps); i++)
1360  {
1361  if ( (lcase[lc].dat[i] = (float *)malloc( (anz->nmax+1) * sizeof(float))) == NULL )
1362  printf("\n\n ERROR: malloc failure\n\n" );
1363  for(j=0; j<=anz->nmax; j++) lcase[lc].dat[i][j]=0.;
1364  }
1365 
1366 
1367  if(flag == 100)
1368  {
1369  nod_data=stoi( rec_str, 25, 36 );
1370  if (!format_flag) n=8;
1371  else n=13;
1372  do
1373  {
1374  length = frecord( handle, rec_str);
1375  if (rec_str[length] == (char)EOF) break;
1376  flag = stoi(rec_str,1,3);
1377 
1378  /* bin mode, active after last column definition was read (-5 lines). Attention flag:-6 not permitted so far! */
1379  if ( format_flag==2)
1380  {
1381  if (flag == -4)
1382  {
1383  ncomps = stoi(rec_str,14,18);
1384  }
1385  else continue;
1386 
1387  //printf("format_flag=%d ncomps:%d\n",format_flag,ncomps);
1388 
1389  /* skip the meta-data */
1390  for(i=0; i<ncomps; i++) length = frecord( handle, rec_str);
1391 
1392  if ( (value = (float *)realloc((float *)value, (lcase[lc].ncomps) * sizeof(float))) == NULL )
1393  printf("\n\n ERROR: realloc failed, value\n\n") ;
1394  for(n=0; n<nod_data; n++)
1395  {
1396  length=fread((int *)&nodenr,sizeof(int),1,handle);
1397  length=fread((float *)value,sizeof(float),lcase[lc].ncomps,handle);
1398  // printf("N:%d ",nodenr);
1399  for(i=0; i<lcase[lc].ncomps; i++)
1400  {
1401  // printf(" %f",value[i]);
1402  lcase[lc].dat[i][nodenr]= value[i];
1403  }
1404  // printf("\n");
1405  }
1406  break;
1407  }
1408 
1409  else if(flag == -1)
1410  {
1411  if (format_flag) nodenr = stoi(rec_str,4,13); else nodenr = stoi(rec_str,4,8);
1412  if (nodenr>anz->nmax)
1413  {
1414  if (!errFlag) { errFlag=1; printf("WARNING: found node:%d in Dataset higher than in geometry allocated:%d\n", nodenr, anz->nmax); }
1415  }
1416  else if ( lcase[lc].irtype == 1 )
1417  {
1418  if(maxcomps==6)
1419  {
1420  i=6;
1421  if ( format_flag)
1422  {
1423  lcase[lc].dat[0][nodenr]= stof(&rec_str[ 13 ], 1, 12);
1424  lcase[lc].dat[1][nodenr]= stof(&rec_str[ 25 ], 1, 12);
1425  lcase[lc].dat[2][nodenr]= stof(&rec_str[ 37 ], 1, 12);
1426  lcase[lc].dat[3][nodenr]= stof(&rec_str[ 49 ], 1, 12);
1427  lcase[lc].dat[4][nodenr]= stof(&rec_str[ 61 ], 1, 12);
1428  lcase[lc].dat[5][nodenr]= stof(&rec_str[ 73 ], 1, 12);
1429  }
1430  else
1431  {
1432  lcase[lc].dat[0][nodenr]= stof(&rec_str[ 8 ], 1, 12);
1433  lcase[lc].dat[1][nodenr]= stof(&rec_str[ 20 ], 1, 12);
1434  lcase[lc].dat[2][nodenr]= stof(&rec_str[ 32 ], 1, 12);
1435  lcase[lc].dat[3][nodenr]= stof(&rec_str[ 44 ], 1, 12);
1436  lcase[lc].dat[4][nodenr]= stof(&rec_str[ 56 ], 1, 12);
1437  lcase[lc].dat[5][nodenr]= stof(&rec_str[ 68 ], 1, 12);
1438  }
1439  }
1440  else for(i=0; i<maxcomps; i++) lcase[lc].dat[i][nodenr]= stof(&rec_str[n+i*12], 1, 12);
1441  }
1442  else i=0;
1443  }
1444  else if(flag == -2)
1445  {
1446  if (!format_flag) n=8;
1447  else n=13;
1448  j=0;
1449  do
1450  {
1451  lcase[lc].dat[i][nodenr]= stof(&rec_str[n+j*12], 1, 12);
1452  i++;j++;
1453  }while((j<6)&&(i<lcase[lc].ncomps));
1454  }
1455  }while(flag!=-3);
1456 
1457  for(j=0; j<anz->orign; j++)
1458  {
1459  for(i=0; i<lcase[lc].ncomps; i++)
1460  {
1461  if(lcase[lc].dat[i][node[j].nr] > lcase[lc].max[i])
1462  {
1463  lcase[lc].max[i]=lcase[lc].dat[i][node[j].nr];
1464  lcase[lc].nmax[i]=node[j].nr;
1465  }
1466  if(lcase[lc].dat[i][node[j].nr] < lcase[lc].min[i])
1467  {
1468  lcase[lc].min[i]=lcase[lc].dat[i][node[j].nr];
1469  lcase[lc].nmin[i]=node[j].nr;
1470  }
1471  }
1472  }
1473  }
1474 
1475  return(0);
1476 }
int * nmin
Definition: readfrd.h:104
int nmax
Definition: readfrd.h:32
#define max(a, b)
Definition: cascade.c:32
double stof(char *string, int a, int b)
Definition: stof.c:15
#define min(a, b)
Definition: cascade.c:31
#define MAX_LINE_LENGTH
Definition: readfrd.h:10
FILE * handle
Definition: readfrd.h:86
int nr
Definition: readfrd.h:45
float * min
Definition: readfrd.h:102
int * nmax
Definition: readfrd.h:103
int ncomps
Definition: readfrd.h:92
float * max
Definition: readfrd.h:101
int orign
Definition: readfrd.h:37
int frecord(FILE *handle1, char *string)
Definition: frecord.c:17
float ** dat
Definition: readfrd.h:99
int loaded
Definition: readfrd.h:88
int stoi(char *string, int a, int b)
Definition: stoi.c:15

◆ stof()

double stof ( char *  string,
int  a,
int  b 
)
16 {
17  register int n, i;
18  static char puffer[MAX_LINE_LENGTH];
19 
20  n=-1;
21  for (i=a-1; i<b; i++)
22  {
23  n++;
24  if ((i>=MAX_LINE_LENGTH)||(n>=MAX_LINE_LENGTH)) break;
25  puffer[n] = string[i];
26  }
27  puffer[n+1] = '\0';
28  return( atof( puffer ) );
29 }
#define MAX_LINE_LENGTH
Definition: readfrd.h:10

◆ stoi()

int stoi ( char *  string,
int  a,
int  b 
)
16 {
17  register int n, i;
18  static char puffer[MAX_LINE_LENGTH];
19 
20  n=-1;
21  for (i=a-1; i<b; i++)
22  {
23  n++;
24  if ((i>=MAX_LINE_LENGTH)||(n>=MAX_LINE_LENGTH)) break;
25  puffer[n] = string[i];
26  }
27  puffer[n+1] = '\0';
28  return( atoi( puffer ) );
29 }
#define MAX_LINE_LENGTH
Definition: readfrd.h:10

◆ stos()

void stos ( char *  string,
int  a,
int  b,
char *  puffer 
)
17 {
18  register int n, i;
19 
20  n=-1;
21  for (i=a-1; i<b; i++)
22  {
23  n++;
24  if ((i>=MAX_LINE_LENGTH)||(n>=MAX_LINE_LENGTH)) break;
25  puffer[n] = string[i];
26  }
27  puffer[n+1] = '\0';
28 }
#define MAX_LINE_LENGTH
Definition: readfrd.h:10

◆ strsplt()

int strsplt ( char *  rec_str,
char  breakchar,
char ***  ptr 
)
14 {
15  int i,j;
16  int nextarg=0, letter=0, skip_breakchar=0;
17  char **dat;
18 
19  if( (dat= (char **)malloc( 1*sizeof(char *))) == NULL )
20  printf(" ERROR: malloc failed\n");
21  if( (dat[0]= (char *)malloc(MAX_LINE_LENGTH *sizeof(char))) == NULL )
22  printf(" ERROR: malloc failed\n");
23 
24  /* scan all args divided by breakchar */
25  nextarg=0;letter=0;
26  for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
27  for(i=0; i<MAX_LINE_LENGTH; i++)
28  {
29  if(rec_str[i]==(char)EOF) { break; }
30  if(rec_str[i]=='\n') { break; }
31  if(rec_str[i]==0) { break; }
32  if((rec_str[i]==breakchar)&&(!skip_breakchar))
33  {
34  /* check if the former dat has chars */
35  if(strlen(dat[nextarg]))
36  {
37  nextarg++;
38  letter=0;
39  if( (dat= (char **)realloc((char **)dat, (nextarg+1)*sizeof(char *))) == NULL )
40  printf(" ERROR: realloc failed\n");
41  if( (dat[nextarg]= (char *)malloc(MAX_LINE_LENGTH *sizeof(char))) == NULL )
42  printf(" ERROR: malloc failed\n");
43  for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
44  }
45  }
46  else
47  {
48  if(rec_str[i]=='"') skip_breakchar=!skip_breakchar;
49  else if(skip_breakchar)
50  {
51  dat[nextarg][letter]=rec_str[i];
52  letter++;
53  }
54  else if(rec_str[i]!=' ')
55  {
56  dat[nextarg][letter]=rec_str[i];
57  letter++;
58  }
59  }
60  }
61  *ptr=dat;
62 
63  /* check if the former dat has chars */
64  if(strlen(dat[nextarg])) nextarg++;
65 
66  /* for(i=0; i<nextarg; i++) printf("dat:%s|\n",dat[i]); */
67  return(nextarg);
68 }
#define MAX_LINE_LENGTH
Definition: readfrd.h:10

◆ v_betrag()

double v_betrag ( double *  a)
13 {
14  return sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
15 }

◆ v_prod()

void v_prod ( double *  A,
double *  B,
double *  C 
)
6 {
7  C[0]=A[1]*B[2]-A[2]*B[1];
8  C[1]=A[2]*B[0]-A[0]*B[2];
9  C[2]=A[0]*B[1]-A[1]*B[0];
10 }

◆ v_result()

void v_result ( double *  A,
double *  B,
double *  C 
)
Hosted by OpenAircraft.com, (Michigan UAV, LLC)