#include #include #include #include #include #define WINDOW "image" #define UP 101 #define DOWN 103 #define RIGHT 102 #define LEFT 100 #define MAX 200 int NX, NY, MAXNZ, setsx, setsy; void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int ); void readnames( char[] ), readarray( float[], char[], int ), readjet(); void TimerFunction( int ), bitmap( char[], int, int ); float data[MAX][MAX*MAX], mxval, mnval, jet[MAX][MAX]; float globalmx=0, globalmn=100; int win[MAX], ilev=1, howmany, count=0, glo=0, usr=0, anim=0; char initfns[MAX][MAX], fns[MAX][MAX][MAX]; void menu(int value){ int i; switch( value ){ case 1: usr=glo=0; // unset glo & usr, sets local max/min glutPostRedisplay(); break; case 2: glo=1; // enables global max/min usr=0; // unsets usr mxval=globalmx; // sets max to globalmx mnval=globalmn; // sets min to globalmn glutPostRedisplay(); // display with new values break; case 3: usr=1; // switch to user-set max/min glo=0; // unset glo printf( "Max=" ); scanf( "%f", &mxval ); // prompt for new max/min printf( "Min=" ); scanf( "%f", &mnval ); glutPostRedisplay(); // display with new values break; } } void display(void){ int i, j, ioff, q; float r, g, b, num, k, y; char str[MAX]; for( q=0; qmxval ) num=63; // if data is more than max, =max else num=63*( data[q][ioff]-mnval )/( mxval-mnval ); //scale num from 0-63 } r=jet[(int)num][0]; // set red val g=jet[(int)num][1]; // set green val b=jet[(int)num][2]; // set blue val } glColor3f( r, g, b ); // put r, g, b into effect glRectf( i, j, i+1, j+1 ); // draws a square for data value ioff++; } } glColor3f( 1, 1, 1 ); // set color to white glRectf( NX, 0, NX+1, NY+1 ); // draws a border glRectf( 0, NY, NX, NY+1 ); // draws a border for( i=0; i<64; i++ ){ //draws color bar glColor3f( jet[i][0], jet[i][1], jet[i][2]); //sets color k=(float)i; // turns i into a float y=(float)NY/64; // sets height of rectangles glRectf( NX+10, y*k, NX+20, (k+1)*y ); // draws rectangle } glColor3f( 1, 1, 1 ); // color to white sprintf( str, "%.2e", mxval ); // labels color bar with max val bitmap( str, NX+2, NY-1 ); sprintf( str, "%.2e", mnval ); // labels color bar with min val bitmap( str, NX+2, 1 ); sprintf( str, "Level %d", ilev ); // labels current level bitmap( str, 1, NY+3); if( glo ) // labels how max/min have been set sprintf( str, "Global" ); // if glo is set, display Global if( usr ) sprintf( str, "User-set" ); // if usr is set, display User-set if( !usr && !glo ) sprintf( str, "Local" ); // else display Local bitmap( str, NX+12, NY+3); if( anim ){ // tell user if autoplay is on sprintf( str, "Autoplay" ); bitmap( str, NX-15, NY+3 ); } bitmap( fns[q][count], 1, NY+6 ); // labels current file glutSwapBuffers(); glFlush(); } } void bitmap( char str[], int x, int y ){ int i; glRasterPos2f( x, y ); for( i=0; i1 ) ilev--; // if up arrow is pressed, moves up levels break; case LEFT : if( count>0 ) count--; // if left arrow is pressed, moves back in time break; case RIGHT: if( count1 ) // if you haven't reached the top ilev--; // keep going up break; case RIGHT : if( count0 ) // if you haven't reached the first file count--; // keep going left break; } glutPostRedisplay(); } void global(){ // calculates the max/min for the total data set FILE* fp; int h, i, j; for( h=0; h globalmx ) globalmx = mxval; // sets highest value to globalmx if( mnval < globalmn ) globalmn = mnval; // sets lowest value to globalmn } } void local( int i, int time, int lev ){ // calculates local max/min int j; mxval=0; mnval=100; readarray( data[i], fns[i][time], lev ); // read new array of data for( j=0; j mxval ) mxval=data[i][j]; // set largest val to mxval if( data[i][j] < mnval ) mnval=data[i][j]; // set smallest val to mnval } } void readnames( char filename[] ){ // reads in list of filenames FILE* fp; int i=0, j=0; fp=fopen( filename, "r" ); // opens list while( !feof(fp) ){ // reads until the end of the file fscanf( fp, "%s", initfns[i] ); // places filename into an array of strings i++; // counts how many filenames there are } fclose( fp ); // close file howmany=i-1; for(i=0; i