Parent Directory
|
Revision Log
|
Revision Graph
|
Patch
--- MITgcm_contrib/darwinview/src/darwin.c 2007/08/03 14:37:15 1.8
+++ MITgcm_contrib/darwinview/src/darwin.c 2007/08/03 19:14:34 1.9
@@ -1,3 +1,24 @@
+/*
+ * darwinView
+ * Written by Marissa Weichman June-July 2007
+ * Contact: mweichman@gmail.com
+ *
+ * See the darwinView Guide for instructions on using this program.
+ *
+ * The program begins running at main(), at the bottom of this file. The function
+ * readjet() reads in the rgb for the color scale, while readnames() fills the array
+ * fns[][][] with the appropriate filenames to read data from. The functions that
+ * do the reading in are readxy(), readxz() and readyz() depending upon which plane
+ * is being viewed (xy, xz and yz, respectively). The functions global() and local()
+ * calculate the global and local maximum and minimum of the data sets. The key()
+ * and specialkey() functions handle keyboard input from the user. Everytime a key
+ * push changes any information, the display() function is called, which redisplays
+ * the plots with the new values. Finally, TimerFunction() is called when the
+ * autoplay feature is set, and an arrow key is pushed. TimerFunction() calls itself
+ * recursively, and redisplays every 10th of a second as it scrolls through time,
+ * depth levels, etc.
+ */
+
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
@@ -14,18 +35,17 @@
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[] ), readdepths( char[] );
void TimerFunction( int ), stroke( char[], int, int );
+void readxy( float[], char[], int), readxz( float[], char[] ), readyz( float[], char[] );
+void readnames( char[] ), readjet(), readdepths( char[] );
-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, 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;
+float data[MAX][MAX*MAX], mxval, mnval, jet[64][3], globalmx=0, globalmn=100;
+int glo=0, usr=0, anim=0, endian=0, logscale=0, xz=0, yz=0, nonegs=1, scaledepth=0;
+int win[MAX], depths[MAX], ilev=1, howmany, sets, count=0, xmax, ymax, yoffset=0, xoffset=0;
+int totaldepth=0, scalecount=0;
char initfns[MAX][MAX], fns[MAX][MAX][MAX];
-void menu( int value ){ // called when menu is opened on right click
+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
@@ -37,184 +57,191 @@
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
+ printf( "Max = " ); scanf( "%f", &mxval ); // prompt user for new max
+ printf( "Min = " ); scanf( "%f", &mnval ); // prompt user for new min
break;
- case 4: logscale=( logscale+1 )%2; // switch log scale on/off
+ case 4: logscale=( logscale+1 )%2; // toggle log scale
break;
- case 5: nonegs=( nonegs+1 )%2; // switch allowance of negatives on/off
+ case 5: nonegs=( nonegs+1 )%2; // toggle allowance of negatives
break;
- case 6: endian=( endian+1 )%2; // switch between big/little endian
+ case 6: endian=( endian+1 )%2; // toggle big/little endian
break;
}
- glutPostRedisplay();
+ glutPostRedisplay(); // redisplay with new values
}
-void display(){ // called on glutPostRedisplay
+void display(){ // called on glutPostRedisplay
int i, h, ioff, q;
float r, g, b, k, y, j, tmp;
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
+ 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; }
+ if( xz ) { xmax=NX; ymax=NZ; } // if in xz view, set y-axis to depth
else{
- if( yz ){ xmax=NY; ymax=NZ; }
- else { xmax=NX; ymax=NY; }
+ if( yz ){ xmax=NY; ymax=NZ; } // if in yz view, set x-axis to y, y-axis to depth
+ else { xmax=NX; ymax=NY; } // otherwise, x-axis = x, y-axis = y
}
- if( glo || usr ){ // if global or user-set max/min
- if( xz )
- readxz( data[q], fns[q][count] );
+ if( glo || usr ){ // if global or user-set max/min
+ if( xz ) // if in xz view
+ readxz( data[q], fns[q][count] ); // read new xz values w/o calculcating 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
+ if( yz ) // if in yz view
+ readyz( data[q], fns[q][count] );// read new yz values w/o calculating local max/min
+ else // if in xy view
+ readxy( data[q], fns[q][count], ilev ); // read new xy values 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
- if( logscale ){
- if( usr ){
- logmx=(double)mxval;
+ if( logscale ){ // if log scale is set
+ if( usr ){ // and values are user-set
+ logmx=(double)mxval; // assume the log has already been taken of max/min
logmn=(double)mnval;
}
- else{
- logmx=log10( mxval );
+ else{ // otherwise
+ logmx=log10( mxval ); // take the log of max/min
logmn=log10( mnval );
}
}
- if( scaledepth && xz || scaledepth && yz ) ymax=NY;
- tmp=(float)ymax/totaldepth;
- j=0; ioff=0; h=0; // ioff will count both i&j b/c data is 1D
+ if( scaledepth && xz || scaledepth && yz ){ // if scale-depth is set
+ ymax=NY; // scale z values to ymax
+ tmp=(float)ymax/totaldepth; // calculate ratio between z and ymax
+ }
- while ( j<ymax ){ // cycles through y values
+ j=0; // counts through y-values
+ ioff=0; // counts through i&j values, because data is 1 dimensional
+ h=0; // h counts depth levels if scaledepth is set
+
+ while ( j<ymax ){ // 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{
- if( logscale ){
+ if( logscale ){ // if logscale is set
num=(double)data[q][ioff];
- num=log10( num );
- if( num<logmn ) num=0;
+ num=log10( num ); // calculate log of data
+ if( num<logmn ) num=0; // set data less than min to min
else{
- if( num>logmx ) num=63;
+ if( num>logmx ) num=63; // set data more than max to max
else
- num=63*( num-logmn )/( logmx-logmn );
+ num=63*( num-logmn )/( logmx-logmn ); // scale all others
}
}
- else{
- if( data[q][ioff]<mnval ) num=0; // if data is less than min, =min
+ else{ // if not logscale
+ if( data[q][ioff]<mnval ) num=0; // set data less than min to min
else{
- if( data[q][ioff]>mxval ) num=63; // if data is more than max, =max
+ if( data[q][ioff]>mxval ) num=63; // set data more than max to max
else
- num=63*( data[q][ioff]-mnval )/( mxval-mnval ); // scale num from 0-63 (not defined for 64)
+ num=63*( data[q][ioff]-mnval )/( mxval-mnval ); // scale all others
}
}
- r=jet[(int)num][0]; // set red val
- g=jet[(int)num][1]; // set green val
- b=jet[(int)num][2]; // set blue val
+ r=jet[(int)num][0]; // set red value
+ g=jet[(int)num][1]; // set green value
+ b=jet[(int)num][2]; // set blue value
}
- glColor3f( r, g, b ); // put r, g, b into effect
- if( scaledepth && xz || scaledepth && yz )
- glRectf( i, j, i+1, j+(depths[h]*tmp) );
- else
- glRectf( i, j, i+1, j+1 ); // draws a square for data value
+ glColor3f( r, g, b ); // put r, g, b into effect
+ if( scaledepth && xz || scaledepth && yz ) // if scaledepth is set
+ glRectf( i, j, i+1, j+(depths[h]*tmp) ); // draw box appropriate to width of level
+ else // otherwise
+ glRectf( i, j, i+1, j+1 ); // draw a square
ioff++;
- }
- if( scaledepth && xz || scaledepth && yz ){
- j+=(depths[h]*tmp);
- h++;
+ } // leave x loop
+ if( scaledepth && xz || scaledepth && yz ){ // if scaledepth is set
+ j+=(depths[h]*tmp); // scale j by width of current depth level
+ h++; // increment h (counts through depth levels)
}
- else j++;
- }
+ else j++; // otherwise, increment j by 1
+ } // leave y loop
- 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
- 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)ymax/64; // sets height of rectangles
- glRectf( xmax+10, y*k, xmax+20, (k+1)*y ); // draws rectangle
+ glColor3f( 1, 1, 1 ); // set color to white
+ glRectf( xmax, 0, xmax+1, ymax+1 ); // draw a border right of plot
+ glRectf( 0, ymax, xmax, ymax+1 ); // draw a border on top of plot
+
+ for( i=0; i<64; i++ ){ // draw color bar
+ glColor3f( jet[i][0], jet[i][1], jet[i][2]); // sets color
+ k=(float)i; // turns i into a float
+ y=(float)ymax/64; // scales rectangles to fit in ymax
+ glRectf( xmax+10, y*k, xmax+20, (k+1)*y ); // draws rectangle
}
- glColor3f( 1, 1, 1 ); // color to white
- if( logscale )
+ glColor3f( 1, 1, 1 ); // color to white
+
+ if( logscale )
sprintf( str, "%.2f", logmx );
else
- sprintf( str, "%.1e", mxval ); // labels color bar with max val
+ sprintf( str, "%.1e", mxval ); // labels color bar with max val
stroke( str, xmax+2, ymax-1 );
if( logscale )
sprintf( str, "%.2f", logmn );
else
- sprintf( str, "%.1e", mnval ); // labels color bar with min val
+ sprintf( str, "%.1e", mnval ); // labels color bar with min val
stroke( str, xmax+2, 1 );
- if( xz )
- sprintf( str, "N-S slice %d", yoffset+1);
+ if( xz ) // in xz view
+ sprintf( str, "N-S slice %d", yoffset+1); // labels NS slice
else{
- if( yz )
- sprintf( str, "E-W slice %d", xoffset+1);
- else
- sprintf( str, "Level %d", ilev ); // labels current level
+ if( yz ) // in yz view
+ sprintf( str, "E-W slice %d", xoffset+1); // labels EW slice
+ else // in xy view
+ sprintf( str, "Level %d", ilev ); // labels current level
}
stroke( str, 1, ymax+5 );
- sprintf( str, "Time %d", count+1 ); // labels current time
+ sprintf( str, "Time %d", count+1 ); // labels current time step
stroke( str, xmax/2, ymax+5 );
- if( glo ) // labels how max/min have been set
- sprintf( str, "Global" ); // if glo is set, display Global
+ if( glo ) // labels how max/min have been set
+ sprintf( str, "Global" ); // if glo is set, display Global
if( usr )
- sprintf( str, "User-set" ); // if usr is set, display User-set
+ sprintf( str, "User-set" ); // if usr is set, display User-set
if( !usr && !glo )
- sprintf( str, "Local" ); // else display Local
+ sprintf( str, "Local" ); // else display Local
stroke( str, xmax+8, ymax+8 );
- if( anim ){ // tell user if autoplay is on
+ if( anim ){ // tell user if autoplay is on
sprintf( str, "Autoplay" );
stroke( str, xmax-35, ymax+8 );
}
if( logscale ){
- sprintf( str, "Log Scale" ); // tell user if log scale is on
+ sprintf( str, "Log Scale" ); // tell user if log scale is on
stroke( str, xmax-25, ymax+15);
}
- stroke( fns[q][count], 1, ymax+15 ); // labels current file
+ stroke( fns[q][count], 1, ymax+15 ); // labels current file
- glutSwapBuffers(); // double buffering set to animate smoothly
+ glutSwapBuffers(); // double buffering set to animate smoothly
glFlush();
}
}
-void stroke( 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;
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- glEnable( GL_BLEND );
- glEnable( GL_LINE_SMOOTH );
- glMatrixMode( GL_MODELVIEW );
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // sets blending mode
+ glEnable( GL_BLEND ); // enables blending
+ glEnable( GL_LINE_SMOOTH ); // enables smooth lines
+ glMatrixMode( GL_MODELVIEW ); // sets matrix mode
- glPushMatrix();
+ glPushMatrix(); // push matrix
- glScalef( SCALE, SCALE, SCALE );
- glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 );
+ glScalef( SCALE, SCALE, SCALE ); // scales stroked text
+ glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 ); // determines location of text
- for( i=0; i<strlen( str ); i++) // display each character of str
+ for( i=0; i<strlen( str ); i++) // stroke each character of str
glutStrokeCharacter( GLUT_STROKE_ROMAN, str[i] );
- glPopMatrix();
+ glPopMatrix(); // pop matrix
}
void key( unsigned char key, int x, int y ){ // called on key press
@@ -222,136 +249,136 @@
char fn[MAX];
switch(key){
- case 'q': exit(0); // quits on 'q'
+ case 'q': exit(0); // close window
break;
- case 'r': count=0; // resets back to first time
+ case 'r': count=0; // reset back to first time
ilev=1; // and first level
- xz=yz=0;
+ xz=yz=0; // and xy view
break;
- case 'a': anim=(anim+1)%2; // turns anim on/off
+ case 'a': anim=(anim+1)%2; // toggle autoplay
break;
- case 'x': xz=(xz+1)%2;
- yz=0;
+ case 'x': xz=(xz+1)%2; // toggle xz/xy view
+ yz=0; // unset yz view, just in case
break;
- case 'y': yz=(yz+1)%2;
- xz=0;
+ case 'y': yz=(yz+1)%2; // toggle yz/xy view
+ xz=0; // uset xz view, just in case
break;
- case 'z': if( xz || yz ){
- scaledepth=( scaledepth+1 )%2;
- scalecount++;
- if( scalecount==1 ){
+ case 'z': if( xz || yz ){ // if xz or yz view is set
+ scaledepth=( scaledepth+1 )%2; // enable depth scaling
+ scalecount++;
+ if( scalecount==1 ){ // read in filename the first time z is pressed
printf( "Please enter filename containing depth data: " );
scanf( "%s", fn );
- readdepths( fn );
+ readdepths( fn ); // read in depth data
}
}
break;
}
- glutPostRedisplay();
+ glutPostRedisplay(); // redisplay with new values
}
-void TimerFunction( int value ){ // called when anim is set and arrow key is pressed
+void TimerFunction( int value ){ // called when autoplay is set and arrow key is pressed
int i;
switch(value){ // increments in the correct direction
- case DOWN : if( xz && yoffset>0 )
- yoffset--;
+ case DOWN : if( xz && yoffset>0 ) // if down arrow key is pressed
+ yoffset--; // in xz view, move south
else{
if( yz && xoffset<NX-1 )
- xoffset++;
+ xoffset++; // in yz view, move east
else
if( ilev<NZ && !xz && !yz )
- ilev++; // if down arrow pressed, move down a level
+ ilev++; // in xy view, move down a depth level
}
break;
- case UP : if( xz && yoffset<NY-1 )
- yoffset++;
+ case UP : if( xz && yoffset<NY-1 ) // if up arrow key is ressed
+ yoffset++; // in xz view, move north
else{
if( yz && xoffset>0 )
- xoffset--;
+ xoffset--; // in yz view, move west
else
if( ilev>1 && !xz && !yz )
- ilev--; // if up arrow is pressed, move up a level
+ ilev--; // in xy view, move up a depth level
}
break;
case LEFT : if( count>0 )
count--; // if left arrow is pressed, move back one time step
break;
case RIGHT: if( count<howmany-1 )
- count++; // if right arrow is pressed, moves forward one time step
+ count++; // if right arrow is pressed, move forward one time step
break;
}
- glutPostRedisplay();
+ glutPostRedisplay(); // redisplay with new values
- if ( anim )
+ if ( anim ) // if autoplay is still set
switch( value ){
- case DOWN : if( xz && yoffset==0 )
- yoffset=NY-1;
+ case DOWN : if( xz && yoffset==0 ) // if furthest south is reached in xz view
+ yoffset=NY-1; // start at the top again
else{
- if( yz && xoffset==NX-1 )
- xoffset=0;
+ if( yz && xoffset==NX-1 ) // if furthest east is reached in yz view
+ xoffset=0; // start in the west again
else
- if( ilev==NZ && !xz && !yz )
- ilev=1; // if end reached, restart
+ if( ilev==NZ && !xz && !yz ) // if bottom level is reached in xy view
+ ilev=1; // start at the surface again
}
- glutTimerFunc( 100, TimerFunction, value ); // recalls itself
+ glutTimerFunc( 100, TimerFunction, value ); // recall timer func
break;
- case UP : if( xz && yoffset==NY-1 )
- yoffset=0;
+ case UP : if( xz && yoffset==NY-1 ) // if furthest north is reached in xz view
+ yoffset=0; // start at the bottom again
else{
- if( yz && xoffset==0 )
- xoffset=NX-1;
+ if( yz && xoffset==0 ) // if furthest west is reached in yz view
+ xoffset=NX-1; // start in the east again
else
- if( ilev==1 )
- ilev=NZ; // if end reached, restart
+ if( ilev==1 && !xz && !yz ) // if top level is reached in xy view
+ ilev=NZ; // start at the bottom again
}
- glutTimerFunc( 100, TimerFunction, value ); // recalls itself
+ glutTimerFunc( 100, TimerFunction, value ); // recall timer func
break;
- case LEFT : if( count==0 ) count=howmany-1; // if end reached, restart
- glutTimerFunc( 100, TimerFunction, value ); // recalls itself
+ case LEFT : if( count==0 ) count=howmany-1; // if first time reached, start at last
+ glutTimerFunc( 100, TimerFunction, value ); // recall timer func
break;
- case RIGHT: if( count==howmany-1 ) count=0; // if end reached, restart
- glutTimerFunc( 100, TimerFunction, value ); // recalls itself
+ case RIGHT: if( count==howmany-1 ) count=0; // if last time reached, start at first
+ glutTimerFunc( 100, TimerFunction, value ); // recall timer func
break;
}
}
-void specialkey( int key, int x, int y ){
+void specialkey( int key, int x, int y ){ // called on arrow key press
int i;
- if( anim ) // if animation is set, call the timer function
- glutTimerFunc( 100, TimerFunction, key); // to scroll automatically
+ if( anim ) // if autoplay is set, call the timer function
+ glutTimerFunc( 100, TimerFunction, key); // to scroll automatically
switch(key){
- case DOWN : if( xz && yoffset>0 )
- yoffset--;
+ case DOWN : if( xz && yoffset>0 ) // if you haven't reached the bottom in xz view
+ yoffset--; // go down one NS slice
else{
- if( yz && xoffset<NY-1 )
- xoffset++;
+ if( yz && xoffset<NY-1 ) // if you haven't reached the edge in yz view
+ xoffset++; // go east one EW slice
else
- if( ilev<NZ && !xz && !yz ) // if you haven't reached the bottom
- ilev++; // keep going down
+ if( ilev<NZ && !xz && !yz ) // if you haven't reached the bottom in xy view
+ ilev++; // go down one level
}
break;
- case UP : if( xz && yoffset<NY-1 )
- yoffset++;
+ case UP : if( xz && yoffset<NY-1 ) // if you haven't reached the top in xz view
+ yoffset++; // go up one NS slice
else{
- if( yz && xoffset>0 )
- xoffset--;
+ if( yz && xoffset>0 ) // if you haven't reached the edge in yz view
+ xoffset--; // go west one EW slice
else
- if( ilev>1 ) // if you haven't reached the top
- ilev--; // keep going up
+ if( ilev>1 && !xz && !yz ) // if you haven't reached the top in xy view
+ ilev--; // go up one level
}
break;
- case RIGHT : if( count<howmany-1 ) // if you haven't reached the last file
- count++; // keep going right
+ case RIGHT : if( count<howmany-1 ) // if you haven't reached the last time step
+ count++; // go forward one time step
break;
- case LEFT : if( count>0 ) // if you haven't reached the first file
- count--; // keep going left
+ case LEFT : if( count>0 ) // if you haven't reached the first time step
+ count--; // go back one time step
break;
}
- glutPostRedisplay();
+ glutPostRedisplay(); // redisplay with new values
}
void global(){ // calculates the max/min for the total data set
@@ -359,7 +386,7 @@
int h, i, j;
for( h=0; h<sets; h++) // cycles through each window
for( i=0; i<howmany; i++ ) // cycles through each time
- for( j=0; j<NZ; j++ ){ // cycles through each level for each file
+ for( j=0; j<NZ; j++ ){ // cycles through each depth level
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
@@ -369,21 +396,21 @@
void local( int i, int time, int lev ){ // calculates local max/min
int j;
- mxval=0;
+ mxval=0;
mnval=100;
if( xz )
- readxz( data[i], fns[i][time]);
+ readxz( data[i], fns[i][time]); // if xz view, reads new array of xz vals
else{
if( yz )
- readyz( data[i], fns[i][time]);
+ readyz( data[i], fns[i][time]); // if yz view, reads new array of yz vals
else
- readarray( data[i], fns[i][time], lev ); // read new array of data
+ readxy( data[i], fns[i][time], lev ); // if xy view, reads new array of xy vals
}
- for( j=0; j<xmax*ymax; j++ ){
+ for( j=0; j<xmax*ymax; j++ ){ // cycles through all values in the array
if( data[i][j] > mxval )
mxval=data[i][j]; // set largest val to mxval
if( data[i][j] < mnval && data[i][j]!=0 )
- mnval=data[i][j]; // set smallest positive val to mnval
+ mnval=data[i][j]; // set smallest nonzero val to mnval
}
}
@@ -397,9 +424,9 @@
i++; // counts how many filenames there are
}
fclose( fp ); // close file
- sets=i-1; // saves number of initial filenames
+ sets=i-1; // saves number of initial filenames
- for(i=0; i<sets; i++){ // goes through each read-in filename
+ for(i=0; i<sets; i++){ // goes through each filename just read in
fp=fopen( initfns[i], "r" ); // opens each filename
j=0;
while( !feof(fp) ){ // reads in filenames from each filename
@@ -408,88 +435,99 @@
}
fclose(fp); // close file
}
- howmany=j-1; // saves number of data filenames
+ howmany=j-1; // saves number of time steps
}
-void readdepths( char filename[] ){
+void readdepths( char filename[] ){ // called when the scale depth feature is enabled
int i;
FILE* fp;
- fp=fopen( filename, "r" );
+ fp=fopen( filename, "r" ); // open depth data file
- for( i=NZ-1; i>=0; i-- ){
+ for( i=NZ-1; i>=0; i-- ){ // read in data backwards, starting at the lowest depth
fscanf( fp, "%d ", &depths[i] );
- totaldepth+=depths[i];
+ totaldepth+=depths[i]; // calculate total depth
}
- fclose( fp );
+ fclose( fp ); // close file
}
-void readjet(){ //reads in color scale values
+void readjet(){ // read in color scale values
FILE* fp;
int i, j;
- fp=fopen( "jet.dat", "r" ); // opens file containing values
- for( i=0; i<64; i++ ) // reads in 64 sets of r, g, b values
+ fp=fopen( "jet.dat", "r" ); // open file containing values
+ for( i=0; i<64; i++ ) // read in 64 sets of rgb values
for( j=0; j<3; j++ )
fscanf( fp, "%f", &jet[i][j] );
- fclose( fp ); // closes file
+ fclose( fp ); // close file
}
-void readxz( float arr[], char filename[] ){
+void readxz( float arr[], char filename[] ){ // reads in xz values
int i, j;
- float tmp[MAX][MAX], tmp2[MAX*MAX];
+ float tmp[MAX][MAX];
FILE* fp;
- fp=fopen( filename, "rb" );
- for( i=0; i<NZ; i++){
- 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
+ fp=fopen( filename, "rb" ); // open data file
+ for( i=0; i<NZ; i++ ){ // run through each depth level
+ fseek( fp, (NX*yoffset*4)+(i*NX*NY*4), SEEK_SET ); // seek to correct place in the file
+ fread( &arr[NX*i], sizeof( arr[0] ), NX, fp ); // reads in one row of x-values
}
- fclose( fp );
+ fclose( fp ); // close file
- 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++ ) // the array should start at the ocean floor and move upwards
+ for( j=0; j<NX; j++) // so it has been read in backwards
+ tmp[i][j]=arr[i*NX+j]; // put each row of x-values into a 2d array
- for( i=0; i<NZ; i++ )
+ for( i=0; i<NZ; i++ )
for( j=0; j<NX; j++)
- tmp2[i*NX+j]=tmp[NZ-i-1][j];
+ arr[i*NX+j]=tmp[NZ-i-1][j]; // flip the order of the rows, and store in the data array
- for( i=0; i<NX*NZ; i++)
- arr[i]=tmp2[i];
+ if( nonegs )
+ for( i=0; i<NX*NZ; i++ )
+ if( arr[i] < 0 )
+ arr[i] = pow(10, -20); // sets negative values to 10^-20
+
+ if( endian )
+ do_byteswap_f32( arr, NX*NZ ); // switches endian
}
-void readyz( float arr[], char filename[] ){
+void readyz( float arr[], char filename[] ){ // reads in yz values
int i, j;
- float tmp[MAX][MAX], tmp2[MAX*MAX];
+ float tmp[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 );
+ fp=fopen( filename, "rb" ); // open data file
+ for( i=0; i<NY*NZ; i++ ){ // run through each line in the file
+ fseek( fp, (xoffset*4)+(i*NX*4), SEEK_SET ); // seek to the correct place in the file
+ fread( &arr[i], sizeof( arr[0] ), 1, fp ); // reads in one y-value at the correct x
}
- fclose(fp);
+ fclose(fp); // close file
- 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++ ) // the array should start at the ocean floor and move upwards
+ for( j=0; j<NY; j++) // so it has been read in backwards
+ tmp[i][j]=arr[i*NY+j]; // put each row of x-values into a 2d array
for( i=0; i<NZ; i++ )
for( j=0; j<NY; j++)
- tmp2[i*NY+j]=tmp[NZ-i-1][j];
+ arr[i*NY+j]=tmp[NZ-i-1][j]; // flip the order of the rows, and store in the data array
+
+ if( nonegs )
+ for( i=0; i<NY*NZ; i++ )
+ if( arr[i] < 0 )
+ arr[i] = pow(10, -20); // sets negative values to 10^-20
+
+ if( endian )
+ do_byteswap_f32( arr, NY*NZ ); // switches endian
- for( i=0; i<NY*NZ; i++)
- arr[i]=tmp2[i];
}
-void readarray( float arr[], char filename[], int il ){ // reads new data
+void readxy( float arr[], char filename[], int il ){ // reads in xy values
FILE* fp;
int i;
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
+ fseek( fp, (il-1)*NX*NY*4, SEEK_SET ); // seeks to the correct place
fread( arr, sizeof( arr[0] ), NX*NY, fp ); // reads in data to fill one level
fclose( fp ); // close file
@@ -517,7 +555,7 @@
}
}
-void black( ){
+void black( ){ // display func for extra windows
glClear( GL_COLOR_BUFFER_BIT );
glutSwapBuffers();
glFlush();
@@ -529,40 +567,40 @@
char str[MAX], filename[MAX];
FILE* fp;
- if( strcmp(argv[1], "binary") == 0 )
+ if( strcmp(argv[1], "binary") == 0 ) // if data files are binary open binconfig
fp=fopen( ".darwinview/binconfig", "r" );
else
- if( strcmp(argv[1],"netcdf") == 0 )
+ if( strcmp(argv[1],"netcdf") == 0 ) // if data files are netcdf open ncconfig
fp=fopen( ".darwinview/ncconfig", "r" );
- fscanf( fp, "%dx%d ", &winx, &winy );
- winy-=60; winx-=20; // adjusts resolution so edges won't get cut off
- fscanf( fp, "%d %d %d ", &NX, &NY, &NZ );
- fscanf( fp, "%dx%d ", &setsx, &setsy ); // prompts user for dimensions of subwindows
- fscanf( fp, "%s", filename );
-
- 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
+ fscanf( fp, "%dx%d ", &winx, &winy ); // read in screen resolution
+ winy-=60; winx-=20; // adjust resolution so edges won't get cut off
+ fscanf( fp, "%d %d %d ", &NX, &NY, &NZ ); // read in dimensions of data
+ fscanf( fp, "%dx%d ", &setsx, &setsy ); // read in dimensions of subwindows
+ fscanf( fp, "%s", filename ); // read in name of file containing data filenames
+
+ fclose( fp ); // close file
+
+ xmax=NX; ymax=NY; // default to xy
+
+ readjet(); // stores color values
+ readnames( filename ); // gets list of filenames to read from
+ global(); // calculates max and min for all data
glutInit( &argc, argv );
- glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); // sets rgb mode and double buffering
+ glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); // set rgb mode and double buffering
glutInitWindowSize( winx, winy ); // parent window will cover screen
- glutInitWindowPosition( 10, 10 ); // location of parent window
- parent=glutCreateWindow( WINDOW ); // creates parent window
+ glutInitWindowPosition( 10, 10 ); // set location of parent window
+ parent=glutCreateWindow( WINDOW ); // create parent window
- glClearColor( 0, 0, 0, 0 ); // sets clear color to black
- gluOrtho2D( 0, winx , winy, 0 ); // sets(0,0) as top left corner
- glutDisplayFunc( display );
+ glClearColor( 0, 0, 0, 0 ); // set clear color to black
+ gluOrtho2D( 0, winx , winy, 0 ); // set (0,0) as top left corner
+ glutDisplayFunc( display ); // declares display func
glutKeyboardFunc( key ); // called on key press
glutSpecialFunc( specialkey ); // called on special key press (arrow keys)
- for( i=0; i<setsx*setsy; i++ ){
+ for( i=0; i<setsx*setsy; i++ ){ // for each subwindow
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
@@ -570,10 +608,10 @@
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 ) //
- glutDisplayFunc( black );
- else
- glutDisplayFunc( display ); // sets display func for subwindow
+ if( i >= sets ) // if there are more subwindows than data sets
+ glutDisplayFunc( black ); // color those windows black
+ else // otherwise
+ glutDisplayFunc( display ); // sets display func for subwindow
glutCreateMenu( menu ); // adds a menu
| ViewVC Help | |
| Powered by ViewVC 1.1.22 |