/[MITgcm]/MITgcm_contrib/darwinview/src/darwin.c
ViewVC logotype

Diff of /MITgcm_contrib/darwinview/src/darwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

--- MITgcm_contrib/darwinview/src/darwin.c	2007/07/13 18:47:12	1.3
+++ MITgcm_contrib/darwinview/src/darwin.c	2007/07/16 15:40:16	1.4
@@ -8,17 +8,18 @@
 #define DOWN 103
 #define RIGHT 102
 #define LEFT 100
-#define MAX 200
+#define MAX 700 
  
 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();
+void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] );
 void TimerFunction( int ), bitmap( char[], int, int );
 
-float data[MAX][MAX*MAX], mxval, mnval, jet[MAX][MAX];
+float data[MAX][MAX*MAX], mxval, mnval, jet[64][3];
 float globalmx=0, globalmn=100;
-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;
+int xmax, ymax, offset=0;
 char initfns[MAX][MAX], fns[MAX][MAX][MAX];
 
 void menu(int value){           // called when menu is opened on right click
@@ -50,17 +51,24 @@
           break;
  }
 }
-void display(void){                 // called on glutPostRedisplay
+void display(){                 // 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<sets; 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 
-   readarray( data[q], fns[q][count], ilev );  // read new array w/o calculating local max/min
+  if( xz )   ymax=NZ; 
+  else       ymax=NY;
+
+  if( glo || usr ){                  // if global or user-set max/min 
+   if( xz )
+    readxz( data[q], fns[q][count] );
+   else
+    readarray( data[q], fns[q][count], ilev );  // read new array w/o calculating local max/min
+  }
   else                              // if local max/min is set 
    local( q, count, ilev );         // read new array and calculate local max/min
 
@@ -74,10 +82,10 @@
     logmn=log10( mnval );
    }
   }
-
+ 
   ioff=0;                           // ioff will count both i&j b/c data is 1D
-  for( j=0; j<NY; j++ ){            // cycles through y values
-   for( i=0; i<NX; i++ ){           // cycles through x values
+  for( j=0; j<ymax; j++ ){            // cycles through y values
+   for( i=0; i<xmax; i++ ){           // cycles through x values
     r=g=b=0;                        // set color values to black
     if( data[q][ioff]==0 );           // if data=0, values stay black
     else{
@@ -110,13 +118,13 @@
    } 
   } 
   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  
+  glRectf( xmax, 0, xmax+1, ymax+1 );     // draws a border
+  glRectf( 0, ymax, xmax, ymax+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 
+   y=(float)ymax/64;                  // sets height of rectangles
+   glRectf( xmax+10, y*k, xmax+20, (k+1)*y );               // draws rectangle 
   } 
   glColor3f( 1, 1, 1 );             // color to white
 
@@ -124,19 +132,22 @@
    sprintf( str, "%.2f", logmx );
   else
    sprintf( str, "%.1e", mxval );    // labels color bar with max val
-  bitmap( str, NX+2, NY-1 );
+  bitmap( str, xmax+2, ymax-1 );
   
   if( logscale )
    sprintf( str, "%.2f", logmn );
   else
    sprintf( str, "%.1e", mnval );    // labels color bar with min val
-  bitmap( str, NX+2, 1 );
+  bitmap( str, xmax+2, 1 );
 
-  sprintf( str, "Level %d", ilev ); // labels current level 
-  bitmap( str, 1, NY+3 );
+  if( xz )
+   sprintf( str, "Y-coordinate=%d", offset+1);
+  else
+   sprintf( str, "Level %d", ilev ); // labels current level 
+  bitmap( str, 1, ymax+3 );
 
   sprintf( str, "Time %d", count+1 ); // labels current time 
-  bitmap( str, 50, NY+3 );
+  bitmap( str, 80, ymax+3 );
 
   if( glo )                         // labels how max/min have been set
    sprintf( str, "Global" );        // if glo is set, display Global
@@ -144,19 +155,19 @@
    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 );
+  bitmap( str, xmax+12, ymax+3 );
   
   if( anim ){                       // tell user if autoplay is on
    sprintf( str, "Autoplay" );
-   bitmap( str, NX-25, NY+3 );
+   bitmap( str, xmax-25, ymax+3 );
   }
 
   if( logscale ){
    sprintf( str, "Log Scale" );     // tell user if log scale is on
-   bitmap( str, NX-25, NY+10 ); 
+   bitmap( str, xmax-25, ymax+10 ); 
   }
 
-  bitmap( fns[q][count], 1, NY+10 ); // labels current file
+  bitmap( fns[q][count], 1, ymax+10 ); // labels current file
  
   glutSwapBuffers();                // double buffering set to animate smoothly
   glFlush(); 
@@ -184,6 +195,9 @@
   case 'a':   anim=(anim+1)%2;      // turns anim on/off
               glutPostRedisplay();            
               break;
+  case 'x':   xz=(xz+1)%2;
+              glutPostRedisplay();
+              break;
  } 
 }
 
