#!/bin/tcsh -f # +-======-+ # Copyright (c) 2003-2007 United States Government as represented by # the Admistrator of the National Aeronautics and Space Administration. # All Rights Reserved. # # THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE, # REPRODUCTION, DISTRIBUTION, MODIFICATION AND REDISTRIBUTION OF CERTAIN # COMPUTER SOFTWARE ORIGINALLY RELEASED BY THE UNITED STATES GOVERNMENT AS # REPRESENTED BY THE GOVERNMENT AGENCY LISTED BELOW ("GOVERNMENT AGENCY"). # THE UNITED STATES GOVERNMENT, AS REPRESENTED BY GOVERNMENT AGENCY, IS AN # INTENDED THIRD-PARTY BENEFICIARY OF ALL SUBSEQUENT DISTRIBUTIONS OR # REDISTRIBUTIONS OF THE SUBJECT SOFTWARE. ANYONE WHO USES, REPRODUCES, # DISTRIBUTES, MODIFIES OR REDISTRIBUTES THE SUBJECT SOFTWARE, AS DEFINED # HEREIN, OR ANY PART THEREOF, IS, BY THAT ACTION, ACCEPTING IN FULL THE # RESPONSIBILITIES AND OBLIGATIONS CONTAINED IN THIS AGREEMENT. # # Government Agency: National Aeronautics and Space Administration # Government Agency Original Software Designation: GSC-15354-1 # Government Agency Original Software Title: GEOS-5 GCM Modeling Software # User Registration Requested. Please Visit http://opensource.gsfc.nasa.gov # Government Agency Point of Contact for Original Software: # Dale Hithon, SRA Assistant, (301) 286-2691 # # +-======-+ alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`' if ( ! $?GEOSUTIL ) then echo " " echo Environment variable GEOSUTIL must be defined before use! echo Set GEOSUTIL to the directory path of the GEOS_util module echo " " exit 1 endif @ nmax = $#argv # ------------------- if( $nmax == 0 ) then Usage: echo " " echo "Usage:" echo "-----" echo "quickstat -rc STATS_RC" echo " [-exps EXPS]" echo " [-level LEVEL]" echo " [-fields FIELDS]" echo " [-plots PLOTS]" echo " [-output OUTPUT]" echo " [-gradsx GRADSX]" echo " [-batch ]" echo " [-partition PARTITION]" echo " [-qos QOS]" echo " " echo "where: STATS_RC: is the full path (including filename) of the stats resource file to use " echo " EXPS: Experiment IDs to plot (e.g., 0 1 3 4 ) (Default: ALL experiments in STATS_RC) " echo " LEVEL: Pressure Level to plot (e.g., 850 ) (Default: ALL Levels) " echo " FIELDS: Fields to plot (e.g., p u v ) (Default: p u v t q h) " echo " PLOTS: Plot Types (corcmp, sys, syscmp) (Default: ALL) " echo " OUTPUT: Output directory to contain plots (Default: STATS_RC directory) " echo " GRADSX: GrADS executable to use for processing (Default: grads) " echo " " echo "Note: Plots will be located in experiment sub-directories under OUTPUT " echo " Usage of -batch option will send plots to BATCH " echo " " exit 1 endif # Set Variables # ------------- set QUEUE = partition set PARTITION = compute set batch = NULL set statsrc = NULL set output = NULL set gradsx = grads set exps = ALL set level = ALL set plots = `echo corcmp pltsys syscmp` set fields = `echo p u v t q h` set lcd = `pwd` # Parse command line # ------------------ @ n = 1 while( $n <= $nmax ) if( "$argv[$n]" == "-rc" ) then @ n = $n + 1 set statsrc = $argv[$n] endif if( "$argv[$n]" =~ \-lev* ) then @ n = $n + 1 set level = $argv[$n] endif if( "$argv[$n]" =~ \-b* ) then set batch = 'BATCH' endif if( "$argv[$n]" == "-partition" ) then @ n = $n + 1 set PARTITION = $argv[$n] endif if( "$argv[$n]" == "-qos" ) then @ n = $n + 1 set PARTITION = $argv[$n] set QUEUE = 'qos' endif if( "$argv[$n]" == "-gradsx" ) then @ n = $n + 1 set gradsx = $argv[$n] endif if( "$argv[$n]" == "-output" ) then @ n = $n + 1 set output = $argv[$n] endif if( "$argv[$n]" =~ \-exp* ) then @ n = $n + 1 set exps = "" set next = $argv[$n] set bit = `echo $next | cut -c1-1` while( "$bit" != "-" ) set exps = `echo $exps $next` @ n = $n + 1 if( $n <= $nmax ) then set next = $argv[$n] set bit = `echo $next | cut -c1-1` else set bit = "-" endif end @ n = $n - 1 endif if( "$argv[$n]" =~ \-plot* ) then @ n = $n + 1 set plots = "" set next = $argv[$n] if( "$next" == "sys" ) set next = pltsys set bit = `echo $next | cut -c1-1` while( "$bit" != "-" ) set plots = `echo $plots $next` @ n = $n + 1 if( $n <= $nmax ) then set next = $argv[$n] if( "$next" == "sys" ) set next = pltsys set bit = `echo $next | cut -c1-1` else set bit = "-" endif end @ n = $n - 1 endif if( "$argv[$n]" =~ \-field* ) then @ n = $n + 1 set fields = "" set next = $argv[$n] set bit = `echo $next | cut -c1-1` while( "$bit" != "-" ) set fields = `echo $fields $next` @ n = $n + 1 if( $n <= $nmax ) then set next = $argv[$n] set bit = `echo $next | cut -c1-1` else set bit = "-" endif end @ n = $n - 1 endif @ n = $n + 1 end if( $statsrc == NULL | -d $statsrc ) then echo ' ' echo '\!\! You must enter the full path (including filename) of the stats.rc to use \!\!' goto Usage exit endif set rcfile = `basename $statsrc` setenv GRADSX $gradsx # Determine ROOT directory containing stats.rc # -------------------------------------------- @ n = 1 set root = `echo $statsrc | cut -d / -f$n` while( .$root == . ) @ n = $n + 1 set root = `echo $statsrc | cut -d / -f$n` end set ROOTDIR = '' while( $root != $rcfile ) set ROOTDIR = `echo ${ROOTDIR}/${root}` @ n = $n + 1 set root = `echo $statsrc | cut -d / -f$n` end # Set SOURCE directory containing Plots # ------------------------------------- if( $output == NULL ) then setenv SOURCE $ROOTDIR else if(! -e $output ) mkdir -p $output setenv SOURCE $output if(-e $output/$rcfile ) /bin/rm -f $output/$rcfile /bin/ln -sf $statsrc $output endif # Determine Experiments to plot # ----------------------------- if( $exps[1] == ALL ) then set allexps = `grep "EXP.*:" $statsrc | grep -v \#` @ numexps = $#allexps / 2 set exps = '' @ n = 1 while ($n <= $numexps ) @ loc = $n * 2 - 1 set len1 = `echo $allexps[$loc] | awk '{print length($0)}'` @ len2 = $len1 - 1 set exp = `echo $allexps[$loc] | cut -c4-$len2` set exps = `echo $exps $exp` @ n = $n + 1 end endif # Configure QUICKSTAT to Computing Platform # ----------------------------------------- cd $SOURCE if( -e LOCKFILE ) /bin/echo "Waiting for LOCKFILE ... " if( -e LOCKFILE ) set LOCK = `stat -c %Z LOCKFILE` while( -e LOCKFILE ) set EPOCH = `date +'%s'` @ LOCKAGE = $EPOCH - $LOCK if( $LOCKAGE > 120 ) /bin/rm -f LOCKFILE end lockfile LOCKFILE $GEOSUTIL/plots/configure source $SOURCE/.quickplotrc /bin/rm -f LOCKFILE echo " " echo " ARCH = " `uname` echo " HOST = " `hostname` echo " GRADS = " $GRADS echo " GEOSUTIL = " $GEOSUTIL echo " OUTPUT = " $SOURCE echo " STATS_RC = " $statsrc echo " EXPS = " $exps echo " LEVEL = " $level echo " FIELDS = " $fields echo " PLOTS = " $plots echo " " if( $level == ALL ) set level = NULL # Check for BATCH Job # ------------------- if( $batch == 'BATCH' ) then # Set Default GEOS Build Directories # ---------------------------------- set command = `which $0` set root = `echo $command | cut -d / -f1` if( $root == . ) set command = `echo $lcd`/quickstat set root = `echo $command | cut -b1` if( "$root" != "/" ) set command = `echo $lcd`/$command @ n = 1 set root = `echo $command | cut -d / -f$n` while( .$root == . ) @ n = $n + 1 set root = `echo $command | cut -d / -f$n` end set GEOSDEF = '' while( $root != 'src' ) set GEOSDEF = `echo ${GEOSDEF}/${root}` @ n = $n + 1 set root = `echo $command | cut -d / -f$n` end set GEOSSRC = ${GEOSDEF}/src set GEOSBIN = ${GEOSDEF}/Linux/bin set GEOSAPP = ${GEOSDEF}/src/Applications/GEOSgcm_App # Create QUICKSTAT commands # ------------------------- set NPLOTS = $#plots set NEXPS = $#exps set NFIELDS = $#fields set FIELDS_PER_TASK_SYS = 3 set FIELDS_PER_TASK_SYSCMP = 1 echo " NPLOTS = " $NPLOTS echo " NEXPS = " $NEXPS echo " NFIELDS = " $NFIELDS echo " FIELDS_PER_TASK_SYS = " $FIELDS_PER_TASK_SYS echo " FIELDS_PER_TASK_SYSCMP = " $FIELDS_PER_TASK_SYSCMP echo " " @ SUBTASKS_SYS = 0 @ n = 0 foreach FIELD ($fields) @ n = $n + 1 if( $n == $FIELDS_PER_TASK_SYS ) then @ SUBTASKS_SYS = $SUBTASKS_SYS + 1 @ n = 0 endif end if( $n != 0 ) then @ SUBTASKS_SYS = $SUBTASKS_SYS + 1 endif @ SUBTASKS_SYSCMP = 0 @ n = 0 foreach FIELD ($fields) @ n = $n + 1 if( $n == $FIELDS_PER_TASK_SYSCMP ) then @ SUBTASKS_SYSCMP = $SUBTASKS_SYSCMP + 1 @ n = 0 endif end if( $n != 0 ) then @ SUBTASKS_SYSCMP = $SUBTASKS_SYSCMP + 1 endif set quickstat_corcmp = '' set quickstat_pltsys = '' set quickstat_syscmp = '' @ NTASKS = 0 foreach plot ($plots) if( $plot == 'corcmp' ) then set quickstat_corcmp = `echo "./quickstat -rc $statsrc -plots corcmp -fields $fields"` @ CORCMPID = $NTASKS + 1 MATH NTASKS = $NTASKS + 1 echo CORCMP: NTASKS = $NTASKS endif if( $plot == 'pltsys' ) then set quickstat_pltsys = `echo "./quickstat -rc $statsrc -plots sys "` @ PLTSYSID = $NTASKS + 1 MATH NTASKS = $NTASKS + ( $NEXPS * $SUBTASKS_SYS ) echo PLTSYS: NTASKS = $NTASKS \( SUBTASKS_SYS:$SUBTASKS_SYS x NEXPS: $NEXPS \) endif if( $plot == 'syscmp' ) then set quickstat_syscmp = `echo "./quickstat -rc $statsrc -plots syscmp "` set syscmpexps = '' foreach exp ($exps) if( $exp != 0 ) set syscmpexps = `echo $syscmpexps $exp` end set NSYSCMPEXPS = $#syscmpexps @ SYSCMPID = $NTASKS + 1 MATH NTASKS = $NTASKS + ( $NSYSCMPEXPS * $SUBTASKS_SYSCMP ) echo SYSCMP: NTASKS = $NTASKS \( SUBTASKS_SYSCMP:$SUBTASKS_SYSCMP x NEXPS:$NSYSCMPEXPS \) endif end echo " " /bin/rm -f $SOURCE/gcm_quickstat.tmpl touch $SOURCE/gcm_quickstat.tmpl cat $GEOSAPP/gcm_quickstat.j >> $SOURCE/gcm_quickstat.tmpl if( $#quickstat_corcmp > 1 ) then @ IDX = $CORCMPID echo 'if( $ID == '$IDX' ) '$quickstat_corcmp >> $SOURCE/gcm_quickstat.tmpl echo " " >> $SOURCE/gcm_quickstat.tmpl endif if( $#quickstat_pltsys > 1 ) then @ IDX = $PLTSYSID foreach EXP ($exps) @ TASK = 1 while( $TASK <= $SUBTASKS_SYS ) MATH BEGFIELD = 1 + ( $TASK - 1 ) * $FIELDS_PER_TASK_SYS MATH ENDFIELD = $BEGFIELD + $FIELDS_PER_TASK_SYS - 1 if( $ENDFIELD > $NFIELDS ) set ENDFIELD = $NFIELDS set FIELDLIST = `echo $fields[${BEGFIELD}-${ENDFIELD}]` echo 'if( $ID == '$IDX' ) '$quickstat_pltsys" -field $FIELDLIST -exp $EXP" >> $SOURCE/gcm_quickstat.tmpl @ TASK = $TASK + 1 @ IDX = $IDX + 1 end end echo " " >> $SOURCE/gcm_quickstat.tmpl endif if( $#quickstat_syscmp > 1 ) then @ IDX = $SYSCMPID foreach EXP ($syscmpexps) @ TASK = 1 while( $TASK <= $SUBTASKS_SYSCMP ) MATH BEGFIELD = 1 + ( $TASK - 1 ) * $FIELDS_PER_TASK_SYSCMP MATH ENDFIELD = $BEGFIELD + $FIELDS_PER_TASK_SYSCMP - 1 if( $ENDFIELD > $NFIELDS ) set ENDFIELD = $NFIELDS set FIELDLIST = `echo $fields[${BEGFIELD}-${ENDFIELD}]` echo 'if( $ID == '$IDX' ) '$quickstat_syscmp" -field $FIELDLIST -exp $EXP" >> $SOURCE/gcm_quickstat.tmpl @ TASK = $TASK + 1 @ IDX = $IDX + 1 end end echo " " >> $SOURCE/gcm_quickstat.tmpl endif /bin/rm -f $SOURCE/gcm_quickstat.j /bin/rm -f $SOURCE/sedfile touch $SOURCE/sedfile cat > $SOURCE/sedfile << EOF s?@GEOSBIN?$GEOSBIN?g s?@GEOSSRC?$GEOSSRC?g s?@NTASKS?$NTASKS?g s?@PARTITION?$PARTITION?g s?@QUEUE?$QUEUE?g EOF sed -f $SOURCE/sedfile $SOURCE/gcm_quickstat.tmpl > $SOURCE/gcm_quickstat.j echo "Please Submit: $SOURCE/gcm_quickstat.j for processing" echo " " exit endif # Run Grads-Based Quickstat Utility for Anomaly Correlation Comparison # -------------------------------------------------------------------- if( "$plots" =~ *corcmp* ) then set tmpdir = "" foreach field ($fields) set pltdir = $SOURCE/scratch_corcmp/$field.`date +%Y%m%d_%H%M%S` mkdir -p $pltdir cd $pltdir ; set tmpdir = `echo $tmpdir $pltdir` $GRADS -l -b -c "run $GEOSUTIL/plots/fcst/pltcorcmp -source $SOURCE -rc $statsrc -fields $field" & sleep 5 end foreach exp ($exps) if( $exp != 0 ) then set DESC = `cat $statsrc | grep DESC: | grep -v \# | cut -d: -f2` set EXP0 = `cat $statsrc | grep EXP0: | grep -v \# | cut -d: -f2` set DSC0 = `cat $statsrc | grep DSC0: | grep -v \# | cut -d: -f2` set EXP1 = `cat $statsrc | grep EXP${exp}: | grep -v \# | cut -d: -f2` set DSC1 = `cat $statsrc | grep DSC${exp}: | grep -v \# | cut -d: -f2` foreach field ($fields) if( $field != p ) then set pltdir = $SOURCE/scratch_corcmpz/$field.`date +%Y%m%d_%H%M%S` mkdir -p $pltdir cd $pltdir ; set tmpdir = `echo $tmpdir $pltdir` /bin/rm -f $pltdir/corcmp_$exp.rc touch $pltdir/corcmp_$exp.rc echo DESC: $DESC >> $pltdir/corcmp_$exp.rc echo EXP0: $EXP0 >> $pltdir/corcmp_$exp.rc echo DSC0: $DSC0 >> $pltdir/corcmp_$exp.rc echo EXP1: $EXP1 >> $pltdir/corcmp_$exp.rc echo DSC1: $DSC1 >> $pltdir/corcmp_$exp.rc $GRADS -l -b -c "run $GEOSUTIL/plots/fcst/pltcorcmpz -source $SOURCE -rc $pltdir/corcmp_$exp.rc -fields $field" & sleep 5 endif end foreach field ($fields) if( $field != p ) then set pltdir = $SOURCE/scratch_rmscmpz/$field.`date +%Y%m%d_%H%M%S` mkdir -p $pltdir cd $pltdir ; set tmpdir = `echo $tmpdir $pltdir` /bin/rm -f $pltdir/corcmp_$exp.rc touch $pltdir/corcmp_$exp.rc echo DESC: $DESC >> $pltdir/corcmp_$exp.rc echo EXP0: $EXP0 >> $pltdir/corcmp_$exp.rc echo DSC0: $DSC0 >> $pltdir/corcmp_$exp.rc echo EXP1: $EXP1 >> $pltdir/corcmp_$exp.rc echo DSC1: $DSC1 >> $pltdir/corcmp_$exp.rc $GRADS -l -b -c "run $GEOSUTIL/plots/fcst/pltrmscmpz -source $SOURCE -rc $pltdir/corcmp_$exp.rc -fields $field" & sleep 5 endif end endif end wait cd $SOURCE $GEOSUTIL/plots/grads_util/stats_montage $statsrc /bin/rm -r $tmpdir endif # Run Grads-Based Quickstat Utility for Systematic Error # ------------------------------------------------------ if( "$plots" =~ *pltsys* ) then set tmpdir = "" foreach exp ($exps) foreach field ($fields) set pltdir = $SOURCE/scratch_pltsys/EXP${exp}_$field.`date +%Y%m%d_%H%M%S` mkdir -p $pltdir cd $pltdir ; set tmpdir = `echo $tmpdir $pltdir` $GRADS -l -b -c "run pltsys.gs -exp $exp -field $field -rc $statsrc -level $level" & sleep 5 end end wait set files = `find $SOURCE/scratch_pltsys -name MONTHLAB.txt` set SEASON = `cat $files[1]` foreach exp ($exps) set DESC = `cat $statsrc | grep DSC$exp | grep -v \# | grep : | cut -d: -f2` set sysfiles = `/bin/ls -1 $SOURCE/$DESC/*fma*.nc3` if( $#sysfiles == 6 ) then $GEOSUTIL/plots/grads_util/make_syserr $SOURCE/$DESC /bin/mv $SOURCE/$DESC/syserr_${DESC}.nc4 $SOURCE/${DESC}_syserr_${SEASON}.nc4 endif end /bin/rm -r $tmpdir endif # Run Grads-Based Quickstat Utility for Systematic Error Comparison # ----------------------------------------------------------------- if( "$plots" =~ *syscmp* ) then set tmpdir = "" foreach exp ($exps) if( $exp != 0 ) then foreach field ($fields) if( $field == p ) then if( $level == 'NULL' | $level == 1000 ) then set pltdir = $SOURCE/scratch_syscmp/EXP${exp}_${field}_1000.`date +%Y%m%d_%H%M%S` mkdir -p $pltdir cd $pltdir ; set tmpdir = `echo $tmpdir $pltdir` $GRADS -l -b -c "run $GEOSUTIL/plots/fcst/setup_statd -exps 0 $exp -fields $field -rc $statsrc -levels 1000 " & sleep 5 endif else if( $level == 'NULL' ) then set levels = `echo 1000 975 950 925 900 850 800 750 700 600 500 400 300 250 200 150 100 zonal` else set levels = $level endif foreach level ( $levels ) set pltdir = $SOURCE/scratch_syscmp/EXP${exp}_${field}_${level}.`date +%Y%m%d_%H%M%S` mkdir -p $pltdir cd $pltdir ; set tmpdir = `echo $tmpdir $pltdir` $GRADS -l -b -c "run $GEOSUTIL/plots/fcst/setup_statd -exps 0 $exp -fields $field -rc $statsrc -levels $level " & sleep 5 end endif end endif end wait /bin/rm -r $tmpdir endif # Sleep for 20 seconds to ensure all plots are finished # ----------------------------------------------------- sleep 20 # Reset Environment # ----------------- cd $SOURCE exit