/[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/24 16:53:55	1.6
+++ MITgcm_contrib/darwinview/src/darwin.c	2007/08/01 18:04:15	1.7
@@ -9,58 +9,58 @@
 #define RIGHT 102
 #define LEFT 100
 #define MAX 700 
+#define SCALE .06
  
 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(), readxz( float[], char[] );
-void readyz( float[], char[] );
-void TimerFunction( int ), bitmap( char[], int, int );
+void readyz( float[], char[] ), readdepths( char[] );
+void TimerFunction( int ), stroke( 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, yoffset=0, xoffset=0, yz=0;
+int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, endian=0;
+int xmax, ymax, yoffset=0, xoffset=0, yz=0, logscale=0, xz=0, nonegs=1;
+int depths[MAX], scaledepth=0, totaldepth=0, scalecount=0;
 char initfns[MAX][MAX], fns[MAX][MAX][MAX];
 
 void menu( int value ){           // called when menu is opened on right click
 
  switch( value ){
   case 1: usr=glo=0;            // unset glo & usr, sets local max/min
-          glutPostRedisplay();  // recall display func with new values 
           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();  // recall display func with new values
           break;
   case 3: usr=1;                // switch to user-set max/min 
           glo=0;                // unset glo
           printf( "Max=" );  scanf( "%f", &mxval );  // prompt user for new max
           printf( "Min=" );  scanf( "%f", &mnval );  // prompt user for new min
-          glutPostRedisplay();                       // recall display func with new values
           break;
-  case 4: logscale=(logscale+1)%2;  // switch log scale on/off
-          glutPostRedisplay();
+  case 4: logscale=( logscale+1 )%2;  // switch log scale on/off
           break;
-  case 5: nonegs=(nonegs+1)%2;      // switch allowance of negatives on/off 
-          glutPostRedisplay();
+  case 5: nonegs=( nonegs+1 )%2;      // switch allowance of negatives on/off 
           break;
-  case 6: endian=(endian+1)%2;      // switch between big/little endian
-          glutPostRedisplay();
+  case 6: endian=( endian+1 )%2;      // switch between big/little endian
           break;
  }
+ glutPostRedisplay();
 }
+
 void display(){                 // called on glutPostRedisplay
- int i, j, ioff, q; 
+ int i, j, h, 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
   glutSetWindow( win[q] );          // sets which subwindow to display to
   glClear( GL_COLOR_BUFFER_BIT );   // background to black
+
   if( xz ) {  xmax=NX;  ymax=NZ;  }
   else{
    if( yz ){  xmax=NY;  ymax=NZ;  } 
@@ -91,10 +91,11 @@
    }
   }
  
-  ioff=0;                           // ioff will count both i&j b/c data is 1D
+  if( scaledepth && xz || scaledepth && yz )  ymax=totaldepth;
+  ioff=0; h=0;                        // ioff will count both i&j b/c data is 1D
   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
+    r=g=b=0;                          // set color values to black
     if( data[q][ioff]==0 );           // if data=0, values stay black
     else{
      if( logscale ){
@@ -121,10 +122,18 @@
     }
 
     glColor3f( r, g, b );           // put r, g, b into effect
-    glRectf( i, j, i+1, j+1 );      // draws a square for data value 
+    if( scaledepth && xz || scaledepth && yz )
+     glRectf( i, j, i+1, j+depths[h] );
+    else
+     glRectf( i, j, i+1, j+1 );      // draws a square for data value 
     ioff++;                    
    } 
+   if( scaledepth && xz || scaledepth && yz ){
+    j+=depths[h]-1;
+    h++;
+   }
   } 
+
   glColor3f( 1, 1, 1 );             // set color to white
   glRectf( xmax, 0, xmax+1, ymax+1 );     // draws a border
   glRectf( 0, ymax, xmax, ymax+1 );       // draws a border  
@@ -140,13 +149,13 @@
    sprintf( str, "%.2f", logmx );
   else
    sprintf( str, "%.1e", mxval );    // labels color bar with max val
-  bitmap( str, xmax+2, ymax-1 );
+  stroke( str, xmax+2, ymax-1 );
   
   if( logscale )
    sprintf( str, "%.2f", logmn );
   else
    sprintf( str, "%.1e", mnval );    // labels color bar with min val
-  bitmap( str, xmax+2, 1 );
+  stroke( str, xmax+2, 1 );
 
   if( xz )
    sprintf( str, "N-S slice %d", yoffset+1);
@@ -156,10 +165,10 @@
    else
     sprintf( str, "Level %d", ilev ); // labels current level 
   }
