1 /* --------------------------------------------------------------------  */
2 /*                          CALCULIX                                     */
3 /*                   - GRAPHICAL INTERFACE -                             */
4 /*                                                                       */
5 /*     A 3-dimensional pre- and post-processor for finite elements       */
6 /*              Copyright (C) 1996 Klaus Wittig                          */
7 /*                                                                       */
8 /*     This program is free software; you can redistribute it and/or     */
9 /*     modify it under the terms of the GNU General Public License as    */
10 /*     published by the Free Software Foundation; version 2 of           */
11 /*     the License.                                                      */
12 /*                                                                       */
13 /*     This program is distributed in the hope that it will be useful,   */
14 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */
15 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
16 /*     GNU General Public License for more details.                      */
17 /*                                                                       */
18 /*     You should have received a copy of the GNU General Public License */
19 /*     along with this program; if not, write to the Free Software       */
20 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
21 /* --------------------------------------------------------------------  */
22 
23 #include <cgx.h>
24 #include <ctype.h>
25 #include  <time.h>
26 
27 
28 #define ANSYS 0
29 #define TEST  0
30 
31 #define INI_FIELD_SIZE 1000000
32 #define DAT_SIZE       80
33 
34 /* duplication of equations for segments of a cycsym-calc */
35 #define NODE_OFFSET 0 /* 107064 */
36 #define SEGMENTS 14
37 
38 #define     BOU         "+bou"
39 #define     DEP         "+dep"
40 #define     IND         "+ind"
41 #define     MPC         "+mpc"
42 #define     CLO         "+clo"
43 #define     DLO         "+dlo"
44 #define     RAD         "+rad"
45 #define     FLM         "+flm"
46 #define     CFLX        "+cflx"
47 #define     DFLX        "+dflx"
48 #define     MFLW        "+mflw"
49 #define     CONT1        "+cont1"
50 #define     CONT2        "+cont2"
51 #define     SPCF        "+spcf"
52 #define     TIE1        "+tie1"
53 #define     TIE2        "+tie2"
54 #define     TIECYC1        "+tiecyc1"
55 #define     TIECYC2        "+tiecyc2"
56 #define     TIEMUL1        "+tiemult1"
57 #define     TIEMUL2        "+tiemult2"
58 
59 #define     DOFT        11
60 #define     DOFP        8
61 
62 char ansys_dof[6][5]={"UX","UY","UZ","ROTX","ROTY","ROTZ"}; /* SHORT-CUTS FOR ANSYS DOFS */
63 char ansys_frc[6][5]={"FX","FY","FZ"}; /* SHORT-CUTS FOR ANSYS FORCE */
64 
65 FILE *handlein;
66 FILE *handleans;
67 
68 int fileOpenError=0;
69 
70 typedef struct {
71     int   nset;
72     double d;
73 }Elprop;
74 
75 Elprop    elprop[1];
76 int      *selected_elems=NULL;
77 int       filesopen=0;
78 FILE     *openfile[100];
79 
80 
81 int      matnr=0, ansFlag=0;
82 char     **dat=NULL;
83 
84 Sets      *setx=NULL;
85 Elements  *elemx=NULL;
86 Nodes     *nodex=NULL;
87 Datasets  *lcasex=NULL;
88 Summen    *anzx=NULL;
89 int       anz_fb=-1;
90 
91 extern int MAKE_SETS_DEF;
92 extern char buffer[MAX_LINE_LENGTH];
93 extern Alias     *alias;
94 extern Materials *material;
95 extern Amplitudes *amplitude;
96 extern SumGeo    anzGeo[1];
97 extern SumAsci   sumAsci[1];
98 extern char printFlag;
99 Elements  *e_enqirex=NULL;     /* feld in dem e_enqire[elem[i].nr].xx abgelegt ist, statt elem[i].xx */
100 
101 char dataset_text[MAX_LINE_LENGTH];
102 double dataset_value=0;
103 int copyFlag=0, step_nr=0;
104 FILE *handle_equ=NULL;
105 int  node_field_size=0, elem_field_size=0, elem_field_size2=0;
106 int  dlo_field_size=1, film_field_size=1, rad_field_size=1, amp_field_size=1, mat_field_size=1;
107 int step_flag=0;
108 clock_t t1, t2 ;
109 int resetFlag=0;
110 int userTempSetNr=-1;     /* >-1: user temps are included for the given setnr, abqrecord() changes mode */
111 
annotation(void)112 void annotation( void )
113 {
114   printf("******************************************************************************\n");
115   printf("*  read ccx input                                   4.4.2002 wi              *\n");
116   printf("*                                                                            *\n");
117   printf("*                                                                            *\n");
118   printf("* -only free-format is supported. fixed format might cause a prg-crash.      *\n");
119   printf("*                                                                            *\n");
120   printf("*                                                                            *\n");
121   printf("******************************************************************************\n");
122 }
123 
124 /* liest einen Record bis '\n'; uebergibt Anzahl gelesene Zeichen */
arecord(FILE * handle1,char * string)125 int arecord( FILE *handle1,  char *string)
126 {
127   int i, n, c;
128 
129   for (i=0; i<MAX_LINE_LENGTH-1; i++)
130   {
131     do{ string[i] = getc(handle1); }while((string[i]==' ')||(string[i]=='\t'));
132     if (string[i] == '\n')
133       {
134       for (n=i+1; n<MAX_LINE_LENGTH; ++n) string[n] = '\0';
135       return(i);
136       }
137     if (string[i] == '\r')
138       {
139       c = getc(handle1);
140       if (c != '\n')
141         ungetc(c, handle1);
142 
143       for (n=i+1; n<MAX_LINE_LENGTH; ++n) string[n] = '\0';
144       return(i);
145      }
146     else if (string[i] == (char)EOF)
147       {
148       for (n=i+1; n<MAX_LINE_LENGTH; ++n) string[n] = '\0';
149       return(i);
150       }
151   }
152   if(i==MAX_LINE_LENGTH-1)
153   {
154     printf(" WARNING: Ignore long string:%s",string);
155     do{ n=getc(handle1); printf("%c",n); }while((n!='\n')&&(n!='\r')&&(n!='\0')&&(n!=(char)EOF));
156   }
157   string[MAX_LINE_LENGTH-1] = '\0';
158   return(MAX_LINE_LENGTH-1);
159 }
160 
161 
162 
163 /* return:           */
164 /* 1: regular string */
165 /* -2:  end of data block     */
166 /* -1:  all files closed      */
abqrecord(char * string)167 int abqrecord( char *string)
168 {
169   int i,l;
170 
171  getNextLine:;
172 
173   /* check for comments and usertemps */
174   if(userTempSetNr>-1)
175   {
176     do{
177       l=arecord( handlein, string);
178 
179       // if usertemps remove the leading ** and continue
180       if((l>20)&&(string[2]=='*')&&(string[3]!='*'))
181       {
182         for(i=0;i<15; i++) string[i]=toupper(string[i]);
183         if (compare(&string[3], "UTEMPINCLUDE",12)==12)
184 	{
185           for(i=0; i<l-2; i++) string[i]=string[i+2];
186           string[i]=0;
187 	}
188       }
189     } while(((string[0]=='*')&&(string[1]=='*'))||(string[0]=='\n')||(string[0]=='\r'));
190   }
191   else
192   {
193     do{ l=arecord( handlein, string); } while(((string[0]=='*')&&(string[1]=='*'))||(string[0]=='\n')||(string[0]=='\r'));
194   }
195 
196   /* check for include */
197   if(string[0]=='*')
198   {
199     if ((compare(string, "*INCLUDE",5)==5)||(compare(string, "*include",5)==5))
200     {
201      /* change the filepointer */
202      filesopen=getFilePointer( filesopen, openfile, string);
203      goto getNextLine;
204     }
205     else return(-2);
206   }
207 
208   if (string[l] == (char)EOF)
209   {
210     /* are there files open? */
211     if(filesopen>1)
212     {
213         fclose(handlein);
214 	filesopen--;
215 	handlein=openfile[filesopen-1];
216         if(printFlag) printf("open file again:%d\n",filesopen);
217     goto getNextLine;
218     }
219     else return(-1);
220   }
221   return(l);
222 }
223 
224 
225 
__crecord(char * rec_str,char ** dat)226 int __crecord( char *rec_str, char **dat)
227 {
228   int i,j;
229   int nextarg=0, letter=0;
230 
231   /* scan all args divided by comma */
232   nextarg=0;letter=0;
233   for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
234   for(i=0; i<MAX_LINE_LENGTH; i++)
235   {
236     if(rec_str[i]==(char)EOF) {  break; }
237     if(rec_str[i]=='\n') {  break; }
238     if(rec_str[i]==0) {  break; }
239     if(rec_str[i]==',')
240     {
241       nextarg++;
242       letter=0;
243       for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
244     }
245     else
246     {
247       if((rec_str[i]>32)&& (rec_str[i]<127))
248       {
249         dat[nextarg][letter]=rec_str[i];
250         letter++;
251       }
252     }
253   }
254   //if(nextarg>=80) { printf("ERROR in crecord: increase dat\n"); exit(0); }
255   if(dat[nextarg][0]=='\0') return(nextarg);
256   return(nextarg+1);
257 }
258 
259 
260 
261 
262 
crecord(char * rec_str,char ** dat)263 int crecord( char *rec_str, char **dat)
264 {
265   register int i;
266   int nextarg=0, letter=0;
267 
268   /* scan all args divided by comma */
269   nextarg=0;letter=0;
270   //for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
271   for(i=0; i<MAX_LINE_LENGTH; i++)
272   {
273     if(rec_str[i]==(char)EOF) {dat[nextarg][letter]='\0';  break; }
274     if(rec_str[i]=='\n') {dat[nextarg][letter]='\0';  break; }
275     if(rec_str[i]==0) {dat[nextarg][letter]='\0';  break; }
276     if(rec_str[i]==',')
277     {
278       dat[nextarg][letter]='\0';
279       nextarg++;
280       letter=0;
281       //for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
282     }
283     else
284     {
285       if((rec_str[i]>32)&& (rec_str[i]<127))
286       {
287         dat[nextarg][letter]=rec_str[i];
288         letter++;
289       }
290     }
291   }
292   if(nextarg>=DAT_SIZE) { printf("ERROR in crecord: increase DAT_SIZE\n"); exit(0); }
293   if(dat[nextarg][0]=='\0') return(nextarg);
294   return(nextarg+1);
295 }
296 
297 
298 /*------------------------------------------------------------------*/
299 /* entity einem Set zuordnen                                        */
300 /*------------------------------------------------------------------*/
301 
302 
303 /* returns set-Index if known, or -1  */
getSetNrx(char * name)304 int getSetNrx(char *name)
305 {
306   int  i;
307   int length, pfree=-1;
308 
309   if(!anzx->sets) return(-1);
310   if(name== (char *)NULL) return(-1);
311   length=strlen(name);
312 
313   for (i=0; i<anzx->sets; i++)
314   {
315     if (setx[i].name!= (char *)NULL)
316     {
317       if ((compare( setx[i].name, name, length)==length) && (sword( setx[i].name, buffer)==length))
318       {
319         return(i);
320       }
321     }
322   }
323   return(pfree);
324 }
325 
326 
327 
328 
delSetx(char * setname)329 void delSetx( char *setname)
330 {
331   int i, setNr;
332 
333   setNr=getSetNrx(setname);
334 
335   if (setNr<0)
336   {
337     if(printFlag) printf (" delSet: set:%s does not exist\n", setname);
338     return;
339   }
340 
341   /* der set wird wieder frei gegeben */
342   if(setx[setNr].anz_elf)
343     for(i=0; i<setx[setNr].anz_elf; i++)
344       if(setx[setNr].elf[i].n) free(setx[setNr].elf[i].v);
345 
346   free(setx[setNr].name);
347   free(setx[setNr].valu);
348   free(setx[setNr].node);
349   free(setx[setNr].elem);
350   free(setx[setNr].face);
351   free(setx[setNr].elf);
352   free(setx[setNr].pnt);
353   free(setx[setNr].line);
354   free(setx[setNr].lcmb);
355   free(setx[setNr].surf);
356   free(setx[setNr].body);
357   free(setx[setNr].nurl);
358   free(setx[setNr].nurs);
359   free(setx[setNr].set);
360   free(setx[setNr].shp);
361   free(setx[setNr].eparm);
362   setx[setNr].name=(char *)NULL;
363   setx[setNr].valu=(int *)NULL;
364   setx[setNr].node=(int *)NULL;
365   setx[setNr].elem=(int *)NULL;
366   setx[setNr].face=(int *)NULL;
367   setx[setNr].elf=(Elfaces *)NULL;
368   setx[setNr].pnt= (int *)NULL;
369   setx[setNr].line=(int *)NULL;
370   setx[setNr].lcmb=(int *)NULL;
371   setx[setNr].surf=(int *)NULL;
372   setx[setNr].body=(int *)NULL;
373   setx[setNr].nurl=(int *)NULL;
374   setx[setNr].nurs=(int *)NULL;
375   setx[setNr].set=(int *)NULL;
376   setx[setNr].shp=(int *)NULL;
377   setx[setNr].eparm=(char *)NULL;
378   setx[setNr].material = -1;
379   setx[setNr].flag = 'c';
380   setx[setNr].type = 0;
381   setx[setNr].anz_v = 0;
382   setx[setNr].anz_n = 0;
383   setx[setNr].anz_e = 0;
384   setx[setNr].anz_f = 0;
385   setx[setNr].anz_elf = 0;
386   setx[setNr].anz_p = 0;
387   setx[setNr].anz_l = 0;
388   setx[setNr].anz_c = 0;
389   setx[setNr].anz_s = 0;
390   setx[setNr].anz_b = 0;
391   setx[setNr].anz_nurl = 0;
392   setx[setNr].anz_nurs = 0;
393   setx[setNr].anz_se = 0;
394   setx[setNr].anz_sh = 0;
395 }
396 
397 
setax(int setNr,char * type,int number)398 int setax( int setNr, char *type, int number)
399 {
400   if( setx[setNr].name == (char *)NULL )
401   {
402     errMsg(" ERROR: setNr:%d is undefined\n", setNr);
403     return(-1);
404   }
405 
406   /* check if item is known and if its already member of the set */
407   if ( type[0] == 'r' )
408   {
409     if (number<0)
410     { if(printFlag) printf(" set:%d does not exist\n", number ); return(-1); }
411     setx[setNr].anz_se= iinsert(&setx[setNr].set, setx[setNr].anz_se, number);
412     setx[number].anz_se= iinsert(&setx[number].set, setx[number].anz_se, setNr);
413   }
414   else if (( type[0] == 'h' )||(( type[0] == 's' )&&( type[1] == 'h' )))
415   {
416     if (number<0)
417     { if(printFlag) printf(" shape:%d does not exist\n", number ); return(-1); }
418     setx[setNr].anz_sh= iinsert(&setx[setNr].shp, setx[setNr].anz_sh, number);
419   }
420   else if ( type[0] == 'n' )
421   {
422     setx[setNr].anz_n= iinsert(&setx[setNr].node, setx[setNr].anz_n, number);
423   }
424   else if ( type[0] == 'e' )
425   {
426     setx[setNr].anz_e=iinsert(&setx[setNr].elem, setx[setNr].anz_e, number);
427   }
428   else if ( type[0] == 'f' )
429   {
430     setx[setNr].anz_f=iinsert(&setx[setNr].face, setx[setNr].anz_f, number);
431   }
432   else if ( type[0] == 'j' )
433   {
434     if((setx[setNr].elf= (Elfaces *)realloc(setx[setNr].elf, (setx[setNr].anz_elf+1)*sizeof(Elfaces))) == NULL )
435     { printf("ERROR: realloc failed in seta()\n\n" ); return(-1); }
436     if(number)
437     {
438       setx[setNr].elf[setx[setNr].anz_elf].n=number;
439       if((setx[setNr].elf[setx[setNr].anz_elf].v= (float *)calloc(number, sizeof(float))) == NULL )
440       { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
441     }
442     else setx[setNr].elf[setx[setNr].anz_elf].n=0;
443     setx[setNr].anz_elf++;
444     return(setx[setNr].anz_elf-1);
445   }
446   else
447   {
448     errMsg ("WARNING: in seta type:%s not recognized\n", type);
449     return(-1);
450   }
451   return(1);
452 }
453 
454 
455 
pre_setax(char * string,char * type,char * name)456 int pre_setax( char *string, char *type, char *name)
457 {
458   int i, setNr;
459   int n=0;
460   int number;
461   char setname[MAX_LINE_LENGTH]; /* string is not changeable. Therefore a new char is necessary */
462 
463   /* remove blanks and other illegal chars*/
464   for(i=0;i<strlen(string); i++) if(string[i]>(char)0x20) { setname[n]=string[i]; n++; }
465   if(!n) return(-1);
466   setname[n]='\0';
467 
468   operateAlias( setname, "se" );
469   setNr=getSetNrx(setname);
470 
471   number=0;
472 
473   if (setNr==-1)
474   {
475     if ((setx = (Sets *)realloc( (Sets *)setx, (anzx->sets+2)*sizeof(Sets)) ) == NULL )
476     {
477       printf(" ERROR: realloc failure in pre_setax, set:%s not installed\n\n", setname);
478       return(-1);
479     }
480     setNr= anzx->sets;
481     anzx->sets++;
482 
483     i=strlen(setname);
484     if((setx[setNr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
485     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
486     strcpy( setx[setNr].name, setname);
487     if(printFlag) printf (" create set:%s\n", setx[setNr].name);
488     setx[setNr].flag='c';
489     if ( type[1] == 's' ) setx[setNr].type=1;
490     else                  setx[setNr].type=0;
491     setx[setNr].etyp=0;
492     if((setx[setNr].valu= (int *)malloc(sizeof(int))) == NULL )
493     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
494     if((setx[setNr].node= (int *)malloc(sizeof(int))) == NULL )
495     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
496     if((setx[setNr].elem= (int *)malloc(sizeof(int))) == NULL )
497     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
498     if((setx[setNr].face= (int *)malloc(sizeof(int))) == NULL )
499     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
500     if((setx[setNr].elf= (Elfaces *)malloc(sizeof(Elfaces))) == NULL )
501     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
502     if((setx[setNr].pnt= (int *)malloc(sizeof(int))) == NULL )
503     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
504     if((setx[setNr].line= (int *)malloc(sizeof(int))) == NULL )
505     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
506     if((setx[setNr].lcmb= (int *)malloc(sizeof(int))) == NULL )
507     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
508     if((setx[setNr].surf= (int *)malloc(sizeof(int))) == NULL )
509     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
510     if((setx[setNr].body= (int *)malloc(sizeof(int))) == NULL )
511     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
512     if((setx[setNr].nurl= (int *)malloc(sizeof(int))) == NULL )
513     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
514     if((setx[setNr].nurs= (int *)malloc(sizeof(int))) == NULL )
515     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
516     if((setx[setNr].set= (int *)malloc(sizeof(int))) == NULL )
517     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
518     if((setx[setNr].shp= (int *)malloc(sizeof(int))) == NULL )
519     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
520     setx[setNr].index = -1;
521     setx[setNr].material = -1;
522     setx[setNr].anz_v = 0;
523     setx[setNr].anz_n = 0;
524     setx[setNr].anz_e = 0;
525     setx[setNr].anz_f = 0;
526     setx[setNr].anz_elf = 0;
527     setx[setNr].anz_p = 0;
528     setx[setNr].anz_l = 0;
529     setx[setNr].anz_c = 0;
530     setx[setNr].anz_s = 0;
531     setx[setNr].anz_b = 0;
532     setx[setNr].anz_nurl = 0;
533     setx[setNr].anz_nurs = 0;
534     setx[setNr].anz_se = 0;
535     setx[setNr].anz_sh = 0;
536     setx[setNr].eparm=(char *)NULL;
537   }
538   else if (setNr<-1)    /* replace a deleted set */
539   {
540     setNr=-(setNr+10);
541     i=strlen(setname);
542     if((setx[setNr].name= (char *)malloc((i+1)*sizeof(char))) == NULL )
543     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
544     strcpy( setx[setNr].name, setname);
545     if ( type[1] == 's' ) setx[setNr].type=1;
546     else                  setx[setNr].type=0;
547     if((setx[setNr].valu= (int *)malloc(sizeof(int))) == NULL )
548     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
549     if((setx[setNr].node= (int *)malloc(sizeof(int))) == NULL )
550     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
551     if((setx[setNr].elem= (int *)malloc(sizeof(int))) == NULL )
552     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
553     if((setx[setNr].face= (int *)malloc(sizeof(int))) == NULL )
554     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
555     if((setx[setNr].elf= (Elfaces *)malloc(sizeof(Elfaces))) == NULL )
556     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
557     if((setx[setNr].pnt= (int *)malloc(sizeof(int))) == NULL )
558     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
559     if((setx[setNr].line= (int *)malloc(sizeof(int))) == NULL )
560     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
561     if((setx[setNr].lcmb= (int *)malloc(sizeof(int))) == NULL )
562     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
563     if((setx[setNr].surf= (int *)malloc(sizeof(int))) == NULL )
564     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
565     if((setx[setNr].body= (int *)malloc(sizeof(int))) == NULL )
566     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
567     if((setx[setNr].nurl= (int *)malloc(sizeof(int))) == NULL )
568     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
569     if((setx[setNr].nurs= (int *)malloc(sizeof(int))) == NULL )
570     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
571     if((setx[setNr].set= (int *)malloc(sizeof(int))) == NULL )
572     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
573     if((setx[setNr].shp= (int *)malloc(sizeof(int))) == NULL )
574     { printf("ERROR: malloc failed in seta()\n\n" ); return(-1); }
575     setx[setNr].index = -1;
576     setx[setNr].material = -1;
577     setx[setNr].anz_v = 0;
578     setx[setNr].anz_n = 0;
579     setx[setNr].anz_e = 0;
580     setx[setNr].anz_f = 0;
581     setx[setNr].anz_elf = 0;
582     setx[setNr].anz_p = 0;
583     setx[setNr].anz_l = 0;
584     setx[setNr].anz_c = 0;
585     setx[setNr].anz_s = 0;
586     setx[setNr].anz_b = 0;
587     setx[setNr].anz_nurl = 0;
588     setx[setNr].anz_nurs = 0;
589     setx[setNr].anz_se = 0;
590     setx[setNr].anz_sh = 0;
591     setx[setNr].eparm=(char *)NULL;
592   }
593 
594   /* determine the index of the entity */
595   if (( type[0] == 's' )&&( type[1] == 'e' ))  number=getSetNrx(name);
596   else if (( type[0] == 's' )&&( type[1] == 'h' ))  number=getShapeNr(name);
597   else if ( type[0] == 'n' )                   number=atoi(name);
598   else if ( type[0] == 'e' )                   number=atoi(name);
599   else if ( type[0] == 'f' )                   number=atoi(name);
600   else if ( type[0] == 'i' )
601   {
602     if(printFlag) printf (" set initialized\n");
603     return(setNr);
604   }
605   else
606   {
607     errMsg ("ERROR: in seta type:%s not recognized\n", type);
608     return(-1);
609   }
610 
611   /* add to the set */
612   if( setax(setNr, type, number)<0 )
613     return(-1);
614   else
615     return(setNr);
616 }
617 
618 
writeNodeVals(int anzx_l,int nd,double f,int dof)619 int writeNodeVals(int anzx_l, int nd, double f, int dof)
620 {
621   int i;
622   if (nd>anzx->nmax)
623   {
624     printf(" WARNING: found nodeNr:%d in Dataset higher than in Geometry allocated:%d\n"
625     , nd, anzx->nmax);
626     // exit(-1);
627     return(0);
628   }
629   lcasex[anzx_l].dat[dof][nd]       = f;
630 
631   /* max and min */
632   for(i=0; i<lcasex[anzx_l].ncomps; i++)
633   {
634   if(lcasex[anzx_l].dat[i][nd] > lcasex[anzx_l].max[i])
635   {
636     lcasex[anzx_l].max[i]=lcasex[anzx_l].dat[i][nd];
637     lcasex[anzx_l].nmax[i]=nd;
638   }
639   if(lcasex[anzx_l].dat[i][nd] < lcasex[anzx_l].min[i])
640   {
641     lcasex[anzx_l].min[i]=lcasex[anzx_l].dat[i][nd];
642     lcasex[anzx_l].nmin[i]=nd;
643   }
644   }
645   return(1);
646 }
647 
648 
649 
getBoundaries(char * rec_str)650 int getBoundaries(char *rec_str)
651 {
652   int i,j,n;
653   int args, nset;
654   int ival[80], dof;
655   double f;
656   static int setNr[7]={0,0,0,0,0,0,0};
657   static int local_step_nr=0, anzx_l;
658 
659   /* reset all static variables */
660   if(resetFlag)
661   {
662     for(i=0; i<7; i++) setNr[i]=0;
663     local_step_nr=0;
664     anzx_l=0;
665     return(0);
666   }
667 
668   if(printFlag) printf("%s\n",rec_str);
669   /* scan the properties and write to file */
670 
671   /* create a dataset if a new step beginns */
672   if(step_nr>local_step_nr)
673   {
674     local_step_nr=step_nr;
675     /* ini lcasex */
676     sprintf( lcasex[anzx->l].name,"%s", BOU);
677     printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
678     lcasex[anzx->l].value=0;
679     lcasex[anzx->l].ncomps=7;
680     lcasex[anzx->l].irtype=1;
681     lcasex[anzx->l].npheader=0;
682 
683     strcpy(lcasex[anzx->l].analysis_name,"");
684     sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
685     strcpy(lcasex[anzx->l].dataset_text,"");
686     lcasex[anzx->l].step_number=step_nr;
687     lcasex[anzx->l].analysis_type=1;
688 
689     if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
690       printf("\n\n ERROR: malloc failure\n\n" );
691     if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
692       printf("\n\n ERROR: malloc failure\n\n" );
693     if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
694       printf("\n\n ERROR: malloc failure\n\n" );
695     if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
696       printf("\n\n ERROR: malloc failure\n\n" );
697     if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
698       printf("\n\n ERROR: malloc failure\n\n" );
699     if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
700       printf("\n\n ERROR: malloc failure\n\n" );
701     if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
702       printf("\n\n ERROR: malloc failure\n\n" );
703     if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
704       printf("\n\n ERROR: malloc failure\n\n" );
705     if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
706       printf("\n\n ERROR: malloc failure\n\n" );
707     if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
708       printf("\n\n ERROR: malloc failure\n\n" );
709     if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
710       printf("\n\n ERROR: malloc failure\n\n" );
711     if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
712       printf("\n\n ERROR: malloc failure\n\n" );
713 
714     for(i=0; i<lcasex[anzx->l].ncomps; i++)
715     {
716       if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
717         printf("\n\n ERROR: malloc failure\n\n" );
718       if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
719         printf("\n\n ERROR: malloc failed\n\n" );
720       if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
721         printf("\n\n ERROR: malloc failed\n\n" );
722       lcasex[anzx->l].max[i]=-MAX_FLOAT;
723       lcasex[anzx->l].min[i]=MAX_FLOAT;
724 
725       lcasex[anzx->l].menu[i] = 1;
726       lcasex[anzx->l].ictype[i] = 1;
727       lcasex[anzx->l].icind1[i] = i+1;
728       lcasex[anzx->l].icind2[i] = 0;
729       lcasex[anzx->l].iexist[i] = 0;
730       if(i==0) sprintf( lcasex[anzx->l].compName[i], "bou11");
731       else sprintf( lcasex[anzx->l].compName[i], "bou%d",i);
732     }
733 
734     anzx_l=anzx->l;
735 
736     anzx->l++;
737     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
738     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
739   }
740 
741   do{
742     i=abqrecord(rec_str);
743     if(i==-1) return(-1);
744     if(i==-2) break;
745 
746     /* get the arguments of the string */
747     args=crecord(rec_str, dat);
748 
749     /* screen dump */
750     if(printFlag)
751     {
752       for(i=0; i<args; i++) printf("%s ",dat[i]);
753       printf(" (%d)\n",i);
754     }
755 
756     /* extract node, dofs, disp */
757     for(i=0; i<80; i++) ival[i]=0;
758     for(i=0; i<args; i++) ival[i]=atoi(dat[i]);
759     if(args>3) f=atof(dat[3]); else f=0.;
760 
761     /* write to file */
762     if(ival[2]<ival[1]) ival[2]=ival[1];
763 
764     for(i=ival[1]; i<=ival[2]; i++)
765     {
766       /* if the nodes are stored in a set */
767       if(ival[0]<1)
768       {
769         nset=getSetNrx(dat[0]);
770         if(nset<0)
771         {
772           printf("ERROR: In *BOUNDARY set:%s not defined\n",dat[0]);
773           return(-1);
774         }
775         for(j=0; j<setx[nset].anz_n; j++)
776         {
777           if(!setNr[0])
778           {
779             setNr[0]=pre_setax( BOU, "i", 0);
780           }
781           if(!setNr[i])
782           {
783             sprintf(buffer, "%s%d", BOU,i);
784             setNr[i]=pre_setax( buffer, "i", 0);
785           }
786           setax(setNr[0], "n", setx[nset].node[j]);
787           setax(setNr[i], "n", setx[nset].node[j]);
788           if(step_nr>0)
789 	  {
790             dof=-1;
791             if(i<7) dof=i;
792             else if(i==11) dof=0;
793 	    if(dof>-1) writeNodeVals(anzx_l, setx[nset].node[j], lcasex[anzx_l].dat[dof][setx[nset].node[j]]+f, dof);
794 	  }
795           if(ansFlag)
796           {
797             /* write in ansys-format */
798             if ((i<1)||(i>6)) errMsg ("ERROR dof:%d not known\n", i);
799             else fprintf(handleans, "D,%d, %s, 0.  \n", setx[nset].node[j], ansys_dof[i-1]);
800           }
801         }
802       }
803       else
804       {
805         if(!setNr[0])
806         {
807           setNr[0]=pre_setax( BOU, "i", 0);
808         }
809         if(!setNr[i])
810         {
811           sprintf(buffer, "%s%d", BOU,i);
812           setNr[i]=pre_setax( buffer, "i", 0);
813         }
814         setax(setNr[0], "n", ival[0]);
815         setax(setNr[i], "n", ival[0]);
816         if(step_nr>0)
817 	{
818           dof=-1;
819           if(i<7) dof=i;
820           else if(i==11) dof=0;
821 	  if(dof>-1) writeNodeVals(anzx_l, ival[0], lcasex[anzx_l].dat[dof][ival[0]]+f, dof);
822 	}
823         if(copyFlag)
824         {
825           /* write to equ-file */
826 	  for (n=0; n<SEGMENTS; n++) {printf( "%d,%d, ,\n", ival[0]+(n*NODE_OFFSET), i);
827             fprintf(handle_equ, "%d,%d, ,\n", ival[0]+(n*NODE_OFFSET), i); }
828         }
829         if(ansFlag)
830         {
831           /* write in ansys-format */
832           if ((i<1)||(i>6)) errMsg ("ERROR dof:%d not known\n", i);
833           else fprintf(handleans, "D,%d, %s, 0.  \n", ival[0], ansys_dof[i-1]);
834         }
835       }
836     }
837   }while(1);
838   return(1);
839 }
840 
841 
getEquations(char * rec_str)842 int getEquations(char *rec_str)
843 {
844   int i,ii,n, neq;
845   int args;
846   int   nd[80], dof[80];
847   double val[80];
848   static int neqn=0;
849   static int setDep[80], setInd[80];
850   int transdep=-1, transind=-1;
851   static int elem=1;
852 
853   /* reset all static variables */
854   if(resetFlag)
855   {
856     neqn=0;
857     for(i=0; i<80; i++) setDep[i]=setInd[i]=0;
858     return(0);
859   }
860 
861   if(printFlag) printf("*EQUATION:\n");
862   if(strstr(rec_str, ",")!=NULL) { abqrecord(rec_str); return(0); }
863   do
864   {
865     i=abqrecord(rec_str);
866     if(i==-1) return(-1);
867     if(i==-2) break;
868 
869     /* get the number of terms */
870     neq=atoi(rec_str);
871     n=0;
872     do
873     {
874       /* get the terms */
875       i=abqrecord(rec_str);
876       if(i==-1) return(-1);
877       if(i==-2) break;
878 
879       args=crecord(rec_str, dat);
880 
881       /* ignore trailing comma */
882       args=(int)(args/3)*3;
883       /* extract node, dof, weight of each term */
884       for(i=0; i<args; i+=3)
885       {
886         if(printFlag) printf("eq:%d %s %s %s\n", n, dat[i],dat[i+1],dat[i+2]);
887         nd[n]  = atoi(dat[i]);
888         dof[n] = atoi(dat[i+1]);
889         val[n] = atof(dat[i+2]);
890         n++;
891       }
892     }while(n<neq);
893 
894     /* write sets */
895     if(!setDep[0]) { setDep[0]=pre_setax( DEP, "i", 0);  }
896     if(!setInd[0]) { setInd[0]=pre_setax( IND, "i", 0);  }
897 
898     for(i=0; i<neq; i++)
899     {
900       if(!i)
901       {
902         if(!setDep[dof[0]])
903         {
904           sprintf(buffer, "%s%d", DEP,dof[0]);
905           setDep[dof[0]]=pre_setax( buffer, "i", 0);
906         }
907         setax(setDep[0], "n", nd[0]);
908         setax(setDep[dof[0]], "n", nd[0]);
909 
910         /* look if the nodes belong to a certain transformation */
911         for(ii=anzx->sets-1; ii>-1; ii--)
912         {
913           if((setx[ii].name!=NULL)&&(compare(setx[ii].name, "+trans",6)==6))
914           {
915             if( getIndex(&setx[ii].node,setx[ii].anz_n,nd[0]) >-1)
916             {
917   	    //printf("n:%d\n", nd[0]);
918               transdep=ii;
919               break;
920             }
921           }
922         }
923       }
924       else
925       {
926         /* look if the node belongs to the same transformation as the dep-node */
927         for(ii=anzx->sets-1; ii>-1; ii--)
928         {
929           if((setx[ii].name!=NULL)&&(compare(setx[ii].name, "+trans",6)==6))
930           {
931             if( getIndex(&setx[ii].node,setx[ii].anz_n,nd[i]) >-1)
932             {
933   	    //printf("n:%d\n", nd[i]);
934               transind=ii;
935               break;
936             }
937           }
938         }
939         if(transdep!=transind)
940 	{
941            printf(" Warning: dep-node %d", nd[0]);
942 	   if(transdep>-1)  printf(" belongs to %s", setx[transdep].name);
943 	   else  printf(" belongs to basic system");
944            printf(" were ind-node %d", nd[i]);
945 	   if(transind>-1)  printf(" belongs to %s\n", setx[transind].name);
946 	   else  printf(" belongs to basic system\n");
947 	}
948         if(!setInd[dof[i]])
949         {
950           sprintf(buffer, "%s%d", IND,dof[i]);
951           setInd[dof[i]]=pre_setax( buffer, "i", 0);
952         }
953         setax(setInd[0], "n", nd[i]);
954         setax(setInd[dof[i]], "n", nd[i]);
955         if(printFlag) printf("elem %d %d %d be2\n", elem++, nd[0], nd[i] );
956       }
957     }
958 
959     if(copyFlag)
960     {
961       /* write to equ-file */
962       for (n=0; n<SEGMENTS; n++)
963       {
964         fprintf(handle_equ, "*EQUATION\n");
965         fprintf(handle_equ, "%d\n", neq);
966         for (i=0;i<neq;i++)
967           fprintf(handle_equ, "%d,%d,%.12lf\n", nd[i]+(n*NODE_OFFSET), dof[i], val[i]);
968       }
969     }
970     if(ansFlag)
971     {
972       /* write to ans-file */
973       neqn++;
974       for (i=0;i<neq;i++)
975         fprintf(handleans, "CE,%d,0,%d,%s,%8.5f\n", neqn, nd[i], ansys_dof[dof[i]-1], val[i]);
976     }
977   }while(1);
978   return(1);
979 }
980 
981 
getEquationf(char * rec_str)982 int getEquationf(char *rec_str)
983 {
984   int i,j,n;
985   int args, neq;
986   int   el[80],face[80], dof[80];
987   double val[80];
988   static int setDep[80], setInd[80];
989 
990   /* reset all static variables */
991   if(resetFlag)
992   {
993     for(i=0; i<80; i++) setDep[i]=setInd[i]=0;
994     return(0);
995   }
996 
997   if(printFlag) printf("*EQUATIONF:\n");
998   do
999   {
1000     i=abqrecord(rec_str);
1001     if(i==-1) return(-1);
1002     if(i==-2) break;
1003 
1004     /* get the number of terms */
1005     neq=atoi(rec_str);
1006     n=0;
1007     do
1008     {
1009       /* get the terms */
1010       i=abqrecord(rec_str);
1011       if(i==-1) return(-1);
1012       if(i==-2) break;
1013 
1014       args=crecord(rec_str, dat);
1015 
1016       /* ignore trailing comma */
1017       args=(int)(args/4)*4;
1018       /* extract elem,face, dof, weight of each term */
1019       for(i=0; i<args; i+=4)
1020       {
1021         if(printFlag)
1022           printf("eq:%d %s %s %s %s\n", n, dat[i],dat[i+1],dat[i+2],dat[i+3]);
1023         el[n]  = atoi(dat[i]);
1024         face[n]  = (int)atoi(&dat[i+1][1])-1;
1025         dof[n] = atoi(dat[i+2]);
1026         val[n] = atof(dat[i+3]);
1027         if(printFlag)
1028           printf(" %d %d %d %f\n",el[n],face[n],dof[n],val[n] );
1029         n++;
1030       }
1031     }while(n<neq);
1032 
1033     /* write sets */
1034     if(!setDep[0]) { setDep[0]=pre_setax( DEP, "i", 0);  }
1035     if(!setInd[0]) { setInd[0]=pre_setax( IND, "i", 0);  }
1036 
1037     for(i=0; i<neq; i++)
1038     {
1039       if((e_enqirex[el[i]].type>6)&&(e_enqirex[el[i]].type<11))
1040       {
1041         if(e_enqirex[el[i]].attr>3)
1042         {
1043           if(e_enqirex[el[i]].type<9)
1044           {
1045             if(face[i]<0) { if(dat[1][1]=='N') face[i]=4; else face[i]=5; }
1046             else face[i]+=1;
1047           }
1048           else
1049           {
1050             if(face[i]<0) { if(dat[1][1]=='N') face[i]=5; else face[i]=6; }
1051             else face[i]+=1;
1052           }
1053         }
1054         else
1055         {
1056           if(face[i]>1) face[i]+=1; else { if(dat[1][1]=='N') face[i]=0; else face[i]=1; }
1057         }
1058       }
1059 
1060       if(printFlag)
1061         printf(" %d %d %d %f\n",el[i],face[i],dof[i],val[i] );
1062       if(!i)
1063       {
1064         if(!setDep[dof[0]])
1065         {
1066           sprintf(buffer, "%s%d", DEP,dof[0]);
1067           setDep[dof[0]]=pre_setax( buffer, "i", 0);
1068         }
1069         //setax(setDep[0], "e", el[0]);
1070         //setax(setDep[dof[0]], "e", el[0]);
1071         j=setax(setDep[0],"j",0);
1072         if(j>-1)
1073 	{
1074           setx[setDep[0]].elf[j].e=el[0];
1075           setx[setDep[0]].elf[j].f=face[0];
1076         }
1077         j=setax(setDep[dof[0]],"j",0);
1078         if(j>-1)
1079 	{
1080           setx[setDep[dof[0]]].elf[j].e=el[0];
1081           setx[setDep[dof[0]]].elf[j].f=face[0];
1082         }
1083       }
1084       else
1085       {
1086         if(!setInd[dof[i]])
1087         {
1088           sprintf(buffer, "%s%d", IND,dof[i]);
1089           setInd[dof[i]]=pre_setax( buffer, "i", 0);
1090         }
1091         //setax(setInd[0], "e", el[i]);
1092         //setax(setInd[dof[i]], "e", el[i]);
1093         j=setax(setInd[0],"j",0);
1094         if(j>-1)
1095 	{
1096           setx[setInd[0]].elf[j].e=el[i];
1097           setx[setInd[0]].elf[j].f=face[i];
1098         }
1099         j=setax(setInd[dof[i]],"j",0);
1100         if(j>-1)
1101 	{
1102           setx[setInd[dof[i]]].elf[j].e=el[i];
1103           setx[setInd[dof[i]]].elf[j].f=face[i];
1104         }
1105       }
1106     }
1107   }while(1);
1108   return(1);
1109 }
1110 
1111 
1112 
getContactPair(char * rec_str)1113 int getContactPair(char *rec_str)
1114 {
1115   int i,f,args, length;
1116   int setdep, setind;
1117   static int setMasCont, setSlavCont, setMasTie, setSlavTie, setMasTieCyc, setSlavTieCyc, setMasTieMult, setSlavTieMult;
1118   int setMas=0, setSlav=0;
1119 
1120   /* reset all static variables */
1121   if(resetFlag)
1122   {
1123     setMasTieCyc=setSlavTieCyc=setMasTieMult=setSlavTieMult=setMasTie=setSlavTie=setMasCont=setSlavCont=0;
1124     return(0);
1125   }
1126 
1127   /* get the arguments of the string */
1128   args=crecord(rec_str, dat);
1129 
1130   /* toupper */
1131   i=0; while(dat[0][i]!='\0') { dat[0][i]=toupper(dat[0][i]); i++; }
1132 
1133   if(compare(dat[0], "*TIE",4)==4)
1134   {
1135     for(i=1; i<args; i++)
1136     {
1137       if(compare(dat[i], "CYCLIC",6)==6)
1138       {
1139         if(!setMasTieCyc)  { setMasTieCyc =pre_setax( TIECYC2, "i", 0);  }
1140         if(!setSlavTieCyc) { setSlavTieCyc=pre_setax( TIECYC1, "i", 0);  }
1141         setMas=setMasTieCyc;
1142         setSlav=setSlavTieCyc;
1143       }
1144       else if(compare(dat[i], "MULTISTAGE",6)==6)
1145       {
1146         if(!setMasTieMult)  { setMasTieMult =pre_setax( TIEMUL2, "i", 0);  }
1147         if(!setSlavTieMult) { setSlavTieMult=pre_setax( TIEMUL1, "i", 0);  }
1148         setMas=setMasTieMult;
1149         setSlav=setSlavTieMult;
1150       }
1151     }
1152     if(setMas==0)
1153     {
1154       if(!setMasTie)  { setMasTie =pre_setax( TIE2, "i", 0);  }
1155       if(!setSlavTie) { setSlavTie=pre_setax( TIE1, "i", 0);  }
1156       setMas=setMasTie;
1157       setSlav=setSlavTie;
1158     }
1159   }
1160   else //if (compare(dat[0], "*CONTACTPAIR",11)==11)
1161   {
1162     if(!setMasCont)  { setMasCont =pre_setax( CONT2, "i", 0);  }
1163     if(!setSlavCont) { setSlavCont=pre_setax( CONT1, "i", 0);  }
1164     setMas=setMasCont;
1165     setSlav=setSlavCont;
1166   }
1167 
1168   do{
1169   /* get the arguments of the 2nd line */
1170   length=abqrecord(rec_str);
1171   if(length==-1) return(-1);
1172   if(length==-2) break;
1173   args=crecord(rec_str, dat);
1174   if(args!=2)
1175   {
1176     printf("ERROR: In *CONTACT PAIR 2nd line:%s \n", rec_str);
1177     return(-1);
1178   }
1179 
1180   setdep=getSetNrx(dat[0]);
1181   if(setdep<0)
1182   {
1183     printf("ERROR: In *CONTACT PAIR set:%s not defined\n", dat[0]);
1184     return(-1);
1185   }
1186   setind=getSetNrx(dat[1]);
1187   if(setind<0)
1188   {
1189     printf("ERROR: In *CONTACT PAIR set:%s not defined\n", dat[0]);
1190     return(-1);
1191   }
1192 
1193   /* relate both contact sets */
1194   setax(setdep,"r", setind);
1195   setax(setind,"r", setdep);
1196 
1197   /* store both in contact sets (master &slave) */
1198   for( i=0; i<setx[setind].anz_n; i++ ) setax(setMas, "n", setx[setind].node[i]);
1199   for( i=0; i<setx[setind].anz_elf; i++ )
1200   {
1201     f=setax(setMas,"j",0);
1202     if(f>-1)
1203     {
1204       setx[setMas].elf[f].e=setx[setind].elf[i].e;
1205       setx[setMas].elf[f].f=setx[setind].elf[i].f;
1206     }
1207   }
1208   for( i=0; i<setx[setdep].anz_n; i++ ) setax(setSlav, "n",setx[setdep].node[i] );
1209   for( i=0; i<setx[setdep].anz_elf; i++ )
1210   {
1211     f=setax(setSlav,"j",0);
1212     if(f>-1)
1213     {
1214       setx[setSlav].elf[f].e=setx[setdep].elf[i].e;
1215       setx[setSlav].elf[f].f=setx[setdep].elf[i].f;
1216     }
1217   }
1218   }while(1);
1219   return(1);
1220 }
1221 
1222 
1223 
getSurfaces(char * rec_str)1224 int getSurfaces(char *rec_str)
1225 {
1226   int i,j,n,args, length, el, eset;
1227   char name[MAX_LINE_LENGTH], type[MAX_LINE_LENGTH];
1228   int setNr, face, facei;
1229 
1230   /* defaults */
1231   strcpy(type, "ELEM");
1232 
1233   /* get the arguments of the string */
1234   args=crecord(rec_str, dat);
1235 
1236   /* extract the setname */
1237   sprintf(name, "+sur");
1238   for(i=0; i<args; i++)
1239   {
1240     /* delete blanks */
1241     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
1242     buffer[n]='\0';
1243     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
1244     if(compare(dat[i],"NAME=",5)==5) { strcpy(name,&buffer[5]); }
1245     if(compare(dat[i],"TYPE=",5)==5) { strcpy(type,&dat[i][5]); }
1246   }
1247   if(compareStrings(dat[0], "*SURFACE")<1)
1248   {
1249     printf(" ignore statement: %s\n", dat[0]);
1250     length=abqrecord(rec_str);
1251     return(1);
1252   }
1253   if(printFlag) printf("*SURFACE, NAME=%s, TYPE=%s\n", name, type);
1254 
1255   setNr=getSetNrx(name);
1256   if(setNr<0) setNr=pre_setax( name, "i", 0);
1257 
1258   /* store setNr, element and face for later use in cgx */
1259   if(compare( type, "NODE", 4)==4)
1260   {
1261     do{
1262       length=abqrecord(rec_str);
1263       if(length==-1) return(-1);
1264       if(length==-2) break;
1265 
1266       args=crecord(rec_str, dat);
1267       el=atoi(dat[0]);
1268 
1269       /* check if the node-number is 0, then an eset is defined */
1270       if (el==0)
1271       {
1272         eset=getSetNrx(dat[0]);
1273         if(eset<0)
1274         {
1275           printf("ERROR: In *SURFACE set:%s not defined\n", dat[0]);
1276           return(-1);
1277         }
1278         for(j=0; j<setx[eset].anz_n; j++) setax(setNr, "n", setx[eset].node[j]);
1279       }
1280       else setax(setNr, "n", el);
1281     }while(1);
1282   }
1283   else if(compare( type, "ELEM", 4)==4)
1284   {
1285     do{
1286       length=abqrecord(rec_str);
1287       if(length==-1) return(-1);
1288       if(length==-2) break;
1289 
1290       args=crecord(rec_str, dat);
1291       el=atoi(dat[0]);
1292       face=(int)atoi(&dat[1][1])-1;
1293 
1294       // printf("el:%d f:%d\n", el, face);
1295       if(face>=-1)
1296       {
1297         /* check if the element-number is 0, then an eset is defined */
1298         if (el==0)
1299         {
1300           eset=getSetNrx(dat[0]);
1301           if(eset<0)
1302           {
1303             printf("ERROR: In *SURFACE set:%s not defined\n", dat[0]);
1304             return(-1);
1305           }
1306           for(j=0; j<setx[eset].anz_e; j++)
1307           {
1308 	    facei=face;
1309 	    el=setx[eset].elem[j];
1310             if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
1311             {
1312               if(e_enqirex[el].attr>3)
1313               {
1314                 if(e_enqirex[el].type<9)
1315                 {
1316                   if(facei<0) { if(dat[1][1]=='N') facei=4; else facei=5; }
1317                   else facei+=1;
1318                 }
1319                 else
1320                 {
1321                   if(facei<0) { if(dat[1][1]=='N') facei=5; else facei=6; }
1322                   else facei+=1;
1323                 }
1324               }
1325               else
1326               {
1327                 if(facei>1) facei+=1; else { if(dat[1][1]=='N') facei=0; else facei=1; }
1328               }
1329             }
1330 	    //	printf("el:%d f:%d\n", el, facei);
1331             i=setax(setNr,"j",0);
1332             if(i>-1)
1333 	    {
1334               setx[setNr].elf[i].e=el;
1335               setx[setNr].elf[i].f=facei;
1336 	    }
1337           }
1338         }
1339         else
1340         {
1341           if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
1342           {
1343             if(e_enqirex[el].attr>3)
1344             {
1345               if(e_enqirex[el].type<9)
1346               {
1347                 if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
1348                 else face+=1;
1349               }
1350               else
1351               {
1352                 if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
1353                 else face+=1;
1354               }
1355             }
1356             else
1357             {
1358               if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
1359             }
1360           }
1361           i=setax(setNr,"j",0);
1362           if(i>-1)
1363           {
1364 	    //printf(" e:%d f:%d\n", el, face);
1365             setx[setNr].elf[i].e=el;
1366             setx[setNr].elf[i].f=face;
1367 	  }
1368         }
1369       }
1370     }while(1);
1371   }
1372   else length=abqrecord(rec_str);
1373   return(1);
1374 }
1375 
1376 
getTransform(char * rec_str)1377 int getTransform(char *rec_str)
1378 {
1379   int i,j,n,args, eset;
1380   char name[MAX_LINE_LENGTH], type[MAX_LINE_LENGTH], setname[MAX_LINE_LENGTH];
1381   int setNr;
1382 
1383   /* defaults */
1384   strcpy(type, "R");
1385 
1386   /* get the arguments of the string */
1387   args=crecord(rec_str, dat);
1388 
1389   /* extract the setname */
1390   for(i=0; i<args; i++)
1391   {
1392     /* delete blanks */
1393     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
1394     buffer[n]='\0';
1395     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
1396     if(compare(dat[i],"NSET=",5)==5) { strcpy(name,&buffer[5]); }
1397     if(compare(dat[i],"TYPE=",5)==5) { strcpy(type,&dat[i][5]); }
1398   }
1399   if(compareStrings(dat[0], "*TRANSFORM")<1)
1400   {
1401     printf(" ignore statement: %s\n", dat[0]);
1402     abqrecord(rec_str);
1403     return(1);
1404   }
1405   if(printFlag) printf("*TRANSFORM, NSET=%s, TYPE=%s\n", name, type);
1406   abqrecord(rec_str);
1407   sprintf(setname, "+trans%s%s", type, rec_str);
1408   setNr=getSetNrx(setname);
1409   if(setNr<0) setNr=pre_setax( setname, "i", 0);
1410 
1411   eset=getSetNrx(name);
1412   if(eset<0)
1413   {
1414     printf("ERROR: In *TRANSFORM set:%s not defined\n",name );
1415     return(-1);
1416   }
1417   for(j=0; j<setx[eset].anz_n; j++) setax(setNr, "n", setx[eset].node[j]);
1418   return(1);
1419 }
1420 
1421 
getNodes(char * rec_str)1422 int getNodes(char *rec_str)
1423 {
1424   int i,j,n,args,setFlag=0,setNr=0;
1425   char set[MAX_LINE_LENGTH];
1426 
1427   /* get the arguments of the string */
1428   args=crecord(rec_str, dat);
1429 
1430   /* extract the setname */
1431   sprintf(set, "NONE");
1432   for(i=0; i<args; i++)
1433   {
1434     /* delete blanks */
1435     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
1436     buffer[n]='\0';
1437     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
1438     if(compare(dat[i],"NSET=",5)==5)
1439     {
1440       if(strlen(&buffer[5])>0) {  setFlag=1; strcpy(set,&buffer[5]); }
1441     }
1442   }
1443   if(compareStrings(dat[0], "*NODE")<1)
1444   {
1445     printf(" ignore statement: %s\n", dat[0]);
1446     abqrecord(rec_str);
1447     return(1);
1448   }
1449   if(printFlag) printf("*NODE, NSET=%s\n", set);
1450 
1451   if(setFlag)
1452   {
1453     setNr=getSetNrx(set);
1454     if(setNr<0) setNr=pre_setax( set, "i", 0);
1455   }
1456   do{
1457     i=abqrecord(rec_str);
1458     if(i<0)
1459     {
1460       if(setFlag)
1461       {
1462         qsort( setx[setNr].node, setx[setNr].anz_n, sizeof(int), (void *)compareInt );
1463         /* erase multiple entities */
1464         n=0;
1465         for(j=1; j<setx[setNr].anz_n; j++)
1466         {
1467           if(setx[setNr].node[n]!=setx[setNr].node[j]) setx[setNr].node[++n]=setx[setNr].node[j];
1468         }
1469         if(setx[setNr].anz_n) setx[setNr].anz_n=n+1;
1470       }
1471       if(i==-1) return(-1);
1472       if(i==-2) break;
1473     }
1474     /* sscanf is faster (problem: between number and , is no space allowed) */
1475     //args=sscanf ( rec_str, "%d,%lf,%lf,%lf", &n, &x,&y,&z);
1476     dat[1][0]=dat[2][0]=dat[3][0]=0;
1477     args=crecord(rec_str, dat);
1478     n=atoi(dat[0]);
1479     if (n>=node_field_size)
1480     {
1481       if(n<MAX_INTEGER/2) node_field_size=n*2+1; else node_field_size=MAX_INTEGER-2;
1482       do
1483       {
1484         if ( (nodex = (Nodes *)realloc( (Nodes *)nodex, (node_field_size+1) * sizeof(Nodes))) == NULL )
1485         {
1486           printf("WARNING: INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
1487           node_field_size=n+(node_field_size-n)/2;
1488         }
1489         if(node_field_size<=n)
1490         {
1491           printf("\n\n ERROR: not enough memory in readccx()\n\n");
1492           exit(-1);
1493         }
1494       }while(!nodex);
1495       for(j=anzx->nmax+1; j<=node_field_size; j++) nodex[j].indx=-1;
1496     }
1497     /* check if that node is already existent */
1498     /*
1499     nodex[n].nx=x;
1500     nodex[n].ny=y;
1501     nodex[n].nz=z;
1502     */
1503 
1504     nodex[n].nx=atof(dat[1]);
1505     nodex[n].ny=atof(dat[2]);
1506     nodex[n].nz=atof(dat[3]);
1507 
1508     if(nodex[n].indx<0)
1509     {
1510       nodex[anzx->n].nr=n;
1511       nodex[n].indx=anzx->n;
1512       if (n >  anzx->nmax)  anzx->nmax=n;
1513       if (n <  anzx->nmin)  anzx->nmin=n;
1514       if(setFlag)
1515       {
1516         //setax(setNr, "n" ,n);
1517         if ( (setx[setNr].node = (int *)realloc((int *)setx[setNr].node, (setx[setNr].anz_n+1) * sizeof(int))) == NULL )
1518           printf(" ERROR: malloc failed in set[%d]:%s\n\n", setNr, setx[setNr].name);
1519         setx[setNr].node[setx[setNr].anz_n]= n;
1520         setx[setNr].anz_n++;
1521       }
1522       anzx->n++;
1523     }
1524 #if TEST
1525     printf("node: %d xyz: %lf %lf %lf\n", n, nodex[n].nx,nodex[n].ny,nodex[n].nz);
1526 #endif
1527     if(ansFlag)
1528     {
1529       /* write in ansys */
1530       fprintf(handleans, "N,%d,%12.5e,%12.5e,%12.5e,0,0,0\n", n, nodex[n].nx, nodex[n].ny, nodex[n].nz );
1531     }
1532 
1533   }while(1);
1534   return(1);
1535 }
1536 
1537 
getMpc(char * rec_str)1538 int getMpc(char *rec_str)
1539 {
1540   int i,n,args,setNr=0, length;
1541 
1542   setNr=getSetNrx(MPC);
1543   if(setNr<0) setNr=pre_setax( MPC, "i", 0);
1544 
1545   /* get the arguments of the string */
1546   /* args=crecord(rec_str, dat);     */
1547 
1548   /* scan the node-names and write to file */
1549   do
1550   {
1551     length=abqrecord(rec_str);
1552 
1553     if(length==-1) return(-1);
1554     if(length==-2) break;
1555     args=crecord(rec_str, dat);
1556 
1557     for(i=1; i<args; i++)
1558     {
1559       /* write in list format */
1560       n=atoi(dat[i]);
1561       if(n) setax( setNr, "n", n);
1562     }
1563   }while(1);
1564   return(1);
1565 }
1566 
1567 
1568 
writeElem(int e,int t,int g,int m,int * nd,int attr)1569 int writeElem(int e, int t, int g, int m, int *nd, int attr)
1570 {
1571   register int i;
1572   int ipuf=0,ipuf2=0;
1573   int prev_emax;
1574 
1575   prev_emax=anzx->emax;
1576   if (anzx->e>=elem_field_size)
1577   {
1578     if(anzx->e<MAX_INTEGER/2) elem_field_size=anzx->e*2+1; else elem_field_size=MAX_INTEGER-2;
1579     do
1580     {
1581       if((elemx = (Elements *)realloc( (Elements *)elemx, (elem_field_size+1) * sizeof(Elements))) == NULL )
1582       {
1583         printf("WARNING: INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size);
1584         elem_field_size=anzx->e+(elem_field_size-anzx->e)/2;
1585       }
1586       if(elem_field_size<=anzx->e)
1587       {
1588         printf("\n\n ERROR: not enough memory in readccx()\n\n");
1589         exit(-1);
1590       }
1591     }while(!elemx);
1592   }
1593 
1594   elemx[anzx->e].nr   = e;
1595   if (elemx[anzx->e].nr >  anzx->emax)  anzx->emax=elemx[anzx->e].nr;
1596   if (elemx[anzx->e].nr <  anzx->emin)  anzx->emin=elemx[anzx->e].nr;
1597 
1598   elemx[anzx->e].type = t;
1599   elemx[anzx->e].group= g;
1600   elemx[anzx->e].mat  = m;
1601   if(toupper(attr)=='R') elemx[anzx->e].attr  = 1;
1602   else if(toupper(attr)=='I') elemx[anzx->e].attr  = 2;
1603   else if(toupper(attr)=='D') elemx[anzx->e].attr  = 3;
1604   else if(toupper(attr)=='E') elemx[anzx->e].attr  = 4;
1605   else if(toupper(attr)=='S') elemx[anzx->e].attr  = 5;
1606   else if(toupper(attr)=='C') elemx[anzx->e].attr  = 6;
1607   else if(toupper(attr)=='F') elemx[anzx->e].attr  = 7;
1608   else if(toupper(attr)=='M') elemx[anzx->e].attr  = 8;
1609   else if(toupper(attr)=='T') elemx[anzx->e].attr  = 9;
1610   else elemx[anzx->e].attr  = 0;
1611 
1612   switch(elemx[anzx->e].type)
1613   {
1614     case 1:
1615       ipuf = 8;       /* HEXA8 */
1616     break;
1617     case 2:
1618       ipuf = 6;  /* PENTA6 */
1619     break;
1620     case 3:
1621       ipuf = 4;  /* TET4 */
1622     break;
1623     case 4:
1624       ipuf = 20; /* HEXA20 */
1625     break;
1626     case 5:
1627       ipuf = 15; /* PENTA15 */
1628     break;
1629     case 6:
1630       ipuf = 10; /* TET10 */
1631     break;
1632     case 7:
1633       ipuf = 3;  /* TRI3  */
1634     break;
1635     case 8:
1636       ipuf = 6;  /* TRI6  */
1637     break;
1638     case 9:
1639       ipuf = 4;  /* QUAD4 */
1640     break;
1641     case 10:
1642       ipuf = 8; /* QUAD8 */
1643     break;
1644     case 11:
1645       ipuf = 2; /* BEAM */
1646     break;
1647     case 12:
1648       ipuf = 3; /* BEAM3 */
1649     break;
1650   }
1651   if (ipuf==0)
1652   {
1653     printf (" elem(%d) not a known type (%d)\n", elemx[anzx->e].nr, elemx[anzx->e].type);
1654   }
1655   else
1656   {
1657     anzx->etype[elemx[anzx->e].type]++;
1658     for (i=0; i<ipuf; i++) { elemx[anzx->e].nod[i] = nd[i];  }
1659 
1660     /* set the midside nodenr to 0 */
1661     if (elemx[anzx->e].type == 4) ipuf2 = 26; /* HEX20 */
1662     else if (elemx[anzx->e].type == 5) ipuf2 = 20; /* PENTA15 */
1663     else if (elemx[anzx->e].type == 10) ipuf2 = 9; /* QUAD8 */
1664     if (ipuf2!=0) for (i=ipuf; i<ipuf2; i++)
1665     {
1666       elemx[anzx->e].nod[i]=0;
1667     }
1668   }
1669 
1670   /* ini e_enqire-feld in dem e_enqire[elem[i].nr].xx abgelegt ist, statt elem[i].xx  */
1671   if (e>=elem_field_size2)
1672   {
1673     if(e<MAX_INTEGER/2) elem_field_size2=e*2+1; else elem_field_size2=MAX_INTEGER-2;
1674     do
1675     {
1676       if((e_enqirex=(Elements *)realloc((Elements *)e_enqirex,(elem_field_size2+1)*sizeof(Elements)))==NULL)
1677       {
1678         printf("WARNING: INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size);
1679         elem_field_size2=e+(elem_field_size2-e)/2;
1680       }
1681       if(elem_field_size2<=e)
1682       {
1683         printf("\n\n ERROR: not enough memory in readccx()\n\n");
1684         exit(-1);
1685       }
1686     }while(!e_enqirex);
1687   }
1688 
1689   if(anzx->e>anzx->emax)
1690   {
1691     printf("ERROR: found more elements:%d than the maximum number:%d\n probably elements are redefined. This is not permitted.\n", anzx->e,anzx->emax );
1692     exit(-1);
1693   }
1694   for(i=prev_emax+1; i<e; i++) { e_enqirex[i].type=0; }
1695   e_enqirex[ e ].type    = t;
1696   e_enqirex[ e ].group   = g;
1697   e_enqirex[ e ].mat     = m;
1698   e_enqirex[ e ].attr     = elemx[anzx->e].attr;
1699   for (i=0; i<ipuf; i++)
1700   {
1701     e_enqirex[ e ].nod[i]=nd[i];
1702   }
1703   anzx->e++;
1704   return(1);
1705 }
1706 
1707 
writeElemAns(int mat,int * selected_elems,Summen * ans,Nodes * nodex,Elements * elemx)1708 int writeElemAns(int mat, int *selected_elems, Summen *ans, Nodes *nodex, Elements *elemx)
1709 {
1710   int i,j;
1711   static int type=0, anz_e=0;
1712   int el, nd[20];
1713 
1714   /* reset all static variables */
1715   if(resetFlag)
1716   {
1717     type=anz_e=0;
1718     return(0);
1719   }
1720 
1721   for(i=0; i<anzx->e; i++) if(selected_elems[elemx[i].nr])
1722   {
1723 
1724     el=elemx[i].nr;
1725     for(j=0; j<20; j++) nd[j]=elemx[i].nod[j];
1726 
1727     if(elemx[i].type==1)
1728     {
1729       if (((anz_e>0)&&(type != 1))||(anz_e==0))
1730       {
1731         fprintf (handleans, "ET, %d, 45\n", elemx[i].type);
1732         fprintf (handleans, "TYPE, %d\n", elemx[i].type);
1733       }
1734       fprintf (handleans, "EN,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d \n",el, nd[0], nd[1], nd[2], nd[3],nd[4], nd[5], nd[6], nd[7] );
1735       type=1;
1736       anz_e++;
1737     }
1738 
1739     if(elemx[i].type==4)
1740     {
1741       if (((anz_e>0)&&(type != 4))||(anz_e==0))
1742       {
1743         fprintf (handleans, "ET, %d, 95\n", elemx[i].type);
1744         fprintf (handleans, "TYPE, %d\n", elemx[i].type);
1745       }
1746       fprintf (handleans, "EN,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d \n",el, nd[0], nd[1], nd[2], nd[3],nd[4], nd[5], nd[6], nd[7] );
1747       fprintf (handleans, "EMORE,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d \n", nd[8],  nd[9], nd[10], nd[11], nd[16], nd[17], nd[18], nd[19] );
1748       fprintf (handleans, "EMORE,%8d,%8d,%8d,%8d \n", nd[12], nd[13], nd[14], nd[15] );
1749       type=4;
1750       anz_e++;
1751     }
1752 
1753     if(elemx[i].type==9)
1754     {
1755       if (((anz_e>0)&&(type != 9))||(anz_e==0))
1756       {
1757 	/* plastic shell */
1758         fprintf (handleans, "ET, %d, 43\n", elemx[i].type);
1759         fprintf (handleans, "TYPE, %d\n", elemx[i].type);
1760         /* elastic shell */
1761         /* fprintf (handleans, "ET, %d, 63\n", elem[i].type); */
1762       }
1763       fprintf (handleans, "EN,%8d,%8d,%8d,%8d,%8d \n",el, nd[0], nd[1], nd[2], nd[3] );
1764       type=9;
1765       anz_e++;
1766     }
1767 
1768     if(elemx[i].type==7)
1769     {
1770       if (((anz_e>0)&&(type != 7))||(anz_e==0))
1771       {
1772 	/* plastic shell */
1773         fprintf (handleans, "ET, %d, 43\n", elemx[i].type);
1774         /* elastic shell */
1775         /* fprintf (handleans, "ET, %d, 63\n", elem[i].type); */
1776         fprintf (handleans, "TYPE, %d\n", elemx[i].type);
1777       }
1778       fprintf (handleans, "EN,%8d,%8d,%8d,%8d,%8d \n",el, nd[0], nd[1], nd[2], nd[2] );
1779       type=7;
1780       anz_e++;
1781     }
1782 
1783     if(elemx[i].type==6)
1784     {
1785       if (((anz_e>0)&&(type != 6))||(anz_e==0))
1786       {
1787         fprintf (handleans, "ET, %d, 92\n", elemx[i].type);
1788         fprintf (handleans, "TYPE, %d\n", elemx[i].type);
1789       }
1790       fprintf (handleans, "EN,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d,%8d,\n",el, nd[0], nd[1], nd[2], nd[3],nd[4], nd[5], nd[6], nd[7]);
1791       fprintf (handleans, "EMORE,%8d,%8d \n", nd[8],  nd[9]);
1792       type=6;
1793       anz_e++;
1794     }
1795   }
1796   return(1);
1797 }
1798 
1799 
1800 
hashAmplitude(SumAsci * sumAsci,char * name,int nr)1801 int hashAmplitude( SumAsci *sumAsci, char *name, int nr)
1802 {
1803   int i=0,j=0;
1804   int sum=0;
1805 
1806   while(name[i]!='\0') { sum+=name[i]*(++j); i++;}
1807 
1808   /* check if sum is higher as the allocated value */
1809   /* else look for a free entry */
1810   if(sum>sumAsci->max_sumamp)
1811   {
1812     if ((sumAsci->anzamp=(int *)realloc( (int *)sumAsci->anzamp, (sum+1)*sizeof(int)) ) == NULL )
1813     { printf("\n\nERROR: realloc failure in hashAmplitude(), Amplitude:%s not included\n\n", name); return(-1); }
1814     if ((sumAsci->ampindx=(int **)realloc( (int **)sumAsci->ampindx, (sum+1)*sizeof(int *)) ) == NULL )
1815     { printf("\n\nERROR: realloc failure in hashAmplitude(), Amplitude:%s not included\n\n", name); return(-1); }
1816     for(i=sumAsci->max_sumamp+1; i<=sum; i++) { sumAsci->anzamp[i]=0; sumAsci->ampindx[i]=NULL; }
1817     sumAsci->max_sumamp=sum;
1818   }
1819 
1820   /* alloc of a new entry in the hash table */
1821   if ((sumAsci->ampindx[sum]
1822   =(int *)realloc( (int *)sumAsci->ampindx[sum], (sumAsci->anzamp[sum]+1)*sizeof(int)) ) == NULL )
1823   { printf("\n\nERROR: realloc failure in hashAmplitude(), pnt:%s not included\n\n", name); return(-1); }
1824 
1825   sumAsci->ampindx[sum][sumAsci->anzamp[sum]] = nr;
1826   sumAsci->anzamp[sum]++;
1827   return(sum);
1828 }
1829 
1830 
hashMaterial(SumAsci * sumAsci,char * name,int nr)1831 int hashMaterial( SumAsci *sumAsci, char *name, int nr)
1832 {
1833   int i=0,j=0;
1834   int sum=0;
1835 
1836   while(name[i]!='\0') { sum+=name[i]*(++j); i++;}
1837 
1838   /* check if sum is higher as the allocated value */
1839   /* else look for a free entry */
1840   if(sum>sumAsci->max_summat)
1841   {
1842     if ((sumAsci->anzmat=(int *)realloc( (int *)sumAsci->anzmat, (sum+1)*sizeof(int)) ) == NULL )
1843     { printf("\n\nERROR: realloc failure in hashMaterial(), Material:%s not included\n\n", name); return(-1); }
1844     if ((sumAsci->matindx=(int **)realloc( (int **)sumAsci->matindx, (sum+1)*sizeof(int *)) ) == NULL )
1845     { printf("\n\nERROR: realloc failure in hashMaterial(), Material:%s not included\n\n", name); return(-1); }
1846     for(i=sumAsci->max_summat+1; i<=sum; i++) { sumAsci->anzmat[i]=0; sumAsci->matindx[i]=NULL; }
1847     sumAsci->max_summat=sum;
1848   }
1849 
1850   /* alloc of a new entry in the hash table */
1851   if ((sumAsci->matindx[sum]
1852   =(int *)realloc( (int *)sumAsci->matindx[sum], (sumAsci->anzmat[sum]+1)*sizeof(int)) ) == NULL )
1853   { printf("\n\nERROR: realloc failure in hashMaterial(), pnt:%s not included\n\n", name); return(-1); }
1854 
1855   sumAsci->matindx[sum][sumAsci->anzmat[sum]] = nr;
1856   sumAsci->anzmat[sum]++;
1857   return(sum);
1858 }
1859 
1860 
getAmplitudeNr(char * name,int checkFlag)1861 int getAmplitudeNr(char *name, int checkFlag)
1862 {
1863   static int i, n, length,sum;
1864 
1865   i=length=sum=0;
1866 
1867   while(name[length]!='\0') { sum+=name[length++]*(++i); }
1868   if(!length) return(-1);
1869 
1870   if(sum<0)
1871   {
1872     printf ("ERROR: Illegal name:|%s| sum-ascii:%d\n", name, sum);
1873     return(-1);
1874   }
1875   if(sum<=sumAsci->max_sumamp)
1876   {
1877    for (i=0; i<sumAsci->anzamp[sum]; i++)
1878    {
1879     if(( amplitude[sumAsci->ampindx[sum][i]].name != (char *)NULL ) && (strlen(amplitude[sumAsci->ampindx[sum][i]].name) == length))
1880     {
1881       n=length-1;
1882       while(amplitude[sumAsci->ampindx[sum][i]].name[n]==name[n])
1883       {
1884         if(!n--)
1885         {
1886           return(sumAsci->ampindx[sum][i]);
1887 	}
1888       }
1889       /*
1890       printf(" name:%s nam:%s indx:%d\n"
1891       , name, amplitude[sumAsci->ampindx[sum][i]].name, sumAsci->ampindx[sum][i]);
1892       */
1893     }
1894    }
1895   }
1896 
1897   if (checkFlag) return(-1);
1898 
1899   if (anzx->amps>=amp_field_size-1)
1900   {
1901     if(anzx->amps<MAX_INTEGER/2) amp_field_size=anzx->amps*2+1; else amp_field_size=MAX_INTEGER-2;
1902     do
1903     {
1904       if ((amplitude = (Amplitudes *)realloc( (Amplitudes *)amplitude, (amp_field_size+1)*sizeof(Amplitudes)) ) == NULL )
1905       {
1906         printf("WARNING: INI_FIELD_SIZE:%d to large and is reduced\n", amp_field_size );
1907         amp_field_size=anzx->amps+(amp_field_size-anzx->amps)/2;
1908       }
1909       if(amp_field_size<=anzx->amps)
1910       {
1911         printf("\n\n ERROR: not enough memory in readccx()\n\n");
1912         exit(-1);
1913       }
1914     }while(!amplitude);
1915   }
1916   if(printFlag) printf("create amplitude[%d]:%s\n", anzx->amps, name);
1917   strcpy(amplitude[anzx->amps].name, name);
1918   hashAmplitude( sumAsci, name, anzx->amps );
1919   amplitude[anzx->amps].n=0;
1920   amplitude[anzx->amps].x=NULL;
1921   amplitude[anzx->amps].y=NULL;
1922   anzx->amps++;
1923 
1924   return(anzx->amps-1);
1925 }
1926 
1927 
getMatNr(char * name,int checkFlag)1928 int getMatNr(char *name, int checkFlag)
1929 {
1930   static int i, n, length, sum;
1931 
1932   i=length=sum=0;
1933 
1934   while(name[length]!='\0') { sum+=name[length++]*(++i); }
1935   if(!length) return(-1);
1936 
1937   if(sum<0)
1938   {
1939     printf ("ERROR: Illegal name:|%s| sum-ascii:%d\n", name, sum);
1940     return(-1);
1941   }
1942   if(sum<=sumAsci->max_summat)
1943   {
1944    for (i=0; i<sumAsci->anzmat[sum]; i++)
1945    {
1946     if(( material[sumAsci->matindx[sum][i]].name != (char *)NULL ) && (strlen(material[sumAsci->matindx[sum][i]].name) == length))
1947     {
1948       n=length-1;
1949       while(material[sumAsci->matindx[sum][i]].name[n]==name[n])
1950       {
1951         if(!n--)
1952         {
1953           return(sumAsci->matindx[sum][i]);
1954 	}
1955       }
1956       /*
1957       printf(" name:%s nam:%s indx:%d\n"
1958       , name, material[sumAsci->matindx[sum][i]].name, sumAsci->matindx[sum][i]);
1959       */
1960     }
1961    }
1962   }
1963 
1964   if (checkFlag) return(-1);
1965 
1966   if (anzx->mats>=mat_field_size-1)
1967   {
1968     if(anzx->mats<MAX_INTEGER/2) mat_field_size=anzx->mats*2+1; else mat_field_size=MAX_INTEGER-2;
1969     do
1970     {
1971       if ((material = (Materials *)realloc( (Materials *)material, (mat_field_size+1)*sizeof(Materials)) ) == NULL )
1972       {
1973         printf("WARNING: INI_FIELD_SIZE:%d to large and is reduced\n", mat_field_size );
1974         mat_field_size=anzx->mats+(mat_field_size-anzx->mats)/2;
1975       }
1976       if(mat_field_size<=anzx->mats)
1977       {
1978         printf("\n\n ERROR: not enough memory in readccx()\n\n");
1979         exit(-1);
1980       }
1981     }while(!material);
1982   }
1983   if(printFlag) printf("create material[%d]:%s\n", anzx->mats, name);
1984   strcpy(material[anzx->mats].name, name);
1985   hashMaterial( sumAsci, name, anzx->mats );
1986   material[anzx->mats].rho=-1.;
1987   material[anzx->mats].nela=0;
1988   material[anzx->mats].tela=NULL;
1989   material[anzx->mats].ela=NULL;
1990   material[anzx->mats].nue=NULL;
1991   material[anzx->mats].nexp=0;
1992   material[anzx->mats].texp=NULL;
1993   material[anzx->mats].exp=NULL;
1994   material[anzx->mats].ncon=0;
1995   material[anzx->mats].tcon=NULL;
1996   material[anzx->mats].con=NULL;
1997   material[anzx->mats].nsph=0;
1998   material[anzx->mats].tsph=NULL;
1999   material[anzx->mats].sph=NULL;
2000   material[anzx->mats].npl=0;
2001   material[anzx->mats].tpl=NULL;
2002   material[anzx->mats].spl=NULL;
2003   material[anzx->mats].epl=NULL;
2004   anzx->mats++;
2005 
2006   return(anzx->mats-1);
2007 }
2008 
2009 
getAbqElement(char * rec_str,int nn,int * el,int * nd)2010 int getAbqElement(char *rec_str, int nn, int *el, int *nd)
2011 {
2012   register int i,j,n;
2013 
2014       n=0;
2015       i=abqrecord(rec_str);
2016       if(i<0)
2017       {
2018         if(i==-1) return(-1);
2019         if(i==-2) return(-2);
2020       }
2021       i=crecord(rec_str, dat);
2022       *el=atoi(dat[0]);
2023       for(j=0; j<i-1; j++)
2024       {
2025         if(dat[j+1][0]!=0) nd[n]=atoi(dat[j+1]); else break;
2026         n++;
2027         //  printf("a j:%d n:%d nd:%d\n",j,n-1,nd[n-1]);
2028         //if(nd[n-1]==0) { n--; break; }
2029       }
2030       while(n<nn)
2031       {
2032         i=abqrecord(rec_str);
2033         if(i<0)
2034         {
2035           if(i==-1) return(-1);
2036           if(i==-2) return(-2);
2037 	}
2038         i=crecord(rec_str, dat);
2039         for(j=0; j<i; j++)
2040         {
2041           nd[n]=atoi(dat[j]);
2042           n++;
2043           // printf("b j:%d n:%d nd:%d\n",j,n-1,nd[n-1]);
2044           //if(nd[n-1]==0) { n--; break; }
2045 	}
2046       }
2047   return(1);
2048 }
2049 
2050 /* uses sscanf (problem: between number and ',' is no space allowed, if removed -> not longer faster!) */
__getAbqElement(char * rec_str,int nn,int * el,int * nd)2051 int __getAbqElement(char *rec_str, int nn, int *el, int *nd)
2052 {
2053     int i,j,n=0,args;
2054 
2055       i=abqrecord(rec_str);
2056       if(i<0)
2057       {
2058         if(i==-1) return(-1);
2059         if(i==-2) return(-2);
2060       }
2061       args=sscanf ( rec_str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", el, &nd[0], &nd[1], &nd[2], &nd[3], &nd[4], &nd[5], &nd[6], &nd[7], &nd[8], &nd[9], &nd[10], &nd[11], &nd[12], &nd[13], &nd[14]);
2062 
2063       // printf("a:%d e:%d ", args, *el);
2064 
2065       for(n=0; n<args-1; n++)
2066       {
2067 	//printf(" n[%d]:%d ",n, nd[n]);
2068         if(nd[n]==0) break;
2069       }
2070       while(n<nn)
2071       {
2072         i=abqrecord(rec_str);
2073         if(i<0)
2074         {
2075           if(i==-1) return(-1);
2076           if(i==-2) return(-2);
2077 	}
2078         args=sscanf ( rec_str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &nd[n], &nd[n+1], &nd[n+2], &nd[n+3], &nd[n+4], &nd[n+5], &nd[n+6], &nd[n+7], &nd[n+8], &nd[n+9], &nd[n+10], &nd[n+11], &nd[n+12], &nd[n+13], &nd[n+14], &nd[n+15]);
2079         for(j=0; j<args; j++)
2080         {
2081           // printf(" n[%d]:%d ",n, nd[n]);
2082           if(nd[n]==0) break;
2083           n++;
2084 	}
2085       }
2086       // printf("\n");
2087   return(1);
2088 }
2089 
2090 
2091 
2092 
2093 
getElements(char * rec_str)2094 int getElements(char *rec_str)
2095 {
2096   int i,j,n, args, setFlag=0, setNr=0;
2097   char set[MAX_LINE_LENGTH], elemtyp[MAX_LINE_LENGTH], setname[MAX_LINE_LENGTH], cbuf;
2098   int el, se, nd[40];
2099   int eattr=0;
2100 
2101   elemtyp[0]=0;
2102 
2103   /* get the arguments of the string */
2104   args=crecord(rec_str, dat);
2105 
2106   /* extract element-type and setname */
2107   for(i=0; i<args; i++)
2108   {
2109     /* delete blanks */
2110     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2111     buffer[n]='\0';
2112     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2113     if(compare(dat[i],"TYPE=",5)==5) strcpy(elemtyp,&dat[i][5]);
2114     if(compare(dat[i],"ELSET=",6)==6)
2115     {
2116       if(strlen(&buffer[6])>0) { strcpy(set,&buffer[6]); setFlag=1; }
2117     }
2118   }
2119   if(printFlag) printf("*ELEMENT, TYPE=%s ,ELSET=%s\n", elemtyp, set);
2120 
2121   /* write to file */
2122   if(setFlag)
2123   {
2124     setNr=getSetNrx(set);
2125     if(setNr<0) setNr=pre_setax( set, "i", 0);
2126   }
2127   sprintf(setname,"+%s", elemtyp);
2128 
2129   /* quickfix: conversion from fluit type into structural */
2130   if(elemtyp[0]=='F') { elemtyp[0]='C'; eattr='F'; }
2131 
2132   if(compare(elemtyp,"C3D8",4)==4)
2133   {
2134     se=pre_setax(setname, "i", 0);
2135     do{
2136       if(getAbqElement(rec_str, 8, &el, nd) <0) break;
2137 
2138       if(eattr=='F') writeElem(el, 1, 1, 1, nd, eattr );
2139       else writeElem(el, 1, 1, 1, nd, elemtyp[4]);
2140 
2141       /* write set */
2142       if(setFlag) setax( setNr, "e", el);
2143       setax( se, "e", el);
2144     }while(1);
2145   }
2146   else if(compare(elemtyp,"C3D20",5)==5)
2147   {
2148     se=pre_setax(setname, "i", 0);
2149     do{
2150       if(getAbqElement(rec_str, 20, &el, nd) <0) break;
2151       for(i=0; i<12; i++) nd[20+i]=nd[i];
2152       for(i=0; i<4; i++) nd[32+i]=nd[i+16];
2153       for(i=0; i<4; i++) nd[36+i]=nd[i+12];
2154 
2155       writeElem(el, 4, 4, 1, &nd[20], elemtyp[5]);
2156 
2157       /* write set */
2158       if(setFlag) setax( setNr, "e", el);
2159       setax( se, "e", el);
2160     }while(1);
2161   }
2162   else if(compare(elemtyp,"C3D4",4)==4)
2163   {
2164     se=pre_setax(setname, "i", 0);
2165     do{
2166       if(getAbqElement(rec_str, 4, &el, nd) <0) break;
2167 
2168       writeElem(el, 3, 3, 1, nd, elemtyp[4]);
2169 
2170       /* write set */
2171       if(setFlag) setax( setNr, "e", el);
2172       setax( se, "e", el);
2173     }while(1);
2174   }
2175   else if(compare(elemtyp,"C3D6",5)==5)
2176   {
2177     se=pre_setax(setname, "i", 0);
2178     do{
2179       if(getAbqElement(rec_str, 6, &el, nd) <0) break;
2180 
2181       writeElem(el, 2, 2, 1, nd, elemtyp[4]);
2182 
2183       /* write set */
2184       if(setFlag) setax( setNr, "e", el);
2185       setax( se, "e", el);
2186     }while(1);
2187   }
2188   else if(compare(elemtyp,"C3D10",5)==5)
2189   {
2190     se=pre_setax(setname, "i", 0);
2191     do{
2192       if(getAbqElement(rec_str, 10, &el, nd) <0) break;
2193 
2194       writeElem(el, 6, 6, 1, nd, elemtyp[5]);
2195 
2196       /* write set */
2197       if(setFlag) setax( setNr, "e", el);
2198       setax( se, "e", el);
2199     }while(1);
2200   }
2201   else if(compare(elemtyp,"C3D15",5)==5)
2202   {
2203     se=pre_setax(setname, "i", 0);
2204     do{
2205       if(getAbqElement(rec_str, 15, &el, nd) <0) break;
2206       for(i=0; i<9; i++) nd[20+i]=nd[i];
2207       for(i=0; i<3; i++) nd[29+i]=nd[i+12];
2208       for(i=0; i<3; i++) nd[32+i]=nd[i+9];
2209 
2210       writeElem(el, 5, 5, 1, &nd[20], elemtyp[5]);
2211 
2212       /* write set */
2213       if(setFlag) setax( setNr, "e", el);
2214       setax( se, "e", el);
2215     }while(1);
2216   }
2217   else if((compare(elemtyp,"DS3",3)==3)||(compare(elemtyp,"M3D3",4)==4)||
2218           (compare(elemtyp,"S3",2)==2)||(compare(elemtyp,"SFM3D3",6)==6)||
2219           (compare(elemtyp,"US3",3)==3)||
2220           (compare(elemtyp,"CPE3",4)==4)||(compare(elemtyp,"CPS3",4)==4)||
2221           (compare(elemtyp,"CAX3",4)==4)||(compare(elemtyp,"STRI3",5)==5))
2222   {
2223     if(compare(elemtyp,"CPE",3)==3) cbuf='E';
2224     else if(compare(elemtyp,"CPS",3)==3) cbuf='S';
2225     else if(compare(elemtyp,"CAX",3)==3) cbuf='C';
2226     else cbuf=0;
2227     se=pre_setax(setname, "i", 0);
2228     do{
2229       if(getAbqElement(rec_str, 3, &el, nd) <0) break;
2230 
2231       writeElem(el, 7, 7, 1, nd, cbuf);
2232 
2233       /* write set */
2234       if(setFlag) setax( setNr, "e", el);
2235       setax( se, "e", el);
2236     }while(1);
2237   }
2238   else if((compare(elemtyp,"S6",2)==2)||(compare(elemtyp,"DS6",3)==3)||
2239           (compare(elemtyp,"CPE6",4)==4)||(compare(elemtyp,"CPS6",4)==4)||
2240           (compare(elemtyp,"CAX6",4)==4)||
2241           (compare(elemtyp,"M3D6",4)==4)||(compare(elemtyp,"SC6",3)==3)||
2242           (compare(elemtyp,"SFM3D6",6)==6)||(compare(elemtyp,"STRI65",6)==6))
2243   {
2244     if(compare(elemtyp,"CPE",3)==3) cbuf='E';
2245     else if(compare(elemtyp,"CPS",3)==3) cbuf='S';
2246     else if(compare(elemtyp,"CAX",3)==3) cbuf='C';
2247     else cbuf=0;
2248     se=pre_setax(setname, "i", 0);
2249     do{
2250       if(getAbqElement(rec_str, 6, &el, nd) <0) break;
2251 
2252       writeElem(el, 8, 8, 1, nd, cbuf);
2253 
2254       /* write set */
2255       if(setFlag) setax( setNr, "e", el);
2256       setax( se, "e", el);
2257     }while(1);
2258   }
2259   else if((compare(elemtyp,"DS4",3)==3)||(compare(elemtyp,"M3D4",4)==4)||
2260           (compare(elemtyp,"SC4",3)==3)||(compare(elemtyp,"CAX4",4)==4)||
2261           (compare(elemtyp,"CPE4",4)==4)||(compare(elemtyp,"CPS4",4)==4)||
2262           (compare(elemtyp,"S4",2)==2)||(compare(elemtyp,"SFM3D4",6)==6))
2263   {
2264     if(compare(elemtyp,"CPE",3)==3) cbuf='E';
2265     else if(compare(elemtyp,"CPS",3)==3) cbuf='S';
2266     else if(compare(elemtyp,"CAX",3)==3) cbuf='C';
2267     else cbuf=0;
2268     se=pre_setax(setname, "i", 0);
2269     do{
2270       if(getAbqElement(rec_str, 4, &el, nd) <0) break;
2271 
2272       writeElem(el, 9, 9, 1, nd, cbuf);
2273 
2274       /* write set */
2275       if(setFlag) setax( setNr, "e", el);
2276       setax( se, "e", el);
2277     }while(1);
2278   }
2279   else if((compare(elemtyp,"M3D8",4)==4)||(compare(elemtyp,"S8",2)==2)||
2280           (compare(elemtyp,"DS8",3)==3)||(compare(elemtyp,"CAX8",4)==4)||
2281           (compare(elemtyp,"CPE8",4)==4)||(compare(elemtyp,"CPS8",4)==4)||
2282           (compare(elemtyp,"SC8",3)==3)||(compare(elemtyp,"SFM3D8",6)==6)||
2283           (compare(elemtyp,"S8R",3)==3)||(compare(elemtyp,"S8R5",4)==4))
2284   {
2285     if(compare(elemtyp,"CPE",3)==3) cbuf='E';
2286     else if(compare(elemtyp,"CPS",3)==3) cbuf='S';
2287     else if(compare(elemtyp,"CAX",3)==3) cbuf='C';
2288     else cbuf=0;
2289     se=pre_setax(setname, "i", 0);
2290     do{
2291       if(getAbqElement(rec_str, 8, &el, nd) <0) break;
2292 
2293       writeElem(el, 10, 10, 1, nd, cbuf);
2294 
2295       /* write set */
2296       if(setFlag) setax( setNr, "e", el);
2297       setax( se, "e", el);
2298     }while(1);
2299   }
2300   else if(compare(elemtyp,"SPRING1",7)==7)
2301   {
2302     cbuf=0;
2303     se=pre_setax(setname, "i", 0);
2304     do{
2305       if(getAbqElement(rec_str, 1, &el, nd) <0) break;
2306 
2307       /* write set */
2308       if(setFlag) setax( setNr, "n", nd[0]);
2309       setax( se, "n", nd[0]);
2310     }while(1);
2311   }
2312   else if((compare(elemtyp,"B21",3)==3)||(compare(elemtyp,"B31",3)==3)||(compare(elemtyp,"T2D2",4)==4)||(compare(elemtyp,"T3D2",4)==4)||
2313           (compare(elemtyp,"DASHPOT",7)==7)||(compare(elemtyp,"SPRING2",7)==7)||(compare(elemtyp,"GAPUNI",6)==6))
2314   {
2315     if(compare(elemtyp,"DASHPOT",3)==3) cbuf='D';
2316     else cbuf=0;
2317     se=pre_setax(setname, "i", 0);
2318     do{
2319       if(getAbqElement(rec_str, 2, &el, nd) <0) break;
2320 
2321       writeElem(el, 11, 11, 1, nd, 0);
2322 
2323       /* write set */
2324       if(setFlag) setax( setNr, "e", el);
2325       setax( se, "e", el);
2326     }while(1);
2327   }
2328   else if((compare(elemtyp,"B22",3)==3)||(compare(elemtyp,"B32",3)==3)||
2329           (compare(elemtyp,"D",1)==strlen(elemtyp)))
2330   {
2331     se=pre_setax(setname, "i", 0);
2332     do{
2333       if(getAbqElement(rec_str, 3, &el, nd) <0) break;
2334       /* check if its an inflow or out-flow element */
2335       if(!nd[0])
2336         writeElem(el, 11, 11, 1, &nd[1], 0);
2337       else if(!nd[2])
2338         writeElem(el, 11, 11, 1, nd, 0);
2339       else
2340       {
2341         i=nd[1];
2342         nd[1]=nd[2];
2343         nd[2]=i;
2344         writeElem(el, 12, 12, 1, nd, 0);
2345       }
2346       /* write set */
2347       if(setFlag) setax( setNr, "e", el);
2348       setax( se, "e", el);
2349     }while(1);
2350   }
2351   else
2352   {
2353     i=abqrecord(rec_str);
2354     if(i==-1) return(-1);
2355   }
2356   return(1);
2357 }
2358 
2359 
2360 
getAmplitude(char * rec_str)2361 int getAmplitude(char *rec_str)
2362 {
2363   int i,j,n, args, ampnr;
2364   char aname[MAX_LINE_LENGTH];
2365 
2366 
2367   /* get the arguments of the string */
2368   args=crecord(rec_str, dat);
2369 
2370   /* extract the material-name */
2371   for(i=0; i<args; i++)
2372   {
2373     /* delete blanks */
2374     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2375     buffer[n]='\0';
2376     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2377     if(compare(dat[i],"NAME=",5)==5) strcpy(aname,&buffer[5]);
2378   }
2379   if(printFlag) printf("*AMPLITUDE, NAME=%s\n", aname);
2380 
2381   /* get or define an amplitude-number */
2382   ampnr=getAmplitudeNr(aname,0);
2383 
2384 
2385   do{
2386     i=abqrecord(rec_str);
2387 
2388     if(i==-1) return(-1);
2389     if(i==-2) break;
2390 
2391     /* get the arguments of the string */
2392     args=crecord(rec_str, dat);
2393 
2394     /* screen dump */
2395     if(printFlag)
2396     {
2397       for(i=0; i<args; i++) printf("%s ",dat[i]);
2398       printf(" (%d)\n",i);
2399     }
2400 
2401     /* extract x,y pairs */
2402     for(i=0; i<args-1; i+=2)
2403     {
2404       if ((amplitude[ampnr].x = (double *)realloc( (double *)amplitude[ampnr].x, (amplitude[ampnr].n+2)*sizeof(double)) ) == NULL )
2405       {
2406         printf(" ERROR: realloc failure in getAmplitude\n\n");
2407         return(-1);
2408       }
2409       if ((amplitude[ampnr].y = (double *)realloc( (double *)amplitude[ampnr].y, (amplitude[ampnr].n+2)*sizeof(double)) ) == NULL )
2410       {
2411         printf(" ERROR: realloc failure in getAmplitude\n\n");
2412         return(-1);
2413       }
2414       amplitude[ampnr].x[amplitude[ampnr].n]=atof(dat[i]);
2415       amplitude[ampnr].y[amplitude[ampnr].n]=atof(dat[i+1]);
2416       amplitude[ampnr].n++;
2417     }
2418   }while(args>0);
2419 
2420   if(printFlag) for (i=0; i<amplitude[ampnr].n; i++)
2421     printf("%d %lf %lf\n",i,amplitude[ampnr].x[i],amplitude[ampnr].y[i] );
2422   return(1);
2423 }
2424 
2425 
getMaterial(char * rec_str)2426 int getMaterial(char *rec_str)
2427 {
2428   int i,j,n, args;
2429   char mname[MAX_LINE_LENGTH];
2430 
2431 
2432   /* get the arguments of the string */
2433   args=crecord(rec_str, dat);
2434 
2435   /* extract the material-name */
2436   for(i=0; i<args; i++)
2437   {
2438     /* delete blanks */
2439     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2440     buffer[n]='\0';
2441     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2442     if(compare(dat[i],"NAME=",5)==5) strcpy(mname,&buffer[5]);
2443   }
2444   if(printFlag) printf("*MATERIAL, NAME=%s\n", mname);
2445 
2446   /* get the next line */
2447   i=abqrecord(rec_str);
2448   if(i==-1) return(-1);
2449 
2450   /* get or define a material-number */
2451   matnr=getMatNr(mname,0);
2452 
2453   if(ansFlag)
2454     fprintf( handleans, "! ----  MATERIAL: %s, NR: %d -----\n",mname, matnr);
2455   return(1);
2456 }
2457 
2458 
getElastic(char * rec_str)2459 int getElastic(char *rec_str)
2460 {
2461   int i,j,n, args,length;
2462   static char **dat=NULL;
2463   char type[MAX_LINE_LENGTH];
2464   double E,nue,t;
2465 
2466   if((dat = (char **)realloc((char **)dat, (80)*sizeof(char*)))==NULL)
2467     errMsg("\n\n ERROR: realloc failed for **dat\n" );
2468   for (i=0; i<80; i++)
2469   {
2470     dat[i]=NULL;
2471     if((dat[i] = (char *)realloc((char *)dat[i], (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
2472       errMsg("\n\n ERROR: realloc failed for *dat\n" );
2473   }
2474 
2475   /* get the arguments of the string */
2476   args=crecord(rec_str, dat);
2477 
2478   /* extract the type */
2479   strcpy(type,"ISO"); /*default */
2480   for(i=0; i<args; i++)
2481   {
2482     /* delete blanks */
2483     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2484     buffer[n]='\0';
2485     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2486     if(compare(dat[i],"TYPE=",5)==5) strcpy(type,&dat[i][5]);
2487   }
2488   if(printFlag) printf("*ELASTIC, TYPE=%s\n", type);
2489 
2490   /* scan the properties and write to file */
2491   if(compare(type,"ISO",3)==3)
2492   {
2493     i=0;
2494     do{
2495       length=abqrecord(rec_str);
2496       if(length==-1) return(-1);
2497       if(length==-2) break;
2498       length=sscanf ( rec_str, "%lf, %lf, %lf", &E,&nue,&t);
2499       if(printFlag) printf("temp:%lf E:%lf nue:%lf\n",t,E,nue);
2500 
2501       if ((material[matnr].tela = (double *)realloc( (double *)material[matnr].tela, (material[matnr].nela+2)*sizeof(double)) ) == NULL )
2502       {
2503         printf(" ERROR: realloc failure in getElastic\n\n");
2504         return(-1);
2505       }
2506       if ((material[matnr].ela = (double *)realloc( (double *)material[matnr].ela, (material[matnr].nela+2)*sizeof(double)) ) == NULL )
2507       {
2508         printf(" ERROR: realloc failure in getElastic\n\n");
2509         return(-1);
2510       }
2511       if ((material[matnr].nue = (double *)realloc( (double *)material[matnr].nue, (material[matnr].nela+2)*sizeof(double)) ) == NULL )
2512       {
2513         printf(" ERROR: realloc failure in getElastic\n\n");
2514         return(-1);
2515       }
2516       material[matnr].tela[material[matnr].nela]=t;
2517       material[matnr].ela[material[matnr].nela]=E;
2518       material[matnr].nue[material[matnr].nela]=nue;
2519       material[matnr].nela++;
2520 
2521       if(ansFlag)
2522       {
2523         i++;
2524         /* write in ansys format */
2525         fprintf(handleans, "MPTEMP, %d, %lf,\n",i, t);
2526         fprintf(handleans, "MPDATA, EX, %d, %d, %e,\n",matnr, i, E);
2527         fprintf(handleans, "MPDATA, NUXY, %d, %d, %lf,\n",matnr, i, nue);
2528       }
2529     }while(1);
2530   }
2531   else
2532   {
2533     errMsg(" WARNING: TYPE:%s not known\n",type);
2534       length=abqrecord(rec_str);
2535       if(length==-1) return(-1);
2536   }
2537   return(1);
2538 }
2539 
2540 
getExpansion(char * rec_str)2541 int getExpansion(char *rec_str)
2542 {
2543   int i,j,n, args,length;
2544   char type[MAX_LINE_LENGTH];
2545   double a,t;
2546 
2547 
2548   /* get the arguments of the string */
2549   args=crecord(rec_str, dat);
2550 
2551   /* extract the type */
2552   strcpy(type,"ISO"); /*default */
2553   for(i=0; i<args; i++)
2554   {
2555     /* delete blanks */
2556     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2557     buffer[n]='\0';
2558     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2559     if(compare(dat[i],"TYPE=",5)==5) strcpy(type,&dat[i][5]);
2560   }
2561   if(printFlag) printf("*EXPANSION, TYPE=%s\n", type);
2562 
2563   /* scan the properties and write to file */
2564   if(compare(type,"ISO",3)==3)
2565   {
2566     i=0;
2567     do{
2568       length=abqrecord(rec_str);
2569       if(length==-1) return(-1);
2570       if(length==-2) break;
2571       length=sscanf ( rec_str, "%lf, %lf", &a,&t);
2572       if(printFlag) printf("temp:%lf alpha:%lf\n",t,a);
2573 
2574       if ((material[matnr].texp = (double *)realloc( (double *)material[matnr].texp, (material[matnr].nexp+2)*sizeof(double)) ) == NULL )
2575       {
2576         printf(" ERROR: realloc failure in getElastic\n\n");
2577         return(-1);
2578       }
2579       if ((material[matnr].exp = (double *)realloc( (double *)material[matnr].exp, (material[matnr].nexp+2)*sizeof(double)) ) == NULL )
2580       {
2581         printf(" ERROR: realloc failure in getElastic\n\n");
2582         return(-1);
2583       }
2584       material[matnr].texp[material[matnr].nexp]=t;
2585       material[matnr].exp[material[matnr].nexp]=a;
2586       material[matnr].nexp++;
2587 
2588       if(ansFlag)
2589       {
2590         i++;
2591         /* write in ansys format */
2592         fprintf(handleans, "MPTEMP, %d, %lf,\n",i, t);
2593         fprintf(handleans, "MPDATA, ALPX, %d, %d, %e,\n",matnr, i, a);
2594       }
2595     }while(1);
2596   }
2597   else
2598   {
2599     errMsg(" WARNING: TYPE:%s not known\n",type);
2600       length=abqrecord(rec_str);
2601       if(length==-1) return(-1);
2602   }
2603   return(1);
2604 }
2605 
2606 
getConductivity(char * rec_str)2607 int getConductivity(char *rec_str)
2608 {
2609   int i,j,n, args,length;
2610   char type[MAX_LINE_LENGTH];
2611   double a,t;
2612 
2613 
2614   /* get the arguments of the string */
2615   args=crecord(rec_str, dat);
2616 
2617   /* extract the type */
2618   strcpy(type,"ISO"); /*default */
2619   for(i=0; i<args; i++)
2620   {
2621     /* delete blanks */
2622     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2623     buffer[n]='\0';
2624     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2625     if(compare(dat[i],"TYPE=",5)==5) strcpy(type,&dat[i][5]);
2626   }
2627   if(printFlag) printf("*CONDUCTIVITY, TYPE=%s\n", type);
2628 
2629   /* scan the properties and write to file */
2630   if(compare(type,"ISO",3)==3)
2631   {
2632     i=0;
2633     do{
2634       length=abqrecord(rec_str);
2635       if(length==-1) return(-1);
2636       if(length==-2) break;
2637       length=sscanf ( rec_str, "%lf, %lf", &a,&t);
2638       if(printFlag) printf("temp:%lf w:%lf\n",t,a);
2639 
2640       if ((material[matnr].tcon = (double *)realloc( (double *)material[matnr].tcon, (material[matnr].ncon+2)*sizeof(double)) ) == NULL )
2641       {
2642         printf(" ERROR: realloc failure in getConductivity\n\n");
2643         return(-1);
2644       }
2645       if ((material[matnr].con = (double *)realloc( (double *)material[matnr].con, (material[matnr].ncon+2)*sizeof(double)) ) == NULL )
2646       {
2647         printf(" ERROR: realloc failure in getConductivity\n\n");
2648         return(-1);
2649       }
2650       material[matnr].tcon[material[matnr].ncon]=t;
2651       material[matnr].con[material[matnr].ncon]=a;
2652       material[matnr].ncon++;
2653 
2654       if(ansFlag)
2655       {
2656         i++;
2657         /* write in ansys format */
2658         printf("ERROR: Coductivity not yet supported. EXIT\n"); exit(1);
2659         fprintf(handleans, "MPTEMP, %d, %lf,\n",i, t);
2660         fprintf(handleans, "MPDATA, ALPX, %d, %d, %e,\n",matnr, i, a);
2661       }
2662     }while(1);
2663   }
2664   else
2665   {
2666     errMsg(" WARNING: TYPE:%s not known\n",type);
2667       length=abqrecord(rec_str);
2668       if(length==-1) return(-1);
2669   }
2670   return(1);
2671 }
2672 
2673 
getSpecificHeat(char * rec_str)2674 int getSpecificHeat(char *rec_str)
2675 {
2676   int i,j,n, args,length;
2677   char type[MAX_LINE_LENGTH];
2678   double a,t;
2679 
2680 
2681   /* get the arguments of the string */
2682   args=crecord(rec_str, dat);
2683 
2684   /* extract the type */
2685   strcpy(type,"ISO"); /*default */
2686   for(i=0; i<args; i++)
2687   {
2688     /* delete blanks */
2689     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2690     buffer[n]='\0';
2691     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2692     if(compare(dat[i],"TYPE=",5)==5) strcpy(type,&dat[i][5]);
2693   }
2694   if(printFlag) printf("*SPECIFIC HEAT, TYPE=%s\n", type);
2695 
2696   /* scan the properties and write to file */
2697   if(compare(type,"ISO",3)==3)
2698   {
2699     i=0;
2700     do{
2701       length=abqrecord(rec_str);
2702       if(length==-1) return(-1);
2703       if(length==-2) break;
2704       length=sscanf ( rec_str, "%lf, %lf", &a,&t);
2705       if(printFlag) printf("temp:%lf h:%lf\n",t,a);
2706 
2707       if ((material[matnr].tsph = (double *)realloc( (double *)material[matnr].tsph, (material[matnr].nsph+2)*sizeof(double)) ) == NULL )
2708       {
2709         printf(" ERROR: realloc failure in getSpecificHeat\n\n");
2710         return(-1);
2711       }
2712       if ((material[matnr].sph = (double *)realloc( (double *)material[matnr].sph, (material[matnr].nsph+2)*sizeof(double)) ) == NULL )
2713       {
2714         printf(" ERROR: realloc failure in getSpecificHeat\n\n");
2715         return(-1);
2716       }
2717       material[matnr].tsph[material[matnr].nsph]=t;
2718       material[matnr].sph[material[matnr].nsph]=a;
2719       material[matnr].nsph++;
2720 
2721       if(ansFlag)
2722       {
2723         i++;
2724         /* write in ansys format */
2725         printf("ERROR: SpecificHeat not yet supported. EXIT\n"); exit(1);
2726         fprintf(handleans, "MPTEMP, %d, %lf,\n",i, t);
2727         fprintf(handleans, "MPDATA, ALPX, %d, %d, %e,\n",matnr, i, a);
2728       }
2729     }while(1);
2730   }
2731   else
2732   {
2733     errMsg(" WARNING: TYPE:%s not known\n",type);
2734       length=abqrecord(rec_str);
2735       if(length==-1) return(-1);
2736   }
2737   return(1);
2738 }
2739 
2740 
getDensity(char * rec_str)2741 int getDensity(char *rec_str)
2742 {
2743   int length;
2744   double rho=0.,t=0.;
2745 
2746   /* scan the properties and write to file */
2747   do{
2748     length=abqrecord(rec_str);
2749     if(length==-1) return(-1);
2750     if(length==-2) break;
2751     length=sscanf ( rec_str, "%lf, %lf", &rho,&t);
2752     material[matnr].rho=rho;
2753     if(printFlag) printf("*DENSITY\n %e, %lf\n", material[matnr].rho, t);
2754 
2755     if(ansFlag)
2756     {
2757       /* write in ansys format */
2758       fprintf(handleans, "MP,DENS, %d, %e,\n", matnr, rho);
2759     }
2760   }while(1);
2761   return(1);
2762 }
2763 
2764 
getPlastic(char * rec_str)2765 int getPlastic(char *rec_str)
2766 {
2767   int i,j,n, args,length;
2768   char type[MAX_LINE_LENGTH];
2769   double s,e,t;
2770 
2771 
2772   /* get the arguments of the string */
2773   args=crecord(rec_str, dat);
2774 
2775   /* extract the type */
2776   strcpy(type,"ISOTROPIC"); /*default */
2777   for(i=0; i<args; i++)
2778   {
2779     /* delete blanks */
2780     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
2781     buffer[n]='\0';
2782     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
2783     if(compare(dat[i],"HARDENING=",5)==5) strcpy(type,&dat[i][10]);
2784   }
2785   if(printFlag) printf("*PLASTIC, HARDENING=%s\n", type);
2786 
2787   /* scan the properties and write to file */
2788   //if(compare(type,"ISOTROPIC",3)==3)
2789   {
2790     i=0;
2791     do{
2792       length=abqrecord(rec_str);
2793       if(length==-1) return(-1);
2794       if(length==-2) break;
2795       length=sscanf ( rec_str, "%lf, %lf, %lf", &s,&e,&t);
2796       if(printFlag) printf("%lf %lf %lf\n",s,e,t);
2797 
2798       if ((material[matnr].spl = (double *)realloc( (double *)material[matnr].spl, (material[matnr].npl+2)*sizeof(double)) ) == NULL )
2799       {
2800         printf(" ERROR: realloc failure in getSpecificHeat\n\n");
2801         return(-1);
2802       }
2803       if ((material[matnr].epl = (double *)realloc( (double *)material[matnr].epl, (material[matnr].npl+2)*sizeof(double)) ) == NULL )
2804       {
2805         printf(" ERROR: realloc failure in getSpecificHeat\n\n");
2806         return(-1);
2807       }
2808       if ((material[matnr].tpl = (double *)realloc( (double *)material[matnr].tpl, (material[matnr].npl+2)*sizeof(double)) ) == NULL )
2809       {
2810         printf(" ERROR: realloc failure in getSpecificHeat\n\n");
2811         return(-1);
2812       }
2813       material[matnr].spl[material[matnr].npl]=s;
2814       material[matnr].epl[material[matnr].npl]=e;
2815       material[matnr].tpl[material[matnr].npl]=t;
2816       material[matnr].npl++;
2817 
2818       if(ansFlag)
2819       {
2820         i++;
2821         /* write in ansys format */
2822         printf("ERROR: Plastic matdata not yet supported. EXIT\n"); exit(1);
2823         //fprintf(handleans, "MPTEMP, %d, %lf,\n",i, t);
2824         //fprintf(handleans, "MPDATA, ALPX, %d, %d, %e,\n",matnr, i, a);
2825       }
2826     }while(1);
2827   }
2828   return(1);
2829 }
2830 
2831 
calcMaxMinValues(int l)2832 int calcMaxMinValues(int l)
2833 {
2834   int i,j;
2835   for(i=0; i<lcasex[l].ncomps; i++)
2836   {
2837     lcasex[l].max[i]=-MAX_FLOAT;
2838     lcasex[l].min[i]=MAX_FLOAT;
2839     for(j=0; j<anzx->n; j++)
2840     {
2841       if (lcasex[l].dat[i][nodex[j].nr] > lcasex[l].max[i])
2842       {  lcasex[l].max[i]=lcasex[l].dat[i][nodex[j].nr]; lcasex[l].nmax[i]=nodex[j].nr; }
2843       if (lcasex[l].dat[i][nodex[j].nr] < lcasex[l].min[i])
2844       {  lcasex[l].min[i]=lcasex[l].dat[i][nodex[j].nr]; lcasex[l].nmin[i]=nodex[j].nr; }
2845     }
2846   }
2847   return(1);
2848 }
2849 
2850 
2851 /*
2852 el: elementNr
2853 face: abaqus element face nr
2854 nr: ncomp
2855 val: values[comp]
2856 string: setname
2857 */
2858 
writeFaceVals(int anzx_l,int el,int face,int nr,float * val)2859 int writeFaceVals(int anzx_l, int el, int face, int nr, float *val)
2860 {
2861   int i,j, anzn, nface[26];
2862 
2863   if(nr<1) return(0);
2864 
2865     if (el>anzx->emax)
2866     {
2867       printf("WARNING: found elementNr:%d in Dataset higher than in Geometry allocated:%d\n", el, anzx->emax);
2868       return(0);
2869     }
2870 
2871     /* convert from abaqus syntax to cgx syntax */
2872     if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
2873     {
2874       if(e_enqirex[el].attr>3)
2875       {
2876         face++;
2877         if(e_enqirex[el].type<9)
2878         {
2879           if(face>4) face=1;
2880         }
2881         else
2882         {
2883           if(face>5) face=1;
2884         }
2885       }
2886       else
2887       {
2888         face--;
2889         if(face==0) face=1;
2890       }
2891     }
2892     anzn=getElemFaceNodes(e_enqirex, el,face,nface);
2893     for (i=0; i<anzn; i++)
2894     {
2895       /* load */
2896 
2897       for(j=0; j<nr; j++) lcasex[anzx_l].dat[j][nface[i]]+=val[j];
2898       /* number of loads per node */
2899       lcasex[anzx_l].dat[nr][nface[i]]++;
2900     }
2901 
2902   return(1);
2903 }
2904 
2905 
getUserTemps(char * rec_str)2906 int getUserTemps(char *rec_str)
2907 {
2908   int i,j,n;
2909   int length, nd, foundLoads=0, nset, comp;
2910   double t;
2911 
2912   FILE *handle;
2913   char *file;
2914 
2915   file=strstr(rec_str, "=");
2916   file++;
2917   handle=fopen(file, "r");
2918   if ( handle== NULL ) { printf ("\nERROR in readccx: The input file \"%s\" could not be opened.\n\n",file); return(-1); }
2919   printf (" file \"%s\" opened.\n\n",file);
2920 
2921   sprintf( lcasex[anzx->l].name,"TEMP");
2922   printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
2923   comp=0;
2924   lcasex[anzx->l].ncomps=1;
2925   lcasex[anzx->l].irtype=1;
2926   lcasex[anzx->l].npheader=0;
2927 
2928   if(anzx->l) lcasex[anzx->l].value=lcasex[anzx->l-1].value+dataset_value;
2929   else lcasex[anzx->l].value=dataset_value;
2930   //dataset_value=0.;
2931 
2932   strcpy(lcasex[anzx->l].analysis_name,"");
2933   sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
2934   if(strlen(dataset_text))
2935   {
2936     strcpy(lcasex[anzx->l].dataset_text,"");
2937     //dataset_text[0]=0;
2938   }
2939   else strcpy(lcasex[anzx->l].dataset_text,dataset_text);
2940   lcasex[anzx->l].step_number=step_nr;
2941   lcasex[anzx->l].analysis_type=1;
2942 
2943   if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2944     printf("\n\n ERROR: malloc failure\n\n" );
2945   if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2946     printf("\n\n ERROR: malloc failure\n\n" );
2947   if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
2948     printf("\n\n ERROR: malloc failure\n\n" );
2949   if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
2950     printf("\n\n ERROR: malloc failure\n\n" );
2951   if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
2952     printf("\n\n ERROR: malloc failure\n\n" );
2953   if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
2954     printf("\n\n ERROR: malloc failure\n\n" );
2955   if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
2956     printf("\n\n ERROR: malloc failure\n\n" );
2957   if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2958     printf("\n\n ERROR: malloc failure\n\n" );
2959   if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2960     printf("\n\n ERROR: malloc failure\n\n" );
2961   if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2962     printf("\n\n ERROR: malloc failure\n\n" );
2963   if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2964     printf("\n\n ERROR: malloc failure\n\n" );
2965   if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
2966     printf("\n\n ERROR: malloc failure\n\n" );
2967 
2968   for(i=comp; i<lcasex[anzx->l].ncomps; i++)
2969   {
2970     if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
2971       printf("\n\n ERROR: malloc failure\n\n" );
2972     if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
2973       printf("\n\n ERROR: malloc failed\n\n" );
2974     if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
2975       printf("\n\n ERROR: malloc failed\n\n" );
2976     lcasex[anzx->l].max[i]=-MAX_FLOAT;
2977     lcasex[anzx->l].min[i]=MAX_FLOAT;
2978 
2979     lcasex[anzx->l].menu[i] = 1;
2980     lcasex[anzx->l].ictype[i] = 1;
2981     lcasex[anzx->l].icind1[i] = 0;
2982     lcasex[anzx->l].icind2[i] = 0;
2983     lcasex[anzx->l].iexist[i] = 0;
2984     lcasex[anzx->l].max[i]=-MAX_FLOAT;  lcasex[anzx->l].min[i]=MAX_FLOAT;
2985   }
2986 
2987   strcpy ( lcasex[anzx->l].compName[0], "T  ");
2988   do{
2989     length=fscanf(handle,"%s",rec_str);
2990     if(length==EOF) break;
2991     if(length==0) break;
2992     foundLoads=1;
2993 
2994     crecord(rec_str, dat);
2995     nd=atoi(dat[0]);
2996     t=atof(dat[1]);
2997     /* check if the node-number is 0, then a set was defined */
2998     if (nd==0)
2999     {
3000       nset=getSetNrx(dat[0]);
3001       if(nset<0)
3002       {
3003         printf("ERROR: set:%s not defined\n", dat[0]);
3004         return(-1);
3005       }
3006       for(j=0; j<setx[nset].anz_n; j++)
3007       {
3008         writeNodeVals(anzx->l, setx[nset].node[j], t, 0);
3009         if(ansFlag)
3010         {
3011           /* write in ansys format */
3012 	  fprintf(handleans, "BF, %d, TEMP, %lf\n", setx[nset].node[j], t);
3013         }
3014       }
3015     }
3016     else
3017     {
3018       writeNodeVals(anzx->l, nd, t, 0);
3019       if(copyFlag)
3020       {
3021         /* write to equ-file */
3022         for (n=0; n<SEGMENTS; n++) {
3023           fprintf(handle_equ, "%d,%lf\n", nd+(n*NODE_OFFSET), t); }
3024       }
3025       if(ansFlag)
3026       {
3027         /* write in ansys format */
3028         fprintf(handleans, "BF, %d, TEMP, %lf\n", nd, t);
3029       }
3030     }
3031   }while(1);
3032 
3033   if(foundLoads)
3034   {
3035     anzx->l++;
3036     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
3037     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3038   }
3039 
3040   fclose(handle);
3041   return(1);
3042 }
3043 
3044 
3045 
getScalarvalue(char * rec_str,char * type)3046 int getScalarvalue(char *rec_str, char *type)
3047 {
3048   int i,j,n;
3049   int length, nd, foundLoads=0, nset, comp, args;
3050   double t;
3051 
3052   if(printFlag) printf("%s\n",rec_str);
3053   /* scan the properties and write to file */
3054 
3055   if(compare(type,"TEMP",4)==4)
3056   {
3057     /* get the arguments of the string */
3058     args=crecord(rec_str, dat);
3059     for(i=0; i<args; i++)
3060     {
3061       /* delete blanks */
3062       n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
3063       buffer[n]='\0';
3064       for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
3065       if(compare(dat[i],"USER",4)==4)
3066       {
3067         // printf("WARNING: %s not known. Data ignored.\n", rec_str);
3068         length=abqrecord(rec_str);
3069         // somehow getSetNrx is not working (trailingblanks?)
3070 	//printf("Set:%s\n",rec_str);
3071         //userTempSetNr=getSetNrx(rec_str);
3072         userTempSetNr=0;
3073 	printf("found userTempSetNr:%d\n",userTempSetNr);
3074         return(1);
3075       }
3076     }
3077     sprintf( lcasex[anzx->l].name,"TEMP");
3078   }
3079   else if(compare(type,"PRES",4)==4)
3080   {
3081     sprintf( lcasex[anzx->l].name,"PRES");
3082   }
3083   else if(compare(type,"TOTA",4)==4)
3084   {
3085     sprintf( lcasex[anzx->l].name,"TTEMP");
3086   }
3087   else if(compare(type,"MASS",4)==4)
3088   {
3089     sprintf( lcasex[anzx->l].name,"MASSFL");
3090   }
3091   else
3092   {
3093     printf("ERROR: In getScalarValue type:%s not known\n", type);
3094     return(-1);
3095   }
3096   printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
3097   comp=0;
3098   lcasex[anzx->l].ncomps=1;
3099   lcasex[anzx->l].irtype=1;
3100   lcasex[anzx->l].npheader=0;
3101 
3102   if(anzx->l) lcasex[anzx->l].value=lcasex[anzx->l-1].value+dataset_value;
3103   else lcasex[anzx->l].value=dataset_value;
3104   //dataset_value=0.;
3105 
3106   strcpy(lcasex[anzx->l].analysis_name,"");
3107   sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
3108   if(strlen(dataset_text))
3109   {
3110     strcpy(lcasex[anzx->l].dataset_text,"");
3111     //dataset_text[0]=0;
3112   }
3113   else strcpy(lcasex[anzx->l].dataset_text,dataset_text);
3114   lcasex[anzx->l].step_number=step_nr;
3115   lcasex[anzx->l].analysis_type=1;
3116 
3117   if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3118     printf("\n\n ERROR: malloc failure\n\n" );
3119   if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3120     printf("\n\n ERROR: malloc failure\n\n" );
3121   if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3122     printf("\n\n ERROR: malloc failure\n\n" );
3123   if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3124     printf("\n\n ERROR: malloc failure\n\n" );
3125   if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
3126     printf("\n\n ERROR: malloc failure\n\n" );
3127   if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3128     printf("\n\n ERROR: malloc failure\n\n" );
3129   if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3130     printf("\n\n ERROR: malloc failure\n\n" );
3131   if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3132     printf("\n\n ERROR: malloc failure\n\n" );
3133   if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3134     printf("\n\n ERROR: malloc failure\n\n" );
3135   if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3136     printf("\n\n ERROR: malloc failure\n\n" );
3137   if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3138     printf("\n\n ERROR: malloc failure\n\n" );
3139   if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3140     printf("\n\n ERROR: malloc failure\n\n" );
3141 
3142   for(i=comp; i<lcasex[anzx->l].ncomps; i++)
3143   {
3144     if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
3145       printf("\n\n ERROR: malloc failure\n\n" );
3146     if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3147       printf("\n\n ERROR: malloc failed\n\n" );
3148     if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3149       printf("\n\n ERROR: malloc failed\n\n" );
3150     lcasex[anzx->l].max[i]=-MAX_FLOAT;
3151     lcasex[anzx->l].min[i]=MAX_FLOAT;
3152 
3153     lcasex[anzx->l].menu[i] = 1;
3154     lcasex[anzx->l].ictype[i] = 1;
3155     lcasex[anzx->l].icind1[i] = 0;
3156     lcasex[anzx->l].icind2[i] = 0;
3157     lcasex[anzx->l].iexist[i] = 0;
3158     lcasex[anzx->l].max[i]=-MAX_FLOAT;  lcasex[anzx->l].min[i]=MAX_FLOAT;
3159   }
3160 
3161 
3162   if(compare(type,"TEMP",4)==4)
3163   {
3164     strcpy ( lcasex[anzx->l].compName[0], "T  ");
3165   }
3166   else if(compare(type,"PRES",4)==4)
3167   {
3168     strcpy ( lcasex[anzx->l].compName[0], "P  ");
3169   }
3170   else if(compare(type,"TOTA",4)==4)
3171   {
3172     strcpy ( lcasex[anzx->l].compName[0], "TT");
3173   }
3174   else if(compare(type,"MASS",4)==4)
3175   {
3176     strcpy ( lcasex[anzx->l].compName[0], "M  ");
3177   }
3178 
3179   do{
3180     length=abqrecord(rec_str);
3181     if(length==-1)
3182     {
3183       anzx->l++;
3184       if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
3185       { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3186       return(-1);
3187     }
3188     if(length==-2) break;
3189     foundLoads=1;
3190 
3191     crecord(rec_str, dat);
3192     nd=atoi(dat[0]);
3193     t=atof(dat[1]);
3194     /* check if the node-number is 0, then a set was defined */
3195     if (nd==0)
3196     {
3197       nset=getSetNrx(dat[0]);
3198       if(nset<0)
3199       {
3200         printf("ERROR: In getScalarvalue type *%s set:%s not defined\n", type, dat[0]);
3201         return(-1);
3202       }
3203       for(j=0; j<setx[nset].anz_n; j++)
3204       {
3205         writeNodeVals(anzx->l, setx[nset].node[j], t, 0);
3206         if(ansFlag)
3207         {
3208           /* write in ansys format */
3209 	  fprintf(handleans, "BF, %d, %s, %lf\n", setx[nset].node[j], type, t);
3210         }
3211       }
3212     }
3213     else
3214     {
3215       writeNodeVals(anzx->l, nd, t, 0);
3216       if(copyFlag)
3217       {
3218         /* write to equ-file */
3219         for (n=0; n<SEGMENTS; n++) {
3220           fprintf(handle_equ, "%d,%lf\n", nd+(n*NODE_OFFSET), t); }
3221       }
3222       if(ansFlag)
3223       {
3224         /* write in ansys format */
3225         fprintf(handleans, "BF, %d, %s, %lf\n", nd, type, t);
3226       }
3227     }
3228   }while(1);
3229 
3230   if(foundLoads)
3231   {
3232     anzx->l++;
3233     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
3234     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3235   }
3236   return(1);
3237 }
3238 
3239 
3240 
getInitialVector(char * rec_str,char * type)3241 int getInitialVector(char *rec_str, char *type)
3242 {
3243   int i,j,n;
3244   int length, nd, dof, foundLoads=0,nset=0;
3245   double f;
3246 
3247   if(printFlag) printf("%s\n",rec_str);
3248   /* scan the properties and write to file */
3249 
3250   /* ini lcasex */
3251   if(compare(type,"DISP",4)==4)
3252   {
3253     sprintf( lcasex[anzx->l].name,"DISP");
3254   }
3255   else if((compare(type,"FLUID",4)==4)||(compare(type,"VELO",4)==4))
3256   {
3257     sprintf( lcasex[anzx->l].name,"VELO");
3258   }
3259   else
3260   {
3261     printf("ERROR: In getInitialVector type:%s not known\n", type);
3262     return(-1);
3263   }
3264   printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
3265   lcasex[anzx->l].value=0;
3266   lcasex[anzx->l].ncomps=3;
3267   lcasex[anzx->l].irtype=1;
3268   lcasex[anzx->l].npheader=0;
3269 
3270   strcpy(lcasex[anzx->l].analysis_name,"");
3271   sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
3272   strcpy(lcasex[anzx->l].dataset_text,"");
3273   lcasex[anzx->l].step_number=step_nr;
3274   lcasex[anzx->l].analysis_type=1;
3275 
3276   if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3277     printf("\n\n ERROR: malloc failure\n\n" );
3278   if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3279     printf("\n\n ERROR: malloc failure\n\n" );
3280   if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3281     printf("\n\n ERROR: malloc failure\n\n" );
3282   if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3283     printf("\n\n ERROR: malloc failure\n\n" );
3284   if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
3285     printf("\n\n ERROR: malloc failure\n\n" );
3286   if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3287     printf("\n\n ERROR: malloc failure\n\n" );
3288   if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3289     printf("\n\n ERROR: malloc failure\n\n" );
3290   if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3291     printf("\n\n ERROR: malloc failure\n\n" );
3292   if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3293     printf("\n\n ERROR: malloc failure\n\n" );
3294   if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3295     printf("\n\n ERROR: malloc failure\n\n" );
3296   if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3297     printf("\n\n ERROR: malloc failure\n\n" );
3298   if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3299     printf("\n\n ERROR: malloc failure\n\n" );
3300 
3301   for(i=0; i<lcasex[anzx->l].ncomps; i++)
3302   {
3303     if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
3304       printf("\n\n ERROR: malloc failure\n\n" );
3305     if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3306       printf("\n\n ERROR: malloc failed\n\n" );
3307     if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3308       printf("\n\n ERROR: malloc failed\n\n" );
3309     lcasex[anzx->l].max[i]=-MAX_FLOAT;
3310     lcasex[anzx->l].min[i]=MAX_FLOAT;
3311 
3312     lcasex[anzx->l].menu[i] = 1;
3313     lcasex[anzx->l].ictype[i] = 2;
3314     lcasex[anzx->l].icind1[i] = i+1;
3315     lcasex[anzx->l].icind2[i] = 0;
3316     lcasex[anzx->l].iexist[i] = 0;
3317   }
3318 
3319   if(compare(type,"DISP",4)==4)
3320   {
3321     strcpy ( lcasex[anzx->l].compName[0], "dx ");
3322     strcpy ( lcasex[anzx->l].compName[1], "dy ");
3323     strcpy ( lcasex[anzx->l].compName[2], "dz ");
3324 /*
3325     strcpy ( lcasex[anzx->l].compName[3], "rx ");
3326     strcpy ( lcasex[anzx->l].compName[4], "ry ");
3327     strcpy ( lcasex[anzx->l].compName[5], "rz ");
3328 */
3329   }
3330   if((compare(type,"FLUID",4)==4)||(compare(type,"VELO",4)==4))
3331   {
3332     strcpy ( lcasex[anzx->l].compName[0], "vx ");
3333     strcpy ( lcasex[anzx->l].compName[1], "vy ");
3334     strcpy ( lcasex[anzx->l].compName[2], "vz ");
3335   }
3336   do{
3337     length=abqrecord(rec_str);
3338     if(length==-1)
3339     {
3340       anzx->l++;
3341       if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
3342       { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3343       return(-1);
3344     }
3345     if(length==-2) break;
3346 
3347     crecord(rec_str, dat);
3348     nd=atoi(dat[0]);
3349     dof=atoi(dat[1]);
3350     f=atof(dat[2]);
3351 
3352     if((dof<1)||(dof>3))
3353     {
3354       printf("ERROR: In getInitialVector dof:%d at:%s not supported\n", dof,dat[0]);
3355       continue;
3356     }
3357 
3358     /* check if the node-number is 0, then a set was defined */
3359     if (nd==0)
3360     {
3361       nset=getSetNrx(dat[0]);
3362       if(nset<0)
3363       {
3364         printf("ERROR: In getInitialVector set:%s not defined\n", dat[0]);
3365         return(-1);
3366       }
3367       foundLoads=1;
3368       for(j=0; j<setx[nset].anz_n; j++)
3369       {
3370         writeNodeVals(anzx->l, setx[nset].node[j], f, dof-1);
3371       }
3372     }
3373     else
3374     {
3375       foundLoads=1;
3376       writeNodeVals(anzx->l, nd, f, dof-1);
3377     }
3378 
3379     if(copyFlag)
3380     {
3381       /* write to equ-file */
3382       for (n=0; n<SEGMENTS; n++)
3383         fprintf(handle_equ, "%d, %d, %lf\n", nd+(n*NODE_OFFSET), dof, f);
3384     }
3385     /* write in ansys format */
3386     if(ansFlag)
3387     {
3388       // TBD
3389 	;
3390     }
3391   }while(1);
3392   if(foundLoads)
3393   {
3394     anzx->l++;
3395     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
3396     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3397   }
3398   return(1);
3399 }
3400 
3401 
3402 
getCload(char * rec_str)3403 int getCload(char *rec_str)
3404 {
3405   int i,j,k,n;
3406   int length, nd, dof, foundLoads=0,nset=0,args;
3407   double f;
3408   static int setNr[7]={0,0,0,0,0,0,0};
3409   int ncur=0;
3410   static int *nclo=NULL;
3411   double csab[6];
3412   static int sector;
3413   static char **dat=NULL;
3414   static int local_step_nr=0, anzx_l;
3415 
3416   /* reset all static variables */
3417   if(resetFlag)
3418   {
3419     for(i=0; i<7; i++) setNr[i]=0;
3420     sector=0;
3421     local_step_nr=0;
3422     anzx_l=0;
3423     return(0);
3424   }
3425 
3426   if(printFlag) printf("%s\n",rec_str);
3427   /* scan the properties and write to file */
3428 
3429   /* get the arguments of the string */
3430   if((dat = (char **)realloc((char **)dat, (80)*sizeof(char*)))==NULL)
3431     errMsg("\n\n ERROR: realloc failed for **dat\n" );
3432     for (i=0; i<80; i++)
3433     {
3434       dat[i]=NULL;
3435       if((dat[i] = (char *)realloc((char *)dat[i], (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
3436         errMsg("\n\n ERROR: realloc failed for *dat\n" );
3437     }
3438   args=crecord(rec_str, dat);
3439   for(i=0; i<args; i++)
3440   {
3441     /* delete blanks */
3442     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
3443     buffer[n]='\0';
3444     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
3445     if(compare(dat[i],"SECTOR=",6)==6)
3446     {
3447       /* data for a new sector, create a new dataset */
3448       local_step_nr=0;
3449       sector=atoi(&dat[i][7]);
3450     }
3451   }
3452 
3453   /* create a dataset if a new step beginns */
3454   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); local_step_nr=-1; step_flag=1; }
3455   if(step_nr>local_step_nr)
3456   {
3457     local_step_nr=step_nr;
3458 
3459     /* ini lcasex, one for forces, one for moments */
3460 
3461     /* forces */
3462     if(sector) sprintf( lcasex[anzx->l].name,"%s%d", CLO, sector);
3463     else sprintf( lcasex[anzx->l].name,"%s", CLO);
3464     printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
3465     lcasex[anzx->l].value=0;
3466     lcasex[anzx->l].ncomps=3;
3467     lcasex[anzx->l].irtype=1;
3468     lcasex[anzx->l].npheader=0;
3469 
3470     strcpy(lcasex[anzx->l].analysis_name,"");
3471     sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
3472     strcpy(lcasex[anzx->l].dataset_text,"");
3473     lcasex[anzx->l].step_number=step_nr;
3474     lcasex[anzx->l].analysis_type=1;
3475 
3476     if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3477       printf("\n\n ERROR: malloc failure\n\n" );
3478     if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3479       printf("\n\n ERROR: malloc failure\n\n" );
3480     if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3481       printf("\n\n ERROR: malloc failure\n\n" );
3482     if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3483       printf("\n\n ERROR: malloc failure\n\n" );
3484     if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
3485       printf("\n\n ERROR: malloc failure\n\n" );
3486     if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3487       printf("\n\n ERROR: malloc failure\n\n" );
3488     if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3489       printf("\n\n ERROR: malloc failure\n\n" );
3490     if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3491       printf("\n\n ERROR: malloc failure\n\n" );
3492     if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3493       printf("\n\n ERROR: malloc failure\n\n" );
3494     if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3495       printf("\n\n ERROR: malloc failure\n\n" );
3496     if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3497       printf("\n\n ERROR: malloc failure\n\n" );
3498     if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3499       printf("\n\n ERROR: malloc failure\n\n" );
3500 
3501     for(i=0; i<lcasex[anzx->l].ncomps; i++)
3502     {
3503       if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
3504         printf("\n\n ERROR: malloc failure\n\n" );
3505       if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3506         printf("\n\n ERROR: malloc failed\n\n" );
3507       if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3508         printf("\n\n ERROR: malloc failed\n\n" );
3509       lcasex[anzx->l].max[i]=-MAX_FLOAT;
3510       lcasex[anzx->l].min[i]=MAX_FLOAT;
3511 
3512       lcasex[anzx->l].menu[i] = 1;
3513       lcasex[anzx->l].ictype[i] = 2;
3514       lcasex[anzx->l].icind1[i] = i+1;
3515       lcasex[anzx->l].icind2[i] = 0;
3516       lcasex[anzx->l].iexist[i] = 0;
3517     }
3518 
3519     strcpy ( lcasex[anzx->l].compName[0], "fx ");
3520     strcpy ( lcasex[anzx->l].compName[1], "fy ");
3521     strcpy ( lcasex[anzx->l].compName[2], "fz ");
3522     anzx->l++;
3523     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+3) * sizeof(Datasets))) == NULL )
3524     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3525 
3526     /* Moments */
3527     if(sector) sprintf( lcasex[anzx->l].name,"%s%d", CLO, sector);
3528     else sprintf( lcasex[anzx->l].name,"%s", CLO);
3529     printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
3530     lcasex[anzx->l].ncomps=3;
3531     lcasex[anzx->l].irtype=1;
3532     lcasex[anzx->l].npheader=0;
3533 
3534     strcpy(lcasex[anzx->l].analysis_name,"");
3535     sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
3536     strcpy(lcasex[anzx->l].dataset_text,"");
3537     lcasex[anzx->l].step_number=step_nr;
3538     lcasex[anzx->l].analysis_type=1;
3539 
3540     if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3541       printf("\n\n ERROR: malloc failure\n\n" );
3542     if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3543       printf("\n\n ERROR: malloc failure\n\n" );
3544     if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3545       printf("\n\n ERROR: malloc failure\n\n" );
3546     if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3547       printf("\n\n ERROR: malloc failure\n\n" );
3548     if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
3549       printf("\n\n ERROR: malloc failure\n\n" );
3550     if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3551       printf("\n\n ERROR: malloc failure\n\n" );
3552     if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3553       printf("\n\n ERROR: malloc failure\n\n" );
3554     if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3555       printf("\n\n ERROR: malloc failure\n\n" );
3556     if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3557       printf("\n\n ERROR: malloc failure\n\n" );
3558     if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3559       printf("\n\n ERROR: malloc failure\n\n" );
3560     if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3561       printf("\n\n ERROR: malloc failure\n\n" );
3562     if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3563       printf("\n\n ERROR: malloc failure\n\n" );
3564 
3565     for(i=0; i<lcasex[anzx->l].ncomps; i++)
3566     {
3567       if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
3568         printf("\n\n ERROR: malloc failure\n\n" );
3569       if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3570         printf("\n\n ERROR: malloc failed\n\n" );
3571       if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3572         printf("\n\n ERROR: malloc failed\n\n" );
3573       lcasex[anzx->l].max[i]=-MAX_FLOAT;
3574       lcasex[anzx->l].min[i]=MAX_FLOAT;
3575 
3576       lcasex[anzx->l].menu[i] = 1;
3577       lcasex[anzx->l].ictype[i] = 2;
3578       lcasex[anzx->l].icind1[i] = i+1;
3579       lcasex[anzx->l].icind2[i] = 0;
3580       lcasex[anzx->l].iexist[i] = 0;
3581     }
3582 
3583     strcpy ( lcasex[anzx->l].compName[0], "mx ");
3584     strcpy ( lcasex[anzx->l].compName[1], "my ");
3585     strcpy ( lcasex[anzx->l].compName[2], "mz ");
3586 
3587     anzx_l=anzx->l;
3588 
3589     anzx->l++;
3590     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+3) * sizeof(Datasets))) == NULL )
3591     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3592   }
3593 
3594   do{
3595     length=abqrecord(rec_str);
3596     if(length==-1) return(-1);
3597     if(length==-2) break;
3598 
3599     args=crecord(rec_str, dat);
3600     nd=atoi(dat[0]);
3601     dof=atoi(dat[1]);
3602     if(args>2) f=atof(dat[2]); else f=0.;
3603 
3604     if((dof<1)||(dof>6))
3605     {
3606       printf("ERROR: In *CLOAD dof:%d not known\n", dof);
3607       return(-1);
3608     }
3609 
3610     /* check if the node-number is 0, then a set was defined */
3611     if (nd==0)
3612     {
3613       nset=getSetNrx(dat[0]);
3614       if(nset<0)
3615       {
3616         printf("ERROR: In *CLOAD set:%s not defined\n", dat[0]);
3617         return(-1);
3618       }
3619       foundLoads=1;
3620       if((nclo=(int *)realloc((int *)nclo, (ncur+setx[nset].anz_n+1)*sizeof(int)) )==NULL)
3621       {  printf("\n\n ERROR: realloc failure\n\n" ); return(-1); }
3622       for(j=0; j<setx[nset].anz_n; j++)
3623       {
3624         if(!setNr[0])
3625         {
3626           setNr[0]=pre_setax( CLO, "i", 0);
3627         }
3628         if(!setNr[dof])
3629         {
3630           sprintf(buffer,"%s%d", CLO, dof);
3631           setNr[dof]=pre_setax( buffer, "i", 0);
3632         }
3633         nclo[ncur++]=setx[nset].node[j];
3634         setax(setNr[0], "n", setx[nset].node[j]);
3635         setax(setNr[dof], "n", setx[nset].node[j]);
3636 
3637         /* cloads must sum up on each node! */
3638         if(dof<4)
3639         {
3640           writeNodeVals(anzx_l-1, setx[nset].node[j], lcasex[anzx_l-1].dat[dof-1][nd]+f, dof-1);
3641 	}
3642         else
3643 	{
3644           writeNodeVals(anzx_l, setx[nset].node[j], lcasex[anzx_l].dat[dof-4][nd]+f, dof-4);
3645 	}
3646       }
3647     }
3648     else
3649     {
3650       foundLoads=1;
3651       if(!setNr[0])
3652       {
3653         setNr[0]=pre_setax( CLO, "i", 0);
3654       }
3655       if(!setNr[dof])
3656       {
3657         sprintf(buffer,"%s%d", CLO, dof);
3658         setNr[dof]=pre_setax( buffer, "i", 0);
3659       }
3660       if((nclo=(int *)realloc((int *)nclo, (ncur+2)*sizeof(int)) )==NULL)
3661       {  printf("\n\n ERROR: realloc failure\n\n" ); return(-1); }
3662       nclo[ncur++]=nd;
3663       setax(setNr[0], "n", nd);
3664       setax(setNr[dof], "n", nd);
3665 
3666       /* cloads must sum up on each node! */
3667       if(dof<4) writeNodeVals(anzx_l-1,nd,  lcasex[anzx_l-1].dat[dof-1][nd]+f, dof-1);
3668       else
3669       {
3670         writeNodeVals(anzx_l,nd,  lcasex[anzx_l].dat[dof-4][nd]+f, dof-4);
3671       }
3672     }
3673 
3674     if(copyFlag)
3675     {
3676       /* write to equ-file */
3677       for (n=0; n<SEGMENTS; n++)
3678         fprintf(handle_equ, "%d, %d, %lf\n", nd+(n*NODE_OFFSET), dof, f);
3679     }
3680     /* write in ansys format */
3681     if(ansFlag)
3682     {
3683       if ((dof<1)||(dof>6)) errMsg ("ERROR dof:%d not known\n", dof);
3684       else fprintf(handleans, "F,%d, %s, %lf\n", nd, ansys_frc[dof-1], f);
3685     }
3686   }while(1);
3687 
3688   if(foundLoads)
3689   {
3690     /* if the nodes were assigned previously to a cyl-sys, values have to be transformed */
3691 
3692     /* all nodenrs have to be uniqe */
3693     qsort( nclo, ncur, sizeof(int), (void *)compareInt );
3694     i=0;
3695     for(j=1; j<ncur; j++)
3696     {
3697       if(nclo[i]!=nclo[j]) nclo[++i]=nclo[j];
3698     }
3699     ncur=i+1;
3700 
3701     for(j=0; j<ncur; j++)
3702     {
3703       for(i=anzx->sets-1; i>-1; i--)
3704       {
3705         if((setx[i].name!=NULL)&&(compare(setx[i].name, "+transC",7)==7))
3706         {
3707           if( getIndex(&setx[i].node,setx[i].anz_n,nclo[j]) >-1)
3708           {
3709 	    //printf("set[%d]:%s n[%d]:%d\n", i, setx[i].name, j, nclo[j]);
3710             /* transform from cylindrical to cartesian coordinate */
3711             args=crecord(&setx[i].name[7], dat);
3712             for (k=0; k<6; k++) csab[k]=atof(dat[k]);
3713             rectcyl(-1, csab, nclo[j], nodex, lcasex, anzx_l-1, 'd');
3714             rectcyl(-1, csab, nclo[j], nodex, lcasex, anzx_l, 'd');
3715             break;
3716           }
3717         }
3718       }
3719     }
3720     free(nclo);
3721     nclo=NULL;
3722 
3723     /* get new max min */
3724     calcMaxMinValues(anzx_l-1);
3725     calcMaxMinValues(anzx_l);
3726   }
3727   return(1);
3728 }
3729 
3730 
getCflux(char * rec_str)3731 int getCflux(char *rec_str)
3732 {
3733   int i,j;
3734   int length, nd, dof, nset, args;
3735   double f;
3736   static int setNr[7]={0,0,0,0,0,0,0};
3737   static int local_step_nr=0, anzx_l;
3738 
3739   /* reset all static variables */
3740   if(resetFlag)
3741   {
3742     for(i=0; i<7; i++) setNr[i]=0;
3743     local_step_nr=0;
3744     anzx_l=0;
3745     return(0);
3746   }
3747 
3748   if(printFlag) printf("%s\n",rec_str);
3749   /* scan the properties and write to file */
3750 
3751   /* create a dataset if a new step beginns */
3752   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
3753   else if(step_nr>local_step_nr)
3754   {
3755     local_step_nr=step_nr;
3756     /* ini lcasex */
3757     sprintf( lcasex[anzx->l].name,"%s", CFLX);
3758     printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
3759     lcasex[anzx->l].value=0;
3760     lcasex[anzx->l].ncomps=1;
3761     lcasex[anzx->l].irtype=1;
3762     lcasex[anzx->l].npheader=0;
3763 
3764     strcpy(lcasex[anzx->l].analysis_name,"");
3765     sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
3766     strcpy(lcasex[anzx->l].dataset_text,"");
3767     lcasex[anzx->l].step_number=step_nr;
3768     lcasex[anzx->l].analysis_type=1;
3769 
3770     if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3771       printf("\n\n ERROR: malloc failure\n\n" );
3772     if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3773       printf("\n\n ERROR: malloc failure\n\n" );
3774     if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3775       printf("\n\n ERROR: malloc failure\n\n" );
3776     if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
3777       printf("\n\n ERROR: malloc failure\n\n" );
3778     if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
3779       printf("\n\n ERROR: malloc failure\n\n" );
3780     if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3781       printf("\n\n ERROR: malloc failure\n\n" );
3782     if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
3783       printf("\n\n ERROR: malloc failure\n\n" );
3784     if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3785       printf("\n\n ERROR: malloc failure\n\n" );
3786     if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3787       printf("\n\n ERROR: malloc failure\n\n" );
3788     if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3789       printf("\n\n ERROR: malloc failure\n\n" );
3790     if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3791       printf("\n\n ERROR: malloc failure\n\n" );
3792     if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
3793       printf("\n\n ERROR: malloc failure\n\n" );
3794 
3795     for(i=0; i<lcasex[anzx->l].ncomps; i++)
3796     {
3797       if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
3798         printf("\n\n ERROR: malloc failure\n\n" );
3799       if ( (lcasex[anzx->l].compName[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3800         printf("\n\n ERROR: malloc failed\n\n" );
3801       if ( (lcasex[anzx->l].icname[i] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
3802         printf("\n\n ERROR: malloc failed\n\n" );
3803       lcasex[anzx->l].max[i]=-MAX_FLOAT;
3804       lcasex[anzx->l].min[i]=MAX_FLOAT;
3805 
3806       lcasex[anzx->l].menu[i] = 1;
3807       lcasex[anzx->l].ictype[i] = 1;
3808       lcasex[anzx->l].icind1[i] = i+1;
3809       lcasex[anzx->l].icind2[i] = 0;
3810       lcasex[anzx->l].iexist[i] = 0;
3811     }
3812 
3813     strcpy ( lcasex[anzx->l].compName[0], "flux");
3814 
3815     anzx_l=anzx->l;
3816 
3817     anzx->l++;
3818     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
3819     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
3820   }
3821 
3822   do{
3823     length=abqrecord(rec_str);
3824     if(length==-1) return(-1);
3825     if(length==-2) break;
3826 
3827     args=crecord(rec_str, dat);
3828     nd=atoi(dat[0]);
3829     dof=0;
3830     if(args>2) f=atof(dat[2]); else f=0.;
3831 
3832     /* check if the node-number is 0, then a set was defined */
3833     if (nd==0)
3834     {
3835       nset=getSetNrx(dat[0]);
3836       if(nset<0)
3837       {
3838         printf("ERROR: In *CFLUX set:%s not defined\n", dat[0]);
3839         return(-1);
3840       }
3841       for(j=0; j<setx[nset].anz_n; j++)
3842       {
3843         if(!setNr[0])
3844         {
3845           setNr[0]=pre_setax( CFLX, "i", 0);
3846         }
3847         setax(setNr[0], "n", setx[nset].node[j]);
3848         /* cflux must sum up on each node! */
3849         writeNodeVals(anzx_l, setx[nset].node[j], lcasex[anzx_l].dat[dof][nd]+f, dof);
3850       }
3851     }
3852     else
3853     {
3854       if(!setNr[0])
3855       {
3856         setNr[0]=pre_setax( CFLX, "i", 0);
3857       }
3858       setax(setNr[0], "n", nd);
3859       /* cflux must sum up on each node! */
3860       writeNodeVals(anzx_l, nd, lcasex[anzx_l].dat[dof][nd]+f, dof);
3861     }
3862 
3863     /* write in ansys format */
3864     if(ansFlag)
3865     {
3866 	printf("ERROR: CFLUX for ansys not yet supported\n");
3867     }
3868   }while(1);
3869   return(1);
3870 }
3871 
3872 
3873 
3874 /* type 0:dload type 1:dsload */
getDload(char * rec_str,int type)3875 int getDload(char *rec_str, int type)
3876 {
3877   int j,i,n;
3878   int length, el, sum_e,args,face;
3879   int setNr, eset;
3880   static int created_ds=0;
3881   static int sector;
3882   float vals[1];
3883   static char **dat=NULL;
3884   static int local_step_nr=0, anzx_l;
3885   char setname[MAX_LINE_LENGTH];
3886 
3887   /* reset all static variables */
3888   if(resetFlag)
3889   {
3890     sector=0;
3891     local_step_nr=0;
3892     anzx_l=0;
3893     return(0);
3894   }
3895 
3896   if(printFlag) printf("%s\n",rec_str);
3897 
3898   /* scan the properties and write to file */
3899 
3900   /* get the arguments of the string */
3901   if((dat = (char **)realloc((char **)dat, (80)*sizeof(char*)))==NULL)
3902     errMsg("\n\n ERROR: realloc failed for **dat\n" );
3903   for (i=0; i<80; i++)
3904   {
3905     dat[i]=NULL;
3906     if((dat[i] = (char *)realloc((char *)dat[i], (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
3907       errMsg("\n\n ERROR: realloc failed for *dat\n" );
3908   }
3909   args=crecord(rec_str, dat);
3910 
3911   sprintf(setname,"%s_ds",DLO);
3912   for(i=0; i<args; i++)
3913   {
3914     /* delete blanks */
3915     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
3916     buffer[n]='\0';
3917     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
3918     if(compare(dat[i],"SECTOR=",6)==6)
3919     {
3920       /* data for a new sector, create a new dataset */
3921       local_step_nr=0;
3922       sector=atoi(&dat[i][7]);
3923       sprintf(setname,"%s_s%d_ds",DLO, sector);
3924     }
3925     if(compare(dat[i],"SUBMODEL",6)==6) { sprintf(setname,"%s_SubmSt_ds",DLO); type=2; }
3926     if(compare(dat[i],"STEP",4)==4) vals[0]=atoi(&dat[i][5]);
3927   }
3928 
3929   /* create a dataset if a new step beginns */
3930   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
3931   else if(step_nr>local_step_nr)
3932   {
3933     /* ini lcasex */
3934     anzx_l=anzx->l;
3935     created_ds=1;
3936   }
3937 
3938   /* store the datasetNr in the setname. this will be used later to fill the dataset in generateNodeValuesFromFaces() */
3939   sprintf(&setname[strlen(setname)],"%d", anzx_l);
3940   setNr=getSetNrx(setname);
3941   if(setNr<0)
3942   {
3943     setNr=pre_setax( setname, "i", 0);
3944   }
3945 
3946   do{
3947     length=abqrecord(rec_str);
3948     if(length==-1) return(-1);
3949     if(length==-2) break;
3950 
3951     crecord(rec_str, dat);
3952 
3953     /* check if it is a face load */
3954     if((toupper(dat[1][0])=='P')||(toupper(dat[1][0])=='E'))
3955     {
3956       if(type!=1)
3957       {
3958         if(toupper(dat[1][0])=='E') face=(int)atoi(&dat[1][5])+1;
3959         else face=(int)atoi(&dat[1][1])-1;
3960         eset=getSetNrx(dat[0]);
3961         if (eset>-1) sum_e=setx[eset].anz_e;
3962         else sum_e=1;
3963         if(!type) vals[0]=atof(dat[2]);
3964       }
3965       else
3966       {
3967         eset=getSetNrx(dat[0]);
3968         if (eset>-1) sum_e=setx[eset].anz_elf;
3969         else break;
3970         vals[0]=atof(dat[2]);
3971       }
3972 
3973       for(j=0; j<sum_e; j++)
3974       {
3975         if(type!=1)
3976         {
3977           if(eset>-1) el=setx[eset].elem[j];
3978           else el=atoi(dat[0]);
3979 	}
3980         else
3981         {
3982           el=setx[eset].elf[j].e;
3983           face=setx[eset].elf[j].f;
3984 	}
3985         if((el<anzx->emin)||(el>anzx->emax)) { printf("elem:%d does not exist\n",el); continue;}
3986         if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
3987         {
3988            if(e_enqirex[el].attr>3)
3989            {
3990              if(e_enqirex[el].type<9)
3991   	     {
3992                if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
3993                else face+=1;
3994   	     }
3995              else
3996   	     {
3997                if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
3998                else face+=1;
3999   	     }
4000            }
4001            else
4002            {
4003              if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
4004            }
4005         }
4006 
4007         /* check if the face-number is 0, then an eset is defined */
4008         if(face>=0)
4009         {
4010           i=setax(setNr,"j",1);
4011           if(i>-1)
4012           {
4013             setx[setNr].elf[i].e=el;
4014             setx[setNr].elf[i].f=face;
4015             setx[setNr].elf[i].v[0]=vals[0];
4016           }
4017         }
4018 
4019         /* write in ansys format */
4020         if(ansFlag)
4021         {
4022           errMsg ("ERROR dload not supported\n");
4023         }
4024       }
4025     }
4026   }while(1);
4027 
4028   /* activate a new dataset only if data are stored */
4029   if(created_ds)
4030   {
4031     if(setx[setNr].anz_elf)
4032     {
4033       if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
4034       { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
4035       lcasex[anzx->l].step_number=step_nr;
4036       anzx->l++;
4037       created_ds=0;
4038       local_step_nr=step_nr;
4039     }
4040   }
4041 
4042   return(1);
4043 }
4044 
4045 
getDflux(char * rec_str)4046 int getDflux(char *rec_str)
4047 {
4048   int j,i;
4049   int length, el, sum_e, face;
4050   int setNr, eset;
4051   static int created_ds=0;
4052   float vals[1];
4053   static int local_step_nr=0, anzx_l;
4054   char setname[MAX_LINE_LENGTH];
4055 
4056   /* reset all static variables */
4057   if(resetFlag)
4058   {
4059     local_step_nr=0;
4060     anzx_l=0;
4061     return(0);
4062   }
4063 
4064 
4065   if(printFlag) printf("%s\n",rec_str);
4066 
4067   /* scan the properties and write to file */
4068   sprintf(setname,"%s_ds",DFLX);
4069 
4070   /* create a dataset if a new step beginns */
4071   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
4072   else if(step_nr>local_step_nr)
4073   {
4074     /* ini lcasex */
4075     anzx_l=anzx->l;
4076     created_ds=1;
4077   }
4078 
4079   /* store the datasetNr in the setname. this will be used later to fill the dataset in generateNodeValuesFromFaces() */
4080   sprintf(&setname[strlen(setname)],"%d", anzx_l);
4081   setNr=getSetNrx(setname);
4082   if(setNr<0)
4083   {
4084     setNr=pre_setax( setname, "i", 0);
4085   }
4086 
4087   do{
4088     length=abqrecord(rec_str);
4089     if(length==-1) return(-1);
4090     if(length==-2) break;
4091 
4092     crecord(rec_str, dat);
4093 
4094     /* check if it is a face load */
4095     if(toupper(dat[1][0])=='S')
4096     {
4097       face=(int)atoi(&dat[1][1])-1;
4098 
4099       eset=getSetNrx(dat[0]);
4100       if (eset>-1) sum_e=setx[eset].anz_e;
4101       else sum_e=1;
4102       for(j=0; j<sum_e; j++)
4103       {
4104         if(eset>-1) el=setx[eset].elem[j];
4105         else el=atoi(dat[0]);
4106 
4107         if((el<anzx->emin)||(el>anzx->emax)) { printf("elem:%d does not exist\n",el); continue;}
4108         if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
4109         {
4110            if(e_enqirex[el].attr>3)
4111            {
4112              if(e_enqirex[el].type<9)
4113   	   {
4114                if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
4115                else face+=1;
4116   	   }
4117              else
4118   	   {
4119                if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
4120                else face+=1;
4121   	   }
4122            }
4123            else
4124            {
4125              if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
4126            }
4127         }
4128         vals[0]=atof(dat[2]);
4129 
4130         /* check if the node-number is 0, then an eset is defined */
4131         if(face>=0)
4132         {
4133           i=setax(setNr,"j",1);
4134           if(i>-1)
4135           {
4136             setx[setNr].elf[i].e=el;
4137             setx[setNr].elf[i].f=face;
4138             setx[setNr].elf[i].v[0]=vals[0];
4139           }
4140         }
4141 
4142         /* write in ansys format */
4143         if(ansFlag)
4144         {
4145           errMsg ("ERROR dflux not supported\n");
4146         }
4147       }
4148     }
4149   }while(1);
4150 
4151   /* activate a new dataset only if data are stored */
4152   if(created_ds)
4153   {
4154     if(setx[setNr].anz_elf)
4155     {
4156       if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
4157       { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
4158       lcasex[anzx->l].step_number=step_nr;
4159       anzx->l++;
4160       created_ds=0;
4161       local_step_nr=step_nr;
4162     }
4163   }
4164 
4165   return(1);
4166 }
4167 
4168 
4169 
getMassflow(char * rec_str)4170 int getMassflow(char *rec_str)
4171 {
4172   int j,i;
4173   int length, el, sum_e,face;
4174   int setNr, eset;
4175   static int created_ds=0;
4176   float vals[1];
4177   static int local_step_nr=0, anzx_l;
4178   char setname[MAX_LINE_LENGTH];
4179 
4180   /* reset all static variables */
4181   if(resetFlag)
4182   {
4183     local_step_nr=0;
4184     anzx_l=0;
4185     return(0);
4186   }
4187 
4188 
4189   if(printFlag) printf("%s\n",rec_str);
4190 
4191   /* scan the properties and write to file */
4192   sprintf(setname,"%s_ds",MFLW);
4193 
4194   /* create a dataset if a new step beginns */
4195   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
4196   else if(step_nr>local_step_nr)
4197   {
4198     /* ini lcasex */
4199     anzx_l=anzx->l;
4200     created_ds=1;
4201   }
4202 
4203   /* store the datasetNr in the setname. this will be used later to fill the dataset in generateNodeValuesFromFaces() */
4204   sprintf(&setname[strlen(setname)],"%d", anzx_l);
4205   setNr=getSetNrx(setname);
4206   if(setNr<0)
4207   {
4208     setNr=pre_setax( setname, "i", 0);
4209   }
4210 
4211 
4212   do{
4213     length=abqrecord(rec_str);
4214     if(length==-1) return(-1);
4215     if(length==-2) break;
4216 
4217     crecord(rec_str, dat);
4218 
4219     /* check if it is a face load */
4220     if(toupper(dat[1][0])=='M')
4221     {
4222       face=(int)atoi(&dat[1][1])-1;
4223 
4224       eset=getSetNrx(dat[0]);
4225 
4226       /* the set could already store faces instead of elements */
4227       if (eset>-1) { sum_e=setx[eset].anz_e; if(!sum_e) sum_e=setx[eset].anz_elf; }
4228       else sum_e=1;
4229       for(j=0; j<sum_e; j++)
4230       {
4231         if((eset>-1)&&(setx[eset].anz_e)) el=setx[eset].elem[j];
4232         else if((eset>-1)&&(setx[eset].anz_elf)) { el=setx[eset].elf[j].e; face=setx[eset].elf[j].f; goto jumpFaceM; }
4233         else el=atoi(dat[0]);
4234 
4235         if((el<anzx->emin)||(el>anzx->emax)) { printf("elem:%d does not exist\n",el); continue;}
4236         if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
4237         {
4238            if(e_enqirex[el].attr>3)
4239            {
4240              if(e_enqirex[el].type<9)
4241   	     {
4242                if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
4243                else face+=1;
4244   	     }
4245              else
4246   	     {
4247                if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
4248                else face+=1;
4249   	     }
4250            }
4251            else
4252            {
4253              if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
4254            }
4255         }
4256     jumpFaceM:;
4257         vals[0]=atof(dat[2]);
4258 
4259         /* check if the node-number is 0, then an eset is defined */
4260         if(face>=0)
4261         {
4262           i=setax(setNr,"j",1);
4263           if(i>-1)
4264           {
4265             setx[setNr].elf[i].e=el;
4266             setx[setNr].elf[i].f=face;
4267             setx[setNr].elf[i].v[0]=vals[0];
4268           }
4269         }
4270 
4271         /* write in ansys format */
4272         if(ansFlag)
4273         {
4274           errMsg ("ERROR massflow not supported\n");
4275         }
4276       }
4277     }
4278   }while(1);
4279 
4280   /* activate a new dataset only if data are stored */
4281   if(created_ds)
4282   {
4283     if(setx[setNr].anz_elf)
4284     {
4285       if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
4286       { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
4287       lcasex[anzx->l].step_number=step_nr;
4288       anzx->l++;
4289       created_ds=0;
4290       local_step_nr=step_nr;
4291     }
4292   }
4293 
4294   return(1);
4295 }
4296 
4297 
getRadiation(char * rec_str)4298 int getRadiation(char *rec_str)
4299 {
4300   int j,i,n;
4301   int length, el, sum_e, args, face;
4302   int setNr, eset;
4303   int firstTimeFlag=1;
4304   float vals[2];
4305   static char **dat=NULL;
4306   static int local_step_nr=0, anzx_l;
4307   char setname[MAX_LINE_LENGTH];
4308 
4309   /* reset all static variables */
4310   if(resetFlag)
4311   {
4312     local_step_nr=0;
4313     anzx_l=0;
4314     return(0);
4315   }
4316 
4317   if(printFlag) printf("%s\n",rec_str);
4318 
4319   /* scan the properties and write to file */
4320 
4321   /* get the arguments of the string */
4322   if((dat = (char **)realloc((char **)dat, (80)*sizeof(char*)))==NULL)
4323     errMsg("\n\n ERROR: realloc failed for **dat\n" );
4324   for (i=0; i<80; i++)
4325   {
4326     dat[i]=NULL;
4327     if((dat[i] = (char *)realloc((char *)dat[i], (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
4328       errMsg("\n\n ERROR: realloc failed for *dat\n" );
4329   }
4330   args=crecord(rec_str, dat);
4331 
4332   sprintf(setname,"%s_stp%d",RAD, step_nr);
4333   for(i=0; i<args; i++)
4334   {
4335     /* delete blanks */
4336     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
4337     buffer[n]='\0';
4338     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
4339     if(compare(dat[i],"CAVITY=",6)==6) sprintf(setname,"%s_stp%d_cav:%s",RAD, step_nr, &dat[i][7]);
4340   }
4341   setNr=getSetNrx(setname);
4342   if(setNr<0)
4343   {
4344     setNr=pre_setax( setname, "i", 0);
4345   }
4346 
4347   /* create a dataset if a new step beginns */
4348   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
4349   else if(step_nr>local_step_nr)
4350   {
4351     local_step_nr=step_nr;
4352     /* ini lcasex */
4353     sprintf( lcasex[anzx->l].name,"%s", RAD);
4354     printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
4355     lcasex[anzx->l].ncomps=3;
4356     lcasex[anzx->l].irtype=1;
4357     lcasex[anzx->l].npheader=0;
4358 
4359     lcasex[anzx->l].value=0;
4360     strcpy(lcasex[anzx->l].analysis_name,"");
4361     sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
4362     strcpy(lcasex[anzx->l].dataset_text,"");
4363     lcasex[anzx->l].step_number=step_nr;
4364     lcasex[anzx->l].analysis_type=1;
4365 
4366     if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4367       printf("\n\n ERROR: malloc failure\n\n" );
4368     if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4369       printf("\n\n ERROR: malloc failure\n\n" );
4370     if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
4371       printf("\n\n ERROR: malloc failure\n\n" );
4372     if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
4373       printf("\n\n ERROR: malloc failure\n\n" );
4374     if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
4375       printf("\n\n ERROR: malloc failure\n\n" );
4376     if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
4377       printf("\n\n ERROR: malloc failure\n\n" );
4378     if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
4379       printf("\n\n ERROR: malloc failure\n\n" );
4380     if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4381       printf("\n\n ERROR: malloc failure\n\n" );
4382     if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4383       printf("\n\n ERROR: malloc failure\n\n" );
4384     if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4385       printf("\n\n ERROR: malloc failure\n\n" );
4386     if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4387       printf("\n\n ERROR: malloc failure\n\n" );
4388     if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4389       printf("\n\n ERROR: malloc failure\n\n" );
4390 
4391     for(i=0; i<lcasex[anzx->l].ncomps; i++)
4392     {
4393       if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
4394         printf("\n\n ERROR: malloc failure\n\n" );
4395       if ( (lcasex[anzx->l].compName[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
4396         printf("\n\n ERROR: malloc failed\n\n" );
4397       if ( (lcasex[anzx->l].icname[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
4398         printf("\n\n ERROR: malloc failed\n\n" );
4399       lcasex[anzx->l].max[i]=-MAX_FLOAT;
4400       lcasex[anzx->l].min[i]=MAX_FLOAT;
4401       for(j=0; j<=anzx->nmax; j++) lcasex[anzx->l].dat[i][j]=0.;
4402 
4403       lcasex[anzx->l].menu[i] = 1;
4404       lcasex[anzx->l].ictype[i] = 1;
4405       lcasex[anzx->l].icind1[i] = i+1;
4406       lcasex[anzx->l].icind2[i] = 0;
4407       lcasex[anzx->l].iexist[i] = -2;
4408     }
4409     lcasex[anzx->l].iexist[2] = 0;
4410     strcpy ( lcasex[anzx->l].compName[0], "temp");
4411     strcpy ( lcasex[anzx->l].compName[1], "emis");
4412     strcpy ( lcasex[anzx->l].compName[2], "nodes");
4413     lcasex[anzx->l].menu[2] = 0;
4414 
4415     anzx_l=anzx->l;
4416 
4417     anzx->l++;
4418     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
4419     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
4420   }
4421 
4422   do{
4423     length=abqrecord(rec_str);
4424     if(length==-1) return(-1);
4425     if(length==-2) break;
4426 
4427     crecord(rec_str, dat);
4428     /* delete blanks and get face-nr */
4429     i=0; for(j=0;j<strlen(dat[1]); j++) if(dat[1][j]!=' ') { buffer[i]=dat[1][j]; i++; }
4430     buffer[i]='\0';
4431     face=atoi(&buffer[1])-1;
4432 
4433     eset=getSetNrx(dat[0]);
4434     if (eset>-1) sum_e=setx[eset].anz_e;
4435     else sum_e=1;
4436     for(j=0; j<sum_e; j++)
4437     {
4438       if(eset>-1) el=setx[eset].elem[j];
4439       else el=atoi(dat[0]);
4440 
4441       if((el<anzx->emin)||(el>anzx->emax)) { printf("elem:%d in *film does not exist\n",el); continue;}
4442       if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
4443       {
4444         if(e_enqirex[el].attr>3)
4445         {
4446           if(e_enqirex[el].type<9)
4447 	  {
4448             if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
4449             else face+=1;
4450 	  }
4451           else
4452 	  {
4453             if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
4454             else face+=1;
4455 	  }
4456         }
4457         else
4458         {
4459           if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
4460         }
4461       }
4462       if(face<0) printf(" ERROR, face from string:%s unknown\n", buffer);
4463       //snip1
4464 
4465       if(compare(&buffer[2],"CRNU", 4)==4)
4466       {
4467         vals[0]=-1;
4468         vals[1]=atof(&buffer[6]);
4469         if(firstTimeFlag)
4470         {
4471           strcpy ( lcasex[anzx_l].compName[0], "undef");
4472           strcpy ( lcasex[anzx_l].compName[1], "pattrn");
4473           strcpy ( lcasex[anzx_l].compName[2], "nodes");
4474           lcasex[anzx_l].value=vals[1];
4475         }
4476         else firstTimeFlag=0;
4477       }
4478       else if(compare(&buffer[2],"CR", 2)==2)
4479       {
4480         vals[0]=atof(dat[2]);
4481         vals[1]=atof(dat[3]);
4482         if(firstTimeFlag)
4483         {
4484           strcpy ( lcasex[anzx_l].compName[0], "temp");
4485           strcpy ( lcasex[anzx_l].compName[1], "emis");
4486           strcpy ( lcasex[anzx_l].compName[2], "nodes");
4487         }
4488         else firstTimeFlag=0;
4489       }
4490       else if(compare(&buffer[2],"NU", 2)==2)
4491       {
4492         vals[0]=-1.;
4493         vals[1]=atof(&buffer[6]);
4494         if(firstTimeFlag)
4495         {
4496           strcpy ( lcasex[anzx_l].compName[0], "undef");
4497           strcpy ( lcasex[anzx_l].compName[1], "pattrn");
4498           strcpy ( lcasex[anzx_l].compName[2], "nodes");
4499           lcasex[anzx_l].value=vals[1];
4500         }
4501         else firstTimeFlag=0;
4502       }
4503       else
4504       {
4505         vals[0]=atof(dat[2]);
4506         vals[1]=atof(dat[3]);
4507       }
4508 
4509       //snip2
4510       if(face>=0)
4511       {
4512         i=setax(setNr,"j",0);
4513         if(i>-1)
4514         {
4515           setx[setNr].elf[i].e=el;
4516           setx[setNr].elf[i].f=face;
4517         }
4518         writeFaceVals(anzx_l, el, face, 2, vals);
4519       }
4520 
4521       /* write in ansys format */
4522       if(ansFlag)
4523       {
4524         errMsg ("ERROR radiation not supported\n");
4525       }
4526     }
4527   }while(1);
4528   return(1);
4529 }
4530 
4531 
getFilm(char * rec_str)4532 int getFilm(char *rec_str)
4533 {
4534   int j,i;
4535   int length, el, sum_e, face;
4536   int setNr, eset;
4537   int firstTimeFlag=1;
4538   float vals[2];
4539   static int local_step_nr=0, anzx_l;
4540   char setname[MAX_LINE_LENGTH];
4541 
4542   /* reset all static variables */
4543   if(resetFlag)
4544   {
4545     local_step_nr=0;
4546     anzx_l=0;
4547     return(0);
4548   }
4549 
4550   if(printFlag) printf("%s\n",rec_str);
4551   /* scan the properties and write to file */
4552   sprintf(setname,"%s_stp%d",FLM, step_nr);
4553   setNr=getSetNrx(setname);
4554   if(setNr<0)
4555   {
4556     setNr=pre_setax( setname, "i", 0);
4557   }
4558 
4559   /* create a dataset if a new step beginns */
4560   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
4561   else if(step_nr>local_step_nr)
4562   {
4563     local_step_nr=step_nr;
4564     /* ini lcasex */
4565     sprintf( lcasex[anzx->l].name,"%s", FLM);
4566     printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
4567     lcasex[anzx->l].ncomps=3;
4568     lcasex[anzx->l].irtype=1;
4569     lcasex[anzx->l].npheader=0;
4570 
4571     lcasex[anzx->l].value=0;
4572     strcpy(lcasex[anzx->l].analysis_name,"");
4573     sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
4574     strcpy(lcasex[anzx->l].dataset_text,"");
4575     lcasex[anzx->l].step_number=step_nr;
4576     lcasex[anzx->l].analysis_type=1;
4577 
4578     if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4579       printf("\n\n ERROR: malloc failure\n\n" );
4580     if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4581       printf("\n\n ERROR: malloc failure\n\n" );
4582     if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
4583       printf("\n\n ERROR: malloc failure\n\n" );
4584     if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
4585       printf("\n\n ERROR: malloc failure\n\n" );
4586     if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
4587       printf("\n\n ERROR: malloc failure\n\n" );
4588     if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
4589       printf("\n\n ERROR: malloc failure\n\n" );
4590     if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
4591       printf("\n\n ERROR: malloc failure\n\n" );
4592     if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4593       printf("\n\n ERROR: malloc failure\n\n" );
4594     if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4595       printf("\n\n ERROR: malloc failure\n\n" );
4596     if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4597       printf("\n\n ERROR: malloc failure\n\n" );
4598     if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4599       printf("\n\n ERROR: malloc failure\n\n" );
4600     if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4601       printf("\n\n ERROR: malloc failure\n\n" );
4602 
4603     for(i=0; i<lcasex[anzx->l].ncomps; i++)
4604     {
4605       if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
4606         printf("\n\n ERROR: malloc failure\n\n" );
4607       if ( (lcasex[anzx->l].compName[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
4608         printf("\n\n ERROR: malloc failed\n\n" );
4609       if ( (lcasex[anzx->l].icname[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
4610         printf("\n\n ERROR: malloc failed\n\n" );
4611       lcasex[anzx->l].max[i]=-MAX_FLOAT;
4612       lcasex[anzx->l].min[i]=MAX_FLOAT;
4613       for(j=0; j<=anzx->nmax; j++) lcasex[anzx->l].dat[i][j]=0.;
4614       lcasex[anzx->l].menu[i] = 1;
4615       lcasex[anzx->l].ictype[i] = 1;
4616       lcasex[anzx->l].icind1[i] = i+1;
4617       lcasex[anzx->l].icind2[i] = 0;
4618       /* remember the component which stores the nr of summands */
4619       lcasex[anzx->l].iexist[i] = -2;
4620     }
4621     lcasex[anzx->l].iexist[2] = 0;
4622     strcpy ( lcasex[anzx->l].compName[0], "temp");
4623     strcpy ( lcasex[anzx->l].compName[1], "alpha");
4624     strcpy ( lcasex[anzx->l].compName[2], "nodes");
4625     lcasex[anzx->l].menu[2] = 0;
4626 
4627     anzx_l=anzx->l;
4628 
4629     anzx->l++;
4630     if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
4631     { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
4632   }
4633 
4634   do{
4635     length=abqrecord(rec_str);
4636     if(length==-1) return(-1);
4637     if(length==-2) break;
4638 
4639     crecord(rec_str, dat);
4640     /* delete blanks and get face-nr */
4641     i=0; for(j=0;j<strlen(dat[1]); j++) if(dat[1][j]!=' ') { buffer[i]=dat[1][j]; i++; }
4642     buffer[i]='\0';
4643     face=atoi(&buffer[1])-1;
4644 
4645     eset=getSetNrx(dat[0]);
4646     if (eset>-1) sum_e=setx[eset].anz_e;
4647     else sum_e=1;
4648     for(j=0; j<sum_e; j++)
4649     {
4650       if(eset>-1) el=setx[eset].elem[j];
4651       else el=atoi(dat[0]);
4652 
4653       if((el<anzx->emin)||(el>anzx->emax)) { printf("elem:%d in *film does not exist\n",el); continue;}
4654       if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
4655       {
4656         if(e_enqirex[el].attr>3)
4657         {
4658           if(e_enqirex[el].type<9)
4659 	  {
4660             if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
4661             else face+=1;
4662 	  }
4663           else
4664 	  {
4665             if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
4666             else face+=1;
4667 	  }
4668         }
4669         else
4670         {
4671           if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
4672         }
4673       }
4674       if(face<0) printf(" ERROR, face from string:%s unknown\n", buffer);
4675       if(compare(&buffer[2],"FCNU", 4)==4)
4676       {
4677         vals[0]=atof(dat[2]);
4678         vals[1]=atof(&buffer[6]);
4679         if(firstTimeFlag)
4680         {
4681           strcpy ( lcasex[anzx_l].compName[0], "refnod");
4682           strcpy ( lcasex[anzx_l].compName[1], "pattrn");
4683           strcpy ( lcasex[anzx_l].compName[2], "nodes");
4684           lcasex[anzx_l].value=vals[1];
4685         }
4686         else firstTimeFlag=0;
4687       }
4688       else if(compare(&buffer[2],"FC", 2)==2)
4689       {
4690         vals[0]=atof(dat[2]);
4691         vals[1]=atof(dat[3]);
4692         if(firstTimeFlag)
4693         {
4694           strcpy ( lcasex[anzx_l].compName[0], "refnod");
4695           strcpy ( lcasex[anzx_l].compName[1], "alpha");
4696           strcpy ( lcasex[anzx_l].compName[2], "nodes");
4697         }
4698         else firstTimeFlag=0;
4699       }
4700       else if(compare(&buffer[2],"NU", 2)==2)
4701       {
4702         vals[0]=-1.;
4703         vals[1]=atof(&buffer[6]);
4704         if(firstTimeFlag)
4705         {
4706           strcpy ( lcasex[anzx_l].compName[0], "undef");
4707           strcpy ( lcasex[anzx_l].compName[1], "pattrn");
4708           strcpy ( lcasex[anzx_l].compName[2], "nodes");
4709         }
4710         else firstTimeFlag=0;
4711       }
4712       else
4713       {
4714         vals[0]=atof(dat[2]);
4715         vals[1]=atof(dat[3]);
4716       }
4717 
4718       /* check if the node-number is 0, then an eset is defined */
4719       if(face>=0)
4720       {
4721         i=setax(setNr,"j",0);
4722         if(i>-1)
4723         {
4724           setx[setNr].elf[i].e=el;
4725           setx[setNr].elf[i].f=face;
4726         }
4727         writeFaceVals(anzx_l, el, face, 2, vals);
4728       }
4729 
4730       /* write in ansys format */
4731       if(ansFlag)
4732       {
4733         errMsg ("ERROR film not supported\n");
4734       }
4735     }
4736   }while(1);
4737   return(1);
4738 }
4739 
4740 
4741 
getSpcf(char * rec_str)4742 int getSpcf(char *rec_str)
4743 {
4744   int i,j,k,lc;
4745   int length, el, sum_e, face;
4746   int setNr, eset, setNr_dof[12];
4747   int dof[2];
4748   float vals[12];
4749   static int local_step_nr=-1, anzx_l;
4750   char setname[MAX_LINE_LENGTH];
4751 
4752   /* reset all static variables */
4753   if(resetFlag)
4754   {
4755     local_step_nr=-1;
4756     anzx_l=0;
4757     return(0);
4758   }
4759 
4760   if(printFlag) printf("%s\n",rec_str);
4761   /* scan the properties and write to file */
4762   sprintf(setname,"%s_stp%d",SPCF, step_nr);
4763   setNr=getSetNrx(setname);
4764   if(setNr<0)
4765   {
4766     setNr=pre_setax( setname, "i", 0);
4767   }
4768 
4769   /* create a dataset if a new step beginns */
4770   /* .. local_step_nr was initialized with 0
4771   if(!step_flag) { printf("%s\n ERROR: load was defined outside a *STEP\n\n",rec_str); exit(0); }
4772   else
4773   */
4774   if(step_nr>local_step_nr)
4775   {
4776     anzx_l=anzx->l;
4777 
4778     local_step_nr=step_nr;
4779     /* ini lcasex */
4780     for(lc=0; lc<5; lc++)
4781     {
4782       sprintf( lcasex[anzx->l].name,"%s", SPCF);
4783       printf (" create dataset:%d name= %s\n", anzx->l, lcasex[anzx->l].name);
4784       lcasex[anzx->l].ncomps=2;
4785       lcasex[anzx->l].irtype=1;
4786       lcasex[anzx->l].npheader=0;
4787 
4788       lcasex[anzx->l].value=0;
4789       strcpy(lcasex[anzx->l].analysis_name,"");
4790       sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
4791       strcpy(lcasex[anzx->l].dataset_text,"");
4792       lcasex[anzx->l].step_number=step_nr;
4793       lcasex[anzx->l].analysis_type=1;
4794 
4795       if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4796         printf("\n\n ERROR: malloc failure\n\n" );
4797       if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4798         printf("\n\n ERROR: malloc failure\n\n" );
4799       if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
4800         printf("\n\n ERROR: malloc failure\n\n" );
4801       if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
4802         printf("\n\n ERROR: malloc failure\n\n" );
4803       if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
4804         printf("\n\n ERROR: malloc failure\n\n" );
4805       if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
4806         printf("\n\n ERROR: malloc failure\n\n" );
4807       if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
4808         printf("\n\n ERROR: malloc failure\n\n" );
4809       if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4810         printf("\n\n ERROR: malloc failure\n\n" );
4811       if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4812         printf("\n\n ERROR: malloc failure\n\n" );
4813       if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4814         printf("\n\n ERROR: malloc failure\n\n" );
4815       if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4816         printf("\n\n ERROR: malloc failure\n\n" );
4817       if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
4818         printf("\n\n ERROR: malloc failure\n\n" );
4819 
4820       for(i=0; i<lcasex[anzx->l].ncomps; i++)
4821       {
4822         if ( (lcasex[anzx->l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
4823           printf("\n\n ERROR: malloc failure\n\n" );
4824         if ( (lcasex[anzx->l].compName[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
4825           printf("\n\n ERROR: malloc failed\n\n" );
4826         if ( (lcasex[anzx->l].icname[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
4827           printf("\n\n ERROR: malloc failed\n\n" );
4828         lcasex[anzx->l].max[i]=-MAX_FLOAT;
4829         lcasex[anzx->l].min[i]=MAX_FLOAT;
4830         for(j=0; j<=anzx->nmax; j++) lcasex[anzx->l].dat[i][j]=0.;
4831         lcasex[anzx->l].menu[i] = 1;
4832         lcasex[anzx->l].ictype[i] = 1;
4833         lcasex[anzx->l].icind1[i] = i+1;
4834         lcasex[anzx->l].icind2[i] = 0;
4835         /* remember the component which stores the nr of summands */
4836         lcasex[anzx->l].iexist[i] = -1;
4837       }
4838       lcasex[anzx->l].iexist[1] = 0;
4839       lcasex[anzx->l].menu[1] = 0;
4840       strcpy ( lcasex[anzx->l].compName[0], "value");
4841       strcpy ( lcasex[anzx->l].compName[1], "nodes");
4842       anzx->l++;
4843       if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
4844       { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
4845     }
4846 
4847     strcpy ( lcasex[anzx_l].name,   "DOF1");
4848     strcpy ( lcasex[anzx_l+1].name, "DOF2");
4849     strcpy ( lcasex[anzx_l+2].name, "DOF3");
4850     strcpy ( lcasex[anzx_l+3].name, "PRESS");
4851     strcpy ( lcasex[anzx_l+4].name, "TEMP ");
4852   }
4853   do{
4854     length=abqrecord(rec_str);
4855     if(length==-1) return(-1);
4856     if(length==-2) break;
4857 
4858     crecord(rec_str, dat);
4859     /* delete blanks and get face-nr */
4860     i=0; for(j=0;j<strlen(dat[1]); j++) if(dat[1][j]!=' ') { buffer[i]=dat[1][j]; i++; }
4861     buffer[i]='\0';
4862     face=(int)atoi(&buffer[1])-1;
4863 
4864     eset=getSetNrx(dat[0]);
4865 
4866     /* the set could already store faces instead of elements */
4867     if (eset>-1) { sum_e=setx[eset].anz_e; if(!sum_e) sum_e=setx[eset].anz_elf; }
4868     else sum_e=1;
4869     for(j=0; j<sum_e; j++)
4870     {
4871       if((eset>-1)&&(setx[eset].anz_e)) el=setx[eset].elem[j];
4872       else if((eset>-1)&&(setx[eset].anz_elf)) { el=setx[eset].elf[j].e; face=setx[eset].elf[j].f; goto jumpFace; }
4873       else el=atoi(dat[0]);
4874 
4875       if((el<anzx->emin)||(el>anzx->emax)) { printf("elem:%d in *boundaryf does not exist\n",el); continue;}
4876       if((e_enqirex[el].type>6)&&(e_enqirex[el].type<11))
4877       {
4878         if(e_enqirex[el].attr>3)
4879         {
4880           if(e_enqirex[el].type<9)
4881 	  {
4882             if(face<0) { if(dat[1][1]=='N') face=4; else face=5; }
4883             else face+=1;
4884 	  }
4885           else
4886 	  {
4887             if(face<0) { if(dat[1][1]=='N') face=5; else face=6; }
4888             else face+=1;
4889 	  }
4890         }
4891         else
4892         {
4893           if(face>1) face+=1; else { if(dat[1][1]=='N') face=0; else face=1; }
4894         }
4895       }
4896     jumpFace:;
4897       if(face<0) printf(" ERROR, face from string:%s unknown\n", buffer);
4898       //snip1
4899 
4900       for(i=0; i<12; i++)   vals[i]=0.;
4901       dof[0]=atoi(dat[2]);
4902       dof[1]=atoi(dat[3]);
4903       for(i=0; i<2; i++)
4904       {
4905         if(dof[i]==DOFP) dof[i]=4;
4906         if(dof[i]==DOFT) dof[i]=5;
4907       }
4908       if(dof[1]<dof[0]) dof[1]=dof[0];
4909 
4910       for(i=dof[0]-1; i<=dof[1]-1; i++)
4911       {
4912         vals[i]=(double)atof(dat[4]);
4913       }
4914 
4915       /* create sets for the actual dofs */
4916       for(i=dof[0]-1; i<=dof[1]-1; i++)
4917       {
4918         if(i+1==4) sprintf(setname,"%s%d_stp%d",SPCF, 8, step_nr);
4919         else if(i+1==5) sprintf(setname,"%s%d_stp%d",SPCF, 11, step_nr);
4920         else sprintf(setname,"%s%d_stp%d",SPCF, i+1, step_nr);
4921         setNr_dof[i]=getSetNrx(setname);
4922         if(setNr_dof[i]<0)
4923         {
4924           setNr_dof[i]=pre_setax( setname, "i", 0);
4925         }
4926         //printf("dof: i+1:%d set:%s nr:%d\n", i+1, setname, setNr_dof[i]);
4927       }
4928 
4929       //snip2
4930       if(face>=0)
4931       {
4932         i=setax(setNr,"j",0);
4933         if(i>-1)
4934         {
4935           setx[setNr].elf[i].e=el;
4936           setx[setNr].elf[i].f=face;
4937         }
4938         for(i=dof[0]-1; i<=dof[1]-1; i++)
4939 	{
4940           k=setax(setNr_dof[i],"j",0);
4941           if(k>-1)
4942           {
4943             setx[setNr_dof[i]].elf[k].e=el;
4944             setx[setNr_dof[i]].elf[k].f=face;
4945           }
4946           writeFaceVals(anzx_l+i, el, face, 1, &vals[i]);
4947         }
4948       }
4949 
4950       /* write in ansys format */
4951       if(ansFlag)
4952       {
4953         errMsg ("ERROR spcf not supported\n");
4954       }
4955     }
4956   }while(1);
4957   return(1);
4958 }
4959 
4960 
getElset(char * rec_str)4961 int getElset(char *rec_str)
4962 {
4963   int i,j,n, args,length, generate=0, setNr, eset;
4964   char set[MAX_LINE_LENGTH];
4965   int el[20];
4966 
4967   /* get the arguments of the string */
4968   args=crecord(rec_str, dat);
4969 
4970   /* extract the type */
4971   for(i=0; i<args; i++)
4972   {
4973     /* delete blanks */
4974     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
4975     buffer[n]='\0';
4976     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
4977     if(compare(dat[i],"ELSET=",6)==6) strcpy(set,&buffer[6]);
4978     if(compare(dat[i],"GENERATE",5)==5) generate=1;
4979   }
4980   if(printFlag) printf("*ELSET: ELSET:%s\n", set);
4981   setNr=getSetNrx(set);
4982   if(setNr<0) setNr=pre_setax( set, "i", 0);
4983 
4984   /* scan the element-names and write to file */
4985   do
4986   {
4987     length=abqrecord(rec_str);
4988     if(length==-1) return(-1);
4989     if(length==-2) break;
4990     if(generate)
4991     {
4992       el[0]=el[1]=0;
4993       el[2]=1;
4994       length=sscanf ( rec_str, "%d, %d, %d", &el[0],&el[1],&el[2]);
4995       /* write in list format */
4996       if(!el[2])
4997       {
4998         setax( setNr, "e", el[0]);
4999         setax( setNr, "e", el[1]);
5000       }
5001       else
5002       {
5003         for(i=el[0]; i<=el[1]; i+=el[2])
5004         {
5005           setax( setNr, "e", i);
5006         }
5007       }
5008     }
5009     else
5010     {
5011       args=crecord(rec_str, dat);
5012       /* extract the type */
5013       for(i=0; i<args; i++)
5014       {
5015         /* write in list format */
5016         el[0]=atoi(dat[i]);
5017         if(el[0]) setax( setNr, "e", el[0]);
5018         else
5019 	{
5020           eset=getSetNrx(dat[i]);
5021           if(eset<0)
5022           {
5023             printf("ERROR: In *ELSET set:%s not defined\n",dat[i]);
5024             return(-1);
5025           }
5026           for(j=0; j<setx[eset].anz_e; j++) setax( setNr, "e", setx[eset].elem[j]);
5027 	}
5028       }
5029     }
5030   }while(1);
5031   return(1);
5032 }
5033 
5034 
getNset(char * rec_str)5035 int getNset(char *rec_str)
5036 {
5037   int i,j,n, args,length, generate=0, setNr, nset;
5038   char set[MAX_LINE_LENGTH];
5039   int nd[20];
5040 
5041 
5042   /* get the arguments of the string */
5043   args=crecord(rec_str, dat);
5044 
5045   /* extract the type */
5046   for(i=0; i<args; i++)
5047   {
5048     /* delete blanks */
5049     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
5050     buffer[n]='\0';
5051     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
5052     if(compare(dat[i],"NSET=",5)==5) strcpy(set,&buffer[5]);
5053     if(compare(dat[i],"GENERATE",5)==5) generate=1;
5054   }
5055   if(printFlag) printf("*NSET: NSET:%s\n", set);
5056   setNr=getSetNrx(set);
5057   if(setNr<0) setNr=pre_setax( set, "i", 0);
5058 
5059   /* scan the node-names and write to file */
5060   do
5061   {
5062     length=abqrecord(rec_str);
5063     if(length==-1) return(-1);
5064     if(length==-2) break;
5065     if(generate)
5066     {
5067       nd[0]=nd[1]=0;
5068       nd[2]=1;
5069       length=sscanf ( rec_str, "%d, %d, %d", &nd[0],&nd[1],&nd[2]);
5070       /* write in list format */
5071       if(!nd[2])
5072       {
5073         setax( setNr, "n", nd[0]);
5074         setax( setNr, "n", nd[1]);
5075       }
5076       else
5077       {
5078         for(i=nd[0]; i<=nd[1]; i+=nd[2])
5079         {
5080           setax( setNr, "n", i);
5081         }
5082       }
5083     }
5084     else
5085     {
5086       args=crecord(rec_str, dat);
5087       /* extract the type */
5088       for(i=0; i<args; i++)
5089       {
5090         /* write in list format */
5091         nd[0]=atoi(dat[i]);
5092         if(nd[0]) setax( setNr, "n", nd[0]);
5093         else
5094 	{
5095           nset=getSetNrx(dat[i]);
5096           if(nset<0)
5097           {
5098             printf("ERROR: In *NSET set:%s not defined\n",dat[i]);
5099             return(-1);
5100           }
5101           for(j=0; j<setx[nset].anz_n; j++) setax( setNr, "n", setx[nset].node[j]);
5102 	}
5103       }
5104     }
5105   }while(1);
5106   return(1);
5107 }
5108 
5109 
getShellSelection(char * rec_str)5110 int getShellSelection(char *rec_str)
5111 {
5112   int i,j,n, args,length, setNr;
5113   char elset[MAX_LINE_LENGTH];
5114   char material[MAX_LINE_LENGTH];
5115   int ip=5;
5116   double d=0.;
5117 
5118 
5119   if((selected_elems=(int *)realloc((int *)selected_elems,(anzx->emax+1)*sizeof(int )))==NULL)
5120   {
5121     printf("\n\n ERROR: realloc failed in getShellSelection\n") ;
5122     return(1);
5123   }
5124   for(i=0; i<=anzx->emax; i++) selected_elems[i]=0;
5125 
5126 
5127   /* get the arguments of the string */
5128   args=crecord(rec_str, dat);
5129 
5130   /* extract the material-name */
5131   for(i=0; i<args; i++)
5132   {
5133     /* delete blanks */
5134     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
5135     buffer[n]='\0';
5136     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
5137     if(compare(dat[i],"ELSET=",6)==6) strcpy(elset,&buffer[6]);
5138     if(compare(dat[i],"MATERIAL=",9)==9) strcpy(material,&buffer[9]);
5139     if((compare(buffer,"NODAL",5)==5)||
5140        (compare(buffer,"COMPOS",5)==5)||
5141        (compare(buffer,"ORIENT",5)==5))
5142     {
5143       errMsg("WARNING: option:%s not supported, keyword ignored\n", buffer);
5144       // return(1);
5145     }
5146   }
5147   if(printFlag) printf("*SHELL SECTION: ELSET:%s MATERIAL:%s\n", elset, material);
5148 
5149   /* get the next line */
5150   length=abqrecord(rec_str);
5151   if(length==-1) return(-1);
5152   sscanf(rec_str, "%lf, %d",&d, &ip);
5153   elprop->nset++;
5154   elprop->d=d;
5155   if(printFlag) printf("set:%d d:%lf ip:%d\n",elprop->nset, elprop->d, ip);
5156 
5157   /* get or define a material-number */
5158   matnr=getMatNr(material,0);
5159 
5160   if(ansFlag)
5161   {
5162     /* write ansys commands */
5163     setNr=getSetNrx(elset);
5164     if ( setNr<0 )  { printf ("\nThe set \"%s\" could not be opened. The setdefinition was used before the set was created.\n\n",elset); exit(-1); }
5165 
5166     fprintf (handleans,"! ----------- ELSET: %s MAT:%s ---------------\n", elset, material);
5167     fprintf (handleans, "REAL, %d\n", elprop->nset);
5168     fprintf (handleans, "R, %d, %lf\n", elprop->nset, elprop->d);
5169     fprintf (handleans,"MAT, %d\n",matnr);
5170     for(i=0; i<setx[setNr].anz_e; i++)
5171     {
5172       selected_elems[setx[setNr].elem[i]]=1;
5173     }
5174     writeElemAns(matnr, selected_elems, anzx, nodex, elemx);
5175   }
5176   return(1);
5177 }
5178 
5179 
getStatic(char * rec_str)5180 int getStatic(char *rec_str)
5181 {
5182   int args,length;
5183   length=abqrecord(rec_str);
5184   if(length==-1) return(-1);
5185 
5186   /* get the arguments of the string */
5187   args=crecord(rec_str, dat);
5188 
5189   if((args>1)&&(dat[0][0]!='*')) dataset_value=atof(dat[1]);
5190   else dataset_value=0.;
5191   return(1);
5192 }
5193 
getSolidSelection(char * rec_str)5194 int getSolidSelection(char *rec_str)
5195 {
5196   int i,j,n, args,length, setNr;
5197   char elset[MAX_LINE_LENGTH];
5198   char material[MAX_LINE_LENGTH];
5199 
5200 
5201   if((selected_elems=(int *)realloc((int *)selected_elems,(anzx->emax+1)*sizeof(int )))==NULL)
5202   {
5203     printf("\n\n ERROR: realloc failed in getSolidSelection\n") ;
5204     return(1);
5205   }
5206   for(i=0; i<=anzx->emax; i++) selected_elems[i]=0;
5207 
5208   /* get the arguments of the string */
5209   args=crecord(rec_str, dat);
5210 
5211   /* extract the material-name */
5212   for(i=0; i<args; i++)
5213   {
5214     /* delete blanks */
5215     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
5216     buffer[n]='\0';
5217     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
5218     if(compare(dat[i],"ELSET=",6)==6) strcpy(elset,&buffer[6]);
5219     if(compare(dat[i],"MATERIAL=",9)==9) strcpy(material,&buffer[9]);
5220     if((compare(buffer,"COMPOS",5)==5)||
5221        (compare(buffer,"ORIENT",5)==5))
5222     {
5223       errMsg("WARNING: option:%s not supported, keyword ignored\n", buffer);
5224       /* get the next line */
5225       /*
5226       length=abqrecord(rec_str);
5227       if(length==-1) return(-1);
5228       return(1);
5229       */
5230     }
5231   }
5232   if(printFlag) printf("*SOLID SECTION: ELSET:%s MATERIAL:%s\n", elset, material);
5233 
5234   /* get or define a material-number */
5235   matnr=getMatNr(material,0);
5236   setNr=getSetNrx(elset);
5237   if ( setNr<0 )  { printf ("\nThe set \"%s\" could not be opened. The setdefinition was used before the set was created.\n\n",elset); exit(-1); }
5238   setx[setNr].material=matnr;
5239 
5240   if(ansFlag)
5241   {
5242     /* write ansys commands */
5243 
5244     fprintf(handleans,"! ----------- ELSET: %s MAT:%s ---------------\n", elset, material);
5245     fprintf(handleans,"MAT, %d\n",matnr);
5246     for(i=0; i<setx[setNr].anz_e; i++)
5247     {
5248       selected_elems[setx[setNr].elem[i]]=1;
5249     }
5250     writeElemAns(matnr, selected_elems, anzx, nodex, elemx);
5251   }
5252 
5253   /* get the next line */
5254   length=abqrecord(rec_str);
5255   if(length==-1) return(-1);
5256   return(1);
5257 }
5258 
5259 
getInitialConditions(char * rec_str)5260 int getInitialConditions(char *rec_str)
5261 {
5262   int i,j,n, args, length, setNr;
5263   int enr,enrold=0,e,p,g=0,v, nnr,nm,n1,n2;
5264   char type[MAX_LINE_LENGTH];
5265   double enodval[20][6];
5266   int *vpnode=NULL;
5267 
5268   typedef struct {
5269     int nr;
5270     double dat[27][6];
5271   }Elresult;
5272   Elresult *elresult=NULL;
5273 
5274   /* midside node-pos based on frd definition (different to ccx) */
5275   double nonei10[]={ 5,1,2,6,2,3,7,3,1,8,1,4,9,2,4,10,3,4 };
5276   double nonei15[]={ 7,1,2,8,2,3,9,3,1,13,4,5,14,5,6,15,6,4,10,1,4,11,2,5,12,3,6 };
5277   double nonei20[]={ 9,1,2,10,2,3,11,3,4,12,4,1,17,5,6,18,6,7,19,7,8,20,8,5,13,1,5,14,2,6,15,3,7,16,4,8 };
5278 
5279   /* extrapolation factors from gausp to nodep */
5280   /* f: a8(8,8),a4(4,4),a27(20,27),a9(6,9),a2(6,2) */
5281   /* c: a8[8][8],a4[4][4],a27[27][20],a9[9][6],a2[2][6] */
5282   double a2[]={
5283       1.1455,-0.1455,1.1455,-0.1455,1.1455,-0.1455,
5284       -0.1455,1.1455,-0.1455,1.1455,-0.1455,1.1455 };
5285   double a4[]={
5286       1.92705, -0.30902, -0.30902, -0.30902,
5287       -0.30902,  1.92705, -0.30902, -0.30902,
5288       -0.30902, -0.30902,  1.92705, -0.30902,
5289       -0.30902, -0.30902, -0.30902,  1.92705 };
5290   double a9[]={
5291       1.63138,-0.32628,-0.32628,-0.52027, 0.10405, 0.10405,
5292       -0.32628, 1.63138,-0.32628, 0.10405,-0.52027, 0.10405,
5293       -0.32628,-0.32628, 1.63138, 0.10405, 0.10405,-0.52027,
5294        0.55556,-0.11111,-0.11111, 0.55556,-0.11111,-0.11111,
5295       -0.11111, 0.55556,-0.11111,-0.11111, 0.55556,-0.11111,
5296       -0.11111,-0.11111, 0.55556,-0.11111,-0.11111, 0.55556,
5297       -0.52027, 0.10405, 0.10405, 1.63138,-0.32628,-0.32628,
5298        0.10405,-0.52027, 0.10405,-0.32628, 1.63138,-0.32628,
5299       0.10405, 0.10405,-0.52027,-0.32628,-0.32628, 1.63138 };
5300   double a8[]={
5301       2.549,-.683,.183,-.683,-.683,.183,
5302       -.04904,.183,-.683,2.549,-.683,.183,
5303       .183,-.683,.183,-.04904,-.683,.183,
5304       -.683,2.549,.183,-.04904,.183,-.683,
5305       .183,-.683,2.549,-.683,-.04904,.183,
5306       -.683,.183,-.683,.183,-.04904,.183,
5307       2.549,-.683,.183,-.683,.183,-.683,
5308       .183,-.04904,-.683,2.549,-.683,.183,
5309       .183,-.04904,.183,-.683,-.683,.183,
5310       -.683,2.549,-.04904,.183,-.683,.183,
5311       .183,-.683,2.549,-.683 } ;
5312   double a27[]={
5313        2.37499,-0.12559,-0.16145,-0.12559,-0.12559,-0.16145, 0.11575,
5314       -0.16145, 0.32628, 0.11111, 0.11111, 0.32628, 0.11111,-0.10405,
5315       -0.10405, 0.11111, 0.32628, 0.11111,-0.10405, 0.11111,-0.31246,
5316       -0.31246, 0.31481, 0.31481, 0.31481, 0.31481,-0.16902,-0.16902,
5317        1.28439,-0.27072,-0.19444,-0.27072,-0.19444, 0.15961,-0.00661,
5318        0.15961,-0.27072,-0.27072, 0.15961, 0.15961,-0.12559, 2.37499,
5319       -0.12559,-0.16145,-0.16145,-0.12559,-0.16145, 0.11575, 0.32628,
5320        0.32628, 0.11111, 0.11111, 0.11111, 0.11111,-0.10405,-0.10405,
5321        0.11111, 0.32628, 0.11111,-0.10405,-0.31246, 0.31481, 0.31481,
5322       -0.31246, 0.31481,-0.16902,-0.16902, 0.31481,-0.27072,-0.19444,
5323       -0.27072, 1.28439, 0.15961,-0.00661, 0.15961,-0.19444,-0.27072,
5324        0.15961, 0.15961,-0.27072,-0.48824,-0.48824,-0.48824,-0.48824,
5325        0.22898, 0.22898, 0.22898, 0.22898, 0.05556, 0.05556, 0.05556,
5326        0.05556, 0.05556, 0.05556, 0.05556, 0.05556,-0.22222,-0.22222,
5327       -0.22222,-0.22222, 0.31481,-0.31246,-0.31246, 0.31481,-0.16902,
5328        0.31481, 0.31481,-0.16902,-0.27072, 1.28439,-0.27072,-0.19444,
5329        0.15961,-0.19444, 0.15961,-0.00661, 0.15961,-0.27072,-0.27072,
5330        0.15961,-0.12559,-0.16145,-0.12559, 2.37499,-0.16145, 0.11575,
5331       -0.16145,-0.12559, 0.11111, 0.11111, 0.32628, 0.32628,-0.10405,
5332       -0.10405, 0.11111, 0.11111, 0.11111,-0.10405, 0.11111, 0.32628,
5333        0.31481, 0.31481,-0.31246,-0.31246,-0.16902,-0.16902, 0.31481,
5334        0.31481,-0.19444,-0.27072, 1.28439,-0.27072,-0.00661, 0.15961,
5335       -0.19444, 0.15961, 0.15961, 0.15961,-0.27072,-0.27072,-0.16145,
5336       -0.12559, 2.37499,-0.12559, 0.11575,-0.16145,-0.12559,-0.16145,
5337        0.11111, 0.32628, 0.32628, 0.11111,-0.10405, 0.11111, 0.11111,
5338       -0.10405,-0.10405, 0.11111, 0.32628, 0.11111,-0.31246, 0.31481,
5339       -0.16902, 0.31481,-0.31246, 0.31481,-0.16902, 0.31481,-0.27072,
5340        0.15961, 0.15961,-0.27072,-0.27072, 0.15961, 0.15961,-0.27072,
5341        1.28439,-0.19444,-0.00661,-0.19444,-0.48824,-0.48824, 0.22898,
5342        0.22898,-0.48824,-0.48824, 0.22898, 0.22898, 0.05556,-0.22222,
5343        0.05556,-0.22222, 0.05556,-0.22222, 0.05556,-0.22222, 0.05556,
5344        0.05556, 0.05556, 0.05556, 0.31481,-0.31246, 0.31481,-0.16902,
5345        0.31481,-0.31246, 0.31481,-0.16902,-0.27072,-0.27072, 0.15961,
5346        0.15961,-0.27072,-0.27072, 0.15961, 0.15961,-0.19444, 1.28439,
5347       -0.19444,-0.00661,-0.48824, 0.22898, 0.22898,-0.48824,-0.48824,
5348        0.22898, 0.22898,-0.48824,-0.22222, 0.05556,-0.22222, 0.05556,
5349       -0.22222, 0.05556,-0.22222, 0.05556, 0.05556, 0.05556, 0.05556,
5350        0.05556,-0.29630,-0.29630,-0.29630,-0.29630,-0.29630,-0.29630,
5351       -0.29630,-0.29630,-0.11111,-0.11111,-0.11111,-0.11111,-0.11111,
5352       -0.11111,-0.11111,-0.11111,-0.11111,-0.11111,-0.11111,-0.11111,
5353        0.22898,-0.48824,-0.48824, 0.22898, 0.22898,-0.48824,-0.48824,
5354        0.22898,-0.22222, 0.05556,-0.22222, 0.05556,-0.22222, 0.05556,
5355       -0.22222, 0.05556, 0.05556, 0.05556, 0.05556, 0.05556, 0.31481,
5356       -0.16902, 0.31481,-0.31246, 0.31481,-0.16902, 0.31481,-0.31246,
5357        0.15961, 0.15961,-0.27072,-0.27072, 0.15961, 0.15961,-0.27072,
5358       -0.27072,-0.19444,-0.00661,-0.19444, 1.28439, 0.22898, 0.22898,
5359       -0.48824,-0.48824, 0.22898, 0.22898,-0.48824,-0.48824, 0.05556,
5360       -0.22222, 0.05556,-0.22222, 0.05556,-0.22222, 0.05556,-0.22222,
5361        0.05556, 0.05556, 0.05556, 0.05556,-0.16902, 0.31481,-0.31246,
5362        0.31481,-0.16902, 0.31481,-0.31246, 0.31481, 0.15961,-0.27072,
5363       -0.27072, 0.15961, 0.15961,-0.27072,-0.27072, 0.15961,-0.00661,
5364       -0.19444, 1.28439,-0.19444,-0.12559,-0.16145, 0.11575,-0.16145,
5365        2.37499,-0.12559,-0.16145,-0.12559, 0.11111,-0.10405,-0.10405,
5366        0.11111, 0.32628, 0.11111, 0.11111, 0.32628, 0.32628, 0.11111,
5367       -0.10405, 0.11111, 0.31481, 0.31481,-0.16902,-0.16902,-0.31246,
5368       -0.31246, 0.31481, 0.31481,-0.19444, 0.15961,-0.00661, 0.15961,
5369        1.28439,-0.27072,-0.19444,-0.27072,-0.27072,-0.27072, 0.15961,
5370        0.15961,-0.16145,-0.12559,-0.16145, 0.11575,-0.12559, 2.37499,
5371       -0.12559,-0.16145, 0.11111, 0.11111,-0.10405,-0.10405, 0.32628,
5372        0.32628, 0.11111, 0.11111, 0.11111, 0.32628, 0.11111,-0.10405,
5373        0.31481,-0.16902,-0.16902, 0.31481,-0.31246, 0.31481, 0.31481,
5374       -0.31246, 0.15961,-0.00661, 0.15961,-0.19444,-0.27072,-0.19444,
5375       -0.27072, 1.28439,-0.27072, 0.15961, 0.15961,-0.27072, 0.22898,
5376        0.22898, 0.22898, 0.22898,-0.48824,-0.48824,-0.48824,-0.48824,
5377        0.05556, 0.05556, 0.05556, 0.05556, 0.05556, 0.05556, 0.05556,
5378        0.05556,-0.22222,-0.22222,-0.22222,-0.22222,-0.16902, 0.31481,
5379        0.31481,-0.16902, 0.31481,-0.31246,-0.31246, 0.31481, 0.15961,
5380       -0.19444, 0.15961,-0.00661,-0.27072, 1.28439,-0.27072,-0.19444,
5381        0.15961,-0.27072,-0.27072, 0.15961,-0.16145, 0.11575,-0.16145,
5382       -0.12559,-0.12559,-0.16145,-0.12559, 2.37499,-0.10405,-0.10405,
5383        0.11111, 0.11111, 0.11111, 0.11111, 0.32628, 0.32628, 0.11111,
5384       -0.10405, 0.11111, 0.32628,-0.16902,-0.16902, 0.31481, 0.31481,
5385        0.31481, 0.31481,-0.31246,-0.31246,-0.00661, 0.15961,-0.19444,
5386        0.15961,-0.19444,-0.27072, 1.28439,-0.27072, 0.15961, 0.15961,
5387       -0.27072,-0.27072, 0.11575,-0.16145,-0.12559,-0.16145,-0.16145,
5388       -0.12559, 2.37499,-0.12559,-0.10405, 0.11111, 0.11111,-0.10405,
5389        0.11111, 0.32628, 0.32628, 0.11111,-0.10405, 0.11111, 0.32628,
5390        0.11111 };
5391 
5392 
5393 
5394   /* get the arguments of the string */
5395   args=crecord(rec_str, dat);
5396 
5397   /* extract the name */
5398   for(i=0; i<args; i++)
5399   {
5400     /* delete blanks */
5401     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
5402     buffer[n]='\0';
5403     for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
5404     if(compare(dat[i],"TYPE=",5)==5)
5405     {
5406       strcpy(dat[i],&buffer[5]);
5407       /* delete blanks */
5408       n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
5409       buffer[n]='\0';
5410       for(j=0;j<=strlen(buffer); j++) dat[i][j]=toupper(buffer[j]);
5411       if(printFlag) printf("*INITIAL CONDITIONS: TYPE:%s \n", buffer);
5412 
5413       if(compare(dat[i],"DISP",4)==4)
5414       {
5415         if(ansFlag)
5416         {
5417 	    printf("ERROR: type:%s is not supportet for ansys\n", dat[i]);
5418         }
5419         else getInitialVector(rec_str,dat[i]);
5420         return(1);
5421       }
5422       else if((compare(dat[i],"FLUID",4)==4)||(compare(dat[i],"VELO",4)==4))
5423       {
5424         if(ansFlag)
5425         {
5426 	    printf("ERROR: type:%s is not supportet for ansys\n", dat[i]);
5427         }
5428         else getInitialVector(rec_str,dat[i]);
5429         return(1);
5430       }
5431       else if(compare(dat[i],"TEMPERATURE",6)==6)
5432       {
5433         if(ansFlag)
5434         {
5435           /* get the next line */
5436           length=abqrecord(rec_str);
5437           if(length==-1) return(-1);
5438           if(length==-2) return(1);
5439 
5440           /* get the arguments of the string */
5441           args=crecord(rec_str, dat);
5442 
5443           /* extract the set-name */
5444           /* delete blanks */
5445           n=0; for(j=0;j<strlen(dat[0]); j++) if(dat[0][j]!=' ') { buffer[n]=dat[0][j]; n++; }        buffer[n]='\0';
5446 
5447           if((selected_elems=(int *)realloc((int *)selected_elems,(anzx->nmax+1)*sizeof(int )))==NULL)
5448           {
5449             printf("\n\n ERROR: realloc failed in getSolidSelection\n") ;
5450             return(1);
5451           }
5452           for(j=0; j<anzx->nmax; j++) selected_elems[j]=0;
5453 
5454           /* check if a setname or a node-number is provided */
5455           if(atoi(buffer)>0)
5456           {
5457             length=abqrecord(rec_str);
5458 
5459             if(length==-1) return(-1);
5460             if(length==-2) break;
5461             args=crecord(rec_str, dat);
5462             selected_elems[atoi(dat[0])]=1;
5463           }
5464           else
5465           {
5466             /* open the file which contains the affected nodes */
5467             setNr=getSetNrx(buffer);
5468             if ( setNr<0 )  { printf ("\nThe set \"%s\" could not be opened. The setdefinition was used before the set was created.\n\n", buffer); exit(-1); }
5469             for(i=0; i<setx[setNr].anz_n; i++)
5470             {
5471               selected_elems[setx[setNr].node[i]]=1;
5472             }
5473           }
5474 
5475           /* write ansys */
5476           for(j=0; j<anzx->n; j++) if(selected_elems[nodex[j].nr]==0)
5477 	  {
5478             printf("WARNING: TREF not unique, no TREF written for set:%s. n:%d ntot:%d\n", buffer, j,anzx->n);
5479             return(1);
5480           }
5481           fprintf(handleans,"! ----------- INITIAL CONDITIONS, SET:%s ---------------\n", buffer);
5482           fprintf(handleans, "TREF, %s\n",dat[1]);
5483         }
5484         else { strcpy(type,dat[i]);getScalarvalue(rec_str,type); }
5485         return(1);
5486       }
5487       else if(compare(dat[i],"PRES",4)==4)
5488       {
5489         if(ansFlag)
5490         {
5491 	    printf("ERROR: type:%s is not supportet for ansys\n", dat[i]);
5492         }
5493         else { strcpy(type,dat[i]);getScalarvalue(rec_str,type); }
5494         return(1);
5495       }
5496       else if(compare(dat[i],"TOTA",4)==4)
5497       {
5498         if(ansFlag)
5499         {
5500 	    printf("ERROR: type:%s is not supportet for ansys\n", dat[i]);
5501         }
5502         else { strcpy(type,dat[i]);getScalarvalue(rec_str,type); }
5503         return(1);
5504       }
5505       else if(compare(dat[i],"MASS",4)==4)
5506       {
5507         if(ansFlag)
5508         {
5509 	    printf("ERROR: type:%s is not supportet for ansys\n", dat[i]);
5510         }
5511         else { strcpy(type,dat[i]);getScalarvalue(rec_str,type); }
5512         return(1);
5513       }
5514       else if((compare(dat[i],"STRESS",6)==6) || (compare(dat[i],"PLASTICSTRAIN",13)==13) || (compare(dat[i],"PLASTIC STRAIN",14)==14))
5515       {
5516         /* create a new dataset */
5517         if(compare(dat[i],"STRESS",6)==6) sprintf( lcasex[anzx->l].name,"STRESS");
5518         if(compare(dat[i],"PLASTICSTRAIN",13)==13) sprintf( lcasex[anzx->l].name,"PE");
5519         if(compare(dat[i],"PLASTIC STRAIN",14)==14) sprintf( lcasex[anzx->l].name,"PE");
5520         printf (" create dataset:%d name= %s, components 5.6 will be switched (abq->cgx)!\n", anzx->l, lcasex[anzx->l].name);
5521         lcasex[anzx->l].value=0;
5522         lcasex[anzx->l].ncomps=6;
5523         lcasex[anzx->l].irtype=1;
5524         lcasex[anzx->l].npheader=0;
5525 
5526         strcpy(lcasex[anzx->l].analysis_name,"");
5527         sprintf(lcasex[anzx->l].dataset_name,"STP %d", step_nr);
5528         strcpy(lcasex[anzx->l].dataset_text,"INITIAL");
5529         lcasex[anzx->l].step_number=step_nr;
5530         lcasex[anzx->l].analysis_type=1;
5531 
5532         if ( (lcasex[anzx->l].nmax = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5533           printf("\n\n ERROR: malloc failure\n\n" );
5534         if ( (lcasex[anzx->l].nmin = (int *)malloc( lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5535           printf("\n\n ERROR: malloc failure\n\n" );
5536         if ( (lcasex[anzx->l].max = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
5537           printf("\n\n ERROR: malloc failure\n\n" );
5538         if ( (lcasex[anzx->l].min = (float *)malloc(lcasex[anzx->l].ncomps * sizeof(float))) == NULL )
5539           printf("\n\n ERROR: malloc failure\n\n" );
5540         if ( (lcasex[anzx->l].dat = (float **)malloc(lcasex[anzx->l].ncomps * sizeof(float *))) == NULL )
5541           printf("\n\n ERROR: malloc failure\n\n" );
5542         if ( (lcasex[anzx->l].compName = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
5543           printf("\n\n ERROR: malloc failure\n\n" );
5544         if ( (lcasex[anzx->l].icname = (char **)malloc(lcasex[anzx->l].ncomps * sizeof(char *))) == NULL )
5545           printf("\n\n ERROR: malloc failure\n\n" );
5546         if ( (lcasex[anzx->l].menu = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5547           printf("\n\n ERROR: malloc failure\n\n" );
5548         if ( (lcasex[anzx->l].ictype = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5549           printf("\n\n ERROR: malloc failure\n\n" );
5550         if ( (lcasex[anzx->l].icind1 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5551           printf("\n\n ERROR: malloc failure\n\n" );
5552         if ( (lcasex[anzx->l].icind2 = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5553           printf("\n\n ERROR: malloc failure\n\n" );
5554         if ( (lcasex[anzx->l].iexist = (int *)malloc(lcasex[anzx->l].ncomps * sizeof(int))) == NULL )
5555           printf("\n\n ERROR: malloc failure\n\n" );
5556 
5557         for(j=0; j<lcasex[anzx->l].ncomps; j++)
5558         {
5559           if ( (lcasex[anzx->l].dat[j] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
5560             printf("\n\n ERROR: malloc failure\n\n" );
5561           if ( (lcasex[anzx->l].compName[j] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
5562             printf("\n\n ERROR: malloc failed\n\n" );
5563           if ( (lcasex[anzx->l].icname[j] = (char *)malloc( MAX_LINE_LENGTH * sizeof(char))) == NULL )
5564             printf("\n\n ERROR: malloc failed\n\n" );
5565           lcasex[anzx->l].max[j]=-MAX_FLOAT;
5566           lcasex[anzx->l].min[j]=MAX_FLOAT;
5567 
5568           lcasex[anzx->l].menu[j] = 1;
5569           lcasex[anzx->l].ictype[j] = 4;
5570           lcasex[anzx->l].icind1[j] = 0;
5571           lcasex[anzx->l].icind2[j] = 0;
5572           lcasex[anzx->l].iexist[j] = 0;
5573         }
5574         if(compare(dat[i],"STRESS",6)==6)
5575         {
5576           strcpy ( lcasex[anzx->l].compName[0], "SXX   ");
5577           strcpy ( lcasex[anzx->l].compName[1], "SYY   ");
5578           strcpy ( lcasex[anzx->l].compName[2], "SZZ   ");
5579           strcpy ( lcasex[anzx->l].compName[3], "SXY   ");
5580           strcpy ( lcasex[anzx->l].compName[5], "SXZ   ");
5581           strcpy ( lcasex[anzx->l].compName[4], "SYZ   ");
5582 	}
5583         if(compare(dat[i],"PLASTICSTRAIN",13)==13)
5584         {
5585           strcpy ( lcasex[anzx->l].compName[0], "EXX   ");
5586           strcpy ( lcasex[anzx->l].compName[1], "EYY   ");
5587           strcpy ( lcasex[anzx->l].compName[2], "EZZ   ");
5588           strcpy ( lcasex[anzx->l].compName[3], "EXY   ");
5589           strcpy ( lcasex[anzx->l].compName[5], "EXZ   ");
5590           strcpy ( lcasex[anzx->l].compName[4], "EYZ   ");
5591 	}
5592         if ( (vpnode = (int *)calloc( (anzx->nmax+1), sizeof(int))) == NULL )
5593           printf("\n\n ERROR: malloc failure\n\n" );
5594 
5595         /* read elem-nr, all gaus-vals and extrapolate to the nodes */
5596         if ( (elresult = (Elresult *)realloc( (Elresult *)elresult, (anzx->emax+1) * sizeof(Elresult))) == NULL )
5597           printf("\n\n ERROR: malloc failure\n\n" );
5598 
5599         e=-1;
5600         do{
5601             length=abqrecord(rec_str);
5602             if(length==-1)
5603             {
5604               anzx->l++;
5605               if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
5606               { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
5607               return(-1);
5608             }
5609             if(length==-2) break;
5610             args=crecord(rec_str, dat);
5611 	    if(args!=8) return(-1);
5612 	    enr=atoi(dat[0]);
5613 	    //printf("enr:%d e:%d :%d\n",enr,e,anzx->e);
5614             if (enr!= enrold)
5615             {
5616               enrold=enr;
5617               e++;
5618 	      elresult[e].nr=enr;
5619 	    }
5620             p=atoi(dat[1])-1;
5621             elresult[e].dat[p][0]=atof(dat[2]);
5622             elresult[e].dat[p][1]=atof(dat[3]);
5623             elresult[e].dat[p][2]=atof(dat[4]);
5624             elresult[e].dat[p][3]=atof(dat[5]);
5625             elresult[e].dat[p][4]=atof(dat[6]);
5626             elresult[e].dat[p][5]=atof(dat[7]);
5627         }while(1);
5628 
5629         /* extrapolate to the node-pos */
5630         for(e=0; e<anzx->e; e++)
5631 	{
5632           for(n=0; n<20; n++) for(v=0; v<6; v++) enodval[n][v]=0.;
5633 
5634           /* he8 */
5635           if((e_enqirex[elresult[e].nr].type==1)&&(e_enqirex[elresult[e].nr].attr==1))
5636 	  { nnr=8;  for(n=0; n<8; n++) for(v=0; v<6; v++) enodval[n][v]+=elresult[e].dat[g][v]; }
5637           else if((e_enqirex[elresult[e].nr].type==1)&&(e_enqirex[elresult[e].nr].attr==0))
5638           { nnr=8;  for(n=0; n<8; n++) for(g=0; g<8; g++) for(v=0; v<6; v++) enodval[n][v]+=a8[g*8+n]*elresult[e].dat[g][v]; }
5639 
5640           /* he20 */
5641           else if((e_enqirex[elresult[e].nr].type==4)&&(e_enqirex[elresult[e].nr].attr==1))
5642           {
5643             nnr=20;
5644             for(n=0; n<8; n++) for(g=0; g<8; g++) for(v=0; v<6; v++) enodval[n][v]+=a8[g*8+n]*elresult[e].dat[g][v];
5645             for(n=8; n<20; n++)
5646             {
5647               nm=nonei20[(n-8)*3]-1;
5648               n1=nonei20[(n-8)*3+1]-1;
5649               n2=nonei20[(n-8)*3+2]-1;
5650               for(v=0; v<6; v++) enodval[nm][v]=(enodval[n1][v]+enodval[n2][v])*.5;
5651             }
5652 	  }
5653           else if((e_enqirex[elresult[e].nr].type==4)&&(e_enqirex[elresult[e].nr].attr==0))
5654           {
5655             nnr=20;
5656             for(n=0; n<12; n++) for(g=0; g<27; g++) for(v=0; v<6; v++) enodval[n][v]+=a27[g*20+n]*elresult[e].dat[g][v];
5657             for(n=12; n<16; n++) for(g=0; g<27; g++) for(v=0; v<6; v++) enodval[n][v]+=a27[g*20+n+4]*elresult[e].dat[g][v];
5658             for(n=16; n<20; n++) for(g=0; g<27; g++) for(v=0; v<6; v++) enodval[n][v]+=a27[g*20+n-4]*elresult[e].dat[g][v];
5659           }
5660 
5661           /* TET4 and TET10 */
5662           else if((e_enqirex[elresult[e].nr].type==3)&&(e_enqirex[elresult[e].nr].attr==0))
5663 	  { nnr=4;  for(n=0; n<4; n++) for(v=0; v<6; v++) enodval[n][v]+=elresult[e].dat[g][v]; }
5664           else if((e_enqirex[elresult[e].nr].type==6)&&(e_enqirex[elresult[e].nr].attr==0))
5665           {
5666             nnr=10;
5667             for(n=0; n<4; n++) for(g=0; g<4; g++) for(v=0; v<6; v++) enodval[n][v]+=a4[g*4+n]*elresult[e].dat[g][v];
5668             for(n=4; n<10; n++)
5669             {
5670               nm=nonei10[(n-4)*3]-1;
5671               n1=nonei10[(n-4)*3+1]-1;
5672               n2=nonei10[(n-4)*3+2]-1;
5673               for(v=0; v<6; v++) enodval[nm][v]=(enodval[n1][v]+enodval[n2][v])*.5;
5674             }
5675           }
5676 
5677 	  /* PE6 and PE15 */
5678           else if((e_enqirex[elresult[e].nr].type==2)&&(e_enqirex[elresult[e].nr].attr==0))
5679           { nnr=6;  for(n=0; n<6; n++) for(g=0; g<2; g++) for(v=0; v<6; v++) enodval[n][v]+=a2[g*6+n]*elresult[e].dat[g][v]; }
5680           else if((e_enqirex[elresult[e].nr].type==5)&&(e_enqirex[elresult[e].nr].attr==0))
5681           {
5682             nnr=15;
5683             for(n=0; n<6; n++) for(g=0; g<9; g++) for(v=0; v<6; v++) enodval[n][v]+=a9[g*6+n]*elresult[e].dat[g][v];
5684             for(n=6; n<15; n++)
5685             {
5686               nm=nonei15[(n-6)*3]-1;
5687               n1=nonei15[(n-6)*3+1]-1;
5688               n2=nonei15[(n-6)*3+2]-1;
5689               for(v=0; v<6; v++) enodval[nm][v]=(enodval[n1][v]+enodval[n2][v])*.5;
5690 	      //printf("el:%d n: %d %d %d\n",elresult[e].nr,e_enqirex[elresult[e].nr].nod[n1],e_enqirex[elresult[e].nr].nod[nm],e_enqirex[elresult[e].nr].nod[n2]);
5691             }
5692           }
5693 
5694           else goto jumpElem;
5695 
5696           /* add the node-vals per node and count the values per node */
5697           for(n=0; n<nnr; n++)
5698           {
5699             for(v=0; v<6; v++) lcasex[anzx->l].dat[v][e_enqirex[elresult[e].nr].nod[n]]+=enodval[n][v];
5700             vpnode[e_enqirex[elresult[e].nr].nod[n]]++;
5701 	    //printf("n:%d e:%d nod:%d nrv:%d\n", n, elresult[e].nr,e_enqirex[elresult[e].nr].nod[n], vpnode[e_enqirex[elresult[e].nr].nod[n]]);
5702 	  }
5703 
5704 	jumpElem:;
5705 	}
5706 
5707         /* divide the node-vals by the number of values per node */
5708         for(n=0; n<anzx->n; n++)
5709 	{
5710           if(vpnode[nodex[n].nr]) for(v=0; v<6; v++) lcasex[anzx->l].dat[v][nodex[n].nr]/=vpnode[nodex[n].nr];
5711 	}
5712 
5713         /* get max and min vals */
5714         for(n=0; n<anzx->n; n++) for(v=0; v<6; v++)
5715         {
5716           if(lcasex[anzx->l].dat[v][nodex[n].nr] > lcasex[anzx->l].max[v])
5717           {
5718             lcasex[anzx->l].max[v]=lcasex[anzx->l].dat[v][nodex[n].nr];
5719             lcasex[anzx->l].nmax[v]=nodex[n].nr;
5720           }
5721           if(lcasex[anzx->l].dat[v][nodex[n].nr] < lcasex[anzx->l].min[v])
5722           {
5723             lcasex[anzx->l].min[v]=lcasex[anzx->l].dat[v][nodex[n].nr];
5724             lcasex[anzx->l].nmin[v]=nodex[n].nr;
5725           }
5726 	}
5727 
5728         anzx->l++;
5729         if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
5730         { printf("\n\n ERROR: malloc failure\n\n" ); exit(1); }
5731         free(vpnode);
5732         free(elresult);
5733         return(1);
5734       }
5735       else
5736       {
5737         errMsg("WARNING: option:%s not supported, keyword ignored\n", buffer);
5738         /* get the next line */
5739         length=abqrecord(rec_str);
5740         if(length==-1) return(-1);
5741         return(1);
5742       }
5743     }
5744   }
5745   /* get the next line */
5746   length=abqrecord(rec_str);
5747   if(length==-1) return(-1);
5748   return(1);
5749 }
5750 
5751 
getFilePointer(int filesopen,FILE ** openfile,char * rec_str)5752 int getFilePointer( int filesopen, FILE **openfile, char *rec_str)
5753 {
5754   int i,j,n,args,setFlag=0, length;
5755   char set[MAX_LINE_LENGTH];
5756   FILE *handle;
5757 
5758   /* get the arguments of the string */
5759   args=crecord(rec_str, dat);
5760 
5761   /* extract the filename */
5762   sprintf(set, "NONE");
5763   for(i=0; i<args; i++)
5764   {
5765     /* delete blanks */
5766     n=0; for(j=0;j<strlen(dat[i]); j++) if(dat[i][j]!=' ') { buffer[n]=dat[i][j]; n++; }
5767     buffer[n]='\0';
5768     if(compare(buffer,"INPUT=",6)==6) { setFlag=1; strcpy(set,&buffer[6]); }
5769     if(compare(buffer,"input=",6)==6) { setFlag=1; strcpy(set,&buffer[6]); }
5770     if(compare(buffer,"Input=",6)==6) { setFlag=1; strcpy(set,&buffer[6]); }
5771   }
5772   if(!setFlag)
5773   {
5774     printf(" WARNING: No input file provided %s\n", rec_str);
5775     length=abqrecord(rec_str);
5776     if(length==-1) return(filesopen);
5777     return(filesopen);
5778   }
5779   if(printFlag) printf("*INCLUDE: FILE=%s\n", set);
5780 
5781   /* open input file */
5782   handle = fopen(set, "r");
5783   if ( handle== NULL ) { printf ("\nERROR in readccx: The input file \"%s\" could not be opened.\n\n",set); fileOpenError=1; return(filesopen); }
5784   else
5785   {
5786     handlein=handle;
5787     openfile[filesopen]=handlein; filesopen++;
5788   }
5789 
5790   return(filesopen);
5791 }
5792 
5793 
5794 
compareElfaces(Elfaces * a,Elfaces * b)5795 int compareElfaces(Elfaces *a, Elfaces *b)
5796 {
5797   /* wird von qsort aufgerufen, vergleicht int-Felder */
5798 
5799   if ( a[0].e < b[0].e )
5800     return -1 ;
5801   else if ( a[0].e > b[0].e )
5802     return 1 ;
5803   else if ( a[0].f < b[0].f )
5804     return -1 ;
5805   else if ( a[0].f > b[0].f )
5806     return 1 ;
5807   else
5808     return 0 ;
5809 }
5810 
5811 
5812 
generateNodeValuesFromFaces(void)5813 void generateNodeValuesFromFaces( void )
5814 {
5815   int i,j, setNr, anzx_l=0;
5816   double nval;
5817   char *string;
5818   char setName[MAX_LINE_LENGTH], nodeName[MAX_LINE_LENGTH];
5819 
5820   /* go over all sets and perform due actions */
5821   for(setNr=0; setNr<anzx->sets; setNr++)
5822   {
5823     if(setx[setNr].name!=NULL)
5824     {
5825       /* is a certain dataset referenced? Only then create the additional data */
5826       string=strstr(setx[setNr].name,"ds");
5827       //printf("set:%s str:%s\n",setx[setNr].name,string);
5828 
5829       if((setx[setNr].anz_elf)&&(string))
5830       {
5831         printf(" generate node-values for set:%s\n", setx[setNr].name);
5832 
5833         anzx_l=atoi(&string[2]);
5834         *(string-1)=0;
5835 
5836         /* is it valid for a certain sector? */
5837         string=strstr(setx[setNr].name,"_s");
5838 
5839         /* ini lcase */
5840         sprintf( lcasex[anzx_l].name,"%s",setx[setNr].name);
5841         printf (" fill dataset:%d name= %s\n", anzx_l, lcasex[anzx_l].name);
5842         lcasex[anzx_l].ncomps=setx[setNr].elf[0].n+1;
5843 	printf(" ncomps:%d\n",lcasex[anzx_l].ncomps);
5844         lcasex[anzx_l].irtype=1;
5845         lcasex[anzx_l].npheader=0;
5846         lcasex[anzx_l].value=0;
5847 
5848         strcpy(lcasex[anzx_l].analysis_name,"");
5849         strcpy(lcasex[anzx_l].dataset_text,"");
5850         //lcasex[anzx_l].step_number=step_nr;
5851         sprintf(lcasex[anzx_l].dataset_name,"STP %d", lcasex[anzx_l].step_number);
5852         lcasex[anzx_l].analysis_type=1;
5853 
5854         if ( (lcasex[anzx_l].nmax = (int *)malloc( lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5855           printf("\n\n ERROR: malloc failure\n\n" );
5856         if ( (lcasex[anzx_l].nmin = (int *)malloc( lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5857           printf("\n\n ERROR: malloc failure\n\n" );
5858         if ( (lcasex[anzx_l].max = (float *)malloc(lcasex[anzx_l].ncomps * sizeof(float))) == NULL )
5859           printf("\n\n ERROR: malloc failure\n\n" );
5860         if ( (lcasex[anzx_l].min = (float *)malloc(lcasex[anzx_l].ncomps * sizeof(float))) == NULL )
5861           printf("\n\n ERROR: malloc failure\n\n" );
5862         if ( (lcasex[anzx_l].dat = (float **)malloc(lcasex[anzx_l].ncomps * sizeof(float *))) == NULL )
5863           printf("\n\n ERROR: malloc failure\n\n" );
5864         if ( (lcasex[anzx_l].compName = (char **)malloc(lcasex[anzx_l].ncomps * sizeof(char *))) == NULL )
5865           printf("\n\n ERROR: malloc failure\n\n" );
5866         if ( (lcasex[anzx_l].icname = (char **)malloc(lcasex[anzx_l].ncomps * sizeof(char *))) == NULL )
5867           printf("\n\n ERROR: malloc failure\n\n" );
5868         if ( (lcasex[anzx_l].menu = (int *)malloc(lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5869           printf("\n\n ERROR: malloc failure\n\n" );
5870         if ( (lcasex[anzx_l].ictype = (int *)malloc(lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5871           printf("\n\n ERROR: malloc failure\n\n" );
5872         if ( (lcasex[anzx_l].icind1 = (int *)malloc(lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5873           printf("\n\n ERROR: malloc failure\n\n" );
5874         if ( (lcasex[anzx_l].icind2 = (int *)malloc(lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5875           printf("\n\n ERROR: malloc failure\n\n" );
5876         if ( (lcasex[anzx_l].iexist = (int *)malloc(lcasex[anzx_l].ncomps * sizeof(int))) == NULL )
5877           printf("\n\n ERROR: malloc failure\n\n" );
5878 
5879         for(i=0; i<lcasex[anzx_l].ncomps; i++)
5880         {
5881           if ( (lcasex[anzx_l].dat[i] = (float *)calloc( (anzx->nmax+1), sizeof(float))) == NULL )
5882             printf("\n\n ERROR: malloc failure\n\n" );
5883           if ( (lcasex[anzx_l].compName[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
5884             printf("\n\n ERROR: malloc failed\n\n" );
5885           if ( (lcasex[anzx_l].icname[i] = (char *)calloc( MAX_LINE_LENGTH, sizeof(char))) == NULL )
5886             printf("\n\n ERROR: malloc failed\n\n" );
5887           lcasex[anzx_l].menu[i] = 1;
5888           lcasex[anzx_l].ictype[i] = 1;
5889           lcasex[anzx_l].icind1[i] = i+1;
5890           lcasex[anzx_l].icind2[i] = 0;
5891           lcasex[anzx_l].iexist[i] = 0;
5892           lcasex[anzx_l].max[i]=-MAX_FLOAT;
5893           lcasex[anzx_l].min[i]=MAX_FLOAT;
5894           sprintf ( lcasex[anzx_l].compName[i], "val%d",i+1);
5895         }
5896         lcasex[anzx_l].iexist[0] = -1;
5897         lcasex[anzx_l].menu[i-1] = 0;
5898         strcpy ( lcasex[anzx_l].compName[i-1], "nodes");
5899 
5900 
5901         /* combine loads from same faces first! */
5902         /* sort according to elem, face */
5903 	/*
5904         qsort( setx[setNr].elf, setx[setNr].anz_elf, sizeof(Elfaces), (void *)compareElfaces );
5905 
5906         // if previous elem has same nr and face, add the values to this one and set n to 0 of the previous one
5907         for(i=1; i<setx[setNr].anz_elf; i++)
5908         {
5909           if((setx[setNr].elf[i].e==setx[setNr].elf[i-1].e) && (setx[setNr].elf[i].f==setx[setNr].elf[i-1].f))
5910 	  {
5911             for(j=0; j<setx[setNr].elf[i].n; j++) setx[setNr].elf[i].v[j]+=setx[setNr].elf[i-1].v[j];
5912             setx[setNr].elf[i-1].n=0;
5913 	  }
5914 	}
5915 	*/
5916 
5917         for(i=0; i<setx[setNr].anz_elf; i++)
5918         {
5919           writeFaceVals(anzx_l, setx[setNr].elf[i].e, setx[setNr].elf[i].f, setx[setNr].elf[i].n, setx[setNr].elf[i].v);
5920 	}
5921         for(i=0; i<lcasex[anzx_l].ncomps-1; i++)
5922         {
5923           for(j=0; j<anzx->n; j++) if(lcasex[anzx_l].dat[lcasex[anzx_l].ncomps-1][nodex[j].nr]>0)
5924           {
5925             nval=lcasex[anzx_l].dat[i][nodex[j].nr]/lcasex[anzx_l].dat[lcasex[anzx_l].ncomps-1][nodex[j].nr];
5926             if (nval >  lcasex[anzx_l].max[i])
5927             {  lcasex[anzx_l].max[i]=nval; lcasex[anzx_l].nmax[i]=nodex[j].nr; }
5928             if (nval <  lcasex[anzx_l].min[i])
5929             {  lcasex[anzx_l].min[i]=nval; lcasex[anzx_l].nmin[i]=nodex[j].nr; }
5930           }
5931           printf("max min :%f %f\n",lcasex[anzx_l].max[i],lcasex[anzx_l].min[i]);
5932         }
5933 
5934         /* generate common sets to cluster the face loads only if the value is likely a set identifier (1..99) */
5935         if((lcasex[anzx_l].ncomps==2)&&(lcasex[anzx_l].max[0]>=1)&&(lcasex[anzx_l].max[0]<100)&&(lcasex[anzx_l].min[0]>=1))
5936         {
5937           for(j=0; j<anzx->n; j++) if(lcasex[anzx_l].dat[1][nodex[j].nr]>0)
5938           {
5939             nval=lcasex[anzx_l].dat[0][nodex[j].nr]/lcasex[anzx_l].dat[1][nodex[j].nr];
5940 	    //printf("nval:%f %d\n",nval,(int)nval);
5941             sprintf( setName, "%s%d", setx[setNr].name, (int)nval);
5942             sprintf( nodeName, "%d", nodex[j].nr);
5943             pre_setax( setName, "n", nodeName);
5944 	  }
5945         }
5946 
5947       }
5948     }
5949   }
5950 }
5951 
5952 
5953 
readccx(char * datin,Summen * apre,Sets ** sptr,Nodes ** nptr,Elements ** eptr,Datasets ** lptr)5954 int readccx(char *datin, Summen *apre, Sets **sptr, Nodes **nptr, Elements **eptr, Datasets **lptr )
5955 {
5956   int i, j, jj, l, nr, length, args;
5957   char rec_str[MAX_LINE_LENGTH];
5958   char command[MAX_LINE_LENGTH];
5959 
5960   /* reset for each call */
5961   step_nr=0;
5962   step_flag=0;
5963   copyFlag=0;
5964   resetFlag=0;
5965   filesopen=0;
5966   matnr=0;
5967   ansFlag=0;
5968   userTempSetNr=-1;
5969   anz_fb=-1;
5970   dataset_value=0;
5971   node_field_size=0;
5972   elem_field_size=0;
5973   elem_field_size2=0;
5974   dlo_field_size=1;
5975   film_field_size=1;
5976   rad_field_size=1;
5977   amp_field_size=1;
5978   mat_field_size=1;
5979 
5980   annotation();
5981   t1=clock() ;
5982 
5983   anzx=apre;
5984   setx=*sptr;
5985   //nodex=*nptr;
5986   //elemx=*eptr;
5987   nodex=NULL;
5988   elemx=NULL;
5989   lcasex=*lptr;
5990   anz_fb=-1;
5991   step_flag=0;
5992 #if ANSYS
5993   ansFlag=1;
5994   /* open the ansys file */
5995   handleans = fopen("ccx.ans", "w");
5996   elprop->nset=0;
5997   fprintf(handleans, "/PREP7\n");
5998   fprintf(handleans, "SHPP, OFF\n");
5999 #endif
6000 #if TEST
6001   printFlag=1;
6002 #endif
6003 #if NODE_OFFSET
6004   copyFlag=1;
6005   handle_equ = fopen ("cgx.equ", "w");
6006   if ( handle_equ== NULL )  { printf ("\nThe file cgx.equ could not be opened.\n"); return(-1); }
6007 #endif
6008 
6009   /* allocate space */
6010 
6011   if(!anzx->nmax) node_field_size=INI_FIELD_SIZE; else node_field_size=anzx->nmax;
6012   anzx->nmax=0;
6013   do
6014   {
6015     if ( (nodex = (Nodes *)realloc( (Nodes *)nodex, (node_field_size+1) * sizeof(Nodes))) == NULL )
6016     {
6017       printf("WARNING: in readccx() is INI_FIELD_SIZE:%d to large and is reduced\n", node_field_size );
6018       node_field_size/=2;
6019     }
6020     if(node_field_size<1)
6021     {
6022       printf("\n\n ERROR: not enough memory in readccx()\n\n");
6023       exit(0);
6024     }
6025     for(i=0; i<node_field_size; i++) nodex[i].indx=-1;
6026   }while(!nodex);
6027 
6028   if(!anzx->emax) elem_field_size=INI_FIELD_SIZE; else elem_field_size=anzx->emax;
6029   anzx->nmax=0;
6030   elem_field_size2=elem_field_size;
6031   do
6032   {
6033     if((elemx = (Elements *)realloc( (Elements *)elemx, (elem_field_size+1) * sizeof(Elements))) == NULL )
6034     {
6035       printf("WARNING: in readccx() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size );
6036       elem_field_size/=2;
6037     }
6038     if(elem_field_size<1)
6039     {
6040       printf("\n\n ERROR: not enough memory in readccx()\n\n");
6041       exit(-1);
6042     }
6043   }while(!elemx);
6044   do
6045   {
6046     if((e_enqirex=(Elements *)realloc((Elements *)e_enqirex,(elem_field_size2+1)*sizeof(Elements)))==NULL)
6047     {
6048       printf("WARNING: in readccx() is INI_FIELD_SIZE:%d to large and is reduced\n", elem_field_size2 );
6049       elem_field_size2/=2;
6050     }
6051     if(elem_field_size2<1)
6052     {
6053       printf("\n\n ERROR: not enough memory in readccx()\n\n");
6054       exit(-1);
6055     }
6056   }while(!e_enqirex);
6057   for(i=0; i<=elem_field_size2; i++) e_enqirex[i].type=0;
6058 
6059   if ( (lcasex = (Datasets *)realloc((Datasets *)lcasex, (anzx->l+2) * sizeof(Datasets))) == NULL )
6060     printf("\n\n ERROR: realloc failed\n\n") ;
6061 
6062   if((dat = (char **)realloc((char **)dat, (DAT_SIZE)*sizeof(char*)))==NULL)
6063   errMsg("\n\n ERROR: realloc failed for **dat\n" );
6064   for (i=0; i<DAT_SIZE; i++)
6065   {
6066     dat[i]=NULL;
6067     if((dat[i] = (char *)realloc((char *)dat[i], (MAX_LINE_LENGTH)*sizeof(char)))==NULL)
6068       errMsg("\n\n ERROR: realloc failed for *dat\n" );
6069   }
6070 
6071   /* scan through the input-file and look for keywords */
6072 
6073   handlein = fopen(datin, "r");
6074   if ( handlein== NULL )  { printf ("\nThe input file \"%s\" could not be opened.\n\n",datin); return(-1);}
6075   else { filesopen=1; openfile[0]=handlein; }
6076 
6077   do
6078   {
6079     /* all subroutines return eventually the next keyword which could be any. Therefore check again */
6080     length=abqrecord(rec_str);
6081     //printf("Length:%d string:%s\n",length,rec_str);
6082     if(length==-1) break;
6083     checknextstr1:;
6084 
6085     /* get the arguments of the string */
6086     args=crecord(rec_str, dat);
6087     if(args==0) continue;
6088 
6089     /* toupper */
6090     i=0; while(dat[0][i]!='\0') { dat[0][i]=toupper(dat[0][i]); i++; }
6091 
6092     /* get the nodes */
6093     if (compare(dat[0], "*NODE",5)==5) { length=getNodes(rec_str); goto checknextstr1; }
6094 
6095     /* get the elements */
6096     else if ((compare(dat[0], "*ELEMENT",8)==8)&&(strlen(dat[0])==8)) { length=getElements(rec_str); goto checknextstr1; }
6097 
6098     /* get the set-definitions */
6099     else if (compare(dat[0], "*ELSET",6)==6) { length=getElset(rec_str); goto checknextstr1; }
6100     else if (compare(dat[0], "*NSET",5)==5) { length=getNset(rec_str); goto checknextstr1; }
6101     else if (compare(dat[0], "*SURFACE",7)==7) { length=getSurfaces(rec_str); goto checknextstr1; }
6102   }while(length!=-1);
6103   fclose(handlein);
6104 
6105   node_field_size=anzx->nmax+1;
6106   if((nodex = (Nodes *)realloc( (Nodes *)nodex, node_field_size * sizeof(Nodes))) == NULL )
6107     printf("\n\n ERROR: realloc failed\n\n") ;
6108   else
6109     printf ("\n %d nodes reallocated \n",anzx->nmax);
6110   elem_field_size=anzx->e+1;
6111   if ( (elemx = (Elements *)realloc((Elements *)elemx, elem_field_size * sizeof(Elements))) == NULL )
6112     printf("\n\n ERROR: in readccx realloc failed\n\n") ;
6113   else
6114     printf ("\n %d elements reallocated \n", anzx->e);
6115 
6116   handlein = fopen(datin, "r");
6117   if ( handlein== NULL )  { printf ("\nThe input file \"%s\" could not be opened.\n\n",datin); return(-1);}
6118   else { filesopen=1; openfile[0]=handlein; }
6119 
6120   do
6121   {
6122     /* all subroutines return eventually the next keyword which could be any. Therefore check again */
6123     length=abqrecord(rec_str);
6124     if(length==-1) break;
6125     checknextstr:;
6126 
6127     /* get the arguments of the string */
6128     args=crecord(rec_str, dat);
6129     if(args==0) continue;
6130 
6131     /* toupper */
6132     i=0; while(dat[0][i]!='\0') { dat[0][i]=toupper(dat[0][i]); i++; }
6133 
6134     /* fix for oragl input */
6135     if (compareStrings(dat[0], "*CONTACT")==8) { strcpy(dat[0], "*CONTACTPAIR"); }
6136 
6137     /* get the cload */
6138     if (compare(dat[0], "*CLOAD",5)==5) { length=getCload(rec_str); goto checknextstr; }
6139 
6140     /* get the cflux */
6141     else if (compare(dat[0], "*CFLUX",5)==5) { length=getCflux(rec_str); goto checknextstr; }
6142 
6143     /* get the dload */
6144     else if (compare(dat[0], "*DLOAD",5)==5) { length=getDload(rec_str, 0); goto checknextstr; }
6145 
6146     /* get the dsload */
6147     else if (compare(dat[0], "*DSLOAD",5)==5) { length=getDload(rec_str, 1); goto checknextstr; }
6148 
6149     /* get the radiation */
6150     else if (compare(dat[0], "*RADIATION",5)==5) { length=getRadiation(rec_str); goto checknextstr; }
6151 
6152     /* get the film */
6153     else if (compare(dat[0], "*FILM",5)==5) { length=getFilm(rec_str); goto checknextstr; }
6154 
6155     /* get the massflow */
6156     else if ((compare(dat[0], "*MASSFLOW",9)==9)||(compare(dat[0], "*MASS FLOW",9)==9)) { length=getMassflow(rec_str); goto checknextstr; }
6157 
6158     /* get the dflux */
6159     else if (compare(dat[0], "*DFLUX",5)==5) { length=getDflux(rec_str); goto checknextstr; }
6160 
6161     /* get the heading */
6162     else if (compare(dat[0], "*HEADING",7)==7)
6163     {
6164       strcpy(rec_str,"ULIN ");
6165       length=abqrecord(&rec_str[5]);
6166       strcpy(command,"ULIN");
6167       commandoInterpreter( command, rec_str, 4, 0, 0, 0, 0 );
6168       goto checknextstr;
6169     }
6170 
6171     /* get step-info */
6172     else if (compare(dat[0], "*STEP",5)==5) { step_nr++; step_flag=1; }
6173     //else if (compare(dat[0], "*ENDSTEP",8)==8) { endstep(); }
6174     else if (compare(dat[0], "*STATIC",7)==7) { length=getStatic(rec_str); goto checknextstr; }
6175 
6176     /* get the surfaces and contact pairs */
6177     /* first the oragl pressures */
6178     else if (compare(dat[0],"*SURFACEINTERACTION",11)==11)
6179     {
6180       for(i=0; i<args; i++)
6181       {
6182         if(compare(dat[i],"PRELOAD",4)==4)
6183 	{
6184           if(compare(strstr(dat[i],"="), "=PRESSURE",4)==4)
6185 	  {   length=getScalarvalue(rec_str, "PRESSURE"); goto checknextstr; }
6186 	}
6187       }
6188     }
6189     else if (compare(dat[0], "*CONTACTPAIR",11)==11) { length=getContactPair(rec_str); goto checknextstr; }
6190     else if (compare(dat[0], "*TIE",4)==4) { length=getContactPair(rec_str); goto checknextstr; }
6191 
6192     /* get the initial conditions */
6193     else if (compare(dat[0], "*INITIALCONDITIONS",18)==18) { length=getInitialConditions(rec_str); goto checknextstr; }
6194 
6195     /* get the boundaries */
6196     else if (compare(dat[0], "*BOUNDARYF",10)==10) { length=getSpcf(rec_str); goto checknextstr; }
6197     else if (compare(dat[0], "*BOUNDARY",9)==9) { length=getBoundaries(rec_str); goto checknextstr; }
6198 
6199     /* get the equations */
6200     else if (compare(dat[0], "*EQUATIONF",10)==10) { length=getEquationf(rec_str); goto checknextstr; }
6201     else if (compare(dat[0], "*EQUATION",9)==9) { length=getEquations(rec_str); goto checknextstr; }
6202 
6203     /* get the mpc */
6204     else if (compare(dat[0], "*MPC",4)==4) { length=getMpc(rec_str); goto checknextstr; }
6205 
6206     /* open the material-file */
6207     else if (compare(dat[0], "*MATERIAL",9)==9) { length=getMaterial(rec_str); goto checknextstr; }
6208 
6209     /* get the material-definitions */
6210     else if (compare(dat[0], "*ELASTIC",8)==8) { length=getElastic(rec_str); goto checknextstr; }
6211     else if (compare(dat[0], "*EXPANSION",8)==8) { length=getExpansion(rec_str); goto checknextstr; }
6212     else if (compare(dat[0], "*CONDUCTIVITY",8)==8) { length=getConductivity(rec_str); goto checknextstr; }
6213     else if (compare(dat[0], "*SPECIFICHEAT",8)==8) { length=getSpecificHeat(rec_str); goto checknextstr; }
6214     else if (compare(dat[0], "*DENSITY",8)==8) { length=getDensity(rec_str); goto checknextstr; }
6215     else if (compare(dat[0], "*PLASTIC",8)==8) { length=getPlastic(rec_str); goto checknextstr; }
6216 
6217     /* get the amplitude-definitions */
6218     else if (compare(dat[0], "*AMPLITUDE",6)==6) { length=getAmplitude(rec_str); goto checknextstr; }
6219 
6220     /* asign material to sets */
6221     else if (compare(dat[0], "*SHELLSECTION",13)==13) { length=getShellSelection(rec_str); goto checknextstr; }
6222     else if (compare(dat[0], "*SOLIDSECTION",13)==13) { length=getSolidSelection(rec_str); goto checknextstr; }
6223 
6224     /* asign TEMPERATURE to sets */
6225     else if (compare(dat[0], "*TEMPERATURE",12)==12) { length=getScalarvalue(rec_str, &dat[0][1]); goto checknextstr; }
6226     else if (compare(dat[0], "*UTEMPINCLUDE",12)==12) { length=getUserTemps(rec_str); }
6227 
6228     /* get the coordinate systems */
6229     else if (compare(dat[0], "*TRANSFORM",7)==7) { length=getTransform(rec_str); goto checknextstr; }
6230 
6231 
6232     /* jump the nodes */
6233     else if (compare(dat[0], "*NODE",5)==5) ;
6234 
6235     /* jump the elements */
6236     else if (compare(dat[0], "*ELEMENT",8)==8) ;
6237 
6238     /* jump the set-definitions */
6239     else if (compare(dat[0], "*ELSET",6)==6) ;
6240     else if (compare(dat[0], "*NSET",5)==5) ;
6241     else if (compare(dat[0], "*SURFACE",7)==7) ;
6242 
6243     else
6244     {
6245       if ((dat[0][0]=='*')&&(dat[0][1]!='*')) printf("WARNING: %s not known. Data ignored.\n", dat[0]);
6246     }
6247   }while(length!=-1);
6248   fclose(handlein);
6249 
6250   /* reset temporary setpointer */
6251   resetFlag=1;
6252   getBoundaries(0);
6253   getEquations(0);
6254   getContactPair(0);
6255   writeElemAns(0,0,0,0,0);
6256   getCload(0);
6257   getCflux(0);
6258   getDload(0, 0);
6259   getDflux(0);
6260   getMassflow(0);
6261   getRadiation(0);
6262   getFilm(0);
6263   resetFlag=0;
6264 
6265   /*
6266   t2=clock() ;
6267   printf("\nread in %.2f seconds\n", ((double)t2 - (double)t1)/(double)CLOCKS_PER_SEC) ;
6268   */
6269 
6270   /* check if nodes or elements were found */
6271   if(anzx->nmax==-MAX_INTEGER)
6272   {
6273     /* no nodes allocated */
6274     anzx->nmax=anzx->nmin=0;
6275   }
6276   if(anzx->emax==-MAX_INTEGER)
6277   {
6278     /* no elements allocated */
6279     anzx->emax=anzx->emin=0;
6280   }
6281   if(fileOpenError)
6282   {
6283     /* no nodes allocated */
6284     anzx->nmax=anzx->nmin=0;
6285     /* no elements allocated */
6286     anzx->emax=anzx->emin=0;
6287   }
6288 
6289   /* generate node-values (additional Datasets) from face-loads (dload, film etc.) */
6290   generateNodeValuesFromFaces();
6291 
6292   /* set all lcasex.loaded to 1 to indicate that the data are available */
6293   for (i=0; i<anzx->l; i++) { lcasex[i].fileptr=NULL; lcasex[i].loaded=1; }
6294 
6295   for(l=0; l<anzx->l; l++)
6296   {
6297     for(j=0; j<lcasex[l].ncomps; j++)
6298     {
6299       /* divide all face-loads by the nr of nodes who summed up to the value */
6300       if(lcasex[l].iexist[j] <0)
6301       {
6302         nr=-lcasex[l].iexist[j];
6303         lcasex[l].iexist[j]=0;
6304         for (i=0; i<anzx->n; i++)
6305         {
6306           if(lcasex[l].dat[nr][nodex[i].nr])
6307           {
6308             for(jj=0; jj<nr; jj++) lcasex[l].dat[jj][nodex[i].nr]/= lcasex[l].dat[nr][nodex[i].nr];
6309             lcasex[l].dat[nr][nodex[i].nr]=1;
6310 	  }
6311 	}
6312       }
6313     }
6314 
6315     for(j=0; j<lcasex[l].ncomps; j++)
6316     {
6317       for (i=0; i<anzx->n; i++)
6318       {
6319         if (lcasex[l].dat[j][nodex[i].nr] >  lcasex[l].max[j])
6320         {
6321           lcasex[l].max[j]=lcasex[l].dat[j][nodex[i].nr];
6322           lcasex[l].nmax[j]=nodex[i].nr;
6323         }
6324         if (lcasex[l].dat[j][nodex[i].nr] <  lcasex[l].min[j])
6325         {
6326           lcasex[l].min[j]=lcasex[l].dat[j][nodex[i].nr];
6327           lcasex[l].nmin[j]=nodex[i].nr;
6328         }
6329       }
6330     }
6331   }
6332 
6333   /* resize the entities */
6334   if (anzx->amps)
6335     if ((amplitude = (Amplitudes *)realloc( (Amplitudes *)amplitude, (anzx->amps+1)*sizeof(Amplitudes)) ) == NULL )
6336     {
6337       printf("\n\n ERROR: amplitudes:%d could not be resized\n", anzx->amps );
6338     }
6339   if (anzx->mats)
6340     if ((material = (Materials *)realloc( (Materials *)material, (anzx->mats+1)*sizeof(Materials)) ) == NULL )
6341     {
6342       printf("\n\n ERROR: materials:%d could not be resized\n", anzx->mats );
6343     }
6344   free(e_enqirex);
6345   e_enqirex=NULL;
6346 
6347   *sptr= setx; *nptr =  nodex; *eptr = elemx; *lptr = lcasex;
6348   if(ansFlag) fclose(handleans);
6349 
6350   return(1);
6351 }
6352