/[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

revision 1.6 by marissa, Tue Jul 24 16:53:55 2007 UTC revision 1.8 by marissa, Fri Aug 3 14:37:15 2007 UTC
# Line 9  Line 9 
9  #define RIGHT 102  #define RIGHT 102
10  #define LEFT 100  #define LEFT 100
11  #define MAX 700  #define MAX 700
12    #define SCALE .06
13    
14  int NX, NY, NZ;  int NX, NY, NZ;
15    
16  void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int );  void do_byteswap_f32( float arr[], int nel ), global(), local( int, int, int );
17  void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] );  void readnames( char[] ), readarray( float[], char[], int ), readjet(), readxz( float[], char[] );
18  void readyz( float[], char[] );  void readyz( float[], char[] ), readdepths( char[] );
19  void TimerFunction( int ), bitmap( char[], int, int );  void TimerFunction( int ), stroke( char[], int, int );
20    
21  float data[MAX][MAX*MAX], mxval, mnval, jet[64][3];  float data[MAX][MAX*MAX], mxval, mnval, jet[64][3];
22  float globalmx=0, globalmn=100;  float globalmx=0, globalmn=100;
23  int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, logscale=0, xz=0, nonegs=1, endian=0;  int win[MAX], ilev=1, howmany, sets, count=0, glo=0, usr=0, anim=0, endian=0;
24  int xmax, ymax, yoffset=0, xoffset=0, yz=0;  int xmax, ymax, yoffset=0, xoffset=0, yz=0, logscale=0, xz=0, nonegs=1;
25    int depths[MAX], scaledepth=0, totaldepth=0, scalecount=0;
26  char initfns[MAX][MAX], fns[MAX][MAX][MAX];  char initfns[MAX][MAX], fns[MAX][MAX][MAX];
27    
28  void menu( int value ){           // called when menu is opened on right click  void menu( int value ){           // called when menu is opened on right click
29    
30   switch( value ){   switch( value ){
31    case 1: usr=glo=0;            // unset glo & usr, sets local max/min    case 1: usr=glo=0;            // unset glo & usr, sets local max/min
           glutPostRedisplay();  // recall display func with new values  
32            break;            break;
33    case 2: glo=1;                // enables global max/min      case 2: glo=1;                // enables global max/min  
34            usr=0;                // unsets usr            usr=0;                // unsets usr
35            mxval=globalmx;       // sets max to globalmx            mxval=globalmx;       // sets max to globalmx
36            mnval=globalmn;       // sets min to globalmn            mnval=globalmn;       // sets min to globalmn
           glutPostRedisplay();  // recall display func with new values  
37            break;            break;
38    case 3: usr=1;                // switch to user-set max/min    case 3: usr=1;                // switch to user-set max/min
39            glo=0;                // unset glo            glo=0;                // unset glo
40            printf( "Max=" );  scanf( "%f", &mxval );  // prompt user for new max            printf( "Max=" );  scanf( "%f", &mxval );  // prompt user for new max
41            printf( "Min=" );  scanf( "%f", &mnval );  // prompt user for new min            printf( "Min=" );  scanf( "%f", &mnval );  // prompt user for new min
           glutPostRedisplay();                       // recall display func with new values  
42            break;            break;
43    case 4: logscale=(logscale+1)%2;  // switch log scale on/off    case 4: logscale=( logscale+1 )%2;  // switch log scale on/off
           glutPostRedisplay();  
44            break;            break;
45    case 5: nonegs=(nonegs+1)%2;      // switch allowance of negatives on/off    case 5: nonegs=( nonegs+1 )%2;      // switch allowance of negatives on/off
           glutPostRedisplay();  
46            break;            break;
47    case 6: endian=(endian+1)%2;      // switch between big/little endian    case 6: endian=( endian+1 )%2;      // switch between big/little endian
           glutPostRedisplay();  
48            break;            break;
49   }   }
50     glutPostRedisplay();
51  }  }
52    
53  void display(){                 // called on glutPostRedisplay  void display(){                 // called on glutPostRedisplay
54   int i, j, ioff, q;   int i, h, ioff, q;
55   float r, g, b, k, y;   float r, g, b, k, y, j, tmp;
56   double num, logmx, logmn;   double num, logmx, logmn;
57   char str[MAX];   char str[MAX];
58    
59    
60   for( q=0; q<sets; q++ ){           // runs display func for each subwindow   for( q=0; q<sets; q++ ){           // runs display func for each subwindow
61    glutSetWindow( win[q] );          // sets which subwindow to display to    glutSetWindow( win[q] );          // sets which subwindow to display to
62    glClear( GL_COLOR_BUFFER_BIT );   // background to black    glClear( GL_COLOR_BUFFER_BIT );   // background to black
63    
64    if( xz ) {  xmax=NX;  ymax=NZ;  }    if( xz ) {  xmax=NX;  ymax=NZ;  }
65    else{    else{
66     if( yz ){  xmax=NY;  ymax=NZ;  }     if( yz ){  xmax=NY;  ymax=NZ;  }
# Line 91  void display(){                 // calle Line 91  void display(){                 // calle
91     }     }
92    }    }
93    
94    ioff=0;                           // ioff will count both i&j b/c data is 1D    if( scaledepth && xz || scaledepth && yz ) ymax=NY;
95    for( j=0; j<ymax; j++ ){            // cycles through y values    tmp=(float)ymax/totaldepth;
96      j=0; ioff=0; h=0;                        // ioff will count both i&j b/c data is 1D
97    
98      while ( j<ymax ){            // cycles through y values
99     for( i=0; i<xmax; i++ ){           // cycles through x values     for( i=0; i<xmax; i++ ){           // cycles through x values
100      r=g=b=0;                        // set color values to black      r=g=b=0;                          // set color values to black
101      if( data[q][ioff]==0 );           // if data=0, values stay black      if( data[q][ioff]==0 );           // if data=0, values stay black
102      else{      else{
103       if( logscale ){       if( logscale ){
# Line 121  void display(){                 // calle Line 124  void display(){                 // calle
124      }      }
125    
126      glColor3f( r, g, b );           // put r, g, b into effect      glColor3f( r, g, b );           // put r, g, b into effect
127      glRectf( i, j, i+1, j+1 );      // draws a square for data value      if( scaledepth && xz || scaledepth && yz )
128         glRectf( i, j, i+1, j+(depths[h]*tmp) );
129        else
130         glRectf( i, j, i+1, j+1 );      // draws a square for data value
131      ioff++;                          ioff++;                    
132     }     }
133       if( scaledepth && xz || scaledepth && yz ){
134        j+=(depths[h]*tmp);
135        h++;
136       }
137       else j++;
138    }    }
139    
140    glColor3f( 1, 1, 1 );             // set color to white    glColor3f( 1, 1, 1 );             // set color to white
141    glRectf( xmax, 0, xmax+1, ymax+1 );     // draws a border    glRectf( xmax, 0, xmax+1, ymax+1 );     // draws a border
142    glRectf( 0, ymax, xmax, ymax+1 );       // draws a border      glRectf( 0, ymax, xmax, ymax+1 );       // draws a border  
# Line 140  void display(){                 // calle Line 152  void display(){                 // calle
152     sprintf( str, "%.2f", logmx );     sprintf( str, "%.2f", logmx );
153    else    else
154     sprintf( str, "%.1e", mxval );    // labels color bar with max val     sprintf( str, "%.1e", mxval );    // labels color bar with max val
155    bitmap( str, xmax+2, ymax-1 );    stroke( str, xmax+2, ymax-1 );
156        
157    if( logscale )    if( logscale )
158     sprintf( str, "%.2f", logmn );     sprintf( str, "%.2f", logmn );
159    else    else
160     sprintf( str, "%.1e", mnval );    // labels color bar with min val     sprintf( str, "%.1e", mnval );    // labels color bar with min val
161    bitmap( str, xmax+2, 1 );    stroke( str, xmax+2, 1 );
162    
163    if( xz )    if( xz )
164     sprintf( str, "N-S slice %d", yoffset+1);     sprintf( str, "N-S slice %d", yoffset+1);
# Line 156  void display(){                 // calle Line 168  void display(){                 // calle
168     else     else
169      sprintf( str, "Level %d", ilev ); // labels current level      sprintf( str, "Level %d", ilev ); // labels current level
170    }    }
171    bitmap( str, 1, ymax+3 );    stroke( str, 1, ymax+5 );
172    
173    sprintf( str, "Time %d", count+1 ); // labels current time    sprintf( str, "Time %d", count+1 ); // labels current time
174    bitmap( str, 80, ymax+3 );    stroke( str, xmax/2, ymax+5 );
175    
176    if( glo )                         // labels how max/min have been set    if( glo )                         // labels how max/min have been set
177     sprintf( str, "Global" );        // if glo is set, display Global     sprintf( str, "Global" );        // if glo is set, display Global
# Line 167  void display(){                 // calle Line 179  void display(){                 // calle
179     sprintf( str, "User-set" );      // if usr is set, display User-set     sprintf( str, "User-set" );      // if usr is set, display User-set
180    if( !usr && !glo )    if( !usr && !glo )
181     sprintf( str, "Local" );         // else display Local     sprintf( str, "Local" );         // else display Local
182    bitmap( str, xmax+12, ymax+3 );    stroke( str, xmax+8, ymax+8 );
183        
184    if( anim ){                       // tell user if autoplay is on    if( anim ){                       // tell user if autoplay is on
185     sprintf( str, "Autoplay" );     sprintf( str, "Autoplay" );
186     bitmap( str, xmax-25, ymax+3 );     stroke( str, xmax-35, ymax+8 );
187    }    }
188    
189    if( logscale ){    if( logscale ){
190     sprintf( str, "Log Scale" );     // tell user if log scale is on     sprintf( str, "Log Scale" );     // tell user if log scale is on
191     bitmap( str, xmax-25, ymax+10 );     stroke( str, xmax-25, ymax+15);
192    }    }
193    
194    bitmap( fns[q][count], 1, ymax+10 ); // labels current file    stroke( fns[q][count], 1, ymax+15 ); // labels current file
195    
196    glutSwapBuffers();                // double buffering set to animate smoothly    glutSwapBuffers();                // double buffering set to animate smoothly
197    glFlush();    glFlush();
198   }   }
199  }  }
200    
201  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
202   int i;   int i;
203    
204   glRasterPos2f( x, y );             // set position of text   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
205     glEnable( GL_BLEND );
206     glEnable( GL_LINE_SMOOTH );
207     glMatrixMode( GL_MODELVIEW );
208    
209     glPushMatrix();
210    
211     glScalef( SCALE, SCALE, SCALE );
212     glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 );
213    
214   for( i=0; i<strlen( str ); i++)    // display each character of str   for( i=0; i<strlen( str ); i++)    // display each character of str
215    glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, str[i] );    glutStrokeCharacter( GLUT_STROKE_ROMAN, str[i] );
216    
217     glPopMatrix();
218  }  }
219    
220  void key( unsigned char key, int x, int y ){   // called on key press  void key( unsigned char key, int x, int y ){   // called on key press
221   int i, tmp;   int i, tmp;
222     char fn[MAX];
223    
224   switch(key){   switch(key){
225    case 'q':   exit(0);              // quits on 'q'    case 'q':   exit(0);              // quits on 'q'
226                break;                break;
227    case 'r':   count=0;              // resets back to first time        case 'r':   count=0;              // resets back to first time    
228                ilev=1;               // and first level                ilev=1;               // and first level
229                glutPostRedisplay();                            xz=yz=0;
230                break;                break;
231    case 'a':   anim=(anim+1)%2;      // turns anim on/off    case 'a':   anim=(anim+1)%2;      // turns anim on/off
               glutPostRedisplay();              
232                break;                break;
233    case 'x':   xz=(xz+1)%2;    case 'x':   xz=(xz+1)%2;
234                yz=0;                yz=0;
               glutPostRedisplay();  
235                break;                break;
236    case 'y':   yz=(yz+1)%2;    case 'y':   yz=(yz+1)%2;
237                xz=0;                xz=0;
238                glutPostRedisplay();                break;
239      case 'z':   if( xz || yz ){
240                   scaledepth=( scaledepth+1 )%2;
241                   scalecount++;
242                   if( scalecount==1 ){
243                    printf( "Please enter filename containing depth data: " );
244                    scanf( "%s", fn );
245                    readdepths( fn );
246                   }
247                  }
248                  break;
249   }   }
250     glutPostRedisplay();
251  }  }
252    
253  void TimerFunction( int value ){    // called when anim is set and arrow key is pressed  void TimerFunction( int value ){    // called when anim is set and arrow key is pressed
# Line 378  void readnames( char filename[] ){ Line 411  void readnames( char filename[] ){
411   howmany=j-1;                                  // saves number of data filenames     howmany=j-1;                                  // saves number of data filenames  
412  }  }
413    
414    void readdepths( char filename[] ){
415     int i;
416     FILE* fp;
417    
418     fp=fopen( filename, "r" );
419    
420     for( i=NZ-1; i>=0; i-- ){
421      fscanf( fp, "%d ", &depths[i] );
422      totaldepth+=depths[i];
423     }
424    
425     fclose( fp );
426    }
427    
428  void readjet(){               //reads in color scale values  void readjet(){               //reads in color scale values
429   FILE* fp;   FILE* fp;
430   int i, j;   int i, j;
431        
432   fp=fopen( ".darwinview/jet.h", "r" );  // opens file containing values   fp=fopen( "jet.dat", "r" );  // opens file containing values
433   for( i=0; i<64; i++ )        // reads in 64 sets of r, g, b values   for( i=0; i<64; i++ )        // reads in 64 sets of r, g, b values
434    for( j=0; j<3; j++ )    for( j=0; j<3; j++ )
435     fscanf( fp, "%f", &jet[i][j] );     fscanf( fp, "%f", &jet[i][j] );
# Line 520  int main( int argc, char *argv[] ){ Line 567  int main( int argc, char *argv[] ){
567    tmpy = (i/setsx)*(winy/setsy);                  // y coordinate of top left corner of subwindow    tmpy = (i/setsx)*(winy/setsy);                  // y coordinate of top left corner of subwindow
568    
569    win[i]=glutCreateSubWindow( parent, tmpx, tmpy, winx/setsx, winy/setsy ); // creates subwindow    win[i]=glutCreateSubWindow( parent, tmpx, tmpy, winx/setsx, winy/setsy ); // creates subwindow
570    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
571    glutKeyboardFunc( key );                        // called on key press    glutKeyboardFunc( key );                        // called on key press
572    glutSpecialFunc( specialkey );                  // called on special key press (arrow keys)    glutSpecialFunc( specialkey );                  // called on special key press (arrow keys)
573    if( i >= sets )                                 //    if( i >= sets )                                 //

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.22