# # C-shell script to run DISORT on the default (or your own) DISORT test # problems. # # USAGE: rundis1.2 [sp,dp] # (if no arguments, a brief help message is printed) # # where: sp = run entirely in single precision # dp = run entirely in double precision # (if argument omitted, run in normal mixed single-double # precision) # # NOTES and WARNINGS: # # (1) Changing the compiler options used is the main customization # needed to run this script on other Unix machines. These options are # set near the beginning of the script, and again later for the 'dp' # mode of execution. If an auto-doubling option is not available, the # 'dp' mode will not work and should be error-trapped. # # (2) Do not run two copies of this script at the same time. It will become # fatally confused. # # (3) This script will probably behave OK when run in background or batch # mode; all expectable error messages and output are redirected to # the output file after compilation begins, but unexpected output may # want to write to the terminal. # # (4) Do not put R1MACH in a type statement (e.g. REAL R1MACH) in any variant # of DISORTsp.f; this will be changed to 'REAL D1MACH' and thus will # prevent the 'dp' option from working correctly. It is too difficult # to design a 'sed' or 'awk' command to search for all possible variants # of such a type statement and change them. # # (5) Let this script manage the file 'runnumfile' that will appear in its # host directory the first time you run it; 'runnumfile' contains # a unique incrementing tag that will be used to identify the output # file from each run (the tag runs from 1 to 99, then cycles back to 1). # # # Expected output # --------------- # # (1) Listing file code.l: each new one overwrites the previous one. # Read it right away or lose it. # # (2) Normal output file 'Onn.DISOTEST1.2[sp,dp]' where 'nn' is the run # number, and [sp,dp] merely echoes script argument if it is supplied # [informational messages + Compilation summary + Standard Output # + Standard Error] # # (3) Messages from this script: # # * error messages prior to compile step go to terminal screen; # these should appear quickly; # * a one-line notice that compilation was successful # (the run acquires a permanent "run number" at this point); # # * once compilation finishes, no further text messages # are sent to the terminal; # # * informational messages, and error messages from compile # or execute step, go to the normal output file (2); # # The script attempts to die gracefully if it receives an interrupt; # If running in the foreground, it is immune to hangups (logoffs) # because it contains the 'nohup' command. # # Author: Dr. Warren Wiscombe (Warren.Wiscombe@gsfc.nasa.gov) # NASA Goddard Space Flight Center, Code 913 # Greenbelt, MD 20771 # ============================================================================ onintr intr_handler # arrange to clean up if interrupted set scriptname = $0 set script = $scriptname:t nohup # ignore hangups (logoffs) by user unalias * # keep aliases from screwing things up unset noclobber # allow file overwriting (crucial) set nonomatch # do not abort commands where a filename # expansion does not match any files set ApplicDir = `pwd` # save application directory name # f77 compiler options set CompilerOps = "etcetcetc" set NumArg = $#argv if ( $NumArg > 1 ) then echo "\ Correct usage is $script [sp,dp]\ where sp(dp) = run entirely in single (double) precision\ " exit 1 endif if ( ! (-e runnumfile) ) then # Create run number file echo -n 0 > runnumfile # (-n means no carr. ret. after number) endif @ runnum = `cat runnumfile` if ( $runnum < 0 || $runnum > 99 ) then # Run number out of bounds; fix @ runnum = 0 echo -n $runnum > runnumfile endif # Increment run number and keep it # below 3 digits but do not store back # in run number file yet @ runnum = $runnum + 1 if ( $runnum >= 100 ) @ runnum = 1 set OutputFile = O$runnum.DISTST$revision set precision = normal if ( $NumArg == 1 ) then if ( $1 == sp ) then set precision = single else if ( $1 == dp ) then set precision = double else echo "$script argument $1 is not one of {sp,dp}." exit 3 endif set OutputFile = $OutputFile$1 endif date > $OutputFile set TestDriver = DISOTEST.f if ( $precision == single || $precision == double ) then set DisortCode = DISORTsp.f else set DisortCode = DISORT.f endif # compile and link (producing a.out) if ( $precision == normal || $precision == single ) then cat ErrPack.f R1MACH.f D1MACH.f LINPAK.f > DisortUtils.f cat $TestDriver $DisortCode DisortUtils.f > code.f rm -f DisortUtils.f >& /dev/null f77 $CompilerOps code.f >>& $OutputFile set compilstatus = $status else if ( $precision == double ) then cat ErrPack.f LINPAK.f > DisortUtils.f # chg all instances of R1MACH to D1MACH rm -f tempDISORT.f >& /dev/null sed 's/R1MACH/D1MACH/g' DISORTsp.f > tempDISORT.f cat $TestDriver tempDISORT.f DisortUtils.f > code.f rm -f tempDISORT.f DisortUtils.f >& /dev/null # f77 compiler options: # c: produce object (.o) file only # autodblpad: convert to double precision f77 $CompilerOps -c D1MACH.f >>& $OutputFile f77 $CompilerOps +autodblpad code.f D1MACH.o >>& $OutputFile set compilstatus = $status endif if ( $compilstatus != 0 ) then echo "\ --------------------------------------------------\ $script (run number $runnum). Compilation failed.\ Check listing file. Aborting...\ --------------------------------------------------" rm -f a.out code.f *.o >& /dev/null exit 4 endif rm -f code.f *.o >& /dev/null # ------------------------------------------------------------ # Compilation successful; run has now earned a new run number # ------------------------------------------------------------ echo "Compilation successful; Starting execution of $script run number $runnum" echo -n $runnum > $ApplicDir/runnumfile # Update run number file # ------------------------------- # From here on, avoid sending any # messages to terminal screen # ------------------------------- chmod u+x ./a.out # make a.out executable # Execute, merging std output and std error ./a.out >>& $OutputFile # "./" ensures local a.out is executed set execstat = $status if ( $execstat != 0 ) then echo "\ -----------------------------------------------\ $script (run number $runnum). Execution bombed\ with status code $execstat. Check output file.\ -----------------------------------------------\ " >> $OutputFile endif rm -f a.out core >& /dev/null # Clean up exit $execstat # =============================================================== # The following commands are executed when the script receives an # interrupt signal (e.g. Ctl-C from user or kill from operator). intr_handler: onintr - # Prevent further interrupts echo "\ ---------------------------------------------------------\ $script (run number $runnum). Received interrupt signal.\ ---------------------------------------------------------\ " exit 99