-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotSlice.c
More file actions
236 lines (206 loc) · 7.75 KB
/
plotSlice.c
File metadata and controls
236 lines (206 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "tipsyPlot.h"
#include <plplot/plplot.h>
#include <libconfig.h>
#define GAMMA 1.4
#define GAS_CONST 0.4
#define SLICE_MIN -0.1
#define SLICE_MAX 0.1
int main(int argc, char* argv[]){
printf("Hello World\n");
/*
######## ### ######## ### ## ## ######
## ## ## ## ## ## ## ## ### ### ## ##
## ## ## ## ## ## ## ## #### #### ##
######## ## ## ######## ## ## ## ### ## ######
## ######### ## ## ######### ## ## ##
## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ######
*/
const char* genericfilename = NULL;
const char* genericfileout = NULL;
const char* genericTitle = NULL;
int nsteps, interval, nbins;
double dxmin, dxmax, dymin, dymax, dmaxtemp, ddDelta;
float xmin, xmax, ymin, ymax, maxtemp, dDelta;
config_t cfg;
config_init(&cfg);
if (argv[1] == NULL || argc == 1){
system("cat nagato");
printf("Error: No config file was indicated\n\tPlease enter a config file.\n");
printf("\tThe following config files were found in your working directory:\n");
system("ls *.config");
exit(-1);
}
if (config_read_file(&cfg, argv[1]) == 0){
system("cat nagato");
printf("Error: cannot find file %s\n", argv[1]);
exit(-1);
}
else {
printf("reading config file: %s\n", argv[1]);
config_lookup_string(&cfg, "genericfilename", &genericfilename);
printf("\tgenericfilename = %s\n", genericfilename);
config_lookup_string(&cfg, "genericfileout", &genericfileout);
printf("\tgenericfileout = %s\n", genericfileout);
config_lookup_string(&cfg, "genericTitle", &genericTitle);
printf("\tgenericTitle = %s\n", genericTitle);
config_lookup_int(&cfg, "nsteps", &nsteps);
config_lookup_int(&cfg, "interval", &interval);
printf("\tnsteps = %d\tinterval = %d\n", nsteps, interval);
config_lookup_int(&cfg, "nbins", &nbins);
printf("\tnbins = %d\n", nbins);
config_lookup_float(&cfg, "xmin", &dxmin);
config_lookup_float(&cfg, "xmax", &dxmax);
config_lookup_float(&cfg, "ymin", &dymin);
config_lookup_float(&cfg, "ymax", &dymax);
xmin=(float)dxmin; xmax=(float)dxmax; ymin=(float)dymin; ymax=(float)dymax;
printf("\txmin = %f\txmax = %f\n\tymin = %f\tymax = %f\n", xmin, xmax, ymin, ymax);
config_lookup_float(&cfg, "maxtemp", &dmaxtemp);
maxtemp=(float)dmaxtemp;
printf("\tmaxtemp = %f\n", maxtemp);
config_lookup_float(&cfg, "dDelta", &ddDelta);
dDelta=(float)ddDelta;
printf("\tdDelta = %f\n", dDelta);
}
const int nout = (int)nsteps/interval;
/*
## ## ### ######## ######
## ## ## ## ## ## ## ##
## ## ## ## ## ## ##
## ## ## ## ######## ######
## ## ######### ## ## ##
## ## ## ## ## ## ## ##
### ## ## ## ## ######
*/
char simname[100];
char filenameout[100];
char title[100];
char command[500];
int i, j;
int filetime;
tipsy* snap;
tipsy* snapl;
tipsy* snapr;
profile* pfilel; // need a dummy profile cuz I'm dumb and the whole profile and variable calculation functions are dumb and I'm too lazy to make a nicer one rn
profile* pfiler;
/*
DERIVED ARRAYS
*/
int numvars = 1;
printf("here\n");
derivedvar* plotvars = (derivedvar*)malloc(numvars*sizeof(derivedvar));
initializeDerivedVar(&plotvars[0], "y", "slice", "slice", calc_y, TYPE_GAS);
printf("\n\n\n");
/*
######## ## ####### ########
## ## ## ## ## ##
## ## ## ## ## ##
######## ## ## ## ##
## ## ## ## ##
## ## ## ## ##
## ######## ####### ##
*/
printf("creating plots now\n");
// delete all pictures
printf("rm test/slice/*.png -v\n");
system("rm test/slice/slice.*.png -v");
for (i=0; i<nout; i++){
filetime = (i+1)*interval; // calculate current filename time
sprintf(simname, "%s.%05d", genericfilename, filetime); // generate filename
printf("reading: %s\n", simname);
snap = readTipsyStd(simname); // prepare cropped tipsys
snapl = tipsyClone(snap);
snapr = tipsyClone(snap);
hackyTipsySplit(snap, snapl, snapr);
tipsyExtend(snapl, 28672, 0, 0);
tipsyExtend(snapr, 28672, 0, 0);
tipsyCrop(snapl, cropThinSliceZ);
tipsyCrop(snapr, cropThinSliceZ);
pfilel = profileCreate(snapl, nbins, xmin, xmax, xpos);
pfiler = profileCreate(snapr, nbins, xmin, xmax, xpos);
for (j=0; j<numvars; j++){
printf("\tplotting: slice\n");
sprintf(filenameout, "./test/slice/slice.%s.%05d.png", genericfileout, filetime);
sprintf(title, "%s: %s t=%.4f", genericTitle, plotvars[j].title, (float)filetime*dDelta);
plsdev("pngcairo");
plfontld(1);
plsetopt("geometry", "810x670");
plsetopt("dpi", "810x670");
plscolbg(255, 255, 255);
plscol0(1, 0, 0, 0);
plsfnam(filenameout);
plinit();
plenv(xmin, xmax, ymin, ymax, 0, 0);
pllab("x", "y", title);
// plot points
plcol0(9); // blue
calculateDerivedVarPoints(&plotvars[j], pfilel, TYPE_GAS);
plstring(snapl->head->nsph, plotvars[j].points_xs, plotvars[j].points_ys, "#(210)");
plcol0(13); // magenta
calculateDerivedVarPoints(&plotvars[j], pfiler, TYPE_GAS);
plstring(snapr->head->nsph, plotvars[j].points_xs, plotvars[j].points_ys, "#(210)");
plend();
}
tipsyDestroy(snap);
tipsyDestroy(snapl);
tipsyDestroy(snapr);
profileDestroy(pfilel);
profileDestroy(pfiler);
}
// make gifs
float delay = (float)1000/(float)nout;
sprintf(command, "convert -layers optimize -delay %f ./test/slice/slice.*.png ./test/slice.animation.gif", delay);
printf("%s\n", command);
system(command);
return 0;
}
// hacky functions cuz I need it rn
void hackyTipsySplit(tipsy* tipsyIn, tipsy* tipsyLeft, tipsy* tipsyRight){
int i;
for (i=0; i<28672; i++){
pFlopGas(&tipsyLeft->gas[i], &tipsyIn->gas[i], NULL, flopCopy);
}
for (i=28672; i<57344; i++){
pFlopGas(&tipsyRight->gas[i-28672], &tipsyIn->gas[i], NULL, flopCopy);
}
}
// slice crops
int cropThinSliceZ(void* particle, int type){
if (type == TYPE_GAS){
if (((gas_particle*)particle)->pos[AXIS_Z]>SLICE_MIN && ((gas_particle*)particle)->pos[AXIS_Z]<SLICE_MAX)
return 1;
else
return 0;
}
else {
return 1;
}
}
// calc_var
float calc_y(void* particle, int type){
if (type == TYPE_GAS)
return ((gas_particle*)particle)->pos[AXIS_Y];
else
errorCase(ERR_INVALID_ATTRIBUTE);
}
// calc_bin
float xpos(tipsy* tipsyIn, int type, int p){
switch (type){
case TYPE_GAS:
return tipsyIn->gas[p].pos[AXIS_X];
break;
case TYPE_DARK:
return tipsyIn->dark[p].pos[AXIS_X];
break;
case TYPE_STAR:
return tipsyIn->star[p].pos[AXIS_X];
break;
default:
errorCase(ERR_UNKNOWN_PARTICLE);
}
}