1 /* this is a function from Joel Phillips for generating matlab matrices
2 for visualization of a fastcap structure */
3 /* It produces the file panels.mat */
4
5 #include "mulGlobal.h"
6
dump_struct(chglist,qv)7 dump_struct(chglist,qv)
8 charge *chglist;
9 double *qv;
10 {
11
12 charge *cp;
13 double *x, *y, *z, *q;
14 int index;
15 FILE *fp, *fopen();
16 int type;
17 int size, i;
18 extern char *title, *ps_file_base, *in_file_name;
19 char *fname, *concat3();
20
21 fname = concat3(ps_file_base,".","mat");
22
23 fprintf(stdout,"Dumping structure to Matlab file %s\n", fname);
24
25 size = 0;
26 for (cp = chglist; cp != NULL; cp = cp->next) {
27 size++;
28 }
29 if ( (fp = fopen(fname, "w")) == NULL) {
30 fprintf(stderr, "Can't open %s\n",fname);
31 exit(1);
32 }
33
34 x = (double *) calloc( 4*size, sizeof(double));
35 y = (double *) calloc( 4*size, sizeof(double));
36 z = (double *) calloc( 4*size, sizeof(double));
37 q = (double *) calloc( 4*size, sizeof(double));
38
39 /* do the triangles */
40 index = 0;
41 for (cp = chglist; cp != NULL; cp = cp->next) {
42 if (cp->shape == 3) {
43 for (i=0; i<cp->shape; i++) {
44 x[3*index+i] = cp->corner[i][0] * cp->X[0] + cp->corner[i][1]*cp->Y[0] +
45 cp->corner[i][2] * cp->Z[0] + cp->x;
46
47 y[3*index+i] = cp->corner[i][0] * cp->X[1] + cp->corner[i][1]*cp->Y[1] +
48 cp->corner[i][2] * cp->Z[1] + cp->y;
49
50 z[3*index+i] = cp->corner[i][0] * cp->X[2] + cp->corner[i][1]*cp->Y[2] +
51 cp->corner[i][2] * cp->Z[2] + cp->z;
52
53 }
54 if (qv != NULL)
55 q[index] = qv[cp->index];
56 else
57 q[index] = 0.0;
58 index++;
59 }
60 }
61
62
63 #ifdef sun
64 type = 1000;
65 #else
66 type = 0000;
67 #endif
68 if (index > 0) {
69 savemat(fp, type, "xt", 3, index, 0, x, NULL);
70 savemat(fp, type, "yt", 3, index, 0, y, NULL);
71 savemat(fp, type, "zt", 3, index, 0, z, NULL);
72 savemat(fp, type, "qt", 3, index, 0, q, NULL);
73 }
74
75 /* now the quads */
76
77 index = 0;
78 for (cp = chglist; cp != NULL; cp = cp->next) {
79 if (cp->shape == 4) {
80 for (i=0; i<cp->shape; i++) {
81 x[4*index+i] = cp->corner[i][0] * cp->X[0] + cp->corner[i][1]*cp->Y[0] +
82 cp->corner[i][2] * cp->Z[0] + cp->x;
83
84 y[4*index+i] = cp->corner[i][0] * cp->X[1] + cp->corner[i][1]*cp->Y[1] +
85 cp->corner[i][2] * cp->Z[1] + cp->y;
86
87 z[4*index+i] = cp->corner[i][0] * cp->X[2] + cp->corner[i][1]*cp->Y[2] +
88 cp->corner[i][2] * cp->Z[2] + cp->z;
89
90 }
91 if (qv != NULL)
92 q[index] = qv[cp->index];
93 else
94 q[index] = 0.0;
95 index++;
96 }
97 }
98 if (index > 0) {
99 savemat(fp, type, "xq", 4, index, 0, x, NULL);
100 savemat(fp, type, "yq", 4, index, 0, y, NULL);
101 savemat(fp, type, "zq", 4, index, 0, z, NULL);
102 savemat(fp, type, "qq", 4, index, 0, q, NULL);
103 }
104
105 fclose(fp);
106
107 }
108
109