| 8 |
#define DOWN 103 |
#define DOWN 103 |
| 9 |
#define RIGHT 102 |
#define RIGHT 102 |
| 10 |
#define LEFT 100 |
#define LEFT 100 |
| 11 |
#define MAX 200 |
#define MAX 700 |
| 12 |
|
|
| 13 |
int NX, NY, NZ; |
int NX, NY, NZ; |
| 14 |
|
|
| 15 |
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 ); |
| 16 |
void readnames( char[] ), readarray( float[], char[], int ), readjet(); |
void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] ); |
| 17 |
void TimerFunction( int ), bitmap( char[], int, int ); |
void TimerFunction( int ), bitmap( char[], int, int ); |
| 18 |
|
|
| 19 |
float data[MAX][MAX*MAX], mxval, mnval, jet[MAX][MAX]; |
float data[MAX][MAX*MAX], mxval, mnval, jet[64][3]; |
| 20 |
float globalmx=0, globalmn=100; |
float globalmx=0, globalmn=100; |
| 21 |
int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, logscale=0, nonegs=1, endian=0; |
int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, logscale=0, xz=0, nonegs=1, endian=0; |
| 22 |
|
int xmax, ymax, offset=0; |
| 23 |
char initfns[MAX][MAX], fns[MAX][MAX][MAX]; |
char initfns[MAX][MAX], fns[MAX][MAX][MAX]; |
| 24 |
|
|
| 25 |
void menu(int value){ // called when menu is opened on right click |
void menu(int value){ // called when menu is opened on right click |
| 51 |
break; |
break; |
| 52 |
} |
} |
| 53 |
} |
} |
| 54 |
void display(void){ // called on glutPostRedisplay |
void display(){ // called on glutPostRedisplay |
| 55 |
int i, j, ioff, q; |
int i, j, ioff, q; |
| 56 |
float r, g, b, k, y; |
float r, g, b, k, y; |
| 57 |
double num, logmx, logmn; |
double num, logmx, logmn; |
| 58 |
char str[MAX]; |
char str[MAX]; |
| 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 |
if( glo || usr ) // if global or user-set max/min |
if( xz ) ymax=NZ; |
| 64 |
readarray( data[q], fns[q][count], ilev ); // read new array w/o calculating local max/min |
else ymax=NY; |
| 65 |
|
|
| 66 |
|
if( glo || usr ){ // if global or user-set max/min |
| 67 |
|
if( xz ) |
| 68 |
|
readxz( data[q], fns[q][count] ); |
| 69 |
|
else |
| 70 |
|
readarray( data[q], fns[q][count], ilev ); // read new array w/o calculating local max/min |
| 71 |
|
} |
| 72 |
else // if local max/min is set |
else // if local max/min is set |
| 73 |
local( q, count, ilev ); // read new array and calculate local max/min |
local( q, count, ilev ); // read new array and calculate local max/min |
| 74 |
|
|
| 82 |
logmn=log10( mnval ); |
logmn=log10( mnval ); |
| 83 |
} |
} |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
ioff=0; // ioff will count both i&j b/c data is 1D |
ioff=0; // ioff will count both i&j b/c data is 1D |
| 87 |
for( j=0; j<NY; j++ ){ // cycles through y values |
for( j=0; j<ymax; j++ ){ // cycles through y values |
| 88 |
for( i=0; i<NX; i++ ){ // cycles through x values |
for( i=0; i<xmax; i++ ){ // cycles through x values |
| 89 |
r=g=b=0; // set color values to black |
r=g=b=0; // set color values to black |
| 90 |
if( data[q][ioff]==0 ); // if data=0, values stay black |
if( data[q][ioff]==0 ); // if data=0, values stay black |
| 91 |
else{ |
else{ |
| 118 |
} |
} |
| 119 |
} |
} |
| 120 |
glColor3f( 1, 1, 1 ); // set color to white |
glColor3f( 1, 1, 1 ); // set color to white |
| 121 |
glRectf( NX, 0, NX+1, NY+1 ); // draws a border |
glRectf( xmax, 0, xmax+1, ymax+1 ); // draws a border |
| 122 |
glRectf( 0, NY, NX, NY+1 ); // draws a border |
glRectf( 0, ymax, xmax, ymax+1 ); // draws a border |
| 123 |
for( i=0; i<64; i++ ){ // draws color bar |
for( i=0; i<64; i++ ){ // draws color bar |
| 124 |
glColor3f( jet[i][0], jet[i][1], jet[i][2]); // sets color |
glColor3f( jet[i][0], jet[i][1], jet[i][2]); // sets color |
| 125 |
k=(float)i; // turns i into a float |
k=(float)i; // turns i into a float |
| 126 |
y=(float)NY/64; // sets height of rectangles |
y=(float)ymax/64; // sets height of rectangles |
| 127 |
glRectf( NX+10, y*k, NX+20, (k+1)*y ); // draws rectangle |
glRectf( xmax+10, y*k, xmax+20, (k+1)*y ); // draws rectangle |
| 128 |
} |
} |
| 129 |
glColor3f( 1, 1, 1 ); // color to white |
glColor3f( 1, 1, 1 ); // color to white |
| 130 |
|
|
| 132 |
sprintf( str, "%.2f", logmx ); |
sprintf( str, "%.2f", logmx ); |
| 133 |
else |
else |
| 134 |
sprintf( str, "%.1e", mxval ); // labels color bar with max val |
sprintf( str, "%.1e", mxval ); // labels color bar with max val |
| 135 |
bitmap( str, NX+2, NY-1 ); |
bitmap( str, xmax+2, ymax-1 ); |
| 136 |
|
|
| 137 |
if( logscale ) |
if( logscale ) |
| 138 |
sprintf( str, "%.2f", logmn ); |
sprintf( str, "%.2f", logmn ); |
| 139 |
else |
else |
| 140 |
sprintf( str, "%.1e", mnval ); // labels color bar with min val |
sprintf( str, "%.1e", mnval ); // labels color bar with min val |
| 141 |
bitmap( str, NX+2, 1 ); |
bitmap( str, xmax+2, 1 ); |
| 142 |
|
|
| 143 |
sprintf( str, "Level %d", ilev ); // labels current level |
if( xz ) |
| 144 |
bitmap( str, 1, NY+3 ); |
sprintf( str, "Y-coordinate=%d", offset+1); |
| 145 |
|
else |
| 146 |
|
sprintf( str, "Level %d", ilev ); // labels current level |
| 147 |
|
bitmap( str, 1, ymax+3 ); |
| 148 |
|
|
| 149 |
sprintf( str, "Time %d", count+1 ); // labels current time |
sprintf( str, "Time %d", count+1 ); // labels current time |
| 150 |
bitmap( str, 50, NY+3 ); |
bitmap( str, 80, ymax+3 ); |
| 151 |
|
|
| 152 |
if( glo ) // labels how max/min have been set |
if( glo ) // labels how max/min have been set |
| 153 |
sprintf( str, "Global" ); // if glo is set, display Global |
sprintf( str, "Global" ); // if glo is set, display Global |
| 155 |
sprintf( str, "User-set" ); // if usr is set, display User-set |
sprintf( str, "User-set" ); // if usr is set, display User-set |
| 156 |
if( !usr && !glo ) |
if( !usr && !glo ) |
| 157 |
sprintf( str, "Local" ); // else display Local |
sprintf( str, "Local" ); // else display Local |
| 158 |
bitmap( str, NX+12, NY+3 ); |
bitmap( str, xmax+12, ymax+3 ); |
| 159 |
|
|
| 160 |
if( anim ){ // tell user if autoplay is on |
if( anim ){ // tell user if autoplay is on |
| 161 |
sprintf( str, "Autoplay" ); |
sprintf( str, "Autoplay" ); |
| 162 |
bitmap( str, NX-25, NY+3 ); |
bitmap( str, xmax-25, ymax+3 ); |
| 163 |
} |
} |
| 164 |
|
|
| 165 |
if( logscale ){ |
if( logscale ){ |
| 166 |
sprintf( str, "Log Scale" ); // tell user if log scale is on |
sprintf( str, "Log Scale" ); // tell user if log scale is on |
| 167 |
bitmap( str, NX-25, NY+10 ); |
bitmap( str, xmax-25, ymax+10 ); |
| 168 |
} |
} |
| 169 |
|
|
| 170 |
bitmap( fns[q][count], 1, NY+10 ); // labels current file |
bitmap( fns[q][count], 1, ymax+10 ); // labels current file |
| 171 |
|
|
| 172 |
glutSwapBuffers(); // double buffering set to animate smoothly |
glutSwapBuffers(); // double buffering set to animate smoothly |
| 173 |
glFlush(); |
glFlush(); |
| 195 |
case 'a': anim=(anim+1)%2; // turns anim on/off |
case 'a': anim=(anim+1)%2; // turns anim on/off |
| 196 |
glutPostRedisplay(); |
glutPostRedisplay(); |
| 197 |
break; |
break; |
| 198 |
|
case 'x': xz=(xz+1)%2; |
| 199 |
|
glutPostRedisplay(); |
| 200 |
|
break; |
| 201 |
} |
} |
| 202 |
} |
} |
| 203 |
|
|
| 205 |
int i; |
int i; |
| 206 |
|
|
| 207 |
switch(value){ // increments in the correct direction |
switch(value){ // increments in the correct direction |
| 208 |
case DOWN : if( ilev<NZ ) |
case DOWN : if( xz ){ |
| 209 |
ilev++; // if down arrow pressed, move down a level |
if( offset>0 ) |
| 210 |
|
offset--; |
| 211 |
|
} |
| 212 |
|
else{ |
| 213 |
|
if( ilev<NZ ) |
| 214 |
|
ilev++; // if down arrow pressed, move down a level |
| 215 |
|
} |
| 216 |
break; |
break; |
| 217 |
case UP : if( ilev>1 ) |
case UP : if( xz ){ |
| 218 |
ilev--; // if up arrow is pressed, move up a level |
if( offset<NY-1 ) |
| 219 |
|
offset++; |
| 220 |
|
} |
| 221 |
|
else{ |
| 222 |
|
if( ilev>1 ) |
| 223 |
|
ilev--; // if up arrow is pressed, move up a level |
| 224 |
|
} |
| 225 |
break; |
break; |
| 226 |
case LEFT : if( count>0 ) |
case LEFT : if( count>0 ) |
| 227 |
count--; // if left arrow is pressed, move back one time step |
count--; // if left arrow is pressed, move back one time step |
| 235 |
|
|
| 236 |
if (anim ) |
if (anim ) |
| 237 |
switch( value ){ |
switch( value ){ |
| 238 |
case DOWN : if( ilev==NZ ) ilev=1; // if end reached, restart |
case DOWN : if( xz ){ |
| 239 |
|
if( offset==0 ) offset=NY-1; |
| 240 |
|
} |
| 241 |
|
else{ |
| 242 |
|
if( ilev==NZ ) ilev=1; // if end reached, restart |
| 243 |
|
} |
| 244 |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
| 245 |
break; |
break; |
| 246 |
case UP : if( ilev==1 ) ilev=NZ; // if end reached, restart |
case UP : if( xz ){ |
| 247 |
|
if( offset==NY-1) offset=0; |
| 248 |
|
} |
| 249 |
|
else{ |
| 250 |
|
if( ilev==1 ) ilev=NZ; // if end reached, restart |
| 251 |
|
} |
| 252 |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
| 253 |
break; |
break; |
| 254 |
case LEFT : if( count==0 ) count=howmany-1; // if end reached, restart |
case LEFT : if( count==0 ) count=howmany-1; // if end reached, restart |
| 267 |
glutTimerFunc( 100, TimerFunction, key); // to scroll automatically |
glutTimerFunc( 100, TimerFunction, key); // to scroll automatically |
| 268 |
|
|
| 269 |
switch(key){ |
switch(key){ |
| 270 |
case DOWN : if( ilev<NZ ) // if you haven't reached the bottom |
case DOWN : if( xz ){ |
| 271 |
ilev++; // keep going down |
if( offset>0 ) |
| 272 |
|
offset--; |
| 273 |
|
} |
| 274 |
|
else{ |
| 275 |
|
if( ilev<NZ ) // if you haven't reached the bottom |
| 276 |
|
ilev++; // keep going down |
| 277 |
|
} |
| 278 |
break; |
break; |
| 279 |
case UP : if( ilev>1 ) // if you haven't reached the top |
case UP : if( xz ){ |
| 280 |
ilev--; // keep going up |
if( offset<NY-1 ) |
| 281 |
|
offset++; |
| 282 |
|
} |
| 283 |
|
else{ |
| 284 |
|
if( ilev>1 ) // if you haven't reached the top |
| 285 |
|
ilev--; // keep going up |
| 286 |
|
} |
| 287 |
break; |
break; |
| 288 |
case RIGHT : if( count<howmany-1 ) // if you haven't reached the last file |
case RIGHT : if( count<howmany-1 ) // if you haven't reached the last file |
| 289 |
count++; // keep going right |
count++; // keep going right |
| 312 |
|
|
| 313 |
mxval=0; |
mxval=0; |
| 314 |
mnval=100; |
mnval=100; |
| 315 |
readarray( data[i], fns[i][time], lev ); // read new array of data |
if( xz ) |
| 316 |
for( j=0; j<NX*NY; j++ ){ |
readxz( data[i], fns[i][time]); |
| 317 |
|
else |
| 318 |
|
readarray( data[i], fns[i][time], lev ); // read new array of data |
| 319 |
|
for( j=0; j<xmax*ymax; j++ ){ |
| 320 |
if( data[i][j] > mxval ) |
if( data[i][j] > mxval ) |
| 321 |
mxval=data[i][j]; // set largest val to mxval |
mxval=data[i][j]; // set largest val to mxval |
| 322 |
if( data[i][j] < mnval && data[i][j]!=0 ) |
if( data[i][j] < mnval && data[i][j]!=0 ) |
| 359 |
fclose( fp ); // closes file |
fclose( fp ); // closes file |
| 360 |
} |
} |
| 361 |
|
|
| 362 |
|
void readxz( float arr[], char filename[] ){ |
| 363 |
|
int i; |
| 364 |
|
float tmp[MAX*MAX]; |
| 365 |
|
FILE* fp; |
| 366 |
|
|
| 367 |
|
fp=fopen( filename, "rb" ); |
| 368 |
|
for( i=0; i<NZ; i++){ |
| 369 |
|
fseek( fp, (NX*offset*4)+(i*NX*NY*4), SEEK_SET ); |
| 370 |
|
fread( &arr[NX*i], sizeof( arr[0] ), NX, fp ); // reads in data to fill one level |
| 371 |
|
} |
| 372 |
|
fclose( fp ); |
| 373 |
|
for( i=1; i<NX*NZ+1; i++ ) |
| 374 |
|
tmp[NX*NZ-i]=arr[i-1]; |
| 375 |
|
for( i=0; i<NX*NZ; i++ ) |
| 376 |
|
arr[i]=tmp[i]; |
| 377 |
|
} |
| 378 |
|
|
| 379 |
void readarray( float arr[], char filename[], int il ){ // reads new data |
void readarray( float arr[], char filename[], int il ){ // reads new data |
| 380 |
FILE* fp; |
FILE* fp; |
| 381 |
int i; |
int i; |
| 382 |
|
|
| 383 |
fp=fopen( filename, "r" ); // opens the file containing data |
fp=fopen( filename, "rb" ); // opens the file containing data |
| 384 |
fseek( fp, (il-1)*NX*NY*4, SEEK_SET ); // seeks to the correct place using ilev |
fseek( fp, (il-1)*NX*NY*4, SEEK_SET ); // seeks to the correct place using ilev |
| 385 |
fread( arr, sizeof( arr[0] ), NX*NY, fp ); // reads in data to fill one level |
fread( arr, sizeof( arr[0] ), NX*NY, fp ); // reads in data to fill one level |
| 386 |
fclose( fp ); // close file |
fclose( fp ); // close file |
| 429 |
printf( "Please enter dimensions of data sets.\n" ); |
printf( "Please enter dimensions of data sets.\n" ); |
| 430 |
scanf( "%dx%d", &setsx, &setsy ); // prompts user for dimensions of subwindows |
scanf( "%dx%d", &setsx, &setsy ); // prompts user for dimensions of subwindows |
| 431 |
|
|
| 432 |
|
xmax=NX; ymax=NY; |
| 433 |
|
|
| 434 |
readjet(); // stores color values |
readjet(); // stores color values |
| 435 |
readnames( filename ); // gets list of filenames to read from |
readnames( filename ); // gets list of filenames to read from |
| 436 |
global(); // calculates max and min for all data |
global(); // calculates max and min for all data |