Parent Directory
|
Revision Log
|
Revision Graph
|
Patch
--- MITgcm_contrib/darwinview/src/darwin.c 2007/07/12 18:30:19 1.2
+++ MITgcm_contrib/darwinview/src/darwin.c 2007/07/13 18:47:12 1.3
@@ -10,7 +10,7 @@
#define LEFT 100
#define MAX 200
-int NX, NY, MAXNZ, setsx, setsy;
+int NX, NY, NZ;
void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int );
void readnames( char[] ), readarray( float[], char[], int ), readjet();
@@ -18,7 +18,7 @@
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, logscale=0;
+int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, logscale=0, nonegs=1, endian=0;
char initfns[MAX][MAX], fns[MAX][MAX][MAX];
void menu(int value){ // called when menu is opened on right click
@@ -42,16 +42,21 @@
case 4: logscale=(logscale+1)%2; // switch log scale on/off
glutPostRedisplay();
break;
+ case 5: nonegs=(nonegs+1)%2; // switch allowance of negatives on/off
+ glutPostRedisplay();
+ break;
+ case 6: endian=(endian+1)%2; // switch between big/little endian
+ glutPostRedisplay();
+ break;
}
}
-
void display(void){ // called on glutPostRedisplay
int i, j, ioff, q;
float r, g, b, k, y;
double num, logmx, logmn;
char str[MAX];
- for( q=0; q<setsx*setsy; q++ ){ // runs display func for each subwindow
+ for( q=0; q<sets; q++ ){ // runs display func for each subwindow
glutSetWindow( win[q] ); // sets which subwindow to display to
glClear( GL_COLOR_BUFFER_BIT ); // background to black
if( glo || usr ) // if global or user-set max/min
@@ -80,16 +85,19 @@
num=(double)data[q][ioff];
num=log10( num );
if( num<logmn ) num=0;
- if( num>logmx ) num=63;
- else
- num=63*( num-logmn )/( logmx-logmn );
+ else{
+ if( num>logmx ) num=63;
+ else
+ num=63*( num-logmn )/( logmx-logmn );
+ }
}
else{
if( data[q][ioff]<mnval ) num=0; // if data is less than min, =min
- else
+ else{
if( data[q][ioff]>mxval ) num=63; // if data is more than max, =max
else
num=63*( data[q][ioff]-mnval )/( mxval-mnval ); // scale num from 0-63 (not defined for 64)
+ }
}
r=jet[(int)num][0]; // set red val
g=jet[(int)num][1]; // set green val
@@ -115,13 +123,13 @@
if( logscale )
sprintf( str, "%.2f", logmx );
else
- sprintf( str, "%.2e", mxval ); // labels color bar with max val
+ sprintf( str, "%.1e", mxval ); // labels color bar with max val
bitmap( str, NX+2, NY-1 );
if( logscale )
sprintf( str, "%.2f", logmn );
else
- sprintf( str, "%.2e", mnval ); // labels color bar with min val
+ sprintf( str, "%.1e", mnval ); // labels color bar with min val
bitmap( str, NX+2, 1 );
sprintf( str, "Level %d", ilev ); // labels current level
@@ -164,7 +172,7 @@
}
void key( unsigned char key, int x, int y ){ // called on key press
- int i;
+ int i, tmp;
switch(key){
case 'q': exit(0); // quits on 'q'
@@ -183,7 +191,7 @@
int i;
switch(value){ // increments in the correct direction
- case DOWN : if( ilev<MAXNZ )
+ case DOWN : if( ilev<NZ )
ilev++; // if down arrow pressed, move down a level
break;
case UP : if( ilev>1 )
@@ -201,10 +209,10 @@
if (anim )
switch( value ){
- case DOWN : if( ilev==MAXNZ ) ilev=1; // if end reached, restart
+ case DOWN : if( ilev==NZ ) ilev=1; // if end reached, restart
glutTimerFunc( 100, TimerFunction, value ); // recalls itself
break;
- case UP : if( ilev==1 ) ilev=MAXNZ; // if end reached, restart
+ case UP : if( ilev==1 ) ilev=NZ; // if end reached, restart
glutTimerFunc( 100, TimerFunction, value ); // recalls itself
break;
case LEFT : if( count==0 ) count=howmany-1; // if end reached, restart
@@ -223,7 +231,7 @@
glutTimerFunc( 100, TimerFunction, key); // to scroll automatically
switch(key){
- case DOWN : if( ilev<MAXNZ ) // if you haven't reached the bottom
+ case DOWN : if( ilev<NZ ) // if you haven't reached the bottom
ilev++; // keep going down
break;
case UP : if( ilev>1 ) // if you haven't reached the top
@@ -242,9 +250,9 @@
void global(){ // calculates the max/min for the total data set
FILE* fp;
int h, i, j;
- for( h=0; h<setsx*setsy; h++) // cycles through each window
+ for( h=0; h<sets; h++) // cycles through each window
for( i=0; i<howmany; i++ ) // cycles through each time
- for( j=0; j<MAXNZ; j++ ){ // cycles through each level for each file
+ for( j=0; j<NZ; j++ ){ // cycles through each level for each file
local( h, i, j ); // calculates local max/min for specific data set
if( mxval > globalmx ) globalmx = mxval; // sets highest value to globalmx
if( mnval < globalmn ) globalmn = mnval; // sets lowest value to globalmn
@@ -260,7 +268,7 @@
for( j=0; j<NX*NY; j++ ){
if( data[i][j] > mxval )
mxval=data[i][j]; // set largest val to mxval
- if( data[i][j] < mnval && data[i][j] > 0 )
+ if( data[i][j] < mnval && data[i][j]!=0 )
mnval=data[i][j]; // set smallest positive val to mnval
}
}
@@ -275,9 +283,9 @@
i++; // counts how many filenames there are
}
fclose( fp ); // close file
- howmany=i-1; // saves number of initial filenames
+ sets=i-1; // saves number of initial filenames
- for(i=0; i<howmany; i++){ // goes through each read-in filename
+ for(i=0; i<sets; i++){ // goes through each read-in filename
fp=fopen( initfns[i], "r" ); // opens each filename
j=0;
while( !feof(fp) ){ // reads in filenames from each filename
@@ -290,7 +298,6 @@
}
void readjet(){ //reads in color scale values
-
FILE* fp;
int i, j;
@@ -301,49 +308,58 @@
fclose( fp ); // closes file
}
-
void readarray( float arr[], char filename[], int il ){ // reads new data
- FILE *fp;
+ 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 place using ilev
fread( arr, sizeof( arr[0] ), NX*NY, fp ); // reads in data to fill one level
fclose( fp ); // close file
- for( i=0; i<NX*NY; i++ )
- if( arr[i] < 0 ) arr[i] = pow(10, -20); // sets negative values to 10^-20
- //do_byteswap_f32( arr, NX*NY ); // switches endian
+ if( nonegs )
+ for( i=0; i<NX*NY; i++ )
+ if( arr[i] < 0 )
+ arr[i] = pow(10, -20); // sets negative values to 10^-20
+
+ if( endian )
+ do_byteswap_f32( arr, NX*NY ); // switches endian
}
-void do_byteswap_f32( float arr[], int nel ) // switches endian
-{
- int i;
- char src[4];
- char trg[4];
- for( i=0; i<nel; i++ ){
- memcpy( src, &(arr[i]), 4);
- trg[0]=src[3];
- trg[1]=src[2];
- trg[2]=src[1];
- trg[3]=src[0];
- memcpy( &(arr[i]), trg, 4);
- }
+void do_byteswap_f32( float arr[], int nel ){ // switches endian
+
+ int i;
+ char src[4], trg[4];
+
+ for( i=0; i<nel; i++ ){
+ memcpy( src, &(arr[i]), 4 );
+ trg[0]=src[3];
+ trg[1]=src[2];
+ trg[2]=src[1];
+ trg[3]=src[0];
+ memcpy( &(arr[i]), trg, 4 );
+ }
+}
+
+void black(){
+ glClear( GL_COLOR_BUFFER_BIT );
+ glutSwapBuffers();
+ glFlush();
}
int main( int argc, char *argv[] ){
- int i, tmpx, tmpy, winx, winy, parent;
+ int i, setsx, setsy, tmpx, tmpy, winx, winy, parent;
char filename[MAX];
- sscanf(argv[1], "%dx%d", &winx, &winy); // reads screen resolution from command line
+ sscanf( argv[1], "%dx%d", &winx, &winy ); // reads screen resolution from command line
winy-=60; winx-=20; // adjusts resolution so edges won't get cut off
printf( "Please enter x, y and z dimensions.\n" );
- scanf( "%d %d %d", &NX, &NY, &MAXNZ ); // prompts user for NX, NY, NZ
+ scanf( "%d %d %d", &NX, &NY, &NZ ); // prompts user for NX, NY, NZ
printf( "Please enter filename.\n" );
scanf( "%s", filename ); // prompts user for initial filenames
printf( "Please enter dimensions of data sets.\n" );
- scanf( "%dx%d", &setsx, &setsy); // prompts user for dimensions of subwindows
+ scanf( "%dx%d", &setsx, &setsy ); // prompts user for dimensions of subwindows
readjet(); // stores color values
readnames( filename ); // gets list of filenames to read from
@@ -360,25 +376,30 @@
glutDisplayFunc( display );
glutKeyboardFunc( key ); // called on key press
glutSpecialFunc( specialkey ); // called on special key press (arrow keys)
+
for( i=0; i<setsx*setsy; i++ ){
tmpx = (i%setsx)*(winx/setsx); // x coordinate of top left corner of subwindow
tmpy = (i/setsx)*(winy/setsy); // y coordinate of top left corner of subwindow
- local( i, count, ilev ); // reads curr data array, finds local max/min
-
win[i]=glutCreateSubWindow( parent, tmpx, tmpy, winx/setsx, winy/setsy ); // creates subwindow
gluOrtho2D( 0, NX+35, 0, NY+15 ); // sets how data is mapped to subwindow
- glutDisplayFunc( display ); // sets display func for subwindow
glutKeyboardFunc( key ); // called on key press
glutSpecialFunc( specialkey ); // called on special key press (arrow keys)
+ if( i >= sets ) //
+ glutDisplayFunc( black );
+ else
+ glutDisplayFunc( display ); // sets display func for subwindow
+
- glutCreateMenu( menu ); // adds a menu
- glutAddMenuEntry( "Local Color Scale", 1 ); // adds a menu entry
- glutAddMenuEntry( "Global Color Scale", 2 ); // adds a menu entry
- glutAddMenuEntry( "User-Set Color Scale", 3 ); // adds a menu entry
- glutAddMenuEntry( "Log Scale (on/off)", 4 ); // adds a menu entry
- glutAttachMenu( GLUT_RIGHT_BUTTON ); // menu called on right click
+ glutCreateMenu( menu ); // adds a menu
+ glutAddMenuEntry( "Local Color Scale", 1 ); // adds a menu entry
+ glutAddMenuEntry( "Global Color Scale", 2 ); // adds a menu entry
+ glutAddMenuEntry( "User-Set Color Scale", 3 ); // adds a menu entry
+ glutAddMenuEntry( "Log Scale (on/off)", 4 ); // adds a menu entry
+ glutAddMenuEntry( "Allow Negatives (on/off)", 5 ); // adds a menu entry
+ glutAddMenuEntry( "Switch Endian (big/little) ", 6); // adds a menu entry
+ glutAttachMenu( GLUT_RIGHT_BUTTON ); // menu called on right click
}
glutMainLoop(); // begin processing events
| ViewVC Help | |
| Powered by ViewVC 1.1.22 |