commit | author | age
|
7f6076
|
1 |
/* vim: set ts=4 sts=4 sw=4 noet : */ |
SP |
2 |
/* vim: set ts=4 sts=4 sw=4 noet : */ |
854cb6
|
3 |
#include<stdio.h> |
SP |
4 |
#include<general.h> |
|
5 |
#include<snapshot.h> |
22721d
|
6 |
#include<stdlib.h> |
SP |
7 |
#include<stdarg.h> |
|
8 |
#include <zlib.h> |
f0bcea
|
9 |
#include<inttypes.h> |
11fef8
|
10 |
#include<config.h> |
2e8c7f
|
11 |
#include <time.h> |
aecb11
|
12 |
#include <string.h> |
698ae1
|
13 |
#include "io.h" |
dba66b
|
14 |
#include <b64zlib_compression.h> |
a3dbf0
|
15 |
/* a helper function that utilizes ts_string data structure and performs same as sprintf */ |
22721d
|
16 |
ts_uint ts_sprintf(ts_string *str, char *fmt, ...){ |
SP |
17 |
va_list ap; |
|
18 |
va_start(ap,fmt); |
|
19 |
ts_uint n=vsprintf(&(str->string[str->beg]),fmt,ap); |
|
20 |
va_end(ap); |
|
21 |
str->beg+=n; |
|
22 |
return n; |
|
23 |
} |
|
24 |
|
a3dbf0
|
25 |
/* outputs additional data into paraview xml file */ |
854cb6
|
26 |
ts_bool xml_trisurf_data(FILE *fh, ts_vesicle *vesicle){ |
22721d
|
27 |
|
SP |
28 |
ts_string *data=(ts_string *)malloc(sizeof(ts_sprintf)); |
02d65c
|
29 |
data->string=(char *)malloc(5120000*sizeof(char)); /*TODO: warning, can break if the string is to long */ |
22721d
|
30 |
data->beg=0; |
SP |
31 |
|
854cb6
|
32 |
xml_trisurf_header(fh, vesicle); |
22721d
|
33 |
xml_trisurf_tria(data,vesicle->tlist); |
SP |
34 |
xml_trisurf_tria_neigh(data,vesicle->tlist); |
|
35 |
xml_trisurf_vtx_neigh(data,vesicle->vlist); |
|
36 |
xml_trisurf_vtx_tristar(data,vesicle->vlist); |
4891eb
|
37 |
xml_trisurf_nucleus(data,vesicle); |
49981c
|
38 |
xml_trisurf_constvolarea(data,V0,A0); |
aecb11
|
39 |
//#ifdef COMPRESSION |
f0bcea
|
40 |
char *compressed; |
588bbb
|
41 |
ts_uint nbytes=ts_compress_string64(data->string, data->beg-1, &compressed); //suppress null character at the end with by substracting 1 |
f0bcea
|
42 |
fwrite(compressed, sizeof(unsigned char), nbytes, fh); |
SP |
43 |
free (compressed); |
aecb11
|
44 |
//#else |
SP |
45 |
// fprintf(fh,"%s", data->string); |
|
46 |
//#endif |
a3dbf0
|
47 |
free(data->string); /* TODO: valgrind is not ok with this! */ |
22721d
|
48 |
free(data); |
854cb6
|
49 |
xml_trisurf_footer(fh); |
SP |
50 |
return TS_SUCCESS; |
|
51 |
} |
|
52 |
|
|
53 |
ts_bool xml_trisurf_header(FILE *fh, ts_vesicle *vesicle){ |
2e8c7f
|
54 |
/* format current time */ |
SP |
55 |
time_t current_time; |
|
56 |
char *c_time_string; |
|
57 |
current_time = time(NULL); |
|
58 |
c_time_string = ctime(¤t_time); |
a3dbf0
|
59 |
int npoly, nfono; |
SP |
60 |
|
e29756
|
61 |
fprintf(fh, "<trisurfversion>Trisurf (commit %s), compiled on %s %s</trisurfversion>\n",TS_VERSION, __DATE__, __TIME__); |
2e8c7f
|
62 |
fprintf(fh, "<dumpdate>%s</dumpdate>\n", c_time_string); |
SP |
63 |
|
cc95bd
|
64 |
fprintf(fh, "<tape>"); |
698ae1
|
65 |
fprintf(fh,"%s",tapetxt); |
f0bcea
|
66 |
fprintf(fh, "</tape>\n"); |
a3dbf0
|
67 |
if(vesicle->poly_list!=NULL){ |
SP |
68 |
npoly=vesicle->poly_list->n; |
|
69 |
if(npoly!=0){ |
|
70 |
nfono=vesicle->poly_list->poly[0]->vlist->n; |
|
71 |
} else { |
|
72 |
nfono=0; |
|
73 |
} |
|
74 |
} else { |
|
75 |
npoly=0; |
|
76 |
nfono=0; |
|
77 |
} |
86b69b
|
78 |
fprintf(fh, "<trisurf nvtx=\"%u\" npoly=\"%u\" nmono=\"%u\" compressed=\"false\">\n", vesicle->vlist->n, npoly, nfono); |
854cb6
|
79 |
return TS_SUCCESS; |
SP |
80 |
} |
|
81 |
|
|
82 |
ts_bool xml_trisurf_footer(FILE *fh){ |
|
83 |
fprintf(fh, "</trisurf>\n"); |
|
84 |
return TS_SUCCESS; |
|
85 |
} |
|
86 |
|
22721d
|
87 |
ts_bool xml_trisurf_tria(ts_string *data, ts_triangle_list *tlist){ |
854cb6
|
88 |
ts_uint i; |
588bbb
|
89 |
ts_sprintf(data,"<tria>"); |
854cb6
|
90 |
for(i=0; i<tlist->n;i++){ |
e87e4e
|
91 |
ts_sprintf(data,"%u %u %u ",tlist->tria[i]->vertex[0]->idx, tlist->tria[i]->vertex[1]->idx, tlist->tria[i]->vertex[2]->idx); |
854cb6
|
92 |
} |
588bbb
|
93 |
ts_sprintf(data,"</tria>"); |
854cb6
|
94 |
return TS_SUCCESS; |
SP |
95 |
} |
|
96 |
|
22721d
|
97 |
ts_bool xml_trisurf_tria_neigh(ts_string *data, ts_triangle_list *tlist){ |
854cb6
|
98 |
ts_uint i; |
22721d
|
99 |
ts_sprintf(data,"<trianeigh>\n"); |
854cb6
|
100 |
for(i=0; i<tlist->n;i++){ |
e87e4e
|
101 |
ts_sprintf(data,"%u %u %u ",tlist->tria[i]->neigh[0]->idx, tlist->tria[i]->neigh[1]->idx, tlist->tria[i]->neigh[2]->idx); |
854cb6
|
102 |
} |
22721d
|
103 |
ts_sprintf(data,"</trianeigh>\n"); |
854cb6
|
104 |
return TS_SUCCESS; |
SP |
105 |
} |
|
106 |
|
22721d
|
107 |
ts_bool xml_trisurf_vtx_neigh(ts_string *data, ts_vertex_list *vlist){ |
854cb6
|
108 |
ts_uint i,j; |
SP |
109 |
for(i=0;i<vlist->n;i++){ |
22721d
|
110 |
ts_sprintf(data,"<vtxn idx=\"%u\">",vlist->vtx[i]->idx); |
854cb6
|
111 |
for(j=0;j<vlist->vtx[i]->neigh_no;j++){ |
22721d
|
112 |
ts_sprintf(data,"%u ",vlist->vtx[i]->neigh[j]->idx); |
854cb6
|
113 |
} |
588bbb
|
114 |
ts_sprintf(data, "</vtxn>"); |
854cb6
|
115 |
} |
SP |
116 |
return TS_SUCCESS; |
|
117 |
} |
|
118 |
|
22721d
|
119 |
ts_bool xml_trisurf_vtx_tristar(ts_string *data, ts_vertex_list *vlist){ |
854cb6
|
120 |
ts_uint i,j; |
SP |
121 |
for(i=0;i<vlist->n;i++){ |
22721d
|
122 |
ts_sprintf(data,"<tristar idx=\"%u\">",vlist->vtx[i]->idx); |
854cb6
|
123 |
for(j=0;j<vlist->vtx[i]->tristar_no;j++){ |
22721d
|
124 |
ts_sprintf(data,"%u ",vlist->vtx[i]->tristar[j]->idx); |
854cb6
|
125 |
} |
588bbb
|
126 |
ts_sprintf(data, "</tristar>"); |
854cb6
|
127 |
} |
SP |
128 |
return TS_SUCCESS; |
|
129 |
} |
|
130 |
|
4891eb
|
131 |
ts_bool xml_trisurf_nucleus(ts_string *data, ts_vesicle* vesicle){ |
SP |
132 |
if(vesicle->R_nucleus>0.0 || (vesicle->R_nucleusX>0.0 && vesicle->R_nucleusY>0.0 && vesicle->R_nucleusZ>0.0)){ |
49981c
|
133 |
ts_sprintf(data,"<nucleus>%.17e %.17e %.17e</nucleus>",vesicle->nucleus_center[0], vesicle->nucleus_center[1], vesicle->nucleus_center[2]); |
4891eb
|
134 |
} |
SP |
135 |
return TS_SUCCESS; |
|
136 |
} |
49981c
|
137 |
ts_bool xml_trisurf_constvolarea(ts_string *data, ts_double volume, ts_double area){ |
SP |
138 |
ts_sprintf(data,"<constant_volume>%.17e</constant_volume>",volume); |
|
139 |
ts_sprintf(data,"<constant_area>%.17e</constant_area>",area); |
|
140 |
|
|
141 |
return TS_SUCCESS; |
|
142 |
} |
f0bcea
|
143 |
|