1 |
#include <GL/glut.h> |
#!/bin/bash |
|
#include <stdlib.h> |
|
|
#include <stdio.h> |
|
|
#include <string.h> |
|
|
#include <math.h> |
|
|
#define WINDOW "image" |
|
|
#define UP 101 |
|
|
#define DOWN 103 |
|
|
#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[] ), 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, 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 |
|
|
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 |
|
|
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 |
|
|
break; |
|
|
case 4: logscale=( logscale+1 )%2; // switch log scale on/off |
|
|
break; |
|
|
case 5: nonegs=( nonegs+1 )%2; // switch allowance of negatives on/off |
|
|
break; |
|
|
case 6: endian=( endian+1 )%2; // switch between big/little endian |
|
|
break; |
|
|
} |
|
|
glutPostRedisplay(); |
|
|
} |
|
|
|
|
|
void display(){ // called on glutPostRedisplay |
|
|
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; } |
|
|
else { xmax=NX; ymax=NY; } |
|
|
} |
|
|
|
|
|
if( glo || usr ){ // if global or user-set max/min |
|
|
if( xz ) |
|
|
readxz( data[q], fns[q][count] ); |
|
|
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 |
|
|
|
|
|
if( logscale ){ |
|
|
if( usr ){ |
|
|
logmx=(double)mxval; |
|
|
logmn=(double)mnval; |
|
|
} |
|
|
else{ |
|
|
logmx=log10( mxval ); |
|
|
logmn=log10( mnval ); |
|
|
} |
|
|
} |
|
|
|
|
|
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 |
|
|
if( data[q][ioff]==0 ); // if data=0, values stay black |
|
|
else{ |
|
|
if( logscale ){ |
|
|
num=(double)data[q][ioff]; |
|
|
num=log10( num ); |
|
|
if( num<logmn ) num=0; |
|
|
else{ |
|
|
if( num>logmx ) num=63; |
|
|
else |
|
|
num=63*( num-logmn )/( logmx-logmn ); |
|
|
} |
|
|
} |
|
|
else{ |
|
|
if( data[q][ioff]<mnval ) num=0; // if data is less than min, =min |
|
|
else{ |
|
|
if( data[q][ioff]>mxval ) num=63; // if data is more than max, =max |
|
|
else |
|
|
num=63*( data[q][ioff]-mnval )/( mxval-mnval ); // scale num from 0-63 (not defined for 64) |
|
|
} |
|
|
} |
|
|
r=jet[(int)num][0]; // set red val |
|
|
g=jet[(int)num][1]; // set green val |
|
|
b=jet[(int)num][2]; // set blue val |
|
|
} |
|
|
|
|
|
glColor3f( r, g, b ); // put r, g, b into effect |
|
|
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 |
|
|
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 ); // color to white |
|
|
|
|
|
if( logscale ) |
|
|
sprintf( str, "%.2f", logmx ); |
|
|
else |
|
|
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 |
|
|
stroke( str, xmax+2, 1 ); |
|
|
|
|
|
if( xz ) |
|
|
sprintf( str, "N-S slice %d", yoffset+1); |
|
|
else{ |
|
|
if( yz ) |
|
|
sprintf( str, "E-W slice %d", xoffset+1); |
|
|
else |
|
|
sprintf( str, "Level %d", ilev ); // labels current level |
|
|
} |
|
|
stroke( str, 1, ymax+5 ); |
|
|
|
|
|
sprintf( str, "Time %d", count+1 ); // labels current time |
|
|
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( usr ) |
|
|
sprintf( str, "User-set" ); // if usr is set, display User-set |
|
|
if( !usr && !glo ) |
|
|
sprintf( str, "Local" ); // else display Local |
|
|
stroke( str, xmax+8, ymax+8 ); |
|
|
|
|
|
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 |
|
|
stroke( str, xmax-25, ymax+15); |
|
|
} |
|
|
|
|
|
stroke( fns[q][count], 1, ymax+15 ); // labels current file |
|
|
|
|
|
glutSwapBuffers(); // double buffering set to animate smoothly |
|
|
glFlush(); |
|
|
} |
|
|
} |
|
|
|
|
|
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 ); |
|
2 |
|
|
3 |
glPushMatrix(); |
mkdir -p .darwinview |
4 |
|
|
5 |
glScalef( SCALE, SCALE, SCALE ); |
echo -n "What format is the data in? (binary/netcdf): " |
6 |
glTranslatef( (1/SCALE)*x, (1/SCALE)*y, 0 ); |
read nb |
7 |
|
|
8 |
for( i=0; i<strlen( str ); i++) // display each character of str |
if [ $nb = 'binary' ]; then |
|
glutStrokeCharacter( GLUT_STROKE_ROMAN, str[i] ); |
|
9 |
|
|
10 |
glPopMatrix(); |
echo -n "Would you like to use default settings? (y/n): " |
11 |
} |
read yn |
|
|
|
|
void key( unsigned char key, int x, int y ){ // called on key press |
|
|
int i, tmp; |
|
|
|
|
|
switch(key){ |
|
|
case 'q': exit(0); // quits on 'q' |
|
|
break; |
|
|
case 'r': count=0; // resets back to first time |
|
|
ilev=1; // and first level |
|
|
break; |
|
|
case 'a': anim=(anim+1)%2; // turns anim on/off |
|
|
break; |
|
|
case 'x': xz=(xz+1)%2; |
|
|
yz=0; |
|
|
break; |
|
|
case 'y': yz=(yz+1)%2; |
|
|
xz=0; |
|
|
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 |
|
|
int i; |
|
|
|
|
|
switch(value){ // increments in the correct direction |
|
|
case DOWN : if( xz && yoffset>0 ) |
|
|
yoffset--; |
|
|
else{ |
|
|
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 && yoffset<NY-1 ) |
|
|
yoffset++; |
|
|
else{ |
|
|
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 ) |
|
|
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 |
|
|
break; |
|
|
} |
|
|
|
|
|
glutPostRedisplay(); |
|
|
|
|
|
if ( anim ) |
|
|
switch( value ){ |
|
|
case DOWN : if( xz && yoffset==0 ) |
|
|
yoffset=NY-1; |
|
|
else{ |
|
|
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 && yoffset==NY-1 ) |
|
|
yoffset=0; |
|
|
else{ |
|
|
if( yz && xoffset==0 ) |
|
|
xoffset=NX-1; |
|
|
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 |
|
|
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
|
|
break; |
|
|
case RIGHT: if( count==howmany-1 ) count=0; // if end reached, restart |
|
|
glutTimerFunc( 100, TimerFunction, value ); // recalls itself |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
void specialkey( int key, int x, int y ){ |
|
|
int i; |
|
|
|
|
|
if( anim ) // if animation is set, call the timer function |
|
|
glutTimerFunc( 100, TimerFunction, key); // to scroll automatically |
|
|
|
|
|
switch(key){ |
|
|
case DOWN : if( xz && yoffset>0 ) |
|
|
yoffset--; |
|
|
else{ |
|
|
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 && yoffset<NY-1 ) |
|
|
yoffset++; |
|
|
else{ |
|
|
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 |
|
|
count++; // keep going right |
|
|
break; |
|
|
case LEFT : if( count>0 ) // if you haven't reached the first file |
|
|
count--; // keep going left |
|
|
break; |
|
|
} |
|
|
glutPostRedisplay(); |
|
|
} |
|
|
|
|
|
void global(){ // calculates the max/min for the total data set |
|
|
FILE* fp; |
|
|
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 |
|
|
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 |
|
|
} |
|
|
} |
|
|
|
|
|
void local( int i, int time, int lev ){ // calculates local max/min |
|
|
int j; |
|
|
|
|
|
mxval=0; |
|
|
mnval=100; |
|
|
if( xz ) |
|
|
readxz( data[i], fns[i][time]); |
|
|
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 |
|
|
if( data[i][j] < mnval && data[i][j]!=0 ) |
|
|
mnval=data[i][j]; // set smallest positive val to mnval |
|
|
} |
|
|
} |
|
|
|
|
|
void readnames( char filename[] ){ // reads in list of filenames |
|
|
FILE* fp; |
|
|
int i=0, j=0; |
|
|
|
|
|
fp=fopen( filename, "r" ); // opens list of filenames |
|
|
while( !feof(fp) ){ // reads until the end of the file |
|
|
fscanf( fp, "%s", initfns[i] ); // places filename into an array of strings |
|
|
i++; // counts how many filenames there are |
|
|
} |
|
|
fclose( fp ); // close file |
|
|
sets=i-1; // saves number of initial filenames |
|
|
|
|
|
for(i=0; i<sets; i++){ // goes through each read-in filename |
|
|
fp=fopen( initfns[i], "r" ); // opens each filename |
|
|
j=0; |
|
|
while( !feof(fp) ){ // reads in filenames from each filename |
|
|
fscanf( fp, "%s", fns[i][j]); |
|
|
j++; |
|
|
} |
|
|
fclose(fp); // close file |
|
|
} |
|
|
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; |
|
12 |
|
|
13 |
fp=fopen( ".darwinview/jet.h", "r" ); // opens file containing values |
if [ $yn = 'n' ]; then |
|
for( i=0; i<64; i++ ) // reads in 64 sets of r, g, b values |
|
|
for( j=0; j<3; j++ ) |
|
|
fscanf( fp, "%f", &jet[i][j] ); |
|
|
fclose( fp ); // closes file |
|
|
} |
|
|
|
|
|
void readxz( float arr[], char filename[] ){ |
|
|
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*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=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 |
|
|
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 |
|
|
|
|
|
if( nonegs ) |
|
|
for( i=0; i<NX*NY; i++ ) |
|
|
if( arr[i] < 0 ) |
|
|
arr[i] = pow(10, -20); // sets negative values to 10^-20 |
|
|
|
|
|
if( endian ) |
|
|
do_byteswap_f32( arr, NX*NY ); // switches endian |
|
|
} |
|
|
|
|
|
void do_byteswap_f32( float arr[], int nel ){ // switches endian |
|
|
|
|
|
int i; |
|
|
char src[4], trg[4]; |
|
|
|
|
|
for( i=0; i<nel; i++ ){ |
|
|
memcpy( src, &(arr[i]), 4 ); |
|
|
trg[0]=src[3]; |
|
|
trg[1]=src[2]; |
|
|
trg[2]=src[1]; |
|
|
trg[3]=src[0]; |
|
|
memcpy( &(arr[i]), trg, 4 ); |
|
|
} |
|
|
} |
|
|
|
|
|
void black( ){ |
|
|
glClear( GL_COLOR_BUFFER_BIT ); |
|
|
glutSwapBuffers(); |
|
|
glFlush(); |
|
|
} |
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] ){ |
|
|
int i, setsx, setsy, tmpx, tmpy, winx, winy, parent; |
|
|
char str[MAX], filename[MAX]; |
|
|
FILE* fp; |
|
|
|
|
|
if( strcmp(argv[1], "binary") == 0 ) |
|
|
fp=fopen( ".darwinview/binconfig", "r" ); |
|
|
else |
|
|
if( strcmp(argv[1],"netcdf") == 0 ) |
|
|
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 ); |
|
14 |
|
|
15 |
fclose( fp ); |
rm -f .darwinview/binfilenames |
16 |
|
rm -f .darwinview/*.datbin |
17 |
|
|
18 |
xmax=NX; ymax=NY; |
xrandr | grep '*' | awk -F' ' '{print $1}' > .darwinview/binconfig |
19 |
|
echo -n "Please enter dimensions of data: " |
20 |
readjet(); // stores color values |
read dim |
21 |
readnames( filename ); // gets list of filenames to read from |
echo $dim >> .darwinview/binconfig |
22 |
global(); // calculates max and min for all data |
echo -n "Please enter dimensions of data sets: " |
23 |
|
read dimset |
24 |
glutInit( &argc, argv ); |
echo $dimset >> .darwinview/binconfig |
25 |
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); // sets rgb mode and double buffering |
echo .darwinview/binfilenames >> .darwinview/binconfig |
|
glutInitWindowSize( winx, winy ); // parent window will cover screen |
|
|
glutInitWindowPosition( 10, 10 ); // location of parent window |
|
|
parent=glutCreateWindow( WINDOW ); // creates 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 ); |
|
|
glutKeyboardFunc( key ); // called on key press |
|
|
glutSpecialFunc( specialkey ); // called on special key press (arrow keys) |
|
|
|
|
26 |
|
|
27 |
for( i=0; i<setsx*setsy; i++ ){ |
echo -n "Please enter directory containing data: " |
28 |
tmpx = (i%setsx)*(winx/setsx); // x coordinate of top left corner of subwindow |
read dir |
|
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+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 |
|
29 |
|
|
30 |
|
echo -n "Please enter name of file containing desired species: " |
31 |
|
read fn |
32 |
|
|
33 |
|
vn=( `cat $fn` ) |
34 |
|
|
35 |
glutCreateMenu( menu ); // adds a menu |
for name in ${vn[@]}; do |
36 |
glutAddMenuEntry( "Local Color Scale", 1 ); // adds a menu entry |
touch .darwinview/$name.datbin |
37 |
glutAddMenuEntry( "Global Color Scale", 2 ); // adds a menu entry |
echo .darwinview/$name.datbin >> .darwinview/binfilenames |
38 |
glutAddMenuEntry( "User-Set Color Scale", 3 ); // adds a menu entry |
for i in `ls $dir`; do |
39 |
glutAddMenuEntry( "Log Scale (on/off)", 4 ); // adds a menu entry |
echo $dir/$i/`ls $dir/$i | grep $name` >> .darwinview/$name.datbin |
40 |
glutAddMenuEntry( "Allow Negatives (on/off)", 5 ); // adds a menu entry |
done |
41 |
glutAddMenuEntry( "Switch Endian (big/little) ", 6); // adds a menu entry |
done |
42 |
glutAttachMenu( GLUT_RIGHT_BUTTON ); // menu called on right click |
|
43 |
} |
elif [ `echo $yn | grep -v y` ]; then |
44 |
|
echo "Error: please enter 'y' or 'n.'" |
45 |
glutMainLoop(); // begin processing events |
exit |
46 |
return 0; |
fi |
47 |
} |
|
48 |
|
elif [ $nb = 'netcdf' ]; then |
49 |
|
|
50 |
|
echo -n "Would you like to use default settings? (y/n): " |
51 |
|
read yn |
52 |
|
|
53 |
|
if [ $yn = 'n' ]; then |
54 |
|
|
55 |
|
rm -f .darwinview/ncfilenames |
56 |
|
rm -f .darwinview/*.datnc |
57 |
|
|
58 |
|
xrandr | grep '*' | awk -F' ' '{print $1}' > .darwinview/ncconfig |
59 |
|
echo -n "Please enter dimensions of data: " |
60 |
|
read dim |
61 |
|
echo $dim >> .darwinview/ncconfig |
62 |
|
echo -n "Please enter dimensions of data sets: " |
63 |
|
read dimset |
64 |
|
echo $dimset >> .darwinview/ncconfig |
65 |
|
echo .darwinview/ncfilenames >> .darwinview/ncconfig |
66 |
|
|
67 |
|
echo -n "Please enter directory containing data: " |
68 |
|
read tmp |
69 |
|
echo $tmp > .darwinview/netcdf |
70 |
|
|
71 |
|
|
72 |
|
echo -n "Please enter directory to write to: " |
73 |
|
read tmp |
74 |
|
echo $tmp >> .darwinview/netcdf |
75 |
|
|
76 |
|
echo -n "Please enter name of file containing desired species: " |
77 |
|
read tmp |
78 |
|
echo $tmp >> .darwinview/netcdf |
79 |
|
|
80 |
|
echo -n "Please enter name of file containing desired tiles: " |
81 |
|
read tmp |
82 |
|
echo $tmp >> .darwinview/netcdf |
83 |
|
|
84 |
|
echo -n "Please enter name of file containing desired time steps: " |
85 |
|
read tmp |
86 |
|
echo $tmp >> .darwinview/netcdf |
87 |
|
|
88 |
|
elif [ `echo $yn | grep -v y` ]; then |
89 |
|
echo "Error: please enter 'y' or 'n.'" |
90 |
|
exit |
91 |
|
fi |
92 |
|
|
93 |
|
indir=( `cat .darwinview/netcdf | head -1` ) |
94 |
|
outdir=( `cat .darwinview/netcdf | head -2 | tail -1` ) |
95 |
|
fn=( `cat .darwinview/netcdf | head -3 | tail -1` ) |
96 |
|
vn=( `cat $fn` ) |
97 |
|
fn=( `cat .darwinview/netcdf | head -4 | tail -1` ) |
98 |
|
tlist=( `cat $fn` ) |
99 |
|
fn=( `cat .darwinview/netcdf | tail -1` ) |
100 |
|
itlist=( `cat $fn` ) |
101 |
|
|
102 |
|
initdir=`pwd` |
103 |
|
gcc netcdf.c -I/usr/include/netcdf-3 -L/usr/lib/netcdf-3 -lnetcdf |
104 |
|
for tstep in ${itlist[@]}; do |
105 |
|
cd $initdir |
106 |
|
cd $outdir |
107 |
|
mkdir -p $tstep |
108 |
|
cd $tstep |
109 |
|
for name in ${vn[@]}; do |
110 |
|
for tile in ${tlist[@]}; do |
111 |
|
$initdir/a.out ~/${indir}/ptr_tave.${tstep}.${tile}.nc $name |
112 |
|
done |
113 |
|
done |
114 |
|
done |
115 |
|
|
116 |
|
cd $initdir |
117 |
|
|
118 |
|
for name in ${vn[@]}; do |
119 |
|
echo $name |
120 |
|
touch .darwinview/$name.datnc |
121 |
|
echo .darwinview/$name.datnc >> .darwinview/ncfilenames |
122 |
|
for i in `ls $outdir`; do |
123 |
|
echo $outdir/$i/`ls $outdir/$i | grep $name` >> .darwinview/$name.datnc |
124 |
|
done |
125 |
|
done |
126 |
|
|
127 |
|
else |
128 |
|
echo "Error: please enter 'binary' or 'netcdf.'" |
129 |
|
exit |
130 |
|
fi |
131 |
|
|
132 |
|
if [ ! `ls | grep jet.dat` ]; then |
133 |
|
echo "Error: jet.dat not found." |
134 |
|
exit |
135 |
|
fi |
136 |
|
|
137 |
|
gcc darwin.c -lglut |
138 |
|
./a.out $nb |