/[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/16 15:40:16	1.4
+++ MITgcm_contrib/darwinview/src/darwin.c	2007/07/16 19:16:26	1.5
@@ -14,12 +14,13 @@
 
 void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int );
 void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] );
+void readyz( float[], char[] );
 void TimerFunction( int ), bitmap( char[], int, int );
 
 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, xz=0, nonegs=1, endian=0;
-int xmax, ymax, offset=0;
+int xmax, ymax, yoffset=0, xoffset=0, yz=0;
 char initfns[MAX][MAX], fns[MAX][MAX][MAX];
 
 void menu(int value){           // called when menu is opened on right click
@@ -60,14 +61,21 @@
  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( xz )   ymax=NZ; 
-  else       ymax=NY;
+  if( xz ) {  xmax=NX;  ymax=NZ;  }
+  else{
+   if( yz ){  xmax=NY;  ymax=NZ;  } 
+   else    {  xmax=NX;  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( yz )
+     readyz( 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
@@ -141,9 +149,13 @@
   bitmap( str, xmax+2, 1 );
 
   if( xz )
-   sprintf( str, "Y-coordinate=%d", offset+1);
-  else
-   sprintf( str, "Level %d", ilev ); // labels current level 
+   sprintf( str, "Y-coordinate=%d", yoffset+1);
+  else{
+   if( yz )
+    sprintf( str, "X-coordinate=%d", xoffset+1); 
+   else
+    sprintf( str, "Level %d", ilev ); // labels current level 
+  }
   bitmap( str, 1, ymax+3 );
 
   sprintf( str, "Time %d", count+1 ); // labels current time 
@@ -196,8 +208,12 @@
               glutPostRedisplay();            
               break;
   case 'x':   xz=(xz+1)%2;
+              yz=0;
               glutPostRedisplay();
               break;
+  case 'y':   yz=(yz+1)%2;
+              xz=0;
+              glutPostRedisplay();
  } 
 }
 
@@ -205,22 +221,24 @@
  int i;
 
  switch(value){                     // increments in the correct direction
-  case DOWN : if( xz ){
-               if( offset>0 )
-                offset--;
-              }
+  case DOWN : if( xz && yoffset>0 )
+               yoffset--;
               else{
-               if( ilev<NZ ) 
-                ilev++;              // if down arrow pressed, move down a level      
+               if( yz && xoffset<NX-1 )
+                xoffset++;
+               else 
+                if( ilev<NZ && !xz && !yz ) 
+                 ilev++;              // if down arrow pressed, move down a level      
               }
               break;
-  case UP   : if( xz ){
-               if( offset<NY-1 )
-                offset++;
-              }
+  case UP   : if( xz && yoffset<NY-1 )
+               yoffset++;
               else{
-               if( ilev>1 )    
-                ilev--;              // if up arrow is pressed, move up a level
+               if( yz && xoffset>0 )
+                xoffset--; 
+               else
+                if( ilev>1 && !xz && !yz )    
+                 ilev--;              // if up arrow is pressed, move up a level
               }
               break;
   case LEFT : if( count>0 )      
@@ -233,21 +251,27 @@
  
  glutPostRedisplay();            
 
- if (anim )
+ if ( anim )
   switch( value ){    
-   case DOWN : if( xz ){
-                if( offset==0 ) offset=NY-1;
-               }
+   case DOWN : if( xz && yoffset==0 )
+                yoffset=NY-1;
                else{ 
-                if( ilev==NZ ) ilev=1;                   // if end reached, restart 
+                if( yz && xoffset==NX-1 )
+                 xoffset=0;
+                else
+                 if( ilev==NZ && !xz && !yz )
+                  ilev=1;                   // if end reached, restart 
                }
                glutTimerFunc( 100, TimerFunction, value ); // recalls itself
                break;
-   case UP   : if( xz ){
-                if( offset==NY-1) offset=0;
-               }
+   case UP   : if( xz && yoffset==NY-1 )
+                yoffset=0;
                else{
-                if( ilev==1 ) ilev=NZ;                   // if end reached, restart 
+                if( yz && xoffset==0 )
+                 xoffset=NX-1;
+                else
+                 if( ilev==1 )
+                  ilev=NZ;                   // if end reached, restart 
                }
                glutTimerFunc( 100, TimerFunction, value ); // recalls itself 
                break;
@@ -267,22 +291,24 @@
   glutTimerFunc( 100, TimerFunction, key);             // to scroll automatically
 
  switch(key){
-  case DOWN   :  if( xz ){
-                  if( offset>0 ) 
-                   offset--;
-                 }
+  case DOWN   :  if( xz && yoffset>0 ) 
+                  yoffset--;
                  else{ 
-                  if( ilev<NZ )      // if you haven't reached the bottom
-                   ilev++;              // keep going down
+                  if( yz && xoffset<NY-1 )
+                   xoffset++;
+                  else
+                   if( ilev<NZ && !xz && !yz )      // if you haven't reached the bottom
+                    ilev++;              // keep going down
                  } 
                  break;
-  case UP     :  if( xz ){
-                  if( offset<NY-1 ) 
-                   offset++;
-                 }
+  case UP     :  if( xz && yoffset<NY-1 )
+                  yoffset++;
                  else{
-                  if( ilev>1 )          // if you haven't reached the top
-                   ilev--;              // keep going up
+                  if( yz && xoffset>0 )
+                   xoffset--;
+                  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
@@ -314,8 +340,12 @@
  mnval=100;
  if( xz )
   readxz( data[i], fns[i][time]);
- else
-  readarray( data[i], fns[i][time], lev );      // read new array of data
+ else{
+  if( yz )
+   readyz( 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 
@@ -360,27 +390,58 @@
 }
 
 void readxz( float arr[], char filename[] ){
- int i;
- float tmp[MAX*MAX];
+ int i, j;
+ float tmp[MAX][MAX], tmp2[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 );
+  fseek( fp, (NX*yoffset*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];
+
+ for( i=0; i<NZ; i++ )
+  for( j=0; j<NX; j++)
+   tmp[i][j]=arr[i*NX+j];
+
+ for( i=0; i<NZ; i++ )
+  for( j=0; j<NX; j++)
+   tmp2[i*NX+j]=tmp[NZ-i-1][j];
+
+ for( i=0; i<NX*NZ; i++)
+  arr[i]=tmp2[i];
+}
+
+void readyz( float arr[], char filename[] ){
+ int i, j;
+ float tmp[MAX][MAX], tmp2[MAX*MAX];
+ FILE* fp;  
+ 
+ fp=fopen( filename, "rb" );
+ for( i=0; i<NY*NZ; i++ ){
+  fseek( fp, (xoffset*4)+(i*NX*4), SEEK_SET ); 
+  fread( &arr[i], sizeof( arr[0] ), 1, fp );
+ }
+ fclose(fp);
+
+ for( i=0; i<NZ; i++ )
+  for( j=0; j<NY; j++)
+   tmp[i][j]=arr[i*NY+j];
+
+ for( i=0; i<NZ; i++ )
+  for( j=0; j<NY; j++)
+   tmp2[i*NY+j]=tmp[NZ-i-1][j];
+
+ for( i=0; i<NY*NZ; i++)
+  arr[i]=tmp2[i];
 }
 
 void readarray( float arr[], char filename[], int il ){   // reads new data
  FILE* fp;
  int i;
  
- fp=fopen( filename, "rb" );                  // 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

 

  ViewVC Help
Powered by ViewVC 1.1.22