1 |
marissa |
1.1 |
#include <GL/glut.h> |
2 |
|
|
#include <stdlib.h> |
3 |
|
|
#include <stdio.h> |
4 |
|
|
#include <string.h> |
5 |
|
|
#include <math.h> |
6 |
|
|
#define WINDOW "image" |
7 |
|
|
#define UP 101 |
8 |
|
|
#define DOWN 103 |
9 |
|
|
#define RIGHT 102 |
10 |
|
|
#define LEFT 100 |
11 |
marissa |
1.4 |
#define MAX 700 |
12 |
marissa |
1.7 |
#define SCALE .06 |
13 |
marissa |
1.1 |
|
14 |
marissa |
1.3 |
int NX, NY, NZ; |
15 |
marissa |
1.1 |
|
16 |
|
|
void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int ); |
17 |
marissa |
1.4 |
void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] ); |
18 |
marissa |
1.7 |
void readyz( float[], char[] ), readdepths( char[] ); |
19 |
|
|
void TimerFunction( int ), stroke( char[], int, int ); |
20 |
marissa |
1.1 |
|
21 |
marissa |
1.4 |
float data[MAX][MAX*MAX], mxval, mnval, jet[64][3]; |
22 |
marissa |
1.1 |
float globalmx=0, globalmn=100; |
23 |
marissa |
1.7 |
int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, endian=0; |
24 |
|
|
int xmax, ymax, yoffset=0, xoffset=0, yz=0, logscale=0, xz=0, nonegs=1; |
25 |
|
|
int depths[MAX], scaledepth=0, totaldepth=0, scalecount=0; |
26 |
marissa |
1.1 |
char initfns[MAX][MAX], fns[MAX][MAX][MAX]; |
27 |
|
|
|
28 |
marissa |
1.6 |
void menu( int value ){ // called when menu is opened on right click |
29 |
marissa |
1.1 |
|
30 |
|
|
switch( value ){ |
31 |
marissa |
1.2 |
case 1: usr=glo=0; // unset glo & usr, sets local max/min |
32 |
marissa |
1.1 |
break; |
33 |
marissa |
1.2 |
case 2: glo=1; // enables global max/min |
34 |
|
|
usr=0; // unsets usr |
35 |
|
|
mxval=globalmx; // sets max to globalmx |
36 |
|
|
mnval=globalmn; // sets min to globalmn |
37 |
marissa |
1.1 |
break; |
38 |
marissa |
1.2 |
case 3: usr=1; // switch to user-set max/min |
39 |
|
|
glo=0; // unset glo |
40 |
|
|
printf( "Max=" ); scanf( "%f", &mxval ); // prompt user for new max |
41 |
|
|
printf( "Min=" ); scanf( "%f", &mnval ); // prompt user for new min |
42 |
|
|
break; |
43 |
marissa |
1.7 |
case 4: logscale=( logscale+1 )%2; // switch log scale on/off |
44 |
marissa |
1.1 |
break; |
45 |
marissa |
1.7 |
case 5: nonegs=( nonegs+1 )%2; // switch allowance of negatives on/off |
46 |
marissa |
1.3 |
break; |
47 |
marissa |
1.7 |
case 6: endian=( endian+1 )%2; // switch between big/little endian |
48 |
marissa |
1.3 |
break; |
49 |
marissa |
1.1 |
} |
50 |
marissa |
1.7 |
glutPostRedisplay(); |
51 |
marissa |
1.1 |
} |
52 |
marissa |
1.7 |
|
53 |
marissa |
1.4 |
void display(){ // called on glutPostRedisplay |
54 |
marissa |
1.8 |
int i, h, ioff, q; |
55 |
|
|
float r, g, b, k, y, j, tmp; |
56 |
marissa |
1.2 |
double num, logmx, logmn; |
57 |
marissa |
1.1 |
char str[MAX]; |
58 |
|
|
|
59 |
marissa |
1.7 |
|
60 |
marissa |
1.4 |
for( q=0; q<sets; q++ ){ // runs display func for each subwindow |
61 |
marissa |
1.2 |
glutSetWindow( win[q] ); // sets which subwindow to display to |
62 |
|
|
glClear( GL_COLOR_BUFFER_BIT ); // background to black |
63 |
marissa |
1.7 |
|
64 |
marissa |
1.5 |
if( xz ) { xmax=NX; ymax=NZ; } |
65 |
|
|
else{ |
66 |
|
|
if( yz ){ xmax=NY; ymax=NZ; } |
67 |
|
|
else { xmax=NX; ymax=NY; } |
68 |
|
|
} |
69 |
marissa |
1.4 |
|
70 |
|
|
if( glo || usr ){ // if global or user-set max/min |
71 |
|
|
if( xz ) |
72 |
|
|
readxz( data[q], fns[q][count] ); |
73 |
marissa |
1.5 |
else{ |
74 |
|
|
if( yz ) |
75 |
|
|
readyz( data[q], fns[q][count] ); |
76 |
|
|
else |
77 |
|
|
readarray( data[q], fns[q][count], ilev ); // read new array w/o calculating local max/min |
78 |
|
|
} |
79 |
marissa |
1.4 |
} |
80 |
marissa |
1.2 |
else // if local max/min is set |
81 |
|
|
local( q, count, ilev ); // read new array and calculate local max/min |
82 |
|
|
|
83 |
|
|
if( logscale ){ |
84 |
|
|
if( usr ){ |
85 |
|
|
logmx=(double)mxval; |
86 |
|
|
logmn=(double)mnval; |
87 |
|
|
} |
88 |
|
|
else{ |
89 |
|
|
logmx=log10( mxval ); |
90 |
|
|
logmn=log10( mnval ); |
91 |
|
|
} |
92 |
|
|
} |
93 |
marissa |
1.4 |
|
94 |
marissa |
1.8 |
if( scaledepth && xz || scaledepth && yz ) ymax=NY; |
95 |
|
|
tmp=(float)ymax/totaldepth; |
96 |
|
|
j=0; ioff=0; h=0; // ioff will count both i&j b/c data is 1D |
97 |
|
|
|
98 |
|
|
while ( j<ymax ){ // cycles through y values |
99 |
marissa |
1.4 |
for( i=0; i<xmax; i++ ){ // cycles through x values |
100 |
marissa |
1.7 |
r=g=b=0; // set color values to black |
101 |
marissa |
1.2 |
if( data[q][ioff]==0 ); // if data=0, values stay black |
102 |
marissa |
1.1 |
else{ |
103 |
marissa |
1.2 |
if( logscale ){ |
104 |
|
|
num=(double)data[q][ioff]; |
105 |
|
|
num=log10( num ); |
106 |
|
|
if( num<logmn ) num=0; |
107 |
marissa |
1.3 |
else{ |
108 |
|
|
if( num>logmx ) num=63; |
109 |
|
|
else |
110 |
|
|
num=63*( num-logmn )/( logmx-logmn ); |
111 |
|
|
} |
112 |
marissa |
1.2 |
} |
113 |
marissa |
1.1 |
else{ |
114 |
marissa |
1.2 |
if( data[q][ioff]<mnval ) num=0; // if data is less than min, =min |
115 |
marissa |
1.3 |
else{ |
116 |
marissa |
1.2 |
if( data[q][ioff]>mxval ) num=63; // if data is more than max, =max |
117 |
|
|
else |
118 |
|
|
num=63*( data[q][ioff]-mnval )/( mxval-mnval ); // scale num from 0-63 (not defined for 64) |
119 |
marissa |
1.3 |
} |
120 |
marissa |
1.1 |
} |
121 |
marissa |
1.2 |
r=jet[(int)num][0]; // set red val |
122 |
|
|
g=jet[(int)num][1]; // set green val |
123 |
|
|
b=jet[(int)num][2]; // set blue val |
124 |
marissa |
1.1 |
} |
125 |
marissa |
1.2 |
|
126 |
|
|
glColor3f( r, g, b ); // put r, g, b into effect |
127 |
marissa |
1.7 |
if( scaledepth && xz || scaledepth && yz ) |
128 |
marissa |
1.8 |
glRectf( i, j, i+1, j+(depths[h]*tmp) ); |
129 |
marissa |
1.7 |
else |
130 |
|
|
glRectf( i, j, i+1, j+1 ); // draws a square for data value |
131 |
marissa |
1.1 |
ioff++; |
132 |
|
|
} |
133 |
marissa |
1.7 |
if( scaledepth && xz || scaledepth && yz ){ |
134 |
marissa |
1.8 |
j+=(depths[h]*tmp); |
135 |
marissa |
1.7 |
h++; |
136 |
|
|
} |
137 |
marissa |
1.8 |
else j++; |
138 |
marissa |
1.1 |
} |
139 |
marissa |
1.7 |
|
140 |
marissa |
1.2 |
glColor3f( 1, 1, 1 ); // set color to white |
141 |
marissa |
1.4 |
glRectf( xmax, 0, xmax+1, ymax+1 ); // draws a border |
142 |
|
|
glRectf( 0, ymax, xmax, ymax+1 ); // draws a border |
143 |
marissa |
1.2 |
for( i=0; i<64; i++ ){ // draws color bar |
144 |
|
|
glColor3f( jet[i][0], jet[i][1], jet[i][2]); // sets color |
145 |
|
|
k=(float)i; // turns i into a float |
146 |
marissa |
1.4 |
y=(float)ymax/64; // sets height of rectangles |
147 |
|
|
glRectf( xmax+10, y*k, xmax+20, (k+1)*y ); // draws rectangle |
148 |
marissa |
1.1 |
} |
149 |
marissa |
1.2 |
glColor3f( 1, 1, 1 ); // color to white |
150 |
marissa |
1.1 |
|
151 |
marissa |
1.2 |
if( logscale ) |
152 |
|
|
sprintf( str, "%.2f", logmx ); |
153 |
|
|
else |
154 |
marissa |
1.3 |
sprintf( str, "%.1e", mxval ); // labels color bar with max val |
155 |
marissa |
1.7 |
stroke( str, xmax+2, ymax-1 ); |
156 |
marissa |
1.1 |
|
157 |
marissa |
1.2 |
if( logscale ) |
158 |
|
|
sprintf( str, "%.2f", logmn ); |
159 |
|
|
else |
160 |
marissa |
1.3 |
sprintf( str, "%.1e", mnval ); // labels color bar with min val |
161 |
marissa |
1.7 |
stroke( str, xmax+2, 1 ); |
162 |
marissa |
1.1 |
|
163 |
marissa |
1.4 |
if( xz ) |
164 |
marissa |
1.6 |
sprintf( str, "N-S slice %d", yoffset+1); |
165 |
marissa |
1.5 |
else{ |
166 |
|
|
if( yz ) |
167 |
marissa |
1.6 |
sprintf( str, "E-W slice %d", xoffset+1); |
168 |
marissa |
1.5 |
else |
169 |
|
|
sprintf( str, "Level %d", ilev ); // labels current level |
170 |
|
|
} |
171 |
marissa |
1.7 |
stroke( str, 1, ymax+5 ); |
172 |
marissa |
1.1 |
|
173 |
marissa |
1.2 |
sprintf( str, "Time %d", count+1 ); // labels current time |
174 |
marissa |
1.7 |
stroke( str, xmax/2, ymax+5 ); |
175 |
marissa |
1.2 |
|
176 |
|
|
if( glo ) // labels how max/min have been set |
177 |
|
|
sprintf( str, "Global" ); // if glo is set, display Global |
178 |
marissa |
1.1 |
if( usr ) |
179 |
marissa |
1.2 |
sprintf( str, "User-set" ); // if usr is set, display User-set |
180 |
marissa |
1.1 |
if( !usr && !glo ) |
181 |
marissa |
1.2 |
sprintf( str, "Local" ); // else display Local |
182 |
marissa |
1.7 |
stroke( str, xmax+8, ymax+8 ); |
183 |
marissa |
1.1 |
|
184 |
marissa |
1.2 |
if( anim ){ // tell user if autoplay is on |
185 |
marissa |
1.1 |
sprintf( str, "Autoplay" ); |
186 |
marissa |
1.7 |
stroke( str, xmax-35, ymax+8 ); |
187 |
marissa |
1.2 |
} |
188 |
|
|
|
189 |
|
|
if( logscale ){ |
190 |
|
|
sprintf( str, "Log Scale" ); // tell user if log scale is on |
191 |
marissa |
1.7 |
stroke( str, xmax-25, ymax+15); |
192 |
marissa |
1.1 |
} |
193 |
|
|
|
194 |
marissa |
1.7 |
stroke( fns[q][count], 1, ymax+15 ); // labels current file |
195 |
marissa |
1.1 |
|
196 |
marissa |
1.2 |
glutSwapBuffers(); // double buffering set to animate smoothly |
197 |
marissa |
1.1 |
glFlush(); |
198 |
|
|
} |
199 |
|
|
} |
200 |
|
|
|
201 |
marissa |
1.7 |
void stroke( char str[], int x, int y ){ // called to display text onscreen |
202 |
marissa |
1.1 |
int i; |
203 |
|
|
|
204 |
marissa |
1.7 |
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
205 |
|
|
glEnable( GL_BLEND ); |
206 |
|
|
glEnable( GL_LINE_SMOOTH ); |
207 |
|
|
glMatrixMode( GL_MODELVIEW ); |
208 |
|
|
|
209 |
|
|
glPushMatrix(); |
210 |
|
|
|
211 |
|
|
glScalef( SCALE, SCALE, SCALE ); |
212 |
|
|
glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 ); |
213 |
|
|
|
214 |
marissa |
1.2 |
for( i=0; i<strlen( str ); i++) // display each character of str |
215 |
marissa |
1.7 |
glutStrokeCharacter( GLUT_STROKE_ROMAN, str[i] ); |
216 |
|
|
|
217 |
|
|
glPopMatrix(); |
218 |
marissa |
1.1 |
} |
219 |
|
|
|
220 |
marissa |
1.2 |
void key( unsigned char key, int x, int y ){ // called on key press |
221 |
marissa |
1.3 |
int i, tmp; |
222 |
marissa |
1.8 |
char fn[MAX]; |
223 |
marissa |
1.1 |
|
224 |
|
|
switch(key){ |
225 |
marissa |
1.2 |
case 'q': exit(0); // quits on 'q' |
226 |
marissa |
1.1 |
break; |
227 |
marissa |
1.2 |
case 'r': count=0; // resets back to first time |
228 |
|
|
ilev=1; // and first level |
229 |
marissa |
1.8 |
xz=yz=0; |
230 |
marissa |
1.1 |
break; |
231 |
marissa |
1.2 |
case 'a': anim=(anim+1)%2; // turns anim on/off |
232 |
marissa |
1.1 |
break; |
233 |
marissa |
1.4 |
case 'x': xz=(xz+1)%2; |
234 |
marissa |
1.5 |
yz=0; |
235 |
marissa |
1.4 |
break; |
236 |
marissa |
1.5 |
case 'y': yz=(yz+1)%2; |
237 |
|
|
xz=0; |
238 |
marissa |
1.7 |
break; |
239 |
|
|
case 'z': if( xz || yz ){ |
240 |
|
|
scaledepth=( scaledepth+1 )%2; |
241 |
|
|
scalecount++; |
242 |
marissa |
1.8 |
if( scalecount==1 ){ |
243 |
|
|
printf( "Please enter filename containing depth data: " ); |
244 |
|
|
scanf( "%s", fn ); |
245 |
|
|
readdepths( fn ); |
246 |
|
|
} |
247 |
marissa |
1.7 |
} |
248 |
|
|
break; |
249 |
marissa |
1.1 |
} |
250 |
marissa |
1.7 |
glutPostRedisplay(); |
251 |
marissa |
1.1 |
} |
252 |
|
|
|
253 |
marissa |
1.2 |
void TimerFunction( int value ){ // called when anim is set and arrow key is pressed |
254 |
marissa |
1.1 |
int i; |
255 |
|
|
|
256 |
marissa |
1.2 |
switch(value){ // increments in the correct direction |
257 |
marissa |
1.5 |
case DOWN : if( xz && yoffset>0 ) |
258 |
|
|
yoffset--; |
259 |
marissa |
1.4 |
else{ |
260 |
marissa |
1.5 |
if( yz && xoffset<NX-1 ) |
261 |
|
|
xoffset++; |
262 |
|
|
else |
263 |
|
|
if( ilev<NZ && !xz && !yz ) |
264 |
|
|
ilev++; // if down arrow pressed, move down a level |
265 |
marissa |
1.4 |
} |
266 |
marissa |
1.1 |
break; |
267 |
marissa |
1.5 |
case UP : if( xz && yoffset<NY-1 ) |
268 |
|
|
yoffset++; |
269 |
marissa |
1.4 |
else{ |
270 |
marissa |
1.5 |
if( yz && xoffset>0 ) |
271 |
|
|
xoffset--; |
272 |
|
|
else |
273 |
|
|
if( ilev>1 && !xz && !yz ) |
274 |
|
|
ilev--; // if up arrow is pressed, move up a level |
275 |
marissa |
1.4 |
} |
276 |
marissa |
1.1 |
break; |
277 |
|
|
case LEFT : if( count>0 ) |
278 |
marissa |
1.2 |
count--; // if left arrow is pressed, move back one time step |
279 |
marissa |
1.1 |
break; |
280 |
|
|
case RIGHT: if( count<howmany-1 ) |
281 |
marissa |
1.2 |
count++; // if right arrow is pressed, moves forward one time step |
282 |
marissa |
1.1 |
break; |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
glutPostRedisplay(); |
286 |
|
|
|
287 |
marissa |
1.5 |
if ( anim ) |
288 |
marissa |
1.1 |
switch( value ){ |
289 |
marissa |
1.5 |
case DOWN : if( xz && yoffset==0 ) |
290 |
|
|
yoffset=NY-1; |
291 |
marissa |
1.4 |
else{ |
292 |
marissa |
1.5 |
if( yz && xoffset==NX-1 ) |
293 |
|
|
xoffset=0; |
294 |
|
|
else |
295 |
|
|
if( ilev==NZ && !xz && !yz ) |
296 |
|
|
ilev=1; // if end reached, restart |
297 |
marissa |
1.4 |
} |
298 |
marissa |
1.1 |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
299 |
|
|
break; |
300 |
marissa |
1.5 |
case UP : if( xz && yoffset==NY-1 ) |
301 |
|
|
yoffset=0; |
302 |
marissa |
1.4 |
else{ |
303 |
marissa |
1.5 |
if( yz && xoffset==0 ) |
304 |
|
|
xoffset=NX-1; |
305 |
|
|
else |
306 |
|
|
if( ilev==1 ) |
307 |
|
|
ilev=NZ; // if end reached, restart |
308 |
marissa |
1.4 |
} |
309 |
marissa |
1.1 |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
310 |
|
|
break; |
311 |
marissa |
1.2 |
case LEFT : if( count==0 ) count=howmany-1; // if end reached, restart |
312 |
marissa |
1.1 |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
313 |
|
|
break; |
314 |
marissa |
1.2 |
case RIGHT: if( count==howmany-1 ) count=0; // if end reached, restart |
315 |
marissa |
1.1 |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
316 |
|
|
break; |
317 |
|
|
} |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
void specialkey( int key, int x, int y ){ |
321 |
|
|
int i; |
322 |
|
|
|
323 |
marissa |
1.2 |
if( anim ) // if animation is set, call the timer function |
324 |
|
|
glutTimerFunc( 100, TimerFunction, key); // to scroll automatically |
325 |
marissa |
1.1 |
|
326 |
|
|
switch(key){ |
327 |
marissa |
1.5 |
case DOWN : if( xz && yoffset>0 ) |
328 |
|
|
yoffset--; |
329 |
marissa |
1.4 |
else{ |
330 |
marissa |
1.5 |
if( yz && xoffset<NY-1 ) |
331 |
|
|
xoffset++; |
332 |
|
|
else |
333 |
|
|
if( ilev<NZ && !xz && !yz ) // if you haven't reached the bottom |
334 |
|
|
ilev++; // keep going down |
335 |
marissa |
1.4 |
} |
336 |
marissa |
1.1 |
break; |
337 |
marissa |
1.5 |
case UP : if( xz && yoffset<NY-1 ) |
338 |
|
|
yoffset++; |
339 |
marissa |
1.4 |
else{ |
340 |
marissa |
1.5 |
if( yz && xoffset>0 ) |
341 |
|
|
xoffset--; |
342 |
|
|
else |
343 |
|
|
if( ilev>1 ) // if you haven't reached the top |
344 |
|
|
ilev--; // keep going up |
345 |
marissa |
1.4 |
} |
346 |
marissa |
1.1 |
break; |
347 |
|
|
case RIGHT : if( count<howmany-1 ) // if you haven't reached the last file |
348 |
|
|
count++; // keep going right |
349 |
|
|
break; |
350 |
|
|
case LEFT : if( count>0 ) // if you haven't reached the first file |
351 |
|
|
count--; // keep going left |
352 |
|
|
break; |
353 |
|
|
} |
354 |
|
|
glutPostRedisplay(); |
355 |
|
|
} |
356 |
|
|
|
357 |
marissa |
1.2 |
void global(){ // calculates the max/min for the total data set |
358 |
marissa |
1.1 |
FILE* fp; |
359 |
|
|
int h, i, j; |
360 |
marissa |
1.3 |
for( h=0; h<sets; h++) // cycles through each window |
361 |
marissa |
1.2 |
for( i=0; i<howmany; i++ ) // cycles through each time |
362 |
marissa |
1.3 |
for( j=0; j<NZ; j++ ){ // cycles through each level for each file |
363 |
marissa |
1.2 |
local( h, i, j ); // calculates local max/min for specific data set |
364 |
marissa |
1.1 |
if( mxval > globalmx ) globalmx = mxval; // sets highest value to globalmx |
365 |
|
|
if( mnval < globalmn ) globalmn = mnval; // sets lowest value to globalmn |
366 |
|
|
} |
367 |
|
|
} |
368 |
|
|
|
369 |
marissa |
1.2 |
void local( int i, int time, int lev ){ // calculates local max/min |
370 |
marissa |
1.1 |
int j; |
371 |
|
|
|
372 |
|
|
mxval=0; |
373 |
|
|
mnval=100; |
374 |
marissa |
1.4 |
if( xz ) |
375 |
|
|
readxz( data[i], fns[i][time]); |
376 |
marissa |
1.5 |
else{ |
377 |
|
|
if( yz ) |
378 |
|
|
readyz( data[i], fns[i][time]); |
379 |
|
|
else |
380 |
|
|
readarray( data[i], fns[i][time], lev ); // read new array of data |
381 |
|
|
} |
382 |
marissa |
1.4 |
for( j=0; j<xmax*ymax; j++ ){ |
383 |
marissa |
1.2 |
if( data[i][j] > mxval ) |
384 |
|
|
mxval=data[i][j]; // set largest val to mxval |
385 |
marissa |
1.3 |
if( data[i][j] < mnval && data[i][j]!=0 ) |
386 |
marissa |
1.2 |
mnval=data[i][j]; // set smallest positive val to mnval |
387 |
marissa |
1.1 |
} |
388 |
|
|
} |
389 |
|
|
|
390 |
marissa |
1.2 |
void readnames( char filename[] ){ // reads in list of filenames |
391 |
marissa |
1.1 |
FILE* fp; |
392 |
|
|
int i=0, j=0; |
393 |
|
|
|
394 |
marissa |
1.2 |
fp=fopen( filename, "r" ); // opens list of filenames |
395 |
|
|
while( !feof(fp) ){ // reads until the end of the file |
396 |
|
|
fscanf( fp, "%s", initfns[i] ); // places filename into an array of strings |
397 |
|
|
i++; // counts how many filenames there are |
398 |
marissa |
1.1 |
} |
399 |
marissa |
1.2 |
fclose( fp ); // close file |
400 |
marissa |
1.3 |
sets=i-1; // saves number of initial filenames |
401 |
marissa |
1.1 |
|
402 |
marissa |
1.3 |
for(i=0; i<sets; i++){ // goes through each read-in filename |
403 |
marissa |
1.2 |
fp=fopen( initfns[i], "r" ); // opens each filename |
404 |
marissa |
1.1 |
j=0; |
405 |
marissa |
1.2 |
while( !feof(fp) ){ // reads in filenames from each filename |
406 |
|
|
fscanf( fp, "%s", fns[i][j]); |
407 |
marissa |
1.1 |
j++; |
408 |
|
|
} |
409 |
marissa |
1.2 |
fclose(fp); // close file |
410 |
marissa |
1.1 |
} |
411 |
marissa |
1.2 |
howmany=j-1; // saves number of data filenames |
412 |
marissa |
1.1 |
} |
413 |
|
|
|
414 |
marissa |
1.7 |
void readdepths( char filename[] ){ |
415 |
|
|
int i; |
416 |
|
|
FILE* fp; |
417 |
|
|
|
418 |
|
|
fp=fopen( filename, "r" ); |
419 |
|
|
|
420 |
|
|
for( i=NZ-1; i>=0; i-- ){ |
421 |
|
|
fscanf( fp, "%d ", &depths[i] ); |
422 |
|
|
totaldepth+=depths[i]; |
423 |
|
|
} |
424 |
|
|
|
425 |
|
|
fclose( fp ); |
426 |
|
|
} |
427 |
|
|
|
428 |
marissa |
1.2 |
void readjet(){ //reads in color scale values |
429 |
marissa |
1.1 |
FILE* fp; |
430 |
|
|
int i, j; |
431 |
|
|
|
432 |
marissa |
1.8 |
fp=fopen( "jet.dat", "r" ); // opens file containing values |
433 |
marissa |
1.2 |
for( i=0; i<64; i++ ) // reads in 64 sets of r, g, b values |
434 |
marissa |
1.1 |
for( j=0; j<3; j++ ) |
435 |
|
|
fscanf( fp, "%f", &jet[i][j] ); |
436 |
marissa |
1.2 |
fclose( fp ); // closes file |
437 |
marissa |
1.1 |
} |
438 |
|
|
|
439 |
marissa |
1.4 |
void readxz( float arr[], char filename[] ){ |
440 |
marissa |
1.5 |
int i, j; |
441 |
|
|
float tmp[MAX][MAX], tmp2[MAX*MAX]; |
442 |
marissa |
1.4 |
FILE* fp; |
443 |
|
|
|
444 |
|
|
fp=fopen( filename, "rb" ); |
445 |
|
|
for( i=0; i<NZ; i++){ |
446 |
marissa |
1.5 |
fseek( fp, (NX*yoffset*4)+(i*NX*NY*4), SEEK_SET ); |
447 |
marissa |
1.4 |
fread( &arr[NX*i], sizeof( arr[0] ), NX, fp ); // reads in data to fill one level |
448 |
|
|
} |
449 |
|
|
fclose( fp ); |
450 |
marissa |
1.5 |
|
451 |
|
|
for( i=0; i<NZ; i++ ) |
452 |
|
|
for( j=0; j<NX; j++) |
453 |
|
|
tmp[i][j]=arr[i*NX+j]; |
454 |
|
|
|
455 |
|
|
for( i=0; i<NZ; i++ ) |
456 |
|
|
for( j=0; j<NX; j++) |
457 |
|
|
tmp2[i*NX+j]=tmp[NZ-i-1][j]; |
458 |
|
|
|
459 |
|
|
for( i=0; i<NX*NZ; i++) |
460 |
|
|
arr[i]=tmp2[i]; |
461 |
|
|
} |
462 |
|
|
|
463 |
|
|
void readyz( float arr[], char filename[] ){ |
464 |
|
|
int i, j; |
465 |
|
|
float tmp[MAX][MAX], tmp2[MAX*MAX]; |
466 |
|
|
FILE* fp; |
467 |
|
|
|
468 |
|
|
fp=fopen( filename, "rb" ); |
469 |
|
|
for( i=0; i<NY*NZ; i++ ){ |
470 |
|
|
fseek( fp, (xoffset*4)+(i*NX*4), SEEK_SET ); |
471 |
|
|
fread( &arr[i], sizeof( arr[0] ), 1, fp ); |
472 |
|
|
} |
473 |
|
|
fclose(fp); |
474 |
|
|
|
475 |
|
|
for( i=0; i<NZ; i++ ) |
476 |
|
|
for( j=0; j<NY; j++) |
477 |
|
|
tmp[i][j]=arr[i*NY+j]; |
478 |
|
|
|
479 |
|
|
for( i=0; i<NZ; i++ ) |
480 |
|
|
for( j=0; j<NY; j++) |
481 |
|
|
tmp2[i*NY+j]=tmp[NZ-i-1][j]; |
482 |
|
|
|
483 |
|
|
for( i=0; i<NY*NZ; i++) |
484 |
|
|
arr[i]=tmp2[i]; |
485 |
marissa |
1.4 |
} |
486 |
|
|
|
487 |
marissa |
1.1 |
void readarray( float arr[], char filename[], int il ){ // reads new data |
488 |
marissa |
1.3 |
FILE* fp; |
489 |
marissa |
1.1 |
int i; |
490 |
|
|
|
491 |
marissa |
1.5 |
fp=fopen( filename, "rb" ); // opens the file containing data |
492 |
marissa |
1.2 |
fseek( fp, (il-1)*NX*NY*4, SEEK_SET ); // seeks to the correct place using ilev |
493 |
marissa |
1.1 |
fread( arr, sizeof( arr[0] ), NX*NY, fp ); // reads in data to fill one level |
494 |
marissa |
1.2 |
fclose( fp ); // close file |
495 |
|
|
|
496 |
marissa |
1.3 |
if( nonegs ) |
497 |
|
|
for( i=0; i<NX*NY; i++ ) |
498 |
|
|
if( arr[i] < 0 ) |
499 |
|
|
arr[i] = pow(10, -20); // sets negative values to 10^-20 |
500 |
|
|
|
501 |
|
|
if( endian ) |
502 |
|
|
do_byteswap_f32( arr, NX*NY ); // switches endian |
503 |
marissa |
1.1 |
} |
504 |
|
|
|
505 |
marissa |
1.3 |
void do_byteswap_f32( float arr[], int nel ){ // switches endian |
506 |
|
|
|
507 |
|
|
int i; |
508 |
|
|
char src[4], trg[4]; |
509 |
|
|
|
510 |
|
|
for( i=0; i<nel; i++ ){ |
511 |
|
|
memcpy( src, &(arr[i]), 4 ); |
512 |
|
|
trg[0]=src[3]; |
513 |
|
|
trg[1]=src[2]; |
514 |
|
|
trg[2]=src[1]; |
515 |
|
|
trg[3]=src[0]; |
516 |
|
|
memcpy( &(arr[i]), trg, 4 ); |
517 |
|
|
} |
518 |
|
|
} |
519 |
|
|
|
520 |
marissa |
1.6 |
void black( ){ |
521 |
marissa |
1.3 |
glClear( GL_COLOR_BUFFER_BIT ); |
522 |
|
|
glutSwapBuffers(); |
523 |
marissa |
1.6 |
glFlush(); |
524 |
marissa |
1.1 |
} |
525 |
|
|
|
526 |
marissa |
1.6 |
|
527 |
marissa |
1.1 |
int main( int argc, char *argv[] ){ |
528 |
marissa |
1.3 |
int i, setsx, setsy, tmpx, tmpy, winx, winy, parent; |
529 |
marissa |
1.6 |
char str[MAX], filename[MAX]; |
530 |
|
|
FILE* fp; |
531 |
|
|
|
532 |
|
|
if( strcmp(argv[1], "binary") == 0 ) |
533 |
|
|
fp=fopen( ".darwinview/binconfig", "r" ); |
534 |
|
|
else |
535 |
|
|
if( strcmp(argv[1],"netcdf") == 0 ) |
536 |
|
|
fp=fopen( ".darwinview/ncconfig", "r" ); |
537 |
marissa |
1.1 |
|
538 |
marissa |
1.6 |
fscanf( fp, "%dx%d ", &winx, &winy ); |
539 |
marissa |
1.2 |
winy-=60; winx-=20; // adjusts resolution so edges won't get cut off |
540 |
marissa |
1.6 |
fscanf( fp, "%d %d %d ", &NX, &NY, &NZ ); |
541 |
|
|
fscanf( fp, "%dx%d ", &setsx, &setsy ); // prompts user for dimensions of subwindows |
542 |
|
|
fscanf( fp, "%s", filename ); |
543 |
|
|
|
544 |
|
|
fclose( fp ); |
545 |
marissa |
1.1 |
|
546 |
marissa |
1.4 |
xmax=NX; ymax=NY; |
547 |
marissa |
1.8 |
|
548 |
marissa |
1.2 |
readjet(); // stores color values |
549 |
|
|
readnames( filename ); // gets list of filenames to read from |
550 |
|
|
global(); // calculates max and min for all data |
551 |
|
|
|
552 |
|
|
glutInit( &argc, argv ); |
553 |
|
|
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); // sets rgb mode and double buffering |
554 |
|
|
glutInitWindowSize( winx, winy ); // parent window will cover screen |
555 |
|
|
glutInitWindowPosition( 10, 10 ); // location of parent window |
556 |
|
|
parent=glutCreateWindow( WINDOW ); // creates parent window |
557 |
marissa |
1.1 |
|
558 |
marissa |
1.2 |
glClearColor( 0, 0, 0, 0 ); // sets clear color to black |
559 |
|
|
gluOrtho2D( 0, winx , winy, 0 ); // sets(0,0) as top left corner |
560 |
marissa |
1.1 |
glutDisplayFunc( display ); |
561 |
marissa |
1.2 |
glutKeyboardFunc( key ); // called on key press |
562 |
|
|
glutSpecialFunc( specialkey ); // called on special key press (arrow keys) |
563 |
marissa |
1.3 |
|
564 |
marissa |
1.1 |
|
565 |
|
|
for( i=0; i<setsx*setsy; i++ ){ |
566 |
marissa |
1.2 |
tmpx = (i%setsx)*(winx/setsx); // x coordinate of top left corner of subwindow |
567 |
|
|
tmpy = (i/setsx)*(winy/setsy); // y coordinate of top left corner of subwindow |
568 |
marissa |
1.1 |
|
569 |
marissa |
1.2 |
win[i]=glutCreateSubWindow( parent, tmpx, tmpy, winx/setsx, winy/setsy ); // creates subwindow |
570 |
marissa |
1.7 |
gluOrtho2D( 0, NX+35, 0, NY+25 ); // sets how data is mapped to subwindow |
571 |
marissa |
1.2 |
glutKeyboardFunc( key ); // called on key press |
572 |
|
|
glutSpecialFunc( specialkey ); // called on special key press (arrow keys) |
573 |
marissa |
1.3 |
if( i >= sets ) // |
574 |
|
|
glutDisplayFunc( black ); |
575 |
|
|
else |
576 |
|
|
glutDisplayFunc( display ); // sets display func for subwindow |
577 |
|
|
|
578 |
marissa |
1.2 |
|
579 |
marissa |
1.3 |
glutCreateMenu( menu ); // adds a menu |
580 |
|
|
glutAddMenuEntry( "Local Color Scale", 1 ); // adds a menu entry |
581 |
|
|
glutAddMenuEntry( "Global Color Scale", 2 ); // adds a menu entry |
582 |
|
|
glutAddMenuEntry( "User-Set Color Scale", 3 ); // adds a menu entry |
583 |
|
|
glutAddMenuEntry( "Log Scale (on/off)", 4 ); // adds a menu entry |
584 |
|
|
glutAddMenuEntry( "Allow Negatives (on/off)", 5 ); // adds a menu entry |
585 |
|
|
glutAddMenuEntry( "Switch Endian (big/little) ", 6); // adds a menu entry |
586 |
|
|
glutAttachMenu( GLUT_RIGHT_BUTTON ); // menu called on right click |
587 |
marissa |
1.1 |
} |
588 |
|
|
|
589 |
marissa |
1.2 |
glutMainLoop(); // begin processing events |
590 |
marissa |
1.1 |
return 0; |
591 |
|
|
} |
592 |
|
|
|