9 |
#define RIGHT 102 |
#define RIGHT 102 |
10 |
#define LEFT 100 |
#define LEFT 100 |
11 |
#define MAX 700 |
#define MAX 700 |
12 |
|
#define SCALE .06 |
13 |
|
|
14 |
int NX, NY, NZ; |
int NX, NY, NZ; |
15 |
|
|
16 |
void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int ); |
void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int ); |
17 |
void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] ); |
void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] ); |
18 |
void readyz( float[], char[] ); |
void readyz( float[], char[] ), readdepths( char[] ); |
19 |
void TimerFunction( int ), bitmap( char[], int, int ); |
void TimerFunction( int ), stroke( char[], int, int ); |
20 |
|
|
21 |
float data[MAX][MAX*MAX], mxval, mnval, jet[64][3]; |
float data[MAX][MAX*MAX], mxval, mnval, jet[64][3]; |
22 |
float globalmx=0, globalmn=100; |
float globalmx=0, globalmn=100; |
23 |
int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, logscale=0, xz=0, nonegs=1, endian=0; |
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; |
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 |
char initfns[MAX][MAX], fns[MAX][MAX][MAX]; |
char initfns[MAX][MAX], fns[MAX][MAX][MAX]; |
27 |
|
|
28 |
void menu( int value ){ // called when menu is opened on right click |
void menu( int value ){ // called when menu is opened on right click |
29 |
|
|
30 |
switch( value ){ |
switch( value ){ |
31 |
case 1: usr=glo=0; // unset glo & usr, sets local max/min |
case 1: usr=glo=0; // unset glo & usr, sets local max/min |
|
glutPostRedisplay(); // recall display func with new values |
|
32 |
break; |
break; |
33 |
case 2: glo=1; // enables global max/min |
case 2: glo=1; // enables global max/min |
34 |
usr=0; // unsets usr |
usr=0; // unsets usr |
35 |
mxval=globalmx; // sets max to globalmx |
mxval=globalmx; // sets max to globalmx |
36 |
mnval=globalmn; // sets min to globalmn |
mnval=globalmn; // sets min to globalmn |
|
glutPostRedisplay(); // recall display func with new values |
|
37 |
break; |
break; |
38 |
case 3: usr=1; // switch to user-set max/min |
case 3: usr=1; // switch to user-set max/min |
39 |
glo=0; // unset glo |
glo=0; // unset glo |
40 |
printf( "Max=" ); scanf( "%f", &mxval ); // prompt user for new max |
printf( "Max=" ); scanf( "%f", &mxval ); // prompt user for new max |
41 |
printf( "Min=" ); scanf( "%f", &mnval ); // prompt user for new min |
printf( "Min=" ); scanf( "%f", &mnval ); // prompt user for new min |
|
glutPostRedisplay(); // recall display func with new values |
|
42 |
break; |
break; |
43 |
case 4: logscale=(logscale+1)%2; // switch log scale on/off |
case 4: logscale=( logscale+1 )%2; // switch log scale on/off |
|
glutPostRedisplay(); |
|
44 |
break; |
break; |
45 |
case 5: nonegs=(nonegs+1)%2; // switch allowance of negatives on/off |
case 5: nonegs=( nonegs+1 )%2; // switch allowance of negatives on/off |
|
glutPostRedisplay(); |
|
46 |
break; |
break; |
47 |
case 6: endian=(endian+1)%2; // switch between big/little endian |
case 6: endian=( endian+1 )%2; // switch between big/little endian |
|
glutPostRedisplay(); |
|
48 |
break; |
break; |
49 |
} |
} |
50 |
|
glutPostRedisplay(); |
51 |
} |
} |
52 |
|
|
53 |
void display(){ // called on glutPostRedisplay |
void display(){ // called on glutPostRedisplay |
54 |
int i, j, ioff, q; |
int i, j, h, ioff, q; |
55 |
float r, g, b, k, y; |
float r, g, b, k, y; |
56 |
double num, logmx, logmn; |
double num, logmx, logmn; |
57 |
char str[MAX]; |
char str[MAX]; |
58 |
|
|
59 |
|
|
60 |
for( q=0; q<sets; q++ ){ // runs display func for each subwindow |
for( q=0; q<sets; q++ ){ // runs display func for each subwindow |
61 |
glutSetWindow( win[q] ); // sets which subwindow to display to |
glutSetWindow( win[q] ); // sets which subwindow to display to |
62 |
glClear( GL_COLOR_BUFFER_BIT ); // background to black |
glClear( GL_COLOR_BUFFER_BIT ); // background to black |
63 |
|
|
64 |
if( xz ) { xmax=NX; ymax=NZ; } |
if( xz ) { xmax=NX; ymax=NZ; } |
65 |
else{ |
else{ |
66 |
if( yz ){ xmax=NY; ymax=NZ; } |
if( yz ){ xmax=NY; ymax=NZ; } |
91 |
} |
} |
92 |
} |
} |
93 |
|
|
94 |
ioff=0; // ioff will count both i&j b/c data is 1D |
if( scaledepth && xz || scaledepth && yz ) ymax=totaldepth; |
95 |
|
ioff=0; h=0; // ioff will count both i&j b/c data is 1D |
96 |
for( j=0; j<ymax; j++ ){ // cycles through y values |
for( j=0; j<ymax; j++ ){ // cycles through y values |
97 |
for( i=0; i<xmax; i++ ){ // cycles through x values |
for( i=0; i<xmax; i++ ){ // cycles through x values |
98 |
r=g=b=0; // set color values to black |
r=g=b=0; // set color values to black |
99 |
if( data[q][ioff]==0 ); // if data=0, values stay black |
if( data[q][ioff]==0 ); // if data=0, values stay black |
100 |
else{ |
else{ |
101 |
if( logscale ){ |
if( logscale ){ |
122 |
} |
} |
123 |
|
|
124 |
glColor3f( r, g, b ); // put r, g, b into effect |
glColor3f( r, g, b ); // put r, g, b into effect |
125 |
glRectf( i, j, i+1, j+1 ); // draws a square for data value |
if( scaledepth && xz || scaledepth && yz ) |
126 |
|
glRectf( i, j, i+1, j+depths[h] ); |
127 |
|
else |
128 |
|
glRectf( i, j, i+1, j+1 ); // draws a square for data value |
129 |
ioff++; |
ioff++; |
130 |
} |
} |
131 |
|
if( scaledepth && xz || scaledepth && yz ){ |
132 |
|
j+=depths[h]-1; |
133 |
|
h++; |
134 |
|
} |
135 |
} |
} |
136 |
|
|
137 |
glColor3f( 1, 1, 1 ); // set color to white |
glColor3f( 1, 1, 1 ); // set color to white |
138 |
glRectf( xmax, 0, xmax+1, ymax+1 ); // draws a border |
glRectf( xmax, 0, xmax+1, ymax+1 ); // draws a border |
139 |
glRectf( 0, ymax, xmax, ymax+1 ); // draws a border |
glRectf( 0, ymax, xmax, ymax+1 ); // draws a border |
149 |
sprintf( str, "%.2f", logmx ); |
sprintf( str, "%.2f", logmx ); |
150 |
else |
else |
151 |
sprintf( str, "%.1e", mxval ); // labels color bar with max val |
sprintf( str, "%.1e", mxval ); // labels color bar with max val |
152 |
bitmap( str, xmax+2, ymax-1 ); |
stroke( str, xmax+2, ymax-1 ); |
153 |
|
|
154 |
if( logscale ) |
if( logscale ) |
155 |
sprintf( str, "%.2f", logmn ); |
sprintf( str, "%.2f", logmn ); |
156 |
else |
else |
157 |
sprintf( str, "%.1e", mnval ); // labels color bar with min val |
sprintf( str, "%.1e", mnval ); // labels color bar with min val |
158 |
bitmap( str, xmax+2, 1 ); |
stroke( str, xmax+2, 1 ); |
159 |
|
|
160 |
if( xz ) |
if( xz ) |
161 |
sprintf( str, "N-S slice %d", yoffset+1); |
sprintf( str, "N-S slice %d", yoffset+1); |
165 |
else |
else |
166 |
sprintf( str, "Level %d", ilev ); // labels current level |
sprintf( str, "Level %d", ilev ); // labels current level |
167 |
} |
} |
168 |
bitmap( str, 1, ymax+3 ); |
stroke( str, 1, ymax+5 ); |
169 |
|
|
170 |
sprintf( str, "Time %d", count+1 ); // labels current time |
sprintf( str, "Time %d", count+1 ); // labels current time |
171 |
bitmap( str, 80, ymax+3 ); |
stroke( str, xmax/2, ymax+5 ); |
172 |
|
|
173 |
if( glo ) // labels how max/min have been set |
if( glo ) // labels how max/min have been set |
174 |
sprintf( str, "Global" ); // if glo is set, display Global |
sprintf( str, "Global" ); // if glo is set, display Global |
176 |
sprintf( str, "User-set" ); // if usr is set, display User-set |
sprintf( str, "User-set" ); // if usr is set, display User-set |
177 |
if( !usr && !glo ) |
if( !usr && !glo ) |
178 |
sprintf( str, "Local" ); // else display Local |
sprintf( str, "Local" ); // else display Local |
179 |
bitmap( str, xmax+12, ymax+3 ); |
stroke( str, xmax+8, ymax+8 ); |
180 |
|
|
181 |
if( anim ){ // tell user if autoplay is on |
if( anim ){ // tell user if autoplay is on |
182 |
sprintf( str, "Autoplay" ); |
sprintf( str, "Autoplay" ); |
183 |
bitmap( str, xmax-25, ymax+3 ); |
stroke( str, xmax-35, ymax+8 ); |
184 |
} |
} |
185 |
|
|
186 |
if( logscale ){ |
if( logscale ){ |
187 |
sprintf( str, "Log Scale" ); // tell user if log scale is on |
sprintf( str, "Log Scale" ); // tell user if log scale is on |
188 |
bitmap( str, xmax-25, ymax+10 ); |
stroke( str, xmax-25, ymax+15); |
189 |
} |
} |
190 |
|
|
191 |
bitmap( fns[q][count], 1, ymax+10 ); // labels current file |
stroke( fns[q][count], 1, ymax+15 ); // labels current file |
192 |
|
|
193 |
glutSwapBuffers(); // double buffering set to animate smoothly |
glutSwapBuffers(); // double buffering set to animate smoothly |
194 |
glFlush(); |
glFlush(); |
195 |
} |
} |
196 |
} |
} |
197 |
|
|
198 |
void bitmap( char str[], int x, int y ){ // called to display text onscreen |
void stroke( char str[], int x, int y ){ // called to display text onscreen |
199 |
int i; |
int i; |
200 |
|
|
201 |
glRasterPos2f( x, y ); // set position of text |
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
202 |
|
glEnable( GL_BLEND ); |
203 |
|
glEnable( GL_LINE_SMOOTH ); |
204 |
|
glMatrixMode( GL_MODELVIEW ); |
205 |
|
|
206 |
|
glPushMatrix(); |
207 |
|
|
208 |
|
glScalef( SCALE, SCALE, SCALE ); |
209 |
|
glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 ); |
210 |
|
|
211 |
for( i=0; i<strlen( str ); i++) // display each character of str |
for( i=0; i<strlen( str ); i++) // display each character of str |
212 |
glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, str[i] ); |
glutStrokeCharacter( GLUT_STROKE_ROMAN, str[i] ); |
213 |
|
|
214 |
|
glPopMatrix(); |
215 |
} |
} |
216 |
|
|
217 |
void key( unsigned char key, int x, int y ){ // called on key press |
void key( unsigned char key, int x, int y ){ // called on key press |
222 |
break; |
break; |
223 |
case 'r': count=0; // resets back to first time |
case 'r': count=0; // resets back to first time |
224 |
ilev=1; // and first level |
ilev=1; // and first level |
|
glutPostRedisplay(); |
|
225 |
break; |
break; |
226 |
case 'a': anim=(anim+1)%2; // turns anim on/off |
case 'a': anim=(anim+1)%2; // turns anim on/off |
|
glutPostRedisplay(); |
|
227 |
break; |
break; |
228 |
case 'x': xz=(xz+1)%2; |
case 'x': xz=(xz+1)%2; |
229 |
yz=0; |
yz=0; |
|
glutPostRedisplay(); |
|
230 |
break; |
break; |
231 |
case 'y': yz=(yz+1)%2; |
case 'y': yz=(yz+1)%2; |
232 |
xz=0; |
xz=0; |
233 |
glutPostRedisplay(); |
break; |
234 |
|
case 'z': if( xz || yz ){ |
235 |
|
scaledepth=( scaledepth+1 )%2; |
236 |
|
scalecount++; |
237 |
|
if( scalecount==1 ) |
238 |
|
readdepths( ".darwinview/depths" ); |
239 |
|
} |
240 |
|
break; |
241 |
} |
} |
242 |
|
glutPostRedisplay(); |
243 |
} |
} |
244 |
|
|
245 |
void TimerFunction( int value ){ // called when anim is set and arrow key is pressed |
void TimerFunction( int value ){ // called when anim is set and arrow key is pressed |
403 |
howmany=j-1; // saves number of data filenames |
howmany=j-1; // saves number of data filenames |
404 |
} |
} |
405 |
|
|
406 |
|
void readdepths( char filename[] ){ |
407 |
|
int i; |
408 |
|
FILE* fp; |
409 |
|
|
410 |
|
fp=fopen( filename, "r" ); |
411 |
|
|
412 |
|
for( i=NZ-1; i>=0; i-- ){ |
413 |
|
fscanf( fp, "%d ", &depths[i] ); |
414 |
|
totaldepth+=depths[i]; |
415 |
|
} |
416 |
|
|
417 |
|
fclose( fp ); |
418 |
|
} |
419 |
|
|
420 |
void readjet(){ //reads in color scale values |
void readjet(){ //reads in color scale values |
421 |
FILE* fp; |
FILE* fp; |
422 |
int i, j; |
int i, j; |
536 |
fclose( fp ); |
fclose( fp ); |
537 |
|
|
538 |
xmax=NX; ymax=NY; |
xmax=NX; ymax=NY; |
539 |
|
|
540 |
readjet(); // stores color values |
readjet(); // stores color values |
541 |
readnames( filename ); // gets list of filenames to read from |
readnames( filename ); // gets list of filenames to read from |
542 |
global(); // calculates max and min for all data |
global(); // calculates max and min for all data |
559 |
tmpy = (i/setsx)*(winy/setsy); // y coordinate of top left corner of subwindow |
tmpy = (i/setsx)*(winy/setsy); // y coordinate of top left corner of subwindow |
560 |
|
|
561 |
win[i]=glutCreateSubWindow( parent, tmpx, tmpy, winx/setsx, winy/setsy ); // creates subwindow |
win[i]=glutCreateSubWindow( parent, tmpx, tmpy, winx/setsx, winy/setsy ); // creates subwindow |
562 |
gluOrtho2D( 0, NX+35, 0, NY+15 ); // sets how data is mapped to subwindow |
gluOrtho2D( 0, NX+35, 0, NY+25 ); // sets how data is mapped to subwindow |
563 |
glutKeyboardFunc( key ); // called on key press |
glutKeyboardFunc( key ); // called on key press |
564 |
glutSpecialFunc( specialkey ); // called on special key press (arrow keys) |
glutSpecialFunc( specialkey ); // called on special key press (arrow keys) |
565 |
if( i >= sets ) // |
if( i >= sets ) // |