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 /* Bugs:
24 */
25
26 #define TEST 0
27
28 /* temporary conversion from old to new bias definition */
29 extern int OLD_BIAS_DEF;
30 int old_bias_def;
31
32 #include <cgx.h>
33 #include <sys/utsname.h>
34
35 extern struct utsname cursys[1];
36
37 extern int ddiv;
38 extern double dbias;
39
40 extern Scale scale[1];
41 extern Summen anz[1];
42 extern Nodes *node;
43 extern Elements *e_enqire;
44 extern Datasets *lcase;
45 extern Faces *face;
46 extern Alias *alias;
47 extern Sets *set;
48 extern Shapes *shape;
49 extern Values *value;
50 extern Points *point;
51 extern Lines *line;
52 extern Lcmb *lcmb;
53 extern Gsur *surf;
54 extern Gbod *body;
55 extern Nurbl *nurbl;
56 extern Nurbs *nurbs;
57 extern SumGeo anzGeo[1];
58 extern SumAsci sumAsci[1];
59
60
61 extern char printFlag; /* printf on/off */
62 extern char delPntFlag; /* 1: deleted points exists */
63 extern char delShapeFlag; /* 1: deleted shapes exists */
64 extern char delLineFlag; /* 1: deleted lines exists */
65 extern char delLcmbFlag; /* 1: deleted lcmbs exists */
66 extern char delSurfFlag; /* 1: deleted surfs exists */
67 extern char delBodyFlag; /* 1: deleted bodys exists */
68 extern char delNursFlag;
69
70 extern char **valuestack;
71 extern int valuestack_ptr, valuestackFlag;
72 extern SpecialSet specialset[1];
73 extern GLint gl_max_eval_order; /* max order of NURBS */
74 extern int setall;
75
76 extern char **parameter;
77
78
79
80 /*------------------------------------------------------------------*/
81 /* define node */
82 /*------------------------------------------------------------------*/
83
delNod(int anzn,int * index)84 void delNod( int anzn, int *index )
85 {
86 int j,k;
87 int *buf; /* must be, else error because *index could be from a set (which is manipul.) */
88
89 if( (buf=(int *)malloc((anzn+1)*sizeof(int) ) )==NULL)
90 { printf(" ERROR: malloc failure\n"); return; }
91 for (j=0; j<anzn; j++) buf[j]=index[j];
92
93 for (j=0; j<anzn; j++)
94 {
95 if(node[buf[j]].pflag==-1) continue;
96 if(printFlag) printf (" delete node:%d\n",buf[j] );
97 for (k=0; k<anz->sets; k++)
98 {
99 if( set[k].name != (char *)NULL ) setr( k, "n", buf[j]);
100 }
101 node[buf[j]].pflag=-1;
102 }
103 free(buf);
104
105 /* search the last valid node */
106 while(node[anz->nmax].pflag==-1) { anz->nmax--; anz->n--; }
107 if(anz->nnext>anz->nmax) anz->nnext=anz->nmax+1;
108 }
109
110
111
112
113 /* WARNING: */
114 /* - before use: delete all midface-nodes for he20 etc. (see pre_nod()) or you might use a certain node-nr twice! */
115 /* - also switch back to the undeformed nodes with: if(addDispFlag==1) addDispToCoordinates(node); */
nod(Summen * anz,Nodes ** nptr,int setFlag,int nodnr,double x,double y,double z,int scalFlag)116 int nod( Summen *anz, Nodes **nptr, int setFlag, int nodnr, double x, double y, double z, int scalFlag)
117 {
118 int nr, i, lc;
119 Nodes *node;
120
121 node=*nptr;
122 //if(setFlag) { nr=getNodNr(anz, node, nodnr); }
123 //else nr=-1;
124 nr=getNodNr(anz, node, nodnr);
125 if (nr==-1) /* new node */
126 {
127 if(nodnr>anz->nmax)
128 {
129 #if TEST
130 printf(" create nod:%d %x\n", nodnr, node);
131 #endif
132 if ((node = (Nodes *)realloc( (Nodes *)node, (nodnr+1)*sizeof(Nodes)) ) == NULL )
133 { errMsg("ERROR: realloc failure in nod, node:%d not installed\n", nodnr); return(-1); }
134 #if TEST
135 printf(" create nod:%d %x\n", nodnr, node);
136 #endif
137 *nptr=node;
138 for(i=anz->nmax+1; i<=nodnr; i++) node[i].indx=-1;
139 anz->nmax=nodnr;
140 }
141 if ( nodnr < anz->nmin ) anz->nmin=nodnr;
142 *nptr = node;
143 nr=anz->n++;
144 node[nr].nr=nodnr;
145 node[node[nr].nr].indx=nr;
146 node[node[nr].nr].pflag=0;
147
148 /* extend the lc by the new node */
149 for (lc=0; lc<anz->l; lc++)
150 {
151 if (lcase[lc].loaded)
152 {
153 for(i=0; i<lcase[lc].ncomps; i++)
154 {
155 if ( (lcase[lc].dat[i] = (float *)realloc(lcase[lc].dat[i], (anz->nmax+1) * sizeof(float))) == NULL )
156 printf("\n\n ERROR: realloc failure nod\n\n" );
157 lcase[lc].dat[i][nodnr]=0.;
158 }
159 }
160 }
161 if(printFlag) printf (" new Node %d nodnr %d anz->nmax %d \n", nr, nodnr,anz->nmax);
162 }
163 else if(nr<-1) /* replace a deleted node */
164 {
165 nr=-(nr+10);
166 if(printFlag) printf (" Node %d nodnr %d anz->nmax %d, use a deleted node\n", nr, nodnr,anz->nmax);
167 node[node[nr].nr].pflag=0;
168 }
169 else
170 {
171 if(printFlag) printf (" Node %d nodnr %d anz->nmax %d in use: Koordinates will be changed\n", nr, nodnr,node[nr].nr);
172 node[node[nr].nr].pflag=0;
173 }
174
175 if (setFlag)
176 {
177 for (i=0; i<anz->sets; i++)
178 {
179 if ( set[i].flag=='o') seta( i, "n", nodnr );
180 }
181 }
182
183 if(scalFlag)
184 {
185 node[nodnr].nx=(x-scale->x)/scale->w;
186 node[nodnr].ny=(y-scale->y)/scale->w;
187 node[nodnr].nz=(z-scale->z)/scale->w;
188 }
189 else
190 {
191 node[nodnr].nx=x;
192 node[nodnr].ny=y;
193 node[nodnr].nz=z;
194 }
195 node[nodnr].nv[0]=node[nodnr].nv[1]=node[nodnr].nv[2]=0.;
196
197 return(nr);
198 }
199
pre_nod(char * record)200 int pre_nod( char *record)
201 {
202 int i,nr,updFlag=1;
203 char nrs[MAX_LINE_LENGTH];
204 double x=0.,y=0.,z=0.;
205
206 sscanf( record, "%s %lf %lf %lf %d\n", nrs, &x, &y, &z, &updFlag);
207 if(nrs[0]=='!') nr=anz->nnext;
208 else nr=atoi(nrs);
209 if(nr<1) { printf (" prnt: node:%d is not a valid nr\n", nr); return(0); }
210 if(printFlag) printf("node:%d x:%lf y:%lf z:%lf \n", nr, x, y, z);
211
212 /* free the additional midside-nodes for higher order elements */
213 for(i=anz->orign; i<anz->n; i++) node[node[i].nr].pflag=-1;
214 anz->n= anz->orign;
215 anz->nmax=anz->orignmax;
216
217 // next automatic nr is not incremented if a nr below nnext is specified
218 if(nr>=anz->nnext) anz->nnext=nr+1;
219 nr=nod( anz, &node, 1, nr, x, y, z, 1);
220
221 /* new midnodes */
222 if(updFlag)
223 {
224 adjustDrawNodes(1);
225 makeSurfaces(); // includes getFaceNormalen
226 getElemNormalen( e_enqire, node, anz->e );
227 realloc_colNr();
228 updateDispLists();
229 }
230 if( nr <0)
231 {
232 printf("ERROR: node could not be created\n");
233 return(0);
234 }
235 else return(node[nr].nr);
236 }
237
238
239 /*------------------------------------------------------------------*/
240 /* define elements */
241 /*------------------------------------------------------------------*/
242
243 /* delElem() if introduced must provide that e_enquire[].nr is defined without holes */
delElem(int anze,int * index)244 void delElem( int anze, int *index )
245 {
246 int j,k,e,n,anz_e,anz_emax,ipuf;
247 int *buf; /* index must be buffered, because *index could be from a set (which is manipul.) */
248 Elements *elem=NULL;
249
250 if( (buf=(int *)malloc((anze+1)*sizeof(int) ) )==NULL)
251 { printf(" ERROR: malloc failure\n"); return; }
252 for (j=0; j<anze; j++) buf[j]=index[j];
253
254 for (j=0; j<anze; j++)
255 {
256 if(printFlag) printf (" delete element:%d\n",buf[j] );
257 if(e_enqire[buf[j]].type>0)
258 {
259 for (k=0; k<anzGeo->l; k++)
260 {
261 for (n=0; n<line[k].ne; n++)
262 {
263 if(line[k].elem[n]==buf[j]) line[k].elem[n]=0;
264 }
265 e=0;
266 for(n=0; n<line[k].ne; n++) if(line[k].elem[n]>0) line[k].elem[e++]=line[k].elem[n];
267 line[k].ne=e;
268 }
269 for (k=0; k<anzGeo->s; k++)
270 {
271 for (n=0; n<surf[k].ne; n++)
272 {
273 if(surf[k].elem[n]==buf[j]) surf[k].elem[n]=0;
274 }
275 e=0;
276 for(n=0; n<surf[k].ne; n++) if(surf[k].elem[n]>0) surf[k].elem[e++]=surf[k].elem[n];
277 surf[k].ne=e;
278 }
279 for (k=0; k<anzGeo->b; k++)
280 {
281 for (n=0; n<body[k].ne; n++)
282 {
283 if(body[k].elem[n]==buf[j]) body[k].elem[n]=0;
284 }
285 e=0;
286 for(n=0; n<body[k].ne; n++) if(body[k].elem[n]>0) body[k].elem[e++]=body[k].elem[n];
287 body[k].ne=e;
288 }
289 }
290 for (k=0; k<anz->sets; k++)
291 {
292 if( set[k].name != (char *)NULL )
293 {
294 e=set[k].anz_e;
295 setr( k, "e", buf[j]);
296 }
297 }
298 e_enqire[buf[j]].type=0;
299 }
300 free(buf);
301
302 /* create a new element data structure */
303 anz_e=anz->e;
304 anz_emax=anz->emax;
305 for(j=0; j<100; j++) anz->etype[j]=0;
306 anz->emax=0; anz->emin=MAX_INTEGER;
307 anz->e=0;
308 anz->enext=1;
309 if((elem=(Elements *)realloc((Elements *)elem,(anz_emax+1)*sizeof(Elements)))==NULL)
310 {
311 printf("\n\n ERROR: realloc failed, elements:%d\n\n", anz_emax);
312 return;
313 }
314
315 for(e=0; e<anz_e; e++)
316 {
317 j=e_enqire[e].nr;
318 if(e_enqire[j].type)
319 {
320 elem[anz->e].nr = j;
321 elem[anz->e].type = e_enqire[j].type;
322 elem[anz->e].group= e_enqire[j].group;
323 elem[anz->e].mat = e_enqire[j].mat;
324 elem[anz->e].attr = e_enqire[j].attr;
325 ipuf=0;
326 if (elem[anz->e].nr > anz->emax) anz->emax=elem[anz->e].nr;
327 if (elem[anz->e].nr < anz->emin) anz->emin=elem[anz->e].nr;
328 if (elem[anz->e].type == 1) ipuf = 8; /* HEXA8 */
329 else if (elem[anz->e].type == 2) ipuf = 6; /* PE6 */
330 else if (elem[anz->e].type == 3) ipuf = 4; /* TET4 */
331 else if (elem[anz->e].type == 4) ipuf = 20; /* HEXA20 */
332 else if (elem[anz->e].type == 5) ipuf = 15; /* PE15 */
333 else if (elem[anz->e].type == 6) ipuf = 10; /* TET10 */
334 else if (elem[anz->e].type == 7) ipuf = 3; /* TRI3 */
335 else if (elem[anz->e].type == 8) ipuf = 6; /* TRI6 */
336 else if (elem[anz->e].type == 9) ipuf = 4; /* QUAD4 */
337 else if (elem[anz->e].type == 10) ipuf = 10; /* QUAD8 */
338 else if (elem[anz->e].type == 11) ipuf = 2; /* BEAM2 */
339 else if (elem[anz->e].type == 12) ipuf = 3; /* BEAM3 */
340
341 anz->etype[elem[anz->e].type]++;
342 for(n=0; n<ipuf; n++) elem[anz->e].nod[n]= e_enqire[j].nod[n];
343 anz->e++;
344 }
345 }
346 if(!anz->e) anz->emin=0;
347 /* initialize the new element data structure */
348 /* and update faces in sets */
349 iniElements(anz, elem, anz_e);
350 if(anz->enext>anz->emax) anz->enext=anz->emax+1;
351 free(elem); elem=NULL;
352 updateDispLists();
353 }
354
355
356
elem_define(Summen * anz,Elements ** eptr,int elnr,int type,int * node,int setFlag,int eattr)357 int elem_define( Summen *anz, Elements **eptr, int elnr, int type, int *node, int setFlag, int eattr )
358 {
359 int nr, ipuf=0,ipuf2=0, n, i,nf=0;
360 Elements *e_enqire;
361
362 e_enqire=*eptr;
363 if (elnr<=anz->emax) nr=e_enqire[elnr].type;
364 else nr=0;
365 if (nr==0) /* new elem */
366 {
367 if (elnr>anz->emax) /* new elem */
368 {
369 if((e_enqire=(Elements *)realloc((Elements *)e_enqire, (elnr+1) * sizeof(Elements))) == NULL )
370 printf("\n\n ERROR: malloc failed e_enqire\n\n") ;
371 for(i=anz->emax+1; i<elnr; i++) e_enqire[i].type = 0;
372 anz->emax=elnr;
373 *eptr=e_enqire;
374 }
375 if ( elnr < anz->emin ) anz->emin=elnr;
376 e_enqire[anz->e].nr = elnr;
377 e_enqire[elnr].side = NULL;
378 nr=anz->e++;
379 }
380 else
381 {
382 if(printFlag) printf (" Elem:%d in use: Def will be changed\n", elnr);
383
384 /* free space for the normal-vectors */
385 if(e_enqire[ elnr ].side!=NULL)
386 {
387 if (e_enqire[ elnr ].type == 1) nf=6; /* HEXA8 */
388 else if (e_enqire[ elnr ].type == 2) nf=6; /* PENTA6 */
389 else if (e_enqire[ elnr ].type == 3) nf=4; /* TET4 */
390 else if (e_enqire[ elnr ].type == 4) nf=48; /* HEXA20 */
391 else if (e_enqire[ elnr ].type == 5) nf=48; /* PENTA15 */
392 else if (e_enqire[ elnr ].type == 6) nf=16; /* TET10 */
393 else if (e_enqire[ elnr ].type == 7) nf=1; /* TRI3 */
394 else if (e_enqire[ elnr ].type == 8) nf=4; /* TRI6 */
395 else if (e_enqire[ elnr ].type == 9) nf=2; /* QUAD4 */
396 else if (e_enqire[ elnr ].type == 10) nf=8; /* QUAD8 */
397 else if (e_enqire[ elnr ].type == 11) nf=1; /* BEAM */
398 else if (e_enqire[ elnr ].type == 12) nf=1; /* BEAM3 */
399 for(i=0; i<nf; i++) free(e_enqire[ elnr ].side[i]);
400 free(e_enqire[ elnr ].side);
401 e_enqire[ elnr ].side = NULL;
402 }
403 }
404
405 e_enqire[ elnr ].group = 0;
406 e_enqire[ elnr ].mat = 1;
407 e_enqire[ elnr ].attr = eattr;
408 e_enqire[ elnr ].type = type ;
409 if (setFlag) for (i=0; i<anz->sets; i++) if ( set[i].flag=='o') seta( i, "e", elnr );
410
411 switch (e_enqire[ elnr ].type)
412 {
413 case 1:
414 ipuf = 8; nf=6; /* HEXA8 */
415 break;
416 case 2:
417 ipuf = 6; nf=6; /* PENTA6 */
418 break;
419 case 3:
420 ipuf = 4; nf=4; /* TET4 */
421 break;
422 case 4:
423 ipuf = 20; nf=48; ipuf2 = 26;/* HEX20 */
424 break;
425 case 5:
426 ipuf = 15; nf=48; ipuf2 = 20;/* PENTA15 */
427 break;
428 case 6:
429 ipuf = 10; nf=16; /* TET10 */
430 break;
431 case 7:
432 ipuf = 3; nf=1; /* TRI3 */
433 break;
434 case 8:
435 ipuf = 6; nf=4; /* TRI6 */
436 break;
437 case 9:
438 ipuf = 4; nf=2; /* QUAD4 */
439 break;
440 case 10:
441 ipuf = 8; nf=8; ipuf2 = 9;/* QUAD8 */
442 break;
443 case 11:
444 ipuf = 2; nf=1; /* BEAM */
445 break;
446 case 12:
447 ipuf = 3; nf=1;/* BEAM3 */
448 break;
449 }
450 if (ipuf!=0) for (n=0; n<ipuf; n++)
451 {
452 e_enqire[ elnr ].nod[n]=node[n];
453 }
454 /* set the midside nodenr to 0 */
455 if (ipuf2!=0) for (n=ipuf; n<ipuf2; n++)
456 {
457 e_enqire[ elnr ].nod[n]=0;
458 }
459
460 /* space for the normal-vectors */
461 if((e_enqire[ elnr ].side=(double **)malloc((nf)*sizeof(double *)))==NULL)
462 printf("\n\n ERROR: malloc failed\n\n" );
463 for(i=0; i<nf; i++)
464 {
465 if((e_enqire[ elnr ].side[i]=(double *)malloc((3)*sizeof(double)))==NULL)
466 printf("\n\n ERROR: malloc failed\n\n" );
467 }
468
469 #if TEST
470 printf("e:%d ", elnr);
471 if (ipuf!=0) for (n=0; n<ipuf; n++)
472 {
473 printf("n:%d ",node[n]);
474 }
475 printf("\n ");
476 #endif
477
478 return(nr);
479 }
480
481
482
pre_elem(char * record)483 void pre_elem( char *record)
484 {
485 int i,e, type;
486 int length, nr[27], args=0, ptr=0, setNr=-1;
487 char dat[MAX_LINE_LENGTH];
488
489 /* lese eingabe mit variabler laenge */
490 for (i=0; i<22; i++)
491 {
492 length= sword( &record[ptr], dat );
493 if((i==0)&&(dat[0]=='!'))
494 {
495 nr[0]=anz->enext;
496 if(dat[0]=='!') setNr=-2;
497 }
498 else nr[i]=atoi( dat);
499 if(i==0)
500 {
501 /* next automatic elemnr is not incremented if a elemnr below enext is specified */
502 if(nr[0]>=anz->enext) anz->enext++;
503 }
504 if((i==1)&&(setNr==-2))
505 {
506 /* generate elems from faces if a valid set was given */
507 setNr=getSetNr(dat);
508 if(setNr>-1)
509 {
510 if(printFlag) printf("make elems from faces, set:%s\n",set[setNr].name);
511 for (i=0; i<set[setNr].anz_f; i++)
512 {
513 e=set[setNr].face[i];
514 if(elem_define(anz,&e_enqire, anz->enext++, face[e].type, face[e].nod, 1, 0 ) <0 ) errMsg("WARNING: element %d could not be created\n", anz->enext--);
515 }
516 return;
517 }
518 }
519 if(nr[i]==0) break;
520 ptr+=length+1;
521 args++;
522 }
523
524 if(printFlag) printf("elem: ");
525 for (i=0; i<args; i++)
526 {
527 if(printFlag) printf("%d, ", nr[i]);
528 }
529 if(printFlag) printf("%s \n", dat);
530
531 for(i=0; i<strlen(dat); i++) dat[i]=toupper(dat[i]);
532 if (compare( dat, "HE8", 3)==3 ) type=1;
533 else if (compare( dat, "HE20", 3)==3 ) type=4;
534 else if (compare( dat, "TR3", 3)==3 ) type=7;
535 else if (compare( dat, "TR6", 3)==3 ) type=8;
536 else if (compare( dat, "QU4", 3)==3 ) type=9;
537 else if (compare( dat, "QU8", 3)==3 ) type=10;
538 else if (compare( dat, "BE2", 3)==3 ) type=11;
539 else if (compare( dat, "BE3", 3)==3 ) type=12;
540 else
541 {
542 printf(" element type:%s not known\n", dat);
543 return;
544 }
545 i=elem_define(anz,&e_enqire, nr[0], type, &nr[1], 1, 0 );
546 if( i <0)
547 errMsg("WARNING: element %d could not be created\n", nr[0]);
548 }
549
550
551 /*------------------------------------------------------------------*/
552 /* define alias */
553 /*------------------------------------------------------------------*/
554
hashAlias(SumAsci * sumAsci,char * name,int nr)555 int hashAlias( SumAsci *sumAsci, char *name, int nr)
556 {
557 int i=0,j=0;
558 int sum=0;
559
560 while(name[i]!='\0') { sum+=name[i]*(++j); i++;}
561
562 /* check if sum is higher as the allocated value */
563 if(sum>sumAsci->max_suma)
564 {
565 if ((sumAsci->anza=(int *)realloc( (int *)sumAsci->anza, (sum+1)*sizeof(int)) ) == NULL )
566 { printf("\n\nERROR: realloc failure in hashAlias(), Alias:%s not included\n\n", name); return(-1); }
567 if ((sumAsci->aindx=(int **)realloc( (int **)sumAsci->aindx, (sum+1)*sizeof(int *)) ) == NULL )
568 { printf("\n\nERROR: realloc failure in hashAlias(), Alias:%s not included\n\n", name); return(-1); }
569 for(i=sumAsci->max_suma+1; i<=sum; i++) { sumAsci->anza[i]=0; sumAsci->aindx[i]=NULL; }
570 sumAsci->max_suma=sum;
571 }
572
573 /* alloc of a new entry in the hash table */
574 if ((sumAsci->aindx[sum]
575 =(int *)realloc( (int *)sumAsci->aindx[sum], (sumAsci->anza[sum]+1)*sizeof(int)) ) == NULL )
576 { printf("\n\nERROR: realloc failure in hashAlias(), alias:%s not included\n\n", name); return(-1); }
577
578 sumAsci->aindx[sum][sumAsci->anza[sum]] = nr;
579 sumAsci->anza[sum]++;
580 return(sum);
581 }
582
583
operateAlias(char * name,char * type)584 void operateAlias( char *name, char *type )
585 {
586 int length, i, alnam;
587
588 if( name[0] == '%')
589 {
590 /* existing alias found, search real name */
591 length= strlen( name );
592 if(printFlag) printf (" rename %s ", name );
593 for (i=0; i<length; i++) name[i] = name[i+1];
594 if(printFlag) printf (" to aliasName %s \n", name );
595 i=getAliasNr( name );
596 if( i >-1)
597 {
598 if(printFlag) printf(" existing alias found:%s, real name:%s\n", name, alias[i].entityName);
599 strcpy( name, alias[i].entityName );
600 return;
601 }
602 if(printFlag) printf(" found no real name for alias:%s \n", name);
603 }
604 else if( name[0] == '?')
605 {
606 /* slow function to search the entity name for a given alias name */
607 length=strlen(name)-1;
608 for (i=0; i<anzGeo->alias; i++)
609 {
610 if( alias[i].entityName != (char *)NULL )
611 {
612 if((strlen(alias[i].entityName)==length) && (compare( alias[i].entityName, &name[1], length)==length))
613 {
614 printf("alias name:%s\n",alias[i].name);
615 strcpy( name, &name[1] );
616 return;
617 }
618 }
619 }
620 }
621 else if( name[0] == '!')
622 {
623 /* Alias found, generate new entity-name */
624 length= strlen( name );
625 if (length==1)
626 {
627 if ( getNewName( name, type ) == -1 )
628 { printf(" ERROR: operateAlias: Type %s not known\n", type); }
629 return;
630 }
631 if(printFlag) printf (" rename %s ", name );
632 for (i=0; i<length; i++) name[i] = name[i+1];
633 if(printFlag) printf (" to aliasName %s \n", name );
634
635 /* is the name in use? if yes, overwrite him */
636 alnam=getAliasNr(name);
637 if (alnam==-1)
638 {
639 if((alias=(Alias *)realloc((Alias *)alias,(anzGeo->alias+1)*sizeof(Alias)))==NULL)
640 { errMsg(" ERROR: realloc failure in operateAlias\n");
641 return; }
642 alnam=anzGeo->alias; /* new alias */
643 hashAlias( sumAsci, name, alnam );
644 anzGeo->alias++;
645 }
646
647 i=strlen(name);
648 if((alias[alnam].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
649 { printf("ERROR: malloc failed\n\n" ); return; }
650 strcpy( alias[alnam].name, name );
651 if ( getNewName( name, type ) == -1 )
652 { printf(" ERROR: operateAlias: Type %s not known\n", type); }
653 i=strlen(name);
654 if((alias[alnam].entityName= (char *)malloc((i+1)*sizeof(char))) == NULL )
655 { printf("ERROR: malloc failed\n\n" ); return; }
656 strcpy( alias[alnam].entityName, name );
657 if(printFlag) printf(" real name:%s\n", alias[alnam].entityName);
658 }
659 }
660
661 /*------------------------------------------------------------------*/
662 /* define value */
663 /*------------------------------------------------------------------*/
664
delVal(int anzv,int * number)665 void delVal( int anzv, int *number )
666 {
667 int j,k, *nrbuffer;
668
669 delPntFlag=1;
670 if ((nrbuffer = (int *)malloc((anzv+1)*sizeof(int)) ) == NULL )
671 { printf("\n\nERROR: realloc failure in delVal\n\n"); return; }
672
673 /* nessesary to store the numbers in a independent area */
674 for (j=0; j<anzv; j++)
675 nrbuffer[j]=number[j];
676
677 for (j=0; j<anzv; j++) if( value[nrbuffer[j]].name != (char *)NULL )
678 {
679 /* remove the values from all sets */
680 for (k=0; k<anz->sets; k++)
681 {
682 if( set[k].name != (char *)NULL )
683 {
684 if(set[k].type==0)
685 setr( k, "v", nrbuffer[j]);
686 else
687 seqr( k, "v", nrbuffer[j] );
688 }
689 }
690 if(printFlag) printf (" delete value:%s \n", value[nrbuffer[j]].name );
691 free(value[nrbuffer[j]].name);
692 value[nrbuffer[j]].name = (char *)NULL ;
693 value[nrbuffer[j]].flag = 0 ;
694 }
695 free(nrbuffer);
696 }
697
hashValue(SumAsci * sumAsci,char * name,int nr)698 int hashValue( SumAsci *sumAsci, char *name, int nr)
699 {
700 int i=0,j=0, n;
701 int sum=0;
702
703 while(name[i]!='\0') { sum+=name[i]*(++j); i++;}
704
705 /* check if sum is higher as the allocated value */
706 /* else look for a free entry */
707 if(sum>sumAsci->max_sumv)
708 {
709 if ((sumAsci->anzv=(int *)realloc( (int *)sumAsci->anzv, (sum+1)*sizeof(int)) ) == NULL )
710 { printf("\n\nERROR: realloc failure in hashValue(), value:%s not included\n\n", name); return(-1); }
711 if ((sumAsci->vindx=(int **)realloc( (int **)sumAsci->vindx, (sum+1)*sizeof(int *)) ) == NULL )
712 { printf("\n\nERROR: realloc failure in hashValue(), value:%s not included\n\n", name); return(-1); }
713 for(i=sumAsci->max_sumv+1; i<=sum; i++) { sumAsci->anzv[i]=0; sumAsci->vindx[i]=NULL; }
714 sumAsci->max_sumv=sum;
715 }
716 else
717 {
718 for (i=0; i<sumAsci->anzv[sum]; i++)
719 {
720 n=sumAsci->vindx[sum][i];
721 if( value[n].name == (char *)NULL )
722 {
723 /* already existing space to fill */
724 sumAsci->vindx[sum][i]=nr;
725 return(sum);
726 }
727 }
728 }
729
730 /* alloc of a new entry in the hash table */
731 if ((sumAsci->vindx[sum]
732 =(int *)realloc( (int *)sumAsci->vindx[sum], (sumAsci->anzv[sum]+1)*sizeof(int)) ) == NULL )
733 { printf("\n\nERROR: realloc failure in hashValue(), value:%s not included\n\n", name); return(-1); }
734
735 sumAsci->vindx[sum][sumAsci->anzv[sum]] = nr;
736 sumAsci->anzv[sum]++;
737 return(sum);
738 }
739
740
value_i(char * name,char * string)741 int value_i( char *name, char *string )
742 {
743 int nr, i;
744 nr=getValuNr(name);
745
746 if (nr==-1) /* new */
747 {
748 if ((value = (Values *)realloc( (Values *)value, (anz->v+1)*sizeof(Values)) ) == NULL )
749 { printf("\n\nERROR: realloc failure, value:%s not installed\n\n", name); return(-1); }
750 nr=anz->v;
751 i=strlen(name);
752 if((value[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
753 { printf("ERROR: malloc failed\n\n" ); return(-1); }
754 strcpy(value[nr].name, name);
755 hashValue( sumAsci, name, nr );
756 value[nr].string=NULL;
757 value[nr].flag=0;
758 anz->v++;
759 }
760 else if (nr<-1) /* replace a deleted value */
761 {
762 nr=-(nr+10);
763 i=strlen(name);
764 if((value[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
765 { printf("ERROR: malloc failed\n\n" ); return(-1); }
766 strcpy(value[nr].name, name);
767 hashValue( sumAsci, name, nr );
768 value[nr].string[0]=0;
769 value[nr].flag=0;
770 }
771 else
772 {
773 if(printFlag) printf (" Value in use: value will be changed\n");
774 }
775
776 if ((value[nr].string = (char *)realloc( (char *)value[nr].string, (strlen(string)+1)*sizeof(char)) ) == NULL )
777 { printf("\n\nERROR: realloc failure, value:%s not installed\n\n", name); return(-1); }
778 strcpy(value[nr].string,string);
779
780 /* mark all values with a leading ! as not to be saved */
781 if(value[nr].name[0]=='!') value[nr].flag=1;
782
783 for (i=0; i<anz->sets; i++)
784 {
785 if(( set[i].name!=(char *)NULL)&&( set[i].flag=='o')) seta( i, "v", nr );
786 }
787 return(nr);
788 }
789
pre_value(char * record)790 int pre_value( char *record)
791 {
792 int i,j,n, vnr, length, args;
793 char name[MAX_LINE_LENGTH];
794 char *text=NULL;
795 char string[MAX_LINE_LENGTH];
796 char arg1[MAX_LINE_LENGTH];
797 char arg2[MAX_LINE_LENGTH];
798 int vnr1, vnr2;
799 double val1=0.,val2=0.;
800 char splitkey[2]={0,0};
801 char *str=NULL, *token=NULL, *saveptr=NULL;
802 char param[MAX_LINE_LENGTH];
803
804 name[0]=string[0]=arg1[0]=arg2[0]=0;
805 length=sscanf (record,"%s%s%s%s", name, string, arg1, arg2 );
806
807 if(length<2) return(-1);
808 else if(compareStrings(string, "push")>0)
809 {
810 if(length>2) splitkey[0]=arg1[0];
811 else splitkey[0]=' ';
812 vnr=getValuNr(name);
813 if (vnr>-1)
814 {
815 /* split the value[vnr].string in separate strings at <splitkey> occurences and write them to the stack */
816 strcpy(param,value[vnr].string);
817 for(args=0, str=param; ; args++, str=NULL)
818 {
819 token = strtok_r(str,(const char *)&splitkey, &saveptr);
820 if(token == NULL) break;
821 if(args == 20) break;
822 strcpy(parameter[args],token);
823 }
824 write2stack(args, parameter);
825 return(vnr);
826 }
827 else return(-1);
828 }
829 else if(compareStrings(string, "pop")>0)
830 {
831 if(length>2) n=atoi(arg1); else n=1;
832 for(i=0; i<n; i++)
833 {
834 if(valuestack_ptr)
835 {
836 valuestack_ptr--;
837 strcpy(string, valuestack[valuestack_ptr] );
838 free(valuestack[valuestack_ptr]);
839 }
840 else return(-1);
841 }
842 }
843 else if(compareStrings(string, "?")>0)
844 {
845 /* search a text between "" */
846 i=j=0;
847 do
848 {
849 if(record[i]=='"')
850 {
851 if((text=(char *)malloc(sizeof(char))) == NULL)
852 printf("\n ERROR: malloc failed\n");
853 i++;
854 while((record[i]!='"')&&(record[i]!=0))
855 {
856 text[j++]=record[i++];
857 if((text=(char *)realloc(text,(j+1)*sizeof(char))) == NULL)
858 printf("\n ERROR: realloc failed\n");
859 }
860 text[j++]='\0';
861 }
862 }while(record[i++]!='\0');
863 printf("\n** Waiting for user input. Please type into the terminal (this has to be the active window!) **\n");
864 if(text!=NULL) { printf("-> %s\n",text); free(text); }
865
866 i=0;
867 string[i]=0;
868 do
869 {
870 string[i]=getchar(); i++;
871 }while(string[i-1]!='\n');
872 string[i-1]=0;
873 }
874 else if (length>2)
875 {
876 vnr1=getValuNr(arg1);
877 if (vnr1>-1)
878 {
879 // its a valu, convert to float
880 val1=atof(value[vnr1].string );
881 }
882 else
883 {
884 // it might be a constant string or a float. Try a float.
885 val1=atof(arg1);
886 }
887 vnr2=getValuNr(arg2);
888 if (vnr2>-1)
889 {
890 // its a valu, convert to float
891 val2=atof(value[vnr2].string );
892 }
893 else
894 {
895 // it might be a constant string or a float. Try a float.
896 val2=atof(arg2);
897 }
898 if(compareStrings(string, "&")>0)
899 {
900 if((vnr1<0)&&(vnr2<0)) sprintf(string,"%s%s",arg1,arg2);
901 else if(vnr1<0) sprintf(string,"%s%s",arg1,value[vnr2].string);
902 else if(vnr2<0) sprintf(string,"%s%s",value[vnr1].string,arg2);
903 else sprintf(string,"%s%s",value[vnr1].string,value[vnr2].string);
904 }
905 else
906 {
907 if(compareStrings(string, "*")>0) sprintf(string,"%e",val1*val2);
908 else if(compareStrings(string, "/")>0) sprintf(string,"%e",val1/val2);
909 else if(compareStrings(string, "+")>0) sprintf(string,"%e",val1+val2);
910 else if(compareStrings(string, "-")>0) sprintf(string,"%e",val1-val2);
911 else if(compareStrings(string, "abs")>0) sprintf(string,"%e",abs(val1));
912 else if(compareStrings(string, "int")>0) sprintf(string,"%d",(int)val1);
913 else if(compareStrings(string, "float")>0) sprintf(string,"%f",(float)val1);
914 else if(compareStrings(string, "exp")>0) sprintf(string,"%e",(double)val1);
915 else if(compareStrings(string, "max")>0) sprintf(string,"%e",dmax(val1,val2));
916 else if(compareStrings(string, "min")>0) sprintf(string,"%e",dmin(val1,val2));
917 else if(compareStrings(string, "pow")>0) sprintf(string,"%e",pow(val1,val2));
918 else if(compareStrings(string, "sqr")>0) sprintf(string,"%e",sqrt(val1));
919 else if(compareStrings(string, "sin")>0) sprintf(string,"%e",sin(val1*PI/180.));
920 else if(compareStrings(string, "cos")>0) sprintf(string,"%e",cos(val1*PI/180.));
921 else if(compareStrings(string, "tan")>0) sprintf(string,"%e",tan(val1*PI/180.));
922 else if(compareStrings(string, "asin")>0) sprintf(string,"%e",asin(val1)*180./PI);
923 else if(compareStrings(string, "acos")>0) sprintf(string,"%e",acos(val1)*180./PI);
924 else if(compareStrings(string, "atan")>0) sprintf(string,"%e",atan(val1)*180./PI);
925 /* get rid of trailing '0' */
926 for(i=strlen(string); i>0; i--) if(string[i]=='0') string[i]=0; else break;
927 }
928 }
929 else if (length==2)
930 {
931 vnr=getValuNr(string);
932 if(vnr>-1) sprintf(string,"%s",value[vnr].string);
933 }
934
935 if( (vnr=value_i( name, string)) <0) printf("ERROR: value could not be created\n");
936 return(vnr);
937 }
938
939
940
941 /*------------------------------------------------------------------*/
942 /* define point */
943 /*------------------------------------------------------------------*/
944
delPnt(int anzp,int * number)945 void delPnt( int anzp, int *number )
946 {
947 int j, k, *nrbuffer;
948
949 delPntFlag=1;
950 if ((nrbuffer = (int *)malloc((anzp+1)*sizeof(int)) ) == NULL )
951 { printf("\n\nERROR: realloc failure in delPnt\n\n"); return; }
952
953 /* nessesary to store the numbers in a independent area */
954 for (j=0; j<anzp; j++)
955 nrbuffer[j]=number[j];
956
957 for (j=0; j<anzp; j++) if( point[nrbuffer[j]].name != (char *)NULL )
958 {
959 /* remove the points from all sets */
960 for (k=0; k<anz->sets; k++)
961 {
962 if( set[k].name != (char *)NULL )
963 {
964 if(set[k].type==0)
965 setr( k, "p", nrbuffer[j]);
966 else
967 seqr( k, "p", nrbuffer[j] );
968 }
969 }
970 if(printFlag) printf (" delete pnt:%s \n", point[nrbuffer[j]].name );
971 free(point[nrbuffer[j]].name);
972 point[nrbuffer[j]].name = (char *)NULL ;
973 point[nrbuffer[j]].nn= 0;
974 free(point[nrbuffer[j]].nod);
975 point[nrbuffer[j]].nod = NULL;
976 }
977 free(nrbuffer);
978 }
979
hashPoint(SumAsci * sumAsci,char * name,int nr)980 int hashPoint( SumAsci *sumAsci, char *name, int nr)
981 {
982 int i=0,j=0, n;
983 int sum=0;
984
985 while(name[i]!='\0') { sum+=name[i]*(++j); i++;}
986
987 /* check if sum is higher as the allocated value */
988 /* else look for a free entry */
989 if(sum>sumAsci->max_sump)
990 {
991 if ((sumAsci->anzp=(int *)realloc( (int *)sumAsci->anzp, (sum+1)*sizeof(int)) ) == NULL )
992 { printf("\n\nERROR: realloc failure in hashPoint(), Point:%s not included\n\n", name); return(-1); }
993 if ((sumAsci->pindx=(int **)realloc( (int **)sumAsci->pindx, (sum+1)*sizeof(int *)) ) == NULL )
994 { printf("\n\nERROR: realloc failure in hashPoint(), Point:%s not included\n\n", name); return(-1); }
995 for(i=sumAsci->max_sump+1; i<=sum; i++) { sumAsci->anzp[i]=0; sumAsci->pindx[i]=NULL; }
996 sumAsci->max_sump=sum;
997 }
998 else
999 {
1000 if (delPntFlag)
1001 for (i=0; i<sumAsci->anzp[sum]; i++)
1002 {
1003 n=sumAsci->pindx[sum][i];
1004 if( point[n].name == (char *)NULL )
1005 {
1006 /* already existing space to fill */
1007 sumAsci->pindx[sum][i]=nr;
1008 return(sum);
1009 }
1010 }
1011 }
1012
1013 /* alloc of a new entry in the hash table */
1014 if ((sumAsci->pindx[sum]
1015 =(int *)realloc( (int *)sumAsci->pindx[sum], (sumAsci->anzp[sum]+1)*sizeof(int)) ) == NULL )
1016 { printf("\n\nERROR: realloc failure in hashPoint(), pnt:%s not included\n\n", name); return(-1); }
1017
1018 sumAsci->pindx[sum][sumAsci->anzp[sum]] = nr;
1019 sumAsci->anzp[sum]++;
1020 return(sum);
1021 }
1022
1023
pnt(char * name,double x,double y,double z,int scalFlag)1024 int pnt( char *name, double x, double y, double z, int scalFlag )
1025 {
1026 int nr, i;
1027 nr=getPntNr(name);
1028
1029 if (nr==-1) /* new point */
1030 {
1031 if ((point = (Points *)realloc( (Points *)point, (anzGeo->p+1)*sizeof(Points)) ) == NULL )
1032 { printf("\n\nERROR: realloc failure in pnt, pnt:%s not installed\n\n", name); return(-1); }
1033 nr=anzGeo->p;
1034 i=strlen(name);
1035 if((point[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1036 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1037 strcpy(point[nr].name, name);
1038 hashPoint( sumAsci, name, nr );
1039 anzGeo->p++;
1040 point[nr].nod = NULL;
1041 }
1042 else if (nr<-1) /* replace a deleted point */
1043 {
1044 nr=-(nr+10);
1045 i=strlen(name);
1046 if((point[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1047 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1048 strcpy(point[nr].name, name);
1049 hashPoint( sumAsci, name, nr );
1050 }
1051 else
1052 {
1053 if(printFlag) printf (" Point in use: Coordinates will be changed\n");
1054 free(point[nr].nod);
1055 point[nr].nod = NULL;
1056 }
1057 point[nr].nn= 0;
1058
1059 if(scalFlag)
1060 {
1061 point[nr].px=(x-scale->x)/scale->w;
1062 point[nr].py=(y-scale->y)/scale->w;
1063 point[nr].pz=(z-scale->z)/scale->w;
1064 }
1065 else
1066 {
1067 point[nr].px=x;
1068 point[nr].py=y;
1069 point[nr].pz=z;
1070 }
1071
1072 for (i=0; i<anz->sets; i++)
1073 {
1074 if(( set[i].name!=(char *)NULL)&&( set[i].flag=='o')) seta( i, "p", nr );
1075 }
1076 return(nr);
1077 }
1078
1079
1080 #define RATIO_FACTOR 10000 /* makes integer from double < 1. */
1081
pre_pnt(char * record,int addFlag)1082 int pre_pnt( char *record, int addFlag)
1083 {
1084 int i, length, setNr, nr, pnr=-1, noName=0;
1085 char name[MAX_LINE_LENGTH];
1086 char xbuf[MAX_LINE_LENGTH], ybuf[MAX_LINE_LENGTH];
1087 double fbuf, p0[3], p1[3], p01[3], p01t[3], bias;
1088 double x=0.,y=0.,z=0.,t=1.;
1089
1090 xbuf[0]=ybuf[0]=0;
1091
1092 if (!addFlag) length=sscanf (record,"%s%s%s%lg%lg", name, xbuf, ybuf, &z, &t );
1093 else { name[0]='!'; length=sscanf (record,"%s%s%s%lg%lg", &name[1], xbuf, ybuf, &z, &t ); }
1094
1095 /* check if no name is specified */
1096 if((strlen(name)==1)&&(name[0]=='!')) noName=1;
1097 operateAlias( name, "p" );
1098
1099 if (length==2)
1100 {
1101 /* make points from nodes, names are automatically generated */
1102 setNr=getSetNr(xbuf);
1103
1104 if (setNr<0)
1105 {
1106 x=atof(xbuf);
1107 if(printFlag) printf (" pnt=%s x=%lf y=%lf z=%lf\n", name, x, y, z);
1108 if( (pnr=pnt( name, x, y, z, 1 )) <0) printf("ERROR: point could not be created\n");
1109 }
1110 else
1111 {
1112 for (i=0; i<set[setNr].anz_n; i++)
1113 {
1114 if(noName) getNewName( name, "p" );
1115 else noName=1;
1116 if(printFlag) printf (" pnt=%s x=%lf y=%lf z=%lf\n", name, x, y, z);
1117 if( (pnr=pnt( name
1118 , node[set[setNr].node[i]].nx
1119 , node[set[setNr].node[i]].ny
1120 , node[set[setNr].node[i]].nz, 0 )) <0) printf("ERROR: point could not be created\n");
1121 pre_seta( set[setNr].name, "p", name );
1122 }
1123 }
1124 }
1125 else if(!checkIfNumber(xbuf)) /* xbuf is not a number, could be a line or a point */
1126 {
1127 if(!checkIfNumber(ybuf)) /* xbuf is not a number, must be a point */
1128 {
1129 /* create pnt from ratio, names are automatically generated */
1130 /* bestimme die Koordinaten der Linienendpunkte */
1131 nr= getPntNr( xbuf );
1132 if(nr<0) { printf("ERROR: pnt:%s not defined\n", xbuf); return(-1); }
1133 p0[0] = point[nr].px;
1134 p0[1] = point[nr].py;
1135 p0[2] = point[nr].pz;
1136 nr= getPntNr( ybuf );
1137 if(nr<0) { printf("ERROR: pnt:%s not defined\n", xbuf); return(-1); }
1138 p1[0] = point[nr].px;
1139 p1[1] = point[nr].py;
1140 p1[2] = point[nr].pz;
1141 v_result( p0, p1, p01 );
1142 for(i=1; i<=t; i++)
1143 {
1144 fbuf=z*i;
1145 v_scal( &fbuf, p01, p1 );
1146 v_add( p0, p1, p01t );
1147 if(noName) getNewName( name, "p" );
1148 else noName=1;
1149 if(printFlag) printf (" pnt %s %lf %lf %lf\n", name, p01t[0]*scale->w+scale->x, p01t[1]*scale->w+scale->y, p01t[2]*scale->w+scale->z);
1150 if( (pnr=pnt( name, p01t[0], p01t[1], p01t[2], 0 )) <0) printf("ERROR: point could not be created\n");
1151 }
1152 }
1153 else /* point from line */
1154 {
1155 nr= getLineNr( xbuf );
1156 if(nr<0) { printf("ERROR: line:%s not defined\n", xbuf); return(-1); }
1157
1158 x=atof(ybuf);
1159 if(!z) z=1;
1160 if(z*x>1) z=1/x;
1161 bias=line[nr].bias;
1162 line[nr].bias=1.;
1163 for(i=1; i<=z; i++)
1164 {
1165 if (line[nr].typ=='a')
1166 {
1167 arcNodes( nr, RATIO_FACTOR*x*i, RATIO_FACTOR, p01t );
1168 }
1169 else if (line[nr].typ=='s')
1170 {
1171 splineNodes( nr, RATIO_FACTOR*x*i, RATIO_FACTOR, p01t );
1172 }
1173 else if (line[nr].typ=='n')
1174 {
1175 nurlNodes( nr, RATIO_FACTOR*x*i, RATIO_FACTOR, p01t );
1176 }
1177 else
1178 {
1179 straightNodes( nr, RATIO_FACTOR*x*i, RATIO_FACTOR, p01t );
1180 }
1181 if(noName) getNewName( name, "p" );
1182 else noName=1;
1183 if(printFlag) printf (" pnt %s %lf %lf %lf\n", name, p01t[0]*scale->w+scale->x, p01t[1]*scale->w+scale->y, p01t[2]*scale->w+scale->z);
1184 if( (pnr=pnt( name, p01t[0], p01t[1], p01t[2], 0 )) <0) printf("ERROR: point could not be created\n");
1185 }
1186 line[nr].bias=bias;
1187 }
1188 }
1189 else
1190 {
1191 x=atof(xbuf);
1192 y=atof(ybuf);
1193 if(printFlag) printf (" pnt %s %lf %lf %lf\n", name, x, y, z);
1194 if( (pnr=pnt( name, x, y, z, 1 )) <0) printf("ERROR: point could not be created\n");
1195 }
1196 return(pnr);
1197 }
1198
1199
1200 /*------------------------------------------------------------------*/
1201 /* define shape */
1202 /*------------------------------------------------------------------*/
1203
delShape(int anzs,int * number)1204 void delShape( int anzs, int *number )
1205 {
1206 int j, k, *nrbuffer;
1207
1208 delShapeFlag=1;
1209
1210 // printf ("sum:%d num:%d shape:%s\n", anzs, number[0], shape[number[0]].name );
1211
1212 if ((nrbuffer = (int *)malloc((anzs+1)*sizeof(int)) ) == NULL )
1213 { printf("\n\nERROR: realloc failure in delShape\n\n"); return; }
1214
1215 /* nessesary to store the numbers in a independent area */
1216 for (j=0; j<anzs; j++)
1217 nrbuffer[j]=number[j];
1218
1219 for (j=0; j<anzs; j++) if( shape[nrbuffer[j]].name != (char *)NULL )
1220 {
1221 for (k=0; k<anz->sets; k++)
1222 {
1223 if(set[k].type==0)
1224 if( set[k].name != (char *)NULL )
1225 setr( k, "sh", nrbuffer[j]);
1226 }
1227 if(printFlag) printf (" delete shape:%s \n", shape[nrbuffer[j]].name );
1228 free(shape[nrbuffer[j]].name);
1229 shape[nrbuffer[j]].name = (char *)NULL ;
1230 shape[nrbuffer[j]].npgn= 0;
1231 free(shape[nrbuffer[j]].pgn);
1232 shape[nrbuffer[j]].pgn= NULL;
1233 shape[nrbuffer[j]].ns= 0;
1234 free(shape[nrbuffer[j]].s);
1235 shape[nrbuffer[j]].s= NULL;
1236 }
1237 free(nrbuffer);
1238 }
1239
1240
shape_refSurf(int nr,int surfNr)1241 int shape_refSurf( int nr, int surfNr)
1242 {
1243 if(nr<0) return(-1);
1244 shape[nr].ns= iinsert(&shape[nr].s, shape[nr].ns, surfNr);
1245 return(0);
1246 }
1247
1248
hashShape(SumAsci * sumAsci,char * name,int nr)1249 int hashShape( SumAsci *sumAsci, char *name, int nr)
1250 {
1251 int i=0,j=0, n;
1252 int sum=0;
1253
1254 while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
1255
1256 /* check if sum is higher as the allocated value */
1257 /* else look for a free entry */
1258 if(sum>sumAsci->max_sumsh)
1259 {
1260 if ((sumAsci->anzsh=(int *)realloc( (int *)sumAsci->anzsh, (sum+1)*sizeof(int)) ) == NULL )
1261 { printf("\n\nERROR: realloc failure in hashShape(), Shape:%s not included\n\n", name); return(-1); }
1262 if ((sumAsci->shindx=(int **)realloc( (int **)sumAsci->shindx, (sum+1)*sizeof(int *)) ) == NULL )
1263 { printf("\n\nERROR: realloc failure in hashShape(), Shape:%s not included\n\n", name); return(-1); }
1264 for(i=sumAsci->max_sumsh+1; i<=sum; i++) { sumAsci->anzsh[i]=0; sumAsci->shindx[i]=NULL; }
1265 sumAsci->max_sumsh=sum;
1266 }
1267 else
1268 {
1269 if (delShapeFlag)
1270 for (i=0; i<sumAsci->anzsh[sum]; i++)
1271 {
1272 n=sumAsci->shindx[sum][i];
1273 if( shape[n].name == (char *)NULL )
1274 {
1275 /* already existing space to fill */
1276 sumAsci->shindx[sum][i]=nr;
1277 return(sum);
1278 }
1279 }
1280 }
1281
1282 /* alloc of a new entry in the hash table */
1283 if ((sumAsci->shindx[sum]=(int *)realloc( (int *)sumAsci->shindx[sum], (sumAsci->anzsh[sum]+1)*sizeof(int)) ) == NULL )
1284 { printf("\n\nERROR: realloc failure in hashShape(), shape:%s not included\n\n", name); return(-1); }
1285
1286 sumAsci->shindx[sum][sumAsci->anzsh[sum]] = nr;
1287 sumAsci->anzsh[sum]++;
1288 return(sum);
1289 }
1290
1291
shape_i(char * name,int type,int ip1,int ip2,int ip3,int ip4,int ip5,int ip6,int ip7)1292 int shape_i( char *name, int type, int ip1, int ip2, int ip3, int ip4, int ip5, int ip6, int ip7 )
1293 {
1294 int nr, i;
1295
1296 nr=getShapeNr(name);
1297 if (nr==-1) /* new */
1298 {
1299 if ((shape = (Shapes *)realloc( (Shapes *)shape, (anzGeo->sh+1)*sizeof(Shapes)) ) == NULL )
1300 { printf("\n\nERROR: realloc failure in line, line:%s not installed\n\n", name); return(-1); }
1301 nr=anzGeo->sh;
1302 anzGeo->sh++;
1303 i=strlen(name);
1304 if((shape[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1305 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1306 strcpy(shape[nr].name, name);
1307 hashShape( sumAsci, name, nr );
1308 shape[nr].npgn= 0;
1309 shape[nr].pgn= NULL;
1310 shape[nr].ns= 0;
1311 shape[nr].s= NULL;
1312 }
1313 else if (nr<-1) /* replace a deleted line */
1314 {
1315 nr=-(nr+10);
1316 i=strlen(name);
1317 if((shape[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1318 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1319 strcpy(shape[nr].name, name);
1320 hashShape( sumAsci, name, nr );
1321 }
1322 else
1323 {
1324 if(printFlag) printf (" shape %s in use: Definition will be changed\n", name);
1325 shape[nr].npgn= 0;
1326 free(shape[nr].pgn);
1327 shape[nr].pgn= NULL;
1328 shape[nr].ns= 0;
1329 free(shape[nr].s);
1330 shape[nr].s= NULL;
1331 }
1332 shape[nr].type=type;
1333 shape[nr].p[0]=ip1;
1334 shape[nr].p[1]=ip2;
1335 shape[nr].p[2]=ip3;
1336 shape[nr].p[3]=ip4;
1337 shape[nr].p[4]=ip5;
1338 shape[nr].p[5]=ip6;
1339 shape[nr].p[6]=ip7;
1340
1341 for (i=0; i<anz->sets; i++)
1342 {
1343 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o')) seta( i, "sh", nr );
1344 }
1345
1346 return(nr);
1347 }
1348
1349
1350
pre_shape(char * record,int addFlag)1351 void pre_shape( char *record, int addFlag)
1352 {
1353 int i;
1354 char name[MAX_LINE_LENGTH], type[MAX_LINE_LENGTH], datum[4][MAX_LINE_LENGTH];
1355 char buffer[MAX_LINE_LENGTH];
1356 int typi, p1,p2=0,p3=0,p4=0,p5=0,p6=0,p7=0, nsave;
1357 double r1,r2,r12;
1358 double p1p2[3], pn[3], v[3];
1359
1360 sscanf( record, "%*s%s", type);
1361 for(i=0; i<strlen(type); i++) type[i]=toupper(type[i]);
1362
1363 nsave=getSetNr(specialset->nsave);
1364 if (compare(type, "PLN",3)==3)
1365 {
1366 typi=0;
1367 if (!addFlag) sscanf( record, "%s%*s%s%s%s", name, datum[0], datum[1], datum[2] );
1368 else
1369 {
1370 name[0]='!';
1371 datum[0][0]=datum[1][0]=datum[2][0]='%';
1372 sscanf( record, "%s%*s%s%s%s", &name[1], &datum[0][1], &datum[1][1], &datum[2][1] );
1373 }
1374 operateAlias( datum[0], "p" );
1375 operateAlias( datum[1], "p" );
1376 operateAlias( datum[2], "p" );
1377
1378 /* check if points exists */
1379 p1=getPntNr(datum[0]);
1380 if (p1==-1) /* new point */
1381 {
1382 printf ("ERROR: point %s of Shape %s not defined\n", datum[0], name);
1383 return;
1384 }
1385 p2=getPntNr(datum[1]);
1386 if (p2==-1) /* new point */
1387 {
1388 printf ("ERROR: point %s of Shape %s not defined\n", datum[1], name);
1389 return;
1390 }
1391 p3=getPntNr(datum[2]);
1392 if (p3==-1) /* new point */
1393 {
1394 printf ("ERROR: point %s of Shape %s not defined\n", datum[2], name);
1395 return;
1396 }
1397 }
1398 else if (compare(type, "CYL",3)==3)
1399 {
1400 typi=1;
1401 if (!addFlag) sscanf( record, "%s%*s%s%s%lf", name, datum[0], datum[1], &r1 );
1402 else
1403 {
1404 name[0]='!';
1405 datum[0][0]=datum[1][0]='%';
1406 sscanf( record, "%s%*s%s%s%lf", &name[1], &datum[0][1], &datum[1][1], &r1 );
1407 }
1408 operateAlias( datum[0], "p" );
1409 operateAlias( datum[1], "p" );
1410
1411 /* check if points exists */
1412 p1=getPntNr(datum[0]);
1413 if (p1==-1) /* new point */
1414 {
1415 printf ("ERROR: point %s of Shape %s not defined\n", datum[0], name);
1416 return;
1417 }
1418 p2=getPntNr(datum[1]);
1419 if (p2==-1) /* new point */
1420 {
1421 printf ("ERROR: point %s of Shape %s not defined\n", datum[1], name);
1422 return;
1423 }
1424 if(r1<=0.)
1425 {
1426 printf ("ERROR: radius %f of Shape %s not valid\n", r1, name);
1427 return;
1428 }
1429 r1/=scale->w;
1430
1431 /* generate a third point perpendicular to the axis at a distant of r1 */
1432 v_result( &point[p1].px, &point[p2].px, p1p2 );
1433 pn[0]=p1p2[1];
1434 pn[1]=p1p2[2];
1435 pn[2]=p1p2[0];
1436 v_prod( p1p2, pn, v);
1437 v_norm(v,v );
1438 v_scal( &r1, v, v);
1439 v_add(&point[p1].px, v, v);
1440 getNewName( buffer, "p" );
1441 p3= pnt( buffer, v[0], v[1], v[2], 0 );
1442 seta( nsave, "p", p3);
1443 }
1444 else if (compare(type, "CON",3)==3)
1445 {
1446 typi=2;
1447 if (!addFlag) sscanf( record, "%s%*s%s%s%lf%lf", name, datum[0], datum[1], &r1, &r2 );
1448 else
1449 {
1450 name[0]='!';
1451 datum[0][0]=datum[1][0]='%';
1452 sscanf( record, "%s%*s%s%s%lf%lf", &name[1], &datum[0][1], &datum[1][1], &r1, &r2 );
1453 }
1454 operateAlias( datum[0], "p" );
1455 operateAlias( datum[1], "p" );
1456
1457 /* check if points exists */
1458 p1=getPntNr(datum[0]);
1459 if (p1==-1) /* new point */
1460 {
1461 printf ("ERROR: point %s of Shape %s not defined\n", datum[0], name);
1462 return;
1463 }
1464 p2=getPntNr(datum[1]);
1465 if (p2==-1) /* new point */
1466 {
1467 printf ("ERROR: point %s of Shape %s not defined\n", datum[1], name);
1468 return;
1469 }
1470 if(r1<0.)
1471 {
1472 printf ("ERROR: radius1 %f of Shape %s not valid\n", r1, name);
1473 return;
1474 }
1475 if(r2<0.)
1476 {
1477 printf ("ERROR: radius2 %f of Shape %s not valid\n", r2, name);
1478 return;
1479 }
1480 r1/=scale->w;
1481 r2/=scale->w;
1482
1483 /* generate a third point perpendicular to the axis at a distant of r1 */
1484 v_result( &point[p1].px, &point[p2].px, p1p2 );
1485 pn[0]=p1p2[1];
1486 pn[1]=p1p2[2];
1487 pn[2]=p1p2[0];
1488 v_prod( p1p2, pn, v);
1489 v_norm(v,v );
1490 v_scal( &r1, v, v);
1491 v_add(&point[p1].px, v, v);
1492 getNewName( buffer, "p" );
1493 p3= pnt( buffer, v[0], v[1], v[2], 0 );
1494 seta( nsave, "p", p3);
1495
1496 /* generate a fourth point perpendicular to the axis at a distant of r2 */
1497 v_prod( p1p2, pn, v);
1498 v_norm(v,v );
1499 v_scal( &r2, v, v);
1500 v_add(&point[p2].px, v, v);
1501 getNewName( buffer, "p" );
1502 p4= pnt( buffer, v[0], v[1], v[2], 0 );
1503 seta( nsave, "p", p4);
1504 }
1505 else if (compare(type, "TOR",3)==3)
1506 {
1507 typi=5;
1508 if (!addFlag) sscanf( record, "%s%*s%s%lf%s%lf", name, datum[0], &r1, datum[1], &r2 );
1509 else
1510 {
1511 name[0]='!';
1512 datum[0][0]=datum[1][0]='%';
1513 sscanf( record, "%s%*s%s%lf%s%lf", &name[1], &datum[0][1], &r1, &datum[1][1], &r2 );
1514 }
1515 operateAlias( datum[0], "p" );
1516 operateAlias( datum[1], "p" );
1517
1518 /* check if points exists */
1519 p1=getPntNr(datum[0]);
1520 if (p1==-1) /* new point */
1521 {
1522 printf ("ERROR: point %s of Shape %s not defined\n", datum[0], name);
1523 return;
1524 }
1525 p2=getPntNr(datum[1]);
1526 if (p2==-1) /* new point */
1527 {
1528 printf ("ERROR: point %s of Shape %s not defined\n", datum[1], name);
1529 return;
1530 }
1531 if(r1<0.)
1532 {
1533 printf ("ERROR: radius1 %f of Shape %s not valid\n", r1, name);
1534 return;
1535 }
1536 if(r2<0.)
1537 {
1538 printf ("ERROR: radius2 %f of Shape %s not valid\n", r2, name);
1539 return;
1540 }
1541 r1/=scale->w;
1542 r2/=scale->w;
1543
1544 /* generate a third point perpendicular to the axis at a distant of r1 */
1545 v_result( &point[p1].px, &point[p2].px, p1p2 );
1546 pn[0]=p1p2[1];
1547 pn[1]=p1p2[2];
1548 pn[2]=p1p2[0];
1549 v_prod( p1p2, pn, v);
1550 v_norm(v,v );
1551 v_scal( &r1, v, v);
1552 v_add(&point[p1].px, v, v);
1553 getNewName( buffer, "p" );
1554 p3= pnt( buffer, v[0], v[1], v[2], 0 );
1555 seta( nsave, "p", p3);
1556
1557 /* generate a fourth point perpendicular to the axis at a distant of r1+r2 */
1558 v_prod( p1p2, pn, v);
1559 v_norm(v,v );
1560 r12=r1+r2;
1561 v_scal( &r12, v, v);
1562 v_add(&point[p1].px, v, v);
1563 getNewName( buffer, "p" );
1564 p4= pnt( buffer, v[0], v[1], v[2], 0 );
1565 seta( nsave, "p", p4);
1566 }
1567 else if (compare(type, "SPH",3)==3)
1568 {
1569 typi=3;
1570 if (!addFlag) sscanf( record, "%s%*s%s%lf", name, datum[0], &r1 );
1571 else
1572 {
1573 name[0]='!';
1574 datum[0][0]=datum[1][0]='%';
1575 sscanf( record, "%s%*s%s%lf", &name[1], &datum[0][1], &r1 );
1576 }
1577 operateAlias( datum[0], "p" );
1578
1579 /* check if points exists */
1580 p1=getPntNr(datum[0]);
1581 if (p1==-1) /* new point */
1582 {
1583 printf ("ERROR: point %s of Shape %s not defined\n", datum[0], name);
1584 return;
1585 }
1586 if(r1<=0.)
1587 {
1588 printf ("ERROR: radius1 %f of Shape %s not valid\n", r1, name);
1589 return;
1590 }
1591
1592
1593 /* generate a second point perpendicular to the axis at a distant of r1 */
1594 v[0]=r1/scale->w;
1595 v[1]=0.;
1596 v[2]=0.;
1597 v_add(&point[p1].px, v, v);
1598 getNewName( buffer, "p" );
1599 p2= pnt( buffer, v[0], v[1], v[2], 0 );
1600 v[0]=0.;
1601 v[1]=r1/scale->w;
1602 v[2]=0.;
1603 v_add(&point[p1].px, v, v);
1604 getNewName( buffer, "p" );
1605 p3= pnt( buffer, v[0], v[1], v[2], 0 );
1606 v[0]=0.;
1607 v[1]=0.;
1608 v[2]=r1/scale->w;
1609 v_add(&point[p1].px, v, v);
1610 getNewName( buffer, "p" );
1611 p4= pnt( buffer, v[0], v[1], v[2], 0 );
1612 v[0]=-r1/scale->w;
1613 v[1]=0.;
1614 v[2]=0.;
1615 v_add(&point[p1].px, v, v);
1616 getNewName( buffer, "p" );
1617 p5= pnt( buffer, v[0], v[1], v[2], 0 );
1618 v[0]=0.;
1619 v[1]=-r1/scale->w;
1620 v[2]=0.;
1621 v_add(&point[p1].px, v, v);
1622 getNewName( buffer, "p" );
1623 p6= pnt( buffer, v[0], v[1], v[2], 0 );
1624 v[0]=0.;
1625 v[1]=0.;
1626 v[2]=-r1/scale->w;
1627 v_add(&point[p1].px, v, v);
1628 getNewName( buffer, "p" );
1629 p7= pnt( buffer, v[0], v[1], v[2], 0 );
1630 seta( nsave, "p", p2);
1631 seta( nsave, "p", p3);
1632 seta( nsave, "p", p4);
1633 seta( nsave, "p", p5);
1634 seta( nsave, "p", p6);
1635 seta( nsave, "p", p7);
1636 }
1637 else { printf(" ERROR: shpe type %s unknown\n", type); return; }
1638
1639 operateAlias( name, "sh" );
1640 if(printFlag) printf(" shpe %s %s %s %s %s %s\n", name, type, datum[0], datum[1], datum[2], datum[3]);
1641
1642 if( shape_i( name, typi, p1, p2, p3, p4, p5, p6, p7) <0)
1643 printf("ERROR: shape could not be created\n");
1644 }
1645
1646
1647 /*------------------------------------------------------------------*/
1648 /* define line */
1649 /*------------------------------------------------------------------*/
1650
delLine(int anzl,int * number)1651 void delLine( int anzl, int *number )
1652 {
1653 int j, k, *nrbuffer;
1654
1655 delLineFlag=1;
1656 /*
1657 printf ("sum:%d num:%d lin:%s\n", anzl, number[0], line[number[0]].name );
1658 */
1659 if ((nrbuffer = (int *)malloc((anzl+1)*sizeof(int)) ) == NULL )
1660 { printf("\n\nERROR: realloc failure in delSurf\n\n"); return; }
1661
1662 /* nessesary to store the numbers in a independent area */
1663 for (j=0; j<anzl; j++)
1664 nrbuffer[j]=number[j];
1665
1666 for (j=0; j<anzl; j++) if( line[nrbuffer[j]].name != (char *)NULL )
1667 {
1668 for (k=0; k<anz->sets; k++)
1669 {
1670 if(set[k].type==0)
1671 if( set[k].name != (char *)NULL )
1672 setr( k, "l", nrbuffer[j]);
1673 }
1674 if(printFlag) printf (" delete line:%s \n", line[nrbuffer[j]].name );
1675 free(line[nrbuffer[j]].name);
1676 line[nrbuffer[j]].name = (char *)NULL ;
1677 line[nrbuffer[j]].div = 0;
1678 if (line[nrbuffer[j]].typ=='s')
1679 {
1680 /* delete the set */
1681 delSet(set[line[nrbuffer[j]].trk].name);
1682 }
1683 line[nrbuffer[j]].typ=' ';
1684 line[nrbuffer[j]].etyp=0;
1685 line[nrbuffer[j]].p1=-1;
1686 line[nrbuffer[j]].p2=-1;
1687 line[nrbuffer[j]].trk=-1;
1688 line[nrbuffer[j]].nip= -1;
1689 free(line[nrbuffer[j]].ip);
1690 line[nrbuffer[j]].ip= NULL;
1691 line[nrbuffer[j]].nn= 0;
1692 free(line[nrbuffer[j]].nod);
1693 line[nrbuffer[j]].nod = NULL;
1694 line[nrbuffer[j]].ne= 0;
1695 free(line[nrbuffer[j]].elem);
1696 line[nrbuffer[j]].elem = NULL;
1697 }
1698 free(nrbuffer);
1699 }
1700
hashLine(SumAsci * sumAsci,char * name,int nr)1701 int hashLine( SumAsci *sumAsci, char *name, int nr)
1702 {
1703 int i=0,j=0, n;
1704 int sum=0;
1705
1706 while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
1707
1708 /* check if sum is higher as the allocated value */
1709 /* else look for a free entry */
1710 if(sum>sumAsci->max_suml)
1711 {
1712 if ((sumAsci->anzl=(int *)realloc( (int *)sumAsci->anzl, (sum+1)*sizeof(int)) ) == NULL )
1713 { printf("\n\nERROR: realloc failure in hashLine(), Line:%s not included\n\n", name); return(-1); }
1714 if ((sumAsci->lindx=(int **)realloc( (int **)sumAsci->lindx, (sum+1)*sizeof(int *)) ) == NULL )
1715 { printf("\n\nERROR: realloc failure in hashLine(), Line:%s not included\n\n", name); return(-1); }
1716 for(i=sumAsci->max_suml+1; i<=sum; i++) { sumAsci->anzl[i]=0; sumAsci->lindx[i]=NULL; }
1717 sumAsci->max_suml=sum;
1718 }
1719 else
1720 {
1721 if (delLineFlag)
1722 for (i=0; i<sumAsci->anzl[sum]; i++)
1723 {
1724 n=sumAsci->lindx[sum][i];
1725 if( line[n].name == (char *)NULL )
1726 {
1727 /* already existing space to fill */
1728 sumAsci->lindx[sum][i]=nr;
1729 return(sum);
1730 }
1731 }
1732 }
1733
1734 /* alloc of a new entry in the hash table */
1735 if ((sumAsci->lindx[sum]=(int *)realloc( (int *)sumAsci->lindx[sum], (sumAsci->anzl[sum]+1)*sizeof(int)) ) == NULL )
1736 { printf("\n\nERROR: realloc failure in hashLine(), line:%s not included\n\n", name); return(-1); }
1737
1738 sumAsci->lindx[sum][sumAsci->anzl[sum]] = nr;
1739 sumAsci->anzl[sum]++;
1740 return(sum);
1741 }
1742
1743
line_i(char * name,int ip1,int ip2,int trk,int div,double bias,char type)1744 int line_i( char *name, int ip1, int ip2, int trk, int div, double bias, char type )
1745 {
1746 int nr, i;
1747
1748 nr=getLineNr(name);
1749 if (nr==-1) /* new line */
1750 {
1751 if ((line = (Lines *)realloc( (Lines *)line, (anzGeo->l+1)*sizeof(Lines)) ) == NULL )
1752 { printf("\n\nERROR: realloc failure in line, line:%s not installed\n\n", name); return(-1); }
1753 nr=anzGeo->l;
1754 i=strlen(name);
1755 if((line[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1756 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1757 strcpy(line[nr].name, name);
1758 hashLine( sumAsci, name, nr );
1759 anzGeo->l++;
1760 line[nr].div = ddiv;
1761 line[nr].nod = NULL;
1762 line[nr].elem = NULL;
1763 line[nr].ip= NULL;
1764 }
1765 else if (nr<-1) /* replace a deleted line */
1766 {
1767 nr=-(nr+10);
1768 i=strlen(name);
1769 if((line[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1770 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1771 strcpy(line[nr].name, name);
1772 hashLine( sumAsci, name, nr );
1773 line[nr].div = ddiv;
1774 }
1775 else
1776 {
1777 if(printFlag) printf (" line %s in use: Definition will be changed\n", name);
1778 free(line[nr].nod);
1779 free(line[nr].elem);
1780 free(line[nr].ip);
1781 line[nr].nod = NULL;
1782 line[nr].elem = NULL;
1783 line[nr].ip= NULL;
1784 }
1785
1786 if(div>0) line[nr].div = div;
1787 if(line[nr].div<1) line[nr].div = ddiv;
1788 line[nr].p1=ip1;
1789 line[nr].p2=ip2;
1790 line[nr].bias = bias;
1791 line[nr].etyp=0;
1792 line[nr].eattr=0;
1793 line[nr].nn= 0;
1794 line[nr].ne= 0;
1795 line[nr].nip= 0;
1796 if (type==0)
1797 {
1798 line[nr].trk=-1;
1799 line[nr].typ=' ';
1800 }
1801 else
1802 {
1803 if (type=='s') set[trk].type=1;
1804 line[nr].trk=trk;
1805 line[nr].typ=type;
1806 }
1807
1808 for (i=0; i<anz->sets; i++)
1809 {
1810 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o'))
1811 {
1812 seta( i, "l", nr );
1813 if((set[i].etyp==11)||(set[i].etyp==12)) line[nr].etyp=set[i].etyp;
1814 }
1815 }
1816
1817 repLine(nr);
1818 return(nr);
1819 }
1820
1821
line_(char * name,char * p1,char * p2,char * trk,int div,double bias)1822 int line_( char *name, char *p1, char *p2, char *trk, int div, double bias )
1823 {
1824 int nr, i;
1825 int ip1, ip2, sum=0;
1826
1827 /* check if points exists */
1828 ip1=getPntNr(p1);
1829 if (ip1==-1) /* new point */
1830 {
1831 printf ("ERROR: point %s of Line %s not defined\n", p1, name);
1832 return(-1);
1833 }
1834 ip2=getPntNr(p2);
1835 if (ip2==-1) /* new point */
1836 {
1837 printf ("ERROR: point %s of Line %s not defined\n", p2, name);
1838 return(-1);
1839 }
1840
1841 nr=getLineNr(name);
1842 if (nr==-1) /* new line */
1843 {
1844 if ((line = (Lines *)realloc( (Lines *)line, (anzGeo->l+1)*sizeof(Lines)) ) == NULL )
1845 { printf("\n\nERROR: realloc failure in line, line:%s not installed\n\n", name); return(-1); }
1846 nr=anzGeo->l;
1847 i=strlen(name);
1848 if((line[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1849 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1850 strcpy(line[nr].name, name);
1851 sum=hashLine( sumAsci, name, nr );
1852 anzGeo->l++;
1853 line[nr].div = ddiv;
1854 line[nr].nod = NULL;
1855 line[nr].elem = NULL;
1856 line[nr].ip= NULL;
1857 }
1858 else if (nr<-1) /* replace a deleted line */
1859 {
1860 nr=-(nr+10);
1861 i=strlen(name);
1862 if((line[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
1863 { printf("ERROR: malloc failed\n\n" ); return(-1); }
1864 strcpy(line[nr].name, name);
1865 sum=hashLine( sumAsci, name, nr );
1866 line[nr].div = ddiv;
1867 }
1868 else
1869 {
1870 if(printFlag) printf (" line %s in use: Definition will be changed\n", name);
1871 free(line[nr].nod);
1872 free(line[nr].elem);
1873 free(line[nr].ip);
1874 line[nr].nod = NULL;
1875 line[nr].elem = NULL;
1876 line[nr].ip= NULL;
1877 }
1878
1879 line[nr].p1=ip1;
1880 line[nr].p2=ip2;
1881
1882 if (trk[0]!=' ')
1883 {
1884 i=getSetNr(trk);
1885 if (i>-1) /* SEQ */
1886 {
1887 set[i].type=1;
1888 line[nr].trk=i;
1889 line[nr].typ='s';
1890 }
1891 else
1892 {
1893 i=getPntNr(trk);
1894 if (i>-1) /* arc */
1895 {
1896 line[nr].trk=i;
1897 line[nr].typ='a';
1898 }
1899 else
1900 {
1901 printf ("ERROR: trk %s not defined, Line %s will be straight\n", trk, name);
1902 line[nr].trk=-1;
1903 line[nr].typ=' ';
1904 }
1905 }
1906 }
1907 else
1908 {
1909 line[nr].trk=-1;
1910 line[nr].typ=' ';
1911 }
1912
1913 if(div>0) line[nr].div = div;
1914 if(line[nr].div<1) line[nr].div = ddiv;
1915 line[nr].bias = bias;
1916 line[nr].etyp=0;
1917 line[nr].eattr=0;
1918 line[nr].nn= 0;
1919 line[nr].ne= 0;
1920 line[nr].nip= 0;
1921
1922 /* print the values of the hash table */
1923 if(sum<0) exit(-1);
1924 /*
1925 else printf(" asciSum:%d asci-indx:%d sumL in hash-table:%d name:%s index:%d\n"
1926 , sum, sumAsci->anzl[sum]-1, sumAsci->anzl[sum]
1927 , line[sumAsci->lindx[sum][sumAsci->anzl[sum]-1]].name
1928 , sumAsci->lindx[sum][sumAsci->anzl[sum]-1] );
1929 */
1930 for (i=0; i<anz->sets; i++)
1931 {
1932 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o'))
1933 {
1934 seta( i, "l", nr );
1935 if((set[i].etyp==11)||(set[i].etyp==12)) line[nr].etyp=set[i].etyp;
1936 }
1937 }
1938
1939 repLine(nr);
1940 return(nr);
1941 }
1942
1943
1944 /* calculates cadfix representation of bias */
1945 /* cadfix requires that a bias <=9 with no decimal-places is presented as integer */
1946 /* all other are integer *10 */
getBias_fbd(int l,Lines * line)1947 int getBias_fbd(int l, Lines *line)
1948 {
1949 int bias_fbd=0;
1950
1951 if((line[l].bias!=1.)&&(line[l].div>1))
1952 {
1953 if(line[l].bias<1.)
1954 {
1955 bias_fbd= (pow(1./line[l].bias,(line[l].div-1.))*-10.) -.5;
1956 }
1957 else
1958 {
1959 bias_fbd= (pow(line[l].bias,(line[l].div-1.))*10.) +.5;
1960 }
1961 }
1962 else bias_fbd= 1;
1963 if((abs(bias_fbd)<100)&&((bias_fbd%10)==0)) bias_fbd/=10;
1964 #if TEST
1965 printf("bias_fbd:%d\n", bias_fbd);
1966 #endif
1967 return(bias_fbd);
1968 }
1969
1970
splitBiasDiv(int * ptrdiv,double * ptrbias)1971 void splitBiasDiv(int *ptrdiv, double *ptrbias)
1972 {
1973 char datum[MAX_LINE_LENGTH];
1974 int div;
1975 double bias;
1976 int bias_fbd;
1977 int i;
1978
1979 div=*ptrdiv;
1980 bias=*ptrbias;
1981
1982
1983 /* determine bias and division */
1984 sprintf( datum, "%d", div);
1985 i=strlen( datum );
1986 if(i>2)
1987 {
1988 div=atoi( &datum[i-2]);
1989 datum[i-2]=0;
1990
1991 /* bias_fbd with more than one digit represents a float with one digit after the dot (x.x) * 10 as int */
1992 bias_fbd=atoi( datum);
1993
1994 /* for conversation from old bias definition to the new one */
1995 if(old_bias_def)
1996 bias_fbd*=10;
1997 else
1998 if(abs(bias_fbd)<10) bias_fbd*=10;
1999
2000
2001 #if TEST
2002 printf("div:%d bias_fbd:%d\n", div,bias_fbd);
2003 #endif
2004
2005 /* in the fbd-format-definition bias is defined as bias(a)=(elem_length(last)/elem_length(first)) */
2006 /* therefore a re-calculation is necessary because in cgx the definition is: */
2007 /* bias(b) = (elem_length(n+1)/elem_length(n)) => bias(a)= bias(b)**(div-1) */
2008 if((div>1)&&(abs(bias_fbd)>10))
2009 {
2010 if(bias_fbd<0) bias= 1./pow(((double)bias_fbd*-.1), (1./((double)div-1.)));
2011 else bias= pow(((double)bias_fbd*.1), (1./((double)div-1.)));
2012 }
2013 else bias=1.;
2014 }
2015 else
2016 {
2017 bias=1.;
2018 }
2019 if (div>MAX_LINE_DIV)
2020 {
2021 printf("WARNING: div:%d to high, reduced to %d\n",div, MAX_LINE_DIV);
2022 div=MAX_LINE_DIV;
2023 }
2024
2025 #if TEST
2026 printf("div:%d bias:%f\n", div,bias);
2027 #endif
2028
2029 *ptrdiv=div;
2030 *ptrbias=bias;
2031 }
2032
pre_line(char * record,int addFlag)2033 int pre_line( char *record, int addFlag)
2034 {
2035 int ii, i, j, length, div=0, lnr=-1;
2036 double bias=0.;
2037 char name[MAX_LINE_LENGTH], datum[5][MAX_LINE_LENGTH];
2038 int p1, p2, trk=-1;
2039 int buf1, buf2;
2040 char typ=0;
2041
2042 if (!addFlag) length = sscanf( record, "%s%s%s%s%s%s", name, datum[0], datum[1], datum[2], datum[3], datum[4] );
2043 else
2044 {
2045 name[0]='!';
2046 datum[0][0]=datum[1][0]='%';
2047 length = sscanf( record, "%s%s%s%s%s%s", &name[1], &datum[0][1], &datum[1][1], datum[2], datum[3], datum[4] );
2048 }
2049
2050 operateAlias( name, "l" );
2051 operateAlias( datum[0], "p" );
2052 operateAlias( datum[1], "p" );
2053
2054 /* check if a lcmb has this name, not use it */
2055 if (getLcmbNr(name) >0) {errMsg("ERROR: LCMB uses this name %s, try another name \n", name); return(-1);}
2056
2057 if ( length==3 )
2058 {
2059 div=0;
2060 datum[2][0]=0;
2061 }
2062 else if ( length==4 )
2063 {
2064 /* check if we get a valid division from arg4 */
2065 div=atoi(datum[2]);
2066 if ((div>0)||(div<0))
2067 {
2068 datum[2][0]=0;
2069 }
2070 else
2071 {
2072 div=0;
2073 if (addFlag) { for(i=strlen(datum[2]); i>=0; i--) datum[2][i+1]=datum[2][i]; datum[2][0]='%'; }
2074 operateAlias( datum[2], "p" );
2075 }
2076 }
2077 else if ( length==5 )
2078 {
2079 /* check if we get a valid division from arg4 then arg5 is bias */
2080 div=atoi(datum[2]);
2081 if ((div>0)||(div<0))
2082 {
2083 datum[2][0]=0;
2084 bias=atof(datum[3]);
2085 }
2086 else
2087 {
2088 div=atoi(datum[3]);
2089 if (addFlag) { for(i=strlen(datum[2]); i>=0; i--) datum[2][i+1]=datum[2][i]; datum[2][0]='%'; }
2090 operateAlias( datum[2], "p" );
2091 }
2092 }
2093 else if ( length==6 )
2094 {
2095 div=atoi(datum[3]);
2096 bias=atof(datum[4]);
2097 if (addFlag) { for(i=strlen(datum[2]); i>=0; i--) datum[2][i+1]=datum[2][i]; datum[2][0]='%'; }
2098 operateAlias( datum[2], "p" );
2099 }
2100 else
2101 {
2102 printf("ERROR: Inkorrect definition");
2103 return(-1);
2104 }
2105
2106 if(printFlag) printf("line:%s %s %s %s %d \n", name, datum[0], datum[1], datum[2], div);
2107
2108 /* check if points exists */
2109 p1=getPntNr(datum[0]);
2110 if (p1==-1) /* new point */
2111 {
2112 printf ("ERROR: point %s of Line %s not defined\n", datum[0], name);
2113 return(-1);
2114 }
2115 p2=getPntNr(datum[1]);
2116 if (p2==-1) /* new point */
2117 {
2118 printf ("ERROR: point %s of Line %s not defined\n", datum[1], name);
2119 return(-1);
2120 }
2121 if (datum[2][0])
2122 {
2123 i=getSetNr(datum[2]);
2124 if (i>-1) /* SEQ */
2125 {
2126 /* if a point of the same name exists then check if the line endpoints are endpoints in the seq. if not use point. */
2127 ii=getPntNr(datum[2]);
2128 if (ii>-1)
2129 {
2130 if( ((p1!=set[i].pnt[0])&&(p2!=set[i].pnt[0]))
2131 || ((p1!=set[i].pnt[set[i].anz_p-1])&&(p2!=set[i].pnt[set[i].anz_p-1])) )
2132 {
2133 /* its not a seq */
2134 trk=ii;
2135 typ='a';
2136 }
2137 }
2138 if(typ==0)
2139 {
2140 set[i].type=1;
2141 trk=i;
2142 typ='s';
2143
2144 /* special fix for bad defined seqa-lines */
2145
2146 /* - add the endpoints if the endpoints are not included in the set */
2147 /* search for the endpoint in the set */
2148 buf1=buf2=-1; for(j=0; j<set[i].anz_p; j++) { if(p1==set[i].pnt[j]) buf1=j; if(p2==set[i].pnt[j]) buf2=j; }
2149 if((buf1==-1) && (buf2==-1))
2150 {
2151 if ( (set[i].pnt = (int *)realloc((int *)set[i].pnt, (set[i].anz_p+2)*sizeof(int))) == NULL )
2152 printf(" ERROR: malloc failed in setr\n\n");
2153 for(j=set[i].anz_p; j>0; j--)
2154 {
2155 set[i].pnt[j]=set[i].pnt[j-1];
2156 }
2157 set[i].pnt[0]=p1;
2158 set[i].anz_p++;
2159
2160 if ( (set[i].pnt = (int *)realloc((int *)set[i].pnt, (set[i].anz_p+2)*sizeof(int))) == NULL )
2161 printf(" ERROR: malloc failed in setr\n\n");
2162 set[i].pnt[set[i].anz_p]=p2;
2163 set[i].anz_p++;
2164 }
2165 else if ((buf1==-1) || (buf2==-1))
2166 {
2167 printf("ERROR: just one endpoint in trk:%s, Line %s will be straight\n", set[i].name, name);
2168 trk=-1;
2169 typ=0;
2170 }
2171 }
2172 /* check if the seqence includes the end-points and has more than two points */
2173 if( ((p1!=set[i].pnt[0])&&(p2!=set[i].pnt[0]))
2174 || ((p1!=set[i].pnt[set[i].anz_p-1])&&(p2!=set[i].pnt[set[i].anz_p-1])) || (set[i].anz_p<3))
2175 {
2176 /* its not a valid seq */
2177 printf("ERROR: failure in trk:%s, Line %s will be straight\n", set[i].name, name);
2178 trk=-1;
2179 typ=0;
2180 }
2181 }
2182 else
2183 {
2184 i=getPntNr(datum[2]);
2185 if (i>-1) /* arc */
2186 {
2187 trk=i;
2188 typ='a';
2189 }
2190 else
2191 {
2192 printf ("ERROR: trk %s not defined, Line %s will be straight\n", datum[2], name);
2193 trk=-1;
2194 typ=0;
2195 }
2196 }
2197 }
2198 else
2199 {
2200 trk=-1;
2201 typ=0;
2202 }
2203
2204 /* determine bias and division (+conversion from old to new bias-definition) */
2205 old_bias_def=OLD_BIAS_DEF;
2206
2207 if(bias==0.) splitBiasDiv(&div, &bias);
2208
2209 old_bias_def=0;
2210
2211 /* check the orientation of the sequence-set */
2212 if (typ=='s')
2213 {
2214 if (p2==set[trk].pnt[0])
2215 {
2216 printf("WARNING: sequence:%s in line:%s wrong defined, line inverted\n",set[trk].name,name);
2217 i=p2;
2218 p2=p1;
2219 p1=i;
2220 }
2221 }
2222 if( (lnr=line_i( name, p1, p2, trk, div, bias, typ)) <0)
2223 printf("ERROR: line could not be created\n");
2224 return(lnr);
2225 }
2226
2227
2228
2229 /*------------------------------------------------------------------*/
2230 /* define lcmb */
2231 /*------------------------------------------------------------------*/
2232
delLcmb(int anzc,int * number)2233 void delLcmb( int anzc, int *number )
2234 {
2235 int j, k, *nrbuffer;
2236
2237 #if TEST
2238 printf("delLcmb\n");
2239 #endif
2240
2241 delLcmbFlag=1;
2242 /*
2243 printf ("sum:%d num:%d lcmb:%s\n", anzc, number[0], lcmb[number[0]].name );
2244 */
2245 if ((nrbuffer = (int *)malloc((anzc+1)*sizeof(int)) ) == NULL )
2246 { printf("\n\nERROR: realloc failure in delLcmb\n\n"); return; }
2247
2248 /* nessesary to store the numbers in a independent area */
2249 for (j=0; j<anzc; j++)
2250 nrbuffer[j]=number[j];
2251
2252 for (j=0; j<anzc; j++) if( lcmb[nrbuffer[j]].name != (char *)NULL )
2253 {
2254 for (k=0; k<anz->sets; k++)
2255 {
2256 if(set[k].type==0)
2257 if( set[k].name != (char *)NULL )
2258 setr( k, "c", nrbuffer[j]);
2259 }
2260 if(printFlag) printf (" delete lcmb:%s \n", lcmb[nrbuffer[j]].name );
2261 free(lcmb[nrbuffer[j]].name);
2262 lcmb[nrbuffer[j]].name = (char *)NULL;
2263 lcmb[nrbuffer[j]].nl=0;
2264 free(lcmb[nrbuffer[j]].o);
2265 lcmb[nrbuffer[j]].o= NULL;
2266 free(lcmb[nrbuffer[j]].l);
2267 lcmb[nrbuffer[j]].l= NULL;
2268 lcmb[nrbuffer[j]].p1=-1;
2269 lcmb[nrbuffer[j]].p2=-1;
2270 }
2271 free(nrbuffer);
2272 }
2273
2274
hashLcmb(SumAsci * sumAsci,char * name,int nr)2275 int hashLcmb( SumAsci *sumAsci, char *name, int nr)
2276 {
2277 int i=0,j=0, n;
2278 int sum=0;
2279
2280 #if TEST
2281 printf("hashLcmb\n");
2282 #endif
2283
2284 while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
2285
2286 /* check if sum is higher as the allocated value */
2287 /* else look for a free entry */
2288 if(sum>sumAsci->max_sumc)
2289 {
2290 if ((sumAsci->anzc=(int *)realloc( (int *)sumAsci->anzc, (sum+1)*sizeof(int)) ) == NULL )
2291 { printf("\n\nERROR: realloc failure in hashLcmb(), Lcmb:%s not included\n\n", name); return(-1); }
2292 if ((sumAsci->cindx=(int **)realloc( (int **)sumAsci->cindx, (sum+1)*sizeof(int *)) ) == NULL )
2293 { printf("\n\nERROR: realloc failure in hashLcmb(), Lcmb:%s not included\n\n", name); return(-1); }
2294 for(i=sumAsci->max_sumc+1; i<=sum; i++) { sumAsci->anzc[i]=0; sumAsci->cindx[i]=NULL; }
2295 sumAsci->max_sumc=sum;
2296 }
2297 else
2298 {
2299 /* look for a free entry */
2300 if (delLcmbFlag)
2301 for (i=0; i<sumAsci->anzc[sum]; i++)
2302 {
2303 n=sumAsci->cindx[sum][i];
2304 if( lcmb[n].name == (char *)NULL )
2305 {
2306 /* already existing space to fill */
2307 sumAsci->cindx[sum][i]=nr;
2308 return(sum);
2309 }
2310 }
2311 }
2312
2313 /* alloc of a new entry in the hash table */
2314 if ((sumAsci->cindx[sum]
2315 =(int *)realloc( (int *)sumAsci->cindx[sum], (sumAsci->anzc[sum]+1)*sizeof(int)) ) == NULL )
2316 { printf("\n\nERROR: realloc failure in hashLcmb(), lcmb:%s not included\n\n", name); return(-1); }
2317
2318 sumAsci->cindx[sum][sumAsci->anzc[sum]] = nr;
2319 sumAsci->anzc[sum]++;
2320 return(sum);
2321 }
2322
2323
lcmb_i(char * name,int add,int anz_l,char * ori,int * lin)2324 int lcmb_i( char *name, int add, int anz_l, char *ori, int *lin )
2325 {
2326 int nr, i;
2327 int sum=0, offset=0;
2328
2329 #if TEST
2330 printf("lcmb_i\n");
2331 #endif
2332
2333 nr=getLcmbNr(name);
2334 if (nr==-1) /* new lcmb */
2335 {
2336 if ((lcmb = (Lcmb *)realloc( (Lcmb *)lcmb, (anzGeo->c+1)*sizeof(Lcmb)) ) == NULL )
2337 { printf("\n\nERROR: realloc failure in lcmb_, lcmb:%s not installed\n\n", name); return(-1); }
2338 nr=anzGeo->c;
2339 if ((lcmb[nr].o = (char *)malloc( (anz_l+1)*sizeof(char)) ) == NULL )
2340 { printf("\n\nERROR: malloc failure in lcmb_, lcmb.o:%s not installed\n\n", name); return(-1); }
2341 if ((lcmb[nr].l = (int *)malloc( (anz_l+1)*sizeof(int)) ) == NULL )
2342 { printf("\n\nERROR: malloc failure in lcmb_, lcmb.l:%s not installed\n\n", name); return(-1); }
2343 anzGeo->c++;
2344 i=strlen(name);
2345 if((lcmb[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2346 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2347 strcpy(lcmb[nr].name, name);
2348 sum=hashLcmb( sumAsci, name, nr );
2349 }
2350 else if (nr<-1) /* replace a deleted lcmb */
2351 {
2352 nr=-(nr+10);
2353 if ((lcmb[nr].o = (char *)realloc( (char *)lcmb[nr].o, (anz_l+1)*sizeof(char)) ) == NULL )
2354 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.o :%s not installed\n\n", name); return(-1); }
2355 if ((lcmb[nr].l = (int *)realloc( (int *)lcmb[nr].l, (anz_l+1)*sizeof(int)) ) == NULL )
2356 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.l:%s not installed\n\n", name); return(-1); }
2357 i=strlen(name);
2358 if((lcmb[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2359 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2360 strcpy(lcmb[nr].name, name);
2361 sum=hashLcmb( sumAsci, name, nr );
2362 }
2363 else
2364 {
2365 if(add) offset=lcmb[nr].nl;
2366 /* check the number of lines */
2367 if(printFlag) printf (" lcmb in use: Definition will be changed\n");
2368 if ((lcmb[nr].o = (char *)realloc( (char *)lcmb[nr].o, (anz_l+offset+1)*sizeof(char)) ) == NULL )
2369 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.o:%s not installed\n\n", name); return(-1); }
2370 if ((lcmb[nr].l = (int *)realloc( (int *)lcmb[nr].l, (anz_l+offset+1)*sizeof(int)) ) == NULL )
2371 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.l:%s not installed\n\n", name); return(-1); }
2372 }
2373 for (i=0; i<anz_l; i++)
2374 {
2375 lcmb[nr].l[i+offset]=lin[i];
2376 lcmb[nr].o[i+offset]=ori[i];
2377 }
2378 lcmb[nr].nl= anz_l+offset;
2379
2380 /* print the values of the hash table */
2381 if(sum<0) exit(-1);
2382 /*
2383 else printf(" asciSum:%d asci-indx:%d sumC in hash-table:%d name:%s index:%d\n"
2384 , sum, sumAsci->anzc[sum]-1, sumAsci->anzc[sum]
2385 , lcmb[sumAsci->cindx[sum][sumAsci->anzc[sum]-1]].name
2386 , sumAsci->cindx[sum][sumAsci->anzc[sum]-1] );
2387 */
2388
2389 /* orient the new lcmb */
2390 if ( orientLcmb( nr ) <0 )
2391 {
2392 errMsg ("ERROR: orientLcmb:%s failed\n", name);
2393 delLcmb( 1, &nr );
2394 return(-1);
2395 }
2396 for (i=0; i<anz->sets; i++)
2397 {
2398 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o')) seta( i, "c", nr );
2399 }
2400 return(nr);
2401 }
2402
2403
lcmb_(char * name,int add,int anz_l,char * ori,char * lin)2404 int lcmb_( char *name, int add, int anz_l, char *ori, char *lin )
2405 {
2406 int nr, i, lnr;
2407 int sum=0, offset=0;
2408
2409 #if TEST
2410 printf("lcmb_\n");
2411 #endif
2412
2413 nr=getLcmbNr(name);
2414 if (nr==-1) /* new lcmb */
2415 {
2416 if ((lcmb = (Lcmb *)realloc( (Lcmb *)lcmb, (anzGeo->c+1)*sizeof(Lcmb)) ) == NULL )
2417 { printf("\n\nERROR: realloc failure in lcmb_, lcmb:%s not installed\n\n", name); return(-1); }
2418 nr=anzGeo->c;
2419 if ((lcmb[nr].o = (char *)malloc( (anz_l+1)*sizeof(char)) ) == NULL )
2420 { printf("\n\nERROR: malloc failure in lcmb_, lcmb.o:%s not installed\n\n", name); return(-1); }
2421 if ((lcmb[nr].l = (int *)malloc( (anz_l+1)*sizeof(int)) ) == NULL )
2422 { printf("\n\nERROR: malloc failure in lcmb_, lcmb.l:%s not installed\n\n", name); return(-1); }
2423 anzGeo->c++;
2424 i=strlen(name);
2425 if((lcmb[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2426 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2427 strcpy(lcmb[nr].name, name);
2428 sum=hashLcmb( sumAsci, name, nr );
2429 }
2430 else if (nr<-1) /* replace a deleted lcmb */
2431 {
2432 nr=-(nr+10);
2433 if ((lcmb[nr].o = (char *)realloc( (char *)lcmb[nr].o, (anz_l+1)*sizeof(char)) ) == NULL )
2434 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.o :%s not installed\n\n", name); return(-1); }
2435 if ((lcmb[nr].l = (int *)realloc( (int *)lcmb[nr].l, (anz_l+1)*sizeof(int)) ) == NULL )
2436 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.l:%s not installed\n\n", name); return(-1); }
2437 i=strlen(name);
2438 if((lcmb[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2439 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2440 strcpy(lcmb[nr].name, name);
2441 sum=hashLcmb( sumAsci, name, nr );
2442 }
2443 else
2444 {
2445 if(add) offset=lcmb[nr].nl;
2446 if(printFlag) printf (" lcmb in use: Definition will be changed\n");
2447 if ((lcmb[nr].o = (char *)realloc( (char *)lcmb[nr].o, (anz_l+offset+1)*sizeof(char)) ) == NULL )
2448 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.o:%s not installed\n\n", name); return(-1); }
2449 if ((lcmb[nr].l = (int *)realloc( (int *)lcmb[nr].l, (anz_l+offset+1)*sizeof(int)) ) == NULL )
2450 { printf("\n\nERROR: realloc failure in lcmb_, lcmb.l:%s not installed\n\n", name); return(-1); }
2451 }
2452 for (i=0; i<anz_l; i++)
2453 {
2454 lnr=getLineNr((char*)&lin[i*MAX_LINE_LENGTH]);
2455 if( lnr>-1 ) { lcmb[nr].l[i+offset]=lnr; }
2456 else
2457 {
2458 errMsg ("ERROR: line:%s in lcmb:%s are undefined\n", &lin[i*MAX_LINE_LENGTH], lcmb[nr].name );
2459 if(printFlag) printf (" delete lcmb:%s \n", lcmb[nr].name );
2460 lcmb[nr].name = (char *)NULL ;
2461 return(-1);
2462 }
2463 lcmb[nr].o[i+offset]=ori[i*2];
2464 }
2465 lcmb[nr].nl= anz_l+offset;
2466
2467 /* print the values of the hash table */
2468 if(sum<0) exit(-1);
2469 /*
2470 else printf(" asciSum:%d asci-indx:%d sumC in hash-table:%d name:%s index:%d\n"
2471 , sum, sumAsci->anzc[sum]-1, sumAsci->anzc[sum]
2472 , lcmb[sumAsci->cindx[sum][sumAsci->anzc[sum]-1]].name
2473 , sumAsci->cindx[sum][sumAsci->anzc[sum]-1] );
2474 */
2475
2476 /* orient the new lcmb */
2477 if ( orientLcmb( nr ) <0 )
2478 {
2479 errMsg ("ERROR: orientLcmb:%s failed\n", name);
2480 delLcmb( 1, &nr );
2481 return(-1);
2482 }
2483 for (i=0; i<anz->sets; i++)
2484 {
2485 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o')) seta( i, "c", nr );
2486 }
2487 return(nr);
2488 }
2489
2490
pre_lcmb(char * record,int addFlag)2491 void pre_lcmb( char *record, int addFlag)
2492 {
2493 int i,j, length, anz_l, add;
2494 char name[MAX_LINE_LENGTH], typ[MAX_LINE_LENGTH];
2495 char ori[14][2], lin[14][MAX_LINE_LENGTH];
2496
2497 #if TEST
2498 printf("pre_lcmb\n");
2499 #endif
2500
2501 if (!addFlag) length = sscanf( record, "%s%s", name, typ);
2502 else
2503 {
2504 length = sscanf( record, "%s%s", &name[1], typ);
2505 if( compare(typ, "ADD", 3) == 3) name[0]='%'; else name[0]='!';
2506 }
2507 operateAlias( name, "c" );
2508
2509 /* check if a line has this name, not use it */
2510 if (getLineNr(name) >0) { errMsg("ERROR: Could not create lcmb:%s A LINE uses this name already\n", name); return; }
2511
2512 if( compare(typ, "ADD", 3) == 3)
2513 {
2514 add=1;
2515 length = sscanf( record, "%*s%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
2516 ori[0], lin[0],ori[1], lin[1],
2517 ori[2], lin[2],ori[3], lin[3],ori[4], lin[4],ori[5], lin[5],ori[6], lin[6],ori[7], lin[7],
2518 ori[8], lin[8],ori[9], lin[9],ori[10], lin[10],ori[11], lin[11],ori[12], lin[12],ori[13], lin[13] );
2519 }
2520 else
2521 {
2522 add=0;
2523 length = sscanf( record, "%*s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
2524 ori[0], lin[0],ori[1], lin[1],
2525 ori[2], lin[2],ori[3], lin[3],ori[4], lin[4],ori[5], lin[5],ori[6], lin[6],ori[7], lin[7],
2526 ori[8], lin[8],ori[9], lin[9],ori[10], lin[10],ori[11], lin[11],ori[12], lin[12],ori[13], lin[13] );
2527 }
2528 anz_l=length/2;
2529 if(printFlag) printf("lcmb: %s ", name );
2530 for (i=0; i<anz_l; i++)
2531 {
2532 if (addFlag) { for(j=strlen(lin[i]); j>=0; j--) lin[i][j+1]=lin[i][j]; lin[i][0]='%'; }
2533 operateAlias( lin[i], "l" );
2534 if ((ori[i][0]=='+')||(ori[i][0]=='-'))
2535 {
2536 if(printFlag) printf("%s %s ", ori[i], lin[i]);
2537 }
2538 else
2539 {
2540 printf("ERROR: Orientation:%s of line:%s not recognized\n", ori[i], lin[i] );
2541 return;
2542 }
2543 }
2544 if(printFlag) printf("\n");
2545 i=lcmb_( name, add, anz_l, &ori[0][0], &lin[0][0] );
2546 if( i <0)
2547 {
2548 printf("ERROR: lcmb could not be created\n");
2549 pre_seta( specialset->zap, "c", name);
2550 zap(specialset->zap);
2551 }
2552 }
2553
2554
2555 /*------------------------------------------------------------------*/
2556 /* define surface */
2557 /*------------------------------------------------------------------*/
2558
delSurf(int anzc,int * number)2559 void delSurf( int anzc, int *number )
2560 {
2561 int j, k, *nrbuffer;
2562
2563 delSurfFlag=1;
2564 /*
2565 printf ("sum:%d num:%d surf:%s\n", anzc, number[0], surf[number[0]].name );
2566 */
2567 if ((nrbuffer = (int *)malloc((anzc+1)*sizeof(int)) ) == NULL )
2568 { printf("\n\nERROR: realloc failure in delSurf\n\n"); return; }
2569
2570 /* nessesary to store the numbers in a independent area */
2571 for (j=0; j<anzc; j++)
2572 nrbuffer[j]=number[j];
2573
2574 for (j=0; j<anzc; j++) if( surf[nrbuffer[j]].name != (char *)NULL )
2575 {
2576 for (k=0; k<anz->sets; k++)
2577 {
2578 if(set[k].type==0)
2579 if( set[k].name != (char *)NULL )
2580 setr( k, "s", nrbuffer[j]);
2581 }
2582 if(printFlag) printf (" delete surf:%s \n", surf[nrbuffer[j]].name );
2583 if(surf[nrbuffer[j]].sh>-1)
2584 {
2585 shape[surf[nrbuffer[j]].sh].ns=iremove(&shape[surf[nrbuffer[j]].sh].s, shape[surf[nrbuffer[j]].sh].ns, nrbuffer[j]);
2586 surf[nrbuffer[j]].sh=-1;
2587 }
2588 free(surf[nrbuffer[j]].name);
2589 surf[nrbuffer[j]].name = (char *)NULL ;
2590 surf[nrbuffer[j]].nl= 0;
2591 free(surf[nrbuffer[j]].typ);
2592 surf[nrbuffer[j]].typ= NULL;
2593 free(surf[nrbuffer[j]].o);
2594 surf[nrbuffer[j]].o= NULL;
2595 free(surf[nrbuffer[j]].l);
2596 surf[nrbuffer[j]].l= NULL;
2597 surf[nrbuffer[j]].nn= 0;
2598 free(surf[nrbuffer[j]].nod);
2599 surf[nrbuffer[j]].nod= NULL;
2600 surf[nrbuffer[j]].ne= 0;
2601 free(surf[nrbuffer[j]].elem);
2602 surf[nrbuffer[j]].elem= NULL;
2603 surf[nrbuffer[j]].etyp= 0;
2604 surf[nrbuffer[j]].npgn= 0;
2605 free(surf[nrbuffer[j]].pgn);
2606 surf[nrbuffer[j]].pgn= NULL;
2607 }
2608 free(nrbuffer);
2609 }
2610
2611
hashSurf(SumAsci * sumAsci,char * name,int nr)2612 int hashSurf( SumAsci *sumAsci, char *name, int nr)
2613 {
2614 int i=0,j=0, n;
2615 int sum=0;
2616
2617 while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
2618
2619 /* check if sum is higher as the allocated value */
2620 /* else look for a free entry */
2621 if(sum>sumAsci->max_sums)
2622 {
2623 if ((sumAsci->anzs=(int *)realloc( (int *)sumAsci->anzs, (sum+1)*sizeof(int)) ) == NULL )
2624 { printf("\n\nERROR: realloc failure in hashSurf(), Surf:%s not included\n\n", name); return(-1); }
2625 if ((sumAsci->sindx=(int **)realloc( (int **)sumAsci->sindx, (sum+1)*sizeof(int *)) ) == NULL )
2626 { printf("\n\nERROR: realloc failure in hashSurf(), Surf:%s not included\n\n", name); return(-1); }
2627 for(i=sumAsci->max_sums+1; i<=sum; i++) { sumAsci->anzs[i]=0; sumAsci->sindx[i]=NULL; }
2628 sumAsci->max_sums=sum;
2629 }
2630 else
2631 {
2632 if (delSurfFlag)
2633 for (i=0; i<sumAsci->anzs[sum]; i++)
2634 {
2635 n=sumAsci->sindx[sum][i];
2636 if( surf[n].name == (char *)NULL )
2637 {
2638 /* already existing space to fill */
2639 sumAsci->sindx[sum][i]=nr;
2640 return(sum);
2641 }
2642 }
2643 }
2644
2645 /* alloc of a new entry in the hash table */
2646 if ((sumAsci->sindx[sum]
2647 =(int *)realloc( (int *)sumAsci->sindx[sum], (sumAsci->anzs[sum]+1)*sizeof(int)) ) == NULL )
2648 { printf("\n\nERROR: realloc failure in hashSurf(), surf:%s not included\n\n", name); return(-1); }
2649
2650 sumAsci->sindx[sum][sumAsci->anzs[sum]] = nr;
2651 sumAsci->anzs[sum]++;
2652 return(sum);
2653 }
2654
2655
surface_i(char * name,char ori,int blend,int anz_c,char * cori,int * edge,char * ctyp)2656 int surface_i( char *name, char ori, int blend, int anz_c, char *cori, int *edge, char *ctyp )
2657 {
2658 int nr, i;
2659 int sum=0;
2660 nr=getSurfNr(name);
2661 if (nr==-1) /* new surf */
2662 {
2663 if ((surf = (Gsur *)realloc( (Gsur *)surf, (anzGeo->s+1)*sizeof(Gsur)) ) == NULL )
2664 { printf("\n\nERROR: realloc failure in surface, surf:%s not installed\n\n", name); return(-1); }
2665 nr=anzGeo->s;
2666 if ((surf[nr].typ = (char *)malloc( (anz_c+1)*sizeof(char)) ) == NULL )
2667 { printf("\n\nERROR: malloc failure in surface, surf.typ:%s not installed\n\n", name); return(-1); }
2668 if ((surf[nr].o = (char *)malloc( (anz_c+1)*sizeof(char)) ) == NULL )
2669 { printf("\n\nERROR: malloc failure in surface, surf.o:%s not installed\n\n", name); return(-1); }
2670 if ((surf[nr].l = (int *)malloc( (anz_c+1)*sizeof(int)) ) == NULL )
2671 { printf("\n\nERROR: malloc failure in surface, surf.l:%s not installed\n\n", name); return(-1); }
2672 anzGeo->s++;
2673 i=strlen(name);
2674 if((surf[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2675 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2676 strcpy(surf[nr].name, name);
2677 sum=hashSurf( sumAsci, name, nr );
2678 surf[nr].nc= 0;
2679 surf[nr].nn= 0;
2680 surf[nr].ne= 0;
2681 surf[nr].c= NULL;
2682 surf[nr].nod= NULL;
2683 surf[nr].elem= NULL;
2684 surf[nr].npgn= 0;
2685 surf[nr].pgn= NULL;
2686 surf[nr].eattr=0;
2687 surf[nr].eparm=(char *)NULL;
2688 surf[nr].etyp=0;
2689 }
2690 else if (nr<-1) /* replace a deleted surf */
2691 {
2692 nr=-(nr+10);
2693 if ((surf[nr].typ = (char *)realloc( (char *)surf[nr].typ, (anz_c+1)*sizeof(char)) ) == NULL )
2694 { printf("\n\nERROR: realloc failure in surface, surf.typ:%s not installed\n\n", name); return(-1); }
2695 if ((surf[nr].o = (char *)realloc( (char *)surf[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
2696 { printf("\n\nERROR: realloc failure in surface, surf.o:%s not installed\n\n", name); return(-1); }
2697 if ((surf[nr].l = (int *)realloc( (int *)surf[nr].l, (anz_c+1)*sizeof(int)) ) == NULL )
2698 { printf("\n\nERROR: realloc failure in surface, surf.l:%s not installed\n\n", name); return(-1); }
2699 i=strlen(name);
2700 if((surf[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2701 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2702 strcpy(surf[nr].name, name);
2703 sum=hashSurf( sumAsci, name, nr );
2704 surf[nr].eattr=0;
2705 surf[nr].eparm=(char *)NULL;
2706 surf[nr].etyp=0;
2707 }
2708 else
2709 {
2710 if(printFlag) printf (" surf in use: Definition will be changed\n");
2711 if ((surf[nr].typ = (char *)realloc( (char *)surf[nr].typ, (anz_c+1)*sizeof(char)) ) == NULL )
2712 { printf("\n\nERROR: realloc failure in surface, surf.typ:%s not installed\n\n", name); return(-1); }
2713 if ((surf[nr].o = (char *)realloc( (char *)surf[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
2714 { printf("\n\nERROR: realloc failure in surface, surf.o:%s not installed\n\n", name); return(-1); }
2715 if ((surf[nr].l = (int *)realloc( (int *)surf[nr].l, (anz_c+1)*sizeof(int)) ) == NULL )
2716 { printf("\n\nERROR: realloc failure in surface, surf.l:%s not installed\n\n", name); return(-1); }
2717 free(surf[nr].c);
2718 free(surf[nr].nod);
2719 free(surf[nr].elem);
2720 surf[nr].c= NULL;
2721 surf[nr].nod= NULL;
2722 surf[nr].elem= NULL;
2723 surf[nr].nc= 0;
2724 surf[nr].nn= 0;
2725 surf[nr].ne= 0;
2726 surf[nr].npgn= 0;
2727 free(surf[nr].pgn);
2728 surf[nr].pgn= NULL;
2729 }
2730
2731 for (i=0; i<anz_c; i++)
2732 {
2733 surf[nr].typ[i]= ctyp[i];
2734 surf[nr].l[i] = edge[i];
2735 surf[nr].o[i] = cori[i];
2736 }
2737 surf[nr].sh= blend;
2738 if(surf[nr].sh>-1) shape_refSurf(surf[nr].sh, nr);
2739 surf[nr].ori= ori;
2740 surf[nr].nl= anz_c;
2741 surf[nr].fail= 0;
2742 surf[nr].patch= 0;
2743
2744 /* print the values of the hash table */
2745 if(sum<0) exit(-1);
2746 /*
2747 else printf(" asciSum:%d asci-indx:%d sums in hash-table:%d name:%s index:%d\n"
2748 , sum, sumAsci->anzs[sum]-1, sumAsci->anzs[sum]
2749 , surf[sumAsci->sindx[sum][sumAsci->anzs[sum]-1]].name
2750 , sumAsci->sindx[sum][sumAsci->anzs[sum]-1] );
2751 */
2752
2753 /* orient the new surf */
2754 if ( orientSurf( nr ) <0 )
2755 {
2756 errMsg ("ERROR: orientSurf:%s failed\n", name);
2757 surf[nr].name = (char *)NULL ;
2758 return(-1);
2759 }
2760 for (i=0; i<anz->sets; i++)
2761 {
2762 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o'))
2763 {
2764 seta( i, "s", nr );
2765 if((set[i].etyp>6)&&(set[i].etyp<11)) surf[nr].etyp=set[i].etyp;
2766 }
2767 }
2768 return(nr);
2769 }
2770
surface(char * name,char ori,char * blend,int anz_c,char * cori,char * edge)2771 int surface( char *name, char ori, char *blend, int anz_c, char *cori, char *edge )
2772 {
2773 int nr, i, lnr, cnr;
2774 int sum=0;
2775
2776 nr=getSurfNr(name);
2777 if (nr==-1) /* new surf */
2778 {
2779 if ((surf = (Gsur *)realloc( (Gsur *)surf, (anzGeo->s+1)*sizeof(Gsur)) ) == NULL )
2780 { printf("\n\nERROR: realloc failure in surface, surf:%s not installed\n\n", name); return(-1); }
2781 nr=anzGeo->s;
2782 if ((surf[nr].typ = (char *)malloc( (anz_c+1)*sizeof(char)) ) == NULL )
2783 { printf("\n\nERROR: malloc failure in surface, surf.typ:%s not installed\n\n", name); return(-1); }
2784 if ((surf[nr].o = (char *)malloc( (anz_c+1)*sizeof(char)) ) == NULL )
2785 { printf("\n\nERROR: malloc failure in surface, surf.o:%s not installed\n\n", name); return(-1); }
2786 if ((surf[nr].l = (int *)malloc( (anz_c+1)*sizeof(int)) ) == NULL )
2787 { printf("\n\nERROR: malloc failure in surface, surf.l:%s not installed\n\n", name); return(-1); }
2788 anzGeo->s++;
2789 i=strlen(name);
2790 if((surf[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2791 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2792 strcpy(surf[nr].name, name);
2793 sum=hashSurf( sumAsci, name, nr );
2794 surf[nr].nc= 0;
2795 surf[nr].nn= 0;
2796 surf[nr].ne= 0;
2797 surf[nr].c= NULL;
2798 surf[nr].nod= NULL;
2799 surf[nr].elem= NULL;
2800 surf[nr].npgn= 0;
2801 surf[nr].pgn= NULL;
2802 }
2803 else if (nr<-1) /* replace a deleted surf */
2804 {
2805 nr=-(nr+10);
2806 if ((surf[nr].typ = (char *)realloc( (char *)surf[nr].typ, (anz_c+1)*sizeof(char)) ) == NULL )
2807 { printf("\n\nERROR: realloc failure in surface, surf.typ:%s not installed\n\n", name); return(-1); }
2808 if ((surf[nr].o = (char *)realloc( (char *)surf[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
2809 { printf("\n\nERROR: realloc failure in surface, surf.o:%s not installed\n\n", name); return(-1); }
2810 if ((surf[nr].l = (int *)realloc( (int *)surf[nr].l, (anz_c+1)*sizeof(int)) ) == NULL )
2811 { printf("\n\nERROR: realloc failure in surface, surf.l:%s not installed\n\n", name); return(-1); }
2812 i=strlen(name);
2813 if((surf[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
2814 { printf("ERROR: malloc failed\n\n" ); return(-1); }
2815 strcpy(surf[nr].name, name);
2816 sum=hashSurf( sumAsci, name, nr );
2817 }
2818 else
2819 {
2820 if(printFlag) printf (" surf in use: Definition will be changed\n");
2821 if ((surf[nr].typ = (char *)realloc( (char *)surf[nr].typ, (anz_c+1)*sizeof(char)) ) == NULL )
2822 { printf("\n\nERROR: realloc failure in surface, surf.typ:%s not installed\n\n", name); return(-1); }
2823 if ((surf[nr].o = (char *)realloc( (char *)surf[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
2824 { printf("\n\nERROR: realloc failure in surface, surf.o:%s not installed\n\n", name); return(-1); }
2825 if ((surf[nr].l = (int *)realloc( (int *)surf[nr].l, (anz_c+1)*sizeof(int)) ) == NULL )
2826 { printf("\n\nERROR: realloc failure in surface, surf.l:%s not installed\n\n", name); return(-1); }
2827 free(surf[nr].c);
2828 free(surf[nr].nod);
2829 free(surf[nr].elem);
2830 surf[nr].c= NULL;
2831 surf[nr].nod= NULL;
2832 surf[nr].elem= NULL;
2833 surf[nr].nc= 0;
2834 surf[nr].nn= 0;
2835 surf[nr].ne= 0;
2836 surf[nr].npgn= 0;
2837 free(surf[nr].pgn);
2838 surf[nr].pgn= NULL;
2839 }
2840
2841 for (i=0; i<anz_c; i++)
2842 {
2843 operateAlias( (char*)&edge[i*MAX_LINE_LENGTH], "l" );
2844 lnr=getLineNr((char*)&edge[i*MAX_LINE_LENGTH]);
2845 operateAlias( (char*)&edge[i*MAX_LINE_LENGTH], "c" );
2846 cnr=getLcmbNr((char*)&edge[i*MAX_LINE_LENGTH]);
2847 if( lnr>-1 ) { surf[nr].typ[i]='l'; surf[nr].l[i]=lnr; }
2848 else if( cnr>-1 ) { surf[nr].typ[i]='c'; surf[nr].l[i]=cnr; }
2849 else
2850 {
2851 errMsg ("ERROR: line:%s in surf:%s is undefined\n", &edge[i*MAX_LINE_LENGTH], name );
2852 if(printFlag) printf (" delete surf:%s \n", surf[nr].name );
2853 surf[nr].name = (char *)NULL ;
2854 return(-1);
2855 }
2856 surf[nr].o[i]=cori[i*2];
2857 }
2858 operateAlias( blend, "S" );
2859 surf[nr].sh= getShapeNr(blend);
2860 if(surf[nr].sh>-1) shape_refSurf(surf[nr].sh, nr);
2861 surf[nr].ori= ori;
2862 surf[nr].nl= anz_c;
2863 surf[nr].fail=0;
2864 surf[nr].etyp=0;
2865 surf[nr].eattr=0;
2866 surf[nr].eparm=(char *)NULL;
2867 surf[nr].patch=0;
2868 /* print the values of the hash table */
2869 if(sum<0) exit(-1);
2870 /*
2871 else printf(" asciSum:%d asci-indx:%d sums in hash-table:%d name:%s index:%d\n"
2872 , sum, sumAsci->anzs[sum]-1, sumAsci->anzs[sum]
2873 , surf[sumAsci->sindx[sum][sumAsci->anzs[sum]-1]].name
2874 , sumAsci->sindx[sum][sumAsci->anzs[sum]-1] );
2875 */
2876
2877 /* orient the new surf */
2878 if ( orientSurf( nr ) <0 )
2879 {
2880 errMsg ("WARNING: orientSurf:%s failed\n", name);
2881 }
2882 for (i=0; i<anz->sets; i++)
2883 {
2884 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o'))
2885 {
2886 seta( i, "s", nr );
2887 if((set[i].etyp>6)&&(set[i].etyp<11)) surf[nr].etyp=set[i].etyp;
2888 }
2889 }
2890 return(nr);
2891 }
2892
2893
getSurfParameters(char * record,char * name,char * ori,char * blend,char ** cori,char ** edge,int offset)2894 int getSurfParameters( char *record, char *name, char *ori, char *blend, char **cori, char **edge, int offset )
2895 {
2896 int i=0; /* scans through the record */
2897 int j,k;
2898 char *cori_, *edge_;
2899
2900 /* take the addresses from the calling function */
2901 /* at first call, the calling function must deliver NULL */
2902 cori_=*cori;
2903 edge_=*edge;
2904
2905
2906 /* read the name */
2907 do
2908 {
2909 if(record[i]!=' ') break;
2910 i++;
2911 }while(1);
2912 for(j=offset; j<MAX_LINE_LENGTH; j++)
2913 {
2914 name[j]=record[i];
2915 i++;
2916 if(record[i]==' ') break;
2917 }
2918 name[j+1]='\0';
2919
2920 /* read either orientation of the surface or 'ADD' */
2921 do
2922 {
2923 i++;
2924 if(record[i]!=' ') break;
2925 }while(1);
2926 for(j=0; j<MAX_LINE_LENGTH; j++)
2927 {
2928 ori[j]=record[i];
2929 i++;
2930 if(record[i]==' ') break;
2931 }
2932 ori[j+1]='\0';
2933
2934 /* read either the BLEND or if ori=="ADD" then no blend is specified */
2935 if((ori[0]=='+')||(ori[0]=='-'))
2936 {
2937 do
2938 {
2939 i++;
2940 if(record[i]!=' ') break;
2941 }while(1);
2942 for(j=offset; j<MAX_LINE_LENGTH; j++)
2943 {
2944 blend[j]=record[i];
2945 i++;
2946 if(record[i]==' ') break;
2947 }
2948 blend[j+1]='\0';
2949 }
2950
2951 /* get the orientation- and the name of the lines */
2952 j=-1;
2953 do
2954 {
2955 /* get the orientation and scan for eor */
2956 do
2957 {
2958 if( (record[i]=='\n') || (record[i]=='\r') ) goto found_all_lines;
2959 if(record[i]==(char)EOF) goto found_all_lines;
2960 if(record[i]=='\0') goto found_all_lines;
2961 if(record[i]!=' ') break;
2962 i++;
2963 }while(1);
2964
2965 /* new line expected */
2966 j++;
2967
2968 cori_=(char *)realloc((char *)cori_, (int)((j+2)*2)*sizeof(char));
2969 if(cori_==NULL) { printf("ERROR: realloc failed in getSurfParameters()\n"); return(0); }
2970 cori_[j*2+1]='\0';
2971 cori_[j*2]=record[i];
2972
2973 /* get the name */
2974 do
2975 {
2976 i++;
2977 if(record[i]!=' ') break;
2978 }while(1);
2979 for(k=offset; k<MAX_LINE_LENGTH; k++)
2980 {
2981 edge_=(char *)realloc((char *)edge_, (int)((j+2)*MAX_LINE_LENGTH)*sizeof(char));
2982 if(edge_==NULL) { printf("ERROR: realloc failed in getSurfParameters()\n"); return(0); }
2983 edge_[j*MAX_LINE_LENGTH+k]=record[i];
2984 i++;
2985 if(record[i]==' ') break;
2986 if( (record[i]=='\n') || (record[i]=='\r') ) break;
2987 if(record[i]==(char)EOF) break;
2988 if(record[i]=='\0') break;
2989 }
2990 edge_[j*MAX_LINE_LENGTH+k+1]='\0';
2991
2992 /* next line j */
2993 }while(1);
2994
2995 found_all_lines:;
2996 *cori=cori_;
2997 *edge=edge_;
2998 return(j+1);
2999 }
3000
3001
3002
pre_gsur(char * record,int addFlag)3003 void pre_gsur( char *record, int addFlag)
3004 {
3005 int anz_c, i, nr, lines;
3006 char name[MAX_LINE_LENGTH], ori[MAX_LINE_LENGTH], blend[MAX_LINE_LENGTH];
3007 char *cori=NULL, *edge=NULL;
3008
3009 if(addFlag)
3010 {
3011 /* add a special char in front of all strings */
3012 anz_c = getSurfParameters(record, name, ori, blend, &cori, &edge, (int)1);
3013 if(compareStrings(ori, "ADD")==3) name[0]='%'; else name[0]='!';
3014 blend[0]='%';
3015 for(i=0; i<anz_c; i++) edge[i*MAX_LINE_LENGTH]='%';
3016 }
3017 else
3018 anz_c = getSurfParameters(record, name, ori, blend, &cori, &edge, (int)0);
3019
3020 operateAlias( name, "s " );
3021 if(printFlag) printf("Gsur:%s ", name );
3022
3023
3024 /* check if lines should be added to an existing surface. This is triggered by the */
3025 /* keyword 'ADD' in parameter ori. If yes then add the already defined lines to the */
3026 /* new ones */
3027 if(compareStrings(ori, "ADD")==3)
3028 {
3029 /* get the index of the original surface */
3030 nr=getSurfNr(name);
3031 if (nr==-1)
3032 {
3033 printf("ERROR: in pre_gsur, surf:%s does not exist and can not be extended\n", name);
3034 goto errorPreGsur;
3035 }
3036
3037 /* get the ori and blend from the original surface */
3038 ori[0]=surf[nr].ori;
3039 ori[1]='\0';
3040 if(surf[nr].sh>-1) strcpy(blend,shape[surf[nr].sh].name);
3041 else strcpy(blend,"BLEND");
3042
3043 /* extend cori and edge by the already defined ones */
3044 lines=anz_c+surf[nr].nl;
3045 cori=(char *)realloc((char *)cori, (int)(lines*2)*sizeof(char));
3046 if(cori==NULL) { printf("ERROR: realloc failed in pre_gsur()\n"); goto errorPreGsur; }
3047 edge=(char *)realloc((char *)edge, (int)(lines*MAX_LINE_LENGTH)*sizeof(char));
3048 if(edge==NULL) { printf("ERROR: realloc failed in pre_gsur()\n"); goto errorPreGsur; }
3049
3050 /* re-arrange and store all lines */
3051 for(i=anz_c-1; i>-1; i--)
3052 {
3053 strcpy(&cori[(i+surf[nr].nl)*2], &cori[i*2]);
3054 strcpy(&edge[(i+surf[nr].nl)*MAX_LINE_LENGTH], &edge[i*MAX_LINE_LENGTH]);
3055 }
3056 for(i=0; i<surf[nr].nl; i++)
3057 {
3058 cori[i*2]= surf[nr].o[i];
3059 cori[i*2+1]= '\0';
3060 if(surf[nr].typ[i]=='l') strcpy(&edge[i*MAX_LINE_LENGTH], line[surf[nr].l[i]].name);
3061 if(surf[nr].typ[i]=='c') strcpy(&edge[i*MAX_LINE_LENGTH], lcmb[surf[nr].l[i]].name);
3062 }
3063 anz_c=lines;
3064 }
3065
3066 if ((ori[0]=='+')||(ori[0]=='-'))
3067 {
3068 if(printFlag) printf("%s %s ", ori, blend);
3069 }
3070 else
3071 {
3072 printf("ERROR: Orientation:%s of surf:%s not recognized\n", ori, name );
3073 goto errorPreGsur;
3074 }
3075
3076 for (i=0; i<anz_c; i++)
3077 {
3078 if ((compare( &cori[i*2], "+", 1) ==1 )||(compare( &cori[i*2], "-", 1) ==1 ))
3079 {
3080 if(printFlag) printf("%s %s ", &cori[i*2], &edge[i*MAX_LINE_LENGTH]);
3081 }
3082 else
3083 {
3084 printf("ERROR: Orientation:%s of line:%s not recognized\n", &cori[i*2], &edge[i*MAX_LINE_LENGTH] );
3085 goto errorPreGsur;
3086 }
3087 }
3088 if(printFlag) printf("\n");
3089
3090 /* replace lcmb's which reference just one line by the line itself */
3091 for (i=0; i<anz_c; i++)
3092 {
3093 operateAlias( (char*)&edge[i*MAX_LINE_LENGTH], "c" );
3094 nr=getLcmbNr((char*)&edge[i*MAX_LINE_LENGTH]);
3095 if( nr>-1 )
3096 {
3097 if(lcmb[nr].nl==1)
3098 {
3099 strcpy( &edge[i*MAX_LINE_LENGTH], line[lcmb[nr].l[0]].name );
3100 }
3101 }
3102 }
3103
3104 if( surface( name, ori[0], blend, anz_c, &cori[0], &edge[0] ) <0)
3105 printf("ERROR: surface could not be created\n");
3106
3107 errorPreGsur:;
3108 free(cori);
3109 free(edge);
3110 return;
3111 }
3112
3113
pre_surf(char * record)3114 void pre_surf( char *record)
3115 {
3116 int length, anz_c, i, se;
3117 char name[MAX_LINE_LENGTH], ori[2], blend[MAX_LINE_LENGTH], cori[6][2], edge[6][MAX_LINE_LENGTH];
3118 char *dummy=NULL;
3119 strcpy(blend,"BLEND");
3120
3121 length = sscanf( record, "%s%s%s%s%s%s%s", name, edge[0], edge[1], edge[2], edge[3], edge[4], edge[5] );
3122 operateAlias( name, "s " );
3123
3124 anz_c=length-1;
3125 if (anz_c == 1)
3126 {
3127 se=getSetNr( edge[0]);
3128 if(se>-1)
3129 {
3130 /* a set is defined, generate an unstructured surface */
3131 dummy=(char *)realloc((char *)dummy, (int)(MAX_LINE_LENGTH)*sizeof(char));
3132 if(dummy==NULL) { printf("ERROR: realloc failed in pre_surf()\n"); }
3133
3134 sprintf(dummy,"%s + %s", name,blend);
3135 for(i=0; i<set[se].anz_l; i++)
3136 {
3137 dummy=(char *)realloc((char *)dummy, (int)(strlen(dummy)+strlen(line[set[se].line[i]].name)+10)*sizeof(char));
3138 if(dummy==NULL) { printf("ERROR: realloc failed in pre_surf()\n"); }
3139
3140 sprintf(&dummy[strlen(dummy)]," + %s", line[set[se].line[i]].name);
3141 }
3142 pre_gsur( dummy, 0 );
3143 free(dummy);
3144 return;
3145 }
3146 else
3147 {
3148 printf("ERROR: surface could not be created, set:%s unknown\n",edge[0]);
3149 return;
3150 }
3151 }
3152
3153 ori[0]='+';
3154 for (i=0; i<anz_c; i++)
3155 {
3156 cori[i][0]='+';
3157 }
3158
3159 if( surface( name, ori[0], blend, anz_c, &cori[0][0], &edge[0][0] ) <0)
3160 printf("ERROR: surface could not be created\n");
3161
3162 free(dummy);
3163 return;
3164 }
3165
3166
3167 /*------------------------------------------------------------------*/
3168 /* define body */
3169 /*------------------------------------------------------------------*/
3170
delBody(int anzb,int * number)3171 void delBody( int anzb, int *number )
3172 {
3173 int j, k, *nrbuffer;
3174
3175 delBodyFlag=1;
3176 /*
3177 printf ("sum:%d num:%d surf:%s\n", anzb, number[0], surf[number[0]].name );
3178 */
3179 if ((nrbuffer = (int *)malloc((anzb+1)*sizeof(int)) ) == NULL )
3180 { printf("\n\nERROR: realloc failure in delBody\n\n"); return; }
3181
3182 /* nessesary to store the numbers in a independent area */
3183 for (j=0; j<anzb; j++)
3184 nrbuffer[j]=number[j];
3185
3186 for (j=0; j<anzb; j++) if( body[nrbuffer[j]].name != (char *)NULL )
3187 {
3188 for (k=0; k<anz->sets; k++)
3189 {
3190 if(set[k].type==0)
3191 if( set[k].name != (char *)NULL )
3192 setr( k, "b", nrbuffer[j]);
3193 }
3194 if(printFlag) printf (" delete body:%s \n", body[nrbuffer[j]].name );
3195 free(body[nrbuffer[j]].name);
3196 body[nrbuffer[j]].name = (char *)NULL ;
3197 body[nrbuffer[j]].ns=0;
3198 free(body[nrbuffer[j]].o);
3199 body[nrbuffer[j]].o= NULL;
3200 free(body[nrbuffer[j]].s);
3201 body[nrbuffer[j]].s= NULL;
3202 body[nrbuffer[j]].nn=0;
3203 free(body[nrbuffer[j]].nod);
3204 body[nrbuffer[j]].nod= NULL;
3205 body[nrbuffer[j]].ne=0;
3206 free(body[nrbuffer[j]].elem);
3207 body[nrbuffer[j]].elem= NULL;
3208 body[nrbuffer[j]].etyp= 0;
3209 }
3210 free(nrbuffer);
3211 return;
3212 }
3213
3214
hashBody(SumAsci * sumAsci,char * name,int nr)3215 int hashBody( SumAsci *sumAsci, char *name, int nr)
3216 {
3217 int i=0,j=0, n;
3218 int sum=0;
3219
3220 while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
3221
3222 /* check if sum is higher as the allocated value */
3223 /* else look for a free entry */
3224 if(sum>sumAsci->max_sumb)
3225 {
3226 if ((sumAsci->anzb=(int *)realloc( (int *)sumAsci->anzb, (sum+1)*sizeof(int)) ) == NULL )
3227 { printf("\n\nERROR: realloc failure in hashBody(), Body:%s not included\n\n", name); return(-1); }
3228 if ((sumAsci->bindx=(int **)realloc( (int **)sumAsci->bindx, (sum+1)*sizeof(int *)) ) == NULL )
3229 { printf("\n\nERROR: realloc failure in hashBody(), Body:%s not included\n\n", name); return(-1); }
3230 for(i=sumAsci->max_sumb+1; i<=sum; i++) { sumAsci->anzb[i]=0; sumAsci->bindx[i]=NULL; }
3231 sumAsci->max_sumb=sum;
3232 }
3233 else
3234 {
3235 if (delBodyFlag)
3236 for (i=0; i<sumAsci->anzb[sum]; i++)
3237 {
3238 n=sumAsci->bindx[sum][i];
3239 if( body[n].name == (char *)NULL )
3240 {
3241 /* already existing space to fill */
3242 sumAsci->bindx[sum][i]=nr;
3243 return(sum);
3244 }
3245 }
3246 }
3247
3248 /* alloc of a new entry in the hash table */
3249 if ((sumAsci->bindx[sum]
3250 =(int *)realloc( (int *)sumAsci->bindx[sum], (sumAsci->anzb[sum]+1)*sizeof(int)) ) == NULL )
3251 { printf("\n\nERROR: realloc failure in hashBody(), body:%s not included\n\n", name); return(-1); }
3252
3253 sumAsci->bindx[sum][sumAsci->anzb[sum]] = nr;
3254 sumAsci->anzb[sum]++;
3255 return(sum);
3256 }
3257
3258
body_(char * name,char * edge)3259 int body_( char *name, char *edge )
3260 {
3261 int i,j,k,n;
3262 int l, snr[6], p[2]={0,0};
3263 int anz_c=0; /* nr of slave surfs */
3264 int *cnr[2]={NULL,NULL}; /* stores indexes of points at the master surfs */
3265 int anz_s=0;
3266 char surfname[MAX_LINE_LENGTH];
3267
3268 int **surl=NULL; /* stores indexes of all lines or lcmbs for the slave surfs */
3269 char **surt=NULL; /* stores type (l,c) of all edges for the slave surfs */
3270 int *surnr=NULL; /* stores amount of lines and lcmbs for the slave surfs found */
3271 char *lori=NULL;
3272 int *bsur=NULL;
3273
3274 if(printFlag) printf (" create body:%s from surf:%s and %s\n", name, &edge[0], &edge[MAX_LINE_LENGTH] );
3275
3276 /* first guess of body-surfaces */
3277 if ( (bsur = (int *)realloc( (int *)bsur, (7) * sizeof(int))) == NULL )
3278 { printf("\n\n ERROR: realloc failed in body_\n") ; goto errorBody_; }
3279
3280 /* extract the master surfs */
3281 anz_s=0;
3282 for(i=0; i<2; i++)
3283 {
3284 snr[i]=getSurfNr((char*)&edge[i*MAX_LINE_LENGTH]);
3285 if( snr[i]<0 )
3286 {
3287 errMsg (" ERROR: surf:%s is undefined\n", &edge[i*MAX_LINE_LENGTH] );
3288 goto errorBody_;
3289 }
3290 bsur[i]=snr[i]; anz_s++;
3291 }
3292
3293 /* check if both surfs have equal nr of edges */
3294 if (surf[snr[0]].nl!=surf[snr[1]].nl)
3295 {
3296 errMsg (" ERROR: surfs have not equal nr of edges\n");
3297 goto errorBody_;
3298 }
3299 anz_c=surf[snr[0]].nl;
3300
3301 if ( (bsur = (int *)realloc( (int *)bsur, (anz_c+3) * sizeof(int))) == NULL )
3302 { printf("\n\n ERROR: realloc failed in body_\n") ; goto errorBody_; }
3303 if ( (surnr = (int *)realloc( (int *)surnr, (anz_c+1) * sizeof(int))) == NULL )
3304 { printf("\n\n ERROR: realloc failed in body_\n") ; goto errorBody_; }
3305 if ( (surl = (int **)realloc( (int **)surl, (anz_c+1) * sizeof(int *))) == NULL )
3306 { printf("\n\n ERROR: realloc failed in body_\n") ; goto errorBody_; }
3307 if ( (surt = (char **)realloc( (char **)surt, (anz_c+1) * sizeof(char *))) == NULL )
3308 { printf("\n\n ERROR: realloc failed in body_\n") ; goto errorBody_; }
3309 for(i=0; i<anz_c; i++)
3310 {
3311 if ( (surl[i] = (int *)malloc( (4+1) * sizeof(int))) == NULL )
3312 { printf("\n\n ERROR: malloc failed in body_\n") ; goto errorBody_; }
3313 if ( (surt[i] = ( char *)malloc( (4+1) * sizeof(char))) == NULL )
3314 { printf("\n\n ERROR: malloc failed in body_\n") ; goto errorBody_; }
3315 }
3316
3317 /* find the edgepoints of the surfs */
3318 for(i=0; i<2; i++)
3319 {
3320 if ( (cnr[i] = (int *)realloc( (int *)cnr[i], (anz_c+1) * sizeof(int))) == NULL )
3321 { printf("\n\n ERROR: realloc failed in body_\n") ; goto errorBody_; }
3322 for(j=0; j<anz_c; j++)
3323 {
3324 l=surf[snr[i]].l[j];
3325 if (surf[snr[i]].typ[j]=='l')
3326 {
3327 if (surf[snr[i]].o[j]=='+') cnr[i][j]=line[l].p1; else cnr[i][j]=line[l].p2;
3328 }
3329 if (surf[snr[i]].typ[j]=='c')
3330 {
3331 if (surf[snr[i]].o[j]=='+') cnr[i][j]=lcmb[l].p1; else cnr[i][j]=lcmb[l].p2;
3332 }
3333 if(printFlag) printf (" corner-point:%s selected\n", point[cnr[i][j]].name);
3334 }
3335 }
3336
3337 /* suche verbindungslinien zw. den surfs */
3338 for(j=0; j<anz_c; j++)
3339 {
3340 l=0;
3341 /* compare the corner point with all lines (use indexes of end-points) */
3342 for(i=0; i<anzGeo->l; i++)
3343 {
3344 if( line[i].name != (char *)NULL )
3345 {
3346 p[0]=line[i].p1;
3347 p[1]=line[i].p2;
3348 if((cnr[0][j]==p[0])||(cnr[0][j]==p[1])) /* first point matches */
3349 {
3350 for(k=0; k<anz_c; k++)
3351 {
3352 if((cnr[1][k]==p[0])||(cnr[1][k]==p[1])) /* second point matches */
3353 {
3354 /* found a line */
3355 if(printFlag) printf("line[%d]:%s matches p:%s and p:%s\n", i, line[i].name
3356 , point[cnr[0][j]].name, point[cnr[1][k]].name);
3357 surl[j][l]=i; surt[j][l]='l'; l++; goto foundEdge;
3358 }
3359 }
3360 }
3361 }
3362 }
3363 /* compare with all lcmb (use indexes of end-points) */
3364 for(i=0; i<anzGeo->c; i++)
3365 {
3366 if( lcmb[i].name != (char *)NULL )
3367 {
3368 p[0]=lcmb[i].p1;
3369 p[1]=lcmb[i].p2;
3370 if((cnr[0][j]==p[0])||(cnr[0][j]==p[1])) /* first point matches */
3371 {
3372 for(k=0; k<anz_c; k++)
3373 {
3374 if((cnr[1][k]==p[0])||(cnr[1][k]==p[1])) /* second point matches */
3375 {
3376 /* found a lcmb */
3377 if(printFlag) printf("lcmb[%d]:%s matches p:%s and p:%s\n", i, lcmb[i].name
3378 , point[cnr[0][j]].name, point[cnr[1][k]].name);
3379 surl[j][l]=i; surt[j][l]='c'; l++; goto foundEdge;
3380 }
3381 }
3382 }
3383 }
3384 }
3385 foundEdge:;
3386 /* store the amount of edges (lines,lcmbs) found for the connecting surf */
3387 if (!l)
3388 {
3389 errMsg(" ERROR: found not all edges between selected surfs\n");
3390 goto errorBody_;
3391 }
3392 surnr[j]=l;
3393
3394 /* add this edge also to the slave-surf before (j-1) */
3395 if (j>0)
3396 {
3397 surl[j-1][surnr[j-1]]=surl[j][surnr[j]-1];
3398 surt[j-1][surnr[j-1]]=surt[j][surnr[j]-1];
3399 surnr[j-1]++;
3400 }
3401 }
3402 surl[j-1][surnr[j-1]]=surl[0][surnr[0]-2];
3403 surt[j-1][surnr[j-1]]=surt[0][surnr[0]-2];
3404 surnr[j-1]++;
3405
3406 /* determine the corresponding corner-points on master-surf1 again */
3407 for(j=0; j<anz_c; j++)
3408 {
3409 if(surt[j][0]=='l')
3410 {
3411 if(cnr[0][j]==line[surl[j][0]].p1) cnr[1][j]=line[surl[j][0]].p2;
3412 else cnr[1][j]=line[surl[j][0]].p1;
3413 }
3414 if(surt[j][0]=='c')
3415 {
3416 if(cnr[0][j]==lcmb[surl[j][0]].p1) cnr[1][j]=lcmb[surl[j][0]].p2;
3417 else cnr[1][j]=lcmb[surl[j][0]].p1;
3418 }
3419 if(printFlag) printf(" point %s matches %s \n", point[cnr[0][j]].name,point[cnr[1][j]].name);
3420 }
3421
3422 /* suche linien zw. den cnr einer surf */
3423 for(j=0; j<anz_c; j++)
3424 {
3425 /* add edge-line of master-surf0 to the slave-surf */
3426 surl[j][surnr[j]]=surf[snr[0]].l[j];
3427 surt[j][surnr[j]]=surf[snr[0]].typ[j];
3428 surnr[j]++;
3429
3430 /* add edge-line of master-surf1 to the slave-surf */
3431 /* determine the correct edge to use */
3432 /* compare with all lines (use indexes of end-points) */
3433 for(i=0; i<surf[snr[1]].nl; i++)
3434 {
3435 if(surf[snr[1]].typ[i]=='l')
3436 {
3437 p[0]=line[surf[snr[1]].l[i]].p1;
3438 p[1]=line[surf[snr[1]].l[i]].p2;
3439 }
3440 if(surf[snr[1]].typ[i]=='c')
3441 {
3442 p[0]=lcmb[surf[snr[1]].l[i]].p1;
3443 p[1]=lcmb[surf[snr[1]].l[i]].p2;
3444 }
3445 if (j<anz_c-1)
3446 {
3447 if( ((cnr[1][j]==p[0])&&(cnr[1][j+1]==p[1]))
3448 || ((cnr[1][j]==p[1])&&(cnr[1][j+1]==p[0])) )
3449 {
3450 surl[j][surnr[j]]=surf[snr[1]].l[i];
3451 surt[j][surnr[j]]=surf[snr[1]].typ[i];
3452 surnr[j]++; break;
3453 }
3454 }
3455 else
3456 {
3457 if( ((cnr[1][j]==p[0])&&(cnr[1][0]==p[1]))
3458 || ((cnr[1][j]==p[1])&&(cnr[1][0]==p[0])) )
3459 {
3460 surl[j][surnr[j]]=surf[snr[1]].l[i];
3461 surt[j][surnr[j]]=surf[snr[1]].typ[i];
3462 surnr[j]++; break;
3463 }
3464 }
3465 }
3466 }
3467
3468 /* present all edges for all slave surfs */
3469 if(printFlag) for(i=0; i<anz_c; i++)
3470 {
3471 printf(" sur:%d lines found:%d\n", i, surnr[i]);
3472 printf(" sur:%d ", i);
3473 for( j=0; j<surnr[i]; j++)
3474 {
3475 if(surt[i][j]=='l') printf("%s ", line[surl[i][j]].name);
3476 if(surt[i][j]=='c') printf("%s ", lcmb[surl[i][j]].name);
3477 }
3478 printf("\n");
3479 }
3480
3481 /* kontrolle ob eine surf zw den linen bereits existiert */
3482 for(i=0; i<anz_c; i++)
3483 {
3484 for(j=0; j<anzGeo->s; j++)
3485 {
3486 #if TEST
3487 printf(" check surf:%s nl:%d\n", surf[j].name, surf[j].nl);
3488 #endif
3489 if(( surf[j].name != (char *)NULL )&&( surnr[i]==surf[j].nl ))
3490 {
3491 n=0;
3492 for(k=0; k<surnr[i]; k++)
3493 {
3494 for(l=0; l<surf[j].nl; l++)
3495 {
3496 #if TEST
3497 printf(" check type and index:%d edge%c surf:%c %d\n", surl[i][k], surt[i][k], surf[j].typ[l], surf[j].l[l]);
3498 #endif
3499 if((surl[i][k]==surf[j].l[l])&&(surt[i][k]==surf[j].typ[l])) n++;
3500 }
3501 }
3502 if(n==surf[j].nl)
3503 {
3504 if(printFlag) printf(" surf:%s exists\n", surf[j].name);
3505 bsur[anz_s]=j; anz_s++;
3506 goto next_edge;
3507 }
3508 }
3509 }
3510 /* no surf was found, create one */
3511
3512 if ((lori = (char *)realloc((char *)lori, (surnr[i])*sizeof(char)) ) == NULL )
3513 { printf("ERROR: realloc failure in pre_swep()\n"); goto errorBody_; }
3514 for (k=0; k<surnr[i]; k++) lori[k]= '+';
3515 if ( getNewName( surfname, "s" ) == -1 )
3516 { printf(" Type s not known, surf can not be created\n"); }
3517 n=surface_i( surfname, '+', -1, surnr[i], lori, surl[i], surt[i] );
3518 if ( n <0)
3519 { printf(" ERROR: surf could not be created\n"); }
3520 bsur[anz_s]=n; anz_s++;
3521 if(printFlag) printf(" surf:%s created\n", surfname);
3522 next_edge:;
3523 }
3524
3525 /* erzeuge body */
3526 if ((lori = (char *)realloc((char *)lori, (anz_s)*sizeof(char)) ) == NULL )
3527 { printf("ERROR: realloc failure in pre_swep()\n"); goto errorBody_; }
3528 for (k=0; k<anz_s; k++) lori[k]= '+';
3529
3530 n=gbod_i( name, -1, anz_s, lori, bsur );
3531 if( n <0)
3532 { printf("body_: could not create new body\n"); goto errorBody_; }
3533 if(printFlag) printf(" body:%s created\n", name );
3534
3535 for(i=0; i<anz_c; i++) { free(surl[i]); free(surt[i]); }
3536 free(bsur);
3537 free(surnr);
3538 free(lori);
3539 return(n);
3540 errorBody_:;
3541 for(i=0; i<anz_c; i++) { free(surl[i]); free(surt[i]); }
3542 free(bsur);
3543 free(surnr);
3544 free(lori);
3545 return(-1);
3546 }
3547
3548
3549
3550
gbod(char * name,char * blend,int anz_c,char * cori,char * edge)3551 int gbod( char *name, char *blend, int anz_c, char *cori, char *edge )
3552 {
3553 int nr, i, snr;
3554 int sum=0;
3555
3556 //if(anz_c > 7) return(-1);
3557
3558 nr=getBodyNr(name);
3559 if (nr==-1) /* new body */
3560 {
3561 if ((body = (Gbod *)realloc( (Gbod *)body, (anzGeo->b+1)*sizeof(Gbod)) ) == NULL )
3562 { printf("\n\nERROR: realloc failure in body, body:%s not installed\n\n", name); return(-1); }
3563 nr=anzGeo->b;
3564 if ((body[nr].o = (char *)malloc( (anz_c+1)*sizeof(char)) ) == NULL )
3565 { printf("\n\nERROR: malloc failure in body, body.o:%s not installed\n\n", name); return(-1); }
3566 if ((body[nr].s = (int *)malloc( (anz_c+1)*sizeof(int)) ) == NULL )
3567 { printf("\n\nERROR: malloc failure in body, body.l:%s not installed\n\n", name); return(-1); }
3568 anzGeo->b++;
3569 i=strlen(name);
3570 if((body[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
3571 { printf("ERROR: malloc failed\n\n" ); return(-1); }
3572 strcpy(body[nr].name, name);
3573 sum=hashBody( sumAsci, name, nr );
3574 body[nr].nn=0;
3575 body[nr].ne=0;
3576 body[nr].nod= NULL;
3577 body[nr].elem= NULL;
3578 }
3579 else if (nr<-1) /* replace a deleted body */
3580 {
3581 nr=-(nr+10);
3582 if ((body[nr].o = (char *)realloc( (char *)body[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
3583 { printf("\n\nERROR: realloc failure in body, body.o:%s not installed\n\n", name); return(-1); }
3584 if ((body[nr].s = (int *)realloc( (int *)body[nr].s, (anz_c+1)*sizeof(int)) ) == NULL )
3585 { printf("\n\nERROR: realloc failure in body, body.s:%s not installed\n\n", name); return(-1); }
3586 i=strlen(name);
3587 if((body[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
3588 { printf("ERROR: malloc failed\n\n" ); return(-1); }
3589 strcpy(body[nr].name, name);
3590 sum=hashBody( sumAsci, name, nr );
3591 }
3592 else
3593 {
3594 if(printFlag) printf (" body in use: Definition will be changed\n");
3595 if ((body[nr].o = (char *)realloc( (char *)body[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
3596 { printf("\n\nERROR: realloc failure in body, body.o:%s not installed\n\n", name); return(-1); }
3597 if ((body[nr].s = (int *)realloc( (int *)body[nr].s, (anz_c+1)*sizeof(int)) ) == NULL )
3598 { printf("\n\nERROR: realloc failure in body, body.s:%s not installed\n\n", name); return(-1); }
3599 free(body[nr].nod);
3600 free(body[nr].elem);
3601 body[nr].nod= NULL;
3602 body[nr].elem= NULL;
3603 body[nr].nn=0;
3604 body[nr].ne=0;
3605 }
3606
3607 /* for the moment all bodys are + oriented */
3608 for (i=0; i<anz_c; i++)
3609 {
3610 //printf(" surf:%s ori:%s \n", &edge[i*MAX_LINE_LENGTH], &cori[i*2] );
3611 snr=getSurfNr((char*)&edge[i*MAX_LINE_LENGTH]);
3612 if( snr>-1 ) { body[nr].s[i]=snr; }
3613 else
3614 {
3615 errMsg ("ERROR: surf:%s in body:%s is undefined\n", &edge[i*MAX_LINE_LENGTH], name );
3616 if(printFlag) printf (" delete body:%s \n", body[nr].name );
3617 body[nr].name = (char *)NULL ;
3618 return(-1);
3619 }
3620 body[nr].o[i]=cori[i*2];
3621 }
3622 body[nr].ori= '+';
3623 body[nr].ns= anz_c;
3624 body[nr].etyp=0;
3625 body[nr].eattr=0;
3626 body[nr].eparm=(char *)NULL;
3627
3628 /* print the values of the hash table */
3629 if(sum<0) exit(-1);
3630 /*
3631 else printf(" asciSum:%d asci-indx:%d sums in hash-table:%d name:%s index:%d\n"
3632 , sum, sumAsci->anzb[sum]-1, sumAsci->anzb[sum]
3633 , body[sumAsci->bindx[sum][sumAsci->anzb[sum]-1]].name
3634 , sumAsci->bindx[sum][sumAsci->anzb[sum]-1] );
3635 */
3636
3637 /* orient the new body */
3638 if ( orientBody( nr ) <0 )
3639 {
3640 errMsg ("ERROR: orientBody:%s failed\n", name);
3641 body[nr].name = (char *)NULL ;
3642 return(-1);
3643 }
3644 for (i=0; i<anz->sets; i++)
3645 {
3646 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o'))
3647 {
3648 seta( i, "b", nr );
3649 if(set[i].etyp<7) body[nr].etyp=set[i].etyp;
3650 }
3651 }
3652 return(nr);
3653 }
3654
3655
gbod_i(char * name,int blend,int anz_c,char * cori,int * edge)3656 int gbod_i( char *name, int blend, int anz_c, char *cori, int *edge )
3657 {
3658 int nr, i;
3659 int sum=0;
3660
3661 //if(anz_c > 7) return(-1);
3662
3663 nr=getBodyNr(name);
3664 if (nr==-1) /* new body */
3665 {
3666 if ((body = (Gbod *)realloc( (Gbod *)body, (anzGeo->b+1)*sizeof(Gbod)) ) == NULL )
3667 { printf("\n\nERROR: realloc failure in body, body:%s not installed\n\n", name); return(-1); }
3668 nr=anzGeo->b;
3669 if ((body[nr].o = (char *)malloc( (anz_c+1)*sizeof(char)) ) == NULL )
3670 { printf("\n\nERROR: malloc failure in body, body.o:%s not installed\n\n", name); return(-1); }
3671 if ((body[nr].s = (int *)malloc( (anz_c+1)*sizeof(int)) ) == NULL )
3672 { printf("\n\nERROR: malloc failure in body, body.l:%s not installed\n\n", name); return(-1); }
3673 anzGeo->b++;
3674 i=strlen(name);
3675 if((body[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
3676 { printf("ERROR: malloc failed\n\n" ); return(-1); }
3677 strcpy(body[nr].name, name);
3678 sum=hashBody( sumAsci, name, nr );
3679 body[nr].nn=0;
3680 body[nr].ne=0;
3681 body[nr].nod= NULL;
3682 body[nr].elem= NULL;
3683 }
3684 else if (nr<-1) /* replace a deleted body */
3685 {
3686 nr=-(nr+10);
3687 if ((body[nr].o = (char *)realloc( (char *)body[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
3688 { printf("\n\nERROR: realloc failure in body, body.o:%s not installed\n\n", name); return(-1); }
3689 if ((body[nr].s = (int *)realloc( (int *)body[nr].s, (anz_c+1)*sizeof(int)) ) == NULL )
3690 { printf("\n\nERROR: realloc failure in body, body.s:%s not installed\n\n", name); return(-1); }
3691 i=strlen(name);
3692 if((body[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
3693 { printf("ERROR: malloc failed\n\n" ); return(-1); }
3694 strcpy(body[nr].name, name);
3695 sum=hashBody( sumAsci, name, nr );
3696 }
3697 else
3698 {
3699 if(printFlag) printf (" body in use: Definition will be changed\n");
3700 if ((body[nr].o = (char *)realloc( (char *)body[nr].o, (anz_c+1)*sizeof(char)) ) == NULL )
3701 { printf("\n\nERROR: realloc failure in body, body.o:%s not installed\n\n", name); return(-1); }
3702 if ((body[nr].s = (int *)realloc( (int *)body[nr].s, (anz_c+1)*sizeof(int)) ) == NULL )
3703 { printf("\n\nERROR: realloc failure in body, body.s:%s not installed\n\n", name); return(-1); }
3704 free(body[nr].nod);
3705 free(body[nr].elem);
3706 body[nr].nod= NULL;
3707 body[nr].elem= NULL;
3708 body[nr].nn=0;
3709 body[nr].ne=0;
3710 }
3711
3712 /* for the moment all bodys are + oriented */
3713 for (i=0; i<anz_c; i++)
3714 {
3715 body[nr].s[i]=edge[i];
3716 body[nr].o[i]=cori[i];
3717 }
3718 body[nr].ori= '+';
3719 body[nr].ns= anz_c;
3720 body[nr].etyp=0;
3721 body[nr].eattr=0;
3722 body[nr].eparm=(char *)NULL;
3723
3724 /* print the values of the hash table */
3725 if(sum<0) exit(-1);
3726 /*
3727 else printf(" asciSum:%d asci-indx:%d sums in hash-table:%d name:%s index:%d\n"
3728 , sum, sumAsci->anzb[sum]-1, sumAsci->anzb[sum]
3729 , body[sumAsci->bindx[sum][sumAsci->anzb[sum]-1]].name
3730 , sumAsci->bindx[sum][sumAsci->anzb[sum]-1] );
3731 */
3732 /* orient the new body */
3733 if ( orientBody( nr ) <0 )
3734 {
3735 errMsg ("ERROR: orientBody:%s failed\n", name);
3736 body[nr].name = (char *)NULL ;
3737 return(-1);
3738 }
3739 for (i=0; i<anz->sets; i++)
3740 {
3741 if(( set[i].name != (char *)NULL)&&( set[i].flag=='o'))
3742 {
3743 seta( i, "b", nr );
3744 if(set[i].etyp<7) body[nr].etyp=set[i].etyp;
3745 }
3746 }
3747 return(nr);
3748 }
3749
3750
3751
getBodyParameters(char * record,char * name,char * ori,char *** cori,char *** edge,int offset)3752 int getBodyParameters( char *record, char *name, char *ori, char ***cori, char ***edge, int offset )
3753 {
3754 int i=0; /* scans through the record */
3755 int j,k, bodyNr=-1;
3756 char **cori_, **edge_;
3757
3758 /* take the addresses from the calling function */
3759 /* before the first call, the calling function must deliver NULL */
3760 cori_=*cori;
3761 edge_=*edge;
3762
3763 /* read the name */
3764 do
3765 {
3766 if(record[i]!=' ') break;
3767 i++;
3768 }while(1);
3769 for(j=offset; j<MAX_LINE_LENGTH; j++)
3770 {
3771 name[j]=record[i];
3772 i++;
3773 if(record[i]==' ') break;
3774 }
3775 name[j+1]='\0';
3776
3777 /* read either orientation or 'ADD' */
3778 do
3779 {
3780 i++;
3781 if(record[i]!=' ') break;
3782 }while(1);
3783 for(j=0; j<MAX_LINE_LENGTH; j++)
3784 {
3785 ori[j]=record[i];
3786 i++;
3787 if(record[i]==' ') break;
3788 }
3789 ori[j+1]='\0';
3790
3791 if(offset) { if(compareStrings(ori, "ADD")==3) name[0]='%'; else name[0]='!'; }
3792 operateAlias( name, "b " );
3793
3794 if(compareStrings(ori, "ADD")==3)
3795 {
3796 bodyNr=getBodyNr(name);
3797 if(bodyNr<0) { printf("ERROR: Body:%s not known and can not be extended\n", name); return(0); }
3798
3799 j=body[bodyNr].ns-1;
3800
3801 cori_=(char **)realloc((char **)cori_, (int)(j+1)*sizeof(char *));
3802 if(cori_==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3803 edge_=(char **)realloc((char **)edge_, (int)((j+1))*sizeof(char *));
3804 if(edge_==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3805 for(k=0; k<=j; k++)
3806 {
3807 cori_[k]=(char *)malloc((int)(2)*sizeof(char));
3808 if(cori_[k]==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3809 cori_[k][0]=body[bodyNr].o[k];
3810 cori_[k][1]='\0';
3811 edge_[k]=(char *)malloc((int)(strlen(surf[body[bodyNr].s[k]].name)+1)*sizeof(char));
3812 if(edge_[k]==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3813 strcpy(edge_[k], surf[body[bodyNr].s[k]].name);
3814 }
3815 }
3816 else j=-1;
3817
3818 /* get the orientation- and the name of the surfs */
3819 do
3820 {
3821 /* get the orientation and scan for eor */
3822 do
3823 {
3824 if( (record[i]=='\n') || (record[i]=='\r') ) goto found_all_surfs;
3825 if(record[i]==(char)EOF) goto found_all_surfs;
3826 if(record[i]=='\0') goto found_all_surfs;
3827 if(record[i]!=' ') break;
3828 i++;
3829 }while(1);
3830 if((record[i]!='+')&&(record[i]!='-')) { printf("ERROR: string:%c does not contain '+' or '-'\n", record[i] ); return(0); }
3831
3832 /* new surf expected */
3833 j++;
3834
3835 cori_=(char **)realloc((char **)cori_, (int)(j+1)*sizeof(char *));
3836 if(cori_==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3837 cori_[j]=(char *)malloc((int)(2)*sizeof(char));
3838 if(cori_[j]==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3839 cori_[j][0]=record[i];
3840 cori_[j][1]='\0';
3841
3842 /* get the name */
3843 do
3844 {
3845 i++;
3846 if(record[i]!=' ') break;
3847 }while(1);
3848
3849 edge_=(char **)realloc((char **)edge_, (int)((j+1))*sizeof(char *));
3850 if(edge_==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3851 edge_[j]=(char *)malloc((int)(strlen(&record[i])+2)*sizeof(char));
3852 if(edge_[j]==NULL) { printf("ERROR: realloc failed in getBodyParameters()\n"); return(0); }
3853
3854 k=0;
3855 if(offset) edge_[j][k++]='%';
3856 do
3857 {
3858 edge_[j][k++]=record[i];
3859 i++;
3860 if( (record[i]=='\n') || (record[i]=='\r') ) break;
3861 if(record[i]=='\0') break;
3862 if(record[i]==' ') break;
3863 }while(1);
3864 edge_[j][k]='\0';
3865
3866 /* next surf j */
3867 }while(1);
3868
3869 found_all_surfs:;
3870 *cori=cori_;
3871 *edge=edge_;
3872 return(j+1);
3873 }
3874
3875
3876
pre_gbod(char * record,int addFlag)3877 int pre_gbod( char *record, int addFlag)
3878 {
3879 int anz_c, i;
3880 char name[MAX_LINE_LENGTH], ori[MAX_LINE_LENGTH];
3881 char **cori=NULL, **edge=NULL;
3882 char *coris=NULL, *edges=NULL;
3883
3884 if(addFlag) anz_c=getBodyParameters(record, name, ori, &cori, &edge, (int)1);
3885 else
3886 anz_c = getBodyParameters(record, name, ori, &cori, &edge, (int)0);
3887 if(anz_c<1) goto errorPreGbod;
3888
3889 if(printFlag) printf("Gbod:%s ", name );
3890
3891 if ((compare( ori, "NORM", 4) ==4 )||(compare( ori, "norm", 4) ==4 ))
3892 {
3893 if(printFlag) printf("%s ", ori);
3894 }
3895 else
3896 {
3897 if(printFlag) printf("WARNING: Orientation:%s of Body:%s not recognized and set to NORM\n", ori, name );
3898 strcpy( ori, "NORM");
3899 }
3900
3901 for (i=0; i<anz_c; i++)
3902 {
3903 operateAlias( edge[i], "s " );
3904 if ((compare( cori[i], "+", 1) ==1 )||(compare( cori[i], "-", 1) ==1 ))
3905 {
3906 if(printFlag) printf("%s %s ", cori[i], edge[i]);
3907 }
3908 else
3909 {
3910 printf("ERROR: Orientation:%s of body:%s not recognized\n", cori[i], edge[i] );
3911 goto errorPreGbod;;
3912 }
3913 }
3914 if(printFlag) printf("\n");
3915
3916 /* alle ori und surfs umspeichern */
3917 coris=(char *)calloc((int)(anz_c*2), sizeof(char));
3918 if(coris==NULL) { printf("ERROR: realloc failed in pre_gsur()\n"); goto errorPreGbod; }
3919 edges=(char *)calloc((int)(anz_c*MAX_LINE_LENGTH), sizeof(char));
3920 if(edges==NULL) { printf("ERROR: realloc failed in pre_gsur()\n"); goto errorPreGbod; }
3921 for(i=0; i<anz_c; i++)
3922 {
3923 coris[i*2]= cori[i][0];
3924 coris[i*2+1]= '\0';
3925 strcpy(&edges[i*MAX_LINE_LENGTH], edge[i]);
3926 free(cori[i]);
3927 free(edge[i]);
3928 }
3929
3930 i=gbod( name, ori, anz_c, coris, edges );
3931 free(coris);
3932 free(edges);
3933
3934 if( i <0)
3935 printf("ERROR: body could not be created\n");
3936 return(i);
3937 errorPreGbod:;
3938 free(coris);
3939 free(edges);
3940 return(-1);
3941 }
3942
3943
pre_body(char * record)3944 int pre_body( char *record)
3945 {
3946 int length, anz_c, i, se;
3947 char name[MAX_LINE_LENGTH], ori[MAX_LINE_LENGTH], cori[7][2], edge[7][MAX_LINE_LENGTH], buffer[MAX_LINE_LENGTH];
3948 char *dummy=NULL;
3949
3950 length = sscanf( record, "%s%s%s%s%s%s%s%s%s",
3951 name, edge[0], edge[1], edge[2], edge[3], edge[4], edge[5], edge[6], buffer);
3952 operateAlias( name, "b " );
3953
3954 if(compareStrings( name, "!" )>0) getNewName( name, "b" );
3955
3956 anz_c=length-1;
3957
3958 if((anz_c>4)&&(anz_c<8))
3959 {
3960 strcpy( ori, "NORM");
3961 for (i=0; i<anz_c; i++)
3962 {
3963 operateAlias( edge[i], "s " );
3964 cori[i][0]= '+';
3965 }
3966 i=gbod( name, ori, anz_c, &cori[0][0], &edge[0][0] );
3967 if( i <0)
3968 printf("ERROR: body could not be created\n");
3969 }
3970 else if(anz_c==2)
3971 {
3972 operateAlias( edge[0], "s " );
3973 operateAlias( edge[1], "s " );
3974 i=body_( name, &edge[0][0] );
3975 if( i <0)
3976 printf("ERROR: body could not be created\n");
3977 }
3978 else if(anz_c==1)
3979 {
3980 se=getSetNr( edge[0]);
3981 if(se>-1)
3982 {
3983 /* a set is defined, generate an unoriented body */
3984 dummy=(char *)realloc((char *)dummy, (int)(strlen(name)+7)*sizeof(char));
3985 if(dummy==NULL) { printf("ERROR: realloc failed in pre_surf()\n"); }
3986 sprintf(dummy,"%s NORM", name);
3987
3988 for(i=0; i<set[se].anz_s; i++)
3989 {
3990 dummy=(char *)realloc((char *)dummy, (int)(strlen(dummy)+strlen(surf[set[se].surf[i]].name)+10)*sizeof(char));
3991 if(dummy==NULL) { printf("ERROR: realloc failed in pre_surf()\n"); }
3992 sprintf(&dummy[strlen(dummy)]," + %s", surf[set[se].surf[i]].name);
3993 }
3994 i=pre_gbod( dummy, 0 );
3995 free(dummy);
3996 }
3997 else
3998 {
3999 printf("ERROR: surface could not be created, set:%s unknown\n",edge[0]);
4000 goto errorPreBody;
4001 }
4002 }
4003 else
4004 {
4005 printf("ERROR: body could not be created\n");
4006 goto errorPreBody;
4007 }
4008 return(i);
4009 errorPreBody:;
4010 return(-1);
4011 }
4012
4013
4014 /*------------------------------------------------------------------*/
4015 /* define Nurbs line */
4016 /* returns index of related spline and not of the nurbs-line */
4017 /*------------------------------------------------------------------*/
4018
nurl(char * string,int addFlag)4019 int nurl( char *string, int addFlag )
4020 {
4021 char action[MAX_LINE_LENGTH], name[MAX_LINE_LENGTH], buffer[MAX_LINE_LENGTH], pstart[MAX_LINE_LENGTH], pend[MAX_LINE_LENGTH], dummy[MAX_LINE_LENGTH];
4022 double x,y,z;
4023 GLfloat value, weight;
4024 int i, j, length, pnr, nr, snr=-2, flag;
4025 static int pnr1, pnr2;
4026 #if NO_NURL
4027 int zapset;
4028 #endif
4029 static int compactFlag;
4030 static int div=0;
4031 double bias=1.;
4032
4033 Rsort *rsort=NULL;
4034
4035 if (!addFlag) sscanf (string,"%s%s%s", name, action, dummy);
4036 else
4037 {
4038 sscanf (string,"%s%s%s", &name[1], action, dummy);
4039 if(( compare( action, "DEFI", 4) == 4 )||( compare( action, "defi", 4) == 4 )) name[0]='!';
4040 else name[0]='%';
4041 }
4042 operateAlias( name, "L" );
4043 if(printFlag) printf (" nurl:%s action:%s \n ", name, action);
4044
4045 nr=getNurlNr(name);
4046
4047 if(( compare( action, "DEFI", 4) == 4 ) || ( compare( action, "defi", 4) == 4 ))
4048 {
4049 /* create new NURBS line */
4050 div=0;
4051
4052 #if NO_NURL
4053 /* open a set for the controll-points, they will be deleted after comletition */
4054 if( (zapset=pre_seta( specialset->zap, "i", 0)) <0 ) return(-1);
4055 #endif
4056
4057 if (nr==-1) /* new Nurl */
4058 {
4059 nr=anzGeo->nurl;
4060 anzGeo->nurl++;
4061 if(printFlag) printf ("add NURL Nr:%d Name:%s\n", anzGeo->nurl, name);
4062
4063 if ((nurbl = (Nurbl *)realloc( (Nurbl *)nurbl, (anzGeo->nurl+1)*sizeof(Nurbl)) ) == NULL )
4064 { printf("\n\nERROR: realloc failure in Nurl, nurbl:%s not installed\n\n", name); return(-1); }
4065
4066 i=strlen(name);
4067 if((nurbl[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
4068 { printf("ERROR: malloc failed\n\n" ); return(-1); }
4069 strcpy(nurbl[nr].name, name);
4070 }
4071 else if (nr<-1) /* replace a deleted nurl */
4072 {
4073 nr=-(nr+10);
4074 if(printFlag) printf ("redefine NURL Nr:%d Name:%s\n", anzGeo->nurl, name);
4075 i=strlen(name);
4076 if((nurbl[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
4077 { printf("ERROR: malloc failed\n\n" ); return(-1); }
4078 strcpy(nurbl[nr].name, name);
4079 free( nurbl[nr].uknt );
4080 free( nurbl[nr].ctlpnt );
4081 free( nurbl[nr].weight );
4082 }
4083 else
4084 {
4085 if(printFlag) printf ("replace NURL Nr:%d Name:%s\n", anzGeo->nurl, name);
4086 free( nurbl[nr].uknt );
4087 free( nurbl[nr].ctlpnt );
4088 free( nurbl[nr].weight );
4089 }
4090
4091 /* define NURBS as incomplete */
4092 nurbl[nr].endFlag=0;
4093
4094 /* read the header data of the nurbs with the COMPACT fam statement */
4095 if(compare(dummy,"COMP",4)==4)
4096 {
4097 compactFlag=1;
4098 if (!addFlag) sscanf (string,"%*s%*s%*s%s%s%d%d%d%d", pstart, pend, &nurbl[nr].u_exp, &nurbl[nr].u_npnt, &nurbl[nr].u_nknt, &div);
4099 else
4100 {
4101 pstart[0]=pend[0]='%';
4102 sscanf (string,"%*s%*s%*s%s%s%d%d%d%d", &pstart[1], &pend[1], &nurbl[nr].u_exp, &nurbl[nr].u_npnt, &nurbl[nr].u_nknt, &div);
4103 }
4104 }
4105 else if(compare(dummy,"FULL",4)==4)
4106 {
4107 compactFlag=0;
4108 if (!addFlag) sscanf (string,"%*s%*s%*s%s%s%d%d%d%d", pstart, pend, &nurbl[nr].u_exp, &nurbl[nr].u_npnt, &nurbl[nr].u_nknt, &div);
4109 else
4110 {
4111 pstart[0]=pend[0]='%';
4112 sscanf (string,"%*s%*s%*s%s%s%d%d%d%d", &pstart[1], &pend[1], &nurbl[nr].u_exp, &nurbl[nr].u_npnt, &nurbl[nr].u_nknt, &div);
4113 }
4114 }
4115 else
4116 {
4117 compactFlag=0;
4118 if (!addFlag) sscanf (string,"%*s%*s%s%s%d%d%d%d", pstart, pend, &nurbl[nr].u_exp, &nurbl[nr].u_npnt, &nurbl[nr].u_nknt, &div);
4119 else
4120 {
4121 pstart[0]=pend[0]='%';
4122 sscanf (string,"%*s%*s%s%s%d%d%d%d", &pstart[1], &pend[1], &nurbl[nr].u_exp, &nurbl[nr].u_npnt, &nurbl[nr].u_nknt, &div);
4123 }
4124 }
4125 operateAlias( pstart, "p" );
4126 operateAlias( pend, "p" );
4127 if (nurbl[nr].u_npnt<1)
4128 {
4129 errMsg("ERROR: Nurbs[%d]:%s has only %d u_npnts\n\n", nr, nurbl[nr].name, nurbl[nr].u_npnt);
4130 anzGeo->nurl--;
4131 nurbl[nr].name = (char *)NULL;
4132 return(-1);
4133 }
4134 if (nurbl[nr].u_nknt<1)
4135 {
4136 errMsg("ERROR: Nurbs[%d]:%s has only %d u_nknt\n\n", nr, nurbl[nr].name, nurbl[nr].u_nknt);
4137 anzGeo->nurl--;
4138 nurbl[nr].name = (char *)NULL;
4139 return(-1);
4140 }
4141
4142 /* check if points exists */
4143 pnr1=getPntNr(pstart);
4144 if (pnr1==-1) /* new point */
4145 {
4146 printf ("ERROR: point %s of Line %s not defined\n", pstart, name);
4147 anzGeo->nurl--;
4148 nurbl[nr].name = (char *)NULL;
4149 return(-1);
4150 }
4151 pnr2=getPntNr(pend);
4152 if (pnr2==-1) /* new point */
4153 {
4154 printf ("ERROR: point %s of Line %s not defined\n", pend, name);
4155 anzGeo->nurl--;
4156 nurbl[nr].name = (char *)NULL;
4157 return(-1);
4158 }
4159
4160 /* allocate Knots and control-points */
4161 if ( (nurbl[nr].uknt =
4162 (GLfloat *)malloc( (nurbl[nr].u_nknt+1) * sizeof(GLfloat))) == NULL )
4163 printf("\n\n ERROR: malloc failed uknt\n\n");
4164 if ( (nurbl[nr].ctlpnt =
4165 (GLint *)malloc( (nurbl[nr].u_npnt+1) * sizeof(GLint))) == NULL )
4166 printf("\n\n ERROR: malloc failed ctlpnt\n\n");
4167 if ( (nurbl[nr].weight =
4168 (GLfloat *)malloc( (nurbl[nr].u_npnt+1) * sizeof(GLfloat))) == NULL )
4169 printf("\n\n ERROR: malloc failed ctlpnt\n\n");
4170 }
4171 else if(( compare( action, "CONT", 4) == 4 ) || ( compare( action, "cont", 4) == 4 ))
4172 {
4173 /* Add a control point */
4174 if (nr<0)
4175 {
4176 printf(" ERROR, NURL:%s not defined\n", name );
4177 return(-1);
4178 }
4179 if(!compactFlag)
4180 {
4181 if (!addFlag) length=sscanf (string,"%*s%*s%d%s%f", &i, buffer, &weight);
4182 else
4183 {
4184 buffer[0]='%';
4185 length=sscanf (string,"%*s%*s%d%s%f", &i, &buffer[1], &weight);
4186 }
4187 operateAlias( buffer, "p" );
4188 pnr=getPntNr(buffer);
4189 if (pnr<0)
4190 {
4191 printf("ERROR: Control-Point:%s in Nurbl:%s is not defined, Nurbl will be deleted\n", buffer, nurbl[nr].name );
4192 anzGeo->nurl--;
4193 nurbl[nr].name = (char *)NULL;
4194 return(-1);
4195 }
4196 i--;
4197 if((i<0)&&(i>nurbl[nr].u_nknt)) { printf("ERROR in nurl\n"); exit(1); }
4198 nurbl[nr].ctlpnt[i] = pnr;
4199 if(length==3) nurbl[nr].weight[i] =(GLfloat)weight;
4200 else nurbl[nr].weight[i]=1.;
4201 }
4202 else
4203 {
4204 length=sscanf (string,"%*s%*s%d%lf%lf%lf%f", &i, &x,&y,&z, &weight);
4205 getNewName( buffer, "p" );
4206 pnr= pnt( buffer, x, y, z, 1);
4207 i--;
4208 if((i<0)&&(i>nurbl[nr].u_nknt)) { printf("ERROR in nurl\n"); exit(1); }
4209 nurbl[nr].ctlpnt[i] = pnr;
4210 if(length==5) nurbl[nr].weight[i] =(GLfloat)weight;
4211 else nurbl[nr].weight[i]=1.;
4212 }
4213 #if NO_NURL
4214 /* store the controll-point in the zap-set */
4215 if((pnr!=pnr1)&&(pnr!=pnr2)) seta( zapset, "p", pnr );
4216 #endif
4217 }
4218 else if(( compare( action, "KNOT", 4) == 4 ) || ( compare( action, "knot", 4) == 4 ))
4219 {
4220 /* Add a Knot */
4221 if (nr<0)
4222 {
4223 printf(" ERROR, NURL:%s not defined\n", name );
4224 return(-1);
4225 }
4226 sscanf (string,"%*s%*s%d%f", &i, &value);
4227 i--;
4228 if((i<0)&&(i>nurbl[nr].u_nknt)) { printf("ERROR in nurl\n"); exit(1); }
4229
4230 nurbl[nr].uknt[i] = (GLfloat)value;
4231 }
4232 else if(( compare( action, "END", 3) == 3 ) || ( compare( action, "end", 3) == 3 ))
4233 {
4234 /* close the NURBS */
4235 if (nr<0)
4236 {
4237 printf(" ERROR, NURL:%s not defined\n", name );
4238 return(-1);
4239 }
4240 nurbl[nr].endFlag=1; /* define NURBL as complete */
4241 nurbl[nr].type=GL_MAP1_VERTEX_4;
4242 nurbl[nr].u_stride=4;
4243 nurbl[nr].ctlarray=NULL;
4244
4245
4246 /* negative values are not allowed - all knots are moved by the difference to 0 */
4247 if(nurbl[nr].uknt[0]<0.)
4248 {
4249 for(i=1; i<nurbl[nr].u_nknt; i++) nurbl[nr].uknt[i]-=nurbl[nr].uknt[0];
4250 nurbl[nr].uknt[0]=0.;
4251 }
4252
4253 /* create a spline from the nurbl */
4254 /* the nurbl will be evaluated at several values of u and points will be created and used */
4255 /* as spline-points */
4256 /* create the basic line */
4257 if(div==0) div=MAX_LINE_DIV;
4258 pnr= nurbl2seq(nr, nurbl);
4259
4260 /* search close points in set pnr to p1 and p2 and replace them by p1 and p2 */
4261 /* calculate all dr between p1 and pnt and sort the indexes according to dr */
4262 if ( (rsort = (Rsort *)malloc( (set[pnr].anz_p+1) * sizeof(Rsort))) == NULL )
4263 printf("ERROR: realloc failed: Rsort\n\n" );
4264 for (i=0; i<set[pnr].anz_p; i++)
4265 {
4266 x=point[pnr1].px-point[set[pnr].pnt[i]].px;
4267 y=point[pnr1].py-point[set[pnr].pnt[i]].py;
4268 z=point[pnr1].pz-point[set[pnr].pnt[i]].pz;
4269 rsort[i].r=sqrt(x*x+y*y+z*z);
4270 rsort[i].i=i;
4271 }
4272 qsort( rsort, set[pnr].anz_p, sizeof(Rsort), (void *)compareRsort );
4273 #if TEST
4274 for (i=0; i<set[pnr].anz_p; i++)
4275 printf("%d p:%d r:%lf\n", i, rsort[i].i, rsort[i].r);
4276 #endif
4277 // printf("type:%d name:%s p1[%d]:%s p2[%d]:%s p[%d]:%s\n", set[pnr].type, set[pnr].name, pnr2, point[pnr2].name, pnr1, point[pnr1].name, set[pnr].pnt[rsort[0].i], point[set[pnr].pnt[rsort[0].i]].name);
4278 if(pnr1!=set[pnr].pnt[rsort[0].i])
4279 {
4280 set[pnr].pnt[rsort[0].i]=pnr1;
4281 //delPnt( 1, ptr ); /* do not delete. endpoints from set pnt might be the same as the nurl-endpoints */
4282 }
4283
4284 /* calculate all dr between p2 and pnt and sort the indexes according to dr */
4285 for (i=0; i<set[pnr].anz_p; i++)
4286 {
4287 x=point[pnr2].px-point[set[pnr].pnt[i]].px;
4288 y=point[pnr2].py-point[set[pnr].pnt[i]].py;
4289 z=point[pnr2].pz-point[set[pnr].pnt[i]].pz;
4290 rsort[i].r=sqrt(x*x+y*y+z*z);
4291 rsort[i].i=i;
4292 }
4293 qsort( rsort, set[pnr].anz_p, sizeof(Rsort), (void *)compareRsort );
4294 if(pnr2!=set[pnr].pnt[rsort[0].i])
4295 {
4296 set[pnr].pnt[rsort[0].i]=pnr2;
4297 }
4298
4299 /* keep only points between p1 and p2 */
4300 flag=j=0;
4301 for (i=0; i<set[pnr].anz_p; i++)
4302 {
4303 if((set[pnr].pnt[i]==pnr1) || (set[pnr].pnt[i]==pnr2)) { rsort[j].i=set[pnr].pnt[i]; j++; flag=!flag; }
4304 else if(flag) { rsort[j].i=set[pnr].pnt[i]; j++; }
4305 }
4306 set[pnr].anz_p=j;
4307 for (i=0; i<set[pnr].anz_p; i++) set[pnr].pnt[i]=rsort[i].i;
4308 free(rsort);
4309
4310 /* determine bias and division */
4311 splitBiasDiv(&div, &bias);
4312 snr=line_i( name, pnr1, pnr2, pnr, div, bias, 's' );
4313
4314 #if NO_NURL
4315 /* for the moment delete the nurl and the controll-points */
4316 nurbl[nr].name = (char *)NULL;
4317 #else
4318 for (i=0; i<anz->sets; i++)
4319 {
4320 if ( set[i].flag=='o') seta( i, "L", nr );
4321 }
4322 nurbl[nr].Nurb = (GLUnurbsObj *)gluNewNurbsRenderer();
4323 #endif
4324 }
4325 else
4326 {
4327 printf("ERROR: %s not known\n", action);
4328 }
4329 return(snr);
4330 }
4331
4332
4333 /*------------------------------------------------------------------*/
4334 /* define Nurbs surface */
4335 /*------------------------------------------------------------------*/
delNurs(int anzs,int * number)4336 void delNurs( int anzs, int *number )
4337 {
4338 int j, k, p, *nrbuffer;
4339
4340 delNursFlag=1;
4341 /*
4342 printf ("sum:%d num:%d surf:%s\n", anzs, number[0], surf[number[0]].name );
4343 */
4344 if ((nrbuffer = (int *)malloc((anzs+1)*sizeof(int)) ) == NULL )
4345 { printf("\n\nERROR: realloc failure in delBody\n\n"); return; }
4346
4347 /* nessesary to store the numbers in a independent area */
4348 for (j=0; j<anzs; j++)
4349 nrbuffer[j]=number[j];
4350
4351 for (j=0; j<anzs; j++) if( nurbs[nrbuffer[j]].name != (char *)NULL )
4352 {
4353 for (k=0; k<anz->sets; k++)
4354 {
4355 if(set[k].type==0)
4356 if( set[k].name != (char *)NULL )
4357 setr( k, "S", nrbuffer[j]);
4358 }
4359 for (k=0; k<anzGeo->sh; k++)
4360 {
4361 if(shape[k].name!=(char *)NULL) { if((shape[k].type==4)&&(shape[k].p[0]==nrbuffer[j])) delShape(1, &k); }
4362 }
4363 if(printFlag)
4364 printf (" delete nurs[%d]:%s \n",nrbuffer[j], nurbs[nrbuffer[j]].name );
4365 free(nurbs[nrbuffer[j]].name);
4366 nurbs[nrbuffer[j]].name = (char *)NULL ;
4367 nurbs[nrbuffer[j]].endFlag=0;
4368 free(nurbs[nrbuffer[j]].uknt);
4369 free(nurbs[nrbuffer[j]].vknt);
4370 free(nurbs[nrbuffer[j]].ctlarray);
4371 nurbs[nrbuffer[j]].uknt=NULL;
4372 nurbs[nrbuffer[j]].vknt=NULL;
4373 nurbs[nrbuffer[j]].ctlarray=NULL;
4374
4375 for(p=0; p<nurbs[nrbuffer[j]].patches; p++)
4376 {
4377 for(k=0; k<nurbs[nrbuffer[j]].nc[p]; k++)
4378 { free(nurbs[nrbuffer[j]].uv[p][k]);
4379 free(nurbs[nrbuffer[j]].xyz[p][k]); }
4380 nurbs[nrbuffer[j]].nc[p]=0;
4381 free(nurbs[nrbuffer[j]].uv[p]);
4382 free(nurbs[nrbuffer[j]].xyz[p]);
4383 free(nurbs[nrbuffer[j]].np[p]);
4384 free(nurbs[nrbuffer[j]].sum_ambiguousPnts[p]);
4385 free(nurbs[nrbuffer[j]].uvflipped[p]);
4386 }
4387 nurbs[nrbuffer[j]].patches=0;
4388 free(nurbs[nrbuffer[j]].uv);
4389 free(nurbs[nrbuffer[j]].xyz);
4390 free(nurbs[nrbuffer[j]].np);
4391 free(nurbs[nrbuffer[j]].umax);
4392 free(nurbs[nrbuffer[j]].vmax);
4393 free(nurbs[nrbuffer[j]].ustep);
4394 free(nurbs[nrbuffer[j]].vstep);
4395 free(nurbs[nrbuffer[j]].sum_ambiguousPnts);
4396 free(nurbs[nrbuffer[j]].uvflipped);
4397 nurbs[nrbuffer[j]].uv=NULL;
4398 nurbs[nrbuffer[j]].xyz=NULL;
4399 nurbs[nrbuffer[j]].np=NULL;
4400 nurbs[nrbuffer[j]].umax=NULL;
4401 nurbs[nrbuffer[j]].vmax=NULL;
4402 nurbs[nrbuffer[j]].sum_ambiguousPnts=NULL;
4403 nurbs[nrbuffer[j]].uvflipped=NULL;
4404
4405 for(k=0; k<nurbs[nrbuffer[j]].u_npnt; k++)
4406 { free(nurbs[nrbuffer[j]].ctlpnt[k]);
4407 free(nurbs[nrbuffer[j]].weight[k]); }
4408 nurbs[nrbuffer[j]].u_npnt=0;
4409 nurbs[nrbuffer[j]].v_npnt=0;
4410 free(nurbs[nrbuffer[j]].ctlpnt);
4411 free(nurbs[nrbuffer[j]].weight);
4412 nurbs[nrbuffer[j]].ctlpnt=NULL;
4413 nurbs[nrbuffer[j]].weight=NULL;
4414 nurbs[nrbuffer[j]].u_nknt=0;
4415 nurbs[nrbuffer[j]].v_nknt=0;
4416
4417 gluDeleteNurbsRenderer(nurbs[nrbuffer[j]].Nurb);
4418 nurbs[nrbuffer[j]].Nurb=NULL;
4419 }
4420 free(nrbuffer);
4421 }
4422
4423
hashNurs(SumAsci * sumAsci,char * name,int nr)4424 int hashNurs( SumAsci *sumAsci, char *name, int nr)
4425 {
4426 int i=0,j=0, n;
4427 int sum=0;
4428
4429 while(name[i]!='\0') { sum+=name[i]*(++j); i++; }
4430
4431 /* check if sum is higher as the allocated value */
4432 /* else look for a free entry */
4433 if(sum>sumAsci->max_sumS)
4434 {
4435 if ((sumAsci->anzS=(int *)realloc( (int *)sumAsci->anzS, (sum+1)*sizeof(int)) ) == NULL )
4436 { printf("\n\nERROR: realloc failure in hashNurs(), Nurs:%s not included\n\n", name); return(-1); }
4437 if ((sumAsci->Sindx=(int **)realloc( (int **)sumAsci->Sindx, (sum+1)*sizeof(int *)) ) == NULL )
4438 { printf("\n\nERROR: realloc failure in hashNurs(), Nurs:%s not included\n\n", name); return(-1); }
4439 for(i=sumAsci->max_sumS+1; i<=sum; i++) { sumAsci->anzS[i]=0; sumAsci->Sindx[i]=NULL; }
4440 sumAsci->max_sumS=sum;
4441 }
4442 else
4443 {
4444 if (delNursFlag)
4445 for (i=0; i<sumAsci->anzS[sum]; i++)
4446 {
4447 n=sumAsci->Sindx[sum][i];
4448 if( nurbs[n].name == (char *)NULL )
4449 {
4450 /* already existing space to fill */
4451 sumAsci->Sindx[sum][i]=nr;
4452 return(sum);
4453 }
4454 }
4455 }
4456
4457 /* alloc of a new entry in the hash table */
4458 if ((sumAsci->Sindx[sum]
4459 =(int *)realloc( (int *)sumAsci->Sindx[sum], (sumAsci->anzS[sum]+1)*sizeof(int)) ) == NULL )
4460 { printf("\n\nERROR: realloc failure in hashNurs(), nurs:%s not included\n\n", name); return(-1); }
4461
4462 sumAsci->Sindx[sum][sumAsci->anzS[sum]] = nr;
4463 sumAsci->anzS[sum]++;
4464 return(sum);
4465 }
4466
4467
nurs(char * string,int addFlag)4468 int nurs( char *string, int addFlag )
4469 {
4470 char action[MAX_LINE_LENGTH], name[MAX_LINE_LENGTH], buffer[MAX_LINE_LENGTH], dummy[MAX_LINE_LENGTH];
4471 double x,y,z;
4472 GLfloat weight, value;
4473 int i, j, p, k, pnr, length, nr=-2;
4474 #if NO_NURS
4475 int zapset;
4476 #endif
4477 static int switchFlag=0; /* for IRIX: if u_exp ==1 switch u,v */
4478 static int compactFlag;
4479
4480 if (!addFlag) sscanf (string,"%s%s%s", name, action, dummy);
4481 else
4482 {
4483 sscanf (string,"%s%s%s", &name[1], action, dummy);
4484 if(( compare( action, "DEFI", 4) == 4 )||( compare( action, "defi", 4) == 4 )) name[0]='!';
4485 else name[0]='%';
4486 }
4487 operateAlias( name, "S" );
4488 if(printFlag) printf (" nurs:%s action:%s \n ", name, action);
4489
4490 nr=getNursNr(name);
4491
4492 if(( compare( action, "DEFI", 4) == 4 ) || ( compare( action, "defi", 4) == 4 ))
4493 {
4494 /* create new NURBS shape */
4495
4496 #if NO_NURS
4497 /* open a set for the controll-points, they will be deleted after comletition */
4498 if( (zapset=pre_seta( specialset->zap, "i", 0)) <0 ) return(-1);
4499 #endif
4500
4501 if (nr==-1) /* new nurs */
4502 {
4503 if(printFlag) printf ("store NURS Nr:%d Name:%s\n", anzGeo->nurs+1, name);
4504
4505 if ((nurbs = (Nurbs *)realloc( (Nurbs *)nurbs, (anzGeo->nurs+1)*sizeof(Nurbs)) ) == NULL )
4506 { printf("\n\nERROR: realloc failure in Nurs, nurbs:%s not installed\n\n", name); return(-1); }
4507
4508 nr=anzGeo->nurs;
4509 hashNurs( sumAsci, name, nr );
4510 anzGeo->nurs++;
4511 i=strlen(name);
4512 if((nurbs[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
4513 { printf("ERROR: malloc failed\n\n" ); return(-1); }
4514 strcpy(nurbs[nr].name, name);
4515 }
4516 else if (nr<-1) /* replace a deleted nurs */
4517 {
4518 nr=-(nr+10);
4519
4520 if ((nurbs = (Nurbs *)realloc( (Nurbs *)nurbs, (anzGeo->nurs+1)*sizeof(Nurbs)) ) == NULL )
4521 { printf("\n\nERROR: realloc failure in Nurs, nurbs:%s not installed\n\n", name); return(-1); }
4522
4523 i=strlen(name);
4524 if((nurbs[nr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
4525 { printf("ERROR: malloc failed\n\n" ); return(-1); }
4526 strcpy(nurbs[nr].name, name);
4527 free( nurbs[nr].uknt );
4528 free( nurbs[nr].vknt );
4529 for (i=0; i<nurbs[nr].u_npnt; i++)
4530 {
4531 free( nurbs[nr].ctlpnt[i] );
4532 }
4533 free( nurbs[nr].ctlpnt );
4534 free( nurbs[nr].weight );
4535
4536 for(p=0; p<nurbs[nr].patches; p++)
4537 {
4538 for(k=0; k<nurbs[nr].nc[p]; k++)
4539 { free(nurbs[nr].uv[p][k]);
4540 free(nurbs[nr].xyz[p][k]); }
4541 free(nurbs[nr].uv[p]);
4542 free(nurbs[nr].xyz[p]);
4543 free(nurbs[nr].np[p]);
4544 free(nurbs[nr].sum_ambiguousPnts[p]);
4545 free(nurbs[nr].uvflipped[p]);
4546 }
4547 free(nurbs[nr].uv);
4548 free(nurbs[nr].xyz);
4549 free(nurbs[nr].np);
4550 free(nurbs[nr].nc);
4551 free(nurbs[nr].umax);
4552 free(nurbs[nr].vmax);
4553 free(nurbs[nr].ustep);
4554 free(nurbs[nr].vstep);
4555 free(nurbs[nr].sum_ambiguousPnts);
4556 free(nurbs[nr].uvflipped);
4557 nurbs[nr].uv=NULL;
4558 nurbs[nr].xyz=NULL;
4559 nurbs[nr].np=NULL;
4560 nurbs[nr].nc=NULL;
4561 nurbs[nr].umax=NULL;
4562 nurbs[nr].vmax=NULL;
4563 nurbs[nr].vstep=NULL;
4564 nurbs[nr].ustep=NULL;
4565 nurbs[nr].sum_ambiguousPnts=NULL;
4566 nurbs[nr].uvflipped=NULL;
4567
4568 hashNurs( sumAsci, name, nr );
4569 }
4570 else
4571 {
4572 if(printFlag) printf ("redefine NURS:%s\n", name);
4573 free( nurbs[nr].uknt );
4574 free( nurbs[nr].vknt );
4575 for (i=0; i<nurbs[nr].u_npnt; i++)
4576 {
4577 free( nurbs[nr].ctlpnt[i] );
4578 free( nurbs[nr].weight[i] );
4579 }
4580 free( nurbs[nr].ctlpnt );
4581 free( nurbs[nr].weight );
4582
4583 for(p=0; p<nurbs[nr].patches; p++)
4584 {
4585 for(k=0; k<nurbs[nr].nc[p]; k++)
4586 { free(nurbs[nr].uv[p][k]);
4587 free(nurbs[nr].xyz[p][k]);
4588 }
4589 free(nurbs[nr].uv[p]);
4590 free(nurbs[nr].xyz[p]);
4591 free(nurbs[nr].np[p]);
4592 free(nurbs[nr].sum_ambiguousPnts[p]);
4593 free(nurbs[nr].uvflipped[p]);
4594 }
4595 free(nurbs[nr].uv);
4596 free(nurbs[nr].xyz);
4597 free(nurbs[nr].np);
4598 free(nurbs[nr].nc);
4599 free(nurbs[nr].umax);
4600 free(nurbs[nr].vmax);
4601 free(nurbs[nr].ustep);
4602 free(nurbs[nr].vstep);
4603 free(nurbs[nr].sum_ambiguousPnts);
4604 free(nurbs[nr].uvflipped);
4605 nurbs[nr].uv=NULL;
4606 nurbs[nr].xyz=NULL;
4607 nurbs[nr].np=NULL;
4608 nurbs[nr].nc=NULL;
4609 nurbs[nr].umax=NULL;
4610 nurbs[nr].vmax=NULL;
4611 nurbs[nr].vstep=NULL;
4612 nurbs[nr].ustep=NULL;
4613 nurbs[nr].sum_ambiguousPnts=NULL;
4614 nurbs[nr].uvflipped=NULL;
4615 }
4616
4617 /* define NURBS as incomplete */
4618 nurbs[nr].endFlag=0;
4619
4620 /* read the header data of the nurbs with the COMPACT fam statement */
4621 if(compare(dummy,"COMP",4)==4)
4622 {
4623 compactFlag=1;
4624 sscanf (string,"%*s%*s%*s%d%d%d%d%d%d", &nurbs[nr].u_exp, &nurbs[nr].v_exp, &nurbs[nr].u_npnt, &nurbs[nr].v_npnt, &nurbs[nr].u_nknt, &nurbs[nr].v_nknt);
4625 }
4626 /* read the header data of the nurbs with the FULL fam statement */
4627 else if(compare(dummy,"FULL",4)==4)
4628 {
4629 compactFlag=0;
4630 sscanf (string,"%*s%*s%*s%d%d%d%d%d%d", &nurbs[nr].u_exp, &nurbs[nr].v_exp, &nurbs[nr].u_npnt, &nurbs[nr].v_npnt, &nurbs[nr].u_nknt, &nurbs[nr].v_nknt);
4631 }
4632 else
4633 {
4634 compactFlag=0;
4635 sscanf (string,"%*s%*s%d%d%d%d%d%d", &nurbs[nr].u_exp, &nurbs[nr].v_exp, &nurbs[nr].u_npnt, &nurbs[nr].v_npnt, &nurbs[nr].u_nknt, &nurbs[nr].v_nknt);
4636 }
4637
4638 /* if its an irix-computer handle a known bug in the libGL.so by switching u and v */
4639 switchFlag=0;
4640 if( (compare(cursys->sysname,"IRIX",4)==4)&&(nurbs[nr].u_exp==1))
4641 {
4642 switchFlag=1;
4643 p=nurbs[nr].u_exp;
4644 nurbs[nr].u_exp=nurbs[nr].v_exp;
4645 nurbs[nr].v_exp=p;
4646
4647 p=nurbs[nr].u_npnt;
4648 nurbs[nr].u_npnt=nurbs[nr].v_npnt;
4649 nurbs[nr].v_npnt=p;
4650
4651 p=nurbs[nr].u_nknt;
4652 nurbs[nr].u_nknt=nurbs[nr].v_nknt;
4653 nurbs[nr].v_nknt=p;
4654 }
4655
4656 if (nurbs[nr].u_npnt<1)
4657 {
4658 errMsg("ERROR: Nurbs[%d]:%s has only %d u_npnts\n\n",
4659 nr, nurbs[nr].name, nurbs[nr].u_npnt);
4660 anzGeo->nurs--;
4661 nurbs[nr].name = (char *)NULL;
4662 return(-1);
4663 }
4664 if (nurbs[nr].v_npnt<1)
4665 {
4666 errMsg("ERROR: Nurbs[%d]:%s has only %d v_npnts\n\n",
4667 nr, nurbs[nr].name, nurbs[nr].u_npnt);
4668 anzGeo->nurs--;
4669 nurbs[nr].name = (char *)NULL;
4670 return(-1);
4671 }
4672
4673 /* allocate Knots and control-points */
4674 if ( (nurbs[nr].uknt =
4675 (GLfloat *)malloc( (nurbs[nr].u_nknt+1) * sizeof(GLfloat))) == NULL )
4676 printf("\n\n ERROR: malloc failed uknt\n\n");
4677 if ( (nurbs[nr].vknt =
4678 (GLfloat *)malloc( (nurbs[nr].v_nknt+1) * sizeof(GLfloat))) == NULL )
4679 printf("\n\n ERROR: malloc failed vknt\n\n");
4680
4681 if ( (nurbs[nr].ctlpnt =
4682 (int **)malloc( (nurbs[nr].u_npnt+1) * sizeof(int *))) == NULL )
4683 printf("\n\n ERROR: malloc failed ctlpnt\n\n");
4684 for (i=0; i<nurbs[nr].u_npnt; i++)
4685 {
4686 if ( (nurbs[nr].ctlpnt[i] =
4687 (int *)malloc( (nurbs[nr].v_npnt+1) * sizeof( int ))) == NULL )
4688 printf("\n\n ERROR: malloc failed ctlpnt[i]\n\n");
4689 }
4690
4691 if ( (nurbs[nr].weight =
4692 (GLfloat **)malloc( (nurbs[nr].u_npnt+1) * sizeof(GLfloat *))) == NULL )
4693 printf("\n\n ERROR: malloc failed weight\n\n");
4694 for (i=0; i<nurbs[nr].u_npnt; i++)
4695 {
4696 if ( (nurbs[nr].weight[i] =
4697 (GLfloat *)malloc( (nurbs[nr].v_npnt+1) * sizeof(GLfloat))) == NULL )
4698 printf("\n\n ERROR: malloc failed weight[i]\n\n");
4699 }
4700 }
4701 else if(( compare( action, "CONT", 4) == 4 ) || ( compare( action, "cont", 4) == 4 ))
4702 {
4703 /* Add a control point with weight */
4704 if (nr<0)
4705 {
4706 printf(" ERROR, NURS:%s not defined\n", name );
4707 return(-1);
4708 }
4709
4710 /* read the control point by its coordinates (x y z). Used by fam. */
4711 /* length=sscanf (string,"%*s%*s%d%d%lf%lf%lf%s", &i, &j, &x,&y,&z, dummy); */
4712 /* read the control point by its name (buffer) */
4713 if(!compactFlag)
4714 {
4715 if (!addFlag) length=sscanf (string,"%*s%*s%d%d%s%f", &i, &j, buffer, &weight);
4716 else
4717 {
4718 buffer[0]='%';
4719 length=sscanf (string,"%*s%*s%d%d%s%f", &i, &j, &buffer[1], &weight);
4720 }
4721 operateAlias( buffer, "p" );
4722 pnr=getPntNr(buffer);
4723 if (pnr<0)
4724 {
4725 printf("ERROR: Control-Point:%s in Nurbs:%s is not defined, Nurbs will be deleted\n", buffer, nurbs[nr].name );
4726 anzGeo->nurs--;
4727 nurbs[nr].name = (char *)NULL;
4728 return(-1);
4729 }
4730 if(switchFlag)
4731 {
4732 p=i;
4733 i=j;
4734 j=p;
4735 }
4736 i--;
4737 j--;
4738 nurbs[nr].ctlpnt[i][j] = pnr;
4739 if(length==4) nurbs[nr].weight[i][j] =weight;
4740 else nurbs[nr].weight[i][j]=1.;
4741 }
4742 else
4743 {
4744 length=sscanf (string,"%*s%*s%d%d%lf%lf%lf%f", &i, &j, &x,&y,&z, &weight);
4745 if(switchFlag)
4746 {
4747 p=i;
4748 i=j;
4749 j=p;
4750 }
4751 i--;
4752 j--;
4753 getNewName( buffer, "p" );
4754 pnr= pnt( buffer, x, y, z, 0);
4755 nurbs[nr].ctlpnt[i][j] = pnr;
4756 if(length==6) nurbs[nr].weight[i][j] =weight;
4757 else nurbs[nr].weight[i][j]=1.;
4758 }
4759 #if NO_NURS
4760 /* store the controll-point in the zap-set */
4761 seta( zapset, "p", pnr );
4762 #endif
4763 }
4764 else if(( compare( action, "KNOT", 4) == 4 ) || ( compare( action, "knot", 4) == 4 ))
4765 {
4766 /* Add a Knot */
4767 if (nr<0)
4768 {
4769 printf(" ERROR, NURS:%s not defined\n", name );
4770 return(-1);
4771 }
4772
4773 /* read the knot, direction (u|v), index, value */
4774 sscanf (string,"%*s%*s%s%d%f", buffer, &i, &value);
4775 if(switchFlag)
4776 {
4777 if((buffer[0]=='U')||(buffer[0]=='u')) buffer[0]='V';
4778 else buffer[0]='U';
4779 }
4780
4781 i--;
4782 if((buffer[0]=='U')||(buffer[0]=='u'))
4783 {
4784 if(i<nurbs[nr].u_nknt) nurbs[nr].uknt[i] = value;
4785 else printf("WARNING: definition of NURS:%s in error\n", nurbs[nr].name);
4786 }
4787 else if((buffer[0]=='V')||(buffer[0]=='v'))
4788 {
4789 if(i<nurbs[nr].v_nknt) nurbs[nr].vknt[i]=value;
4790 else printf("WARNING: definition of NURS:%s in error\n", nurbs[nr].name);
4791 }
4792 else { printf(" ERROR: parameter:%s not U or V \n", buffer); return(-1); }
4793 }
4794 else if(( compare( action, "END", 3) == 3 ) || ( compare( action, "end", 3) == 3 ))
4795 {
4796 /* close the NURBS */
4797 if (nr<0)
4798 {
4799 printf(" ERROR, NURS:%s not defined\n", name );
4800 return(-2);
4801 }
4802 if((nurbs[nr].uknt[0]==nurbs[nr].uknt[nurbs[nr].u_nknt-1])||(nurbs[nr].vknt[0]==nurbs[nr].vknt[nurbs[nr].v_nknt-1]))
4803 {
4804 printf(" ERROR, NURS:%s knods not valid umin:%f max:%f vmin:%f max:%f\n", name, nurbs[nr].uknt[0], nurbs[nr].uknt[nurbs[nr].u_nknt-1], nurbs[nr].vknt[0], nurbs[nr].vknt[nurbs[nr].v_nknt-1]);
4805 anzGeo->nurs--;
4806 nurbs[nr].name = (char *)NULL;
4807 return(-2);
4808 }
4809 nurbs[nr].type=GL_MAP2_VERTEX_4;
4810 nurbs[nr].u_stride=4* nurbs[nr].v_npnt;
4811 nurbs[nr].v_stride=4;
4812 nurbs[nr].ctlarray=(GLfloat *)NULL;
4813
4814 /* additional variables for the trimming and meshing */
4815 nurbs[nr].nurbsType=0;
4816 nurbs[nr].trimFlag=0;
4817 nurbs[nr].patches=0;
4818
4819 nurbs[nr].uv=NULL;
4820 nurbs[nr].xyz=NULL;
4821 nurbs[nr].np=NULL;
4822 nurbs[nr].nc=NULL;
4823 nurbs[nr].umax=NULL;
4824 nurbs[nr].vmax=NULL;
4825 nurbs[nr].ustep=NULL;
4826 nurbs[nr].vstep=NULL;
4827 nurbs[nr].sum_ambiguousPnts=NULL;
4828 nurbs[nr].uvflipped=NULL;
4829
4830 #if NO_NURS
4831 /* for the moment delete the nurs and the controll-points */
4832 nurbs[nr].name = (char *)NULL;
4833 #else
4834
4835 /* first uexp+1 vexp+1 knot-vals must be the same */
4836 for (i=1; i<=nurbs[nr].u_exp; i++) if(nurbs[nr].uknt[i]!=nurbs[nr].uknt[0])
4837 {
4838 printf(" WARNING: Nurbs:%s has a knot-multiplicity(u) of:%d but needs:%d\n",nurbs[nr].name,i,nurbs[nr].u_exp+1 );
4839 return(nr);
4840 }
4841 for (i=1; i<=nurbs[nr].v_exp; i++) if(nurbs[nr].vknt[i]!=nurbs[nr].vknt[0])
4842 {
4843 printf(" WARNING: Nurbs:%s has a knot-multiplicity(v) of:%d but needs:%d\n",nurbs[nr].name,i,nurbs[nr].v_exp+1 );
4844 return(nr);
4845 }
4846 for (i=nurbs[nr].u_nknt-nurbs[nr].u_exp; i<nurbs[nr].u_nknt; i++)
4847 if(nurbs[nr].uknt[i]!=nurbs[nr].uknt[nurbs[nr].u_nknt-1-nurbs[nr].u_exp])
4848 {
4849 printf(" WARNING: Nurbs:%s has a knot-multiplicity(u) of:%d but needs:%d\n",nurbs[nr].name,i+1-(nurbs[nr].u_nknt-nurbs[nr].u_exp),nurbs[nr].u_exp+1 );
4850 return(nr);
4851 }
4852 for (i=nurbs[nr].v_nknt-nurbs[nr].v_exp; i<nurbs[nr].v_nknt; i++)
4853 if(nurbs[nr].vknt[i]!=nurbs[nr].vknt[nurbs[nr].v_nknt-1-nurbs[nr].v_exp])
4854 {
4855 printf(" WARNING: Nurbs:%s has a knot-multiplicity(v) of:%d but needs:%d\n",nurbs[nr].name,i+1-(nurbs[nr].v_nknt-nurbs[nr].v_exp),nurbs[nr].v_exp+1 );
4856 return(nr);
4857 }
4858
4859 for (i=0; i<anz->sets; i++)
4860 {
4861 if ( set[i].flag=='o') seta( i, "S", nr );
4862 }
4863
4864 /* negative values are not allowed - all knots are moved by the difference to 0 */
4865 if(nurbs[nr].uknt[0]<0.)
4866 {
4867 for(i=1; i<nurbs[nr].u_nknt; i++) nurbs[nr].uknt[i]-=nurbs[nr].uknt[0];
4868 nurbs[nr].uknt[0]=0.;
4869 }
4870 if(nurbs[nr].vknt[0]<0.)
4871 {
4872 for(i=1; i<nurbs[nr].v_nknt; i++) nurbs[nr].vknt[i]-=nurbs[nr].vknt[0];
4873 nurbs[nr].vknt[0]=0.;
4874 }
4875 /*
4876 for (i=0; i<nurbs[nr].u_nknt; i++) printf("ku:%lf\n", nurbs[nr].uknt[i]);
4877 for (i=0; i<nurbs[nr].v_nknt; i++) printf("kv:%lf\n", nurbs[nr].vknt[i]);
4878 */
4879
4880 nurbs[nr].Nurb = (GLUnurbsObj *)gluNewNurbsRenderer();
4881 nurbs[nr].endFlag=1;
4882 repNurs(nr);
4883
4884 /* create a shape of the same name for reference in surfaces */
4885 if( shape_i( nurbs[nr].name, 4, nr, 0, 0, 0, 0, 0, 0)==-1 )
4886 printf("ERROR: shape could not be created\n");
4887 #endif
4888 }
4889 else
4890 {
4891 printf("ERROR: %s not known\n", action);
4892 }
4893 return(nr);
4894 }
4895