#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, sets; int foo; void do_byteswap_f32( float arr[], int nel ), global(), local( int, int ); void readnames( char[] ), readarray( float[], char[], int ), readjet(); void TimerFunction( int ); float data[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 fns[MAX][MAX]; void menu(int value){ int i; switch( value ){ case 1: usr=glo=0; // unset glo & usr, sets local max/min local( count, ilev ); // reads new array, set local max/min 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 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 ); break; } for( i=0; imxval ) num=63; // if data is more than max, =max else num=63*( data[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 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, "%.4e", mxval ); // labels color bar with max val glRasterPos2f( NX+2, NY-1 ); // sets where to write to 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 ) // sets limit that you can go up glutTimerFunc( 100, TimerFunction, value ); // recalls itself break; case LEFT : if( count>0 ) // sets limit that you can go left glutTimerFunc( 100, TimerFunction, value ); // recalls itself 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; } if( glo || usr ) // if global or user-set max/min readarray(data, fns[count], ilev); // read new array w/o new max/min else // if local max/min set local(count, ilev); // read new array and calculate local max/min for(i=0; i globalmx ) globalmx = mxval; // sets highest value to globalmx if( mnval < globalmn ) globalmn = mnval; // sets lowest value to globalmn } } void local( int time, int lev ){ // calculates local max/min int i; mxval=0; mnval=100; readarray( data, fns[time], lev ); // read new array of data for( i=0;i mxval ) mxval=data[i]; // set largest val to mxval if( data[i] < mnval ) mnval=data[i]; // set smallest val to mnval } } void readnames( char filename[] ){ // reads in list of filenames containing data FILE* fp; int i=0; fp=fopen( filename, "r" ); // opens list while( !feof(fp) ){ // reads until the end of the file fscanf( fp, "%s",fns[i] ); // places filename into an array of strings i++; // counts how many filenames there are } fclose( fp ); // close file howmany=i-1; } void readjet(){ //reads in color scale values FILE* fp; int i, j; fp=fopen( "jet.dat", "r" ); // opens file containing values for( i=0; i<64; i++ ) // reads in 64 sets of r, g, b values for( j=0; j<3; j++ ) fscanf( fp, "%f", &jet[i][j] ); fclose( fp ); // closes file } void readarray( float arr[], char filename[], int il ){ // reads new data FILE *fp; int i; fp=fopen( filename, "r" ); // opens the file containing data fseek( fp, (il-1)*NX*NY*4, SEEK_SET ); // seeks to the correct level using ilev fread( arr, sizeof( arr[0] ), NX*NY, fp ); // reads in data to fill one level fclose( fp ); // close file do_byteswap_f32( arr,NX*NY ); // swaps the binary data } void do_byteswap_f32( float arr[], int nel ) // switches endian { int i; char src[4]; char trg[4]; for( i=0; i