root/src/readfrd.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. freeDatasets
  2. readfrd
  3. readfrdblock
  4. getRecord
  5. readOneNode

   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 <unistd.h>
  24 #include <stdio.h>
  25 #include <math.h>
  26 #include <stdlib.h>
  27 #include <pthread.h>
  28 #include "CalculiX.h"
  29 
  30 #include <stdlib.h>
  31 #include <math.h>
  32 #include <stdio.h>
  33 #include <string.h>
  34 #include <unistd.h>
  35 #include "readfrd.h"
  36 
  37 #define TEST     0
  38 
  39 #define INI_FIELD_SIZE 1000000
  40 
  41 
  42 /* ToDo:
  43 */
  44 
  45 
  46 void freeDatasets(Datasets *lcase, ITG nr)
  47 {
  48   register ITG i;
  49 
  50   printf(" free lc[%" ITGFORMAT "] ncomps:%" ITGFORMAT "\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 }
  82 
  83 
  84 /* read_mode=0: jump '100C' data-blocks and read them later on demand */
  85 /* in any case for each results of a new step the first data-block is readed to see how much nodes are included */
  86 
  87 ITG readfrd( char *datin, Summen *anz, Nodes **nptr, Elements **eptr, Datasets **lptr, ITG read_mode )
  88 {
  89   FILE *handle;
  90   register ITG i=0, j=0;
  91   ITG  nodeflag=0, elemflag=0, errFlag=0, firsttime=1;
  92   ITG n;  /* used in format_flag */
  93   long offset=0;
  94   fpos_t *filepntr=NULL;
  95   ITG 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   ITG  ncomps, maxcomps=0, nvals, nentities;
  98   char rec_str[MAX_LINE_LENGTH];
  99   ITG  node_field_size, elem_field_size;
 100   ITG  e_nmax=1, e_nmin=1;
 101   ITG  length, flag, format_flag;
 102   ITG  ipuf, nodenr=0;
 103   static float *value=NULL;
 104 
 105   char **dat, **compName;
 106   ITG          *menu, *ictype, *icind1, *icind2, *iexist; 
 107 
 108   ITG 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:%" ITGFORMAT " IFORMT:%" ITGFORMAT "\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:%" ITGFORMAT " 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:%" ITGFORMAT " 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:%" ITGFORMAT " 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=%" ITGFORMAT " 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((ITG *)&node[anz->n].nr,sizeof(ITG),1,handle);
 298         //printf("n:%" ITGFORMAT "\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:%" ITGFORMAT " 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:%" ITGFORMAT " 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=%" ITGFORMAT " 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 %" ITGFORMAT " 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:%" ITGFORMAT " 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 %" ITGFORMAT " elements allocated \n", elem_data);
 389         for (i=0; i<elem_data; i++)
 390         {
 391           anz->e++;
 392           length=fread((ITG *)&elem[anz->e].nr,sizeof(ITG),1,handle);
 393           length=fread((ITG *)&elem[anz->e].type,sizeof(ITG),1,handle);
 394           length=fread((ITG *)&elem[anz->e].group,sizeof(ITG),1,handle);
 395           length=fread((ITG *)&elem[anz->e].mat,sizeof(ITG),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:%" ITGFORMAT " t:%" ITGFORMAT " g:%" ITGFORMAT " m:%" ITGFORMAT " n:%" ITGFORMAT "\n", elem[anz->e].nr, elem[anz->e].type,elem[anz->e].group,elem[anz->e].mat, ipuf);
 413           length=fread((ITG *)elem[anz->e].nod,sizeof(ITG),ipuf,handle);
 414           //for(j=0;j<ipuf; j++) printf(" %" ITGFORMAT "",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:%" ITGFORMAT " 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%" ITGFORMAT " e=%" ITGFORMAT " typ=%" ITGFORMAT " grp=%" ITGFORMAT " mat=%" ITGFORMAT " \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:%" ITGFORMAT " is from unknown type:%" ITGFORMAT "\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:%" ITGFORMAT " 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 %" ITGFORMAT " elements reallocated \n", anz->e);
 529       }
 530     }
 531 
 532     else if(flag == 100)
 533     {
 534       anz->l++;
 535 
 536       printf ("reading Dataset No:%" ITGFORMAT "\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:%" ITGFORMAT " than in the model defined:%" ITGFORMAT "\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:%" ITGFORMAT "\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 %" ITGFORMAT "", &ipuf);
 597             if(ipuf>-1) sprintf(lcase[anz->l].dataset_text,"ND:%" ITGFORMAT "",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 %" ITGFORMAT "", &ipuf);
 605             if(ipuf>-1) sprintf(&lcase[anz->l].dataset_text[strlen(lcase[anz->l].dataset_text)]," MODE:%" ITGFORMAT "",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=%" ITGFORMAT " ncomps:%" ITGFORMAT " lcncomps:%" ITGFORMAT "\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((ITG *)&nodenr,sizeof(ITG),1,handle);
 641               length=fread((float *)value,sizeof(float),lcase[anz->l].ncomps,handle);
 642               // printf("n:%" ITGFORMAT " N:%" ITGFORMAT " ",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:%" ITGFORMAT "\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:%" ITGFORMAT " in Dataset higher than in geometry allocated:%" ITGFORMAT "\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("%" ITGFORMAT "", 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 = (ITG *)malloc( (lcase[anz->l].ncomps) * sizeof(ITG))) == NULL )
 751             printf("\n\n ERROR: malloc failure\n\n" );
 752           if ( (lcase[anz->l].nmin = (ITG *)malloc( (lcase[anz->l].ncomps) * sizeof(ITG))) == 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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 763             printf("\n\n ERROR: malloc failure\n\n" );
 764           if ( (lcase[anz->l].ictype = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 765             printf("\n\n ERROR: malloc failure\n\n" );
 766           if ( (lcase[anz->l].icind1 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 767             printf("\n\n ERROR: malloc failure\n\n" );
 768           if ( (lcase[anz->l].icind2 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 769             printf("\n\n ERROR: malloc failure\n\n" );
 770           if ( (lcase[anz->l].iexist = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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[%" ITGFORMAT "] ncomps:%" ITGFORMAT "\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:%" ITGFORMAT " \"%s\" %" ITGFORMAT "\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:%" ITGFORMAT " nvals:%" ITGFORMAT "\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:%" ITGFORMAT " nod_data:%" ITGFORMAT " n:%" ITGFORMAT " nvals:%" ITGFORMAT "\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 = (ITG *)malloc( ipuf * sizeof(ITG))) == NULL )
 878             printf("\n\n ERROR: malloc failure\n\n" );
 879           if ( (ictype = (ITG *)malloc( ipuf * sizeof(ITG))) == NULL )
 880             printf("\n\n ERROR: malloc failure\n\n" );
 881           if ( (icind1 = (ITG *)malloc( ipuf * sizeof(ITG))) == NULL )
 882             printf("\n\n ERROR: malloc failure\n\n" );
 883           if ( (icind2 = (ITG *)malloc( ipuf * sizeof(ITG))) == NULL )
 884             printf("\n\n ERROR: malloc failure\n\n" );
 885           if ( (iexist = (ITG *)malloc( ipuf * sizeof(ITG))) == 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:%" ITGFORMAT "\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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 948         printf("\n\n ERROR: malloc failure\n\n" );
 949       if ( (lcase[anz->l].nmin = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 974         printf("\n\n ERROR: malloc failure\n\n" );
 975       if ( (lcase[anz->l].ictype = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 976         printf("\n\n ERROR: malloc failure\n\n" );
 977       if ( (lcase[anz->l].icind1 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 978         printf("\n\n ERROR: malloc failure\n\n" );
 979       if ( (lcase[anz->l].icind2 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
 980         printf("\n\n ERROR: malloc failure\n\n" );
 981       if ( (lcase[anz->l].iexist = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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:%" ITGFORMAT " in Dataset higher than in geometry allocated:%" ITGFORMAT "\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:%" ITGFORMAT "\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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1056         printf("\n\n ERROR: malloc failure\n\n" );
1057       if ( (lcase[anz->l].nmin = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1082         printf("\n\n ERROR: malloc failure\n\n" );
1083       if ( (lcase[anz->l].ictype = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1084         printf("\n\n ERROR: malloc failure\n\n" );
1085       if ( (lcase[anz->l].icind1 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1086         printf("\n\n ERROR: malloc failure\n\n" );
1087       if ( (lcase[anz->l].icind2 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1088         printf("\n\n ERROR: malloc failure\n\n" );
1089       if ( (lcase[anz->l].iexist = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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:%" ITGFORMAT " in Dataset higher than in geometry allocated:%" ITGFORMAT "\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:%" ITGFORMAT "\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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1183         printf("\n\n ERROR: malloc failure\n\n" );
1184       if ( (lcase[anz->l].nmin = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1209         printf("\n\n ERROR: malloc failure\n\n" );
1210       if ( (lcase[anz->l].ictype = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1211         printf("\n\n ERROR: malloc failure\n\n" );
1212       if ( (lcase[anz->l].icind1 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1213         printf("\n\n ERROR: malloc failure\n\n" );
1214       if ( (lcase[anz->l].icind2 = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == NULL )
1215         printf("\n\n ERROR: malloc failure\n\n" );
1216       if ( (lcase[anz->l].iexist = (ITG *)malloc( lcase[anz->l].ncomps * sizeof(ITG))) == 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:%" ITGFORMAT " in Dataset higher than in geometry allocated:%" ITGFORMAT "\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:%" ITGFORMAT " %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=%" ITGFORMAT " e_nmin=%" ITGFORMAT "\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=%" ITGFORMAT " e_nmin=%" ITGFORMAT "\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 }
1318 
1319 
1320 
1321 /* if a block was skipped during first read of frd-file read it now */
1322 /* return -1 if failure */
1323 ITG readfrdblock(ITG lc, Summen *anz,   Nodes     *node, Datasets *lcase )
1324 {
1325   register ITG i,j, n;
1326   ITG  length, flag, format_flag, nodenr=0, ncomps;
1327   ITG  nod_data=0, maxcomps=0;
1328   ITG  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=%" ITGFORMAT " ncomps:%" ITGFORMAT "\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((ITG *)&nodenr,sizeof(ITG),1,handle);
1397           length=fread((float *)value,sizeof(float),lcase[lc].ncomps,handle);
1398           // printf("N:%" ITGFORMAT " ",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:%" ITGFORMAT " in Dataset higher than in geometry allocated:%" ITGFORMAT "\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 }
1477 
1478 
1479 /* regula falsi to find the matching record fast */
1480 /* not finished */
1481 char *getRecord(FILE *handle, ITG n, ITG x0 )
1482 {
1483     ITG ii, m, n1,n2, x=0, offset=0;
1484 
1485     /* search the intersection */
1486     n1=0;                              
1487     n2=n;                            
1488     for(ii=0; ii<n; ii++)
1489     {                     
1490       m=(n2+n1)/2;
1491 
1492       
1493       if( fseek( handle, offset, SEEK_CUR )!=0) printf("error in fseek\n");
1494                           
1495       if(x0>= x ) n1=m;              
1496       if(x0 < x ) n2=m;              
1497       if((n2-n1) == 1) break;           
1498     }                                 
1499 #if TEST
1500     printf("x:%" ITGFORMAT " x0:%" ITGFORMAT "\n", x,x0); 
1501 #endif
1502   return(NULL);
1503 }
1504 
1505 
1506 /* return -1 if failure */
1507 /* return 0 if successfull */
1508 ITG readOneNode( ITG lc, Summen *anz, Datasets *lcase, ITG nodenr, double **vptr, long *byte_offset )
1509 {
1510   register ITG i=0,j, n;
1511   ITG length, flag, inodenr=0;
1512   ITG   maxcomps=0, ncomps;
1513   long offset=0;
1514   ITG  errFlag=0, readFlag=0, bailout=0;
1515   char rec_str[MAX_LINE_LENGTH];
1516   FILE *handle;
1517   float *value=NULL;
1518   double *dat;
1519   ITG  nod_data=0, nvals=0;
1520 
1521   // printf("readOneNode for file:%s *byte_offset:%" ITGFORMAT "\n", lcase[lc].filename, *byte_offset);
1522 
1523   /* Open the files and check to see that it was opened correctly */
1524   handle = lcase[lc].handle;
1525   if ( handle== NULL )  { printf ("ERROR: The input file \"%s\" could not be opened.\n\n", lcase[lc].filename); return(-1); }
1526 
1527   if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1528 
1529   /* the header-lines must be skipped in case byte_offset==0 and format == 2(bin) */
1530   if((lcase[lc].format_flag==2)&&(!*byte_offset))
1531   {
1532     do
1533     {
1534       length = frecord( handle, rec_str);
1535       if (rec_str[length] == (char)EOF) return(-1);
1536       *byte_offset+=length+1;
1537       printf ("record:%s\n", rec_str);
1538       flag = stoi(rec_str,1,5);
1539       if (flag == -4)
1540       {
1541         ncomps = stoi(rec_str,14,18);
1542       }
1543       else continue;
1544 
1545       /* skip the meta-data */
1546       for(i=0; i<ncomps; i++) *byte_offset+= frecord( handle, rec_str)+1;
1547       break;        
1548     }while(1);
1549   }
1550   else{ if( fseek( handle, *byte_offset, SEEK_CUR )!=0) printf("error in fseek\n"); }
1551 
1552   offset=*byte_offset;
1553 
1554   if ( (dat = (double *)malloc( (lcase[lc].ncomps) * sizeof(double ))) == NULL )
1555     printf("\n\n ERROR: malloc failure\n\n" );
1556   *vptr=dat;
1557 
1558   /* if bin mode */
1559   if(lcase[lc].format_flag==2)
1560   {
1561     if ( (value = (float *)realloc((float *)value, (lcase[lc].ncomps) * sizeof(float))) == NULL )
1562       printf("\n\n ERROR: realloc failed, value\n\n") ;
1563     do
1564     {
1565       length=fread((ITG *)&inodenr,sizeof(ITG),1,handle)*sizeof(ITG);
1566       length+=fread((float *)value,sizeof(float),lcase[lc].ncomps,handle)*sizeof(float);
1567       //printf("N:%" ITGFORMAT " ",inodenr);
1568       //for(i=0; i<lcase[lc].ncomps; i++) printf(" %f",value[i]);
1569       //printf("\n");
1570       if(inodenr==nodenr) break;
1571       else offset+=length;
1572     }while(1);
1573     for(i=0; i<lcase[lc].ncomps; i++)
1574     {
1575         //printf(" %f",value[i]);
1576       dat[i]= value[i];
1577     }
1578 
1579     *byte_offset=offset;
1580     //printf("offset:%" ITGFORMAT "\n", offset);
1581     return(0);
1582   }
1583 
1584   if(lcase[lc].ncomps<6) maxcomps=lcase[lc].ncomps;
1585   else maxcomps=6;
1586   if (!lcase[lc].format_flag) n=8;
1587   else n=13;
1588 
1589   if( lcase[lc].irtype > 2 )
1590   {
1591     printf(" ERROR: Found ELEMENT DATA, this is not suported!\n");
1592     return(-1);
1593   }
1594 
1595  repeat_search:;
1596   do
1597   {
1598     length = frecord( handle, rec_str);
1599     if (rec_str[length] == (char)EOF)
1600     {
1601       /* offset obviously false */
1602       offset=0;
1603       if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1604     }
1605     flag = stoi(rec_str,1,3);
1606 
1607     if((readFlag)&&(flag == -2))
1608     {
1609       //printf("-2 node found:%" ITGFORMAT " %" ITGFORMAT " at pos:%" ITGFORMAT "\n", inodenr,nodenr, nod_data);
1610       if (!lcase[lc].format_flag) n=8;
1611       else n=13;
1612       j=0;
1613       do
1614       {
1615         dat[i]= stof(&rec_str[n+j*12], 1, 12);
1616         i++;j++;
1617       }while((j<6)&&(i<lcase[lc].ncomps));
1618     }
1619     else if(readFlag)
1620     {
1621       /* leave after all records of that node are read */
1622 
1623       nod_data--;
1624 
1625       /* get the offset for the next call: */
1626       for (i=0; i<lcase[lc].ncomps; i++) if(lcase[lc].iexist[i]!=1) nvals++;
1627 
1628       if (!lcase[lc].format_flag) n=8;
1629       else n=13;
1630       if(nvals<=6) offset+= nod_data * (n+nvals*12); 
1631       else
1632       {
1633         for(i=0; i<nvals/6; i++) 
1634           offset+= nod_data * (n+6*12+1);
1635         if(nvals%6)
1636           offset+= nod_data * (n+(nvals%6)*12+1);
1637       }
1638       *byte_offset=offset;
1639       //printf("offset:%" ITGFORMAT " nod_data:%" ITGFORMAT " n:%" ITGFORMAT " nvals:%" ITGFORMAT " dat:%f\n", offset,nod_data,n,nvals, dat[0]);
1640       return(0);
1641     }
1642     else if(flag == -1)
1643     {
1644       if (lcase[lc].format_flag) inodenr = stoi(rec_str,4,13); else inodenr = stoi(rec_str,4,8);
1645       nod_data++; 
1646       //printf("node:%" ITGFORMAT " %" ITGFORMAT " at pos:%" ITGFORMAT " ir:%" ITGFORMAT "\n", inodenr,nodenr, nod_data, lcase[lc].irtype);
1647       if (inodenr>anz->nmax)
1648       {
1649         if (!errFlag) { errFlag=1; printf("WARNING: found node:%" ITGFORMAT " in Dataset higher than in geometry allocated:%" ITGFORMAT "\n", inodenr, anz->nmax); }
1650       }
1651       else if (( inodenr==nodenr)&&(lcase[lc].irtype == 1 ))
1652       {
1653         //printf("node found:%" ITGFORMAT " %" ITGFORMAT " at pos:%" ITGFORMAT "\n", inodenr,nodenr, nod_data);
1654         readFlag=1;
1655         if(maxcomps==6)
1656         {
1657           i=6;
1658           if ( lcase[lc].format_flag)
1659           {
1660             dat[0]= stof(&rec_str[  13  ], 1, 12);
1661             dat[1]= stof(&rec_str[  25  ], 1, 12);
1662             dat[2]= stof(&rec_str[  37  ], 1, 12);
1663             dat[3]= stof(&rec_str[  49  ], 1, 12);
1664             dat[4]= stof(&rec_str[  61  ], 1, 12);
1665             dat[5]= stof(&rec_str[  73  ], 1, 12);
1666           }
1667           else
1668           {
1669             dat[0]= stof(&rec_str[  8   ], 1, 12);
1670             dat[1]= stof(&rec_str[  20  ], 1, 12);
1671             dat[2]= stof(&rec_str[  32  ], 1, 12);
1672             dat[3]= stof(&rec_str[  44  ], 1, 12);
1673             dat[4]= stof(&rec_str[  56  ], 1, 12);
1674             dat[5]= stof(&rec_str[  68  ], 1, 12);
1675           }
1676         }
1677         else for(i=0; i<maxcomps; i++) dat[i]= stof(&rec_str[n+i*12], 1, 12);
1678       }
1679       else i=0;
1680     }
1681     
1682   }while(flag!=-3);
1683 
1684   if(!bailout)
1685   {
1686     bailout=1;
1687     offset=0;
1688     //printf("repeat search\n");
1689     if( fsetpos( handle, (fpos_t *)lcase[lc].fileptr)!=0) { printf("error in fsetpos"); return(-1); }
1690     goto repeat_search;
1691   }
1692   return(-1);
1693 }
1694 

/* [<][>][^][v][top][bottom][index][help] */