@@ -191,11 +205,23 @@
  int i;
 
  switch(value){                     // increments in the correct direction
-  case DOWN : if( ilev<NZ ) 
-               ilev++;              // if down arrow pressed, move down a level      
+  case DOWN : if( xz ){
+               if( offset>0 )
+                offset--;
+              }
+              else{
+               if( ilev<NZ ) 
+                ilev++;              // if down arrow pressed, move down a level      
+              }
               break;
-  case UP   : if( ilev>1 )    
-               ilev--;              // if up arrow is pressed, move up a level
+  case UP   : if( xz ){
+               if( offset<NY-1 )
+                offset++;
+              }
+              else{
+               if( ilev>1 )    
+                ilev--;              // if up arrow is pressed, move up a level
+              }
               break;
   case LEFT : if( count>0 )      
                count--;             // if left arrow is pressed, move back one time step 
@@ -209,10 +235,20 @@
 
  if (anim )
   switch( value ){    
-   case DOWN : if( ilev==NZ ) ilev=1;                   // if end reached, restart 
+   case DOWN : if( xz ){
+                if( offset==0 ) offset=NY-1;
+               }
+               else{ 
+                if( ilev==NZ ) ilev=1;                   // if end reached, restart 
+               }
                glutTimerFunc( 100, TimerFunction, value ); // recalls itself
                break;
-   case UP   : if( ilev==1 ) ilev=NZ;                   // if end reached, restart 
+   case UP   : if( xz ){
+                if( offset==NY-1) offset=0;
+               }
+               else{
+                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 
@@ -231,11 +267,23 @@
   glutTimerFunc( 100, TimerFunction, key);             // to scroll automatically
 
  switch(key){
-  case DOWN   :  if( ilev<NZ )      // if you haven't reached the bottom
-                  ilev++;              // keep going down
+  case DOWN   :  if( xz ){
+                  if( offset>0 ) 
+                   offset--;
+                 }
+                 else{ 
+                  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
-                  ilev--;              // keep going up
+  case UP     :  if( xz ){
+                  if( offset<NY-1 ) 
+                   offset++;
+                 }
+                 else{
+                  if( ilev>1 )          // if you haven't reached the top
+                   ilev--;              // keep going up
+                 }
                  break;
   case RIGHT  :  if( count<howmany-1 ) // if you haven't reached the last file
                   count++;             // keep going right
@@ -264,8 +312,11 @@
  
  mxval=0;  
  mnval=100;
- readarray( data[i], fns[i][time], lev );      // read new array of data
- for( j=0; j<NX*NY; j++ ){
+ if( xz )
+  readxz( data[i], fns[i][time]);
+ else
+  readarray( data[i], fns[i][time], lev );      // read new array of data
+ for( j=0; j<xmax*ymax; j++ ){
   if( data[i][j] > mxval ) 
    mxval=data[i][j];                           // set largest val to mxval 
   if( data[i][j] < mnval && data[i][j]!=0 ) 
@@ -308,11 +359,28 @@
  fclose( fp );                // closes file
 }
 
+void readxz( float arr[], char filename[] ){
+ int i;
+ float tmp[MAX*MAX];
+ FILE* fp;
+ 
+ fp=fopen( filename, "rb" );   
+ for( i=0; i<NZ; i++){
+  fseek( fp, (NX*offset*4)+(i*NX*NY*4), SEEK_SET );
+  fread( &arr[NX*i], sizeof( arr[0] ), NX, fp );  // reads in data to fill one level 
+ }
+ fclose( fp );
+ for( i=1; i<NX*NZ+1; i++ )
+  tmp[NX*NZ-i]=arr[i-1];
+ for( i=0; i<NX*NZ; i++ )
+  arr[i]=tmp[i];
+}
+
 void readarray( float arr[], char filename[], int il ){   // reads new data
  FILE* fp;
  int i;
  
- fp=fopen( filename, "r" );                  // opens the file containing data
+ fp=fopen( filename, "rb" );                  // 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
@@ -361,6 +429,8 @@
  printf( "Please enter dimensions of data sets.\n" );
  scanf( "%dx%d", &setsx, &setsy );                 // prompts user for dimensions of subwindows
 
+ xmax=NX; ymax=NY;
+
  readjet();                               // stores color values
  readnames( filename );                   // gets list of filenames to read from
  global();                                // calculates max and min for all data

 

  ViewVC Help
Powered by ViewVC 1.1.22