-  bitmap( str, 1, ymax+3 );
+  stroke( str, 1, ymax+5 );
 
   sprintf( str, "Time %d", count+1 ); // labels current time 
-  bitmap( str, 80, ymax+3 );
+  stroke( str, xmax/2, ymax+5 );
 
   if( glo )                         // labels how max/min have been set
    sprintf( str, "Global" );        // if glo is set, display Global
@@ -167,31 +176,42 @@
    sprintf( str, "User-set" );      // if usr is set, display User-set
   if( !usr && !glo ) 
    sprintf( str, "Local" );         // else display Local 
-  bitmap( str, xmax+12, ymax+3 );
+  stroke( str, xmax+8, ymax+8 );
   
   if( anim ){                       // tell user if autoplay is on
    sprintf( str, "Autoplay" );
-   bitmap( str, xmax-25, ymax+3 );
+   stroke( str, xmax-35, ymax+8 );
   }
 
   if( logscale ){
    sprintf( str, "Log Scale" );     // tell user if log scale is on
-   bitmap( str, xmax-25, ymax+10 ); 
+   stroke( str, xmax-25, ymax+15); 
   }
 
-  bitmap( fns[q][count], 1, ymax+10 ); // labels current file
+  stroke( fns[q][count], 1, ymax+15 ); // labels current file
  
   glutSwapBuffers();                // double buffering set to animate smoothly
   glFlush(); 
  }
 }
 
-void bitmap( char str[], int x, int y ){  // called to display text onscreen
+void stroke( char str[], int x, int y ){  // called to display text onscreen
  int i;
 
- glRasterPos2f( x, y );             // set position of text
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+ glEnable( GL_BLEND );
+ glEnable( GL_LINE_SMOOTH );
+ glMatrixMode( GL_MODELVIEW );
+
+ glPushMatrix();
+
+ glScalef( SCALE, SCALE, SCALE );
+ glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 );
+
  for( i=0; i<strlen( str ); i++)    // display each character of str
-  glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, str[i] );
+  glutStrokeCharacter( GLUT_STROKE_ROMAN, str[i] );
+
+ glPopMatrix();
 }
 
 void key( unsigned char key, int x, int y ){   // called on key press
@@ -202,19 +222,24 @@
               break;
   case 'r':   count=0;              // resets back to first time    
               ilev=1;               // and first level
-              glutPostRedisplay();            
               break;
   case 'a':   anim=(anim+1)%2;      // turns anim on/off
-              glutPostRedisplay();            
               break;
   case 'x':   xz=(xz+1)%2;
               yz=0;
-              glutPostRedisplay();
               break;
   case 'y':   yz=(yz+1)%2;
               xz=0;
-              glutPostRedisplay();
+              break;
+  case 'z':   if( xz || yz ){
+               scaledepth=( scaledepth+1 )%2;
+               scalecount++;
+               if( scalecount==1 ) 
+                readdepths( ".darwinview/depths" );
+              }
+              break; 
  } 
+ glutPostRedisplay();
 }
 
 void TimerFunction( int value ){    // called when anim is set and arrow key is pressed
@@ -378,6 +403,20 @@
  howmany=j-1;                                  // saves number of data filenames  
 }
 
+void readdepths( char filename[] ){
+ int i;
+ FILE* fp;
+
+ fp=fopen( filename, "r" );
+
+ for( i=NZ-1; i>=0; i-- ){
+  fscanf( fp, "%d ", &depths[i] );
+  totaldepth+=depths[i];
+ } 
+
+ fclose( fp );
+}
+
 void readjet(){               //reads in color scale values
  FILE* fp;
  int i, j; 
@@ -497,7 +536,7 @@
  fclose( fp );
 
  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
@@ -520,7 +559,7 @@
   tmpy = (i/setsx)*(winy/setsy);                  // y coordinate of top left corner of subwindow 
 
   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
+  gluOrtho2D( 0, NX+35, 0, NY+25 );               // sets how data is mapped to subwindow
   glutKeyboardFunc( key );                        // called on key press
   glutSpecialFunc( specialkey );                  // called on special key press (arrow keys)
   if( i >= sets )                                 // 

 

  ViewVC Help
Powered by ViewVC 1.1.22