1 
2 #include <cgx.h>
3 
write2dolfyn(char * setname,int strings,char ** string,Summen * anz,Nodes * node,Faces * face,Elements * e_enqire,Sets * set)4 int write2dolfyn(char *setname, int strings, char **string, Summen *anz, Nodes *node, Faces *face, Elements *e_enqire, Sets *set)
5 {
6     FILE *handle1=NULL;
7     char datout[MAX_LINE_LENGTH];
8     int  i, j=0, k, n, setNr;
9 
10     /* check if we have a mesh */
11     if(anz->e==0) {
12         printf("ERROR: No mesh!\n");
13         return(0);
14     }
15 
16     setNr=getSetNr(setname);
17     if(setNr>-1)
18     {
19         /* write vertices */
20         sprintf(datout, "%s.vrt", setname);
21         handle1 = fopen (datout, "w+b");
22         if (handle1==NULL) {
23             printf ("\nThe output file \"%s\" could not be opened.\n\n", datout);
24             return(-1);
25         } else {
26             printf (" file %s opened\n",datout);
27         }
28 
29         for(i=0; i<set[setNr].anz_n; i++)
30         {
31             fprintf (handle1, "%9d      %16.9E%16.9E%16.9E\n", set[setNr].node[i],
32                      node[set[setNr].node[i]].nx, node[set[setNr].node[i]].ny,
33                      node[set[setNr].node[i]].nz);
34         }
35 
36         fclose(handle1);
37         handle1 = NULL;
38 
39         /* write elements */
40         sprintf(datout, "%s.cel", setname);
41         handle1 = fopen (datout, "w+b");
42         if (handle1==NULL) {
43             printf ("\nThe output file \"%s\" could not be opened.\n\n", datout);
44             return(-1);
45         } else {
46             printf (" file %s opened\n",datout);
47         }
48 
49         for(i=0; i<set[setNr].anz_e; i++)
50         {
51             if (e_enqire[set[setNr].elem[i]].type == 1) {
52                 /* HEXA8 */
53                 fprintf (handle1, "%9d      %9d%9d%9d%9d%9d%9d%9d%9d    %5d%5d\n",
54                          set[setNr].elem[i],
55                          e_enqire[set[setNr].elem[i]].nod[0],
56                          e_enqire[set[setNr].elem[i]].nod[1],
57                          e_enqire[set[setNr].elem[i]].nod[2],
58                          e_enqire[set[setNr].elem[i]].nod[3],
59                          e_enqire[set[setNr].elem[i]].nod[4],
60                          e_enqire[set[setNr].elem[i]].nod[5],
61                          e_enqire[set[setNr].elem[i]].nod[6],
62                          e_enqire[set[setNr].elem[i]].nod[7], 1, 1);
63             } else if (e_enqire[set[setNr].elem[j]].type == 2) {
64                 /* PENTA6 */
65                 fprintf (handle1, "%9d      %9d%9d%9d%9d%9d%9d%9d%9d    %5d%5d\n",
66                          set[setNr].elem[i],
67                          e_enqire[set[setNr].elem[i]].nod[0],
68                          e_enqire[set[setNr].elem[i]].nod[1],
69                          e_enqire[set[setNr].elem[i]].nod[2],
70                          e_enqire[set[setNr].elem[i]].nod[2],
71                          e_enqire[set[setNr].elem[i]].nod[3],
72                          e_enqire[set[setNr].elem[i]].nod[4],
73                          e_enqire[set[setNr].elem[i]].nod[5],
74                          e_enqire[set[setNr].elem[i]].nod[5], 1, 1);
75 
76             } else if (e_enqire[set[setNr].elem[j]].type == 3) {
77                 /* TET4 */
78                 fprintf (handle1, "%9d      %9d%9d%9d%9d%9d%9d%9d%9d    %5d%5d\n",
79                          set[setNr].elem[i],
80                          e_enqire[set[setNr].elem[i]].nod[0],
81                          e_enqire[set[setNr].elem[i]].nod[1],
82                          e_enqire[set[setNr].elem[i]].nod[2],
83                          e_enqire[set[setNr].elem[i]].nod[2],
84                          e_enqire[set[setNr].elem[i]].nod[3],
85                          e_enqire[set[setNr].elem[i]].nod[3],
86                          e_enqire[set[setNr].elem[i]].nod[3],
87                          e_enqire[set[setNr].elem[i]].nod[3], 1, 1);
88             } else {
89                 printf("Element type %d in element %d not supported!\n",
90                         e_enqire[set[setNr].elem[j]].type, set[setNr].elem[i]);
91             }
92         }
93 
94         fclose(handle1);
95         handle1 = NULL;
96     }
97 
98     /* write boundary */
99     if (strings > 0) {
100         sprintf(datout, "%s.bnd", setname);
101         handle1 = fopen (datout, "w+b");
102         if (handle1==NULL) {
103             printf ("\nThe output file \"%s\" could not be opened.\n\n", datout);
104             return(-1);
105         } else {
106             printf (" file %s opened\n",datout);
107         }
108     }
109 
110     j = k = 1;
111     n = 0;
112     do {
113         setNr=getSetNr(string[n + 1]);
114         if(setNr>-1) {
115             for(i=0; i<set[setNr].anz_f; i++)
116             {
117                 if (face[set[setNr].face[i]].type == 7) {
118                     /* TRI3  */
119                     fprintf (handle1, "%9d%9d%9d%9d    %5d%5d%10s\n",
120                     face[set[setNr].face[i]].nod[0],
121                     face[set[setNr].face[i]].nod[1],
122                     face[set[setNr].face[i]].nod[2],
123                     face[set[setNr].face[i]].nod[2],
124                     j, 0, string[n]);
125                 } else if (face[set[setNr].face[i]].type == 9) {
126                     /* QUAD4  */
127                     fprintf (handle1, "%9d%9d%9d%9d%9d    %5d%5d%10s\n", k,
128                     face[set[setNr].face[i]].nod[0],
129                     face[set[setNr].face[i]].nod[1],
130                     face[set[setNr].face[i]].nod[2],
131                     face[set[setNr].face[i]].nod[3],
132                     j, 0, string[n]);
133                 } else {
134                     printf("ERROR: face-type:%d not supported\n",
135                             face[set[setNr].face[i]].type);
136                 }
137                 k++;
138             }
139         }
140         n += 2;
141         j++;
142     } while(n < strings);
143 
144     if (strings > 0) {
145         fclose(handle1);
146         handle1 = NULL;
147     }
148 
149     return (1);
150 }
151