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 /*
24 Peter Heppel Jan 2016
25    if keyword ndsb  (NoDeleteShellsBeams) is present in pre_read,
26    then DO NOT  delete elements in special sets created by readNG
27 */
28 
29 #include <cgx.h>
30 #include <dirent.h>
31 #include <xwd.h>
32 
33 
34 #define TEST 0
35 #define NOTHREADING 0
36 
37 /* choose the optimization-steps for the mesher */
38 #define MESHOPT_LENGTH 1
39 #define MESHOPT_ANGLE  0
40 #define MAX_PARAM_IN_BRECORD 100
41 #define     N_CLOSEST_TRI 150
42 #define     SMALL_TET_VOLUME 1.e-20
43 #define     LTOL 1.e-7                 // tolerance for tet splitting
44 #define MAX_NR_OF_TETS_PER_ELEM 44
45 #define N_CLOSEST_TETS 200
46 extern int   cmaps;                         /* nr of colormap names */
47 extern char *cmap_names[];
48 extern char cmap_name[];         /* possible values: "classic", "viridis", "turbo", "inferno" */
49 extern int   col_maxc,col_minc;  /* colors of the regions with clipped colors (commands maxc,minc) */
50 extern int   defScalMethod;         /* method to display the scale */
51 extern int   entitycols;
52 extern Entitycol *entitycol;         /* predefined colors of entities */
53 extern char  datin[MAX_LINE_LENGTH];         /* Input-data-file */
54 extern char  buffer[MAX_LINE_LENGTH];
55 extern int   offset, maxIndex;                        /* offset+steps-1 = maxIndex */
56 extern int   basCol[3];                     /* color indexes due to basic colormap */
57 extern int   foregrndcol, backgrndcol;          /* default fore- and background color */
58 extern int   width_ini, height_ini; /* Grafig-Fensterbreite/hoehe */
59 extern int   width_menu, height_menu;
60 extern int   w0, w1, w_index, w_rgb, activWindow;
61 extern int   width_w0, height_w0;
62 extern int   width_w1, height_w1;
63 extern int   MouseMode;                                   /* status maustasten */
64 extern int   halfperiod;
65 extern double dtx, dty, dtz, drx, dry, drz, ds;                 /* Verschiebungen */
66 extern double anim_faktor;                            /* Scalierung der Amplitude */
67 extern char  drawMode;               /* protokoliert drawFunktion (Load=1,Light=2,Animate=3,preprocessor=4, vector=5)*/
68 extern char  automode;            /* set to 1 to perform various automatic actions as determining of divisions etc. during reading of command files */
69 extern char  allowSysFlag;           /* 1: allow the execution of system calls (sys command) */
70 extern char  autoDivFlag;                   /* The div command will set it to 0 and no auto-div is executed */
71 extern char  autoEltyFlag;                   /* The elty command will set it to 0 and no auto-elty is executed */
72 extern char  cullFlag;               /* 1: front face culling */
73 extern char  animFlag;
74 extern GLint   gl_max_eval_order;                         /* max order of NURBS */
75 extern GLdouble R[4][4];                                   /* Rotationsmatrix */
76 extern char  surfFlag;                /* zeichne nur Oberflaechenelemente (1), sonst (0)*/
77 extern char  modelEdgeFlag;                /* zeichne mit Modell-Ecken (1), sonst (0)*/
78 extern char  elemEdgeFlag;                 /* zeichne mit Surface Ecken (1), sonst (0)*/
79 extern char  frameFlag;                   /* mit (1) oder ohne Rahmen um das Grafikfenster */
80 extern char  sequenceFlag;                  /* 1: play a sequence of LC */
81 extern char  captionFlag;                   /* mit (1) oder ohne filename im Menufenster */
82 extern char  textFlag;                   /* mit (1) oder ohne text im Menufenster */
83 extern char  printFlag;                     /* printf 1:on 0:off */
84 extern char  frameFlag;               /* mit (1) oder ohne Rahmen um das Grafigfenster */
85 extern char  scalaFlag;                 /* mit (1) oder ohne scala und wertetexte */
86 extern char  addDispFlag;                    /* 0: original node-coordinates, 1: node-coordinates+displacements */
87 extern char  flipColorFlag;                 /* 0: high values use red, low use blue in scale; 1: flipped */
88 extern char  vectorFlag;                    /* 0: scalar plot, 1: vector plot */
89 extern int   frameSetFlag;               /* triggers frameSet() */
90 extern double dx ,dy;                                      /* Mauskoordinaten */
91 extern int   steps;                          /* Schrittweite der Farbscala */
92 extern double gtol;
93 extern int     ddiv;
94 extern double     dbias;
95 extern char  picture_caption[MAX_LINE_LENGTH];               /* Caption on window base line */
96 extern char  picture_text[MAX_LINE_LENGTH];
97 extern double v_scale;                                    /* scaling-factor for the vectors in the vector-plot */
98 extern char  psviewer[MAX_LINE_LENGTH];
99 extern char  homepath[MAX_LINE_LENGTH];           /* path to the home dir */
100 
101 extern int  cur_commandFile;                   /* >0: current open command file  */
102 int   stopped_commandFile=-1;               /* >0: stopped open command file  */
103 int   commandFiles=0;                  /* counts nr of open command files  */
104 CommandFile *commandFile;             /* stores informations of open command files */
105 extern char  delPntFlag;                    /* 1: deleted points exists */
106 extern char  delShapeFlag;                  /* 1: deleted shapes exists */
107 extern char  delLineFlag;                   /* 1: deleted lines exists */
108 extern char  delLcmbFlag;                   /* 1: deleted lcmbs exists */
109 extern char  delSurfFlag;                   /* 1: deleted surfs exists */
110 extern char  delBodyFlag;                   /* 1: deleted bodys exists */
111 extern char  delNursFlag;
112 extern char  delSetFlag;                  /* 1: deleted sets exists */
113 extern char  movieFlag;                     /* >0: save sequence of gif pictures */
114 extern int  movieFrames;
115 extern char  movieCommandFile[MAX_LINE_LENGTH];        /* stores the file name of a command file which will be executed after the movie is created (frames option only) */
116 extern char  stopFlag;                      /* stop/start animation */
117 extern char  inpformat;                     /* defines the start-up mode of cgx */
118 
119 extern int     read_mode;
120 extern int     setall;
121 extern int   animList;
122 extern int   lcase_animList;
123 
124 extern int     elemMat[MAX_MATERIALS];      /*  Material Numbers, Number of Materials stored in elemMat[0]  */
125 
126 extern int       nasMpc;                                       /* 1: areampc generates mpcs; 0: rbes with optional heat-expansion-coefficient */
127 extern double    nasRbeHec;
128 
129 /* for rgb mode */
130 extern Colours   *colRgb;
131 
132 /* for index mode */
133 extern int       *colNr;
134 
135 extern Scale     scale[1];
136 extern Elements  *e_enqire;     /* elem-array by elem-number instead of elem[index]... */
137 extern Summen    anz[1];
138 extern Edges     *edge;
139 extern Nodes     *node;
140 extern Datasets *lcase;
141 extern Faces     *face;
142 extern NodeBlocks *nBlock;
143 extern BGpicture *bgpicture;
144 
145 extern Meshp meshp;
146 
147 extern Alias     *alias;
148 extern Sets      *set;
149 extern Shapes    *shape;
150 extern Materials *material;
151 extern Psets     *pset;
152 extern Values    *value;
153 extern Points    *point;
154 extern Lines     *line;
155 extern Lcmb      *lcmb;
156 extern Gsur      *surf;
157 extern Gbod      *body;
158 extern Nurbl     *nurbl;
159 extern Nurbs     *nurbs;
160 extern Materials *material;
161 extern Amplitudes *amplitude;
162 extern SumGeo    anzGeo[1];
163 extern SumAsci   sumAsci[1];
164 extern Texts     *ntext;
165 
166 /* nr of graph 2d plot */
167 extern int graph_Nr;
168 extern int graph_on;
169 
170 /* nr of hardcopies */
171 extern int psNr, tgaNr, gifNr, pngNr;
172 
173 
174 extern Eqal eqal;
175 
176 /* additional entities */
177 extern char **valuestack;
178 extern int valuestack_ptr, valuestackFlag;
179 extern OpenSets   openSets[1];
180 extern SpecialSet specialset[1];
181 extern int  set_bsur;
182 
183 
184 Lchar     lchar[1]={{'0','0','D','L','C','A','B','Q','N','A','H'}};      /* first letter in the entity names */
185 
186 extern int  cur_entity;                                       /* aktive entity (component) */
187 extern int  cur_lc;
188 extern void       *glut_font[];  /* glut fonts */
189 extern int       legend_font;                         /* active font for the legend */
190 extern int       draw_font;                         /* active font for the annotation of entities */
191 extern int       menu_font;                         /* active font for the menu */
192 
193 /* the copied node-sets which have to be filled with values from new loaded Datasets */
194 extern CopiedNodeSets copiedNodeSets[1];
195 extern char **parameter;
196 
197 extern sem_t  sem_n;
198 sem_t   sem_map3d;
199 
200 int       nodeCsys=0;                        /*  Number of coordinate systems (nastran)  */
201 int       nodeCsysSet[MAX_MATERIALS];        /*  setNr  */
202 int       nodeCsysNr[MAX_MATERIALS];         /*  csysNr  */
203 
204 /* mpc generation between incompatible element-types for connected bodies */
205 int sum_equSets=0, *depSet=NULL, *indSet=NULL;
206 
207 
208 /* returns node-Index if known, or -(Index+10) of a unused node or if none is unused -1  */
getNodNr(Summen * anz,Nodes * node,int nodnr)209 int getNodNr(Summen *anz, Nodes *node, int nodnr )
210 {
211   //int pfree;
212   //printf("nodnr:%d anz->nmax:%d \n", nodnr,anz->nmax);
213   if(nodnr>anz->nmax) return(-1);
214   //printf("nodindx:%d anz->n:%d \n", node[nodnr].indx,anz->n);
215   if(node[nodnr].indx<0) return(-1);
216   if(node[nodnr].indx>anz->n) return(-1);
217 
218   if( node[node[nodnr].indx].nr == nodnr )
219   {
220     /* unused node ?  */
221     //if( node[nodnr].pflag == -1) return(pfree=-node[nodnr].indx-10);
222     if( node[nodnr].pflag == -1) return(-node[nodnr].indx-10);
223     else return(node[nodnr].indx);
224   }
225   return(-1);
226 }
227 
228 
229 
230 /* returns alias-Index if known, or if not -1  */
getAliasNr(char * name)231 int getAliasNr(char *name)
232 {
233   int i, n, length, pfree, sum;
234 
235   if(!anzGeo->alias) return(-1);
236 
237   i=length=sum=0;
238   pfree=-1;
239 
240   while(name[length]!='\0') { sum+=name[length++]*(++i); }
241   if(!length) return(-1);
242 
243   if(sum<0)
244   {
245     printf ("ERROR: Illegal name:|%s| sum-ascii:%d\n", name, sum);
246     strcpy(name,"0000");
247     return(-1);
248   }
249   if(sum<=sumAsci->max_suma)
250   {
251    for (i=0; i<sumAsci->anza[sum]; i++)
252    {
253     if(( alias[sumAsci->aindx[sum][i]].name != (char *)NULL ) && (strlen(alias[sumAsci->aindx[sum][i]].name) == length))
254     {
255       n=length-1;
256       while(alias[sumAsci->aindx[sum][i]].name[n]==name[n])
257       {
258         if(!n--)
259         {
260           return(sumAsci->aindx[sum][i]);
261 	}
262       }
263       /*
264       printf(" name:%s nam:%s indx:%d\n"
265       , name, alias[sumAsci->pindx[sum][i]].name, sumAsci->aindx[sum][i]);
266       */
267     }
268    }
269   }
270   else
271   {
272     if(printFlag) printf(" WARNING alias:%s not found in hash-table\n", name);
273      for (i=0; i<anzGeo->alias; i++) if( alias[i].name != (char *)NULL )
274       if((compare( alias[i].name, name, length)==length) && (sword( alias[i].name, buffer)==length))
275         return(i);
276   }
277   return(pfree);
278 }
279 
280 
281 /* returns value-Index if known, or -(Index+10) of a deleted value or if none is deleted -1  */
getValuNr(char * name)282 int getValuNr(char *name)
283 {
284   int i, n, length, pfree, sum;
285 
286   if(!anz->v) return(-1);
287 
288   i=length=sum=0;
289   pfree=-1;
290 
291   while(name[length]!='\0') { sum+=name[length++]*(++i); }
292   if(!length) return(-1);
293 
294   if(sum<0)
295   {
296     printf ("ERROR: Illegal value name:|%s| sum-ascii:%d\n", name, sum);
297     strcpy(name,"0000");
298     return(-1);
299   }
300   if(sum<=sumAsci->max_sumv)
301   {
302    for (i=0; i<sumAsci->anzv[sum]; i++)
303    {
304     if(( value[sumAsci->vindx[sum][i]].name != (char *)NULL ) && (strlen(value[sumAsci->vindx[sum][i]].name) == length))
305     {
306       n=length-1;
307       while(value[sumAsci->vindx[sum][i]].name[n]==name[n])
308       {
309         if(!n--)
310         {
311           return(sumAsci->vindx[sum][i]);
312 	}
313       }
314       /*
315       printf(" name:%s nam:%s indx:%d\n"
316       , name, value[sumAsci->vindx[sum][i]].name, sumAsci->vindx[sum][i]);
317       */
318     }
319    }
320   }
321   else
322   {
323     if(printFlag) printf(" WARNING value:%s not found in hash-table\n", name);
324     for (i=0; i<anz->v; i++) if( value[i].name != (char *)NULL )
325       if((compare( value[i].name, name, length)==length) && (sword( value[i].name, buffer)==length))
326         return(i);
327   }
328 
329   /* if not found  look for free cells */
330   for (i=0; i<anz->v; i++)
331   {
332     /* do we have a "deleted" point for use?  */
333     if( value[i].name == (char *)NULL )
334     {
335       pfree=-i-10;
336       return(pfree);
337     }
338   }
339   return(pfree);
340 }
341 
342 
343 /* returns pnt-Index if known, or -(Index+10) of a deleted pnt or if none is deleted -1  */
getPntNr(char * name)344 int getPntNr(char *name)
345 {
346   int i, n, length, pfree, sum;
347 
348   if(!anzGeo->p) return(-1);
349   if(name==(char *)NULL) return(-1);
350 
351   i=length=sum=0;
352   pfree=-1;
353 
354   while(name[length]!='\0') { sum+=name[length++]*(++i); }
355   if(!length) return(-1);
356 
357   if(sum<0)
358   {
359     printf ("ERROR: Illegal Point name:|%s| sum-ascii:%d\n", name, sum);
360     strcpy(name,"0000");
361     return(-1);
362   }
363   if(sum<=sumAsci->max_sump)
364   {
365    for (i=0; i<sumAsci->anzp[sum]; i++)
366    {
367     if(( point[sumAsci->pindx[sum][i]].name != (char *)NULL ) && (strlen(point[sumAsci->pindx[sum][i]].name) == length))
368     {
369       n=length-1;
370       while(point[sumAsci->pindx[sum][i]].name[n]==name[n])
371       {
372         if(!n--)
373         {
374           return(sumAsci->pindx[sum][i]);
375 	}
376       }
377       /*
378       printf(" name:%s nam:%s indx:%d\n"
379       , name, point[sumAsci->pindx[sum][i]].name, sumAsci->pindx[sum][i]);
380       */
381     }
382    }
383   }
384   else
385   {
386     if(printFlag) printf(" WARNING point:%s not found in hash-table\n", name);
387     for (i=0; i<anzGeo->p; i++) if( point[i].name != (char *)NULL )
388       if((compare( point[i].name, name, length)==length) && (sword( point[i].name, buffer)==length))
389         return(i);
390   }
391 
392   /* if not found  look for free cells */
393   if (delPntFlag)
394   for (i=0; i<anzGeo->p; i++)
395   {
396     /* do we have a "deleted" point for use?  */
397     if( point[i].name == (char *)NULL )
398     {
399       pfree=-i-10;
400       return(pfree);
401     }
402   }
403   delPntFlag=0; /* only if "deleted" was no more found */
404   return(pfree);
405 }
406 
407 
408 /* returns shape-Index if known, or -(Index+10) of a deleted shape or if none is deleted -1  */
getShapeNr(char * name)409 int getShapeNr(char *name)
410 {
411   int  i, n, length, pfree, sum;
412 
413   if(!anzGeo->sh) return(-1);
414 
415   i=length=sum=0;
416   pfree=-1;
417 
418   while(name[length]!='\0') { sum+=name[length++]*(++i); }
419   if(!length) return(-1);
420 
421   /*
422   printf ("in getShapeNr anzsh[%d]: %d\n", sum, sumAsci->anzsh[sum]);
423   */
424   if(sum<0)
425   {
426     printf ("ERROR: Illegal shape name:|%s| sum-ascii:%d\n", name, sum);
427     strcpy(name,"0000");
428     return(-1);
429   }
430   if(sum<=sumAsci->max_sumsh)
431   {
432    for (i=0; i<sumAsci->anzsh[sum]; i++)
433    {
434     if(( shape[sumAsci->shindx[sum][i]].name != (char *)NULL ) && (strlen(shape[sumAsci->shindx[sum][i]].name) == length))
435     {
436       n=length-1;
437       while(shape[sumAsci->shindx[sum][i]].name[n]==name[n])
438       {
439         if(!n--)
440         {
441           return(sumAsci->shindx[sum][i]);
442 	}
443       }
444       /*
445       printf(" name:%s nam:%s indx:%d\n"
446       , name, shape[sumAsci->shindx[sum][i]].name, sumAsci->shindx[sum][i]);
447       */
448     }
449    }
450   }
451   else
452   {
453     if(printFlag) printf(" WARNING shape:%s not found in hash-table\n", name);
454     for (i=0; i<anzGeo->sh; i++)
455     {
456       if( shape[i].name != (char *)NULL )
457       {
458         if((compare( shape[i].name, name, length)==length) && (sword( shape[i].name, buffer)==length))
459           return(i);
460       }
461     }
462   }
463 
464   /* if not found look for free cells */
465   if (delShapeFlag)
466   for (i=0; i<anzGeo->sh; i++)
467   {
468     /* do we have a "deleted" shape for use?  */
469     if( shape[i].name == (char *)NULL )
470     {
471       pfree=-i-10;
472       return(pfree);
473     }
474   }
475   delShapeFlag=0;
476   return(pfree);
477 }
478 
479 
480 /* returns line-Index if known, or -(Index+10) of a deleted line or if none is deleted -1  */
getLineNr(char * name)481 int getLineNr(char *name)
482 {
483   int  i, n, length, pfree, sum;
484 
485   if(!anzGeo->l) return(-1);
486 
487   i=length=sum=0;
488   pfree=-1;
489 
490   while(name[length]!='\0') { sum+=name[length++]*(++i); }
491   if(!length) return(-1);
492 
493   /*
494   printf ("in getLineNr anzl[%d]: %d\n", sum, sumAsci->anzl[sum]);
495   */
496   if(sum<0)
497   {
498     printf ("ERROR: Illegal line name:|%s| sum-ascii:%d\n", name, sum);
499     strcpy(name,"0000");
500     return(-1);
501   }
502   if(sum<=sumAsci->max_suml)
503   {
504    for (i=0; i<sumAsci->anzl[sum]; i++)
505    {
506     if(( line[sumAsci->lindx[sum][i]].name != (char *)NULL ) && (strlen(line[sumAsci->lindx[sum][i]].name) == length))
507     {
508       n=length-1;
509       while(line[sumAsci->lindx[sum][i]].name[n]==name[n])
510       {
511         if(!n--)
512         {
513           return(sumAsci->lindx[sum][i]);
514 	}
515       }
516       /*
517       printf(" name:%s nam:%s indx:%d\n"
518       , name, line[sumAsci->lindx[sum][i]].name, sumAsci->lindx[sum][i]);
519       */
520     }
521    }
522   }
523   else
524   {
525     if(printFlag) printf(" WARNING line:%s not found in hash-table\n", name);
526     for (i=0; i<anzGeo->l; i++)
527     {
528       if( line[i].name != (char *)NULL )
529       {
530         if((compare( line[i].name, name, length)==length) && (sword( line[i].name, buffer)==length))
531           return(i);
532       }
533     }
534   }
535 
536   /* if not found look for free cells */
537   if (delLineFlag)
538   for (i=0; i<anzGeo->l; i++)
539   {
540     /* do we have a "deleted" line for use?  */
541     if( line[i].name == (char *)NULL )
542     {
543       pfree=-i-10;
544       return(pfree);
545     }
546   }
547   delLineFlag=0;
548   return(pfree);
549 }
550 
551 
552 /* returns line-Index if known, or -(Index+10) of a deleted line or if none is deleted -1  */
getLcmbNr(char * name)553 int getLcmbNr(char *name)
554 {
555   int  i, n, length, pfree, sum;
556 
557   if(!anzGeo->c) return(-1);
558 
559   i=length=sum=0;
560   pfree=-1;
561 
562   while(name[length]!='\0') { sum+=name[length++]*(++i); }
563   if(!length) return(-1);
564 
565   /* printf ("in getLcmbNr sum:%d max_sumc:%d anzGeo->c:%d\n", sum, sumAsci->max_sumc, anzGeo->c); */
566 
567   if(sum<0)
568   {
569     printf ("ERROR: Illegal Lcmb name:|%s| sum-ascii:%d\n", name, sum);
570     strcpy(name,"0000");
571     return(-1);
572   }
573   if(sum<=sumAsci->max_sumc)
574   {
575    /* printf ("in getLcmbNr anzc[%d]:%d \n", sum, sumAsci->anzc[sum]); */
576    for (i=0; i<sumAsci->anzc[sum]; i++)
577    {
578     if(( lcmb[sumAsci->cindx[sum][i]].name != (char *)NULL ) && (strlen(lcmb[sumAsci->cindx[sum][i]].name) == length))
579     {
580       n=length-1;
581       while(lcmb[sumAsci->cindx[sum][i]].name[n]==name[n])
582       {
583         if(!n--)
584         {
585           return(sumAsci->cindx[sum][i]);
586 	}
587       }
588       /*
589       printf(" name:%s nam:%s indx:%d\n"
590       , name, lcmb[sumAsci->cindx[sum][i]].name, sumAsci->cindx[sum][i]);
591       */
592     }
593    }
594   }
595   else
596   {
597     if(printFlag) printf(" WARNING lcmb:%s not found in hash-table\n", name);
598     for (i=0; i<anzGeo->c; i++) if( lcmb[i].name != (char *)NULL )
599       if((compare( lcmb[i].name, name, length)==length) && (sword( lcmb[i].name, buffer)==length))
600         return(i);
601   }
602 
603   /* if not found look for free cells */
604   if (delLcmbFlag)
605   for (i=0; i<anzGeo->c; i++)
606   {
607     /* do we have a "deleted" lcmb for use?  */
608     if(( lcmb[i].name == (char *)NULL )&& ( lcmb[i].o == NULL )&& ( lcmb[i].l == NULL ))
609     {
610       pfree=-i-10;
611       return(pfree);
612     }
613   }
614   delLcmbFlag=0;
615   return(pfree);
616 }
617 
618 
619 /* returns surf-Index if known, or -(Index+10) of a deleted surf or if none is deleted -1  */
getSurfNr(char * name)620 int getSurfNr(char *name)
621 {
622   int  i, n, length, pfree, sum;
623 
624   if(!anzGeo->s) return(-1);
625 
626   i=length=sum=0;
627   pfree=-1;
628 
629   while(name[length]!='\0') { sum+=name[length++]*(++i); }
630   if(!length) return(-1);
631   /*
632   printf ("in getSurfNr anzs[%d]: %d\n", sum, sumAsci->anzs[sum]);
633   */
634   if(sum<0)
635   {
636     printf ("ERROR: Illegal Surf name:|%s| sum-ascii:%d\n", name, sum);
637     strcpy(name,"0000");
638     return(-1);
639   }
640   if(sum<=sumAsci->max_sums)
641   {
642    for (i=0; i<sumAsci->anzs[sum]; i++)
643    {
644     if(( surf[sumAsci->sindx[sum][i]].name != (char *)NULL ) && (strlen(surf[sumAsci->sindx[sum][i]].name) == length))
645     {
646       n=length-1;
647       while(surf[sumAsci->sindx[sum][i]].name[n]==name[n])
648       {
649         if(!n--)
650         {
651           return(sumAsci->sindx[sum][i]);
652 	}
653       }
654       /*
655       printf(" name:%s nam:%s indx:%d\n"
656       , name, surf[sumAsci->sindx[sum][i]].name, sumAsci->sindx[sum][i]);
657       */
658     }
659    }
660   }
661   else
662   {
663     if(printFlag) printf(" WARNING surf:%s not found in hash-table\n", name);
664     for (i=0; i<anzGeo->s; i++) if( surf[i].name != (char *)NULL )
665     {
666       if((compare( surf[i].name, name, length)==length) && (sword( surf[i].name, buffer)==length)) return(i);
667     }
668   }
669 
670   /* if not found look for free cells */
671   if (delSurfFlag)
672   for (i=0; i<anzGeo->s; i++)
673   {
674     /* do we have a "deleted" surf for use?  */
675     if( surf[i].name == (char *)NULL )
676     {
677       pfree=-i-10;
678       return(pfree);
679     }
680   }
681   delSurfFlag=0;
682   return(pfree);
683 }
684 
685 /* returns body-Index if known, or -(Index+10) of a deleted body or if none is deleted -1  */
getBodyNr(char * name)686 int getBodyNr(char *name)
687 {
688   int  i, n, length, pfree, sum;
689 
690   if(!anzGeo->b) return(-1);
691 
692   i=length=sum=0;
693   pfree=-1;
694 
695   while(name[length]!='\0') { sum+=name[length++]*(++i); }
696   if(!length) return(-1);
697   /*
698   printf ("in getBodyNr anzb[%d]: %d\n", sum, sumAsci->anzb[sum]);
699   */
700   if(sum<0)
701   {
702     printf ("ERROR: Illegal Body name:|%s| sum-ascii:%d\n", name, sum);
703     strcpy(name,"0000");
704     return(-1);
705   }
706   if(sum<=sumAsci->max_sumb)
707   {
708    for (i=0; i<sumAsci->anzb[sum]; i++)
709    {
710     if(( body[sumAsci->bindx[sum][i]].name != (char *)NULL ) && (strlen(body[sumAsci->bindx[sum][i]].name) == length))
711     {
712       n=length-1;
713       while(body[sumAsci->bindx[sum][i]].name[n]==name[n])
714       {
715         if(!n--)
716         {
717           return(sumAsci->bindx[sum][i]);
718 	}
719       }
720       /*
721       printf(" name:%s nam:%s indx:%d\n"
722       , name, body[sumAsci->bindx[sum][i]].name, sumAsci->bindx[sum][i]);
723       */
724     }
725    }
726   }
727   else
728   {
729     if(printFlag) printf(" WARNING body:%s not found in hash-table\n", name);
730     for (i=0; i<anzGeo->b; i++) if( body[i].name != (char *)NULL )
731       if((compare( body[i].name, name, length)==length) && (sword( body[i].name, buffer)==length))
732         return(i);
733   }
734 
735   /* if not found check all and look for free cells */
736   /* check all is not active, should not be necessary */
737   if (delBodyFlag)
738   for (i=0; i<anzGeo->b; i++)
739   {
740     /* do we have a "deleted" body for use?  */
741     if( body[i].name == (char *)NULL )
742     {
743       pfree=-i-10;
744       return(pfree);
745     }
746   }
747   delBodyFlag=0;
748   return(pfree);
749 }
750 
751 
752 /* returns Nurs-Index if known, or -(Index+10) of a deleted body or if none is deleted -1  */
getNursNr(char * name)753 int getNursNr(char *name)
754 {
755   int  i, n, length, pfree, sum;
756 
757   if(!anzGeo->nurs) return(-1);
758   if(compareStrings(name, "BLEND")>0) return(-1);
759 
760   i=length=sum=0;
761   pfree=-1;
762 
763   while(name[length]!='\0') {  sum+=name[length++]*(++i); }
764   if(!length) return(-1);
765 
766   if(sum<0)
767   {
768     printf ("ERROR: Illegal Nurs name:|%s| sum-ascii:%d\n", name, sum);
769     strcpy(name,"0000");
770     return(-1);
771   }
772 
773   if(sum<=sumAsci->max_sumS)
774   {
775    for (i=0; i<sumAsci->anzS[sum]; i++)
776    {
777     if(( nurbs[sumAsci->Sindx[sum][i]].name != (char *)NULL ) && (strlen(nurbs[sumAsci->Sindx[sum][i]].name) == length))
778     {
779       n=length-1;
780       while(nurbs[sumAsci->Sindx[sum][i]].name[n]==name[n])
781       {
782         if(!n--)
783         {
784           return(sumAsci->Sindx[sum][i]);
785 	}
786       }
787       //printf(" name:%s nam:%s indx:%d\n", name, nurbs[sumAsci->Sindx[sum][i]].name, sumAsci->Sindx[sum][i]);
788     }
789    }
790   }
791   else
792   {
793    if(printFlag)
794      printf("WARNING NURS:%s not found in hash-table\n", name);
795    for (i=0; i<anzGeo->nurs; i++)
796    {
797      // printf(" nurbsname:%d %d\n", i, nurbs[i].name);
798     if( nurbs[i].name != (char *)NULL )
799     {
800       //printf("nurs:%s length:%d name:%s length:%d\n", nurbs[i].name, strlen(nurbs[i].name), name, length);
801       if((compare( nurbs[i].name, name, length)==length) && (sword( nurbs[i].name, buffer)==length))
802         return(i);
803     }
804    }
805   }
806 
807   /* if not found check all and look for free cells */
808   /* check all is not active, should not be necessary */
809   if (delNursFlag)
810   for (i=0; i<anzGeo->nurs; i++)
811   {
812     /* do we have a "deleted" nurbs for use?  */
813     if( nurbs[i].name == (char *)NULL )
814     {
815       pfree=-i-10;
816       return(pfree);
817     }
818   }
819   delNursFlag=0;
820   return(pfree);
821 }
822 
823 /* returns nurl-Index if known, or -(Index+10) of a deleted nurl or if none is deleted -1  */
getNurlNr(char * name)824 int getNurlNr(char *name)
825 {
826   int i, length, pfree;
827 
828   if(!anzGeo->nurl) return(-1);
829 
830   i=0;
831   pfree=-1;
832   length=sword( name, buffer );
833   if(!length) return(-1);
834 
835   for (i=0; i<anzGeo->nurl; i++)
836   {
837     if( nurbl[i].name != (char *)NULL )
838     {
839       if( ( compare( nurbl[i].name, name, length)==length) && ( sword( nurbl[i].name, buffer)==length) )
840         return(i);
841       if( nurbl[i].name == (char *)NULL )
842         pfree=-i-10;
843     }
844   }
845   return(pfree);
846 }
847 
848 
849 
850 /* returns set-Index if known, or -(Index+10) of a deleted set or if none is deleted -1  */
getSetNr(char * name)851 int getSetNr(char *name)
852 {
853   int  i, n, length, pfree, sum;
854 
855   if(!anz->sets) return(-1);
856   if(name== (char *)NULL) return(-1);
857 
858   i=length=sum=0;
859   pfree=-1;
860 
861   while((name[length]!='\0')&&(length<MAX_LINE_LENGTH)) { sum+=name[length++]*(++i); }
862   if(!length) return(-1);
863 
864   if(sum<0)
865   {
866     printf ("ERROR: Illegal Set name:|%s| sum-ascii:%d\n", name, sum);
867     strcpy(name,"0000");
868     return(-1);
869   }
870   if(sum<=sumAsci->max_sumse)
871   {
872    for (i=0; i<sumAsci->anzse[sum]; i++)
873    {
874     if(( set[sumAsci->seindx[sum][i]].name != (char *)NULL ) && (strlen(set[sumAsci->seindx[sum][i]].name) == length))
875     {
876       n=length-1;
877       while(set[sumAsci->seindx[sum][i]].name[n]==name[n])
878       {
879         if(!n--)
880         {
881           return(sumAsci->seindx[sum][i]);
882 	}
883       }
884       /*
885       printf(" name:%s nam:%s indx:%d\n"
886       , name, set[sumAsci->seindx[sum][i]].name, sumAsci->seindx[sum][i]);
887       */
888     }
889    }
890   }
891 
892   if(printFlag) printf(" WARNING set:%s not found in hash-table\n", name);
893   for (i=0; i<anz->sets; i++)
894   {
895     if (set[i].name!= (char *)NULL)
896     {
897       if ((compare( set[i].name, name, length)==length) && (sword( set[i].name, buffer)==length))
898         return(i);
899     }
900   }
901 
902   /* set not found, check if the name could be an set-index */
903   if (checkIfNumber(name)>0)
904   {
905     /* the user has specified the set-index */
906     n=atoi(name);
907     if(n<=anz->sets)
908     {
909       for (i=0; i<anz->sets; i++) if(set[i].index==n)
910       {
911         printf (" index %s points to %s\n", name, set[i].name);
912         return (i);
913       }
914     }
915   }
916 
917   /* if not found check all and look for free cells */
918   /* check all is not active, should not be necessary */
919   if (delSetFlag)
920   for (i=0; i<anz->sets; i++)
921   {
922     /* do we have a "deleted" set for use?  */
923     if( set[i].name == (char *)NULL )
924     {
925       pfree=-i-10;
926       return(pfree);
927     }
928   }
929   delSetFlag=0;
930   return(pfree);
931 }
932 
933 
934 
935 
936 /* search an element in an sorted integer-array */
937 /* return -1 if not found or index if found */
getIndex(int ** ipnt,int n,int x0)938 int getIndex(int **ipnt, int n, int x0 )
939 {
940   int i=0,ii,m,n1,n2;
941   int *x;
942 
943   x=*ipnt;
944   /* if x0 is lower than the first elem */
945   if((n==0)||(x0<x[0])) return(-1);
946 
947   /* if x0 is higher than the last elem */
948   else if(x0>x[n-1]) return(-1);
949 
950   else
951   {
952     /* search the intersection */
953     n1=0;
954     n2=n;
955     for(ii=0; ii<n; ii++)
956     {
957       m=(n2+n1)/2;
958       if(x0>= x[m] ) n1=m;
959       if(x0 < x[m] ) n2=m;
960       if((n2-n1) == 1) break;
961     }
962     i=n1;
963 #if TEST
964     printf("i:%d x:%d x0:%d x++:%d\n", i,x[i],x0,x[i+1]);
965 #endif
966 
967     if (x0!=x[i])
968     {
969       /* element not found */
970       return(-1);
971     }
972   }
973 
974 #if TEST
975   for(ii=0; ii<n; ii++)
976   {
977     printf("i:%d x:%d \n", ii,x[ii]);
978   }
979 #endif
980 
981 #if TEST
982   printf("b:%d\n", *(*ipnt));
983 #endif
984   return(n);
985 }
986 
987 
988 
delSet(char * setname)989 void delSet( char *setname)
990 {
991   int i, j;
992   int   setNr;
993 
994   setNr=getSetNr(setname);
995   if (setNr<0)
996   {
997     if(printFlag) printf (" delSet: set:%s does not exist\n", setname);
998     return;
999   }
1000   /* suche abhaengige entities */
1001   if( set[setNr].type )
1002   {
1003     /* durchsuche alle linien   */
1004     for(i=0; i<anzGeo->l; i++)
1005     {
1006       if (( line[i].name != (char *)NULL)&&(line[i].typ=='s')&&(setNr==line[i].trk))
1007       {
1008         printf (" ERROR: trk removed, Line will be straight\n");
1009         line[i].trk=-1;
1010         line[i].typ=' ';
1011       }
1012     }
1013   }
1014   /* durchsuche alle uebrigen sets und entferne den set  */
1015   for(i=0; i<anz->sets; i++)
1016   {
1017     if((set[i].name!=(char *)NULL)&&(set[i].name[0]!='-')&&( getIndex(&set[i].set,set[i].anz_se, setNr) >-1))
1018     {
1019       setr( i, "r", setNr);
1020     }
1021   }
1022   /* durchsuche alle psets und entferne den set   */
1023   j=0; for(i=0; i<anzGeo->psets; i++)
1024   {
1025     if (setNr!=pset[i].nr)
1026     {
1027       if(i!=j) {
1028         pset[j].nr=pset[i].nr;
1029         strcpy(pset[j].type,pset[i].type);
1030         pset[j].col=pset[i].col;
1031       }
1032       j++;
1033     }
1034   }
1035   anzGeo->psets=j;
1036 
1037   /* der set wird wieder frei gegeben */
1038   delSetFlag=1;
1039   if(set[setNr].anz_elf)
1040     for(i=0; i<set[setNr].anz_elf; i++)
1041       if(set[setNr].elf[i].n) free(set[setNr].elf[i].v);
1042     free(set[setNr].name);
1043     free(set[setNr].valu);
1044     free(set[setNr].node);
1045     free(set[setNr].elem);
1046     free(set[setNr].face);
1047     free(set[setNr].elf);
1048     free(set[setNr].pnt);
1049     free(set[setNr].line);
1050     free(set[setNr].lcmb);
1051     free(set[setNr].surf);
1052     free(set[setNr].body);
1053     free(set[setNr].nurl);
1054     free(set[setNr].nurs);
1055     free(set[setNr].set);
1056     free(set[setNr].shp);
1057     free(set[setNr].eparm);
1058     set[setNr].name=(char *)NULL;
1059     set[setNr].valu=(int *)NULL;
1060     set[setNr].node=(int *)NULL;
1061     set[setNr].elem=(int *)NULL;
1062     set[setNr].face=(int *)NULL;
1063     set[setNr].elf=(Elfaces *)NULL;
1064     set[setNr].pnt= (int *)NULL;
1065     set[setNr].line=(int *)NULL;
1066     set[setNr].lcmb=(int *)NULL;
1067     set[setNr].surf=(int *)NULL;
1068     set[setNr].body=(int *)NULL;
1069     set[setNr].nurl=(int *)NULL;
1070     set[setNr].nurs=(int *)NULL;
1071     set[setNr].set=(int *)NULL;
1072     set[setNr].shp=(int *)NULL;
1073     set[setNr].eparm=(char *)NULL;
1074     set[setNr].material = -1;
1075     set[setNr].flag = 'c';
1076     set[setNr].type = 0;
1077     set[setNr].anz_v = 0;
1078     set[setNr].anz_n = 0;
1079     set[setNr].anz_e = 0;
1080     set[setNr].anz_f = 0;
1081     set[setNr].anz_elf = 0;
1082     set[setNr].anz_p = 0;
1083     set[setNr].anz_l = 0;
1084     set[setNr].anz_c = 0;
1085     set[setNr].anz_s = 0;
1086     set[setNr].anz_b = 0;
1087     set[setNr].anz_nurl = 0;
1088     set[setNr].anz_nurs = 0;
1089     set[setNr].anz_se = 0;
1090     set[setNr].anz_sh = 0;
1091 }
1092 
1093 /*------------------------------------------------------------------*/
1094 /* einen set als offen markieren                                    */
1095 /*------------------------------------------------------------------*/
1096 
seto(char * setname)1097 int seto( char *setname )
1098 {
1099   int   i,setNr;
1100 
1101   operateAlias( setname, "se" );
1102 
1103   setNr=getSetNr(setname);
1104 
1105   if (strlen(setname)<=0)
1106   {
1107     /* list all open sets */
1108     for (i=0; i<anz->sets; i++)
1109     {
1110       if( set[i].name != (char *)NULL )
1111       {
1112         if ((!set[i].type)&&(set[i].flag=='o'))
1113           printf ("%s stat:%c n:%d e:%d f:%d p:%d l:%d c:%d s:%d b:%d L:%d S:%d se:%d sh:%d\n", set[i].name, set[i].flag, set[i].anz_n, set[i].anz_e, set[i].anz_f, set[i].anz_p, set[i].anz_l, set[i].anz_c, set[i].anz_s, set[i].anz_b, set[i].anz_nurl, set[i].anz_nurs, set[i].anz_se, set[i].anz_sh);
1114       }
1115     }
1116     return(-1);
1117   }
1118 
1119   if (setNr==-1)       /* open a new set */
1120   {
1121     if ((set = (Sets *)realloc( (Sets *)set, (anz->sets+1)*sizeof(Sets)) ) == NULL )
1122     {
1123       printf(" ERROR: realloc failure in seto, set:%s not installed\n\n", setname);
1124       return(-1);
1125     }
1126     setNr= anz->sets;
1127     anz->sets++;
1128 
1129     i=strlen(setname);
1130     if((set[setNr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1131     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1132     strcpy( set[setNr].name, setname);
1133     hashSet( sumAsci, setname, setNr );
1134     if(printFlag) printf (" create and open set:%s\n", set[setNr].name);
1135     set[setNr].flag='o';
1136     set[setNr].type=0;
1137     set[setNr].etyp=0;
1138     set[setNr].eattr=0;
1139     set[setNr].eseq=0;
1140     if((set[setNr].valu= (int *)malloc(sizeof(int))) == NULL )
1141     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1142     if((set[setNr].node= (int *)malloc(sizeof(int))) == NULL )
1143     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1144     if((set[setNr].elem= (int *)malloc(sizeof(int))) == NULL )
1145     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1146     if((set[setNr].face= (int *)malloc(sizeof(int))) == NULL )
1147     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1148     if((set[setNr].elf= (Elfaces *)malloc(sizeof(Elfaces))) == NULL )
1149     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1150     if((set[setNr].pnt= (int *)malloc(sizeof(int))) == NULL )
1151     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1152     if((set[setNr].line= (int *)malloc(sizeof(int))) == NULL )
1153     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1154     if((set[setNr].lcmb= (int *)malloc(sizeof(int))) == NULL )
1155     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1156     if((set[setNr].surf= (int *)malloc(sizeof(int))) == NULL )
1157     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1158     if((set[setNr].body= (int *)malloc(sizeof(int))) == NULL )
1159     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1160     if((set[setNr].nurl= (int *)malloc(sizeof(int))) == NULL )
1161     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1162     if((set[setNr].nurs= (int *)malloc(sizeof(int))) == NULL )
1163     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1164     if((set[setNr].set= (int *)malloc(sizeof(int))) == NULL )
1165     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1166     if((set[setNr].shp= (int *)malloc(sizeof(int))) == NULL )
1167     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1168     set[setNr].index = -1;
1169     set[setNr].material = -1;
1170     set[setNr].anz_v = 0;
1171     set[setNr].anz_n = 0;
1172     set[setNr].anz_e = 0;
1173     set[setNr].anz_f = 0;
1174     set[setNr].anz_elf = 0;
1175     set[setNr].anz_p = 0;
1176     set[setNr].anz_l = 0;
1177     set[setNr].anz_c = 0;
1178     set[setNr].anz_s = 0;
1179     set[setNr].anz_b = 0;
1180     set[setNr].anz_nurl = 0;
1181     set[setNr].anz_nurs = 0;
1182     set[setNr].anz_se = 0;
1183     set[setNr].anz_sh = 0;
1184     set[setNr].eparm=(char *)NULL;
1185   }
1186   else if (setNr<-1)    /* replace a deleted set */
1187   {
1188     setNr=-(setNr+10);
1189     i=strlen(setname);
1190     if((set[setNr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1191     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1192     strcpy( set[setNr].name, setname);
1193     hashSet( sumAsci, setname, setNr );
1194     set[setNr].flag='o';
1195     set[setNr].type=0;
1196     if(printFlag) printf (" open set:%s\n", set[setNr].name);
1197   }
1198   else
1199   {
1200     if (set[setNr].flag=='o')
1201     {
1202       printf (" set:%s is already open\n", set[setNr].name);
1203       return(setNr);
1204     }
1205     else
1206     {
1207       if(printFlag) printf (" open set:%s\n", set[setNr].name);
1208       set[setNr].flag='o';
1209     }
1210   }
1211 
1212   /* add the set to openSets */
1213   openSets->nr++;
1214   if( (openSets->set = (int *)realloc( (int *)openSets->set, openSets->nr*sizeof(int))) == NULL )
1215   { printf(" ERROR: realloc failed in seto\n\n"); return(-1); }
1216   openSets->set[ openSets->nr-1 ] = setNr;
1217   if(printFlag) printf("seto: openSets->nr:%d openSets->set:%d set:%s\n", openSets->nr, openSets->set[openSets->nr-1],set[setNr].name);
1218   return(setNr);
1219 }
1220 
1221 
1222 /*------------------------------------------------------------------*/
1223 /* einen set schliessen                                             */
1224 /*------------------------------------------------------------------*/
1225 
setc(char * setname)1226 void setc( char *setname )
1227 {
1228   int   setNr, i, n, flag=0;
1229   int *puf=NULL;
1230 
1231   operateAlias( setname, "se" );
1232   if (strlen(setname)>0) setNr=getSetNr(setname);
1233   else if(openSets->nr>0) setNr=openSets->set[openSets->nr-1];
1234   else { printf("no open set\n"); return; }
1235 
1236   if (setNr<0)
1237   {
1238     printf (" setc: set:%s does not exist\n", setname);
1239     return;
1240   }
1241   else
1242   {
1243     if (set[setNr].flag=='c')
1244     {
1245       printf (" set:%s is already closed\n", set[setNr].name);
1246     }
1247     else
1248     {
1249       if(printFlag) printf (" close set:%s\n", set[setNr].name);
1250       set[setNr].flag='c';
1251 
1252       /* remove the set from openSets */
1253       /* puffer allocieren  */
1254       if ( (puf = (int *)malloc( (openSets->nr+1)*sizeof(int))) == NULL )
1255       printf(" ERROR: malloc failed in setc\n\n");
1256 
1257       n=0;
1258       for ( i=0; i<openSets->nr; i++)
1259       {
1260         if ( openSets->set[i]!=setNr )
1261         {
1262           puf[n] = openSets->set[i];
1263           n++;
1264         }
1265         else
1266           flag=1;
1267       }
1268 
1269       if (flag)
1270       {
1271         openSets->nr--;
1272         if ((openSets->set = (int *)realloc( (int *)openSets->set, (openSets->nr+1)*sizeof(int)) ) == NULL)
1273         { printf(" ERROR: realloc failed in setc\n\n"); free(puf); return; }
1274 
1275         for ( i=0; i<openSets->nr; i++)
1276         {
1277           openSets->set[i] = puf[i];
1278         }
1279       }
1280       free(puf);
1281       if(printFlag) printf("setc: openSets->nr:%d openSets->set:%d set:%s\n", openSets->nr, setNr, set[setNr].name);
1282     }
1283   }
1284 }
1285 
1286 
1287 /*------------------------------------------------------------------*/
1288 /* entity einem Set zuordnen                                        */
1289 /*------------------------------------------------------------------*/
1290 
1291 
hashSet(SumAsci * sumAsci,char * name,int nr)1292 int hashSet( SumAsci *sumAsci, char *name, int nr)
1293 {
1294   int i=0,j=0, n;
1295   int sum=0;
1296 
1297   while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
1298 
1299   /* check if sum is higher as the allocated value */
1300   /* if not look for a free entry */
1301   if(sum>sumAsci->max_sumse)
1302   {
1303     if ((sumAsci->anzse=(int *)realloc( (int *)sumAsci->anzse, (sum+1)*sizeof(int)) ) == NULL )
1304     { printf("\n\nERROR: realloc failure in hashSet(), set:%s not included\n\n", name); return(-1); }
1305     if ((sumAsci->seindx=(int **)realloc( (int **)sumAsci->seindx, (sum+1)*sizeof(int *)) ) == NULL )
1306     { printf("\n\nERROR: realloc failure in hashSet(), set:%s not included\n\n", name); return(-1); }
1307     for(i=sumAsci->max_sumse+1; i<=sum; i++) { sumAsci->anzse[i]=0; sumAsci->seindx[i]=NULL; }
1308     sumAsci->max_sumse=sum;
1309   }
1310   else
1311   {
1312     if (delSetFlag)
1313     for (i=0; i<sumAsci->anzse[sum]; i++)
1314     {
1315       n=sumAsci->seindx[sum][i];
1316       if( set[n].name == (char *)NULL )
1317       {
1318         /* already existing space to fill */
1319         sumAsci->seindx[sum][i]=nr;
1320         return(sum);
1321       }
1322     }
1323   }
1324 
1325   /* alloc of a new entry in the hash table */
1326   if ((sumAsci->seindx[sum] =(int *)realloc( (int *)sumAsci->seindx[sum], (sumAsci->anzse[sum]+1)*sizeof(int)) ) == NULL )
1327   { printf("\n\nERROR: realloc failure in hashSet(), set:%s not included\n\n", name); return(-1); }
1328 
1329   sumAsci->seindx[sum][sumAsci->anzse[sum]] = nr;
1330   sumAsci->anzse[sum]++;
1331   return(sum);
1332 }
1333 
1334 
1335 
pre_seta(char * string,char * type,char * name)1336 int pre_seta( char *string, char *type, char *name)
1337 {
1338   int i, setNr;
1339   int n=0;
1340   int number;
1341   char setname[MAX_LINE_LENGTH]; /* string is not changeable. Therefore a new char is necessary */
1342 
1343   /* remove blanks and other illegal chars*/
1344   for(i=0;i<strlen(string); i++) if(string[i]>(char)0x20) { setname[n]=string[i]; n++; }
1345   if(!n) return(-1);
1346   setname[n]='\0';
1347 
1348   operateAlias( setname, "se" );
1349   setNr=getSetNr(setname);
1350   number=0;
1351 
1352   if (setNr==-1)
1353   {
1354     if ((set = (Sets *)realloc( (Sets *)set, (anz->sets+2)*sizeof(Sets)) ) == NULL )
1355     {
1356       printf(" ERROR: realloc failure in pre_seta, set:%s not installed\n\n", setname);
1357       return(-1);
1358     }
1359     setNr= anz->sets;
1360     anz->sets++;
1361 
1362     i=strlen(setname);
1363     if((set[setNr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1364     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1365     strcpy( set[setNr].name, setname);
1366     hashSet( sumAsci, setname, setNr );
1367     if(printFlag) printf (" create set:%s\n", set[setNr].name);
1368     set[setNr].flag='c';
1369     if ( type[1] == 's' ) set[setNr].type=1;
1370     else                  set[setNr].type=0;
1371     set[setNr].etyp=0;
1372     set[setNr].eattr=0;
1373     set[setNr].eseq=0;
1374     if((set[setNr].valu= (int *)malloc(sizeof(int))) == NULL )
1375     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1376     if((set[setNr].node= (int *)malloc(sizeof(int))) == NULL )
1377     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1378     if((set[setNr].elem= (int *)malloc(sizeof(int))) == NULL )
1379     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1380     if((set[setNr].face= (int *)malloc(sizeof(int))) == NULL )
1381     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1382     if((set[setNr].elf= (Elfaces *)malloc(sizeof(Elfaces))) == NULL )
1383     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1384     if((set[setNr].pnt= (int *)malloc(sizeof(int))) == NULL )
1385     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1386     if((set[setNr].line= (int *)malloc(sizeof(int))) == NULL )
1387     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1388     if((set[setNr].lcmb= (int *)malloc(sizeof(int))) == NULL )
1389     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1390     if((set[setNr].surf= (int *)malloc(sizeof(int))) == NULL )
1391     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1392     if((set[setNr].body= (int *)malloc(sizeof(int))) == NULL )
1393     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1394     if((set[setNr].nurl= (int *)malloc(sizeof(int))) == NULL )
1395     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1396     if((set[setNr].nurs= (int *)malloc(sizeof(int))) == NULL )
1397     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1398     if((set[setNr].set= (int *)malloc(sizeof(int))) == NULL )
1399     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1400     if((set[setNr].shp= (int *)malloc(sizeof(int))) == NULL )
1401     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1402     set[setNr].index = -1;
1403     set[setNr].material = -1;
1404     set[setNr].anz_v = 0;
1405     set[setNr].anz_n = 0;
1406     set[setNr].anz_e = 0;
1407     set[setNr].anz_f = 0;
1408     set[setNr].anz_elf = 0;
1409     set[setNr].anz_p = 0;
1410     set[setNr].anz_l = 0;
1411     set[setNr].anz_c = 0;
1412     set[setNr].anz_s = 0;
1413     set[setNr].anz_b = 0;
1414     set[setNr].anz_nurl = 0;
1415     set[setNr].anz_nurs = 0;
1416     set[setNr].anz_se = 0;
1417     set[setNr].anz_sh = 0;
1418     set[setNr].eparm=(char *)NULL;
1419   }
1420   else if (setNr<-1)    /* replace a deleted set */
1421   {
1422     setNr=-(setNr+10);
1423     i=strlen(setname);
1424     if((set[setNr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1425     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1426     strcpy( set[setNr].name, setname);
1427     if ( type[1] == 's' ) set[setNr].type=1;
1428     else                  set[setNr].type=0;
1429     hashSet( sumAsci, setname, setNr );
1430     if((set[setNr].valu= (int *)malloc(sizeof(int))) == NULL )
1431     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1432     if((set[setNr].node= (int *)malloc(sizeof(int))) == NULL )
1433     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1434     if((set[setNr].elem= (int *)malloc(sizeof(int))) == NULL )
1435     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1436     if((set[setNr].face= (int *)malloc(sizeof(int))) == NULL )
1437     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1438     if((set[setNr].elf= (Elfaces *)malloc(sizeof(Elfaces))) == NULL )
1439     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1440     if((set[setNr].pnt= (int *)malloc(sizeof(int))) == NULL )
1441     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1442     if((set[setNr].line= (int *)malloc(sizeof(int))) == NULL )
1443     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1444     if((set[setNr].lcmb= (int *)malloc(sizeof(int))) == NULL )
1445     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1446     if((set[setNr].surf= (int *)malloc(sizeof(int))) == NULL )
1447     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1448     if((set[setNr].body= (int *)malloc(sizeof(int))) == NULL )
1449     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1450     if((set[setNr].nurl= (int *)malloc(sizeof(int))) == NULL )
1451     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1452     if((set[setNr].nurs= (int *)malloc(sizeof(int))) == NULL )
1453     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1454     if((set[setNr].set= (int *)malloc(sizeof(int))) == NULL )
1455     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1456     if((set[setNr].shp= (int *)malloc(sizeof(int))) == NULL )
1457     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1458     set[setNr].index = -1;
1459     set[setNr].material = -1;
1460     set[setNr].anz_v = 0;
1461     set[setNr].anz_n = 0;
1462     set[setNr].anz_e = 0;
1463     set[setNr].anz_f = 0;
1464     set[setNr].anz_elf = 0;
1465     set[setNr].anz_p = 0;
1466     set[setNr].anz_l = 0;
1467     set[setNr].anz_c = 0;
1468     set[setNr].anz_s = 0;
1469     set[setNr].anz_b = 0;
1470     set[setNr].anz_nurl = 0;
1471     set[setNr].anz_nurs = 0;
1472     set[setNr].anz_se = 0;
1473     set[setNr].anz_sh = 0;
1474     set[setNr].eparm=(char *)NULL;
1475   }
1476 
1477   /* determine the index of the entity */
1478   if (( type[0] == 's' )&&( type[1] == 'e' ))  number=getSetNr(name);
1479   else if (( type[0] == 's' )&&( type[1] == 'h' ))  number=getShapeNr(name);
1480   else if ( type[0] == 'n' )                   if(checkIfNumber(name)) number=atoi(name); else return(-1);
1481   else if ( type[0] == 'e' )                   if(checkIfNumber(name)) number=atoi(name); else return(-1);
1482   else if ( type[0] == 'f' )                   if(checkIfNumber(name)) number=atoi(name); else return(-1);
1483   else if ( type[0] == 'v' )                   number=getValuNr(name);
1484   else if ( type[0] == 'p' )                   number=getPntNr(name);
1485   else if ( type[0] == 'l' )                   number=getLineNr(name);
1486   else if ( type[0] == 'c' )                   number=getLcmbNr(name);
1487   else if ( type[0] == 's' )                   number=getSurfNr(name);
1488   else if ( type[0] == 'b' )                   number=getBodyNr(name);
1489   else if ( type[0] == 'L' )                   number=getNurlNr(name);
1490   else if ( type[0] == 'S' )                   number=getNursNr(name);
1491   else if ( type[0] == 'r' )                   number=getSetNr(name);
1492   else if ( type[0] == 'i' )
1493   {
1494     if(printFlag) printf (" set initialized\n");
1495     return(setNr);
1496   }
1497   else
1498   {
1499     errMsg ("ERROR: in seta type:%s not recognized\n", type);
1500     return(-1);
1501   }
1502   if(number<0)
1503   {
1504     if(printFlag) errMsg ("WARNING: in seta entity:%s not known\n", name);
1505     return(-1);
1506   }
1507 
1508   /* add to the set */
1509   if( seta(setNr, type, number)<0 )
1510   {
1511     errMsg ("ERROR: seta failed\n", name);
1512     return(-1);
1513   }
1514   else
1515     return(setNr);
1516 }
1517 
1518 
1519 
rnam(int setNr,char * new_name)1520 int rnam( int setNr, char *new_name)
1521 {
1522   if(strlen(set[setNr].name)<strlen(new_name))
1523   {
1524     if((set[setNr].name= (char *)realloc((char *)set[setNr].name, (strlen(new_name)+1)*sizeof(char))) == NULL )
1525     { printf("ERROR: malloc failed\n\n" ); return(-1); }
1526   }
1527   strcpy(set[setNr].name, new_name );
1528   hashSet( sumAsci,set[setNr].name, setNr );
1529   return(setNr);
1530 }
1531 
1532 
1533 
seta(int setNr,char * type,int number)1534 int seta( int setNr, char *type, int number)
1535 {
1536   int n,k;
1537   if( set[setNr].name == (char *)NULL )
1538   {
1539     errMsg(" ERROR: setNr:%d is undefined\n", setNr);
1540     return(-1);
1541   }
1542   if( number<0)
1543   {
1544     errMsg(" ERROR in seta: A negative entity-index:%d was used in set %s\n", number,set[setNr].name);
1545     return(-1);
1546   }
1547 
1548   /* check if item is known and if its already member of the set */
1549   if ( type[0] == 'r' )
1550   {
1551     if (number<0)
1552     { if(printFlag) printf(" ERROR in seta: set:%d does not exist\n", number ); return(-1); }
1553     set[setNr].anz_se= iinsert(&set[setNr].set, set[setNr].anz_se, number);
1554     set[number].anz_se= iinsert(&set[number].set, set[number].anz_se, setNr);
1555   }
1556   else if ( type[0] == 'v' )
1557   {
1558     set[setNr].anz_v=iinsert(&set[setNr].valu, set[setNr].anz_v, number);
1559   }
1560   else if (( type[0] == 's' )&&( type[1] == 'e' ))
1561   {
1562     if (number<0)
1563     { if(printFlag) printf(" ERROR in seta: set:%d does not exist\n", number ); return(-1); }
1564     set[setNr].anz_se= iinsert(&set[setNr].set, set[setNr].anz_se, number);
1565   }
1566   else if (( type[0] == 'h' )||(( type[0] == 's' )&&( type[1] == 'h' )))
1567   {
1568     if (number<0)
1569     { if(printFlag) printf(" ERROR in seta: shape:%d in set %s does not exist\n", number,set[setNr].name ); return(-1); }
1570     set[setNr].anz_sh= iinsert(&set[setNr].shp, set[setNr].anz_sh, number);
1571   }
1572   else if ( type[0] == 'n' )
1573   {
1574     if ((number<anz->nmin)|| (number>anz->nmax)||(node[number].indx<0) || (number!=node[node[number].indx].nr)||(node[number].pflag!=0))
1575       {  printf(" ERROR in seta: node:%d does not exist and can not be placed in set %s, min:%d max:%d\n", number,set[setNr].name, anz->nmin, anz->nmax); return(-1); }
1576 
1577     if(set[setNr].type==1) /* seqa */
1578     {
1579       for (n=0; n<set[setNr].anz_n; n++)
1580       {
1581         if( set[setNr].node[n] == number )
1582         { if(printFlag) printf(" ERROR in seta: node already stored in set %s\n",set[setNr].name); return(-1); }
1583       }
1584       set[setNr].anz_n++;
1585       if( (set[setNr].node = (int *)realloc( (int *)set[setNr].node, set[setNr].anz_n*sizeof(int))) == NULL )
1586       { printf(" ERROR: realloc failed in set[%d]:%s\n\n", setNr, set[setNr].name); return(-1); }
1587       else
1588       {
1589         if(printFlag) printf(" set[%d]:%s reallocated and node %d added\n"
1590             , setNr, set[setNr].name, number );
1591       }
1592       set[setNr].node[ (set[setNr].anz_n-1) ] = number;
1593     }
1594     else
1595       set[setNr].anz_n= iinsert(&set[setNr].node, set[setNr].anz_n, number);
1596   }
1597   else if ( type[0] == 'e' )
1598   {
1599     if ((number<anz->emin)|| (number>anz->emax) || (e_enqire[number].type==0))
1600       { printf(" ERROR in seta: set %s, elem:%d does not exist, min:%d max:%d\n", set[setNr].name, number, anz->emin, anz->emax ); return(-1); }
1601     set[setNr].anz_e=iinsert(&set[setNr].elem, set[setNr].anz_e, number);
1602   }
1603   else if ( type[0] == 'f' )
1604   {
1605     set[setNr].anz_f=iinsert(&set[setNr].face, set[setNr].anz_f, number);
1606   }
1607   else if ( type[0] == 'p' )
1608   {
1609     if (number<0)
1610     { if(printFlag) printf(" ERROR in seta: set %s, pntNr:%d does not exist\n", set[setNr].name, number ); return(-1); }
1611 
1612     if(set[setNr].type==1) /* seqa */
1613     {
1614       if (number<0)
1615       { if(printFlag) printf(" ERROR in seta: set %s, pntNr:%d does not exist\n", set[setNr].name, number ); return(-1); }
1616       for (n=0; n<set[setNr].anz_p; n++)
1617       {
1618         if( set[setNr].pnt[n] == number )
1619         { if(printFlag) printf(" ERROR in seta: pnt already stored in set %s\n", set[setNr].name); return(-1); }
1620       }
1621       set[setNr].anz_p++;
1622       if( (set[setNr].pnt = (int *)realloc( (int *)set[setNr].pnt, set[setNr].anz_p*sizeof(int))) == NULL )
1623       { printf(" ERROR: realloc failed in set[%d]:%s\n\n", setNr, set[setNr].name); return(-1); }
1624       else
1625       {
1626         if(printFlag) printf(" set[%d]:%s reallocated and pnt %s added\n"
1627             , setNr, set[setNr].name, point[number].name );
1628       }
1629       set[setNr].pnt[ (set[setNr].anz_p-1) ] = number;
1630     }
1631     else
1632       set[setNr].anz_p=iinsert(&set[setNr].pnt, set[setNr].anz_p, number);
1633 
1634     if (point[number].nn>0)
1635     {
1636       for (k=0; k<point[number].nn; k++)
1637       {
1638         set[setNr].anz_n=iinsert(&set[setNr].node, set[setNr].anz_n, point[number].nod[k] );
1639       }
1640     }
1641   }
1642   else if ( type[0] == 'l' )
1643   {
1644     if (number<0)
1645     { if(printFlag) printf(" lineNr:%d does not exist\n", number ); return(-1); }
1646     set[setNr].anz_l= iinsert(&set[setNr].line, set[setNr].anz_l, number);
1647     if( line[number].nn >0 )
1648     {
1649       for (k=0; k<line[number].nn; k++)
1650       {
1651         set[setNr].anz_n= iinsert(&set[setNr].node, set[setNr].anz_n, line[number].nod[k] );
1652       }
1653     }
1654     if (line[number].ne>0)
1655     {
1656       for (k=0; k<line[number].ne; k++)
1657       {
1658         set[setNr].anz_e=iinsert(&set[setNr].elem, set[setNr].anz_e, line[number].elem[k] );
1659       }
1660     }
1661   }
1662   else if ( type[0] == 'c' )
1663   {
1664     if (number<0)
1665     { if(printFlag) printf(" lcmbNr:%d does not exist\n", number ); return(-1); }
1666     set[setNr].anz_c= iinsert(&set[setNr].lcmb, set[setNr].anz_c, number);
1667   }
1668   else if ( type[0] == 's' )
1669   {
1670     if (number<0)
1671     { if(printFlag) printf(" surfNr:%d does not exist\n", number ); return(-1); }
1672     set[setNr].anz_s= iinsert(&set[setNr].surf, set[setNr].anz_s, number);
1673     if (surf[number].nn>0)
1674     {
1675       for (k=0; k<surf[number].nn; k++)
1676       {
1677         set[setNr].anz_n= iinsert(&set[setNr].node, set[setNr].anz_n, surf[number].nod[k] );
1678       }
1679     }
1680     if (surf[number].ne>0)
1681     {
1682       for (k=0; k<surf[number].ne; k++)
1683       {
1684         set[setNr].anz_e=iinsert(&set[setNr].elem, set[setNr].anz_e, surf[number].elem[k] );
1685       }
1686     }
1687   }
1688   else if ( type[0] == 'b' )
1689   {
1690     if (number<0)
1691     { if(printFlag) printf(" bodyNr:%d does not exist\n", number ); return(-1); }
1692     set[setNr].anz_b= iinsert(&set[setNr].body, set[setNr].anz_b, number);
1693 
1694     if (body[number].nn>0)
1695     {
1696       for (k=0; k<body[number].nn; k++)
1697       {
1698         set[setNr].anz_n= iinsert(&set[setNr].node, set[setNr].anz_n,body[number].nod[k] );
1699       }
1700     }
1701     if (body[number].ne>0)
1702     {
1703       for (k=0; k<body[number].ne; k++)
1704       {
1705         set[setNr].anz_e=iinsert(&set[setNr].elem, set[setNr].anz_e,body[number].elem[k] );
1706       }
1707     }
1708   }
1709   else if ( type[0] == 'L' )
1710   {
1711     if (number<0)
1712     { if(printFlag) printf(" NurlNr:%d does not exist\n", number ); return(-1); }
1713     set[setNr].anz_nurl= iinsert(&set[setNr].nurl, set[setNr].anz_nurl, number);
1714   }
1715   else if ( type[0] == 'S' )
1716   {
1717     if (number<0)
1718     { if(printFlag) printf(" NursNr:%d does not exist\n", number ); return(-1); }
1719     set[setNr].anz_nurs= iinsert(&set[setNr].nurs, set[setNr].anz_nurs, number);
1720   }
1721   else if ( type[0] == 'j' )
1722   {
1723     if((set[setNr].elf= (Elfaces *)realloc(set[setNr].elf, (set[setNr].anz_elf+1)*sizeof(Elfaces))) == NULL )
1724     { printf("ERROR: realloc failed in seta()\n\n" ); return(-1); }
1725     if(number)
1726     {
1727       set[setNr].elf[set[setNr].anz_elf].n=number;
1728       if((set[setNr].elf[set[setNr].anz_elf].v= (float *)calloc(number, sizeof(float))) == NULL )
1729       { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
1730     }
1731     else set[setNr].elf[set[setNr].anz_elf].n=0;
1732     set[setNr].anz_elf++;
1733     return(set[setNr].anz_elf-1);
1734   }
1735   else
1736   {
1737     errMsg ("WARNING: in seta type:%s not recognized\n", type);
1738     return(-1);
1739   }
1740   return(1);
1741 }
1742 
1743 
sete(int setNr,char * type,char * mode)1744 int sete( int setNr, char *type, char *mode)
1745 {
1746   int i=0,s;
1747   int failFlag=0;
1748 
1749   /* check if all entities of setNr are also members in another sets */
1750   if ((type[0]=='s')&&(type[1]=='e'))
1751   {
1752     for(s=0; s<anz->sets; s++)
1753     {
1754       failFlag=0;
1755       if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
1756       {
1757         if(set[setNr].anz_n> set[s].anz_n) continue;
1758         if(set[setNr].anz_e> set[s].anz_e) continue;
1759         if(set[setNr].anz_f> set[s].anz_f) continue;
1760         if(set[setNr].anz_p> set[s].anz_p) continue;
1761         if(set[setNr].anz_l> set[s].anz_l) continue;
1762         if(set[setNr].anz_c> set[s].anz_c) continue;
1763         if(set[setNr].anz_s> set[s].anz_s) continue;
1764         if(set[setNr].anz_b> set[s].anz_b) continue;
1765         if(set[setNr].anz_se> set[s].anz_se) continue;
1766         if(set[setNr].anz_sh> set[s].anz_sh) continue;
1767         if(set[setNr].anz_nurl> set[s].anz_nurl) continue;
1768         if(set[setNr].anz_nurs> set[s].anz_nurs) continue;
1769         if((s!=setNr)&&(set[s].name!=NULL))
1770 	{
1771           for (i=0; i<set[setNr].anz_n; i++)
1772           {
1773             if(0>ifind(&set[s].node, set[s].anz_n, set[setNr].node[i] )) break;
1774           }
1775           if(i!=set[setNr].anz_n) failFlag=1;
1776           for (i=0; i<set[setNr].anz_e; i++)
1777           {
1778             if(0>ifind(&set[s].elem, set[s].anz_e, set[setNr].elem[i] )) break;
1779           }
1780           if(i!=set[setNr].anz_e) failFlag=1;
1781           for (i=0; i<set[setNr].anz_f; i++)
1782           {
1783             if(0>ifind(&set[s].face, set[s].anz_f, set[setNr].face[i] )) break;
1784           }
1785           if(i!=set[setNr].anz_f) failFlag=1;
1786           for (i=0; i<set[setNr].anz_p; i++)
1787           {
1788             if(0>ifind(&set[s].pnt, set[s].anz_p, set[setNr].pnt[i] )) break;
1789           }
1790           if(i!=set[setNr].anz_p) failFlag=1;
1791           for (i=0; i<set[setNr].anz_l; i++)
1792           {
1793             if(0>ifind(&set[s].line, set[s].anz_l, set[setNr].line[i] )) break;
1794           }
1795           if(i!=set[setNr].anz_l) failFlag=1;
1796           for (i=0; i<set[setNr].anz_c; i++)
1797           {
1798             if(0>ifind(&set[s].lcmb, set[s].anz_c, set[setNr].lcmb[i] )) break;
1799           }
1800           if(i!=set[setNr].anz_c) failFlag=1;
1801           for (i=0; i<set[setNr].anz_s; i++)
1802           {
1803             if(0>ifind(&set[s].surf, set[s].anz_s, set[setNr].surf[i] )) break;
1804           }
1805           if(i!=set[setNr].anz_s) failFlag=1;
1806           for (i=0; i<set[setNr].anz_b; i++)
1807           {
1808             if(0>ifind(&set[s].body, set[s].anz_b, set[setNr].body[i] )) break;
1809           }
1810           if(i!=set[setNr].anz_b) failFlag=1;
1811           for (i=0; i<set[setNr].anz_se; i++)
1812           {
1813             if(0>ifind(&set[s].set, set[s].anz_se, set[setNr].set[i] )) break;
1814           }
1815           if(i!=set[setNr].anz_se) failFlag=1;
1816           for (i=0; i<set[setNr].anz_sh; i++)
1817           {
1818             if(0>ifind(&set[s].shp, set[s].anz_sh, set[setNr].shp[i] )) break;
1819           }
1820           if(i!=set[setNr].anz_sh ) failFlag=1;
1821           for (i=0; i<set[setNr].anz_nurl; i++)
1822           {
1823             if(0>ifind(&set[s].nurl, set[s].anz_nurl, set[setNr].nurl[i] )) break;
1824           }
1825           if(i!=set[setNr].anz_nurl) failFlag=1;
1826           for (i=0; i<set[setNr].anz_nurs; i++)
1827           {
1828             if(0>ifind(&set[s].nurs, set[s].anz_nurs, set[setNr].nurs[i] )) break;
1829           }
1830           if(i!=set[setNr].anz_nurs) failFlag=1;
1831           if(!failFlag)
1832           {
1833             /* all entities from setNr are in s included */
1834             if( compare( mode, "min", 3)==3)
1835 	    {
1836               printf(" All entities from set:%s are also in %s\n", set[setNr].name, set[s].name);
1837               strcpy(parameter[0], set[s].name);
1838               write2stack(1, parameter);
1839 	    }
1840             else /* strict, s must not include more nodes as setNr */
1841 	    {
1842               if(
1843                 (set[setNr].anz_n==set[s].anz_n)&&
1844                 (set[setNr].anz_e==set[s].anz_e)&&
1845                 (set[setNr].anz_f==set[s].anz_f)&&
1846                 (set[setNr].anz_p==set[s].anz_p)&&
1847                 (set[setNr].anz_l==set[s].anz_l)&&
1848                 (set[setNr].anz_c==set[s].anz_c)&&
1849                 (set[setNr].anz_s==set[s].anz_s)&&
1850                 (set[setNr].anz_b==set[s].anz_b)&&
1851                 (set[setNr].anz_se==set[s].anz_se)&&
1852                 (set[setNr].anz_sh==set[s].anz_sh)&&
1853                 (set[setNr].anz_nurl==set[s].anz_nurl)&&
1854                 (set[setNr].anz_nurs==set[s].anz_nurs) )
1855               { printf(" set:%s and %s share identical entities\n", set[setNr].name, set[s].name);
1856                   strcpy(parameter[0], set[s].name);
1857                   write2stack(1, parameter);
1858 	      }
1859 	    }
1860 	  }
1861 	}
1862       }
1863       else /* max */
1864       {
1865         if(set[setNr].anz_n< set[s].anz_n) continue;
1866         if(set[setNr].anz_e< set[s].anz_e) continue;
1867         if(set[setNr].anz_f< set[s].anz_f) continue;
1868         if(set[setNr].anz_p< set[s].anz_p) continue;
1869         if(set[setNr].anz_l< set[s].anz_l) continue;
1870         if(set[setNr].anz_c< set[s].anz_c) continue;
1871         if(set[setNr].anz_s< set[s].anz_s) continue;
1872         if(set[setNr].anz_b< set[s].anz_b) continue;
1873         if(set[setNr].anz_se< set[s].anz_se) continue;
1874         if(set[setNr].anz_sh< set[s].anz_sh) continue;
1875         if(set[setNr].anz_nurl< set[s].anz_nurl) continue;
1876         if(set[setNr].anz_nurs< set[s].anz_nurs) continue;
1877         if((s!=setNr)&&(set[s].name!=NULL))
1878 	{
1879           for (i=0; i<set[s].anz_n; i++)
1880           {
1881             if(0>ifind(&set[setNr].node, set[setNr].anz_n, set[s].node[i] )) break;
1882           }
1883           if(i!=set[setNr].anz_n) failFlag=1;
1884           for (i=0; i<set[s].anz_e; i++)
1885           {
1886             if(0>ifind(&set[setNr].elem, set[setNr].anz_e, set[s].elem[i] )) break;
1887           }
1888           if(i!=set[s].anz_e) failFlag=1;
1889           for (i=0; i<set[s].anz_f; i++)
1890           {
1891             if(0>ifind(&set[setNr].face, set[setNr].anz_f, set[s].face[i] )) break;
1892           }
1893           if(i!=set[s].anz_f) failFlag=1;
1894           for (i=0; i<set[s].anz_p; i++)
1895           {
1896             if(0>ifind(&set[setNr].pnt, set[setNr].anz_p, set[s].pnt[i] )) break;
1897           }
1898           if(i!=set[s].anz_p) failFlag=1;
1899           for (i=0; i<set[s].anz_l; i++)
1900           {
1901             if(0>ifind(&set[setNr].line, set[setNr].anz_l, set[s].line[i] )) break;
1902           }
1903           if(i!=set[s].anz_l) failFlag=1;
1904           for (i=0; i<set[s].anz_c; i++)
1905           {
1906             if(0>ifind(&set[setNr].lcmb, set[setNr].anz_c, set[s].lcmb[i] )) break;
1907           }
1908           if(i!=set[s].anz_c) failFlag=1;
1909           for (i=0; i<set[s].anz_s; i++)
1910           {
1911             if(0>ifind(&set[setNr].surf, set[setNr].anz_s, set[s].surf[i] )) break;
1912           }
1913           if(i!=set[s].anz_s) failFlag=1;
1914           for (i=0; i<set[s].anz_b; i++)
1915           {
1916             if(0>ifind(&set[setNr].body, set[setNr].anz_b, set[s].body[i] )) break;
1917           }
1918           if(i!=set[s].anz_b) failFlag=1;
1919           for (i=0; i<set[s].anz_se; i++)
1920           {
1921             if(0>ifind(&set[setNr].set, set[setNr].anz_se, set[s].set[i] )) break;
1922           }
1923           if(i!=set[s].anz_se) failFlag=1;
1924           for (i=0; i<set[s].anz_sh; i++)
1925           {
1926             if(0>ifind(&set[setNr].shp, set[setNr].anz_sh, set[s].shp[i] )) break;
1927           }
1928           if(i!=set[s].anz_sh ) failFlag=1;
1929           for (i=0; i<set[s].anz_nurl; i++)
1930           {
1931             if(0>ifind(&set[setNr].nurl, set[setNr].anz_nurl, set[s].nurl[i] )) break;
1932           }
1933           if(i!=set[s].anz_nurl) failFlag=1;
1934           for (i=0; i<set[s].anz_nurs; i++)
1935           {
1936             if(0>ifind(&set[setNr].nurs, set[setNr].anz_nurs, set[s].nurs[i] )) break;
1937           }
1938           if(i!=set[s].anz_nurs) failFlag=1;
1939           if(!failFlag)
1940           {
1941             /* all entities from s are in setNr included */
1942             printf(" All entities from set:%s are also in %s\n", set[s].name, set[setNr].name);
1943             strcpy(parameter[0], set[setNr].name);
1944             write2stack(1, parameter);
1945 	  }
1946 	}
1947       }
1948     }
1949     return(1);
1950   }
1951 
1952   for(s=0; s<anz->sets; s++)
1953   {
1954     if((s!=setNr)&&(set[s].name!=NULL))
1955     {
1956       if ((type[0]=='s')&&(type[1]=='h'))
1957       {
1958         if(!set[setNr].anz_sh) continue;
1959         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
1960         {
1961           if(set[setNr].anz_sh> set[s].anz_sh) continue;
1962 	  failFlag=0;
1963           for (i=0; i<set[setNr].anz_sh; i++)
1964           {
1965             if(0>ifind(&set[s].shp, set[s].anz_sh, set[setNr].shp[i] )) break;
1966           }
1967           if(i!=set[setNr].anz_sh ) failFlag=1;
1968           if(!failFlag)
1969           {
1970             /* all entities from setNr are in s included */
1971             if( compare( mode, "min", 3)==3)
1972 	    {
1973               printf(" All shapes from set:%s are also in %s\n", set[setNr].name, set[s].name);
1974               strcpy(parameter[0], set[s].name);
1975               write2stack(1, parameter);
1976 	    }
1977             else /* strict, s must not include more nodes as setNr */
1978 	    {
1979               if(set[setNr].anz_n==set[s].anz_n) {  printf(" set:%s and %s share identical shapes\n", set[setNr].name, set[s].name);
1980                 strcpy(parameter[0], set[s].name);
1981                 write2stack(1, parameter);
1982 	      }
1983 	    }
1984 	  }
1985         }
1986         else /* max */
1987         {
1988           if(set[setNr].anz_sh< set[s].anz_sh) continue;
1989 	  failFlag=0;
1990           for (i=0; i<set[s].anz_sh; i++)
1991           {
1992             if(0>ifind(&set[setNr].shp, set[setNr].anz_sh, set[s].shp[i] )) break;
1993           }
1994           if(i!=set[s].anz_sh ) failFlag=1;
1995           if(!failFlag)
1996           {
1997             /* all entities from s are in setNr included */
1998             printf(" All shapes from set:%s are also in %s\n", set[s].name, set[setNr].name);
1999             strcpy(parameter[0], set[setNr].name);
2000             write2stack(1, parameter);
2001 	  }
2002 	}
2003       }
2004 
2005       else if (type[0]=='n')
2006       {
2007         if(!set[setNr].anz_n) continue;
2008         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2009         {
2010           if(set[setNr].anz_n> set[s].anz_n) continue;
2011 	  failFlag=0;
2012           for (i=0; i<set[setNr].anz_n; i++)
2013           {
2014             if(0>ifind(&set[s].node, set[s].anz_n, set[setNr].node[i] )) break;
2015           }
2016           if(i!=set[setNr].anz_n ) failFlag=1;
2017           if(!failFlag)
2018           {
2019             /* all entities from setNr are in s included */
2020             if( compare( mode, "min", 3)==3)
2021 	    {
2022               printf(" All nodes from set:%s also in %s\n", set[setNr].name, set[s].name);
2023               strcpy(parameter[0], set[s].name);
2024               write2stack(1, parameter);
2025 	    }
2026             else /* strict, s must not include more nodes as setNr */
2027 	    {
2028               if(set[setNr].anz_n==set[s].anz_n) {  printf(" set:%s and %s share identical nodes\n", set[setNr].name, set[s].name);
2029                 strcpy(parameter[0], set[s].name);
2030                 write2stack(1, parameter);
2031 	      }
2032 	    }
2033 	  }
2034         }
2035         else /* max */
2036         {
2037           if(set[setNr].anz_n< set[s].anz_n) continue;
2038 	  failFlag=0;
2039           for (i=0; i<set[s].anz_n; i++)
2040           {
2041             if(0>ifind(&set[setNr].node, set[setNr].anz_n, set[s].node[i] )) break;
2042           }
2043           if(i!=set[s].anz_n ) failFlag=1;
2044           if(!failFlag)
2045           {
2046             /* all entities from s are in setNr included */
2047             printf(" All nodes from set:%s also in %s\n", set[s].name, set[setNr].name);
2048             strcpy(parameter[0], set[setNr].name);
2049             write2stack(1, parameter);
2050 	  }
2051 	}
2052       }
2053 
2054       else if (type[0]=='e')
2055       {
2056         if(!set[setNr].anz_e) continue;
2057         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2058         {
2059           if(set[setNr].anz_e> set[s].anz_e) continue;
2060 	  failFlag=0;
2061           for (i=0; i<set[setNr].anz_e; i++)
2062           {
2063             if(0>ifind(&set[s].elem, set[s].anz_e, set[setNr].elem[i] )) break;
2064           }
2065           if(i!=set[setNr].anz_e ) failFlag=1;
2066           if(!failFlag)
2067           {
2068             /* all entities from setNr are in s included */
2069             if( compare( mode, "min", 3)==3)
2070 	    {
2071               printf(" All elems from set:%s are also in %s\n", set[setNr].name, set[s].name);
2072               strcpy(parameter[0], set[s].name);
2073               write2stack(1, parameter);
2074 	    }
2075             else /* strict, s must not include more elems as setNr */
2076 	    {
2077               if(set[setNr].anz_e==set[s].anz_e) {  printf(" set:%s and %s share identical elems\n", set[setNr].name, set[s].name);
2078                 strcpy(parameter[0], set[s].name);
2079                 write2stack(1, parameter);
2080 	      }
2081 	    }
2082 	  }
2083         }
2084         else /* max */
2085         {
2086           if(set[setNr].anz_e< set[s].anz_e) continue;
2087 	  failFlag=0;
2088           for (i=0; i<set[s].anz_e; i++)
2089           {
2090             if(0>ifind(&set[setNr].elem, set[setNr].anz_e, set[s].elem[i] )) break;
2091           }
2092           if(i!=set[s].anz_e ) failFlag=1;
2093           if(!failFlag)
2094           {
2095             /* all entities from s are in setNr included */
2096             printf(" All elems from set:%s also in %s\n", set[s].name, set[setNr].name);
2097             strcpy(parameter[0], set[setNr].name);
2098             write2stack(1, parameter);
2099 	  }
2100 	}
2101       }
2102 
2103       else if (type[0]=='p')
2104       {
2105         if(!set[setNr].anz_p) continue;
2106         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2107         {
2108           if(set[setNr].anz_p> set[s].anz_p) continue;
2109 	  failFlag=0;
2110           for (i=0; i<set[setNr].anz_p; i++)
2111           {
2112             if(0>ifind(&set[s].pnt , set[s].anz_p, set[setNr].pnt[i] )) break;
2113           }
2114           if(i!=set[setNr].anz_p ) failFlag=1;
2115           if(!failFlag)
2116           {
2117             /* all entities from setNr are in s included */
2118             if( compare( mode, "min", 3)==3)
2119 	    {
2120               printf(" All points from set:%s are also in %s\n", set[setNr].name, set[s].name);
2121               strcpy(parameter[0], set[s].name);
2122               write2stack(1, parameter);
2123 	    }
2124             else /* strict, s must not include more nodes as setNr */
2125 	    {
2126               if(set[setNr].anz_p==set[s].anz_p) {  printf(" set:%s and %s share identical points\n", set[setNr].name, set[s].name);
2127                 strcpy(parameter[0], set[s].name);
2128                 write2stack(1, parameter);
2129 	      }
2130 	    }
2131 	  }
2132         }
2133         else /* max */
2134         {
2135           if(set[setNr].anz_p< set[s].anz_p) continue;
2136 	  failFlag=0;
2137           for (i=0; i<set[s].anz_p; i++)
2138           {
2139             if(0>ifind(&set[setNr].pnt , set[setNr].anz_p, set[s].pnt[i] )) break;
2140           }
2141           if(i!=set[s].anz_p ) failFlag=1;
2142           if(!failFlag)
2143           {
2144             /* all entities from s are in setNr included */
2145             printf(" All points from set:%s also in %s\n", set[s].name, set[setNr].name);
2146             strcpy(parameter[0], set[setNr].name);
2147             write2stack(1, parameter);
2148 	  }
2149 	}
2150       }
2151 
2152       else if (type[0]=='c')
2153       {
2154         if(!set[setNr].anz_c) continue;
2155         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2156         {
2157           if(set[setNr].anz_c> set[s].anz_c) continue;
2158 	  failFlag=0;
2159           for (i=0; i<set[setNr].anz_c; i++)
2160           {
2161             if(0>ifind(&set[s].lcmb, set[s].anz_c, set[setNr].lcmb[i] )) break;
2162           }
2163           if(i!=set[setNr].anz_c ) failFlag=1;
2164           if(!failFlag)
2165           {
2166             /* all entities from setNr are in s included */
2167             if( compare( mode, "min", 3)==3)
2168 	    {
2169               printf(" All lcmbs from set:%s are also in %s\n", set[setNr].name, set[s].name);
2170               strcpy(parameter[0], set[s].name);
2171               write2stack(1, parameter);
2172 	    }
2173             else /* strict, s must not include more nodes as setNr */
2174 	    {
2175               if(set[setNr].anz_c==set[s].anz_c) {  printf(" set:%s and %s share identical lcmbs\n", set[setNr].name, set[s].name);
2176                 strcpy(parameter[0], set[s].name);
2177                 write2stack(1, parameter);
2178 	      }
2179 	    }
2180 	  }
2181         }
2182         else /* max */
2183         {
2184           if(set[setNr].anz_c< set[s].anz_c) continue;
2185 	  failFlag=0;
2186           for (i=0; i<set[s].anz_c; i++)
2187           {
2188             if(0>ifind(&set[setNr].lcmb, set[setNr].anz_c, set[s].lcmb[i] )) break;
2189           }
2190           if(i!=set[s].anz_c ) failFlag=1;
2191           if(!failFlag)
2192           {
2193             /* all entities from s are in setNr included */
2194             printf(" All lcmbs from set:%s also in %s\n", set[s].name, set[setNr].name);
2195             strcpy(parameter[0], set[setNr].name);
2196             write2stack(1, parameter);
2197 	  }
2198 	}
2199       }
2200 
2201       else if (type[0]=='l')
2202       {
2203         if(!set[setNr].anz_l) continue;
2204         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2205         {
2206           if(set[setNr].anz_l> set[s].anz_l) continue;
2207 	  failFlag=0;
2208           for (i=0; i<set[setNr].anz_l; i++)
2209           {
2210             if(0>ifind(&set[s].line, set[s].anz_l, set[setNr].line[i] )) break;
2211           }
2212           if(i!=set[setNr].anz_l ) failFlag=1;
2213           if(!failFlag)
2214           {
2215             /* all entities from setNr are in s included */
2216             if( compare( mode, "min", 3)==3)
2217 	    {
2218               printf(" All lines from set:%s are also in %s\n", set[setNr].name, set[s].name);
2219               strcpy(parameter[0], set[s].name);
2220               write2stack(1, parameter);
2221 	    }
2222             else /* strict, s must not include more nodes as setNr */
2223 	    {
2224               if(set[setNr].anz_l==set[s].anz_l) {  printf(" set:%s and %s share identical lines\n", set[setNr].name, set[s].name);
2225                 strcpy(parameter[0], set[s].name);
2226                 write2stack(1, parameter);
2227 	      }
2228 	    }
2229 	  }
2230         }
2231         else /* max */
2232         {
2233           if(set[setNr].anz_l< set[s].anz_l) continue;
2234 	  failFlag=0;
2235           for (i=0; i<set[s].anz_l; i++)
2236           {
2237             if(0>ifind(&set[setNr].line, set[setNr].anz_l, set[s].line[i] )) break;
2238           }
2239           if(i!=set[s].anz_l ) failFlag=1;
2240           if(!failFlag)
2241           {
2242             /* all entities from s are in setNr included */
2243             printf(" All lines from set:%s also in %s\n", set[s].name, set[setNr].name);
2244             strcpy(parameter[0], set[setNr].name);
2245             write2stack(1, parameter);
2246 	  }
2247 	}
2248       }
2249 
2250       else if (type[0]=='s')
2251       {
2252         if(!set[setNr].anz_s) continue;
2253         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2254         {
2255           if(set[setNr].anz_s> set[s].anz_s) continue;
2256 	  failFlag=0;
2257           for (i=0; i<set[setNr].anz_s; i++)
2258           {
2259             if(0>ifind(&set[s].surf, set[s].anz_s, set[setNr].surf[i] )) break;
2260           }
2261           if(i!=set[setNr].anz_s ) failFlag=1;
2262           if(!failFlag)
2263           {
2264             /* all entities from setNr are in s included */
2265             if( compare( mode, "min", 3)==3)
2266 	    {
2267               printf(" All surfs from set:%s are also in %s\n", set[setNr].name, set[s].name);
2268               strcpy(parameter[0], set[s].name);
2269               write2stack(1, parameter);
2270 	    }
2271             else /* strict, s must not include more nodes as setNr */
2272 	    {
2273               if(set[setNr].anz_s==set[s].anz_s) {  printf(" set:%s and %s share identical surfs\n", set[setNr].name, set[s].name);
2274                 strcpy(parameter[0], set[s].name);
2275                 write2stack(1, parameter);
2276 	      }
2277 	    }
2278 	  }
2279         }
2280         else /* max */
2281         {
2282           if(set[setNr].anz_s< set[s].anz_s) continue;
2283 	  failFlag=0;
2284           for (i=0; i<set[s].anz_s; i++)
2285           {
2286             if(0>ifind(&set[setNr].surf, set[setNr].anz_s, set[s].surf[i] )) break;
2287           }
2288           if(i!=set[s].anz_s ) failFlag=1;
2289           if(!failFlag)
2290           {
2291             /* all entities from s are in setNr included */
2292             printf(" All surfs from set:%s also in %s\n", set[s].name, set[setNr].name);
2293             strcpy(parameter[0], set[setNr].name);
2294             write2stack(1, parameter);
2295 	  }
2296 	}
2297       }
2298 
2299       else if (type[0]=='b')
2300       {
2301         if(!set[setNr].anz_b) continue;
2302         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2303         {
2304           if(set[setNr].anz_b> set[s].anz_b) continue;
2305 	  failFlag=0;
2306           for (i=0; i<set[setNr].anz_b; i++)
2307           {
2308             if(0>ifind(&set[s].body, set[s].anz_b, set[setNr].body[i] )) break;
2309           }
2310           if(i!=set[setNr].anz_b ) failFlag=1;
2311           if(!failFlag)
2312           {
2313             /* all entities from setNr are in s included */
2314             if( compare( mode, "min", 3)==3)
2315 	    {
2316               printf(" All bodies from set:%s are also in %s\n", set[setNr].name, set[s].name);
2317               strcpy(parameter[0], set[s].name);
2318               write2stack(1, parameter);
2319 	    }
2320             else /* strict, s must not include more nodes as setNr */
2321 	    {
2322               if(set[setNr].anz_b==set[s].anz_b) {  printf(" set:%s and %s share identical bodies\n", set[setNr].name, set[s].name);
2323                 strcpy(parameter[0], set[s].name);
2324                 write2stack(1, parameter);
2325 	      }
2326 	    }
2327 	  }
2328         }
2329         else /* max */
2330         {
2331           if(set[setNr].anz_b< set[s].anz_b) continue;
2332 	  failFlag=0;
2333           for (i=0; i<set[s].anz_b; i++)
2334           {
2335             if(0>ifind(&set[setNr].body, set[setNr].anz_b, set[s].body[i] )) break;
2336           }
2337           if(i!=set[s].anz_b ) failFlag=1;
2338           if(!failFlag)
2339           {
2340             /* all entities from s are in setNr included */
2341             printf(" All bodies from set:%s also in %s\n", set[s].name, set[setNr].name);
2342             strcpy(parameter[0], set[setNr].name);
2343             write2stack(1, parameter);
2344 	  }
2345 	}
2346       }
2347 
2348       else if (type[0]=='L')
2349       {
2350         if(!set[setNr].anz_nurl) continue;
2351         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2352         {
2353           if(set[setNr].anz_nurl> set[s].anz_nurl) continue;
2354 	  failFlag=0;
2355           for (i=0; i<set[setNr].anz_nurl; i++)
2356           {
2357             if(0>ifind(&set[s].nurl, set[s].anz_nurl, set[setNr].nurl[i] )) break;
2358           }
2359           if(i!=set[setNr].anz_nurl ) failFlag=1;
2360           if(!failFlag)
2361           {
2362             /* all entities from setNr are in s included */
2363             if( compare( mode, "min", 3)==3)
2364 	    {
2365               printf(" All nurls from set:%s are also in %s\n", set[setNr].name, set[s].name);
2366               strcpy(parameter[0], set[s].name);
2367               write2stack(1, parameter);
2368 	    }
2369             else /* strict, s must not include more nodes as setNr */
2370 	    {
2371               if(set[setNr].anz_nurl==set[s].anz_nurl) {  printf(" set:%s and %s share identical nurls\n", set[setNr].name, set[s].name);
2372                 strcpy(parameter[0], set[s].name);
2373                 write2stack(1, parameter);
2374 	      }
2375 	    }
2376 	  }
2377         }
2378         else /* max */
2379         {
2380           if(set[setNr].anz_nurl< set[s].anz_nurl) continue;
2381 	  failFlag=0;
2382           for (i=0; i<set[s].anz_nurl; i++)
2383           {
2384             if(0>ifind(&set[setNr].nurl, set[setNr].anz_nurl, set[s].nurl[i] )) break;
2385           }
2386           if(i!=set[s].anz_nurl ) failFlag=1;
2387           if(!failFlag)
2388           {
2389             /* all entities from s are in setNr included */
2390             printf(" All nurls from set:%s also in %s\n", set[s].name, set[setNr].name);
2391             strcpy(parameter[0], set[setNr].name);
2392             write2stack(1, parameter);
2393 	  }
2394 	}
2395       }
2396 
2397       else if (type[0]=='S')
2398       {
2399         if(!set[setNr].anz_nurs) continue;
2400         if(( compare( mode, "min", 3)==3)||( compare( mode, "strict", 3)==3))
2401         {
2402           if(set[setNr].anz_nurs> set[s].anz_nurs) continue;
2403 	  failFlag=0;
2404           for (i=0; i<set[setNr].anz_nurs; i++)
2405           {
2406             if(0>ifind(&set[s].nurs, set[s].anz_nurs, set[setNr].nurs[i] )) break;
2407           }
2408           if(i!=set[setNr].anz_nurs ) failFlag=1;
2409           if(!failFlag)
2410           {
2411             /* all entities from setNr are in s included */
2412             if( compare( mode, "min", 3)==3)
2413 	    {
2414               printf(" All nurbs from set:%s are also in %s\n", set[setNr].name, set[s].name);
2415               strcpy(parameter[0], set[s].name);
2416               write2stack(1, parameter);
2417 	    }
2418             else /* strict, s must not include more nodes as setNr */
2419 	    {
2420               if(set[setNr].anz_nurs==set[s].anz_nurs) {  printf(" set:%s and %s share identical nurbs\n", set[setNr].name, set[s].name);
2421                 strcpy(parameter[0], set[s].name);
2422                 write2stack(1, parameter);
2423 	      }
2424 	    }
2425 	  }
2426         }
2427         else /* max */
2428         {
2429           if(set[setNr].anz_nurs< set[s].anz_nurs) continue;
2430 	  failFlag=0;
2431           for (i=0; i<set[s].anz_nurs; i++)
2432           {
2433             if(0>ifind(&set[setNr].nurs, set[setNr].anz_nurs, set[s].nurs[i] )) break;
2434           }
2435           if(i!=set[s].anz_nurs ) failFlag=1;
2436           if(!failFlag)
2437           {
2438             /* all entities from s are in setNr included */
2439             printf(" All nurbs from set:%s also in %s\n", set[s].name, set[setNr].name);
2440             strcpy(parameter[0], set[setNr].name);
2441             write2stack(1, parameter);
2442 	  }
2443 	}
2444       }
2445 
2446     }
2447   }
2448   return(1);
2449 }
2450 
2451 
seti(int setNr,char * type,int sets,char dat[MAX_PARAM_PER_RECORD][MAX_LINE_LENGTH])2452 int seti( int setNr, char *type, int sets, char dat[MAX_PARAM_PER_RECORD][MAX_LINE_LENGTH])
2453 {
2454   int i,j,s,setnr[100];
2455 
2456   if(sets>100) { printf(" ERROR, to much sets\n"); return(0); }
2457   j=0;
2458   for(s=0; s<sets; s++) { i=getSetNr( dat[s] ); if((i>-1)&&(set[i].name!=NULL)) setnr[j++]=i; }
2459   sets=j;
2460 
2461 
2462   /* check if the entity is a member in all sets */
2463   if ((type[0]=='s')&&(type[1]=='e'))
2464   {
2465     for (j=0; j<set[setnr[0]].anz_n; j++)
2466     {
2467       for(s=1; s<sets; s++)
2468       {
2469         if(0>ifind(&set[setnr[s]].node, set[setnr[s]].anz_n, set[setnr[0]].node[j] )) break;
2470       }
2471       if(s==sets) seta( setNr, "n", set[setnr[0]].node[j] );
2472     }
2473     for (j=0; j<set[setnr[0]].anz_e; j++)
2474     {
2475       for(s=1; s<sets; s++)
2476       {
2477         if(0>ifind(&set[setnr[s]].elem, set[setnr[s]].anz_e, set[setnr[0]].elem[j] )) break;
2478       }
2479       if(s==sets) seta( setNr, "e", set[setnr[0]].elem[j] );
2480     }
2481     for (j=0; j<set[setnr[0]].anz_f; j++)
2482     {
2483       for(s=1; s<sets; s++)
2484       {
2485         if(0>ifind(&set[setnr[s]].face, set[setnr[s]].anz_f, set[setnr[0]].face[j] )) break;
2486       }
2487       if(s==sets) seta( setNr, "f", set[setnr[0]].face[j] );
2488     }
2489     for (j=0; j<set[setnr[0]].anz_p; j++)
2490     {
2491       for(s=1; s<sets; s++)
2492       {
2493         if(0>ifind(&set[setnr[s]].pnt, set[setnr[s]].anz_p, set[setnr[0]].pnt[j] )) break;
2494       }
2495       if(s==sets) seta( setNr, "p", set[setnr[0]].pnt[j] );
2496     }
2497     for (j=0; j<set[setnr[0]].anz_l; j++)
2498     {
2499       for(s=1; s<sets; s++)
2500       {
2501         if(0>ifind(&set[setnr[s]].line, set[setnr[s]].anz_l, set[setnr[0]].line[j] )) break;
2502       }
2503       if(s==sets) seta( setNr, "l", set[setnr[0]].line[j] );
2504     }
2505     for (j=0; j<set[setnr[0]].anz_c; j++)
2506     {
2507       for(s=1; s<sets; s++)
2508       {
2509         if(0>ifind(&set[setnr[s]].lcmb, set[setnr[s]].anz_c, set[setnr[0]].lcmb[j] )) break;
2510       }
2511       if(s==sets) seta( setNr, "c", set[setnr[0]].lcmb[j] );
2512     }
2513     for (j=0; j<set[setnr[0]].anz_s; j++)
2514     {
2515       for(s=1; s<sets; s++)
2516       {
2517         if(0>ifind(&set[setnr[s]].surf, set[setnr[s]].anz_s, set[setnr[0]].surf[j] )) break;
2518       }
2519       if(s==sets) seta( setNr, "s", set[setnr[0]].surf[j] );
2520     }
2521     for (j=0; j<set[setnr[0]].anz_b; j++)
2522     {
2523       for(s=1; s<sets; s++)
2524       {
2525         if(0>ifind(&set[setnr[s]].body, set[setnr[s]].anz_b, set[setnr[0]].body[j] )) break;
2526       }
2527       if(s==sets) seta( setNr, "b", set[setnr[0]].body[j] );
2528     }
2529     for (j=0; j<set[setnr[0]].anz_se; j++)
2530     {
2531       for(s=1; s<sets; s++)
2532       {
2533         if(0>ifind(&set[setnr[s]].set, set[setnr[s]].anz_se, set[setnr[0]].set[j] )) break;
2534       }
2535       if(s==sets) seta( setNr, "se", set[setnr[0]].set[j] );
2536     }
2537     for (j=0; j<set[setnr[0]].anz_sh; j++)
2538     {
2539       for(s=1; s<sets; s++)
2540       {
2541         if(0>ifind(&set[setnr[s]].shp, set[setnr[s]].anz_sh, set[setnr[0]].shp[j] )) break;
2542       }
2543       if(s==sets) seta( setNr, "sh", set[setnr[0]].shp[j] );
2544     }
2545   }
2546   else if ((type[0]=='s')&&(type[1]=='h'))
2547   {
2548     for (j=0; j<set[setnr[0]].anz_sh; j++)
2549     {
2550       for(s=1; s<sets; s++)
2551       {
2552         if(0>ifind(&set[setnr[s]].shp, set[setnr[s]].anz_sh, set[setnr[0]].shp[j] )) break;
2553       }
2554       if(s==sets) seta( setNr, "sh", set[setnr[0]].shp[j] );
2555     }
2556   }
2557   else if (type[0]=='n')
2558   {
2559     for (j=0; j<set[setnr[0]].anz_n; j++)
2560     {
2561       for(s=1; s<sets; s++)
2562       {
2563         if(0>ifind(&set[setnr[s]].node, set[setnr[s]].anz_n, set[setnr[0]].node[j] )) break;
2564       }
2565       if(s==sets) seta( setNr, "n", set[setnr[0]].node[j] );
2566     }
2567   }
2568   else if (type[0]=='e')
2569   {
2570     for (j=0; j<set[setnr[0]].anz_e; j++)
2571     {
2572       for(s=1; s<sets; s++)
2573       {
2574         if(0>ifind(&set[setnr[s]].elem, set[setnr[s]].anz_e, set[setnr[0]].elem[j] )) break;
2575       }
2576       if(s==sets) seta( setNr, "e", set[setnr[0]].elem[j] );
2577     }
2578   }
2579   else if (type[0]=='f')
2580   {
2581     for (j=0; j<set[setnr[0]].anz_f; j++)
2582     {
2583       for(s=1; s<sets; s++)
2584       {
2585         if(0>ifind(&set[setnr[s]].face, set[setnr[s]].anz_f, set[setnr[0]].face[j] )) break;
2586       }
2587       if(s==sets) seta( setNr, "f", set[setnr[0]].face[j] );
2588     }
2589   }
2590   else if (type[0]=='p')
2591   {
2592     for (j=0; j<set[setnr[0]].anz_p; j++)
2593     {
2594       for(s=1; s<sets; s++)
2595       {
2596         if(0>ifind(&set[setnr[s]].pnt, set[setnr[s]].anz_p, set[setnr[0]].pnt[j] )) break;
2597       }
2598       if(s==sets) seta( setNr, "p", set[setnr[0]].pnt[j] );
2599     }
2600   }
2601   else if (type[0]=='l')
2602   {
2603     for (j=0; j<set[setnr[0]].anz_l; j++)
2604     {
2605       for(s=1; s<sets; s++)
2606       {
2607         if(0>ifind(&set[setnr[s]].line, set[setnr[s]].anz_l, set[setnr[0]].line[j] )) break;
2608       }
2609       if(s==sets) seta( setNr, "l", set[setnr[0]].line[j] );
2610     }
2611   }
2612   else if (type[0]=='c')
2613   {
2614     for (j=0; j<set[setnr[0]].anz_c; j++)
2615     {
2616       for(s=1; s<sets; s++)
2617       {
2618         if(0>ifind(&set[setnr[s]].lcmb, set[setnr[s]].anz_c, set[setnr[0]].lcmb[j] )) break;
2619       }
2620       if(s==sets) seta( setNr, "c", set[setnr[0]].lcmb[j] );
2621     }
2622   }
2623   else if (type[0]=='s')
2624   {
2625     for (j=0; j<set[setnr[0]].anz_s; j++)
2626     {
2627       for(s=1; s<sets; s++)
2628       {
2629         if(0>ifind(&set[setnr[s]].surf, set[setnr[s]].anz_s, set[setnr[0]].surf[j] )) break;
2630       }
2631       if(s==sets) seta( setNr, "s", set[setnr[0]].surf[j] );
2632     }
2633   }
2634   else if (type[0]=='b')
2635   {
2636     for (j=0; j<set[setnr[0]].anz_b; j++)
2637     {
2638       for(s=1; s<sets; s++)
2639       {
2640         if(0>ifind(&set[setnr[s]].body, set[setnr[s]].anz_b, set[setnr[0]].body[j] )) break;
2641       }
2642       if(s==sets) seta( setNr, "b", set[setnr[0]].body[j] );
2643     }
2644   }
2645   return(1);
2646 }
2647 
2648 
2649 
embodies(int set1,int set2,double cof[4])2650 int embodies( int set1, int set2, double cof[4])
2651 {
2652   int i,j,e,n;
2653   int etet, tets=0, extrapolflag=-1, includedFlag=-1;
2654 
2655   static Elements  *elem=NULL;
2656   static Nodes     *nod=NULL;
2657   static Tetraeder *tet=NULL;
2658   static Rsort *rsort=NULL;
2659 
2660   static double *orig_ex=NULL, *orig_ey=NULL, *orig_ez=NULL, *sort_ex=NULL, *sort_ey=NULL, *sort_ez=NULL;
2661   static int *sort_enx=NULL, *sort_eny=NULL, *sort_enz=NULL, near_node[N_CLOSEST_TETS];
2662   int     n_closest_tets;
2663 
2664 
2665   /* split elements into tet's (with cg and volu) */
2666 
2667   if ( (nod = (Nodes *)realloc( (Nodes *)nod, (anz->nmax+1) * sizeof(Nodes))) == NULL )
2668   {
2669     printf("WARNING: realloc error interpol3d\n");
2670   }
2671   if((elem = (Elements *)realloc( (Elements *)elem, (set[set2].anz_e) * sizeof(Elements))) == NULL )
2672   {
2673     printf("WARNING: realloc error interpol3d\n");
2674   }
2675   for (j=1; j<=anz->nmax; j++)
2676   {
2677     nod[j].nx=node[j].nx;
2678     nod[j].ny=node[j].ny;
2679     nod[j].nz=node[j].nz;
2680   }
2681   for (i=0; i<set[set2].anz_e; i++)
2682   {
2683     e=set[set2].elem[i];
2684     if(e_enqire[e].type==4) elem[i].type=1;
2685     else if(e_enqire[e].type==6) elem[i].type=3;
2686     else elem[i].type=e_enqire[e].type;
2687     elem[i].nr=e;
2688     for (j=0; j<26; j++) elem[i].nod[j]=e_enqire[e].nod[j];
2689   }
2690 
2691   tets = splitElementsToTets(set[set2].anz_e, nod, elem, &tet);
2692   if(!tets) { printf(" No 3D master elements found\n"); return(set1); }
2693 
2694   /* delete unusable tets (small volume) */
2695   j=0;
2696   for(i=0; i<tets; i++)
2697   {
2698     if(tet[i].v<SMALL_TET_VOLUME) { if(printFlag) printf("Scip Tet:%d vol:%e < SMALL_TET_VOLUME\n", i, tet[i].v); continue; }
2699     if(j<i)
2700     {
2701       for(n=0;n<4; n++) tet[j].n[n]=tet[i].n[n];
2702       for(n=0;n<3; n++) tet[j].cg[n]=tet[i].cg[n];
2703       tet[j].v=tet[i].v;
2704       tet[j].e=tet[i].e;
2705     }
2706     j++;
2707   }
2708   tets=j;
2709   if(printFlag) printf(" %d tets created\n", tets);
2710 
2711 
2712   if(set[set2].anz_n>tets)
2713   {
2714     if ( (rsort = (Rsort *)malloc( (set[set2].anz_n+1) * sizeof(Rsort))) == NULL )
2715       printf("ERROR: realloc failed: Rsort\n\n" );
2716   }
2717   else
2718   {
2719     if ( (rsort = (Rsort *)malloc( (tets+1) * sizeof(Rsort))) == NULL )
2720       printf("ERROR: realloc failed: Rsort\n\n" );
2721   }
2722 
2723   /* get the close tets */
2724   /* search the closest elements based on the closest cg */
2725   if ( (orig_ex = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
2726     printf("ERROR: realloc failed \n\n" );
2727   if ( (orig_ey = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
2728     printf("ERROR: realloc failed \n\n" );
2729   if ( (orig_ez = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
2730     printf("ERROR: realloc failed \n\n" );
2731   if ( (sort_ex = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
2732     printf("ERROR: realloc failed \n\n" );
2733   if ( (sort_ey = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
2734     printf("ERROR: realloc failed \n\n" );
2735   if ( (sort_ez = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
2736     printf("ERROR: realloc failed \n\n" );
2737   if ( (sort_enx = (int *)malloc( (tets+1) * sizeof(int))) == NULL )
2738     printf("ERROR: realloc failed \n\n" );
2739   if ( (sort_eny = (int *)malloc( (tets+1) * sizeof(int))) == NULL )
2740     printf("ERROR: realloc failed \n\n" );
2741   if ( (sort_enz = (int *)malloc( (tets+1) * sizeof(int))) == NULL )
2742     printf("ERROR: realloc failed \n\n" );
2743   for(i=0; i<tets; i++)
2744   {
2745     rsort[i].r=orig_ex[i]=tet[i].cg[0];
2746     rsort[i].i=i;
2747   }
2748   qsort( rsort, tets, sizeof(Rsort), (void *)compareRsort );
2749   for(i=0; i<tets; i++)
2750   {
2751     sort_ex[i]=rsort[i].r;
2752     sort_enx[i]=rsort[i].i;
2753   }
2754   for(i=0; i<tets; i++)
2755   {
2756     rsort[i].r=orig_ey[i]=tet[i].cg[1];
2757     rsort[i].i=i;
2758   }
2759   qsort( rsort, tets, sizeof(Rsort), (void *)compareRsort );
2760   for(i=0; i<tets; i++)
2761   {
2762     sort_ey[i]=rsort[i].r;
2763     sort_eny[i]=rsort[i].i;
2764   }
2765   for(i=0; i<tets; i++)
2766   {
2767     rsort[i].r=orig_ez[i]=tet[i].cg[2];
2768     rsort[i].i=i;
2769   }
2770   qsort( rsort, tets, sizeof(Rsort), (void *)compareRsort );
2771   for(i=0; i<tets; i++)
2772   {
2773     sort_ez[i]=rsort[i].r;
2774     sort_enz[i]=rsort[i].i;
2775   }
2776 
2777   if((int)N_CLOSEST_TETS/10<tets)  n_closest_tets= (int)N_CLOSEST_TETS/10; else n_closest_tets= tets;
2778 
2779   /* check if all nodes of setNr are inside the elements of elsetNr */
2780   for(i=0; i<set[set1].anz_n; i++)
2781   {
2782     /* search a close element */
2783     near3d(orig_ex,orig_ey,orig_ez,sort_ex,sort_ey,sort_ez,sort_enx,sort_eny,sort_enz, node[set[set1].node[i]].nx,node[set[set1].node[i]].ny, node[set[set1].node[i]].nz, tets, &near_node[0], n_closest_tets);
2784 
2785     etet=calcCoefficientsTet(set[set1].node[i], &near_node[0], n_closest_tets, node, tet, cof, extrapolflag);
2786     if(etet>-1)
2787     {
2788       includedFlag=set[set1].node[i];
2789       break;
2790     }
2791     //for (j=0; j<n_closest_tets; j++) printf("node:%d nearest tets:%d e:%d i:%d\n",set[set1].node[i], near_node[j]+1, etet, includedFlag);
2792   }
2793   if(orig_ex) free(orig_ex);
2794   if(orig_ey) free(orig_ey);
2795   if(orig_ez) free(orig_ez);
2796   if(sort_ex) free(sort_ex);
2797   if(sort_ey) free(sort_ey);
2798   if(sort_ez) free(sort_ez);
2799   if(sort_enx) free(sort_enx);
2800   if(sort_eny) free(sort_eny);
2801   if(sort_enz) free(sort_enz);
2802   free(nod);
2803   free(elem);
2804   free(tet);
2805   nod=NULL;
2806   elem=NULL;
2807 
2808   printf("done\n");
2809   return(includedFlag);
2810 }
2811 
2812 
2813 
setr(int setNr,char * type,int number)2814 int setr( int setNr, char *type, int number)
2815 {
2816   int i,j;
2817 
2818   if( set[setNr].name == (char *)NULL )
2819   {
2820     errMsg(" ERROR: setNr:%d is undefined\n", setNr);
2821     return(-1);
2822   }
2823   if( number<0)
2824   {
2825     errMsg(" ERROR in setr: A negative entity-index:%d was used\n", number);
2826     return(-1);
2827   }
2828 
2829   if (( type[0] == 'r' )||(( type[0] == 's' )&&( type[1] == 'e' )))
2830   {
2831     /* set remove  */
2832     i=iremove(&set[setNr].set, set[setNr].anz_se, number);
2833     if(i<set[setNr].anz_se)
2834     {
2835       set[setNr].anz_se=i;
2836     }
2837     else { if(printFlag) printf(" set:%s not in set:%s\n", set[number].name, set[setNr].name); }
2838   }
2839   else if (type[0]=='v')
2840   {
2841     /* value remove  */
2842     i=iremove(&set[setNr].valu, set[setNr].anz_v, number);
2843     if(i<set[setNr].anz_v)
2844     {
2845       set[setNr].anz_v=i;
2846     }
2847     else { if(printFlag) printf(" value:%s not in set:%s\n", value[number].name, set[setNr].name); }
2848   }
2849   else if (( type[0] == 'h' )||(( type[0] == 's' )&&( type[1] == 'h' )))
2850   {
2851     /* set remove  */
2852     i=iremove(&set[setNr].shp, set[setNr].anz_sh, number);
2853     if(i<set[setNr].anz_sh)
2854     {
2855       set[setNr].anz_sh=i;
2856     }
2857     else { if(printFlag) printf(" shape:%s not in set:%s\n", shape[number].name, set[setNr].name); }
2858   }
2859   else if (type[0]=='n')
2860   {
2861     /* node remove  */
2862     i=iremove(&set[setNr].node, set[setNr].anz_n, number);
2863     if(i<set[setNr].anz_n)
2864     {
2865       set[setNr].anz_n=i;
2866     }
2867     else { if(printFlag) printf(" node:%d not in set:%s\n", number, set[setNr].name); }
2868   }
2869   else if (type[0]=='e')
2870   {
2871     /* element remove  */
2872     i=iremove(&set[setNr].elem, set[setNr].anz_e, number);
2873     if(i<set[setNr].anz_e)
2874     {
2875       set[setNr].anz_e=i;
2876     }
2877     else { if(printFlag) printf(" element:%d not in set:%s\n", number, set[setNr].name); }
2878   }
2879   else if (type[0]=='f')
2880   {
2881     /* element remove  */
2882     i=iremove(&set[setNr].face, set[setNr].anz_f, number);
2883     if(i<set[setNr].anz_f)
2884     {
2885       set[setNr].anz_f=i;
2886     }
2887     else { if(printFlag) printf(" face:%d not in set:%s\n", number, set[setNr].name); }
2888   }
2889   else if (type[0]=='p')
2890   {
2891     /* point remove  */
2892     i=iremove(&set[setNr].pnt, set[setNr].anz_p, number);
2893     if(i<set[setNr].anz_p)
2894     {
2895       set[setNr].anz_p=i;
2896 
2897       /* remove also embedded nodes */
2898       for (j=0; j<point[number].nn; j++)
2899       {
2900         set[setNr].anz_n=iremove(&set[setNr].node, set[setNr].anz_n, point[number].nod[j]);
2901       }
2902     }
2903     else { if(printFlag) printf(" pnt:%s not in set:%s\n", point[number].name, set[setNr].name); }
2904   }
2905   else if (type[0]=='l')
2906   {
2907     /* line remove  */
2908     i=iremove(&set[setNr].line, set[setNr].anz_l, number);
2909     if(i<set[setNr].anz_l)
2910     {
2911       set[setNr].anz_l=i;
2912 
2913       /* remove also embedded nodes */
2914       for (j=0; j<line[number].nn; j++)
2915       {
2916         set[setNr].anz_n=iremove(&set[setNr].node, set[setNr].anz_n, line[number].nod[j]);
2917       }
2918 
2919       /* remove also embedded elements */
2920       for (j=0; j<line[number].ne; j++)
2921       {
2922         set[setNr].anz_e=iremove(&set[setNr].elem, set[setNr].anz_e, line[number].elem[j]);
2923       }
2924     }
2925     else { if(printFlag) printf(" line:%s not in set:%s\n", line[number].name, set[setNr].name); }
2926   }
2927   else if (type[0]=='c')
2928   {
2929     /* lcmb remove  */
2930     i=iremove(&set[setNr].lcmb, set[setNr].anz_c, number);
2931     if(i<set[setNr].anz_c)
2932     {
2933       set[setNr].anz_c=i;
2934     }
2935     else{  if(printFlag) printf(" lcmb:%s not in set:%s\n", lcmb[number].name, set[setNr].name); }
2936   }
2937   else if (type[0]=='s')
2938   {
2939     /* surface remove  */
2940     i=iremove(&set[setNr].surf, set[setNr].anz_s, number);
2941     if(i<set[setNr].anz_s)
2942     {
2943       set[setNr].anz_s=i;
2944 
2945       /* remove also embedded nodes */
2946       for (j=0; j<surf[number].nn; j++)
2947       {
2948         set[setNr].anz_n=iremove(&set[setNr].node, set[setNr].anz_n, surf[number].nod[j]);
2949       }
2950 
2951       /* remove also embedded elements */
2952       for (j=0; j<surf[number].ne; j++)
2953       {
2954         set[setNr].anz_e=iremove(&set[setNr].elem, set[setNr].anz_e, surf[number].elem[j]);
2955       }
2956     }
2957     else{  if(printFlag) printf(" surf:%s not in set:%s\n", surf[number].name, set[setNr].name); }
2958   }
2959   else if (type[0]=='b')
2960   {
2961     /* body remove  */
2962     i=iremove(&set[setNr].body, set[setNr].anz_b, number);
2963     if(i<set[setNr].anz_b)
2964     {
2965       set[setNr].anz_b=i;
2966 
2967       /* remove also embedded nodes */
2968       for (j=0; j<body[number].nn; j++)
2969       {
2970         set[setNr].anz_n=iremove(&set[setNr].node, set[setNr].anz_n, body[number].nod[j]);
2971       }
2972 
2973       /* remove also embedded elements */
2974       for (j=0; j<body[number].ne; j++)
2975       {
2976         set[setNr].anz_e=iremove(&set[setNr].elem, set[setNr].anz_e, body[number].elem[j]);
2977       }
2978     }
2979     else{ if(printFlag) printf(" body:%s not in set:%s\n", body[number].name, set[setNr].name); }
2980   }
2981   else if (type[0]=='L')
2982   {
2983     /* nurl remove  */
2984     i=iremove(&set[setNr].nurl, set[setNr].anz_nurl, number);
2985     if(i<set[setNr].anz_nurl)
2986     {
2987       set[setNr].anz_nurl=i;
2988     }
2989     else{ if(printFlag) printf(" nurl:%s not in set:%s\n", nurbl[number].name, set[setNr].name); }
2990   }
2991   else if (type[0]=='S')
2992   {
2993     /* nurs remove  */
2994     i=iremove(&set[setNr].nurs, set[setNr].anz_nurs, number);
2995     if(i<set[setNr].anz_nurs)
2996     {
2997       set[setNr].anz_nurs=i;
2998     }
2999     else{ if(printFlag) printf(" nurs:%s not in set:%s\n", nurbs[number].name, set[setNr].name); }
3000   }
3001   else if ( type[0] == 'j' )
3002   {
3003     if(number<set[setNr].anz_elf-1)
3004     {
3005       for ( i=number; i<set[setNr].anz_elf-1; i++)
3006       {
3007         set[setNr].elf[number].e=set[setNr].elf[number+1].e;
3008         set[setNr].elf[number].f=set[setNr].elf[number+1].f;
3009       }
3010       if((set[setNr].elf= (Elfaces *)realloc(set[setNr].elf, (set[setNr].anz_elf)*sizeof(Elfaces))) == NULL )
3011       { printf("ERROR: realloc failed in seta()\n\n" ); return(-1); }
3012       set[setNr].anz_elf--;
3013     }
3014     else if(number==set[setNr].anz_elf-1)
3015     {
3016       if((set[setNr].elf= (Elfaces *)realloc(set[setNr].elf, (set[setNr].anz_elf)*sizeof(Elfaces))) == NULL )
3017       { printf("ERROR: realloc failed in seta()\n\n" ); return(-1); }
3018       set[setNr].anz_elf--;
3019     }
3020     else{ if(printFlag) printf(" elf:%d not in set:%s\n", number, set[setNr].name); }
3021   }
3022   else
3023   {
3024     errMsg ("WARNING: in setr type:%s not recognized\n", type );
3025     return(-1);
3026   }
3027   return(1);
3028 }
3029 
3030 
3031 /*  seqr works only for sequences (set[].type==1) with points and nodes */
seqr(int setNr,char * type,int number)3032 int seqr( int setNr, char *type, int number)
3033 {
3034   int i, n;
3035   int *puf=NULL;
3036   int flag=0;
3037 
3038   if( set[setNr].name == (char *)NULL )
3039   {
3040     errMsg(" ERROR: setNr:%d is undefined\n", setNr);
3041     return(0);
3042   }
3043   if( number<0)
3044   {
3045     errMsg(" ERROR in seqr: A negative entity-index:%d was used\n", number);
3046     return(-1);
3047   }
3048 
3049   if ( set[setNr].type!=1)
3050   {
3051     errMsg(" FATAL ERROR: in seqr, set:%s is not a sequence\n", set[setNr].name );
3052   }
3053   else if (type[0]=='n')
3054   {
3055     /* puffer allocieren  */
3056     if ( (puf = (int *)malloc( (set[setNr].anz_n+1)*sizeof(int))) == NULL )
3057       printf(" ERROR: malloc failed in setr\n\n");
3058 
3059     n=0;
3060     for ( i=0; i<set[setNr].anz_n; i++)
3061     {
3062       if (set[setNr].node[i] != number)
3063       {
3064         puf[n] = set[setNr].node[i];
3065         n++;
3066       }
3067       else
3068         flag=1;
3069     }
3070 
3071     if (flag)
3072     {
3073       set[setNr].anz_n--;
3074       /* if the set is empty, delete the set */
3075       if((set[setNr].anz_p <1)&& (set[setNr].anz_n <1))
3076       {
3077         delSet(set[setNr].name); free(puf); return(0);
3078       }
3079       if ((set[setNr].node = (int *)realloc( (int *)set[setNr].node,(set[setNr].anz_n+1)*sizeof(int)) ) == NULL)
3080       { printf(" ERROR: realloc failed in set[%d]:%s\n\n", setNr, set[setNr].name); free(puf); return(0); }
3081       else if(printFlag)
3082         printf (" set[%d]:%s reallocated and node %d removed\n", setNr, set[setNr].name, number );
3083 
3084       for ( i=0; i<set[setNr].anz_n; i++)
3085       {
3086         set[setNr].node[i] = puf[i];
3087       }
3088     }
3089     else if(printFlag) printf(" node:%d not in set:%s\n", number, set[setNr].name);
3090     free(puf);
3091   }
3092   else if (type[0]=='p')
3093   {
3094     /* puffer allocieren  */
3095     if ( (puf = (int *)malloc( (set[setNr].anz_p+1)*sizeof(int))) == NULL )
3096       printf(" ERROR: malloc failed in setr\n\n");
3097 
3098     n=0;
3099     for ( i=0; i<set[setNr].anz_p; i++)
3100     {
3101       if (set[setNr].pnt[i] != number)
3102       {
3103         puf[n] = set[setNr].pnt[i];
3104         n++;
3105       }
3106       else
3107         flag=1;
3108     }
3109 
3110     if (flag)
3111     {
3112       set[setNr].anz_p--;
3113       /* if the set is empty, delete the set */
3114       if((set[setNr].anz_p <1)&& (set[setNr].anz_n <1))
3115       {
3116         /* suche abhaengige linien, redefine if necessary */
3117         for (i=0; i<anzGeo->l; i++)
3118         {
3119           if(( line[i].typ == 's' )&&( setNr == line[i].trk ))
3120           {
3121             line[i].typ = ' ';
3122           }
3123         }
3124         delSet(set[setNr].name); free(puf); return(0);
3125       }
3126       if ((set[setNr].pnt = (int *)realloc( (int *)set[setNr].pnt,(set[setNr].anz_p+1)*sizeof(int)) ) == NULL)
3127       { printf(" ERROR: realloc failed in set[%d]:%s\n\n", setNr, set[setNr].name); free(puf); return(0); }
3128       else if(printFlag)
3129         printf (" set[%d]:%s reallocated and pnt %s removed\n", setNr, set[setNr].name, point[number].name );
3130 
3131       for ( i=0; i<set[setNr].anz_p; i++)
3132       {
3133         set[setNr].pnt[i] = puf[i];
3134       }
3135     }
3136     else if(printFlag) printf(" pnt:%s not in set:%s\n", point[number].name, set[setNr].name);
3137     free(puf);
3138   }
3139   return(1);
3140 }
3141 
3142 
calcLineLength(int l)3143 double calcLineLength(int l)
3144 {
3145   int n;
3146   double p1[3], p2[3], p1p2[3], lp1p2, lmax=0.;
3147 
3148   repLine(l);
3149   p1[0]=line[l].ip[0]*scale->w+scale->x;
3150   p1[1]=line[l].ip[1]*scale->w+scale->y;
3151   p1[2]=line[l].ip[2]*scale->w+scale->z;
3152   for (n=3; n<line[l].nip; n+=3)
3153   {
3154     p2[0]=line[l].ip[n]*scale->w+scale->x;
3155     p2[1]=line[l].ip[n+1]*scale->w+scale->y;
3156     p2[2]=line[l].ip[n+2]*scale->w+scale->z;
3157     v_result( p1, p2, p1p2 );
3158     lp1p2=v_betrag( p1p2 );
3159     lmax+=lp1p2;
3160 
3161     p1[0]=p2[0];
3162     p1[1]=p2[1];
3163     p1[2]=p2[2];
3164   }
3165   return(lmax);
3166 }
3167 
3168 
3169 /* returns 0 if commands are to be skipped */
pre_while(char * type,char ** ptr_string,int * na,int * nb,FILE * handle1,int * addFlag,int * gtolFlag,int wFlag,int ifFlag)3170 int pre_while(char *type, char **ptr_string, int *na, int *nb, FILE *handle1, int *addFlag, int *gtolFlag, int wFlag, int ifFlag)
3171 {
3172   typedef struct{
3173     int flag;              // whileFlag:
3174                            // 0 do not restore and do not not execute
3175                            // 1 execute command
3176                            // 2 store and execute command
3177                            // 3 restore and execute in commandoInterpreter,
3178                            // 4 store command but not execute
3179                            // 5 restore command but not execute
3180     int clines;            // counts command lines
3181     int lineptr;           // points to the active command line in the stack (this parameters of that line will be returned)
3182     int prev_while;        // previous while loop (previous stack)
3183     int *next_while;       // embedded whiles, all while-command lines in the active loop have to be addressed.
3184     int whiles;            // counts embedded while loops
3185     int whileptr;          // points to the next embedded while loop
3186     char arg1[MAX_LINE_LENGTH];
3187     char arg2[MAX_LINE_LENGTH];
3188     char operator[MAX_LINE_LENGTH];
3189     char **type;           // command name
3190     char **string;         // complete command string
3191     int *na;
3192     int *nb;
3193     FILE **handle1;
3194     int *addFlag;
3195     int *gtolFlag;
3196   }whileStack;
3197 
3198   static whileStack *stack=NULL;
3199   static int stack_ptr=-1;             // active while loop
3200   static int nwhiles=0;             // allocated loops
3201   int   i,j;
3202   int   new_length,flag;
3203   char  arg1[MAX_LINE_LENGTH], operator[MAX_LINE_LENGTH], arg2[MAX_LINE_LENGTH];
3204 
3205   //printf("hallo in pre_while: type:%s str:%s nab:%d %d addf:%d gtolf:%d ",type,*ptr_string,*na,*nb,*addFlag,*gtolFlag);
3206   //printf("hallo whileFlag:%d\n",wFlag);
3207 
3208   // store the command
3209   // wFlag==2,4: save the command (makes here no difference)
3210   if((wFlag==2)||(wFlag==4))
3211   {
3212     if ((stack[stack_ptr].type = (char **)realloc(stack[stack_ptr].type, (stack[stack_ptr].clines+1)*sizeof(char *)) ) == NULL )
3213     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3214     if ((stack[stack_ptr].type[stack[stack_ptr].clines] = (char *)malloc( (strlen(type)+1)*sizeof(char)) ) == NULL )
3215     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3216     strcpy(stack[stack_ptr].type[stack[stack_ptr].clines], type);
3217 
3218     if ((stack[stack_ptr].string = (char **)realloc(stack[stack_ptr].string, (stack[stack_ptr].clines+1)*sizeof(char *)) ) == NULL )
3219     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3220     if ((stack[stack_ptr].string[stack[stack_ptr].clines] = (char *)malloc( (strlen(*ptr_string)+2)*sizeof(char)) ) == NULL )
3221     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3222     strcpy(stack[stack_ptr].string[stack[stack_ptr].clines], *ptr_string);
3223 
3224     if ((stack[stack_ptr].na = (int *)realloc(stack[stack_ptr].na, (stack[stack_ptr].clines+1)*sizeof(int)) ) == NULL )
3225     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3226     stack[stack_ptr].na[stack[stack_ptr].clines]=*na;
3227 
3228     if ((stack[stack_ptr].nb = (int *)realloc(stack[stack_ptr].nb, (stack[stack_ptr].clines+1)*sizeof(int)) ) == NULL )
3229     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3230     stack[stack_ptr].nb[stack[stack_ptr].clines]=*nb;
3231 
3232     if ((stack[stack_ptr].handle1 = (FILE **)realloc(stack[stack_ptr].handle1, (stack[stack_ptr].clines+1)*sizeof(FILE *)) ) == NULL )
3233     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3234     stack[stack_ptr].handle1[stack[stack_ptr].clines]=handle1;
3235 
3236     if ((stack[stack_ptr].addFlag = (int *)realloc(stack[stack_ptr].addFlag, (stack[stack_ptr].clines+1)*sizeof(int)) ) == NULL )
3237     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3238     stack[stack_ptr].addFlag[stack[stack_ptr].clines]=*addFlag;
3239 
3240     if ((stack[stack_ptr].gtolFlag = (int *)realloc(stack[stack_ptr].gtolFlag, (stack[stack_ptr].clines+1)*sizeof(int)) ) == NULL )
3241     { printf("\n\nERROR: realloc failure, whilestack\n\n"); return(1); }
3242     stack[stack_ptr].gtolFlag[stack[stack_ptr].clines]=*gtolFlag;
3243 
3244     stack[stack_ptr].clines++;
3245 
3246     //printf("hallo stored command[%d]:%s \n",stack[stack_ptr].clines, *ptr_string);
3247     return(wFlag);// unmodified
3248   }
3249 
3250   // restore the next command
3251   else if((wFlag==3)||(wFlag==5))
3252   {
3253     if(stack[stack_ptr].lineptr<stack[stack_ptr].clines)
3254     {
3255       strcpy(type,stack[stack_ptr].type[stack[stack_ptr].lineptr]);
3256       new_length=strlen(stack[stack_ptr].string[stack[stack_ptr].lineptr])+1;
3257       if(new_length<MAX_LINE_LENGTH) new_length=MAX_LINE_LENGTH;
3258       if( (*ptr_string=realloc(*ptr_string, (new_length)*sizeof(char)))== NULL ) { printf(" ERROR: realloc failed in pre_while()\n"); return(0); }
3259       *ptr_string[0]=0;
3260       strcpy(*ptr_string,stack[stack_ptr].string[stack[stack_ptr].lineptr]);
3261       *na=stack[stack_ptr].na[stack[stack_ptr].lineptr];
3262       *nb=stack[stack_ptr].nb[stack[stack_ptr].lineptr];
3263       handle1=stack[stack_ptr].handle1[stack[stack_ptr].lineptr];
3264       *addFlag=stack[stack_ptr].addFlag[stack[stack_ptr].lineptr];
3265       *gtolFlag=stack[stack_ptr].gtolFlag[stack[stack_ptr].lineptr];
3266       stack[stack_ptr].lineptr++;
3267     }
3268     else { printf("ERROR: in while, no more commands (%d from %d stack_ptr:%d\n", stack[stack_ptr].lineptr, stack[stack_ptr].clines, stack_ptr); exit(0); }
3269 
3270     //printf("hallo restored command[%d]:%s\n", stack[stack_ptr].lineptr, *ptr_string );
3271     return(wFlag); // unmodified
3272   }
3273 
3274   else if(compare( type,"WHILE",2)==2 )
3275   {
3276     //printf("hallo %s stackptr:%d\n",type,stack_ptr);
3277 
3278     sscanf(*ptr_string, "%*s %s %s %s", arg1, operator, arg2);
3279 
3280     i=getValuNr(arg1);
3281     if (i>-1) strcpy(arg1,value[i].string );
3282     i=getValuNr(arg2);
3283     if (i>-1) strcpy(arg2,value[i].string );
3284 
3285     if((operator[0]=='e')&&(operator[1]=='q')) { if(compareStrings(arg1,arg2)>0) flag=3; else flag=0; }
3286     else if((operator[0]=='n')&&(operator[1]=='e')) { if(compareStrings(arg1,arg2)<1) flag=3; else flag=0; }
3287     else if((operator[0]=='=')&&(operator[1]=='=')) { if(atof(arg1)==atof(arg2)) flag=3; else flag=0; }
3288     else if((operator[0]=='!')&&(operator[1]=='=')) { if(atof(arg1)!=atof(arg2)) flag=3; else flag=0; }
3289     else if(operator[0]=='>') { if(atof(arg1)>atof(arg2)) flag=3; else flag=0; }
3290     else if(operator[0]=='<') { if(atof(arg1)<atof(arg2)) flag=3; else flag=0; }
3291     else { printf("ERROR: operator not known:%s\n", operator); flag=1; }
3292 
3293     //printf(" args:%s %s\n",arg1,arg2);
3294     //printf(" nwhiles:%d stackptr:%d flag:%d wflag:%d\n", nwhiles, stack_ptr, flag, wFlag);
3295     if(flag==1) return(1);  // error or strings are not equal
3296 
3297 
3298     if((wFlag==-3)||(wFlag==-5)) // restore the next command
3299     {
3300       //printf(" an open while (stack_ptr:%d) references this while:%d in a sequencial order:%d\n",stack_ptr, stack[stack_ptr].next_while[stack[stack_ptr].whileptr], stack[stack_ptr].whileptr);
3301       stack_ptr=stack[stack_ptr].next_while[stack[stack_ptr].whileptr++];        // set the pointer to the next while
3302       //printf(" change stack_ptr to:%d\n", stack_ptr);
3303       if((flag==3)&& (wFlag==-3)) stack[stack_ptr].flag=3;  // restore and execute (all commands are stored and repeated)
3304       else stack[stack_ptr].flag=5;  //  restore and do not not execute
3305       return(stack[stack_ptr].flag);
3306     }
3307     else if((stack_ptr<0)||(wFlag==-2)||(wFlag==-4)) // create a new while-stack as long as the commands have to be saved
3308     {
3309       if ((stack = (whileStack *)realloc( (whileStack *)stack, (nwhiles+1)*sizeof(whileStack)) ) == NULL )
3310       { printf("\n\nERROR: realloc failure, whileStack\n\n"); return(1); }
3311       if((flag==3)&&(wFlag>=-2)) stack[nwhiles].flag=2;  // store and execute
3312       else stack[nwhiles].flag=4;  // store but not execute
3313       stack[nwhiles].whileptr=0;
3314       stack[nwhiles].clines=0;
3315       stack[nwhiles].prev_while=stack_ptr;
3316       stack[nwhiles].whiles=-1;
3317       stack[nwhiles].next_while=NULL;
3318       // an eventually open while has to reference this while in a sequencial order
3319       if(stack_ptr>-1)
3320       {
3321         stack[stack_ptr].whiles++;
3322         //printf(" an open while (stack_ptr:%d) will reference this while:%d in a sequencial order:%d\n",stack_ptr, nwhiles, stack[stack_ptr].whiles);
3323         if ((stack[stack_ptr].next_while = (int *)realloc(stack[stack_ptr].next_while , (stack[stack_ptr].whiles+1)*sizeof(int)) ) == NULL )
3324         { printf("\n\nERROR: realloc failure, whileStack\n\n"); return(1); }
3325         stack[stack_ptr].next_while[stack[stack_ptr].whiles]=nwhiles;
3326       }
3327       sscanf(*ptr_string, "%*s %s %s %s", arg1, operator, arg2);
3328       strcpy(stack[nwhiles].arg1,arg1);
3329       strcpy(stack[nwhiles].arg2,arg2);
3330       strcpy(stack[nwhiles].operator,operator);
3331       stack[nwhiles].type=NULL;
3332       stack[nwhiles].string=NULL;
3333       stack[nwhiles].na=NULL;
3334       stack[nwhiles].nb=NULL;
3335       stack[nwhiles].handle1=NULL;
3336       stack[nwhiles].addFlag=NULL;
3337       stack[nwhiles].gtolFlag=NULL;
3338       stack_ptr=nwhiles;
3339       //printf(" new stack_ptr:%d\n", stack_ptr);
3340       return(stack[nwhiles++].flag);
3341     }
3342     printf(" talk to the programmer! should NEVER be here.  stack_ptr:%d flag:%d\n", stack_ptr, flag); exit(0);
3343   }
3344 
3345   else if(compare( type,"ENDWHILE",3)==3 )
3346   {
3347     //printf("hallo %s stackptr:%d stack[stack_ptr].flag:%d ifFlag:%d\n",type,stack_ptr, stack[stack_ptr].flag, ifFlag);
3348 
3349     // if the while was skipped from the beginning continue executing
3350     if((stack[stack_ptr].flag == 0)||(stack[stack_ptr].flag == 4))
3351     {
3352       // for seriell whiles the stack_ptr has to be decreased by the amount of seriell whiles
3353       stack[stack_ptr].lineptr=0;
3354       stack_ptr = stack[stack_ptr].prev_while;
3355       //printf("  3 changed stack_ptr:%d\n", stack_ptr);
3356       if(stack_ptr>=0)
3357         return(stack[stack_ptr].flag);
3358       else return(1);
3359     }
3360     else
3361     {
3362       // reset the embedded while counter
3363       stack[stack_ptr].whileptr=0;
3364       stack[stack_ptr].lineptr=0;
3365 
3366       // restore the command line to check if the loop has finished
3367       strcpy(arg1,stack[stack_ptr].arg1);
3368       strcpy(arg2,stack[stack_ptr].arg2);
3369       strcpy(operator,stack[stack_ptr].operator);
3370 	//printf(" 1args:%s %s  operator:%s\n",arg1,arg2,operator);
3371 
3372       i=getValuNr(arg1);
3373       if (i>-1) strcpy(arg1,value[i].string );
3374       i=getValuNr(arg2);
3375       if (i>-1) strcpy(arg2,value[i].string );
3376 	//printf(" 2args:%s %s  operator:%s\n",arg1,arg2,operator);
3377 
3378       if((operator[0]=='e')&&(operator[1]=='q')) { if(compareStrings(arg1,arg2)>0) flag=3; else flag=1; }
3379       else if((operator[0]=='n')&&(operator[1]=='e')) { if(compareStrings(arg1,arg2)<1) flag=3; else flag=1; }
3380       else if((operator[0]=='=')&&(operator[1]=='=')) { if(atof(arg1)==atof(arg2)) flag=3; else flag=1; }
3381       else if((operator[0]=='!')&&(operator[1]=='=')) { if(atof(arg1)!=atof(arg2)) flag=3; else flag=1; }
3382       else if(operator[0]=='>') { if(atof(arg1)>atof(arg2)) flag=3; else flag=1; }
3383       else if(operator[0]=='<') { if(atof(arg1)<atof(arg2)) flag=3; else flag=1; }
3384       else { printf("ERROR: operator not known:%s\n", operator); flag=1; }
3385       stack[stack_ptr].flag=flag;
3386 
3387       //printf("  flag:%d\n", flag);
3388 
3389       // if finished
3390       if((flag==1)||(ifFlag==0))
3391       {
3392         stack_ptr = stack[stack_ptr].prev_while;
3393 	//printf("  4 changed stack_ptr:%d new_flag:%d\n", stack_ptr, stack[stack_ptr].flag);
3394 
3395         // free if stack_ptr is <0 (first while is closed)
3396 	if(stack_ptr<0)
3397 	{
3398 	  for(i=0; i<nwhiles; i++)
3399 	  {
3400 	    for(j=0; j<stack[i].clines; j++)
3401 	    {
3402               free(stack[i].type[j]);
3403               free(stack[i].string[j]);
3404             }
3405             free(stack[i].next_while);
3406             free(stack[i].type);
3407             free(stack[i].string);
3408             free(stack[i].na);
3409             free(stack[i].nb);
3410             free(stack[i].handle1);
3411             free(stack[i].addFlag);
3412             free(stack[i].gtolFlag);
3413             stack[i].type=NULL;
3414             stack[i].string=NULL;
3415             stack[i].next_while=NULL;
3416             stack[i].na=NULL;
3417             stack[i].nb=NULL;
3418             stack[i].handle1=NULL;
3419             stack[i].addFlag=NULL;
3420             stack[i].gtolFlag=NULL;
3421 
3422 	  }
3423           nwhiles=0;
3424 	}
3425         if(stack_ptr>=0)
3426           return(stack[stack_ptr].flag);
3427         else return(1);
3428       }
3429       return(3);
3430     }
3431   }
3432 
3433   //printf("hallo return pre_while\n");
3434   return(0);
3435 }
3436 
3437 
3438 /* returns 0 if commands are to be skipped */
pre_if(char * string)3439 int pre_if(char *string)
3440 {
3441   int i,args, flag;
3442   char type[MAX_LINE_LENGTH], arg1[MAX_LINE_LENGTH], operator[MAX_LINE_LENGTH], arg2[MAX_LINE_LENGTH];
3443 
3444   /* stack for the 'if' blocks */
3445   static int *ifstack=NULL;
3446   static int *ifdone=NULL;
3447   static int ifstack_ptr=0;
3448 
3449 
3450   //printf("IF string:%s\n",string);
3451   args=sscanf(string, "%s %s %s %s", type, arg1, operator, arg2);
3452   for(i=0;i<strlen(type); i++) type[i]=toupper(type[i]);
3453 
3454   if(compare( type,"IF",2)==2 )
3455   {
3456     if((operator[0]=='e')&&(operator[1]=='q')) { if(compareStrings(arg1,arg2)>0) flag=1; else flag=0; }
3457     else if((operator[0]=='n')&&(operator[1]=='e')) { if(compareStrings(arg1,arg2)<1) flag=1; else flag=0; }
3458     else if((operator[0]=='=')&&(operator[1]=='=')) { if(atof(arg1)==atof(arg2)) flag=1; else flag=0; }
3459     else if((operator[0]=='!')&&(operator[1]=='=')) { if(atof(arg1)!=atof(arg2)) flag=1; else flag=0; }
3460     else if(operator[0]=='>') { if(atof(arg1)>atof(arg2)) flag=1; else flag=0; }
3461     else if(operator[0]=='<') { if(atof(arg1)<atof(arg2)) flag=1; else flag=0; }
3462     else { printf("ERROR: operator not known:%s\n", operator); flag=1; }
3463 
3464     if ((ifstack = (int *)realloc( (int *)ifstack, (ifstack_ptr+1)*sizeof(int)) ) == NULL )
3465       { printf("\n\nERROR: realloc failure, ifstack ptr:%d\n\n", ifstack_ptr); return(1); }
3466     if ((ifdone = (int *)realloc( (int *)ifdone, (ifstack_ptr+1)*sizeof(int)) ) == NULL )
3467     { printf("\n\nERROR: realloc failure, ifdone ptr:%d\n\n", ifstack_ptr); return(1); }
3468     ifstack[ifstack_ptr]=flag;
3469     ifdone[ifstack_ptr]=flag;
3470     //printf(" IF stackptr:%d ifdone = flag:%d\n",ifstack_ptr,flag);
3471     // check if the block is active
3472     for(i=0; i<ifstack_ptr; i++) { if(!ifstack[i] ) { flag=0; break; }}
3473     //printf(" upper if states checked: flag:%d\n",flag);
3474     ifstack_ptr++;
3475     return(flag);
3476   }
3477   else if(compare( type,"ELSE",2)==2 )
3478   {
3479     if(ifstack_ptr>0)
3480     {
3481       if(args>1)
3482       {
3483         for(i=0;i<strlen(arg1); i++) arg1[i]=toupper(arg1[i]);
3484         if(compare( arg1,"IF",2)==2 )
3485 	{
3486           sscanf(string, "%*s %*s %s %s %s", arg1, operator, arg2);
3487           if((operator[0]=='e')&&(operator[1]=='q')) { if(compareStrings(arg1,arg2)>0) flag=1; else flag=0; }
3488           else if((operator[0]=='n')&&(operator[1]=='e')) { if(compareStrings(arg1,arg2)<1) flag=1; else flag=0; }
3489           else if((operator[0]=='=')&&(operator[1]=='=')) { if(atof(arg1)==atof(arg2)) flag=1; else flag=0; }
3490           else if((operator[0]=='!')&&(operator[1]=='=')) { if(atof(arg1)!=atof(arg2)) flag=1; else flag=0; }
3491           else if(operator[0]=='>') { if(atof(arg1)>atof(arg2)) flag=1; else flag=0; }
3492           else if(operator[0]=='<') { if(atof(arg1)<atof(arg2)) flag=1; else flag=0; }
3493           else { printf("ERROR: operator not known:%s\n", operator); flag=1; }
3494           if(ifdone[ifstack_ptr-1]==1) flag=0;
3495           ifstack[ifstack_ptr-1]=flag;
3496           if(flag==1) ifdone[ifstack_ptr-1]=1;
3497           // check if the block is active
3498           for(i=0; i<ifstack_ptr-1; i++) { if(!ifstack[i] ) { flag=0; break; }}
3499           //printf(" upper if states checked: flag:%d\n",flag);
3500           return(flag);
3501 	}
3502       }
3503       else
3504       {
3505          if(ifdone[ifstack_ptr-1]==1) flag=0; else flag=1;
3506         ifstack[ifstack_ptr-1]=flag;
3507         if(flag==1) ifdone[ifstack_ptr-1]=1;
3508         //printf(" ELSE stackptr:%d flag:%d ifdone:%d\n",ifstack_ptr-1, flag, ifdone[ifstack_ptr-1]);
3509         // check if the block is active
3510         for(i=0; i<ifstack_ptr-1; i++) { if(!ifstack[i] ) { flag=0; break; }}
3511         //printf(" upper if states checked: flag:%d\n",flag);
3512         return(flag);
3513       }
3514     }
3515     else return(1);
3516   }
3517   else if(compare( type,"ENDIF",2)==2 )
3518   {
3519     ifdone[ifstack_ptr-1]=flag=1;
3520     //printf(" ENDIF stackptr:%d flag:%d\n",ifstack_ptr-1, flag);
3521     // check if the block is active
3522     for(i=0; i<ifstack_ptr-1; i++) { if(!ifstack[i] ) { flag=0; break; }}
3523     //printf(" upper if states checked: flag:%d\n",flag);
3524     ifstack_ptr--;
3525     return(flag);
3526   }
3527 
3528   return(0);
3529 }
3530 
3531 
pre_length(char * setname)3532 double pre_length(char *setname)
3533 {
3534   int   i,n;
3535   int   setNr,l;
3536   double L=0, Ll=0;
3537   //double sum_valLe=0., value=0.;
3538 
3539   setNr=getSetNr(setname);
3540   if (setNr<0)
3541   {
3542     printf (" ERROR: set:%s does not exist\n", setname);
3543     return(-1);
3544   }
3545 
3546   for(i=0; i<set[setNr].anz_l; i++)
3547   {
3548     l=set[setNr].line[i];
3549     Ll=calcLineLength(l);
3550     L+=Ll;
3551   }
3552   printf("LENGTH:%e", L);
3553   //if(anz->l) printf(" AVERAGE-VALUE:%f\n", sum_valLe/vol);
3554   //else
3555     printf("\n");
3556   if(valuestackFlag)
3557   {
3558     n=1;
3559     if ((valuestack = (char **)realloc( (char **)valuestack, (valuestack_ptr+n)*sizeof(char *)) ) == NULL )
3560     { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
3561     for(i=0; i<n; i++)
3562     {
3563       if ((valuestack[valuestack_ptr+i] = (char *)malloc( MAX_LINE_LENGTH*sizeof(char)) ) == NULL )
3564       { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
3565     }
3566     sprintf(valuestack[valuestack_ptr++],"%e", L );
3567     printf(" written to stack\n");
3568   }
3569 
3570   return(L);
3571 }
3572 
3573 
pre_area(char * setname)3574 double pre_area(char *setname)
3575 {
3576   int   i,j,n;
3577   int   nr, setNr;
3578   double A=0., Ae, Abuf, p[3][3], pcg[3], Ix, Iy, Ixy;
3579   double xcg=0., ycg=0., zcg=0.;
3580   double sum_valAe=0., value=0.;
3581 
3582   setNr=getSetNr(setname);
3583   if (setNr<0)
3584   {
3585     printf (" ERROR: set:%s does not exist\n", setname);
3586     return(-1);
3587   }
3588   if (set[setNr].anz_f<1)
3589   {
3590     printf (" ERROR: set:%s does not contain faces\n", setname);
3591     return(-1);
3592   }
3593 
3594   for(i=0; i<set[setNr].anz_f; i++)
3595   {
3596     Abuf=A;
3597     nr=set[setNr].face[i];
3598     switch(face[nr].type)
3599     {
3600       case 7:
3601       for(j=0; j<3; j++)
3602       {
3603         p[j][0]=node[face[nr].nod[j]].nx*scale->w+scale->x;
3604         p[j][1]=node[face[nr].nod[j]].ny*scale->w+scale->y;
3605         p[j][2]=node[face[nr].nod[j]].nz*scale->w+scale->z;
3606       }
3607       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3608       {
3609         A+=Ae;
3610         xcg+=pcg[0]*Ae;
3611         ycg+=pcg[1]*Ae;
3612         zcg+=pcg[2]*Ae;
3613       }
3614       break;
3615 
3616 
3617       case 8:
3618       p[0][0]=node[face[nr].nod[0]].nx*scale->w+scale->x;
3619       p[0][1]=node[face[nr].nod[0]].ny*scale->w+scale->y;
3620       p[0][2]=node[face[nr].nod[0]].nz*scale->w+scale->z;
3621       p[1][0]=node[face[nr].nod[3]].nx*scale->w+scale->x;
3622       p[1][1]=node[face[nr].nod[3]].ny*scale->w+scale->y;
3623       p[1][2]=node[face[nr].nod[3]].nz*scale->w+scale->z;
3624       p[2][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3625       p[2][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3626       p[2][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3627       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3628       {
3629         A+=Ae;
3630         xcg+=pcg[0]*Ae;
3631         ycg+=pcg[1]*Ae;
3632         zcg+=pcg[2]*Ae;
3633       }
3634       p[0][0]=node[face[nr].nod[3]].nx*scale->w+scale->x;
3635       p[0][1]=node[face[nr].nod[3]].ny*scale->w+scale->y;
3636       p[0][2]=node[face[nr].nod[3]].nz*scale->w+scale->z;
3637       p[1][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3638       p[1][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3639       p[1][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3640       p[2][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3641       p[2][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3642       p[2][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3643       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3644       {
3645         A+=Ae;
3646         xcg+=pcg[0]*Ae;
3647         ycg+=pcg[1]*Ae;
3648         zcg+=pcg[2]*Ae;
3649       }
3650       p[0][0]=node[face[nr].nod[3]].nx*scale->w+scale->x;
3651       p[0][1]=node[face[nr].nod[3]].ny*scale->w+scale->y;
3652       p[0][2]=node[face[nr].nod[3]].nz*scale->w+scale->z;
3653       p[1][0]=node[face[nr].nod[1]].nx*scale->w+scale->x;
3654       p[1][1]=node[face[nr].nod[1]].ny*scale->w+scale->y;
3655       p[1][2]=node[face[nr].nod[1]].nz*scale->w+scale->z;
3656       p[2][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3657       p[2][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3658       p[2][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3659       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3660       {
3661         A+=Ae;
3662         xcg+=pcg[0]*Ae;
3663         ycg+=pcg[1]*Ae;
3664         zcg+=pcg[2]*Ae;
3665       }
3666       p[0][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3667       p[0][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3668       p[0][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3669       p[1][0]=node[face[nr].nod[2]].nx*scale->w+scale->x;
3670       p[1][1]=node[face[nr].nod[2]].ny*scale->w+scale->y;
3671       p[1][2]=node[face[nr].nod[2]].nz*scale->w+scale->z;
3672       p[2][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3673       p[2][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3674       p[2][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3675       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3676       {
3677         A+=Ae;
3678         xcg+=pcg[0]*Ae;
3679         ycg+=pcg[1]*Ae;
3680         zcg+=pcg[2]*Ae;
3681       }
3682       break;
3683 
3684 
3685       case 9:
3686       for(j=0; j<3; j++)
3687       {
3688         p[j][0]=node[face[nr].nod[j]].nx*scale->w+scale->x;
3689         p[j][1]=node[face[nr].nod[j]].ny*scale->w+scale->y;
3690         p[j][2]=node[face[nr].nod[j]].nz*scale->w+scale->z;
3691       }
3692       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3693       {
3694         A+=Ae;
3695         xcg+=pcg[0]*Ae;
3696         ycg+=pcg[1]*Ae;
3697         zcg+=pcg[2]*Ae;
3698       }
3699       n=j=0;
3700       p[n][0]=node[face[nr].nod[j]].nx*scale->w+scale->x;
3701       p[n][1]=node[face[nr].nod[j]].ny*scale->w+scale->y;
3702       p[n++][2]=node[face[nr].nod[j]].nz*scale->w+scale->z;
3703       for(j=2; j<4; j++)
3704       {
3705         p[n][0]=node[face[nr].nod[j]].nx*scale->w+scale->x;
3706         p[n][1]=node[face[nr].nod[j]].ny*scale->w+scale->y;
3707         p[n++][2]=node[face[nr].nod[j]].nz*scale->w+scale->z;
3708       }
3709       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3710       {
3711         A+=Ae;
3712         xcg+=pcg[0]*Ae;
3713         ycg+=pcg[1]*Ae;
3714         zcg+=pcg[2]*Ae;
3715       }
3716       break;
3717 
3718 
3719       case 10:
3720       p[0][0]=node[face[nr].nod[0]].nx*scale->w+scale->x;
3721       p[0][1]=node[face[nr].nod[0]].ny*scale->w+scale->y;
3722       p[0][2]=node[face[nr].nod[0]].nz*scale->w+scale->z;
3723       p[1][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3724       p[1][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3725       p[1][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3726       p[2][0]=node[face[nr].nod[7]].nx*scale->w+scale->x;
3727       p[2][1]=node[face[nr].nod[7]].ny*scale->w+scale->y;
3728       p[2][2]=node[face[nr].nod[7]].nz*scale->w+scale->z;
3729       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3730       {
3731         A+=Ae;
3732         xcg+=pcg[0]*Ae;
3733         ycg+=pcg[1]*Ae;
3734         zcg+=pcg[2]*Ae;
3735       }
3736       p[0][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3737       p[0][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3738       p[0][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3739       p[1][0]=node[face[nr].nod[8]].nx*scale->w+scale->x;
3740       p[1][1]=node[face[nr].nod[8]].ny*scale->w+scale->y;
3741       p[1][2]=node[face[nr].nod[8]].nz*scale->w+scale->z;
3742       p[2][0]=node[face[nr].nod[7]].nx*scale->w+scale->x;
3743       p[2][1]=node[face[nr].nod[7]].ny*scale->w+scale->y;
3744       p[2][2]=node[face[nr].nod[7]].nz*scale->w+scale->z;
3745       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3746       {
3747         A+=Ae;
3748         xcg+=pcg[0]*Ae;
3749         ycg+=pcg[1]*Ae;
3750         zcg+=pcg[2]*Ae;
3751       }
3752       p[0][0]=node[face[nr].nod[7]].nx*scale->w+scale->x;
3753       p[0][1]=node[face[nr].nod[7]].ny*scale->w+scale->y;
3754       p[0][2]=node[face[nr].nod[7]].nz*scale->w+scale->z;
3755       p[1][0]=node[face[nr].nod[8]].nx*scale->w+scale->x;
3756       p[1][1]=node[face[nr].nod[8]].ny*scale->w+scale->y;
3757       p[1][2]=node[face[nr].nod[8]].nz*scale->w+scale->z;
3758       p[2][0]=node[face[nr].nod[6]].nx*scale->w+scale->x;
3759       p[2][1]=node[face[nr].nod[6]].ny*scale->w+scale->y;
3760       p[2][2]=node[face[nr].nod[6]].nz*scale->w+scale->z;
3761       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3762       {
3763         A+=Ae;
3764         xcg+=pcg[0]*Ae;
3765         ycg+=pcg[1]*Ae;
3766         zcg+=pcg[2]*Ae;
3767       }
3768 
3769       p[0][0]=node[face[nr].nod[7]].nx*scale->w+scale->x;
3770       p[0][1]=node[face[nr].nod[7]].ny*scale->w+scale->y;
3771       p[0][2]=node[face[nr].nod[7]].nz*scale->w+scale->z;
3772       p[1][0]=node[face[nr].nod[6]].nx*scale->w+scale->x;
3773       p[1][1]=node[face[nr].nod[6]].ny*scale->w+scale->y;
3774       p[1][2]=node[face[nr].nod[6]].nz*scale->w+scale->z;
3775       p[2][0]=node[face[nr].nod[3]].nx*scale->w+scale->x;
3776       p[2][1]=node[face[nr].nod[3]].ny*scale->w+scale->y;
3777       p[2][2]=node[face[nr].nod[3]].nz*scale->w+scale->z;
3778       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3779       {
3780         A+=Ae;
3781         xcg+=pcg[0]*Ae;
3782         ycg+=pcg[1]*Ae;
3783         zcg+=pcg[2]*Ae;
3784       }
3785       p[0][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3786       p[0][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3787       p[0][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3788       p[1][0]=node[face[nr].nod[1]].nx*scale->w+scale->x;
3789       p[1][1]=node[face[nr].nod[1]].ny*scale->w+scale->y;
3790       p[1][2]=node[face[nr].nod[1]].nz*scale->w+scale->z;
3791       p[2][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3792       p[2][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3793       p[2][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3794       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3795       {
3796         A+=Ae;
3797         xcg+=pcg[0]*Ae;
3798         ycg+=pcg[1]*Ae;
3799         zcg+=pcg[2]*Ae;
3800       }
3801       p[0][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3802       p[0][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3803       p[0][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3804       p[1][0]=node[face[nr].nod[6]].nx*scale->w+scale->x;
3805       p[1][1]=node[face[nr].nod[6]].ny*scale->w+scale->y;
3806       p[1][2]=node[face[nr].nod[6]].nz*scale->w+scale->z;
3807       p[2][0]=node[face[nr].nod[8]].nx*scale->w+scale->x;
3808       p[2][1]=node[face[nr].nod[8]].ny*scale->w+scale->y;
3809       p[2][2]=node[face[nr].nod[8]].nz*scale->w+scale->z;
3810       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3811       {
3812         A+=Ae;
3813         xcg+=pcg[0]*Ae;
3814         ycg+=pcg[1]*Ae;
3815         zcg+=pcg[2]*Ae;
3816       }
3817       p[0][0]=node[face[nr].nod[8]].nx*scale->w+scale->x;
3818       p[0][1]=node[face[nr].nod[8]].ny*scale->w+scale->y;
3819       p[0][2]=node[face[nr].nod[8]].nz*scale->w+scale->z;
3820       p[1][0]=node[face[nr].nod[4]].nx*scale->w+scale->x;
3821       p[1][1]=node[face[nr].nod[4]].ny*scale->w+scale->y;
3822       p[1][2]=node[face[nr].nod[4]].nz*scale->w+scale->z;
3823       p[2][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3824       p[2][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3825       p[2][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3826       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3827       {
3828         A+=Ae;
3829         xcg+=pcg[0]*Ae;
3830         ycg+=pcg[1]*Ae;
3831         zcg+=pcg[2]*Ae;
3832       }
3833 
3834       p[0][0]=node[face[nr].nod[5]].nx*scale->w+scale->x;
3835       p[0][1]=node[face[nr].nod[5]].ny*scale->w+scale->y;
3836       p[0][2]=node[face[nr].nod[5]].nz*scale->w+scale->z;
3837       p[1][0]=node[face[nr].nod[2]].nx*scale->w+scale->x;
3838       p[1][1]=node[face[nr].nod[2]].ny*scale->w+scale->y;
3839       p[1][2]=node[face[nr].nod[2]].nz*scale->w+scale->z;
3840       p[2][0]=node[face[nr].nod[6]].nx*scale->w+scale->x;
3841       p[2][1]=node[face[nr].nod[6]].ny*scale->w+scale->y;
3842       p[2][2]=node[face[nr].nod[6]].nz*scale->w+scale->z;
3843       if(getGeoDataTria( p[0], p[1], p[2], &Ix, &Iy, &Ixy, &Ae, pcg)!=0)
3844       {
3845         A+=Ae;
3846         xcg+=pcg[0]*Ae;
3847         ycg+=pcg[1]*Ae;
3848         zcg+=pcg[2]*Ae;
3849       }
3850       break;
3851 
3852 
3853       printf("ERROR: type:%d of face:%d not known. Interrupt\n",face[nr].type,nr);
3854       return(-1.);
3855     }
3856 
3857     /* determine the average node-value */
3858     if(anz->l)
3859     {
3860       if (face[nr].type == 7) n = 3;  /* TRI3  */
3861       else if (face[nr].type == 8) n = 6;  /* TRI6  */
3862       else if (face[nr].type == 9) n = 4;  /* QUAD4 */
3863       else if (face[nr].type == 10) n = 8; /* QUAD8 */
3864       else if (face[nr].type == 11) n = 2; /* beam2 */
3865       else if (face[nr].type == 12) n = 3; /* beam3 */
3866       else n=0;
3867       value=0.;
3868       for (j=0; j<n; j++)
3869       {
3870         if(sequenceFlag) value+=lcase[lcase_animList].dat[animList][face[nr].nod[j]];
3871         else value+=lcase[cur_lc].dat[cur_entity][face[nr].nod[j]];
3872       }
3873       sum_valAe+=value/n*(A-Abuf);
3874     }
3875   }
3876   if(anz->l) printf("AREA:%e  CENTER OF GRAVITY: %e %e %e AVERAGE-VALUE:%e\n", A,xcg/A,ycg/A,zcg/A, sum_valAe/A);
3877   else   printf("AREA:%e  CENTER OF GRAVITY: %e %e %e\n", A,xcg/A,ycg/A,zcg/A);
3878 
3879   if(valuestackFlag)
3880   {
3881     if(anz->l) n=5; else n=4;
3882     if ((valuestack = (char **)realloc( (char **)valuestack, (valuestack_ptr+n)*sizeof(char *)) ) == NULL )
3883     { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
3884     for(i=0; i<n; i++)
3885     {
3886       if ((valuestack[valuestack_ptr+i] = (char *)malloc( MAX_LINE_LENGTH*sizeof(char)) ) == NULL )
3887       { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
3888     }
3889     if(anz->l) sprintf(valuestack[valuestack_ptr++],"%e", sum_valAe/A );
3890     sprintf(valuestack[valuestack_ptr++],"%e", zcg/A );
3891     sprintf(valuestack[valuestack_ptr++],"%e", ycg/A );
3892     sprintf(valuestack[valuestack_ptr++],"%e", xcg/A );
3893     sprintf(valuestack[valuestack_ptr++],"%e", A );
3894     printf(" in inverse order written to stack\n");
3895   }
3896 
3897   return(A);
3898 }
3899 
3900 
3901 
pre_volu(char * setname)3902 double pre_volu(char *setname)
3903 {
3904   int   i,j,n;
3905   int   nr, setNr, massFlag=1, elFlag=0;
3906   int   istat[3]={0,0,0};
3907   double vol=0., mass=0., vole, masse, x[20],y[20],z[20];
3908   double xcg=0., ycg=0., zcg=0., xcge, ycge, zcge;
3909   double sum_valVe=0., value=0.;
3910   double xl[20][3], cg[3];
3911   char elty[MAX_LINE_LENGTH];
3912 
3913   setNr=getSetNr(setname);
3914   if (setNr<0)
3915   {
3916     printf (" ERROR: set:%s does not exist\n", setname);
3917     return(-1);
3918   }
3919 
3920   /* code also used in pre_eprop() */
3921   for(i=0; i<set[setNr].anz_e; i++)
3922   {
3923     nr=set[setNr].elem[i];
3924     if(e_enqire[nr].type==1)
3925     {
3926       for(j=0; j<8; j++)
3927       {
3928         xl[j][0]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
3929         xl[j][1]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
3930         xl[j][2]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
3931 	//printf("xyz: %f %f %f\n", xl[j][0],xl[j][1],xl[j][2]);
3932       }
3933       strcpy(elty,"C3D8");
3934       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
3935       xcge=cg[0];
3936       ycge=cg[1];
3937       zcge=cg[2];
3938       //printf("vol:%e cg: %f %f %f\n", vole,xcge,ycge,zcge);
3939       //return(0);
3940     }
3941     else if(e_enqire[nr].type==4)
3942     {
3943       for(j=0; j<12; j++)
3944       {
3945         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[j]].nx* scale->w+scale->x;
3946         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[j]].ny* scale->w+scale->y;
3947         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[j]].nz* scale->w+scale->z;
3948       }
3949       for(n=16; n<20; n++)
3950       {
3951         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
3952         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
3953         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
3954         j++;
3955       }
3956       for(n=12; n<16; n++)
3957       {
3958         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
3959         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
3960         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
3961         j++;
3962       }
3963       strcpy(elty,"C3D20");
3964       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
3965       xcge=cg[0];
3966       ycge=cg[1];
3967       zcge=cg[2];
3968       //return(0);
3969     }
3970     else if(e_enqire[nr].type==2)
3971     {
3972       for(j=0; j<6; j++)
3973       {
3974         xl[j][0]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
3975         xl[j][1]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
3976         xl[j][2]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
3977 	//printf("xyz: %f %f %f\n", xl[j][0],xl[j][1],xl[j][2]);
3978       }
3979       strcpy(elty,"C3D6");
3980       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
3981       xcge=cg[0];
3982       ycge=cg[1];
3983       zcge=cg[2];
3984     }
3985     else if(e_enqire[nr].type==5)
3986     {
3987       for(j=0; j<9; j++)
3988       {
3989         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[j]].nx* scale->w+scale->x;
3990         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[j]].ny* scale->w+scale->y;
3991         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[j]].nz* scale->w+scale->z;
3992       }
3993       for(n=12; n<15; n++)
3994       {
3995         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
3996         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
3997         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
3998         j++;
3999       }
4000       for(n=9; n<12; n++)
4001       {
4002         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
4003         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
4004         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
4005         j++;
4006       }
4007       strcpy(elty,"C3D15");
4008       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
4009       xcge=cg[0];
4010       ycge=cg[1];
4011       zcge=cg[2];
4012     }
4013     else if(e_enqire[nr].type==3)
4014     {
4015       for(j=0; j<4; j++)
4016       {
4017         x[j]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
4018         y[j]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
4019         z[j]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
4020       }
4021       tetraeder_(&nr, istat, x,y,z, &vole, &xcge, &ycge, &zcge );
4022     }
4023     else if(e_enqire[nr].type==6)
4024     {
4025       for(j=0; j<10; j++)
4026       {
4027         xl[j][0]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
4028         xl[j][1]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
4029         xl[j][2]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
4030 	//printf("xyz: %f %f %f\n", xl[j][0],xl[j][1],xl[j][2]);
4031       }
4032       strcpy(elty,"C3D10");
4033       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
4034       xcge=cg[0];
4035       ycge=cg[1];
4036       zcge=cg[2];
4037       //return(0);
4038     }
4039     else
4040     {
4041       printf("ERROR: type:%d of elem:%d not known. Interrupt\n",e_enqire[nr].type,nr);
4042       return(-1.);
4043     }
4044 
4045     /* determine the average node-value */
4046     if(anz->l)
4047     {
4048       /* check if the data of the specified lcase (Dataset) are already available */
4049       if(sequenceFlag)
4050       {
4051         if (!lcase[lcase_animList].loaded)
4052         {
4053           if( pre_readfrdblock(copiedNodeSets , lcase_animList, anz, node, lcase )==-1)
4054           {
4055             printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", lcase_animList+1);
4056             return(0);
4057           }
4058           calcDatasets( lcase_animList, anz, node, lcase );
4059           recompileEntitiesInMenu(lcase_animList);
4060         }
4061       }
4062       else
4063       {
4064         if (!lcase[cur_lc].loaded)
4065         {
4066           if( pre_readfrdblock(copiedNodeSets , cur_lc, anz, node, lcase )==-1)
4067           {
4068             printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", cur_lc+1);
4069             return(0);
4070           }
4071           calcDatasets( cur_lc, anz, node, lcase );
4072           recompileEntitiesInMenu(cur_lc);
4073         }
4074       }
4075 
4076       if (e_enqire[nr].type == 1) n = 8;  /* HEXA8 */
4077       else if (e_enqire[nr].type == 2) n = 6;  /* PENTA6 */
4078       else if (e_enqire[nr].type == 3) n = 4;  /* TET4 */
4079       else if (e_enqire[nr].type == 4) n = 20; /* HEX20 */
4080       else if (e_enqire[nr].type == 5) n = 15; /* PENTA15 */
4081       else if (e_enqire[nr].type == 6) n = 10; /* TET10 */
4082       else if (e_enqire[nr].type == 7) n = 3;  /* TRI3  */
4083       else if (e_enqire[nr].type == 8) n = 6;  /* TRI6  */
4084       else if (e_enqire[nr].type == 9) n = 4;  /* QUAD4 */
4085       else if (e_enqire[nr].type == 10) n = 8; /* QUAD8 */
4086       else if (e_enqire[nr].type == 11) n = 2; /* BEAM */
4087       else if (e_enqire[nr].type == 12) n = 3; /* BEAM3 */
4088       else n=0;
4089       value=0.;
4090       for (j=0; j<n; j++)
4091       {
4092         if(sequenceFlag) value+=lcase[lcase_animList].dat[animList][e_enqire[nr].nod[j]];
4093         else value+=lcase[cur_lc].dat[cur_entity][e_enqire[nr].nod[j]];
4094       }
4095       sum_valVe+=value/n*(vole);
4096     }
4097 
4098     /*
4099        Berechnung globaler Größen:
4100     */
4101 
4102     /* get material properties */
4103     masse=-MAX_FLOAT;
4104     elFlag=-1;
4105     for(j=0; j<anz->sets; j++)
4106     {
4107       if((set[j].name!=(char *)NULL) && (!set[j].type) && (set[j].name[0]!='-') && (set[j].material>-1))
4108       {
4109         if(( getIndex(&set[j].elem,set[j].anz_e,nr) >-1) && (material[set[j].material].rho>-1.))
4110         {
4111           if(elFlag!=-1)
4112           {
4113             printf("ERROR: found material-definition for elem:%d in set:%s and %s\n", nr, set[j].name,set[elFlag].name );
4114             break;
4115           }
4116           elFlag=j;
4117           masse= vole * material[set[j].material].rho;
4118           mass+= masse;
4119         }
4120       }
4121     }
4122     if (masse==-MAX_FLOAT)
4123     {
4124       massFlag=0;
4125       masse=vole;
4126     }
4127 
4128     vol+=vole;
4129     xcg+=xcge*masse;
4130     ycg+=ycge*masse;
4131     zcg+=zcge*masse;
4132   }
4133   if((mass!=0.)&&(!massFlag))
4134   {
4135     printf("ERROR: some elements have no material assigned, either none or all need a material reference\n");
4136   }
4137   else
4138   {
4139     if (massFlag)     printf("VOLUME:%e  MASS:%e CENTER OF GRAVITY: %e %e %e", vol,mass,xcg/mass,ycg/mass,zcg/mass);
4140     else printf("VOLUME:%e CENTER OF GRAVITY: %e %e %e", vol,xcg/vol,ycg/vol,zcg/vol);
4141     if(anz->l) printf(" AVERAGE-VALUE:%e\n", sum_valVe/vol); else printf("\n");
4142   }
4143 
4144   if(valuestackFlag)
4145   {
4146     if(anz->l) n=5; else n=4;
4147     if (massFlag) n++;
4148     if ((valuestack = (char **)realloc( (char **)valuestack, (valuestack_ptr+n)*sizeof(char *)) ) == NULL )
4149     { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
4150     for(i=0; i<n; i++)
4151     {
4152       if ((valuestack[valuestack_ptr+i] = (char *)malloc( MAX_LINE_LENGTH*sizeof(char)) ) == NULL )
4153       { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
4154     }
4155     if(anz->l) sprintf(valuestack[valuestack_ptr++],"%e", sum_valVe/vol );
4156     if (massFlag)
4157     {
4158       sprintf(valuestack[valuestack_ptr++],"%e", zcg/mass );
4159       sprintf(valuestack[valuestack_ptr++],"%e", ycg/mass );
4160       sprintf(valuestack[valuestack_ptr++],"%e", xcg/mass );
4161       sprintf(valuestack[valuestack_ptr++],"%e", mass );
4162     }
4163     else
4164     {
4165       sprintf(valuestack[valuestack_ptr++],"%e", zcg/vol );
4166       sprintf(valuestack[valuestack_ptr++],"%e", ycg/vol );
4167       sprintf(valuestack[valuestack_ptr++],"%e", xcg/vol );
4168     }
4169     sprintf(valuestack[valuestack_ptr++],"%e", vol );
4170     printf(" in inverse order written to stack\n");
4171   }
4172   return(vol);
4173 }
4174 
4175 
completeFacesByTolerance(int set_highl,int setNr,double qaddTol)4176 void completeFacesByTolerance(int set_highl, int setNr, double qaddTol)
4177 {
4178   register int i,j,jj,jjj,jjjj;
4179   int f,n,n2,k,l, equ;
4180 
4181   int sumMaster=0;
4182 
4183   int *facebuf;  // stores the identified faces which fulfill the criterion
4184   int *fchecked; // 1: if a certain face was already checked
4185   double **fnorm;  // average normal on the face
4186   double criterion;
4187   double v1[3], v2[3], sprod;
4188   Nodes *norm;
4189   int   *sum_n, nmax;
4190 
4191   typedef struct {
4192     int sum;
4193     int *face;   // face which uses this node (lowest node-nr in face
4194   }Fnode;
4195   Fnode *fnode;  // field indexed by the lowest node-nr of a face
4196 
4197 
4198   criterion=qaddTol*PI/180.;
4199 
4200   /*
4201   Go over all master-faces and check the neighbours against the criterion of qaddTol.
4202   If a face passes it will also be a master face.
4203   The ammount of masters will therefore increase up to a certain level.
4204   The comparison stops if no master is left.
4205   */
4206 
4207   if ( ( fnode= (Fnode *)malloc((anz->nmax+1) * sizeof(Fnode))) == NULL )
4208     printf("\n\n ERROR: realloc failed\n");
4209   for(i=0; i<=anz->nmax; i++) { fnode[i].face=NULL; fnode[i].sum=0; }
4210   if ( ( facebuf= (int *)malloc((set[setNr].anz_f+1) * sizeof(int))) == NULL )
4211     printf("\n\n ERROR: realloc failed\n");
4212   if ( ( fchecked= (int *)malloc((anz->f+1) * sizeof(int))) == NULL )
4213     printf("\n\n ERROR: realloc failed\n");
4214   if ( ( fnorm= (double **)malloc((anz->f+1) * sizeof(double *))) == NULL )
4215     printf("\n\n ERROR: realloc failed\n");
4216   for(i=0; i<anz->f; i++)
4217     if ( ( fnorm[i]= (double *)calloc((3), sizeof(double))) == NULL )
4218       printf("\n\n ERROR: realloc failed\n");
4219   for(i=0; i<anz->f; i++)
4220   {
4221     fchecked[i]=0;
4222   }
4223   for(i=0; i<set[setNr].anz_f; i++)
4224   {
4225     facebuf[i]=set[setNr].face[i];
4226     fchecked[set[setNr].face[i]]=1;
4227   }
4228   sumMaster=set[setNr].anz_f;
4229 
4230   /* calc the average normal on all faces */
4231 
4232   /* calculate the average normal on every node */
4233   getNodeNormalen(&sum_n, &norm, setall, anz, face);
4234   for (f=0; f<anz->f; f++)
4235   {
4236     if (face[f].type == 7) n = 3;  /* TRI3  */
4237     else if (face[f].type == 8) n = 3;  /* TRI6  */
4238     else if (face[f].type == 9) n = 4;  /* QUAD4 */
4239     else if (face[f].type == 10) n = 4; /* QUAD8 */
4240     else if (face[f].type == 11) n = 2; /* BEAM2 */
4241     else if (face[f].type == 12) n = 2; /* BEAM3 */
4242     else n=0;
4243     if(n==2)
4244     {
4245       v_result( &node[face[f].nod[0]].nx, &node[face[f].nod[1]].nx, fnorm[f]);
4246     }
4247     if(n==3)
4248     {
4249       v_result( &node[face[f].nod[0]].nx, &node[face[f].nod[1]].nx, v1);
4250       v_result( &node[face[f].nod[0]].nx, &node[face[f].nod[2]].nx, v2);
4251       v_prod( v1, v2, fnorm[f] );
4252     }
4253     if(n==4)
4254     {
4255       v_result( &node[face[f].nod[0]].nx, &node[face[f].nod[2]].nx, v1);
4256       v_result( &node[face[f].nod[1]].nx, &node[face[f].nod[3]].nx, v2);
4257       v_prod( v1, v2, fnorm[f] );
4258     }
4259     v_norm(fnorm[f],fnorm[f]);
4260 
4261     /* get the faces at each node */
4262     for(j=0;j<n; j++)
4263     {
4264       nmax=face[f].nod[j];
4265       if ( ( fnode[nmax].face= (int *)realloc((int *)fnode[nmax].face, (fnode[nmax].sum+1)*sizeof(int))) == NULL )
4266         printf("\n\n ERROR: realloc failed\n");
4267       fnode[nmax].face[fnode[nmax].sum]=f;
4268       fnode[nmax].sum++;
4269     }
4270   }
4271 
4272   /* go over all master-faces and search and check the slaves */
4273   for(i=0; i<sumMaster; i++)
4274   {
4275     f=facebuf[i];
4276 
4277     /* nodes of the master */
4278     if (face[f].type == 7) n = 3;  /* TRI3  */
4279     else if (face[f].type == 8) n = 3;  /* TRI6  */
4280     else if (face[f].type == 9) n = 4;  /* QUAD4 */
4281     else if (face[f].type == 10) n = 4; /* QUAD8 */
4282     else if (face[f].type == 11) n = 2; /* BEAM2 */
4283     else if (face[f].type == 12) n = 2; /* BEAM3 */
4284     else n=0;
4285 
4286     for(jjj=0;jjj<n; jjj++)
4287     {
4288      nmax=face[f].nod[jjj];
4289      /* identify the neighbour faces */
4290      for (jj=0; jj<fnode[nmax].sum; jj++)
4291      {
4292       j=fnode[nmax].face[jj];
4293       if (face[j].type == 7) n2 = 3;  /* TRI3  */
4294       else if (face[j].type == 8) n2 = 3;  /* TRI6  */
4295       else if (face[j].type == 9) n2 = 4;  /* QUAD4 */
4296       else if (face[j].type == 10) n2 = 4; /* QUAD8 */
4297       else if (face[j].type == 11) n2 = 2; /* BEAM2 */
4298       else if (face[j].type == 12) n2 = 2; /* BEAM3 */
4299       else n2=0;
4300       equ=0;
4301       for (k=0; k<n2; k++) { for (l=0; l<n; l++)  if(face[f].nod[l] == face[j].nod[k]) equ++; }
4302       //if(j==91472) printf("i:%d master:%d m:%d s:%d equ:%d check:%d\n", i, sumMaster, f, j, equ, fchecked[j]);
4303       if((equ==2) || ((n2==2)&&(equ==1)))
4304       {
4305         /* check j against the criterion */
4306         sprod=abs(v_sprod(fnorm[f], fnorm[j]));
4307         if(sprod>1.) sprod=1.;
4308 	/*
4309 	if(j==91472){
4310 	  printf("i:%d sum:%d S:%f angle %f between %d %d, criterion:%f  check:%d\n", i, sumMaster, sprod, acos(sprod), f, j, criterion, fchecked[j]);
4311 	printf("norm master:%f neighbor: %f \n", fnorm[f][0], fnorm[j][0]);
4312 	printf("norm master:%f neighbor: %f \n", fnorm[f][1], fnorm[j][1]);
4313 	printf("norm master:%f neighbor: %f \n", fnorm[f][2], fnorm[j][2]);
4314 	}
4315 	*/
4316         if((!fchecked[j])&&(acos(sprod) < criterion))
4317 	{
4318           /* add j as additional masterface */
4319           if ( ( facebuf= (int *)realloc((int *)facebuf, (sumMaster+1) * sizeof(int))) == NULL )
4320             printf("\n\n ERROR: realloc failed\n");
4321           facebuf[sumMaster]=j;
4322           sumMaster++;
4323           fchecked[j]=1;
4324     printf ("%d e:%d s:%d n= ", j, face[j].elem_nr, face[j].nr+1 );
4325       if(face[j].type==7) k=3;
4326       else if(face[j].type==8) k=6;
4327       else if(face[j].type==9) k=4;
4328       else if(face[j].type==10) k=8;
4329       else k=0;
4330       for (jjjj=0; jjjj<k; jjjj++) printf("%d ",face[j].nod[jjjj]);
4331       printf("\n");
4332           seta( setNr, "f", j );
4333           seta(set_highl, "f", j );
4334 	}
4335       }
4336      }
4337     }
4338   }
4339 }
4340 
4341 /* return sum of generated sets */
separateMeshes(char * setName,char * grpName)4342 int separateMeshes( char *setName, char *grpName)
4343 {
4344   int i,e,k=2;
4345   int setNr, setNrbuf, setTmp, sum_c=0, c1, sum1,sum2;
4346   int *elUsed;
4347   char setname[MAX_LINE_LENGTH];
4348   char buffer[MAX_LINE_LENGTH];
4349 
4350   printf (" please wait for 'ready'\n");
4351 
4352   setNr=getSetNr(setName);
4353   if (setNr<0)
4354   {
4355     printf (" ERROR: set:%s does not exist\n", setName);
4356     return(0);
4357   }
4358 
4359   if (set[setNr].anz_e<2)
4360   {
4361     //printf("ERROR: set:%s contains less than 2 elements!\n", set[setNr].name);
4362     return(0);
4363   }
4364   /*----- complete set with all elements and nodes ---*/
4365 
4366   /* mark all elements as unused */
4367   if((elUsed = (int *)malloc( (int)(anz->emax+1)*sizeof(int)))==NULL)
4368   { errMsg("\n\n ERROR: malloc failed for elUsed\n" ); return(0); }
4369   for(i=0; i<=anz->emax; i++) elUsed[i]=1;
4370   for(i=0; i<set[setNr].anz_e; i++) elUsed[set[setNr].elem[i]]=0;
4371 
4372   /* use "comp set up/do" until no more entities are added */
4373   e=set[setNr].elem[0];
4374   do
4375   {
4376     sprintf( setname, "%s%d", grpName,sum_c+1);
4377     delSet(setname);
4378     c1=pre_seta(setname,"i", 0);
4379     seta(c1,"e", e);                                            // 1st elem in c1
4380     elUsed[e]=1;
4381 
4382     delSet("+buf");
4383     sprintf(buffer,"%d", e);
4384     setNrbuf=pre_seta("+buf","e", buffer);
4385     completeSet_Mesh(  setNrbuf, 0, elUsed, 1);                 // down, nodes from new elems in +buf
4386     for(i=0; i<set[setNrbuf].anz_n; i++)
4387     {
4388       seta(c1,"n", set[setNrbuf].node[i]);                      // nodes from new elem in c1
4389     }
4390 
4391     do
4392     {
4393       sum1=set[c1].anz_n+set[c1].anz_e;
4394 
4395       delSet("+buf2");
4396       setTmp=pre_seta("+buf2", "i", 0 );
4397       completeSet_Mesh( setNrbuf, setTmp, elUsed, 0);                // up, only new elems from +buf (setNrbuf) in +buf2 (setTmp)
4398       completeSet_Mesh(  setTmp, 0, elUsed, 1);                      // down, nodes from new elems in +buf2 (setTmp)
4399       for(i=0; i<set[setNrbuf].anz_n; i++)
4400         setr(setTmp,"n", set[setNrbuf].node[i]);              // remove used nodes in +buf from +buf2
4401       for(i=0; i<set[setTmp].anz_e; i++)
4402       {
4403         seta(c1,"e", set[setTmp].elem[i]);                           // new elems in c1
4404         elUsed[set[setTmp].elem[i]]=1;
4405       }
4406 
4407       delSet("+buf");
4408       setNrbuf=pre_seta("+buf","i", 0);
4409       for(i=0; i<set[setTmp].anz_n; i++)
4410       {
4411         seta(c1,"n", set[setTmp].node[i]);
4412         seta(setNrbuf,"n", set[setTmp].node[i]);
4413       }
4414       sum2=set[c1].anz_n+set[c1].anz_e;
4415     }while(sum1<sum2);
4416 
4417     //completeSet( setname, "f");                  // faces (draw-nodes are missed)
4418     completeSet( setname, "do");                  // faces, nodes (to include also the additional midface-nodes for drawing)
4419 
4420     if(k>=entitycols) k=BAS_COLS-1;
4421     printf("set%d: %s col:%s\n",sum_c+1, setname, entitycol[k].name);
4422     sprintf(buffer,"f %s %s", setname, entitycol[k++].name);
4423     if(!sum_c) plot(buffer);
4424     else plus(buffer);
4425 
4426     sum_c++;
4427     e=0;
4428     for(i=0; i<set[setNr].anz_e; i++)
4429     {
4430       if(elUsed[set[setNr].elem[i]]==0)
4431       {
4432         e=set[setNr].elem[i];
4433         break;
4434       }
4435     }
4436   }while(e);
4437 
4438   free(elUsed);
4439   delSet("+buf");
4440   delSet("+buf2");
4441 
4442   printf (" ready\n");
4443   return(sum_c);
4444 }
4445 
4446 
4447 
4448 
separateLines(char * setName,char * grpName)4449 void separateLines( char *setName, char *grpName)
4450 {
4451   int i,e,k=2;
4452   int setNr, setNrbuf, setTmp, sum_c=0, c1, sum1,sum2;
4453   int *elUsed;
4454   char setname[MAX_LINE_LENGTH];
4455   char buffer[MAX_LINE_LENGTH];
4456 
4457   printf (" please wait for 'ready'\n");
4458 
4459   setNr=getSetNr(setName);
4460   if (setNr<0)
4461   {
4462     printf (" ERROR: set:%s does not exist\n", setName);
4463     return;
4464   }
4465 
4466   if (set[setNr].anz_l<2)
4467   {
4468     //printf("ERROR: set:%s contains less than 2 lines!\n", set[setNr].name);
4469     return;
4470   }
4471   /*----- complete set with all lines and points ---*/
4472 
4473   /* mark all lines as unused */
4474   if((elUsed = (int *)malloc( (int)(anzGeo->l+1)*sizeof(int)))==NULL)
4475   { errMsg("\n\n ERROR: malloc failed for elUsed\n" ); return; }
4476   for(i=0; i<=anzGeo->l; i++) elUsed[i]=1;
4477   for(i=0; i<set[setNr].anz_l; i++) elUsed[set[setNr].line[i]]=0;
4478 
4479   /* use "comp set up/do" until no more entities are added */
4480   e=set[setNr].line[0];
4481   do
4482   {
4483     sprintf( setname, "%s%d", grpName,sum_c+1);
4484     delSet(setname);
4485     c1=pre_seta(setname,"i", 0);
4486 
4487     delSet("+buf");
4488     setNrbuf=pre_seta("+buf","l", line[e].name);
4489     completeSet_Lines(  setNrbuf, 0, elUsed, 1);                      // down, nodes from new elems in +buf
4490     for(i=0; i<set[setNrbuf].anz_p; i++)
4491     {
4492       seta(c1,"p", set[setNrbuf].pnt[i]);
4493     }
4494 
4495     seta(c1,"l", e);
4496     elUsed[e]=1;
4497     do
4498     {
4499       sum1=set[c1].anz_p+set[c1].anz_l;
4500 
4501       delSet("+buf2");
4502       setTmp=pre_seta("+buf2", "i", 0 );
4503       completeSet_Lines( setNrbuf, setTmp, elUsed, 0);                  // up, only new elems in +buf2 (setTmp) based on nodes in +buf (setNrbuf)
4504 
4505       completeSet_Lines(  setTmp, 0, elUsed, 1);                      // down, nodes from new elems in +buf2 (setTmp)
4506 
4507       for(i=0; i<set[setTmp].anz_l; i++)
4508       {
4509         seta(c1,"l", set[setTmp].line[i]);
4510         elUsed[set[setTmp].line[i]]=1;
4511       }
4512 
4513       delSet("+buf");
4514       setNrbuf=pre_seta("+buf","i", 0);
4515       for(i=0; i<set[setTmp].anz_p; i++)
4516       {
4517         seta(c1,"p", set[setTmp].pnt[i]);
4518         seta(setNrbuf,"p", set[setTmp].pnt[i]);
4519       }
4520       sum2=set[c1].anz_p+set[c1].anz_l;
4521     }while(sum1<sum2);
4522 
4523     //completeSet( setname, "do");                  // faces, nodes (to include also the additional midface-nodes for drawing)
4524 
4525     if(k>=SET_COLS) k=BAS_COLS-1;
4526     printf("set%d: %s col:%s\n",sum_c+1, setname, entitycol[k].name);
4527     sprintf(buffer,"l %s %s", setname, entitycol[k++].name);
4528     if(!sum_c) plot(buffer);
4529     else plus(buffer);
4530 
4531     sum_c++;
4532     e=0;
4533     for(i=0; i<set[setNr].anz_l; i++)
4534     {
4535       if(elUsed[set[setNr].line[i]]==0)
4536       {
4537         e=set[setNr].line[i];
4538         break;
4539       }
4540     }
4541   }while(e);
4542 
4543   free(elUsed);
4544   delSet("+buf");
4545   delSet("+buf2");
4546 
4547   printf (" ready\n");
4548 }
4549 
4550 
pre_contact(char * record)4551 void pre_contact( char *record)
4552 {
4553   int i,j;
4554   int length, setNr, sum_c, c1, c2, mpcset[2], flag;
4555   char setname[MAX_LINE_LENGTH], format[MAX_LINE_LENGTH], action[MAX_LINE_LENGTH], par1[MAX_LINE_LENGTH], par2[MAX_LINE_LENGTH];
4556   double tol=0.,gtolbuf;
4557   double  stiffness=-1;
4558   double  mue=0.;
4559   FILE *handle=NULL;
4560 
4561   par1[0]=0;
4562   action[0]=0;
4563   length=sscanf(record, "%s %lf %s %s %s %s", setname, &tol, format, action, par1, par2);
4564   if(action[0]=='e')
4565   {
4566     if(length==5)
4567     {
4568       /* equations */
4569       if((par1[0]=='u')||(par1[0]=='c')) strcpy(par2,par1);
4570       //if(par1[0]!='t') strcpy(par1,"123");
4571     }
4572     else if(length>5)
4573     {
4574       /* equations */
4575       //if(par1[0]!='t') strcpy(par1,"123");
4576       if((par1[0]=='u')||(par1[0]=='c')) strcpy(par2,par1);
4577     }
4578     else
4579     {
4580       strcpy(par1,"123");
4581       strcpy(par2,"c");
4582     }
4583   }
4584   if(action[0]=='t')
4585   {
4586     if(length>=5)
4587     {
4588       if((par1[0]=='y')||(par1[0]=='Y')) strcpy(par1,"YES");
4589     }
4590     else
4591     {
4592       strcpy(par1,"NO");
4593     }
4594   }
4595   if((action[0]=='c')||(action[0]=='n'))
4596   {
4597     if(length>=5)
4598     {
4599       stiffness=atof(par1);
4600     }
4601     if(length>=6)
4602     {
4603       mue=atof(par2);
4604     }
4605   }
4606 
4607   setNr=getSetNr(setname);
4608   if (setNr<0)
4609   {
4610     printf (" ERROR: set:%s does not exist\n", setname);
4611     return;
4612   }
4613 
4614   if (set[setNr].anz_f<2)
4615   {
4616     printf("ERROR: set:%s contains less than 2 faces. Contact between two faces not possible. Consider a <comp %s do> command.\n",set[setNr].name, set[setNr].name);
4617     return;
4618   }
4619   printf("Contact between faces of set:%s with tol:%lf\nwait for <ready>\n", set[setNr].name, tol);
4620 
4621 
4622   /* subdivide the faces into single unconnected sets of faces */
4623   /* return if not at least 2 indep meshes exist */
4624   sum_c=getMeshSections(setNr, anz, face, node);
4625   if(sum_c < 2)
4626   {
4627     printf("ERROR: Found only %d separate meshes. Contact not possible\n", sum_c);
4628     return;
4629   }
4630   printf(" found %d separate meshes\n", sum_c);
4631 
4632 
4633   /* search face-pairs of unconnected sets of faces */
4634   /* deside which side is the dep side */
4635   /* remove all dep-nodes which are not inside the ind-faces */
4636 
4637   if((action[0]=='c')||(action[0]=='n')||(action[0]=='t'))
4638   {
4639     if(compareStrings(format, "abq") !=3)
4640     {
4641       printf("ERROR: Format %s not supported so far for contatct based connections\n", format);
4642       return;
4643     }
4644     handle = fopen ("neigh.con", "w");
4645     if ( handle== NULL )
4646     {
4647       printf ("\nThe file 'neigh.con' could not be opened.\n\n");
4648       return;
4649     }
4650     else printf ("\n write file: neigh.con\n\n");
4651 
4652     if(action[0]=='c')
4653     {
4654       if(par1[0]=='t')
4655       {
4656         //fprintf(handle,"*SURFACE INTERACTION,NAME=SI%d%d\n",i,j+1);
4657         fprintf(handle,"*SURFACE INTERACTION,NAME=DEFAULT\n");
4658         fprintf(handle,"*SURFACE BEHAVIOR,PRESSURE-OVERCLOSURE=TIED\n");
4659         fprintf(handle,"1e7\n");
4660         fprintf(handle,"*FRICTION\n");
4661         fprintf(handle,"1.e30,1e7\n");
4662       }
4663       else if(stiffness!=-1)
4664       {
4665         //fprintf(handle,"*SURFACE INTERACTION,NAME=SI%d%d\n",i,j+1);
4666         fprintf(handle,"*SURFACE INTERACTION,NAME=DEFAULT\n");
4667         fprintf(handle,"*SURFACE BEHAVIOR,PRESSURE-OVERCLOSURE=LINEAR\n");
4668         fprintf(handle,"%e\n", stiffness);
4669         if(mue!=0.)
4670         {
4671           fprintf(handle,"*FRICTION\n");
4672           fprintf(handle,"%f,%e\n",mue,stiffness/100.);
4673         }
4674       }
4675     }
4676     if(action[0]=='n')
4677     {
4678       if(par1[0]=='t')
4679       {
4680         //fprintf(handle,"*SURFACE INTERACTION,NAME=SI%d%d\n",i,j+1);
4681         fprintf(handle,"*SURFACE INTERACTION,NAME=DEFAULT\n");
4682         //fprintf(handle,"*SURFACE BEHAVIOR,PRESSURE-OVERCLOSURE=TIED\n");
4683         fprintf(handle,"****************************************************\n");
4684         fprintf(handle,"** TIED not implemented for n2s in ccx:           **\n");
4685         fprintf(handle,"**   *SURFACE BEHAVIOR,PRESSURE-OVERCLOSURE=TIED  **\n");
4686         fprintf(handle,"**                                                **\n");
4687         fprintf(handle,"** The following lines are used to simulate TIED  **\n");
4688         fprintf(handle,"**   Run your calculation this way:               **\n");
4689         fprintf(handle,"**   ** generate springs                          **\n");
4690         fprintf(handle,"**   *STEP                                        **\n");
4691         fprintf(handle,"**   *STATIC                                      **\n");
4692         fprintf(handle,"**   *BOUNDARY                                    **\n");
4693         fprintf(handle,"**   Nall,1,3                                     **\n");
4694         fprintf(handle,"**   *END STEP                                    **\n");
4695         fprintf(handle,"**   ** keep the springs                          **\n");
4696         fprintf(handle,"**   *STEP,NLGEOM,perturbation                    **\n");
4697         fprintf(handle,"**   ** or:                                       **\n");
4698         fprintf(handle,"**   *STEP,perturbation                           **\n");
4699         fprintf(handle,"**   *STATIC                                      **\n");
4700         fprintf(handle,"**   *BOUNDARY,OP=NEW                             **\n");
4701         fprintf(handle,"**   ** or:                                       **\n");
4702         fprintf(handle,"**   *FREQUENCY                                   **\n");
4703         fprintf(handle,"**   *BOUNDARY,OP=NEW                             **\n");
4704         fprintf(handle,"**   ..                                           **\n");
4705         fprintf(handle,"****************************************************\n");
4706         fprintf(handle,"*SURFACE BEHAVIOR,PRESSURE-OVERCLOSURE=LINEAR\n");
4707         fprintf(handle,"1e7\n");
4708         fprintf(handle,"*FRICTION\n");
4709         fprintf(handle,"1.e30,1e7\n");
4710       }
4711       else if(stiffness!=-1)
4712       {
4713         //fprintf(handle,"*SURFACE INTERACTION,NAME=SI%d%d\n",i,j+1);
4714         fprintf(handle,"*SURFACE INTERACTION,NAME=DEFAULT\n");
4715         fprintf(handle,"*SURFACE BEHAVIOR,PRESSURE-OVERCLOSURE=LINEAR\n");
4716         fprintf(handle,"%e\n", stiffness);
4717         if(mue!=0.)
4718         {
4719           fprintf(handle,"*FRICTION\n");
4720           fprintf(handle,"%f,%e\n",mue,stiffness/100.);
4721         }
4722       }
4723     }
4724   }
4725 
4726   /* ------- node-koordinaten berechnen und am ende wieder scalieren ------ */
4727   descalNodes ( anz->n, node, scale );
4728 
4729   delSet("+UNCON");
4730   for(i=1; i<sum_c; i++)
4731   {
4732     sprintf( setname, "%s%d", specialset->cf,i);
4733     c1=getSetNr(setname);
4734     for(j=i; j<sum_c; j++)
4735     {
4736       sprintf( setname, "%s%d", specialset->cf,j+1);
4737       c2=getSetNr(setname);
4738 
4739       flag=getFacePair( anz, c1, c2, e_enqire, face, node, tol, mpcset, par1);
4740       if(flag)
4741       {
4742         set[c1].eattr=1;
4743         set[c2].eattr=1;
4744         if(action[0]=='e')
4745 	{
4746           /* write equations */
4747           /* write only dep-nodes which are not already used (1) */
4748           completeSet(set[mpcset[1]].name, "do") ;
4749 	  gtolbuf=gtol;
4750           if(gtol<tol) gtol=tol;
4751 	  //printf(" areampc %s tol:%f\n",format, gtol );
4752           areampc(mpcset[0], mpcset[1], format, "areampc", par1, par2, 1, node, 1, 0);
4753           gtol=gtolbuf;
4754 	}
4755         if((action[0]=='c')&&(flag==2))
4756 	{
4757           sendSurfaces( set[mpcset[0]].name, format, anz, node, e_enqire, NULL );
4758           sendSurfaces( set[mpcset[1]].name, format, anz, node, e_enqire, NULL );
4759           /* write contact definitions */
4760           //fprintf(handle,"*CONTACT PAIR,INTERACTION=SI%d%d,TYPE=SURFACE TO SURFACE\n",i,j+1);
4761           fprintf(handle,"*CONTACT PAIR,INTERACTION=DEFAULT,TYPE=SURFACE TO SURFACE\n");
4762           fprintf(handle,"S%s,S%s\n",set[mpcset[0]].name,set[mpcset[1]].name);
4763 	}
4764         if((action[0]=='t')&&(flag==2))
4765 	{
4766           sendSurfaces( set[mpcset[0]].name, format, anz, node, e_enqire, NULL );
4767           sendSurfaces( set[mpcset[1]].name, format, anz, node, e_enqire, NULL );
4768           /* write tie definitions */
4769           fprintf(handle,"*TIE,NAME=SI%d%d,ADJUST=%s\n",i,j+1,par1);
4770           fprintf(handle,"S%s,S%s\n",set[mpcset[0]].name,set[mpcset[1]].name);
4771 	}
4772         if(action[0]=='n')
4773         {
4774           /* write node sets */
4775           sendNames( set[mpcset[0]].name, format, anz, node, e_enqire );
4776           sendSurfaces( set[mpcset[1]].name, format, anz, node, e_enqire, NULL );
4777           /* write contact definitions */
4778           fprintf(handle,"*SURFACE,NAME=S%s,TYPE=NODE\n",set[mpcset[0]].name);
4779           fprintf(handle,"N%s\n",set[mpcset[0]].name);
4780           fprintf(handle,"*CONTACT PAIR,INTERACTION=DEFAULT,TYPE=NODE TO SURFACE\n");
4781           fprintf(handle,"S%s,S%s\n",set[mpcset[0]].name,set[mpcset[1]].name);
4782 	}
4783         strcpy(parameter[0],set[mpcset[0]].name);
4784         strcpy(parameter[1],set[mpcset[1]].name);
4785         write2stack(2, parameter);
4786       }
4787     }
4788   }
4789   if(handle!=NULL) fclose(handle);
4790 
4791   /* are there unconnected sets? */
4792   for(i=1; i<=sum_c; i++)
4793   {
4794     sprintf( setname, "%s%d", specialset->cf,i);
4795     c1=getSetNr(setname);
4796     if(set[c1].eattr==0) pre_seta("+UNCON","se",set[c1].name);
4797     else set[c1].eattr=0;
4798   }
4799   scalNodes ( anz->n, node, scale );
4800   printf("ready\n");
4801 }
4802 
4803 
4804 
pre_del(char * record)4805 void pre_del( char *record)
4806 {
4807   int  b,bb, i, j,jj, k, l,ll, n,nn, m, s,ss, z;
4808   int length, setNr, nf=0, foundSubString, *lines;
4809   char type[MAX_LINE_LENGTH], **datum=NULL, **dat=NULL, *ori;
4810   char buffer[MAX_LINE_LENGTH];
4811   double  v01[3], ds;
4812 
4813   length= sword2( record, type );
4814   for (i=0; i<MAX_PARAM_PER_RECORD; i++)
4815   {
4816     if((datum=(char **)realloc((char **)datum, (i+1)*sizeof(char *)))==NULL)
4817       printf("\n\n ERROR: realloc failure\n\n" );
4818     if((datum[i]=(char *)malloc( (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
4819       printf("\n\n ERROR: realloc failure\n\n" );
4820     n =  sword2( &record[length], datum[i] );
4821     if (n<1) break;
4822     length= length+n;
4823     operateAlias( datum[i], type );
4824   }
4825 
4826   delSet(specialset->zap);
4827 
4828   /* check if wildcards (*) were used */
4829   k=0;
4830   for (n=0; n<i; n++)
4831   {
4832     length= strsplt( datum[n], '*', &dat);
4833     if ((length>0)&&(strstr(datum[n], "*") !=NULL))
4834     {
4835      if (compare(type, "se", 2) == 2 )
4836      {
4837       for(setNr=0; setNr<anz->sets; setNr++)
4838       {
4839         if( set[setNr].name == (char *)NULL ) continue;
4840 
4841         foundSubString=0;
4842         for(l=0; l<length; l++)
4843         {
4844           if(strstr(set[setNr].name, dat[l]) !=NULL)
4845           {
4846             foundSubString++;
4847             /* check if the first or the last char is no '*' then the substring[] must be at start or end */
4848             if(l==0) { if(datum[n][0]!='*')  { if(datum[n][0]!=set[setNr].name[0])  foundSubString--; }  }
4849             if(l==length-1) { if(datum[n][strlen(datum[n])-1]!='*') { if(datum[n][strlen(datum[n])-1]!=set[setNr].name[strlen(set[setNr].name)-1])  foundSubString--; } }
4850           }
4851         }
4852 
4853         if(foundSubString==length)
4854         {
4855           printf(" set:%s matches %s\n", set[setNr].name, datum[n]);
4856           if((datum=(char **)realloc((char **)datum, (i+k+1)*sizeof(char *)))==NULL)
4857             printf("\n\n ERROR: realloc failure\n\n" );
4858           if((datum[i+k]=(char *)malloc( (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
4859             printf("\n\n ERROR: realloc failure\n\n" );
4860           strcpy(datum[i+k],set[setNr].name);
4861           k++;
4862         }
4863       }
4864      }
4865      else printf(" ERROR in %s, wildcards '*' are not supported for type:%s\n", datum[n], type);
4866     }
4867   }
4868   i+=k;
4869   if(printFlag) for (n=0; n<i; n++) printf("datum:'%s' \n", datum[n]);
4870 
4871 
4872   if (compare(type, "se0", 3) == 3 ) /* delete empty sets */
4873   {
4874     for (n=0; n<anz->sets; n++)
4875     {
4876       if((set[n].name != (char *)NULL )&&
4877          (!set[n].anz_v)&&
4878          (!set[n].anz_n)&&
4879          (!set[n].anz_e)&&
4880          (!set[n].anz_f)&&
4881          (!set[n].anz_p)&&
4882          (!set[n].anz_l)&&
4883          (!set[n].anz_c)&&
4884          (!set[n].anz_s)&&
4885          (!set[n].anz_b)&&
4886          (!set[n].anz_nurl)&&
4887          (!set[n].anz_nurs)&&
4888          (!set[n].anz_se)&&
4889 	(!set[n].anz_sh)) { delSet(set[n].name); }
4890     }
4891     return;
4892   }
4893   else if ((compare(type, "se", 2) == 2 )||(compare(type, "sq", 2) == 2 ))
4894   {
4895     for (n=0; n<i; n++)
4896       delSet(datum[n]);
4897     return;
4898   }
4899   else if (compare(type, "sh", 2) == 2 )
4900   {
4901     for (n=0; n<i; n++)
4902     {
4903       j=getShapeNr(datum[n]);
4904       if(j>-1) delShape(1, &j);
4905       else printf(" WARNING: shape %s does not exist\n", datum[n]);
4906     }
4907     return;
4908   }
4909   else if (compare(type, "pic", 2) == 2 )
4910   {
4911     bgpicture=0;
4912     return;
4913   }
4914   else if(compare(type, "mesh", 2) == 2 )
4915   {
4916     /* delete the temporary sets which hold the dependent and independent nodes for incompatible elements */
4917     for(j=0; j<sum_equSets; j++) { delSet(set[depSet[j]].name); delSet(set[indSet[j]].name); }
4918     sum_equSets=0;
4919 
4920     /* delete the mesh */
4921     if(anz->n<1) return;
4922     if((i>0)&&(strlen(datum[i-1])>0))
4923     {
4924       setNr=getSetNr(datum[i-1]);
4925       if(setNr<0)
4926       {
4927         printf(" ERROR: set |%s| does not exist\n",datum[i-1]);
4928         return;
4929       }
4930     }
4931     else setNr=0;
4932     if(printFlag) printf ("delete mesh defined in set:%s\n", set[setNr].name);
4933 
4934     if(setNr==getSetNr("all"))
4935     {
4936       for (j=0; j<anz->sets; j++ )
4937       {
4938         set[j].anz_n = 0;
4939         set[j].anz_e = 0;
4940         set[j].anz_f = 0;
4941       }
4942       for (j=0; j<anzGeo->psets; j++ )
4943       {
4944         set[pset[j].nr].anz_n=0;
4945         set[pset[j].nr].anz_e=0;
4946         set[pset[j].nr].anz_f=0;
4947       }
4948 
4949       for (j=0; j<anz->l; j++)
4950       {
4951         freeDataset(lcase, j);
4952       }
4953       free(lcase); lcase=NULL;
4954 
4955       for (j=0; j<anz->e; j++)
4956       {
4957         /* free space for the normal-vectors */
4958         if(e_enqire[e_enqire[j].nr].side!=NULL)
4959         {
4960           if (e_enqire[e_enqire[j].nr].type == 1)       nf=6;  /* HEXA8 */
4961           else if (e_enqire[e_enqire[j].nr].type == 2)  nf=6;  /* PENTA6 */
4962           else if (e_enqire[e_enqire[j].nr].type == 3)  nf=4;  /* TET4 */
4963           else if (e_enqire[e_enqire[j].nr].type == 4)  nf=48; /* HEXA20 */
4964           else if (e_enqire[e_enqire[j].nr].type == 5)  nf=48; /* PENTA15 */
4965           else if (e_enqire[e_enqire[j].nr].type == 6)  nf=16; /* TET10 */
4966           else if (e_enqire[e_enqire[j].nr].type == 7)  nf=1;  /* TRI3  */
4967           else if (e_enqire[e_enqire[j].nr].type == 8)  nf=4; /* TRI6  */
4968           else if (e_enqire[e_enqire[j].nr].type == 9)  nf=2; /* QUAD4 */
4969           else if (e_enqire[e_enqire[j].nr].type == 10) nf=8; /* QUAD8 */
4970           else if (e_enqire[e_enqire[j].nr].type == 11) nf=1; /* BEAM */
4971           else if (e_enqire[e_enqire[j].nr].type == 12) nf=1; /* BEAM3 */
4972           for(k=0; k<nf; k++) free(e_enqire[e_enqire[j].nr].side[k]);
4973           free(e_enqire[e_enqire[j].nr].side);
4974           e_enqire[e_enqire[j].nr].side=NULL;
4975         }
4976       }
4977       for (j=0; j<anz->f; j++)
4978       {
4979         if(face[j].side!=NULL)
4980         {
4981           if (face[j].type == 7)       nf=1;  /* TRI3  */
4982           else if (face[j].type == 8)  nf=4; /* TRI6  */
4983           else if (face[j].type == 9)  nf=2; /* QUAD4 */
4984           else if (face[j].type == 10) nf=8; /* QUAD8 */
4985           else if (face[j].type == 11) nf=1; /* BEAM */
4986           else if (face[j].type == 12) nf=1; /* BEAM3 */
4987           for(k=0; k<nf; k++) free(face[j].side[k]);
4988           free(face[j].side);
4989           face[j].side=NULL;
4990         }
4991       }
4992       if(anz->p)
4993       {
4994         for(i=0; i<anz->p; i++) free(anz->pheader[i]);
4995         free(anz->pheader);
4996         anz->p=0;
4997       }
4998 
4999       anz->n=0;
5000       anz->e=0;
5001       anz->g=0;
5002       anz->f=0;
5003       anz->l=0;
5004       anz->nmax=0;
5005       anz->nmin=MAX_INTEGER;
5006       anz->emax=0;
5007       anz->emin=MAX_INTEGER;
5008       anz->orignmax=anz->orign=anz->olc=0;
5009       anz->nnext=1;
5010       anz->enext=1;
5011 
5012       for (j=0; j<anzGeo->p; j++)
5013       { free(point[j].nod);
5014         point[j].nod=NULL;
5015         point[j].nn=0; }
5016       for (j=0; j<anzGeo->l; j++)
5017       { free(line[j].nod); free(line[j].elem);
5018         line[j].nod=NULL; line[j].elem=NULL;
5019         line[j].nn=0; line[j].ne=0; }
5020       for (j=0; j<anzGeo->s; j++)
5021       { surf[j].nn=0; free(surf[j].nod); surf[j].nod=NULL;
5022         surf[j].ne=0; free(surf[j].elem); surf[j].elem=NULL; }
5023       for (j=0; j<anzGeo->b; j++)
5024       { body[j].nn=0; free(body[j].nod); body[j].nod=NULL;
5025         body[j].ne=0; free(body[j].elem); body[j].elem=NULL; }
5026       if(drawMode!=4) plot("w all");
5027       updateDispLists();
5028       createNewMainMenu();
5029     }
5030     else
5031     {
5032       j=pre_seta( specialset->zap, "i", 0 );
5033       for (k=0; k<set[setNr].anz_n; k++) seta(j, "n",set[setNr].node[k]);
5034       for (k=0; k<set[setNr].anz_e; k++) seta(j, "e",set[setNr].elem[k]);
5035       if( zap(specialset->zap)==-1)
5036          printf (" ERROR in ZAP: set:%s does not exist\n",specialset->zap );
5037     }
5038     return;
5039   }
5040   else if ((compare(type, "l0", 2) == 2 )&&(strlen(type)==2))  /* delete lines of zero length */
5041   {
5042     setNr=getSetNr(datum[0]);
5043     if(setNr<0)
5044     {
5045       printf(" ERROR: set %s does not exist\n",datum[0]);
5046       return;
5047     }
5048 
5049   searchNewZeroLines:;
5050     delSet("-mrgp");
5051     delSet(specialset->tmp);
5052     m=pre_seta("-mrgp","i", 0);
5053     k=pre_seta(specialset->tmp,"i", 0);
5054     z=pre_seta(specialset->zap,"i", 0);
5055 
5056     for(i=0; i<set[setNr].anz_l; i++)
5057     {
5058       j=set[setNr].line[i];
5059       if( line[j].name == (char *)NULL ) continue;
5060 
5061       /* check the length of the line */
5062       v_result( &point[line[j].p1].px, &point[line[j].p2].px, v01 );
5063       ds=v_betrag( v01 );
5064       if(ds==0.)
5065       {
5066         seta(k, "l",j);
5067         seta(z, "l",j);
5068       }
5069     }
5070 
5071     if(set[z].anz_l)
5072     {
5073       completeSet(specialset->tmp,"do");
5074       sprintf(buffer,"p %s n",specialset->tmp);
5075       pre_merge(buffer);
5076 
5077       /* delete the lines */
5078       for(i=0; i<set[z].anz_l; i++)
5079       {
5080         j=set[z].line[i];
5081         /* suche abhaengige lcmbs */
5082         for (jj=0; jj<anzGeo->c; jj++)
5083         {
5084           if( lcmb[jj].name != (char *)NULL )
5085           for (n=0; n<lcmb[jj].nl; n++)
5086           {
5087             if( j == lcmb[jj].l[n] )
5088             {
5089               if ((lines = (int *)malloc( (lcmb[jj].nl)*sizeof(int)) ) == NULL )
5090               { printf("ERROR: malloc failure\n"); return; }
5091               if ((ori = (char *)malloc( (lcmb[jj].nl)*sizeof(char)) ) == NULL )
5092               { printf("ERROR: malloc failure\n"); return; }
5093               l=0;
5094               if(lcmb[jj].nl>1)
5095   	      {
5096                 for (ll=0; ll<lcmb[jj].nl; ll++)
5097                 {
5098                   if(lcmb[jj].l[ll]!=j) { lines[l]= lcmb[jj].l[ll]; ori[l++]=lcmb[jj].o[ll]; }
5099                   else if(!ll) line[lcmb[jj].l[1]].div+=line[j].div;
5100                   else line[lcmb[jj].l[ll-1]].div+=line[j].div;
5101                 }
5102                 getNewName( buffer, "c" );
5103                 l=lcmb_i( buffer, 0, lcmb[jj].nl-1, ori, lines );
5104                 free(lines);
5105                 free(ori);
5106   	      }
5107               else l=-1;
5108 
5109               if (l >=0 )
5110   	      {
5111                 /* keep the original lcmb since the new lcmb was added to eventually open sets */
5112                 free(lcmb[jj].l);
5113                 free(lcmb[jj].o);
5114                 lcmb[jj].l=lcmb[l].l;
5115                 lcmb[jj].o=lcmb[l].o;
5116                 lcmb[jj].nl=lcmb[l].nl;
5117                 lcmb[jj].p1=lcmb[l].p1;
5118                 lcmb[jj].p2=lcmb[l].p2;
5119                 free(lcmb[l].name);
5120                 lcmb[l].name = (char *)NULL;
5121   	      }
5122               else
5123               {
5124                 printf(" ERROR in del: lcmb could not be redefined\n");
5125 
5126                 /* suche abhaengige surfs */
5127                 for (s=0; s<anzGeo->s; s++)
5128                 {
5129                   if( surf[s].name != (char *)NULL )
5130                   for (nn=0; nn<surf[s].nl; nn++)
5131                   {
5132                     if(( jj == surf[s].l[nn] )&&( surf[s].typ[nn] == 'c' ))
5133                     {
5134                       l=0;
5135                       for (ll=0; ll<surf[s].nl; ll++)
5136                       {
5137                         if(surf[s].l[ll]!=jj)
5138                         {
5139                           surf[s].l[l]=surf[s].l[ll];
5140                           surf[s].o[l]=surf[s].o[ll];
5141                           surf[s].typ[l]=surf[s].typ[ll];
5142                           l++;
5143                         }
5144   		        else
5145   		        {
5146                           if(surf[s].typ[ll]=='l') { seta(m,"p", line[surf[s].l[ll]].p1); seta(m,"p", line[surf[s].l[ll]].p2); }
5147                           if(surf[s].typ[ll]=='c') { seta(m,"p", lcmb[surf[s].l[ll]].p1); seta(m,"p", lcmb[surf[s].l[ll]].p2); }
5148   	                }
5149                       }
5150                       if (l <=0 )
5151                       {
5152                         printf(" WARNING: surf:%s is deleted\n", surf[s].name);
5153 
5154                         /* suche abhaengige bodies */
5155                         for (bb=0; bb<anzGeo->b; bb++)
5156                         {
5157                           if( body[bb].name != (char *)NULL )
5158                           for (b=0; b<body[bb].ns; b++)
5159                           {
5160                             if( jj == body[bb].s[b] )
5161                             {
5162                               ss=0;
5163                               for (ll=0; ll<body[bb].ns; ll++)
5164                               {
5165                                 if(body[bb].s[ll]!=jj)
5166                                 {
5167                                   body[bb].s[ss]=body[bb].s[ll];
5168                                   body[bb].o[ss]=body[bb].o[ll];
5169                                   ss++;
5170                                 }
5171 			      }
5172                               body[bb].ns=ss;
5173                               break;
5174 			    }
5175 			  }
5176 			}
5177 
5178                         sprintf(buffer,"s %s", surf[s].name);
5179                         pre_del(buffer);
5180   		      }
5181                       else surf[s].nl=l;
5182                       break;
5183                     }
5184                   }
5185                 }
5186               }
5187               break;
5188             }
5189           }
5190         }
5191 
5192         /* suche abhaengige surfs */
5193         for (jj=0; jj<anzGeo->s; jj++)
5194         {
5195           if( surf[jj].name != (char *)NULL )
5196           for (n=0; n<surf[jj].nl; n++)
5197           {
5198             if(( j == surf[jj].l[n] )&&( surf[jj].typ[n] == 'l' ))
5199             {
5200               l=0;
5201               for (ll=0; ll<surf[jj].nl; ll++)
5202               {
5203                 if(surf[jj].l[ll]!=j)
5204                 {
5205                   surf[jj].l[l]=surf[jj].l[ll];
5206                   surf[jj].o[l]=surf[jj].o[ll];
5207                   surf[jj].typ[l]=surf[jj].typ[ll];
5208                   l++;
5209                 }
5210   	        else
5211   	        {
5212                   if(surf[jj].typ[ll]=='l') { seta(m,"p", line[surf[jj].l[ll]].p1); seta(m,"p", line[surf[jj].l[ll]].p2); }
5213                   if(surf[jj].typ[ll]=='c') { seta(m,"p", lcmb[surf[jj].l[ll]].p1); seta(m,"p", lcmb[surf[jj].l[ll]].p2); }
5214   		}
5215               }
5216               if (l <=0 )
5217               {
5218                 printf(" WARNING: surf:%s is deleted\n", surf[jj].name);
5219 
5220                 /* suche abhaengige bodies */
5221                 for (bb=0; bb<anzGeo->b; bb++)
5222                 {
5223                   if( body[bb].name != (char *)NULL )
5224                   for (b=0; b<body[bb].ns; b++)
5225                   {
5226                     if( jj == body[bb].s[b] )
5227                     {
5228                       ss=0;
5229                       for (ll=0; ll<body[bb].ns; ll++)
5230                       {
5231                         if(body[bb].s[ll]!=jj)
5232                         {
5233                           body[bb].s[ss]=body[bb].s[ll];
5234                           body[bb].o[ss]=body[bb].o[ll];
5235                           ss++;
5236                         }
5237 		      }
5238                       body[bb].ns=ss;
5239                       break;
5240 		    }
5241 		  }
5242 		}
5243 
5244                 sprintf(buffer,"s %s", surf[jj].name);
5245                 pre_del(buffer);
5246   	      }
5247               else surf[jj].nl=l;
5248               break;
5249             }
5250           }
5251         }
5252       }
5253     }
5254     if(set[m].anz_p)
5255     {
5256       pre_merge("p -mrgp 0.");
5257       // new zero length lines could exist
5258       goto searchNewZeroLines;
5259     }
5260     zap(specialset->zap);
5261     delSet("-mrgp");
5262     return;
5263   }
5264   else if (compare(type, "t", 1) == 1 )
5265   {
5266     setNr=getSetNr(datum[0]);
5267     if(setNr<0)
5268     {
5269       printf(" ERROR: set |%s| does not exist\n",set[setNr].name);
5270       return;
5271     }
5272     for(i=0; i<set[setNr].anz_n; i++)
5273     {
5274       for(j=0; j<anz->t; j++)
5275         if(ntext[j].node_nr==set[setNr].node[i]) ntext[j].node_nr=0;
5276     }
5277     return;
5278   }
5279   else if (((compare(type, "n", 1) == 1 )||
5280       (compare(type, "e", 1) == 1 )||
5281       (compare(type, "p", 1) == 1 )||
5282       (compare(type, "l", 1) == 1 )||
5283       (compare(type, "c", 1) == 1 )||
5284       (compare(type, "s", 1) == 1 )||
5285       (compare(type, "v", 1) == 1 )||
5286       (compare(type, "b", 1) == 1 )||
5287       (compare(type, "S", 1) == 1 ))&&(strlen(type)==1))
5288   {
5289     for (n=0; n<i; n++) pre_seta( specialset->zap, type, datum[n] );
5290     if( zap(specialset->zap)==-1)
5291           printf (" ERROR in ZAP: set:%s does not exist\n",specialset->zap );
5292     return;
5293   }
5294   else printf(" ERROR: type %s not known\n", type);
5295 }
5296 
5297 
pre_bia(char * record)5298 void pre_bia( char *record)
5299 {
5300   int  j=0, nr, setNr;
5301   char setname[MAX_LINE_LENGTH], type[MAX_LINE_LENGTH];
5302   double factor=1., value=1.;
5303   double bias,div;
5304   int bias_fbd;     /* bias * 10 to gain one decimal digit (bias 10 == 100) */
5305 
5306   sscanf( record, "%s%s%lf%lf", setname, type, &factor, &value );
5307 
5308   if ((type[0]=='M')||(type[0]=='m')||(type[0]=='D')||(type[0]=='d') )
5309   {
5310     if ((type[0]=='D')||(type[0]=='d') ) factor=1./factor;
5311     operateAlias( setname, "se" );
5312     nr=getSetNr( setname );
5313     if(nr<0)
5314     {
5315       errMsg(" ERROR: %s is undefined\n", setname );
5316       return;
5317     }
5318     for (j=0; j<set[nr].anz_l; j++)
5319     {
5320       div=line[set[nr].line[j]].div;
5321       bias=line[set[nr].line[j]].bias;
5322       if(bias<1.)
5323       {
5324         bias_fbd= (pow(1./bias,(div-1.))*-10.)-.5;
5325         bias_fbd*=factor;
5326         if(bias_fbd>-10) line[set[nr].line[j]].bias=1.;
5327         else line[set[nr].line[j]].bias= 1./pow(((double)bias_fbd*-0.1), (1./((double)div-1.)));
5328       }
5329       else if(bias>1.)
5330       {
5331         bias_fbd= (pow(bias,(div-1.))*10)+.5;
5332         bias_fbd*=factor;
5333         if(bias_fbd<10) line[set[nr].line[j]].bias=1.;
5334         else line[set[nr].line[j]].bias=pow(((double)bias_fbd*0.1), (1./((double)div-1.)));
5335       }
5336     }
5337   }
5338   else if((type[0]>='1')&&(type[0]<='9'))
5339   {
5340     operateAlias( setname, "l" );
5341     nr=getLineNr( setname );
5342 
5343     operateAlias( setname, "se" );
5344     setNr=getSetNr( setname );
5345 
5346     /* its a line */
5347     if(nr>-1)
5348     {
5349       div=line[nr].div;
5350       bias=atof( &type[0])*factor;
5351       if(div>1)
5352       {
5353         if(bias<0) bias= 1./pow((bias*-1), (1./((double)div-1.)));
5354         else       bias=pow(bias, (1./((double)div-1.)));
5355       }
5356       else bias=1.;
5357       line[nr].bias=bias;
5358       repLine(nr);
5359     }
5360     /* its a set */
5361     else if(setNr>-1)
5362     {
5363       for (j=0; j<set[setNr].anz_l; j++)
5364       {
5365         div=line[set[setNr].line[j]].div;
5366         if(div>1)
5367         {
5368           bias=atof(type)*factor;
5369           if(bias<0) bias= 1./pow((bias*-1), (1./((double)div-1.)));
5370           else       bias=pow(bias, (1./((double)div-1.)));
5371         }
5372         else bias=1.;
5373 	printf("bias:%f factor:%f\n", bias,factor);
5374         line[set[setNr].line[j]].bias=bias;
5375       }
5376       for (j=0; j<set[setNr].anz_l; j++) repLine(set[setNr].line[j]);
5377     }
5378     else
5379     {
5380       errMsg(" ERROR: %s is undefined\n", setname );
5381       return;
5382     }
5383   }
5384   else
5385   {
5386     errMsg(" ERROR: command:|%s| not recognized\n", record );
5387   }
5388   return;
5389 }
5390 
5391 
pre_div(char * record)5392 void pre_div( char *record)
5393 {
5394   int  length,j=0, nr, setNr;
5395   char setname[MAX_LINE_LENGTH], type[MAX_LINE_LENGTH];
5396   double factor=1., value=1., bias=1., length_ratio=ELEM_LENGTH_RATIO;
5397   int bias_fbd,div;
5398 
5399   autoDivFlag=0;
5400   length= sscanf( record, "%s%s%lf%lf%lf", setname, type, &factor, &value, &length_ratio);
5401 
5402   if(length<1)
5403   {
5404     printf(" default:%d\n auto mode: lmax:%e angle:%.1f ratio:%.3f\n",ddiv,gtol*GTOL_NODE_DIST,acos(GTOL_COS_A)*180./PI, length_ratio);
5405     return;
5406   }
5407 
5408   if((length==1)&&(atoi(setname)>0))
5409   {
5410     printf("DDIV %s\n",setname);
5411     sprintf(type,"DDIV %s",setname);
5412     pre_proc(type);
5413   }
5414   else if ((length>2)||(compare(type, "auto", 1) == 1 ))
5415   {
5416     /* its a set */
5417     operateAlias( setname, "se" );
5418     nr=getSetNr( setname );
5419     if(nr<0)
5420     {
5421       errMsg(" ERROR: %s is undefined\n", setname );
5422       return;
5423     }
5424     if ((type[0]=='A')||(type[0]=='a') )
5425     {
5426       if(length_ratio>1.)
5427       {
5428         printf(" ERROR: element length ratio must be lower than 1 but is:%f\n", length_ratio  );
5429         return;
5430       }
5431       if(length==2) { value=GTOL_COS_A; factor=gtol*GTOL_NODE_DIST/scale->w; }
5432       else if(length==3) { value=GTOL_COS_A; factor/=scale->w; }
5433       else  { value=cos(value*PI/180.); factor/=scale->w; }
5434       for (j=0; j<set[nr].anz_l; j++)
5435       {
5436 	if(line[set[nr].line[j]].name!=NULL)
5437           calcLineDiv(line, set[nr].line[j], value, factor, factor*length_ratio  );
5438       }
5439     }
5440     else if ((type[0]=='M')||(type[0]=='m') )
5441     {
5442       for (j=0; j<set[nr].anz_l; j++) if(line[set[nr].line[j]].name!=NULL)
5443       {
5444         if((line[set[nr].line[j]].bias!=1.)&&(line[set[nr].line[j]].div>1))
5445 	{
5446           if(line[set[nr].line[j]].bias<1.)
5447 	  {
5448             bias_fbd= (int)((pow(1./line[set[nr].line[j]].bias,(line[set[nr].line[j]].div-1.))*-10.) -0.5) * value;
5449 	  }
5450           else
5451 	  {
5452             bias_fbd= (int)((pow(line[set[nr].line[j]].bias,(line[set[nr].line[j]].div-1.))*10.) +0.5) * value;
5453 	  }
5454           line[set[nr].line[j]].div*=factor;
5455           if(bias_fbd*bias_fbd<10.) line[set[nr].line[j]].bias=1.;
5456           else
5457           {
5458             if(bias_fbd<0) line[set[nr].line[j]].bias= 1./pow((bias_fbd*-.1), (1./((double)line[set[nr].line[j]].div-1.)));
5459             else       line[set[nr].line[j]].bias=pow((bias_fbd*.1), (1./((double)line[set[nr].line[j]].div-1.)));
5460           }
5461         }
5462         else line[set[nr].line[j]].div*=factor;
5463       }
5464     }
5465     else if ((type[0]=='D')||(type[0]=='d') )
5466     {
5467       for (j=0; j<set[nr].anz_l; j++) if(line[set[nr].line[j]].name!=NULL)
5468       {
5469         if((line[set[nr].line[j]].bias!=1.)&&(line[set[nr].line[j]].div>1))
5470 	{
5471           if(line[set[nr].line[j]].bias<1.)
5472 	  {
5473             bias_fbd= (int)((pow(1./line[set[nr].line[j]].bias,(line[set[nr].line[j]].div-1.))*-10.) -0.5) / value;
5474 	  }
5475           else
5476 	  {
5477             bias_fbd= (int)((pow(line[set[nr].line[j]].bias,(line[set[nr].line[j]].div-1.))*10.) +0.5) / value;
5478 	  }
5479           line[set[nr].line[j]].div/=factor;
5480           if(bias_fbd*bias_fbd<10.) line[set[nr].line[j]].bias=1.;
5481           else
5482           {
5483             if(bias_fbd<0) line[set[nr].line[j]].bias= 1./pow((bias_fbd*-.1), (1./((double)line[set[nr].line[j]].div-1.)));
5484             else       line[set[nr].line[j]].bias=pow((bias_fbd*.1), (1./((double)line[set[nr].line[j]].div-1.)));
5485           }
5486         }
5487         else line[set[nr].line[j]].div/=factor;
5488         if(line[set[nr].line[j]].div<1) line[set[nr].line[j]].div=1;
5489         if(line[set[nr].line[j]].div==1) line[set[nr].line[j]].bias=1;
5490       }
5491     }
5492     else if (length==2)
5493     {
5494       div=atoi(type);
5495       splitBiasDiv(&div, &bias);
5496       line[set[nr].line[j]].div=div;
5497       line[set[nr].line[j]].bias=bias;
5498     }
5499     else printf(" ERROR: type %s not known\n", type);
5500 
5501     for (j=0; j<set[nr].anz_l; j++) repLine(set[nr].line[j]);
5502   }
5503   else if((length==2)&&(type[0]>='1')&&(type[0]<='9'))
5504   {
5505     operateAlias( setname, "l" );
5506     nr=getLineNr( setname );
5507 
5508     operateAlias( setname, "se" );
5509     setNr=getSetNr( setname );
5510 
5511     /* its a line */
5512     if(nr>-1)
5513     {
5514       div=atoi(type);
5515       //splitBiasDiv(&div, &bias);
5516 
5517       line[nr].div=div;
5518       //line[nr].bias=bias;
5519       repLine(nr);
5520     }
5521     /* its a set */
5522     else if(setNr>-1)
5523     {
5524       div=atoi(type);
5525       //splitBiasDiv(&div, &bias);
5526       for (j=0; j<set[setNr].anz_l; j++) if(line[set[setNr].line[j]].name!=NULL)
5527       {
5528         line[set[setNr].line[j]].div=div;
5529         //line[set[setNr].line[j]].bias=bias;
5530       }
5531       for (j=0; j<set[setNr].anz_l; j++) repLine(set[setNr].line[j]);
5532     }
5533     else
5534     {
5535       errMsg(" ERROR: %s is undefined\n", setname );
5536       return;
5537     }
5538   }
5539   else
5540   {
5541     errMsg(" ERROR: command:|%s| not recognized\n", record );
5542   }
5543   return;
5544 }
5545 
5546 
pre_move(char * record)5547 void pre_move( char *record)
5548 {
5549   int  length, i,j,k,p, setNr, nr;
5550   char setname[MAX_LINE_LENGTH];
5551   char type[MAX_LINE_LENGTH];
5552   Nodes *bufn;
5553   char addDispFlagLocal=0;
5554 
5555   length = sword( record, setname );
5556   sword( &record[length], type );
5557 
5558   operateAlias( setname, "se" );
5559   setNr=getSetNr( setname );
5560   if (setNr<0)
5561   {
5562     errMsg(" ERROR: Set (%s) is undefined\n", setname );
5563     return;
5564   }
5565   nr=setNr;
5566 
5567   if (set[nr].anz_p>set[nr].anz_n) i=set[nr].anz_p;
5568   else                             i=set[nr].anz_n;
5569 
5570   if ( (bufn = (Nodes *)malloc( (i+1) * sizeof(Nodes))) == NULL )
5571   {  printf("\n\n ERROR: malloc failed in pre_move(): i=%d\n\n", i) ; return; }
5572 
5573 
5574   if(set[nr].anz_p>0)
5575   {
5576     for (i=0; i<set[nr].anz_p; i++)
5577     {
5578       p=set[nr].pnt[i];
5579       if (p==-1)
5580       {
5581         errMsg(" ERROR: Point-nr:%d is undefined\n", set[nr].pnt[i] );
5582         return;
5583       }
5584       bufn[i].indx=p;
5585       bufn[i].nx=point[p].px*scale->w+scale->x;
5586       bufn[i].ny=point[p].py*scale->w+scale->y;
5587       bufn[i].nz=point[p].pz*scale->w+scale->z;
5588     }
5589     if(transform( &record[length], set[nr].anz_p, bufn )<0) return;
5590 
5591     for (i=0; i<set[nr].anz_p; i++)
5592     {
5593       p=set[nr].pnt[i];
5594       point[p].px= (bufn[i].nx-scale->x)/scale->w;
5595       point[p].py= (bufn[i].ny-scale->y)/scale->w;
5596       point[p].pz= (bufn[i].nz-scale->z)/scale->w;
5597     }
5598   }
5599   if(set[nr].anz_n>0)
5600   {
5601     /* when node coordinates were changed to the deformed ones then switch back before they are copied and then switch again */
5602     if(addDispFlag)
5603     {
5604       addDispToCoordinates(node);
5605       // remember to switch back
5606       addDispFlagLocal=2;
5607     }
5608 
5609     for (i=0; i<set[nr].anz_n; i++)
5610     {
5611       bufn[i].indx=set[nr].node[i];
5612       bufn[i].nx=node[set[nr].node[i]].nx* scale->w+scale->x;
5613       bufn[i].ny=node[set[nr].node[i]].ny* scale->w+scale->y;
5614       bufn[i].nz=node[set[nr].node[i]].nz* scale->w+scale->z;
5615     }
5616     if ( transform( &record[length], set[nr].anz_n, bufn) <0) return;
5617     for (i=0; i<set[nr].anz_n; i++)
5618     {
5619       node[set[nr].node[i]].nx= (bufn[i].nx-scale->x)/scale->w;
5620       node[set[nr].node[i]].ny= (bufn[i].ny-scale->y)/scale->w;
5621       node[set[nr].node[i]].nz= (bufn[i].nz-scale->z)/scale->w;
5622     }
5623 
5624     if(addDispFlagLocal==2)
5625     {
5626       addDispToCoordinates(node);
5627     }
5628   }
5629 
5630   /* the additional nodes for the HE20 etc. (then HE26) elements need a new pos. too  */
5631   if(anz->e>0)
5632   {
5633     // correct the elementsm needed if the mesh was mirrored
5634     setall=getSetNr("all");
5635     elemChecker( set[setall].anz_e, set[setall].elem, node, e_enqire);
5636     adjustDrawNodes(0);
5637     getElemNormalen( e_enqire, node, anz->e );
5638     makeSurfaces();
5639     updateDispLists();
5640   }
5641 
5642   /* dependent higher entities need new label-positions, achived with orient */
5643   /* create a set with the dependent higher entities to be oriented  */
5644 
5645   /* add all points to special set _ORI  */
5646   if(set[nr].anz_p>0)
5647   {
5648     if( (i=pre_seta( specialset->ori, "i", 0 )) <0 ) return;
5649     for (k=0; k<set[nr].anz_p; k++)
5650     {
5651       p=set[nr].pnt[k];
5652       seta( i, "p", p );
5653     }
5654     completeSet( specialset->ori, "up");
5655     orientSet( specialset->ori );
5656 
5657     /*  recalculate the line-shapes    */
5658     for (j=0; j<set[i].anz_l; j++) repLine(set[i].line[j]);
5659 
5660     /* clear special set  */
5661     delSet(specialset->ori);
5662   }
5663   free (bufn);
5664   if(( compare(type,"sca",3) == 3 )||( compare(type,"SCA",3) == 3 ))
5665   { frame(); frameSetFlag=-1; }
5666 }
5667 
5668 
5669 
pre_move_pfast(char * record)5670 void pre_move_pfast( char *record)
5671 {
5672   int  length, i,p, setNr, nr;
5673   char setname[MAX_LINE_LENGTH];
5674   char type[MAX_LINE_LENGTH];
5675   Nodes *bufn;
5676 
5677   length = sword( record, setname );
5678   sword( &record[length], type );
5679 
5680   setNr=getSetNr( setname );
5681   if (setNr<0)
5682   {
5683     errMsg(" ERROR: Set (%s) is undefined\n", setname );
5684     return;
5685   }
5686   nr=setNr;
5687 
5688   i=set[nr].anz_p;
5689 
5690   if ( (bufn = (Nodes *)malloc( (i+1) * sizeof(Nodes))) == NULL )
5691   {  printf("\n\n ERROR: malloc failed in pre_move(): i=%d\n\n", i) ; return; }
5692 
5693 
5694   if(set[nr].anz_p>0)
5695   {
5696     for (i=0; i<set[nr].anz_p; i++)
5697     {
5698       p=set[nr].pnt[i];
5699       if (p==-1)
5700       {
5701         errMsg(" ERROR: Point-nr:%d is undefined\n", set[nr].pnt[i] );
5702         return;
5703       }
5704       bufn[i].nx=point[p].px*scale->w+scale->x;
5705       bufn[i].ny=point[p].py*scale->w+scale->y;
5706       bufn[i].nz=point[p].pz*scale->w+scale->z;
5707     }
5708     if(transform( &record[length], set[nr].anz_p, bufn )<0) return;
5709 
5710     for (i=0; i<set[nr].anz_p; i++)
5711     {
5712       p=set[nr].pnt[i];
5713       point[p].px= (bufn[i].nx-scale->x)/scale->w;
5714       point[p].py= (bufn[i].ny-scale->y)/scale->w;
5715       point[p].pz= (bufn[i].nz-scale->z)/scale->w;
5716     }
5717   }
5718 }
5719 
5720 
5721 
free_proj(double * nx,double * nrad,int * nmissed)5722 void free_proj(double *nx, double *nrad, int *nmissed)
5723 {
5724   free (nx);
5725   free (nrad);
5726   free (nmissed);
5727   delSet(specialset->dep );
5728   delSet(specialset->ind );
5729 }
5730 
5731 
5732 
pre_proc(char * record)5733 void pre_proc( char *record)
5734 {
5735   int  i;
5736   char action[MAX_LINE_LENGTH], param[MAX_LINE_LENGTH];
5737 
5738   sscanf( record,"%s %s", action, param);
5739 
5740   for(i=0; i<strlen(action); i++) action[i]=toupper(action[i]);
5741   if (compareStrings(action, "DDIV")>0)
5742   {
5743     ddiv=atoi(param);
5744     splitBiasDiv(&ddiv, &dbias);
5745   }
5746 }
5747 
5748 
5749 /* l line, l_nr two new lines, ps_nr split-point */
splitLine(int l,int * l_nr,int ps_nr)5750 int splitLine(int l, int *l_nr, int ps_nr)
5751 {
5752   int  i,j,k,n,p,pp;
5753   int  setNr, setNr0, setNr1;
5754   char name[MAX_LINE_LENGTH], trk[2][MAX_LINE_LENGTH];
5755 
5756   int p1_nr, p2_nr, i_min;
5757   char linbuf[MAX_LINE_LENGTH];
5758   double lbez, lbez_min=MAX_FLOAT, div;
5759   double p0[3], p1[3], p01[3], v01[3], p10[3], v10[3];
5760 
5761   double ltot,l1,sp1,sp2,nodeSpacing;
5762   int    div1,div2;
5763 
5764 
5765   /*  erzeuge den trk der neuen linien */
5766   if (line[l].typ=='a')
5767   {
5768     strcpy( trk[0], point[line[l].trk].name );
5769     strcpy( trk[1], point[line[l].trk].name );
5770   }
5771   else if (line[l].typ=='s')
5772   {
5773     repLine(l);  // scal might have changed
5774 
5775     /* suche alle punkte des trk die vor dem schnittpunkt liegen und ordne sie einem */
5776     /* neuen set zu und loesche sie aus dem bestehenden trk */
5777     /* erzeuge zwei neue sets fuer die stuetzpunkte der zwei neuen linien */
5778     getNewName( trk[0], "se" );
5779     setNr0=pre_seta( trk[0], "is", 0);
5780 
5781     getNewName( trk[1], "se" );
5782     setNr1=pre_seta( trk[1], "is", 0);
5783 
5784     //printf(" new seq: %d,%s,%s %d,%s,%s\n", setNr0,set[setNr0].name,trk[0], setNr1,set[setNr1].name,trk[1] );
5785 
5786     /* search the intervall in which the split point exists.
5787        This is the case if the distances between interval endpoints and plitpoint has a minimum.
5788     */
5789     setNr=line[l].trk;
5790     p0[0]=line[l].ip[0];
5791     p0[1]=line[l].ip[1];
5792     p0[2]=line[l].ip[2];
5793     for (i=3; i<line[l].nip; i+=3)
5794     {
5795       lbez=0.;
5796       p1[0]=line[l].ip[i]  ;
5797       p1[1]=line[l].ip[i+1];
5798       p1[2]=line[l].ip[i+2];
5799       v_result( p0, &point[ps_nr].px, p01  );
5800       lbez+=v_betrag( p01 );
5801       v_result( p1, &point[ps_nr].px, p01  );
5802       lbez+=v_betrag( p01 );
5803       p0[0]=p1[0];
5804       p0[1]=p1[1];
5805       p0[2]=p1[2];
5806       if(lbez<lbez_min) { lbez_min=lbez; i_min=i; }
5807       //printf("lbez:%f lbez_min:%f i:%d i_min:%d\n", lbez, lbez_min, i,i_min );
5808     }
5809     v_result(p0, p1, p01);
5810     nodeSpacing=v_betrag( p01 );
5811     //printf("x lbez_min:%f i_min:%d\n", lbez_min, i_min );
5812 
5813     // use v_scal to determine if the current point is in the interval, then take next point
5814     k=0;
5815     seta( setNr0, "ps", line[l].p1 );
5816     if( line[l].p1==set[setNr].pnt[0] ) pp=1;
5817     else { printf(" ERROR in seq:%s\n", set[setNr].name); return(-1); }
5818     //p=0; printf("l1 p[%d]:%s p %f %f %f \n",p, point[set[setNr].pnt[p]].name, point[set[setNr].pnt[p]].px,point[set[setNr].pnt[p]].py,point[set[setNr].pnt[p]].pz);
5819     p0[0]=line[l].ip[0];
5820     p0[1]=line[l].ip[1];
5821     p0[2]=line[l].ip[2];
5822     for (i=3; i<line[l].nip; i+=3)
5823     {
5824       p1[0]=line[l].ip[i]  ;
5825       p1[1]=line[l].ip[i+1];
5826       p1[2]=line[l].ip[i+2];
5827       v_result( p0, p1, v01  );
5828       v_result( p1, p0, v10  );
5829       //printf("i:%d line[l].nip:%d p1 %f %f %f p2: %f %f %f\n",i,line[l].nip,p0[0],p0[1],p0[2],p1[0],p1[1],p1[2]);
5830       //printf(" p01 %f %f %f p10: %f %f %f\n",v01[0],v01[1],v01[2],v10[0],v10[1],v10[2]);
5831       //printf(" i:%d i_min:%d\n",  i,i_min );
5832       if(i<i_min)
5833       {
5834         // search all points in the interval and add them to the set
5835         for ( ; pp<set[setNr].anz_p; pp++)
5836         {
5837 	  if( line[l].p1==set[setNr].pnt[0] ) p=pp;
5838           else p=set[setNr].anz_p-1-pp;
5839 
5840           //printf("l1 p[%d]:%s p %f %f %f \n",p, point[set[setNr].pnt[p]].name, point[set[setNr].pnt[p]].px,point[set[setNr].pnt[p]].py,point[set[setNr].pnt[p]].pz);
5841 
5842           // use v_scal to determine if the current point is in the interval, then take next point (TBD)
5843 	  // the scalar product must be twice positive
5844           v_result( p0, &point[set[setNr].pnt[p]].px, p01  );
5845           sp1=v_sprod(p01,v01);
5846           v_result( p1, &point[set[setNr].pnt[p]].px, p10  );
5847           sp2=v_sprod(p10,v10);
5848           //printf("i:%d line[l].nip:%d p1 %f %f %f p2: %f %f %f\n",i,line[l].nip,p0[0],p0[1],p0[2],p1[0],p1[1],p1[2]);
5849 	  //printf(" p01 %f %f %f p10: %f %f %f     sp %e %e \n",p01[0],p01[1],p01[2],p10[0],p10[1],p10[2],sp1,sp2);
5850 	  //printf("l1 p[%d]:%s  sp %e %e \n",p,point[set[setNr].pnt[p]].name,sp1,sp2);
5851           if((sp1>=0.)&&(sp2>=0.))
5852 	      seta( setNr0, "ps", set[setNr].pnt[p] );
5853           else break;
5854         }
5855       }
5856       else
5857       {
5858         if(!k)
5859         {
5860           //printf("switch at p[%d]:%s\n",p, point[set[setNr].pnt[p]].name);
5861 
5862 	  // go over the points up to the splitpoint
5863           for (;pp<set[setNr].anz_p; pp++)
5864           {
5865   	    if( line[l].p1==set[setNr].pnt[0] ) p=pp;
5866             else p=set[setNr].anz_p-1-pp;
5867 
5868   	    // the scalar product in the interval to ps_nr  must be twice positive
5869             v_result( p0, &point[set[setNr].pnt[p]].px, p01  );
5870             sp1=v_sprod(p01,v01);
5871             v_result( &point[ps_nr].px, &point[set[setNr].pnt[p]].px, p10  );
5872   	    sp2=v_sprod(p10,v10);
5873             //printf("l2.1 p[%d]:%s  sp %f %f\n",p, point[set[setNr].pnt[p]].name, sp1,sp2);
5874   	    if((sp1>=0.)&&(sp2>=0.))
5875   	    {
5876               /* use the last track-point only if the distance to ps_nr is significant */
5877               v_result( &point[set[setNr].pnt[p]].px, &point[ps_nr].px, p01  );
5878   	      if(v_betrag( p01 )>nodeSpacing*.1) seta( setNr0, "ps", set[setNr].pnt[p] );
5879    	    }
5880             else break;
5881           }
5882 
5883 	  //pp++;
5884           seta( setNr0, "ps", ps_nr );
5885           seta( setNr1, "ps", ps_nr ); k++;
5886         }
5887 
5888         // search all points in the interval and add them to the set
5889         for (;pp<set[setNr].anz_p; pp++)
5890         {
5891 	  if( line[l].p1==set[setNr].pnt[0] ) p=pp;
5892           else p=set[setNr].anz_p-1-pp;
5893 
5894 	  // the scalar product must be twice positive
5895           v_result( p0, &point[set[setNr].pnt[p]].px, p01  );
5896           sp1=v_sprod(p01,v01);
5897           v_result( p1, &point[set[setNr].pnt[p]].px, p10  );
5898 	  sp2=v_sprod(p10,v10);
5899           //printf("l2.2 p[%d]:%s  sp %f %f set:%s\n",p, point[set[setNr].pnt[p]].name, sp1,sp2, set[setNr1].name);
5900   	  if((sp1>=0.)&&(sp2>=0.))
5901   	  {
5902             /* use the last track-point only if the distance to ps_nr is significant */
5903             v_result( &point[set[setNr].pnt[p]].px, &point[ps_nr].px, p01  );
5904   	    if(v_betrag( p01 )>nodeSpacing*.1) seta( setNr1, "ps", set[setNr].pnt[p] );
5905    	  }
5906           else break;
5907         }
5908       }
5909       p0[0]=p1[0];
5910       p0[1]=p1[1];
5911       p0[2]=p1[2];
5912     }
5913     if(line[l].p2!=set[setNr1].pnt[set[setNr1].anz_p-1])
5914       seta( setNr1, "ps", line[l].p2 );
5915     //printf("p2:%s plast:%s\n", point[line[l].p2].name, point[set[setNr1].pnt[set[setNr1].anz_p-1]].name);
5916     if(set[setNr0].anz_p<2) strcpy(trk[0], " ");
5917     if(set[setNr1].anz_p<2) strcpy(trk[1], " ");
5918   }
5919   else
5920   {
5921     strcpy(trk[0], " ");
5922     strcpy(trk[1], " ");
5923   }
5924 
5925   /* sichere den liniennamen bevor der pointer durch realloc in line_ geaendert wird  */
5926   strcpy( linbuf, line[l].name);
5927 
5928   /* erzeuge zwei neue linien  */
5929   p1_nr = line[l].p1;
5930   p2_nr = line[l].p2;
5931   div=1;
5932   getNewName( name, "l" );
5933   if(printFlag) printf(" create line:%s %s %s %s %lf\n", name, point[p1_nr].name, point[ps_nr].name, trk[0], div );
5934   line_( name, point[p1_nr].name, point[ps_nr].name, trk[0], div, 1 );
5935   l_nr[0]=getLineNr(name);
5936   getNewName( name, "l" );
5937   if(printFlag) printf(" create line:%s %s %s %s %lf\n", name, point[ps_nr].name, point[p2_nr].name, trk[1], div );
5938   line_( name, point[ps_nr].name, point[p2_nr].name, trk[1], div, 1 );
5939   l_nr[1]=getLineNr(name);
5940 
5941   /* add snew to sets which contain linbuf */
5942   for(i=0; i<anz->sets; i++)
5943   {
5944     if(!set[i].type)
5945       if((set[i].name!=(char *)NULL)&&(set[i].name[0]!='-')&&(i!=setall)&&( getIndex(&set[i].line,set[i].anz_l,l) >-1)) { seta(i,"l",l_nr[0]); seta(i,"l",l_nr[1]); }
5946   }
5947 
5948   /* calc new div */
5949   if (line[l].div>1)
5950   {
5951     ltot=calcLineLength(l);
5952     l1=calcLineLength(l_nr[0]);
5953     div1=line[l].div/ltot*l1;
5954     // force an even number
5955     if(div1%2!=0) div1++;
5956     div2=line[l].div-div1;
5957     if(printFlag)  printf("1 ltot:%lf l1:%lf ldiv:%d div1:%d div2:%d\n", ltot,l1,line[l].div,div1,div2);
5958 
5959     if(div1<2) { div1=2; div2=line[l].div-div1; }
5960     if(div2<2) { div2=2; }
5961     line[l_nr[0]].div=div1;
5962     line[l_nr[1]].div=div2;
5963     if(printFlag)  printf("2 ltot:%lf l1:%lf ldiv:%d div1:%d div2:%d\n", ltot,l1,line[l].div,div1,div2);
5964     repLine(l_nr[0]);
5965     repLine(l_nr[1]);
5966   }
5967   /* untersuche alle lcmbs ob linbuf ein Mitglied ist */
5968   for (i=0; i<anzGeo->c; i++) if( lcmb[i].name != (char *)NULL )
5969   {
5970     for (j=0; j<lcmb[i].nl; j++)
5971     {
5972       if( l == lcmb[i].l[j] )
5973       {
5974          printf (" realloc lcmb:%s and replace line:%s with %s and %s \n",
5975            lcmb[i].name, line[l].name,line[l_nr[0]].name, line[l_nr[1]].name );
5976         if ((lcmb[i].o = (char *)realloc( (char *)lcmb[i].o, (lcmb[i].nl+1)*sizeof(char)) ) == NULL )
5977         { printf("\n\n ERROR: realloc failure in qspl, lcmb.o:%s not changed\n\n",lcmb[i].name ); return(-1); }
5978         if ((lcmb[i].l = (int *)realloc( (int *)lcmb[i].l, (lcmb[i].nl+1)*sizeof(int)) ) == NULL )
5979         { printf("\n\n ERROR: realloc failure in qspl, lcmb.l:%s not changed\n\n", lcmb[i].name); return(-1); }
5980 	/* umspeichern der linien beginnend bei der letzten bis einschlieslich j */
5981         for (n=lcmb[i].nl; n>j; n--)
5982 	{
5983           lcmb[i].o[n]=lcmb[i].o[n-1];
5984           lcmb[i].l[n]=lcmb[i].l[n-1];
5985         }
5986         /* Auffuellen der j, j+1 pos. mit l1, l2 mit der Orientierung der gesplitteten linie */
5987         lcmb[i].o[j+1]=lcmb[i].o[j];
5988         if(lcmb[i].o[j]=='+')
5989 	{
5990           lcmb[i].l[j]=l_nr[0];
5991           lcmb[i].l[j+1]=l_nr[1];
5992 	}
5993         else
5994 	{
5995           lcmb[i].l[j+1]=l_nr[0];
5996           lcmb[i].l[j]=l_nr[1];
5997 	}
5998         lcmb[i].nl++;
5999       }
6000     }
6001   }
6002 
6003 
6004   /* untersuche alle surfs ob linbuf ein Mitglied ist und ersetze sie durch eine lcmb */
6005   /* kontrolliere ob nicht schon eine geeignete lcmb existiert */
6006   for (i=0; i<anzGeo->s; i++) if( surf[i].name != (char *)NULL )
6007   {
6008     for (j=0; j<surf[i].nl; j++)
6009     {
6010       if(( l == surf[i].l[j] )&&( surf[i].typ[j]=='l' ))
6011       {
6012 
6013         /* do we already have a suitable lcmb? */
6014         for (n=0; n<anzGeo->c; n++ ) if( lcmb[n].name != (char *)NULL )
6015 	{
6016           if (lcmb[n].nl==2)   /* same amount of lines */
6017 	  {
6018 	    /*
6019             printf ("checke lcmb:%s \n", lcmb[n].name);
6020 	    */
6021             if (((lcmb[n].l[0]==l_nr[0])||(lcmb[n].l[0]==l_nr[1])) && ((lcmb[n].l[1]==l_nr[0])||(lcmb[n].l[1]==l_nr[1])))
6022 	    {
6023 	      /*
6024               printf ("equal:%s\n",lcmb[n].name);
6025 	      */
6026               break;
6027 	    }
6028 	  }
6029         }
6030         if (n>=anzGeo->c)  /* no lcmb was found, so create one */
6031         {
6032           /* create lcmb */
6033           if ( getNewName( name, "c" ) == -1 )
6034           { printf("Type c not known, lcmb can not be created\n"); exit(-1); }
6035           lcmb_i( name, (int)0, (int)2, "++", l_nr );
6036           n=getLcmbNr( name );
6037         }
6038         printf ("realloc surf:%s and replace line:%s with lcmb:%s made of %s and %s \n",
6039           surf[i].name, line[l].name, name, line[l_nr[0]].name, line[l_nr[1]].name );
6040         if (n>-1) { surf[i].l[j]=n; surf[i].o[j]='+'; surf[i].typ[j]='c'; }
6041         else { errMsg("lcmb not known, surface could not be changed \n"); return(-1); }
6042       }
6043     }
6044   }
6045 
6046   return(1);
6047 }
6048 
6049 
genSplitTrias(int trgtNr,Tri ** ptr_tri,int scalFlag)6050 int genSplitTrias(int trgtNr, Tri **ptr_tri, int scalFlag )
6051 {
6052   int i,j,n,s;
6053   int sum_tri=0, ss;
6054   Tri *tri;
6055 
6056   tri=*ptr_tri;
6057 
6058   for (ss=0; ss<set[trgtNr].anz_sh; ss++)
6059   {
6060     s=set[trgtNr].shp[ss];
6061     if(printFlag) printf("shape:%s\n", shape[s].name);
6062 
6063     /* go over all shapes */
6064     n=0;
6065     while((shape[s].npgn-n))
6066     {
6067       /* alloc a new tri */
6068       if ( (tri = (Tri *)realloc( (Tri *)tri, (sum_tri+2) * sizeof(Tri))) == NULL )
6069       {
6070         errMsg("\nERROR: realloc failed in genSplitTrias() \n\n");
6071       }
6072 
6073       /* requires that only triangles are used for the interiour description of the shape */
6074       /* this is regarded by the adjustFeedBack() routine */
6075       //n+=5; /* jump over the leading bytes */
6076       tri[sum_tri].p1[0]=shape[s].pgn[n++];
6077       tri[sum_tri].p1[1]=shape[s].pgn[n++];
6078       tri[sum_tri].p1[2]=shape[s].pgn[n++];
6079       tri[sum_tri].p2[0]=shape[s].pgn[n++];
6080       tri[sum_tri].p2[1]=shape[s].pgn[n++];
6081       tri[sum_tri].p2[2]=shape[s].pgn[n++];
6082       tri[sum_tri].p3[0]=shape[s].pgn[n++];
6083       tri[sum_tri].p3[1]=shape[s].pgn[n++];
6084       tri[sum_tri].p3[2]=shape[s].pgn[n++];
6085       tri[sum_tri].fnr= -1;
6086       sum_tri++;
6087     }
6088   }
6089   /* go over all surfs */
6090   for (ss=0; ss<set[trgtNr].anz_s; ss++)
6091   {
6092     s=set[trgtNr].surf[ss];
6093     if(printFlag) printf("surface:%s\n", surf[s].name);
6094 
6095     /* go over all tri */
6096     n=0;
6097     while((surf[s].npgn-n))
6098     {
6099       /* alloc a new tri */
6100       if ( (tri = (Tri *)realloc( (Tri *)tri, (sum_tri+2) * sizeof(Tri))) == NULL )
6101       {
6102         errMsg("\nERROR: realloc failed in genSplitTrias() \n\n");
6103       }
6104 
6105       /* requires that only triangles are used for the interiour description of the surface */
6106       /* this is regarded by the adjustFeedBack() routine */
6107       n+=5; /* jump over the leading bytes */
6108       tri[sum_tri].p1[0]=surf[s].pgn[n++];
6109       tri[sum_tri].p1[1]=surf[s].pgn[n++];
6110       tri[sum_tri].p1[2]=surf[s].pgn[n++];
6111       tri[sum_tri].p2[0]=surf[s].pgn[n++];
6112       tri[sum_tri].p2[1]=surf[s].pgn[n++];
6113       tri[sum_tri].p2[2]=surf[s].pgn[n++];
6114       tri[sum_tri].p3[0]=surf[s].pgn[n++];
6115       tri[sum_tri].p3[1]=surf[s].pgn[n++];
6116       tri[sum_tri].p3[2]=surf[s].pgn[n++];
6117       tri[sum_tri].fnr= -1;
6118       sum_tri++;
6119     }
6120   }
6121   for (ss=0; ss<set[trgtNr].anz_f; ss++)
6122   {
6123     i=set[trgtNr].face[ss];
6124 
6125     if (face[i].type == 7)  /* TRI3  */
6126     {
6127       if ( (tri = (Tri *)realloc( (Tri *)tri, (sum_tri+2) * sizeof(Tri))) == NULL )
6128         errMsg("\nERROR: realloc failed in genSplitTrias() \n\n");
6129       tri[sum_tri].p1[0]=node[face[i].nod[0]].nx;
6130       tri[sum_tri].p1[1]=node[face[i].nod[0]].ny;
6131       tri[sum_tri].p1[2]=node[face[i].nod[0]].nz;
6132       tri[sum_tri].p2[0]=node[face[i].nod[1]].nx;
6133       tri[sum_tri].p2[1]=node[face[i].nod[1]].ny;
6134       tri[sum_tri].p2[2]=node[face[i].nod[1]].nz;
6135       tri[sum_tri].p3[0]=node[face[i].nod[2]].nx;
6136       tri[sum_tri].p3[1]=node[face[i].nod[2]].ny;
6137       tri[sum_tri].p3[2]=node[face[i].nod[2]].nz;
6138       tri[sum_tri].fnr= i;
6139       sum_tri++;
6140     }
6141     else if (face[i].type == 8)  /* TRI6  */
6142     {
6143       if ( (tri = (Tri *)realloc( (Tri *)tri, (sum_tri+6) * sizeof(Tri))) == NULL )
6144         errMsg("\nERROR: realloc failed in genSplitTrias() \n\n");
6145       tri[sum_tri].p1[0]=node[face[i].nod[0]].nx;
6146       tri[sum_tri].p1[1]=node[face[i].nod[0]].ny;
6147       tri[sum_tri].p1[2]=node[face[i].nod[0]].nz;
6148       tri[sum_tri].p2[0]=node[face[i].nod[3]].nx;
6149       tri[sum_tri].p2[1]=node[face[i].nod[3]].ny;
6150       tri[sum_tri].p2[2]=node[face[i].nod[3]].nz;
6151       tri[sum_tri].p3[0]=node[face[i].nod[5]].nx;
6152       tri[sum_tri].p3[1]=node[face[i].nod[5]].ny;
6153       tri[sum_tri].p3[2]=node[face[i].nod[5]].nz;
6154       sum_tri++;
6155       tri[sum_tri].p1[0]=node[face[i].nod[2]].nx;
6156       tri[sum_tri].p1[1]=node[face[i].nod[2]].ny;
6157       tri[sum_tri].p1[2]=node[face[i].nod[2]].nz;
6158       tri[sum_tri].p2[0]=node[face[i].nod[5]].nx;
6159       tri[sum_tri].p2[1]=node[face[i].nod[5]].ny;
6160       tri[sum_tri].p2[2]=node[face[i].nod[5]].nz;
6161       tri[sum_tri].p3[0]=node[face[i].nod[4]].nx;
6162       tri[sum_tri].p3[1]=node[face[i].nod[4]].ny;
6163       tri[sum_tri].p3[2]=node[face[i].nod[4]].nz;
6164       sum_tri++;
6165       tri[sum_tri].p1[0]=node[face[i].nod[4]].nx;
6166       tri[sum_tri].p1[1]=node[face[i].nod[4]].ny;
6167       tri[sum_tri].p1[2]=node[face[i].nod[4]].nz;
6168       tri[sum_tri].p2[0]=node[face[i].nod[5]].nx;
6169       tri[sum_tri].p2[1]=node[face[i].nod[5]].ny;
6170       tri[sum_tri].p2[2]=node[face[i].nod[5]].nz;
6171       tri[sum_tri].p3[0]=node[face[i].nod[3]].nx;
6172       tri[sum_tri].p3[1]=node[face[i].nod[3]].ny;
6173       tri[sum_tri].p3[2]=node[face[i].nod[3]].nz;
6174       sum_tri++;
6175       tri[sum_tri].p1[0]=node[face[i].nod[3]].nx;
6176       tri[sum_tri].p1[1]=node[face[i].nod[3]].ny;
6177       tri[sum_tri].p1[2]=node[face[i].nod[3]].nz;
6178       tri[sum_tri].p2[0]=node[face[i].nod[1]].nx;
6179       tri[sum_tri].p2[1]=node[face[i].nod[1]].ny;
6180       tri[sum_tri].p2[2]=node[face[i].nod[1]].nz;
6181       tri[sum_tri].p3[0]=node[face[i].nod[4]].nx;
6182       tri[sum_tri].p3[1]=node[face[i].nod[4]].ny;
6183       tri[sum_tri].p3[2]=node[face[i].nod[4]].nz;
6184       sum_tri++;
6185     }
6186     else if (face[i].type == 9)  /* QUAD4 */
6187     {
6188       if ( (tri = (Tri *)realloc( (Tri *)tri, (sum_tri+4) * sizeof(Tri))) == NULL )
6189         errMsg("\nERROR: realloc failed in genSplitTrias() \n\n");
6190       tri[sum_tri].p1[0]=node[face[i].nod[0]].nx;
6191       tri[sum_tri].p1[1]=node[face[i].nod[0]].ny;
6192       tri[sum_tri].p1[2]=node[face[i].nod[0]].nz;
6193       tri[sum_tri].p2[0]=node[face[i].nod[1]].nx;
6194       tri[sum_tri].p2[1]=node[face[i].nod[1]].ny;
6195       tri[sum_tri].p2[2]=node[face[i].nod[1]].nz;
6196       tri[sum_tri].p3[0]=node[face[i].nod[3]].nx;
6197       tri[sum_tri].p3[1]=node[face[i].nod[3]].ny;
6198       tri[sum_tri].p3[2]=node[face[i].nod[3]].nz;
6199       tri[sum_tri].fnr= i;
6200       sum_tri++;
6201       tri[sum_tri].p1[0]=node[face[i].nod[3]].nx;
6202       tri[sum_tri].p1[1]=node[face[i].nod[3]].ny;
6203       tri[sum_tri].p1[2]=node[face[i].nod[3]].nz;
6204       tri[sum_tri].p2[0]=node[face[i].nod[1]].nx;
6205       tri[sum_tri].p2[1]=node[face[i].nod[1]].ny;
6206       tri[sum_tri].p2[2]=node[face[i].nod[1]].nz;
6207       tri[sum_tri].p3[0]=node[face[i].nod[2]].nx;
6208       tri[sum_tri].p3[1]=node[face[i].nod[2]].ny;
6209       tri[sum_tri].p3[2]=node[face[i].nod[2]].nz;
6210       tri[sum_tri].fnr= i;
6211       sum_tri++;
6212     }
6213     else if (face[i].type == 10) /* QUAD8 */
6214     {
6215       if ( (tri = (Tri *)realloc( (Tri *)tri, (sum_tri+8) * sizeof(Tri))) == NULL )
6216         errMsg("\nERROR: realloc failed in genSplitTrias() \n\n");
6217       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6218       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6219       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6220       tri[sum_tri].p2[0]=node[face[i].nod[0]].nx;
6221       tri[sum_tri].p2[1]=node[face[i].nod[0]].ny;
6222       tri[sum_tri].p2[2]=node[face[i].nod[0]].nz;
6223       tri[sum_tri].p3[0]=node[face[i].nod[4]].nx;
6224       tri[sum_tri].p3[1]=node[face[i].nod[4]].ny;
6225       tri[sum_tri].p3[2]=node[face[i].nod[4]].nz;
6226       sum_tri++;
6227       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6228       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6229       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6230       tri[sum_tri].p2[0]=node[face[i].nod[4]].nx;
6231       tri[sum_tri].p2[1]=node[face[i].nod[4]].ny;
6232       tri[sum_tri].p2[2]=node[face[i].nod[4]].nz;
6233       tri[sum_tri].p3[0]=node[face[i].nod[1]].nx;
6234       tri[sum_tri].p3[1]=node[face[i].nod[1]].ny;
6235       tri[sum_tri].p3[2]=node[face[i].nod[1]].nz;
6236       sum_tri++;
6237       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6238       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6239       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6240       tri[sum_tri].p2[0]=node[face[i].nod[1]].nx;
6241       tri[sum_tri].p2[1]=node[face[i].nod[1]].ny;
6242       tri[sum_tri].p2[2]=node[face[i].nod[1]].nz;
6243       tri[sum_tri].p3[0]=node[face[i].nod[5]].nx;
6244       tri[sum_tri].p3[1]=node[face[i].nod[5]].ny;
6245       tri[sum_tri].p3[2]=node[face[i].nod[5]].nz;
6246       sum_tri++;
6247       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6248       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6249       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6250       tri[sum_tri].p2[0]=node[face[i].nod[5]].nx;
6251       tri[sum_tri].p2[1]=node[face[i].nod[5]].ny;
6252       tri[sum_tri].p2[2]=node[face[i].nod[5]].nz;
6253       tri[sum_tri].p3[0]=node[face[i].nod[2]].nx;
6254       tri[sum_tri].p3[1]=node[face[i].nod[2]].ny;
6255       tri[sum_tri].p3[2]=node[face[i].nod[2]].nz;
6256       sum_tri++;
6257       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6258       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6259       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6260       tri[sum_tri].p2[0]=node[face[i].nod[2]].nx;
6261       tri[sum_tri].p2[1]=node[face[i].nod[2]].ny;
6262       tri[sum_tri].p2[2]=node[face[i].nod[2]].nz;
6263       tri[sum_tri].p3[0]=node[face[i].nod[6]].nx;
6264       tri[sum_tri].p3[1]=node[face[i].nod[6]].ny;
6265       tri[sum_tri].p3[2]=node[face[i].nod[6]].nz;
6266       sum_tri++;
6267       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6268       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6269       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6270       tri[sum_tri].p2[0]=node[face[i].nod[6]].nx;
6271       tri[sum_tri].p2[1]=node[face[i].nod[6]].ny;
6272       tri[sum_tri].p2[2]=node[face[i].nod[6]].nz;
6273       tri[sum_tri].p3[0]=node[face[i].nod[3]].nx;
6274       tri[sum_tri].p3[1]=node[face[i].nod[3]].ny;
6275       tri[sum_tri].p3[2]=node[face[i].nod[3]].nz;
6276       sum_tri++;
6277       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6278       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6279       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6280       tri[sum_tri].p2[0]=node[face[i].nod[3]].nx;
6281       tri[sum_tri].p2[1]=node[face[i].nod[3]].ny;
6282       tri[sum_tri].p2[2]=node[face[i].nod[3]].nz;
6283       tri[sum_tri].p3[0]=node[face[i].nod[7]].nx;
6284       tri[sum_tri].p3[1]=node[face[i].nod[7]].ny;
6285       tri[sum_tri].p3[2]=node[face[i].nod[7]].nz;
6286       sum_tri++;
6287       tri[sum_tri].p1[0]=node[face[i].nod[8]].nx;
6288       tri[sum_tri].p1[1]=node[face[i].nod[8]].ny;
6289       tri[sum_tri].p1[2]=node[face[i].nod[8]].nz;
6290       tri[sum_tri].p2[0]=node[face[i].nod[7]].nx;
6291       tri[sum_tri].p2[1]=node[face[i].nod[7]].ny;
6292       tri[sum_tri].p2[2]=node[face[i].nod[7]].nz;
6293       tri[sum_tri].p3[0]=node[face[i].nod[0]].nx;
6294       tri[sum_tri].p3[1]=node[face[i].nod[0]].ny;
6295       tri[sum_tri].p3[2]=node[face[i].nod[0]].nz;
6296       sum_tri++;
6297     }
6298   }
6299   for(j=0; j<sum_tri; j++)
6300   {
6301     if(scalFlag)
6302     {
6303       tri[j].p1[0]= tri[j].p1[0]*scale->w+scale->x; tri[j].p1[1]=tri[j].p1[1]* scale->w+scale->y; tri[j].p1[2]= tri[j].p1[2]*scale->w+scale->z;
6304       tri[j].p2[0]= tri[j].p2[0]*scale->w+scale->x; tri[j].p2[1]=tri[j].p2[1]* scale->w+scale->y; tri[j].p2[2]= tri[j].p2[2]*scale->w+scale->z;
6305       tri[j].p3[0]= tri[j].p3[0]*scale->w+scale->x; tri[j].p3[1]=tri[j].p3[1]* scale->w+scale->y; tri[j].p3[2]= tri[j].p3[2]*scale->w+scale->z;
6306     }
6307 
6308     /* "cg" of tri       */
6309     tri[j].cg[0]=(tri[j].p1[0]+tri[j].p2[0]+tri[j].p3[0])/3;
6310     tri[j].cg[1]=(tri[j].p1[1]+tri[j].p2[1]+tri[j].p3[1])/3;
6311     tri[j].cg[2]=(tri[j].p1[2]+tri[j].p2[2]+tri[j].p3[2])/3;
6312   }
6313 
6314   *ptr_tri=tri;
6315   return(sum_tri);
6316 }
6317 
6318 
6319 
pre_split(char * record)6320 void pre_split( char *record)
6321 {
6322   int  c,e,i,j=0,k,n,nn,m,p,ll,l,d1,d2,ss,s, setNr, trgtNr, mode, ibuf=0, orient=0;
6323   char setname[MAX_LINE_LENGTH], targetname[MAX_LINE_LENGTH], name[MAX_LINE_LENGTH], param[MAX_LINE_LENGTH];
6324   double pl[2][3],ps[3][3], pc[3], psplt[10][3], vproj[3], dist=0., dist2=0., distn=0., lp0p1, lps;
6325   double pt1[3], pt2[3], pt3[3], vs[3];
6326   double cg_edge[3][3];
6327 
6328   int p1_nr, p2_nr, ps_nr, l_nr[2], sum_psplt, setSplit;
6329   int *lbuffer=NULL;
6330   int sum_l=0;
6331 
6332   Rsort *rsort=NULL;
6333   Tri *tri=NULL;
6334   int sum_tri=0;
6335   float dx,dy,dz;
6336 
6337   int   ii, jj=0, ns, nm, nc=0, n1, n2, ee, ec, en1, en2, nn1, nn2, setdep, setind, nunspl[6][3];
6338   double  vn_tri[12][3], vn_av[3];
6339   int  set_efail, set_eorig=0, set_etop=0, set_ebot=0, set_ntop=0, set_nbot=0, ecounter=0;
6340 
6341   int  nodseq_te4[]={0,1,1,2,2,0, 0,3,1,3,2,3};
6342   int  nodseq_te10[]={0,4,1,1,5,2,2,6,0, 0,7,3,1,8,3,2,9,3};
6343   int  nodseq_pe6[]={0,1,1,2,2,0, 3,4,4,5,5,3, 0,3,1,4,2,5};
6344   int  nodseq_pe15[]={0,6,1,1,7,2,2,8,0, 3,12,4,4,13,5,5,14,3, 0,9,3,1,10,4,2,11,5};
6345   int  edge[20], nnew[20], ncpy[20], nel[20], nbuf[20], nref[20][2];
6346   double v12[3], v13[3], v15[3], v15n[3], vn[3];
6347   double bv15=0., bvn, bv15n, bgrenz, ltol;
6348   int  ncollapsed[27];
6349 
6350   int     n_closest_nodes;
6351   double *orig_x=NULL, *orig_y=NULL, *orig_z=NULL, *sort_x=NULL, *sort_y=NULL, *sort_z=NULL;
6352   int *sort_nx=NULL, *sort_ny=NULL, *sort_nz=NULL, near_node[N_CLOSEST_TRI];
6353 
6354   typedef struct {
6355       int sum, *n2, *nm, *nc;
6356   }N1nm;
6357   N1nm *n1ns;
6358   N1nm *n1nm;
6359 
6360   param[0]=0;
6361   ncollapsed[0]=-1;
6362   sscanf( record,"%s %s %s", setname, targetname, param );
6363 
6364   delSet(specialset->dep );
6365   delSet(specialset->ind );
6366 
6367   operateAlias( setname, "se" );
6368   setNr=getSetNr( setname );
6369   if (setNr<0)
6370   {
6371     // assume a line
6372     l=getLineNr( setname );
6373     if (l<0)
6374     {
6375       errMsg(" ERROR: %s is undefined\n", setname );
6376       return;
6377     }
6378     if( (setdep=pre_seta( specialset->dep, "l", setname )) <0 ) return;
6379   }
6380   else
6381   {
6382     /* cycle through all entities of setNr and add them to the special set  */
6383     /* cyrcle through all bodys and add  */
6384     if( (setdep=pre_seta( specialset->dep, "i", 0 )) <0 ) return;
6385     for (i=0; i<set[setNr].anz_b; i++)
6386     {
6387       seta( setdep, "b", set[setNr].body[i] );
6388     }
6389     /* cyrcle through all surfs and add  */
6390     for (i=0; i<set[setNr].anz_s; i++)
6391     {
6392       seta( setdep, "s", set[setNr].surf[i] );
6393     }
6394     /* cyrcle through all lcmbs and add  */
6395     for (i=0; i<set[setNr].anz_c; i++)
6396     {
6397       seta( setdep, "c", set[setNr].lcmb[i] );
6398     }
6399     /* cyrcle through all lines and add  */
6400     for (i=0; i<set[setNr].anz_l; i++)
6401     {
6402       seta( setdep, "l", set[setNr].line[i] );
6403     }
6404     for (i=0; i<set[setNr].anz_p; i++)
6405     {
6406       seta( setdep, "p", set[setNr].pnt[i] );
6407     }
6408     for (i=0; i<set[setNr].anz_e; i++)
6409     {
6410       seta( setdep, "e", set[setNr].elem[i] );
6411     }
6412   }
6413   /* second cycle through all entities and add lower ones  to the special set  */
6414   completeSet( specialset->dep, "do") ;
6415 
6416 
6417   /* first assume the target is a point */
6418   operateAlias( targetname, "p" );
6419   ps_nr=getPntNr( targetname );
6420   if (ps_nr>-1)
6421   {
6422     // point given, create two new lines
6423     splitLine(l, l_nr, ps_nr);
6424 
6425     /* loesche basislinie */
6426     delLine( 1, &l );
6427     return;
6428   }
6429 
6430   /* assume the target is a single shape */
6431   operateAlias( targetname, "sh" );
6432   trgtNr=getShapeNr( targetname );
6433   if (trgtNr>-1)
6434   {
6435     if( (setind=pre_seta( specialset->ind, "sh", targetname )) <0 ) return;
6436     trgtNr=-1;
6437   }
6438   else
6439   {
6440     operateAlias( targetname, "se" );
6441     trgtNr=getSetNr( targetname );
6442     if (trgtNr<0)
6443     {
6444       errMsg(" ERROR: Set (%s) is undefined\n", targetname );
6445       return;
6446     }
6447 
6448     /* cycle through all entities of targetNr and add them to the special set  */
6449     /* cyrcle through all bodies and add  */
6450     if( (setind=pre_seta( specialset->ind, "i", 0 )) <0 ) return;
6451     for (i=0; i<set[trgtNr].anz_s; i++)
6452     {
6453       seta( setind, "s", set[trgtNr].surf[i] );
6454     }
6455     for (i=0; i<set[trgtNr].anz_sh; i++)
6456     {
6457       seta( setind, "sh", set[trgtNr].shp[i] );
6458     }
6459     for (i=0; i<set[trgtNr].anz_l; i++)
6460     {
6461       seta( setind, "l", set[trgtNr].line[i] );
6462     }
6463     for (i=0; i<set[trgtNr].anz_f; i++)
6464     {
6465       seta( setind, "f", set[trgtNr].face[i] );
6466     }
6467     for (i=0; i<set[trgtNr].anz_sh; i++)
6468     {
6469       seta( setind, "sh", set[trgtNr].shp[i] );
6470     }
6471   }
6472   /* second cycle through all entities and add lower ones to the special set  */
6473   completeSet( specialset->ind, "do") ;
6474 
6475   if (set[setNr].anz_n==0) set[setdep].anz_n=set[setNr].anz_n;
6476   setNr=setdep;
6477   trgtNr=setind;
6478 
6479   /* fill all unfilled surfaces, do it in any case because points could have been moved! */
6480   /* repShape will change *scale and therefore must be executed first */
6481   repShape(trgtNr);
6482   for (i=0; i<set[setNr].anz_l; i++) repLine(set[setNr].line[i]);
6483   for (j=0; j<set[trgtNr].anz_s; j++)
6484   {
6485     //orientSet( set[trgtNr].name );
6486     //if(surf[set[trgtNr].surf[j]].sh>-1) { repNurs(surf[set[trgtNr].surf[j]].sh); untrimNurs(surf[set[trgtNr].surf[j]].sh); }
6487     repSurf(set[trgtNr].surf[j],1);
6488   }
6489   for (j=0; j<set[setNr].anz_s; j++)
6490   {
6491     repSurf(set[setNr].surf[j],1);
6492   }
6493 
6494   /* generate splitting triangles */
6495   sum_tri=genSplitTrias(trgtNr, &tri, 0);
6496 
6497   /*
6498   printf("sum_tri:%d\n",sum_tri);
6499   */
6500 
6501   ltol=LTOL;
6502 
6503   /* 0) split all elems */
6504   if(set[setdep].anz_e)
6505   {
6506     /* free the additional midside-nodes for higher order elements */
6507     for(i=anz->orign; i<anz->n; i++) node[node[i].nr].pflag=-1;
6508     anz->n= anz->orign;
6509     anz->nmax=anz->orignmax;
6510 
6511     set_efail=pre_seta("+efail","i",0);
6512     if(param[0]=='e') set_eorig=pre_seta("+eorig","i",0);
6513     else
6514     {
6515       set_etop=pre_seta("+etop","i",0);
6516       set_ebot=pre_seta("+ebot","i",0);
6517       set_ntop=pre_seta("+ntop","i",0);
6518       set_nbot=pre_seta("+nbot","i",0);
6519     }
6520 
6521     /* free the additional midside-nodes for higher order elements */
6522     for(i=anz->orign; i<anz->n; i++) node[node[i].nr].pflag=-1;
6523     anz->n= anz->orign;
6524     anz->nmax=anz->orignmax;
6525 
6526     /* create a table for all nodes which points to already created split nodes */
6527     if ( (n1ns = (N1nm *)malloc( (anz->nmax+1) * sizeof(N1nm))) == NULL )
6528     { printf("\n\n ERROR in mids: malloc\n\n") ; exit(-1); }
6529     for (i=0; i<=anz->nmax; i++) n1ns[i].sum=0;
6530     for (i=0; i<=anz->nmax; i++) n1ns[i].n2=n1ns[i].nm=n1ns[i].nc=NULL;
6531 
6532     /* create a table for all nodes which points to already created midside nodes */
6533     if ( (n1nm = (N1nm *)malloc( (anz->nmax+1) * sizeof(N1nm))) == NULL )
6534     { printf("\n\n ERROR in mids: malloc\n\n") ; exit(-1); }
6535     for (i=0; i<=anz->nmax; i++) n1nm[i].sum=0;
6536     for (i=0; i<=anz->nmax; i++) n1nm[i].n2=n1nm[i].nm=n1nm[i].nc=NULL;
6537 
6538     /* stelle daten fuer near3d bereit */
6539     if((int)N_CLOSEST_TRI<sum_tri) n_closest_nodes=(int)N_CLOSEST_TRI; else n_closest_nodes=sum_tri;
6540     if ( (rsort = (Rsort *)realloc((Rsort *)rsort, (sum_tri+1) * sizeof(Rsort))) == NULL )
6541       printf("ERROR: realloc failed: Rsort\n\n" );
6542     if ( (orig_x = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
6543       printf("ERROR: realloc failed \n\n" );
6544     if ( (orig_y = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
6545       printf("ERROR: realloc failed \n\n" );
6546     if ( (orig_z = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
6547       printf("ERROR: realloc failed \n\n" );
6548     if ( (sort_x = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
6549       printf("ERROR: realloc failed \n\n" );
6550     if ( (sort_y = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
6551       printf("ERROR: realloc failed \n\n" );
6552     if ( (sort_z = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
6553       printf("ERROR: realloc failed \n\n" );
6554     if ( (sort_nx = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
6555       printf("ERROR: realloc failed \n\n" );
6556     if ( (sort_ny = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
6557       printf("ERROR: realloc failed \n\n" );
6558     if ( (sort_nz = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
6559       printf("ERROR: realloc failed \n\n" );
6560 
6561     for(i=0; i<sum_tri; i++)
6562     {
6563       rsort[i].r=orig_x[i]=tri[i].cg[0];
6564       rsort[i].i=i;
6565     }
6566     qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
6567     for(i=0; i<sum_tri; i++)
6568     {
6569       sort_x[i]=rsort[i].r;
6570       sort_nx[i]=rsort[i].i;
6571     }
6572     for(i=0; i<sum_tri; i++)
6573     {
6574       rsort[i].r=orig_y[i]=tri[i].cg[1];
6575       rsort[i].i=i;
6576     }
6577     qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
6578     for(i=0; i<sum_tri; i++)
6579     {
6580       sort_y[i]=rsort[i].r;
6581       sort_ny[i]=rsort[i].i;
6582     }
6583     for(i=0; i<sum_tri; i++)
6584     {
6585       rsort[i].r=orig_z[i]=tri[i].cg[2];
6586       rsort[i].i=i;
6587     }
6588     qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
6589     for(i=0; i<sum_tri; i++)
6590     {
6591       sort_z[i]=rsort[i].r;
6592       sort_nz[i]=rsort[i].i;
6593     }
6594 
6595     /* go over all elements and calculate the split-point */
6596     for (ll=0; ll<set[setdep].anz_e; ll++)
6597     {
6598       e=set[setdep].elem[ll];
6599       //debug_pre_split printf("check elem[%d]:%d type:%d\n", ll, e, e_enqire[e].type);
6600       if(ecounter>set[setdep].anz_e/10)
6601       {
6602         printf("%d from %d elems processed\n", ll+1, set[setdep].anz_e);
6603         ecounter=0;
6604       }
6605       else ecounter++;
6606 
6607       if((e_enqire[e].type==3)||(e_enqire[e].type==6))
6608       {
6609         c=j=l=m=k=0;
6610         /* split the 6 edges and remember the new node per edge-nodes */
6611         for(i=0; i<6; i++)
6612         {
6613           en1=nodseq_te4[j++];
6614           en2=nodseq_te4[j++];
6615           n1=e_enqire[e].nod[en1];
6616           n2=e_enqire[e].nod[en2];
6617           pl[0][0]=node[n1].nx;
6618           pl[0][1]=node[n1].ny;
6619           pl[0][2]=node[n1].nz;
6620           pl[1][0]=node[n2].nx;
6621           pl[1][1]=node[n2].ny;
6622           pl[1][2]=node[n2].nz;
6623 
6624           /* The embedded triangles of the surfaces are used as a target */
6625           /* determine the position where the vector vproj between two line-dots meets the triangles */
6626           /* and determine if the position is inside the triangle */
6627           vproj[0]=pl[1][0]-pl[0][0];
6628           vproj[1]=pl[1][1]-pl[0][1];
6629           vproj[2]=pl[1][2]-pl[0][2];
6630           lp0p1=v_betrag( vproj );
6631           /*
6632           printf("n1: %lf %lf %lf\n",pl[0][0],pl[0][1],pl[0][2]);
6633           printf("n2: %lf %lf %lf\n",pl[1][0],pl[1][1],pl[1][2]);
6634           printf("v: %lf %lf %lf\n",vproj[0],vproj[1],vproj[2]);
6635           printf("pt1: %lf %lf %lf\n",pt1[0],pt1[1],pt1[2] );
6636           printf("pt2: %lf %lf %lf\n",pt2[0],pt2[1],pt2[2] );
6637           printf("pt3: %lf %lf %lf\n",pt3[0],pt3[1],pt3[2] );
6638           */
6639 
6640           /* determine the center of the edge */
6641           vn_av[0]=(pl[1][0]+pl[0][0])*.5;
6642 	  vn_av[1]=(pl[1][1]+pl[0][1])*.5;
6643 	  vn_av[2]=(pl[1][2]+pl[0][2])*.5;
6644           near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, pl[0][0],pl[0][1],pl[0][2],
6645               sum_tri, &near_node[0], n_closest_nodes/3);
6646           near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, vn_av[0],vn_av[1],vn_av[2],
6647               sum_tri, &near_node[n_closest_nodes/3], n_closest_nodes/3);
6648           near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, pl[1][0],pl[1][1],pl[1][2],
6649               sum_tri, &near_node[n_closest_nodes/3*2], n_closest_nodes-n_closest_nodes/3*2);
6650 
6651           /* go over the closest splitting-tri */
6652           for( nn=0; nn<n_closest_nodes; nn++)
6653           {
6654             n=near_node[nn];
6655 	    /*
6656 	    printf("pnt %d %f %f %f\n",n1, pl[0][0], pl[0][1], pl[0][2] );
6657 	    printf("pnt ! %f %f %f\n", vn_av[0], vn_av[1], vn_av[2] );
6658 	    printf("pnt %d %f %f %f\n",n2, pl[1][0], pl[1][1], pl[1][2] );
6659 	    printf("line ! %d %d\n", n1,n2);
6660 	    printf("pnt p%d %f %f %f\n", nn+1, tri[n].cg[0], tri[n].cg[1] , tri[n].cg[2]);
6661 	    if(nn==n_closest_nodes-1) exit(0);
6662 */
6663 
6664             dist=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pl[0], vproj, 1.01, &orient);
6665             dist2=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pl[1], vproj, 1.01, &orient);
6666 
6667             /* check if nodes are positioned in (or close to) the splitting plane, these are special cases */
6668               //debug_pre_split printf(" n1:%d dist:%lf ori:%d \n", n1, dist, orient);
6669     	      //debug_pre_split printf(" n2:%d dist:%lf ori:%d \n", n2, dist2, orient);
6670 
6671             if ((abs(dist)<=ltol)||(abs(dist2)<=ltol))
6672 	    {
6673               if(param[0]=='e') { seta(set_eorig, "e", e); goto next_elem; }
6674               /* was this collapsed node evaluated? */
6675        	      /* which side is closer to n1 n2? */
6676               if (abs(dist)<ltol) ns= n1;
6677               else ns= n2;
6678 	      for(ii=0; ii<c; ii++) if(ncollapsed[ii]== ns) break;
6679               if(ii< c) continue;
6680 
6681               ncollapsed[c]=ns;
6682 
6683               //debug_pre_split printf(" node in splitting plane:%d sum_collapsed:%d\n",ncollapsed[c], c+1);
6684 
6685               /* remember the normal vector of the splitting triangle */
6686               v_result( tri[n].p1,tri[n].p2, v12);
6687               v_result( tri[n].p1,tri[n].p3, v13);
6688               v_prod(v12,v13,vn);
6689               v_norm(vn,&vn_tri[m][0]);
6690 
6691               /* The split-point is just a copy of one end-point of that line */
6692 
6693               /* check if the ns exists already */
6694               ns=-1;
6695               for(ii=0; ii<n1ns[n1].sum; ii++) if(n1ns[n1].n2[ii]==n1) { ns=n1ns[n1].nm[ii]; nc=n1ns[n1].nc[ii]; }
6696               for(ii=0; ii<n1ns[n2].sum; ii++) if(n1ns[n2].n2[ii]==n2) { ns=n1ns[n2].nm[ii]; nc=n1ns[n2].nc[ii]; }
6697 
6698               if(ns==-1)
6699               {
6700                 /* move n1 or n2 to the splitting plane */
6701                 /* determine normal direction to plane (before the loop starts, common for all elems (TBD)) */
6702                 distn=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pl[0], vn, 10.0, &orient);
6703                 if (abs(distn)<ltol)
6704 		{
6705                   node[n1].nx=pl[0][0]+vn_tri[m][0]*distn;
6706                   node[n1].ny=pl[0][1]+vn_tri[m][1]*distn;
6707                   node[n1].nz=pl[0][2]+vn_tri[m][2]*distn;
6708 		}
6709                 distn=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pl[1], vn, 10.0, &orient);
6710                 if (abs(distn)<ltol)
6711 	        {
6712                   node[n2].nx=pl[1][0]+vn_tri[m][0]*distn;
6713                   node[n2].ny=pl[1][1]+vn_tri[m][1]*distn;
6714                   node[n2].nz=pl[1][2]+vn_tri[m][2]*distn;
6715       	        }
6716 
6717 		/* which side is closer to n1 n2? */
6718                 if (abs(dist)<ltol) ns= n1;
6719                 else ns= n2;
6720 
6721                 /* copy */
6722                 nc=nod( anz, &node, 1, anz->nnext++, node[ns].nx, node[ns].ny, node[ns].nz, 0);
6723 
6724 		//debug_pre_split printf(" nc:%d distn:%lf ori:%d n:%f %f %f\n", node[nc].nr, distn, orient, vn[0], vn[1], vn[2]);
6725                 if(e_enqire[e].type==6)
6726 	        {
6727                   if ( (n1nm = (N1nm *)realloc(n1nm, (anz->nmax+1) * sizeof(N1nm))) == NULL )
6728                   { printf("\n\n ERROR in mids: malloc\n\n") ; exit(-1); }
6729                   for (ii=anz->nmax-2; ii<=anz->nmax; ii++) n1nm[ii].sum=0;
6730                   for (ii=anz->nmax-2; ii<=anz->nmax; ii++) n1nm[ii].n2=n1nm[ii].nm=n1nm[ii].nc=NULL;
6731 		}
6732                 if ( (n1ns[ns].n2 = (int *)realloc( n1ns[ns].n2, (n1ns[ns].sum+1) * sizeof(int))) == NULL )
6733                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6734                 if ( (n1ns[ns].nm = (int *)realloc( n1ns[ns].nm, (n1ns[ns].sum+1) * sizeof(int))) == NULL )
6735                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6736                 if ( (n1ns[ns].nc = (int *)realloc( n1ns[ns].nc, (n1ns[ns].sum+1) * sizeof(int))) == NULL )
6737                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6738                 //if(ns==n1) n1ns[ns].n2[n1ns[ns].sum]=n2; else n1ns[ns].n2[n1ns[ns].sum]=n1;
6739                 n1ns[ns].n2[n1ns[ns].sum]=ns;
6740                 n1ns[ns].nm[n1ns[ns].sum]=node[ns].indx;
6741                 n1ns[ns].nc[n1ns[ns].sum]=nc;
6742                 n1ns[ns].sum++;
6743                 nnew[m]=node[ns].indx;
6744 	      }
6745               else nnew[m]=ns;
6746               ncpy[m]=nc;
6747 
6748               /* assign the corner-nodes */
6749               nref[m][0]=edge[k++]=n1;
6750               nref[m][1]=edge[k++]=n2;
6751 
6752               //debug_pre_split printf("m:%d c:%d n1:%d n2:%d node:%d copy:%d at  %lf %lf %lf\n", m+1, c+1, n1,n2, node[nnew[m]].nr, node[ncpy[m]].nr,  node[ns].nx, node[ns].ny, node[ns].nz );
6753               m++;
6754               c++;
6755 	      goto nextEdge;
6756 	    }
6757 
6758             /* create a node only if the vector goes through the tri and if the sign of dist has changed (scip the first line-vector (p==3))*/
6759             else if (( dist != OUTSIDE ) && ( dist2 != OUTSIDE ) && (dist2*dist < 0.))
6760             {
6761               if(param[0]=='e') { seta(set_eorig, "e", e); goto next_elem; }
6762 
6763               /* remember the normal vector of the splitting triangle (to be replaced by "orient") */
6764               v_result( tri[n].p1,tri[n].p2, v12);
6765               v_result( tri[n].p1,tri[n].p3, v13);
6766               v_prod(v12,v13,vn);
6767               v_norm(vn,&vn_tri[m][0]);
6768 
6769               /* check if the ns exists already */
6770               ns=-1;
6771               for(ii=0; ii<n1ns[n1].sum; ii++) if(n1ns[n1].n2[ii]==n2) { ns=n1ns[n1].nm[ii]; nc=n1ns[n1].nc[ii]; }
6772               for(ii=0; ii<n1ns[n2].sum; ii++) if(n1ns[n2].n2[ii]==n1) { ns=n1ns[n2].nm[ii]; nc=n1ns[n2].nc[ii]; }
6773 
6774               /* create a split-point and a copy if not existent */
6775               if(ns==-1)
6776 	      {
6777                 v_norm( vproj, pc );
6778                 vs[0]=pc[0]*(dist);
6779                 vs[1]=pc[1]*(dist);
6780                 vs[2]=pc[2]*(dist);
6781                 psplt[0][0]=pl[0][0]+vs[0];
6782                 psplt[0][1]=pl[0][1]+vs[1];
6783                 psplt[0][2]=pl[0][2]+vs[2];
6784 
6785     	        ns=nod( anz, &node, 1, anz->nnext++,  psplt[0][0], psplt[0][1], psplt[0][2], 0);
6786     	        nc=nod( anz, &node, 1, anz->nnext++,  psplt[0][0], psplt[0][1], psplt[0][2], 0);
6787 
6788                 if(e_enqire[e].type==6)
6789 	        {
6790                   if ( (n1nm = (N1nm *)realloc(n1nm, (anz->nmax+1) * sizeof(N1nm))) == NULL )
6791                   { printf("\n\n ERROR in mids: malloc\n\n") ; exit(-1); }
6792                   for (ii=anz->nmax-2; ii<=anz->nmax; ii++) n1nm[ii].sum=0;
6793                   for (ii=anz->nmax-2; ii<=anz->nmax; ii++) n1nm[ii].n2=n1nm[ii].nm=n1nm[ii].nc=NULL;
6794 		}
6795                 if ( (n1ns[n1].n2 = (int *)realloc( n1ns[n1].n2, (n1ns[n1].sum+1) * sizeof(int))) == NULL )
6796                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6797                 if ( (n1ns[n1].nm = (int *)realloc( n1ns[n1].nm, (n1ns[n1].sum+1) * sizeof(int))) == NULL )
6798                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6799                 if ( (n1ns[n1].nc = (int *)realloc( n1ns[n1].nc, (n1ns[n1].sum+1) * sizeof(int))) == NULL )
6800                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6801                 n1ns[n1].n2[n1ns[n1].sum]=n2;
6802                 n1ns[n1].nm[n1ns[n1].sum]=ns;
6803                 n1ns[n1].nc[n1ns[n1].sum]=nc;
6804                 n1ns[n1].sum++;
6805 	      }
6806               nnew[m]=ns;
6807               ncpy[m]=nc;
6808 
6809               /* assign the corner-nodes */
6810               nref[m][0]=edge[k++]=n1;
6811               nref[m][1]=edge[k++]=n2;
6812 
6813               //debug_pre_split printf("m:%d n1:%d n2:%d split node:%d copy:%d   %lf %lf %lf\n", m+1, n1,n2, node[nnew[m]].nr,  node[ncpy[m]].nr, psplt[0][0], psplt[0][1], psplt[0][2] );
6814               m++;
6815 	      goto nextEdge;
6816             }
6817           }
6818 
6819           { nunspl[l][0]=n1; nunspl[l++][1]=n2; }
6820           //debug_pre_split printf("l:%d unsplit nodes:%d %d\n",l, n1,n2 );
6821  nextEdge:;
6822         }
6823 
6824         if((e_enqire[e].type==6)&&(m>=2))
6825         {
6826           /* remember the corner-nodes of the midside nodes of the original element */
6827           j=0;
6828           for(i=0; i<6; i++)
6829           {
6830             n1=e_enqire[e].nod[nodseq_te10[j++]];
6831             nm=node[e_enqire[e].nod[nodseq_te10[j++]]].indx;
6832             n2=e_enqire[e].nod[nodseq_te10[j++]];
6833 	    //debug_pre_split printf("j:%d n1:%d n2:%d nm:%d\n", j, n1,n2, nm);
6834 
6835             if ( (n1nm[n1].n2 = (int *)realloc( n1nm[n1].n2, (n1nm[n1].sum+1) * sizeof(int))) == NULL )
6836             { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6837             if ( (n1nm[n1].nm = (int *)realloc( n1nm[n1].nm, (n1nm[n1].sum+1) * sizeof(int))) == NULL )
6838             { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6839             if ( (n1nm[n1].nc = (int *)realloc( n1nm[n1].nc, (n1nm[n1].sum+1) * sizeof(int))) == NULL )
6840             { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6841             n1nm[n1].n2[n1nm[n1].sum]=n2;
6842             n1nm[n1].nm[n1nm[n1].sum]=nm;
6843             n1nm[n1].nc[n1nm[n1].sum]=-1;
6844             n1nm[n1].sum++;
6845 	  }
6846         }
6847 
6848         /* *******  create new elems ********** */
6849 
6850         if((m==3)&&(c==2)) /* (cut along edge through tet => 2new tets) */
6851 	{
6852           //debug_pre_split printf("e:%d cut along edge through tet => 2new tets\n",e);
6853 
6854           /* calc average normal of the splitting triangles */
6855           for (j=0; j<3; j++) vn_av[j]=0.;
6856           for (i=0; i<m; i++)
6857 	  {
6858             for (j=0; j<3; j++) vn_av[j]+=vn_tri[i][j];
6859 	  }
6860 
6861           /* copy element, modify later */
6862           if(e_enqire[e].type==3)
6863 	  {
6864             elem_define(anz,&e_enqire, anz->enext++, 3, e_enqire[e].nod, 1, 0 );
6865 	  }
6866           else
6867 	  {
6868             elem_define(anz,&e_enqire, anz->enext++, 6, e_enqire[e].nod, 1, 0 );
6869 	  }
6870 
6871           /* search the tetra-top-nodes */
6872           for(i=0; i<4; i++)
6873 	  {
6874             nbuf[i]=e_enqire[e].nod[i];
6875             for(j=0; j<m; j++) if(e_enqire[e].nod[i]==node[nnew[j]].nr) nbuf[i]=-1;
6876             //debug_pre_split for(j=0; j<m; j++) printf("en:%d nnew %d nbuf %d\n", e_enqire[e].nod[i], node[nnew[j]].nr, nbuf[i]);
6877 	  }
6878           j=0;
6879           for(i=0; i<4; i++)
6880 	  {
6881             if(nbuf[i]!=-1) nbuf[j++]=nbuf[i];
6882 	  }
6883           //debug_pre_split printf("j:%d top-nodes: %d %d\n", j, nbuf[0], nbuf[1]);
6884           if(j>2)
6885           {
6886             printf("found 3. top-node:%d\n", nbuf[1]);
6887             for(i=0; i<4; i++) printf("en:%d %d\n", e_enqire[e].nod[i], nbuf[i]);
6888             exit(0);
6889           }
6890 
6891           /* prepare the elements */
6892           /* 1st element gets copied nodes ncpy, oriented in the same way as the plane */
6893           for(i=0; i<3; i++)
6894 	  {
6895             seta(set_ntop, "n",node[ncpy[i]].nr);
6896             seta(set_nbot, "n",node[nnew[i]].nr);
6897 	  }
6898           seta(set_etop, "e", e);
6899           seta(set_ebot, "e", anz->emax);
6900 
6901           /* check the orientation of nnew */
6902           v_result( &node[node[nnew[0]].nr].nx, &node[node[nnew[1]].nr].nx, v12);
6903           v_result( &node[node[nnew[0]].nr].nx, &node[node[nnew[2]].nr].nx, v13);
6904           v_result( &node[node[nnew[0]].nr].nx, &node[edge[i]].nx, v15);
6905           v_prod(v12,v13,vn);
6906           v_norm(vn,vn);
6907           if (v_sprod(vn_av,vn) > 0.)
6908 	  {
6909             ss=1;
6910             j=3;
6911             for(i=0; i<3; i++)
6912 	    {
6913               e_enqire[e].nod[i]=node[ncpy[i]].nr;
6914               e_enqire[anz->emax].nod[i]=node[nnew[--j]].nr;
6915 	    }
6916 	  }
6917 	  else
6918 	  {
6919             ss=0;
6920             j=3;
6921             for(i=0; i<3; i++)
6922 	    {
6923               e_enqire[e].nod[i]=node[ncpy[--j]].nr;
6924               e_enqire[anz->emax].nod[i]=node[nnew[i]].nr;
6925 	    }
6926 	  }
6927 
6928           /* 1st element has copied nodes and nbuf on the positive side of the plane */
6929           v_result( &node[node[nnew[0]].nr].nx,&node[nbuf[0]].nx, v12);
6930           if (v_sprod(vn_av,v12) > 0.)
6931           {
6932               e_enqire[e].nod[3]=nbuf[0];
6933               e_enqire[anz->emax].nod[3]=nbuf[1];
6934 	  }
6935           else
6936           {
6937               e_enqire[e].nod[3]=nbuf[1];
6938               e_enqire[anz->emax].nod[3]=nbuf[0];
6939 	  }
6940 
6941           /* change the midnodes */
6942           if(e_enqire[e].type==6)
6943           {
6944             /* first for the copied elem anz->emax (this has the orig-nodes)  and only the basis (nnew,ncpy) */
6945 
6946             /* gen mitside-nodes */
6947             for (n=0; n<3; n++)
6948             {
6949               nn1= e_enqire[anz->emax].nod[nodseq_te4[n*2]];
6950               nn2= e_enqire[anz->emax].nod[nodseq_te4[n*2+1]];
6951               //debug_pre_split printf("e:%d n12:%d %d \n", e, nn1,nn2 );
6952 
6953               /* check if the nm and nc exist already */
6954               nm=nc=-1;
6955               for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) { nm=n1nm[nn1].nm[i]; nc=n1nm[nn1].nc[i]; }
6956               for(i=0; i<n1nm[nn2].sum; i++) if(n1nm[nn2].n2[i]==nn1) { nm=n1nm[nn2].nm[i]; nc=n1nm[nn2].nc[i]; }
6957 
6958               if(nc==-1)
6959               {
6960                 if(nm==-1)
6961                 {
6962                   /* generate new node */
6963                   nm=nod( anz, &node, 1, anz->nnext++, 0., 0., 0., 0 );
6964                   node[node[nm].nr].nx=(node[nn1].nx+node[nn2].nx)*.5;
6965                   node[node[nm].nr].ny=(node[nn1].ny+node[nn2].ny)*.5;
6966                   node[node[nm].nr].nz=(node[nn1].nz+node[nn2].nz)*.5;
6967                   if ( (n1nm[nn1].n2 = (int *)realloc( n1nm[nn1].n2, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
6968                   { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6969                   if ( (n1nm[nn1].nm = (int *)realloc( n1nm[nn1].nm, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
6970                   { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6971                   n1nm[nn1].n2[n1nm[nn1].sum]=nn2;
6972                   n1nm[nn1].nm[n1nm[nn1].sum]=nm;
6973                   n1nm[nn1].sum++;
6974                 }
6975                 /* generate new copy node */
6976                 nc=nod( anz, &node, 1, anz->nnext++, node[node[nm].nr].nx,node[node[nm].nr].ny,node[node[nm].nr].nz, 0 );
6977                 if ( (n1nm[nn1].nc = (int *)realloc( n1nm[nn1].nc, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
6978                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
6979                 n1nm[nn1].nc[n1nm[nn1].sum]=nc;
6980               }
6981               e_enqire[anz->emax].nod[nodseq_te10[n*3+1]]=node[nm].nr;
6982               seta(set_nbot, "n",node[nm].nr);
6983               //debug_pre_split printf("e:%d p:%d n12:%d %d nm:%d\n", anz->emax, nodseq_te10[n*3+1], nn1,nn2, node[nm].nr );
6984               switch(n)
6985 		{ case 0: jj=5; break;  case 1: jj=4; break; case 2: jj=6; break; default: printf("ERROR: n:%d not possible\n",n); exit(0); }
6986               e_enqire[e].nod[jj]=node[nc].nr;
6987               seta(set_ntop, "n",node[nc].nr);
6988               //debug_pre_split printf("e:%d p:%d n12:%d %d nc:%d\n", e, jj, nn1,nn2, node[nc].nr );
6989             }
6990 
6991             /* edges running from base to top */
6992             ec=e;
6993             for (ee=0; ee<2; ee++)
6994 	    {
6995 	     if(ee==1) ec=anz->emax;
6996              for (n=0; n<3; n++)
6997              {
6998             /* collapsed nodes require a first check with the original nodes */
6999               nn1= node[nnew[n]].nr;
7000               nn2= e_enqire[ec].nod[nodseq_te4[(n+3)*2+1]];
7001               if(ee==0)
7002             {
7003                 if((nn1!=ncollapsed[0])&&(nn1!=ncollapsed[1])) nn1= node[ncpy[n]].nr;
7004             }
7005 
7006               /* check if the nm exist already (nc never used here because its not splittet running to TOP) */
7007               nm=-1;
7008               for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) nm=n1nm[nn1].nm[i];
7009               for(i=0; i<n1nm[nn2].sum; i++) if(n1nm[nn2].n2[i]==nn1) nm=n1nm[nn2].nm[i];
7010 
7011               if(nm==-1)
7012               {
7013                 /* generate new node */
7014                 nm=nod( anz, &node, 1, anz->nnext++, 0., 0., 0., 0 );
7015                 node[node[nm].nr].nx=(node[nn1].nx+node[nn2].nx)*.5;
7016                 node[node[nm].nr].ny=(node[nn1].ny+node[nn2].ny)*.5;
7017                 node[node[nm].nr].nz=(node[nn1].nz+node[nn2].nz)*.5;
7018                 if ( (n1nm[nn1].n2 = (int *)realloc( n1nm[nn1].n2, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7019                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7020                 if ( (n1nm[nn1].nm = (int *)realloc( n1nm[nn1].nm, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7021                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7022                 if ( (n1nm[nn1].nc = (int *)realloc( n1nm[nn1].nc, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7023                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7024                 n1nm[nn1].n2[n1nm[nn1].sum]=nn2;
7025                 n1nm[nn1].nm[n1nm[nn1].sum]=nm;
7026                 n1nm[nn1].nc[n1nm[nn1].sum]=-1;
7027                 n1nm[nn1].sum++;
7028               }
7029               if(ee==ss) e_enqire[ec].nod[9-n]=node[nm].nr;
7030               else e_enqire[ec].nod[n+7]=node[nm].nr;
7031               //debug_pre_split printf("e:%d p:%d n12:%d %d nm:%d\n", ec, n+7, nn1,nn2, node[nm].nr );
7032              }
7033 	    }
7034 	  }
7035 	}
7036         else if((m==1)&&(c==1)) /* 1 node copied (cut at top) */
7037 	{
7038           //debug_pre_split printf("e:%d cut at top\n",e);
7039 
7040           /* calc average normal of the splitting triangles */
7041           for (j=0; j<3; j++) vn_av[j]=0.;
7042           for (i=0; i<m; i++)
7043 	  {
7044             for (j=0; j<3; j++) vn_av[j]+=vn_tri[i][j];
7045 	  }
7046 
7047           /* sort the elements according to their orientation regarding the splitting triangle */
7048           /* the element on the fronside of the plane gets the copied nodes */
7049           if(node[nnew[0]].nr==nref[0][0]) n=nref[0][1]; else n=nref[0][0];
7050           v_result( &node[node[nnew[0]].nr].nx,&node[n].nx, v12);
7051           if (v_sprod(vn_av,v12) > 0.)
7052           {
7053             /* redefine the tet */
7054             for(i=0; i<4; i++)
7055               for(ii=0; ii<m; ii++)
7056                 if(e_enqire[e].nod[i]==node[nnew[ii]].nr)
7057 		{
7058                   //debug_pre_split printf("e:%d n:%d to %d\n", e, e_enqire[e].nod[i],node[ncpy[ii]].nr );
7059 	          e_enqire[e].nod[i]=node[ncpy[ii]].nr;
7060                 }
7061             seta(set_ntop, "n",node[ncpy[0]].nr);
7062             seta(set_etop, "e", e);
7063           }
7064           else
7065           {
7066             seta(set_nbot, "n",node[nnew[0]].nr);
7067             seta(set_ebot, "e", e);
7068           }
7069 	}
7070         else if((m==3)&&(c==3)) /* 3 nodes copied (cut at basis) */
7071 	{
7072           //debug_pre_split printf("e:%d cut at basis\n",e);
7073 
7074           /* calc average normal of the splitting triangles */
7075           for (j=0; j<3; j++) vn_av[j]=0.;
7076           for (i=0; i<m; i++)
7077 	  {
7078             for (j=0; j<3; j++) vn_av[j]+=vn_tri[i][j];
7079 	  }
7080 
7081           /* sort the elements according to their orientation regarding the splitting triangle */
7082           /* the element on the fronside of the plane gets the copied nodes */
7083           if(node[nnew[0]].nr==nref[0][0]) n=nref[0][1]; else n=nref[0][0];
7084           //printf("topn:%d bottomn;%d\n", n, node[nnew[0]].nr);
7085           v_result( &node[node[nnew[0]].nr].nx,&node[n].nx, v12);
7086           if (v_sprod(vn_av,v12) > 0.)
7087           {
7088             /* redefine the tet */
7089             for(i=0; i<4; i++)
7090               for(ii=0; ii<m; ii++)
7091                 if(e_enqire[e].nod[i]==node[nnew[ii]].nr)
7092 		{
7093                   //debug_pre_split printf("e:%d n:%d to %d\n", e, e_enqire[e].nod[i],node[ncpy[ii]].nr );
7094 	          e_enqire[e].nod[i]=node[ncpy[ii]].nr;
7095                 }
7096 
7097             /* copy also the midside nodes. */
7098 	    if(e_enqire[e].type==6)
7099             {
7100               /* copy the midside nodes */
7101               jj=0;
7102               for(ii=0; ii<m; ii++)
7103   	      {
7104                 nn1=node[nnew[jj++]].nr;
7105                 if(jj==m) jj=0;
7106                 nn2=node[nnew[jj++]].nr;
7107                 if(jj==m) jj=0;
7108 		//debug_pre_split printf("nn1:%d nn2:%d\n", nn1,nn2);
7109 
7110                 /* check if the nc exists already */
7111                 nc=nm=s=-1;
7112                 for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) { nm=n1nm[nn1].nm[i]; nc=n1nm[nn1].nc[i]; n=nn1; s=i; break; }
7113   	        if(s<0) { for(i=0; i<n1nm[nn2].sum; i++) { if(n1nm[nn2].n2[i]==nn1) { nm=n1nm[nn2].nm[i]; nc=n1nm[nn2].nc[i];  n=nn2; s=i; break; } } }
7114 		//debug_pre_split printf("nc:%d nm:%d\n", nc, nm);
7115 
7116                 if(nm==-1)
7117                 { printf("\n\n ERROR in midnode not found\n\n") ; exit(-1); }
7118                 if(nc==-1)
7119                 {
7120                   /* generate new mid-node */
7121                   nc=nod( anz, &node, 1, anz->nnext++, node[node[nm].nr].nx, node[node[nm].nr].ny, node[node[nm].nr].nz, 0 );
7122                   n1nm[n].nc[s]=nc;
7123                 }
7124 
7125 		//debug_pre_split printf("nc:%d nod:%d\n", nc,node[nc].nr);
7126                 /* redefine the tet */
7127                 for(i=4; i<10; i++) if(e_enqire[e].nod[i]==node[nm].nr)
7128                 {
7129                   //debug_pre_split printf("e:%d n:%d to %d\n", e, e_enqire[e].nod[i], node[nc].nr );
7130                   e_enqire[e].nod[i]=node[nc].nr;
7131                   break;
7132                 }
7133                 seta(set_ntop, "n",node[nm].nr);
7134               }
7135 	    }
7136             for(ii=0; ii<3; ii++) seta(set_ntop, "n",node[ncpy[ii]].nr);
7137             seta(set_etop, "e",e);
7138           }
7139 	  else
7140 	  {
7141 	    if(e_enqire[e].type==6)
7142             {
7143               /* copy the midside nodes */
7144               jj=0;
7145               for(ii=0; ii<m; ii++)
7146   	      {
7147                 nn1=node[nnew[jj++]].nr;
7148                 if(jj==m) jj=0;
7149                 nn2=node[nnew[jj++]].nr;
7150                 if(jj==m) jj=0;
7151 		//debug_pre_split printf("nn1:%d nn2:%d\n", nn1,nn2);
7152 
7153                 nm=s=-1;
7154                 for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) { nm=n1nm[nn1].nm[i]; s=i; break; }
7155     	        if(s<0) { for(i=0; i<n1nm[nn2].sum; i++) { if(n1nm[nn2].n2[i]==nn1) { nm=n1nm[nn2].nm[i]; break; } } }
7156   	        //debug_pre_split printf("nm:%d\n", nm);
7157                 seta(set_nbot, "n",node[nm].nr);
7158               }
7159 	    }
7160             for(ii=0; ii<3; ii++) seta(set_nbot, "n",node[nnew[ii]].nr);
7161             seta(set_ebot, "e", e);
7162           }
7163 
7164 	}
7165         else if((m==2)&&(c==2)) /* 2 node copied (cut along an edge) */
7166 	{
7167           //debug_pre_split printf("e:%d cut along an edge\n",e);
7168 
7169           /* calc average normal of the splitting triangles */
7170           for (j=0; j<3; j++) vn_av[j]=0.;
7171           for (i=0; i<m; i++)
7172 	  {
7173             for (j=0; j<3; j++) vn_av[j]+=vn_tri[i][j];
7174 	  }
7175 
7176           /* sort the elements according to their orientation regarding the splitting triangle */
7177           /* the element on the fronside of the plane gets the copied nodes */
7178           n=-1;
7179           for(i=0; i<4; i++) if((node[nnew[0]].nr!=e_enqire[e].nod[i])&&(node[nnew[1]].nr!=e_enqire[e].nod[i])) { n=e_enqire[e].nod[i]; break; }
7180           if(n==-1)
7181 	  { printf("ERROR\n"); exit(0); }
7182           //debug_pre_split printf("topn:%d bottomn;%d\n", n, node[nnew[0]].nr);
7183 
7184 
7185           v_result( &node[node[nnew[0]].nr].nx,&node[n].nx, v12);
7186           if (v_sprod(vn_av,v12) > 0.)
7187           {
7188             /* redefine the tet */
7189             for(jj=0; jj<4; jj++)
7190               for(ii=0; ii<m; ii++)
7191                 if(e_enqire[e].nod[jj]==node[nnew[ii]].nr)
7192 	        {
7193                   //debug_pre_split printf("e:%d n:%d to %d\n", e, e_enqire[e].nod[jj], node[ncpy[ii]].nr );
7194                   e_enqire[e].nod[jj]=node[ncpy[ii]].nr;
7195 		}
7196 
7197             /* copy also the midside nodes. */
7198 	    if(e_enqire[e].type==6)
7199             {
7200               /* copy the midside nodes */
7201               jj=0;
7202               for(ii=0; ii<m; ii++)
7203   	      {
7204                 nn1=node[nnew[jj++]].nr;
7205                 if(jj==m) jj=0;
7206                 nn2=node[nnew[jj++]].nr;
7207                 if(jj==m) jj=0;
7208 		//debug_pre_split printf("nn1:%d nn2:%d\n", nn1,nn2);
7209 
7210                 /* check if the nc exists already */
7211                 nc=nm=s=-1;
7212 		//debug_pre_split printf("nn1sum:%d nn2sum:%d\n", n1nm[nn1].sum,n1nm[nn2].sum);
7213                 for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) { nm=n1nm[nn1].nm[i]; nc=n1nm[nn1].nc[i]; n=nn1; s=i; break; }
7214   	        if(s<0) { for(i=0; i<n1nm[nn2].sum; i++) { if(n1nm[nn2].n2[i]==nn1) { nm=n1nm[nn2].nm[i]; nc=n1nm[nn2].nc[i];  n=nn2; s=i; break; } } }
7215 		//debug_pre_split printf("nc:%d nm:%d\n", nc, nm);
7216 
7217                 if(nm==-1)
7218                 { printf("\n\n ERROR in midnode not found\n\n") ; exit(-1); }
7219                 if(nc==-1)
7220                 {
7221                   /* generate new mid-node */
7222                   nc=nod( anz, &node, 1, anz->nnext++, node[node[nm].nr].nx, node[node[nm].nr].ny, node[node[nm].nr].nz, 0 );
7223                   n1nm[n].nc[s]=nc;
7224                 }
7225 
7226 		//debug_pre_split printf("nc:%d nod:%d\n", nc,node[nc].nr);
7227                 /* redefine the tet */
7228                 for(i=4; i<10; i++)
7229                   if(e_enqire[e].nod[i]==node[nm].nr)
7230                   {
7231                     //debug_pre_split printf("e:%d n:%d to %d\n", e, e_enqire[e].nod[i], node[nc].nr );
7232                     e_enqire[e].nod[i]=node[nc].nr;
7233                     break;
7234                   }
7235               }
7236               seta(set_ntop, "n",node[nc].nr);
7237 	    }
7238             seta(set_ntop, "n",node[ncpy[0]].nr);
7239             seta(set_ntop, "n",node[ncpy[1]].nr);
7240             seta(set_etop, "e", e);
7241           }
7242 	  else
7243 	  {
7244             nn1=node[nnew[0]].nr;
7245             nn2=node[nnew[1]].nr;
7246 	    if(e_enqire[e].type==6)
7247             {
7248               nm=s=-1;
7249               for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) { nm=n1nm[nn1].nm[i]; s=i; break; }
7250     	      if(s<0) { for(i=0; i<n1nm[nn2].sum; i++) { if(n1nm[nn2].n2[i]==nn1) { nm=n1nm[nn2].nm[i]; break; } } }
7251               seta(set_nbot, "n",node[nm].nr);
7252             }
7253             seta(set_nbot, "n",nn1);
7254             seta(set_nbot, "n",nn2);
7255             seta(set_ebot, "e", e);
7256           }
7257 
7258 	}
7259         else if(m==4)  /* 4 edges splitted: 2 pentas */
7260         {
7261           //debug_pre_split printf("4 edges splitted: 2 pentas\n",e);
7262 
7263           /* calc average normal of the splitting triangles */
7264           for (j=0; j<3; j++) vn_av[j]=0.;
7265           for (i=0; i<m; i++)
7266 	  {
7267             for (j=0; j<3; j++) vn_av[j]+=vn_tri[i][j];
7268 	  }
7269 
7270           /* the two unsplitted lines must be unconnected */
7271           if((nunspl[0][0]==nunspl[1][0])||(nunspl[0][0]==nunspl[1][1])) goto next_elem;
7272           if((nunspl[0][1]==nunspl[1][0])||(nunspl[0][1]==nunspl[1][1])) goto next_elem;
7273 
7274           /* sort the elements according to their orientation regarding the splitting triangle */
7275           v_result( &node[nunspl[0][0]].nx,&node[nunspl[1][0]].nx, v15);
7276           v_result( &node[nunspl[0][1]].nx,&node[nunspl[1][1]].nx, v13);
7277           v_norm(v15,v15);
7278           v_norm(v13,v13);
7279           v_add(v15,v13,v12);
7280           if (v_sprod(vn_av,v12) < 0.) { n1=1; n2=0; } else { n1=0; n2=1; }
7281 
7282           /* 1. penta */
7283           d1=1; d2=4;
7284           nel[0]=nunspl[n1][0];
7285           nel[3]=nunspl[n1][1];
7286           for(i=0; i<4; i++)
7287           {
7288             for(j=0; j<2; j++)
7289             {
7290 	      //printf("ref:%d unspl:%d %d\n", nref[i][j], nunspl[n1][0],nunspl[n1][1]);
7291 	      if(nref[i][j]==nunspl[n1][0])  nel[d1++]=node[nnew[i]].nr;
7292 	      if(nref[i][j]==nunspl[n1][1])  nel[d2++]=node[nnew[i]].nr;
7293 	    }
7294 	  }
7295 
7296           /* check the orientation */
7297           v_result( &node[nel[0]].nx, &node[nel[1]].nx, v12);
7298           v_result( &node[nel[0]].nx, &node[nel[2]].nx, v13);
7299           v_result( &node[nel[0]].nx, &node[nunspl[n1][1]].nx, v15);
7300           v_prod(v12,v13,vn);
7301           v_result(v15,vn,v15n);
7302           bvn=v_betrag(vn);
7303           bv15=v_betrag(v15);
7304           bgrenz=sqrt(bvn*bvn+bv15*bv15);
7305           bv15n=v_betrag(v15n);
7306 
7307           //printf ("%f %f vn x=%e y=%e z=%e\n",bgrenz, bv15n,vn[0],vn[1],vn[2]);
7308           if (bv15n > bgrenz) { ibuf=nel[1]; nel[1]=nel[2]; nel[2]=ibuf ; }
7309 
7310           /* check the orientation */
7311           v_result( &node[nel[3]].nx, &node[nel[4]].nx, v12);
7312           v_result( &node[nel[3]].nx, &node[nel[5]].nx, v13);
7313           v_result( &node[nel[3]].nx, &node[nunspl[n1][0]].nx, v15);
7314           v_prod(v12,v13,vn);
7315           v_result(v15,vn,v15n);
7316           bvn=v_betrag(vn);
7317           bv15=v_betrag(v15);
7318           bgrenz=sqrt(bvn*bvn+bv15*bv15);
7319           bv15n=v_betrag(v15n);
7320 
7321           //printf ("%f %f vn x=%e y=%e z=%e\n",bgrenz, bv15n,vn[0],vn[1],vn[2]);
7322           if (bv15n < bgrenz) { ibuf=nel[4]; nel[4]=nel[5]; nel[5]=ibuf ; }
7323 
7324           if(e_enqire[e].type==6)
7325 	  {
7326             /* gen mitside-nodes */
7327             for (n=0; n<6; n++) nbuf[n]=nel[n];
7328 
7329             for (n=0; n<9; n++)
7330             {
7331               nel[nodseq_pe15[n*3]]=  nn1= nbuf[nodseq_pe6[n*2]];
7332               nel[nodseq_pe15[n*3+2]]=   nn2= nbuf[nodseq_pe6[n*2+1]];
7333 
7334               /* check if the nm exists already */
7335               nm=-1;
7336               for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) nm=n1nm[nn1].nm[i];
7337               for(i=0; i<n1nm[nn2].sum; i++) if(n1nm[nn2].n2[i]==nn1) nm=n1nm[nn2].nm[i];
7338 
7339               if(nm==-1)
7340               {
7341                 /* generate new node */
7342                 nm=nod( anz, &node, 1, anz->nnext++, 0., 0., 0., 0 );
7343                 node[node[nm].nr].nx=(node[nn1].nx+node[nn2].nx)*.5;
7344                 node[node[nm].nr].ny=(node[nn1].ny+node[nn2].ny)*.5;
7345                 node[node[nm].nr].nz=(node[nn1].nz+node[nn2].nz)*.5;
7346                 if ( (n1nm[nn1].n2 = (int *)realloc( n1nm[nn1].n2, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7347                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7348                 if ( (n1nm[nn1].nm = (int *)realloc( n1nm[nn1].nm, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7349                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7350                 if ( (n1nm[nn1].nc = (int *)realloc( n1nm[nn1].nc, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7351                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7352                 n1nm[nn1].n2[n1nm[nn1].sum]=nn2;
7353                 n1nm[nn1].nm[n1nm[nn1].sum]=nm;
7354                 n1nm[nn1].nc[n1nm[nn1].sum]=-1;
7355                 n1nm[nn1].sum++;
7356               }
7357 
7358               nel[nodseq_pe15[n*3+1]]=node[nm].nr;
7359             }
7360             elem_define(anz,&e_enqire, e, 5, nel, 1, 0 );
7361             seta(set_nbot, "n",nel[1]);
7362             seta(set_nbot, "n",nel[2]);
7363             seta(set_nbot, "n",nel[4]);
7364             seta(set_nbot, "n",nel[5]);
7365             seta(set_nbot, "n",nel[7]);
7366             seta(set_nbot, "n",nel[10]);
7367             seta(set_nbot, "n",nel[11]);
7368             seta(set_nbot, "n",nel[13]);
7369 	  }
7370           else
7371           {
7372             elem_define(anz,&e_enqire, e, 2, nel, 1, 0 );
7373             seta(set_nbot, "n",nel[1]);
7374             seta(set_nbot, "n",nel[2]);
7375             seta(set_nbot, "n",nel[4]);
7376             seta(set_nbot, "n",nel[5]);
7377           }
7378           seta(set_ebot, "e",e);
7379 
7380           /* 2. penta, redefine tet */
7381           d1=1; d2=4;
7382           for(i=0; i<4; i++)
7383           {
7384             nel[0]=nunspl[n2][0];
7385             nel[3]=nunspl[n2][1];
7386             for(j=0; j<2; j++)
7387             {
7388 	      //printf("ref:%d unspl:%d %d\n", nref[i][j], nunspl[n2][0],nunspl[n2][1]);
7389 	      if(nref[i][j]==nunspl[n2][0])  nel[d1++]=node[ncpy[i]].nr;
7390 	      if(nref[i][j]==nunspl[n2][1])  nel[d2++]=node[ncpy[i]].nr;
7391 	    }
7392 	  }
7393 	  //for(i=0; i<6; i++) printf("%d ", nel[i]); printf("\n");
7394 
7395           /* check the orientation */
7396           v_result( &node[nel[0]].nx, &node[nel[1]].nx, v12);
7397           v_result( &node[nel[0]].nx, &node[nel[2]].nx, v13);
7398           v_result( &node[nel[0]].nx, &node[nunspl[n2][1]].nx, v15);
7399           v_prod(v12,v13,vn);
7400           v_result(v15,vn,v15n);
7401           bvn=v_betrag(vn);
7402           bv15=v_betrag(v15);
7403           bgrenz=sqrt(bvn*bvn+bv15*bv15);
7404           bv15n=v_betrag(v15n);
7405 
7406           //printf ("%f %f vn x=%e y=%e z=%e\n",bgrenz, bv15n,vn[0],vn[1],vn[2]);
7407           if (bv15n > bgrenz) { ibuf=nel[1]; nel[1]=nel[2]; nel[2]=ibuf ; }
7408 
7409           /* check the orientation */
7410           v_result( &node[nel[3]].nx, &node[nel[4]].nx, v12);
7411           v_result( &node[nel[3]].nx, &node[nel[5]].nx, v13);
7412           v_result( &node[nel[3]].nx, &node[nunspl[n2][0]].nx, v15);
7413           v_prod(v12,v13,vn);
7414           v_result(v15,vn,v15n);
7415           bvn=v_betrag(vn);
7416           bv15=v_betrag(v15);
7417           bgrenz=sqrt(bvn*bvn+bv15*bv15);
7418           bv15n=v_betrag(v15n);
7419 
7420           //printf ("%f %f vn x=%e y=%e z=%e\n",bgrenz, bv15n,vn[0],vn[1],vn[2]);
7421           if (bv15n < bgrenz) { ibuf=nel[4]; nel[4]=nel[5]; nel[5]=ibuf ; }
7422 
7423           if(e_enqire[e].type==5)
7424 	  {
7425             /* gen mitside-nodes */
7426             for (n=0; n<6; n++) nbuf[n]=nel[n];
7427 
7428             for (n=0; n<9; n++)
7429             {
7430               nel[nodseq_pe15[n*3]]=  nn1= nbuf[nodseq_pe6[n*2]];
7431               nel[nodseq_pe15[n*3+2]]=   nn2= nbuf[nodseq_pe6[n*2+1]];
7432 
7433               /* check if the nm exists already */
7434               nm=-1;
7435               for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) nm=n1nm[nn1].nm[i];
7436               for(i=0; i<n1nm[nn2].sum; i++) if(n1nm[nn2].n2[i]==nn1) nm=n1nm[nn2].nm[i];
7437 
7438               if(nm==-1)
7439               {
7440                 /* generate new node */
7441                 nm=nod( anz, &node, 1, anz->nnext++, 0., 0., 0., 0 );
7442                 node[node[nm].nr].nx=(node[nn1].nx+node[nn2].nx)*.5;
7443                 node[node[nm].nr].ny=(node[nn1].ny+node[nn2].ny)*.5;
7444                 node[node[nm].nr].nz=(node[nn1].nz+node[nn2].nz)*.5;
7445                 if ( (n1nm[nn1].n2 = (int *)realloc( n1nm[nn1].n2, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7446                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7447                 if ( (n1nm[nn1].nm = (int *)realloc( n1nm[nn1].nm, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7448                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7449                 if ( (n1nm[nn1].nc = (int *)realloc( n1nm[nn1].nc, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7450                 { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7451                 n1nm[nn1].n2[n1nm[nn1].sum]=nn2;
7452                 n1nm[nn1].nm[n1nm[nn1].sum]=nm;
7453                 n1nm[nn1].nc[n1nm[nn1].sum]=-1;
7454                 n1nm[nn1].sum++;
7455               }
7456 
7457               nel[nodseq_pe15[n*3+1]]=node[nm].nr;
7458             }
7459             elem_define(anz,&e_enqire, anz->enext++, 5, nel, 1, 0 );
7460             seta(set_ntop, "n",nel[1]);
7461             seta(set_ntop, "n",nel[2]);
7462             seta(set_ntop, "n",nel[4]);
7463             seta(set_ntop, "n",nel[5]);
7464             seta(set_ntop, "n",nel[7]);
7465             seta(set_ntop, "n",nel[10]);
7466             seta(set_ntop, "n",nel[11]);
7467             seta(set_ntop, "n",nel[13]);
7468 	  }
7469           else
7470           {
7471             elem_define(anz,&e_enqire, anz->enext++, 2, nel, 1, 0 );
7472             seta(set_ntop, "n",nel[1]);
7473             seta(set_ntop, "n",nel[2]);
7474             seta(set_ntop, "n",nel[4]);
7475             seta(set_ntop, "n",nel[5]);
7476           }
7477           seta(set_etop, "e", anz->emax);
7478 	}
7479 	else if(m==3)
7480         {
7481 	  //debug_pre_split printf("c:%d e:%d cut at top through tet => 1tet 1pe\n",c, e);
7482 
7483           /* calc average normal of the splitting triangles */
7484           for (j=0; j<3; j++) vn_av[j]=0.;
7485           for (i=0; i<m; i++)
7486 	  {
7487             for (j=0; j<3; j++) vn_av[j]+=vn_tri[i][j];
7488 	  }
7489 
7490           /* search common node of splitted edges, this will be the tip-node of the resulting tet */
7491           /* exclude all nodes on collapsed edges */
7492           /* and later replace also nref with nodes from the edge running from ncollapsed to the tip (at n) */
7493           for(n=0; n<m; n++)
7494           {
7495             if((nref[n][0]==ncollapsed[0])||(nref[n][1]==ncollapsed[0])) { edge[n*2]=edge[n*2+1]=0; break; }
7496 	  }
7497           qsort( edge, 6, sizeof(int), (void *)compareInt );
7498           l=0;
7499           for(i=0;i<5; i++)
7500           {
7501             if(edge[i]==edge[i+1]) l++; else l=0;
7502 	    //debug_pre_split printf("node[%d]:%d l:%d\n",i,edge[i],l);
7503             if((l==1)&&(edge[i]))
7504             {
7505               /* tip of tet was found */
7506               if(c) { nref[n][0]=ncollapsed[0]; nref[n][1]=edge[i]; }
7507               /* sort the elements according to their orientation regarding the splitting triangle */
7508               //v_result( &node[node[nnew[0]].nr].nx,&node[edge[i]].nx, v12);
7509               //if (v_sprod(vn_av,v12) < 0.)
7510               v_result( &node[node[nnew[0]].nr].nx,&node[edge[i]].nx, v15);
7511               v_result( &node[node[nnew[1]].nr].nx,&node[edge[i]].nx, v13);
7512               v_result( &node[node[nnew[2]].nr].nx,&node[edge[i]].nx, v12);
7513               v_norm(v15,v15);
7514               v_norm(v13,v13);
7515               v_norm(v12,v12);
7516               v_add(v15,v13,vn);
7517               v_add(vn,v12,v15);
7518 
7519               if (v_sprod(vn_av,v15) < 0.)
7520               {
7521                 n1=0;
7522               }
7523               else
7524               {
7525                 n1=1;
7526 	      }
7527 
7528 
7529               /* check the orientation */
7530               v_result( &node[node[nnew[0]].nr].nx, &node[node[nnew[1]].nr].nx, v12);
7531               v_result( &node[node[nnew[0]].nr].nx, &node[node[nnew[2]].nr].nx, v13);
7532               v_result( &node[node[nnew[0]].nr].nx, &node[edge[i]].nx, v15);
7533               v_prod(v12,v13,vn);
7534               v_result(v15,vn,v15n);
7535               bvn=v_betrag(vn);
7536               bv15=v_betrag(v15);
7537               bgrenz=sqrt(bvn*bvn+bv15*bv15);
7538               bv15n=v_betrag(v15n);
7539 
7540 	      /*
7541           printf("ntip:%d n:%d\n", edge[i],node[nnew[0]].nr);
7542 	  printf("tri: %f %f %f %f\n", vn_tri[0][0], vn_tri[0][1], vn_tri[0][2], v_betrag(vn_av));
7543 	  printf("v12: %f %f %f %f\n", v12[0], v12[1], v12[2], v_betrag(v12));
7544 	  printf("v15: %f %f %f %f\n", v15[0], v15[1], v15[2], bv15);
7545               printf ("%f %f vn x=%e y=%e z=%e\n",bgrenz, bv15n,vn[0],vn[1],vn[2]);
7546               printf("common node:%d\n",edge[i+1]);
7547 	      */
7548 
7549               if (bv15n < bgrenz)
7550               {
7551                 /* nodes for the penta elem */
7552                 for(j=0; j<3; j++)
7553                 {
7554 		  if(n1) nel[j+3]=node[nnew[j]].nr;
7555 		  else   nel[j+3]=node[ncpy[j]].nr;
7556                   if( edge[i]==nref[j][0]) nel[j]=nref[j][1]; else nel[j]=nref[j][0];
7557 
7558                   /* for collapsed penta */
7559                   if(!n1) if(c) if(nel[j]==ncollapsed[0]) ibuf=nel[j]=node[ncpy[j]].nr;
7560                 }
7561                 /* redefine the tet */
7562                 m=3; j=0;
7563                 if(n1) while(j<3) e_enqire[e].nod[m--]=node[ncpy[j++]].nr;
7564                 else   while(j<3) e_enqire[e].nod[m--]=node[nnew[j++]].nr;
7565 
7566                 /* for collapsed penta on the tet-side */
7567                 if(n1) if(c) for(j=0; j<3; j++) if(node[nnew[j]].nr==ncollapsed[0]) { ibuf=node[ncpy[j]].nr; break; }
7568               }
7569               else
7570               {
7571                 /* nodes for the penta elem */
7572                 for(j=0; j<3; j++)
7573                 {
7574                   if(n1) nel[j]=node[nnew[j]].nr;
7575                   else   nel[j]=node[ncpy[j]].nr;
7576                   if( edge[i]==nref[j][0]) nel[j+3]=nref[j][1]; else nel[j+3]=nref[j][0];
7577 
7578                   /* for collapsed penta */
7579                   if(!n1) if(c) if(nel[j+3]==ncollapsed[0])  ibuf=nel[j+3]=node[ncpy[j]].nr;
7580                 }
7581                 /* redefine the tet */
7582                 m=1; j=0;
7583                 if(n1)  while(j<3) e_enqire[e].nod[m++]=node[ncpy[j++]].nr;
7584                 else    while(j<3) e_enqire[e].nod[m++]=node[nnew[j++]].nr;
7585 
7586                 /* for collapsed penta on the tet-side */
7587                 if(n1) if(c) for(j=0; j<3; j++) if(node[nnew[j]].nr==ncollapsed[0]) { ibuf=node[ncpy[j]].nr; break; }
7588               }
7589               e_enqire[e].nod[0]=edge[i];
7590 
7591               if(e_enqire[e].type==6)
7592 	      {
7593                 /* gen mitside-nodes */
7594                 for (n=0; n<6; n++)
7595                 {
7596                   nn1= e_enqire[e].nod[nodseq_te4[n*2]];
7597                   nn2= e_enqire[e].nod[nodseq_te4[n*2+1]];
7598 
7599                   /* for collapsed penta on the tet-side */
7600                   if((n1)&&(c)&&((n<4)&&(n!=1)))
7601                   {
7602                     if(nn1==ibuf) nn1=ncollapsed[0];
7603                     if(nn2==ibuf) nn2=ncollapsed[0];
7604                   }
7605                   //debug_pre_split printf("b n1:%d c:%d tet:%d n12 %d %d col %d ibuf %d\n", n1, c, e, nn1, nn2, ncollapsed[0], ibuf);
7606 
7607                   /* check if the nm exists already */
7608                   nm=-1;
7609                   for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) nm=n1nm[nn1].nm[i];
7610                   for(i=0; i<n1nm[nn2].sum; i++) if(n1nm[nn2].n2[i]==nn1) nm=n1nm[nn2].nm[i];
7611 
7612                   if(nm==-1)
7613                   {
7614                     /* generate new node */
7615                     nm=nod( anz, &node, 1, anz->nnext++, 0., 0., 0., 0 );
7616                     node[node[nm].nr].nx=(node[nn1].nx+node[nn2].nx)*.5;
7617                     node[node[nm].nr].ny=(node[nn1].ny+node[nn2].ny)*.5;
7618                     node[node[nm].nr].nz=(node[nn1].nz+node[nn2].nz)*.5;
7619                     if ( (n1nm[nn1].n2 = (int *)realloc( n1nm[nn1].n2, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7620                     { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7621                     if ( (n1nm[nn1].nm = (int *)realloc( n1nm[nn1].nm, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7622                     { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7623                     if ( (n1nm[nn1].nc = (int *)realloc( n1nm[nn1].nc, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7624                     { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7625                     n1nm[nn1].n2[n1nm[nn1].sum]=nn2;
7626                     n1nm[nn1].nm[n1nm[nn1].sum]=nm;
7627                     n1nm[nn1].nc[n1nm[nn1].sum]=-1;
7628                     n1nm[nn1].sum++;
7629                   }
7630                   e_enqire[e].nod[nodseq_te10[n*3+1]]=node[nm].nr;
7631                   if((n>3)||(n==1))
7632                   {
7633                     if(!n1) seta(set_nbot, "n",node[nm].nr);
7634                     else   seta(set_ntop, "n",node[nm].nr);
7635                   }
7636                 }
7637 
7638                 /* penta */
7639 
7640                 for (n=0; n<6; n++) nbuf[n]=nel[n];
7641                 for (n=0; n<9; n++)
7642                 {
7643                   nel[nodseq_pe15[n*3]]=  nn1= nbuf[nodseq_pe6[n*2]];
7644                   nel[nodseq_pe15[n*3+2]]=   nn2= nbuf[nodseq_pe6[n*2+1]];
7645 
7646                   /* for collapsed penta */
7647                   if(nn1==nn2)
7648 		  {
7649                     nel[nodseq_pe15[n*3+1]]=nn1;
7650 		  }
7651                   else
7652 		  {
7653                     /* for collapsed penta */
7654                   //debug_pre_split printf("n1:%d c:%d ibuf:%d col:%d n12 %d %d\n", n1,c, ibuf, ncollapsed[0], nn1, nn2);
7655                     if(!n1) if(c) { if(nn1==ibuf) nn1=ncollapsed[0]; if(nn2==ibuf) nn2=ncollapsed[0]; }
7656 
7657                     /* check if the nm exists already */
7658                     nm=-1;
7659                     for(i=0; i<n1nm[nn1].sum; i++) if(n1nm[nn1].n2[i]==nn2) nm=n1nm[nn1].nm[i];
7660                     for(i=0; i<n1nm[nn2].sum; i++) if(n1nm[nn2].n2[i]==nn1) nm=n1nm[nn2].nm[i];
7661 
7662                     if(nm==-1)
7663                     {
7664                       /* generate new node */
7665                       nm=nod( anz, &node, 1, anz->nnext++, 0., 0., 0., 0 );
7666                       node[node[nm].nr].nx=(node[nn1].nx+node[nn2].nx)*.5;
7667                       node[node[nm].nr].ny=(node[nn1].ny+node[nn2].ny)*.5;
7668                       node[node[nm].nr].nz=(node[nn1].nz+node[nn2].nz)*.5;
7669                       if ( (n1nm[nn1].n2 = (int *)realloc( n1nm[nn1].n2, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7670                       { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7671                       if ( (n1nm[nn1].nm = (int *)realloc( n1nm[nn1].nm, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7672                       { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7673                       if ( (n1nm[nn1].nc = (int *)realloc( n1nm[nn1].nc, (n1nm[nn1].sum+1) * sizeof(int))) == NULL )
7674                       { printf("\n\n ERROR in mids: realloc\n\n") ; exit(-1); }
7675                       n1nm[nn1].n2[n1nm[nn1].sum]=nn2;
7676                       n1nm[nn1].nm[n1nm[nn1].sum]=nm;
7677                       n1nm[nn1].nc[n1nm[nn1].sum]=-1;
7678                       n1nm[nn1].sum++;
7679                     }
7680                     nel[nodseq_pe15[n*3+1]]=node[nm].nr;
7681 
7682                     if (bv15n < bgrenz)
7683                     {
7684                     if((n>2)&&(n<6))
7685                     {
7686                         if(n1) seta(set_nbot, "n",node[nm].nr);
7687                         else   seta(set_ntop, "n",node[nm].nr);
7688                     }
7689                   }
7690                     else
7691                     {
7692                     if(n<3)
7693                     {
7694                         if(n1) seta(set_nbot, "n",node[nm].nr);
7695                         else   seta(set_ntop, "n",node[nm].nr);
7696                     }
7697                   }
7698 
7699                   }
7700                 }
7701                 elem_define(anz,&e_enqire, anz->enext++, 5, nel, 1, 0 );
7702 	      }
7703 	      else
7704               {
7705                 elem_define(anz,&e_enqire, anz->enext++, 2, nel, 1, 0 );
7706               }
7707 
7708               for(j=0; j<3; j++) { seta(set_ntop, "n",node[ncpy[j]].nr); seta(set_nbot, "n",node[nnew[j]].nr); }
7709               if (n1==0)
7710               {
7711                 seta(set_ebot, "e", e);
7712                 seta(set_etop, "e",anz->emax);
7713               }
7714               else
7715               {
7716                 seta(set_etop, "e", e);
7717                 seta(set_ebot, "e",anz->emax);
7718 	      }
7719 
7720               break;
7721 	    }
7722           }
7723 
7724         }
7725 	else if(m>0)
7726         {
7727 	  printf("c:%d e:%d m:%d unknow case\n",c, e, m);
7728 	  goto next_elem;
7729 	}
7730       }
7731       continue;
7732     next_elem:;
7733      seta(set_efail, "e",e);
7734     }
7735     if(param[0]=='e') goto ready;
7736 
7737     //completeSet( "all", "up" );
7738     //completeSet( "all", "do" );
7739 
7740     /* new midnodes */
7741     adjustDrawNodes(1);
7742 
7743     /* merge top nodes */
7744     sprintf(buffer,"n %s",set[set_ntop].name);
7745     pre_merge(buffer);
7746 
7747     makeSurfaces();
7748     getElemNormalen( e_enqire, node, anz->e );
7749     realloc_colNr();
7750 
7751     if(printFlag) printf(" updateDispLists\n");
7752     updateDispLists();
7753 
7754     completeSet( set[set_ntop].name, "do" );
7755     completeSet( set[set_nbot].name, "do" );
7756     separateMeshes( "all", "+splt");
7757 
7758   ready:;
7759     adjustDrawNodes(1);
7760     printf (" ready\n");
7761   }
7762 
7763 
7764   /* 1) split all lines */
7765 
7766   /* go over all lines */
7767   if(set[setNr].anz_l)
7768   {
7769     /* create a dummy set for the new lines */
7770     setSplit=pre_seta("-splitbuf","i",0);
7771 
7772     /* go over all lines and calculate the split-point */
7773     for (ll=0; ll<set[setNr].anz_l; ll++)
7774     {
7775       l=set[setNr].line[ll];
7776       if(printFlag) printf("check line:%s\n", line[l].name);
7777 
7778       /* store the line-dots in an array of points */
7779       /* the original coordinates are used  */
7780       lps=0.;
7781       calcLineLength(l)/scale->w;
7782 
7783       pl[0][0]=line[l].ip[0];
7784       pl[0][1]=line[l].ip[1];
7785       pl[0][2]=line[l].ip[2];
7786       for (p=3; p<line[l].nip; p+=3)
7787       {
7788         pl[1][0]=line[l].ip[p]  ;
7789         pl[1][1]=line[l].ip[p+1];
7790         pl[1][2]=line[l].ip[p+2];
7791 
7792         /* The embedded triangles of the surfaces are used as a target */
7793         /* determine the position where the vector vproj between two line-dots meets the triangles */
7794         /* and determine if the position is inside the triangle */
7795         vproj[0]=pl[1][0]-pl[0][0];
7796         vproj[1]=pl[1][1]-pl[0][1];
7797         vproj[2]=pl[1][2]-pl[0][2];
7798         lp0p1=v_betrag( vproj );
7799         /*
7800         printf("pl: %lf %lf %lf\n",pl[0][0],pl[0][1],pl[0][2]);
7801         printf("v: %lf %lf %lf\n",vproj[0],vproj[1],vproj[2]);
7802         printf("pt1: %lf %lf %lf\n",pt1[0],pt1[1],pt1[2] );
7803         printf("pt2: %lf %lf %lf\n",pt2[0],pt2[1],pt2[2] );
7804         printf("pt3: %lf %lf %lf\n",pt3[0],pt3[1],pt3[2] );
7805         */
7806 
7807         /* go over all splitting-tri */
7808         for( n=0; n<sum_tri; n++)
7809         {
7810           pt1[0]=tri[n].p1[0];
7811           pt1[1]=tri[n].p1[1];
7812           pt1[2]=tri[n].p1[2];
7813           pt2[0]=tri[n].p2[0];
7814           pt2[1]=tri[n].p2[1];
7815           pt2[2]=tri[n].p2[2];
7816           pt3[0]=tri[n].p3[0];
7817           pt3[1]=tri[n].p3[1];
7818           pt3[2]=tri[n].p3[2];
7819 
7820           dist=v_distA(  pt1, pt2, pt3, pl[0], vproj, 1., &orient);
7821           dist2=v_distA(  pt1, pt2, pt3, pl[1], vproj, 1., &orient);
7822 
7823           /* create a point only if the vector goes through the tri and if the sign of dist has changed (scip the first line-vector (p==3))*/
7824 	  /* printf("nip:%d dist2:%lf dist:%lf p:%d \n",line[l].nip, dist2, dist, p); */
7825           if (( dist != OUTSIDE ) && ( dist2 != OUTSIDE ) && (dist2*dist < 0.))
7826           {
7827             /* split-point */
7828             v_norm( vproj, pc );
7829             vs[0]=pc[0]*(dist);
7830             vs[1]=pc[1]*(dist);
7831             vs[2]=pc[2]*(dist);
7832             psplt[0][0]=pl[0][0]+vs[0];
7833             psplt[0][1]=pl[0][1]+vs[1];
7834             psplt[0][2]=pl[0][2]+vs[2];
7835             lp0p1=v_betrag( vs );
7836             lps+=lp0p1;
7837 
7838             /* split line only if its end-points are more than ltol away */
7839             mode=0;
7840             dx=psplt[0][0]-(point[line[l].p1].px);
7841             dy=psplt[0][1]-(point[line[l].p1].py);
7842             dz=psplt[0][2]-(point[line[l].p1].pz);
7843             if(sqrt(dx*dx+dy*dy+dz*dz)<ltol) mode=1;
7844 	    /* printf("d1:%lf gtol:%lf\n", sqrt(dx*dx+dy*dy+dz*dz),ltol); */
7845             if(!mode)
7846 	    {
7847               dx=psplt[0][0]-(point[line[l].p2].px);
7848               dy=psplt[0][1]-(point[line[l].p2].py);
7849               dz=psplt[0][2]-(point[line[l].p2].pz);
7850               if(sqrt(dx*dx+dy*dy+dz*dz)<ltol) mode=1;
7851 	      /* printf("d2:%lf gtol:%lf\n", sqrt(dx*dx+dy*dy+dz*dz),ltol); */
7852 	    }
7853             if(!mode)
7854 	    {
7855               getNewName( name, "p" );
7856               if(printFlag) printf(" create split-point:%s %lf %lf %lf\n", name, psplt[0][0], psplt[0][1], psplt[0][2] );
7857               ps_nr  = pnt( name, psplt[0][0], psplt[0][1], psplt[0][2], 0 );
7858 
7859               /* create two new lines l_nr */
7860               splitLine(l, l_nr, ps_nr);
7861               seta(setSplit, "l", l_nr[0]);
7862               seta(setSplit, "l", l_nr[1]);
7863 
7864               /* remember the basic line for later deletion */
7865               if ( (lbuffer = (int *)realloc((int *)lbuffer, (sum_l+1)*sizeof(int))) == NULL ) printf("\n\n ERROR: malloc failure\n\n" );
7866               lbuffer[sum_l]=l;
7867               sum_l++;
7868 
7869             }
7870             goto nextLine;  // check no more tri's, take the next line
7871 	  }
7872         }
7873         lps+=lp0p1;
7874         pl[0][0]=pl[1][0];
7875         pl[0][1]=pl[1][1];
7876         pl[0][2]=pl[1][2];
7877       }
7878     nextLine:;
7879     }
7880     /* delete all splitted lines */
7881     delLine( sum_l, lbuffer );
7882     free(lbuffer);
7883     lbuffer=NULL;
7884     sum_l=0;
7885     /* add the new lines to the split set */
7886     s=getSetNr(setname);
7887     for(ll=0; ll<set[setSplit].anz_l; ll++) seta(s,"l",set[setSplit].line[ll]);
7888     delSet(set[setSplit].name);
7889   }
7890 
7891 
7892   /* 2) split all surfaces */
7893 
7894   /* go over all surfs which should be splitted (opposite to the lines-procedere) */
7895   /* and create the split-points */
7896   for (ss=0; ss<set[setNr].anz_s; ss++)
7897   {
7898     s=set[setNr].surf[ss];
7899     /* go over all tri */
7900     n=0;
7901     while((surf[s].npgn-n))
7902     {
7903       /* requires that only triangles are used for the interiour description of the surface */
7904       /* this is regarded by the adjustFeedBack() routine */
7905       n+=5; /* jump over the leading bytes */
7906       ps[0][0]=surf[s].pgn[n++];
7907       ps[0][1]=surf[s].pgn[n++];
7908       ps[0][2]=surf[s].pgn[n++];
7909       ps[1][0]=surf[s].pgn[n++];
7910       ps[1][1]=surf[s].pgn[n++];
7911       ps[1][2]=surf[s].pgn[n++];
7912       ps[2][0]=surf[s].pgn[n++];
7913       ps[2][1]=surf[s].pgn[n++];
7914       ps[2][2]=surf[s].pgn[n++];
7915 
7916       /* "cg" of tri-edges */
7917       cg_edge[0][0]=(ps[0][0]+ps[1][0])*.5;
7918       cg_edge[0][1]=(ps[0][1]+ps[1][1])*.5;
7919       cg_edge[0][2]=(ps[0][2]+ps[1][2])*.5;
7920 
7921       cg_edge[1][0]=(ps[1][0]+ps[2][0])*.5;
7922       cg_edge[1][1]=(ps[1][1]+ps[2][1])*.5;
7923       cg_edge[1][2]=(ps[1][2]+ps[2][2])*.5;
7924 
7925       cg_edge[2][0]=(ps[2][0]+ps[0][0])*.5;
7926       cg_edge[2][1]=(ps[2][1]+ps[0][1])*.5;
7927       cg_edge[2][2]=(ps[2][2]+ps[0][2])*.5;
7928 
7929       /* go over all edges and determine the split-point */
7930       sum_psplt=0;
7931       for(e=0; e<3; e++)
7932       {
7933         /* find the closest splitting-tri */
7934         /* distance between line-cg and tri-cg */
7935         if ( (rsort = (Rsort *)realloc((Rsort *)rsort, (sum_tri+1) * sizeof(Rsort))) == NULL )
7936           printf("ERROR: realloc failed: Rsort\n\n" );
7937         for(i=0; i<sum_tri; i++)
7938         {
7939           dx=tri[i].cg[0]-cg_edge[e][0];
7940           dy=tri[i].cg[1]-cg_edge[e][1];
7941           dz=tri[i].cg[2]-cg_edge[e][2];
7942           rsort[i].r=dx*dx+dy*dy+dz*dz;
7943           rsort[i].i=i;
7944         }
7945         qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
7946 
7947         //for (i=0; i<sum_tri; i++) printf("%d n:%d r:%lf\n", i, rsort[i].i, rsort[i].r);
7948 
7949         /* check the closest tri for a split-point */
7950         for(i=0; i<sum_tri; i++)
7951         {
7952           /* The embedded triangles of the surfaces are used as a target */
7953           /* determine the position where the vector vproj between two line-dots meets the triangles */
7954           /* and determine if the position is inside the triangle */
7955           if(e==0)      { p2_nr=1; p1_nr=0; }
7956           else if(e==1) { p2_nr=2; p1_nr=1; }
7957           else          { p2_nr=0; p1_nr=2; }
7958           vproj[0]=ps[p2_nr][0]-ps[p1_nr][0];
7959           vproj[1]=ps[p2_nr][1]-ps[p1_nr][1];
7960           vproj[2]=ps[p2_nr][2]-ps[p1_nr][2];
7961           dist=v_distA(  tri[rsort[i].i].p1, tri[rsort[i].i].p2, tri[rsort[i].i].p3, ps[p1_nr], vproj, 1., &orient);
7962           dist2=v_distA( tri[rsort[i].i].p1, tri[rsort[i].i].p2, tri[rsort[i].i].p3, ps[p2_nr], vproj, 1., &orient);
7963 
7964           /* create a point only if the vector goes through the tri and if the sign of dist has changed (scip the first line-vector (p==3))*/
7965           //printf(" tri:%d dist2:%lf dist:%lf\n",rsort[i].i, dist2, dist);
7966           if (( dist != OUTSIDE ) && ( dist2 != OUTSIDE ) && (dist2*dist < 0.))
7967           {
7968             /* split-point */
7969             v_norm( vproj, pc );
7970             psplt[sum_psplt][0]=ps[p1_nr][0]+pc[0]*(dist);
7971             psplt[sum_psplt][1]=ps[p1_nr][1]+pc[1]*(dist);
7972             psplt[sum_psplt][2]=ps[p1_nr][2]+pc[2]*(dist);
7973             sum_psplt++;
7974             break;
7975 	  }
7976     	}
7977       }
7978 
7979       /* create split-point inside the surface-tri */
7980       if(sum_psplt==2)
7981       {
7982         pc[0]=(psplt[0][0]+psplt[1][0])*.5;
7983         pc[1]=(psplt[0][1]+psplt[1][1])*.5;
7984         pc[2]=(psplt[0][2]+psplt[1][2])*.5;
7985         getNewName( name, "p" );
7986         if(printFlag) printf(" create surf-point:%s %lf %lf %lf\n", name, pc[0], pc[1], pc[2] );
7987         ps_nr  = pnt( name, pc[0], pc[1], pc[2], 0 );
7988       }
7989     }
7990   }
7991 
7992   /* split-points are created, create a new line */
7993   /* tbd */
7994 
7995   /* lines are created, create new surfaces */
7996   /* tbd */
7997 
7998   free(lbuffer);
7999   free(tri);
8000   free(rsort);
8001   delSet(specialset->dep);
8002   delSet(specialset->ind);
8003   return;
8004 }
8005 
8006 
8007 
8008 /* liefert MAX_INTEGER wenn der node ausserhalb liegt, */
8009 /* ansonsten den kuerzesten Abstand zur ebene.     */
check_tri3(double * pp,double * pt1,double * pt2,double * pt3,int tolflag)8010 double check_tri3( double *pp, double *pt1, double *pt2, double *pt3, int tolflag )
8011 {
8012    int i;
8013    int inull, iplus, iminus;
8014    double  vN0N1[3], vN1N2[3], vN2N0[3], vN0N[3], vN1N[3],  vN2N[3],
8015           vprod0[3], vprod1[3], vprod2[3], vsprod[3], vnorm[3];
8016    double en[3], ev[3], eu[3], vNN0[3], g, a=0.;
8017 
8018    /* der node liegt im Dreieck wenn: */
8019    /* - berechne die Vektorprodukte zwischen den Kantenvektoren und dem Vektor von den    */
8020    /*   Kantenpunkten zu dem node (v_prod= vP1P2 x vP1Pn)                                 */
8021    /* - berechne die Scalarprtodukte v_sprod zwischen den v_prod und dem Normalenvektor   */
8022    /*   des Dreiecks. Wenn alle v_sprod positiv sind, dann liegt der node innerhalb und   */
8023    /*   davor, wenn alle negativ sind dann dahinter. Wenn uneinheitlich, dann ausserhalb. */
8024 
8025    v_result( pt1, pt2, vN0N1);
8026    v_result( pt2, pt3, vN1N2);
8027    v_result( pt3, pt1, vN2N0);
8028    v_result( pt1, pp, vN0N);
8029    v_result( pt2, pp, vN1N);
8030    v_result( pt3, pp, vN2N);
8031 
8032    /* berechne den Normalenvektor auf der flaeche */
8033    v_prod( vN0N1, vN1N2, vnorm );
8034    v_norm( vnorm, en );
8035    /* berechne die einheitsvektoren der ebenengleichung des tri3 */
8036    v_norm( vN0N1, eu );
8037    v_norm( vN1N2, ev );
8038    /* bestimme den Abstand zwischen den Aufpunkten der Normalen und in n verschobenen Ebene  */
8039    v_result( pp, pt1, vNN0 );
8040 
8041    /* berechne die Konstante g (Abstand)  pn_neu=pn-en*g  */
8042    g = AsplitL( vNN0, eu, ev, en );
8043    v_prod( vN0N1, vN0N, vprod0 );
8044    v_prod( vN1N2, vN1N, vprod1 );
8045    v_prod( vN2N0, vN2N, vprod2 );
8046    vsprod[0]= v_sprod( vnorm, vprod0);
8047    vsprod[1]= v_sprod( vnorm, vprod1);
8048    vsprod[2]= v_sprod( vnorm, vprod2);
8049 
8050    /*   kontrolle ob ein vsprod=0 ist. Dann liegt naemlich                */
8051    /*   der zu kontrollierende node genau ueber einer der umrandungen     */
8052    /*   der kontroll-flaeche (vprod ist dann senkrecht auf der normalen). */
8053    /*   Dann werden vsprod mit den gleichen vorzeichen zusammen-          */
8054    /*   gezaelt, dabei gelten die nuller als joker                        */
8055 
8056    /* setze sehr kleine zahlen zu NULL */
8057    if(tolflag)
8058    {
8059      for (i=0; i<3; i++) a+=abs(vsprod[i]);
8060      a*=1e-10;
8061      for (i=0; i<3; i++) if (abs(vsprod[i])<a) vsprod[i]=0.;
8062    }
8063 
8064    inull=0;
8065    for (i=0; i<3; i++) if (vsprod[i] == 0.) inull++;
8066 
8067    iplus=inull;
8068    for (i=0; i<3; i++) if (vsprod[i] > 0.) iplus++;
8069 
8070    iminus=inull;
8071    for (i=0; i<3; i++) if (vsprod[i] < 0.) iminus++;
8072 
8073    //printf (" vsprod: %le %le %le inull:%d iplus:%d iminus:%d offs:%lf a:%e\n", vsprod[0],vsprod[1],vsprod[2], inull, iplus, iminus, g, a );
8074 
8075    /*           * wenn alle vectorprodukte das gleiche vorzeichen haben    *   */
8076    /*           * dann ist der node innerhalb der flaeche                  *   */
8077 
8078    if (iplus == 3) return(g);
8079    else if (iminus == 3) return(g);
8080    else return(MAX_INTEGER);
8081 }
8082 
8083 
8084 /*
8085   if(compare(action,"PROJ",4)==4) functionFlag=1;
8086   else functionFlag=0; ("DIST")
8087 */
pre_proj(char * string)8088 void pre_proj( char *string)
8089 {
8090 #define INTPOLMODE  0 /* linear */
8091 #define PROJ_BIAS 1.1
8092 #define PROJ_LOOPS 40
8093 
8094   int  length, i,j=0,n,e,p, Stmp, setNr, trgtNr, mode, csys[3], surfFlag=0, normFlag=0, functionFlag, counter=0, orient;
8095   char setname[MAX_LINE_LENGTH], targetname[MAX_LINE_LENGTH], action[MAX_LINE_LENGTH], name[MAX_LINE_LENGTH];
8096   char axis;
8097   double pr[3], pc[3], nr[3], pa1[3], pa2[3], pa3[3], ps1[3], ps2[3], vproj[3],v1[3],v2[3],bv1,bv2, offset=0., dist=1.e33, mindist=0, mindistini=0.;
8098   int  minj=0, anz_n=0;
8099   double pt1[3], pt2[3], pt3[3], rp, triScale=0.;
8100   double *nx=NULL;
8101   double *nrad=NULL;
8102   int  *nmissed=NULL;
8103 
8104   char pkt1[MAX_LINE_LENGTH], pkt2[MAX_LINE_LENGTH];
8105   int   pnr1=0, pnr2=0, setdep, setind;
8106   double r, fi, x, y, z, l, h, q, l_offs, h_offs, q_offs;
8107   double p1[3], p2[3], p1p2[3];
8108   double el[3], eh[3], eq[3];   /* xyz koordinaten der lhq vektoren */
8109   double ex[3], ey[3], ez[3];   /* lhq koordinaten der xyz vektoren */
8110   double ph[3], p1ph[3], pp[3], ppt[3], e1[3], lhq[3], angle;
8111   double pval, qval, divpq, scal_e[2];
8112 
8113   double v_qdis[2][3], da, dax, day, daz;
8114 
8115   double dist_max=-MAX_FLOAT,dist_min=MAX_FLOAT, sum_dist=0.;
8116   double dist_maxx=-MAX_FLOAT,dist_minx=MAX_FLOAT, distx;
8117   double dist_maxy=-MAX_FLOAT,dist_miny=MAX_FLOAT, disty;
8118   double dist_maxz=-MAX_FLOAT,dist_minz=MAX_FLOAT, distz;
8119   int ndist=0;
8120 
8121   Rsort *rsort=NULL;
8122   Tri *tri=NULL;
8123   int sum_tri=0;
8124 
8125   Points    *pproj=NULL;
8126   int sum_pproj;
8127   char *record;
8128 
8129   int     n_closest_tri=0, curr_n_closest_tri=0;
8130   double *orig_x=NULL, *orig_y=NULL, *orig_z=NULL, *sort_x=NULL, *sort_y=NULL, *sort_z=NULL;
8131   int *sort_nx=NULL, *sort_ny=NULL, *sort_nz=NULL, *near_tri=NULL;
8132 
8133   /* get the function name */
8134   i=0; while(string[i]==' ') i++;
8135   i+= sword( string, action);
8136   record=string+i;
8137 
8138   /* check if the function 'dist' or 'proj' was selected */
8139   for(i=0; i<strlen(action); i++) action[i]=toupper(action[i]);
8140   if(compare(action,"PROJ",4)==4) functionFlag=1;
8141   else functionFlag=0;
8142 
8143   /* get basic parameters */
8144   action[0]=0;
8145   length = sscanf( record,"%s %s %s", setname, targetname, action );
8146   operateAlias( setname, "se" );
8147   setNr=getSetNr( setname );
8148   if (setNr<0)
8149   {
8150     errMsg(" ERROR: Set (%s) is undefined\n", setname );
8151     return;
8152   }
8153 
8154   delSet(specialset->dep );
8155   delSet(specialset->ind );
8156 
8157 
8158   /* first assume the target is a single shape */
8159   operateAlias( targetname, "sh" );
8160   trgtNr=getShapeNr( targetname );
8161   if (trgtNr>-1)
8162   {
8163     if( (setind=pre_seta( specialset->ind, "sh", targetname )) <0 )
8164     {
8165       printf("ERROR: shape:%s could not be used\n", shape[trgtNr].name);
8166       return;
8167     }
8168     trgtNr=-1;
8169   }
8170   else
8171   {
8172     operateAlias( targetname, "se" );
8173     trgtNr=getSetNr( targetname );
8174     if (trgtNr<0)
8175     {
8176       errMsg(" ERROR: Set (%s) is undefined\n", targetname );
8177       return;
8178     }
8179 
8180     /* cycle through all entities of targetNr and add them to the special set  */
8181     /* cyrcle through all bodies and add  */
8182     if( (setind=pre_seta( specialset->ind, "i", 0 )) <0 ) return;
8183     for (i=0; i<set[trgtNr].anz_s; i++)
8184     {
8185       seta( setind, "s", set[trgtNr].surf[i] );
8186     }
8187     for (i=0; i<set[trgtNr].anz_l; i++)
8188     {
8189       seta( setind, "l", set[trgtNr].line[i] );
8190     }
8191     for (i=0; i<set[trgtNr].anz_f; i++)
8192     {
8193       seta( setind, "f", set[trgtNr].face[i] );
8194     }
8195     for (i=0; i<set[trgtNr].anz_n; i++)
8196     {
8197       seta( setind, "n", set[trgtNr].node[i] );
8198     }
8199     /* add only shell elements */
8200     for (i=0; i<set[trgtNr].anz_e; i++)
8201     {
8202       if((e_enqire[set[trgtNr].elem[i]].type >6)&&(e_enqire[set[trgtNr].elem[i]].type <11)) seta( setind, "e", set[trgtNr].elem[i] );
8203     }
8204     /* second cycle through all entities and add lower ones  to the special set  */
8205     completeSet( specialset->ind, "do") ;
8206     completeSet( specialset->ind, "do") ;
8207 
8208     /* do not regard surface referenced shapes */
8209     set[setind].anz_nurs=0;
8210     set[setind].anz_sh=0;
8211 
8212     /* add user chosen shapes and nurbs */
8213     for (i=0; i<set[trgtNr].anz_nurs; i++)
8214     {
8215       seta( setind, "S", set[trgtNr].nurs[i] );
8216     }
8217     for (i=0; i<set[trgtNr].anz_sh; i++)
8218     {
8219       seta( setind, "sh", set[trgtNr].shp[i] );
8220     }
8221   }
8222 
8223   /* stop here if just a measurement between points or nodes should be performed */
8224   if( (!functionFlag)&&( (set[setNr].anz_p==1)||(set[setNr].anz_n==1)) && (action[0]==0) )
8225   {
8226     // if just one trgt point, do additional angle and radial measurements
8227     if((set[trgtNr].anz_p==1)||(set[trgtNr].anz_n==1))
8228     {
8229       if(set[trgtNr].anz_p==1)
8230       {
8231         v_qdis[0][0]=point[set[setNr].pnt[0]].px*scale->w+scale->x;
8232         v_qdis[0][1]=point[set[setNr].pnt[0]].py*scale->w+scale->y;
8233         v_qdis[0][2]=point[set[setNr].pnt[0]].pz*scale->w+scale->z;
8234         v_qdis[1][0]=point[set[trgtNr].pnt[0]].px*scale->w+scale->x;
8235         v_qdis[1][1]=point[set[trgtNr].pnt[0]].py*scale->w+scale->y;
8236         v_qdis[1][2]=point[set[trgtNr].pnt[0]].pz*scale->w+scale->z;
8237       }
8238       else
8239       {
8240         v_qdis[0][0]=node[set[setNr].node[0]].nx*scale->w+scale->x;
8241         v_qdis[0][1]=node[set[setNr].node[0]].ny*scale->w+scale->y;
8242         v_qdis[0][2]=node[set[setNr].node[0]].nz*scale->w+scale->z;
8243         v_qdis[1][0]=node[set[trgtNr].node[0]].nx*scale->w+scale->x;
8244         v_qdis[1][1]=node[set[trgtNr].node[0]].ny*scale->w+scale->y;
8245         v_qdis[1][2]=node[set[trgtNr].node[0]].nz*scale->w+scale->z;
8246       }
8247       da=v_angle(v_qdis[0],v_qdis[1]);
8248       for(i=0; i<3; i++) { p1[i]=v_qdis[0][i]; p2[i]=v_qdis[1][i]; }
8249       p1[0]=p2[0]=0.;
8250       dax=v_angle(p1,p2);
8251       for(i=0; i<3; i++) { p1[i]=v_qdis[0][i]; p2[i]=v_qdis[1][i]; }
8252       p1[1]=p2[1]=0.;
8253       day=v_angle(p1,p2);
8254       for(i=0; i<3; i++) { p1[i]=v_qdis[0][i]; p2[i]=v_qdis[1][i]; }
8255       p1[2]=p2[2]=0.;
8256       daz=v_angle(p1,p2);
8257       for(i=0; i<3; i++) { p1[i]=v_qdis[0][i]; p2[i]=v_qdis[1][i]; }
8258 
8259       // dist = p1-p2
8260       dist=sqrt((v_qdis[0][0]-v_qdis[1][0])*(v_qdis[0][0]-v_qdis[1][0])+
8261       (v_qdis[0][1]-v_qdis[1][1])*(v_qdis[0][1]-v_qdis[1][1])+
8262       		(v_qdis[0][2]-v_qdis[1][2])*(v_qdis[0][2]-v_qdis[1][2]));
8263       distx=v_qdis[0][0]-v_qdis[1][0];
8264       disty=v_qdis[0][1]-v_qdis[1][1];
8265       distz=v_qdis[0][2]-v_qdis[1][2];
8266       rp=sqrt(p1[0]*p1[0]+p1[1]*p1[1]+p1[2]*p1[2])-sqrt(p2[0]*p2[0]+p2[1]*p2[1]+p2[2]*p2[2]);
8267       pr[0]=sqrt(p1[1]*p1[1]+p1[2]*p1[2])-sqrt(p2[1]*p2[1]+p2[2]*p2[2]);
8268       pr[1]=sqrt(p1[0]*p1[0]+p1[2]*p1[2])-sqrt(p2[0]*p2[0]+p2[2]*p2[2]);
8269       pr[2]=sqrt(p1[0]*p1[0]+p1[1]*p1[1])-sqrt(p2[0]*p2[0]+p2[1]*p2[1]);
8270 
8271       printf("DISTMAX:%lf dxyz:%lf %lf %lf da:%lf daxyz:%lf %lf %lf dr:%lf drxyz:%lf %lf %lf\n",dist,distx,disty,distz,
8272 	   da*180./PI, dax*180./PI, day*180./PI, daz*180./PI,rp,pr[0],pr[1],pr[2]);
8273 
8274       sprintf(parameter[0],"%f",dist);
8275       sprintf(parameter[1],"%f",distx);
8276       sprintf(parameter[2],"%f",disty);
8277       sprintf(parameter[3],"%f",distz);
8278       sprintf(parameter[4],"%f",da*180./PI);
8279       sprintf(parameter[5],"%f",dax*180./PI);
8280       sprintf(parameter[6],"%f",day*180./PI);
8281       sprintf(parameter[7],"%f",daz*180./PI);
8282       sprintf(parameter[8],"%f",rp);
8283       sprintf(parameter[9],"%f",pr[0]);
8284       sprintf(parameter[10],"%f",pr[1]);
8285       sprintf(parameter[11],"%f",pr[2]);
8286 
8287       write2stack( 8, parameter);
8288       return;
8289     }
8290 
8291     /* loop over all points or nodes of the target */
8292     if(set[setNr].anz_p)
8293       nrad=&point[set[setNr].pnt[0]].px;
8294     else if(set[setNr].anz_n)
8295       nrad=&node[set[setNr].node[0]].nx;
8296     else return;
8297     if((set[trgtNr].anz_p)||(set[trgtNr].anz_n))
8298     {
8299       for(n=0; n<set[trgtNr].anz_p; n++)
8300       {
8301         if(set[trgtNr].anz_p) nx=&point[set[trgtNr].pnt[n]].px;
8302         else nx=&node[set[trgtNr].node[n]].nx;
8303         v_result(nx,nrad,pr);
8304         v_scal(&scale->w,pr,pr );
8305         dist=v_betrag(pr);
8306         distx=pr[0];
8307         disty=pr[1];
8308         distz=pr[2];
8309         if(dist>dist_max) { dist_max=dist; pnr1=n; }
8310         if(dist<dist_min) { dist_min=dist; pnr2=n; }
8311         if(distx>dist_maxx) { dist_maxx=distx; }
8312         if(distx<dist_minx) { dist_minx=distx; }
8313         if(disty>dist_maxy) { dist_maxy=disty; }
8314         if(disty<dist_miny) { dist_miny=disty; }
8315         if(distz>dist_maxz) { dist_maxz=distz; }
8316         if(distz<dist_minz) { dist_minz=distz; }
8317       }
8318 
8319       printf("DISTMAX:%lf dxyz:%lf %lf %lf\n", dist_max, dist_maxx, dist_maxy, dist_maxz );
8320       sprintf(parameter[0],"%f",dist_max);
8321       sprintf(parameter[1],"%f",dist_maxx);
8322       sprintf(parameter[2],"%f",dist_maxy);
8323       sprintf(parameter[3],"%f",dist_maxz);
8324       printf("DISTMIN:%lf dxyz:%lf %lf %lf\n", dist_min, dist_minx, dist_miny, dist_minz );
8325       sprintf(parameter[4],"%f",dist_min);
8326       sprintf(parameter[5],"%f",dist_minx);
8327       sprintf(parameter[6],"%f",dist_miny);
8328       sprintf(parameter[7],"%f",dist_minz);
8329     }
8330 
8331     write2stack( 8, parameter);
8332     return;
8333   }
8334 
8335   /* cycle through all entities of setNr and add them to the special set  */
8336   /* cyrcle through all bodys and add  */
8337   if( (setdep=pre_seta( specialset->dep, "i", 0 )) <0 ) return;
8338   for (i=0; i<set[setNr].anz_n; i++)
8339   {
8340     seta( setdep, "n", set[setNr].node[i] );
8341   }
8342   /* add all related elements for a later midside-node-correction */
8343   completeSet( specialset->dep, "up") ;
8344 
8345   for (i=0; i<set[setNr].anz_b; i++)
8346   {
8347     seta( setdep, "b", set[setNr].body[i] );
8348   }
8349   /* cyrcle through all surfs and add  */
8350   for (i=0; i<set[setNr].anz_s; i++)
8351   {
8352     seta( setdep, "s", set[setNr].surf[i] );
8353   }
8354   /* cyrcle through all lcmbs and add  */
8355   for (i=0; i<set[setNr].anz_c; i++)
8356   {
8357     seta( setdep, "c", set[setNr].lcmb[i] );
8358   }
8359   /* cyrcle through all lines and add  */
8360   for (i=0; i<set[setNr].anz_l; i++)
8361   {
8362     seta( setdep, "l", set[setNr].line[i] );
8363   }
8364   for (i=0; i<set[setNr].anz_p; i++)
8365   {
8366     seta( setdep, "p", set[setNr].pnt[i] );
8367   }
8368   /* second cycle through all entities and add lower ones  to the special set  */
8369   // completeSet( specialset->dep, "do") ;
8370 
8371 
8372   if (set[setNr].anz_n==0) set[setdep].anz_n=set[setNr].anz_n;
8373   setNr=setdep;
8374   trgtNr=setind;
8375 
8376   /* generate an array of all points or nodes to be projected */
8377   /* the original coordinates must be used for radial projection to get the correct axis */
8378   sum_pproj=0;
8379   for (i=0; i<set[setNr].anz_p; i++)
8380   {
8381     p=set[setNr].pnt[i];
8382     if(point[p].name==(char *)NULL) continue;
8383     if (p<0)
8384     {
8385       errMsg(" ERROR: Point-nr:%d is undefined\n", set[setNr].pnt[i] );
8386       goto nextpoint;
8387     }
8388     if ( (pproj = (Points *)realloc( (Points *)pproj, (sum_pproj+2) * sizeof(Points))) == NULL )
8389     {
8390       errMsg("\nERROR: realloc failed in pre_proj() \n\n");
8391     }
8392     pproj[sum_pproj].nn=p;
8393     pproj[sum_pproj].name=point[p].name;
8394     pproj[sum_pproj].px=point[p].px*scale->w+scale->x;
8395     pproj[sum_pproj].py=point[p].py*scale->w+scale->y;
8396     pproj[sum_pproj].pz=point[p].pz*scale->w+scale->z;
8397     sum_pproj++;
8398   }
8399   for (i=0; i<set[setNr].anz_n; i++)
8400   {
8401     n=set[setNr].node[i];
8402     if ( (pproj = (Points *)realloc( (Points *)pproj, (sum_pproj+2) * sizeof(Points))) == NULL )
8403     {
8404       errMsg("\nERROR: realloc failed in pre_proj() \n\n");
8405     }
8406     pproj[sum_pproj].nn=-n;
8407     sprintf(name,"%d",n);
8408     if((pproj[sum_pproj].name= (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL )
8409     { printf("ERROR: malloc failed\n\n" ); return; }
8410     strcpy(pproj[sum_pproj].name,name);
8411     pproj[sum_pproj].px=node[n].nx*scale->w+scale->x;
8412     pproj[sum_pproj].py=node[n].ny*scale->w+scale->y;
8413     pproj[sum_pproj].pz=node[n].nz*scale->w+scale->z;
8414     sum_pproj++;
8415   }
8416   if(!sum_pproj) return;
8417 
8418   /* fill all unfilled surfaces, do it in any case because points could have been moved! */
8419   /* repShape will change *scale and therefore must be executed first */
8420   repShape(trgtNr);
8421   for (j=0; j<set[trgtNr].anz_s; j++)
8422   {
8423     //orientSet( set[trgtNr].name );
8424     if(surf[set[trgtNr].surf[j]].sh>-1)
8425     {
8426       if(shape[surf[set[trgtNr].surf[j]].sh].type==4)
8427       {
8428         repNurs(shape[surf[set[trgtNr].surf[j]].sh].p[0]); untrimNurs(shape[surf[set[trgtNr].surf[j]].sh].p[0]);
8429       }
8430     }
8431     repSurf(set[trgtNr].surf[j],1);
8432   }
8433 
8434   /* generate splitting triangles */
8435   sum_tri=genSplitTrias(trgtNr, &tri, 1);
8436 
8437   /* if no surfs and the type is proj and the direction nor then project directly to the shapes (offset in this case not regarded) */
8438   if((functionFlag)&&(!sum_tri))
8439   {
8440     if((compare(action, "nor",3) == 3)&&(set[trgtNr].anz_sh))
8441     {
8442       for(i=0; i<set[trgtNr].anz_sh; i++)
8443       {
8444         if(shape[set[trgtNr].shp[i]].type==4) projSetToNurbs( shape[set[trgtNr].shp[i]].p[0], set, setNr, point);
8445         else
8446 	{
8447 	  Stmp=-1;
8448 	  if((shape[set[trgtNr].shp[i]].type==1)||(shape[set[trgtNr].shp[i]].type==2)) Stmp=coneToNurs(set[trgtNr].shp[i], 0);
8449 	  if(shape[set[trgtNr].shp[i]].type==3) Stmp=sphToNurs(set[trgtNr].shp[i], 0);
8450 	  if(shape[set[trgtNr].shp[i]].type==5) Stmp=torusToNurs(set[trgtNr].shp[i], 0);
8451 	  if(Stmp>-1)
8452 	  {
8453 	    projSetToNurbs( Stmp, set, setNr, point);
8454             for (j=0; j<nurbs[Stmp].u_npnt; j++) delPnt( nurbs[Stmp].v_npnt, nurbs[Stmp].ctlpnt[j] );
8455             //seta( setall, "S", Stmp );
8456             delNurs( 1, &Stmp );
8457 	  }
8458 	}
8459       }
8460       goto skipTriProj;
8461     }
8462     //else printf(" ERROR: Transformation type %s not implemented for shapes (only 'nor'), please use a surface.\n", action);
8463   }
8464 
8465   /*
8466   printf("sum_tri:%d\n",sum_tri);
8467   j=1; for( n=0; n<sum_tri; n++)
8468   {
8469     printf(" node %d %f %f %f\n", j++, tri[n].p1[0], tri[n].p1[1], tri[n].p1[2]);
8470     printf(" node %d %f %f %f\n", j++, tri[n].p2[0], tri[n].p2[1], tri[n].p2[2]);
8471     printf(" node %d %f %f %f\n", j++, tri[n].p3[0], tri[n].p3[1], tri[n].p3[2]);
8472     printf(" elem %d %d %d %d tr3\n", n+1, j-3,j-2,j-1);
8473   }
8474   */
8475 
8476   /* stelle daten fuer near3d bereit */
8477   n_closest_tri=sum_tri;
8478 
8479   if ( (near_tri = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
8480     printf("ERROR: realloc failed \n\n" );
8481   if ( (rsort = (Rsort *)realloc((Rsort *)rsort, (sum_tri+1) * sizeof(Rsort))) == NULL )
8482     printf("ERROR: realloc failed: Rsort\n\n" );
8483   if ( (orig_x = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
8484     printf("ERROR: realloc failed \n\n" );
8485   if ( (orig_y = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
8486     printf("ERROR: realloc failed \n\n" );
8487   if ( (orig_z = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
8488     printf("ERROR: realloc failed \n\n" );
8489   if ( (sort_x = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
8490     printf("ERROR: realloc failed \n\n" );
8491   if ( (sort_y = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
8492     printf("ERROR: realloc failed \n\n" );
8493   if ( (sort_z = (double *)malloc( (sum_tri+1) * sizeof(double))) == NULL )
8494     printf("ERROR: realloc failed \n\n" );
8495   if ( (sort_nx = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
8496     printf("ERROR: realloc failed \n\n" );
8497   if ( (sort_ny = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
8498     printf("ERROR: realloc failed \n\n" );
8499   if ( (sort_nz = (int *)malloc( (sum_tri+1) * sizeof(int))) == NULL )
8500     printf("ERROR: realloc failed \n\n" );
8501   if( compare( action, "rot", 3) != 3)
8502   {
8503   for(i=0; i<sum_tri; i++)
8504   {
8505     rsort[i].r=orig_x[i]=tri[i].cg[0];
8506     rsort[i].i=i;
8507   }
8508   qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
8509   for(i=0; i<sum_tri; i++)
8510   {
8511     sort_x[i]=rsort[i].r;
8512     sort_nx[i]=rsort[i].i;
8513   }
8514   for(i=0; i<sum_tri; i++)
8515   {
8516     rsort[i].r=orig_y[i]=tri[i].cg[1];
8517     rsort[i].i=i;
8518   }
8519   qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
8520   for(i=0; i<sum_tri; i++)
8521   {
8522     sort_y[i]=rsort[i].r;
8523     sort_ny[i]=rsort[i].i;
8524   }
8525   for(i=0; i<sum_tri; i++)
8526   {
8527     rsort[i].r=orig_z[i]=tri[i].cg[2];
8528     rsort[i].i=i;
8529   }
8530   qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
8531   for(i=0; i<sum_tri; i++)
8532   {
8533     sort_z[i]=rsort[i].r;
8534     sort_nz[i]=rsort[i].i;
8535   }
8536   }
8537 
8538   /* project the nodes and points */
8539   if(getSetNr(specialset->noprj)>-1) delSet(specialset->noprj);
8540   if( compare( action, "rad", 3) == 3)
8541   {
8542     offset=0.;
8543     mindistini=MAX_FLOAT;
8544     length = sscanf( record,"%*s %*s %*s %c %lf %lf", &axis, &offset, &mindistini );
8545 
8546     /* target needs lines or triangles */
8547     if( sum_tri == 0)
8548     {
8549       if( set[trgtNr].anz_l > 0)
8550       {
8551         surfFlag=0;
8552         for (j=0; j<set[trgtNr].anz_l; j++) repLine(set[trgtNr].line[j]);
8553       }
8554       else
8555       {
8556         errMsg(" ERROR: Set (%s) does not have lines, surfaces or a triangle-mesh\n", targetname );
8557         return;
8558       }
8559     }
8560     else
8561     {
8562       surfFlag=1;
8563     }
8564 
8565     for (i=0; i<sum_pproj; i++)
8566     {
8567       /* the original coordinates must be used for radial projection to get the correct axis */
8568       pr[0]=pproj[i].px;
8569       pr[1]=pproj[i].py;
8570       pr[2]=pproj[i].pz;
8571 
8572       /* move the point to the line of nodes or to the surface */
8573       if( surfFlag)
8574       {
8575         /* The embedded triangles of the surfaces are used as a target for the projection */
8576         /* determine the position where the radial-ray through the point meets the triangles */
8577         /* and determine if the position is inside the triangle */
8578 
8579         if( axis=='x')
8580         {
8581           vproj[0]=0.;
8582           vproj[1]=pr[1];
8583           vproj[2]=pr[2];
8584 	}
8585         if( axis=='y')
8586         {
8587           vproj[0]=pr[0];
8588           vproj[1]=0.;
8589           vproj[2]=pr[2];
8590 	}
8591         if( axis=='z')
8592         {
8593           vproj[0]=pr[0];
8594           vproj[1]=pr[1];
8595           vproj[2]=0.;
8596 	}
8597 
8598         counter=0;
8599         do
8600         {
8601           counter++;
8602           curr_n_closest_tri=n_closest_tri*pow(2,counter-PROJ_LOOPS);
8603           if(curr_n_closest_tri<10) { curr_n_closest_tri=10; if(curr_n_closest_tri>n_closest_tri) curr_n_closest_tri=n_closest_tri; }
8604 
8605           /* find the closest tri */
8606           near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, pr[0], pr[1], pr[2],
8607                 sum_tri, &near_tri[0], curr_n_closest_tri);
8608           /*
8609           printf("n_closest_tri:%d\n", n_closest_tri);
8610           for(j=0; j<10; j++)
8611           {
8612             n=near_tri[j];
8613             printf("tri n:%d fnr:%d %f %f %f\n", n, tri[n].fnr, tri[n].cg[0], tri[n].cg[1] , tri[n].cg[2]);
8614             printf("dist: %f %f %f\n", tri[n].cg[0]-pr[0], tri[n].cg[1]-pr[1], tri[n].cg[2]-pr[2]);
8615             printf("dist: %f\n", sqrt((tri[n].cg[0]-pr[0])*(tri[n].cg[0]-pr[0])+ (tri[n].cg[1]-pr[1])*(tri[n].cg[1]-pr[1])+ (tri[n].cg[2]-pr[2])*(tri[n].cg[2]-pr[2])));
8616           }
8617           */
8618 
8619           /* check the closest tri for a split-point */
8620           dist=MAX_FLOAT; minj=-1; mindist=mindistini; triScale=1.;
8621           do
8622           {
8623             for(j=0; j<curr_n_closest_tri; j++)
8624             {
8625               n=near_tri[j];
8626               dist=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pr, vproj, triScale, &orient);
8627               if(( dist != OUTSIDE )&&(abs(dist)<abs(mindist)))
8628               {
8629                 if(printFlag) printf("counter:%d found enclosing tri3:%d for point:%s, distance:%lf %lf\n", counter, n, pproj[i].name, dist, mindist);
8630                 mindist=dist;
8631                 minj=j;
8632               }
8633             }
8634             if( minj!=-1 ) break;
8635             else triScale+=0.1;
8636           }while(triScale<=PROJ_BIAS);
8637 
8638           if( minj!=-1 )
8639           {
8640             j=minj;
8641             n=near_tri[j];
8642             dist=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pr, vproj, triScale, &orient);
8643             /* berechne den Gradeneinheitsvektor en */
8644             v_norm( vproj, pc );
8645             pr[0]+=pc[0]*(dist+offset);
8646             pr[1]+=pc[1]*(dist+offset);
8647             pr[2]+=pc[2]*(dist+offset);
8648           }
8649 	  //}while( ((dist == OUTSIDE) || (dist>gtol))&&(counter<PROJ_LOOPS));
8650 	}while( (dist == OUTSIDE)&&(counter<PROJ_LOOPS));
8651 
8652         if(minj!=-1 )
8653         {
8654         // printf(" found enclosing tri3[%d] for point:%s, distance:%lf triScale:%f break at j=%d  loop:%d\n", n, pproj[i].name, dist, triScale,minj, counter);
8655         }
8656         else
8657         {
8658           if(pproj[i].nn>-1) { printf("WARNING: no enclosing element for point:%s found\n", pproj[i].name ); pre_seta(specialset->noprj, "p",pproj[i].name ); }
8659           else               { printf("WARNING: no enclosing element for node:%s found\n", pproj[i].name );  pre_seta(specialset->noprj, "n",pproj[i].name ); }
8660           goto nextpoint;
8661         }
8662       }
8663       else
8664       {
8665         /* Internal points of the target-lines are used as a target for the projection */
8666 
8667         /* count the internal points */
8668         for (j=0; j<set[trgtNr].anz_l; j++)
8669         {
8670           anz_n+=line[set[trgtNr].line[j]].nip;
8671 	}
8672 	anz_n/=3;
8673 
8674         if ( (nx = (double *)malloc( (anz_n+1) * sizeof(double))) == NULL )
8675         {  errMsg("\n\n ERROR: malloc failed in pre_proj()\n") ; free_proj(nx, nrad, nmissed); return; }
8676         if ( (nrad = (double *)malloc( (anz_n+1) * sizeof(double))) == NULL )
8677         {  errMsg("\n\n ERROR: malloc failed in pre_proj()\n") ; free_proj(nx, nrad, nmissed); return; }
8678 
8679         if( axis=='x') j=0;
8680         else if( axis=='y') j=1;
8681         else if( axis=='z') j=2;
8682         else {  errMsg("\n\n ERROR: axis unknown in pre_proj()\n") ; free_proj(nx, nrad, nmissed); return; };
8683         if( v_rec2cyl( pr, j, csys, pc) <0) goto nextpoint;
8684 
8685         /* move the point to the target-line */
8686         e=0;
8687         for (j=0; j<set[trgtNr].anz_l; j++)
8688         {
8689           for (n=0; n<line[set[trgtNr].line[j]].nip; n+=3)
8690           {
8691             nr[0]=line[set[trgtNr].line[j]].ip[n]*scale->w+scale->x;
8692             nr[1]=line[set[trgtNr].line[j]].ip[n+1]*scale->w+scale->y;
8693             nr[2]=line[set[trgtNr].line[j]].ip[n+2]*scale->w+scale->z;
8694             nx[e]=nr[csys[0]];
8695             nrad[e++]=sqrt(nr[csys[1]]*nr[csys[1]]+nr[csys[2]]*nr[csys[2]]);
8696 	    //printf(" target-line %f %f\n", nx[e-1], nrad[e-1]);
8697           }
8698         }
8699         //printf("move the point to the target-line\n");
8700         mode=INTPOLMODE;
8701         pc[0]=intpol2( nx, nrad, e, pc[2], &mode )+offset;
8702 
8703 	//printf(" csys %d %d %d\n", csys[0], csys[1],csys[2]);
8704         pr[csys[0]]=pc[2];
8705         pr[csys[1]]=cos(pc[1])*pc[0];
8706         pr[csys[2]]=sin(pc[1])*pc[0];
8707       }
8708 
8709       if(functionFlag)
8710       {
8711         /* redefine the point */
8712         pproj[i].px= pr[0];
8713         pproj[i].py= pr[1];
8714         pproj[i].pz= pr[2];
8715       }
8716       else
8717       {
8718         v_result(&pproj[i].px, pr, p1p2);
8719 	//printf(" pp %f %f %f\n", pproj[i].px,pproj[i].py,pproj[i].pz);
8720 	//printf(" pr %f %f %f\n", pr[0], pr[1],pr[2]);
8721 
8722         dist=v_betrag(p1p2);
8723         // since the distance should be given as distance from target:
8724         if(v_betrag(pr)>v_betrag(&pproj[i].px)) dist*=-1;
8725         if(dist>dist_max) dist_max=dist;
8726         if(dist<dist_min) dist_min=dist;
8727         sum_dist+=dist;
8728         ndist++;
8729         //if(printFlag) printf("dist:%f av:%f ndist:%d max:%f min:%f\n", dist, sum_dist/ndist, ndist, dist_max, dist_min);
8730       }
8731 
8732     nextpoint:;
8733     }
8734   }
8735   else if( compare( action, "rot", 3) == 3)
8736   {
8737     offset=0.;
8738     mindistini=MAX_FLOAT;
8739     length = sscanf( record, "%*s%*s%*s%s%s%lf%lf", pkt1, pkt2, &offset, &mindistini );
8740 
8741     p1[0] = 0.;
8742     p1[1] = 0.;
8743     p1[2] = 0.;
8744     p2[0] = 0.;
8745     p2[1] = 0.;
8746     p2[2] = 0.;
8747 
8748     if(!length)
8749     {
8750       errMsg(" ERROR: not enough parameter specified\n");
8751       return;
8752     }
8753     else if(length==1)
8754     {
8755       if(pkt1[0]=='x')   p2[0] = 1.;
8756       else if(pkt1[0]=='y')   p2[1] = 1.;
8757       else if(pkt1[0]=='z')   p2[2] = 1.;
8758       else
8759       {
8760         errMsg(" Axis:%s is undefined\n", pkt1 );
8761         return;
8762       }
8763       offset=0.;
8764     }
8765     else if(length>=2)
8766     {
8767       pnr1=getPntNr( pkt1 );
8768       pnr2=getPntNr( pkt2 );
8769       if(pnr2<0)
8770       {
8771         if(pkt1[0]=='x')   p2[0] = 1.;
8772         else if(pkt1[0]=='y')   p2[1] = 1.;
8773         else if(pkt1[0]=='z')   p2[2] = 1.;
8774         else
8775         {
8776           errMsg(" Axis:%s is undefined\n", pkt1 );
8777           return;
8778         }
8779         offset=atof(pkt2);
8780       }
8781       else
8782       {
8783         p1[0] = point[pnr1].px*scale->w+scale->x;
8784         p1[1] = point[pnr1].py*scale->w+scale->y;
8785         p1[2] = point[pnr1].pz*scale->w+scale->z;
8786 
8787         p2[0] = point[pnr2].px*scale->w+scale->x;
8788         p2[1] = point[pnr2].py*scale->w+scale->y;
8789         p2[2] = point[pnr2].pz*scale->w+scale->z;
8790       }
8791     }
8792     if(offset!=0)
8793     {
8794       printf("\n WARNING option offset not implemented so far. offset:%lf ignored.\n\n",offset);
8795     }
8796 
8797     /* The embedded triangles are used as a target for the projection */
8798 
8799     /* berechnung der Einheitsvektoren des Verdreh-Koordinatensystems */
8800     /* Exneu = p1p2/|p1p2| ist der Einheitsvektor in xneu richtung    */
8801     /* Eyneu = p1p2 X p1ph / |p1p2 X p1ph|     in yneu                */
8802     /* Ezneu = Exneu X Eyneu                   in zneu                */
8803 
8804     v_result( p1, p2, p1p2 );
8805     v_norm  ( p1p2, el );
8806 
8807     /* erzeuge einen Hilfspunkt der nicht auf der el-achse liegt  */
8808     ph[1] = p1p2[0];
8809     ph[2] = p1p2[1];
8810     ph[0] = p1p2[2];
8811 
8812     /* konstuiere damit den 2. einheitsvektor eh  */
8813     v_result( p1, ph, p1ph );
8814     v_prod( p1p2, p1ph, ph );
8815     v_norm (ph, eh);
8816 
8817     /* und der dritte: eq  */
8818     v_prod( p1p2, ph, ex );
8819     v_norm (ex, eq);
8820 
8821     /* berechnung der lhq-koordinaten der xyz einheitsvektoren durch zykl.vertausch.  */
8822     ex[0]=el[0];
8823     ex[1]=eh[0];
8824     ex[2]=eq[0];
8825 
8826     ey[0]=el[1];
8827     ey[1]=eh[1];
8828     ey[2]=eq[1];
8829 
8830     ez[0]=el[2];
8831     ez[1]=eh[2];
8832     ez[2]=eq[2];
8833 
8834     /* Berechnung der lhq-koordinaten des Startpunktes der Drehachse (pnr1 ist der 0-Punkt des lhq systems) */
8835     x=p1[0];
8836     y=p1[1];
8837     z=p1[2];
8838 
8839     l_offs=ex[0]*x+ey[0]*y+ez[0]*z;
8840     h_offs=ex[1]*x+ey[1]*y+ez[1]*z;
8841     q_offs=ex[2]*x+ey[2]*y+ez[2]*z;
8842     /*
8843     printf("el:%lf %lf %lf eh:%lf %lf %lf eq:%lf %lf %lf\n", el[0],el[1],el[2], eh[0],eh[1],eh[2], eq[0],eq[1],eq[2]);
8844     printf("ex:%lf %lf %lf ey:%lf %lf %lf ez:%lf %lf %lf\n", ex[0],ex[1],ex[2], ey[0],ey[1],ey[2], ez[0],ez[1],ez[2]);
8845     printf("xyz p1:%lf %lf %lf\n", x,y,z);
8846     printf("lhq p1:%lf %lf %lf\n", l_offs, h_offs, q_offs);
8847     */
8848 
8849     /* umrechnen der tri schwerpunkte auf lhq cylsys */
8850     for(i=0; i<sum_tri; i++)
8851     {
8852       x=tri[i].cg[0];
8853       y=tri[i].cg[1];
8854       z=tri[i].cg[2];
8855       l=( ex[0]*x+ey[0]*y+ez[0]*z ) - l_offs ;   /* l (drehachse) */
8856       h=( ex[1]*x+ey[1]*y+ez[1]*z ) - h_offs ;   /* h */
8857       q=( ex[2]*x+ey[2]*y+ez[2]*z ) - q_offs ;   /* q */
8858       tri[i].cg[0]=sqrt(h*h+q*q);
8859       tri[i].cg[1]=p_angle(h,q);
8860       tri[i].cg[2]=l;
8861     }
8862     for(i=0; i<sum_tri; i++)
8863     {
8864       rsort[i].r=orig_x[i]=tri[i].cg[0];
8865       rsort[i].i=i;
8866     }
8867     qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
8868     for(i=0; i<sum_tri; i++)
8869     {
8870       sort_x[i]=rsort[i].r;
8871       sort_nx[i]=rsort[i].i;
8872     }
8873     for(i=0; i<sum_tri; i++)
8874     {
8875       rsort[i].r=orig_y[i]=tri[i].cg[1];
8876       rsort[i].i=i;
8877     }
8878     qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
8879     for(i=0; i<sum_tri; i++)
8880     {
8881       sort_y[i]=rsort[i].r;
8882       sort_ny[i]=rsort[i].i;
8883     }
8884     for(i=0; i<sum_tri; i++)
8885     {
8886       rsort[i].r=orig_z[i]=tri[i].cg[2];
8887       rsort[i].i=i;
8888     }
8889     qsort( rsort, sum_tri, sizeof(Rsort), (void *)compareRsort );
8890     for(i=0; i<sum_tri; i++)
8891     {
8892       sort_z[i]=rsort[i].r;
8893       sort_nz[i]=rsort[i].i;
8894     }
8895 
8896     /* Berechnung der lhq-koordinaten aller zu drehenden punkte */
8897     for (i=0; i<sum_pproj; i++)
8898     {
8899       x=pproj[i].px;
8900       y=pproj[i].py;
8901       z=pproj[i].pz;
8902 
8903       ppt[0]=pp[0]=l=( ex[0]*x+ey[0]*y+ez[0]*z ) - l_offs ;   /* l (drehachse) */
8904       pp[1]=h=( ex[1]*x+ey[1]*y+ez[1]*z ) - h_offs ;   /* h */
8905       pp[2]=q=( ex[2]*x+ey[2]*y+ez[2]*z ) - q_offs ;   /* q */
8906       r=sqrt(h*h+q*q);
8907       fi=p_angle(h,q);
8908 
8909       /* define a cutting plane pa by 3 points ( pa1,pa2,pa3) in the lhq system */
8910       pa1[0]=l;  /* Attention: =l is not a 1 ('one'), its an lowercase 'L' */
8911       pa1[1]=0.;
8912       pa1[2]=0.;
8913       pa2[0]=l;
8914       pa2[1]=1.;
8915       pa2[2]=0.;
8916       pa3[0]=l;
8917       pa3[1]=0.;
8918       pa3[2]=1.;
8919 
8920       counter=0;
8921       do
8922       {
8923         counter++;
8924         curr_n_closest_tri=n_closest_tri*pow(2,counter-PROJ_LOOPS);
8925         if(curr_n_closest_tri<10) { curr_n_closest_tri=10; if(curr_n_closest_tri>n_closest_tri) curr_n_closest_tri=n_closest_tri; }
8926 
8927         /* find the closest tri */
8928         near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, r,fi,l, sum_tri, &near_tri[0], curr_n_closest_tri);
8929 
8930         /* check the closest tri for a split-point */
8931         for(j=0; j<curr_n_closest_tri; j++)
8932         {
8933           n=near_tri[j];
8934           x=tri[n].p1[0];
8935           y=tri[n].p1[1];
8936           z=tri[n].p1[2];
8937           pt1[0]=( ex[0]*x+ey[0]*y+ez[0]*z ) - l_offs ;    /* l */
8938           pt1[1]=( ex[1]*x+ey[1]*y+ez[1]*z ) - h_offs ;    /* h */
8939           pt1[2]=( ex[2]*x+ey[2]*y+ez[2]*z ) - q_offs ;    /* q */
8940 
8941           x=tri[n].p2[0];
8942           y=tri[n].p2[1];
8943           z=tri[n].p2[2];
8944           pt2[0]=( ex[0]*x+ey[0]*y+ez[0]*z ) - l_offs ;    /* l */
8945           pt2[1]=( ex[1]*x+ey[1]*y+ez[1]*z ) - h_offs ;    /* h */
8946           pt2[2]=( ex[2]*x+ey[2]*y+ez[2]*z ) - q_offs ;    /* q */
8947 
8948           x=tri[n].p3[0];
8949           y=tri[n].p3[1];
8950           z=tri[n].p3[2];
8951           pt3[0]=( ex[0]*x+ey[0]*y+ez[0]*z ) - l_offs ;    /* l */
8952           pt3[1]=( ex[1]*x+ey[1]*y+ez[1]*z ) - h_offs ;    /* h */
8953           pt3[2]=( ex[2]*x+ey[2]*y+ez[2]*z ) - q_offs ;    /* q */
8954 
8955           dist=OUTSIDE;
8956           if( AsplitA( pa1, pa2, pa3, pt1, pt2, pt3, ps1, ps2) >0 )
8957           {
8958             /* check if the projected point is on that element */
8959             /*
8960   	  printf("pnt pp: %lf %lf %lf\n",l,h,q);
8961   	  printf("pnt ps1: %lf %lf %lf\n",ps1[0],ps1[1],ps1[2]);
8962   	  printf("pnt ps2: %lf %lf %lf\n",ps2[0],ps2[1],ps2[2]);
8963   	  printf("pnt pa1: %lf %lf %lf\n",pa1[0],pa1[1],pa1[2]);
8964   	  printf("pnt pa2: %lf %lf %lf\n",pa2[0],pa2[1],pa2[2]);
8965   	  printf("pnt pa3: %lf %lf %lf\n",pa3[0],pa3[1],pa3[2]);
8966   	  printf("pnt pt1: %lf %lf %lf\n",pt1[0],pt1[1],pt1[2] );
8967   	  printf("pnt pt2: %lf %lf %lf\n",pt2[0],pt2[1],pt2[2] );
8968   	  printf("pnt pt3: %lf %lf %lf\n",pt3[0],pt3[1],pt3[2] );
8969             */
8970 
8971             v_result(ps1,ps2,e1);
8972             rp=v_norm( e1, e1 );
8973             /* check if ps1==ps2 then no intersection line could be determined and no projection is possible */
8974             if(rp>1.e-10)
8975   	    {
8976               pval=2*(ps1[1]*e1[1]+ps1[2]*e1[2])/(e1[1]*e1[1]+e1[2]*e1[2]);
8977               qval=ps1[1]*ps1[1]+ps1[2]*ps1[2]-pp[1]*pp[1]-pp[2]*pp[2];
8978               divpq=pval*pval*0.25-qval;
8979               if(divpq>=0.)
8980   	      {
8981                 if(printFlag) printf(" found enclosing tri3 for point:%s\n", pproj[i].name);
8982 
8983                 /* new h and q values  */
8984                 scal_e[0]=-pval*0.5 +sqrt(divpq);
8985                 scal_e[1]=-pval*0.5 -sqrt(divpq);
8986                 //printf("p:%f q:%f scal:%f scal:%f\n", pval, qval, scal_e[0], scal_e[1]);
8987                 v_scal(&scal_e[0], e1, p1);
8988                 v_add(ps1,p1, p1);
8989                 v_scal(&scal_e[1], e1, p2);
8990                 v_add(ps1,p2, p2);
8991               /*
8992                 printf("pnt e1: %lf %lf %lf\n",e1[0],e1[1],e1[2] );
8993                 printf("pnt pc1: %lf %lf %lf\n",p1[0],p1[1],p1[2] );
8994                 printf("pnt pc2: %lf %lf %lf\n",p2[0],p2[1],p2[2] );
8995               */
8996                 /* check which solution gives the smallest correction */
8997                 v_result(pp,p1,v1);
8998                 v_result(pp,p2,v2);
8999                 //printf("v1:%f v2:%f\n",v_betrag(v1),v_betrag(v2));
9000                 bv1=v_betrag(v1);
9001                 bv2=v_betrag(v2);
9002 
9003                 if(bv1<bv2)
9004                 {
9005                   dist=bv1;
9006                   h=p1[1];
9007                   q=p1[2];
9008                 }
9009                 else
9010                 {
9011                   dist=bv2;
9012                   h=p2[1];
9013                   q=p2[2];
9014                 }
9015                 /* check if the projected point is inside the tri */
9016                 ppt[1]=h;
9017                 ppt[2]=q;
9018                 if(check_tri3(ppt,pt1,pt2,pt3,1)==MAX_INTEGER) dist=OUTSIDE;
9019                 else if(abs(dist)<abs(mindistini)) goto foundTri3rot;
9020               }
9021             }
9022           }
9023         }
9024 	//}while( ((dist == OUTSIDE) || (dist>gtol))&&(counter<PROJ_LOOPS));
9025       }while( (dist == OUTSIDE)&&(counter<PROJ_LOOPS));
9026       if(pproj[i].nn>-1)
9027       { printf("WARNING: no enclosing element for point:%s found\n", pproj[i].name ); pre_seta(specialset->noprj, "p",pproj[i].name ); }
9028       else
9029       { printf("WARNING: no enclosing element for node:%s found\n", pproj[i].name );  pre_seta(specialset->noprj, "n",pproj[i].name ); }
9030       goto nextpointrot;
9031      foundTri3rot:;
9032 
9033       lhq[0]=l;
9034       lhq[1]=h;
9035       lhq[2]=q;
9036       l+= l_offs;
9037       h+= h_offs;
9038       q+= q_offs;
9039 
9040       x=el[0]*l+eh[0]*h+eq[0]*q;
9041       y=el[1]*l+eh[1]*h+eq[1]*q;
9042       z=el[2]*l+eh[2]*h+eq[2]*q;
9043 
9044       if(functionFlag)
9045       {
9046         /* redefine the point */
9047         pproj[i].px=  x;
9048         pproj[i].py=  y;
9049         pproj[i].pz=  z;
9050       }
9051       else
9052       {
9053         pp[0]=lhq[0]=0.;
9054 	angle=v_angle(pp,lhq);
9055 
9056         // generate a signum by try and error
9057         h=lhq[1]*cos(-angle)-lhq[2]*sin(-angle);
9058         q=lhq[1]*sin(-angle)+lhq[2]*cos(-angle);
9059         if((abs(h-pp[1])>1.e-6)||(abs(q-pp[2])>1.e-6)) angle*=-1.;
9060         dist=angle*180./PI;
9061         // since the distance should be given as distance from target:
9062         dist*=-1;
9063         if(dist>dist_max) dist_max=dist;
9064         if(dist<dist_min) dist_min=dist;
9065         sum_dist+=dist;
9066         ndist++;
9067 	if(printFlag) printf("dist:%f av:%f ndist:%d max:%f min:%f\n", dist, sum_dist/ndist, ndist, dist_max, dist_min);
9068       }
9069      nextpointrot:;
9070     }
9071   }
9072   else if(( compare( action, "tra", 3) == 3)||( compare( action, "nor", 3) == 3))
9073   {
9074     offset=0.;
9075     mindistini=MAX_FLOAT;
9076     if( compare( action, "tra", 3) == 3)
9077       length = sscanf( record,"%*s %*s %*s %lf %lf %lf %lf %lf", &vproj[0], &vproj[1], &vproj[2], &offset, &mindistini );
9078     else
9079     {
9080       length = sscanf( record,"%*s %*s %*s %lf %lf", &offset, &mindistini);
9081       normFlag=1;
9082     }
9083 
9084     /* The embedded triangles are the surfaces which are used as a target for the projection */
9085     for (i=0; i<sum_pproj; i++)
9086     {
9087       pr[0]=pproj[i].px;
9088       pr[1]=pproj[i].py;
9089       pr[2]=pproj[i].pz;
9090 
9091       counter=0;
9092       do
9093       {
9094         counter++;
9095         curr_n_closest_tri=n_closest_tri*pow(2,counter-PROJ_LOOPS);
9096         if(curr_n_closest_tri<10) { curr_n_closest_tri=10; if(curr_n_closest_tri>n_closest_tri) curr_n_closest_tri=n_closest_tri; }
9097 
9098         /* find the closest tri */
9099         near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, pr[0], pr[1], pr[2],
9100               sum_tri, &near_tri[0], curr_n_closest_tri);
9101         /*
9102         printf("n_closest_tri:%d\n", n_closest_tri);
9103         for(j=0; j<10; j++)
9104         {
9105           n=near_tri[j];
9106           printf("tri n:%d fnr:%d %f %f %f\n", n, tri[n].fnr, tri[n].cg[0], tri[n].cg[1] , tri[n].cg[2]);
9107           printf("dist: %f %f %f\n", tri[n].cg[0]-pr[0], tri[n].cg[1]-pr[1], tri[n].cg[2]-pr[2]);
9108           printf("dist: %f\n", sqrt((tri[n].cg[0]-pr[0])*(tri[n].cg[0]-pr[0])+ (tri[n].cg[1]-pr[1])*(tri[n].cg[1]-pr[1])+ (tri[n].cg[2]-pr[2])*(tri[n].cg[2]-pr[2])));
9109         }
9110         */
9111 
9112         /* check the closest tri for a split-point */
9113         dist=MAX_FLOAT; minj=-1;mindist=mindistini; triScale=1.;
9114         do
9115         {
9116           for(j=0; j<curr_n_closest_tri; j++)
9117           {
9118             n=near_tri[j];
9119             if(normFlag)
9120    	    {
9121               v_result( tri[n].p1, tri[n].p2, v1);
9122               v_result( tri[n].p1, tri[n].p3, v2);
9123               v_prod( v1, v2, vproj );
9124    	    }
9125             dist=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pr, vproj, triScale, &orient);
9126             //printf(" tri3:%d for point:%s dist:%f mindist:%f triScale:%f\n", n, pproj[i].name, dist, mindist, triScale);
9127             if(( dist != OUTSIDE )&&(abs(dist)<abs(mindist)))
9128             {
9129               if(printFlag) printf("counter:%d found enclosing tri3:%d for point:%s, distance:%lf %lf\n", counter, n, pproj[i].name, dist, mindist);
9130               mindist=dist;
9131               minj=j;
9132             }
9133           }
9134           if( minj!=-1 ) break;
9135           else triScale+=0.1;
9136         }while(triScale<=PROJ_BIAS);
9137 
9138         if( minj!=-1 )
9139         {
9140           j=minj;
9141           n=near_tri[j];
9142           if(normFlag)
9143   	  {
9144             v_result( tri[n].p1, tri[n].p2, v1);
9145             v_result( tri[n].p1, tri[n].p3, v2);
9146             v_prod( v1, v2, vproj );
9147   	  }
9148           dist=v_distA(  tri[n].p1, tri[n].p2, tri[n].p3, pr, vproj, triScale, &orient);
9149         }
9150 	//}while( ((dist == OUTSIDE) || (dist>gtol))&&(counter<PROJ_LOOPS));
9151       }while( (dist == OUTSIDE)&&(counter<PROJ_LOOPS));
9152 
9153       if(minj!=-1 )
9154       {
9155         // printf(" found enclosing tri3[%d] for point:%s, distance:%lf triScale:%f break at j=%d  loop:%d\n", n, pproj[i].name, dist, triScale,minj, counter);
9156         if(functionFlag)
9157 	{
9158           /* berechne den Gradeneinheitsvektoren */
9159           v_norm( vproj, pc );
9160           pr[0]+=pc[0]*(dist+offset);
9161           pr[1]+=pc[1]*(dist+offset);
9162           pr[2]+=pc[2]*(dist+offset);
9163 
9164           /* redefine the point */
9165           pproj[i].px= pr[0];
9166           pproj[i].py= pr[1];
9167           pproj[i].pz= pr[2];
9168 	}
9169         else
9170 	{
9171           /* berechne den Gradeneinheitsvektoren */
9172           /*
9173           v_norm( vproj, pc );
9174           pr[0]=pc[0]*(dist+offset);
9175           pr[1]=pc[1]*(dist+offset);
9176           pr[2]=pc[2]*(dist+offset);
9177           dist=v_betrag(pr);
9178 	  */
9179           // instead keep the sign:
9180           dist=dist-offset;
9181           // since the distance should be given as distance from target:
9182           dist*=-1;
9183           if(dist>dist_max) dist_max=dist;
9184           if(dist<dist_min) dist_min=dist;
9185           sum_dist+=dist;
9186           ndist++;
9187 	  if(printFlag) printf("dist:%f av:%f ndist:%d max:%f min:%f\n", dist, sum_dist/ndist, ndist, dist_max, dist_min);
9188 	}
9189       }
9190       else
9191       {
9192         if(pproj[i].nn>-1) { printf("WARNING: no enclosing element for point:%s found\n", pproj[i].name ); pre_seta(specialset->noprj, "p",pproj[i].name ); }
9193         else               { printf("WARNING: no enclosing element for node:%s found\n", pproj[i].name );  pre_seta(specialset->noprj, "n",pproj[i].name ); }
9194       }
9195     }
9196   }
9197   else
9198   {
9199     errMsg(" ERROR: transformation:%s not known\n", action);
9200     return;
9201   }
9202 
9203   /* map the results to the original entities */
9204   if(functionFlag) for (i=0; i<sum_pproj; i++)
9205   {
9206     if(pproj[i].nn>-1)
9207     {
9208       p=pproj[i].nn;
9209       point[p].px=(pproj[i].px-scale->x)/scale->w;
9210       point[p].py=(pproj[i].py-scale->y)/scale->w;
9211       point[p].pz=(pproj[i].pz-scale->z)/scale->w;
9212     }
9213     else
9214     {
9215       n=-pproj[i].nn;
9216       node[n].nx=(pproj[i].px-scale->x)/scale->w;
9217       node[n].ny=(pproj[i].py-scale->y)/scale->w;
9218       node[n].nz=(pproj[i].pz-scale->z)/scale->w;
9219     }
9220   }
9221   free(pproj);
9222   free(tri);
9223   free(rsort);
9224   if(sum_tri) free(near_tri);
9225   if(orig_x) free(orig_x);
9226   if(orig_y) free(orig_y);
9227   if(orig_z) free(orig_z);
9228   if(sort_x) free(sort_x);
9229   if(sort_y) free(sort_y);
9230   if(sort_z) free(sort_z);
9231   if(sort_nx) free(sort_nx);
9232   if(sort_ny) free(sort_ny);
9233   if(sort_nz) free(sort_nz);
9234 
9235   if(getSetNr(specialset->noprj)>-1)
9236   {
9237     printf("WARNING: check set:%s for failed entities\n", specialset->noprj);
9238     if(( compare( action, "nor", 3) == 3)&&(set[trgtNr].anz_sh))
9239     {
9240       /* at last project normal onto the referenced nurbs-surfaces */
9241 
9242       printf("  trying to project failed entities to nurbs-shapes (successfull proj not removed from %s)\n", specialset->noprj);
9243       setNr=getSetNr(specialset->noprj);
9244       for (i=0; i<set[trgtNr].anz_sh; i++)
9245       {
9246         if(shape[set[trgtNr].shp[i]].type==4)
9247           projSetToNurbs( shape[set[trgtNr].shp[i]].p[0], set, setNr, point);
9248       }
9249 
9250       if(getSetNr(specialset->zap)>-1) delSet(specialset->zap);
9251     }
9252   }
9253 
9254   if(!functionFlag)
9255   {
9256     printf("DIST:%f MAX:%f MIN:%f\n", sum_dist/ndist, dist_max, dist_min);
9257     free_proj(nx, nrad, nmissed);
9258 
9259     if(valuestackFlag)
9260     {
9261       if ((valuestack = (char **)realloc( (char **)valuestack, (valuestack_ptr+3)*sizeof(char *)) ) == NULL )
9262       { printf("\n\nERROR: realloc failure, valuestack\n\n"); return; }
9263       for(i=0; i<3; i++)
9264       {
9265         if ((valuestack[valuestack_ptr+i] = (char *)malloc( MAX_LINE_LENGTH*sizeof(char)) ) == NULL )
9266         { printf("\n\nERROR: realloc failure, valuestack\n\n"); return; }
9267       }
9268       sprintf(valuestack[valuestack_ptr++],"%f", dist_min );
9269       sprintf(valuestack[valuestack_ptr++],"%f", dist_max );
9270       sprintf(valuestack[valuestack_ptr++],"%f", sum_dist/ndist );
9271       printf(" in inverse order written to stack\n");
9272     }
9273     return;
9274   }
9275 
9276  skipTriProj:;
9277 
9278   /* dependent higher entities need new label-positions, achived with orient */
9279   /* create a set with the dependent higher entities to be oriented  */
9280 
9281   /* add all points to special set _ORI  */
9282   if(set[setNr].anz_p>0)
9283   {
9284     j=pre_seta( specialset->ori, "i", 0 );
9285     for (i=0; i<set[setNr].anz_p; i++)
9286     {
9287       p=set[setNr].pnt[i];
9288       seta( j, "p", p );
9289     }
9290     completeSet( specialset->ori, "up");
9291     orientSet( specialset->ori );
9292     delSet(specialset->ori);
9293   }
9294 
9295   /* recalculate the shapes (from command-interpreter "REP") */
9296   for (i=0; i<anzGeo->l; i++) repLine(i);
9297 
9298   /* fix midside-node positions */
9299   fixMidsideNodes(set[setNr].name, "");
9300 
9301   /* reposition the internal drawing nodes */
9302   if(anz->e>0)
9303   {
9304     adjustDrawNodes(0);
9305     //makeSurfaces(); instead:
9306     getFaceNormalen( face, node, anz );
9307     getElemNormalen( e_enqire, node, anz->e );
9308     updateDispLists();
9309   }
9310   free_proj(nx, nrad, nmissed);
9311 }
9312 
9313 
generateSetIndexes()9314 void  generateSetIndexes()
9315 {
9316   int i, index=1;
9317   for (i=0; i<anz->sets; i++)
9318   {
9319     if( set[i].name != (char *)NULL )
9320     {
9321       if (!set[i].type)
9322       {
9323         set[i].index=index++;
9324       }
9325     }
9326   }
9327 }
9328 
9329 
9330 /*------------------------------------------------------------------*/
9331 /* setinhalt schreiben                                              */
9332 /*------------------------------------------------------------------*/
9333 
prnt(char * record)9334 int prnt(char *record)
9335 {
9336   int   setNr, nr, p, l, nc,nl, args, nmin, emin;
9337   int i,j,k,n;
9338   int length, bias_fbd, foundSubString;
9339   char name[MAX_LINE_LENGTH], typ[MAX_LINE_LENGTH], param[MAX_LINE_LENGTH], **dat;
9340   char *str=NULL, *token=NULL, *saveptr=NULL;
9341   double r1[3], r2[3];
9342 
9343   typ[0]=param[0]=name[0]=0;
9344   length=sscanf(record,"%s%s%s",typ,name,param);
9345   if((length==2)&&(compareStrings(name, "*")>0)) length--;
9346 
9347   /* generate the set-indexes */
9348   generateSetIndexes();
9349 
9350   if ((compare( typ, "col", 3) == 3) ||(compare( typ, "COL", 3) == 3))
9351   {
9352     for(i=0; i<entitycols; i++)
9353     {
9354       printf("%d %s %f %f %f\n", i+1, entitycol[i].name, entitycol[i].r, entitycol[i].g, entitycol[i].b  );
9355     }
9356     return(1);
9357   }
9358   if ((compare( typ, "usr", 3) == 3) ||(compare( typ, "USR", 3) == 3))
9359   {
9360     if (!anz->u) printf(" no user headers defined\n");
9361     /* list all existing parameters */
9362     for (i=0; i<anz->u; i++)
9363     {
9364         if( anz->uheader[i] != (char *)NULL )
9365         {
9366           printf ("%s\n", &anz->uheader[i][6]);
9367           strcpy(parameter[0], &anz->uheader[i][6]);
9368           write2stack(1, parameter);
9369         }
9370     }
9371     return(1);
9372   }
9373   if ((compare( typ, "par", 3) == 3) ||(compare( typ, "PAR", 3) == 3))
9374   {
9375     if (!lcase[cur_lc].npheader) printf(" no parameters for active dataset:%d defined\n", cur_lc+1);
9376     if (length==1)
9377     {
9378       /* list all existing parameters */
9379       for (i=0; i<lcase[cur_lc].npheader; i++)
9380       {
9381         if( lcase[cur_lc].pheader[i] != (char *)NULL )
9382         {
9383           printf ("%s\n", &lcase[cur_lc].pheader[i][6]);
9384           strcpy(parameter[0], &lcase[cur_lc].pheader[i][6]);
9385           write2stack(1, parameter);
9386         }
9387       }
9388       return(1);
9389     }
9390     else
9391     {
9392       for (i=0; i<lcase[cur_lc].npheader; i++)
9393       {
9394         if( lcase[cur_lc].pheader[i] != (char *)NULL )
9395         {
9396           if(compare(&lcase[cur_lc].pheader[i][6],name,strlen(name))==strlen(name))
9397 	  {
9398             printf ("%s\n", &lcase[cur_lc].pheader[i][6]);
9399             strcpy(parameter[0], &lcase[cur_lc].pheader[i][6]);
9400             write2stack(1, parameter);
9401 	  }
9402         }
9403       }
9404       return(1);
9405     }
9406   }
9407 
9408   if ((compare( typ, "amp", 3) == 3) ||(compare( typ, "AMP", 3) == 3))
9409   {
9410     if (!anz->amps) printf(" no amplitudes defined\n");
9411     if (length==1)
9412     {
9413       /* list all existing amplitudes */
9414       for (i=0; i<anz->amps; i++)
9415       {
9416         if( amplitude[i].name != (char *)NULL )
9417         {
9418           printf ("%s xy-pairs:%d\n", amplitude[i].name, amplitude[i].n);
9419         }
9420       }
9421       return(1);
9422     }
9423     else
9424     {
9425       setNr=getAmplitudeNr(name,1);
9426       if (setNr<0)
9427       {
9428         /* amp was not found. check if wildcards (*) were used */
9429         length= strsplt( name, '*', &dat);
9430         if ((length>0)&&(strstr(name, "*") !=NULL))
9431 	{
9432           j=0;
9433           for(setNr=0; setNr<anz->amps; setNr++)
9434 	  {
9435             for(i=0; i<length; i++)
9436 	    {
9437               if(strstr(amplitude[setNr].name, dat[i]) !=NULL)
9438 	      {
9439                 if( amplitude[setNr].name != (char *)NULL )
9440                 {
9441                   printf ("%s xy-pairs:%d\n", amplitude[setNr].name, amplitude[setNr].n);
9442                 }
9443 	      }
9444 	    }
9445 	  }
9446           return(0);
9447 	}
9448         printf (" prnt: amplitude:'%s' does not exist\n", name);
9449         return (-1);
9450       }
9451     }
9452     printf ("i      x:            y:\n");
9453     for (i=0; i<amplitude[setNr].n; i++)
9454     {
9455       printf (" %8d %12e %12e\n", i+1, amplitude[setNr].x[i],amplitude[setNr].y[i]);
9456     }
9457   }
9458 
9459   if ((compare( typ, "mat", 3) == 3) ||(compare( typ, "MAT", 3) == 3))
9460   {
9461     if (!anz->mats) printf(" no materials defined\n");
9462     if (length==1)
9463     {
9464       /* list all existing materials */
9465       for (i=0; i<anz->mats; i++)
9466       {
9467         if( material[i].name != (char *)NULL )
9468         {
9469           printf ("%s elastic:%d expansion:%d conductivity:%d specific heat:%d plastic:%d\n", material[i].name, material[i].nela, material[i].nexp, material[i].ncon, material[i].nsph, material[i].npl);
9470         }
9471       }
9472       return(1);
9473     }
9474     else
9475     {
9476       setNr=getMatNr(name,1);
9477       if (setNr<0)
9478       {
9479         /* amp was not found. check if wildcards (*) were used */
9480         length= strsplt( name, '*', &dat);
9481         if ((length>0)&&(strstr(name, "*") !=NULL))
9482 	{
9483           j=0;
9484           for(setNr=0; setNr<anz->mats; setNr++)
9485 	  {
9486             for(i=0; i<length; i++)
9487 	    {
9488               if(strstr(material[setNr].name, dat[i]) !=NULL)
9489 	      {
9490                 if( material[setNr].name != (char *)NULL )
9491                 {
9492                   printf ("%s elastic:%d expansion:%d conductivity:%d specific heat:%d \n", material[setNr].name, material[setNr].nela, material[setNr].nexp, material[setNr].ncon, material[setNr].nsph);
9493                 }
9494 	      }
9495 	    }
9496 	  }
9497           return(0);
9498 	}
9499         printf (" prnt: material:'%s' does not exist\n", name);
9500         return(-1);
9501       }
9502     }
9503     printf ("density:%e\n", material[setNr].rho);
9504     printf ("\ni      elastic:      nue:      temperature:\n");
9505     for (i=0; i<material[setNr].nela; i++)
9506     {
9507       printf (" %8d %12e %12e %12e\n", i+1, material[setNr].ela[i],material[setNr].nue[i],material[setNr].tela[i]);
9508     }
9509     printf ("\ni      expansion:      temperature:\n");
9510     for (i=0; i<material[setNr].nexp; i++)
9511     {
9512       printf (" %8d %12e %12e\n", i+1, material[setNr].exp[i],material[setNr].texp[i]);
9513     }
9514     printf ("\ni      conductivity:      temperature:\n");
9515     for (i=0; i<material[setNr].ncon; i++)
9516     {
9517       printf (" %8d %12e %12e\n", i+1, material[setNr].con[i],material[setNr].tcon[i]);
9518     }
9519     printf ("\ni      sp. heat:      temperature:\n");
9520     for (i=0; i<material[setNr].nsph; i++)
9521     {
9522       printf (" %8d %12e %12e\n", i+1, material[setNr].sph[i],material[setNr].tsph[i]);
9523     }
9524     printf ("\ni      stress:      pl.strain:    temperature:\n");
9525     for (i=0; i<material[setNr].npl; i++)
9526     {
9527       printf (" %8d %12e %12e %12e\n", i+1, material[setNr].spl[i],material[setNr].epl[i],material[setNr].tpl[i]);
9528     }
9529   }
9530 
9531   if ((compare( typ, "st", 2) == 2) ||(compare( typ, "ST", 2) == 2))
9532   {
9533     if ((compare( name, "size", 2) == 2) ||(compare( name, "SIZE", 2) == 2))
9534     {
9535       printf ("%d\n",valuestack_ptr);
9536       sprintf(parameter[0], "%d", valuestack_ptr);
9537       write2stack(1, parameter);
9538     }
9539     else
9540     {
9541       i=valuestack_ptr-1;
9542       if(i<0) printf(" stack is empty\n");
9543       else
9544       {
9545         j=0;
9546         while(0<=i)
9547         {
9548           printf ("%d %s\n",++j,valuestack[i]); i--;
9549         }
9550       }
9551     }
9552   }
9553   else if ((compare( typ, "info", 2) == 2) ||(compare( typ, "INFO", 2) == 2))
9554   {
9555     if(anz->nmin == MAX_INTEGER) nmin=0; else nmin=anz->nmin;
9556     if(anz->emin == MAX_INTEGER) emin=0; else emin=anz->emin;
9557 
9558     printf ("%s %s  n:%d e:%d f:%d ed:%d t:%d se:%d mat:%d amp:%d ds:%d nmax:%d nmin:%d emax:%d emin:%d nnext:%d enext:%d mesh-threads:%d\n", datin, anz->model, set[0].anz_n, anz->e, anz->f, anz->g, anz->t, anz->sets, anz->mats, anz->amps, anz->l, anz->orignmax, nmin, anz->emax, emin, anz->nnext, anz->enext, anz->threads);
9559     printf ("p:%d l:%d c:%d s:%d b:%d sh:%d L:%d S:%d psets:%d\n",anzGeo->p, anzGeo->l, anzGeo->c, anzGeo->s, anzGeo->b, anzGeo->sh, anzGeo->nurl, anzGeo->nurs, anzGeo->psets);
9560     sprintf(parameter[0],"%s",datin);
9561     sprintf(parameter[1],"%s",anz->model);
9562     sprintf(parameter[2],"%d",set[0].anz_n);
9563     sprintf(parameter[3],"%d",anz->e);
9564     sprintf(parameter[4],"%d",anz->f);
9565     sprintf(parameter[5],"%d",anz->g);
9566     sprintf(parameter[6],"%d",anz->t);
9567     sprintf(parameter[7],"%d",anz->sets);
9568     sprintf(parameter[8],"%d",anz->mats);
9569     sprintf(parameter[9],"%d",anz->amps);
9570     sprintf(parameter[10],"%d",anz->l);
9571     sprintf(parameter[11],"%d",anz->orignmax);
9572     sprintf(parameter[12],"%d",nmin);
9573     sprintf(parameter[13],"%d",anz->emax);
9574     sprintf(parameter[14],"%d",emin);
9575     sprintf(parameter[15],"%d",anz->nnext);
9576     sprintf(parameter[16],"%d",anz->enext);
9577     sprintf(parameter[17],"%d",anz->threads);
9578     sprintf(parameter[18],"%d",anzGeo->p);
9579     sprintf(parameter[19],"%d",anzGeo->l);
9580     sprintf(parameter[20],"%d",anzGeo->c);
9581     sprintf(parameter[21],"%d",anzGeo->s);
9582     sprintf(parameter[22],"%d",anzGeo->b);
9583     sprintf(parameter[23],"%d",anzGeo->sh);
9584     sprintf(parameter[24],"%d",anzGeo->nurl);
9585     sprintf(parameter[25],"%d",anzGeo->nurs);
9586     sprintf(parameter[26],"%d",anzGeo->psets);
9587     write2stack( 27, parameter);
9588   }
9589   else if ((compare( typ, "se", 2) == 2) ||(compare( typ, "SE", 2) == 2))
9590   {
9591     if (!anz->sets)
9592     {
9593       printf("ERROR: no sets defined\n");
9594       strcpy(parameter[0], "ERROR: no sets defined");
9595       write2stack(1, parameter);
9596     }
9597     if (length==1)
9598     {
9599       /* list all existing sets */
9600       for (i=0; i<anz->sets; i++)
9601       {
9602         if( set[i].name != (char *)NULL )
9603         {
9604           if ((!set[i].type)&&(set[i].name[0]!=':'))
9605           {
9606             printf ("%-5d %s stat:%c n:%d e:%d f:%d p:%d l:%d c:%d s:%d b:%d L:%d S:%d se:%d sh:%d v:%d\n", set[i].index, set[i].name, set[i].flag, set[i].anz_n, set[i].anz_e, set[i].anz_f, set[i].anz_p, set[i].anz_l, set[i].anz_c, set[i].anz_s, set[i].anz_b, set[i].anz_nurl, set[i].anz_nurs, set[i].anz_se, set[i].anz_sh, set[i].anz_v);
9607             sprintf(parameter[0],"%d",set[i].index);
9608             sprintf(parameter[1],"%s",set[i].name);
9609             sprintf(parameter[2],"%c",set[i].flag);
9610             sprintf(parameter[3],"%d",set[i].anz_n);
9611             sprintf(parameter[4],"%d",set[i].anz_e);
9612             sprintf(parameter[5],"%d",set[i].anz_f);
9613             sprintf(parameter[6],"%d",set[i].anz_p);
9614             sprintf(parameter[7],"%d",set[i].anz_l);
9615             sprintf(parameter[8],"%d",set[i].anz_c);
9616             sprintf(parameter[9],"%d",set[i].anz_s);
9617             sprintf(parameter[10],"%d",set[i].anz_b);
9618             sprintf(parameter[11],"%d",set[i].anz_nurl);
9619             sprintf(parameter[12],"%d",set[i].anz_nurs);
9620             sprintf(parameter[13],"%d",set[i].anz_se);
9621             sprintf(parameter[14],"%d",set[i].anz_sh);
9622             sprintf(parameter[15],"%d",set[i].anz_v);
9623             write2stack( 16, parameter);
9624           }
9625         }
9626       }
9627       return(1);
9628     }
9629     else
9630     {
9631       operateAlias( name, "se" );
9632       setNr=getSetNr(name);
9633       if((setNr>=0)&&(compare(param,"range",3)==3))
9634       {
9635         if((set[setNr].anz_n>2)&&(set[setNr].anz_e>2))
9636 	{
9637           param[0]=0;
9638           /* check for holes */
9639           for(i=0; i<set[setNr].anz_n-1; i++)
9640             if((set[setNr].node[i]+1)!=(set[setNr].node[i+1])) break;
9641 	  if(i<set[setNr].anz_n-1) printf("Warning set %s has holes in the node numbering starting between node %d and %d\n", set[setNr].name, set[setNr].node[i], set[setNr].node[i+1]);
9642           for(i=0; i<set[setNr].anz_e-1; i++)
9643             if((set[setNr].elem[i]+1)!=(set[setNr].elem[i+1])) break;
9644 	  if(i<set[setNr].anz_e-1) printf("Warning set %s has holes in the elem numbering starting between elem %d and %d\n", set[setNr].name, set[setNr].elem[i], set[setNr].elem[i+1]);
9645 
9646           printf ("%-5d %s nr %d %d er %d %d\n", set[setNr].index, set[setNr].name, set[setNr].node[0], set[setNr].node[set[setNr].anz_n-1], set[setNr].elem[0], set[setNr].elem[set[setNr].anz_e-1]);
9647 	}
9648         return(1);
9649       }
9650 
9651       if (setNr<0)
9652       {
9653         /* set was not found. check if wildcards (*) were used */
9654         length= strsplt( name, '*', &dat);
9655         if ((length>0)&&(strstr(name, "*") !=NULL))
9656 	{
9657           j=0;
9658           for(setNr=0; setNr<anz->sets; setNr++) if(set[setNr].name!=(char *)NULL)
9659 	  {
9660             foundSubString=0;
9661             for(i=0; i<length; i++)
9662 	    {
9663               if(strstr(set[setNr].name, dat[i]) !=NULL)
9664 	      {
9665 	        foundSubString++;
9666 	        /* check if the first or the last char is no '*' then the dat[] must be at start or end */
9667 	        if(i==0) { if(name[0]!='*')  { if(name[0]!=set[setNr].name[0])  foundSubString--; }  }
9668          	if(i==length-1) { if(name[strlen(name)-1]!='*') { if(name[strlen(name)-1]!=set[setNr].name[strlen(set[setNr].name)-1])  foundSubString--; } }
9669 	      }
9670 	    }
9671             if(foundSubString==length)
9672 	    {
9673 	      i=setNr;
9674               if (!set[i].type)
9675               {
9676 		j++;
9677                 printf ("%-5d %s stat:%c n:%d e:%d f:%d p:%d l:%d c:%d s:%d b:%d L:%d S:%d se:%d sh:%d v:%d", set[i].index, set[i].name, set[i].flag, set[i].anz_n, set[i].anz_e, set[i].anz_f, set[i].anz_p, set[i].anz_l, set[i].anz_c, set[i].anz_s, set[i].anz_b, set[i].anz_nurl, set[i].anz_nurs, set[i].anz_se, set[i].anz_sh, set[i].anz_v);
9678                 sprintf(parameter[0],"%d", set[i].index	    );
9679                 sprintf(parameter[1],"%s", set[i].name	    );
9680                 sprintf(parameter[2],"%c", set[i].flag	    );
9681                 sprintf(parameter[3],"%d", set[i].anz_n	    );
9682                 sprintf(parameter[4],"%d", set[i].anz_e	    );
9683                 sprintf(parameter[5],"%d", set[i].anz_f	    );
9684                 sprintf(parameter[6],"%d", set[i].anz_p	    );
9685                 sprintf(parameter[7],"%d", set[i].anz_l	    );
9686                 sprintf(parameter[8],"%d", set[i].anz_c	    );
9687                 sprintf(parameter[9],"%d", set[i].anz_s	    );
9688                 sprintf(parameter[10],"%d", set[i].anz_b	    );
9689                 sprintf(parameter[11],"%d", set[i].anz_nurl   );
9690                 sprintf(parameter[12],"%d", set[i].anz_nurs   );
9691                 sprintf(parameter[13],"%d", set[i].anz_se    );
9692                 sprintf(parameter[14],"%d", set[i].anz_sh    );
9693                 sprintf(parameter[15],"%d", set[i].anz_v      );
9694                 if(compare(param,"range",3)==3)
9695 		{
9696                   printf (" nr %d %d er %d %d", set[setNr].node[0], set[setNr].node[set[setNr].anz_n-1], set[setNr].elem[0], set[setNr].elem[set[setNr].anz_e-1]);
9697                   sprintf(parameter[16],"%d", set[i].node[0]   );
9698                   sprintf(parameter[17],"%d", set[i].node[set[setNr].anz_n-1]  );
9699                   sprintf(parameter[18],"%d", set[i].elem[0]  );
9700                   sprintf(parameter[19],"%d", set[i].elem[set[setNr].anz_e-1]   );
9701                   printf ("\n");
9702                   write2stack(20, parameter);
9703 		}
9704                 else
9705 	        {
9706                   printf ("\n");
9707                   write2stack(16, parameter);
9708 		}
9709               }
9710 	    }
9711 	  }
9712           if(j!=0) return(1);
9713 	}
9714         /* free dat */
9715         for(i=0; i<length; i++) free(dat[i]);
9716         free(dat);
9717 
9718         printf ("ERROR: set %s does not exist\n", name);
9719         sprintf(parameter[0], "ERROR: set %s does not exist", name);
9720         write2stack(1, parameter);
9721         return (-1);
9722       }
9723     }
9724     if (set[setNr].type) return(0);
9725 
9726     if(anz->l)
9727     {
9728       printf (" node:    value:       x:            y:           z:\n");
9729       for (i=0; i<set[setNr].anz_n; i++)
9730       {
9731         sprintf(parameter[0],"%8d",set[setNr].node[i]);
9732         sprintf(parameter[1],"%6e",lcase[cur_lc].dat[cur_entity][set[setNr].node[i]]);
9733         sprintf(parameter[2],"%12f",node[set[setNr].node[i]].nx* scale->w+scale->x);
9734         sprintf(parameter[3],"%12f",node[set[setNr].node[i]].ny* scale->w+scale->y);
9735         sprintf(parameter[4],"%12f",node[set[setNr].node[i]].nz* scale->w+scale->z);
9736         printf (" %s %s %s %s %s\n",parameter[0],parameter[1],parameter[2],parameter[3],parameter[4]);
9737         write2stack(5, parameter);
9738       }
9739     }
9740     else
9741     {
9742       printf (" node:       x:            y:           z:\n");
9743       for (i=0; i<set[setNr].anz_n; i++)
9744       {
9745         sprintf(parameter[0],"%8d",set[setNr].node[i]);
9746         sprintf(parameter[1],"%12f",node[set[setNr].node[i]].nx* scale->w+scale->x);
9747         sprintf(parameter[2],"%12f",node[set[setNr].node[i]].ny* scale->w+scale->y);
9748         sprintf(parameter[3],"%12f",node[set[setNr].node[i]].nz* scale->w+scale->z);
9749         printf (" %s %s %s %s\n",parameter[0],parameter[1],parameter[2],parameter[3]);
9750         write2stack(4, parameter);
9751       }
9752     }
9753     for (i=0; i<set[setNr].anz_e; i++)
9754     {
9755       nr=set[setNr].elem[i];
9756       printf (" elem:%d type:%d n:", nr, e_enqire[nr].type);
9757       if     (e_enqire[nr].type==1) k=8;
9758       else if(e_enqire[nr].type==2) k=6;
9759       else if(e_enqire[nr].type==3) k=4;
9760       else if(e_enqire[nr].type==4) k=20;
9761       else if(e_enqire[nr].type==5) k=15;
9762       else if(e_enqire[nr].type==6) k=10;
9763       else if(e_enqire[nr].type==7) k=3;
9764       else if(e_enqire[nr].type==8) k=6;
9765       else if(e_enqire[nr].type==9) k=4;
9766       else if(e_enqire[nr].type==10) k=8;
9767       else if(e_enqire[nr].type==11) k=2;
9768       else if(e_enqire[nr].type==12) k=3;
9769       else k=0;
9770       for (n=0; n<k; n++) printf("%d ",e_enqire[nr].nod[n]);
9771       printf("\n");
9772       sprintf(parameter[0],"%d", nr);
9773       sprintf(parameter[1],"%d", e_enqire[nr].type);
9774       for (n=0; n<k; n++) sprintf(parameter[n+2],"%d", e_enqire[nr].nod[n]);
9775       write2stack(k+2, parameter);
9776     }
9777     for (i=0; i<set[setNr].anz_f; i++)
9778     {
9779       nr=set[setNr].face[i];
9780       printf (" face:%d elem:%d side:%d nodes:",  nr, face[nr].elem_nr, face[nr].nr+1);
9781       if(face[nr].type==7) k=3;
9782       else if(face[nr].type==8) k=6;
9783       else if(face[nr].type==9) k=4;
9784       else if(face[nr].type==10) k=8;
9785       else if(face[nr].type==11) k=2;
9786       else if(face[nr].type==12) k=3;
9787       else k=0;
9788       for (n=0; n<k; n++) printf("%d ",face[nr].nod[n]);
9789       printf("\n");
9790       sprintf(parameter[0],"%d", nr);
9791       sprintf(parameter[1],"%d", face[nr].elem_nr);
9792       sprintf(parameter[2],"%d", face[nr].nr+1);
9793       for (n=0; n<k; n++) sprintf(parameter[n+3],"%d", face[nr].nod[n]);
9794       write2stack(k+3, parameter);
9795     }
9796     for (i=0; i<set[setNr].anz_p; i++)
9797     {
9798       p=set[setNr].pnt[i];
9799       if( point[p].name != (char *)NULL )
9800         printf (" pnt:%s %lf %lf %lf\n", point[p].name,
9801         (point[p].px* scale->w+scale->x),
9802         (point[p].py* scale->w+scale->y),
9803         (point[p].pz* scale->w+scale->z) );
9804       sprintf(parameter[0],"%s", point[p].name);
9805       sprintf(parameter[1],"%lf", point[p].px* scale->w+scale->x);
9806       sprintf(parameter[2],"%lf", point[p].py* scale->w+scale->y);
9807       sprintf(parameter[3],"%lf", point[p].pz* scale->w+scale->z);
9808       write2stack(4, parameter);
9809     }
9810     for (i=0; i<set[setNr].anz_l; i++)
9811     {
9812       l=set[setNr].line[i];
9813       if( line[l].name != (char *)NULL )
9814       {
9815         bias_fbd=getBias_fbd(l, line);
9816 
9817         if( line[l].typ=='a' )  /* arc-line */
9818         {
9819           printf (" line:%s typ:a p1:%s p2:%s pc:%s div:%d bias:%d bias_el:%lf etyp:%d attr:%d\n"
9820           , line[l].name, point[line[l].p1].name,
9821           point[line[l].p2].name, point[line[l].trk].name, line[l].div, bias_fbd, line[l].bias, line[l].etyp, line[l].eattr);
9822           sprintf(parameter[4],"%s",point[line[l].trk].name);
9823         }
9824         else if( line[l].typ=='s' )  /* seq-line */
9825         {
9826           printf (" line:%s typ:s p1:%s p2:%s set:%s div:%d bias:%d bias_el:%lf etyp:%d attr:%d\n"
9827           , line[l].name, point[line[l].p1].name,
9828           point[line[l].p2].name, set[line[l].trk].name, line[l].div, bias_fbd, line[l].bias, line[l].etyp, line[l].eattr);
9829           sprintf(parameter[4],"%s",set[line[l].trk].name);
9830         }
9831         else  /* its a straight line   */
9832         {
9833           printf (" line:%s typ:l p1:%s p2:%s trk:- div:%d bias:%d bias_el:%lf etyp:%d attr:%d\n"
9834           , line[l].name, point[line[l].p1].name,
9835           point[line[l].p2].name, line[l].div, bias_fbd, line[l].bias, line[l].etyp, line[l].eattr);
9836           sprintf(parameter[4],"-");
9837         }
9838         sprintf(parameter[0],"%s",line[l].name);
9839         sprintf(parameter[1],"%c",line[l].typ);
9840         sprintf(parameter[2],"%s",point[line[l].p1].name);
9841         sprintf(parameter[3],"%s",point[line[l].p2].name);
9842         sprintf(parameter[5],"%d",line[l].div);
9843         sprintf(parameter[6],"%d",bias_fbd);
9844         sprintf(parameter[7],"%f",line[l].bias);
9845         sprintf(parameter[8],"%d",line[l].etyp);
9846         sprintf(parameter[9],"%d",line[l].eattr);
9847         write2stack(10, parameter);
9848       }
9849     }
9850     for (i=0; i<set[setNr].anz_c; i++)
9851     {
9852       p=set[setNr].lcmb[i];
9853       if( lcmb[p].name != (char *)NULL )
9854       {
9855         printf (" lcmb:%s uses %d lines:", lcmb[p].name, lcmb[p].nl);
9856         for (j=0; j<lcmb[p].nl; j++)
9857           printf (" %1c %s", lcmb[p].o[j], line[lcmb[p].l[j]].name );
9858         printf (" \n");
9859         sprintf(parameter[0],"%s",lcmb[p].name);
9860         sprintf(parameter[1],"%d",lcmb[p].nl);
9861         j=2;
9862         for (n=0; n<lcmb[p].nl; n++) { sprintf(parameter[j++],"%1c", lcmb[p].o[n]); sprintf(parameter[j++],"%s", line[lcmb[p].l[n]].name); }
9863         write2stack(j, parameter);
9864       }
9865     }
9866     for (i=0; i<set[setNr].anz_s; i++)
9867     {
9868       p=set[setNr].surf[i];
9869       if( surf[p].name != (char *)NULL )
9870       {
9871 	  // printf("sh:%d\n",surf[p].sh);
9872         if (surf[p].sh<=-1) printf (" surf:%s %1c BLEND ", surf[p].name, surf[p].ori );
9873         else if (surf[p].sh>-1) printf (" surf:%s %1c %s ", surf[p].name, surf[p].ori, shape[surf[p].sh].name );
9874         sprintf(parameter[0],"%s", surf[p].name);
9875         sprintf(parameter[1],"%c", surf[p].ori);
9876         if (surf[p].sh<=-1) sprintf(parameter[2],"BLEND");
9877         else  sprintf(parameter[2],"%s", shape[surf[p].sh].name);
9878         for (j=0; j<surf[p].nl; j++)
9879         {
9880           nl=surf[p].l[j];
9881           if (surf[p].typ[j]=='l')
9882           {
9883             printf (" %1c %s", surf[p].o[j], line[nl].name );
9884           }
9885           else
9886           {
9887             printf (" %1c %s", surf[p].o[j], lcmb[nl].name );
9888             for (k=0; k<lcmb[nl].nl; k++ )
9889             {
9890               nc=lcmb[nl].l[k];
9891               printf (" (%c) (%s)", lcmb[nl].o[k], line[nc].name );
9892             }
9893           }
9894         }
9895         if( surf[p].eparm != (char *)NULL ) printf (" etyp:%d attr:%d mshp:%s\n", surf[p].etyp, surf[p].eattr, surf[p].eparm);
9896         else printf (" etyp:%d attr:%d\n", surf[p].etyp, surf[p].eattr);
9897       }
9898       write2stack(3, parameter);
9899     }
9900     for (i=0; i<set[setNr].anz_b; i++)
9901     {
9902       p=set[setNr].body[i];
9903       if( body[p].name != (char *)NULL )
9904       {
9905         printf (" body:%s %1c", body[p].name, body[p].ori );
9906         sprintf(parameter[0],"%s", body[p].name);
9907         sprintf(parameter[1],"%c", body[p].ori);
9908         for (j=0; j<body[p].ns; j++)
9909           printf (" %1c %s", body[p].o[j], surf[body[p].s[j]].name );
9910         if( body[p].eparm != (char *)NULL ) printf (" etyp:%d attr:%d mshp:%s\n", body[p].etyp, body[p].eattr, body[p].eparm);
9911         else printf (" etyp:%d attr:%d\n", body[p].etyp, body[p].eattr);
9912       }
9913       write2stack(2, parameter);
9914     }
9915     for (i=0; i<set[setNr].anz_nurl; i++)
9916     {
9917       nr=set[setNr].nurl[i];
9918       if( nurbl[nr].name != (char *)NULL )
9919       {
9920         printf (" nurl:%s", nurbl[nr].name );
9921         printf (" exp:%d pnts:%d nods:%d End:%d\n", nurbl[nr].u_exp, nurbl[nr].u_npnt, nurbl[nr].u_nknt, nurbl[nr].endFlag);
9922         /*
9923         for (k=0; k<nurbl[nr].u_nknt; k++) printf("u-node[%d] = %lf\n", k+1, nurbl[nr].uknt[k]);
9924         for (k=0; k<nurbl[nr].u_npnt; k++)
9925         {
9926           printf("cpnt[%d]:%s x=%lf y=%lf z=%lf w=%lf\n", k+1, point[nurbl[nr].ctlpnt[k]].name, point[nurbl[nr].ctlpnt[k]].px* scale->w+scale->x,
9927           point[nurbl[nr].ctlpnt[k]].py* scale->w+scale->y, point[nurbl[nr].ctlpnt[k]].pz* scale->w+scale->z, nurbl[nr].weight[k]);
9928         }
9929 	*/
9930       }
9931     }
9932     for (i=0; i<set[setNr].anz_nurs; i++)
9933     {
9934       nr=set[setNr].nurs[i];
9935      if( nurbs[nr].name != (char *)NULL )
9936      {
9937       printf (" nurs:%s", nurbs[nr].name );
9938       printf (" u_exp:%d v_exp:%d u_npnt:%d v_npnt:%d u_nnod:%d v_nnod:%d End:%d\n", nurbs[nr].u_exp, nurbs[nr].v_exp,
9939         nurbs[nr].u_npnt, nurbs[nr].v_npnt, nurbs[nr].u_nknt, nurbs[nr].v_nknt, nurbs[nr].endFlag);
9940       /*
9941       for (k=0; k<nurbs[nr].u_nknt; k++) printf("u-node[%d] = %lf\n", k+1, nurbs[nr].uknt[k]);
9942       for (k=0; k<nurbs[nr].v_nknt; k++) printf("v-node[%d] = %lf\n", k+1, nurbs[nr].vknt[k]);
9943       for (k=0; k<nurbs[nr].u_npnt; k++)
9944       {
9945         for (j=0; j<nurbs[nr].v_npnt; j++)
9946         {
9947           printf("cpnt[%d][%d]:%s x=%lf y=%lf z=%lf w=%lf \n", k+1, j+1, point[nurbs[nr].ctlpnt[k][j]].name, point[nurbs[nr].ctlpnt[k][j]].px* scale->w+scale->x,
9948           point[nurbs[nr].ctlpnt[k][j]].py* scale->w+scale->y, point[nurbs[nr].ctlpnt[k][j]].pz* scale->w+scale->z, nurbs[nr].weight[k][j]);
9949         }
9950       }
9951       */
9952      }
9953     }
9954     for (i=0; i<set[setNr].anz_se; i++)
9955     {
9956       p=set[setNr].set[i];
9957       if( set[p].name != (char *)NULL )
9958       {
9959         printf (" set:%s ", set[p].name );
9960         printf (" \n");
9961       }
9962     }
9963     for (i=0; i<set[setNr].anz_sh; i++)
9964     {
9965       p=set[setNr].shp[i];
9966       if( shape[p].name != (char *)NULL )
9967       {
9968         if(shape[p].type==0)
9969           printf (" shape:%s PLN p1:%s p2:%s p3:%s\n", shape[p].name, point[shape[p].p[0]].name, point[shape[p].p[1]].name, point[shape[p].p[2]].name );
9970         if(shape[p].type==1)
9971         {
9972           v_result( &point[shape[p].p[0]].px, &point[shape[p].p[2]].px, r1  );
9973           printf (" shape:%s CYL p1:%s p2:%s r:%f (p3:%s)\n", shape[p].name, point[shape[p].p[0]].name, point[shape[p].p[1]].name, v_betrag(r1)*scale->w, point[shape[p].p[2]].name );
9974 	}
9975         if(shape[p].type==2)
9976         {
9977           v_result( &point[shape[p].p[0]].px, &point[shape[p].p[2]].px, r1  );
9978           v_result( &point[shape[p].p[1]].px, &point[shape[p].p[3]].px, r2  );
9979           printf (" shape:%s CONE p1:%s p2:%s r1:%f (p3:%s) r2:%f (p4:%s)\n", shape[p].name, point[shape[p].p[0]].name, point[shape[p].p[1]].name, v_betrag(r1)*scale->w, point[shape[p].p[2]].name, v_betrag(r2)*scale->w, point[shape[p].p[3]].name );
9980 	}
9981         if(shape[p].type==3)
9982         {
9983           v_result( &point[shape[p].p[0]].px, &point[shape[p].p[1]].px, r1  );
9984           printf (" shape:%s SPH p1:%s r:%f (p2:%s)\n", shape[p].name, point[shape[p].p[0]].name, v_betrag(r1)*scale->w, point[shape[p].p[1]].name );
9985 	}
9986         if(shape[p].type==4)
9987           printf (" shape:%s NURS %s\n", shape[p].name, nurbs[shape[p].p[0]].name);
9988         if(shape[p].type==5)
9989         {
9990           v_result( &point[shape[p].p[0]].px, &point[shape[p].p[2]].px, r1  );
9991           v_result( &point[shape[p].p[2]].px, &point[shape[p].p[3]].px, r2  );
9992           printf (" shape:%s TOR p1:%s p2:%s r1:%f (p3:%s) r2:%f (p4:%s)\n", shape[p].name, point[shape[p].p[0]].name, point[shape[p].p[1]].name, v_betrag(r1)*scale->w, point[shape[p].p[2]].name, v_betrag(r2)*scale->w, point[shape[p].p[3]].name );
9993 	}
9994       }
9995     }
9996     for (i=0; i<set[setNr].anz_v; i++)
9997     {
9998       p=set[setNr].valu[i];
9999       if( value[p].name != (char *)NULL )
10000       {
10001         printf (" value:%s string:%s\n", value[p].name, value[p].string);
10002       }
10003     }
10004     printf (" %d nodes, %d elements, %d faces, %d Points, %d Lines, %d Lcmb, %d Surfs, %d Bodys, %d Nurl, %d Nurs, %d sets, %d shapes, %d values stored\n", set[setNr].anz_n, set[setNr].anz_e, set[setNr].anz_f, set[setNr].anz_p, set[setNr].anz_l, set[setNr].anz_c, set[setNr].anz_s, set[setNr].anz_b, set[setNr].anz_nurl, set[setNr].anz_nurs, set[setNr].anz_se, set[setNr].anz_sh, set[setNr].anz_v );
10005     sprintf(parameter[0],"%d",set[setNr].anz_n);
10006     sprintf(parameter[1],"%d",set[setNr].anz_e);
10007     sprintf(parameter[2],"%d",set[setNr].anz_f);
10008     sprintf(parameter[3],"%d",set[setNr].anz_p);
10009     sprintf(parameter[4],"%d",set[setNr].anz_l);
10010     sprintf(parameter[5],"%d",set[setNr].anz_c);
10011     sprintf(parameter[6],"%d",set[setNr].anz_s);
10012     sprintf(parameter[7],"%d",set[setNr].anz_b);
10013     sprintf(parameter[8],"%d",set[setNr].anz_nurl);
10014     sprintf(parameter[9],"%d",set[setNr].anz_nurs);
10015     sprintf(parameter[10],"%d",set[setNr].anz_se);
10016     sprintf(parameter[11],"%d",set[setNr].anz_sh);
10017     sprintf(parameter[12],"%d",set[setNr].anz_v);
10018     write2stack( 13, parameter);
10019   }
10020 
10021   else if ((compare( typ, "sh", 2) == 2) ||(compare( typ, "SH", 2) == 2))
10022   {
10023     l=getShapeNr(name);
10024     if (l<0)
10025     {
10026       printf (" prnt: shape:%s does not exist\n", name);
10027       return (-1);
10028     }
10029     if( shape[l].name != (char *)NULL )
10030     {
10031       if(shape[l].type==0)
10032         printf (" shape:%s PLN p1:%s p2:%s p3:%s\n", shape[l].name, point[shape[l].p[0]].name, point[shape[l].p[1]].name, point[shape[l].p[2]].name );
10033       if(shape[l].type==1)
10034       {
10035         v_result( &point[shape[l].p[0]].px, &point[shape[l].p[2]].px, r1  );
10036         printf (" shape:%s CYL p1:%s p2:%s r:%f (p3:%s)\n", shape[l].name, point[shape[l].p[0]].name, point[shape[l].p[1]].name, v_betrag(r1)*scale->w, point[shape[l].p[2]].name );
10037 	}
10038       if(shape[l].type==2)
10039       {
10040         v_result( &point[shape[l].p[0]].px, &point[shape[l].p[2]].px, r1  );
10041         v_result( &point[shape[l].p[1]].px, &point[shape[l].p[3]].px, r2  );
10042         printf (" shape:%s CONE p1:%s p2:%s r1:%f (p3:%s) r2:%f (p4:%s)\n", shape[l].name, point[shape[l].p[0]].name, point[shape[l].p[1]].name, v_betrag(r1)*scale->w, point[shape[l].p[2]].name, v_betrag(r2)*scale->w, point[shape[l].p[3]].name );
10043 	}
10044       if(shape[l].type==3)
10045       {
10046         v_result( &point[shape[l].p[0]].px, &point[shape[l].p[1]].px, r1  );
10047         printf (" shape:%s SPH p1:%s r:%f (p2:%s)\n", shape[l].name, point[shape[l].p[0]].name, v_betrag(r1)*scale->w, point[shape[l].p[1]].name );
10048 	}
10049       if(shape[l].type==4)
10050         printf (" shape:%s NURS %s\n", shape[l].name, nurbs[shape[l].p[0]].name);
10051       if(shape[l].type==5)
10052       {
10053         v_result( &point[shape[l].p[0]].px, &point[shape[l].p[2]].px, r1  );
10054         v_result( &point[shape[l].p[2]].px, &point[shape[l].p[3]].px, r2  );
10055         printf (" shape:%s TOR p1:%s p2:%s r1:%f (p3:%s) r2:%f (p4:%s)\n", shape[l].name, point[shape[l].p[0]].name, point[shape[l].p[1]].name, v_betrag(r1)*scale->w, point[shape[l].p[2]].name, v_betrag(r2)*scale->w, point[shape[l].p[3]].name );
10056       }
10057     }
10058   }
10059   else if ((compare( typ, "sq", 2) == 2) ||(compare( typ, "SQ", 2) == 2))
10060   {
10061     if (length==1)
10062     {
10063       /* list all existing sequential sets */
10064       l=0;
10065       for (i=0; i<anz->sets; i++)
10066       {
10067         if( set[i].name != (char *)NULL )
10068         {
10069           if (set[i].type)
10070 	  {
10071             l++;
10072             printf (" %s type:SEQ stat:%c n:%d p:%d\n", set[i].name, set[i].flag, set[i].anz_n, set[i].anz_p);
10073 	  }
10074         }
10075       }
10076       if (!l) printf(" no sequences defined\n");
10077       return(1);
10078     }
10079     else
10080     {
10081       setNr=getSetNr(name);
10082       if (setNr<0)
10083       {
10084         /* set was not found. check if wildcards (*) were used */
10085         length= strsplt( name, '*', &dat);
10086         if ((length>0)&&(strstr(name, "*") !=NULL))
10087 	{
10088           j=0;
10089           for(setNr=0; setNr<anz->sets; setNr++) if(set[setNr].name!=(char *)NULL)
10090 	  {
10091             foundSubString=0;
10092             for(i=0; i<length; i++)
10093             {
10094               if(strstr(set[setNr].name, dat[i]) !=NULL)
10095 	      {
10096 	        foundSubString++;
10097 	        /* check if the first or the last char is no '*' then the dat[] must be at start or end */
10098 	        if(i==0) { if(name[0]!='*')  { if(name[0]!=set[setNr].name[0])  foundSubString--; }  }
10099          	if(i==length-1) { if(name[strlen(name)-1]!='*') { if(name[strlen(name)-1]!=set[setNr].name[strlen(set[setNr].name)-1])  foundSubString--; } }
10100 	      }
10101 	    }
10102             if(foundSubString==length)
10103 	    {
10104 	      i=setNr;
10105               if (set[i].type)
10106               {
10107                 printf ("%s type:SEQ stat:%c n:%d p:%d\n", set[i].name, set[i].flag, set[i].anz_n, set[i].anz_p);
10108 		j++;
10109               }
10110 	    }
10111 	  }
10112           if(j!=0) return(1);
10113 	}
10114         printf (" prnt: seq:%s does not exist\n", name);
10115         return(-1);
10116       }
10117     }
10118     if (!set[setNr].type) return(0);
10119 
10120     if(anz->l)
10121     {
10122       printf (" node:    value:       x:            y:           z:\n");
10123       for (i=0; i<set[setNr].anz_n; i++)
10124       {
10125         sprintf(parameter[0],"%8d",set[setNr].node[i]);
10126         sprintf(parameter[1],"%6e",lcase[cur_lc].dat[cur_entity][set[setNr].node[i]]);
10127         sprintf(parameter[2],"%12f",node[set[setNr].node[i]].nx* scale->w+scale->x);
10128         sprintf(parameter[3],"%12f",node[set[setNr].node[i]].ny* scale->w+scale->y);
10129         sprintf(parameter[4],"%12f",node[set[setNr].node[i]].nz* scale->w+scale->z);
10130         printf (" %s %s %s %s %s\n",parameter[0],parameter[1],parameter[2],parameter[3],parameter[4]);
10131         write2stack(5, parameter);
10132       }
10133     }
10134     else
10135     {
10136       printf (" node:       x:            y:           z:\n");
10137       for (i=0; i<set[setNr].anz_n; i++)
10138       {
10139         sprintf(parameter[0],"%8d",set[setNr].node[i]);
10140         sprintf(parameter[1],"%12f",node[set[setNr].node[i]].nx* scale->w+scale->x);
10141         sprintf(parameter[2],"%12f",node[set[setNr].node[i]].ny* scale->w+scale->y);
10142         sprintf(parameter[3],"%12f",node[set[setNr].node[i]].nz* scale->w+scale->z);
10143         printf (" %s %s %s %s\n",parameter[0],parameter[1],parameter[2],parameter[3]);
10144         write2stack(4, parameter);
10145       }
10146     }
10147     for (i=0; i<set[setNr].anz_p; i++)
10148     {
10149       p=set[setNr].pnt[i];
10150       if( point[p].name != (char *)NULL )
10151         printf (" pnt:%s x:%lf y:%lf z:%lf\n", point[p].name,
10152         (point[p].px* scale->w+scale->x),
10153         (point[p].py* scale->w+scale->y),
10154         (point[p].pz* scale->w+scale->z) );
10155     }
10156   }
10157 
10158   /* check entities */
10159   else if ((typ[0]=='n')||(typ[0]=='N'))
10160   {
10161     nr=atoi(name);
10162     if((nr<1)||(nr>anz->nmax)) { printf (" prnt: node:'%s' does not exist\n", name);return (-1); }
10163     if(anz->l)
10164     {
10165       printf (" node:%d v:%lf x:%lf y:%lf z:%lf\n", nr, lcase[cur_lc].dat[cur_entity][nr],
10166         (node[nr].nx* scale->w+scale->x),
10167         (node[nr].ny* scale->w+scale->y),
10168         (node[nr].nz* scale->w+scale->z) );
10169       sprintf(parameter[0],"%d", nr);
10170       sprintf(parameter[1],"%lf",lcase[cur_lc].dat[cur_entity][nr]);
10171       sprintf(parameter[2],"%lf",node[nr].nx * scale->w+scale->x);
10172       sprintf(parameter[3],"%lf",node[nr].ny * scale->w+scale->y);
10173       sprintf(parameter[4],"%lf",node[nr].nz * scale->w+scale->z);
10174       write2stack(5, parameter);
10175     }
10176     else
10177     {
10178       printf (" node:%d xyz: %lf %lf %lf\n", nr,
10179         (node[nr].nx* scale->w+scale->x),
10180         (node[nr].ny* scale->w+scale->y),
10181         (node[nr].nz* scale->w+scale->z) );
10182       sprintf(parameter[0],"%d", nr);
10183       sprintf(parameter[1],"%lf",node[nr].nx * scale->w+scale->x);
10184       sprintf(parameter[2],"%lf",node[nr].ny * scale->w+scale->y);
10185       sprintf(parameter[3],"%lf",node[nr].nz * scale->w+scale->z);
10186       write2stack(4, parameter);
10187     }
10188   }
10189   else if ((typ[0]=='e')||(typ[0]=='E'))
10190   {
10191     if (typ[1]=='q')
10192     {
10193       operateAlias( name, "se" );
10194       setNr=getSetNr(name);
10195       if (setNr<0)
10196       {
10197         printf (" prnt: set:%s does not exist\n", name);
10198         return(-1);
10199       }
10200       /* show bad elements */
10201       i=calcBadElements(set[setNr].name);
10202       if (i>0)
10203       {
10204         printf("found %d bad elements in set:%s (stored in set:%s)\n", i, set[setNr].name, specialset->njby);
10205 	setNr=getSetNr(specialset->njby);
10206         for (i=0; i<set[setNr].anz_e; i++)
10207         {
10208           nr=set[setNr].elem[i];
10209           printf (" elem:%d type:%d n:", nr, e_enqire[nr].type);
10210           if     (e_enqire[nr].type==1) k=8;
10211           else if(e_enqire[nr].type==2) k=6;
10212           else if(e_enqire[nr].type==3) k=4;
10213           else if(e_enqire[nr].type==4) k=20;
10214           else if(e_enqire[nr].type==5) k=15;
10215           else if(e_enqire[nr].type==6) k=10;
10216           else if(e_enqire[nr].type==7) k=3;
10217           else if(e_enqire[nr].type==8) k=6;
10218           else if(e_enqire[nr].type==9) k=4;
10219           else if(e_enqire[nr].type==10) k=8;
10220           else if(e_enqire[nr].type==11) k=2;
10221           else if(e_enqire[nr].type==12) k=3;
10222           else k=0;
10223           for (n=0; n<k; n++) printf("%d ",e_enqire[nr].nod[n]);
10224           printf("\n");
10225         }
10226       }
10227       else { printf("found no bad element in set:%s\n", name); delSet(specialset->njby); }
10228       return(1);
10229     }
10230     nr=atoi(name);
10231     printf (" elem:%d ",  nr);
10232     if     (e_enqire[nr].type==1) k=8;
10233     else if(e_enqire[nr].type==2) k=6;
10234     else if(e_enqire[nr].type==3) k=4;
10235     else if(e_enqire[nr].type==4) k=20;
10236     else if(e_enqire[nr].type==5) k=15;
10237     else if(e_enqire[nr].type==6) k=10;
10238     else if(e_enqire[nr].type==7) k=3;
10239     else if(e_enqire[nr].type==8) k=6;
10240     else if(e_enqire[nr].type==9) k=4;
10241     else if(e_enqire[nr].type==10) k=8;
10242     else if(e_enqire[nr].type==11) k=2;
10243     else if(e_enqire[nr].type==12) k=3;
10244     else k=0;
10245     for (n=0; n<k; n++) printf("%d ",e_enqire[nr].nod[n]);
10246     printf("\n");
10247   }
10248   else if ((typ[0]=='f')||(typ[0]=='F'))
10249   {
10250     nr=atoi(name);
10251     printf (" face:%d elem:%d side:%d nodes:",  nr, face[nr].elem_nr, face[nr].nr+1);
10252       if(face[nr].type==7) k=3;
10253       else if(face[nr].type==8) k=6;
10254       else if(face[nr].type==9) k=4;
10255       else if(face[nr].type==10) k=8;
10256       else if(face[nr].type==11) k=2;
10257       else if(face[nr].type==12) k=3;
10258       else k=0;
10259       for (n=0; n<k; n++) printf("%d ",face[nr].nod[n]);
10260       printf("\n");
10261   }
10262   else if ((typ[0]=='p')||(typ[0]=='P'))
10263   {
10264     operateAlias( name, "p" );
10265     p=getPntNr(name);
10266     if (p<0)
10267     {
10268       printf (" prnt: point:%s does not exist\n", name);
10269       return (-1);
10270     }
10271     if( point[p].name != (char *)NULL )
10272     {
10273       printf (" pnt:%s x:%lf y:%lf z:%lf\n", point[p].name,
10274       (point[p].px* scale->w+scale->x),
10275       (point[p].py* scale->w+scale->y),
10276       (point[p].pz* scale->w+scale->z) );
10277       sprintf(parameter[0],"%s", point[p].name);
10278       sprintf(parameter[1],"%lf", point[p].px* scale->w+scale->x);
10279       sprintf(parameter[2],"%lf", point[p].py* scale->w+scale->y);
10280       sprintf(parameter[3],"%lf", point[p].pz* scale->w+scale->z);
10281       write2stack(4, parameter);
10282     }
10283   }
10284   else if ((typ[0]=='l')||(typ[0]=='L'))
10285   {
10286     operateAlias( name, "l" );
10287     l=getLineNr(name);
10288     if (l<0)
10289     {
10290       printf (" prnt: line:%s does not exist\n", name);
10291       return (-1);
10292     }
10293     if( line[l].name != (char *)NULL )
10294     {
10295       bias_fbd=getBias_fbd(l, line);
10296 
10297       if( line[l].typ=='a' )  /* arc-line */
10298       {
10299         printf (" line:%s p1:%s p2:%s pc:%s div:%d bias:%d bias_el:%lf etyp:%d attr:%d\n"
10300         , line[l].name, point[line[l].p1].name,
10301         point[line[l].p2].name, point[line[l].trk].name, line[l].div, bias_fbd, line[l].bias, line[l].etyp, line[l].eattr);
10302       }
10303       else if( line[l].typ=='s' )  /* seq-line */
10304       {
10305         printf (" line:%s p1:%s p2:%s set:%s div:%d bias:%d bias_el:%lf etyp:%d attr:%d\n"
10306         , line[l].name, point[line[l].p1].name,
10307         point[line[l].p2].name, set[line[l].trk].name, line[l].div, bias_fbd, line[l].bias, line[l].etyp, line[l].eattr);
10308       }
10309       else  /* its a straight line   */
10310       {
10311         printf (" line:%s p1:%s p2:%s div:%d bias:%d bias_el:%lf etyp:%d attr:%d\n"
10312         , line[l].name, point[line[l].p1].name,
10313         point[line[l].p2].name, line[l].div, bias_fbd, line[l].bias, line[l].etyp, line[l].eattr);
10314       }
10315     }
10316   }
10317   else if ((typ[0]=='c')||(typ[0]=='C'))
10318   {
10319     operateAlias( name, "c" );
10320     l=getLcmbNr(name);
10321     if (l<0)
10322     {
10323       printf (" prnt: lcmb:%s does not exist\n", name);
10324       return (-1);
10325     }
10326     if( lcmb[l].name != (char *)NULL )
10327     {
10328       printf (" lcmb:%s uses %d lines:", lcmb[l].name, lcmb[l].nl);
10329       for (j=0; j<lcmb[l].nl; j++)
10330         printf (" %1c %s", lcmb[l].o[j], line[lcmb[l].l[j]].name );
10331       printf (" \n");
10332     }
10333   }
10334   else if (typ[0]=='s')
10335   {
10336     operateAlias( name, "s" );
10337     p=getSurfNr(name);
10338     if (p<0)
10339     {
10340       printf (" prnt: surf:%s does not exist\n", name);
10341       return (-1);
10342     }
10343     if( surf[p].name != (char *)NULL )
10344     {
10345       if (surf[p].sh<=-1) printf (" surf:%s %1c BLEND ", surf[p].name, surf[p].ori );
10346       else if (surf[p].sh>-1) printf (" surf:%s %1c %s ", surf[p].name, surf[p].ori, shape[surf[p].sh].name );
10347       for (j=0; j<surf[p].nl; j++)
10348       {
10349         nl=surf[p].l[j];
10350         if (surf[p].typ[j]=='l')
10351         {
10352           printf (" %1c %s", surf[p].o[j], line[nl].name );
10353         }
10354         else
10355         {
10356           printf (" %1c %s", surf[p].o[j], lcmb[nl].name );
10357           for (k=0; k<lcmb[nl].nl; k++ )
10358           {
10359             nc=lcmb[nl].l[k];
10360             printf (" (%c) (%s)", lcmb[nl].o[k], line[nc].name );
10361           }
10362         }
10363       }
10364       if( surf[p].eparm != (char *)NULL ) printf (" etyp:%d attr:%d mshp:%s\n", surf[p].etyp, surf[p].eattr, surf[p].eparm);
10365       else printf (" etyp:%d attr:%d\n", surf[p].etyp, surf[p].eattr);
10366     }
10367   }
10368   else if (typ[0]=='S')
10369   {
10370     operateAlias( name, "S" );
10371     nr=getNursNr(name);
10372     if (nr<0)
10373     {
10374       printf (" prnt: Nurbs:%s does not exist\n", name);
10375       return (-1);
10376     }
10377     if( nurbs[nr].name != (char *)NULL )
10378     {
10379       printf (" nurs:%s", nurbs[nr].name );
10380       printf (" u_exp:%d v_exp:%d u_npnt:%d v_npnt:%d u_nnod:%d v_nnod:%d End:%d\n", nurbs[nr].u_exp, nurbs[nr].v_exp,
10381         nurbs[nr].u_npnt, nurbs[nr].v_npnt, nurbs[nr].u_nknt, nurbs[nr].v_nknt, nurbs[nr].endFlag);
10382 
10383       for (k=0; k<nurbs[nr].u_nknt; k++) printf("u-node[%d] = %lf\n", k+1, nurbs[nr].uknt[k]);
10384       for (k=0; k<nurbs[nr].v_nknt; k++) printf("v-node[%d] = %lf\n", k+1, nurbs[nr].vknt[k]);
10385       for (k=0; k<nurbs[nr].u_npnt; k++)
10386       {
10387         for (j=0; j<nurbs[nr].v_npnt; j++)
10388         {
10389           printf("cpnt[%d][%d]:%s x=%lf y=%lf z=%lf w=%lf \n", k+1, j+1, point[nurbs[nr].ctlpnt[k][j]].name, point[nurbs[nr].ctlpnt[k][j]].px* scale->w+scale->x,
10390           point[nurbs[nr].ctlpnt[k][j]].py* scale->w+scale->y, point[nurbs[nr].ctlpnt[k][j]].pz* scale->w+scale->z, nurbs[nr].weight[k][j]);
10391         }
10392       }
10393 
10394     }
10395   }
10396   else if ((typ[0]=='b')||(typ[0]=='B'))
10397   {
10398     operateAlias( name, "b" );
10399     p=getBodyNr(name);
10400     if (p<0)
10401     {
10402       printf (" prnt: body:%s does not exist\n", name);
10403       return (-1);
10404     }
10405     if( body[p].name != (char *)NULL )
10406     {
10407       printf (" body:%s %1c", body[p].name, body[p].ori );
10408       for (j=0; j<body[p].ns; j++)
10409         printf (" %1c %s", body[p].o[j], surf[body[p].s[j]].name );
10410       if( body[p].eparm != (char *)NULL ) printf (" etyp:%d attr:%d mshp:%s\n", body[p].etyp, body[p].eattr, body[p].eparm);
10411       else printf (" etyp:%d attr:%d\n", body[p].etyp, body[p].eattr);
10412     }
10413   }
10414   else if ((typ[0]=='v')||(typ[0]=='V'))
10415   {
10416     if (length==1)
10417     {
10418       /* list all existing values */
10419       for (i=0; i<anz->v; i++)
10420       {
10421         if( value[i].name != (char *)NULL )
10422         {
10423           printf (" value %s stores %s\n", value[i].name, value[i].string );
10424         }
10425       }
10426       return(1);
10427     }
10428     p=getValuNr(name);
10429     if (p<0)
10430     {
10431       printf (" prnt: value:%s does not exist\n", name);
10432       return (-1);
10433     }
10434     if( value[p].name != (char *)NULL )
10435     {
10436       printf (" value %s stores %s\n", value[p].name, value[p].string );
10437 
10438       /* split the value[p].string in separate strings at ' ' occurences and write them to the stack */
10439       strcpy(param,value[p].string);
10440       for(args=0, str=param; ; args++, str=NULL)
10441       {
10442         token = strtok_r(str," ", &saveptr);
10443         if(token == NULL) break;
10444         if(args == 20) break;
10445         strcpy(parameter[args],token);
10446       }
10447       write2stack(args, parameter);
10448     }
10449   }
10450   return(1);
10451 }
10452 
10453 /*------------------------------------------------------------------*/
10454 /* set und setinhalt loeschen                                       */
10455 /*------------------------------------------------------------------*/
10456 
zap(char * record)10457 int zap(char *record)
10458 {
10459   int i,j;
10460   int setNr,setNrbuf;
10461   int addDispFlagLocal=0;
10462   char setname[MAX_LINE_LENGTH];
10463 
10464   sword( record, setname );
10465   operateAlias( setname, "se" );
10466   setNr=getSetNr(setname);
10467 
10468   if (setNr<0) return (-1);
10469 
10470   /* suche abhaengige linien, redefine if necessary */
10471   for ( i=0; i<set[setNr].anz_p; i++)
10472   {
10473     for (j=0; j<anzGeo->l; j++)
10474     {
10475       if(( set[setNr].pnt[i] == line[j].trk )&&( line[j].typ == 'a' ))
10476       {
10477         line[j].typ = ' ';
10478       }
10479     }
10480   }
10481 
10482   /* vor dem loeschen muessen noch die abhaengigen direkt uebergeordneten Groessen dazugeladen werden  */
10483   printf(" complete set\n");
10484   completeSet( setname, "up");
10485   printf(" set complete\n");
10486 
10487   if (set[setNr].anz_e>0)
10488   {
10489     if(addDispFlag==1) { addDispToCoordinates(node); addDispFlagLocal=2; }
10490     delElem( set[setNr].anz_e, set[setNr].elem );
10491     printf(" elements deleted\n");
10492   }
10493   if (set[setNr].anz_n>0)
10494   {
10495     if(addDispFlag==1) { addDispToCoordinates(node); addDispFlagLocal=2; }
10496     delNod( set[setNr].anz_n, set[setNr].node );
10497     printf(" nodes deleted\n");
10498   }
10499   if(addDispFlagLocal==2) { addDispToCoordinates(node); }
10500   if (set[setNr].anz_nurs>0)
10501   {
10502     delNurs( set[setNr].anz_nurs, set[setNr].nurs );
10503     printf(" nurs deleted\n");
10504   }
10505   if (set[setNr].anz_sh>0)
10506   {
10507     /* check if a remaining surf uses this shape */
10508     /* go over all surfs in setNr and remove this surf from shape[].s */
10509     for ( i=0; i<set[setNr].anz_s; i++)
10510     {
10511       j=surf[set[setNr].surf[i]].sh;
10512       if(j>-1) shape[j].ns=iremove(&shape[j].s, shape[j].ns, set[setNr].surf[i]);
10513     }
10514     if(getSetNr(specialset->tmp)>-1) delSet(specialset->tmp);
10515     setNrbuf=pre_seta(specialset->tmp, "i", 0 );
10516     for ( i=0; i<set[setNr].anz_sh; i++)
10517     {
10518       /* do not delete if shape[].ns>0 */
10519       if(shape[set[setNr].shp[i]].ns>0) seta( setNrbuf, "h", set[setNr].shp[i]);
10520     }
10521     for ( i=0; i<set[setNrbuf].anz_sh; i++) setr( setNr, "h", set[setNrbuf].shp[i]);
10522     if(getSetNr(specialset->tmp)>-1) delSet(specialset->tmp);
10523 
10524     delShape( set[setNr].anz_sh, set[setNr].shp );
10525     printf(" shapes deleted\n");
10526   }
10527   if (set[setNr].anz_b>0)
10528   {
10529     delBody( set[setNr].anz_b, set[setNr].body );
10530     printf(" bodys deleted\n");
10531   }
10532   if (set[setNr].anz_s>0)
10533   {
10534     delSurf( set[setNr].anz_s, set[setNr].surf );
10535     printf(" surfs deleted\n");
10536   }
10537   if (set[setNr].anz_c>0)
10538   {
10539     delLcmb( set[setNr].anz_c, set[setNr].lcmb );
10540     printf(" lcmbs deleted\n");
10541   }
10542   if (set[setNr].anz_l>0)
10543   {
10544     delLine( set[setNr].anz_l, set[setNr].line );
10545     printf(" lines deleted\n");
10546   }
10547   if (set[setNr].anz_p>0)
10548   {
10549     delPnt( set[setNr].anz_p, set[setNr].pnt );
10550     printf(" points deleted\n");
10551   }
10552   if (set[setNr].anz_v>0)
10553   {
10554     delVal( set[setNr].anz_v, set[setNr].valu );
10555     printf(" values deleted\n");
10556   }
10557 
10558   /* delete the set itself */
10559   delSet(setname);
10560 
10561   return(1);
10562 }
10563 
10564 
10565 
mata(int * elemMat,int mat,int setNr)10566 void mata( int *elemMat, int mat, int setNr )
10567 {
10568   int  i, j;
10569   int           *ielem=NULL;
10570 
10571   /* mark the elements of the set for easy identification */
10572   if( (ielem=(int *)malloc((anz->emax+1)*sizeof(int) ) )==NULL)
10573   { printf(" ERROR: malloc failure\n"); return; }
10574   if (setNr==-1)
10575     for (i=0; i<=anz->emax; i++) ielem[i]=1;
10576   else
10577   {
10578     for (i=0; i<=anz->emax; i++) ielem[i]=0;
10579     for (i=0; i<set[setNr].anz_e; i++) ielem[set[setNr].elem[i]]=1;
10580   }
10581 
10582   /* exists this mat? */
10583   for (i=1; i<=elemMat[0]; i++) if (elemMat[i]==mat) break;
10584   if(i>elemMat[0])
10585   {
10586     elemMat[0] = i;
10587     elemMat[i] = mat;
10588   }
10589 
10590   for (j=0; j<anz->e; j++)
10591   {
10592     if (ielem[e_enqire[j].nr])
10593       e_enqire[e_enqire[j].nr].mat= elemMat[i];
10594   }
10595   free(ielem); ielem=NULL;
10596 }
10597 
10598 
getLetter(int i)10599 char getLetter(int i)
10600 {
10601   if(i>9) return(i-10+65);
10602   else return(i+48);
10603 }
10604 
10605 
getFamName(int n,char * c)10606 int getFamName( int n, char *c )
10607 {
10608   int i, j;
10609   double f;
10610 
10611   j=n/46656;
10612   n=n%46656;
10613 
10614   /* change decimal (0->46655) into a string of 3 char (000 -> ZZZ) */
10615   f=n/1296.;
10616   i=f+1e-10;
10617   c[0]=getLetter(i);
10618   f=(f-i)*36.;
10619   i=f+1e-10;
10620   c[1]=getLetter(i);
10621   i=(f-i)*36.+1e-10;
10622   c[2]=getLetter(i);
10623   c[3]='\0';
10624   return(j);
10625 }
10626 
10627 
getNewName(char * name,char * type)10628 int getNewName( char *name, char *type )
10629 {
10630   int i,nr,nr2=0;
10631   static int p, l, c, s, b, L, S, se, sh;
10632   char string[MAX_LINE_LENGTH];
10633 
10634   /* not implemented yet
10635   if(fillSpaceFlag) p=l=c=s=b=S=se=0;
10636   */
10637 
10638     do
10639     {
10640       if (type[0]=='p')
10641       {
10642         p++;
10643         i=getFamName(p, string);
10644         if(lchar->p+i>90)  sprintf(name, "%c%-d", lchar->p, p );
10645         else sprintf(name, "%c%s", lchar->p+i, string );
10646         nr=getPntNr(name);
10647       }
10648       else if (compare( type, "se", 2) == 2 )
10649       {
10650         se++;
10651         i=getFamName(se, string);
10652         if(lchar->se+i>90)  sprintf(name, "%c%-d", lchar->se,se);
10653         else sprintf(name, "%c%s", lchar->se+i, string );
10654         nr=getSetNr(name);
10655       }
10656       else if (compare( type, "sh", 2) == 2 )
10657       {
10658         sh++;
10659         i=getFamName(sh, string);
10660         if(lchar->sh+i>90)  sprintf(name, "%c%-d", lchar->sh,sh);
10661         else sprintf(name, "%c%s", lchar->sh+i, string );
10662         nr=getShapeNr(name);
10663       }
10664       else if (type[0]=='l')
10665       {
10666         l++;
10667         i=getFamName(l, string);
10668         if(lchar->l+i>90)  sprintf(name, "%c%-d", lchar->l, l );
10669         else sprintf(name, "%c%s", lchar->l+i, string );
10670         nr=getLineNr(name);
10671         if(nr<0) nr2=getLcmbNr(name); if(nr2>0) nr=0; /* check if a lcmb has this name, not use it */
10672       }
10673       else if (type[0]=='c')
10674       {
10675         c++;
10676         i=getFamName(c, string);
10677         if(lchar->c+i>90)  sprintf(name, "%c%-d", lchar->c, c );
10678         else sprintf(name, "%c%s", lchar->c+i, string );
10679         nr=getLcmbNr(name);
10680         if(nr<0) nr2=getLineNr(name); if(nr2>0) nr=0; /* check if a line has this name, not use it */
10681       }
10682       else if (type[0]=='s')
10683       {
10684         s++;
10685         i=getFamName(s, string);
10686         if(lchar->s+i>90)  sprintf(name, "%c%-d", lchar->s, s );
10687         else sprintf(name, "%c%s", lchar->s+i, string );
10688         nr=getSurfNr(name);
10689       }
10690       else if (type[0]=='b')
10691       {
10692         b++;
10693         i=getFamName(b, string);
10694         if(lchar->b+i>90)  sprintf(name, "%c%-d", lchar->b, b );
10695         else sprintf(name, "%c%s", lchar->b+i, string );
10696         nr=getBodyNr(name);
10697       }
10698       else if (type[0]=='L')
10699       {
10700         L++;
10701         i=getFamName(L, string);
10702         if(lchar->L+i>90)  sprintf(name, "%c%-d", lchar->L, L );
10703         else sprintf(name, "%c%s", lchar->L+i, string );
10704         nr=getNurlNr(name);
10705       }
10706       else if (type[0]=='S')
10707       {
10708         S++;
10709         i=getFamName(S, string);
10710         if(lchar->S+i>90)  sprintf(name, "%c%-d", lchar->S, S );
10711         else sprintf(name, "%c%s", lchar->S+i, string );
10712         nr=getNursNr(name);
10713       }
10714       else
10715         return(-1);
10716     }while(nr>-1);   /* new entity */
10717 
10718   return(1);
10719 }
10720 
10721 
10722 
calcGTOL(int setNr)10723 double calcGTOL(int setNr)
10724 {
10725   int l,i;
10726   double max[3], min[3], gtol;
10727 
10728   /* calculate the geometric tolerance based on all line-end-points and nodes */
10729   for(i=0; i<3; i++)
10730   {
10731     max[i]=-MAX_INTEGER;
10732     min[i]= MAX_INTEGER;
10733   }
10734   for(l=0; l<set[setNr].anz_l; l++)
10735   {
10736     i=set[setNr].line[l];
10737     if(line[i].name!=(char *)NULL)
10738     {
10739       if(point[line[i].p1].px > max[0]) max[0]=point[line[i].p1].px;
10740       if(point[line[i].p2].px > max[0]) max[0]=point[line[i].p2].px;
10741       if(point[line[i].p1].py > max[1]) max[1]=point[line[i].p1].py;
10742       if(point[line[i].p2].py > max[1]) max[1]=point[line[i].p2].py;
10743       if(point[line[i].p1].pz > max[2]) max[2]=point[line[i].p1].pz;
10744       if(point[line[i].p2].pz > max[2]) max[2]=point[line[i].p2].pz;
10745 
10746       if(point[line[i].p1].px < min[0]) min[0]=point[line[i].p1].px;
10747       if(point[line[i].p2].px < min[0]) min[0]=point[line[i].p2].px;
10748       if(point[line[i].p1].py < min[1]) min[1]=point[line[i].p1].py;
10749       if(point[line[i].p2].py < min[1]) min[1]=point[line[i].p2].py;
10750       if(point[line[i].p1].pz < min[2]) min[2]=point[line[i].p1].pz;
10751       if(point[line[i].p2].pz < min[2]) min[2]=point[line[i].p2].pz;
10752     }
10753   }
10754   for(l=0; l<set[setNr].anz_n; l++)
10755   {
10756     i=set[setNr].node[l];
10757     if(node[i].pflag!=1)
10758     {
10759       if(node[i].nx > max[0]) max[0]=node[i].nx;
10760       if(node[i].nx > max[0]) max[0]=node[i].nx;
10761       if(node[i].ny > max[1]) max[1]=node[i].ny;
10762       if(node[i].ny > max[1]) max[1]=node[i].ny;
10763       if(node[i].nz > max[2]) max[2]=node[i].nz;
10764       if(node[i].nz > max[2]) max[2]=node[i].nz;
10765     }
10766   }
10767   gtol=GTOL;
10768   for(i=0; i<3; i++)
10769   {
10770     max[i]-=min[i];
10771     if(max[i]>gtol) gtol=max[i];
10772   }
10773   gtol=GTOL*gtol*scale->w;
10774 
10775   return(gtol);
10776 }
10777 
10778 
10779 
readlist(char * datin,char * type)10780 int readlist(char *datin, char *type)
10781 {
10782   FILE *handle;
10783 
10784   int length, i, j, n, dotpos, column, setNr;
10785   char string[MAX_LINE_LENGTH], face[MAX_LINE_LENGTH], format[MAX_LINE_LENGTH];
10786   int nr;
10787 
10788   handle = fopen (datin, "r");
10789   if (handle==NULL)
10790   {
10791     printf (" ERROR in readlist: The input file \"%s\" could not be opened.\n\n", datin);
10792     return(-1);
10793   }
10794   else  printf ("\n%s opened",datin);
10795 
10796   length = 1;
10797   printf ("\n reading file\n");
10798 
10799   i=n=0;
10800   dotpos = strlen (datin);
10801   for (j=0; j<dotpos; j++) if (datin[j]=='/') n=j+1;
10802   for (j=n; j<dotpos; j++)
10803   {
10804     if (datin[j]=='.')
10805     {
10806        break;
10807     }
10808     else datin[i]=datin[j];
10809     i++;
10810   }
10811   datin[i]= '\0';
10812 
10813   /* initialize the set */
10814   if( (setNr=pre_seta( datin, "is", 0)) <0 ) return(-1);
10815 
10816   /* get the column */
10817   if(strlen(type)>1) column=atoi(&type[1])-1;
10818   else column=0;
10819 
10820   if((type[0]=='E')||(type[0]=='e'))
10821   {
10822     for (i=0; i<column; i++) sprintf(&format[i*4], "%%*s ");
10823     sprintf(&format[i*4], "%%d, %%s");
10824     while (length > -1)
10825     {
10826       length = frecord( handle, string);
10827       if( string[length]== (char)EOF)  break;
10828       n=sscanf(string, format, &nr, face );
10829       printf("rec:%d e:%d face:%s\n",n,nr,face);
10830       if(n)
10831       {
10832         printf (" seta %s e %d\n", datin, nr );
10833         seta( setNr, "e", nr );
10834         if(n==2) /* element face is provided */
10835 	{
10836           if(e_enqire[nr].type==1)
10837           {
10838 	    if(face[1]=='1')
10839             {
10840               seta( setNr, "n", e_enqire[nr].nod[0] );
10841               seta( setNr, "n", e_enqire[nr].nod[1] );
10842               seta( setNr, "n", e_enqire[nr].nod[2] );
10843               seta( setNr, "n", e_enqire[nr].nod[3] );
10844 	    }
10845 	    else if(face[1]=='2')
10846             {
10847               seta( setNr, "n", e_enqire[nr].nod[4] );
10848               seta( setNr, "n", e_enqire[nr].nod[5] );
10849               seta( setNr, "n", e_enqire[nr].nod[5] );
10850               seta( setNr, "n", e_enqire[nr].nod[7] );
10851 	    }
10852 	    else if(face[1]=='3')
10853             {
10854               seta( setNr, "n", e_enqire[nr].nod[0] );
10855               seta( setNr, "n", e_enqire[nr].nod[1] );
10856               seta( setNr, "n", e_enqire[nr].nod[5] );
10857               seta( setNr, "n", e_enqire[nr].nod[4] );
10858 	    }
10859 	    else if(face[1]=='4')
10860             {
10861               seta( setNr, "n", e_enqire[nr].nod[1] );
10862               seta( setNr, "n", e_enqire[nr].nod[2] );
10863               seta( setNr, "n", e_enqire[nr].nod[6] );
10864               seta( setNr, "n", e_enqire[nr].nod[5] );
10865 	    }
10866 	    else if(face[1]=='5')
10867             {
10868               seta( setNr, "n", e_enqire[nr].nod[2] );
10869               seta( setNr, "n", e_enqire[nr].nod[3] );
10870               seta( setNr, "n", e_enqire[nr].nod[7] );
10871               seta( setNr, "n", e_enqire[nr].nod[6] );
10872 	    }
10873 	    else if(face[1]=='6')
10874             {
10875               seta( setNr, "n", e_enqire[nr].nod[3] );
10876               seta( setNr, "n", e_enqire[nr].nod[0] );
10877               seta( setNr, "n", e_enqire[nr].nod[4] );
10878               seta( setNr, "n", e_enqire[nr].nod[7] );
10879 	    }
10880             else printf(" side:%s not supported\n", face);
10881 	  }
10882           else if(e_enqire[nr].type==6)
10883           {
10884 	    if(face[1]=='1')
10885             {
10886               seta( setNr, "n", e_enqire[nr].nod[0] );
10887               seta( setNr, "n", e_enqire[nr].nod[1] );
10888               seta( setNr, "n", e_enqire[nr].nod[2] );
10889               seta( setNr, "n", e_enqire[nr].nod[4] );
10890               seta( setNr, "n", e_enqire[nr].nod[5] );
10891               seta( setNr, "n", e_enqire[nr].nod[6] );
10892 	    }
10893 	    else if(face[1]=='2')
10894             {
10895               seta( setNr, "n", e_enqire[nr].nod[0] );
10896               seta( setNr, "n", e_enqire[nr].nod[1] );
10897               seta( setNr, "n", e_enqire[nr].nod[3] );
10898               seta( setNr, "n", e_enqire[nr].nod[4] );
10899               seta( setNr, "n", e_enqire[nr].nod[8] );
10900               seta( setNr, "n", e_enqire[nr].nod[7] );
10901 	    }
10902 	    else if(face[1]=='3')
10903             {
10904               seta( setNr, "n", e_enqire[nr].nod[1] );
10905               seta( setNr, "n", e_enqire[nr].nod[2] );
10906               seta( setNr, "n", e_enqire[nr].nod[3] );
10907               seta( setNr, "n", e_enqire[nr].nod[5] );
10908               seta( setNr, "n", e_enqire[nr].nod[9] );
10909               seta( setNr, "n", e_enqire[nr].nod[8] );
10910 	    }
10911 	    else if(face[1]=='4')
10912             {
10913               seta( setNr, "n", e_enqire[nr].nod[2] );
10914               seta( setNr, "n", e_enqire[nr].nod[0] );
10915               seta( setNr, "n", e_enqire[nr].nod[3] );
10916               seta( setNr, "n", e_enqire[nr].nod[6] );
10917               seta( setNr, "n", e_enqire[nr].nod[7] );
10918               seta( setNr, "n", e_enqire[nr].nod[9] );
10919 	    }
10920             else printf(" side:%s not supported\n", face);
10921 	  }
10922           else printf(" element type:%d not supported\n", e_enqire[nr].type);
10923 	}
10924       }
10925     }
10926   }
10927   else if((type[0]=='N')||(type[0]=='n'))
10928   {
10929     for (i=0; i<column; i++) sprintf(&format[i*4], "%%*s ");
10930     sprintf(&format[i*4], "%%d");
10931     while (length > -1)
10932     {
10933       length = frecord( handle, string);
10934       if( string[length]== (char)EOF)  break;
10935       n=sscanf((const char *)string, (const char *)format, &nr );
10936       printf("rec:%d n:%d\n",n,nr);
10937       if(n)
10938       {
10939         printf (" seta %s n %d\n", datin, nr );
10940         seta( setNr, "n", nr );
10941       }
10942     }
10943   }
10944   else printf (" ERROR: type %s not known\n", type );
10945   fclose(handle);
10946   printf ("\n A sequence of name:%s was created. Please use 'prnt sq' for listings \n\n", set[setNr].name );
10947   return(1);
10948 }
10949 
10950 
pre_norm(char * name)10951 void pre_norm(char *name)
10952 {
10953   int i,j, setNr, setcopy;
10954   int *sum_n=NULL;
10955   Nodes *norm=NULL;
10956 
10957   setNr=getSetNr(name);
10958   if (setNr<0)
10959   {
10960     printf (" ERROR: set:%s does not exist\n", name);
10961     goto errorPreNorm;
10962   }
10963 
10964   /* determine the normal based on all connected faces */
10965   delSet("+norm");
10966   setcopy=pre_seta( "+norm", "i", 0);
10967   if (setcopy<0)
10968   {
10969     errMsg (" ERROR: set:+norm could not be created\n" );
10970     goto errorPreNorm;
10971   }
10972   for (i=0; i<set[setNr].anz_n; i++)
10973   {
10974     seta( setcopy, "n", set[setNr].node[i] );
10975   }
10976   completeSet("+norm", "up") ;
10977   completeSet("+norm", "do") ;
10978   getNodeNormalen(&sum_n, &norm, setcopy, anz, face);
10979   delSet("+norm");
10980 
10981   for(i=0; i<set[setNr].anz_n; i++)
10982   {
10983     printf("node:%d norm:%f %f %f\n",set[setNr].node[i], norm[set[setNr].node[i]].nx, norm[set[setNr].node[i]].ny ,norm[set[setNr].node[i]].nz);
10984     if(valuestackFlag)
10985     {
10986       if ((valuestack = (char **)realloc( (char **)valuestack, (valuestack_ptr+4)*sizeof(char *)) ) == NULL )
10987       { printf("\n\nERROR: realloc failure, valuestack\n\n"); goto errorPreNorm; }
10988       for(j=0; j<4; j++)
10989       {
10990         if ((valuestack[valuestack_ptr+j] = (char *)malloc( MAX_LINE_LENGTH*sizeof(char)) ) == NULL )
10991         { printf("\n\nERROR: realloc failure, valuestack\n\n"); goto errorPreNorm; }
10992       }
10993       sprintf(valuestack[valuestack_ptr++],"%f", norm[set[setNr].node[i]].nz );
10994       sprintf(valuestack[valuestack_ptr++],"%f", norm[set[setNr].node[i]].ny );
10995       sprintf(valuestack[valuestack_ptr++],"%f", norm[set[setNr].node[i]].nx );
10996       sprintf(valuestack[valuestack_ptr++],"%d", set[setNr].node[i] );
10997       if(valuestackFlag) printf(" 4 values in inverse order written to stack\n");
10998     }
10999   }
11000  errorPreNorm:;
11001   free(sum_n);
11002   free(norm);
11003   return;
11004 }
11005 
pre_movie(char * string)11006 void pre_movie(char *string)
11007 {
11008   int i,j,k, length;
11009   static int delay=10;
11010   static int loops=0;
11011   double val1=0, val2=0;
11012   char type[MAX_LINE_LENGTH], name[MAX_LINE_LENGTH], movie[MAX_LINE_LENGTH];
11013   movie[0]=0;
11014   length=sscanf(string, "%s %lf %lf %s", type, &val1, &val2, movie );
11015 
11016   if (compareStrings(type, "delay")>0) { if(length==2) delay=100.*val1; else delay=10; }
11017   if (compareStrings(type, "loops")>0) { if(length==2) loops=val1; else loops=0; }
11018   if (compareStrings(type, "start")>0) { movieFlag=1; stopFlag=0; }
11019   if (compareStrings(type, "stop")>0)
11020   {
11021     printf("movie stopped, make movie with 'movie make <nr> <nr> [movie]'\n");
11022     printf("optionally define the delay-time between pictures with:'movie delay <sec>' before 'movi make'\n");
11023     printf("optionally reset the counter and delete the single frames with 'movi clean'\n");
11024     printf("you might use the program 'realplay' or 'firefox' to play the movie.gif file\n");
11025     movieFlag=0;
11026     sprintf( buffer, "rm -f  hcpy_0.tga %s", DEV_NULL2);
11027     system (buffer);
11028   }
11029   if (compareStrings(type, "frames")>0)
11030   {
11031     sprintf( buffer, "rm -f _*.gif %s", DEV_NULL2);
11032     system (buffer);
11033     gifNr=0;
11034     movieFlag=1;
11035     stopFlag=0;
11036     length=sscanf(string, "%*s %s %s", name, movie);
11037     if((length==1)&&(name[0]=='a'))
11038     { movieFrames=-1; movieCommandFile[0]=0; }
11039     else
11040     {
11041       movieFrames=(int)val1;
11042       length=sscanf(string, "%*s %*s %s", movieCommandFile);
11043       if(length<1) movieCommandFile[0]=0;
11044     }
11045     //printf("movieFrames:%d movieCommandFile:%s\n",movieCommandFile);
11046   }
11047   if (compareStrings(type, "clean")>0)
11048   {
11049     sprintf( buffer, "rm -f _*.gif %s", DEV_NULL2);
11050     system (buffer);
11051     gifNr=0;
11052   }
11053   if (compareStrings(type, "make")>0)
11054   {
11055     if(length==1) {  val2=gifNr, val1=1; length=3; }
11056     else if(length==2) {  val2=val1, val1=1; length=3; }
11057 
11058     if(length>2)
11059     {
11060       if(length==4)
11061       {
11062         printf("make movie from %s and pic:%d to %d, wait for ready\n", movie, (int)val1,(int)val2);
11063         sprintf( buffer, "cp %s movie.gif %s", movie, DEV_NULL2);
11064         system (buffer);
11065       }
11066       else
11067       {
11068         printf("make movie from pic:%d to %d, wait for ready\n", (int)val1,(int)val2);
11069         movie[0]=0;
11070       }
11071 
11072       /* generate movie from single gif files */
11073       j=k=0;
11074       for(i=(int)val1; i<=(int)val2; i++)
11075       {
11076         sprintf(&name[j*10], "_%d.gif     ",i); j++;
11077         if(j==9)
11078         {
11079   	j=0;
11080 	sprintf( buffer, "convert -loop %d -delay %d %s __%d.gif %s", loops, delay, name, k++,DEV_NULL2);
11081           system (buffer);
11082         }
11083       }
11084       if(j)
11085       {
11086         sprintf( buffer, "convert -loop %d -delay %d %s __%d.gif %s", loops, delay, name, k++,DEV_NULL2);
11087         system (buffer);
11088       }
11089 
11090       /* assemble all movies */
11091       j=0;
11092       for(i=0; i<k; i++)
11093       {
11094         sprintf(&name[j*12], "__%d.gif     ",i); j++;
11095         if(j==9)
11096         {
11097   	  j=0;
11098           if (i==9) sprintf( buffer, "convert -loop %d -delay %d %s %s movie.gif %s", loops, delay, movie, name,DEV_NULL2);
11099           else sprintf( buffer, "convert -loop %d -delay %d movie.gif %s movie.gif %s", loops, delay, name,DEV_NULL2);
11100           system (buffer);
11101         }
11102       }
11103       if(j)
11104       {
11105         if (k<9) sprintf( buffer, "convert -loop %d -delay %d %s %s movie.gif %s", loops, delay, movie, name,DEV_NULL2);
11106         else sprintf( buffer, "convert -loop %d -delay %d movie.gif %s movie.gif %s", loops, delay, name,DEV_NULL2);
11107         system (buffer);
11108       }
11109       sprintf( buffer, "rm __*.gif %s", DEV_NULL2);
11110       system (buffer);
11111       printf("\nready\n");
11112       printf("\nyou might use the program 'realplay' or 'firefox' to play the movie.gif file\n\n");
11113     }
11114     else
11115     {
11116       printf(" ERROR: make movie with 'movie make <nr> <nr> [movie]'\n");
11117     }
11118   }
11119 }
11120 
11121 
11122 
calcCoefficientsTet(int nslav,int * emas,int n_closest_tets,Nodes * node,Tetraeder * tet,double cof[4],int extrapolflag)11123 int calcCoefficientsTet(int nslav, int *emas, int n_closest_tets, Nodes *node, Tetraeder *tet, double cof[4], int extrapolflag)
11124 {
11125   int i,e=0;
11126   int secondLoopFlag=0;
11127   double v12[3], v13[3], v14[3], vn[3], sum=0.;
11128   int closestElem=0;
11129   double closestDist=-MAX_FLOAT;
11130 
11131   /* ----------------------------------------- */
11132   //int j, el=1;
11133   //FILE *handle;
11134   /* ----------------------------------------- */
11135 
11136   for(e=0; e<n_closest_tets; e++)
11137   {
11138     secondLoop:;
11139     /* ----------------------------------------- */
11140     /*
11141     handle = fopen ( "int.inp", "a");
11142     fprintf(handle,"*NODE, NSET=Nall\n");
11143     j=nslav;
11144     fprintf(handle," %d,%f,%f,%f\n", j,node[j].nx,node[j].ny,node[j].nz  );
11145     for (i=0; i<4; i++)
11146     {
11147       j=tet[emas[e]].n[i];
11148       fprintf(handle," %d,%f,%f,%f\n", j,node[j].nx,node[j].ny,node[j].nz  );
11149     }
11150     fprintf(handle,"*ELEMENTS, TYPE=C3D4\n");
11151     fprintf(handle," %d,%d,%d,%d,%d\n", el++, tet[emas[e]].n[0], tet[emas[e]].n[1], tet[emas[e]].n[2], nslav);
11152     fprintf(handle," %d,%d,%d,%d,%d\n", el++, tet[emas[e]].n[1], tet[emas[e]].n[3], tet[emas[e]].n[2], nslav);
11153     fprintf(handle," %d,%d,%d,%d,%d\n", el++, tet[emas[e]].n[2], tet[emas[e]].n[3], tet[emas[e]].n[0], nslav);
11154     fprintf(handle," %d,%d,%d,%d,%d\n", el++, tet[emas[e]].n[3], tet[emas[e]].n[1], tet[emas[e]].n[0], nslav);
11155     fclose(handle);
11156     */
11157     /* ----------------------------------------- */
11158 
11159     /* calc volu, coef of opposite node is volu/tot_volu */
11160 
11161     /* volu = 1/6 * a x b * c */
11162     v_result( &node[tet[emas[e]].n[0]].nx, &node[tet[emas[e]].n[1]].nx, v12);
11163     v_result( &node[tet[emas[e]].n[0]].nx, &node[tet[emas[e]].n[2]].nx, v13);
11164     v_result( &node[tet[emas[e]].n[0]].nx, &node[nslav].nx, v14);
11165     v_prod(v12,v13,vn);
11166     cof[3]=v_sprod(vn,v14)/6./tet[emas[e]].v;
11167 
11168     v_result( &node[tet[emas[e]].n[1]].nx, &node[tet[emas[e]].n[3]].nx, v12);
11169     v_result( &node[tet[emas[e]].n[1]].nx, &node[tet[emas[e]].n[2]].nx, v13);
11170     v_result( &node[tet[emas[e]].n[1]].nx, &node[nslav].nx, v14);
11171     v_prod(v12,v13,vn);
11172     cof[0]=v_sprod(vn,v14)/6./tet[emas[e]].v;
11173 
11174     v_result( &node[tet[emas[e]].n[2]].nx, &node[tet[emas[e]].n[3]].nx, v12);
11175     v_result( &node[tet[emas[e]].n[2]].nx, &node[tet[emas[e]].n[0]].nx, v13);
11176     v_result( &node[tet[emas[e]].n[2]].nx, &node[nslav].nx, v14);
11177     v_prod(v12,v13,vn);
11178     cof[1]=v_sprod(vn,v14)/6./tet[emas[e]].v;
11179 
11180     v_result( &node[tet[emas[e]].n[3]].nx, &node[tet[emas[e]].n[1]].nx, v12);
11181     v_result( &node[tet[emas[e]].n[3]].nx, &node[tet[emas[e]].n[0]].nx, v13);
11182     v_result( &node[tet[emas[e]].n[3]].nx, &node[nslav].nx, v14);
11183     v_prod(v12,v13,vn);
11184     cof[2]=v_sprod(vn,v14)/6./tet[emas[e]].v;
11185 
11186     if(printFlag) printf(" e:%d cof:%e %e %e %e\n", emas[e]+1, cof[0], cof[1], cof[2], cof[3]);
11187 
11188     if(secondLoopFlag) break;
11189 
11190     /* a negativ cof means the nslav is outside, try the next element */
11191     secondLoopFlag=1;
11192     sum=0.;
11193     for (i=0; i<4; i++)
11194     {
11195       if (cof[i]<0.)
11196       {
11197         sum+=cof[i];
11198         secondLoopFlag=0;
11199       }
11200     }
11201     if((sum<0.)&&(sum>closestDist)) { closestElem=e; closestDist=sum; }
11202     if(secondLoopFlag) break;
11203   }
11204   if(!secondLoopFlag)
11205   {
11206     /* take the element with the smallest negative cof */
11207     e=closestElem;
11208     secondLoopFlag=1;
11209     goto secondLoop;
11210   }
11211   if(e==n_closest_tets) return(-1);
11212 
11213   /* a negativ cof means the nslav is outside, set the cof to 0 and scale the rest to a sum of 1 */
11214   sum=0.;
11215   for (i=0; i<4; i++)
11216   {
11217     if (cof[i]<=0.)
11218     {
11219       if(extrapolflag==-1) return(-1);  // strict!
11220       if((extrapolflag==0)&&(cof[i]<-1.e-2)) return(-1); // relaxed!
11221       cof[i]=0.;
11222     }
11223     else sum+=cof[i];
11224   }
11225   if(sum>0) for (i=0; i<4; i++) cof[i]/=sum;
11226   else return(-1);
11227   return(emas[e]);
11228 }
11229 
11230 
11231 
11232 int glob_map3d=0;
thread_interpol3d(void * vargp)11233 void *thread_interpol3d(void *vargp)
11234 {
11235   int i,ii,j,e,n ;
11236   int set1, set2;
11237   int coarseFlag, extrapolflag;
11238   int ds=0, allds=0;
11239   int etet, tets=0, failedNodesSet;
11240   double  cof[4], dr, dx, dy, dz, tol;
11241 
11242   int near_node[N_CLOSEST_TETS];
11243   int     n_closest_nodes, n_closest_tets;
11244   int tetList[MAX_NR_OF_TETS_PER_ELEM];
11245 
11246   double *orig_x=NULL, *orig_y=NULL, *orig_z=NULL, *sort_x=NULL, *sort_y=NULL, *sort_z=NULL;
11247   int *sort_nx=NULL, *sort_ny=NULL, *sort_nz=NULL;
11248   double *orig_ex=NULL, *orig_ey=NULL, *orig_ez=NULL, *sort_ex=NULL, *sort_ey=NULL, *sort_ez=NULL;
11249   int *sort_enx=NULL, *sort_eny=NULL, *sort_enz=NULL;
11250 
11251   Tetraeder *tet;
11252   Nodes     *nod;
11253   Elements  *elem;
11254 
11255   Tetraeder *tet2;
11256   Tetraeder *tetbuf;
11257   Elements  elem2;
11258 
11259   typedef struct {
11260     Tetraeder *tet;
11261     Nodes     *nod;
11262     Elements  *elem;
11263     int vargi[9];
11264     double vargd[1];
11265     int *vargpi[6];
11266     double *vargpd[12];
11267   } Threadargs;
11268   Threadargs *param;
11269 
11270   param=(Threadargs *)vargp;
11271 
11272   tet=param->tet;
11273   nod=param->nod;
11274   elem=param->elem;
11275   tol=param->vargd[0];
11276   allds=param->vargi[2];
11277   set1=param->vargi[3];
11278   set2=param->vargi[4];
11279   extrapolflag=param->vargi[5];
11280   failedNodesSet=param->vargi[6];
11281   tets=param->vargi[7];
11282   ds=param->vargi[8];
11283   orig_x=param->vargpd[0];
11284   orig_y=param->vargpd[1];
11285   orig_z=param->vargpd[2];
11286   sort_x=param->vargpd[3];
11287   sort_y=param->vargpd[4];
11288   sort_z=param->vargpd[5];
11289   sort_nx=param->vargpi[0];
11290   sort_ny=param->vargpi[1];
11291   sort_nz=param->vargpi[2];
11292   orig_ex=param->vargpd[6];
11293   orig_ey=param->vargpd[7];
11294   orig_ez=param->vargpd[8];
11295   sort_ex=param->vargpd[9];
11296   sort_ey=param->vargpd[10];
11297   sort_ez=param->vargpd[11];
11298   sort_enx=param->vargpi[3];
11299   sort_eny=param->vargpi[4];
11300   sort_enz=param->vargpi[5];
11301 
11302 
11303   n_closest_nodes=1;
11304 
11305   while(1)
11306   {
11307     /* get the next node (i) */
11308     sem_wait(&sem_map3d);
11309     i=glob_map3d++;
11310     sem_post(&sem_map3d);
11311     if(i>=param->vargi[1]) break;
11312     //printf(" thread:%d node:%d tol:%e\n", param->vargi[0], set[set1].node[i], sqrt(tol));
11313 
11314     /* first, search for a close node */
11315     near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, node[set[set1].node[i]].nx,node[set[set1].node[i]].ny,
11316            node[set[set1].node[i]].nz, set[set2].anz_n, &near_node[0], n_closest_nodes);
11317     //for (j=0; j<n_closest_nodes; j++) printf("node:%d near node:%d \n",set[set1].node[i], set[set2].node[near_node[j]]);
11318     dx= node[set[set2].node[near_node[0]]].nx - node[set[set1].node[i]].nx;
11319     dy= node[set[set2].node[near_node[0]]].ny - node[set[set1].node[i]].ny;
11320     dz= node[set[set2].node[near_node[0]]].nz - node[set[set1].node[i]].nz;
11321     dr=dx*dx + dy*dy + dz*dz;
11322     if(dr<tol )
11323     {
11324       if(printFlag) printf("node:%d, found equal node:%d with dr:%lf\n", set[set1].node[i], set[set2].node[near_node[0]], sqrt(dr));
11325 
11326       /* interpolate */
11327       if(allds)
11328       {
11329         /* all datasets should be interpolated */
11330         for(ds=0; ds<anz->l; ds++)
11331         {
11332           for(e=0; e<lcase[ds].ncomps; e++)
11333           {
11334             lcase[ds].dat[e][set[set1].node[i]]=lcase[ds].dat[e][ set[set2].node[near_node[0]] ];
11335             //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][ set[set1].node[i] ]);
11336           }
11337         }
11338       }
11339       else
11340       {
11341         for(e=0; e<lcase[ds].ncomps; e++)
11342         {
11343           lcase[ds].dat[e][set[set1].node[i]]=lcase[ds].dat[e][ set[set2].node[near_node[0]] ];
11344           //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][ set[set1].node[i] ]);
11345         }
11346       }
11347       continue;
11348     }
11349 
11350     if((int)N_CLOSEST_TETS/10<tets)  n_closest_tets= (int)N_CLOSEST_TETS/10; else n_closest_tets= tets;
11351     coarseFlag=1;
11352   secondLoop:;
11353     /* if no close node exists, search a close element */
11354     near3d(orig_ex,orig_ey,orig_ez,sort_ex,sort_ey,sort_ez,sort_enx,sort_eny,sort_enz, node[set[set1].node[i]].nx,node[set[set1].node[i]].ny, node[set[set1].node[i]].nz, tets, &near_node[0], n_closest_tets);
11355     //for (j=0; j<n_closest_tets; j++) printf("node:%d nearest tets:%d \n",set[set1].node[i], near_node[j]+1);
11356 
11357     etet=calcCoefficientsTet(set[set1].node[i], &near_node[0], n_closest_tets, node, tet, cof, extrapolflag);
11358     if(etet==-1)
11359     {
11360       if(coarseFlag) { coarseFlag=0; n_closest_tets*=10; goto secondLoop; }
11361       printf(" WARNING: no interpolation possible for node:%d\n", set[set1].node[i]);
11362       sem_wait(&sem_n);
11363       seta(failedNodesSet,"n",set[set1].node[i]);
11364       sem_post(&sem_n);
11365       continue;
11366     }
11367     //printf("node:%d near tet:%d \n",set[set1].node[i], etet+1);
11368 
11369     if((e_enqire[elem[tet[etet].e].nr].type==4)||(e_enqire[elem[tet[etet].e].nr].type==6))
11370     {
11371       //printf("create finer tets for elem:%d\n",elem[tet[etet].e].nr);
11372       e=elem[tet[etet].e].nr;
11373       elem2.type=e_enqire[e].type;
11374       elem2.nr=e;
11375       for (j=0; j<26; j++) elem2.nod[j]=e_enqire[e].nod[j];
11376 
11377       j = splitElementsToTets(1, nod, &elem2, &tet2);
11378 
11379       /* delete unusable tets (small volume) */
11380       e=0;
11381       for(ii=0; ii<j; ii++)
11382       {
11383         if(tet2[ii].v<SMALL_TET_VOLUME) { continue; }
11384         if(e<ii)
11385         {
11386           for(n=0;n<4; n++) tet2[e].n[n]=tet2[ii].n[n];
11387           for(n=0;n<3; n++) tet2[e].cg[n]=tet2[ii].cg[n];
11388           tet2[e].v=tet2[ii].v;
11389           tet2[e].e=tet2[ii].e;
11390         }
11391         e++;
11392       }
11393 
11394       //printf(" %d finer tets created\n", e);
11395       for(j=0; j<e; j++) tetList[j]=j;
11396       etet=calcCoefficientsTet(set[set1].node[i], &tetList[0], e, node, tet2, cof, extrapolflag);
11397       //printf("closest tet:%d\n", etet);
11398 
11399       /* temporary switch the tet pointer to the tet2 pointer */
11400       tetbuf=tet;
11401       //printf("switch the tet pointer forth %d\n", tetbuf);
11402       tet=tet2;
11403     }
11404     else tetbuf=0;
11405 
11406     /* interpolate */
11407     if(allds)
11408     {
11409       /* all datasets should be interpolated */
11410       for(ds=0; ds<anz->l; ds++)
11411       {
11412         for(e=0; e<lcase[ds].ncomps; e++)
11413         {
11414           if(etet>=0)
11415           {
11416             //printf("ds:%d e:%d etet:%d \n",ds+1,e+1, etet);
11417             //for(j=0; j<4; j++) printf("n:%d val*cof: %f %f = %f\n",tet[etet].n[j], lcase[ds].dat[e][tet[etet].n[j]], cof[j], lcase[ds].dat[e][tet[etet].n[j]]*cof[j]);
11418             lcase[ds].dat[e][set[set1].node[i]]=0.;
11419             for(j=0; j<4; j++) lcase[ds].dat[e][set[set1].node[i]]+=lcase[ds].dat[e][tet[etet].n[j]]*cof[j];
11420 
11421             //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][set[set1].node[i]]);
11422           }
11423         }
11424       }
11425     }
11426     else
11427     {
11428       for(e=0; e<lcase[ds].ncomps; e++)
11429       {
11430         if(etet>-1)
11431         {
11432           //printf("ds:%d e:%d etet:%d \n",ds+1,e+1, etet);
11433           //for(j=0; j<4; j++) printf("n:%d val*cof: %f %f = %f\n",tet[etet].n[j], lcase[ds].dat[e][tet[etet].n[j]],cof[j], lcase[ds].dat[e][tet[etet].n[j]]*cof[j]);
11434           lcase[ds].dat[e][set[set1].node[i]]=0.;
11435           for(j=0; j<4; j++) lcase[ds].dat[e][set[set1].node[i]]+=lcase[ds].dat[e][tet[etet].n[j]]*cof[j];
11436 
11437           //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][set[set1].node[i]]);
11438         }
11439 
11440       }
11441     }
11442     if(tetbuf)
11443     {
11444       /* switch the tet pointer back */
11445       //printf("switch the tet pointer back %d\n", tetbuf);
11446       tet=tetbuf;
11447       tetbuf=0;
11448     }
11449   }
11450 
11451   return((void *)1);
11452 }
11453 
11454 
11455 
11456 /* return 0: ok, -1: no datasets, else setNr with nodes which could not be mapped */
interpol3d(int set1,int set2,char * format,char * dataset,int extrapolflag)11457 int interpol3d(int set1, int set2, char *format, char *dataset, int extrapolflag)
11458 {
11459 
11460 #if NOTHREADING
11461   // from here on initialization w/o subroutine
11462 
11463   int i,ii,j,n,e;
11464   int ds=0, allds=0;
11465   int etet, tets=0, n1,n2, elnr, failedNodesSet, coarseFlag;
11466   double cof[4], dr, dx, dy, dz,tol;
11467   static Elements  *elem=NULL;
11468   static Nodes     *nod=NULL;
11469   static Tetraeder *tet=NULL;
11470   static Rsort *rsort=NULL;
11471 
11472   static double *orig_x=NULL, *orig_y=NULL, *orig_z=NULL, *sort_x=NULL, *sort_y=NULL, *sort_z=NULL;
11473   static int *sort_nx=NULL, *sort_ny=NULL, *sort_nz=NULL, near_node[N_CLOSEST_TETS];
11474   int     n_closest_nodes;
11475 
11476   static double *orig_ex=NULL, *orig_ey=NULL, *orig_ez=NULL, *sort_ex=NULL, *sort_ey=NULL, *sort_ez=NULL;
11477   static int *sort_enx=NULL, *sort_eny=NULL, *sort_enz=NULL;
11478   int     n_closest_tets;
11479 
11480   static Elements  elem2;
11481   static Tetraeder *tet2=NULL;
11482   static Tetraeder *tetbuf=0;
11483   static int tetList[MAX_NR_OF_TETS_PER_ELEM];
11484 
11485 #else
11486   // initialization w subroutine for threading (less variables needed)
11487   int i,j,n,e;
11488   int ds=0, allds=0;
11489   int tets=0, n1,n2, elnr, failedNodesSet;
11490   double tol;
11491   Elements  *elem=NULL;
11492   Nodes     *nod=NULL;
11493   Tetraeder *tet=NULL;
11494   Rsort *rsort=NULL;
11495 
11496   double *orig_x=NULL, *orig_y=NULL, *orig_z=NULL, *sort_x=NULL, *sort_y=NULL, *sort_z=NULL;
11497   int *sort_nx=NULL, *sort_ny=NULL, *sort_nz=NULL;
11498   double *orig_ex=NULL, *orig_ey=NULL, *orig_ez=NULL, *sort_ex=NULL, *sort_ey=NULL, *sort_ez=NULL;
11499   int *sort_enx=NULL, *sort_eny=NULL, *sort_enz=NULL;
11500 
11501   typedef struct {
11502     Tetraeder *tet;
11503     Nodes     *nod;
11504     Elements  *elem;
11505     int vargi[9];
11506     double vargd[1];
11507     int *vargpi[6];
11508     double *vargpd[12];
11509   } Threadargs;
11510   Threadargs *targ=NULL;
11511   pthread_t *tid=NULL;
11512   int nlocalThreads;
11513   int threads=NTHREADS_MAX;
11514 #endif
11515 
11516 #if TEST
11517   double volu=0, cg[3]={0,0,0};
11518   FILE *handle;
11519 #endif
11520 
11521   printf("interpol3d\n");
11522   tol=gtol;
11523   tol*=tol;
11524 
11525   if ( (nod = (Nodes *)realloc( (Nodes *)nod, (anz->nmax+1) * sizeof(Nodes))) == NULL )
11526   {
11527     printf("WARNING: realloc error interpol3d\n");
11528   }
11529   if((elem = (Elements *)realloc( (Elements *)elem, (set[set2].anz_e) * sizeof(Elements))) == NULL )
11530   {
11531     printf("WARNING: realloc error interpol3d\n");
11532   }
11533   for (j=1; j<=anz->nmax; j++)
11534   {
11535     nod[j].nx=node[j].nx;
11536     nod[j].ny=node[j].ny;
11537     nod[j].nz=node[j].nz;
11538   }
11539   for (i=0; i<set[set2].anz_e; i++)
11540   {
11541     e=set[set2].elem[i];
11542     if(e_enqire[e].type==4) elem[i].type=1;
11543     else if(e_enqire[e].type==6) elem[i].type=3;
11544     else elem[i].type=e_enqire[e].type;
11545     elem[i].nr=e;
11546     for (j=0; j<26; j++) elem[i].nod[j]=e_enqire[e].nod[j];
11547   }
11548 
11549   if(dataset[0]=='d')
11550   {
11551     if(compareStrings( dataset, "ds" )>0)
11552     {
11553       /* all datasets should be interpolated */
11554       for(ds=0; ds<anz->l; ds++)
11555       {
11556         for(e=0; e<lcase[ds].ncomps; e++)
11557           printf(" interpol:%s entity:%s\n", lcase[ds].name, lcase[ds].compName[e]);
11558         /* check if the data of the specified lcase (Dataset) are already available */
11559         if (!lcase[ds].loaded)
11560         {
11561           if( pre_readfrdblock(copiedNodeSets , ds, anz, node, lcase )==-1)
11562           {
11563             printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", ds+1);
11564     	    return(-1);
11565           }
11566           calcDatasets( ds, anz, node, lcase );
11567           recompileEntitiesInMenu(ds);
11568         }
11569       }
11570       allds=1;
11571     }
11572     else
11573     {
11574       ds=atoi(&dataset[2])-1;
11575       if((ds<0)||(ds>anz->l-1)) { printf(" specified Dataset:%d not available\n",ds); return(-1); }
11576       for(e=0; e<lcase[ds].ncomps; e++)
11577         printf(" interpol:%s entity:%s\n", lcase[ds].name, lcase[ds].compName[e]);
11578       /* check if the data of the specified lcase (Dataset) are already available */
11579       if (!lcase[ds].loaded)
11580       {
11581         if( pre_readfrdblock(copiedNodeSets , ds, anz, node, lcase )==-1)
11582         {
11583           printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", ds+1);
11584           return(-1);
11585         }
11586         calcDatasets( ds, anz, node, lcase );
11587         recompileEntitiesInMenu(ds);
11588       }
11589     }
11590   }
11591   else { printf(" Dataset not given for interpolation of data\n"); return(-1); }
11592 
11593 
11594   /* split elements into tet's (with cg and volu) */
11595   tets = splitElementsToTets(set[set2].anz_e, nod, elem, &tet);
11596   if(!tets) { printf(" No 3D master elements found\n"); return(set1); }
11597 
11598   /* delete unusable tets (small volume) */
11599   j=0;
11600   for(i=0; i<tets; i++)
11601   {
11602     if(tet[i].v<SMALL_TET_VOLUME) { if(printFlag) printf("Scip Tet:%d vol:%e < SMALL_TET_VOLUME\n", i, tet[i].v); continue; }
11603     if(j<i)
11604     {
11605       for(n=0;n<4; n++) tet[j].n[n]=tet[i].n[n];
11606       for(n=0;n<3; n++) tet[j].cg[n]=tet[i].cg[n];
11607       tet[j].v=tet[i].v;
11608       tet[j].e=tet[i].e;
11609     }
11610     j++;
11611   }
11612   tets=j;
11613   if(printFlag) printf(" %d tets created\n", tets);
11614 
11615 #if TEST
11616   handle = fopen ( "tets.inp", "w");
11617   fprintf(handle,"*NODE, NSET=Nall\n");
11618   for (i=0; i<anz->n; i++)
11619   {
11620     j=node[i].nr;
11621     //if( node[j].pflag == 0)
11622       fprintf(handle," %d,%f,%f,%f\n", j,node[j].nx,node[j].ny,node[j].nz  );
11623   }
11624   fprintf(handle,"*NODE, NSET=CG\n");
11625   for(i=0; i<tets; i++)
11626   {
11627     fprintf(handle," %d,%f,%f,%f\n", i+anz->nmax+1, tet[i].cg[0], tet[i].cg[1], tet[i].cg[2] );
11628     cg[0]+=tet[i].cg[0];
11629     cg[1]+=tet[i].cg[1];
11630     cg[2]+=tet[i].cg[2];
11631   }
11632   cg[0]/=tets;
11633   cg[1]/=tets;
11634   cg[2]/=tets;
11635   fprintf(handle,"*ELEMENTS, TYPE=C3D4\n");
11636   for(i=0; i<tets; i++)
11637   {
11638     fprintf(handle," %d,%d,%d,%d,%d\n", i+1, tet[i].n[0], tet[i].n[1], tet[i].n[2], tet[i].n[3]);
11639   }
11640   fprintf(handle,"*TEMPERATURE\nNall,0.\n");
11641   for(i=0; i<tets; i++)
11642   {
11643     fprintf(handle," %d,%e\n", i+anz->nmax+1,  tet[i].v );
11644     volu+=tet[i].v;
11645   }
11646   //printf("v:%f cg:%f %f %f\n",volu*scale->w*scale->w*scale->w,cg[0]* scale->w+scale->x,cg[1]* scale->w+scale->y,cg[2]* scale->w+scale->z);
11647   fclose(handle);
11648 #endif
11649 
11650   /* extend the datasets by the midface nodes later used in the process */
11651   if(allds)
11652   {
11653     /* all datasets should be interpolated */
11654     for(ds=0; ds<anz->l; ds++)
11655     {
11656       for(e=0; e<lcase[ds].ncomps; e++)
11657       {
11658         if((lcase[ds].dat[e] = (float *)realloc(lcase[ds].dat[e], (anz->nmax+1) * sizeof(float))) == NULL )
11659           printf("\n\n ERROR: realloc failure\n");
11660         /* block from nodalDataset() */
11661         for ( j=0; j<set[set2].anz_e; j++ )
11662         {
11663           elnr=set[set2].elem[j];
11664           switch(e_enqire[elnr].type)
11665           {
11666             case 4:
11667             for (n=0; n<3; n++)  /* create new vals at nodes in center of areas */
11668             {
11669               lcase[ds].dat[e][e_enqire[elnr].nod[20+n]] = -0.25* (
11670                 lcase[ds].dat[e][e_enqire[elnr].nod[0+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[1+n]]    +
11671                 lcase[ds].dat[e][e_enqire[elnr].nod[5+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[4+n]] )  + 0.5*(
11672                 lcase[ds].dat[e][e_enqire[elnr].nod[8+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[13+n]]   +
11673                 lcase[ds].dat[e][e_enqire[elnr].nod[16+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[12+n]]) ;
11674             }
11675               lcase[ds].dat[e][e_enqire[elnr].nod[23]] = -0.25* (
11676                 lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[0]]    +
11677                 lcase[ds].dat[e][e_enqire[elnr].nod[4]]+lcase[ds].dat[e][e_enqire[elnr].nod[7]] )  + 0.5*(
11678                 lcase[ds].dat[e][e_enqire[elnr].nod[11]]+lcase[ds].dat[e][e_enqire[elnr].nod[12]]   +
11679                 lcase[ds].dat[e][e_enqire[elnr].nod[19]]+lcase[ds].dat[e][e_enqire[elnr].nod[15]]) ;
11680             for (n=0; n<2; n++)
11681             {
11682               n1=n*4;
11683               n2=n*8;
11684               lcase[ds].dat[e][e_enqire[elnr].nod[24+n]] = -0.25* (
11685                 lcase[ds].dat[e][e_enqire[elnr].nod[0+n1]]+lcase[ds].dat[e][e_enqire[elnr].nod[1+n1]]    +
11686                 lcase[ds].dat[e][e_enqire[elnr].nod[2+n1]]+lcase[ds].dat[e][e_enqire[elnr].nod[3+n1]] )  + 0.5*(
11687                 lcase[ds].dat[e][e_enqire[elnr].nod[8+n2]]+lcase[ds].dat[e][e_enqire[elnr].nod[9+n2]]   +
11688                 lcase[ds].dat[e][e_enqire[elnr].nod[10+n2]]+lcase[ds].dat[e][e_enqire[elnr].nod[11+n2]]) ;
11689             }
11690             break;
11691 
11692 
11693             case 5:
11694             for (n=0; n<2; n++)
11695             {
11696               lcase[ds].dat[e][e_enqire[elnr].nod[15+n]] = -0.25* (
11697                 lcase[ds].dat[e][e_enqire[elnr].nod[0+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[1+n]]    +
11698                 lcase[ds].dat[e][e_enqire[elnr].nod[4+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[3+n]] )  + 0.5*(
11699                 lcase[ds].dat[e][e_enqire[elnr].nod[6+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[10+n]]   +
11700                 lcase[ds].dat[e][e_enqire[elnr].nod[12+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 9+n]]) ;
11701             }
11702               lcase[ds].dat[e][e_enqire[elnr].nod[17]] = -0.25* (
11703                 lcase[ds].dat[e][e_enqire[elnr].nod[2]]+lcase[ds].dat[e][e_enqire[elnr].nod[0]]    +
11704                 lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[5]] )  + 0.5*(
11705                 lcase[ds].dat[e][e_enqire[elnr].nod[ 8]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 9]]   +
11706                 lcase[ds].dat[e][e_enqire[elnr].nod[14]]+lcase[ds].dat[e][e_enqire[elnr].nod[11]]) ;
11707               lcase[ds].dat[e][e_enqire[elnr].nod[18]] = -0.25* (
11708                 lcase[ds].dat[e][e_enqire[elnr].nod[0]]+lcase[ds].dat[e][e_enqire[elnr].nod[2]]    +
11709                 lcase[ds].dat[e][e_enqire[elnr].nod[1]]+lcase[ds].dat[e][e_enqire[elnr].nod[0]] )  + 0.5*(
11710                 lcase[ds].dat[e][e_enqire[elnr].nod[ 8]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 7]]   +
11711                 lcase[ds].dat[e][e_enqire[elnr].nod[ 6]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 0]]) ;
11712               lcase[ds].dat[e][e_enqire[elnr].nod[19]] = -0.25* (
11713                 lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[4]]    +
11714                 lcase[ds].dat[e][e_enqire[elnr].nod[5]]+lcase[ds].dat[e][e_enqire[elnr].nod[3]] )  + 0.5*(
11715                 lcase[ds].dat[e][e_enqire[elnr].nod[12]]+lcase[ds].dat[e][e_enqire[elnr].nod[13]]   +
11716                 lcase[ds].dat[e][e_enqire[elnr].nod[14]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 3]]) ;
11717             break;
11718 
11719 
11720             case 10:
11721             lcase[ds].dat[e][e_enqire[elnr].nod[8]] = -0.25* (
11722             lcase[ds].dat[e][e_enqire[elnr].nod[0]]+lcase[ds].dat[e][e_enqire[elnr].nod[1]] +
11723             lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[2]])+0.5*(
11724             lcase[ds].dat[e][e_enqire[elnr].nod[4]]+lcase[ds].dat[e][e_enqire[elnr].nod[6]] +
11725             lcase[ds].dat[e][e_enqire[elnr].nod[7]]+lcase[ds].dat[e][e_enqire[elnr].nod[5]]);
11726             break;
11727           }
11728         }
11729 	  /* end block */
11730       }
11731     }
11732   }
11733   else
11734   {
11735     for(e=0; e<lcase[ds].ncomps; e++)
11736     {
11737         if((lcase[ds].dat[e] = (float *)realloc(lcase[ds].dat[e], (anz->nmax+1) * sizeof(float))) == NULL )
11738           printf("\n\n ERROR: realloc failure\n");
11739         /* block from nodalDataset() */
11740         for ( j=0; j<set[set2].anz_e; j++ )
11741         {
11742           elnr=set[set2].elem[j];
11743           switch(e_enqire[elnr].type)
11744           {
11745             case 4:
11746             for (n=0; n<3; n++)  /* create new vals at nodes in center of areas */
11747             {
11748               lcase[ds].dat[e][e_enqire[elnr].nod[20+n]] = -0.25* (
11749                 lcase[ds].dat[e][e_enqire[elnr].nod[0+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[1+n]]    +
11750                 lcase[ds].dat[e][e_enqire[elnr].nod[5+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[4+n]] )  + 0.5*(
11751                 lcase[ds].dat[e][e_enqire[elnr].nod[8+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[13+n]]   +
11752                 lcase[ds].dat[e][e_enqire[elnr].nod[16+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[12+n]]) ;
11753             }
11754               lcase[ds].dat[e][e_enqire[elnr].nod[23]] = -0.25* (
11755                 lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[0]]    +
11756                 lcase[ds].dat[e][e_enqire[elnr].nod[4]]+lcase[ds].dat[e][e_enqire[elnr].nod[7]] )  + 0.5*(
11757                 lcase[ds].dat[e][e_enqire[elnr].nod[11]]+lcase[ds].dat[e][e_enqire[elnr].nod[12]]   +
11758                 lcase[ds].dat[e][e_enqire[elnr].nod[19]]+lcase[ds].dat[e][e_enqire[elnr].nod[15]]) ;
11759             for (n=0; n<2; n++)
11760             {
11761               n1=n*4;
11762               n2=n*8;
11763               lcase[ds].dat[e][e_enqire[elnr].nod[24+n]] = -0.25* (
11764                 lcase[ds].dat[e][e_enqire[elnr].nod[0+n1]]+lcase[ds].dat[e][e_enqire[elnr].nod[1+n1]]    +
11765                 lcase[ds].dat[e][e_enqire[elnr].nod[2+n1]]+lcase[ds].dat[e][e_enqire[elnr].nod[3+n1]] )  + 0.5*(
11766                 lcase[ds].dat[e][e_enqire[elnr].nod[8+n2]]+lcase[ds].dat[e][e_enqire[elnr].nod[9+n2]]   +
11767                 lcase[ds].dat[e][e_enqire[elnr].nod[10+n2]]+lcase[ds].dat[e][e_enqire[elnr].nod[11+n2]]) ;
11768             }
11769             break;
11770 
11771 
11772             case 5:
11773             for (n=0; n<2; n++)
11774             {
11775               lcase[ds].dat[e][e_enqire[elnr].nod[15+n]] = -0.25* (
11776                 lcase[ds].dat[e][e_enqire[elnr].nod[0+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[1+n]]    +
11777                 lcase[ds].dat[e][e_enqire[elnr].nod[4+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[3+n]] )  + 0.5*(
11778                 lcase[ds].dat[e][e_enqire[elnr].nod[6+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[10+n]]   +
11779                 lcase[ds].dat[e][e_enqire[elnr].nod[12+n]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 9+n]]) ;
11780             }
11781               lcase[ds].dat[e][e_enqire[elnr].nod[17]] = -0.25* (
11782                 lcase[ds].dat[e][e_enqire[elnr].nod[2]]+lcase[ds].dat[e][e_enqire[elnr].nod[0]]    +
11783                 lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[5]] )  + 0.5*(
11784                 lcase[ds].dat[e][e_enqire[elnr].nod[ 8]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 9]]   +
11785                 lcase[ds].dat[e][e_enqire[elnr].nod[14]]+lcase[ds].dat[e][e_enqire[elnr].nod[11]]) ;
11786               lcase[ds].dat[e][e_enqire[elnr].nod[18]] = -0.25* (
11787                 lcase[ds].dat[e][e_enqire[elnr].nod[0]]+lcase[ds].dat[e][e_enqire[elnr].nod[2]]    +
11788                 lcase[ds].dat[e][e_enqire[elnr].nod[1]]+lcase[ds].dat[e][e_enqire[elnr].nod[0]] )  + 0.5*(
11789                 lcase[ds].dat[e][e_enqire[elnr].nod[ 8]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 7]]   +
11790                 lcase[ds].dat[e][e_enqire[elnr].nod[ 6]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 0]]) ;
11791               lcase[ds].dat[e][e_enqire[elnr].nod[19]] = -0.25* (
11792                 lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[4]]    +
11793                 lcase[ds].dat[e][e_enqire[elnr].nod[5]]+lcase[ds].dat[e][e_enqire[elnr].nod[3]] )  + 0.5*(
11794                 lcase[ds].dat[e][e_enqire[elnr].nod[12]]+lcase[ds].dat[e][e_enqire[elnr].nod[13]]   +
11795                 lcase[ds].dat[e][e_enqire[elnr].nod[14]]+lcase[ds].dat[e][e_enqire[elnr].nod[ 3]]) ;
11796             break;
11797 
11798 
11799             case 10:
11800             lcase[ds].dat[e][e_enqire[elnr].nod[8]] = -0.25* (
11801             lcase[ds].dat[e][e_enqire[elnr].nod[0]]+lcase[ds].dat[e][e_enqire[elnr].nod[1]] +
11802             lcase[ds].dat[e][e_enqire[elnr].nod[3]]+lcase[ds].dat[e][e_enqire[elnr].nod[2]])+0.5*(
11803             lcase[ds].dat[e][e_enqire[elnr].nod[4]]+lcase[ds].dat[e][e_enqire[elnr].nod[6]] +
11804             lcase[ds].dat[e][e_enqire[elnr].nod[7]]+lcase[ds].dat[e][e_enqire[elnr].nod[5]]);
11805             break;
11806           }
11807         }
11808 	  /* end block */
11809     }
11810   }
11811 
11812   printf(" start interpolation\n");
11813 
11814   /* create set for failed nodes */
11815   delSet("-notMapped");
11816   failedNodesSet=pre_seta("-notMapped","i",0);
11817 
11818   if(set[set2].anz_n>tets)
11819   {
11820     if ( (rsort = (Rsort *)malloc( (set[set2].anz_n+1) * sizeof(Rsort))) == NULL )
11821       printf("ERROR: realloc failed: Rsort\n\n" );
11822   }
11823   else
11824   {
11825     if ( (rsort = (Rsort *)malloc( (tets+1) * sizeof(Rsort))) == NULL )
11826       printf("ERROR: realloc failed: Rsort\n\n" );
11827   }
11828 
11829   /* get the close node */
11830   /* search the closest node */
11831   if ( (orig_x = (double *)malloc( (set[set2].anz_n+1) * sizeof(double))) == NULL )
11832     printf("ERROR: realloc failed \n\n" );
11833   if ( (orig_y = (double *)malloc( (set[set2].anz_n+1) * sizeof(double))) == NULL )
11834     printf("ERROR: realloc failed \n\n" );
11835   if ( (orig_z = (double *)malloc( (set[set2].anz_n+1) * sizeof(double))) == NULL )
11836     printf("ERROR: realloc failed \n\n" );
11837   if ( (sort_x = (double *)malloc( (set[set2].anz_n+1) * sizeof(double))) == NULL )
11838     printf("ERROR: realloc failed \n\n" );
11839   if ( (sort_y = (double *)malloc( (set[set2].anz_n+1) * sizeof(double))) == NULL )
11840     printf("ERROR: realloc failed \n\n" );
11841   if ( (sort_z = (double *)malloc( (set[set2].anz_n+1) * sizeof(double))) == NULL )
11842     printf("ERROR: realloc failed \n\n" );
11843   if ( (sort_nx = (int *)malloc( (set[set2].anz_n+1) * sizeof(int))) == NULL )
11844     printf("ERROR: realloc failed \n\n" );
11845   if ( (sort_ny = (int *)malloc( (set[set2].anz_n+1) * sizeof(int))) == NULL )
11846     printf("ERROR: realloc failed \n\n" );
11847   if ( (sort_nz = (int *)malloc( (set[set2].anz_n+1) * sizeof(int))) == NULL )
11848     printf("ERROR: realloc failed \n\n" );
11849   for(i=0; i<set[set2].anz_n; i++)
11850   {
11851     rsort[i].r=orig_x[i]=node[set[set2].node[i]].nx;
11852     rsort[i].i=i;
11853   }
11854   qsort( rsort, set[set2].anz_n, sizeof(Rsort), (void *)compareRsort );
11855   for(i=0; i<set[set2].anz_n; i++)
11856   {
11857     sort_x[i]=rsort[i].r;
11858     sort_nx[i]=rsort[i].i;
11859   }
11860   for(i=0; i<set[set2].anz_n; i++)
11861   {
11862     rsort[i].r=orig_y[i]=node[set[set2].node[i]].ny;
11863     rsort[i].i=i;
11864   }
11865   qsort( rsort, set[set2].anz_n, sizeof(Rsort), (void *)compareRsort );
11866   for(i=0; i<set[set2].anz_n; i++)
11867   {
11868     sort_y[i]=rsort[i].r;
11869     sort_ny[i]=rsort[i].i;
11870   }
11871   for(i=0; i<set[set2].anz_n; i++)
11872   {
11873     rsort[i].r=orig_z[i]=node[set[set2].node[i]].nz;
11874     rsort[i].i=i;
11875   }
11876   qsort( rsort, set[set2].anz_n, sizeof(Rsort), (void *)compareRsort );
11877   for(i=0; i<set[set2].anz_n; i++)
11878   {
11879     sort_z[i]=rsort[i].r;
11880     sort_nz[i]=rsort[i].i;
11881   }
11882 
11883   /* get the close tets */
11884   /* search the closest elements based on the closest cg */
11885   if ( (orig_ex = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
11886     printf("ERROR: realloc failed \n\n" );
11887   if ( (orig_ey = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
11888     printf("ERROR: realloc failed \n\n" );
11889   if ( (orig_ez = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
11890     printf("ERROR: realloc failed \n\n" );
11891   if ( (sort_ex = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
11892     printf("ERROR: realloc failed \n\n" );
11893   if ( (sort_ey = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
11894     printf("ERROR: realloc failed \n\n" );
11895   if ( (sort_ez = (double *)malloc( (tets+1) * sizeof(double))) == NULL )
11896     printf("ERROR: realloc failed \n\n" );
11897   if ( (sort_enx = (int *)malloc( (tets+1) * sizeof(int))) == NULL )
11898     printf("ERROR: realloc failed \n\n" );
11899   if ( (sort_eny = (int *)malloc( (tets+1) * sizeof(int))) == NULL )
11900     printf("ERROR: realloc failed \n\n" );
11901   if ( (sort_enz = (int *)malloc( (tets+1) * sizeof(int))) == NULL )
11902     printf("ERROR: realloc failed \n\n" );
11903   for(i=0; i<tets; i++)
11904   {
11905     rsort[i].r=orig_ex[i]=tet[i].cg[0];
11906     rsort[i].i=i;
11907   }
11908   qsort( rsort, tets, sizeof(Rsort), (void *)compareRsort );
11909   for(i=0; i<tets; i++)
11910   {
11911     sort_ex[i]=rsort[i].r;
11912     sort_enx[i]=rsort[i].i;
11913   }
11914   for(i=0; i<tets; i++)
11915   {
11916     rsort[i].r=orig_ey[i]=tet[i].cg[1];
11917     rsort[i].i=i;
11918   }
11919   qsort( rsort, tets, sizeof(Rsort), (void *)compareRsort );
11920   for(i=0; i<tets; i++)
11921   {
11922     sort_ey[i]=rsort[i].r;
11923     sort_eny[i]=rsort[i].i;
11924   }
11925   for(i=0; i<tets; i++)
11926   {
11927     rsort[i].r=orig_ez[i]=tet[i].cg[2];
11928     rsort[i].i=i;
11929   }
11930   qsort( rsort, tets, sizeof(Rsort), (void *)compareRsort );
11931   for(i=0; i<tets; i++)
11932   {
11933     sort_ez[i]=rsort[i].r;
11934     sort_enz[i]=rsort[i].i;
11935   }
11936 
11937 #if NOTHREADING
11938 
11939   n_closest_nodes=1;
11940 
11941   //while(1)
11942   for (i=0; i<set[set1].anz_n; i++ )
11943   {
11944     /* get the next node (i) */
11945     //if(sem_wait(&sem_map3d)) printf("Error in:sem_wait\n");
11946     //i=glob_map3d++;
11947     //if(sem_post(&sem_map3d)) printf("Error in:sem_post\n");
11948     //if(i>=param->vargi[1]) break;
11949     //printf(" nothread node:%d tol:%e\n", set[set1].node[i], tol);
11950 
11951     /* first, search for a close node */
11952     near3d(orig_x,orig_y,orig_z,sort_x,sort_y,sort_z,sort_nx,sort_ny,sort_nz, node[set[set1].node[i]].nx,node[set[set1].node[i]].ny,
11953            node[set[set1].node[i]].nz, set[set2].anz_n, &near_node[0], n_closest_nodes);
11954     //for (j=0; j<n_closest_nodes; j++) printf("node:%d near node:%d \n",set[set1].node[i], set[set2].node[near_node[j]]);
11955     dx= node[set[set2].node[near_node[0]]].nx - node[set[set1].node[i]].nx;
11956     dy= node[set[set2].node[near_node[0]]].ny - node[set[set1].node[i]].ny;
11957     dz= node[set[set2].node[near_node[0]]].nz - node[set[set1].node[i]].nz;
11958     dr=dx*dx + dy*dy + dz*dz;
11959     if(dr<tol )
11960     {
11961       if(printFlag) printf("node:%d, found equal node:%d with dr:%lf\n", set[set1].node[i], set[set2].node[near_node[0]], sqrt(dr));
11962 
11963       /* interpolate */
11964       if(allds)
11965       {
11966         /* all datasets should be interpolated */
11967         for(ds=0; ds<anz->l; ds++)
11968         {
11969           for(e=0; e<lcase[ds].ncomps; e++)
11970           {
11971             lcase[ds].dat[e][set[set1].node[i]]=lcase[ds].dat[e][ set[set2].node[near_node[0]] ];
11972             //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][ set[set1].node[i] ]);
11973           }
11974         }
11975       }
11976       else
11977       {
11978         for(e=0; e<lcase[ds].ncomps; e++)
11979         {
11980           lcase[ds].dat[e][set[set1].node[i]]=lcase[ds].dat[e][ set[set2].node[near_node[0]] ];
11981           //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][ set[set1].node[i] ]);
11982         }
11983       }
11984       continue;
11985     }
11986 
11987     if((int)N_CLOSEST_TETS/10<tets)  n_closest_tets= (int)N_CLOSEST_TETS/10; else n_closest_tets= tets;
11988     coarseFlag=1;
11989   secondLoop:;
11990     /* if no close node exists, search a close element */
11991     near3d(orig_ex,orig_ey,orig_ez,sort_ex,sort_ey,sort_ez,sort_enx,sort_eny,sort_enz, node[set[set1].node[i]].nx,node[set[set1].node[i]].ny, node[set[set1].node[i]].nz, tets, &near_node[0], n_closest_tets);
11992     //for (j=0; j<n_closest_tets; j++) printf("node:%d nearest tets:%d \n",set[set1].node[i], near_node[j]+1);
11993 
11994     etet=calcCoefficientsTet(set[set1].node[i], &near_node[0], n_closest_tets, node, tet, cof, extrapolflag);
11995     if(etet==-1)
11996     {
11997       if(coarseFlag) { coarseFlag=0; n_closest_tets*=10; goto secondLoop; }
11998       printf(" WARNING: no interpolation possible for node:%d\n", set[set1].node[i]);
11999       //sem_wait(&sem_g);
12000       seta(failedNodesSet,"n",set[set1].node[i]);
12001       //sem_post(&sem_g);
12002       continue;
12003     }
12004     //printf("node:%d near tet:%d \n",set[set1].node[i], etet+1);
12005 
12006     if((e_enqire[elem[tet[etet].e].nr].type==4)||(e_enqire[elem[tet[etet].e].nr].type==6))
12007     {
12008       //printf("create finer tets for elem:%d\n",elem[tet[etet].e].nr);
12009       e=elem[tet[etet].e].nr;
12010       elem2.type=e_enqire[e].type;
12011       elem2.nr=e;
12012       for (j=0; j<26; j++) elem2.nod[j]=e_enqire[e].nod[j];
12013 
12014       j = splitElementsToTets(1, nod, &elem2, &tet2);
12015 
12016       /* delete unusable tets (small volume) */
12017       e=0;
12018       for(ii=0; ii<j; ii++)
12019       {
12020         if(tet2[ii].v<SMALL_TET_VOLUME) { continue; }
12021         if(e<ii)
12022         {
12023           for(n=0;n<4; n++) tet2[e].n[n]=tet2[ii].n[n];
12024           for(n=0;n<3; n++) tet2[e].cg[n]=tet2[ii].cg[n];
12025           tet2[e].v=tet2[ii].v;
12026           tet2[e].e=tet2[ii].e;
12027         }
12028         e++;
12029       }
12030 
12031       //printf(" %d finer tets created\n", e);
12032       for(j=0; j<e; j++) tetList[j]=j;
12033       etet=calcCoefficientsTet(set[set1].node[i], &tetList[0], e, node, tet2, cof, extrapolflag);
12034       //printf("closest tet:%d\n", etet);
12035 
12036       /* temporary switch the tet pointer to the tet2 pointer */
12037       tetbuf=tet;
12038       //printf("switch the tet pointer forth %d\n", tetbuf);
12039       tet=tet2;
12040     }
12041     else tetbuf=0;
12042 
12043     /* interpolate */
12044     if(allds)
12045     {
12046       /* all datasets should be interpolated */
12047       for(ds=0; ds<anz->l; ds++)
12048       {
12049         for(e=0; e<lcase[ds].ncomps; e++)
12050         {
12051           if(etet>=0)
12052           {
12053             //printf("ds:%d e:%d etet:%d \n",ds+1,e+1, etet);
12054             //for(j=0; j<4; j++) printf("n:%d val*cof: %f %f = %f\n",tet[etet].n[j], lcase[ds].dat[e][tet[etet].n[j]], cof[j], lcase[ds].dat[e][tet[etet].n[j]]*cof[j]);
12055             lcase[ds].dat[e][set[set1].node[i]]=0.;
12056             for(j=0; j<4; j++) lcase[ds].dat[e][set[set1].node[i]]+=lcase[ds].dat[e][tet[etet].n[j]]*cof[j];
12057 
12058             //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][set[set1].node[i]]);
12059           }
12060         }
12061       }
12062     }
12063     else
12064     {
12065       for(e=0; e<lcase[ds].ncomps; e++)
12066       {
12067         if(etet>-1)
12068         {
12069           //printf("ds:%d e:%d etet:%d \n",ds+1,e+1, etet);
12070           //for(j=0; j<4; j++) printf("n:%d val*cof: %f %f = %f\n",tet[etet].n[j], lcase[ds].dat[e][tet[etet].n[j]],cof[j], lcase[ds].dat[e][tet[etet].n[j]]*cof[j]);
12071           lcase[ds].dat[e][set[set1].node[i]]=0.;
12072           for(j=0; j<4; j++) lcase[ds].dat[e][set[set1].node[i]]+=lcase[ds].dat[e][tet[etet].n[j]]*cof[j];
12073 
12074           //printf("n:%d value:%f\n", set[set1].node[i], lcase[ds].dat[e][set[set1].node[i]]);
12075         }
12076 
12077       }
12078     }
12079     if(tetbuf)
12080     {
12081       /* switch the tet pointer back */
12082       //printf("switch the tet pointer back %d\n", tetbuf);
12083       tet=tetbuf;
12084       tetbuf=0;
12085     }
12086   }
12087 
12088 #else
12089 
12090   if(sem_init(&sem_map3d, 0, 1) < 0) printf("Error in:sem_init\n");
12091   if(threads>set[set1].anz_n) { nlocalThreads=set[set1].anz_n; }
12092   else nlocalThreads=threads;
12093   //nlocalThreads=1;
12094   if ((tid=(pthread_t *)realloc((pthread_t *)tid, nlocalThreads*sizeof(pthread_t)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
12095   if ((targ=(Threadargs *)realloc((Threadargs *)targ, nlocalThreads*sizeof(Threadargs)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return(-1);}
12096 
12097   for(i=0; i<nlocalThreads; i++)
12098   {
12099     targ[i].tet                   = tet;
12100     targ[i].nod                   = nod;
12101     targ[i].elem                 = elem;
12102     targ[i].vargd[0]              = tol;
12103     targ[i].vargi[0]                 =i;
12104     targ[i].vargi[1]   =set[set1].anz_n;
12105     targ[i].vargi[2]            = allds;
12106     targ[i].vargi[3]             = set1;
12107     targ[i].vargi[4]             = set2;
12108     targ[i].vargi[5]     = extrapolflag;
12109     targ[i].vargi[6]   = failedNodesSet;
12110     targ[i].vargi[7]             = tets;
12111     targ[i].vargi[8]               = ds;
12112     targ[i].vargpd[0]          = orig_x;
12113     targ[i].vargpd[1]          = orig_y;
12114     targ[i].vargpd[2]          = orig_z;
12115     targ[i].vargpd[3]          = sort_x;
12116     targ[i].vargpd[4]          = sort_y;
12117     targ[i].vargpd[5]          = sort_z;
12118     targ[i].vargpi[0]         = sort_nx;
12119     targ[i].vargpi[1]         = sort_ny;
12120     targ[i].vargpi[2]         = sort_nz;
12121     targ[i].vargpd[6]         = orig_ex;
12122     targ[i].vargpd[7]         = orig_ey;
12123     targ[i].vargpd[8]         = orig_ez;
12124     targ[i].vargpd[9]         = sort_ex;
12125     targ[i].vargpd[10]        = sort_ey;
12126     targ[i].vargpd[11]        = sort_ez;
12127     targ[i].vargpi[3]        = sort_enx;
12128     targ[i].vargpi[4]        = sort_eny;
12129     targ[i].vargpi[5]        = sort_enz;
12130     //thread_interpol3d((void *)&targ[i]);
12131     pthread_create(&tid[i],NULL,thread_interpol3d,(void *)&targ[i]);
12132   }
12133   for(i=0; i<nlocalThreads; i++)
12134   {
12135     pthread_join(tid[i], NULL);
12136   }
12137   glob_map3d=0;
12138   free(tid); tid=NULL;
12139   free(targ); targ=NULL;
12140   if(sem_destroy(&sem_map3d) < 0) printf("Error in:sem_init\n");
12141 #endif
12142 
12143   if(rsort) free(rsort);
12144   if(orig_x) free(orig_x);
12145   if(orig_y) free(orig_y);
12146   if(orig_z) free(orig_z);
12147   if(sort_x) free(sort_x);
12148   if(sort_y) free(sort_y);
12149   if(sort_z) free(sort_z);
12150   if(sort_nx) free(sort_nx);
12151   if(sort_ny) free(sort_ny);
12152   if(sort_nz) free(sort_nz);
12153 
12154   if(orig_ex) free(orig_ex);
12155   if(orig_ey) free(orig_ey);
12156   if(orig_ez) free(orig_ez);
12157   if(sort_ex) free(sort_ex);
12158   if(sort_ey) free(sort_ey);
12159   if(sort_ez) free(sort_ez);
12160   if(sort_enx) free(sort_enx);
12161   if(sort_eny) free(sort_eny);
12162   if(sort_enz) free(sort_enz);
12163 
12164   free(nod);
12165   free(elem);
12166   free(tet);
12167   nod=NULL;
12168   elem=NULL;
12169 
12170   printf("done\n");
12171   return(failedNodesSet);
12172 }
12173 
12174 
12175 
brecord(char * rec_str,char dat[MAX_PARAM_IN_BRECORD][MAX_LINE_LENGTH])12176 int brecord( char *rec_str, char dat[MAX_PARAM_IN_BRECORD][MAX_LINE_LENGTH])
12177 {
12178   int i, length;
12179   int nextarg=0, letter=0;
12180 
12181   length=strlen(rec_str);
12182   /* scan all args divided by comma */
12183   nextarg=0;letter=0;
12184   for(i=0; i<=length; i++)
12185   {
12186     if(rec_str[i]==(char)EOF) {dat[nextarg][letter]='\0';  break; }
12187     if(rec_str[i]=='\n') {dat[nextarg][letter]='\0';  break; }
12188     if(rec_str[i]==0) {dat[nextarg][letter]='\0';  break; }
12189     if((rec_str[i]==' ')&&(letter))
12190     {
12191       dat[nextarg][letter]='\0';
12192       nextarg++;
12193       letter=0;
12194       if(nextarg>=MAX_PARAM_IN_BRECORD) { printf("ERROR: too much parameters in line:\n%s\n\n", rec_str); exit(1); }
12195     }
12196     else
12197     {
12198       if((rec_str[i]>32)&& (rec_str[i]<127))
12199       {
12200         dat[nextarg][letter]=rec_str[i];
12201         letter++;
12202         if(nextarg>=MAX_LINE_LENGTH) { printf("ERROR: brecord, increase MAX_LINE_LENGTH in extUtil.h\n\n"); exit(1); }
12203       }
12204     }
12205   }
12206   if(dat[nextarg][0]=='\0') return(nextarg);
12207   return(nextarg+1);
12208 }
12209 
12210 
12211 
pre_eprop(char * setname)12212 void pre_eprop(char *setname)
12213 {
12214   int i,j,n,nr,ipuf,setNr;
12215   double dmin,dv[8][3],area,l,lmax,r,quality;
12216 
12217   int istat[3]={0,0,0};
12218   double vole, x[20],y[20],z[20];
12219   double xcge, ycge, zcge;
12220   double xl[20][3], cg[3],vn[3];
12221   char elty[MAX_LINE_LENGTH];
12222 
12223   setNr=getSetNr(setname);
12224   if (setNr<0)
12225   {
12226     printf (" set:%s does not exist\n", setname);
12227     return;
12228   }
12229   printf (" create new dataset: EPROP for set:%s\n", set[setNr].name);
12230 
12231   /* create a new dataset */
12232   if ( (lcase = (Datasets *)realloc((Datasets *)lcase, (anz->l+1) * sizeof(Datasets))) == NULL )
12233     printf("\n\n ERROR: malloc failure\n\n" );
12234 
12235   lcase[anz->l].ncomps = 3;
12236   lcase[anz->l].irtype = 1;
12237   lcase[anz->l].npheader  = 0 ;
12238   lcase[anz->l].value  = 0. ;
12239   strcpy(lcase[anz->l].name,"EPROP") ;
12240   sprintf( lcase[anz->l].dataset_name,"");
12241   strcpy(lcase[anz->l].dataset_text,set[setNr].name);
12242   strcpy(lcase[anz->l].analysis_name,"");
12243   lcase[anz->l].step_number=-1;
12244   lcase[anz->l].analysis_type=1;
12245   lcase[anz->l].loaded = 1;
12246   lcase[anz->l].fileptr = NULL;
12247 
12248   if ( (lcase[anz->l].nmax = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12249     printf("\n\n ERROR: malloc failure\n\n" );
12250   if ( (lcase[anz->l].nmin = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12251     printf("\n\n ERROR: malloc failure\n\n" );
12252   if ( (lcase[anz->l].max = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
12253     printf("\n\n ERROR: malloc failure\n\n" );
12254   if ( (lcase[anz->l].min = (float *)malloc( lcase[anz->l].ncomps * sizeof(float))) == NULL )
12255     printf("\n\n ERROR: malloc failure\n\n" );
12256   if ( (lcase[anz->l].dat = (float **)malloc( lcase[anz->l].ncomps * sizeof(float *))) == NULL )
12257     printf("\n\n ERROR: malloc failure\n\n" );
12258   if ( (lcase[anz->l].compName = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
12259     printf("\n\n ERROR: malloc failure\n\n" );
12260   if ( (lcase[anz->l].icname = (char **)malloc( lcase[anz->l].ncomps * sizeof(char *))) == NULL )
12261     printf("\n\n ERROR: malloc failure\n\n" );
12262   for(i=0; i<lcase[anz->l].ncomps; i++)
12263   {
12264     if ( (lcase[anz->l].dat[i] = (float *)malloc( (anz->nmax+1) * sizeof(float))) == NULL )
12265       printf("\n\n ERROR: malloc failure\n\n" );
12266     if ( (lcase[anz->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
12267        printf("\n\n ERROR: malloc failed\n\n" );
12268     if ( (lcase[anz->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
12269        printf("\n\n ERROR: malloc failed\n\n" );
12270     lcase[anz->l].max[i]=-MAX_INTEGER;
12271     lcase[anz->l].min[i]=MAX_INTEGER;
12272     lcase[anz->l].nmax[i]=0;
12273     lcase[anz->l].nmin[i]=0;
12274     for(n=0; n<=anz->nmax; n++)
12275       lcase[anz->l].dat[i][n]=0.;
12276   }
12277   if ( (lcase[anz->l].menu = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12278     printf("\n\n ERROR: malloc failure\n\n" );
12279   if ( (lcase[anz->l].ictype = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12280     printf("\n\n ERROR: malloc failure\n\n" );
12281   if ( (lcase[anz->l].icind1 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12282     printf("\n\n ERROR: malloc failure\n\n" );
12283   if ( (lcase[anz->l].icind2 = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12284     printf("\n\n ERROR: malloc failure\n\n" );
12285   if ( (lcase[anz->l].iexist = (int *)malloc( lcase[anz->l].ncomps * sizeof(int))) == NULL )
12286     printf("\n\n ERROR: malloc failure\n\n" );
12287   for(i=0; i<lcase[anz->l].ncomps; i++)
12288   {
12289     lcase[anz->l].menu[i] = 1;
12290     lcase[anz->l].ictype[i] = 1;
12291     lcase[anz->l].icind1[i] = 1;
12292     lcase[anz->l].icind2[i] = 0;
12293     lcase[anz->l].iexist[i] = 0;
12294   }
12295   sprintf( lcase[anz->l].compName[0],"1/DMIN");
12296   sprintf( lcase[anz->l].compName[1],"1/VOLU");
12297   sprintf( lcase[anz->l].compName[2],"Flatness");
12298 
12299   /** store the minimum distance between a given node and its closest neighbor **/
12300 
12301   /* initialize */
12302   for(i=0; i<lcase[anz->l].ncomps; i++)
12303   {
12304     for(n=0; n<anz->n; n++)
12305     {
12306       lcase[anz->l].dat[i][node[n].nr]=0.;
12307     }
12308   }
12309 
12310   /* go over all elements  */
12311   ipuf=0;
12312   for(i=0; i<set[setNr].anz_e; i++)
12313   {
12314     /* store the edge length if lower than already stored */
12315     if (e_enqire[set[setNr].elem[i]].type == 1) ipuf = 8;  /* HEXA8 */
12316     else if (e_enqire[set[setNr].elem[i]].type == 4) ipuf = 8;  /* HEXA20 as HEXA8 */
12317     else if (e_enqire[set[setNr].elem[i]].type == 2) ipuf = 6;  /* PENTA6 */
12318     else if (e_enqire[set[setNr].elem[i]].type == 5) ipuf = 6;  /* PENTA15 as PENTA6*/
12319     else if (e_enqire[set[setNr].elem[i]].type == 3) ipuf = 4;  /* TET4 */
12320     else if (e_enqire[set[setNr].elem[i]].type == 6) ipuf = 4;  /* TET10 as TET4 */
12321     else if (e_enqire[set[setNr].elem[i]].type == 7) ipuf = 3;  /* TRI3  */
12322     else if (e_enqire[set[setNr].elem[i]].type == 8) ipuf = 3;  /* TRI6 as TRI3  */
12323     else if (e_enqire[set[setNr].elem[i]].type == 9) ipuf = 4;  /* QUAD4 */
12324     else if (e_enqire[set[setNr].elem[i]].type == 10) ipuf = 4; /* QUAD8 as QUAD4*/
12325     else if (e_enqire[set[setNr].elem[i]].type == 11) ipuf = 2; /* BEAM2 */
12326     else if (e_enqire[set[setNr].elem[i]].type == 12) ipuf = 2; /* BEAM3 as BEAM2 */
12327     else printf("elem %d of type %d not supported\n", set[setNr].elem[i],e_enqire[set[setNr].elem[i]].type);
12328     for (n=0; n<ipuf; n++)
12329     {
12330       if(n==ipuf-1) v_result(&node[e_enqire[set[setNr].elem[i]].nod[n]].nx, &node[e_enqire[set[setNr].elem[i]].nod[0]].nx,dv[n]);
12331       else v_result(&node[e_enqire[set[setNr].elem[i]].nod[n]].nx, &node[e_enqire[set[setNr].elem[i]].nod[n+1]].nx,dv[n]);
12332       dmin=1./(v_betrag(dv[n])*scale->w);
12333       if(dmin>lcase[anz->l].dat[0][e_enqire[set[setNr].elem[i]].nod[n]]) lcase[anz->l].dat[0][e_enqire[set[setNr].elem[i]].nod[n]]=dmin;
12334     }
12335 
12336     /* store the volume if lower than already stored  */
12337     /* code from pre_volu() */
12338     /*
12339      In addition
12340      calculate the element quality. The measure used is proportional
12341      to the ratio of the longest edge divided by the radius of the
12342      inscribed sphere. The proportionality constant is such that
12343      the quality is 1 for an equilateral tetrahedron. For all other
12344      elements it exceeds 1. The bigger this number, the worse the
12345      quality
12346     */
12347     nr=set[setNr].elem[i];
12348     if(e_enqire[nr].type==1)
12349     {
12350       for(j=0; j<8; j++)
12351       {
12352         xl[j][0]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
12353         xl[j][1]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
12354         xl[j][2]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
12355 	//printf("xyz: %f %f %f\n", xl[j][0],xl[j][1],xl[j][2]);
12356       }
12357       strcpy(elty,"C3D8");
12358       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
12359       dmin=1./vole;
12360       for (j=0;  j<8; j++)
12361       {
12362         if(dmin>lcase[anz->l].dat[1][e_enqire[nr].nod[j]]) lcase[anz->l].dat[1][e_enqire[nr].nod[j]]=dmin;
12363       }
12364     }
12365     else if(e_enqire[nr].type==4)
12366     {
12367       for(j=0; j<12; j++)
12368       {
12369         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[j]].nx* scale->w+scale->x;
12370         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[j]].ny* scale->w+scale->y;
12371         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[j]].nz* scale->w+scale->z;
12372       }
12373       for(n=16; n<20; n++)
12374       {
12375         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
12376         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
12377         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
12378         j++;
12379       }
12380       for(n=12; n<16; n++)
12381       {
12382         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
12383         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
12384         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
12385         j++;
12386       }
12387       strcpy(elty,"C3D20");
12388       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
12389       dmin=1./vole;
12390       for (j=0;  j<20; j++)
12391       {
12392         if(dmin>lcase[anz->l].dat[1][e_enqire[nr].nod[j]]) lcase[anz->l].dat[1][e_enqire[nr].nod[j]]=dmin;
12393       }
12394     }
12395     else if(e_enqire[nr].type==2)
12396     {
12397       for(j=0; j<6; j++)
12398       {
12399         xl[j][0]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
12400         xl[j][1]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
12401         xl[j][2]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
12402 	//printf("xyz: %f %f %f\n", xl[j][0],xl[j][1],xl[j][2]);
12403       }
12404       strcpy(elty,"C3D6");
12405       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
12406       dmin=1./vole;
12407       for (j=0;  j<6; j++)
12408       {
12409         if(dmin>lcase[anz->l].dat[1][e_enqire[nr].nod[j]]) lcase[anz->l].dat[1][e_enqire[nr].nod[j]]=dmin;
12410       }
12411     }
12412     else if(e_enqire[nr].type==5)
12413     {
12414       for(j=0; j<9; j++)
12415       {
12416         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[j]].nx* scale->w+scale->x;
12417         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[j]].ny* scale->w+scale->y;
12418         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[j]].nz* scale->w+scale->z;
12419       }
12420       for(n=12; n<15; n++)
12421       {
12422         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
12423         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
12424         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
12425         j++;
12426       }
12427       for(n=9; n<12; n++)
12428       {
12429         xl[j][0]= node[e_enqire[set[setNr].elem[i]].nod[n]].nx* scale->w+scale->x;
12430         xl[j][1]= node[e_enqire[set[setNr].elem[i]].nod[n]].ny* scale->w+scale->y;
12431         xl[j][2]= node[e_enqire[set[setNr].elem[i]].nod[n]].nz* scale->w+scale->z;
12432         j++;
12433       }
12434       strcpy(elty,"C3D15");
12435       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
12436       dmin=1./vole;
12437       for (j=0;  j<15; j++)
12438       {
12439         if(dmin>lcase[anz->l].dat[1][e_enqire[nr].nod[j]]) lcase[anz->l].dat[1][e_enqire[nr].nod[j]]=dmin;
12440       }
12441     }
12442     else if(e_enqire[nr].type==3)
12443     {
12444       for(j=0; j<4; j++)
12445       {
12446         x[j]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
12447         y[j]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
12448         z[j]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
12449       }
12450       tetraeder_(&nr, istat, x,y,z, &vole, &xcge, &ycge, &zcge );
12451       dmin=1./vole;
12452 
12453       /*  calculating area of each face in the element */
12454       area=0.;
12455       for (n=0;  n<4; n++)
12456       {
12457         if(n==3) v_prod( dv[n], dv[0], vn );
12458 	else v_prod( dv[n], dv[n+1], vn );
12459         area+=v_betrag(vn)*scale->w*scale->w;
12460       }
12461       area*=.5;
12462 
12463       // radius of the inscribed sphere
12464       r=3.*vole/area;
12465 
12466       // maximum edge length
12467       lmax=0;
12468       for (n=0;  n<4; n++)
12469       {
12470 	l=v_betrag(dv[n]);
12471 	if( lmax<l) lmax=l;
12472       }
12473       lmax*=scale->w;
12474       // quality, alpha=sqrt(6.)/12.=0.20412;
12475       if(r>0.) quality=0.20412*lmax/r;
12476       else quality=MAX_FLOAT;
12477       printf("Volu:%f Area:%f lmax:%f r:%f quality: %f\n", vole, area, lmax, r, quality);
12478 
12479       for (j=0;  j<4; j++)
12480       {
12481         if(dmin>lcase[anz->l].dat[1][e_enqire[nr].nod[j]]) lcase[anz->l].dat[1][e_enqire[nr].nod[j]]=dmin;
12482         if(quality>lcase[anz->l].dat[2][e_enqire[nr].nod[j]]) lcase[anz->l].dat[2][e_enqire[nr].nod[j]]=quality;
12483       }
12484     }
12485     else if(e_enqire[nr].type==6)
12486     {
12487       for(j=0; j<10; j++)
12488       {
12489         xl[j][0]=node[e_enqire[nr].nod[j]].nx*scale->w+scale->x;
12490         xl[j][1]=node[e_enqire[nr].nod[j]].ny*scale->w+scale->y;
12491         xl[j][2]=node[e_enqire[nr].nod[j]].nz*scale->w+scale->z;
12492 	//printf("xyz: %f %f %f\n", xl[j][0],xl[j][1],xl[j][2]);
12493       }
12494       strcpy(elty,"C3D10");
12495       e_c3d_volu_(&xl[0][0], elty, &vole, cg);
12496       dmin=1./vole;
12497 
12498       /*  calculating area of each face in the element */
12499       area=0.;
12500       for (n=0;  n<4; n++)
12501       {
12502         if(n==3) v_prod( dv[n], dv[0], vn );
12503 	else v_prod( dv[n], dv[n+1], vn );
12504         area+=v_betrag(vn)*scale->w*scale->w;
12505       }
12506       area*=.5;
12507 
12508       // radius of the inscribed sphere
12509       r=3.*vole/area;
12510 
12511       // maximum edge length
12512       lmax=0;
12513       for (n=0;  n<4; n++)
12514       {
12515 	l=v_betrag(dv[n]);
12516 	if( lmax<l) lmax=l;
12517       }
12518       lmax*=scale->w;
12519       // quality, alpha=sqrt(6.)/12.=0.20412;
12520       if(r>0.) quality=0.20412*lmax/r;
12521       else quality=MAX_FLOAT;
12522       // printf("Volu:%f Area:%f lmax:%f r:%f quality: %f\n", vole, area, lmax, r, quality);
12523 
12524       for (j=0;  j<10; j++)
12525       {
12526         if(dmin>lcase[anz->l].dat[1][e_enqire[nr].nod[j]]) lcase[anz->l].dat[1][e_enqire[nr].nod[j]]=dmin;
12527         if(quality>lcase[anz->l].dat[2][e_enqire[nr].nod[j]]) lcase[anz->l].dat[2][e_enqire[nr].nod[j]]=quality;
12528       }
12529     }
12530     else
12531     {
12532       printf("ERROR: type:%d of elem:%d not known. Interrupt\n",e_enqire[nr].type,nr);
12533       return;
12534     }
12535   }
12536 
12537   /* search max min */
12538   for(i=0; i<lcase[anz->l].ncomps; i++)
12539   {
12540     for(n=0; n<anz->n; n++)
12541     {
12542       if (lcase[anz->l].dat[i][node[n].nr] >  lcase[anz->l].max[i])
12543       {  lcase[anz->l].max[i]=lcase[anz->l].dat[i][node[n].nr]; lcase[anz->l].nmax[i]=node[n].nr;}
12544       if (lcase[anz->l].dat[i][node[n].nr] <  lcase[anz->l].min[i])
12545       {  lcase[anz->l].min[i]=lcase[anz->l].dat[i][node[n].nr]; lcase[anz->l].nmin[i]=node[n].nr;}
12546     }
12547   }
12548 
12549   anz->l++;
12550   calcDatasets( anz->l-1, anz, node, lcase );
12551   recompileEntitiesInMenu(anz->l-1);
12552   if(activWindow!=-1) createDatasetEntries();
12553 }
12554 
12555 
pre_nurs(char * string,int addFlag)12556 int pre_nurs(char *string, int addFlag)
12557 {
12558   int i,ii,j,jj,k,n,m,s;
12559   int length, ps, nr, setNr, ibuf, sum_div;
12560   char  name[MAX_LINE_LENGTH], comm[MAX_LINE_LENGTH], buffer[MAX_LINE_LENGTH];
12561   int  lnew[2], cl[2];
12562   char typnew[2];
12563   int edge[MAX_EDGES_PER_SURF];                 /* lines/lcmb for the meshable substitute surface with 4 edges */
12564   char  ctyp[MAX_EDGES_PER_SURF];      /*   type: l=line c=lcmb */
12565   char  cori[MAX_EDGES_PER_SURF];      /*   l-orient +- */
12566 
12567   length = sscanf( string, "%s%s%s", name, comm, buffer  );
12568 
12569   /* check if a set of blended surfaces should make nurbs. The surfaces will use this nurbs */
12570   if((length==2) && ( name[0] == '!' ))
12571   {
12572     setNr=getSetNr(comm);
12573     if(setNr<0)
12574     {
12575       printf("ERROR: Set:[%s] does not exist\n",comm);
12576       return(-2);
12577     }
12578     setall=getSetNr("all");
12579     /* try to create a nurbs if no shape is assigned */
12580     ibuf=set[setNr].anz_s;
12581     for ( i=0; i<ibuf; i++)
12582     {
12583       nr = set[setNr].surf[i];
12584       if (surf[nr].sh<=-1)
12585       {
12586         /* nurbs need 4 edges, create a temporary surf if the requirement is violated */
12587         if (surf[nr].nl==4)
12588 	{
12589           s=nr;
12590           k=createBlendedNurbs(s);
12591 	}
12592         else if (surf[nr].nl==2)
12593         {
12594           ps=splitLineAtDivratio( surf[nr].l[0], surf[nr].typ[0], 0.5, edge, ctyp);
12595           if (ps==-1) { return(-1); }
12596           if(surf[nr].o[0]=='-')
12597           {
12598             n=edge[0];
12599             m=ctyp[0];
12600             edge[0]=edge[1];
12601             ctyp[0]=ctyp[1];
12602             edge[1]=n;
12603             ctyp[1]=m;
12604           }
12605           ps=splitLineAtDivratio( surf[nr].l[1], surf[nr].typ[1], 0.5, &edge[2], &ctyp[2]);
12606           if (ps==-1) { return(-1); }
12607 
12608           /* create a 4 sided surf */
12609           for (jj=0; jj<4; jj+=2) { cori[jj]=cori[jj+1]=surf[nr].o[jj]; }
12610           getNewName( name, "s" );
12611           s=surface_i( name, surf[nr].ori, surf[nr].sh, (int)4, cori, edge, ctyp );
12612           if( s<0) { printf("ERROR: surface could not be created\n"); return(-1); }
12613           if(printFlag) printf(" temp. surf[%d]:%s generated\n",s, surf[s].name);
12614           k=createBlendedNurbs(s);
12615           delLine( 4, &edge[0] );
12616           delSurf( 1, &s );
12617         }
12618         else if (surf[nr].nl==3)
12619         {
12620           /* choose an edge with has no rest for the equation division/4 in case elements have quadratic formulation */
12621           for (ii=0; ii<3; ii++)
12622           {
12623             if(( surf[nr].typ[ii]=='l')&&(!(line[surf[nr].l[ii]].div%4))) break;
12624             else if( line[surf[nr].l[ii]].typ=='c')
12625             {
12626               sum_div=0;
12627               for(jj=0; jj<lcmb[surf[nr].l[ii]].nl; jj++) sum_div+=line[lcmb[surf[nr].l[ii]].l[jj]].div;
12628               if (!(sum_div%4)) break;
12629   	    }
12630           }
12631           /* no mesh if no suitable edge exists */
12632           if(ii==3) ii=2;
12633           ps=splitLineAtDivratio( surf[nr].l[ii], surf[nr].typ[ii], 0.5, lnew, typnew);
12634           if (ps==-1) { return(-1); }
12635 
12636           /* create a 4 sided surf */
12637           for (jj=0; jj<ii; jj++)
12638           {
12639             edge[jj]=surf[nr].l[jj];
12640             cori[jj]=surf[nr].o[jj];
12641             ctyp[jj]=surf[nr].typ[jj];
12642           }
12643           if(surf[nr].o[ii]=='+') { n=0; m=1; } else { n=1; m=0; }
12644           edge[jj]=lnew[n];
12645           cori[jj]=surf[nr].o[ii];
12646           ctyp[jj]=typnew[n];
12647           jj++;
12648           edge[jj]=lnew[m];
12649           cori[jj]=surf[nr].o[ii];
12650           ctyp[jj]=typnew[m];
12651           for (; jj<3; jj++) /* thats ok so */
12652           {
12653             edge[jj+1]=surf[nr].l[jj];
12654             cori[jj+1]=surf[nr].o[jj];
12655             ctyp[jj+1]=surf[nr].typ[jj];
12656           }
12657           getNewName( name, "s" );
12658           s=surface_i( name, surf[nr].ori, surf[nr].sh, (int)4, cori, edge, ctyp );
12659           if( s<0)
12660           { printf("ERROR: surface could not be created\n"); return(-1); }
12661           if(printFlag) printf(" temp. surf[%d]:%s generated\n",s, surf[s].name);
12662           k=createBlendedNurbs(s);
12663           delLine( 2, &lnew[0] );
12664           delSurf( 1, &s );
12665         }
12666         /* to mesh a n-sided surf two corners will be combined to one lcmb until only 4 edges remain */
12667         else if (surf[nr].nl>4)
12668         {
12669           /* create a temporary surface for the meshing */
12670           getNewName( name, "s" );
12671           s=surface_i( name, surf[nr].ori, surf[nr].sh, surf[nr].c[0], surf[nr].o, surf[nr].l, surf[nr].typ );
12672           if( s<0) { printf("ERROR: surface could not be created\n"); return(-1); }
12673           surf[s].etyp=surf[nr].etyp;
12674           surf[s].eattr=surf[nr].eattr;
12675 
12676           for (ii=0; ii<surf[nr].nl-4; ii++)
12677           {
12678             /* determine the best suited corner for the lcmb */
12679             determineBestCorners( s,cl);
12680             /* create a lcmb out of 2 edges */
12681             lnew[0]=addTwoLines( surf[s].l[cl[0]], surf[s].o[cl[0]], surf[s].typ[cl[0]], surf[s].l[cl[1]] ,surf[s].o[cl[1]], surf[s].typ[cl[1]] );
12682             if( lnew[0]==-1) { return(-1); }
12683 
12684             /* replace the concatonated lines of the surface */
12685             if (cl[0]==surf[s].nl-1)
12686             {
12687               surf[s].l[0]=lnew[0];
12688               surf[s].o[0]='+';
12689               surf[s].typ[0]='c';
12690               surf[s].nl--;
12691             }
12692             else
12693             {
12694               surf[s].l[cl[0]]=lnew[0];
12695               surf[s].o[cl[0]]='+';
12696               surf[s].typ[cl[0]]='c';
12697               for (jj=cl[0]+1; jj<surf[s].nl-1; jj++)
12698               {
12699                 surf[s].l[jj]=surf[s].l[jj+1];
12700                 surf[s].o[jj]=surf[s].o[jj+1];
12701                 surf[s].typ[jj]=surf[s].typ[jj+1];
12702               }
12703               surf[s].nl--;
12704             }
12705           }
12706           if(printFlag) printf(" temp. surf[%d]:%s generated\n",s, surf[s].name);
12707           k=createBlendedNurbs(s);
12708           delSurf( 1, &s );
12709         }
12710         else return(-1);
12711         if(k>-1)
12712         {
12713           seta( setall, "S", k );
12714           for (j=0; j<anz->sets; j++)
12715           {
12716             if(( set[j].name != (char *)NULL)&&( set[j].flag=='o')) seta( j, "S", k );
12717           }
12718 
12719           /* create a shape of the same name for reference in surfaces */
12720           surf[nr].sh=shape_i( nurbs[k].name, 4, k, 0, 0, 0, 0, 0, 0);
12721           repNurs(k);
12722           repSurf(nr,0);
12723 	}
12724       }
12725     }
12726   }
12727   else { if(nurs(string, addFlag)==-1) return(-1); }
12728   return(0);
12729 }
12730 
12731 
placeTxt(char * string)12732 void placeTxt(char *string)
12733 {
12734   int   i,j, k, n=0, nr;
12735   double x,y;
12736   int args, ibuf, setNr=-1, dx,dy;
12737   GLint    viewport[4];
12738   GLdouble mvmatrix[16], projmatrix[16];
12739   char *text=NULL, name[MAX_LINE_LENGTH], dat[3][MAX_LINE_LENGTH];
12740   static GLdouble wx, wy, wz;  /*  returned window x, y, z coords  */
12741   static int flag;
12742 
12743   /* search a text between "" and erase him from the string */
12744   i=j=0;
12745   do
12746   {
12747     if(string[i]=='"')
12748     {
12749       string[i++]=' ';
12750       if((text=(char *)malloc(sizeof(char))) == NULL)
12751         printf("\n ERROR: malloc failed\n");
12752       while((string[i]!='"')&&(string[i]!=0))
12753       {
12754         text[j++]=string[i];
12755         string[i++]=' ';
12756         if((text=(char *)realloc(text,(j+1)*sizeof(char))) == NULL)
12757           printf("\n ERROR: realloc failed\n");
12758       }
12759       string[i++]=' ';
12760       text[j++]='\0';
12761     }
12762   }while(string[i++]!='\0');
12763 
12764   args=sscanf(string,"%s %s %s %s", name, dat[0], dat[1], dat[2]);
12765   if(checkIfNumber(name)) { n=atoi(name); }
12766   if(n<1)
12767   {
12768     setNr=getSetNr(name);
12769     if (setNr<0)
12770     {
12771       printf (" txt: %s does not exist\n", name);
12772       return;
12773     }
12774   }
12775   if(args==1) { dx=0; dy=0; k=-1; }
12776   else if(checkIfNumber(dat[0])) { x=atof(dat[0]); y=atof(dat[1]); k=-1; dx=x*width_w1; dy=y*height_w1; }
12777   else if(args==2) { dx=0; dy=0; k=0; }
12778   else { x=atof(dat[1]); y=atof(dat[2]); k=0; dx=x*width_w1; dy=y*height_w1; }
12779 
12780   if(setNr<0)
12781   {
12782     ibuf=0; i=set[ibuf].anz_n;
12783     goto skipSet;
12784   }
12785   else ibuf=setNr;
12786   for(i=0; i<set[ibuf].anz_n; i++)
12787   {
12788     n=set[ibuf].node[i];
12789   skipSet:;
12790     if(args<=2) nr=createText(n, -1, -1 );
12791     else nr=createText(n, -1, 0 );
12792     ntext[nr].text=text;
12793     ntext[nr].tFlag=1;
12794     if(k>-1)
12795     {
12796       for(j=0; j<strlen(dat[k]); j++)
12797       {
12798         if(dat[k][j]=='n') ntext[nr].nFlag=0;
12799         else if(dat[k][j]=='t') ntext[nr].tFlag=0;
12800         else if(dat[k][j]=='v') ntext[nr].vFlag=0;
12801         else if(dat[k][j]=='e') ntext[nr].fFlag=0;
12802         else if(dat[k][j]=='f') ntext[nr].fFlag=1;
12803         else if(dat[k][j]=='s') ntext[nr].pFlag=1;
12804         else if(dat[k][j]=='i') ntext[nr].fFlag=2;
12805       }
12806     }
12807     if((dx)||(dy))
12808     {
12809       glutSetWindow( w1);
12810       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
12811       glLoadIdentity();
12812       moveModel();
12813 
12814       glGetIntegerv (GL_VIEWPORT, viewport);
12815       glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
12816       glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
12817       flag=gluProject( node[ntext[nr].node_nr].nx, node[ntext[nr].node_nr].ny, node[ntext[nr].node_nr].nz, mvmatrix, projmatrix, viewport,  &wx, &wy, &wz);
12818       if (flag==GL_FALSE) printf("WARNING: Malfunction, please reselect\n");
12819       ntext[nr].tx= wx+(double)(dx);
12820       ntext[nr].ty= (viewport[3]-wy)-(double)(dy);
12821     }
12822   }
12823 }
12824 
12825 
fixBadDivisions(int setNr)12826 void fixBadDivisions(int setNr)
12827 {
12828   int i,j,f,c,s,l,k,n, ii;
12829   int surfbuf[10], nsurfs,counter,loops=0;
12830   int msh,se,nr;
12831   char buffer[MAX_LINE_LENGTH];
12832 
12833   loopFix:;
12834 
12835   // search for faces of type 11 and 12 which exists at unconnected triangles
12836   // and collect the related lines in set '-EDGE‘
12837   delSet(specialset->tmp);
12838   delSet("-mesh");
12839   delSet("-EDGE" );
12840   se=pre_seta(specialset->tmp,"i",0);
12841   msh=pre_seta("-mesh","i",0);
12842   nr=pre_seta("-EDGE","i",0);
12843 
12844   for (i=0; i<set[setNr].anz_b; i++) seta( se, "b", set[setNr].body[i] );
12845   for (i=0; i<set[setNr].anz_s; i++) seta( se, "s", set[setNr].surf[i] );
12846 
12847   /* cyrcle through all bodys and add all surfs */
12848   for (i=0; i<set[se].anz_b; i++)
12849   {
12850     c=set[se].body[i];
12851     for (j=0; j<body[c].ns; j++)
12852     {
12853       l=body[c].s[j];
12854       seta( se, "s", l);
12855     }
12856   }
12857   /* cyrcle through all surfs and add all lines, lcmbs and nurbs */
12858   for (i=0; i<set[se].anz_s; i++)
12859   {
12860     s=set[se].surf[i];
12861     for (j=0; j<surf[s].nl; j++)
12862     {
12863       l=surf[s].l[j];
12864       if(surf[s].typ[j]=='l')
12865       {
12866         seta( se, "l", l );
12867       }
12868       else
12869       {
12870         seta( se, "c", l );
12871       }
12872     }
12873   }
12874   /* cyrcle through all lcmbs and add all lines */
12875   for (i=0; i<set[se].anz_c; i++)
12876   {
12877     c=set[se].lcmb[i];
12878     for (j=0; j<lcmb[c].nl; j++)
12879     {
12880       l=lcmb[c].l[j];
12881       seta( se, "l", l);
12882     }
12883   }
12884 
12885   /* cyrcle through all lines and add all related faces of type 11,12 */
12886   for (i=0; i<set[se].anz_l; i++)
12887   {
12888     l= set[se].line[i];
12889     for(f=0; f<anz->f; f++)
12890     {
12891       counter=0;
12892       if((face[f].type==11)||(face[f].type==12))
12893       {
12894         for(n=0; n<2; n++)
12895         {
12896           for(k=0; k<line[l].nn; k++) if(line[l].nod[k]==face[f].nod[n]) counter++;
12897           if((point[line[l].p1].nn)&&(point[line[l].p1].nod[0]==face[f].nod[n])) counter++;
12898           if((point[line[l].p2].nn)&&(point[line[l].p2].nod[0]==face[f].nod[n])) counter++;
12899 	}
12900       }
12901       if(counter==2)
12902       {
12903         seta(nr,"l",l);
12904       }
12905     }
12906   }
12907   if(set[nr].anz_l==0) goto exitfixBadDivisions;
12908   if(loops>=MAX_REFINEMENT_LOOPS)
12909   {
12910     delSet(specialset->tmp);
12911     delSet("-mesh");
12912     printf(" WARNING: mesh not closed (see set -EDGE) \n");
12913     return;
12914   }
12915   loops++;
12916 
12917   /* remesh the affected regions */
12918   /* add the surfaces */
12919   for(i=0; i<set[nr].anz_l; i++)
12920   {
12921     nsurfs=0;
12922     l=set[nr].line[i];
12923     // search for line related surfs
12924     for(k=0; k<set[se].anz_s; k++)
12925     {
12926       s=set[se].surf[k];
12927       for(ii=0; ii<surf[s].nl; ii++)
12928       {
12929         if(surf[s].l[ii]==l) surfbuf[nsurfs++]=s;
12930       }
12931     }
12932     // search for lcmb related surfs
12933     for(j=0; j<set[se].anz_c; j++)
12934     {
12935       c=set[se].lcmb[j];
12936       for (n=0; n<lcmb[c].nl; n++)
12937       {
12938         if(lcmb[c].l[n]==l)
12939         {
12940           for(k=0; k<set[se].anz_s; k++)
12941           {
12942             s=set[se].surf[k];
12943             for(ii=0; ii<surf[s].nl; ii++)
12944             {
12945               if(surf[s].l[ii]==lcmb[c].l[n]) surfbuf[nsurfs++]=s;
12946             }
12947           }
12948         }
12949       }
12950     }
12951     // add surfs only if they are '2' and of type unstruct tr3
12952     if(nsurfs==2)
12953     {
12954       k=0;
12955       for(j=0; j<2; j++)
12956       {
12957         s=surfbuf[j];
12958         if(((surf[s].etyp==7)||(surf[s].etyp==8))&&(surf[s].eattr==-1)) k=1;
12959       }
12960       if(k)
12961       {
12962         seta( msh, "s", surfbuf[0]);
12963         seta( msh, "s", surfbuf[1]);
12964         seta( msh, "l", l);
12965       }
12966     }
12967   }
12968 
12969   if(set[msh].anz_s)
12970   {
12971     // inc line div
12972     for(i=0; i<set[msh].anz_l; i++)
12973     {
12974       line[set[msh].line[i]].div+=2;
12975       repLine(set[msh].line[i]);
12976     }
12977 
12978     /* delete the mesh */
12979     sprintf(buffer,"me %s", set[msh].name);
12980     pre_del(buffer);
12981     for(i=0; i<set[msh].anz_l; i++)
12982     {
12983       printf("del mesh line %s\n",line[set[msh].line[i]].name);
12984       line[set[msh].line[i]].nn=0;
12985       line[set[msh].line[i]].ne=0;
12986     }
12987     for(i=0; i<set[msh].anz_s; i++)
12988     {
12989       printf("del mesh surf %s\n",surf[set[msh].surf[i]].name);
12990       surf[set[msh].surf[i]].nn=0;
12991       surf[set[msh].surf[i]].ne=0;
12992     }
12993     /* mesh again */
12994     for(i=0; i<set[msh].anz_s; i++)
12995     {
12996       printf("mesh %s\n",surf[set[msh].surf[i]].name);
12997     }
12998     completeSet(set[msh].name, "do");
12999     pre_mesh( set[msh].name );
13000     sprintf(buffer,"n %s",set[msh].name);
13001     pre_merge(buffer);
13002     printf(" %d edges in the model\n", anz->g);
13003   }
13004   else goto exitfixBadDivisions;
13005   goto loopFix;
13006 
13007  exitfixBadDivisions:;
13008   delSet( "-EDGE" );
13009   delSet(specialset->tmp);
13010   delSet("-mesh");
13011   return;
13012 }
13013 
13014 
13015 
13016 
13017 /*------------------------------------------------------------------*/
13018 /* Daten im fbd-format einlesen                                     */
13019 /*------------------------------------------------------------------*/
13020 /* return <0 if reading has to be stopped abnormally */
commandoInterpreter(char * type,char * string,int na,int nb,FILE * handle1,int addFlag,int * gtolFlag)13021 int commandoInterpreter( char *type, char *string, int na, int nb, FILE *handle1, int addFlag, int *gtolFlag )
13022 {
13023   int   i,j,k,l,n;
13024   int   lc,nr,ibuf=0;
13025   char  cbuf;
13026   char  buffer[MAX_LINE_LENGTH];
13027   char  setname[MAX_LINE_LENGTH], setname2[MAX_LINE_LENGTH];
13028   char  xbuf[MAX_LINE_LENGTH], format[MAX_LINE_LENGTH], dataset[MAX_LINE_LENGTH];
13029   char  name[MAX_LINE_LENGTH], comm[MAX_LINE_LENGTH], posn[MAX_LINE_LENGTH], entity[MAX_LINE_LENGTH];
13030   char  addDispFlagLocal=0;
13031   static char  **seq=NULL;
13032   char  **buf;
13033   char  *sbuf;
13034   char  dat[MAX_PARAM_IN_BRECORD][MAX_LINE_LENGTH];
13035   int       args,anz_seq, length, setNr, setNr2;
13036   double    lfbuf, pscal, x,y,z,dx,dy,dz, wx[2], wy[2], cof[4];
13037   char      **substring=NULL;
13038   int       foundSubString;
13039   static int *picnr=NULL;
13040   int pics;
13041   int pnts[3];
13042   DIR *dirp;
13043   struct dirent *dp;
13044   static int ifFlag=1, whileFlag=1;
13045   int   returnFlag=1;
13046   Scale scaleSet[1];
13047 
13048   int ncomps, analysis_type, step_number;
13049   char dataset_text[MAX_LINE_LENGTH], analysis_name[MAX_LINE_LENGTH];
13050   static char *ptr_string=NULL;
13051 
13052   for(j=0;j<strlen(type); j++) type[j]=toupper(type[j]);
13053  whileLoop:;
13054   for(j=0;j<MAX_PARAM_PER_RECORD; j++) dat[j][0]=0;
13055   for(j=0;j<strlen(string); j++) if(string[j]=='\n') string[j]=0;
13056 
13057   /* check if a loop starts due to "WHILE" */
13058   /* this has to be evaluated before a substitution of values happened! */
13059   /* whileFlag=0 condition was not fulfilled, skip the command
13060      whileFlag=1 execute command
13061      whileFlag=2 store and execute command
13062      whileFlag=3 restore and execute command and at the end of commandoInterpreter() go back to whileLoop:
13063      whileFlag=4 store command but do not execute
13064      whileFlag=5 restore command but do not execute command and at the end of commandoInterpreter() go back to whileLoop:
13065   */
13066   //printf(" commandoInterpreter, string:%s\n", string);
13067   if(whileFlag>1)
13068   {
13069     if((whileFlag==3)||(whileFlag==5))
13070     {
13071       whileFlag=pre_while(type, &ptr_string, &na, &nb, handle1, &addFlag, gtolFlag, whileFlag,ifFlag);
13072       string=ptr_string;
13073     }
13074     else whileFlag=pre_while(type, &string, &na, &nb, handle1, &addFlag, gtolFlag, whileFlag,ifFlag);
13075   }
13076   // fill data-structures for while loops
13077   if( (compareStrings(type, "WHILE")>0)||(compareStrings(type, "ENDWHILE")>0))
13078   {
13079     if((whileFlag==3)||(whileFlag==5))
13080     {
13081       whileFlag=pre_while(type, &ptr_string, &na, &nb, handle1, &addFlag, gtolFlag, -whileFlag,ifFlag);
13082       string=ptr_string;
13083     }
13084     else whileFlag=pre_while(type, &string, &na, &nb, handle1, &addFlag, gtolFlag, -whileFlag,ifFlag);
13085     goto checkForError;
13086   }
13087   //printf("whileFlag:%d\n",whileFlag);
13088   if((whileFlag==0)||(whileFlag==4)||(whileFlag==5)) goto checkForError;
13089 
13090 
13091   /* replace parameters by defined values */
13092   //if ((compare(type, "VALU", 4)!=4)&&(compare(type, "PRNT",4)!=4)&&(compare(type, "SET", 3)!=3))
13093   if (compare(type, "VALU", 4)!=4)
13094   {
13095     args=brecord(&string[na], dat);
13096     string[na]=0;
13097     for(i=0; i<args; i++)
13098     {
13099       j=getValuNr(dat[i]);
13100       if (j>-1)
13101       {
13102         //printf (" param:%s replaced by value:%s\n", value[j].name, value[j].string );
13103         strcpy(dat[i],value[j].string );
13104       }
13105       sprintf(&string[strlen(string)]," %s",dat[i]);
13106     }
13107     //printf("replaced parameters by defined values: %s\n", string);
13108   }
13109   /* substitution of values in PRNT leads to errors!  */
13110 
13111   /* check for "IF" statements */
13112   if((compareStrings(type, "IF")>0)||(compareStrings(type, "ELSE")>0)||(compareStrings(type, "ENDIF")>0))
13113   {
13114     ifFlag=pre_if(string);
13115     goto checkForError;
13116   }
13117   if(ifFlag==0) goto checkForError;
13118 
13119 
13120   setname[0]=name[0]=posn[0]=comm[0]=entity[0]=xbuf[0]=format[0]=0;
13121 
13122   /* remove masking of parameters (usually values) */
13123   if((anz->v)&&(strlen(string)>0)) for(i=0; i<strlen(string)-1; i++) if(string[i]=='\\') { string[i]=' '; i+=2; } // check only every third char
13124 
13125   if (compareStrings(type, "ALLOW_SYS")>0);
13126   else if (compareStrings(type, "ANIM")>0)
13127   {
13128     pre_animate(&string[na+1]);
13129   }
13130   else if (compareStrings(type, "AREA")>0)
13131   {
13132     pre_area(&string[na+1]);
13133   }
13134   else if (compareStrings(type, "ASGN")>0)
13135   {
13136     sscanf(&string[na+1], "%s %s", entity, name);
13137     if(( entity[0]=='s')&&( entity[1]=='e')) lchar->se=name[0];
13138     else if( compareStrings(entity, "graph")>0)
13139     {
13140       if( compare( name, "off", 3)==3) graph_on=0;
13141       else if( compare( name, "on", 2)==2) graph_on=1;
13142       else graph_Nr=atoi(name)-1;
13143     }
13144     else if( compareStrings(entity, "usr")>0)
13145     {
13146       createUSERparam( name, &string[na+3+strlen(entity)+strlen(name)]);
13147     }
13148     else if( compareStrings(entity, "netgen")>0)
13149     {
13150       meshp.tetmesher=0;
13151       printf(" tetmesher: netgen\n");
13152     }
13153     else if( compareStrings(entity, "tetgen")>0)
13154     {
13155       meshp.tetmesher=1;
13156       printf(" tetmesher: tetgen\n");
13157     }
13158     else if( compareStrings(entity, "mem")>0)
13159     {
13160       if(name[0]=='f')
13161       {
13162 	anz->free=1;
13163         for(lc=0; lc<anz->l; lc++)
13164         {
13165           if(cur_lc!=lc)
13166           {
13167             printf(" free lc[%d] ncomps:%d\n",lc,lcase[lc].ncomps);
13168             if(lcase[lc].loaded)
13169             {
13170               for(i=0; i<lcase[lc].ncomps; i++) free(lcase[lc].dat[i]);
13171             }
13172             /* always allocated */
13173             free(lcase[lc].dat);
13174             lcase[lc].dat=NULL;
13175             lcase[lc].loaded=0;
13176           }
13177         }
13178       }
13179       else anz->free=0;
13180     }
13181     else if( compareStrings(entity, "thrds")>0) anz->threads=atoi(name);
13182     else if( compareStrings(entity, "alpha")>0) meshp.alpha=atof(name);
13183     else if( compareStrings(entity, "beta")>0) meshp.beta=atof(name);
13184     else if( compareStrings(entity, "mpc")>0) { nasMpc=1; printf("rbe %d %f %8f %s\n", nasMpc, nasRbeHec, nasRbeHec, name); }
13185 
13186     else if( compareStrings(entity, "nadapt")>0) meshp.nadapt=atoi(name);
13187     else if( compareStrings(entity, "rbe")>0) { nasMpc=0; nasRbeHec=atof(name); printf("rbe %d %f %8f %s\n", nasMpc, nasRbeHec, nasRbeHec, name); }
13188     else if( entity[0]=='n') { if(atoi(name)>0) anz->nnext=atoi(name); else printf("ERROR: %s not a valid nr\n",name); }
13189     else if( entity[0]=='e') { if(atoi(name)>0) anz->enext=atoi(name); else printf("ERROR: %s not a valid nr\n",name); }
13190     else if( entity[0]=='p') lchar->p=name[0];
13191     else if( entity[0]=='l') lchar->l=name[0];
13192     else if( entity[0]=='c') lchar->c=name[0];
13193     else if( entity[0]=='s') lchar->s=name[0];
13194     else if( entity[0]=='b') lchar->b=name[0];
13195     else if( entity[0]=='L') lchar->L=name[0];
13196     else if( entity[0]=='S') lchar->S=name[0];
13197     else if( entity[0]=='h') lchar->sh=name[0];
13198     else if( compareStrings(entity, "max")>0) { defScalMethod=0; redraw(); }
13199     else if( compareStrings(entity, "maxr")>0) { defScalMethod=1; redraw(); }
13200     else if( compareStrings(entity, "maxc")>0)
13201     {
13202       defScalMethod=2;
13203       for(i=0; i<entitycols; i++) if(compareStrings(name,entitycol[i].name)>0) col_maxc=i;
13204       redraw();
13205     }
13206     else if( compareStrings(entity, "minc")>0)
13207     {
13208       defScalMethod=2;
13209       for(i=0; i<entitycols; i++) if(compareStrings(name,entitycol[i].name)>0) col_minc=i;
13210       redraw();
13211     }
13212     else errMsg(" %s not recognized\n", entity);
13213   }
13214   else if (compareStrings(type, "BIA")>0)
13215   {
13216     pre_bia(&string[na+1]);
13217   }
13218   else if (compareStrings(type, "BODY")>0)
13219   {
13220     pre_body(&string[na+1]);
13221   }
13222   else if (compareStrings(type, "BREAK")>0)
13223   {
13224     printf("BREAK by user request\n");
13225     return(-1);
13226   }
13227   else if (compareStrings(type, "CALL")>0)
13228   {
13229     /* when node coordinates were changed to the deformed ones then switch back */
13230     if(addDispFlag)
13231     {
13232       addDispToCoordinates(node);
13233       // remember to switch back
13234       addDispFlagLocal=2;
13235     }
13236     if(vectorFlag) pre_view("vector off");
13237     descalAll();
13238 
13239     userFunction(&string[na+1], anz, anzGeo);
13240 
13241     descalAll();
13242     getScaleValues( setall, set, point, node, scale);
13243     scalPoints ( anzGeo->p, point, scale );
13244     scalNodes ( anz->n, node, scale);
13245     scalSurfs( anzGeo->s, surf, scale);
13246     // recalculate the line-shapes
13247     for (i=0; i<anzGeo->l; i++) repLine(i);
13248     // recalculate the nurbl-controll-points
13249     for (i=0; i<anzGeo->nurl; i++) repNurl(i);
13250     // recalculate the nurbs-controll-points
13251     for (i=0; i<anzGeo->nurs; i++) repNurs(i);
13252     //orientSet( "all" );
13253 
13254     if(anz->e>0)
13255     {
13256       adjustDrawNodes(0);
13257       makeSurfaces();
13258       getElemNormalen( e_enqire, node, anz->e );
13259       updateDispLists();
13260     }
13261     /* when node coordinates were changed to the deformed ones then switch back before they are copied and then switch again */
13262     if(addDispFlagLocal==2)
13263     {
13264       addDispToCoordinates(node);
13265     }
13266     if(activWindow!=-1) createDatasetEntries();
13267   }
13268   else if (compareStrings(type, "CAPT")>0)
13269   {
13270     stos( &string[na], 1, strlen(&string[na]), picture_caption);
13271     if(inpformat)
13272     {
13273       glutSetWindow( w0);
13274       glutPostRedisplay();
13275     }
13276   }
13277   else if (compareStrings(type, "CNTR")>0)
13278   {
13279     length=sscanf(&string[na+1], "%s %s %s", dat[0], dat[1], dat[2]);
13280     if (length < 1)
13281     { printf(" ERROR in formulation\n"); goto checkForError; }
13282     else if (length == 3)
13283     {
13284       center( (atof(dat[0])-scale->x)/scale->w,(atof(dat[1])-scale->y)/scale->w,(atof(dat[2])-scale->z)/scale->w);
13285     }
13286     else
13287     {
13288       nr=getSetNr(dat[0]);
13289       if(nr<0)
13290       {
13291         nr=getPntNr(dat[0]);
13292         if(nr<0)
13293         {
13294           if(checkIfNumber(dat[0])==0)
13295           {
13296             printf(" ERROR: arg:%s is no set, point or node\n", dat[0]);
13297             goto checkForError;
13298           }
13299           nr=atoi(dat[0]);
13300           center( node[nr].nx, node[nr].ny, node[nr].nz);
13301         }
13302         else  center( point[nr].px, point[nr].py, point[nr].pz);
13303       }
13304       else
13305       {
13306         delSet(specialset->tmp);
13307         setNr=pre_seta(specialset->tmp, "i", 0 );
13308         seta( setNr, "se", nr );
13309         completeSet_frame(setNr, 0);
13310         getScaleValues( setNr, set, point, node, scaleSet);
13311         center( scaleSet->x, scaleSet->y, scaleSet->z);
13312         delSet(specialset->tmp);
13313       }
13314     }
13315   }
13316   else if (compareStrings(type, "CONT")>0)
13317   {
13318     if(stopped_commandFile>-1)
13319     {
13320 	if((commandFile[stopped_commandFile].handle!=NULL)&&(commandFile[stopped_commandFile].stopped))
13321         {
13322           printf("CONTINUE to read file:%s\n", commandFile[stopped_commandFile].name);
13323           readfbd( 0, 0);
13324           return(0);
13325 	}
13326     }
13327     else printf("ERROR: No open commandFile\n");
13328   }
13329   else if (compareStrings(type, "COL")>0)
13330   {
13331     length=sscanf(&string[na+1], "%s", dat[0]);
13332     for(i=0; i<entitycols; i++)
13333     {
13334       if(compareStrings(dat[0],entitycol[i].name)>0)
13335       {
13336         entitycol[i].r=entitycol[i].g=entitycol[i].b=0;
13337         length=sscanf(&string[na+1], "%s %f %f %f", entitycol[i].name, &entitycol[i].r, &entitycol[i].g, &entitycol[i].b );
13338 	return(0);
13339       }
13340     }
13341     entitycols++;
13342     if( (entitycol= (Entitycol *)realloc(entitycol, entitycols*sizeof(Entitycol))) == NULL )
13343       printf("\n\n ERROR: malloc failed\n\n") ;
13344     i=entitycols-1;
13345     entitycol[i].r=entitycol[i].g=entitycol[i].b=0;
13346     length=sscanf(&string[na+1], "%s %f %f %f", entitycol[i].name, &entitycol[i].r, &entitycol[i].g, &entitycol[i].b );
13347   }
13348   else if (compareStrings(type, "COPY")>0)
13349   {
13350     pre_copy(&string[na+1]);
13351     redraw();
13352   }
13353   else if (compareStrings(type, "COMP")>0)
13354   {
13355     if ( sscanf(&string[na+1], "%s%s", name, xbuf) < 2)
13356     { printf(" ERROR in formulation\n"); goto checkForError; }
13357 
13358     setNr=getSetNr(name);
13359     if (setNr<0)
13360     {
13361       /* set was not found. check if wildcards (*) were used */
13362       if((strlen(name)==1)&&(name[0]=='*'))
13363       {
13364         for(setNr=0; setNr<anz->sets; setNr++) if(set[setNr].name!=(char *)NULL)
13365         {
13366           if (!set[setNr].type)
13367           {
13368             printf(" comp %s %s\n", set[setNr].name, xbuf) ;
13369             completeSet( set[setNr].name, xbuf) ;
13370           }
13371         }
13372         goto checkForError;
13373       }
13374       length= strsplt( name, '*', &buf);
13375       if (length>0)
13376       {
13377         j=0;
13378         for(setNr=0; setNr<anz->sets; setNr++) if(set[setNr].name!=(char *)NULL)
13379         {
13380           foundSubString=0;
13381           for(i=0; i<length; i++)
13382           {
13383             if(strstr(set[setNr].name, buf[i]) !=NULL)
13384             {
13385               foundSubString++;
13386               /* check if the first or the last char is no '*' then the buf[] must be at start or end */
13387               if(i==0) { if(name[0]!='*')  { if(name[0]!=set[setNr].name[0])  foundSubString--; }  }
13388               if(i==length-1) { if(name[strlen(name)-1]!='*') { if(name[strlen(name)-1]!=set[setNr].name[strlen(set[setNr].name)-1])  foundSubString--; } }
13389 	    }
13390 	  }
13391           if(foundSubString==length)
13392 	  {
13393             i=setNr;
13394             if (!set[i].type)
13395             {
13396               j++;
13397               printf(" comp %s %s\n", set[i].name, xbuf) ;
13398               completeSet( set[i].name, xbuf) ;
13399             }
13400 	  }
13401 	}
13402         if(j!=0) goto checkForError;
13403       }
13404       /* free buf */
13405       for(i=0; i<length; i++) free(buf[i]);
13406       free(buf);
13407 
13408       printf (" WARNING(comp): set '%s' does not exist\n", name);
13409       goto checkForError;
13410     }
13411     else  completeSet( name, xbuf) ;
13412   }
13413   else if (compareStrings(type, "CORRAD")>0)
13414   {
13415     length=sscanf(string, "%*s %s %lf",name,&x);
13416     if (length==1) x=0.;
13417     operateAlias( name, "se" );
13418     setNr=getSetNr(name);
13419     if (setNr<0)
13420     {
13421       printf (" corrad: set:%s does not exist\n", name);
13422       goto checkForError;
13423     }
13424     corrad( setNr, x);
13425   }
13426   else if (compareStrings(type, "CSYSA")>0)
13427   {
13428     length = sscanf(&string[na+1], "%d %s", &nr, name);
13429     if(length<2) { printf(" wrong syntax\n"); goto checkForError; }
13430     operateAlias( name, "se" );
13431     setNr=getSetNr(name);
13432     if (setNr<0)
13433     {
13434       printf (" ERROR in csysa: set:%s does not exist\n", name);
13435       goto checkForError;
13436     }
13437     nodeCsysSet[nodeCsys]=setNr;
13438     nodeCsysNr[nodeCsys]=nr;
13439     nodeCsys++;
13440   }
13441   else if (compareStrings(type, "CUT")>0)
13442   {
13443     ibuf=sscanf(&string[na+1], "%s %s %s", dat[0], dat[1], dat[2]);
13444     if(ibuf==1)
13445     {
13446       nr=atoi(dat[0]);
13447       if(nr<1)
13448       {
13449         printf(" ERROR: arg:%s is no node\n", dat[i]);
13450         goto checkForError;
13451       }
13452       pre_cut( nr, 'v' );
13453     }
13454     else if(ibuf==3)
13455     {
13456      for (i=0; i<3; i++)
13457      {
13458       nr=getPntNr(dat[i]);
13459       if(nr<0)
13460       {
13461         if(checkIfNumber(dat[i])==0)
13462 	{
13463           printf(" ERROR: arg:%s is no point and no node\n", dat[i]);
13464           goto checkForError;
13465         }
13466         nr=atoi(dat[i]);
13467         pre_cut( nr, 'n' );
13468       }
13469       else pre_cut( nr, 'p' );
13470      }
13471     }
13472     else
13473     {
13474       printf(" ERROR: wrong number of arguments. One node or 3 points or nodes needed\n");
13475       goto checkForError;
13476     }
13477     goto checkForError;
13478   }
13479   else if (compareStrings(type, "DEL")>0)
13480   {
13481     pre_del(&string[na+1]);
13482   }
13483   else if (compareStrings(type, "DIST")>0)
13484   {
13485     na=sscanf(string, "%*s%s%s",dat[0],dat[1]);
13486     if(na==1)
13487     {
13488       setNr=getSetNr(dat[0]);
13489       x=y=z=-MAX_FLOAT;
13490       dx=dy=dz=MAX_FLOAT;
13491       if(setNr>-1)
13492       {
13493         for( i=0; i<set[setNr].anz_n; i++ )
13494 	{
13495           j=set[setNr].node[i];
13496           x = dmax(x,node[node[j].nr].nx);
13497           dx = dmin(dx,node[node[j].nr].nx);
13498           y = dmax(y,node[node[j].nr].ny);
13499           dy = dmin(dy,node[node[j].nr].ny);
13500           z = dmax(z,node[node[j].nr].nz);
13501           dz = dmin(dz,node[node[j].nr].nz);
13502 	}
13503         for( i=0; i<set[setNr].anz_p; i++ )
13504 	{
13505           j=set[setNr].pnt[i];
13506           if( point[j].name != (char *)NULL )
13507 	  {
13508             x = dmax(x,point[j].px);
13509             dx = dmin(dx,point[j].px);
13510             y = dmax(y,point[j].py);
13511             dy = dmin(dy,point[j].py);
13512             z = dmax(z,point[j].pz);
13513             dz = dmin(dz,point[j].pz);
13514 	  }
13515         }
13516       }
13517       dx=(x-dx)* scale->w;
13518       dy=(y-dy)* scale->w;
13519       dz=(z-dz)* scale->w;
13520       printf(" dxyz: %f %f %f\n", dx,dy,dz);
13521       sprintf(parameter[0],"%f",dx);
13522       sprintf(parameter[1],"%f",dy);
13523       sprintf(parameter[2],"%f",dz);
13524       write2stack( 3, parameter);
13525     }
13526     else pre_proj( string );
13527   }
13528   else if (compareStrings(type, "DIV")>0)
13529   {
13530     /*
13531     descalAll();
13532     getScaleValues(0, set, point, node, scale);
13533     scalNodes ( anz->n, node, scale );
13534     scalPoints ( anzGeo->p, point, scale );
13535     scalSurfs( anzGeo->s, surf, scale);
13536     // recalculate the line-shapes
13537     for (i=0; i<anzGeo->l; i++) repLine(i);
13538     // recalculate the nurbl-controll-points
13539     for (i=0; i<anzGeo->nurl; i++) repNurl(i);
13540     // recalculate the nurbs-controll-points
13541     for (i=0; i<anzGeo->nurs; i++) repNurs(i);
13542     // correct the orientation of all entities
13543     orientSet( "all" );
13544     */
13545     pre_div(&string[na+1]);
13546   }
13547   else if ((compareStrings(type, "DS")>0)||(compareStrings(type, "LC")>0))
13548   {
13549     sscanf(string,"%*s %s",buffer);
13550     if(buffer[0]=='e')
13551     {
13552       strcpy(name,"user");
13553       ncomps=1;
13554       analysis_type=0;
13555       i=0;
13556       j=0;
13557       sscanf(string,"%*s %*s %s %d %d %d %d", name, &ncomps, &analysis_type, &i, &j);
13558       if(i==0) i=ncomps;
13559       if(analysis_type==0) analysis_type=1;
13560       if(defineEntity(anz, lcase, node, name, ncomps, analysis_type, i, j)!=0) printf(" WARNING: entity:%d of dataset %d could not be set.\n", ncomps, cur_lc+1);
13561       if(activWindow!=-1) createDatasetEntries();
13562     }
13563     else if(buffer[0]=='g')
13564     {
13565       ncomps=0;
13566       sscanf(string,"%*s %*s %*s %d", &ncomps);
13567       if(!ncomps)
13568       {
13569         if(!anz->l) { printf(" ERROR: No current dataset exists.\n"); return(-1); }
13570 	lfbuf=lcase[cur_lc].value;
13571 	strcpy( name, lcase[cur_lc].name) ;
13572 	strcpy(dataset_text, lcase[cur_lc].dataset_text);
13573 	strcpy(analysis_name, lcase[cur_lc].analysis_name);
13574         step_number=lcase[cur_lc].step_number;
13575         analysis_type=lcase[cur_lc].analysis_type;
13576       }
13577       /* defaults */
13578       else
13579       {
13580         strcpy(name,"unnamed");
13581         lfbuf=0.;
13582         dataset_text[0]=0;
13583         analysis_type=1;
13584         if(anz->l) step_number=lcase[anz->l-1].step_number+1; else step_number=1;
13585         analysis_name[0]=0;
13586       }
13587       sscanf(string,"%*s %*s %s %d %lf %s %d %d %s", name, &ncomps, &lfbuf, dataset_text, &analysis_type, &step_number, analysis_name);
13588       generateDataset(anz, &lcase, name, ncomps, lfbuf, dataset_text, analysis_type, step_number, analysis_name);
13589       recompileEntitiesInMenu(anz->l-1);
13590       if(activWindow!=-1) createDatasetEntries();
13591     }
13592     else if(buffer[0]=='f')
13593     {
13594         for(n=0; n<anz->n; n++)
13595         {
13596           for(i=0; i<lcase[cur_lc].ncomps; i++)
13597           {
13598             if (lcase[cur_lc].dat[i][node[n].nr] >  lcase[cur_lc].max[i])
13599             {  lcase[cur_lc].max[i]=lcase[cur_lc].dat[i][node[n].nr]; lcase[cur_lc].nmax[i]=node[n].nr; }
13600             if (lcase[cur_lc].dat[i][node[n].nr] <  lcase[cur_lc].min[i])
13601             {  lcase[cur_lc].min[i]=lcase[cur_lc].dat[i][node[n].nr]; lcase[cur_lc].nmin[i]=node[n].nr; }
13602           }
13603         }
13604       calcDatasets( anz->l-1, anz, node, lcase );
13605     }
13606     else if(buffer[0]=='l') { selectData( &string[na+1] ); }
13607     else if(checkIfNumber(buffer)) { selectData( &string[na+1] ); }
13608     else { printf(" ERROR: Parameter:%s not recognized.\n", buffer); }
13609   }
13610   else if (compareStrings(type, "ELEM")>0)
13611   {
13612     pre_elem(&string[na+1]);
13613   }
13614   else if (compareStrings(type, "ELTY")>0)
13615   {
13616     pre_elty(&string[na+1]);
13617   }
13618   else if (compareStrings(type, "ENQ")>0)
13619   {
13620     enquireEntities(&string[na+1]);
13621   }
13622   else if (compareStrings(type, "EPROP")>0)
13623   {
13624     pre_eprop(&string[na+1]);
13625   }
13626   else if (compareStrings(type, "EQAL")>0)
13627   {
13628     pre_eqal(&string[na+1]);
13629   }
13630   else if ( compareStrings(type, "EXIT")>0 )
13631   {
13632     strcpy(setname,datin);
13633     for (i=strlen(datin); i>=0; i--)
13634     {
13635       if(datin[i]=='.')break;
13636     }
13637     setname[i]='\0';
13638 #ifdef WIN32
13639     sprintf (buffer, "move /y \"%s\" \"%s.fbb\"", datin, setname );
13640 #else
13641     sprintf (buffer, "mv %s %s.fbb", datin, setname );
13642 #endif
13643     if(compare(&datin[i+1],"fbd",3)==3) system (buffer);
13644     pre_write(" all fbd ");
13645     if( compareStrings( setname, "all")<3)
13646     {
13647 #ifdef WIN32
13648       sprintf (buffer, "move /y all.fbd \"%s.fbd\"", setname );
13649 #else
13650       sprintf (buffer, "mv all.fbd %s.fbd", setname );
13651 #endif
13652       system (buffer);
13653     }
13654     exit(0);
13655   }
13656   else if (compareStrings(type, "FIL")>0)
13657   {
13658     /* intersection of 2 lines */
13659     if (!addFlag)    length = sscanf(string, "%*s%s%s%lf", dat[0], dat[1], &x);
13660     else
13661     {
13662       name[0]='!';
13663       dat[0][0]=dat[1][0]='%';
13664       length = sscanf(string, "%*s%s%s%lf", &dat[0][1],  &dat[1][1], &x);
13665     }
13666     operateAlias( dat[0], "l" );
13667     operateAlias( dat[1], "l" );
13668     i=getLineNr(dat[0]);
13669     j=getLineNr(dat[1]);
13670     x/=scale->w;
13671 
13672     pscal=gtol;
13673     gtol=MAX_FLOAT;
13674     createFillet(i, x);
13675     createFillet(j, x);
13676     gtol=pscal;
13677     repLine(i);
13678     repLine(j);
13679   }
13680   else if (compareStrings(type, "FLIP")>0)
13681   {
13682     na=sscanf(string, "%*s%s%s",dat[0],dat[1]);
13683     nr=getSetNr(dat[0]);
13684     if((nr>-1)&&(set[nr].type==1)) nr=-1;
13685     if(nr>-1)
13686     {
13687       if(dat[1][0]=='e') for(i=0; i<set[nr].anz_e; i++) flip("e",set[nr].elem[i]);
13688       else if(dat[1][0]=='s') for(i=0; i<set[nr].anz_s; i++) flip("s",set[nr].surf[i]);
13689       else if(dat[1][0]=='b') for(i=0; i<set[nr].anz_b; i++) flip("b",set[nr].body[i]);
13690       else
13691       {
13692         if(!set[nr].anz_s) for(i=0; i<set[nr].anz_e; i++) flip("e",set[nr].elem[i]);
13693         for(i=0; i<set[nr].anz_s; i++) flip("s",set[nr].surf[i]);
13694         for(i=0; i<set[nr].anz_b; i++) flip("b",set[nr].body[i]);
13695       }
13696     }
13697     else
13698     {
13699       nr=getSurfNr(dat[0]);
13700       if(nr>-1)
13701       {
13702         if((na>1)&&(dat[1][0]=='a'))  flip("sa",nr);
13703         else flip("s",nr);
13704         return(0);
13705       }
13706       nr=getBodyNr(dat[0]);
13707       if(nr>-1)
13708       {
13709         flip("b",nr);
13710         return(0);
13711       }
13712       nr=atoi(dat[0]);
13713       if(nr>0)
13714       {
13715         flip("e",nr);
13716         return(0);
13717       }
13718       printf(" ERROR Name unknown:%s\n",dat[0]);
13719     }
13720   }
13721   else if (compareStrings(type, "FLPC")>0)
13722   {
13723     flipColorFlag=!flipColorFlag;
13724     redraw();
13725   }
13726   else if (compareStrings(type, "FONT")>0)
13727   {
13728     i=DEF_GLUT_FONT+1;
13729     sscanf(&string[na+1],"%s %d",buffer,&i);
13730     if((i>0)&&(i<=SUM_GLUT_FONTS))
13731     {
13732       i--;
13733       if(compare(buffer, "legend", 1)==1) legend_font=i;
13734       else if(compare(buffer, "draw", 1)==1) draw_font=i;
13735       else if(compare(buffer, "menu", 1)==1) menu_font=i;
13736       else if(compare(buffer, "cl", 1)==1) menu_font=i;
13737       else printf(" WARNING: Unknown target:%s\n", buffer);
13738       redraw();
13739       reshape( width_w0, height_w0 );
13740     }
13741     else printf(" WARNING: Unknown font index:%d\n",i);
13742   }
13743   else if (compareStrings(type, "FRAME")>0)
13744   {
13745     na=sscanf(string, "%*s%s",name);
13746     if(na>0)
13747     {
13748       setNr=getSetNr(name);
13749       if (setNr<0)
13750       {
13751         printf (" set:%s does not exist\n", name);
13752         goto checkForError;
13753       }
13754       frameSetFlag=setNr;
13755     }
13756     else frameSetFlag=-1;
13757     frame();
13758   }
13759   else if (compareStrings(type, "GBOD")>0)
13760   {
13761     pre_gbod(&string[na+1], addFlag);
13762   }
13763   else if (compareStrings(type, "GONLY")>0)
13764   {
13765     if ( compare(&string[na+1], "of", 2) == 2)
13766     {
13767       frameFlag=1;
13768       captionFlag=1;
13769       textFlag=1;
13770       scalaFlag=1;
13771     }
13772     else
13773     {
13774       frameFlag=0;
13775       captionFlag=0;
13776       textFlag=0;
13777       scalaFlag=0;
13778     }
13779     redraw();
13780     if(inpformat)
13781     {
13782       glutSetWindow( w0);
13783       glutPostRedisplay();
13784     }
13785   }
13786   else if (compareStrings(type, "GRAPH")>0)
13787   {
13788     nr=graph(&string[na+1]);
13789 
13790     /* actual graph nr */
13791     sprintf(buffer,"!graph_Nr %d", nr);
13792     pre_value(buffer);
13793   }
13794   else if (compareStrings(type, "GRPA")>0)
13795   {
13796     length = sscanf(&string[na+1], "%d %s", &nr, name);
13797     if(length<2) { printf(" wrong syntax\n"); goto checkForError; }
13798     operateAlias( name, "se" );
13799     setNr=getSetNr(name);
13800     if (setNr<0)
13801     {
13802       printf (" ERROR in mata: set:%s does not exist\n", name);
13803       goto checkForError;
13804     }
13805     for (i=0; i<anz->e; i++)
13806     {
13807       e_enqire[e_enqire[i].nr].group=nr;
13808     }
13809   }
13810   else if (compareStrings(type, "GRPS")>0)
13811   {
13812     for (i=0; i<anz->e; i++)
13813     {
13814       sprintf(name,"%d", e_enqire[i].nr);
13815       sprintf(buffer, "+grp%d", e_enqire[e_enqire[i].nr].group );
13816       pre_seta( buffer, "e", name  );
13817     }
13818     prnt("se +grp*");
13819   }
13820   else if (compareStrings(type, "TYPS")>0)
13821   {
13822     for (i=0; i<anz->e; i++)
13823     {
13824       sprintf(name,"%d", e_enqire[i].nr);
13825       sprintf(buffer, "+typ%d", e_enqire[e_enqire[i].nr].type );
13826       pre_seta( buffer, "e", name  );
13827     }
13828     prnt("se +typ*");
13829   }
13830   else if (compareStrings(type, "GROUP")>0)
13831   {
13832     printf("ERROR: Not longer supported.\n");
13833   }
13834   else if (compareStrings(type, "GSUR")>0)
13835   {
13836     pre_gsur(&string[na+1], addFlag);
13837   }
13838   else if (compareStrings(type, "GTOL")>0)
13839   {
13840     if(gtolFlag>(int *)NULL) *gtolFlag=1;
13841     length=sscanf(string, "%*s %s",buffer);
13842     if (length==1)
13843     {
13844       if(buffer[0]=='a') { gtol=calcGTOL(setall);  printf ("gtol new calculated:%e\n", gtol); }
13845       else { gtol=atof(buffer); printf ("gtol set to:%e\n", gtol); }
13846     }
13847     else printf ("gtol:%e\n", gtol);
13848 
13849     if(valuestackFlag)
13850     {
13851       n=1;
13852       if ((valuestack = (char **)realloc( (char **)valuestack, (valuestack_ptr+n)*sizeof(char *)) ) == NULL )
13853       { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
13854       for(i=0; i<n; i++)
13855       {
13856         if ((valuestack[valuestack_ptr+i] = (char *)malloc( MAX_LINE_LENGTH*sizeof(char)) ) == NULL )
13857         { printf("\n\nERROR: realloc failure, valuestack\n\n"); return(-1); }
13858       }
13859       sprintf(valuestack[valuestack_ptr++],"%f", gtol );
13860       printf(" gtol written to stack\n");
13861     }
13862   }
13863   else if (compareStrings(type, "HCPY")>0)
13864   {
13865     format[0]=0;
13866     args=sscanf(string,"%*s %s %s", name, format);
13867     if(args==2) sbuf=format; else sbuf=NULL;
13868     if     (compareStrings(name, "ps")>0)  createHardcopy(1,sbuf);
13869     else if(compareStrings(name, "tga")>0) createHardcopy(2,sbuf);
13870     else if(compareStrings(name, "gif")>0) createHardcopy(4,sbuf);
13871     else if(compareStrings(name, "png")>0) createHardcopy(5,sbuf);
13872     else if(compareStrings(name, "clean")>0)
13873     {
13874       sprintf( buffer, "rm -f hcpy_*.* %s", DEV_NULL2);
13875       system (buffer);
13876       psNr=tgaNr=gifNr=pngNr=0;
13877     }
13878     else if(compareStrings(name, "make")>0)
13879     {
13880       /* open the actual dir and get the available hcpy files */
13881       pics=0;
13882       dirp = opendir(".");
13883       if (dirp != NULL) while ((dp = readdir(dirp)) != NULL)
13884       {
13885         /* search for hcpy_xx.ps files  */
13886         if( (compare(dp->d_name, "hcpy", 4) == 4) && ( dp->d_name[strlen(dp->d_name)-2]=='p') && ( dp->d_name[strlen(dp->d_name)-1]=='s') )
13887         {
13888           printf(" found %s \n", dp->d_name);
13889           /* get the pic-nr */
13890           i=0; while(dp->d_name[i]!='_') i++; i++;
13891           j=0; while(dp->d_name[i]!='.') { posn[j]=dp->d_name[i]; j++; i++;}
13892           posn[j]=0;
13893           if ( (picnr = (int *)realloc( (int *)picnr, (pics+2) * sizeof(int))) == NULL )
13894           {  printf("\n\n ERROR: realloc failed, hcpy\n\n"); }
13895           picnr[pics]=atoi(posn); pics++;
13896         }
13897       }
13898       closedir(dirp);
13899       qsort( picnr, pics, sizeof(int), (void *)compareInt );
13900 
13901       nr=0; /* page-nr */
13902       ibuf=0; /* pic-nr */
13903       do
13904       {
13905         sprintf( buffer, "gs -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=tmp.ps ");
13906         for(j=0; j<6; j++) /* 6 pics per page */
13907 	{
13908           if(ibuf==pics) break;
13909           sprintf( &buffer[strlen(buffer)], " hcpy_%d.ps", picnr[ibuf++]);
13910 	}
13911         system (buffer);
13912         printf("%s\n",buffer);
13913         if ( compareStrings(format, "ls")>0)
13914         {
13915           pscal=0.42;
13916           x=11.; dx=9.;
13917           y=1.5;  dy=9.;
13918           /* sscanf(string,"%*s %*s %*s %lf %lf %lf %lf %lf", &x, &y, &dx, &dy, &pscal); */
13919 
13920           // activate this lined if ps2write is used
13921           //sprintf( buffer, "convert -density %dx%d tmp.ps tmp.ps", (int)((double)(PS_DENSITY*width_w0)/(double)(INI_SCREEN+INI_MENU_WIDTH)),(int)((double)(PS_DENSITY*width_w0)/(double)(INI_SCREEN+INI_MENU_WIDTH)));
13922           system (buffer);
13923           printf("%s\n",buffer);
13924 
13925           sprintf( buffer, "pstops '6:0L@%lf(%lfcm,%lfcm)+3L@%lf(%lfcm,%lfcm)+1L@%lf(%lfcm,%lfcm)+4L@%lf(%lfcm,%lfcm)+2L@%lf(%lfcm,%lfcm)+5L@%lf(%lfcm,%lfcm)' tmp.ps tmp_%d.ps", pscal, x,y, pscal, x+dx,y, pscal, x,y+dy, pscal, x+dx,y+dy, pscal, x,y+2.*dy, pscal, x+dx,y+2.*dy, nr);
13926         }
13927         else
13928         {
13929           pscal=0.42;
13930           x=2.; dx=9.;
13931           y=1.; dy=9.;
13932           /* sscanf(string,"%*s %*s %*s %lf %lf %lf %lf %lf", &x, &y, &dx, &dy, &pscal); */
13933 
13934           // activate this lined if ps2write is used
13935           //sprintf( buffer, "convert -density %dx%d tmp.ps tmp.ps", (int)((double)(PS_DENSITY*width_w0)/(double)(INI_SCREEN+INI_MENU_WIDTH)),(int)((double)(PS_DENSITY*width_w0)/(double)(INI_SCREEN+INI_MENU_WIDTH)));
13936           system (buffer);
13937           printf("%s\n",buffer);
13938 
13939           sprintf( buffer, "pstops '6:4@%lf(%lfcm,%lfcm)+5@%lf(%lfcm,%lfcm)+2@%lf(%lfcm,%lfcm)+3@%lf(%lfcm,%lfcm)+0@%lf(%lfcm,%lfcm)+1@%lf(%lfcm,%lfcm)' tmp.ps tmp_%d.ps", pscal, x,y, pscal, x+dx,y, pscal, x,y+dy, pscal, x+dx,y+dy, pscal, x,y+2.*dy, pscal, x+dx,y+2.*dy, nr);
13940         }
13941         system (buffer);
13942         printf("%s\n",buffer);
13943         sprintf( buffer, "gs -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=cgx_%d.ps tmp_%d.ps", nr, nr);
13944         system (buffer);
13945         printf("%s\n",buffer);
13946         sprintf( buffer, "rm -f tmp*.ps %s",DEV_NULL);
13947         system (buffer);
13948         nr++;
13949       }while(j==6);
13950       sprintf( buffer, "gs -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=cgx.ps ");
13951       for(j=0; j<nr; j++)
13952       {
13953         sprintf( &buffer[strlen(buffer)], " cgx_%d.ps", j);
13954       }
13955       system (buffer);
13956       printf("%s\n",buffer);
13957       sprintf( buffer, "rm -f cgx_*.ps %s",DEV_NULL);
13958       system (buffer);
13959       // TBD: if ( compareStrings(format, "ls")>0)
13960       if(inpformat) sprintf(buffer, "%s cgx.ps &", psviewer);
13961       system (buffer);
13962       printf("ready\n");
13963 
13964       // activate this lined if ps2write is used
13965       printf(" you may convert to pdf with 'convert -density 600x600 cgx.ps cgx.pdf\n");
13966 
13967     }
13968     else if(compareStrings(&string[na+1], "clean")>0)
13969     {
13970       sprintf( buffer, "rm -f hcpy_* %s",DEV_NULL);
13971       system (buffer);
13972       psNr=tgaNr=gifNr=pngNr=0;
13973     }
13974     else createHardcopy(2, NULL);
13975   }
13976   else if (compareStrings(type, "INT")>0)
13977   {
13978     /* intersection of 2 lines */
13979     if (!addFlag)    length = sscanf(string, "%*s%s%s", dat[0], dat[1]);
13980     else
13981     {
13982       name[0]='!';
13983       dat[0][0]=dat[1][0]='%';
13984       length = sscanf(string, "%*s%s%s", &dat[0][1],  &dat[1][1]);
13985     }
13986     operateAlias( dat[0], "l" );
13987     operateAlias( dat[1], "l" );
13988     i=getLineNr(dat[0]);
13989     j=getLineNr(dat[1]);
13990 
13991     pscal=gtol;
13992     gtol=MAX_FLOAT;
13993     intersect(i);
13994     intersect(j);
13995     gtol=pscal;
13996     repLine(i);
13997     repLine(j);
13998   }
13999   else if (compareStrings(type, "LCMB")>0)
14000   {
14001     pre_lcmb(&string[na+1], addFlag);
14002   }
14003   else if (compareStrings(type, "LENGTH")>0)
14004   {
14005     pre_length(&string[na+1]);
14006   }
14007   else if (compareStrings(type, "LINE")>0)
14008   {
14009     pre_line(&string[na+1], addFlag);
14010   }
14011   else if (compareStrings(type, "LNOR")>0)
14012   {
14013     if (!addFlag)    length = sscanf(string, "%*s%s%s%s%s%lf", name, dat[1], dat[2], dat[0], &pscal);
14014     else
14015     {
14016       name[0]='!';
14017       dat[0][0]=dat[1][0]=dat[2][0]='%';
14018       length = sscanf(string, "%*s%s%s%s%s%lf", &name[1],  &dat[1][1],  &dat[2][1],  &dat[0][1], &pscal);
14019     }
14020     operateAlias( name, "l" );
14021     operateAlias( dat[0], "p" );
14022     operateAlias( dat[1], "p" );
14023     operateAlias( dat[2], "p" );
14024 
14025     /* check if a lcmb has this name, not use it */
14026     if (getLcmbNr(name) >0) {errMsg("ERROR: LCMB uses this name %s, try another name \n", name); return(-1);}
14027     if (!pscal) {errMsg("ERROR: length must not be 0\n"); return(-1);}
14028 
14029     for(i=0; i<3; i++) pnts[i]=getPntNr(dat[i]);
14030     if((i=normalLine(name, pnts, pscal))<0)
14031     { printf("lnor: could not create new line\n");  return(-1);}
14032     else { printf(" create line:%s with new end-point %s\n", name, point[i].name ); }
14033   }
14034   else if (compareStrings(type, "INIT")>0)
14035   {
14036     initModel(string);
14037     if(backgrndcol) sprintf(buffer,"bg w"); else sprintf(buffer,"bg k");
14038     pre_view(buffer);
14039     if (cullFlag) sprintf(buffer,"back"); else sprintf(buffer,"front");
14040     pre_view(buffer);
14041     redraw();
14042   }
14043   else if (compareStrings(type, "MAP")>0)
14044   {
14045     dat[0][0]=0;
14046     length = sscanf(string, "%*s%s%s%s%s%s", setname, setname2, name, dataset, dat[0]);
14047     setNr=getSetNr(setname);
14048     if (setNr<0)
14049     {
14050       printf (" set:%s does not exist\n", setname);
14051       goto checkForError;
14052     }
14053     setNr2=getSetNr(setname2);
14054     if (setNr2<0)
14055     {
14056       printf (" set:%s does not exist\n", setname2);
14057       goto checkForError;
14058     }
14059     if (set[setNr2].anz_n<=0)
14060     {
14061       printf (" set:%s does not contain nodes\n", setname2);
14062       goto checkForError;
14063     }
14064 
14065     /* mapping needs stronger gtol */
14066     x=gtol;
14067     gtol*=GTOL_FACTOR_MAP;
14068 
14069     if ((compare(name, "surf", 1)==1)||(name[0]== 'r')||(name[0]== 'x')||(name[0]== 'y')||(name[0]== 'z'))
14070     {
14071       if(dat[0][0]=='n') areampc(setNr, setNr2, "map", name, dataset, 0, 0, node, 0, 1);
14072       else areampc(setNr, setNr2, "map", name, dataset, 0, 0, node, 1, 1);
14073     }
14074     else if (compare(name, "volu", 1)==1)
14075     {
14076       if(dat[0][0]=='n') i=interpol3d(setNr, setNr2, name, dataset, 0);
14077       else i=interpol3d(setNr, setNr2, name, dataset, 1 );
14078       if(i) printf(" WARNING: set %s includes nodes which could not be mapped\n", set[i].name);
14079     }
14080     else
14081     {
14082       printf(" ERROR: Neither 'surf' nor 'volu' given: %s\n", name);
14083       goto checkForError;
14084     }
14085 
14086     printf(" Mapping done with %e times gtol=%e. The user might increase gtol if needed.\n",GTOL_FACTOR_MAP,gtol);
14087     gtol=x;
14088 
14089     redraw();
14090   }
14091   else if (compareStrings(type, "MATA")>0)
14092   {
14093     length = sscanf(&string[na+1], "%d %s", &nr, name);
14094     if(length<2) { printf(" wrong syntax\n"); goto checkForError; }
14095     operateAlias( name, "se" );
14096     setNr=getSetNr(name);
14097     if (setNr<0)
14098     {
14099       printf (" ERROR in mata: set:%s does not exist\n", name);
14100       goto checkForError;
14101     }
14102     mata( elemMat, nr, setNr);
14103   }
14104   else if (compareStrings(type, "MATS")>0)
14105   {
14106     for (i=0; i<anz->e; i++)
14107     {
14108       sprintf(name,"%d", e_enqire[i].nr);
14109       sprintf(buffer, "+mat%d", e_enqire[e_enqire[i].nr].mat );
14110       pre_seta( buffer, "e", name );
14111     }
14112     prnt("se +mat*");
14113   }
14114   else if (compareStrings(type, "MAXC")>0)
14115   {
14116     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14117     sscanf( string, "%*s %lf %c %c",&scale->smax,&scale->format,&scale->lock );
14118     scale->smaxr=2;
14119     redraw();
14120   }
14121   else if (compareStrings(type, "MAXR")>0)
14122   {
14123     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14124     sscanf( string, "%*s %lf %c %c",&scale->smax,&scale->format,&scale->lock );
14125     scale->smaxr=1;
14126     redraw();
14127   }
14128   else if (compareStrings(type, "MAX")>0)
14129   {
14130     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14131     sscanf( string, "%*s %lf %c %c",&scale->smax,&scale->format,&scale->lock );
14132     scale->smaxr=0;
14133     redraw();
14134   }
14135   else if (compareStrings(type, "MENU")>0)
14136   {
14137     pre_menu( &string[na+1] );
14138   }
14139   else if (compareStrings(type, "MERG")>0)
14140   {
14141     pre_merge( &string[na+1] );
14142     redraw();
14143   }
14144   else if (compareStrings(type, "MESH")>0)
14145   {
14146     if(addDispFlag)
14147     {
14148       addDispToCoordinates(node);
14149       addDispFlagLocal=2;
14150     }
14151     delSet("-EDGE");
14152     nr=pre_mesh( &string[na+1] );
14153     //adjustDrawNodes(0);
14154     //getElemNormalen( e_enqire, node, anz->e );
14155     //makeSurfaces();
14156     if(automode==1) { fixBadDivisions(nr); automode=0; }
14157 
14158     if(addDispFlagLocal==2)
14159     {
14160       addDispToCoordinates(node);
14161     }
14162     redraw();
14163   }
14164   else if (compareStrings(type, "MIDS")>0)
14165   {
14166     if(addDispFlag==1)
14167     {
14168       printf (" WARNING: displacements were added to the node-coords. This is not permitted\n");
14169       addDispToCoordinates(node);
14170     }
14171     pre_view(" surf");
14172     sscanf( string, "%*s %s %s", setname, comm);
14173 
14174     /* free the additional midside-nodes for higher order elements */
14175     for(i=anz->orign; i<anz->n; i++) node[node[i].nr].pflag=-1;
14176     anz->n= anz->orign;
14177     anz->nmax=anz->orignmax;
14178     fixMidsideNodes( setname, comm );
14179 
14180     adjustDrawNodes(1);
14181 
14182     makeSurfaces();        // includes getFaceNormalen
14183     getElemNormalen( e_enqire, node, anz->e );
14184     if(compare(comm,"gen",2)==2)
14185     {
14186       for (j=0; j<anz->l; j++)
14187       {
14188         freeDataset(lcase, j);
14189       }
14190       free(lcase); lcase=NULL;
14191       anz->l=0;
14192       printf (" WARNING: Results were intentionally not interpolated to new nodes. Do not work with Datasets any more.\n");
14193       updateDispLists();
14194       createNewMainMenu();
14195     }
14196     else
14197     {
14198       updateDispLists();
14199     }
14200     redraw();
14201   }
14202   else if (compareStrings(type, "MINUS")>0)
14203   {
14204     minus(&string[na+1] );
14205   }
14206   else if (compareStrings(type, "MINC")>0)
14207   {
14208     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14209     sscanf( string, "%*s %lf %c %c",&scale->smin,&scale->format,&scale->lock );
14210     scale->sminr=2;
14211     redraw();
14212   }
14213   else if (compareStrings(type, "MINR")>0)
14214   {
14215     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14216     sscanf( string, "%*s %lf %c %c",&scale->smin,&scale->format,&scale->lock );
14217     scale->sminr=1;
14218     redraw();
14219   }
14220   else if (compareStrings(type, "MIN")>0)
14221   {
14222     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14223     sscanf( string, "%*s %lf %c %c",&scale->smin,&scale->format,&scale->lock );
14224     scale->sminr=0;
14225     redraw();
14226   }
14227   else if (compareStrings(type, "MM")>0)
14228   {
14229     if((animFlag)&&(!halfperiod)) { printf("ERROR: The scale can not be changed during animation\n\n"); return(1); }
14230     sscanf( string, "%*s %lf %c %c",&scale->smax,&scale->format,&scale->lock );
14231     scale->smin=-scale->smax;
14232     redraw();
14233   }
14234   else if (compareStrings(type, "MOVE")>0)
14235   {
14236     pre_move( &string[na+1] );
14237     redraw();
14238   }
14239   else if (compareStrings(type, "MOVI")>0)
14240   {
14241     pre_movie( &string[na+1] );
14242   }
14243   else if (compareStrings(type, "MSHP")>0)
14244   {
14245     buffer[0]=0;
14246     k=0;
14247     l=0;
14248     if(!addFlag) length = sscanf( string, "%*s%s%s%d%d%s", name, entity, &k,&l, buffer);
14249     else
14250     {
14251       name[0]='%';
14252       length = sscanf( string, "%*s%s%s%d%d%s", &name[1], entity, &k,&l, buffer);
14253     }
14254     if(entity[0]=='l')
14255     {
14256       operateAlias( name,"l");
14257       nr=getLineNr(name);
14258       if(nr>-1)
14259       {
14260         line[nr].etyp=k;
14261         line[nr].eattr=l;
14262       }
14263     }
14264     else if(entity[0]=='s')
14265     {
14266       operateAlias( name,"s");
14267       nr=getSurfNr(name);
14268       if(nr>-1)
14269       {
14270         if(strlen(buffer))
14271 	{
14272           if((surf[nr].eparm= (char *)realloc((char *)surf[nr].eparm, (strlen(buffer)+1)*sizeof(char))) == NULL )
14273           { printf("ERROR: malloc failed\n\n" ); goto checkForError; }
14274           strcpy(surf[nr].eparm, buffer);
14275 	}
14276         surf[nr].etyp=k;
14277         surf[nr].eattr=l;
14278       }
14279     }
14280     else if(entity[0]=='b')
14281     {
14282       operateAlias( name,"b");
14283       nr=getBodyNr(name);
14284       if(nr>-1)
14285       {
14286         if(strlen(buffer))
14287 	{
14288           if((body[nr].eparm= (char *)realloc((char *)body[nr].eparm, (strlen(buffer)+1)*sizeof(char))) == NULL )
14289           { printf("ERROR: malloc failed\n\n" ); goto checkForError; }
14290           strcpy(body[nr].eparm, buffer);
14291 	}
14292         body[nr].etyp=k;
14293         body[nr].eattr=l;
14294       }
14295     }
14296   }
14297   else if ( compareStrings(type, "MSG")>0 )
14298   {
14299     sscanf( string, "%*s%s", buffer );
14300     if ( compareStrings(buffer, "on")>0) printFlag=1;
14301     else if ( compareStrings(buffer, "off")>0) printFlag=0;
14302     else printf(" %s not recognized (use on/off)\n", buffer);
14303   }
14304   else if (compareStrings(type, "NEIGH")>0)
14305   {
14306     pre_contact(&string[na+1]);
14307   }
14308   else if (compareStrings(type, "NODE")>0)
14309   {
14310     if(addDispFlag==1) { printf (" WARNING: displacements were added to the node-coords. This is not permitted\n"); addDispToCoordinates(node); }
14311     sscanf(&string[na+1],"%d %s",&nr,buffer);
14312     if(buffer[0]!='v') pre_nod(&string[na+1]);
14313     else
14314     {
14315       if((nr<1)||(nr>anz->nmax))
14316       {
14317         printf (" WARNING: node:%d from string:%s not known\n", nr,&string[na+1]);
14318         return(-1);
14319       }
14320       else if(anz->l)
14321       {
14322         /* check if the data of the specified lcase (Dataset) are already available */
14323         if (!lcase[cur_lc].loaded)
14324         {
14325           if( pre_readfrdblock(copiedNodeSets , cur_lc, anz, node, lcase )==-1)
14326           {
14327             printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", cur_lc+1);
14328             return(-1);
14329           }
14330 	}
14331         if(buffer[1]=='s') lcase[cur_lc].dat[cur_entity][nr]=atof(dat[i+2]);
14332         else
14333 	{
14334           args=brecord(&string[na], dat);
14335           if( lcase[cur_lc].ncomps < (args-2) )
14336           {
14337             printf(" ERROR: Defined entities:%d but active dataset:%d has only:%d entities\n",args-2, cur_lc+1,lcase[cur_lc].ncomps );
14338             return(-1);
14339           }
14340           for(i=0; i<args-2; i++) lcase[cur_lc].dat[i][nr]=atof(dat[i+2]);
14341 	}
14342       }
14343       else
14344       {
14345         printf(" ERROR: No active dataset available\n");
14346         return(-1);
14347       }
14348     }
14349   }
14350   else if (compareStrings(type, "NORM")>0)
14351   {
14352     pre_norm(&string[na+1]);
14353   }
14354   else if (compareStrings(type, "NURL")>0)
14355   {
14356     if(nurl( &string[na+1], addFlag )==-1) return(-1);
14357   }
14358   else if (compareStrings(type, "NURS")>0)
14359   {
14360     i=pre_nurs( &string[na+1], addFlag);
14361     if(i==-1) return(-1);
14362   }
14363   else if (compareStrings(type, "ORI")>0)
14364   {
14365     orientSet( &string[na+1] );
14366   }
14367   else if (compareStrings(type, "PLOT")>0)
14368   {
14369     /* trigger new scale-values */
14370     length=sscanf(&string[na+1],"%s", format);
14371     if((compareStrings(format,"ev")>0)||(compareStrings(format,"fv")>0)) { if(scale->lock!='l') scale->smin=scale->smax=0; }
14372     plot( &string[na+1] );
14373   }
14374   else if (compareStrings(type, "PLUS")>0)
14375   {
14376     /* trigger new scale-values */
14377     if((compareStrings(format,"ev")>0)||(compareStrings(format,"fv")>0)) { if(scale->lock!='l') scale->smin=scale->smax=0; }
14378     plus( &string[na+1] );
14379   }
14380   else if (compareStrings(type, "PNT")>0)
14381   {
14382     pre_pnt( &string[na+1], addFlag );
14383   }
14384   else if (compareStrings(type, "PROJ")>0)
14385   {
14386     if(addDispFlag==1) { printf (" WARNING: displacements were added to the node-coords. Projection of nodes might fail.\n"); }
14387     pre_proj( string );
14388   }
14389   else if (compareStrings(type, "PROC")>0)
14390   {
14391     pre_proc( &string[na+1] );
14392   }
14393   else if (compareStrings(type, "PRNT")>0) prnt(&string[na+1]);
14394   else if (compareStrings(type, "QUIT")>0) exit(0);
14395   else if (compareStrings(type, "READ")>0)
14396   {
14397     returnFlag=pre_read(&string[na+1]);
14398   }
14399   else if (compareStrings(type, "REP")>0)
14400   {
14401     nr=getSetNr(&string[na+1]);
14402     if(nr<0)
14403     {
14404       printf("ERROR: Set:[%s] in command:|%s| does not exist\n",&string[na+1],string);
14405       goto checkForError;
14406     }
14407     delSet(specialset->bsur);
14408     set_bsur=pre_seta(specialset->bsur, "i", 0);
14409     if( compareStrings(&string[na+1],"all")>0)
14410     {
14411       for (i=0; i<anzGeo->l; i++) repLine(i);
14412       for (i=0; i<anzGeo->nurl; i++) repNurl(i);
14413       for (i=0; i<anzGeo->nurs; i++) repNurs(i);
14414       /* delete the data-structures for trimming of the nurbs */
14415       for (i=0; i<anzGeo->nurs; i++) untrimNurs(i);
14416       /* recalculate the nurbs-trimming-points (after repNurs) */
14417       /* set "all" to avoid substitute surfs */
14418       j=getSetNr("all");
14419       //if(j>=0) for (i=0; i<set[j].anz_s; i++) repSurf(set[j].surf[i],1);
14420       pre_repSurf(j);
14421       for (i=0; i<anzGeo->nurs; i++) untrimNurs(i);
14422     }
14423     else
14424     {
14425       for (i=0; i<set[nr].anz_l; i++) repLine(set[nr].line[i]);
14426       for (i=0; i<set[nr].anz_nurl; i++) repNurl(set[nr].nurl[i]);
14427       for (i=0; i<set[nr].anz_nurs; i++) repNurs(set[nr].nurs[i]);
14428       for (i=0; i<set[nr].anz_nurs; i++) untrimNurs(set[nr].nurs[i]);
14429       //for (i=0; i<set[nr].anz_s; i++) repSurf(set[nr].surf[i],1);
14430       pre_repSurf(nr);
14431       for (i=0; i<set[nr].anz_nurs; i++) untrimNurs(set[nr].nurs[i]);
14432     }
14433     /* reposition the internal drawing nodes */
14434     if(anz->e>0)
14435     {
14436       adjustDrawNodes(0);
14437       //makeSurfaces();
14438       updateDispLists();
14439     }
14440     if(set[set_bsur].anz_s)
14441       printf("WARNING: %d surfaces could not be filled, see set:%s\n", set[i].anz_s,specialset->bsur);
14442     delSet(specialset->bsur);
14443   }
14444   else if (compareStrings(type, "RNAM")>0)
14445   {
14446     sscanf(string, "%*s %s%s", name, xbuf );
14447     setNr=getSetNr(xbuf);
14448     if (setNr>-1)
14449     {
14450       printf ("ERROR: set:%s exist already\n", xbuf);
14451       goto checkForError;;
14452     }
14453 
14454     setNr=getSetNr(name);
14455     if (setNr<0)
14456     {
14457       printf ("ERROR: set:%s does not exist\n", name);
14458     }
14459     else
14460     {
14461       printf(" rename %s", set[setNr].name );
14462       rnam(setNr, xbuf );
14463       printf(" to %s \n ", set[setNr].name );
14464     }
14465   }
14466   else if (compareStrings(type, "ROT")>0)
14467   {
14468     pre_rot( &string[na+1] );
14469     // redraw re-sets an eventual sequence
14470     i=valuestackFlag;
14471     valuestackFlag=0;
14472     redraw();
14473     valuestackFlag=i;
14474   }
14475   else if ( compareStrings(type, "SAVE")>0 )
14476   {
14477     strcpy(setname,datin);
14478     for (i=strlen(datin); i>=0; i--)
14479     {
14480       if(datin[i]=='.')break;
14481     }
14482     setname[i]='\0';
14483 #ifdef WIN32
14484     sprintf (buffer, "move /y \"%s\" \"%s.fbb\"", datin, setname );
14485 #else
14486     sprintf (buffer, "mv %s %s.fbb", datin, setname );
14487 #endif
14488     if(compare(&datin[i+1],"fbd",3)==3) system (buffer);
14489     pre_write(" all fbd ");
14490     if( compareStrings( setname, "all")<1 )
14491     {
14492 #ifdef WIN32
14493       sprintf (buffer, "move /y all.fbd \"%s.fbd\"", setname );
14494 #else
14495       sprintf (buffer, "mv all.fbd %s.fbd", setname );
14496 #endif
14497       system (buffer);
14498     }
14499   }
14500   else if ( compareStrings(type, "SCAL")>0 )
14501   {
14502     entity[0]=0; x=0.;
14503     length=sscanf(&string[na+1],"%s %lf", entity, &x);
14504     /* vector length */
14505     if(entity[0]=='v')
14506     {
14507       if(x!=0.)  v_scale*=x;
14508       else v_scale=1.;
14509       updateDispLists();
14510     }
14511     else if(entity[0]=='d')
14512     {
14513       if(x!=0.) anim_faktor*=x;
14514       else  anim_faktor=1.;
14515       if(addDispFlag==1)
14516       {
14517          addDispToCoordinates(node);
14518          addDispToCoordinates(node);
14519       }
14520       redraw();
14521     }
14522     else if(entity[0]=='s')
14523     {
14524       scale->smin*=x; scale->smax*=x;
14525       redraw();
14526     }
14527     else printf("type:%s not known, factor:%lf\n", entity, x);
14528   }
14529   else if (compareStrings(type, "SEND")>0)
14530   {
14531     pre_write( &string[na+1] );
14532   }
14533   else if (compareStrings(type, "SEQA")>0)
14534   {
14535     /* if the name is in use and no valid data are spec. then the seq will be overwritten */
14536     /* if the name is in use and valid data are spec. then the command is ignored */
14537 
14538     /* for the moment the commands AFTE and BEFO are wrong interpreted */
14539 
14540     /* determine the commands */
14541     na= sscanf( string, "%*s %s%s%s%s ", name, dat[0],dat[1],dat[2]);
14542     /* search for valid commands */
14543     if((dat[0][0]=='A')||(dat[0][0]=='a'))
14544     {
14545       if (addFlag) { for(j=strlen(name); j>=0; j--) name[j+1]=name[j]; name[0]='%'; }
14546       operateAlias( name, "se" );
14547       if( na < 4) goto checkForError;
14548       strcpy(comm,"AFTE");
14549       if (addFlag) { for(j=strlen(dat[1]); j>=0; j--) dat[1][j+1]=dat[1][j]; dat[1][0]='%'; }
14550       operateAlias( dat[1], "p" );
14551       strcpy(posn,dat[1]);
14552       strcpy(entity,dat[2]);
14553       strcpy(format
14554       , "%*s%*s%*s%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
14555     }
14556     else if((dat[0][0]=='B')||(dat[0][0]=='b'))
14557     {
14558       if (addFlag) { for(j=strlen(name); j>=0; j--) name[j+1]=name[j]; name[0]='%'; }
14559       operateAlias( name, "se" );
14560       if( na < 4) goto checkForError;
14561       strcpy(comm,"BEFO");
14562       if (addFlag) { for(j=strlen(dat[1]); j>=0; j--) dat[1][j+1]=dat[1][j]; dat[1][0]='%'; }
14563       operateAlias( dat[1], "p" );
14564       strcpy(posn,dat[1]);
14565       strcpy(entity,dat[2]);
14566       strcpy(format
14567       , "%*s%*s%*s%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
14568     }
14569     else if ((dat[0][0]=='E')||(dat[0][0]=='e'))
14570     {
14571       if (addFlag) { for(j=strlen(name); j>=0; j--) name[j+1]=name[j]; name[0]='%'; }
14572       operateAlias( name, "se" );
14573       if( na < 3) goto checkForError;
14574       strcpy(comm,"END");
14575       strcpy(entity,dat[1]);
14576       strcpy(format
14577       , "%*s%*s%*s%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
14578     }
14579     else
14580     {
14581       if (addFlag) { for(j=strlen(name); j>=0; j--) name[j+1]=name[j]; name[0]='!'; }
14582       operateAlias( name, "se" );
14583       if( na < 3) goto checkForError;
14584       strcpy(comm,"NEW");
14585       strcpy(entity,dat[0]);
14586       strcpy(format
14587       , "%*s%*s%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
14588     }
14589 
14590     j=anz_seq=0;
14591   newline:;
14592     na =   sscanf( string,format
14593               , dat[0],dat[1],dat[2],dat[3],dat[4],dat[5], dat[6],dat[7],dat[8],dat[9]
14594               , dat[10],dat[11],dat[12],dat[13],dat[14],dat[15], dat[16],dat[17],dat[18],dat[19]);
14595     anz_seq+=na;
14596     if( (seq = (char **)realloc((char **)seq, (anz_seq)*sizeof(char *))) == NULL )
14597     { printf(" ERROR: realloc failure in interpreter()\n\n"); return(-1); }
14598     for (i=anz_seq-na; i<anz_seq; i++)
14599     {
14600       if( (seq[i]= (char *)malloc( MAX_LINE_LENGTH*sizeof(char))) == NULL )
14601       { printf(" ERROR: malloc failure in interpreter()\n\n"); return(-1); }
14602     }
14603 
14604     /* look if the command-line continues */
14605     for (i=0; i<na; i++)
14606     {
14607       /* printf("dat:%d |%s|\n",i, dat[i]); */
14608       if(dat[i][0]=='=')
14609       {
14610         length = frecord( handle1, string);
14611         strcpy(format
14612         , "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
14613         goto newline;
14614       }
14615       if (addFlag) { for(l=strlen(dat[i]); l>=0; l--) dat[i][l+1]=dat[i][l]; dat[i][0]='%'; }
14616       operateAlias( dat[i], "p" );
14617       strcpy(seq[j], dat[i]);
14618       j++;
14619     }
14620 
14621     if((entity[0]=='N')||entity[0]=='n') type[0]='n';
14622     else if((entity[0]=='P')||entity[0]=='p') type[0]='p';
14623     else
14624     {
14625       errMsg(" ERROR in SEQA: entity not known\n" );
14626       goto checkForError;
14627     }
14628     /* mark the set as a sequence-set */
14629     type[1]='s';
14630 
14631     if(comm[0]=='A')
14632     {
14633       /* the set exists */
14634       setNr=getSetNr( name );
14635       if (setNr<0)
14636       {
14637         printf (" ERROR: set:%s does not exist\n", name);
14638         goto checkForError;
14639       }
14640 
14641       if(type[0]=='p') ibuf=set[setNr].anz_p+anz_seq;
14642       if(type[0]=='n') ibuf=set[setNr].anz_n+anz_seq;
14643       if((buf=(char **)malloc(ibuf*sizeof(char *)))==NULL)
14644       { printf(" ERROR: realloc failure in interpreter()\n\n"); return(-1); }
14645       for (i=0; i<ibuf; i++)
14646       {
14647         if( (buf[i]= (char *)malloc( MAX_LINE_LENGTH*sizeof(char))) == NULL )
14648         { printf(" ERROR: realloc failure in interpreter()\n\n"); return(-1); }
14649       }
14650 
14651       j=0;
14652       if( type[0]=='p')
14653       {
14654        for (i=0; i<set[setNr].anz_p; i++)
14655        {
14656         strcpy( buf[j], point[set[setNr].pnt[i]].name); j++;
14657         if( compareStrings( point[set[setNr].pnt[i]].name, posn)>0)
14658         {
14659           for (k=0; k<anz_seq; k++) { strcpy( buf[j], seq[k]); j++; }
14660         }
14661        }
14662        set[setNr].anz_p = 0;
14663       }
14664       if( type[0]=='n')
14665       {
14666        for (i=0; i<set[setNr].anz_n; i++)
14667        {
14668         sprintf( buf[j],"%d", set[setNr].node[i]);
14669         if( compareStrings( buf[j], posn)>0)
14670         {
14671           for (k=0; k<anz_seq; k++) { j++; strcpy( buf[j], seq[k]); }
14672         }
14673         j++;
14674        }
14675        set[setNr].anz_n = 0;
14676       }
14677       for (i=0; i<j; i++)
14678       {
14679         pre_seta( name, type, buf[i]);
14680       }
14681 
14682       for (i=0; i<ibuf; i++) free(buf[i]); free(buf);
14683     }
14684     else if(comm[0]=='B')
14685     {
14686       /* the set exists */
14687       setNr=getSetNr( name );
14688       if (setNr<0)
14689       {
14690         printf (" ERROR: set:%s does not exist\n", name);
14691         goto checkForError;
14692       }
14693 
14694       if(type[0]=='p') ibuf=set[setNr].anz_p+anz_seq;
14695       if(type[0]=='n') ibuf=set[setNr].anz_n+anz_seq;
14696       if((buf=(char **)malloc(ibuf*sizeof(char *)))==NULL)
14697       { printf(" ERROR: realloc failure in interpreter()\n\n"); return(-1); }
14698       for (i=0; i<ibuf; i++)
14699       {
14700         if( (buf[i]= (char *)malloc( MAX_LINE_LENGTH*sizeof(char))) == NULL )
14701         { printf(" ERROR: realloc failure in interpreter()\n\n"); return(-1); }
14702       }
14703 
14704       j=0;
14705       if( type[0]=='p')
14706       {
14707        for (i=0; i<set[setNr].anz_p; i++)
14708        {
14709         if( compareStrings( point[set[setNr].pnt[i]].name, posn)>0)
14710         {
14711           for (k=0; k<anz_seq; k++) { strcpy( buf[j], seq[k]); j++; }
14712         }
14713         strcpy( buf[j], point[set[setNr].pnt[i]].name); j++;
14714        }
14715        set[setNr].anz_p = 0;
14716       }
14717       if( type[0]=='n')
14718       {
14719        for (i=0; i<set[setNr].anz_n; i++)
14720        {
14721         sprintf( xbuf,"%d", set[setNr].node[i]);
14722         if( compareStrings( xbuf, posn)>0)
14723         {
14724           for (k=0; k<anz_seq; k++) { strcpy( buf[j], seq[k]); j++; }
14725         }
14726         sprintf( buf[j],"%d", set[setNr].node[i]); j++;
14727        }
14728        set[setNr].anz_n = 0;
14729       }
14730       for (i=0; i<j; i++)
14731       {
14732         pre_seta( name, type, buf[i]);
14733       }
14734 
14735       for (i=0; i<ibuf; i++) free(buf[i]); free(buf);
14736     }
14737     else if(comm[0]=='E')
14738     {
14739       for (i=0; i<anz_seq; i++)
14740       {
14741         pre_seta( name, type, seq[i]);
14742       }
14743     }
14744     else if(comm[0]=='N')
14745     {
14746       delSet(name);
14747       for (i=0; i<anz_seq; i++)
14748       {
14749         pre_seta( name, type, seq[i]);
14750       }
14751     }
14752 
14753     for (i=0; i<anz_seq; i++) free(seq[i]);
14754   }
14755   else if (compareStrings(type, "SEQC")>0)
14756   {
14757     na= sscanf( string, "%*s %s", name);
14758     setNr=getSetNr(name);
14759     if(setNr<0)
14760     {
14761       printf (" set:%s does not exist\n", name);
14762       goto checkForError;
14763     }
14764     if( (picnr = (int *)realloc( (int *)picnr, (set[setNr].anz_c) * sizeof(int))) == NULL )
14765     {  printf("\n\n ERROR: realloc failed, hcpy\n\n"); }
14766     for(i=0; i<set[setNr].anz_c; i++) picnr[i]=set[setNr].lcmb[i];
14767     pics=set[setNr].anz_c;
14768     l=1;
14769     if(set[setNr].flag=='c') seto(set[setNr].name);
14770     else l=0;
14771     for(i=0; i<pics; i++) convertLCMB( picnr[i]);
14772     if(l) setc(set[setNr].name);
14773   }
14774   else if (compareStrings(type, "SEQL")>0)
14775   {
14776     k=0;
14777     na= sscanf( string, "%*s %s %d", name, &k);
14778     setNr=getSetNr(name);
14779     if(setNr<0)
14780     {
14781       printf (" set:%s does not exist\n", name);
14782       goto checkForError;
14783     }
14784     if(k<0)
14785     {
14786       printf (" the nr of spline-points must be positive\n");
14787       goto checkForError;
14788     }
14789     if(k==0)
14790     {
14791       for(i=0; i<set[setNr].anz_l; i++) line[set[setNr].line[i]].typ=' ';
14792       return(0);
14793     }
14794     l=1;
14795     if(set[setNr].flag=='c') seto(set[setNr].name);
14796     else l=0;
14797     for(i=0; i<set[setNr].anz_l; i++) convertLine( set[setNr].line[i],k);
14798     if(l) setc(set[setNr].name);
14799   }
14800   else if (compareStrings(type, "SETA")>0)
14801   {
14802     na =   sscanf( string, "%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
14803                name, type, dat[0],dat[1],dat[2],dat[3],dat[4],dat[5], dat[6],dat[7],dat[8],dat[9],
14804                dat[10],dat[11],dat[12],dat[13],dat[14],dat[15], dat[16],dat[17],dat[18],dat[19]);
14805 
14806     /* create sets for disjunct meshes */
14807     if((strlen(name)==1)&&(name[0]=='!'))
14808     {
14809       if(type[0]=='e') separateMeshes(dat[0], specialset->cf);
14810       else if(type[0]=='l') separateLines(dat[0], specialset->cf);
14811       else separateMeshes(type, specialset->cf);
14812       goto checkForError;
14813     }
14814 
14815     /* check if the setname matches a seqential-set (sq). if yes do not add entities */
14816     l=getSetNr(name);
14817     if (l>-1)
14818     {
14819       if(set[l].type==1)
14820       {
14821         printf("ERROR: setname:%s in use by a sequence. Set can not be created.\n", name);
14822         goto checkForError;
14823       }
14824     }
14825 
14826     /* Single letters (except 'se' 'sh' 'ld') determine the type of the following entities in cgx. */
14827     /* In FAM no indication of the type is given. So if the name of the entity */
14828     /* consists only of a single letter (or 'se'), it will be ignored. */
14829     if (((type[0]=='n')&&(type[1]=='\0'))||
14830         ((type[0]=='e')&&(type[1]=='\0'))||
14831         ((type[0]=='f')&&(type[1]=='\0'))||
14832         ((type[0]=='v')&&(type[1]=='\0'))||
14833         ((type[0]=='p')&&(type[1]=='\0'))||
14834         ((type[0]=='l')&&(type[1]=='\0'))||
14835         ((type[0]=='l')&&(type[1]=='d'))||
14836         ((type[0]=='c')&&(type[1]=='\0'))||
14837         ((type[0]=='r')&&(type[1]=='\0'))||
14838         ((type[0]=='s')&&(type[1]=='\0'))||
14839         ((type[0]=='s')&&(type[1]=='e'))||
14840         ((type[0]=='s')&&(type[1]=='h'))||
14841         ((type[0]=='L')&&(type[1]=='\0'))||
14842         ((type[0]=='S')&&(type[1]=='\0'))||
14843         ((type[0]=='b')&&(type[1]=='\0')) )
14844     {
14845       /* look if a sequence is defined */
14846       if((dat[1][0]=='-')&&(dat[1][1]=='\0'))
14847       {
14848         if((type[0]!='n')&&(type[0]!='e'))
14849         {
14850           printf("ERROR: sequence only possible for nodes and elements. Set %s can not be created.\n", name);
14851           goto checkForError;
14852         }
14853         for(i=atoi(dat[0]); i<=atoi(dat[2]); i+=atoi(dat[3]) )
14854         {
14855           sprintf(buffer,"%d",i);
14856           pre_seta( name, type, buffer);
14857         }
14858       }
14859       else
14860       {
14861         for (i=0; i<na-2; i++)
14862         {
14863           if (addFlag) { for(l=strlen(dat[i]); l>=0; l--) dat[i][l+1]=dat[i][l]; dat[i][0]='%'; }
14864           operateAlias( dat[i], type );
14865 
14866           /* try to add entity of type to the set, if it fails the entity might be a set itself */
14867           if( pre_seta( name, type, dat[i]) == -1)
14868 	  {
14869             /* look if a set of this name exists */
14870             nr=getSetNr(dat[i]);
14871             if(nr<0)
14872             {
14873               /* set was not found. check if wildcards (*) were used */
14874               length= strsplt( dat[i], '*', &substring);
14875               if ((length>0)&&(strstr(dat[i], "*") !=NULL))
14876               {
14877                 for(setNr=0; setNr<anz->sets; setNr++) if(set[setNr].name!=(char *)NULL)
14878                 {
14879                   foundSubString=0;
14880                   for(l=0; l<length; l++)
14881                   {
14882                     if(strstr(set[setNr].name, substring[l]) !=NULL)
14883                     {
14884                       foundSubString++;
14885                       /* check if the first or the last char is no '*' then the substring[] must be at start or end */
14886           	      if(l==0) { if(dat[i][0]!='*')  { if(dat[i][0]!=set[setNr].name[0])  foundSubString--; }  }
14887                	      if(l==length-1) { if(dat[i][strlen(dat[i])-1]!='*') { if(dat[i][strlen(dat[i])-1]!=set[setNr].name[strlen(set[setNr].name)-1])  foundSubString--; } }
14888             	    }
14889             	  }
14890                   if(foundSubString==length)
14891                   {
14892                     nr=setNr;
14893 	            printf(" set:%s matches %s\n", set[nr].name, dat[i]);
14894                     if( pre_seta( name, type, set[nr].name ) == -1)
14895 	            {
14896                         k=pre_seta( name, "i", 0);
14897                         if ( type[0] == 'n' )        for(j=0; j<set[nr].anz_n; j++) seta(k,type,set[nr].node[j]);
14898                         else if ( type[0] == 'e' )   for(j=0; j<set[nr].anz_e; j++) seta(k,type,set[nr].elem[j]);
14899                         else if ( type[0] == 'f' )   for(j=0; j<set[nr].anz_f; j++) seta(k,type,set[nr].face[j]);
14900                         else if ( type[0] == 'v' )   for(j=0; j<set[nr].anz_v; j++) seta(k,type,set[nr].valu[j]);
14901                         else if ( type[0] == 'p' )   for(j=0; j<set[nr].anz_p; j++) seta(k,type,set[nr].pnt[j]);
14902                         else if ( type[0] == 'l' )
14903 			{
14904                           if((type[1]=='d')&&(type[2]!='\0'))
14905 			  {
14906                             for(j=0; j<set[nr].anz_l; j++) if(line[set[nr].line[j]].div>=atoi(&type[2])) seta(k,type,set[nr].line[j]);
14907 			  }
14908 			  else if(type[1]!='\0') { for(j=0; j<set[nr].anz_l; j++) seta(k,type,set[nr].line[j]); }
14909 			}
14910                         else if ( type[0] == 'c' )   for(j=0; j<set[nr].anz_c; j++) seta(k,type,set[nr].lcmb[j]);
14911                         else if (( type[0] == 's' )&&(type[1]=='\0'))   for(j=0; j<set[nr].anz_s; j++) seta(k,type,set[nr].surf[j]);
14912                         else if (( type[0] == 's' )&&(type[1]=='h'))   for(j=0; j<set[nr].anz_sh; j++) seta(k,type,set[nr].shp[j]);
14913                         else if ( type[0] == 'b' )   for(j=0; j<set[nr].anz_b; j++) seta(k,type,set[nr].body[j]);
14914                         else if ( type[0] == 'L' )   for(j=0; j<set[nr].anz_nurl; j++) seta(k,type,set[nr].nurl[j]);
14915                         else if ( type[0] == 'S' )   for(j=0; j<set[nr].anz_nurs; j++) seta(k,type,set[nr].nurs[j]);
14916                     }
14917                   }
14918                 }
14919               }
14920               /* free substring */
14921               for(j=0; j<length; j++) free(substring[j]);
14922               free(substring);
14923             }
14924             else
14925             {
14926 		//printf(" entity:%s of type:%c does not exist add contents of set:%d\n", dat[i], type[0], nr);
14927               k=pre_seta( name, "i", 0);
14928 	      if ( type[0] == 'n' )        for(j=0; j<set[nr].anz_n; j++) seta(k,type,set[nr].node[j]);
14929 	      else if ( type[0] == 'e' )   for(j=0; j<set[nr].anz_e; j++) seta(k,type,set[nr].elem[j]);
14930 	      else if ( type[0] == 'f' )   for(j=0; j<set[nr].anz_f; j++) seta(k,type,set[nr].face[j]);
14931  	      else if ( type[0] == 'v' )   for(j=0; j<set[nr].anz_v; j++) seta(k,type,set[nr].valu[j]);
14932  	      else if ( type[0] == 'p' )   for(j=0; j<set[nr].anz_p; j++) seta(k,type,set[nr].pnt[j]);
14933               else if ( type[0] == 'l' )
14934 	      {
14935                 if((type[1]=='d')&&(type[2]!='\0'))
14936 	        {
14937                   for(j=0; j<set[nr].anz_l; j++) if(line[set[nr].line[j]].div>=atoi(&type[2])) seta(k,type,set[nr].line[j]);
14938 	        }
14939 	        else if(type[1]=='\0') { for(j=0; j<set[nr].anz_l; j++) seta(k,type,set[nr].line[j]); }
14940 		else printf(" ERROR: Parameter:%s unknown\n",type);
14941 	      }
14942  	      else if ( type[0] == 'c' )   for(j=0; j<set[nr].anz_c; j++) seta(k,type,set[nr].lcmb[j]);
14943  	      else if (( type[0] == 's' )&&(type[1]=='\0'))   for(j=0; j<set[nr].anz_s; j++) seta(k,type,set[nr].surf[j]);
14944  	      else if (( type[0] == 's' )&&(type[1]=='h'))   for(j=0; j<set[nr].anz_sh; j++) seta(k,type,set[nr].shp[j]);
14945  	      else if ( type[0] == 'b' )   for(j=0; j<set[nr].anz_b; j++) seta(k,type,set[nr].body[j]);
14946  	      else if ( type[0] == 'L' )   for(j=0; j<set[nr].anz_nurl; j++) seta(k,type,set[nr].nurl[j]);
14947  	      else if ( type[0] == 'S' )   for(j=0; j<set[nr].anz_nurs; j++) seta(k,type,set[nr].nurs[j]);
14948 	    }
14949           }
14950         }
14951       }
14952 
14953       if((type[0]=='s')&&(type[1]=='e'))
14954       {
14955         completeSet( name, "do");
14956       }
14957     }
14958     else
14959     {
14960       /* items of unknown type, determine each type */
14961       if (addFlag) { for(l=strlen(type); l>=0; l--) type[l+1]=type[l]; type[0]='%'; }
14962       ibuf=0;
14963       operateAlias( type, "v" ); if (getValuNr(type) >-1)  {  pre_seta( name, "v", type); goto next_seta;  }
14964       operateAlias( type, "b" ); if (getBodyNr(type) >-1)  {  pre_seta( name, "b", type); goto next_seta;  }
14965       operateAlias( type, "s" ); if (getSurfNr(type) >-1)  {  pre_seta( name, "s", type); goto  next_seta;  }
14966       operateAlias( type, "c" ); if (getLcmbNr(type) >-1)  {  pre_seta( name, "c", type); goto  next_seta;  }
14967       operateAlias( type, "l" ); if (getLineNr(type) >-1)  {  pre_seta( name, "l", type); goto  next_seta;  }
14968       operateAlias( type, "p" ); if (getPntNr(type) >-1)   {  pre_seta( name, "p", type); goto  next_seta;  }
14969       operateAlias( type, "se" ); if (getSetNr(type) >-1)   {  pre_seta( name, "se", type); ibuf=1; goto  next_seta;  }
14970       operateAlias( type, "sh" ); if (getShapeNr(type) >-1) {  pre_seta( name, "sh", type); ibuf=1; goto  next_seta;  }
14971       next_seta:;
14972 
14973       for (i=0; i<na-2; i++)
14974       {
14975         if (addFlag) { for(l=strlen(dat[i]); l>=0; l--) dat[i][l+1]=dat[i][l]; dat[i][0]='%'; }
14976         operateAlias( dat[i], "v" ); if (getValuNr(dat[i]) >-1)  { pre_seta( name, "v",dat[i] ); goto next_dat;  }
14977         operateAlias( dat[i], "b" ); if (getBodyNr(dat[i]) >-1)  { pre_seta( name, "b",dat[i] ); goto next_dat;  }
14978         operateAlias( dat[i], "s" ); if (getSurfNr(dat[i]) >-1)  { pre_seta( name, "s",dat[i] ); goto  next_dat;  }
14979         operateAlias( dat[i], "c" ); if (getLcmbNr(dat[i]) >-1)  { pre_seta( name, "c",dat[i] ); goto  next_dat;  }
14980         operateAlias( dat[i], "l" ); if (getLineNr(dat[i]) >-1)  { pre_seta( name, "l",dat[i] ); goto  next_dat;  }
14981         operateAlias( dat[i], "p" ); if (getPntNr(dat[i]) >-1)   { pre_seta( name, "p",dat[i] ); goto  next_dat;  }
14982         operateAlias( dat[i], "se" ); if (getSetNr(dat[i]) >-1)   {  pre_seta( name, "se",dat[i]); ibuf=1; goto  next_dat;  }
14983         operateAlias( dat[i], "sh" ); if (getShapeNr(dat[i]) >-1) {  pre_seta( name, "sh",dat[i]); ibuf=1; goto  next_dat;  }
14984       next_dat:;
14985       }
14986       if(ibuf)
14987       {
14988         completeSet( name, "do");
14989       }
14990     }
14991   }
14992   else if (compareStrings(type, "SETC")>0)
14993   {
14994     for(i=0; i<MAX_LINE_LENGTH; i++) name[i]=0;
14995     length=sscanf( string, "%*s%s", name);
14996     setc(name);
14997   }
14998   else if (compareStrings(type, "SETE")>0)
14999   {
15000     for(i=0; i<MAX_LINE_LENGTH; i++) name[i]=0;
15001     strcpy(comm,"strict");
15002     length=sscanf( string, "%*s%s%s%s", name, type, comm);
15003 
15004     /* Single letters (except 'se' 'sh') determine the type of the following entities in cgx. */
15005     /* In FAM no indication of the type is given. So if the name of the entity */
15006     /* consists only of a single letter (or 'se'), it will be ignored. */
15007     if (((type[0]=='n')&&(type[1]=='\0'))||
15008         ((type[0]=='e')&&(type[1]=='\0'))||
15009         ((type[0]=='f')&&(type[1]=='\0'))||
15010         ((type[0]=='p')&&(type[1]=='\0'))||
15011         ((type[0]=='l')&&(type[1]=='\0'))||
15012         ((type[0]=='c')&&(type[1]=='\0'))||
15013         ((type[0]=='r')&&(type[1]=='\0'))||
15014         ((type[0]=='s')&&(type[1]=='\0'))||
15015         ((type[0]=='s')&&(type[1]=='e'))||
15016         ((type[0]=='s')&&(type[1]=='h'))||
15017         ((type[0]=='L')&&(type[1]=='\0'))||
15018         ((type[0]=='S')&&(type[1]=='\0'))||
15019         ((type[0]=='b')&&(type[1]=='\0')) )
15020     {
15021       setNr=getSetNr(name);
15022       if (setNr==-1)
15023       {
15024         printf("ERROR: set:%s does not exist\n", name);
15025         goto checkForError;
15026       }
15027       sete(setNr,type,comm);
15028     }
15029     else
15030     {
15031       printf(" ERROR: Type of data to be enquired has to be stated\n");
15032       goto checkForError;
15033     }
15034   }
15035   else if (compareStrings(type, "SETI")>0)
15036   {
15037     na =   sscanf( string, "%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
15038                name, type, dat[0],dat[1],dat[2],dat[3],dat[4],dat[5], dat[6],dat[7],dat[8],dat[9],
15039                dat[10],dat[11],dat[12],dat[13],dat[14],dat[15], dat[16],dat[17],dat[18],dat[19]);
15040 
15041     /* check if the setname matches a seqential-set (sq). if yes do not add entities */
15042     l=getSetNr(name);
15043     if (l>-1)
15044     {
15045       if(set[l].type==1)
15046       {
15047         printf("ERROR: setname:%s in use by a sequence. Set can not be created.\n", name);
15048         goto checkForError;
15049       }
15050     }
15051     for (i=0; i<na-2; i++)
15052     {
15053       operateAlias( dat[i], type );
15054       l=getSetNr(dat[i]);
15055       if (l==-1)
15056       {
15057         printf("ERROR: set:%s does not exist\n", dat[i]);
15058         goto checkForError;
15059       }
15060     }
15061 
15062     /* Single letters (except 'se' 'sh') determine the type of the following entities in cgx. */
15063     /* In FAM no indication of the type is given. So if the name of the entity */
15064     /* consists only of a single letter (or 'se'), it will be ignored. */
15065     if (((type[0]=='n')&&(type[1]=='\0'))||
15066         ((type[0]=='e')&&(type[1]=='\0'))||
15067         ((type[0]=='f')&&(type[1]=='\0'))||
15068         ((type[0]=='p')&&(type[1]=='\0'))||
15069         ((type[0]=='l')&&(type[1]=='\0'))||
15070         ((type[0]=='c')&&(type[1]=='\0'))||
15071         ((type[0]=='r')&&(type[1]=='\0'))||
15072         ((type[0]=='s')&&(type[1]=='\0'))||
15073         ((type[0]=='s')&&(type[1]=='e'))||
15074         ((type[0]=='s')&&(type[1]=='h'))||
15075         ((type[0]=='L')&&(type[1]=='\0'))||
15076         ((type[0]=='S')&&(type[1]=='\0'))||
15077         ((type[0]=='b')&&(type[1]=='\0')) )
15078     {
15079       /* add the spec type to set 'name' if its included in all spec. sets (dat) */
15080       setNr=pre_seta( name, "i", 0);
15081       seti(setNr,type,na-2, dat);
15082     }
15083     else
15084     {
15085       printf(" ERROR: Type of data to be intersected has to be stated\n");
15086       goto checkForError;
15087     }
15088   }
15089   else if (compareStrings(type, "SETO")>0)
15090   {
15091     name[0]='\0';
15092     length=sscanf( string, "%*s%s", name);
15093     seto(name);
15094   }
15095   else if (compareStrings(type, "SETR")>0)
15096   {
15097     na =   sscanf( string, "%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
15098                name, type, dat[0],dat[1],dat[2],dat[3],dat[4],dat[5], dat[6],dat[7],dat[8],dat[9],
15099                dat[10],dat[11],dat[12],dat[13],dat[14],dat[15], dat[16],dat[17],dat[18],dat[19]);
15100 
15101     operateAlias( name, "se" );
15102     setNr=getSetNr( name );
15103     if (setNr<0)
15104     {
15105       errMsg(" ERROR: Set (%s) is undefined\n", name );
15106       goto checkForError;
15107     }
15108     /* Single letters (except 'se' 'sh') determine the type of the following entities in cgx. */
15109     /* In FAM no indication of the type is given. So if the name of the entity */
15110     /* consists only of a single letter (or 'se'), it will be ignored. */
15111     if (((type[0]=='n')&&(type[1]=='\0'))||
15112         ((type[0]=='e')&&(type[1]=='\0'))||
15113         ((type[0]=='f')&&(type[1]=='\0'))||
15114         ((type[0]=='v')&&(type[1]=='\0'))||
15115         ((type[0]=='p')&&(type[1]=='\0'))||
15116         ((type[0]=='l')&&(type[1]=='\0'))||
15117         ((type[0]=='l')&&(type[1]=='l'))||
15118         ((type[0]=='l')&&(type[1]=='a'))||
15119         ((type[0]=='l')&&(type[1]=='s'))||
15120         ((type[0]=='l')&&(type[1]=='n'))||
15121         ((type[0]=='c')&&(type[1]=='\0'))||
15122         ((type[0]=='s')&&(type[1]=='\0'))||
15123         ((type[0]=='s')&&(type[1]=='e'))||
15124         ((type[0]=='s')&&(type[1]=='h'))||
15125         ((type[0]=='L')&&(type[1]=='\0'))||
15126         ((type[0]=='S')&&(type[1]=='\0'))||
15127         ((type[0]=='b')&&(type[1]=='\0')) )
15128     {
15129       for (i=0; i<na-2; i++)
15130       {
15131         operateAlias( dat[i], type );
15132         nr=getSetNr(dat[i]);
15133         if(nr>-1)
15134         {
15135           if ((type[0]=='s')&&(type[1]=='e'))
15136           {
15137             /* remove the contents of nr from setNr */
15138             for (j=0; j<set[nr].anz_v; j++) setr( setNr, "v", set[nr].valu[j] );
15139             for (j=0; j<set[nr].anz_n; j++) setr( setNr, "n", set[nr].node[j] );
15140             for (j=0; j<set[nr].anz_e; j++) setr( setNr, "e", set[nr].elem[j] );
15141             for (j=0; j<set[nr].anz_f; j++) setr( setNr, "f", set[nr].face[j] );
15142             for (j=0; j<set[nr].anz_p; j++) setr( setNr, "p", set[nr].pnt[j] );
15143             for (j=0; j<set[nr].anz_l; j++) setr( setNr, "l", set[nr].line[j] );
15144             for (j=0; j<set[nr].anz_c; j++) setr( setNr, "c", set[nr].lcmb[j] );
15145             for (j=0; j<set[nr].anz_s; j++) setr( setNr, "s", set[nr].surf[j] );
15146             for (j=0; j<set[nr].anz_b; j++) setr( setNr, "b", set[nr].body[j] );
15147             for (j=0; j<set[nr].anz_nurl; j++) setr( setNr, "L", set[nr].nurl[j] );
15148             for (j=0; j<set[nr].anz_nurs; j++) setr( setNr, "S", set[nr].nurs[j] );
15149             for (j=0; j<set[nr].anz_sh; j++) setr( setNr, "sh", set[nr].shp[j] );
15150             for (j=0; j<set[nr].anz_se; j++) setr( setNr, "r", set[nr].set[j] );
15151           }
15152           else if (type[0]=='v') for (j=0; j<set[nr].anz_v; j++) setr( setNr, "v", set[nr].valu[j] );
15153           else if (type[0]=='n') for (j=0; j<set[nr].anz_n; j++) setr( setNr, "n", set[nr].node[j] );
15154           else if (type[0]=='e') for (j=0; j<set[nr].anz_e; j++) setr( setNr, "e", set[nr].elem[j] );
15155           else if (type[0]=='f') for (j=0; j<set[nr].anz_f; j++) setr( setNr, "f", set[nr].face[j] );
15156           else if (type[0]=='p') for (j=0; j<set[nr].anz_p; j++) setr( setNr, "p", set[nr].pnt[j] );
15157           else if (type[0]=='l')
15158 	  {
15159             for (j=0; j<set[nr].anz_l; j++)
15160 	    {
15161               if((type[1]=='\0')||(type[1]==line[set[nr].line[j]].typ)||((type[1]=='l')&&(line[set[nr].line[j]].typ==32))) setr( setNr, "l", set[nr].line[j] );
15162 	    }
15163 	  }
15164           else if (type[0]=='c') for (j=0; j<set[nr].anz_c; j++) setr( setNr, "c", set[nr].lcmb[j] );
15165           else if ((type[0]=='s')&&(type[1]=='\0')) for (j=0; j<set[nr].anz_s; j++) setr( setNr, "s", set[nr].surf[j] );
15166           else if (type[0]=='b') for (j=0; j<set[nr].anz_b; j++) setr( setNr, "b", set[nr].body[j] );
15167           else if (type[0]=='L') for (j=0; j<set[nr].anz_nurl; j++) setr( setNr, "L", set[nr].nurl[j] );
15168           else if (type[0]=='S') for (j=0; j<set[nr].anz_nurs; j++) setr( setNr, "S", set[nr].nurs[j] );
15169           else if ((type[0]=='s')&&(type[1]=='h')) for (j=0; j<set[nr].anz_sh; j++) setr( setNr, "sh", set[nr].shp[j] );
15170           else if (type[0]=='r') for (j=0; j<set[nr].anz_se; j++) setr( setNr, "r", set[nr].set[j] );
15171         }
15172         else
15173 	{
15174           if(strstr(dat[i], "*") !=NULL)
15175           {
15176             /* set was not found. check if wildcards (*) were used */
15177             length= strsplt( dat[i], '*', &substring);
15178             if (length>0)
15179             {
15180               for(nr=0; nr<anz->sets; nr++) if(set[nr].name!=(char *)NULL)
15181               {
15182                 foundSubString=0;
15183                 for(l=0; l<length; l++)
15184                 {
15185                   if(strstr(set[nr].name, substring[l]) !=NULL)
15186                   {
15187                     foundSubString++;
15188                     /* check if the first or the last char is no '*' then the substring[] must be at start or end */
15189         	      if(l==0) { if(dat[i][0]!='*')  { if(dat[i][0]!=set[nr].name[0])  foundSubString--; }  }
15190              	      if(l==length-1) { if(dat[i][strlen(dat[i])-1]!='*') { if(dat[i][strlen(dat[i])-1]!=set[nr].name[strlen(set[nr].name)-1])  foundSubString--; } }
15191                   }
15192           	}
15193                 if(foundSubString==length)
15194                 {
15195 	          printf(" set:%s matches %s\n", set[nr].name, dat[i]);
15196 
15197                   operateAlias( set[nr].name, type );
15198                   nr=getSetNr(set[nr].name);
15199                   if(nr>-1)
15200                   {
15201                     if ((type[0]=='s')&&(type[1]=='e'))
15202                     {
15203                       /* remove the contents of nr from setNr */
15204                       for (j=0; j<set[nr].anz_v; j++) setr( setNr, "v", set[nr].valu[j] );
15205                       for (j=0; j<set[nr].anz_n; j++) setr( setNr, "n", set[nr].node[j] );
15206                       for (j=0; j<set[nr].anz_e; j++) setr( setNr, "e", set[nr].elem[j] );
15207                       for (j=0; j<set[nr].anz_f; j++) setr( setNr, "f", set[nr].face[j] );
15208                       for (j=0; j<set[nr].anz_p; j++) setr( setNr, "p", set[nr].pnt[j] );
15209                       for (j=0; j<set[nr].anz_l; j++) setr( setNr, "l", set[nr].line[j] );
15210                       for (j=0; j<set[nr].anz_c; j++) setr( setNr, "c", set[nr].lcmb[j] );
15211                       for (j=0; j<set[nr].anz_s; j++) setr( setNr, "s", set[nr].surf[j] );
15212                       for (j=0; j<set[nr].anz_b; j++) setr( setNr, "b", set[nr].body[j] );
15213                       for (j=0; j<set[nr].anz_nurl; j++) setr( setNr, "L", set[nr].nurl[j] );
15214                       for (j=0; j<set[nr].anz_nurs; j++) setr( setNr, "S", set[nr].nurs[j] );
15215                       for (j=0; j<set[nr].anz_sh; j++) setr( setNr, "sh", set[nr].shp[j] );
15216                       for (j=0; j<set[nr].anz_se; j++) setr( setNr, "r", set[nr].set[j] );
15217                     }
15218                     else if (type[0]=='v') for (j=0; j<set[nr].anz_v; j++) setr( setNr, "v", set[nr].valu[j] );
15219                     else if (type[0]=='n') for (j=0; j<set[nr].anz_n; j++) setr( setNr, "n", set[nr].node[j] );
15220                     else if (type[0]=='e') for (j=0; j<set[nr].anz_e; j++) setr( setNr, "e", set[nr].elem[j] );
15221                     else if (type[0]=='f') for (j=0; j<set[nr].anz_f; j++) setr( setNr, "f", set[nr].face[j] );
15222                     else if (type[0]=='p') for (j=0; j<set[nr].anz_p; j++) setr( setNr, "p", set[nr].pnt[j] );
15223                     else if (type[0]=='l') for (j=0; j<set[nr].anz_l; j++) setr( setNr, "l", set[nr].line[j] );
15224                     else if (type[0]=='c') for (j=0; j<set[nr].anz_c; j++) setr( setNr, "c", set[nr].lcmb[j] );
15225                     else if ((type[0]=='s')&&(type[1]=='\0')) for (j=0; j<set[nr].anz_s; j++) setr( setNr, "s", set[nr].surf[j] );
15226                     else if (type[0]=='b') for (j=0; j<set[nr].anz_b; j++) setr( setNr, "b", set[nr].body[j] );
15227                     else if (type[0]=='L') for (j=0; j<set[nr].anz_nurl; j++) setr( setNr, "L", set[nr].nurl[j] );
15228                     else if (type[0]=='S') for (j=0; j<set[nr].anz_nurs; j++) setr( setNr, "S", set[nr].nurs[j] );
15229                     else if ((type[0]=='s')&&(type[1]=='h')) for (j=0; j<set[nr].anz_sh; j++) setr( setNr, "sh", set[nr].shp[j] );
15230                     else if (type[0]=='r') for (j=0; j<set[nr].anz_se; j++) setr( setNr, "r", set[nr].set[j] );
15231                   }
15232                 }
15233               }
15234               /* free substring */
15235               for(i=0; i<length; i++) free(substring[i]);
15236               free(substring);
15237             }
15238           }
15239           else
15240 	  {
15241             if (type[0]=='n') nr=atoi(dat[i]);
15242             else if (type[0]=='e') nr=atoi(dat[i]);
15243             else if (type[0]=='f') nr=atoi(dat[i]);
15244             else if (type[0]=='v') nr=getValuNr(dat[i]);
15245             else if (type[0]=='p') nr=getPntNr(dat[i]);
15246             else if (type[0]=='l') nr=getLineNr(dat[i]);
15247             else if (type[0]=='c') nr=getLcmbNr(dat[i]);
15248             else if ((type[0]=='s')&&(type[1]=='\0')) nr=getSurfNr(dat[i]);
15249             else if (type[0]=='b') nr=getBodyNr(dat[i]);
15250             else if (type[0]=='L') nr=getNurlNr(dat[i]);
15251             else if (type[0]=='S') nr=getNursNr(dat[i]);
15252             else if ((type[0]=='s')&&(type[1]=='h')) nr=getShapeNr(dat[i]);
15253             else if (type[0]=='r') nr=getSetNr(dat[i]);
15254             setr( setNr, type, nr);
15255 	  }
15256         }
15257       }
15258     }
15259     else
15260     {
15261       /* items of unknown type, determine each type */
15262       if (getValuNr(type) >-1)
15263       { setr( setNr, "v", getValuNr(type)); }
15264       if (getBodyNr(type) >-1)
15265       { operateAlias( type, "b" ); setr( setNr, "b", getBodyNr(type)); }
15266       if (getSurfNr(type) >-1)
15267       { operateAlias( type, "s" ); setr( setNr, "s", getSurfNr(type)); }
15268       if (getLcmbNr(type) >-1)
15269       { operateAlias( type, "c" ); setr( setNr, "c", getLcmbNr(type)); }
15270       if (getLineNr(type) >-1)
15271       { operateAlias( type, "l" ); setr( setNr, "l", getLineNr(type)); }
15272       if (getPntNr(type) >-1)
15273       { operateAlias( type, "p" ); setr( setNr, "p", getPntNr(type)); }
15274       if (getShapeNr(type) >-1)
15275       { operateAlias( type, "sh" ); setr( setNr, "sh", getShapeNr(type)); }
15276       for (i=0; i<na-2; i++)
15277       {
15278         if (getValuNr(dat[i]) >-1)
15279         { setr( setNr, "v", getValuNr(dat[i]) ); }
15280         if (getBodyNr(dat[i]) >-1)
15281         { operateAlias( dat[i], "b" ); setr( setNr, "b", getBodyNr(dat[i]) ); }
15282         if (getSurfNr(dat[i]) >-1)
15283         { operateAlias( dat[i], "s" ); setr( setNr, "s", getSurfNr(dat[i]) ); }
15284         if (getLcmbNr(dat[i]) >-1)
15285         { operateAlias( dat[i], "c" ); setr( setNr, "c", getLcmbNr(dat[i]) ); }
15286         if (getLineNr(dat[i]) >-1)
15287         { operateAlias( dat[i], "l" ); setr( setNr, "l", getLineNr(dat[i]) ); }
15288         if (getPntNr(dat[i]) >-1)
15289         { operateAlias( dat[i], "p" ); setr( setNr, "p", getPntNr(dat[i]) ); }
15290         if (getShapeNr(dat[i]) >-1)
15291         { operateAlias( dat[i], "sh" ); setr( setNr, "sh", getShapeNr(dat[i]) ); }
15292       }
15293     }
15294   }
15295   else if (compareStrings(type, "SHPE")>0)
15296   {
15297     pre_shape( &string[na+1], addFlag);
15298   }
15299   else if (compareStrings(type, "SPLIT")>0)
15300   {
15301     pre_split( &string[na+1] );
15302     realloc_colNr();
15303     redraw();
15304   }
15305   else if (compareStrings(type, "STACK")>0)
15306   {
15307     if(compare( &string[na+1],"on",2)==2 ) valuestackFlag=1;
15308     if(compare( &string[na+1],"off",2)==2 ) valuestackFlag=0;
15309     if(compare( &string[na+1],"free",2)==2 )
15310     {
15311       for(i=0; i<valuestack_ptr; i++)  free(valuestack[i]);
15312       valuestack_ptr=0;
15313       free(valuestack);
15314       valuestack=NULL;
15315     }
15316   }
15317   else if (compareStrings(type, "STEPS")>0)
15318   {
15319     steps= atoi( &string[na+1]  );
15320     redraw();
15321   }
15322   else if (compareStrings(type, "STOP")>0)
15323   {
15324     if(cur_commandFile>-1)
15325     {
15326       if(commandFile[cur_commandFile].stopped==0)
15327       {
15328         printf("STOP by user request, reading of file:%s interrupted.\n", commandFile[cur_commandFile].name);
15329         commandFile[cur_commandFile].stopped=1;
15330 	stopped_commandFile=cur_commandFile;
15331         return(-2);
15332       }
15333       else printf("WARNING: commandFile:%s already interrupted\n", commandFile[stopped_commandFile].name);
15334     }
15335     else printf("ERROR: No open commandFile\n");
15336   }
15337   else if (compareStrings(type, "SURF")>0)
15338   {
15339     pre_surf(&string[na+1]);
15340   }
15341   else if (compareStrings(type, "SWEP")>0)
15342   {
15343     pre_swep(&string[na+1]);
15344     redraw();
15345   }
15346   else if (compareStrings(type, "SYS")>0)
15347   {
15348     if(allowSysFlag) system(&string[na+1]);
15349     else
15350     {
15351       printf(" WARNING: Found a 'sys' command (a system call):\n%s\n Since a system call can be dangerous You have to chose now between stop (s), continue (c) or enable (e). If you chose 'e' the 'sys' command will be un-locked by creating or extending your personal config file '%s/.cgx' with the un-lock command ALLOW_SYS. You may delete this command from your '.cgx' file to lock the 'sys' command again.\n", string, homepath);
15352       printf(" Waiting for user input. Please type into the terminal either s,c or e (the terminal has to be the active window!):\n");
15353       i=1;
15354       do
15355       {
15356         scanf("%c%c",&cbuf,(char *)&ibuf);
15357         if(cbuf=='s') exit(0);
15358         else if(cbuf=='c') { i=0; system(&string[na+1]); }
15359         else if(cbuf=='e') { i=0; allowSysFlag=1; addCommandToInitFile("ALLOW_SYS"); }
15360         else { printf(" ERROR:%c not valid\n",cbuf); }
15361       }while(i);
15362     }
15363   }
15364   else if (compareStrings(type, "TEST")>0)
15365   {
15366     length=sscanf( string, "%*s %s %s", type, name);
15367 
15368     if ((type[0]=='i')&&(type[1]=='\0'))
15369     {
15370       length=sscanf( string, "%*s%*s%*s%s", dat[0]);
15371       operateAlias( name, "se" );
15372       operateAlias( dat[0], "se" );
15373 
15374       setNr=getSetNr(name);
15375       if(setNr==-1)
15376       {
15377         printf("ERROR: set:%s does not exist\n", name);
15378         goto checkForError;
15379       }
15380       nr=getSetNr(dat[0]);
15381       if(nr==-1)
15382       {
15383         printf("ERROR: set:%s does not exist\n", dat[0]);
15384         goto checkForError;
15385       }
15386       else completeSet(set[nr].name, "do") ;
15387 
15388       na = embodies(setNr,nr, &cof[0]);
15389       if(na>=1)
15390       {
15391 	strcpy(parameter[0],"TRUE");
15392         printf(" %s\n",parameter[0]);
15393         if(printFlag) printf(" node:%d coef:%e %e %e %e\n",na, cof[0], cof[1], cof[2], cof[3]);
15394         /* only senseful if embodies() would return the deepest penetration
15395         sprintf(parameter[1],"%d",na);
15396         sprintf(parameter[2],"%f",cof[0]);
15397         sprintf(parameter[3],"%f",cof[1]);
15398         sprintf(parameter[4],"%f",cof[2]);
15399         sprintf(parameter[5],"%f",cof[3]);
15400         write2stack(6, parameter);
15401 	*/
15402         write2stack(1, parameter);
15403       }
15404       else
15405       {
15406 	strcpy(parameter[0],"FALSE");
15407         printf(" %s\n",parameter[0]);
15408         write2stack(1, parameter);
15409       }
15410       return(0);
15411     }
15412     if ((type[0]=='o')&&(type[1]=='\0'))
15413     {
15414       operateAlias( name, "se" );
15415       i=getSetNr(name);
15416       if(i>-1)
15417       {
15418         if(set[i].anz_n>0)
15419         {
15420           if( plotNode(set[i].node[0]) >0) strcpy(parameter[0],"TRUE");
15421         }
15422       }
15423       else
15424       {
15425         if( plotNode(atoi(name)) >0) strcpy(parameter[0],"TRUE");
15426       }
15427       return(0);
15428     }
15429     operateAlias( name, type );
15430     strcpy(parameter[0],"FALSE");
15431     if ((type[0]=='n')&&(type[1]=='\0')) { ibuf=atoi(name);
15432       if ((ibuf>=anz->nmin)&&(ibuf<=anz->nmax)&&(node[ibuf].indx==0)&&(ibuf==node[node[ibuf].indx].nr)&&(node[ibuf].pflag==0)) strcpy(parameter[0],"TRUE"); }
15433     if ((type[0]=='e')&&(type[1]=='\0')) { ibuf=atoi(name);
15434       if ((ibuf>=anz->emin)&&(ibuf<=anz->emax)&&(e_enqire[ibuf].type!=0)) strcpy(parameter[0],"TRUE"); }
15435     //if ((type[0]=='f')&&(type[1]=='\0')) { if( get??Nr(name) >-1) strcpy(parameter[0],"TRUE"); }
15436     if ((type[0]=='v')&&(type[1]=='\0')) { if( getValuNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15437     if ((type[0]=='p')&&(type[1]=='\0')) { if( getPntNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15438     if ((type[0]=='l')&&(type[1]=='\0')) { if( getLineNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15439     if ((type[0]=='c')&&(type[1]=='\0')) { if( getLcmbNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15440     //if ((type[0]=='r')&&(type[1]=='\0')) { if( get??Nr(name) >-1) strcpy(parameter[0],"TRUE"); }
15441     if ((type[0]=='s')&&(type[1]=='\0')) { if( getSurfNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15442     if ((type[0]=='s')&&(type[1]=='e'))  { if( getSetNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15443     if ((type[0]=='s')&&(type[1]=='h'))  { if( getShapeNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15444     if ((type[0]=='L')&&(type[1]=='\0')) { if( getNurlNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15445     if ((type[0]=='S')&&(type[1]=='\0')) { if( getNursNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15446     if ((type[0]=='b')&&(type[1]=='\0')) { if( getBodyNr(name) >-1) strcpy(parameter[0],"TRUE"); }
15447     printf(" %s\n",parameter[0]);
15448     write2stack(1, parameter);
15449   }
15450   else if (compareStrings(type, "TRA")>0)
15451   {
15452     length=sscanf( string, "%*s %s %lf", posn, &dx);
15453     if(posn[0]=='u') dty+= dx/scale->w/ds;
15454     if(posn[0]=='d') dty-= dx/scale->w/ds;
15455     if(posn[0]=='l') dtx-= dx/scale->w/ds;
15456     if(posn[0]=='r') dtx+= dx/scale->w/ds;
15457     if(posn[0]=='f') dtz+= dx/scale->w;
15458     //printf("dtx:%f dty:%f dtz:%f dx:%f ds:%f\n", dtx, dty, dtz, (dx*2)/scale->w, ds);
15459     glutPostRedisplay();
15460     updateDispLists();
15461   }
15462   else if (compareStrings(type, "THRS")>0)
15463   {
15464     delSet(specialset->thrs);
15465     sscanf(&string[na+1] , "%s %s %s", xbuf, format, comm);
15466     // off
15467     if(xbuf[0]=='o')
15468     {
15469       sprintf(buffer,"fill");
15470       pre_view(buffer);
15471       sprintf(buffer,"fv all");
15472       plot(buffer);
15473       return(0);
15474     }
15475     sprintf(buffer,"all %s rec _ _ _ 0. %s %s", specialset->thrs, format, xbuf );
15476     enquireEntities(buffer);
15477     completeSet( specialset->thrs, "up");
15478     // generate node-texts on the max or min nodes in each local element cluster
15479     if(comm[0]=='t')
15480     {
15481       // generate separate sets of all clusters
15482       strcpy(setname2, "+grp");
15483       ibuf=separateMeshes(specialset->thrs, setname2);
15484       sprintf(buffer,"point 4");
15485       pre_view(buffer);
15486       sprintf(buffer,"elem off");
15487       pre_view(buffer);
15488       sprintf(buffer,"ev %s", specialset->thrs);
15489       plot(buffer);
15490       // search max/min and generate node text
15491       for(i=1; i<=ibuf; i++)
15492       {
15493         sprintf(buffer,"%s%d %sN%d rec _ _ _ 0. %s", setname2, i, setname2, i, format );
15494         enquireEntities(buffer);
15495         sprintf(buffer,"%sN%d", setname2, i);
15496         setNr=getSetNr(buffer);
15497         if (setNr<0)
15498         {
15499           printf (" txt: set:%s does not exist\n", name);
15500           goto checkForError;
15501         }
15502         for(j=0; j<set[setNr].anz_n; j++)
15503         {
15504           createText(set[setNr].node[j], -1, 0 );
15505         }
15506         sprintf(buffer,"nt %s k", set[setNr].name);
15507         plus(buffer);
15508       }
15509       printf("\n The command 'qtxt' may be used to modify the node related texts\n");
15510     }
15511     else
15512     {
15513       sprintf(buffer,"point 4");
15514       pre_view(buffer);
15515       sprintf(buffer,"elem off");
15516       pre_view(buffer);
15517       sprintf(buffer,"ev %s", specialset->thrs);
15518       plot(buffer);
15519     }
15520   }
15521   else if (compareStrings(type, "TRFM")>0)
15522   {
15523     transformResults(&string[na+1]);
15524   }
15525   else if (compareStrings(type, "TEXT")>0)
15526   {
15527     printf(" WARNING: The text command was replaced by ulin. Please use ulin in future.\n");
15528     stos( &string[na], 1, strlen(&string[na]), picture_text);
15529   }
15530   else if (compareStrings(type, "TXT")>0)
15531   {
15532     placeTxt(&string[na]);
15533   }
15534   else if (compareStrings(type, "UCUT")>0)
15535   {
15536     uncut(1);
15537   }
15538   else if (compareStrings(type, "ULIN")>0)
15539   {
15540     stos( &string[na], 1, strlen(&string[na]), picture_text);
15541     if(inpformat)
15542     {
15543       glutSetWindow( w0);
15544       glutPostRedisplay();
15545     }
15546   }
15547   else if ((compareStrings(type, "VAL")>0)||(compareStrings(type, "VALU")>0))
15548   {
15549     pre_value(&string[na+1]);
15550   }
15551   else if (compareStrings(type, "VIEW")>0)
15552   {
15553     pre_view(&string[na+1]);
15554   }
15555   else if (compareStrings(type, "VOLU")>0)
15556   {
15557     pre_volu(&string[na+1]);
15558   }
15559   else if (compareStrings(type, "WSIZE")>0)
15560   {
15561     setWindowSize(string);
15562   }
15563   else if (compareStrings(type, "WPOS")>0)
15564   {
15565     setWindowPos(string);
15566   }
15567   else if (compareStrings(type, "ZAP")>0)
15568   {
15569     if( zap(&string[na+1])==-1)
15570       printf (" ERROR in ZAP: set:%s does not exist\n",&string[na+1] );
15571   }
15572   else if (compareStrings(type, "ZOOM")>0)
15573   {
15574     length=sscanf( string, "%*s %lf %lf %lf %lf", &wx[0], &wy[0], &wx[1], &wy[1]);
15575     if (length==4)
15576     {
15577       wx[0]*=2.;
15578       wx[1]*=2.;
15579       wy[0]*=2.;
15580       wy[1]*=2.;
15581 
15582       wx[0]+=-1.;
15583       wx[1]+=-1.;
15584       wy[0]+=-1.;
15585       wy[1]+=-1.;
15586     }
15587     else
15588     {
15589       dx=1./wx[0];
15590       wx[0]=wy[0]=-dx;
15591       wx[1]=wy[1]=dx;
15592     }
15593     zoom(wx[0], wy[0], wx[1], wy[1]);
15594   }
15595   else if (compareStrings(type, "CMAP")>0)
15596   {
15597     sscanf(string, "%*s %s", buffer);
15598 
15599     for (i=0; i<cmaps; i++)
15600     {
15601       if( compare( cmap_names[i], buffer, 1)==1)
15602       {
15603         strcpy(cmap_name, buffer);
15604         printf("\nSetting \'%s\' colormap.\n\n", cmap_name);
15605         defineColTextur_load(1.);
15606         redraw();
15607         return(0);
15608       }
15609     }
15610     printf("\nColormap \'%s\' not defined.\n\n", buffer);
15611   }
15612   else if ((type[0]== '!')||(type[0]== '#')||(type[0]== '$'))
15613   {
15614     printf(" %s\n", string );
15615   }
15616   else
15617   {
15618     printf(" key:%s from string %s not known\n", type, string);
15619   }
15620 
15621  checkForError:;
15622   if(returnFlag<0) return(returnFlag);
15623   if((whileFlag==3)||(whileFlag==5)) goto whileLoop;
15624   return(returnFlag);
15625 }
15626 
15627 
15628 
getCommandLine(FILE * handle1,char ** string1)15629 int getCommandLine(FILE *handle1, char **string1)
15630 {
15631   int  i,length;
15632   char buffer[MAX_LINE_LENGTH];
15633   char *string;
15634 
15635   string=*string1;
15636 
15637   /* for long commands (>MAX_LINE_LENGTH-1) combine several calls to frecord to build the command which will be stored in 'string' */
15638   i=0;
15639  addLine:;
15640   do
15641   {
15642     if( (string=realloc(string, MAX_LINE_LENGTH*++i*sizeof(char)))== NULL ) { printf(" ERROR: realloc failed in getCommandLine()\n"); return(0); }
15643     length = frecord( handle1, buffer);
15644     if(i==1) strcpy(string, buffer);
15645     else strcpy(&string[strlen(string)], buffer);
15646   }while(length==(MAX_LINE_LENGTH-1));
15647   //for(i=0; i<strlen(string); i++) printf("char%d %c\n",i,string[i]);
15648   if((length>0)&&(string[strlen(string)-2]=='='))
15649   {
15650     string[strlen(string)-2]=0;
15651     goto addLine;
15652   }
15653 
15654   *string1=string;
15655   return(strlen(string)-1);
15656 }
15657 
15658 
15659 
readfbd(char * datin,int addFlag)15660 int readfbd( char *datin, int addFlag )
15661 {
15662   FILE      *handle1=NULL;
15663   int       result=0, length, i, na, gtolFlag=0;
15664   char type[MAX_LINE_LENGTH];
15665   static char *string=NULL;
15666 
15667   if((datin==0)&&(stopped_commandFile>-1))  // restart reading
15668   {
15669     if(commandFile[stopped_commandFile].stopped==1)
15670     {
15671       cur_commandFile=stopped_commandFile;
15672       handle1 = commandFile[cur_commandFile].handle;  // always the last opened
15673       commandFile[cur_commandFile].stopped=0;
15674       addFlag=commandFile[cur_commandFile].addFlag;
15675       // close and re-open to catch updates in the file
15676       fclose(handle1);
15677       handle1 = fopen (commandFile[cur_commandFile].name, "r");
15678       if (handle1==NULL)
15679       {
15680         printf (" ERROR in readfbd: The input file \"%s\" could not be opened.\n\n", commandFile[cur_commandFile].name);
15681         return(1);
15682       }
15683       if( fsetpos( handle1, (fpos_t *)commandFile[cur_commandFile].filepntr)!=0) { printf("error in fsetpos"); return(-1); }
15684       commandFile[cur_commandFile].handle=handle1;
15685    }
15686     else printf("ERROR: commandFile:%s was not halted\n", commandFile[stopped_commandFile].name);
15687   }
15688   else
15689   {
15690     handle1 = fopen (datin, "r");
15691     if (handle1==NULL)
15692     {
15693       printf (" ERROR in readfbd: The input file \"%s\" could not be opened.\n\n", datin);
15694       return(1);
15695     }
15696     else  printf (" %s opened\n",datin);
15697 
15698     /* store the handle */
15699     if( (commandFile=(CommandFile *)realloc((CommandFile *)commandFile, (commandFiles+1)*sizeof(CommandFile))) == NULL ) printf(" ERROR: malloc failed\n");
15700     strcpy(commandFile[commandFiles].name,datin);
15701     commandFile[commandFiles].handle=handle1;
15702     commandFile[commandFiles].stopped=0;
15703     commandFile[commandFiles].addFlag=addFlag;
15704     cur_commandFile=commandFiles;
15705 
15706     if( (commandFile[commandFiles].filepntr=(fpos_t *)malloc(1*sizeof(fpos_t))) == NULL ) printf(" ERROR: malloc failed\n");
15707 
15708     commandFiles++;
15709     //printf("open cur_commandFile %d files %d\n", cur_commandFile, commandFiles);
15710 
15711     printf ("\n reading file\n");
15712   }
15713 
15714   do
15715   {
15716     length=getCommandLine(handle1, &string);
15717     if (length > 0)
15718     {
15719       type[0]=0;
15720       na=0; while(string[na]==' ') na++;
15721       na+= sword( string, type);
15722       //printf (" record:%s", &string[0]);
15723       result=commandoInterpreter( type, string, na, length, handle1, addFlag, &gtolFlag );
15724       //printf("result%d in %s\n", result, commandFile[cur_commandFile].name);
15725     }
15726     if( string[length]== (char)EOF)  break;
15727   }while (result > -1);
15728 
15729   if((result==-2)||(stopped_commandFile>cur_commandFile))   // a "STOP" command, or a referenced file is stopped
15730   {
15731     //printf("%d stopped file: %s\n", cur_commandFile, commandFile[cur_commandFile].name);
15732     commandFile[cur_commandFile].stopped=1;
15733     if(fgetpos( commandFile[cur_commandFile].handle, (fpos_t *)commandFile[cur_commandFile].filepntr)!=0) { printf("error in fgetpos"); return(-1); }
15734     cur_commandFile--;
15735   }
15736   else // it's not a "STOP" command, file wil be closed
15737   {
15738     //printf("stopped_commandFile:%d cur_commandFile:%d close %s\n",stopped_commandFile, cur_commandFile, commandFile[cur_commandFile].name);
15739     fclose(commandFile[cur_commandFile].handle);
15740     commandFile[cur_commandFile].handle=NULL;
15741     commandFile[cur_commandFile].stopped=0;
15742 
15743     if(cur_commandFile==commandFiles-1) commandFiles--;
15744 
15745     if((cur_commandFile>0)&&(cur_commandFile==stopped_commandFile))   // restart upper stopped commandFiles
15746     {
15747       stopped_commandFile--;
15748       printf("next stopped_commandFile:%d\n",stopped_commandFile);
15749       if((commandFile[stopped_commandFile].handle!=NULL)&&(commandFile[stopped_commandFile].stopped))
15750       {
15751         printf("CONTINUE to read file:%s\n", commandFile[stopped_commandFile].name);
15752         readfbd( 0, 0);
15753         return(0);
15754       }
15755     }
15756 
15757     cur_commandFile--;
15758     if(cur_commandFile==-1)  // last filepointer closed, free struct
15759     {
15760       stopped_commandFile--;
15761       free(commandFile[commandFiles].filepntr);
15762       free(commandFile);
15763       commandFile=NULL;
15764       commandFiles=0;
15765     }
15766     result=0;
15767   }
15768 
15769   //if(!gtolFlag) { valuestackFlagbuffer=valuestackFlag; valuestackFlag=0; gtol=calcGTOL(setall); valuestackFlag=valuestackFlagbuffer; }
15770   // calcGTOL will be executed in pre_read()
15771 
15772   /* delete the entities in specialSet->zap */
15773   zap(specialset->zap);
15774 
15775   /* fit everything in the drawing cube and repaint the entities */
15776   /* (should be done in the trigger functions like move() */
15777   if((!animFlag)&&(!sequenceFlag))
15778   {
15779     descalAll();
15780     getScaleValues( setall, set, point, node, scale);
15781     scalNodes ( anz->n, node, scale );
15782     scalPoints ( anzGeo->p, point, scale );
15783     scalSurfs( anzGeo->s, surf, scale);
15784     // recalculate the line-shapes
15785     for (i=0; i<anzGeo->l; i++) repLine(i);
15786     // recalculate the nurbl-controll-points
15787     for (i=0; i<anzGeo->nurl; i++) repNurl(i);
15788     // recalculate the nurbs-controll-points
15789     for (i=0; i<anzGeo->nurs; i++) repNurs(i);
15790     // correct the orientation of all entities
15791     orientSet( "all" );
15792   }
15793   printf (" done \n\n");
15794   return(result);
15795 }
15796 
15797 
15798 /*------------------------------------------------------------------*/
15799 /* Daten im frd-format einlesen                                     */
15800 /*------------------------------------------------------------------*/
readfrdfile(char * frdfile,char * setname)15801 void readfrdfile( char *frdfile, char *setname )
15802 {
15803   int i, setNr=-1;
15804   char  datum[MAX_LINE_LENGTH];
15805   Summen    anzr[1];
15806   Nodes     *noder=NULL;
15807   Elements  *elemr=NULL;
15808   Datasets  *lcaser=NULL;
15809 
15810 
15811   if (setname[0]!=0) /* store nodes and elements in set */
15812   {
15813     if(printFlag) printf (" read %s in set:%s\n", frdfile, setname );
15814     readfrd( frdfile, anzr, &noder, &elemr, &lcaser, 1);
15815 
15816 
15817     if(anzr->n>0)
15818     {
15819       for (i=0; i<anzr->n; i++)
15820       {
15821         if ((noder[i].nr <= anz->nmax)&&(noder[i].nr >= anz->nmin))
15822         {
15823           if(setNr<0) { sprintf (datum, "%d", noder[i].nr); setNr=pre_seta( setname, "n", datum ); }
15824           else seta( setNr, "n", noder[i].nr );
15825         }
15826         else printf (" node %d is outside range of known nodes\n", noder[i].nr);
15827       }
15828     }
15829     if(anzr->e>0)
15830     {
15831       for (i=0; i<anzr->e; i++)
15832       {
15833         if ((elemr[i].nr <= anz->emax)&&(elemr[i].nr >= anz->emin))
15834         {
15835           if(setNr<0) { sprintf (datum, "%d", elemr[i].nr); pre_seta( setname, "e", datum ); }
15836           else seta( setNr, "e", elemr[i].nr );
15837         }
15838       else printf (" element %d is outside range of known elements\n", elemr[i].nr);
15839       }
15840     }
15841     free(elemr);
15842     free(noder);
15843     free(lcaser);
15844   }
15845 }
15846 
15847 
15848 
swap_long(char * ptr)15849 long swap_long(char *ptr)
15850 {
15851   long buf,buf2;
15852   char *pbuf, *pbuf2;
15853 
15854   pbuf=(char *)&buf;
15855   pbuf2=(char *)&buf2;
15856 
15857   *pbuf2=*(ptr);  pbuf2++;
15858   *pbuf2=*(ptr+1);  pbuf2++;
15859   *pbuf2=*(ptr+2);  pbuf2++;
15860   *pbuf2=*(ptr+3);
15861 
15862   *pbuf=*(ptr+3);  pbuf++;
15863   *pbuf=*(ptr+2);  pbuf++;
15864   *pbuf=*(ptr+1);  pbuf++;
15865   *pbuf=*(ptr);
15866 
15867   // printf("in:%u out:%u\n", buf2, buf);
15868   return(buf);
15869 }
15870 
15871 
15872 #define BYTES 100000000
readxwd(char * datin)15873 BGpicture *readxwd( char * datin)
15874 {
15875   int i, j, k, n, fp, offset;
15876   int bytes_per_line, bits_per_pixel;
15877   XWDFileHeader *xwdheader;
15878 
15879   static char buf[BYTES];
15880   static char buf2[BYTES];
15881   static BGpicture bgpicture;
15882 
15883   char aux;
15884 
15885   fp = open ( datin, O_RDONLY);
15886   if( read( fp, buf, BYTES)<1)
15887   {
15888     printf("ERROR: File:%s could not be opened\n", datin) ;
15889     return(0);
15890   }
15891   xwdheader=(XWDFileHeader *)&buf[0];
15892 
15893   /* swap from big-endian to little-endian */
15894   printf("header: %d or swaped: %ld\n", xwdheader->header_size, swap_long((char *)&xwdheader->header_size));
15895   if ((xwdheader->header_size>300)||(xwdheader->header_size<100))
15896   {
15897     offset=swap_long((char *)&xwdheader->header_size)+swap_long((char *)&xwdheader->ncolors)*sz_XWDColor;
15898     bytes_per_line=swap_long((char *)&xwdheader->bytes_per_line);
15899     bgpicture.width=(GLsizei)swap_long((char *)&xwdheader->window_width);
15900     bgpicture.height=(GLsizei)swap_long((char *)&xwdheader->window_height);
15901     bits_per_pixel=(int)swap_long((char *)&xwdheader->bits_per_pixel);
15902 
15903     /*
15904         printf(" XWD_FILE_VERSION above 	      :%d \n", swap_long(&xwdheader->file_version ));
15905         printf(" ZPixmap or XYPixmap 		      :%d \n", swap_long(&xwdheader->pixmap_format ));
15906         printf(" Pixmap depth 			      :%d \n", swap_long(&xwdheader->pixmap_depth ));
15907         printf(" Pixmap width 	       		       :%d\n", swap_long(&xwdheader->pixmap_width ));
15908         printf(" Pixmap height 		      	      :%d \n", swap_long(&xwdheader->pixmap_height ));
15909         printf(" Bitmap x offset, normally 0   	      :%d\n", swap_long(&xwdheader->xoffset ));
15910         printf(" of image data: MSBFirst, LSBFirs     :%d \n", swap_long(&xwdheader->byte_order ));
15911         printf(" bitmap_unit			      :%d \n", swap_long(&xwdheader->bitmap_unit ));
15912         printf(" bitmaps only: MSBFirst, LSBFirst     :%d\n", swap_long(&xwdheader->bitmap_bit_order ));
15913         printf(" bitmap_pad			      :%d \n", swap_long(&xwdheader->bitmap_pad ));
15914         printf(" Bits per pixel 		      :%d \n", swap_long(&xwdheader->bits_per_pixel ));
15915         printf(" bytes_per_line			      :%d \n", swap_long(&xwdheader->bytes_per_line ));
15916         printf(" Class of colormap 		      :%d \n", swap_long(&xwdheader->visual_class ));
15917         printf(" Z red mask			      :%d \n", swap_long(&xwdheader->red_mask ));
15918         printf(" Z green mask			      :%d \n", swap_long(&xwdheader->green_mask ));
15919         printf(" Z blue mask 			      :%d \n", swap_long(&xwdheader->blue_mask ));
15920         printf(" Log2 of distinct color values	      :%d \n", swap_long(&xwdheader->bits_per_rgb ));
15921         printf(" Number of entries in colormap; not used? :%d  \n", swap_long(&xwdheader->colormap_entries ));
15922         printf(" Number of XWDColor structures	       :%d\n", swap_long(&xwdheader->ncolors ));
15923         printf(" Window width			      :%d \n", swap_long(&xwdheader->window_width ));
15924         printf(" Window height			      :%d \n", swap_long(&xwdheader->window_height ));
15925         printf(" Window upper left X coordinate	      :%d \n", swap_long(&xwdheader->window_x ));
15926         printf(" Window upper left Y coordinate	      :%d \n", swap_long(&xwdheader->window_y ));
15927         printf(" Window border width                  :%d \n", swap_long(&xwdheader->window_bdrwidth ));
15928     */
15929   }
15930   else
15931   {
15932     offset=xwdheader->header_size + xwdheader->ncolors*sz_XWDColor;
15933     bytes_per_line=xwdheader->bytes_per_line;
15934     bgpicture.width=(GLsizei)xwdheader->window_width;
15935     bgpicture.height=(GLsizei)xwdheader->window_height;
15936     bits_per_pixel=(int)xwdheader->bits_per_pixel;
15937 
15938     printf("ncolors:%d\n", xwdheader->ncolors);
15939   }
15940 
15941   bgpicture.name=&buf[100];
15942   printf("windowName:%s\n", bgpicture.name);
15943   if(bits_per_pixel==32) { bgpicture.format=GL_RGBA;  bgpicture.type=GL_UNSIGNED_BYTE; }
15944   if(bits_per_pixel==24) { bgpicture.format=GL_RGB;   bgpicture.type=GL_UNSIGNED_BYTE; }
15945   if(bits_per_pixel==8)  { bgpicture.format=GL_RGBA;  bgpicture.type=GL_UNSIGNED_BYTE; }
15946   if(bits_per_pixel==1)  { bgpicture.format=GL_COLOR_INDEX;  bgpicture.type=GL_BITMAP; }
15947 
15948 
15949   /* inverse the lines (last is first) */
15950   n=0;
15951   for(j=0; j<bgpicture.height; j++)
15952   {
15953     for(i=0; i<bytes_per_line; i++)
15954     {
15955       buf2[n]=buf[offset-1+ (bytes_per_line*(bgpicture.height-j-1)) +i +1];
15956       if(bits_per_pixel==8)
15957       {
15958         for (k=1; k<4; k++) buf2[n+k]=buf2[n];
15959         n+=3;
15960       }
15961       n++;
15962     }
15963   }
15964   /* convert the image data from RGBA to BGRA if 32bit picture */
15965   if (bits_per_pixel == 32) for (i=0; i < bgpicture.width * bgpicture.height * bits_per_pixel/8 ; i+= bits_per_pixel/8)
15966   {
15967       aux = buf2[i];
15968       buf2[i] = buf2[i+2];
15969       buf2[i+2] = aux;
15970   }
15971 
15972   bgpicture.pixels=&buf2[0];
15973   printf("pixel-offset:%d\n", offset);
15974   printf("bits_per_pixel:%d\n", bits_per_pixel);
15975   printf("bytes_per_line:%d\n", bytes_per_line);
15976   printf("window_width:%d\n", bgpicture.width);
15977   printf("window_height:%d\n", bgpicture.height);
15978   /* printf("window-pixels:%x\n", bgpicture.pixels); */
15979 
15980   return(&bgpicture);
15981 }
15982 
_readxwd(void)15983 BGpicture *_readxwd(void)
15984 {
15985    int i, j, c;
15986    static GLubyte checkImage[64][64][3];
15987    static BGpicture bgpicture;
15988    static char name[100];
15989 
15990    for (i = 0; i < 64; i++) {
15991       for (j = 0; j < 64; j++) {
15992          c = ((((i&0x8)==0)^((j&0x8)))==0)*255;
15993          checkImage[i][j][0] = (GLubyte) c/(i+1);
15994          checkImage[i][j][1] = (GLubyte) c/(j+1);
15995          checkImage[i][j][2] = (GLubyte) c;
15996       }
15997    }
15998   strcpy(name,"CheckImage");
15999 
16000   bgpicture.name=&name[0];
16001   bgpicture.width=64;
16002   bgpicture.height=64;
16003   bgpicture.format=GL_RGB;
16004   bgpicture.type=GL_UNSIGNED_BYTE;
16005   bgpicture.pixels=&checkImage;
16006 
16007   return(&bgpicture);
16008 }
16009 
16010 
16011 
readtostack(char * datin)16012 void readtostack(char *datin)
16013 {
16014   int i, length, lines;
16015   FILE *handle;
16016   char **record=NULL;
16017   char string[MAX_LINE_LENGTH];
16018 
16019   handle = fopen (datin, "r");
16020   if (handle==NULL)
16021   {
16022     printf (" ERROR in readlist: The input file \"%s\" could not be opened.\n\n", datin);
16023     return;
16024   }
16025   else  printf ("\n%s opened",datin);
16026 
16027   lines=0;
16028   length=1;
16029   printf ("\n reading file\n");
16030 
16031   while (length > -1)
16032   {
16033     length = frecord( handle, string);
16034     if( string[length]== (char)EOF)  break;
16035     if((record=(char **)realloc((char **)record, (lines+1)*sizeof(char *)))==NULL)
16036     { printf("\n\n ERROR: realloc failed nod\n\n"); return; }
16037     if((record[lines]=(char *)malloc((length+1)*sizeof(char)))==NULL)
16038     { printf("\n\n ERROR: malloc failed nod\n\n"); return; }
16039     for(i=0; i<length; i++) record[lines][i]=string[i]; record[lines][i]=0;
16040     lines++;
16041   }
16042   fclose(handle);
16043   length=valuestackFlag;
16044   valuestackFlag=1;
16045   write2stack(lines, record);
16046   valuestackFlag=length;
16047   for(i=0; i<lines; i++)  free(record[i]);
16048   free(record);
16049   return;
16050 }
16051 
16052 
16053 
pre_read(char * record)16054 int pre_read( char *record )
16055 {
16056   char      datin[MAX_LINE_LENGTH];
16057   char      param1[MAX_LINE_LENGTH];
16058   char      param2[MAX_LINE_LENGTH];
16059   char      ext[MAX_LINE_LENGTH];
16060   int       e,i,j,n,l,lp,lc, length, nset, emax=0, nmax=0;
16061   double    gtol_buf;
16062   Summen    apre[1];
16063   Nodes     *npre=NULL;
16064   Elements  *epre=NULL;
16065   Datasets  *lpre=NULL;
16066   Sets      *spre=NULL;
16067   int *newnode=NULL, *newelem=NULL;
16068   char addDispFlagLocal=0;
16069 
16070   datin[0]=0;
16071   param1[0]=0;
16072   param2[0]=0;
16073   length = sscanf( record, "%s %s %s", datin, param1, param2 );
16074 
16075   i=0; if( datin[0]==0) return(0); else strcpy(parameter[i++],datin);
16076   if( param1[0]!=0) strcpy(parameter[i++],param1);
16077   if( param2[0]!=0) strcpy(parameter[i++],param2);
16078   write2stack(length, parameter);
16079 
16080   /* the filetype is determined by its extension except fbd */
16081   /* frd: frd-format, nodes, element-numbers will be stored in a set, but are not re-defined */
16082   /* inp: abaqus format, nodes, elements, sets */
16083 
16084   /* determine the extension */
16085   for(i=strlen(datin); i>=0; i--) if(datin[i]=='.') break;
16086   for(j=++i; j<strlen(datin); j++) ext[j-i]=datin[j]; ext[j-i]=0;
16087 
16088   gtol_buf=gtol;
16089   if(compare(param1,"stack",3)==3)
16090   { readtostack( datin ); }
16091   else if(param1[0]=='-')
16092   { readlist( datin, &param1[1] ); }
16093   else if(compare( ext, "xwd", 3)== 3)
16094   {
16095     bgpicture=readxwd( datin);
16096     if(length==2) { bgpicture->zoom[0]=atof(param1); bgpicture->zoom[1]=atof(param1); }
16097     else if(length>2) { bgpicture->zoom[0]=atof(param1); bgpicture->zoom[1]=atof(param2); }
16098     else bgpicture->zoom[0]=bgpicture->zoom[1]=1.;
16099   }
16100   else if((compare( ext, "edg", 3)== 3)||(compare( param1, "edg", 3)== 3))
16101   {
16102     if(addDispFlag==1) { addDispToCoordinates(node); addDispFlagLocal=2; }
16103     apre->n=0;
16104     apre->e=0;
16105     apre->f=0;
16106     apre->g=0;
16107     apre->emax=0;  apre->emin=MAX_INTEGER;
16108     apre->nmax=0;  apre->nmin=MAX_INTEGER;
16109     apre->l=0;
16110     readEdges( datin, apre, &npre, &epre );
16111     printf("add nodes:%d maxnr:%d\n",apre->n, apre->nmax);
16112 
16113     /* modify node and element numbers if param2 == add */
16114     if((param2[0]=='A')||(param2[0]=='a'))
16115     {
16116       renumberfrd( anz->enext, anz->nnext, &apre[0], &npre, &epre, &lpre, &newnode, &newelem );
16117       free(newelem);
16118       free(newnode);
16119     }
16120 
16121     /* create the nodes and elements or overwrite old ones */
16122     for(i=0; i<apre->n; i++)  nod( anz, &node, 1, npre[i].nr, npre[npre[i].nr].nx, npre[npre[i].nr].ny, npre[npre[i].nr].nz, 1 );
16123     for(i=0; i<apre->e; i++) elem_define(anz,&e_enqire, epre[i].nr, epre[i].type, epre[i].nod, 1,  0 );
16124     printf("elements:%d maxnr:%d\n",anz->e, anz->emax);
16125 
16126     free(npre);
16127     free(epre);
16128 
16129     /* new scaling for drawing */
16130     descalAll();
16131     getScaleValues( setall, set, point, node, scale);
16132     scalNodes ( anz->n, node, scale );
16133     scalPoints ( anzGeo->p, point, scale );
16134     scalSurfs( anzGeo->s, surf, scale);
16135     // recalculate the line-shapes
16136     for (i=0; i<anzGeo->l; i++) repLine(i);
16137     // recalculate the nurbl-controll-points
16138     for (i=0; i<anzGeo->nurl; i++) repNurl(i);
16139     // recalculate the nurbs-controll-points
16140     for (i=0; i<anzGeo->nurs; i++) repNurs(i);
16141     // correct the orientation of all entities
16142     orientSet( "all" );
16143 
16144     /* from here code from pre_mesh() */
16145     /* das neue netz muss noch zur beleuchteten ansicht aufbereitet werden  */
16146     makeSurfaces();
16147     getElemNormalen( e_enqire, node, anz->e );
16148     realloc_colNr();
16149 
16150     if(addDispFlagLocal==2) { addDispToCoordinates(node); }
16151   }
16152   else if((compare( ext, "frd", 3)== 3)&&((param1[0])&&compareStrings(param1,"new")>0))
16153   {
16154     cur_lc=cur_entity=0;
16155     pre_del("me");
16156     /* descale is needed since scale works only when a descale was done before */
16157     descalNodes ( anz->n, node, scale );
16158     iniMeshData( datin, "frd" );
16159 
16160     /* new scaling for drawing */
16161     descalAll();
16162     getScaleValues( setall, set, point, node, scale);
16163     scalNodes ( anz->n, node, scale );
16164     scalPoints ( anzGeo->p, point, scale );
16165     scalSurfs( anzGeo->s, surf, scale);
16166     // recalculate the line-shapes
16167     for (i=0; i<anzGeo->l; i++) repLine(i);
16168     // recalculate the nurbl-controll-points
16169     for (i=0; i<anzGeo->nurl; i++) repNurl(i);
16170     // recalculate the nurbs-controll-points
16171     for (i=0; i<anzGeo->nurs; i++) repNurs(i);
16172     // correct the orientation of all entities
16173     orientSet( "all" );
16174 
16175     /* calc additional entities only if the block was not jumped during read */
16176     for (i=0; i<anz->olc; i++)  if (lcase[i].loaded)
16177       calcDatasets( i, anz, node, lcase );
16178     /* create the mainmenu */
16179     if(activWindow!=-1) createDatasetEntries();
16180   }
16181   else if((compare( ext, "frd", 3)== 3)&&((param1[0])&&((compareStrings(param1,"add")<1)&&(compareStrings(param1,"ext")<1)&&(compareStrings(param1,"nom")<1))))
16182   {
16183     /* store nodes and elements in set param1 */
16184     printf("create set:%s\n",param1);
16185     readfrdfile(datin,param1);
16186   }
16187   else if((compare( ext, "frd", 3)== 3)||(compare( param1, "ng", 2)== 2)||(compare( ext, "stl", 3)== 3)||(compare( ext, "inp", 3)== 3)||(compare( param1, "inp", 3)== 3)||(compare( param1, "foam", 4)== 4))
16188   {
16189     if(addDispFlag==1) { addDispToCoordinates(node); addDispFlagLocal=2; }
16190     apre->n=0;
16191     apre->e=0;
16192     apre->f=0;
16193     apre->g=0;
16194     apre->emax=0;  apre->emin=MAX_INTEGER;
16195     apre->nmax=0;  apre->nmin=MAX_INTEGER;
16196     apre->b=0;
16197     apre->c=0;
16198     apre->l=0;
16199     apre->sets=0;
16200     apre->mats=anz->mats;
16201     apre->amps=anz->amps;
16202 
16203     if(compare( ext, "frd", 3)== 3)
16204     {
16205       if( (compare( param1, "add", 3)== 3)||(compare( param2, "add", 3)== 3)||(compare( param1, "ext", 3)== 3)||(compare( param2, "ext", 3)== 3))
16206       {
16207         if(readfrd( datin, apre, &npre, &epre, &lpre, 1) <0) return(0);
16208       }
16209       else { if(readfrd( datin, apre, &npre, &epre, &lpre, read_mode) <0) return(0); }
16210     }
16211     else if(compare( param1,"foam",4)==4)
16212     {
16213       readFoam( datin, apre, &spre, &npre, &epre, &lpre );
16214     }
16215     else if(compare( ext, "stl",3)== 3)
16216     {
16217       readStl( datin, apre, &npre, &epre, &lpre );
16218     }
16219     else if(compare( param1,"ng",2)==2)
16220     {
16221       readNG( datin, apre, &spre, &npre, &epre, &lpre );
16222     }
16223     else
16224     {
16225       apre->nmax=anz->nmax;
16226       apre->emax=anz->emax;
16227       if( readccx( datin, apre, &spre, &npre, &epre, &lpre) == -1) return(0);
16228     }
16229 
16230     /* if 'nom(mesh)' is specified, scip the mesh-definition */
16231     if( (compare( param1, "nom", 3)== 3)||(compare( param2, "nom", 3)== 3))
16232     {
16233       if(anz->orign!=apre->n) printf("WARNING: Number of nodes:%d in the inp-file is different to the current number of nodes:%d. The meshes are potentially different.\n",apre->n,anz->orign );
16234       if(anz->e!=apre->e) printf("WARNING: Number of elements:%d in the inp-file is different to the current number of elements:%d. The meshes are potentially different.\n",apre->e,anz->e);
16235     }
16236     else
16237     {
16238       /* free the additional midside-nodes for higher order elements */
16239       for(i=anz->orign; i<anz->n; i++) node[node[i].nr].pflag=-1;
16240       anz->n= anz->orign;
16241       anz->nmax=anz->orignmax;
16242 
16243       /* modify node and element numbers if param2 == add */
16244       if( (compare( param1, "add", 3)== 3)||(compare( param2, "add", 3)== 3))
16245       {
16246         emax=apre->emax;
16247         nmax=apre->nmax;
16248         renumberfrd( anz->enext, anz->nnext, &apre[0], &npre, &epre, &lpre, &newelem, &newnode );
16249       }
16250       if(apre->nmax>anz->nmax) anz->nmax=apre->nmax;
16251       if(anz->nmin==MAX_INTEGER) anz->nmin=apre->nmin;
16252 
16253       /* create the nodes  */
16254       if ((node = (Nodes *)realloc( (Nodes *)node, (anz->nmax+1)*sizeof(Nodes)) ) == NULL )
16255 	{ errMsg("ERROR: realloc failure\n"); return(0); }
16256       for (i=anz->orignmax+1; i<=anz->nmax; i++) node[i].indx=-1;
16257       for (lc=0; lc<anz->l; lc++)
16258       {
16259         if (lcase[lc].loaded)
16260         {
16261           for(l=0; l<lcase[lc].ncomps; l++)
16262           {
16263             if ( (lcase[lc].dat[l] = (float *)realloc(lcase[lc].dat[l], (anz->nmax+1) * sizeof(float))) == NULL )
16264               printf("\n\n ERROR: realloc failure\n\n" );
16265           }
16266         }
16267       }
16268 
16269       if( (compare( param1, "add", 3)== 3)||(compare( param2, "add", 3)== 3))
16270       {
16271        for(i=0; i<apre->n; i++)
16272        {
16273         n=anz->n++;
16274         node[n].nr=npre[i].nr;
16275         node[node[n].nr].indx=n;
16276         node[node[n].nr].pflag=0;
16277         for (lc=0; lc<anz->l; lc++)
16278         {
16279          if (lcase[lc].loaded)
16280          {
16281           for(l=0; l<lcase[lc].ncomps; l++)
16282           {
16283             lcase[lc].dat[l][node[n].nr]=0.;
16284           }
16285          }
16286         }
16287         for (j=0; j<anz->sets; j++)
16288         {
16289           if ( set[j].flag=='o') seta( j, "n", node[n].nr );
16290         }
16291         node[node[n].nr].nx=(npre[npre[i].nr].nx-scale->x)/scale->w;
16292         node[node[n].nr].ny=(npre[npre[i].nr].ny-scale->y)/scale->w;
16293         node[node[n].nr].nz=(npre[npre[i].nr].nz-scale->z)/scale->w;
16294         node[node[n].nr].nv[0]=node[node[n].nr].nv[1]=node[node[n].nr].nv[2]=0.;
16295        }
16296       }
16297       else
16298       {
16299         for(i=0; i<apre->n; i++)
16300         {
16301           nod( anz, &node, 1, npre[i].nr, npre[npre[i].nr].nx, npre[npre[i].nr].ny, npre[npre[i].nr].nz, 1 );
16302         }
16303       }
16304       anz->nnext = anz->nmax+1;
16305 
16306       /* generate elements */
16307       l=anz->emax;
16308       if(apre->emax>anz->emax) anz->emax=apre->emax;
16309       if(anz->emin==MAX_INTEGER) anz->emin=apre->emin;
16310       if((e_enqire=(Elements *)realloc((Elements *)e_enqire, (anz->emax+1) * sizeof(Elements))) == NULL )
16311         printf("\n\n ERROR: malloc failed\n\n") ;
16312       for (i=l+1; i<=anz->emax; i++) e_enqire[i].type=0;
16313       for(i=0; i<apre->e; i++)
16314       {
16315         e=elem_define(anz,&e_enqire, epre[i].nr, epre[i].type, epre[i].nod, 1, epre[i].attr );
16316         e_enqire[epre[i].nr].mat=epre[i].mat;
16317       }
16318       anz->enext = anz->emax+1;
16319 
16320       /* new scaling for drawing */
16321       descalAll();
16322       getScaleValues( setall, set, point, node, scale);
16323       scalNodes ( anz->n, node, scale );
16324       scalPoints ( anzGeo->p, point, scale );
16325       scalSurfs( anzGeo->s, surf, scale);
16326       // recalculate the line-shapes
16327       for (i=0; i<anzGeo->l; i++) repLine(i);
16328       // recalculate the nurbl-controll-points
16329       for (i=0; i<anzGeo->nurl; i++) repNurl(i);
16330       // recalculate the nurbs-controll-points
16331       for (i=0; i<anzGeo->nurs; i++) repNurs(i);
16332       // correct the orientation of all entities
16333       orientSet( "all" );
16334 
16335       /* new midnodes for drawing */
16336       adjustDrawNodes(1);
16337 
16338       getElemNormalen( e_enqire, node, anz->e );
16339       makeSurfaces();
16340     }
16341 
16342     /* add the new datasets if no old exist */
16343     if(anz->l==0)
16344     {
16345       lcase=lpre;
16346       anz->olc=anz->l=apre->l;
16347       lpre=NULL;
16348       for(l=0; l<anz->l; l++)
16349       {
16350         if (lcase[l].loaded) calcDatasets( l, anz, node, lcase );
16351         if(activWindow!=-1) recompileEntitiesInMenu(l);
16352       }
16353     }
16354     else
16355     {
16356       /* add the new nodes to the existing datasets if option ext or add was provided, else add datasets to the existing ones */
16357       if( (compare( param1, "add", 3)== 3)||(compare( param2, "add", 3)== 3)||(compare( param1, "ext", 3)== 3)||(compare( param2, "ext", 3)== 3))
16358       {
16359         lp=0;
16360         for(l=0; l<anz->l; l++)
16361         {
16362           /* fill the datasets */
16363           n=strlen(lcase[l].name)-1;
16364           while((n>0)&&(lcase[l].name[n]==' ')) { lcase[l].name[n]=0; n--; }
16365           n=strlen(lpre[lp].name)-1;
16366           while((n>0)&&(lpre[lp].name[n]==' ')) { lpre[lp].name[n]=0; n--; }
16367 	  printf("compare existing lcase:%s with:%s\n",lcase[l].name, lpre[lp].name);
16368           if((lp<apre->l)&&(lcase[l].ncomps>=lpre[lp].ncomps)&&(compareStrings(lcase[l].name, lpre[lp].name)>0))
16369           {
16370             /* check if the data of the specified lcase (Dataset) are already available */
16371             if (!lcase[l].loaded)
16372             {
16373               if( pre_readfrdblock(copiedNodeSets , l, anz, node, lcase )==-1)
16374               {
16375                 printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", l+1);
16376                 return(0);
16377               }
16378 	    }
16379             for(i=0; i<lcase[l].ncomps; i++)
16380             {
16381               if ( (lcase[l].dat[i] = (float *)realloc(lcase[l].dat[i], (anz->nmax+1) * sizeof(float))) == NULL )
16382               printf("\n\n ERROR: realloc failure nod\n\n" );
16383             }
16384             for(n=0; n<apre->n; n++)
16385             {
16386               for(i=0; i<lpre[lp].ncomps; i++)
16387               {
16388                 lcase[l].dat[i][npre[n].nr]=  lpre[lp].dat[i][npre[n].nr];
16389                 if (lcase[l].dat[i][npre[n].nr] >  lcase[l].max[i])
16390                 {  lcase[l].max[i]=lcase[l].dat[i][npre[n].nr]; lcase[l].nmax[i]=npre[n].nr; }
16391                 if (lcase[l].dat[i][npre[n].nr] <  lcase[l].min[i])
16392                 {  lcase[l].min[i]=lcase[l].dat[i][npre[n].nr]; lcase[l].nmin[i]=npre[n].nr; }
16393               }
16394             }
16395             calcDatasets( l, anz, node, lcase );
16396             recompileEntitiesInMenu(l);
16397   	    printf(" Add dataset[%d]:%s to existing dataset[%d]:%s\n",lp+1, lpre[lp].name, l+1,lcase[l].name);
16398             lp++;
16399           }
16400   	  else
16401           {
16402   	    if(lp) printf(" WARNING: data from new model have different nr of components for dataset[%d]:%s and could not be merged.\n",l+1,lcase[l].name);
16403             if( apre->l > anz->l ) { lp++; l--; }
16404             if(( lp >= apre->l)||(l<0))  break;
16405   	  }
16406         }
16407         /* add the new datasets */
16408         if(!lp)
16409         {
16410           printf("additional Datasets:%d\n",apre->l);
16411           if( ( lcase=(Datasets *)realloc((Datasets *)lcase,(anz->l+apre->l+1)*sizeof(Datasets))  )==NULL)
16412             printf("\n\n ERROR: realloc failed\n\n") ;
16413           for(l=0; l<apre->l; l++)
16414 	  {
16415             lcase[anz->l+l]=lpre[l];
16416             if (lcase[anz->l+l].loaded) calcDatasets( anz->l+l, anz, node, lcase );
16417             if(activWindow!=-1) recompileEntitiesInMenu(anz->l+l);
16418 	  }
16419           anz->l+=apre->l;
16420           anz->olc=anz->l;
16421         }
16422       }
16423       /* add the new datasets */
16424       else
16425       {
16426         printf("additional Datasets:%d\n",apre->l);
16427         if( ( lcase=(Datasets *)realloc((Datasets *)lcase,(anz->l+apre->l+1)*sizeof(Datasets))  )==NULL)
16428         printf("\n\n ERROR: realloc failed\n\n") ;
16429         for(l=0; l<apre->l; l++)
16430 	{
16431           lcase[anz->l+l]=lpre[l];
16432           if (lcase[anz->l+l].loaded) calcDatasets( anz->l+l, anz, node, lcase );
16433           if(activWindow!=-1) recompileEntitiesInMenu(anz->l+l);
16434 	}
16435         anz->l+=apre->l;
16436         anz->olc=anz->l;
16437       }
16438     }
16439 
16440     /* add materials and amplitudes */
16441     anz->mats+=apre->mats;
16442     anz->amps+=apre->amps;
16443 
16444     /* generate sets */
16445     for(i=0; i<apre->sets; i++)
16446     {
16447       nset=getSetNr(spre[i].name);
16448       if(nset<0) nset=pre_seta(spre[i].name,"i",0);
16449       set[nset].type=spre[i].type;
16450       set[nset].material=spre[i].material;
16451       if(newnode) for (j=0; j<spre[i].anz_n; j++) { if(spre[i].node[j]<=nmax) seta(nset,"n",newnode[spre[i].node[j]]); }
16452       else for (j=0; j<spre[i].anz_n; j++) seta(nset,"n",spre[i].node[j]);
16453       if(newelem) for (j=0; j<spre[i].anz_e; j++) { if(spre[i].elem[j]<=emax) seta(nset,"e",newelem[spre[i].elem[j]]); }
16454       else for (j=0; j<spre[i].anz_e; j++) seta(nset,"e",spre[i].elem[j]);
16455 
16456       for (j=0; j<spre[i].anz_elf; j++)
16457       {
16458         if(newelem) e=newelem[spre[i].elf[j].e]; else e=spre[i].elf[j].e;
16459 
16460         /* for the moment a negative face-orientation can not be stored and is changed to positive */
16461         if((e_enqire[e].type>6)&&(e_enqire[e].type<11))
16462         {
16463           if(e_enqire[e].attr>3)
16464           {
16465             spre[i].elf[j].f++;
16466             if(e_enqire[e].type<9)
16467 	    {
16468               if(spre[i].elf[j].f>4) spre[i].elf[j].f=1;
16469 	    }
16470 	    else
16471 	    {
16472               if(spre[i].elf[j].f>5) spre[i].elf[j].f=1;
16473 	    }
16474 	  }
16475           else
16476           {
16477             spre[i].elf[j].f--;
16478             if(spre[i].elf[j].f==0) spre[i].elf[j].f=1;
16479 	  }
16480 	}
16481 
16482         /* store the actual face-indexes in the referenced sets */
16483         seta( nset, "f", face[e].indx[spre[i].elf[j].f]);
16484       }
16485     }
16486 
16487     /* delete elements in special sets created by readNG */
16488     // (Peter)  unless keyword ndsb  (NoDeleteShellsBeams) is present
16489     if((compare(param1,"ng",2)==2) && (compare(param2, "ndsb",4)!=4))
16490     {
16491       for (i=0; i<anz->sets; i++)
16492       {
16493         if(set[i].name!=NULL)
16494 	{
16495           if(compare(set[i].name, "+typ3", 5)==5) break;
16496           if(compare(set[i].name, "+typ6", 5)==5) break;
16497 	}
16498       }
16499       if(i<anz->sets)
16500       {
16501        printf("found volume elements -> delete all shells and beams.\n");
16502        for (i=0; i<anz->sets; i++)
16503        {
16504         if(set[i].name!=NULL)
16505 	{
16506           if(compare(set[i].name, "+typ7", 5)==5) delElem( set[i].anz_e, set[i].elem );
16507           if(compare(set[i].name, "+typ8", 5)==5) delElem( set[i].anz_e, set[i].elem );
16508           if(compare(set[i].name, "+typ11", 6)==6) delElem( set[i].anz_e, set[i].elem );
16509           if(compare(set[i].name, "+typ12", 6)==6) delElem( set[i].anz_e, set[i].elem );
16510 	}
16511        }
16512        for (i=0; i<anz->sets; i++)
16513        {
16514         if((set[i].name!=NULL)&&(compare(set[i].name, "+set", 4)==4))
16515         {
16516           /* get the nodes and faces */
16517           completeSet(set[i].name, "do");
16518         }
16519        }
16520       }
16521     }
16522 
16523     realloc_colNr();
16524 
16525     free(newelem);
16526     free(newnode);
16527 
16528     for(j=0; j<apre->sets; j++) {  delSetx(spre[j].name); }
16529     free(spre); spre=NULL;
16530     free(npre); npre=NULL;
16531     free(epre); epre=NULL;
16532     free(lpre); lpre=NULL;
16533 
16534     /* calculate the line-shapes */
16535     //for (i=0; i<anzGeo->l; i++) repLine(i);
16536     /* calculate the nurbl-controll-points */
16537     //for (i=0; i<anzGeo->nurl; i++) repNurl(i);
16538     /* calculate the nurbs-controll-points */
16539     //for (i=0; i<anzGeo->nurs; i++) repNurs(i);
16540 
16541     if(addDispFlagLocal==2) { addDispToCoordinates(node); }
16542     if(activWindow!=-1) createDatasetEntries();
16543   }
16544   else if ((length==1)||(compare( param1, "rep", 3)== 3))
16545   {
16546     return(readfbd( datin, 0 ));
16547     /* updateDispLists would overwrite the elem and model edges of the 1st frame */
16548     //if(!animFlag) updateDispLists();
16549   }
16550   else if (compare( param1, "add", 3)== 3)
16551   {
16552     return(readfbd( datin, 1 ));
16553     //if(!animFlag) updateDispLists();
16554   }
16555   else printf("ERROR, no matching file-type found\n");
16556 
16557   updateDispLists();
16558   createSuperSets();
16559   if(gtol_buf==gtol)
16560   { gtol=calcGTOL(setall);  printf ("gtol calculated:%e\n", gtol); }
16561 
16562   printf (" ready\n");
16563   return(0);
16564 }
16565 
16566 
16567 /* combine single sets to a superSet */
createSuperSets(void)16568 void createSuperSets(void)
16569 {
16570   int i,j,s,flmSet=-1, radSet=-1, cflxSet=-1, dflxSet=-1;
16571 
16572   s=anz->sets;
16573   for (i=0; i<s; i++) if(set[i].name!=(char *)NULL)
16574   {
16575     /* create additional special sets which add sets of a ceratin type */
16576     if(compare(set[i].name,"+flm",4)==4)
16577     {
16578       if(flmSet<0) flmSet=pre_seta("+flm","i",0);
16579       for (j=0; j<set[i].anz_f; j++) seta(flmSet,"f",set[i].face[j]);
16580     }
16581     if(compare(set[i].name,"+rad",4)==4)
16582     {
16583       if(radSet<0) radSet=pre_seta("+rad","i",0);
16584       for (j=0; j<set[i].anz_f; j++) seta(radSet,"f",set[i].face[j]);
16585     }
16586     if(compare(set[i].name,"+cflx",5)==5)
16587     {
16588       if(cflxSet<0) cflxSet=pre_seta("+cflx","i",0);
16589       for (j=0; j<set[i].anz_f; j++) seta(cflxSet,"f",set[i].face[j]);
16590     }
16591     if(compare(set[i].name,"+dflx",5)==5)
16592     {
16593       if(dflxSet<0) dflxSet=pre_seta("+dflx","i",0);
16594       for (j=0; j<set[i].anz_f; j++) seta(dflxSet,"f",set[i].face[j]);
16595     }
16596   }
16597 }
16598 
16599 
16600 
16601 /* define or change the element-typ in the struct of the lines, surfs, bodies */
pre_elty(char * record)16602 void pre_elty( char *record )
16603 {
16604   int  i,j, length, setNr;
16605   char setname[MAX_LINE_LENGTH], etype[MAX_LINE_LENGTH], eparm[MAX_LINE_LENGTH];
16606   static int elty_callNr=0;
16607   char attr;
16608   char elty[MAX_LINE_LENGTH];
16609   char **elty_string=NULL;
16610 
16611   setname[0]=etype[0]=eparm[0]='\0';
16612   length= sscanf( record, "%s%s%s", setname, etype, eparm);
16613   if(compareStrings(setname, "ALL")==3) strcpy(setname,"all");
16614   autoEltyFlag=0;
16615 
16616   if(length<1)
16617   {
16618     /* show all sets which have an element type assigned */
16619     /* search the highest set[i].eseq (number of elty commands) */
16620     j=1; for(i=0; i<anz->sets; i++)
16621     {
16622       if(set[i].name!=(char *)NULL) j=imax(j, set[i].eseq);
16623     }
16624     j++;
16625     if((elty_string=(char **)malloc(j*sizeof(char *))) == NULL) printf("\n\n ERROR:malloc failure\n\n");
16626     for (i=0; i<j; i++) elty_string[i]=(char *)NULL;
16627 
16628     for (i=0; i<anz->sets; i++)
16629     {
16630       if(set[i].name!=(char *)NULL)
16631       {
16632         if(set[i].eattr==1)  attr='R';
16633         else if(set[i].eattr==2)  attr='I';
16634         else if(set[i].eattr==3)  attr='D';
16635         else if(set[i].eattr==4)  attr='E';
16636         else if(set[i].eattr==5)  attr='S';
16637         else if(set[i].eattr==6)  attr='C';
16638         else if(set[i].eattr==7)  attr='F';
16639         else if(set[i].eattr==8)  attr='M';
16640         else if(set[i].eattr==9)  attr='T';
16641         else if(set[i].eattr==-1)  attr='U';
16642         else attr=' ';
16643         if(set[i].etyp==1) sprintf (elty, " ELTY %s HE8%c", set[i].name, attr);
16644         if(set[i].etyp==3) sprintf (elty, " ELTY %s TE4%c", set[i].name, attr);
16645         if(set[i].etyp==4) sprintf (elty, " ELTY %s HE20%c", set[i].name, attr);
16646         if(set[i].etyp==6) sprintf (elty, " ELTY %s TE10%c", set[i].name, attr);
16647         if(set[i].etyp==7) sprintf (elty, " ELTY %s TR3%c", set[i].name, attr);
16648         if(set[i].etyp==8) sprintf (elty, " ELTY %s TR6%c", set[i].name, attr);
16649         if(set[i].etyp==9) sprintf (elty, " ELTY %s QU4%c", set[i].name, attr);
16650         if(set[i].etyp==10) sprintf (elty, " ELTY %s QU8%c", set[i].name, attr);
16651         if(set[i].etyp==11) sprintf (elty, " ELTY %s BE2%c", set[i].name, attr);
16652         if(set[i].etyp==12) sprintf (elty, " ELTY %s BE3%c", set[i].name, attr);
16653         if(set[i].etyp>0)
16654 	{
16655           if((elty_string[set[i].eseq]=(char *)malloc(MAX_LINE_LENGTH*sizeof(char))) == NULL) printf("\n\n ERROR:malloc failure\n\n");
16656 
16657           if(set[i].eparm!=(char *)NULL) sprintf(elty_string[set[i].eseq], "%s %s",elty, set[i].eparm);
16658           else sprintf(elty_string[set[i].eseq], "%s",elty);
16659         }
16660       }
16661     }
16662     for (i=0; i<j; i++)
16663     {
16664       if(elty_string[i]!=(char *)NULL)
16665       {
16666         printf("%s\n", elty_string[i]);
16667         free(elty_string[i]);
16668       }
16669     }
16670     free(elty_string);
16671   }
16672   else if(length==1)
16673   {
16674     setNr=getSetNr(setname);
16675     if (setNr<0)
16676     {
16677       printf (" ERROR in pre_elty: set:%s does not exist\n", setname);
16678       return;
16679     }
16680 
16681     /* delete all element definitions if the setname is "all" */
16682     if(compareStrings(setname, "all")>0)
16683     {
16684       for (setNr=0; setNr<anz->sets; setNr++)
16685       {
16686         set[setNr].etyp=0;
16687         set[setNr].eattr=0;
16688         if(set[setNr].eparm!=(char *)NULL)
16689 	{
16690           free(set[setNr].eparm);
16691           set[setNr].eparm=(char *)NULL;
16692 	}
16693         for (i=0; i<set[setNr].anz_b; i++)
16694         {
16695           body[set[setNr].body[i]].eattr=set[setNr].eattr ;
16696           body[set[setNr].body[i]].etyp=set[setNr].etyp ;
16697           if(body[set[setNr].body[i]].eparm!=(char *)NULL)
16698 	  { free(body[set[setNr].body[i]].eparm) ; body[set[setNr].body[i]].eparm=(char *)NULL; }
16699         }
16700         for (i=0; i<set[setNr].anz_s; i++)
16701         {
16702           surf[set[setNr].surf[i]].eattr=set[setNr].eattr ;
16703           surf[set[setNr].surf[i]].etyp=set[setNr].etyp ;
16704           if(surf[set[setNr].surf[i]].eparm!=(char *)NULL)
16705 	  { free(surf[set[setNr].surf[i]].eparm) ; surf[set[setNr].surf[i]].eparm=(char *)NULL; }
16706         }
16707         for (i=0; i<set[setNr].anz_l; i++)
16708         {
16709           line[set[setNr].line[i]].eattr=set[setNr].eattr ;
16710           line[set[setNr].line[i]].etyp=set[setNr].etyp ;
16711         }
16712       }
16713     }
16714     /* delete only the element-def of this set */
16715     else
16716     {
16717       set[setNr].etyp=0;
16718       set[setNr].eattr=0;
16719       set[setNr].eparm=(char *)NULL;
16720       if(set[setNr].eparm!=(char *)NULL)
16721       {
16722         free(set[setNr].eparm);
16723         set[setNr].eparm=(char *)NULL;
16724       }
16725       for (i=0; i<set[setNr].anz_b; i++)
16726       {
16727         body[set[setNr].body[i]].eattr=set[setNr].eattr ;
16728         body[set[setNr].body[i]].etyp=set[setNr].etyp ;
16729         if(body[set[setNr].body[i]].eparm!=(char *)NULL)
16730         { free(body[set[setNr].body[i]].eparm) ; body[set[setNr].body[i]].eparm=(char *)NULL; }
16731       }
16732       for (i=0; i<set[setNr].anz_s; i++)
16733       {
16734         surf[set[setNr].surf[i]].eattr=set[setNr].eattr ;
16735         surf[set[setNr].surf[i]].etyp=set[setNr].etyp ;
16736         if(surf[set[setNr].surf[i]].eparm!=(char *)NULL)
16737         { free(surf[set[setNr].surf[i]].eparm) ; surf[set[setNr].surf[i]].eparm=(char *)NULL; }
16738       }
16739       for (i=0; i<set[setNr].anz_l; i++)
16740       {
16741         line[set[setNr].line[i]].eattr=set[setNr].eattr ;
16742         line[set[setNr].line[i]].etyp=set[setNr].etyp ;
16743       }
16744     }
16745   }
16746   else
16747   {
16748     setNr=getSetNr(setname);
16749     if (setNr<0)
16750     {
16751       printf (" ERROR in pre_elty: set:%s does not exist\n", setname);
16752       return;
16753     }
16754     set[setNr].eseq=elty_callNr++;
16755 
16756     for(i=0;i<strlen(etype); i++) etype[i]=toupper(etype[i]);
16757     for(i=0;i<strlen(eparm); i++) eparm[i]=toupper(eparm[i]);
16758     if(strlen(eparm))
16759     {
16760       if((set[setNr].eparm= (char *)realloc((char *)set[setNr].eparm, (strlen(eparm)+1)*sizeof(char))) == NULL )
16761       { printf("ERROR: malloc failed in seta()\n\n" ); return; }
16762       strcpy(set[setNr].eparm, eparm);
16763     }
16764     else { free(set[setNr].eparm); set[setNr].eparm=(char *)NULL; }
16765 
16766     if( compare( etype, "BE2", 3) == 3)
16767     {
16768       if(strlen(etype)==3)   { set[setNr].etyp=11; set[setNr].eattr=0; }
16769       else if(etype[3]=='R') { set[setNr].etyp=11; set[setNr].eattr=1; }
16770       else if(etype[3]=='D') { set[setNr].etyp=11; set[setNr].eattr=3; }
16771       else if(etype[3]=='F') { set[setNr].etyp=11; set[setNr].eattr=7; }
16772       else printf("ERROR: type %s not known\n", etype);
16773     }
16774     else if(compare( etype, "BE3", 3) == 3)
16775     {
16776       if(strlen(etype)==3)   { set[setNr].etyp=12; set[setNr].eattr=0; }
16777       else if(etype[3]=='R') { set[setNr].etyp=12; set[setNr].eattr=1; }
16778       else if(etype[3]=='F') { set[setNr].etyp=12; set[setNr].eattr=7; }
16779       else printf("ERROR: type %s not known\n", etype);
16780     }
16781     else if(compare( etype, "TR3", 3) == 3)
16782     {
16783       if(strlen(etype)==3)   { set[setNr].etyp=7; set[setNr].eattr=0; }
16784       else if(etype[3]=='U') { set[setNr].etyp=7; set[setNr].eattr=-1; }
16785       else if(etype[3]=='E') { set[setNr].etyp=7; set[setNr].eattr=4; }
16786       else if(etype[3]=='S') { set[setNr].etyp=7; set[setNr].eattr=5; }
16787       else if(etype[3]=='C') { set[setNr].etyp=7; set[setNr].eattr=6; }
16788       else if(etype[3]=='F') { set[setNr].etyp=7; set[setNr].eattr=7; }
16789       else printf("ERROR: type %s not known\n", etype);
16790     }
16791     else if(compare( etype, "TR6", 3) == 3)
16792     {
16793       if(strlen(etype)==3)   { set[setNr].etyp=8; set[setNr].eattr=0; }
16794       else if(etype[3]=='U') { set[setNr].etyp=8; set[setNr].eattr=-1; }
16795       else if(etype[3]=='E') { set[setNr].etyp=8; set[setNr].eattr=4; }
16796       else if(etype[3]=='S') { set[setNr].etyp=8; set[setNr].eattr=5; }
16797       else if(etype[3]=='C') { set[setNr].etyp=8; set[setNr].eattr=6; }
16798       else printf("ERROR: type %s not known\n", etype);
16799     }
16800     else if(compare( etype, "QU4", 3) == 3)
16801     {
16802       if(strlen(etype)==3)   { set[setNr].etyp=9; set[setNr].eattr=0; }
16803       else if(etype[3]=='R') { set[setNr].etyp=9; set[setNr].eattr=1; }
16804       else if(etype[3]=='E') { set[setNr].etyp=9; set[setNr].eattr=4; }
16805       else if(etype[3]=='S') { set[setNr].etyp=9; set[setNr].eattr=5; }
16806       else if(etype[3]=='C') { set[setNr].etyp=9; set[setNr].eattr=6; }
16807       else if(etype[3]=='F') { set[setNr].etyp=9; set[setNr].eattr=7; }
16808       else printf("ERROR: type %s not known\n", etype);
16809 
16810       if((strlen(etype)==5)&&(etype[4]=='R')) { set[setNr].eattr+=10; }
16811     }
16812     else if(compare( etype, "QU8", 3) == 3)
16813     {
16814       if(strlen(etype)==3)   { set[setNr].etyp=10; set[setNr].eattr=0; }
16815       else if(etype[3]=='R') { set[setNr].etyp=10; set[setNr].eattr=1; }
16816       else if(etype[3]=='E') { set[setNr].etyp=10; set[setNr].eattr=4; }
16817       else if(etype[3]=='S') { set[setNr].etyp=10; set[setNr].eattr=5; }
16818       else if(etype[3]=='C') { set[setNr].etyp=10; set[setNr].eattr=6; }
16819       else printf("ERROR: type %s not known\n", etype);
16820 
16821       if((strlen(etype)==5)&&(etype[4]=='R')) { set[setNr].eattr+=10; }
16822     }
16823     else if(compare( etype, "HE8", 3) == 3)
16824     {
16825       if(strlen(etype)==3)   { set[setNr].etyp=1; set[setNr].eattr=0; }
16826       else if(etype[3]=='R') { set[setNr].etyp=1; set[setNr].eattr=1; }
16827       else if(etype[3]=='I') { set[setNr].etyp=1; set[setNr].eattr=2; }
16828       else if(etype[3]=='F') { set[setNr].etyp=1; set[setNr].eattr=7; }
16829       else printf("ERROR: type %s not known\n", etype);
16830     }
16831     else if(compare( etype, "HE20", 4) == 4)
16832     {
16833       if(strlen(etype)==4)   { set[setNr].etyp=4; set[setNr].eattr=0; }
16834       else if(etype[4]=='R') { set[setNr].etyp=4; set[setNr].eattr=1; }
16835       else printf("ERROR: type %s not known\n", etype);
16836     }
16837     else if(compare( etype, "PE6", 3) == 3)
16838     {
16839       if(strlen(etype)==3)   { set[setNr].etyp=2; set[setNr].eattr=0; }
16840       else if(etype[3]=='R') { set[setNr].etyp=2; set[setNr].eattr=1; }
16841       else if(etype[3]=='I') { set[setNr].etyp=2; set[setNr].eattr=2; }
16842       else if(etype[3]=='F') { set[setNr].etyp=2; set[setNr].eattr=7; }
16843       else printf("ERROR: type %s not known\n", etype);
16844     }
16845     else if(compare( etype, "PE15", 4) == 4)
16846     {
16847       if(strlen(etype)==4)   { set[setNr].etyp=5; set[setNr].eattr=0; }
16848       else if(etype[4]=='R') { set[setNr].etyp=5; set[setNr].eattr=1; }
16849       else printf("ERROR: type %s not known\n", etype);
16850     }
16851     else if(compare( etype, "TE4", 3) == 3)
16852     {
16853       if(strlen(etype)==3)   { set[setNr].etyp=3; set[setNr].eattr=0; }
16854       else if(etype[3]=='F') { set[setNr].etyp=3; set[setNr].eattr=7; }
16855       else printf("ERROR: type %s not known\n", etype);
16856     }
16857     else if(compare( etype, "TE10", 4) == 4)
16858     {
16859       if(strlen(etype)==4)   { set[setNr].etyp=6; set[setNr].eattr=0; }
16860       else if(etype[4]=='M') { set[setNr].etyp=6; set[setNr].eattr=8; }
16861       else if(etype[4]=='T') { set[setNr].etyp=6; set[setNr].eattr=9; }
16862       else printf("ERROR: type %s not known\n", etype);
16863     }
16864     else
16865     {
16866       printf("ERROR: element-type:%s not known (choose either be2,be3,tr3,tr6,qu4,qu8,he8,he20,te4,te10)\n",etype);
16867       return;
16868     }
16869 
16870     /* assign the element-type to the appropriate entities */
16871     /* assign the attribute */
16872     /* get the basis formulation of the etyp */
16873     if(set[setNr].etyp<7)
16874     {
16875       for (i=0; i<set[setNr].anz_b; i++)
16876       {
16877         body[set[setNr].body[i]].eattr=set[setNr].eattr ;
16878         body[set[setNr].body[i]].etyp=set[setNr].etyp ;
16879         if(set[setNr].eparm!=(char *)NULL) {
16880         if((body[set[setNr].body[i]].eparm= (char *)realloc((char *)body[set[setNr].body[i]].eparm, (strlen(set[setNr].eparm)+1)*sizeof(char))) == NULL )
16881         { printf("ERROR: malloc failed in prnt()\n\n" ); return; }
16882         strcpy(body[set[setNr].body[i]].eparm,set[setNr].eparm); }
16883       }
16884     }
16885     if((set[setNr].etyp>=7)&&(set[setNr].etyp<=10))
16886     {
16887       for (i=0; i<set[setNr].anz_s; i++)
16888       {
16889         surf[set[setNr].surf[i]].eattr=set[setNr].eattr ;
16890         surf[set[setNr].surf[i]].etyp=set[setNr].etyp ;
16891         if(set[setNr].eparm!=(char *)NULL)
16892         {
16893           if((surf[set[setNr].surf[i]].eparm= (char *)realloc((char *)surf[set[setNr].surf[i]].eparm, (strlen(set[setNr].eparm)+1)*sizeof(char))) == NULL )
16894           { printf("ERROR: malloc failed in prnt()\n\n" ); return; }
16895           strcpy(surf[set[setNr].surf[i]].eparm,set[setNr].eparm);
16896         }
16897         else { free(surf[set[setNr].surf[i]].eparm); surf[set[setNr].surf[i]].eparm=(char *)NULL; }
16898       }
16899     }
16900     if((set[setNr].etyp>=11)&&(set[setNr].etyp<=12))
16901     {
16902       for (i=0; i<set[setNr].anz_l; i++)
16903       {
16904         line[set[setNr].line[i]].eattr=set[setNr].eattr ;
16905         line[set[setNr].line[i]].etyp=set[setNr].etyp ;
16906       }
16907     }
16908     for (i=0; i<set[setNr].anz_e; i++)
16909     {
16910       if(e_enqire[set[setNr].elem[i]].type==set[setNr].etyp) e_enqire[set[setNr].elem[i]].attr=set[setNr].eattr ;
16911     }
16912   }
16913 }
16914 
16915 
16916 
16917 /* define the threshold-values for element criterions */
pre_eqal(char * record)16918 void pre_eqal( char *record )
16919 {
16920   int j;
16921   char  etest[MAX_LINE_LENGTH];
16922   double evalue;
16923 
16924   etest[0]='\0';
16925   sscanf( record, "%s%lf", etest, &evalue);
16926   for(j=0;j<=strlen(etest); j++) etest[j]=toupper(etest[j]);
16927 
16928   if(compareStrings(etest,"JBIR")>0)
16929   {
16930     eqal.jbir=evalue;
16931   }
16932   else if(compareStrings(etest,"ASPR")>0)
16933   {
16934     eqal.aspr=evalue;
16935   }
16936   else if(compareStrings(etest,"MCA")>0)
16937   {
16938     eqal.mca=evalue;
16939   }
16940   else
16941   {
16942     printf(" current element quality thresholds (0==off):\n JBIR:%lf\n ASPR:%lf\n MCA:%lf\n", eqal.jbir, eqal.aspr, eqal.mca);
16943     sprintf(parameter[0],"%lf",eqal.jbir);
16944     sprintf(parameter[1],"%lf",eqal.aspr);
16945     sprintf(parameter[2],"%lf",eqal.mca);
16946     write2stack(3, parameter);
16947   }
16948 }
16949 
16950 
16951 /* store the entities to be meshed in a special set and add lower entities, then mesh   */
16952 
pre_mesh(char * record)16953 int pre_mesh( char *record )
16954 {
16955   int c,l,n,s,i,j,k,se, tetSet=0;
16956   char buffer[MAX_LINE_LENGTH],setname[MAX_LINE_LENGTH], code[4][MAX_LINE_LENGTH];
16957   int   anz_nmax,length, setNr, sets, meshoptFlag_length=MESHOPT_LENGTH, meshoptFlag_angle=MESHOPT_ANGLE, blockFlag=0, lonlyFlag=0, projFlag=1, tetFlag=0;
16958   double teth=1e6;
16959   int ntmp,etmp=0,eSet;
16960 
16961   length = sscanf( record,"%s %s %s %s %s", setname,code[0],code[1],code[2],code[3] );
16962 
16963   for(i=0; i<length-1; i++)
16964   {
16965     if(compare(code[i],"nolength",4)==4)  meshoptFlag_length=0;
16966     else if(compare(code[i],"noangle",4)==4)  meshoptFlag_angle=0;
16967     else if(compare(code[i],"length",4)==4)  meshoptFlag_length=1;
16968     else if(compare(code[i],"angle",4)==4)  meshoptFlag_angle=1;
16969     else if(compare(code[i],"block",3)==3) blockFlag=1;
16970     else if(compare(code[i],"fast",3)==3) projFlag=0;
16971     else if(compare(code[i],"lonly",3)==3) lonlyFlag=1;
16972     /* a rudimentary implementation of netgen to generate tets */
16973     else if(compare(code[i],"tet",3)==3)
16974     {
16975       tetFlag=1;
16976       if(length == i+3) teth=(double)atof(code[i+1]);
16977     }
16978   }
16979 
16980   operateAlias( setname, "se" );
16981   setNr=getSetNr(setname);
16982   if (setNr<0)
16983   {
16984     printf (" ERROR in pre_mesh: set:%s does not exist\n", setname);
16985     return(-1);
16986   }
16987   else
16988     if(printFlag) printf (" set[%d]:%s will be meshed\n", setNr, setname);
16989 
16990   printf (" please wait for 'ready'\n");
16991   setall=getSetNr("all");
16992 
16993   /* cycle through all entities and add them to the special set  */
16994 
16995   if( (se=pre_seta( specialset->mesh, "i", 0)) <0 ) return(-1);
16996   if(setNr==setall)
16997   {
16998     for (i=0; i<anz->n; i++) if(node[node[i].nr].pflag==0) seta( se, "n", node[i].nr );
16999     for (i=0; i<anz->e; i++) seta( se, "e", e_enqire[i].nr );
17000     for (i=0; i<anzGeo->l; i++) if( line[i].name != (char *)NULL ) seta( se, "l", i );
17001     for (i=0; i<anzGeo->p; i++) if( point[i].name != (char *)NULL ) seta( se, "p", i );
17002     for (i=0; i<anzGeo->l; i++) if( line[i].name != (char *)NULL ) seta( se, "l", i );
17003     for (i=0; i<anzGeo->s; i++) if( surf[i].name != (char *)NULL ) seta( se, "s", i );
17004     for (i=0; i<anzGeo->b; i++) if( body[i].name != (char *)NULL ) seta( se, "b", i );
17005   }
17006   else
17007   {
17008     for (i=0; i<set[setNr].anz_n; i++) seta( se, "n", set[setNr].node[i] );
17009     for (i=0; i<set[setNr].anz_e; i++) seta( se, "e", set[setNr].elem[i] );
17010     for (i=0; i<set[setNr].anz_b; i++) seta( se, "b", set[setNr].body[i] );
17011     for (i=0; i<set[setNr].anz_s; i++) seta( se, "s", set[setNr].surf[i] );
17012     for (i=0; i<set[setNr].anz_c; i++) seta( se, "c", set[setNr].lcmb[i] );
17013     for (i=0; i<set[setNr].anz_l; i++) seta( se, "l", set[setNr].line[i] );
17014     /* second cycle through all entities and add lower ones  to the special set  */
17015     /* completeSet( specialset->mesh, "do") ; */
17016 
17017     /* cyrcle through all bodys and add all surfs */
17018     for (i=0; i<set[se].anz_b; i++)
17019     {
17020       c= set[se].body[i];
17021       for (j=0; j<body[c].ns; j++)
17022       {
17023         l=body[c].s[j];
17024         seta( se, "s", l );
17025       }
17026     }
17027     /* cyrcle through all surfs and add all lines, lcmbs and nurbs */
17028     for (i=0; i<set[se].anz_s; i++)
17029     {
17030       s= set[se].surf[i];
17031       //if(surf[s].sh>-1) seta( se, "sh", surf[s].sh );
17032       for (j=0; j<surf[s].nl; j++)
17033       {
17034         l=surf[s].l[j];
17035         if (surf[s].typ[j]=='l')
17036         {
17037           seta( se, "l", l );
17038         }
17039         else
17040         {
17041           seta( se, "c", l );
17042         }
17043       }
17044     }
17045     /* cyrcle through all lcmbs and add all lines */
17046     for (i=0; i<set[se].anz_c; i++)
17047     {
17048       c= set[se].lcmb[i];
17049       for (j=0; j<lcmb[c].nl; j++)
17050       {
17051         l=lcmb[c].l[j];
17052         seta( se, "l", l );
17053       }
17054     }
17055     /* cyrcle through all lines and add all points, trks */
17056     for (i=0; i<set[se].anz_l; i++)
17057     {
17058       l= set[se].line[i];
17059       seta( se, "p", line[l].p1 );
17060       seta( se, "p", line[l].p2 );
17061       if (line[l].typ=='a') seta( se, "p", line[l].trk );
17062       if (line[l].typ=='s') seta( se, "se", line[l].trk );
17063     }
17064     /* cyrcle through all nurbs and add all points */
17065     /*
17066     for (i=0; i<set[se].anz_nurs; i++)
17067     {
17068       s= set[se].nurs[i];
17069       for (j=0; j<nurbs[s].u_npnt; j++)
17070         for (k=0; k<nurbs[s].v_npnt; k++)
17071           seta( se, "p", nurbs[s].ctlpnt[j][k] );
17072     }
17073     */
17074   }
17075 
17076   /* cyrcle through all bodys and check the body-etyp, for tet-requests set the surface-etyp */
17077   for (i=0; i<set[se].anz_b; i++)
17078   {
17079     c= set[se].body[i];
17080     if(body[c].etyp==3)
17081     {
17082       for (j=0; j<body[c].ns; j++)
17083       {
17084         l=body[c].s[j];
17085         if(surf[l].etyp!=7) { surf[l].etyp=7; surf[l].eattr=-1; }
17086       }
17087     }
17088     if(body[c].etyp==6)
17089     {
17090       for (j=0; j<body[c].ns; j++)
17091       {
17092         l=body[c].s[j];
17093         if(surf[l].etyp!=8) { surf[l].etyp=8; surf[l].eattr=-1; }
17094       }
17095     }
17096   }
17097 
17098   /* cyrcle again through all bodys and check the body-etyp for hex-requests, then eventually change the eattr of the surfaces */
17099   for (i=0; i<set[se].anz_b; i++)
17100   {
17101     c= set[se].body[i];
17102     if((body[c].etyp==1)||(body[c].etyp==4))
17103     {
17104       for (j=0; j<body[c].ns; j++)
17105       {
17106         l=body[c].s[j];
17107         if(surf[l].eattr==-1) surf[l].eattr=0;
17108       }
17109     }
17110   }
17111 
17112   orientSet( specialset->mesh );
17113 
17114   /* free the additional midside-nodes for higher order elements */
17115   for(i=anz->orign; i<anz->n; i++) node[node[i].nr].pflag=-1;
17116   anz->n= anz->orign;
17117   anz->nmax=anz->orignmax;
17118 
17119   anz_nmax=anz->nmax;
17120   /* mesh an existing surface-mesh */
17121   if(tetFlag)
17122   {
17123     if(set[setNr].flag!='o') { i=1; seto(set[setNr].name); } else { i=0; }
17124     generateTetFromSet(se, teth, set[se].eattr, meshp.tetmesher);
17125     if(i) setc(set[setNr].name);
17126     adjustDrawNodes(1);
17127   }
17128   else
17129   {
17130     /* mesh the geometry */
17131     if(meshSet( specialset->mesh, blockFlag, lonlyFlag, projFlag, meshoptFlag_length, meshoptFlag_angle) <1) goto scipMesh;
17132     setall=getSetNr("all");
17133     elemChecker( set[setall].anz_e, set[setall].elem, node, e_enqire);
17134     adjustDrawNodes(1);
17135 
17136     /* improve bad tr3 elements */
17137     improveBadTr3(specialset->mesh);
17138 
17139     /* cyrcle again through all bodys and check if mpcs have to be generated to glue incompatible element-formulations (he8+he20, tet+he20, etc) */
17140     for (i=0; i<set[se].anz_b; i++)
17141     {
17142       c= set[se].body[i];
17143       if(body[c].etyp==4)
17144       {
17145         for (j=0; j<body[c].ns; j++)
17146         {
17147           l=body[c].s[j];
17148 
17149           /* if surf[l].etyp is defined then a connection of a mid-face node and the edges has to be prepared (mpc) */
17150           if(((surf[l].etyp==7)||(surf[l].etyp==8))&&(body[c].etyp==4))
17151   	  {
17152             /* generate a set with all nodes and related volume elements of the surface */
17153             ntmp=pre_seta("-ntmp","s",surf[l].name) ;
17154             etmp=pre_seta("-etmp","i",0) ;
17155             for(k=0; k<set[ntmp].anz_n; k++)  seta(etmp,"n",set[ntmp].node[k]);
17156             completeSet("-etmp","up");
17157             eSet=pre_seta("-eSet","i",0) ;
17158             for(k=0; k<set[etmp].anz_e; k++) if(e_enqire[set[etmp].elem[k]].type == 4) seta(eSet,"e",set[etmp].elem[k]);
17159   	    completeSet("-eSet","do");
17160             completeSet("-ntmp","do");
17161 
17162             /* create dep and indepsets */
17163             if ( (depSet = (int *)realloc( depSet, (sum_equSets+1) * sizeof(int))) == NULL )
17164               printf("ERROR: realloc failed: meshSet\n\n" );
17165             if ( (indSet = (int *)realloc( indSet, (sum_equSets+1) * sizeof(int))) == NULL )
17166               printf("ERROR: realloc failed: meshSet\n\n" );
17167             sprintf(buffer,"-depSet_tmp%d", sum_equSets);
17168             depSet[sum_equSets]=pre_seta(buffer,"i",0) ;
17169             for(k=0; k<set[ntmp].anz_n; k++)  seta(depSet[sum_equSets],"n",set[ntmp].node[k]);
17170             for(k=0; k<set[eSet].anz_n; k++)  setr(depSet[sum_equSets],"n",set[eSet].node[k]);
17171             sprintf(buffer,"-indSet_tmp%d", sum_equSets);
17172             indSet[sum_equSets]=pre_seta(buffer,"i",0) ;
17173             for(k=0; k<set[ntmp].anz_n; k++)  seta(indSet[sum_equSets],"n",set[ntmp].node[k]);
17174             for(k=0; k<set[depSet[sum_equSets]].anz_n; k++)  setr(indSet[sum_equSets],"n",set[depSet[sum_equSets]].node[k]);
17175             for(k=0; k<set[eSet].anz_e; k++)  seta(indSet[sum_equSets],"e",set[eSet].elem[k]);
17176             sum_equSets++;
17177 
17178             /* delete the temporary sets */
17179             delSet(set[ntmp].name);
17180             delSet(set[etmp].name);
17181             delSet(set[eSet].name);
17182  	  }
17183         }
17184       }
17185     }
17186 
17187     /* tet-mesh */
17188     etmp=0;
17189     tetSet=-1;
17190     for (i=0; i<set[se].anz_b; i++)
17191     {
17192       c= set[se].body[i];
17193       if((body[c].etyp==3)||(body[c].etyp==6))
17194       {
17195         if(tetSet==-1)
17196 	{
17197           delSet( "+tetSet" );
17198           tetSet=pre_seta("+tetSet","i",0);
17199 	}
17200 
17201         /* the final orientation of nurbs-surfaces for the 2D-mesh requires a call to orientBody() */
17202         orientBody(c);
17203 
17204         /* get the surface-elements for later deletion */
17205         for(j=0; j<body[c].ns; j++)
17206 	{
17207           s=body[c].s[j];
17208           for(k=0; k<surf[s].ne; k++) seta(tetSet,"e",surf[s].elem[k]);
17209 	}
17210 
17211 	printf("\n Tet-mesh body:%s\n\n", body[c].name);
17212         if(body[c].eparm!=(char *)NULL) etmp=generateTetFromBody(c, (double)atof(body[c].eparm), body[c].eattr, meshp.tetmesher);
17213         else etmp=generateTetFromBody(c, (double)1.e6, body[c].eattr, meshp.tetmesher);
17214         adjustDrawNodes(1);
17215 
17216         if(etmp>0)
17217 	{
17218 	  printf("\n %d Tet-elems in body:%s\n\n", body[c].ne, body[c].name);
17219 
17220           /* add the inner nodes and elements to the sets */
17221           for(j=0; j<anz->sets; j++)
17222           {
17223             if((set[j].name!=(char *)NULL)&&(set[j].name[0]!='-')&&( getIndex(&set[j].body,set[j].anz_b, c) >-1))
17224   	    {
17225               for(n=0; n<body[c].nn; n++) seta(j,"n", body[c].nod[n]);
17226               for(n=0; n<body[c].ne; n++) seta(j,"e", body[c].elem[n]);
17227   	    }
17228           }
17229 	}
17230         else
17231 	{
17232           printf(" ERROR: No tet-mesh could be created for body:%s\n ", body[c].name);
17233           printf(" The temporary surface mesh is not deleted and can be used for debugging.\n");
17234           printf(" The files nodnr_ng_cgx.out elemnr_ng_cgx.out provide the link between ng and cgx entity numbers.\n");
17235           break;
17236 	}
17237       }
17238     }
17239   scipMesh:;
17240     /* delete the surface-elements which were used to create tets */
17241     if(etmp>0) zap( "+tetSet" );
17242   }
17243 
17244   /* in case that datasets had already existed then this fields have to be extended */
17245   if (anz->l > 0)
17246   {
17247     for (l=0; l< anz->l; l++)
17248     {
17249       if (!lcase[l].loaded)
17250       {
17251         if( pre_readfrdblock(copiedNodeSets , l, anz, node, lcase )==-1)
17252         {
17253           printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", l+1);
17254           return(-1);
17255         }
17256         calcDatasets( l, anz, node, lcase );
17257         recompileEntitiesInMenu(l);
17258       }
17259       for (i=0; i<lcase[l].ncomps; i++)
17260       {
17261         if ( (lcase[l].dat[i] = (float *)realloc( lcase[l].dat[i], (anz->nmax+2) * sizeof(float))) == NULL )
17262           printf("\n\n ERROR: realloc failure\n\n" );
17263         for(j=anz_nmax+1; j<=anz->nmax; j++) lcase[l].dat[i][j]=0.;
17264       }
17265     }
17266   }
17267   //anz->olc       = anz->l;
17268 
17269   if (calcBadElements("all")>0)
17270   {
17271     printf(" try to fix bad elements\n");
17272     fixMidsideNodes( specialset->njby, "lin");
17273     printf(" calcBadElements\n");
17274     calcBadElements("all");
17275   }
17276 
17277   printf(" makeSurfaces\n");
17278   makeSurfaces();
17279   printf(" getElemNormalen\n");
17280   getElemNormalen( e_enqire, node, anz->e );
17281   printf(" realloc_colNr\n");
17282   realloc_colNr();
17283 
17284   printf(" add the faces\n");
17285   /* add the faces */
17286   for (sets=0; sets<anz->sets; sets++)
17287   {
17288     if ((set[sets].type==0)&&(set[sets].name!=(char *)NULL))
17289     {
17290       //set[sets].anz_f=0;
17291       completeSet( set[sets].name, "f" );
17292     }
17293   }
17294 
17295   printf(" updateDispLists\n");
17296   updateDispLists();
17297 
17298   /* clear special set  */
17299   printf(" delSet\n");
17300   delSet(specialset->mesh );
17301   printf (" ready\n");
17302   return(setNr);
17303 }
17304 
17305 
17306 
completeSet_Faces(int setNr,int setNrbuf,int * fUsed,int flag)17307 int completeSet_Faces( int setNr, int setNrbuf, int *fUsed, int flag)
17308 {
17309   int i,j;
17310   int m, n, ipuf=0 ;
17311 
17312   if(!flag)
17313   {
17314    if (set[setNr].anz_n>0)
17315    {
17316     /* suche abhaengige faces */
17317     m=set[setNrbuf].anz_f;
17318     for ( i=0; i<anz->f; i++)
17319     {
17320       switch(face[i].type)
17321       {
17322         case 7:
17323           ipuf = 3;  /* TRI3  */
17324         break;
17325         case 8:
17326           //ipuf = 6;  /* TRI6  */
17327           ipuf = 3;  /* TRI6  */
17328         break;
17329         case 9:
17330           ipuf = 4;  /* QUAD4 */
17331         break;
17332         case 10:
17333           //ipuf = 8; /* QUAD8 */
17334           ipuf = 4; /* QUAD8 */
17335         break;
17336         case 11:
17337           ipuf = 2; /* BEAM */
17338         break;
17339         case 12:
17340           //ipuf = 3; /* BEAM3 */
17341           ipuf = 2; /* BEAM3 */
17342         break;
17343       }
17344       for (j=0; j<ipuf; j++)
17345       {
17346         if(ifind(&set[setNr].node, set[setNr].anz_n, face[i].nod[j])>-1)
17347         {
17348           //printf("n:%d f:%d used:%d\n", face[i].nod[j], face[i].nr, fUsed[i]);
17349           if( !fUsed[i] )
17350           {
17351             if ( (set[setNrbuf].face = (int *)realloc((int *)set[setNrbuf].face, (set[setNrbuf].anz_f+1) * sizeof(int))) == NULL )
17352               printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNrbuf].name);
17353             set[setNrbuf].face[set[setNrbuf].anz_f]= i;
17354             set[setNrbuf].anz_f++;
17355           }
17356           break;
17357         }
17358       }
17359     }
17360     if(set[setNrbuf].anz_f-m)
17361     {
17362       qsort( set[setNrbuf].face, set[setNrbuf].anz_f, sizeof(int), (void *)compareInt );
17363       /* erase multiple entities */
17364       n=0;
17365       for(i=1; i<set[setNrbuf].anz_f; i++)
17366       {
17367 	if(set[setNrbuf].face[n]!=set[setNrbuf].face[i]) set[setNrbuf].face[++n]=set[setNrbuf].face[i];
17368       }
17369       set[setNrbuf].anz_f=n+1;
17370     }
17371 
17372    }
17373   }
17374   else
17375   {
17376     /* circle through all faces and add all nodes */
17377     m=set[setNr].anz_n;
17378     for (n=0; n<set[setNr].anz_f; n++)
17379     {
17380       i=set[setNr].face[n];
17381       switch(face[i].type)
17382       {
17383         case 7:
17384           ipuf = 3;  /* TRI3  */
17385         break;
17386         case 8:
17387           ipuf = 6;  /* TRI6  */
17388         break;
17389         case 9:
17390           ipuf = 4;  /* QUAD4 */
17391         break;
17392         case 10:
17393           ipuf = 8; /* QUAD8 */
17394         break;
17395         case 11:
17396           ipuf = 2; /* BEAM */
17397         break;
17398         case 12:
17399           ipuf = 3; /* BEAM3 */
17400         break;
17401       }
17402       for (j=0; j<ipuf; j++)
17403       {
17404           if ( (set[setNr].node = (int *)realloc((int *)set[setNr].node, (set[setNr].anz_n+1) * sizeof(int))) == NULL )
17405             printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
17406           set[setNr].node[set[setNr].anz_n]= face[i].nod[j];
17407           set[setNr].anz_n++;
17408           //printf("n:%d f:%d used:%d\n", face[i].nod[j], i, fUsed[i]);
17409       }
17410     }
17411     if(set[setNr].anz_n-m)
17412     {
17413       qsort( set[setNr].node, set[setNr].anz_n, sizeof(int), (void *)compareInt );
17414       /* erase multiple entities */
17415       n=0;
17416       for(i=1; i<set[setNr].anz_n; i++)
17417       {
17418 	if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[++n]=set[setNr].node[i];
17419 	//if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[n++]=set[setNr].node[i];
17420       }
17421       set[setNr].anz_n=n+1;
17422       //set[setNr].anz_n=n;
17423     }
17424   }
17425   return(1);
17426 }
17427 
17428 
17429 
completeSet_Mesh(int setNr,int setNrbuf,int * elUsed,int flag)17430 int completeSet_Mesh( int setNr, int setNrbuf, int *elUsed, int flag)
17431 {
17432   int i,j;
17433   int m, n, ipuf=0 ;
17434 
17435   if(!flag)
17436   {
17437    if (set[setNr].anz_n>0)
17438    {
17439     /* suche abhaengige elemente */
17440     m=set[setNrbuf].anz_e;
17441     for ( i=0; i<anz->e; i++)
17442     {
17443       switch(e_enqire[e_enqire[i].nr].type)
17444       {
17445         case 1:
17446           ipuf = 8;       /* HEXA8 */
17447         break;
17448         case 2:
17449           ipuf = 6;  /* PENTA6 */
17450         break;
17451         case 3:
17452           ipuf = 4;  /* TET4 */
17453         break;
17454         case 4:
17455           //ipuf = 20; /* HEXA20 */
17456           ipuf = 8; /* HEXA20 */
17457         break;
17458         case 5:
17459           ipuf = 15; /* PENTA15 */
17460         break;
17461         case 6:
17462           //ipuf = 10; /* TET10 */
17463           ipuf = 4; /* TET10 */
17464         break;
17465         case 7:
17466           ipuf = 3;  /* TRI3  */
17467         break;
17468         case 8:
17469 	  // ipuf = 6;  /* TRI6  */
17470           ipuf = 3;  /* TRI6  */
17471         break;
17472         case 9:
17473           ipuf = 4;  /* QUAD4 */
17474         break;
17475         case 10:
17476           //ipuf = 8; /* QUAD8 */
17477           ipuf = 4; /* QUAD8 */
17478         break;
17479         case 11:
17480           ipuf = 2; /* BEAM */
17481         break;
17482         case 12:
17483           //ipuf = 3; /* BEAM3 */
17484           ipuf = 2; /* BEAM3 */
17485         break;
17486       }
17487       for (j=0; j<ipuf; j++)
17488       {
17489         if(ifind(&set[setNr].node, set[setNr].anz_n, e_enqire[e_enqire[i].nr].nod[j])>-1)
17490         {
17491           //printf("    e:%d \n", e_enqire[i].nr);
17492           if( !elUsed[e_enqire[i].nr] )
17493           {
17494             //printf("add e:%d \n", e_enqire[i].nr);
17495             //seta( setNrbuf, "e", e_enqire[i].nr );
17496             if ( (set[setNrbuf].elem = (int *)realloc((int *)set[setNrbuf].elem, (set[setNrbuf].anz_e+1) * sizeof(int))) == NULL )
17497               printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNrbuf].name);
17498             set[setNrbuf].elem[set[setNrbuf].anz_e]= e_enqire[i].nr;
17499             set[setNrbuf].anz_e++;
17500           }
17501           break;
17502         }
17503       }
17504     }
17505     if(set[setNrbuf].anz_e-m)
17506     {
17507       qsort( set[setNrbuf].elem, set[setNrbuf].anz_e, sizeof(int), (void *)compareInt );
17508       /* erase multiple entities */
17509       n=0;
17510       for(i=1; i<set[setNrbuf].anz_e; i++)
17511       {
17512 	if(set[setNrbuf].elem[n]!=set[setNrbuf].elem[i]) set[setNrbuf].elem[++n]=set[setNrbuf].elem[i];
17513       }
17514       set[setNrbuf].anz_e=n+1;
17515     }
17516 
17517    }
17518   }
17519   else
17520   {
17521     /* circle through all elements and add all nodes */
17522     m=set[setNr].anz_n;
17523     for (i=0; i<set[setNr].anz_e; i++)
17524     {
17525       switch(e_enqire[set[setNr].elem[i]].type)
17526       {
17527         case 1:
17528           ipuf = 8;       /* HEXA8 */
17529         break;
17530         case 2:
17531           ipuf = 6;  /* PENTA6 */
17532         break;
17533         case 3:
17534           ipuf = 4;  /* TET4 */
17535         break;
17536         case 4:
17537           ipuf = 20; /* HEXA20 */
17538         break;
17539         case 5:
17540           ipuf = 15; /* PENTA15 */
17541         break;
17542         case 6:
17543           ipuf = 10; /* TET10 */
17544         break;
17545         case 7:
17546           ipuf = 3;  /* TRI3  */
17547         break;
17548         case 8:
17549           ipuf = 6;  /* TRI6  */
17550         break;
17551         case 9:
17552           ipuf = 4;  /* QUAD4 */
17553         break;
17554         case 10:
17555           ipuf = 8; /* QUAD8 */
17556         break;
17557         case 11:
17558           ipuf = 2; /* BEAM */
17559         break;
17560         case 12:
17561           ipuf = 3; /* BEAM3 */
17562         break;
17563       }
17564       for (j=0; j<ipuf; j++)
17565       {
17566 	  //seta( setNr, "n", e_enqire[set[setNr].elem[i]].nod[j] );
17567           if ( (set[setNr].node = (int *)realloc((int *)set[setNr].node, (set[setNr].anz_n+1) * sizeof(int))) == NULL )
17568             printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
17569           set[setNr].node[set[setNr].anz_n]= e_enqire[set[setNr].elem[i]].nod[j];
17570           set[setNr].anz_n++;
17571       }
17572     }
17573     if(set[setNr].anz_n-m)
17574     {
17575       qsort( set[setNr].node, set[setNr].anz_n, sizeof(int), (void *)compareInt );
17576       /* erase multiple entities */
17577       n=0;
17578       for(i=1; i<set[setNr].anz_n; i++)
17579       {
17580 	if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[++n]=set[setNr].node[i];
17581 	//if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[n++]=set[setNr].node[i];
17582       }
17583       set[setNr].anz_n=n+1;
17584       //set[setNr].anz_n=n;
17585     }
17586   }
17587   return(1);
17588 }
17589 
17590 
17591 
completeSet_Lines(int setNr,int setNrbuf,int * elUsed,int flag)17592 int completeSet_Lines( int setNr, int setNrbuf, int *elUsed, int flag )
17593 {
17594   int i,j;
17595 
17596 
17597   if(!flag) /* up  */
17598   {
17599     if (set[setNr].anz_p>0)
17600     {
17601       /* suche abhaengige linien */
17602       for ( i=0; i<set[setNr].anz_p; i++)
17603       {
17604 	//    printf("pnt:%s\n", point[set[setNr].pnt[i]].name);
17605         for (j=0; j<anzGeo->l; j++)
17606         {
17607 	  //printf("check line:%s %d  p:%d %d %d\n", line[j].name, elUsed[j], set[setNr].pnt[i], line[j].p1, line[j].p2);
17608           if( elUsed[j] ) continue;
17609 
17610           if( line[j].name != (char *)NULL )
17611           if(( set[setNr].pnt[i] == line[j].p1 )||( set[setNr].pnt[i] == line[j].p2 ))
17612           {
17613 	    //printf("line:%s added\n", line[j].name);
17614             seta( setNrbuf, "l", j );
17615           }
17616         }
17617       }
17618     }
17619   }
17620   else /* down */
17621   {
17622     /* cyrcle through all lines and add all points, trks */
17623     for (i=0; i<set[setNr].anz_l; i++)
17624     {
17625       j= set[setNr].line[i];
17626       seta( setNr, "p", line[j].p1 );
17627       seta( setNr, "p", line[j].p2 );
17628     }
17629   }
17630   return(1);
17631 }
17632 
17633 
17634 
completeSet_frame(int setNr,char type)17635 int completeSet_frame( int setNr, char type )
17636 {
17637   int i,j, m, n, p, l, c, s;
17638 
17639     /* cyrcle through all sets and add all entities */
17640     for (i=0; i<set[setNr].anz_se; i++)
17641     {
17642       s= set[setNr].set[i];
17643       if((!type)||(type=='n'))
17644       for (j=0; j<set[s].anz_n; j++)
17645       {
17646         p=set[s].node[j];
17647         seta( setNr, "n", p );
17648       }
17649       if((!type)||(type=='f'))
17650       for (j=0; j<set[s].anz_f; j++)
17651       {
17652         p=set[s].face[j];
17653         seta( setNr, "f", p );
17654       }
17655       if((!type)||(type=='e'))
17656       for (j=0; j<set[s].anz_e; j++)
17657       {
17658         p=set[s].elem[j];
17659         seta( setNr, "e", p );
17660       }
17661       if((!type)||(type=='p'))
17662       for (j=0; j<set[s].anz_p; j++)
17663       {
17664         p=set[s].pnt[j];
17665         seta( setNr, "p", p );
17666       }
17667       if((!type)||(type=='l'))
17668       for (j=0; j<set[s].anz_l; j++)
17669       {
17670         p=set[s].line[j];
17671         seta( setNr, "l", p );
17672       }
17673       if((!type)||(type=='c'))
17674       for (j=0; j<set[s].anz_c; j++)
17675       {
17676         p=set[s].lcmb[j];
17677         seta( setNr, "c", p );
17678       }
17679       if((!type)||(type=='s'))
17680       for (j=0; j<set[s].anz_s; j++)
17681       {
17682         p=set[s].surf[j];
17683         seta( setNr, "s", p );
17684       }
17685       if((!type)||(type=='b'))
17686       for (j=0; j<set[s].anz_b; j++)
17687       {
17688         p=set[s].body[j];
17689         seta( setNr, "b", p );
17690       }
17691     }
17692 
17693     /* remove the appended sets */
17694     while(set[setNr].anz_se>0)
17695     {
17696       s= set[setNr].set[0];
17697       setr( setNr, "r", s);
17698     }
17699 
17700 
17701     /* cyrcle through all faces and add just the first 2 nodes */
17702     m=set[setNr].anz_n;
17703     for (i=0; i<set[setNr].anz_f; i++)
17704     {
17705         if ( (set[setNr].node = (int *)realloc((int *)set[setNr].node, (set[setNr].anz_n+2) * sizeof(int))) == NULL )
17706           printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
17707         set[setNr].node[set[setNr].anz_n]= face[set[setNr].face[i]].nod[0];
17708         set[setNr].anz_n++;
17709         set[setNr].node[set[setNr].anz_n]= face[set[setNr].face[i]].nod[1];
17710         set[setNr].anz_n++;
17711     }
17712     if(set[setNr].anz_n-m)
17713     {
17714       qsort( set[setNr].node, set[setNr].anz_n, sizeof(int), (void *)compareInt );
17715       /* erase multiple entities */
17716       n=0;
17717       for(i=1; i<set[setNr].anz_n; i++)
17718       {
17719 	if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[++n]=set[setNr].node[i];
17720       }
17721       set[setNr].anz_n=n+1;
17722     }
17723     /* circle through all elements and add the first 2 nodes */
17724     m=set[setNr].anz_n;
17725     for (i=0; i<set[setNr].anz_e; i++)
17726     {
17727           if ( (set[setNr].node = (int *)realloc((int *)set[setNr].node, (set[setNr].anz_n+2) * sizeof(int))) == NULL )
17728             printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
17729           set[setNr].node[set[setNr].anz_n]= e_enqire[set[setNr].elem[i]].nod[0];
17730           set[setNr].anz_n++;
17731           set[setNr].node[set[setNr].anz_n]= e_enqire[set[setNr].elem[i]].nod[1];
17732           set[setNr].anz_n++;
17733     }
17734     if(set[setNr].anz_n-m)
17735     {
17736       qsort( set[setNr].node, set[setNr].anz_n, sizeof(int), (void *)compareInt );
17737       /* erase multiple entities */
17738       n=0;
17739       for(i=1; i<set[setNr].anz_n; i++)
17740       {
17741 	if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[++n]=set[setNr].node[i];
17742       }
17743       set[setNr].anz_n=n+1;
17744     }
17745 
17746     /* cyrcle through all bodys and add all surfs */
17747     for (i=0; i<set[setNr].anz_b; i++)
17748     {
17749       c= set[setNr].body[i];
17750       for (j=0; j<body[c].ns; j++)
17751       {
17752         l=body[c].s[j];
17753         seta( setNr, "s", l );
17754       }
17755     }
17756     /* cyrcle through all surfs and add all lines, lcmbs */
17757     for (i=0; i<set[setNr].anz_s; i++)
17758     {
17759       s= set[setNr].surf[i];
17760       for (j=0; j<surf[s].nl; j++)
17761       {
17762         l=surf[s].l[j];
17763         if (surf[s].typ[j]=='l')
17764         {
17765           seta( setNr, "l", l );
17766         }
17767         else
17768         {
17769           seta( setNr, "c", l );
17770         }
17771       }
17772     }
17773     /* cyrcle through all lcmbs and add all lines */
17774     for (i=0; i<set[setNr].anz_c; i++)
17775     {
17776       c= set[setNr].lcmb[i];
17777       for (j=0; j<lcmb[c].nl; j++)
17778       {
17779         l=lcmb[c].l[j];
17780         seta( setNr, "l", l );
17781       }
17782     }
17783     /* cyrcle through all lines and add all points */
17784     for (i=0; i<set[setNr].anz_l; i++)
17785     {
17786       l= set[setNr].line[i];
17787       seta( setNr, "p", line[l].p1 );
17788       seta( setNr, "p", line[l].p2 );
17789       if (line[l].typ=='a') seta( setNr, "p", line[l].trk );
17790     }
17791   return(setNr);
17792 }
17793 
17794 
17795 
completeSet(char * setname,char * type)17796 int completeSet( char *setname, char *type )
17797 {
17798   int i,j,k, m, n, p, l, c, s;
17799   int       setNr, ipuf;
17800   int       *nbody=NULL, *nsurf=NULL, *nline=NULL, *npoint=NULL ;
17801 
17802   operateAlias( setname, "se" );
17803   setNr=getSetNr(setname);
17804   if (setNr<0)
17805   {
17806     printf (" ERROR in completeSet: set:%s does not exist\n", setname);
17807     return(-1);
17808   }
17809 
17810   if (toupper(type[0])=='U') /* up  */
17811   {
17812     if (set[setNr].anz_n>0)
17813     {
17814       /* suche abhaengige elemente */
17815       m=set[setNr].anz_e;
17816       for ( i=0; i<anz->e; i++)
17817       {
17818         ipuf=0;
17819         if (e_enqire[e_enqire[i].nr].type == 1) ipuf = 8;       /* HEXA8 */
17820         else if (e_enqire[e_enqire[i].nr].type == 2) ipuf = 6;  /* PENTA6 */
17821         else if (e_enqire[e_enqire[i].nr].type == 3) ipuf = 4;  /* TET4 */
17822         else if (e_enqire[e_enqire[i].nr].type == 4) ipuf = 20; /* HEXA20 */
17823         else if (e_enqire[e_enqire[i].nr].type == 5) ipuf = 15; /* PENTA15 */
17824         else if (e_enqire[e_enqire[i].nr].type == 6) ipuf = 10; /* TET10 */
17825         else if (e_enqire[e_enqire[i].nr].type == 7) ipuf = 3;  /* TRI3  */
17826         else if (e_enqire[e_enqire[i].nr].type == 8) ipuf = 6;  /* TRI6  */
17827         else if (e_enqire[e_enqire[i].nr].type == 9) ipuf = 4;  /* QUAD4 */
17828         else if (e_enqire[e_enqire[i].nr].type == 10) ipuf = 8; /* QUAD8 */
17829         else if (e_enqire[e_enqire[i].nr].type == 11) ipuf = 2; /* BEAM */
17830         else if (e_enqire[e_enqire[i].nr].type == 12) ipuf = 3; /* BEAM3 */
17831         if (ipuf!=0)
17832         {
17833           for (j=0; j<ipuf; j++)
17834           {
17835             if(ifind(&set[setNr].node, set[setNr].anz_n, e_enqire[e_enqire[i].nr].nod[j])>-1)
17836             {
17837 	      // seta( setNr, "e", e_enqire[i].nr );
17838               if ( (set[setNr].elem = (int *)realloc((int *)set[setNr].elem, (set[setNr].anz_e+1) * sizeof(int))) == NULL )
17839                 printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
17840               set[setNr].elem[set[setNr].anz_e]= e_enqire[i].nr;
17841               set[setNr].anz_e++;
17842               break;
17843             }
17844           }
17845         }
17846       }
17847       if(set[setNr].anz_e-m)
17848       {
17849         qsort( set[setNr].elem, set[setNr].anz_e, sizeof(int), (void *)compareInt );
17850         /* erase multiple entities */
17851         n=0;
17852         for(i=1; i<set[setNr].anz_e; i++)
17853         {
17854 	  if(set[setNr].elem[n]!=set[setNr].elem[i]) set[setNr].elem[++n]=set[setNr].elem[i];
17855         }
17856         set[setNr].anz_e=n+1;
17857       }
17858     }
17859     if (set[setNr].anz_f>0)
17860     {
17861       /* suche abhaengige elemente */
17862       m=set[setNr].anz_e;
17863       for ( i=0; i<set[setNr].anz_f; i++)
17864       {
17865 	// seta( setNr, "e", face[set[setNr].face[i]].elem_nr );
17866         if ( (set[setNr].elem = (int *)realloc((int *)set[setNr].elem, (set[setNr].anz_e+1) * sizeof(int))) == NULL )
17867           printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
17868         set[setNr].elem[set[setNr].anz_e]= face[set[setNr].face[i]].elem_nr;
17869         set[setNr].anz_e++;
17870       }
17871       if(set[setNr].anz_e-m)
17872       {
17873         qsort( set[setNr].elem, set[setNr].anz_e, sizeof(int), (void *)compareInt );
17874         /* erase multiple entities */
17875         n=0;
17876         for(i=1; i<set[setNr].anz_e; i++)
17877         {
17878 	  if(set[setNr].elem[n]!=set[setNr].elem[i]) set[setNr].elem[++n]=set[setNr].elem[i];
17879         }
17880         set[setNr].anz_e=n+1;
17881       }
17882     }
17883     if (set[setNr].anz_p>0)
17884     {
17885       /* suche abhaengige linien */
17886       for ( i=0; i<set[setNr].anz_p; i++)
17887       {
17888         for (j=0; j<anzGeo->l; j++)
17889         {
17890           if( line[j].name != (char *)NULL )
17891           if(( set[setNr].pnt[i] == line[j].p1 )||( set[setNr].pnt[i] == line[j].p2 ))
17892           {
17893             seta( setNr, "l", j );
17894           }
17895         }
17896       }
17897       /* suche abhaengige shapes */
17898       for ( i=0; i<set[setNr].anz_p; i++)
17899       {
17900         for (j=0; j<anzGeo->sh; j++)
17901         {
17902           if(( shape[j].name != (char *)NULL )&&( shape[j].type!=4))
17903           {
17904             /* 0:plane, 1:cyl, 2: cone, 3:sph, 4:nurbs, 5:tor */
17905             /* 0:3p, 1:3p, 2:4p 3:7p 4:p[0]=nurbsindx 5:4p*/
17906 
17907             if(shape[j].type<2) l=3;
17908             else if(shape[j].type==2) l=4;
17909             else if(shape[j].type==3) l=7;
17910             else if(shape[j].type==5) l=4;
17911             else continue;
17912             for(k=0; k<l; k++)
17913 	    {
17914               if ( set[setNr].pnt[i] == shape[j].p[k] )
17915               {
17916                 seta( setNr, "sh", j);
17917               }
17918 	    }
17919           }
17920         }
17921       }
17922       /* suche abhaengige nurl */
17923       for ( i=0; i<set[setNr].anz_p; i++)
17924       {
17925         for (j=0; j<anzGeo->nurl; j++)
17926         {
17927           if( nurbl[j].name != (char *)NULL )
17928           {
17929             for(k=0; k<nurbl[j].u_npnt; k++)
17930 	    {
17931               if ( set[setNr].pnt[i] == nurbl[j].ctlpnt[k] )
17932               {
17933                 seta( setNr, "L", j);
17934               }
17935 	    }
17936           }
17937         }
17938       }
17939       /* suche abhaengige nurs */
17940       for ( i=0; i<set[setNr].anz_p; i++)
17941       {
17942         for (j=0; j<anzGeo->nurs; j++)
17943         {
17944           if( nurbs[j].name != (char *)NULL )
17945           {
17946             for(k=0; k<nurbs[j].u_npnt; k++)
17947 	    {
17948               for(l=0; l<nurbs[j].v_npnt; l++)
17949 	      {
17950                 if ( set[setNr].pnt[i] == nurbs[j].ctlpnt[k][l] )
17951                 {
17952                   seta( setNr, "S", j);
17953 		}
17954               }
17955 	    }
17956           }
17957         }
17958       }
17959     }
17960     if (set[setNr].anz_l>0)
17961     {
17962       /* suche abhaengige lcmbs */
17963       for ( i=0; i<set[setNr].anz_l; i++)
17964       {
17965         for (j=0; j<anzGeo->c; j++)
17966         {
17967           if( lcmb[j].name != (char *)NULL )
17968           for (n=0; n<lcmb[j].nl; n++)
17969           {
17970             if( set[setNr].line[i] == lcmb[j].l[n] )
17971             {
17972               seta( setNr, "c", j );
17973             }
17974           }
17975         }
17976       }
17977       /* suche abhaengige surfs */
17978       for ( i=0; i<set[setNr].anz_l; i++)
17979       {
17980         for (j=0; j<anzGeo->s; j++)
17981         {
17982           if( surf[j].name != (char *)NULL )
17983           for (n=0; n<surf[j].nl; n++)
17984           {
17985             if(( set[setNr].line[i] == surf[j].l[n] )&&( surf[j].typ[n] == 'l' ))
17986             {
17987               seta( setNr, "s", j);
17988             }
17989           }
17990         }
17991       }
17992     }
17993     if (set[setNr].anz_c>0)
17994     {
17995       /* suche abhaengige surfaces */
17996       for ( i=0; i<set[setNr].anz_c; i++)
17997       {
17998         for (j=0; j<anzGeo->s; j++)
17999         {
18000           if( surf[j].name != (char *)NULL )
18001           for (n=0; n<surf[j].nl; n++)
18002           {
18003             if(( set[setNr].lcmb[i] == surf[j].l[n] )&&( surf[j].typ[n] == 'c' ))
18004             {
18005               seta( setNr, "s", j );
18006             }
18007           }
18008         }
18009       }
18010     }
18011     if (set[setNr].anz_s>0)
18012     {
18013       /* suche abhaengige bodys */
18014       for ( i=0; i<set[setNr].anz_s; i++)
18015       {
18016         for (j=0; j<anzGeo->b; j++)
18017         {
18018           if( body[j].name != (char *)NULL )
18019           for (n=0; n<body[j].ns; n++)
18020           {
18021             if ( set[setNr].surf[i] == body[j].s[n] )
18022             {
18023               seta( setNr, "b", j);
18024             }
18025           }
18026         }
18027       }
18028     }
18029     if (set[setNr].anz_nurs>0)
18030     {
18031       /* suche abhaengige shapes */
18032       for ( i=0; i<set[setNr].anz_nurs; i++)
18033       {
18034         for (j=0; j<anzGeo->sh; j++)
18035         {
18036           if(( shape[j].name != (char *)NULL )||( shape[j].type==4))
18037           {
18038             if ( set[setNr].nurs[i] == shape[j].p[0] )
18039             {
18040               seta( setNr, "sh", j);
18041             }
18042           }
18043         }
18044       }
18045     }
18046     if (set[setNr].anz_sh>0)
18047     {
18048       /* suche abhaengige surfaces */
18049       for ( i=0; i<set[setNr].anz_sh; i++)
18050       {
18051         for (j=0; j<anzGeo->s; j++)
18052         {
18053           if( surf[j].name != (char *)NULL )
18054           {
18055             if ( set[setNr].shp[i] == surf[j].sh )
18056             {
18057               seta( setNr, "s", j);
18058             }
18059           }
18060         }
18061       }
18062     }
18063   }
18064 
18065   else if (toupper(type[0])=='D') /* down */
18066   {
18067     /* get the faces */
18068     completeSet( set[setNr].name, "f" );
18069 
18070     /* cyrcle through all nodes and add all geometric entities */
18071     if(set[setNr].anz_n)
18072     {
18073       /* mark the related geometry */
18074       if( (nbody=(int *)malloc( (anz->nmax+1)*sizeof(int) ) )==NULL)
18075       { printf(" ERROR: malloc failure\n"); goto mfail_comp; }
18076       if( (nsurf=(int *)malloc( (anz->nmax+1)*sizeof(int) ) )==NULL)
18077       { printf(" ERROR: malloc failure\n"); goto mfail_comp; }
18078       if( (nline=(int *)malloc( (anz->nmax+1)*sizeof(int) ) )==NULL)
18079       { printf(" ERROR: malloc failure\n"); goto mfail_comp; }
18080       if( (npoint=(int *)malloc( (anz->nmax+1)*sizeof(int) ) )==NULL)
18081       { printf(" ERROR: malloc failure\n"); goto mfail_comp; }
18082       for (i=0; i<=anz->nmax; i++)
18083       {
18084         nbody[i]=nsurf[i]=nline[i]=npoint[i]=-1;
18085       }
18086 
18087       for (i=0; i<anzGeo->b; i++)
18088       {
18089         for (j=0; j<body[i].nn; j++){ nbody[body[i].nod[j]]=i; }
18090       }
18091       for (i=0; i<anzGeo->s; i++)
18092       {
18093         for (j=0; j<surf[i].nn; j++){ nsurf[surf[i].nod[j]]=i; }
18094       }
18095       for (i=0; i<anzGeo->l; i++)
18096       {
18097         for (j=0; j<line[i].nn; j++){ nline[line[i].nod[j]]=i; }
18098       }
18099       for (i=0; i<anzGeo->p; i++)
18100       {
18101         for (j=0; j<point[i].nn; j++){ npoint[point[i].nod[j]]=i; }
18102       }
18103       for (i=0; i<set[setNr].anz_n; i++)
18104       {
18105         /* check if the node is relevant */
18106         if(nbody[set[setNr].node[i]]>-1) seta( setNr, "b", nbody[set[setNr].node[i]]);
18107         if(nsurf[set[setNr].node[i]]>-1) seta( setNr, "s", nsurf[set[setNr].node[i]]);
18108         if(nline[set[setNr].node[i]]>-1) seta( setNr, "l", nline[set[setNr].node[i]]);
18109         if(npoint[set[setNr].node[i]]>-1) seta( setNr, "p", npoint[set[setNr].node[i]]);
18110       }
18111 
18112       mfail_comp:;
18113       free(nbody);
18114       free(nsurf);
18115       free(nline);
18116       free(npoint);
18117     }
18118 
18119     /* cyrcle through all faces and add all nodes */
18120     /* nodes have to be completed before because otherwhise all geometry with their nodes would be included */
18121     m=set[setNr].anz_n;
18122     for (i=0; i<set[setNr].anz_f; i++)
18123     {
18124       if (face[set[setNr].face[i]].type == 7) n = 3;  /* TRI3  */
18125       else if (face[set[setNr].face[i]].type == 8) n = 6;  /* TRI6  */
18126       else if (face[set[setNr].face[i]].type == 9) n = 4;  /* QUAD4 */
18127       else if (face[set[setNr].face[i]].type == 10) n = 8; /* QUAD8 */
18128       else if (face[set[setNr].face[i]].type == 11) n = 2; /* BEAM2 */
18129       else if (face[set[setNr].face[i]].type == 12) n = 3; /* BEAM3 */
18130       else n=0;
18131       for (j=0; j<n; j++)
18132       {
18133         // seta( setNr, "n", face[set[setNr].face[i]].nod[j] );
18134         if ( (set[setNr].node = (int *)realloc((int *)set[setNr].node, (set[setNr].anz_n+1) * sizeof(int))) == NULL )
18135           printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
18136         set[setNr].node[set[setNr].anz_n]= face[set[setNr].face[i]].nod[j];
18137         set[setNr].anz_n++;
18138       }
18139     }
18140     if(set[setNr].anz_n-m)
18141     {
18142       qsort( set[setNr].node, set[setNr].anz_n, sizeof(int), (void *)compareInt );
18143       /* erase multiple entities */
18144       n=0;
18145       for(i=1; i<set[setNr].anz_n; i++)
18146       {
18147 	if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[++n]=set[setNr].node[i];
18148       }
18149       set[setNr].anz_n=n+1;
18150     }
18151     /* circle through all elements and add all nodes and faces */
18152     /* nodes have to be completed before because otherwhise all geometry with their nodes would be included */
18153     m=set[setNr].anz_n;
18154     for (i=0; i<set[setNr].anz_e; i++)
18155     {
18156       if (e_enqire[set[setNr].elem[i]].type == 1) n = 8;       /* HEXA8 */
18157       else if (e_enqire[set[setNr].elem[i]].type == 2) n = 6;  /* PENTA6 */
18158       else if (e_enqire[set[setNr].elem[i]].type == 3) n = 4;  /* TET4 */
18159       else if (e_enqire[set[setNr].elem[i]].type == 4) n = 20; /* HEXA20 */
18160       else if (e_enqire[set[setNr].elem[i]].type == 5) n = 15; /* PENTA15 */
18161       else if (e_enqire[set[setNr].elem[i]].type == 6) n = 10; /* TET10 */
18162       else if (e_enqire[set[setNr].elem[i]].type == 7) n = 3;  /* TRI3  */
18163       else if (e_enqire[set[setNr].elem[i]].type == 8) n = 6;  /* TRI6  */
18164       else if (e_enqire[set[setNr].elem[i]].type == 9) n = 4;  /* QUAD4 */
18165       else if (e_enqire[set[setNr].elem[i]].type == 10) n = 8; /* QUAD8 */
18166       else if (e_enqire[set[setNr].elem[i]].type == 11) n = 2; /* BEAM2 */
18167       else if (e_enqire[set[setNr].elem[i]].type == 12) n = 3; /* BEAM3 */
18168       else n=0;
18169       for (j=0; j<n; j++)
18170       {
18171   	  // seta( setNr, "n", e_enqire[set[setNr].elem[i]].nod[j] );
18172           if ( (set[setNr].node = (int *)realloc((int *)set[setNr].node, (set[setNr].anz_n+1) * sizeof(int))) == NULL )
18173             printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
18174           set[setNr].node[set[setNr].anz_n]= e_enqire[set[setNr].elem[i]].nod[j];
18175           set[setNr].anz_n++;
18176       }
18177     }
18178     if(set[setNr].anz_n-m)
18179     {
18180       qsort( set[setNr].node, set[setNr].anz_n, sizeof(int), (void *)compareInt );
18181       /* erase multiple entities */
18182       n=0;
18183       for(i=1; i<set[setNr].anz_n; i++)
18184       {
18185 	if(set[setNr].node[n]!=set[setNr].node[i]) set[setNr].node[++n]=set[setNr].node[i];
18186       }
18187       set[setNr].anz_n=n+1;
18188     }
18189 
18190     /* cyrcle through all bodys and add all surfs */
18191     for (i=0; i<set[setNr].anz_b; i++)
18192     {
18193       c= set[setNr].body[i];
18194       for (j=0; j<body[c].ns; j++)
18195       {
18196         l=body[c].s[j];
18197         seta( setNr, "s", l );
18198       }
18199     }
18200     /* cyrcle through all surfs and add all lines, lcmbs and nurbs */
18201     for (i=0; i<set[setNr].anz_s; i++)
18202     {
18203       s= set[setNr].surf[i];
18204       if(surf[s].sh>-1) seta( setNr, "sh", surf[s].sh );
18205       for (j=0; j<surf[s].nl; j++)
18206       {
18207         l=surf[s].l[j];
18208         if (surf[s].typ[j]=='l')
18209         {
18210           seta( setNr, "l", l );
18211         }
18212         else
18213         {
18214           seta( setNr, "c", l );
18215         }
18216       }
18217     }
18218     /* cyrcle through all lcmbs and add all lines */
18219     for (i=0; i<set[setNr].anz_c; i++)
18220     {
18221       c= set[setNr].lcmb[i];
18222       for (j=0; j<lcmb[c].nl; j++)
18223       {
18224         l=lcmb[c].l[j];
18225         seta( setNr, "l", l );
18226       }
18227     }
18228     /* cyrcle through all lines and add all points, trks */
18229     for (i=0; i<set[setNr].anz_l; i++)
18230     {
18231       l= set[setNr].line[i];
18232       seta( setNr, "p", line[l].p1 );
18233       seta( setNr, "p", line[l].p2 );
18234       if (line[l].typ=='a') seta( setNr, "p", line[l].trk );
18235       if (line[l].typ=='s') seta( setNr, "se", line[l].trk );
18236     }
18237     /* cyrcle through all shapes and add all points and nurbs */
18238     for (i=0; i<set[setNr].anz_sh; i++)
18239     {
18240       s= set[setNr].shp[i];
18241       if(shape[s].type==0) for (j=0; j<3; j++) seta( setNr, "p", shape[s].p[j] );
18242       else if(shape[s].type==1) for (j=0; j<3; j++) seta( setNr, "p", shape[s].p[j] );
18243       else if(shape[s].type==2) for (j=0; j<4; j++) seta( setNr, "p", shape[s].p[j] );
18244       else if(shape[s].type==3) for (j=0; j<2; j++) seta( setNr, "p", shape[s].p[j] );
18245       else if(shape[s].type==4) seta( setNr, "S", shape[s].p[0] );
18246       else if(shape[s].type==5) for (j=0; j<4; j++) seta( setNr, "p", shape[s].p[j] );
18247     }
18248     /* cyrcle through all nurbs and add all points */
18249     for (i=0; i<set[setNr].anz_nurs; i++)
18250     {
18251       s= set[setNr].nurs[i];
18252       for (j=0; j<nurbs[s].u_npnt; j++)
18253         for (k=0; k<nurbs[s].v_npnt; k++)
18254           seta( setNr, "p", nurbs[s].ctlpnt[j][k] );
18255     }
18256     /* cyrcle through all sets and add all entities */
18257     for (i=0; i<set[setNr].anz_se; i++)
18258     {
18259       s= set[setNr].set[i];
18260       for (j=0; j<set[s].anz_n; j++)
18261       {
18262         p=set[s].node[j];
18263         seta( setNr, "n", p );
18264       }
18265       for (j=0; j<set[s].anz_f; j++)
18266       {
18267         p=set[s].face[j];
18268         seta( setNr, "f", p );
18269       }
18270       for (j=0; j<set[s].anz_e; j++)
18271       {
18272         p=set[s].elem[j];
18273         seta( setNr, "e", p );
18274       }
18275       for (j=0; j<set[s].anz_p; j++)
18276       {
18277         p=set[s].pnt[j];
18278         seta( setNr, "p", p );
18279       }
18280       for (j=0; j<set[s].anz_l; j++)
18281       {
18282         p=set[s].line[j];
18283         seta( setNr, "l", p );
18284       }
18285       for (j=0; j<set[s].anz_c; j++)
18286       {
18287         p=set[s].lcmb[j];
18288         seta( setNr, "c", p );
18289       }
18290       for (j=0; j<set[s].anz_s; j++)
18291       {
18292         p=set[s].surf[j];
18293         seta( setNr, "s", p );
18294       }
18295       for (j=0; j<set[s].anz_b; j++)
18296       {
18297         p=set[s].body[j];
18298         seta( setNr, "b", p );
18299       }
18300       for (j=0; j<set[s].anz_sh; j++)
18301       {
18302         p=set[s].shp[j];
18303         seta( setNr, "sh", p );
18304       }
18305     }
18306 
18307     /* remove the appended sets */
18308     while(set[setNr].anz_se>0)
18309     {
18310       s= set[setNr].set[0];
18311       setr( setNr, "r", s);
18312     }
18313 
18314   }
18315 
18316   else if (toupper(type[0])=='F') /* faces */
18317   {
18318     if ( setNr==getSetNr(specialset->mesh)||( set[setNr].type==1)||(setNr==getSetNr(specialset->nomesh))) return(-1);
18319 
18320     /* add the faces to the sets which fit fully to the included nodes */
18321     if(printFlag) printf(" include faces in sets\n");
18322 
18323     /* go over all faces and look if their nodes are included in the set setNr */
18324     m=set[setNr].anz_f;
18325     for (i=0; i<anz->f; i++)
18326     {
18327       if (face[i].type == 7) n = 3;  /* TRI3  */
18328       else if (face[i].type == 8) n = 6;  /* TRI6  */
18329       else if (face[i].type == 9) n = 4;  /* QUAD4 */
18330       else if (face[i].type == 10) n = 8; /* QUAD8 */
18331       else if (face[i].type == 11) n = 2; /* beam2 */
18332       else if (face[i].type == 12) n = 3; /* beam3 */
18333       else n=0;
18334       k=0;
18335       for (j=0; j<n; j++)
18336       {
18337 	if(ifind(&set[setNr].node, set[setNr].anz_n, face[i].nod[j])>-1) k++;
18338       }
18339       if(k==n)
18340       {
18341 	// seta( setNr, "f", i );
18342         if ( (set[setNr].face = (int *)realloc((int *)set[setNr].face, (set[setNr].anz_f+1) * sizeof(int))) == NULL )
18343           printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
18344         set[setNr].face[set[setNr].anz_f]= i;
18345         set[setNr].anz_f++;
18346       }
18347     }
18348     if(set[setNr].anz_f-m)
18349     {
18350       qsort( set[setNr].face, set[setNr].anz_f, sizeof(int), (void *)compareInt );
18351       /* erase multiple entities */
18352       n=0;
18353       for(i=1; i<set[setNr].anz_f; i++)
18354       {
18355 	if(set[setNr].face[n]!=set[setNr].face[i]) set[setNr].face[++n]=set[setNr].face[i];
18356       }
18357       set[setNr].anz_f=n+1;
18358     }
18359 
18360     /* go over all faces and look if their elements are included in the set setNr */
18361     m=set[setNr].anz_f;
18362     for (i=0; i<anz->f; i++)
18363     {
18364       if(ifind(&set[setNr].elem, set[setNr].anz_e, face[i].elem_nr)>-1)
18365       {
18366 	// seta( setNr, "f", i );
18367         if ( (set[setNr].face = (int *)realloc((int *)set[setNr].face, (set[setNr].anz_f+1) * sizeof(int))) == NULL )
18368           printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, set[setNr].name);
18369         set[setNr].face[set[setNr].anz_f]= i;
18370         set[setNr].anz_f++;
18371       }
18372     }
18373     if(set[setNr].anz_f-m)
18374     {
18375       qsort( set[setNr].face, set[setNr].anz_f, sizeof(int), (void *)compareInt );
18376       /* erase multiple entities */
18377       n=0;
18378       for(i=1; i<set[setNr].anz_f; i++)
18379       {
18380 	if(set[setNr].face[n]!=set[setNr].face[i]) set[setNr].face[++n]=set[setNr].face[i];
18381       }
18382       set[setNr].anz_f=n+1;
18383     }
18384   }
18385 
18386   else if (toupper(type[0])=='C') /* LCMB's */
18387   {
18388     /* cyrcle through all lcmbs and add it if all lines are part of the set */
18389     for (c=0; c<anzGeo->c; c++) if( lcmb[c].name != (char *)NULL )
18390     {
18391       for (j=0; j<lcmb[c].nl; j++)
18392       {
18393         l=lcmb[c].l[j];
18394         if(0>ifind(&set[setNr].line, set[setNr].anz_l, l )) break;
18395       }
18396       if(j==lcmb[c].nl) seta( setNr, "c", c );
18397     }
18398   }
18399 
18400   else if (toupper(type[0])=='E') /* edges */
18401   {
18402     /* cyrcle through all bodys and add all surfs */
18403     for (i=0; i<set[setNr].anz_b; i++)
18404     {
18405       c= set[setNr].body[i];
18406       for (j=0; j<body[c].ns; j++)
18407       {
18408         l=body[c].s[j];
18409         seta( setNr, "s", l );
18410       }
18411     }
18412     /* cyrcle through all surfs and add all lines, lcmbs  */
18413     for (i=0; i<set[setNr].anz_s; i++)
18414     {
18415       s= set[setNr].surf[i];
18416       for (j=0; j<surf[s].nl; j++)
18417       {
18418         l=surf[s].l[j];
18419         if (surf[s].typ[j]=='l')
18420         {
18421           seta( setNr, "l", l );
18422         }
18423         else
18424         {
18425           seta( setNr, "c", l );
18426         }
18427       }
18428     }
18429     /* cyrcle through all lcmbs and add all lines */
18430     for (i=0; i<set[setNr].anz_c; i++)
18431     {
18432       c= set[setNr].lcmb[i];
18433       for (j=0; j<lcmb[c].nl; j++)
18434       {
18435         l=lcmb[c].l[j];
18436         seta( setNr, "l", l );
18437       }
18438     }
18439     /* cyrcle through all lines and add all corner-points */
18440     for (i=0; i<set[setNr].anz_l; i++)
18441     {
18442       l= set[setNr].line[i];
18443       seta( setNr, "p", line[l].p1 );
18444       seta( setNr, "p", line[l].p2 );
18445     }
18446   }
18447   else printf(" Command not recognized, use up down or edges\n");
18448   return(setNr);
18449 }
18450 
18451 
18452 
18453 /* send the interiour of the surfaces in stl format (not used ) */
18454 
sendTriangles(char * setname)18455 int sendTriangles(  char *setname )
18456 {
18457   int i,j,k,n,s, setNr, tris=0;
18458   FILE *handle;
18459 
18460   operateAlias( setname, "se" );
18461   setNr=getSetNr(setname);
18462   if (setNr<0)
18463   {
18464     printf (" ERROR in completeSet: set:%s does not exist\n", setname);
18465     return(-1);
18466   }
18467 
18468   sprintf(buffer, "%s.stl", setname);
18469   handle = fopen (buffer, "w");
18470   if (handle==NULL)
18471   {
18472     printf (" ERROR in sendTriangles: The input file \"%s\" could not be opened.\n\n", datin);
18473     return(-1);
18474   }
18475   else  printf ("\n%s opened\n",buffer);
18476 
18477   /* write the interiour of the surface */
18478   fprintf( handle, "solid\n");
18479   for (i=0; i<set[setNr].anz_s; i++)
18480   {
18481     s= set[setNr].surf[i];
18482 
18483     n=0;
18484     while((surf[s].npgn-n))
18485     {
18486       n++;
18487       j=surf[s].pgn[n++];
18488       fprintf( handle, "  facet normal %e %e %e\n",surf[s].pgn[n],surf[s].pgn[n+1],surf[s].pgn[n+2]); n+=3;
18489       fprintf( handle, "    outer loop\n");
18490       for(k=0; k<j; k++)
18491       {
18492         fprintf( handle, "      vertex %e %e %e\n",
18493           surf[s].pgn[n]*scale->w+scale->x,
18494           surf[s].pgn[n+1]*scale->w+scale->y,
18495           surf[s].pgn[n+2]*scale->w+scale->z); n+=3;
18496       }
18497       tris++;
18498       fprintf( handle, "    endloop\n");
18499       fprintf( handle, "  endfacet\n");
18500     }
18501   }
18502   fprintf( handle, "endsolid\n");
18503   printf("wrote %d triangles\n", tris);
18504   fclose(handle);
18505   return(1);
18506 }
18507 
18508 
18509 
pre_write(char * record)18510 void pre_write( char *record )
18511 {
18512   char  setname[MAX_LINE_LENGTH], format[MAX_LINE_LENGTH], type[MAX_LINE_LENGTH], **dat;
18513   int          length, anz_l, setNr, i,j,k,l=0,s,v,n,b;
18514   char typ, buffer[MAX_LINE_LENGTH];
18515   static char  **val=NULL;
18516   double        f[3]={0.,0.,0.};
18517   int bset;
18518   int bouNr;
18519   NodeBlockbou *blockbou=NULL;
18520   double v1[3], v2[3], v3[3];
18521   int tr6[4][3]={{0,3,5},{4,5,3},{3,1,4},{4,2,5}};
18522   int qu4[2][3]={{0,1,2},{2,3,0}};
18523   int qu8[8][3]={{0,4,8},{8,4,1},{1,5,8},{8,5,2},{2,6,8},{8,6,3},{3,7,8},{8,7,0}};
18524 
18525   FILE *handle=NULL;
18526 
18527   if(val){ for(i=0; i<5; i++) free(val[i]);  free(val); }
18528   if(( val=(char **)malloc( 5*sizeof(char *)) )==NULL)
18529   { printf(" ERROR: malloc failure\n\n" ); return; }
18530   for(i=0; i<5; i++)
18531   {
18532     if(( val[i]=(char *)malloc( MAX_LINE_LENGTH*sizeof(char)) )==NULL)
18533     { printf(" ERROR: malloc failure\n\n" ); return; }
18534     val[i][0]=0;
18535   }
18536 
18537   /* clean the buffers */
18538   for(i=0; i<MAX_LINE_LENGTH; i++) buffer[i]=setname[i]=format[i]=type[i]='\0';
18539   for(i=0; i<MAX_LINE_LENGTH; i++) for(j=0; j<5; j++) val[j][i]='\0';
18540 
18541   length = sscanf(record, "%s%s%s%s%s%s%s%s", setname, format, type, val[0], val[1], val[2], val[3], val[4]);
18542   if (length<2)
18543   {
18544     if (compare( setname, "init", 4)== 4)
18545     {
18546       sprintf(buffer,"init.fbl");
18547       handle = fopen (buffer, "w+b");
18548       if (handle==NULL) { printf ("\nThe output file \"%s\" could not be opened.\n\n", buffer ); return; }
18549       writeInit(handle);
18550       fclose(handle);
18551       printf (" ready\n");
18552       return;
18553     }
18554     else { printf(" ERROR: Format missing!\n"); return; }
18555   }
18556 
18557   /* replace 'lc' by 'ds' */
18558   if(compare( type, "lc", 2)== 2) { type[0]='d'; type[1]='s'; }
18559   for(i=0; i<4; i++) if(compare( val[i], "lc", 2)== 2) { val[i][0]='d'; val[i][1]='s'; }
18560 
18561   operateAlias( setname, "se" );
18562   printf (" please wait for 'ready'\n");
18563 
18564   if (compare( format, "bp", 2)== 2)
18565   {
18566     if(getSetNr(specialset->zap)>-1)
18567     {
18568       errMsg("ERROR: special set:%s is not empty. Please delete the set before\n", specialset->zap);
18569       return;
18570     }
18571     if (length>2)
18572     {
18573       if (compare( type, "c", 1)== 1)
18574       {
18575       completeSet( setname, "do" );
18576       }
18577     }
18578     descalPoints( anzGeo->p, point, scale);
18579     writebp( setname, anz, anzGeo, point, set );
18580     scalPoints( anzGeo->p, point, scale);
18581   }
18582   else if (compare( format, "fbd", 3)== 3)
18583   {
18584     if(getSetNr(specialset->zap)>-1)
18585     {
18586       errMsg("ERROR: special set:%s is not empty. Please delete the set before\n", specialset->zap);
18587       return;
18588     }
18589     if (length>2)
18590     {
18591       if (compare( type, "c", 1)== 1)
18592       {
18593         completeSet( setname, "do" );
18594       }
18595       if (compare( type, "f", 1)== 1)
18596       {
18597         // write point coordinates in long float, else in exp
18598         strcpy( format, "lf" );
18599       }
18600       if (compare( type, "e", 1)== 1)
18601       {
18602         sprintf(buffer,"%s_edges.fbd", setname);
18603         handle = fopen (buffer, "w+b");
18604         if (handle==NULL) { printf ("\nThe output file \"%s\" could not be opened.\n\n", buffer ); return; }
18605         descalNodes ( anz->n, node, scale);
18606         for (i=0; i<anz->g; i++ )
18607         {
18608           fprintf(handle, " pnt a%d %f %f %f\n", i, node[edge[i].p1].nx, node[edge[i].p1].ny, node[edge[i].p1].nz );
18609           fprintf(handle, " pnt b%d %f %f %f\n", i, node[edge[i].p2].nx, node[edge[i].p2].ny, node[edge[i].p2].nz );
18610           fprintf(handle, " line l%d a%d b%d 1\n",i,i,i);
18611         }
18612         fprintf(handle, " merg p all 0.00001\n");
18613         scalNodes ( anz->n, node, scale );
18614         fclose(handle);
18615         printf (" ready\n");
18616         return;
18617       }
18618     }
18619     descalPoints( anzGeo->p, point, scale);
18620     writefbd( setname, anz, anzGeo, point, line, lcmb, surf, body, nurbs, set, shape, value, format );
18621     scalPoints( anzGeo->p, point, scale);
18622   }
18623   else if (compare( format, "ng", 2)== 2)
18624   {
18625     if(compareStrings( setname, "all" )<=0)
18626     {
18627 	printf("ERROR: netgen-format was requested for a subset:%s. Up to now only the faces of the full mesh can be written (set all)\n",setname);
18628       return;
18629     }
18630     if(anz->f<1)
18631     {
18632       printf("ERROR: no faces exist\n");
18633       return;
18634     }
18635 
18636     descalNodes ( anz->n, node, scale);
18637 
18638     handle = fopen ("mesh.ng", "w+b");
18639     if (handle==NULL) { printf ("\nThe output file \"mesh.ng\" could not be opened.\n\n"); return; }
18640     printf (" write surface-mesh data for the netgen-tetmesher ng_vol \n");
18641 
18642     fprintf (handle, "%d\n", anz->n);
18643     for (i=0; i<anz->n; i++)
18644     {
18645       fprintf (handle, "%.12e %.12e %.12e\n", node[node[i].nr].nx, node[node[i].nr].ny, node[node[i].nr].nz);
18646     }
18647     i=0;
18648     for (j=0; j<anz->f; j++)
18649     {
18650       if ((face[j].type == 7)|| (face[j].type == 8)) i++;
18651       else if ((face[j].type == 9)|| (face[j].type == 10)) i+=2;
18652     }
18653     fprintf (handle, "%d\n", i);
18654 /*
18655     fprintf (handle, "%d\n", anz->e);
18656     for (i=0; i<anz->e; i++)
18657     {
18658       j=e_enqire[i].nr;
18659       if (e_enqire[j].type == 7)
18660       {
18661         fprintf (handle, "%d %d %d\n",
18662          node[e_enqire[j].nod[0]].indx+1, node[e_enqire[j].nod[1]].indx+1, node[e_enqire[j].nod[2]].indx+1);
18663       }
18664       else
18665       {
18666         printf (" WARNING: elem(%d) not a known type (%d)\n", e_enqire[j].nr, e_enqire[j].type);
18667       }
18668     }
18669 */
18670     for (j=0; j<anz->f; j++)
18671     {
18672       if ((face[j].type == 7)|| (face[j].type == 8))
18673       {
18674         fprintf (handle, "%d %d %d\n",
18675          node[face[j].nod[0]].indx+1, node[face[j].nod[1]].indx+1, node[face[j].nod[2]].indx+1);
18676       }
18677       else if ((face[j].type == 9)|| (face[j].type == 10))
18678       {
18679         fprintf (handle, "%d %d %d\n",
18680          node[face[j].nod[0]].indx+1, node[face[j].nod[1]].indx+1, node[face[j].nod[2]].indx+1);
18681         fprintf (handle, "%d %d %d\n",
18682          node[face[j].nod[2]].indx+1, node[face[j].nod[3]].indx+1, node[face[j].nod[0]].indx+1);
18683       }
18684       else
18685       {
18686         printf (" WARNING: face(%d) not a known type (%d)\n", j, face[j].type);
18687       }
18688     }
18689     fclose(handle);
18690 
18691     scalNodes ( anz->n, node, scale);
18692   }
18693   else if (compare( format, "frd", 3)== 3)
18694   {
18695     if (length>2)
18696     {
18697       if (compare( type, "nor", 3)== 3)
18698         sendSurfNormalen( setname, format, anz, node, e_enqire, lcase, scale );
18699       else if (compare( type, "sur", 3)== 3)
18700       {
18701         anz_l=anz->l;
18702         anz->l=anz->olc;
18703         strcpy(val[1],val[0]);
18704         strcpy(val[0],type);
18705 	//val[1]=val[0];
18706         //val[0]=type;
18707         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, val);
18708         anz->l=anz_l;
18709       }
18710       else if (compare( type, "c", 1)== 1)
18711       {
18712         anz_l=anz->l;
18713         anz->l=anz->olc;
18714         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
18715         anz->l=anz_l;
18716       }
18717       else if ((compare( type, "ds", 2)== 2)||(compare( type, "bin", 2)== 2)||(compare( type, "dbin", 3)== 3))
18718       {
18719         strcpy(val[1], val[0]);
18720         strcpy(val[0], type);
18721         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, val);
18722       }
18723       else
18724       {
18725         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18726         return;
18727       }
18728     }
18729     else
18730     {
18731       anz_l=anz->l;
18732       anz->l=anz->olc;
18733       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
18734       anz->l=anz_l;
18735     }
18736   }
18737   else if (compare( format, "darwin", 3)== 3)
18738   {
18739     anz_l=anz->l;
18740     anz->l=anz->olc;
18741     strcpy(val[1], val[0]);
18742     strcpy(val[0], type);
18743     senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18744     anz->l=anz_l;
18745   }
18746   /* list of entities */
18747   else if (compare( format, "lst", 3)== 3)
18748   {
18749     senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18750   }
18751   else if (compare( format, "seq", 3)== 3)
18752   {
18753     senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18754   }
18755   /* gagemap */
18756   else if (compare( format, "gmp", 3)== 3)
18757   {
18758     if (length>2)
18759     {
18760       if (compare( type, "names", 3)== 3)
18761         sendNames( setname, format, anz, node, e_enqire );
18762       else
18763       {
18764         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18765         return;
18766       }
18767     }
18768     return;
18769   }
18770   /* patran neutral file */
18771   else if (compare( format, "pat", 3)== 3)
18772   {
18773     if (length>2)
18774     {
18775       if (compare( type, "names", 3)== 3)
18776       {
18777         /* if setname == "all" -> send all sets */
18778         if(compareStrings( setname, "all" )>0)
18779         {
18780           for(i=0; i<anz->sets; i++)
18781 	  {
18782             if((set[i].name!=NULL)&&(set[i].name[0]!='+')&&(set[i].name[0]!='-')&&(compareStrings(set[i].name, "all" )<=0)&&((set[i].anz_n>0)||(set[i].anz_e>0))) sendNames( set[i].name, format, anz, node, e_enqire );
18783 	  }
18784 	}
18785         else sendNames( setname, format, anz, node, e_enqire );
18786       }
18787       else
18788       {
18789         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18790         return;
18791       }
18792     }
18793     return;
18794   }
18795   else if (compare( format, "abq", 3)== 3)
18796   {
18797     if (length>2)
18798     {
18799       if (compare( type, "quadlin", 3)== 3)
18800         sendQuadLin( setname, format, anz, node, e_enqire );
18801       else if (compare( type, "pres", 3)== 3)
18802         sendPressure( setname, format, anz, node, e_enqire, val[0], val[1], val[2], 0 );
18803       else if (compare( type, "film", 3)== 3)
18804         sendFilm( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3], val[4] );
18805       else if (compare( type, "radiate", 3)== 3)
18806         sendRadiate( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3], val[4] );
18807       else if (compare( type, "mflow", 5)== 5)
18808         sendDflux( setname, format, anz, node, e_enqire, val[0], val[1], val[2], 1 );
18809       else if (compare( type, "dflux", 5)== 5)
18810         sendDflux( setname, format, anz, node, e_enqire, val[0], val[1], val[2], 0 );
18811       else if (compare( type, "force", 3)== 3)
18812       { length = sscanf(record, "%*s%*s%*s%lf%lf%lf", &f[0],&f[1],&f[2]);
18813         sendForce( setname, format, anz, node, e_enqire, f ); }
18814       else if (compare( type, "spcf", 4)== 4)
18815         sendSPCF( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3] );
18816       else if (compare( type, "spc", 3)== 3)
18817         sendSPC( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3] );
18818       else if (compare( type, "cflux", 3)== 3)
18819         sendCflux( setname, format, anz, node, e_enqire, "t", val[0] );
18820       else if (compare( type, "slidef", 6)== 6)
18821         sendSlidersf( setname, format, val[0]  );
18822       else if (compare( type, "slide", 3)== 3)
18823         sendSliders( setname, format, anz, node, e_enqire, val[0]  );
18824       else if (compare( type, "names", 3)== 3)
18825       {
18826         /* if setname == "all" -> send all sets */
18827         if(compareStrings( setname, "all" )>0)
18828         {
18829           for(i=0; i<anz->sets; i++)
18830 	  {
18831             if((set[i].name!=NULL)&&(set[i].name[0]!='+')&&(set[i].name[0]!='-')&&(compareStrings(set[i].name, "all" )<=0)&&((set[i].anz_n>0)||(set[i].anz_e>0))) sendNames( set[i].name, format, anz, node, e_enqire );
18832 	  }
18833 	}
18834         sendNames( setname, format, anz, node, e_enqire );
18835       }
18836       else if (compare( type, "raw", 3)== 3)
18837       {
18838         sendNames( setname, type, anz, node, e_enqire );
18839         sendSurfaces( setname, type, anz, node, e_enqire, val[0] );
18840       }
18841       else if (compare( type, "sur", 3)== 3)
18842       {
18843         /* if setname == "all" -> send all sets */
18844         if(compareStrings( setname, "all" )>0)
18845         {
18846           for(i=0; i<anz->sets; i++)
18847 	  {
18848             if((set[i].name!=NULL)&&(set[i].name[0]!='+')&&(set[i].name[0]!='-')&&(compareStrings(set[i].name, "all" )<=0)&&((set[i].anz_f>0))) { sendSurfaces( set[i].name, format, anz, node, e_enqire, val[0] ); }
18849 	  }
18850 	}
18851         else sendSurfaces( setname, format, anz, node, e_enqire, val[0] );
18852       }
18853       else if (compare( type, "mpc", 3)== 3)
18854       { length = sscanf(record, "%*s%*s%*s%*s%lf%lf%lf", &f[0],&f[1],&f[2]);
18855         sendMpc( setname, format, val[0], f ); }
18856       else if (compare( type, "ds", 2)== 2)
18857       {
18858         strcpy(val[1], val[0]);
18859         strcpy(val[0], type);
18860         anz_l=anz->l;
18861         anz->l=anz->olc;
18862         senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18863         anz->l=anz_l;
18864       }
18865       else if (compare( type, "tmf", 2)== 2)
18866       {
18867         anz_l=anz->l;
18868         anz->l=anz->olc;
18869         strcpy(val[0], type);
18870         senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18871         anz->l=anz_l;
18872       }
18873       else if (compare( type, "crp", 2)== 2)
18874       {
18875         anz_l=anz->l;
18876         anz->l=anz->olc;
18877         strcpy(val[3], val[2]); /* write-frequency */
18878         strcpy(val[2], val[1]); /* reference-speed */
18879         strcpy(val[1], val[0]); /* time-factor */
18880         strcpy(val[0], type);
18881         senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18882         anz->l=anz_l;
18883       }
18884       else if (compare( type, "sta", 2)== 2)
18885       {
18886         anz_l=anz->l;
18887         anz->l=anz->olc;
18888         strcpy(val[2], val[0]); /* reference-speed */
18889         strcpy(val[0], type);
18890         senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
18891         anz->l=anz_l;
18892       }
18893       else if (compare( type, "c", 1)== strlen(type))
18894       {
18895         anz_l=anz->l;
18896         anz->l=anz->olc;
18897         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
18898         anz->l=anz_l;
18899       }
18900       else
18901       {
18902         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18903         return;
18904       }
18905     }
18906     else
18907     {
18908       anz_l=anz->l;
18909       anz->l=anz->olc;
18910       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
18911       anz->l=anz_l;
18912     }
18913   }
18914   /* changes from Paul CARRICO */
18915   else if (compare( format, "aster", 3)== 3)
18916   {
18917     if (length>2)
18918     {
18919       if (compare( type, "names", 3)== 3)
18920         sendNames( setname, format, anz, node, e_enqire );
18921       else if (compare( type, "c", 1)== 1)
18922       {
18923         anz_l=anz->l;
18924         anz->l=anz->olc;
18925         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
18926         anz->l=anz_l;
18927       }
18928       else
18929       {
18930         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18931         return;
18932       }
18933     }
18934     else
18935     {
18936       anz_l=anz->l;
18937       anz->l=anz->olc;
18938       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
18939       anz->l=anz_l;
18940     }
18941   }
18942   /* changes from Paul CARRICO */
18943   else if (compare( format, "sam", 3)== 3)
18944   {
18945     if (length>2)
18946     {
18947       if (compare( type, "names", 3)== 3)
18948         sendNames( setname, format, anz, node, e_enqire );
18949       else if (compare( type, "c", 1)== 1)
18950       {
18951         anz_l=anz->l;
18952         anz->l=anz->olc;
18953         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
18954         anz->l=anz_l;
18955       }
18956       else
18957       {
18958         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18959         return;
18960       }
18961     }
18962     else
18963     {
18964       anz_l=anz->l;
18965       anz->l=anz->olc;
18966       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
18967       anz->l=anz_l;
18968     }
18969   }
18970   else if (compare( format, "adh", 3)== 3)
18971   {
18972     if (length>2)
18973     {
18974       if (compare( type, "spc", 3)== 3)
18975         sendSPC( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3] );
18976       else
18977       {
18978         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
18979         return;
18980       }
18981     }
18982     else
18983     {
18984       anz_l=anz->l;
18985       anz->l=anz->olc;
18986       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
18987       anz->l=anz_l;
18988     }
18989   }
18990   else if (compare( format, "ans", 3)== 3)
18991   {
18992     if (length>2)
18993     {
18994       if (compare( type, "pres", 3)== 3)
18995         sendPressure( setname, format, anz, node, e_enqire, val[0], val[1], val[2], 0 );
18996       else if (compare( type, "for", 3)== 3)
18997       { length = sscanf(record, "%*s%*s%*s%lf%lf%lf", &f[0],&f[1],&f[2]);
18998         sendForce( setname, format, anz, node, e_enqire, f ); }
18999       else if (compare( type, "spc", 3)== 3)
19000         sendSPC( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3] );
19001       else if (compare( type, "slide", 3)== 3)
19002         sendSliders( setname, format, anz, node, e_enqire, val[0]  );
19003       else if (compare( type, "names", 3)== 3)
19004         sendNames( setname, format, anz, node, e_enqire );
19005       else if ((compare( type, "ds", 2)== 2)||(compare( type, "tmf", 2)== 2))
19006       {
19007         strcpy(val[1], val[0]);
19008         strcpy(val[0], type);
19009         anz_l=anz->l;
19010         anz->l=anz->olc;
19011         senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
19012         anz->l=anz_l;
19013       }
19014       else if (compare( type, "c", 1)== 1)
19015       {
19016         anz_l=anz->l;
19017         anz->l=anz->olc;
19018         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
19019         anz->l=anz_l;
19020       }
19021       else
19022       {
19023         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
19024         return;
19025       }
19026     }
19027     else
19028     {
19029       anz_l=anz->l;
19030       anz->l=anz->olc;
19031       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
19032       anz->l=anz_l;
19033     }
19034   }
19035   else if (compare( format, "nas", 3)== 3)
19036   {
19037     if (length>2)
19038     {
19039       if (compare( type, "pres", 3)== 3)
19040         sendPressure( setname, format, anz, node, e_enqire, val[0], val[1], val[2], 0 );
19041       else if (compare( type, "for", 3)== 3)
19042       { length = sscanf(record, "%*s%*s%*s%lf%lf%lf", &f[0],&f[1],&f[2]);
19043         sendForce( setname, format, anz, node, e_enqire, f ); }
19044       else if (compare( type, "spc", 3)== 3)
19045         sendSPC( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3] );
19046       else if (compare( type, "c", 1)== 1)
19047       {
19048         anz_l=anz->l;
19049         anz->l=anz->olc;
19050         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
19051         anz->l=anz_l;
19052       }
19053       else if (compare( type, "mpc", 3)== 3)
19054       {
19055         length = sscanf(record, "%*s%*s%*s%*s%lf%lf%lf", &f[0],&f[1],&f[2]);
19056         sendMpc( setname, format, val[0], f );
19057       }
19058       else if (compare( type, "ds", 2)== 2)
19059       {
19060         strcpy(val[1], val[0]);
19061         strcpy(val[0], type);
19062         anz_l=anz->l;
19063         anz->l=anz->olc;
19064         senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, val);
19065         anz->l=anz_l;
19066       }
19067       else
19068       {
19069         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
19070         return;
19071       }
19072     }
19073     else
19074     {
19075       anz_l=anz->l;
19076       anz->l=anz->olc;
19077       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
19078       anz->l=anz_l;
19079     }
19080   }
19081   else if (compare( format, "tcg", 3)== 3)
19082   {
19083     if (length>2)
19084     {
19085       if (compare( type, "pres", 3)== 3)
19086         sendPressure( setname, format, anz, node, e_enqire, val[0], val[1], val[2], 0 );
19087       else if (compare( type, "for", 3)== 3)
19088       { length = sscanf(record, "%*s%*s%*s%lf%lf%lf", &f[0],&f[1],&f[2]);
19089         sendForce( setname, format, anz, node, e_enqire, f ); }
19090       else if (compare( type, "spc", 3)== 3)
19091         sendSPC( setname, format, anz, node, e_enqire, val[0], val[1], val[2], val[3] );
19092       else if (compare( type, "c", 1)== 1)
19093       {
19094         anz_l=anz->l;
19095         anz->l=anz->olc;
19096         senddata( setname, format, anz, node, e_enqire, lcase, scale, 1, 0);
19097         anz->l=anz_l;
19098       }
19099       else
19100       {
19101         errMsg(" ERROR:  %s in format %s not yet supported\n", type, format );
19102         return;
19103       }
19104     }
19105     else
19106     {
19107       anz_l=anz->l;
19108       anz->l=anz->olc;
19109       senddata( setname, format, anz, node, e_enqire, lcase, scale, 0, 0);
19110       anz->l=anz_l;
19111     }
19112   }
19113   else if (compare( format, "dolfyn", 3)== 3)
19114   {
19115     length= strsplt( record, ' ', &dat);
19116     descalNodes ( anz->n, node, scale);
19117     write2dolfyn( setname, length-2, &dat[2], anz, node, face, e_enqire, set );
19118     scalNodes ( anz->n, node, scale);
19119 
19120     /* free dat */
19121     for(i=0; i<length; i++) free(dat[i]); free(dat);
19122   }
19123   else if (compare( format, "duns", 3)== 3)
19124   {
19125     if (compare( type, "names", 3)== 3) sendNames( setname, format, anz, node, e_enqire );
19126     else
19127     {
19128       length= strsplt( record, ' ', &dat);
19129 
19130       /* initialize the bctype with "0" */
19131       for( b=0; b<anz->b; b++)
19132       {
19133         if(nBlock[b].dim==2)
19134         {
19135           s=nBlock[b].geo;
19136           for(j=0; j<surf[s].nl; j++) nBlock[b].bctype[j][0]=0;
19137         }
19138         if(nBlock[b].dim==3)
19139         {
19140           s=nBlock[b].geo;
19141           for(j=0; j<body[s].ns; j++) nBlock[b].bctype[j][0]=0;
19142         }
19143       }
19144 
19145       /* add the grid-blocks to the type of boundary */
19146       bouNr=-1;
19147       n=2; while(n<length)
19148       {
19149         /* search the corresponding blocks */
19150         bset=getSetNr(dat[n+1]);
19151         if(bset<0)
19152         {
19153           printf("boundary set:%s does not exist\n", dat[n+1]);
19154           return;
19155         }
19156         bouNr++;
19157         if((blockbou=(NodeBlockbou *)realloc((NodeBlockbou *)blockbou, (bouNr+1)*sizeof(NodeBlockbou)) )==NULL)
19158         { printf(" ERROR: realloc failure, blockbou:%d could not be allocated\n\n", bouNr ); return; }
19159         strcpy(blockbou[bouNr].name,set[bset].name);
19160         blockbou[bouNr].surf=NULL;
19161         blockbou[bouNr].nBlock=NULL;
19162         blockbou[bouNr].side=NULL;
19163         blockbou[bouNr].surfs=0;
19164 
19165         /* add the lcmb to the set */
19166         for(i=0; i<set[bset].anz_l; i++)
19167         {
19168           for(j=0; j<anzGeo->c; j++) if( lcmb[j].name != (char *)NULL )
19169           {
19170             for(l=0; l<lcmb[j].nl; l++)
19171             {
19172               if(lcmb[j].l[l]==set[bset].line[i]) seta(bset, "c", j);
19173             }
19174           }
19175         }
19176 
19177         /* look if a member of the set is used by a block */
19178         for( b=0; b<anz->b; b++)
19179         {
19180           if(nBlock[b].dim==2)
19181           {
19182             s=nBlock[b].geo;
19183             for(j=0; j<surf[s].nl; j++)
19184             {
19185               if(nBlock[b].map[j][0]==-1)   // has no neighbor
19186               {
19187                 if((blockbou[bouNr].surf=(int *)realloc((int *)blockbou[bouNr].surf, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19188                 { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19189                 if((blockbou[bouNr].nBlock=(int *)realloc((int *)blockbou[bouNr].nBlock, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19190                 { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19191                 if((blockbou[bouNr].side=(int *)realloc((int *)blockbou[bouNr].side, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19192                 { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19193 
19194                 l=surf[s].l[nBlock[b].bcface[j]];
19195                 typ=surf[s].typ[nBlock[b].bcface[j]];
19196 
19197                 if(typ=='l')
19198                 {
19199                   for(i=0; i<set[bset].anz_l; i++)
19200                   {
19201                     if(l==set[bset].line[i])
19202                     {
19203                       printf("set:%s btype:%s bouNr:%d line[%d]:%s block:%d duns-side[%d]:%d\n",set[bset].name, dat[n],bouNr,blockbou[bouNr].surfs, line[set[bset].line[i]].name, b, j, nBlock[b].neighbor[j]);
19204                       blockbou[bouNr].surf[blockbou[bouNr].surfs] = nBlock[b].neighbor[j];
19205                       strcpy(blockbou[bouNr].bctype, dat[n]);
19206                       blockbou[bouNr].nBlock[blockbou[bouNr].surfs] = b;
19207                       blockbou[bouNr].side[blockbou[bouNr].surfs] = j;
19208                       blockbou[bouNr].surfs++;
19209                       break;
19210                     }
19211                   }
19212                 }
19213                 if(typ=='c')
19214                 {
19215                   for(i=0; i<set[bset].anz_c; i++)
19216                   {
19217                     if(l==set[bset].lcmb[i])
19218                     {
19219                       printf("set:%s btype:%s bouNr:%d lcmb[%d]:%s block:%d duns-side:%d\n",set[bset].name, dat[n],bouNr,blockbou[bouNr].surfs, lcmb[set[bset].lcmb[i]].name, b, nBlock[b].neighbor[j]);
19220                       blockbou[bouNr].surf[blockbou[bouNr].surfs] = nBlock[b].neighbor[j];
19221                       strcpy(blockbou[bouNr].bctype, dat[n]);
19222                       blockbou[bouNr].nBlock[blockbou[bouNr].surfs] = b;
19223                       blockbou[bouNr].side[blockbou[bouNr].surfs] = j;
19224                       blockbou[bouNr].surfs++;
19225                       break;
19226                     }
19227                   }
19228                 }
19229 	      }
19230             }
19231           }
19232           if(nBlock[b].dim==3)
19233 	  {
19234             v=nBlock[b].geo;
19235             for(i=0; i<set[bset].anz_s; i++)
19236             {
19237               for(j=0; j<body[v].ns; j++)
19238               {
19239                 if(nBlock[b].map[j][0]==-1)   // has no neighbor
19240 		{
19241 		  s=body[v].s[nBlock[b].bcface[j]];
19242                   if(s==set[bset].surf[i])
19243                   {
19244                     if((blockbou[bouNr].surf=(int *)realloc((int *)blockbou[bouNr].surf, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19245                     { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19246                     if((blockbou[bouNr].nBlock=(int *)realloc((int *)blockbou[bouNr].nBlock, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19247                     { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19248                     if((blockbou[bouNr].side=(int *)realloc((int *)blockbou[bouNr].side, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19249                     { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19250 
19251 		    printf("body:%s bsurf:%s surf:%s\n", body[v].name, surf[body[v].s[nBlock[b].bcface[j]]].name, surf[set[bset].surf[i]].name);
19252                     printf("set:%s btype:%s bouNr:%d surf[%d]:%s block:%d duns-side[%d]:%d\n",set[bset].name, dat[n],bouNr,blockbou[bouNr].surfs, surf[set[bset].surf[i]].name, b, j, nBlock[b].neighbor[j]);
19253                     blockbou[bouNr].surf[blockbou[bouNr].surfs] = nBlock[b].neighbor[j];
19254                     strcpy(blockbou[bouNr].bctype, dat[n]);
19255                     blockbou[bouNr].nBlock[blockbou[bouNr].surfs] = b;
19256                     blockbou[bouNr].side[blockbou[bouNr].surfs] = j;
19257                     blockbou[bouNr].surfs++;
19258                     break;
19259                   }
19260                 }
19261               }
19262             }
19263 	  }
19264         }
19265 
19266 
19267 	/* search special case 'periodic': replace the duns-surfnr in nBlock[b].neighbor[j] with the periodic blocknr and adapt nBlock[b].map[j][] */
19268 	if(compareStrings(dat[n], "periodic")>0)
19269 	{
19270           if(blockbou[bouNr].surfs!=2)
19271 	  {
19272 	    printf(" ERROR: periodic BC needs a set with 2 lines or surfaces, but stored are %d in set:%s\n",blockbou[bouNr].surfs, blockbou[bouNr].name);
19273 	    return;
19274 	  }
19275           if(nBlock[blockbou[bouNr].nBlock[0]].dim==2)
19276 	  {
19277 		  j=blockbou[bouNr].side[0];   // a periodic bc has exactly 2 sides [0,1]
19278 		  b=blockbou[bouNr].nBlock[0];
19279 		  nBlock[b].neighbor[j]=nBlock[blockbou[bouNr].nBlock[1]].geo;
19280 		  if(blockbou[bouNr].side[0]==0)
19281 		  {
19282                     switch(blockbou[bouNr].side[1])
19283 		    {
19284                     case 0:
19285 		      nBlock[b].map[j][0]=4;
19286 		      nBlock[b].map[j][1]=5;
19287 		      nBlock[b].map[j][2]=3;
19288                     break;
19289                     case 1:
19290 		      nBlock[b].map[j][0]=1;
19291 		      nBlock[b].map[j][1]=2;
19292 		      nBlock[b].map[j][2]=3;
19293                     break;
19294                     case 2:
19295 		      nBlock[b].map[j][0]=5;
19296 		      nBlock[b].map[j][1]=1;
19297 		      nBlock[b].map[j][2]=3;
19298                     break;
19299                     case 3:
19300 		      nBlock[b].map[j][0]=2;
19301 		      nBlock[b].map[j][1]=4;
19302 		      nBlock[b].map[j][2]=3;
19303                     break;
19304 		    }
19305 		  }
19306 		  else if(blockbou[bouNr].side[0]==1)
19307 		  {
19308                     switch(blockbou[bouNr].side[1])
19309 		    {
19310                     case 0:
19311 		      nBlock[b].map[j][0]=1;
19312 		      nBlock[b].map[j][1]=2;
19313 		      nBlock[b].map[j][2]=3;
19314                     break;
19315                     case 1:
19316 		      nBlock[b].map[j][0]=4;
19317 		      nBlock[b].map[j][1]=5;
19318 		      nBlock[b].map[j][2]=3;
19319                     break;
19320                     case 2:
19321 		      nBlock[b].map[j][0]=2;
19322 		      nBlock[b].map[j][1]=4;
19323 		      nBlock[b].map[j][2]=3;
19324                     break;
19325                     case 3:
19326 		      nBlock[b].map[j][0]=5;
19327 		      nBlock[b].map[j][1]=1;
19328 		      nBlock[b].map[j][2]=3;
19329                     break;
19330 		    }
19331 		  }
19332 		  else if(blockbou[bouNr].side[0]==2)
19333 		  {
19334                     switch(blockbou[bouNr].side[1])
19335 		    {
19336                     case 0:
19337 		      nBlock[b].map[j][0]=2;
19338 		      nBlock[b].map[j][1]=4;
19339 		      nBlock[b].map[j][2]=3;
19340                     break;
19341                     case 1:
19342 		      nBlock[b].map[j][0]=5;
19343 		      nBlock[b].map[j][1]=1;
19344 		      nBlock[b].map[j][2]=3;
19345                     break;
19346                     case 2:
19347 		      nBlock[b].map[j][0]=4;
19348 		      nBlock[b].map[j][1]=5;
19349 		      nBlock[b].map[j][2]=3;
19350                     break;
19351                     case 3:
19352 		      nBlock[b].map[j][0]=1;
19353 		      nBlock[b].map[j][1]=2;
19354 		      nBlock[b].map[j][2]=3;
19355                     break;
19356 		    }
19357 		  }
19358 		  else if(blockbou[bouNr].side[0]==3)
19359 		  {
19360                     switch(blockbou[bouNr].side[1])
19361 		    {
19362                     case 0:
19363 		      nBlock[b].map[j][0]=5;
19364 		      nBlock[b].map[j][1]=1;
19365 		      nBlock[b].map[j][2]=3;
19366                     break;
19367                     case 1:
19368 		      nBlock[b].map[j][0]=2;
19369 		      nBlock[b].map[j][1]=4;
19370 		      nBlock[b].map[j][2]=3;
19371                     break;
19372                     case 2:
19373 		      nBlock[b].map[j][0]=1;
19374 		      nBlock[b].map[j][1]=2;
19375 		      nBlock[b].map[j][2]=3;
19376                     break;
19377                     case 3:
19378 		      nBlock[b].map[j][0]=4;
19379 		      nBlock[b].map[j][1]=5;
19380 		      nBlock[b].map[j][2]=3;
19381                     break;
19382 		    }
19383 		  }
19384 		  else { printf("ERROR: side:%d not known\n", blockbou[bouNr].side[0]); return; }
19385 
19386 		  j=blockbou[bouNr].side[1];
19387 		  b=blockbou[bouNr].nBlock[1];
19388 		  nBlock[b].neighbor[j]=nBlock[blockbou[bouNr].nBlock[0]].geo;
19389                   // Remark below 0 and 1 are switched compared to the above block
19390 		  if(blockbou[bouNr].side[1]==0)
19391 		  {
19392                     switch(blockbou[bouNr].side[0])
19393 		    {
19394                     case 0:
19395 		      nBlock[b].map[j][0]=4;
19396 		      nBlock[b].map[j][1]=5;
19397 		      nBlock[b].map[j][2]=3;
19398                     break;
19399                     case 1:
19400 		      nBlock[b].map[j][0]=1;
19401 		      nBlock[b].map[j][1]=2;
19402 		      nBlock[b].map[j][2]=3;
19403                     break;
19404                     case 2:
19405 		      nBlock[b].map[j][0]=5;
19406 		      nBlock[b].map[j][1]=1;
19407 		      nBlock[b].map[j][2]=3;
19408                     break;
19409                     case 3:
19410 		      nBlock[b].map[j][0]=2;
19411 		      nBlock[b].map[j][1]=4;
19412 		      nBlock[b].map[j][2]=3;
19413                     break;
19414 		    }
19415 		  }
19416 		  else if(blockbou[bouNr].side[1]==1)
19417 		  {
19418                     switch(blockbou[bouNr].side[0])
19419 		    {
19420                     case 0:
19421 		      nBlock[b].map[j][0]=1;
19422 		      nBlock[b].map[j][1]=2;
19423 		      nBlock[b].map[j][2]=3;
19424                     break;
19425                     case 1:
19426 		      nBlock[b].map[j][0]=4;
19427 		      nBlock[b].map[j][1]=5;
19428 		      nBlock[b].map[j][2]=3;
19429                     break;
19430                     case 2:
19431 		      nBlock[b].map[j][0]=2;
19432 		      nBlock[b].map[j][1]=4;
19433 		      nBlock[b].map[j][2]=3;
19434                     break;
19435                     case 3:
19436 		      nBlock[b].map[j][0]=5;
19437 		      nBlock[b].map[j][1]=1;
19438 		      nBlock[b].map[j][2]=3;
19439                     break;
19440 		    }
19441 		  }
19442 		  else if(blockbou[bouNr].side[1]==2)
19443 		  {
19444                     switch(blockbou[bouNr].side[0])
19445 		    {
19446                     case 0:
19447 		      nBlock[b].map[j][0]=2;
19448 		      nBlock[b].map[j][1]=4;
19449 		      nBlock[b].map[j][2]=3;
19450                     break;
19451                     case 1:
19452 		      nBlock[b].map[j][0]=5;
19453 		      nBlock[b].map[j][1]=1;
19454 		      nBlock[b].map[j][2]=3;
19455                     break;
19456                     case 2:
19457 		      nBlock[b].map[j][0]=4;
19458 		      nBlock[b].map[j][1]=5;
19459 		      nBlock[b].map[j][2]=3;
19460                     break;
19461                     case 3:
19462 		      nBlock[b].map[j][0]=1;
19463 		      nBlock[b].map[j][1]=2;
19464 		      nBlock[b].map[j][2]=3;
19465                     break;
19466 		    }
19467 		  }
19468 		  else if(blockbou[bouNr].side[1]==3)
19469 		  {
19470                     switch(blockbou[bouNr].side[0])
19471 		    {
19472                     case 0:
19473 		      nBlock[b].map[j][0]=5;
19474 		      nBlock[b].map[j][1]=1;
19475 		      nBlock[b].map[j][2]=3;
19476                     break;
19477                     case 1:
19478 		      nBlock[b].map[j][0]=2;
19479 		      nBlock[b].map[j][1]=4;
19480 		      nBlock[b].map[j][2]=3;
19481                     break;
19482                     case 2:
19483 		      nBlock[b].map[j][0]=1;
19484 		      nBlock[b].map[j][1]=2;
19485 		      nBlock[b].map[j][2]=3;
19486                     break;
19487                     case 3:
19488 		      nBlock[b].map[j][0]=4;
19489 		      nBlock[b].map[j][1]=5;
19490 		      nBlock[b].map[j][2]=3;
19491                     break;
19492 		    }
19493 		  }
19494 	          else { printf("ERROR: side:%d not known\n", blockbou[bouNr].side[1]); return; }
19495 	  }
19496 	  else  // 3D
19497 	  {
19498 	    printf(" WARNING: periodic BC only partly implemented for 3D:\n");
19499 	    printf("   All bodies must have been generated by sweeping a 2D model at once into 3D\n");
19500 	    //return;
19501 
19502 		  j=blockbou[bouNr].side[0];   // a periodic bc has exactly 2 sides [0,1]
19503 		  b=blockbou[bouNr].nBlock[0];
19504 		  nBlock[b].neighbor[j]=nBlock[blockbou[bouNr].nBlock[1]].geo;
19505 		  /*
19506                     blockbou[bouNr].side[0] stores the body surface index
19507                      x: surf0 at u=0
19508                      x: surf1 at umax
19509                    4 : surf2 at w=0
19510                    2 : surf3 at v=0
19511                    5 : surf4 at wmax
19512                    3 : surf5 at vmax
19513 
19514                     dir 1 from 3 (0,1,2) or 'u'('i' in duns manual) must be generated by sweeping of surf0, so nBlock[b].map[j][0] matches always 1
19515                     adjacent blocks can ony exist at surf2-5
19516                     mapping of side nr from 3D to 2D
19517                     3D  2D
19518                    2   0
19519                    3   1
19520                    4   2
19521                    5   3
19522 		   */
19523 		  printf("hallo side0:%d side1:%d\n", blockbou[bouNr].side[0], blockbou[bouNr].side[1]);
19524 		  if(blockbou[bouNr].side[0]==2)
19525 		  {
19526                     switch(blockbou[bouNr].side[1])
19527 		    {
19528                     case 2:
19529 		      nBlock[b].map[j][1]=5;
19530 		      nBlock[b].map[j][2]=6;
19531 		      nBlock[b].map[j][0]=1;
19532                     break;
19533                     case 3:
19534 		      nBlock[b].map[j][1]=2;
19535 		      nBlock[b].map[j][2]=3;
19536 		      nBlock[b].map[j][0]=1;
19537                     break;
19538                     case 4:
19539 		      nBlock[b].map[j][1]=6;
19540 		      nBlock[b].map[j][2]=2;
19541 		      nBlock[b].map[j][0]=1;
19542                     break;
19543                     case 5:
19544 		      nBlock[b].map[j][1]=3;
19545 		      nBlock[b].map[j][2]=5;
19546 		      nBlock[b].map[j][0]=1;
19547                     break;
19548 		    }
19549 		  }
19550 		  else if(blockbou[bouNr].side[0]==3)
19551 		  {
19552                     switch(blockbou[bouNr].side[1])
19553 		    {
19554                     case 2:
19555 		      nBlock[b].map[j][1]=2;
19556 		      nBlock[b].map[j][2]=3;
19557 		      nBlock[b].map[j][0]=1;
19558                     break;
19559                     case 3:
19560 		      nBlock[b].map[j][1]=5;
19561 		      nBlock[b].map[j][2]=6;
19562 		      nBlock[b].map[j][0]=1;
19563                     break;
19564                     case 4:
19565 		      nBlock[b].map[j][1]=3;
19566 		      nBlock[b].map[j][2]=5;
19567 		      nBlock[b].map[j][0]=1;
19568                     break;
19569                     case 5:
19570 		      nBlock[b].map[j][1]=6;
19571 		      nBlock[b].map[j][2]=2;
19572 		      nBlock[b].map[j][0]=1;
19573                     break;
19574 		    }
19575 		  }
19576 		  else if(blockbou[bouNr].side[0]==4)
19577 		  {
19578                     switch(blockbou[bouNr].side[1])
19579 		    {
19580                     case 2:
19581 		      nBlock[b].map[j][1]=3;
19582 		      nBlock[b].map[j][2]=5;
19583 		      nBlock[b].map[j][0]=1;
19584                     break;
19585                     case 3:
19586 		      nBlock[b].map[j][1]=6;
19587 		      nBlock[b].map[j][2]=2;
19588 		      nBlock[b].map[j][0]=1;
19589                     break;
19590                     case 4:
19591 		      nBlock[b].map[j][1]=5;
19592 		      nBlock[b].map[j][2]=6;
19593 		      nBlock[b].map[j][0]=1;
19594                     break;
19595                     case 5:
19596 		      nBlock[b].map[j][1]=2;
19597 		      nBlock[b].map[j][2]=3;
19598 		      nBlock[b].map[j][0]=1;
19599                     break;
19600 		    }
19601 		  }
19602 		  else if(blockbou[bouNr].side[0]==5)
19603 		  {
19604                     switch(blockbou[bouNr].side[1])
19605 		    {
19606                     case 2:
19607 		      nBlock[b].map[j][1]=6;
19608 		      nBlock[b].map[j][2]=2;
19609 		      nBlock[b].map[j][0]=1;
19610                     break;
19611                     case 3:
19612 		      nBlock[b].map[j][1]=3;
19613 		      nBlock[b].map[j][2]=5;
19614 		      nBlock[b].map[j][0]=1;
19615                     break;
19616                     case 4:
19617 		      nBlock[b].map[j][1]=2;
19618 		      nBlock[b].map[j][2]=3;
19619 		      nBlock[b].map[j][0]=1;
19620                     break;
19621                     case 5:
19622 		      nBlock[b].map[j][1]=5;
19623 		      nBlock[b].map[j][2]=6;
19624 		      nBlock[b].map[j][0]=1;
19625                     break;
19626 		    }
19627 		  }
19628 		  else { printf("ERROR: side:%d not known\n", blockbou[bouNr].side[0]); return; }
19629 
19630 		  j=blockbou[bouNr].side[1];
19631 		  b=blockbou[bouNr].nBlock[1];
19632 		  nBlock[b].neighbor[j]=nBlock[blockbou[bouNr].nBlock[0]].geo;
19633                   // Remark below 0 and 1 are switched compared to the above block
19634 		  if(blockbou[bouNr].side[1]==2)
19635 		  {
19636                     switch(blockbou[bouNr].side[0])
19637 		    {
19638                     case 2:
19639 		      nBlock[b].map[j][1]=5;
19640 		      nBlock[b].map[j][2]=6;
19641 		      nBlock[b].map[j][0]=1;
19642                     break;
19643                     case 3:
19644 		      nBlock[b].map[j][1]=2;
19645 		      nBlock[b].map[j][2]=3;
19646 		      nBlock[b].map[j][0]=1;
19647                     break;
19648                     case 4:
19649 		      nBlock[b].map[j][1]=6;
19650 		      nBlock[b].map[j][2]=2;
19651 		      nBlock[b].map[j][0]=1;
19652                     break;
19653                     case 5:
19654 		      nBlock[b].map[j][1]=3;
19655 		      nBlock[b].map[j][2]=5;
19656 		      nBlock[b].map[j][0]=1;
19657                     break;
19658 		    }
19659 		  }
19660 		  else if(blockbou[bouNr].side[1]==3)
19661 		  {
19662                     switch(blockbou[bouNr].side[0])
19663 		    {
19664                     case 2:
19665 		      nBlock[b].map[j][1]=2;
19666 		      nBlock[b].map[j][2]=3;
19667 		      nBlock[b].map[j][0]=1;
19668                     break;
19669                     case 3:
19670 		      nBlock[b].map[j][1]=5;
19671 		      nBlock[b].map[j][2]=6;
19672 		      nBlock[b].map[j][0]=1;
19673                     break;
19674                     case 4:
19675 		      nBlock[b].map[j][1]=3;
19676 		      nBlock[b].map[j][2]=5;
19677 		      nBlock[b].map[j][0]=1;
19678                     break;
19679                     case 5:
19680 		      nBlock[b].map[j][1]=6;
19681 		      nBlock[b].map[j][2]=2;
19682 		      nBlock[b].map[j][0]=1;
19683                     break;
19684 		    }
19685 		  }
19686 		  else if(blockbou[bouNr].side[1]==4)
19687 		  {
19688                     switch(blockbou[bouNr].side[0])
19689 		    {
19690                     case 2:
19691 		      nBlock[b].map[j][1]=3;
19692 		      nBlock[b].map[j][2]=5;
19693 		      nBlock[b].map[j][0]=1;
19694                     break;
19695                     case 3:
19696 		      nBlock[b].map[j][1]=6;
19697 		      nBlock[b].map[j][2]=2;
19698 		      nBlock[b].map[j][0]=1;
19699                     break;
19700                     case 4:
19701 		      nBlock[b].map[j][1]=5;
19702 		      nBlock[b].map[j][2]=6;
19703 		      nBlock[b].map[j][0]=1;
19704                     break;
19705                     case 5:
19706 		      nBlock[b].map[j][1]=2;
19707 		      nBlock[b].map[j][2]=3;
19708 		      nBlock[b].map[j][0]=1;
19709                     break;
19710 		    }
19711 		  }
19712 		  else if(blockbou[bouNr].side[1]==5)
19713 		  {
19714                     switch(blockbou[bouNr].side[0])
19715 		    {
19716                     case 2:
19717 		      nBlock[b].map[j][1]=6;
19718 		      nBlock[b].map[j][2]=2;
19719 		      nBlock[b].map[j][0]=1;
19720                     break;
19721                     case 3:
19722 		      nBlock[b].map[j][1]=3;
19723 		      nBlock[b].map[j][2]=5;
19724 		      nBlock[b].map[j][0]=1;
19725                     break;
19726                     case 4:
19727 		      nBlock[b].map[j][1]=2;
19728 		      nBlock[b].map[j][2]=3;
19729 		      nBlock[b].map[j][0]=1;
19730                     break;
19731                     case 5:
19732 		      nBlock[b].map[j][1]=5;
19733 		      nBlock[b].map[j][2]=6;
19734 		      nBlock[b].map[j][0]=1;
19735                     break;
19736 		    }
19737 		  }
19738 	          else { printf("ERROR: side:%d not known\n", blockbou[bouNr].side[1]); return; }
19739 	  }
19740 
19741           bouNr--;
19742 	}
19743 
19744         n+=2;
19745       }
19746       bouNr++;
19747 
19748       descalNodes ( anz->n, node, scale);
19749       write2duns( setname, anz, node, e_enqire, lcase, nBlock, bouNr, blockbou );
19750       scalNodes ( anz->n, node, scale);
19751 
19752       /* free  */
19753       for(i=0; i<bouNr; i++) free(blockbou[i].surf); free(blockbou);
19754       for(i=0; i<length; i++) free(dat[i]); free(dat);
19755     }
19756   }
19757   else if (compare( format, "foam", 3)== 3)
19758   {
19759     length= strsplt( record, ' ', &dat);
19760     descalNodes ( anz->n, node, scale);
19761     write2foam( setname, length-2, &dat[2], anz, node, face, e_enqire, set, lcase );
19762     scalNodes ( anz->n, node, scale);
19763 
19764     /* free dat */
19765     for(i=0; i<length; i++) free(dat[i]); free(dat);
19766   }
19767   else if (compare( format, "isaac", 3)== 3)
19768   {
19769     length= strsplt( record, ' ', &dat);
19770 
19771     for( b=0; b<anz->b; b++)
19772     {
19773       if(nBlock[b].dim==2)
19774       {
19775         s=nBlock[b].geo;
19776         for(j=0; j<surf[s].nl; j++) strcpy(nBlock[b].bctype[j], "not defined");
19777       }
19778       if(nBlock[b].dim==3)
19779       {
19780         s=nBlock[b].geo;
19781         for(j=0; j<body[s].ns; j++) strcpy(nBlock[b].bctype[j], "not defined");
19782       }
19783     }
19784 
19785     /* add the type of boundary to the grid-blocks */
19786     bouNr=-1;
19787     n=2; while(n<length)
19788     {
19789       /* search the corresponding blocks */
19790       bset=getSetNr(dat[n+1]);
19791       if(bset<0)
19792       {
19793         printf("boundary set:%s does not exist\n", dat[n]);
19794         return;
19795       }
19796       bouNr++;
19797       if((blockbou=(NodeBlockbou *)realloc((NodeBlockbou *)blockbou, (bouNr+1)*sizeof(NodeBlockbou)) )==NULL)
19798       { printf(" ERROR: realloc failure, blockbou:%d could not be allocated\n\n", bouNr ); return; }
19799       strcpy(blockbou[bouNr].name,set[bset].name);
19800       blockbou[bouNr].surf=NULL;
19801       blockbou[bouNr].nBlock=NULL;
19802       blockbou[bouNr].side=NULL;
19803       blockbou[bouNr].surfs=0;
19804 
19805       if(nBlock[b].dim==2)
19806       {
19807        /* add the lcmb to the set */
19808        for(i=0; i<set[bset].anz_l; i++)
19809        {
19810         for(j=0; j<anzGeo->c; j++) if( lcmb[j].name != (char *)NULL )
19811         {
19812           for(l=0; l<lcmb[j].nl; l++)
19813 	  {
19814 	    printf("add lcmb:%s to set %s\n", lcmb[j].name, set[bset].name);
19815             if(lcmb[j].l[l]==set[bset].line[i]) seta(bset, "c", j);
19816 	  }
19817 	}
19818        }
19819       }
19820 
19821       /* look if a member of the set is used by a block */
19822       for( b=0; b<anz->b; b++)
19823       {
19824         if(nBlock[b].dim==2)
19825         {
19826           s=nBlock[b].geo;
19827           for(j=0; j<surf[s].nl; j++)
19828           {
19829             if(nBlock[b].map[j][0]==-1)   // has no neighbor
19830             {
19831               if((blockbou[bouNr].surf=(int *)realloc((int *)blockbou[bouNr].surf, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19832               { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19833               if((blockbou[bouNr].nBlock=(int *)realloc((int *)blockbou[bouNr].nBlock, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19834               { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19835               if((blockbou[bouNr].side=(int *)realloc((int *)blockbou[bouNr].side, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19836               { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19837 
19838               l=surf[s].l[nBlock[b].bcface[j]];
19839               typ=surf[s].typ[nBlock[b].bcface[j]];
19840 
19841               if(typ=='l')
19842               {
19843                 for(i=0; i<set[bset].anz_l; i++)
19844                 {
19845                   if(l==set[bset].line[i])
19846                   {
19847                     printf(" store line %s in set:%s\n",line[l].name ,dat[n]);
19848                     strcpy(nBlock[b].bctype[j], dat[n]);
19849                     printf("set:%s btype:%s bouNr:%d line[%d]:%s block:%d side[%d]:%d\n",set[bset].name, dat[n],bouNr,blockbou[bouNr].surfs, line[set[bset].line[i]].name, nBlock[b].geo+1, j, nBlock[b].neighbor[j]);
19850                     blockbou[bouNr].surf[blockbou[bouNr].surfs] = nBlock[b].neighbor[j];
19851                     strcpy(blockbou[bouNr].bctype, dat[n]);
19852                     blockbou[bouNr].nBlock[blockbou[bouNr].surfs] = b;
19853                     blockbou[bouNr].side[blockbou[bouNr].surfs] = j;
19854                     blockbou[bouNr].surfs++;
19855                     break;
19856                   }
19857                 }
19858               }
19859               if(typ=='c')
19860               {
19861                 for(i=0; i<set[bset].anz_c; i++)
19862                 {
19863                   if(l==set[bset].lcmb[i])
19864                   {
19865                     printf(" store lcmb %s in set:%s \n",lcmb[l].name, dat[n]);
19866                     strcpy(nBlock[b].bctype[j], dat[n]);
19867                     printf("set:%s btype:%s bouNr:%d lcmb[%d]:%s block:%d side:%d\n",set[bset].name, dat[n],bouNr,blockbou[bouNr].surfs, lcmb[set[bset].lcmb[i]].name, nBlock[b].geo+1, nBlock[b].neighbor[j]);
19868                     blockbou[bouNr].surf[blockbou[bouNr].surfs] = nBlock[b].neighbor[j];
19869                     strcpy(blockbou[bouNr].bctype, dat[n]);
19870                     blockbou[bouNr].nBlock[blockbou[bouNr].surfs] = b;
19871                     blockbou[bouNr].side[blockbou[bouNr].surfs] = j;
19872                     blockbou[bouNr].surfs++;
19873                     break;
19874                   }
19875                 }
19876               }
19877 	    }
19878           }
19879         }
19880         if(nBlock[b].dim==3)
19881 	{
19882           v=nBlock[b].geo;
19883           for(i=0; i<set[bset].anz_s; i++)
19884           {
19885             for(j=0; j<body[v].ns; j++)
19886             {
19887               if(nBlock[b].map[j][0]==-1)   // has no neighbor
19888 	      {
19889                 s=body[v].s[nBlock[b].bcface[j]];
19890                 if(s==set[bset].surf[i])
19891                 {
19892                   printf(" store surf %s in set:%s\n", surf[s].name, dat[n]);
19893                   strcpy(nBlock[b].bctype[j], dat[n]);
19894 
19895 		  if((blockbou[bouNr].surf=(int *)realloc((int *)blockbou[bouNr].surf, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19896                   { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19897                   if((blockbou[bouNr].nBlock=(int *)realloc((int *)blockbou[bouNr].nBlock, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19898                   { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19899                   if((blockbou[bouNr].side=(int *)realloc((int *)blockbou[bouNr].side, (blockbou[bouNr].surfs+2)*sizeof(int)) )==NULL)
19900                   { printf(" ERROR: realloc failure, blockbou:%d surface could not be allocated\n\n", bouNr ); return; }
19901 
19902 		    printf("body:%s bsurf:%s surf:%s\n", body[v].name, surf[body[v].s[nBlock[b].bcface[j]]].name, surf[set[bset].surf[i]].name);
19903                   printf("set:%s btype:%s bouNr:%d surf[%d]:%s block:%d duns-side[%d]:%d\n",set[bset].name, dat[n],bouNr,blockbou[bouNr].surfs, surf[set[bset].surf[i]].name, nBlock[b].geo+1, j, nBlock[b].neighbor[j]);
19904                   blockbou[bouNr].surf[blockbou[bouNr].surfs] = nBlock[b].neighbor[j];
19905                   strcpy(blockbou[bouNr].bctype, dat[n]);
19906                   blockbou[bouNr].nBlock[blockbou[bouNr].surfs] = b;
19907                   blockbou[bouNr].side[blockbou[bouNr].surfs] = j;
19908                   blockbou[bouNr].surfs++;
19909                   break;
19910                 }
19911               }
19912             }
19913           }
19914         }
19915       }
19916 
19917       /* search special case 'periodic': replace the cfd-surfnr in nBlock[b].neighbor[j] with the periodic blocknr and adapt nBlock[b].map[j][] */
19918       if(compareStrings(dat[n], "periodic")>0)
19919       {
19920           if(blockbou[bouNr].surfs!=2)
19921 	  {
19922 	    printf(" ERROR: periodic BC needs a set with 2 lines or surfaces, but stored are %d in set:%s\n",blockbou[bouNr].surfs, blockbou[bouNr].name);
19923 	    return;
19924 	  }
19925           if(nBlock[blockbou[bouNr].nBlock[0]].dim==2)
19926 	  {
19927 		  j=blockbou[bouNr].side[0];   // a periodic bc has exactly 2 sides side[0,1]
19928 		  b=blockbou[bouNr].nBlock[0];
19929 		  nBlock[b].neighbor[j]=nBlock[blockbou[bouNr].nBlock[1]].geo;
19930 		  printf(" periodic BC, block:%d side:%d block:%d side:%d\n",nBlock[b].geo+1,blockbou[bouNr].side[0],nBlock[b].neighbor[j],blockbou[bouNr].side[0]);
19931 		  if(blockbou[bouNr].side[0]==0)
19932 		  {
19933                     switch(blockbou[bouNr].side[1])
19934 		    {
19935                     case 0:
19936 		      nBlock[b].map[j][0]=4;
19937 		      nBlock[b].map[j][1]=5;
19938 		      nBlock[b].map[j][2]=3;
19939                     break;
19940                     case 1:
19941 		      nBlock[b].map[j][0]=1;
19942 		      nBlock[b].map[j][1]=2;
19943 		      nBlock[b].map[j][2]=3;
19944                     break;
19945                     case 2:
19946 		      nBlock[b].map[j][0]=5;
19947 		      nBlock[b].map[j][1]=1;
19948 		      nBlock[b].map[j][2]=3;
19949                     break;
19950                     case 3:
19951 		      nBlock[b].map[j][0]=2;
19952 		      nBlock[b].map[j][1]=4;
19953 		      nBlock[b].map[j][2]=3;
19954                     break;
19955 		    }
19956 		  }
19957 		  else if(blockbou[bouNr].side[0]==1)
19958 		  {
19959                     switch(blockbou[bouNr].side[1])
19960 		    {
19961                     case 0:
19962 		      nBlock[b].map[j][0]=1;
19963 		      nBlock[b].map[j][1]=2;
19964 		      nBlock[b].map[j][2]=3;
19965                     break;
19966                     case 1:
19967 		      nBlock[b].map[j][0]=4;
19968 		      nBlock[b].map[j][1]=5;
19969 		      nBlock[b].map[j][2]=3;
19970                     break;
19971                     case 2:
19972 		      nBlock[b].map[j][0]=2;
19973 		      nBlock[b].map[j][1]=4;
19974 		      nBlock[b].map[j][2]=3;
19975                     break;
19976                     case 3:
19977 		      nBlock[b].map[j][0]=5;
19978 		      nBlock[b].map[j][1]=1;
19979 		      nBlock[b].map[j][2]=3;
19980                     break;
19981 		    }
19982 		  }
19983 		  else if(blockbou[bouNr].side[0]==2)
19984 		  {
19985                     switch(blockbou[bouNr].side[1])
19986 		    {
19987                     case 0:
19988 		      nBlock[b].map[j][0]=2;
19989 		      nBlock[b].map[j][1]=4;
19990 		      nBlock[b].map[j][2]=3;
19991                     break;
19992                     case 1:
19993 		      nBlock[b].map[j][0]=5;
19994 		      nBlock[b].map[j][1]=1;
19995 		      nBlock[b].map[j][2]=3;
19996                     break;
19997                     case 2:
19998 		      nBlock[b].map[j][0]=4;
19999 		      nBlock[b].map[j][1]=5;
20000 		      nBlock[b].map[j][2]=3;
20001                     break;
20002                     case 3:
20003 		      nBlock[b].map[j][0]=1;
20004 		      nBlock[b].map[j][1]=2;
20005 		      nBlock[b].map[j][2]=3;
20006                     break;
20007 		    }
20008 		  }
20009 		  else if(blockbou[bouNr].side[0]==3)
20010 		  {
20011                     switch(blockbou[bouNr].side[1])
20012 		    {
20013                     case 0:
20014 		      nBlock[b].map[j][0]=5;
20015 		      nBlock[b].map[j][1]=1;
20016 		      nBlock[b].map[j][2]=3;
20017                     break;
20018                     case 1:
20019 		      nBlock[b].map[j][0]=2;
20020 		      nBlock[b].map[j][1]=4;
20021 		      nBlock[b].map[j][2]=3;
20022                     break;
20023                     case 2:
20024 		      nBlock[b].map[j][0]=1;
20025 		      nBlock[b].map[j][1]=2;
20026 		      nBlock[b].map[j][2]=3;
20027                     break;
20028                     case 3:
20029 		      nBlock[b].map[j][0]=4;
20030 		      nBlock[b].map[j][1]=5;
20031 		      nBlock[b].map[j][2]=3;
20032                     break;
20033 		    }
20034 		  }
20035 		  else { printf("ERROR: side:%d not known\n", blockbou[bouNr].side[0]); return; }
20036 
20037 		  j=blockbou[bouNr].side[1];
20038 		  b=blockbou[bouNr].nBlock[1];
20039 		  nBlock[b].neighbor[j]=nBlock[blockbou[bouNr].nBlock[0]].geo;
20040                   // Remark below 0 and 1 are switched compared to the above block
20041 		  if(blockbou[bouNr].side[1]==0)
20042 		  {
20043                     switch(blockbou[bouNr].side[0])
20044 		    {
20045                     case 0:
20046 		      nBlock[b].map[j][0]=4;
20047 		      nBlock[b].map[j][1]=5;
20048 		      nBlock[b].map[j][2]=3;
20049                     break;
20050                     case 1:
20051 		      nBlock[b].map[j][0]=1;
20052 		      nBlock[b].map[j][1]=2;
20053 		      nBlock[b].map[j][2]=3;
20054                     break;
20055                     case 2:
20056 		      nBlock[b].map[j][0]=5;
20057 		      nBlock[b].map[j][1]=1;
20058 		      nBlock[b].map[j][2]=3;
20059                     break;
20060                     case 3:
20061 		      nBlock[b].map[j][0]=2;
20062 		      nBlock[b].map[j][1]=4;
20063 		      nBlock[b].map[j][2]=3;
20064                     break;
20065 		    }
20066 		  }
20067 		  else if(blockbou[bouNr].side[1]==1)
20068 		  {
20069                     switch(blockbou[bouNr].side[0])
20070 		    {
20071                     case 0:
20072 		      nBlock[b].map[j][0]=1;
20073 		      nBlock[b].map[j][1]=2;
20074 		      nBlock[b].map[j][2]=3;
20075                     break;
20076                     case 1:
20077 		      nBlock[b].map[j][0]=4;
20078 		      nBlock[b].map[j][1]=5;
20079 		      nBlock[b].map[j][2]=3;
20080                     break;
20081                     case 2:
20082 		      nBlock[b].map[j][0]=2;
20083 		      nBlock[b].map[j][1]=4;
20084 		      nBlock[b].map[j][2]=3;
20085                     break;
20086                     case 3:
20087 		      nBlock[b].map[j][0]=5;
20088 		      nBlock[b].map[j][1]=1;
20089 		      nBlock[b].map[j][2]=3;
20090                     break;
20091 		    }
20092 		  }
20093 		  else if(blockbou[bouNr].side[1]==2)
20094 		  {
20095                     switch(blockbou[bouNr].side[0])
20096 		    {
20097                     case 0:
20098 		      nBlock[b].map[j][0]=2;
20099 		      nBlock[b].map[j][1]=4;
20100 		      nBlock[b].map[j][2]=3;
20101                     break;
20102                     case 1:
20103 		      nBlock[b].map[j][0]=5;
20104 		      nBlock[b].map[j][1]=1;
20105 		      nBlock[b].map[j][2]=3;
20106                     break;
20107                     case 2:
20108 		      nBlock[b].map[j][0]=4;
20109 		      nBlock[b].map[j][1]=5;
20110 		      nBlock[b].map[j][2]=3;
20111                     break;
20112                     case 3:
20113 		      nBlock[b].map[j][0]=1;
20114 		      nBlock[b].map[j][1]=2;
20115 		      nBlock[b].map[j][2]=3;
20116                     break;
20117 		    }
20118 		  }
20119 		  else if(blockbou[bouNr].side[1]==3)
20120 		  {
20121                     switch(blockbou[bouNr].side[0])
20122 		    {
20123                     case 0:
20124 		      nBlock[b].map[j][0]=5;
20125 		      nBlock[b].map[j][1]=1;
20126 		      nBlock[b].map[j][2]=3;
20127                     break;
20128                     case 1:
20129 		      nBlock[b].map[j][0]=2;
20130 		      nBlock[b].map[j][1]=4;
20131 		      nBlock[b].map[j][2]=3;
20132                     break;
20133                     case 2:
20134 		      nBlock[b].map[j][0]=1;
20135 		      nBlock[b].map[j][1]=2;
20136 		      nBlock[b].map[j][2]=3;
20137                     break;
20138                     case 3:
20139 		      nBlock[b].map[j][0]=4;
20140 		      nBlock[b].map[j][1]=5;
20141 		      nBlock[b].map[j][2]=3;
20142                     break;
20143 		    }
20144 		  }
20145 	          else { printf("ERROR: side:%d not known\n", blockbou[bouNr].side[1]); return; }
20146 
20147 
20148 		  // fill nBlock[b].strt2[edge][dim],  nBlock[b].end_2[edge][dim]
20149 		  j=blockbou[bouNr].side[0];
20150 		  b=blockbou[bouNr].nBlock[0];
20151 		  s=blockbou[bouNr].side[1];
20152 		  v=blockbou[bouNr].nBlock[1];
20153 		  for(i=0; i<3;i++)
20154 		  {
20155 		    //printf(" a%d:%s e%d:%s d%d, strt1:%d end1:%d\n",b,surf[nBlock[b].geo].name,j,line[surf[nBlock[b].geo].l[j]].name, i+1,  nBlock[b].strt1[j][i],nBlock[b].end_1[j][i]);
20156 		    //printf(" a%d:%s e%d:%s d%d, strt1:%d end1:%d\n",v,surf[nBlock[v].geo].name,s,line[surf[nBlock[v].geo].l[s]].name, i+1, nBlock[v].strt1[s][i],nBlock[v].end_1[s][i]);
20157 		    if(nBlock[v].map[s][i]>3)
20158 		    {
20159 		      nBlock[b].strt2[j][i]=nBlock[v].end_1[s][i];
20160 		      nBlock[b].end_2[j][i]=nBlock[v].strt1[s][i];
20161 		    }
20162 		    else
20163 		    {
20164 		      nBlock[b].strt2[j][i]=nBlock[v].strt1[s][i];
20165 		      nBlock[b].end_2[j][i]=nBlock[v].end_1[s][i];
20166 		    }
20167 		    //printf(" periodic BC b1:%d e%d d%d, b2:%d e:%d d%d strt2:%d end2:%d\n",b,j,nBlock[b].map[j][i], v,s,i+1, nBlock[b].strt2[j][i],nBlock[b].end_2[j][i]);
20168 		  }
20169 
20170 		  anz->c++;
20171 		  anz->c++;
20172 	  }
20173 	  else  // 3D
20174 	  {
20175 	    printf(" ERROR: periodic BC not implemented for 3D\n");
20176 	    return;
20177 	  }
20178 
20179 	bouNr--;
20180       }
20181 
20182       n+=2;
20183     }
20184     bouNr++;
20185 
20186     for( b=0; b<anz->b; b++)
20187     {
20188       if(nBlock[b].dim==2)
20189       {
20190         s=nBlock[b].geo;
20191         for(j=0; j<surf[s].nl; j++)
20192         {
20193           if((surf[s].typ[nBlock[b].bcface[j]]=='l')&&(nBlock[b].bctype[j][0]==0))
20194           {
20195             printf(" WARNING: free surface:%s are not defined as boundary:%s in block: %d\n",line[surf[s].l[nBlock[b].bcface[j]]].name,nBlock[b].bctype[j], nBlock[b].geo+1);
20196           }
20197           if((surf[s].typ[nBlock[b].bcface[j]]=='c')&&(nBlock[b].bctype[j][0]==0))
20198           {
20199             printf(" WARNING: free surface:%s are not defined as boundary:%s in block: %d\n",lcmb[surf[s].l[nBlock[b].bcface[j]]].name,nBlock[b].bctype[j], nBlock[b].geo+1);
20200           }
20201 	}
20202       }
20203       if(nBlock[b].dim==3)
20204       {
20205         s=nBlock[b].geo;
20206         for(j=0; j<body[s].ns; j++)
20207         {
20208           if(nBlock[b].bctype[j][0]==0)
20209           {
20210             printf(" WARNING: free surface:%s are not defined as boundary:%s in block: %d\n",surf[body[s].s[nBlock[b].bcface[j]]].name,nBlock[b].bctype[j], nBlock[b].geo+1);
20211           }
20212 	}
20213       }
20214     }
20215 
20216     descalNodes ( anz->n, node, scale);
20217     write2isaac( setname, anz, node, e_enqire, lcase, nBlock, bouNr, blockbou );
20218     scalNodes ( anz->n, node, scale);
20219 
20220     /* free  */
20221     for(i=0; i<bouNr; i++) free(blockbou[i].surf); free(blockbou);
20222     for(i=0; i<length; i++) free(dat[i]); free(dat);
20223   }
20224   else if (compare( format, "stl", 3)== 3)
20225   {
20226     if(compareStrings( setname, "all" )<=0)
20227     {
20228       printf("ERROR: netgen-format was requested for a subset:%s. Up to now only the faces of the full mesh can be written (set all)\n",setname);
20229       return;
20230     }
20231     if(anz->f<1)
20232     {
20233       printf("ERROR: no faces exist\n");
20234       return;
20235     }
20236 
20237     descalNodes ( anz->n, node, scale);
20238 
20239     handle = fopen ("mesh.stl", "w+b");
20240     if (handle==NULL) { printf ("\nThe output file \"mesh.stl\" could not be opened.\n\n"); return; }
20241     printf (" write surface-mesh data in stl format \n");
20242 
20243     fprintf( handle, "solid\n");
20244     for (i=0; i<anz->f; i++)
20245     {
20246       if (face[i].type == 7)
20247       {
20248         v_result( &node[face[i].nod[0]].nx, &node[face[i].nod[1]].nx, v1);
20249         v_result( &node[face[i].nod[1]].nx, &node[face[i].nod[2]].nx, v2);
20250         v_result( &node[face[i].nod[2]].nx, &node[face[i].nod[0]].nx, v3);
20251         if(v_betrag(v1)==0) continue;
20252         if(v_betrag(v2)==0) continue;
20253         if(v_betrag(v3)==0) continue;
20254         v_prod( v1, v2, v3 );
20255         if(v_norm( v3, v1 )==0) continue;
20256         fprintf( handle, "  facet normal %e %e %e\n",v1[0],v1[1],v1[2]);
20257         fprintf( handle, "    outer loop\n");
20258         for(k=0; k<3; k++)
20259         {
20260           fprintf( handle, "      vertex %e %e %e\n",
20261           node[face[i].nod[k]].nx,
20262           node[face[i].nod[k]].ny,
20263           node[face[i].nod[k]].nz);
20264         }
20265         fprintf( handle, "    endloop\n");
20266         fprintf( handle, "  endfacet\n");
20267       }
20268       else if (face[i].type == 8)
20269       {
20270         for(n=0; n<4; n++)
20271         {
20272           v_result( &node[face[i].nod[tr6[n][0]]].nx, &node[face[i].nod[tr6[n][1]]].nx, v1);
20273           v_result( &node[face[i].nod[tr6[n][1]]].nx, &node[face[i].nod[tr6[n][2]]].nx, v2);
20274           v_result( &node[face[i].nod[tr6[n][2]]].nx, &node[face[i].nod[tr6[n][0]]].nx, v3);
20275           if(v_betrag(v1)==0) continue;
20276           if(v_betrag(v2)==0) continue;
20277           if(v_betrag(v3)==0) continue;
20278           v_prod( v1, v2, v3 );
20279           if(v_norm( v3, v1 )==0) continue;
20280           fprintf( handle, "  facet normal %e %e %e\n",v1[0],v1[1],v1[2]);
20281           fprintf( handle, "    outer loop\n");
20282           for(k=0; k<3; k++)
20283           {
20284             fprintf( handle, "      vertex %e %e %e\n",
20285             node[face[i].nod[tr6[n][k]]].nx,
20286             node[face[i].nod[tr6[n][k]]].ny,
20287             node[face[i].nod[tr6[n][k]]].nz);
20288           }
20289           fprintf( handle, "    endloop\n");
20290           fprintf( handle, "  endfacet\n");
20291         }
20292       }
20293       else if (face[i].type == 9)
20294       {
20295         for(n=0; n<2; n++)
20296         {
20297           v_result( &node[face[i].nod[qu4[n][0]]].nx, &node[face[i].nod[qu4[n][1]]].nx, v1);
20298           v_result( &node[face[i].nod[qu4[n][1]]].nx, &node[face[i].nod[qu4[n][2]]].nx, v2);
20299           v_result( &node[face[i].nod[qu4[n][2]]].nx, &node[face[i].nod[qu4[n][0]]].nx, v3);
20300           if(v_betrag(v1)==0) continue;
20301           if(v_betrag(v2)==0) continue;
20302           if(v_betrag(v3)==0) continue;
20303           v_prod( v1, v2, v3 );
20304           if(v_norm( v3, v1 )==0) continue;
20305           fprintf( handle, "  facet normal %e %e %e\n",v1[0],v1[1],v1[2]);
20306           fprintf( handle, "    outer loop\n");
20307           for(k=0; k<3; k++)
20308           {
20309             fprintf( handle, "      vertex %e %e %e\n",
20310             node[face[i].nod[qu4[n][k]]].nx,
20311             node[face[i].nod[qu4[n][k]]].ny,
20312             node[face[i].nod[qu4[n][k]]].nz);
20313           }
20314           fprintf( handle, "    endloop\n");
20315           fprintf( handle, "  endfacet\n");
20316         }
20317       }
20318       else if (face[i].type ==10)
20319       {
20320         for(n=0; n<8; n++)
20321         {
20322           v_result( &node[face[i].nod[qu8[n][0]]].nx, &node[face[i].nod[qu8[n][1]]].nx, v1);
20323           v_result( &node[face[i].nod[qu8[n][1]]].nx, &node[face[i].nod[qu8[n][2]]].nx, v2);
20324           v_result( &node[face[i].nod[qu8[n][2]]].nx, &node[face[i].nod[qu8[n][0]]].nx, v3);
20325           if(v_betrag(v1)==0) continue;
20326           if(v_betrag(v2)==0) continue;
20327           if(v_betrag(v3)==0) continue;
20328           v_prod( v1, v2, v3 );
20329           if(v_norm( v3, v1 )==0) continue;
20330           fprintf( handle, "  facet normal %e %e %e\n",v1[0],v1[1],v1[2]);
20331           fprintf( handle, "    outer loop\n");
20332           for(k=0; k<3; k++)
20333           {
20334             fprintf( handle, "      vertex %e %e %e\n",
20335             node[face[i].nod[qu8[n][k]]].nx,
20336             node[face[i].nod[qu8[n][k]]].ny,
20337             node[face[i].nod[qu8[n][k]]].nz);
20338           }
20339           fprintf( handle, "    endloop\n");
20340           fprintf( handle, "  endfacet\n");
20341         }
20342       }
20343     }
20344     fprintf( handle, "endsolid\n");
20345     fclose(handle);
20346 
20347     /* write netgen Edges */
20348 
20349     /* write the elements if they are be2 */
20350     j=0;
20351     for (i=0; i<anz->e; i++) if (e_enqire[e_enqire[i].nr].type == 11) j++;
20352     if(j)
20353     {
20354       handle = fopen ("mesh.ned", "w+b");
20355       if (handle==NULL) { printf ("\nThe output file \"mesh.ned\" could not be opened.\n\n"); return; }
20356       printf (" write edge data in ng format \n");
20357       fprintf( handle, "%d\n",j);
20358       printf("write %d edges\n", j);
20359 
20360       for (i=0; i<anz->e; i++)
20361       {
20362         if (e_enqire[e_enqire[i].nr].type == 11)
20363         {
20364           fprintf( handle, "2 %e %e %e %e %e %e\n",
20365           node[e_enqire[e_enqire[i].nr].nod[0]].nx,
20366           node[e_enqire[e_enqire[i].nr].nod[0]].ny,
20367           node[e_enqire[e_enqire[i].nr].nod[0]].nz,
20368           node[e_enqire[e_enqire[i].nr].nod[1]].nx,
20369           node[e_enqire[e_enqire[i].nr].nod[1]].ny,
20370           node[e_enqire[e_enqire[i].nr].nod[1]].nz);
20371         }
20372       }
20373       fclose(handle);
20374     }
20375 
20376     scalNodes ( anz->n, node, scale);
20377   }
20378   else
20379   {
20380     /* assume 'format' is  a second set for the mpc's */
20381     setNr=getSetNr(setname);
20382     if (setNr<0)
20383     {
20384       printf (" ERROR: set:%s does not exist\n", setname);
20385       return;
20386     }
20387     i=getSetNr(format);
20388     if (i>-1)
20389     {
20390        length = sscanf(record, "%*s%*s%s%s%s%s", format, type, val[0], buffer);
20391        if (compare(type, "cycmpcf", 7)==7) cycmpc(setNr, i, "abqf", val[0], buffer);
20392        else if (compare(type, "cycmpc", 6)==6) cycmpc(setNr, i, format, val[0], buffer);
20393        else if (compare(type, "gap", 3)==3) gap(record);
20394        else if (compare(type, "areampc", 7)==7) { areampc(setNr, i, format, type, val[0], buffer, 0, node, 1, 1); }
20395        else
20396        {
20397          errMsg(" ERROR: mpc type %s not yet supported, available are cycmpc or areampc\n", type );
20398          return;
20399        }
20400        /* the additional nodes for the HE20 (then HE26) elements need a new pos.  */
20401        adjustDrawNodes(0);
20402     }
20403     else errMsg(" ERROR: format:%s not yet supported, or set:%s does not exist\n", format, format );
20404   }
20405   printf (" ready\n");
20406 }
20407 
20408 
20409 
20410 /*------------------------------------------------------------------*/
20411 /* Netzdaten im frd, abaqus oder nastran format rausschreiben       */
20412 /*------------------------------------------------------------------*/
20413 
20414 /* syntax: 1,2-8,12, 2-8+2 */
lcparser(char * string,int * lc)20415 void lcparser(char *string, int *lc)
20416 {
20417   int i, i1=0, j, val,pos,inc;
20418   char abuf[134];
20419 
20420   j=0;
20421   pos = strlen(string);
20422 
20423   i=0;
20424   while((string[i]>47)&&(string[i]<58)) { abuf[i-i1]=string[i]; i++;}
20425   abuf[i-i1]=0;
20426   printf("val:%s\n", abuf);
20427   val=atoi(abuf);
20428   j=val-1;
20429   lc[j]=1;
20430   for(; i<=pos; i++)
20431   {
20432     if(string[i]==',')
20433     {
20434       i++;
20435       i1=i;
20436       while((string[i]>47)&&(string[i]<58)) { abuf[i-i1]=string[i]; i++;}
20437       abuf[i-i1]=0;
20438       i--;
20439       val=atoi(abuf);
20440       printf("val:%d\n",val );
20441       j=val-1;
20442       lc[j]=1;
20443     }
20444     else if(string[i]=='-')
20445     {
20446       i++;
20447       i1=i;
20448       while((string[i]>47)&&(string[i]<58)) { abuf[i-i1]=string[i]; i++;}
20449       abuf[i-i1]=0;
20450       val=atoi(abuf);
20451       if(string[i]=='+')
20452       {
20453         i++;
20454         i1=i;
20455         while((string[i]>47)&&(string[i]<58)) { abuf[i-i1]=string[i]; printf("i:%d %d abuf:%c\n", i,i1,abuf[i-i1]); i++;}
20456         abuf[i-i1]=0;
20457         inc=atoi(abuf);
20458       }
20459       else inc=1;
20460       i--;
20461       // printf("inc:%d\n", inc);
20462       printf("val:%d\n", val);
20463       for (;j<val;j+=inc) { lc[j]=1; }
20464     }
20465     else if(string[i]==0) printf("parsed\n");
20466     else
20467     {
20468       printf("ERROR: sign:%c not known\n", string[i]);
20469     }
20470   }
20471 }
20472 
20473 
20474 
write2lst(char * datout,Summen * anz,Nodes * node,Elements * elem)20475 void write2lst( char *datout, Summen *anz, Nodes *node, Elements *elem)
20476 {
20477   FILE *handle1;
20478   int  i,n=0;
20479 
20480   handle1 = fopen (datout, "w+b");
20481   if (handle1==NULL)
20482   {
20483     printf ("\nThe output file \"%s\" could not be opened.\n\n",datout);
20484     return;
20485   }
20486   else  printf (" file %s opened\n",datout);
20487 
20488   printf ("\n write list(lst) file  \n");
20489 
20490   fprintf (handle1, "# nodes\n");
20491   for (i=0; i<anz->n; i++)
20492   {
20493     n++;
20494     fprintf (handle1, " %d", node[i].nr);
20495     if(n>6) { n=0; fprintf (handle1, "\n"); }
20496   }
20497   fprintf (handle1, "\n# elements\n");
20498   n=0;
20499   for (i=0; i<anz->e; i++)
20500   {
20501     n++;
20502     fprintf (handle1, " %d", elem[i].nr);
20503     if(n>6) { n=0; fprintf (handle1, "\n"); }
20504   }
20505   fprintf (handle1, "\n");
20506   fclose(handle1);
20507 }
20508 
20509 
20510 
senddata(char * setname,char * format,Summen * anz,Nodes * node,Elements * e_enqire,Datasets * lcase,Scale * scale,int compFlag,char ** val)20511 void senddata( char *setname, char *format, Summen *anz, Nodes *node, Elements *e_enqire, Datasets *lcase , Scale *scale, int compFlag, char **val)
20512 {
20513   int   setNr;
20514   int  length, i, j, n, ipuf=0, lc,lct, comp;
20515   char prognam[MAX_LINE_LENGTH];
20516   Summen    anz2[1];
20517   Nodes     *node2;
20518   Elements  *elem2;
20519   Datasets *lcase2=NULL;
20520   static int   *isort=NULL;
20521   extern int compareInt();
20522   static int step_number2=0;
20523   FILE *handle;
20524   double dx,dy,dz, sum_l=0.;
20525   int  xl[26];
20526   int *e2=NULL;
20527 #define MM_TO_M  0.001
20528 #define DT_KELVIN_TO_C -273.15
20529 
20530   setNr=getSetNr(setname);
20531   if (setNr<0)
20532   {
20533     printf (" ERROR in senddata, set:%s does not exist\n", setname);
20534     return;
20535   }
20536   /* replace 'lc' by 'ds' */
20537   if(val!=NULL) for(i=0; i<2; i++) if(compare( val[i], "lc", 2)== 2) { val[i][0]='d'; val[i][1]='s'; }
20538   strcpy ( prognam, setname);
20539 
20540   /* set is a sequence-set, tabular format */
20541   if(set[setNr].type)
20542   {
20543     length= strlen ( setname );
20544     strcpy (&prognam[length], ".txt");
20545     handle = fopen (prognam, "w+b" );
20546     if (handle==NULL) { printf ("\nThe output file \"%s\" could not be opened.\n\n", prognam); return;}
20547 
20548     if (compare( format, "seq", 3) == 3)
20549     {
20550       for (n=0; n<set[setNr].anz_n; n++)
20551       {
20552         fprintf ( handle, "%d\n",set[setNr].node[n]);
20553       }
20554       fclose(handle);
20555     }
20556 
20557     /* 1D stress for darwin in tabular format */
20558     if (compare( format, "dar", 3) == 3)
20559     {
20560       fprintf (handle, "# X               sigma\n");
20561       fprintf ( handle, "%-12.5e %-12.5e\n", sum_l* scale->w  * MM_TO_M, lcase[cur_lc].dat[cur_entity][set[setNr].node[0]]);
20562       for (n=1; n<set[setNr].anz_n; n++)
20563       {
20564         dx=node[set[setNr].node[n]].nx - node[set[setNr].node[n-1]].nx;
20565         dy=node[set[setNr].node[n]].ny - node[set[setNr].node[n-1]].ny;
20566         dz=node[set[setNr].node[n]].nz - node[set[setNr].node[n-1]].nz;
20567         sum_l+=sqrt(dx*dx+dy*dy+dz*dz);
20568 
20569         fprintf ( handle, "%-12.5e %-12.5e\n", (sum_l* scale->w) * MM_TO_M, lcase[cur_lc].dat[cur_entity][set[setNr].node[n]] );
20570       }
20571       strcpy(parameter[0], prognam);
20572       write2stack(1, parameter);
20573       fclose(handle);
20574     }
20575     return;
20576   }
20577 
20578   /* check if the format is known, else return */
20579   if ( (compare( format, "frd", 3) == 3)||
20580        (compare( format, "nas", 3) == 3)||
20581        (compare( format, "tcg", 3) == 3)||
20582        (compare( format, "lst", 3) == 3)||
20583        (compare( format, "abq", 3) == 3)||
20584        (compare( format, "ans", 3) == 3)||
20585        (compare( format, "ast", 3) == 3)||
20586        (compare( format, "dar", 3) == 3)||
20587        (compare( format, "sam", 3) == 3)||
20588        (compare( format, "stl", 3) == 3) );
20589   else
20590   {
20591     printf (" ERROR: format not recognized:%s\n\n", format);
20592     return;
20593   }
20594 
20595   descalNodes ( anz->n, node, scale);
20596 
20597   /* if the parameter sur was specified, send only the faces (with dataset) */
20598   if((val!=NULL)&&(compare( val[0], "sur", 3)== 3))
20599   {
20600     if((val!=NULL)&&(compare( val[1], "ds", 2)== 2)) strcpy(val[0],val[1]);
20601     anz2->emax=0;
20602     anz2->emin=MAX_INTEGER;
20603     anz2->e = set[setNr].anz_f;
20604     for (i=0; i<13; i++)
20605       anz2->etype[i] = 0;
20606 
20607     if ( (elem2 = (Elements *)malloc( (set[setNr].anz_f+1) * sizeof(Elements))) == NULL )
20608     { printf(" ERROR: malloc failed in senddata\n\n") ; return; }
20609     if ( (isort = (int *)realloc( isort, (set[setNr].anz_f+1) * sizeof(int))) == NULL )
20610       printf("ERROR: realloc failed: isort\n\n" );
20611     for( i=0; i<set[setNr].anz_f; i++) isort[i]=set[setNr].face[i];
20612     qsort( isort, set[setNr].anz_f, sizeof(int), (void *)compareInt );
20613 
20614     for (i=0; i<set[setNr].anz_f; i++)
20615     {
20616       elem2[i].nr      = anz->enext++;
20617       elem2[i].type    = face[isort[i]].type;
20618       elem2[i].group   = face[isort[i]].group;
20619       elem2[i].mat     = face[isort[i]].mat;
20620       elem2[i].attr    = 0;
20621       anz2->etype[elem2[i].type]++;
20622 
20623       if (anz2->emax<elem2[i].nr ) anz2->emax = elem2[i].nr;
20624       if (anz2->emin>elem2[i].nr ) anz2->emin = elem2[i].nr;
20625       ipuf=0;
20626       if (elem2[i].type == 7) ipuf = 3;  /* TRI3  */
20627       if (elem2[i].type == 8) ipuf = 6;  /* TRI6  */
20628       if (elem2[i].type == 9) ipuf = 4;  /* QUAD4 */
20629       if (elem2[i].type == 10) ipuf = 8; /* QUAD8 */
20630       if (elem2[i].type == 11) ipuf = 2; /* BEAM */
20631       if (elem2[i].type == 12) ipuf = 3; /* BEAM3 */
20632       if (ipuf==0)
20633       {
20634         if(printFlag) printf (" elem(%d) not a known type (%d)\n", elem2[i].nr, elem2[i].type);
20635       }
20636       else
20637       {
20638         if (compFlag)
20639         {
20640           for (j=0; j<ipuf; j++)
20641           {
20642             elem2[i].nod[j]=face[isort[i]].nod[j];
20643             seta( setNr, "n", elem2[i].nod[j] );
20644           }
20645         }
20646         else
20647         {
20648           for (j=0; j<ipuf; j++)
20649           {
20650             elem2[i].nod[j]=face[isort[i]].nod[j];
20651           }
20652         }
20653       }
20654     }
20655   }
20656   /* if the parameter sur was not specified, send the elements (with dataset) */
20657   else
20658   {
20659     if ( (elem2 = (Elements *)malloc( (set[setNr].anz_e+1) * sizeof(Elements))) == NULL )
20660     { printf(" ERROR: malloc failed in senddata\n\n") ; return; }
20661     if ( (isort = (int *)realloc( isort, (set[setNr].anz_e+1) * sizeof(int))) == NULL )
20662       printf("ERROR: realloc failed: isort\n\n" );
20663     for( i=0; i<set[setNr].anz_e; i++) isort[i]=set[setNr].elem[i];
20664     qsort( isort, set[setNr].anz_e, sizeof(int), (void *)compareInt );
20665 
20666     anz2->emax=0;
20667     anz2->emin=MAX_INTEGER;
20668     anz2->e = 0;
20669     elem2[0].nr =0;
20670     for (i=0; i<set[setNr].anz_e; i++)
20671     {
20672       if((i)&&(isort[i]==isort[i-1])) continue;
20673 
20674       elem2[anz2->e].nr      = isort[i];
20675       elem2[anz2->e].type    = e_enqire[isort[i]].type;
20676       elem2[anz2->e].group   = e_enqire[isort[i]].group;
20677       elem2[anz2->e].mat     = e_enqire[isort[i]].mat;
20678       elem2[anz2->e].attr    = e_enqire[isort[i]].attr;
20679 
20680       if (anz2->emax<elem2[anz2->e].nr ) anz2->emax = elem2[anz2->e].nr;
20681       if (anz2->emin>elem2[anz2->e].nr ) anz2->emin = elem2[anz2->e].nr;
20682       ipuf=0;
20683       if (elem2[anz2->e].type == 1) ipuf = 8;  /* HEXA8 */
20684       if (elem2[anz2->e].type == 2) ipuf = 6;  /* PENTA6 */
20685       if (elem2[anz2->e].type == 3) ipuf = 4;  /* TET4 */
20686       if (elem2[anz2->e].type == 4) ipuf = 20; /* HEX20 */
20687       if (elem2[anz2->e].type == 5) ipuf = 15; /* PENTA15 */
20688       if (elem2[anz2->e].type == 6) ipuf = 10; /* TET10 */
20689       if (elem2[anz2->e].type == 7) ipuf = 3;  /* TRI3  */
20690       if (elem2[anz2->e].type == 8) ipuf = 6;  /* TRI6  */
20691       if (elem2[anz2->e].type == 9) ipuf = 4;  /* QUAD4 */
20692       if (elem2[anz2->e].type == 10) ipuf = 8; /* QUAD8 */
20693       if (elem2[anz2->e].type == 11) ipuf = 2; /* BEAM */
20694       if (elem2[anz2->e].type == 12) ipuf = 3; /* BEAM3 */
20695       if (ipuf==0)
20696       {
20697         if(printFlag) printf (" elem(%d) not a known type (%d)\n", elem2[anz2->e].nr, elem2[anz2->e].type);
20698       }
20699       else
20700       {
20701         if (compFlag)
20702         {
20703           for (j=0; j<ipuf; j++)
20704           {
20705             elem2[anz2->e].nod[j]=e_enqire[elem2[anz2->e].nr].nod[j];
20706             seta( setNr, "n", elem2[anz2->e].nod[j] );
20707           }
20708         }
20709         else
20710         {
20711           for (j=0; j<ipuf; j++)
20712           {
20713             elem2[anz2->e].nod[j]=e_enqire[elem2[anz2->e].nr].nod[j];
20714           }
20715         }
20716       }
20717       /* if parameter frdm change penta to hexa */
20718       if ( (format[3]=='m')&&(elem2[anz2->e].type==5) )
20719       {
20720         printf (" elem(%d) of type (%d) will be changed to hex20\n", elem2[anz2->e].nr, elem2[anz2->e].type);
20721 
20722         for(j=0; j<3; j++)
20723         {
20724           xl[j]= elem2[anz2->e].nod[j];
20725         }
20726         xl[j]= xl[j-1];
20727         for(j=4; j<7; j++)
20728         {
20729           xl[j]= elem2[anz2->e].nod[j-1];
20730         }
20731         xl[j]= xl[j-1];
20732         for(j=8; j<10; j++)
20733         {
20734           xl[j]= elem2[anz2->e].nod[j-2];
20735         }
20736         xl[j++]= elem2[anz2->e].nod[2];
20737         xl[j]= elem2[anz2->e].nod[8];
20738 
20739         for(j=12; j<14; j++)
20740         {
20741           xl[j]= elem2[anz2->e].nod[j];
20742         }
20743          xl[j++]= elem2[anz2->e].nod[5];
20744         xl[j]= elem2[anz2->e].nod[14];
20745 
20746         for(j=16; j<19; j++)
20747         {
20748           xl[j]= elem2[anz2->e].nod[j-7];
20749         }
20750         xl[j]= xl[j-1];
20751 
20752 
20753         for(j=0; j<12; j++)
20754         {
20755            elem2[anz2->e].nod[j]=xl[j];
20756         }
20757         for(n=16; n<20; n++)
20758         {
20759            elem2[anz2->e].nod[n]=xl[j];
20760           j++;
20761         }
20762         for(n=12; n<16; n++)
20763         {
20764            elem2[anz2->e].nod[n]=xl[j];
20765           j++;
20766         }
20767 
20768 	elem2[anz2->e].type=4;
20769       }
20770       anz2->etype[elem2[anz2->e].type]++;
20771       anz2->e++;
20772     }
20773   }
20774 
20775   /* nodes must follow the elements (seta n above!) */
20776   /* sort the nodenumbers */
20777 
20778   if ( (node2 = (Nodes *)malloc( (anz->nmax+1) * sizeof(Nodes))) == NULL )
20779     { printf(" ERROR: malloc failed in senddata\n\n") ; return; }
20780 
20781   if ( (isort = (int *)realloc( isort, (set[setNr].anz_n+1) * sizeof(int))) == NULL )
20782     printf("ERROR: realloc failed: isort\n\n" );
20783   for( i=0; i<set[setNr].anz_n; i++) isort[i]=set[setNr].node[i];
20784   qsort( isort, set[setNr].anz_n, sizeof(int), (void *)compareInt  );
20785 
20786   anz2->nmax = 0;
20787   anz2->nmin = MAX_INTEGER;
20788   anz2->n = 0;;
20789   node2[0].nr =0;
20790   for (i=0; i<set[setNr].anz_n; i++)
20791   {
20792     if((i)&&(isort[i]==isort[i-1])) continue;
20793 
20794     node2[anz2->n].nr = isort[i];
20795     node2[isort[i]].nx = node[isort[i]].nx;
20796     node2[isort[i]].ny = node[isort[i]].ny;
20797     node2[isort[i]].nz = node[isort[i]].nz;
20798     if (anz2->nmax<node2[anz2->n].nr) anz2->nmax = node2[anz2->n].nr;
20799     if (anz2->nmin>node2[anz2->n].nr) anz2->nmin = node2[anz2->n].nr;
20800     anz2->n++;
20801   }
20802 
20803   strcpy( anz2->model, setname);
20804   anz2->l = anz->l;
20805   anz2->u = anz->u;
20806   anz2->p = anz->p;
20807   anz2->sets = anz->sets;
20808   anz2->uheader = anz->uheader;
20809   anz2->pheader = anz->pheader;
20810 
20811   if(printFlag) printf (" write file \n");
20812   length= strlen ( setname );
20813 
20814   if (compare( format, "lst", 3) == 3)
20815   {
20816     strcpy (&prognam[length], ".lst");
20817     write2lst( prognam, anz2, node2, elem2);
20818   }
20819   else if (compare( format, "frd", 3) == 3)
20820   {
20821     strcpy (&prognam[length], ".frd");
20822 
20823     /* prepare the Datasets only if ds is specified */
20824     if((val)&&((compare( val[0], "ds", 2)== 2)||(compare( val[0], "bin", 2)== 2)||(compare( val[0], "dbin", 3)== 3)))
20825     {
20826       if(val[0][strlen(val[0])-1]=='+') ipuf=2; else ipuf=0;
20827       if(compare( val[0], "ds", 2)== 2)
20828       {
20829         if(val[0][2]=='l') lc=anz->l;
20830         else lc=atoi(&val[0][2]);
20831       }
20832       else
20833       {
20834         if(val[0][3]=='l') lc=anz->l;
20835         else lc=atoi(&val[0][3]);
20836       }
20837       if(lc<0) lc=anz->l+lc;
20838 
20839       if(lc)
20840       {
20841         lc--;
20842         /* check if the data of the specified lcase (Dataset) are already available */
20843         if (!lcase[lc].loaded)
20844         {
20845           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
20846           {
20847             printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
20848             return;
20849           }
20850           calcDatasets( lc, anz, node, lcase );
20851           recompileEntitiesInMenu(lc);
20852         }
20853         anz2->l = 1;
20854         if ( (lcase2 = (Datasets *)realloc((Datasets *)lcase2, 1 * sizeof(Datasets))) == NULL )
20855         { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
20856 
20857         strcpy(lcase2[0].name, lcase[lc].name);
20858         lcase2[0].value= lcase[lc].value ;
20859         lcase2[0].npheader = lcase[lc].npheader;
20860         lcase2[0].irtype = lcase[lc].irtype;
20861         lcase2[0].step_number=++step_number2;
20862         lcase2[0].analysis_type=lcase[lc].analysis_type;
20863         strcpy(lcase2[0].dataset_name,lcase[lc].dataset_name );
20864         strcpy(lcase2[0].dataset_text,lcase[lc].dataset_text);
20865         strcpy(lcase2[0].analysis_name,lcase[lc].analysis_name);
20866         lcase2[0].pheader=lcase[lc].pheader;
20867         lcase2[0].ncomps=0;
20868         lcase2[0].menu=NULL;
20869         lcase2[0].ictype=NULL;
20870         lcase2[0].icind1=NULL;
20871         lcase2[0].icind2=NULL;
20872         lcase2[0].iexist=NULL;
20873         lcase2[0].max=NULL;
20874         lcase2[0].min=NULL;
20875         lcase2[0].nmax=NULL;
20876         lcase2[0].nmin=NULL;
20877         lcase2[0].dat=NULL;
20878         lcase2[0].compName=NULL;
20879         lcase2[0].icname=NULL;
20880 
20881         if ( (e2 = (int *)realloc(e2,  (lcase[lc].ncomps+1) * sizeof(int))) == NULL )
20882           printf("\n\n ERROR: malloc failed\n\n") ;
20883         if(val[1][0]=='e')
20884         {
20885           for(i=0; i<lcase[lc].ncomps; i++) e2[i]=0;
20886           lcparser(&val[1][1], e2);
20887 	}
20888         else
20889           for(i=0; i<lcase[lc].ncomps; i++) e2[i]=1;
20890 
20891         for(i=0; i<lcase[lc].ncomps; i++)
20892         {
20893           if(e2[i]==1)
20894           {
20895             lcase2[0].ncomps++;
20896 
20897             if ( (lcase2[0].nmax = (int *)realloc( (int *)lcase2[0].nmax, lcase2[0].ncomps * sizeof(int))) == NULL )
20898               printf("\n\n ERROR: malloc failure\n\n" );
20899             if ( (lcase2[0].nmin = (int *)realloc( (int *)lcase2[0].nmin, lcase2[0].ncomps * sizeof(int))) == NULL )
20900               printf("\n\n ERROR: malloc failure\n\n" );
20901             if ( (lcase2[0].max = (float *)realloc((float *)lcase2[0].max, lcase2[0].ncomps * sizeof(float))) == NULL )
20902               printf("\n\n ERROR: malloc failure\n\n" );
20903             if ( (lcase2[0].min = (float *)realloc((float *)lcase2[0].min, lcase2[0].ncomps * sizeof(float))) == NULL )
20904               printf("\n\n ERROR: malloc failure\n\n" );
20905             if ( (lcase2[0].dat = (float **)realloc((float **)lcase2[0].dat, lcase2[0].ncomps * sizeof(float *))) == NULL )
20906               printf("\n\n ERROR: malloc failure\n\n" );
20907             if ( (lcase2[0].compName = (char **)realloc((char **)lcase2[0].compName, lcase2[0].ncomps * sizeof(char *))) == NULL )
20908               printf("\n\n ERROR: malloc failure\n\n" );
20909             if ( (lcase2[0].icname = (char **)realloc((char **)lcase2[0].icname, lcase2[0].ncomps * sizeof(char *))) == NULL )
20910               printf("\n\n ERROR: malloc failure\n\n" );
20911             if ( (lcase2[0].menu = (int *)realloc((int *)lcase2[0].menu, lcase2[0].ncomps * sizeof(int))) == NULL )
20912               printf("\n\n ERROR: malloc failure\n\n" );
20913             if ( (lcase2[0].ictype = (int *)realloc((int *)lcase2[0].ictype, lcase2[0].ncomps * sizeof(int))) == NULL )
20914               printf("\n\n ERROR: malloc failure\n\n" );
20915             if ( (lcase2[0].icind1 = (int *)realloc((int *)lcase2[0].icind1, lcase2[0].ncomps * sizeof(int))) == NULL )
20916               printf("\n\n ERROR: malloc failure\n\n" );
20917             if ( (lcase2[0].icind2 = (int *)realloc((int *)lcase2[0].icind2, lcase2[0].ncomps * sizeof(int))) == NULL )
20918               printf("\n\n ERROR: malloc failure\n\n" );
20919             if ( (lcase2[0].iexist = (int *)realloc((int *)lcase2[0].iexist, lcase2[0].ncomps * sizeof(int))) == NULL )
20920               printf("\n\n ERROR: malloc failure\n\n" );
20921 
20922             comp=lcase2[0].ncomps-1;
20923             if ( (lcase2[0].dat[comp] = (float *)malloc( (anz2->nmax+1) * sizeof(float))) == NULL )
20924               printf("\n\n ERROR: malloc failure\n\n" );
20925             if ( (lcase2[0].compName[comp] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
20926               printf("\n\n ERROR: malloc failed\n\n" );
20927             if ( (lcase2[0].icname[comp] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
20928               printf("\n\n ERROR: malloc failed\n\n" );
20929 
20930             lcase2[0].max[comp]=lcase[lc].max[i];
20931             lcase2[0].min[comp]=lcase[lc].min[i];
20932             strcpy ( lcase2[0].compName[comp], lcase[lc].compName[i]);
20933             lcase2[0].menu[comp]   = lcase[lc].menu[i]  ;
20934             lcase2[0].ictype[comp] = lcase[lc].ictype[i];
20935             lcase2[0].icind1[comp] = lcase[lc].icind1[i];
20936             lcase2[0].icind2[comp] = lcase[lc].icind2[i];
20937             lcase2[0].iexist[comp] = lcase[lc].iexist[i];
20938             for(n=0; n<=anz2->nmax; n++) lcase2[0].dat[comp][n]=lcase[lc].dat[i][n];
20939           }
20940 	}
20941 	  // check the type of the components and if all components are available
20942           for(i=0; i<lcase2[0].ncomps; i++)
20943           {
20944 	    // vector
20945 	    if(lcase2[0].ictype[i]==2)
20946 	    {
20947 	      // not enough comps for a vector?
20948 	      if(lcase2[0].ncomps<i+3)
20949 	      {
20950 		lcase2[0].ictype[i]=1;
20951 	      }
20952 	      // check the next two comps
20953 	      else
20954 	      {
20955 		if((lcase2[0].ictype[i+1]!=2)||(lcase2[0].ictype[i+2]!=2))
20956 		lcase2[0].ictype[i+1]=lcase2[0].ictype[i+2]=1;
20957 	        i=i+2;
20958 	      }
20959 	    }
20960 	    // tensor
20961 	    if(lcase2[0].ictype[i]==4)
20962 	    {
20963 	      // not enough comps for a vector?
20964 	      if(lcase2[0].ncomps<i+6)
20965 	      {
20966 		lcase2[0].ictype[i]=1;
20967 	      }
20968 	      // check the next 5 comps
20969 	      else
20970 	      {
20971 		if((lcase2[0].ictype[i+1]!=4)||(lcase2[0].ictype[i+2]!=4)||(lcase2[0].ictype[i+3]!=4)||(lcase2[0].ictype[i+4]!=4)||(lcase2[0].ictype[i+5]!=4))
20972 		lcase2[0].ictype[i+1]=lcase2[0].ictype[i+2]=lcase2[0].ictype[i+3]=lcase2[0].ictype[i+4]=lcase2[0].ictype[i+5]=1;
20973 	        i=i+5;
20974 	      }
20975 	    }
20976 	    // complex vec
20977 	    if(lcase2[0].ictype[i]==12)
20978 	    {
20979 	      // not enough comps for a vector?
20980 	      if(lcase2[0].ncomps<i+6)
20981 	      {
20982 		lcase2[0].ictype[i]=1;
20983 	      }
20984 	      // check the next 5 comps
20985 	      else
20986 	      {
20987 		if((lcase2[0].ictype[i+1]!=12)||(lcase2[0].ictype[i+2]!=12)||(lcase2[0].ictype[i+3]!=12)||(lcase2[0].ictype[i+4]!=12)||(lcase2[0].ictype[i+5]!=12))
20988 		lcase2[0].ictype[i+1]=lcase2[0].ictype[i+2]=lcase2[0].ictype[i+3]=lcase2[0].ictype[i+4]=lcase2[0].ictype[i+5]=1;
20989 	        i=i+5;
20990 	      }
20991 	    }
20992 	    // complex tens
20993 	    if(lcase2[0].ictype[i]==14)
20994 	    {
20995 	      // not enough comps for a vector?
20996 	      if(lcase2[0].ncomps<i+12)
20997 	      {
20998 		lcase2[0].ictype[i]=1;
20999 	      }
21000 	      // check the next 5 comps
21001 	      else
21002 	      {
21003 		if((lcase2[0].ictype[i+1]!=14)||(lcase2[0].ictype[i+2]!=14)||(lcase2[0].ictype[i+3]!=14)||(lcase2[0].ictype[i+4]!=14)||(lcase2[0].ictype[i+5]!=14)
21004 		||(lcase2[0].ictype[i+6]!=14)||(lcase2[0].ictype[i+7]!=14)||(lcase2[0].ictype[i+8]!=14)||(lcase2[0].ictype[i+9]!=14)||(lcase2[0].ictype[i+10]!=14)
21005 		||(lcase2[0].ictype[i+11]!=14))
21006 		lcase2[0].ictype[i+1]=lcase2[0].ictype[i+2]=lcase2[0].ictype[i+3]=lcase2[0].ictype[i+4]=lcase2[0].ictype[i+5]=
21007 		lcase2[0].ictype[i+6]=lcase2[0].ictype[i+7]=lcase2[0].ictype[i+8]=lcase2[0].ictype[i+9]=lcase2[0].ictype[i+10]=
21008 		lcase2[0].ictype[i+11]=1;
21009 	        i=i+11;
21010 	      }
21011 	    }
21012 	}
21013         write2frd( prognam, anz2, node2, elem2, lcase2, ipuf);
21014 
21015         if(lcase2[0].ncomps)
21016 	{
21017           for(i=0; i<lcase2[0].ncomps; i++)
21018           {
21019             free( lcase2[0].icname[i]); free( lcase2[0].compName[i]); free(lcase2[0].dat[i]);
21020           }
21021           free( lcase2[0].menu);
21022           free( lcase2[0].ictype);
21023           free( lcase2[0].icind1);
21024           free( lcase2[0].icind2);
21025           free( lcase2[0].iexist);
21026           free( lcase2[0].max);
21027           free( lcase2[0].min);
21028           free( lcase2[0].nmax);
21029           free( lcase2[0].nmin);
21030           free( lcase2[0].dat);
21031           free( lcase2[0].compName);
21032           free( lcase2[0].icname);
21033 	}
21034       }
21035       else
21036       {
21037        for(lc=0; lc<anz->l; lc++)
21038        {
21039         /* check if the data of the specified lcase (Dataset) are already available */
21040         if (!lcase[lc].loaded)
21041         {
21042           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21043           {
21044             printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21045             return;
21046           }
21047           calcDatasets( lc, anz, node, lcase );
21048           recompileEntitiesInMenu(lc);
21049         }
21050        }
21051        if(compare( val[0], "bin", 2)== 2) write2frd( prognam, anz2, node2, elem2, lcase, 1);
21052        else if(compare( val[0], "dbin", 3)== 3) write2frd( prognam, anz2, node2, elem2, lcase, 3);
21053        else  write2frd( prognam, anz2, node2, elem2, lcase, ipuf);
21054       }
21055     }
21056     else
21057     {
21058       anz2->l = 0;
21059       write2frd( prognam, anz2, node2, elem2, lcase, 0);
21060     }
21061   }
21062   else if (compare( format, "nas", 3) == 3)
21063   {
21064     /* prepare the Datasets only if ds is specified */
21065     if((val)&&(compare( val[0], "ds", 2)== 2))
21066     {
21067       for(lc=0; lc<anz->l; lc++)
21068       {
21069         /* check if the data of the specified lcase (Dataset) are already available */
21070         if (!lcase[lc].loaded)
21071         {
21072           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21073           {
21074             printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21075             return;
21076           }
21077           calcDatasets( lc, anz, node, lcase );
21078           recompileEntitiesInMenu(lc);
21079         }
21080       }
21081     }
21082     else     anz2->l = 0;
21083 
21084     /* in case a coordinate system for nodes regarding the DOFs was defined */
21085     for (i=0; i<anz2->n; i++) node2[node2[i].nr].pflag=0;
21086     if(nodeCsys)
21087     {
21088       for(j=0; j<nodeCsys; j++)
21089       {
21090         printf(" nodes of set:%s get csys:%d\n", set[nodeCsysSet[j]].name, nodeCsysNr[j]);
21091         for (i=0; i<set[nodeCsysSet[j]].anz_n; i++) node2[set[nodeCsysSet[j]].node[i]].pflag=nodeCsysNr[j];
21092       }
21093     }
21094     write2nas( prognam, anz2, node2, elem2, lcase);
21095   }
21096   else if (compare( format, "abq", 3) == 3)
21097   {
21098     if(val)
21099     {
21100      if(compare( val[0], "ds", 2)== 2)
21101      {
21102        if(val[0][strlen(val[0])-1]=='+') ipuf=2; else ipuf=0;
21103        lc=atoi(&val[0][2])-1;
21104        if(lc==-1)
21105        {
21106          printf("\n ERROR: No dataset nr was given, only one dataset at a time can be written.\n\n");
21107 	 return;
21108        }
21109        /* check if the data of the specified lcase (Dataset) are already available */
21110        if (!lcase[lc].loaded)
21111        {
21112          if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21113          {
21114            printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21115            return;
21116          }
21117          calcDatasets( lc, anz, node, lcase );
21118          recompileEntitiesInMenu(lc);
21119        }
21120      }
21121      if((compare( val[0], "tmf", 3)== 3)||(compare( val[0], "sta", 3)== 3)||(compare( val[0], "crp", 3)== 3))
21122      {
21123       for(lc=0; lc<anz->l; lc++)
21124       {
21125         /* check if the data of the specified lcase (Dataset) are already available */
21126         if (!lcase[lc].loaded)
21127         {
21128           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21129           {
21130             printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21131             return;
21132           }
21133           calcDatasets( lc, anz, node, lcase );
21134           recompileEntitiesInMenu(lc);
21135         }
21136       }
21137      }
21138     }
21139 
21140     /* write the equations for incompatible elements */
21141     for(i=0; i<sum_equSets; i++)
21142     {
21143       /* temporary change the element-type to exclude unwanted elements */
21144       for(j=0; j<anz->e; j++) e_enqire[e_enqire[j].nr].type+=100;
21145       for(j=0; j<set[indSet[i]].anz_e; j++) e_enqire[set[indSet[i]].elem[j]].type-=100;
21146 
21147       /* gen mpcs */
21148       rnam(depSet[i], &set[depSet[i]].name[1]);
21149       areampc(depSet[i], indSet[i], "abq", "areampc", "123", "c", 0, node, 1, 1);
21150 
21151       /* restore orig type */
21152       for(j=0; j<set[indSet[i]].anz_e; j++) e_enqire[set[indSet[i]].elem[j]].type+=100;
21153       for(j=0; j<anz->e; j++) e_enqire[e_enqire[j].nr].type-=100;
21154     }
21155 
21156     write2aba( prognam, anz2, node2, elem2, lcase, val, ipuf);
21157 
21158     /* add the equations to the mesh-file */
21159     for(i=0; i<sum_equSets; i++)
21160     {
21161       sprintf(buffer,"cat %s.equ >> %s", set[depSet[i]].name, prognam);
21162       system(buffer);
21163       sprintf(buffer,"rm -f %s.equ", set[depSet[i]].name);
21164       system(buffer);
21165       sprintf(buffer,"-%s", set[depSet[i]].name);
21166       rnam(depSet[i], buffer);
21167     }
21168   }
21169   else if (compare( format, "dar", 3) == 3)
21170   {
21171     /* prepare the Datasets only if ds is specified */
21172     if((val)&&(val[0][0]=='v'));
21173     else if((val)&&(compare( val[0], "ds", 2)== 2))
21174     {
21175       lc=atoi(&val[0][2]);
21176       if(lc)
21177       {
21178         lc--;
21179 
21180         /* check if the data of the specified lcase (Dataset) are already available */
21181         if (!lcase[lc].loaded)
21182         {
21183           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21184           {
21185             printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21186             return;
21187           }
21188           calcDatasets( lc, anz, node, lcase );
21189           recompileEntitiesInMenu(lc);
21190         }
21191 
21192         /* search for related temps */
21193         //if(lc>0) { lct=lc-1; while((lcase[lct].step_number==lcase[lc].step_number)&&(lct>0)) lct--; lct++; }
21194         if(lc) { for (lct=lc-1; lct>=0; lct--) { if(lcase[lct].step_number!=lcase[lc].step_number) break; } lct++; }
21195         else lct=1;
21196         while((lct<anz->l)&&(lcase[lct].step_number==lcase[lc].step_number))
21197         {
21198           if( (compare( lcase[lct].name, "NDTEMP", 6) == 6)||( compare( lcase[lct].name, "TEMP", 4) == 4)||( compare( lcase[lct].name, "TT3D", 4) == 4))
21199           {
21200             if (!lcase[lc].loaded)
21201             {
21202               if( pre_readfrdblock(copiedNodeSets , lct, anz, node, lcase )==-1)
21203               {
21204                 printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lct+1);
21205                 return;
21206               }
21207               calcDatasets( lct, anz, node, lcase );
21208               recompileEntitiesInMenu(lct);
21209             }
21210           }
21211           lct++;
21212         }
21213       }
21214       else
21215       {
21216        for(lc=0; lc<anz->l; lc++)
21217        {
21218         /* check if the data of the specified lcase (Dataset) are already available */
21219         if (!lcase[lc].loaded)
21220         {
21221           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21222           {
21223             printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21224             return;
21225           }
21226           calcDatasets( lc, anz, node, lcase );
21227           recompileEntitiesInMenu(lc);
21228         }
21229        }
21230       }
21231     }
21232     else val=0;
21233     write2darwin( prognam, anz2, node2, elem2, lcase, val);
21234   }
21235   else if (compare( format, "ans", 3) == 3)
21236   {
21237     if(val)
21238     {
21239      if(compare( val[0], "ds", 2)== 2)
21240      {
21241        lc=atoi(&val[0][2])-1;
21242        if(lc==-1)
21243        {
21244          printf("\n ERROR: No dataset nr was given, only one dataset at a time can be written.\n\n");
21245 	 return;
21246        }
21247        /* check if the data of the specified lcase (Dataset) are already available */
21248        if (!lcase[lc].loaded)
21249        {
21250          if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21251          {
21252            printf(" ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21253            return;
21254          }
21255          calcDatasets( lc, anz, node, lcase );
21256          recompileEntitiesInMenu(lc);
21257        }
21258      }
21259      if((compare( val[0], "tmf", 3)== 3)||(compare( val[0], "sta", 3)== 3)||(compare( val[0], "crp", 3)== 3))
21260      {
21261       for(lc=0; lc<anz->l; lc++)
21262       {
21263         /* check if the data of the specified lcase (Dataset) are already available */
21264         if (!lcase[lc].loaded)
21265         {
21266           if( pre_readfrdblock(copiedNodeSets , lc, anz, node, lcase )==-1)
21267           {
21268             printf("ERROR in nodalDataset: Could not read data for Dataset:%d\n", lc+1);
21269             return;
21270           }
21271           calcDatasets( lc, anz, node, lcase );
21272           recompileEntitiesInMenu(lc);
21273         }
21274       }
21275      }
21276     }
21277     else { anz2->l = 0; }
21278     write2ansys( prognam, anz2, node2, elem2, lcase, val);
21279   }
21280   else if (compare( format, "ast", 3) == 3)
21281   {
21282     anz2->l = 0;
21283     write2aster( prognam, anz2, node2, elem2, set, lcase);  //TODD
21284   }
21285   else if (compare( format, "sam", 3) == 3)
21286   {
21287     anz2->l = 0;
21288     write2samcef( prognam, anz2, node2, elem2, lcase);
21289   }
21290   else if (compare( format, "tcg", 3) == 3)
21291   {
21292     anz2->l = 0;
21293     write2tochnog( prognam, anz2, node2, elem2, lcase);
21294   }
21295   else
21296     printf (" ERROR: Format not recognized");
21297 
21298   free(node2);
21299   free(elem2);
21300   scalNodes ( anz->n, node, scale );
21301 
21302   strcpy(parameter[0], prognam);
21303   write2stack(1, parameter);
21304 }
21305 
21306 
21307 
setMaterial_rgb(int col,float alpha)21308 void setMaterial_rgb(int col, float alpha)
21309 {
21310   GLfloat mat_shininess; /* 0->128 Blankheit */
21311   GLfloat mat_specular[4]; /* ungerichtete reflektion*/
21312   GLfloat mat_diffuse[4];  /* gerichtete reflektion*/
21313   mat_shininess= 120.;    /* blankheit, wirkt nicht wg lichtrichtung */
21314 
21315   mat_specular[0]=MAT_SPEC;
21316   mat_specular[1]=MAT_SPEC;
21317   mat_specular[2]=MAT_SPEC;
21318   /*
21319   mat_specular[0]=entitycol[col].r;  //MAT_SPEC
21320   mat_specular[1]=entitycol[col].g;
21321   mat_specular[2]=entitycol[col].b;
21322   */
21323   mat_specular[3]=alpha;
21324 
21325   mat_diffuse[0]=entitycol[col].r;
21326   mat_diffuse[1]=entitycol[col].g;
21327   mat_diffuse[2]=entitycol[col].b;
21328   /*
21329   mat_diffuse[0]=0;
21330   mat_diffuse[1]=0;
21331   mat_diffuse[2]=0;
21332   */
21333   mat_diffuse[3]=alpha;
21334 
21335   /* Reflexionseigenschaften des Materials aufbringen */
21336   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
21337   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,   mat_diffuse);
21338   //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,   mat_diffuse);
21339   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  mat_specular);
21340 }
21341