#!/bin/csh -f # +-======-+ # Copyright (c) 2003-2018 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 # # +-======-+ # This script performs post-processing of monthly mean files which have been created from: gcmpost.script # It performs the following tasks: # # 1) Computes Climatology of Monthly Mean Files # 2) Computes Climatology of Seasonal Means # 3) Computes Climatology of Annual Mean # # ------------------------------------------------------------------------- if ( ! $?GEOSUTIL ) then echo " " echo "Environment variable GEOSUTIL must be defined before use\!" echo " " exit 1 endif if( $#argv < 2 ) then USAGE: echo " " echo "Usage:" echo "gcmclim.script -source SOURCE [-collection COLLECTION]" echo " [-month MM]" echo " [-diurnal]" echo " [-ncpus NCPUS]" echo " " echo "where: SOURCE is your location of your Experiment" echo " COLLECTION is the Collection Name from HISTORY.rc (Default: ALL)" echo " MM is an optional parameter [1-12] to only update" echo " files affected by month MM" echo " -diurnal is an optional parameter to process" echo " monthly mean diurnal files" echo " NCPUS is an optional parameter to specify NCPUS to use" echo " " exit 1 echo endif # Capture Input Arguments # ----------------------- set source = 'NULL' set collections = 'ALL' set NCPUS = 'NULL' set filetype = 'monthly' set diurnal = '' @ MM = -99 @ nargs = $#argv @ n = 1 while( $n <= $nargs ) @ m = $n + 1 if( "$argv[$n]" == "-source" ) then set source = $argv[$m] endif if( "$argv[$n]" == "-collection" ) then set collections = $argv[$m] endif if( "$argv[$n]" == "-month" ) then @ MM = $argv[$m] endif if( "$argv[$n]" == "-ncpus" ) then set NCPUS = $argv[$m] endif if( "$argv[$n]" == "-diurnal" ) then set filetype = 'diurnal' set diurnal = ' -d ' endif @ n = $n + 1 end if( $source == 'NULL' ) goto USAGE if( $MM > 12 ) goto USAGE # Set HOMDIR # ---------- if( -e $source/.HOMDIR ) then set homdir = `cat $source/.HOMDIR` else set homdir = $source endif # Get Experiment Description (trimmed to 49 characters for GrADS limit) # --------------------------------------------------------------------- set expdsc = `grep EXPDSC: $homdir/HISTORY.rc | cut -d" " -f2 | cut -c1-49` # Determine if running in BATCH # ----------------------------- if( $NCPUS == "NULL" ) then if ($?PBS_NODEFILE & $?BATCHNAME) then set BATCHJOB = `qstat | grep $BATCHNAME | grep $LOGNAME | cut -d' ' -f1` set numjobs = $#BATCHJOB if( $numjobs != 0 ) then set NCPUS = `cat $PBS_NODEFILE | wc -l` endif endif endif echo Use: NCPUS = $NCPUS if( $NCPUS == "NULL" | $NCPUS == 1 ) then set TIMEAVE_x = "$GEOSUTIL/post/time_ave.x" else if ( ! $?RUN_CMD ) then echo " " echo "Environment variable RUN_CMD must be defined before use\!" echo " " exit 1 endif set TIMEAVE_x = "$RUN_CMD $NCPUS $GEOSUTIL/post/time_ave.x" endif # Loop over collections # --------------------- if( $collections == 'ALL' ) set collections = `$GEOSUTIL/post/get_streams $homdir/HISTORY.rc` foreach collection ($collections) set climdir = $source/$collection if( "$diurnal" != "" ) set climdir = $source/$collection/diurnal cd $climdir if( $MM > 0 & $MM < 10 ) then set length = `echo $MM | awk '{print length}'` if($length < 2 )set MM = 0$MM endif # Extract EXPID from SOURCE (assuming last node) # ----------------------------------------------- set expid = `basename $source` set fname = $expid.$collection.$filetype # Extract Extension (last node) from Monthly Mean Files # ----------------------------------------------------- set files = `/bin/ls -1 $fname.* | grep -v clim` set num = $#files if( $num == 0 ) then echo " " echo "No $fname files present\!" echo " " exit 1 endif @ loc = 1 while( $loc != 0 ) set dum = `echo $files[1] | cut -d "." -f$loc` if( .$dum != . ) then set ext = $dum @ loc = $loc + 1 else @ loc = 0 endif end # Find Begin and End Dates for Monthly Mean Files # ----------------------------------------------- set filedate = `$GEOSUTIL/post/getdates $files[1]` set begdate = `echo $filedate[1] | cut -c1-6` set filedate = `$GEOSUTIL/post/getdates $files[$num]` set enddate = `echo $filedate[3] | cut -c1-6` set begyear = `echo $begdate | cut -c1-4` set begmonth = `echo $begdate | cut -c5-6` # Compute Monthly Climatologies # ----------------------------- set nymd = ${begdate}15 @ ndt = 30 * 86400 @ n = 1 while( $n <= 12 ) set curyear = `echo $nymd | cut -c1-4` set curmonth = `echo $nymd | cut -c5-6` set curdate = ${curyear}${curmonth} if( $MM == -99 | $MM == $curmonth ) then /bin/rm -f $fname.clim.M$curmonth.$ext /bin/rm -f clim.tabl # to ensure a complete, updated clim.tabl for plots set files = `/bin/ls -1 $fname.*$curmonth.$ext | grep -v clim` $GEOSUTIL/post/check_clim $fname ${begdate} $enddate $curmonth $ext if( $status == 0 ) then $TIMEAVE_x -hdf $files -strict false -tag $fname.clim -noquad -ntmin 1 $diurnal if( "$diurnal" == "" ) then /bin/mv $fname.clim.${curdate}.$ext $fname.clim.M$curmonth.$ext else /bin/rm $fname.clim.${curdate}.$ext /bin/mv $fname.clim_diurnal.${curdate}.$ext $fname.clim.M$curmonth.$ext endif endif endif set date = `$GEOSUTIL/post/tick $nymd 000000 $ndt` set nymd = $date[1] @ n = $n + 1 end # Get POST Resource Parameters # ---------------------------- if(! -e $source/post/post.rc ) ln -sf $GEOSUTIL/post/post.rc $source/post/post.rc set SEASONS = `grep POST_SEASONS: $source/post/post.rc | cut -d'#' -f1 | cut -d':' -f2 | tr "[:lower:]" "[:upper:]"` # Compute 3-Month Season Climatologies # ------------------------------------ foreach MON (01 02 03 04 05 06 07 08 09 10 11 12) @ MON1 = $MON @ MON2 = $MON + 1 @ MON3 = $MON + 2 if( $MON2 > 12 ) @ MON2 = $MON2 - 12 if( $MON3 > 12 ) @ MON3 = $MON3 - 12 if( $MON1 < 10 ) set MON1 = 0$MON1 if( $MON2 < 10 ) set MON2 = 0$MON2 if( $MON3 < 10 ) set MON3 = 0$MON3 if( $MON1 == "01" ) set SEASON = JFM if( $MON1 == "02" ) set SEASON = FMA if( $MON1 == "03" ) set SEASON = MAM if( $MON1 == "04" ) set SEASON = AMJ if( $MON1 == "05" ) set SEASON = MJJ if( $MON1 == "06" ) set SEASON = JJA if( $MON1 == "07" ) set SEASON = JAS if( $MON1 == "08" ) set SEASON = ASO if( $MON1 == "09" ) set SEASON = SON if( $MON1 == "10" ) set SEASON = OND if( $MON1 == "11" ) set SEASON = NDJ if( $MON1 == "12" ) set SEASON = DJF set season = `echo $SEASON | tr "[:upper:]" "[:lower:]"` if( $MM == -99 | $MM == $MON1 | $MM == $MON2 | $MM == $MON3 ) then if( `echo $SEASONS` =~ \*${SEASON}\* ) then /bin/rm -f $fname.clim.$SEASON.$ext /bin/rm -f $season.tabl if( -e $fname.clim.M$MON1.$ext & \ -e $fname.clim.M$MON2.$ext & \ -e $fname.clim.M$MON3.$ext ) then /bin/rm -f $fname.clim.$SEASON.$ext set files = `/bin/ls -1 $fname.clim.M$MON1.$ext $fname.clim.M$MON2.$ext $fname.clim.M$MON3.$ext` $TIMEAVE_x -hdf $files -strict false -tag $fname.clim.$SEASON -noquad -ntmin 1 $diurnal if( "$diurnal" == "" ) then /bin/mv $fname.clim.${SEASON}.*.$ext $fname.clim.$SEASON.$ext else /bin/rm $fname.clim.${SEASON}.*.$ext /bin/mv $fname.clim.${SEASON}_diurnal.*.$ext $fname.clim.$SEASON.$ext endif set year = `echo $begdate | cut -c1-4` set month = `echo $begdate | cut -c5-6` while( $month != $MON1 ) set nymd = ${year}${month}15 @ ndt = 30 * 86400 set date = `$GEOSUTIL/post/tick $nymd 000000 $ndt` set year = `echo $date[1] | cut -c1-4` set month = `echo $date[1] | cut -c5-6` end if( $MON1 == "01" ) set month = JAN if( $MON1 == "02" ) set month = FEB if( $MON1 == "03" ) set month = MAR if( $MON1 == "04" ) set month = APR if( $MON1 == "05" ) set month = MAY if( $MON1 == "06" ) set month = JUN if( $MON1 == "07" ) set month = JUL if( $MON1 == "08" ) set month = AUG if( $MON1 == "09" ) set month = SEP if( $MON1 == "10" ) set month = OCT if( $MON1 == "11" ) set month = NOV if( $MON1 == "12" ) set month = DEC echo DSET $climdir/$fname.clim.$SEASON.$ext > $season.tabl echo TITLE $expdsc Climatology: ${begdate} to ${enddate} >> $season.tabl echo OPTIONS template >> $season.tabl echo TDEF time 1 LINEAR 00:00Z01${month}${year} 1mo >> $season.tabl endif endif endif end # Compute Annual Climatology # -------------------------- if( `echo $SEASONS` =~ \*ANN\* ) then /bin/rm -f $fname.clim.ANN.$ext /bin/rm -f ann.tabl if( -e $fname.clim.DJF.$ext & \ -e $fname.clim.MAM.$ext & \ -e $fname.clim.JJA.$ext & \ -e $fname.clim.SON.$ext ) then set ANNfiles = `/bin/ls -1 $fname.clim.DJF.$ext \ $fname.clim.MAM.$ext \ $fname.clim.JJA.$ext \ $fname.clim.SON.$ext` $TIMEAVE_x -hdf $ANNfiles -strict false -tag $fname.clim.ANN -noquad -ntmin 1 $diurnal if( "$diurnal" == "" ) then /bin/mv $fname.clim.ANN.*.$ext $fname.clim.ANN.$ext else /bin/rm $fname.clim.ANN.*.$ext /bin/mv $fname.clim.ANN_diurnal.*.$ext $fname.clim.ANN.$ext endif set year = `echo $begdate | cut -c1-4` set month = `echo $begdate | cut -c5-6` if( $month == "01" ) set MON = JAN if( $month == "02" ) set MON = FEB if( $month == "03" ) set MON = MAR if( $month == "04" ) set MON = APR if( $month == "05" ) set MON = MAY if( $month == "06" ) set MON = JUN if( $month == "07" ) set MON = JUL if( $month == "08" ) set MON = AUG if( $month == "09" ) set MON = SEP if( $month == "10" ) set MON = OCT if( $month == "11" ) set MON = NOV if( $month == "12" ) set MON = DEC echo DSET $climdir/$fname.clim.ANN.$ext > ann.tabl echo TITLE $expdsc Climatology: ${begdate} to ${enddate} >> ann.tabl echo OPTIONS template >> ann.tabl echo TDEF time 1 LINEAR 00:00Z01${MON}${year} 1mo >> ann.tabl endif endif # Create Grads Data Description File (DDF) for Templated Monthly Mean Climatology # ------------------------------------------------------------------------------- if( "$diurnal" == "" ) then /bin/rm -f clim.tabl set files = `/bin/ls -1 $climdir/$fname.clim.M*.$ext | grep -v MAM` set num = $#files if( $num == 12 ) then set perpyr = `grep PERPETUAL_YEAR: $homdir/CAP.rc | grep -v \#` set perpmo = `grep PERPETUAL_MONTH: $homdir/CAP.rc | grep -v \#` if( $#perpyr != 0 & $#perpmo != 0 ) then set timinc = "yr" else set timinc = "mo" endif set year = `echo $begdate | cut -c1-4` set month = `echo $begdate | cut -c5-6` if( $month == "01" ) set MON = JAN if( $month == "02" ) set MON = FEB if( $month == "03" ) set MON = MAR if( $month == "04" ) set MON = APR if( $month == "05" ) set MON = MAY if( $month == "06" ) set MON = JUN if( $month == "07" ) set MON = JUL if( $month == "08" ) set MON = AUG if( $month == "09" ) set MON = SEP if( $month == "10" ) set MON = OCT if( $month == "11" ) set MON = NOV if( $month == "12" ) set MON = DEC echo DSET $climdir/$fname.clim.M%m2.$ext > clim.tabl echo TITLE $expdsc Climatology: ${begdate} to ${enddate} >> clim.tabl echo OPTIONS template >> clim.tabl echo TDEF time $num LINEAR 00:00Z01${MON}${year} 1$timinc >> clim.tabl endif endif end # End Collections Loop