-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotRhoSlice.c
More file actions
216 lines (189 loc) · 7.17 KB
/
plotRhoSlice.c
File metadata and controls
216 lines (189 loc) · 7.17 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
#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.5
#define SLICE_MAX 0.5
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, dmaxrho, ddDelta;
float xmin, xmax, ymin, ymax, maxrho, 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, "maxrho", &dmaxrho);
maxrho=(float)dmaxrho;
printf("\tmaxrho = %f\n", maxrho);
config_lookup_float(&cfg, "dDelta", &ddDelta);
dDelta=(float)ddDelta;
printf("\tdDelta = %f\n", dDelta);
}
const int nout = (int)nsteps/interval;
const double cmapi[2] = {0.0, 1.0}; // colour map intensity
const double cmapr[2] = {1.0, 1.0}; // red, left
const double cmapg[2] = {0.0, 0.0}; // green, left
const double cmapb[2] = {1.0, 0.0}; // blue, left
/*
## ## ### ######## ######
## ## ## ## ## ## ## ##
## ## ## ## ## ## ##
## ## ## ## ######## ######
## ## ######### ## ## ##
## ## ## ## ## ## ## ##
### ## ## ## ## ######
*/
char simname[100];
char filenameout[100];
char title[100];
char command[500];
int i, j, k;
int filetime;
tipsy* snap;
profile* pfile;
/*
DERIVED ARRAYS
*/
int numvars = 1;
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/slicerho/*.png -v\n");
system("rm test/slicerho/slicerho.*.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
tipsyCrop(snap, cropThinSliceZ);
pfile = profileCreate(snap, nbins, xmin, xmax, xpos);
for (j=0; j<numvars; j++){
printf("\tplotting: slicerho\n");
sprintf(filenameout, "./test/slicerho/slicerho.%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
calculateDerivedVarPoints(&plotvars[j], pfile, TYPE_GAS);
plscmap1l(1, 2, cmapi, cmapr, cmapg, cmapb, 0);
for (k=0; k < snap->head->nsph; k++) {
if ((snap->gas[k].rho/maxrho) > 1)
plcol1(1.0);
else
plcol1((snap->gas[k].rho)/maxrho);
plstring(1, &plotvars[j].points_xs[k], &plotvars[j].points_ys[k], "#(210)");
}
plend();
}
tipsyDestroy(snap);
profileDestroy(pfile);
}
// make gifs
float delay = (float)1000/(float)nout;
sprintf(command, "convert -layers optimize -delay %f ./test/slicerho/slicerho.*.png ./test/slicerho.animation.gif", delay);
printf("%s\n", command);
system(command);
return 0;
}
// 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);
}
}