#!/bin/csh -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 # # +-======-+ # 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 # Determine if running in BATCH # ----------------------------- if( $NCPUS == "NULL" ) then if ($?PBS_NODEFILE) then set nodes = `cat $PBS_NODEFILE` set NCPUS = $#nodes 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 $source/HISTORY.rc` foreach collection ($collections) cd $source/$collection if( $MM > 0 & $MM < 10 ) set MM = 0$MM # 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 = `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( $curmonth == "01" ) set JAN = $curdate if( $curmonth == "02" ) set FEB = $curdate if( $curmonth == "03" ) set MAR = $curdate if( $curmonth == "04" ) set APR = $curdate if( $curmonth == "05" ) set MAY = $curdate if( $curmonth == "06" ) set JUN = $curdate if( $curmonth == "07" ) set JUL = $curdate if( $curmonth == "08" ) set AUG = $curdate if( $curmonth == "09" ) set SEP = $curdate if( $curmonth == "10" ) set OCT = $curdate if( $curmonth == "11" ) set NOV = $curdate if( $curmonth == "12" ) set DEC = $curdate if( $curmonth == "12" ) set ANN = $curdate if( $MM == -99 | $MM == $curmonth ) then /bin/rm -f $fname.clim.M$curmonth.${begdate}_*.$ext set files = `ls -1 $fname.*$curmonth.$ext | grep -v clim` $TIMEAVE_x -hdf $files -strict false -tag $fname.clim -noquad -ntmin 1 $diurnal /bin/mv $fname.clim.${curdate}.$ext $fname.clim.M$curmonth.${begdate}_${enddate}.$ext else set files = `ls -1 $fname.clim.M$curmonth.${begdate}_*.$ext` set num = $#files if( $num != 0 ) /bin/mv `ls -1 $fname.clim.M$curmonth.${begdate}_*.$ext` $fname.clim.M$curmonth.${begdate}_${enddate}.$ext endif set date = `$GEOSUTIL/post/tick $nymd 000000 $ndt` set nymd = $date[1] @ n = $n + 1 end # Compute Seasonal Climatologies # ------------------------------ if( $MM == -99 | $MM == 12 | $MM == 01 | $MM == 02 ) then /bin/rm -f $fname.clim.DJF.${begdate}_*.$ext set DJFfiles = `ls -1 $fname.clim.M12*.$ext $fname.clim.M01*.$ext $fname.clim.M02*.$ext` $TIMEAVE_x -hdf $DJFfiles -strict false -tag $fname.clim.DJF -noquad -ntmin 1 $diurnal /bin/mv $fname.clim.DJF*.$ext $fname.clim.DJF.${begdate}_${enddate}.$ext else set files = `ls -1 $fname.clim.DJF.${begdate}_*.$ext` set num = $#files if( $num != 0 ) /bin/mv `ls -1 $fname.clim.DJF.${begdate}_*.$ext` $fname.clim.DJF.${begdate}_${enddate}.$ext endif if( $MM == -99 | $MM == 03 | $MM == 04 | $MM == 05 ) then /bin/rm -f $fname.clim.MAM.${begdate}_*.$ext set MAMfiles = `ls -1 $fname.clim.M03*.$ext $fname.clim.M04*.$ext $fname.clim.M05*.$ext` $TIMEAVE_x -hdf $MAMfiles -strict false -tag $fname.clim.MAM -noquad -ntmin 1 $diurnal /bin/mv $fname.clim.MAM*.$ext $fname.clim.MAM.${begdate}_${enddate}.$ext else set files = `ls -1 $fname.clim.MAM.${begdate}_*.$ext` set num = $#files if( $num != 0 ) /bin/mv `ls -1 $fname.clim.MAM.${begdate}_*.$ext` $fname.clim.MAM.${begdate}_${enddate}.$ext endif if( $MM == -99 | $MM == 06 | $MM == 07 | $MM == 08 ) then /bin/rm -f $fname.clim.JJA.${begdate}_*.$ext set JJAfiles = `ls -1 $fname.clim.M06*.$ext $fname.clim.M07*.$ext $fname.clim.M08*.$ext` $TIMEAVE_x -hdf $JJAfiles -strict false -tag $fname.clim.JJA -noquad -ntmin 1 $diurnal /bin/mv $fname.clim.JJA*.$ext $fname.clim.JJA.${begdate}_${enddate}.$ext else set files = `ls -1 $fname.clim.JJA.${begdate}_*.$ext` set num = $#files if( $num != 0 ) /bin/mv `ls -1 $fname.clim.JJA.${begdate}_*.$ext` $fname.clim.JJA.${begdate}_${enddate}.$ext endif if( $MM == -99 | $MM == 09 | $MM == 10 | $MM == 11 ) then /bin/rm -f $fname.clim.SON.${begdate}_*.$ext set SONfiles = `ls -1 $fname.clim.M09*.$ext $fname.clim.M10*.$ext $fname.clim.M11*.$ext` $TIMEAVE_x -hdf $SONfiles -strict false -tag $fname.clim.SON -noquad -ntmin 1 $diurnal /bin/mv $fname.clim.SON*.$ext $fname.clim.SON.${begdate}_${enddate}.$ext else set files = `ls -1 $fname.clim.SON.${begdate}_*.$ext` set num = $#files if( $num != 0 ) /bin/mv `ls -1 $fname.clim.SON.${begdate}_*.$ext` $fname.clim.SON.${begdate}_${enddate}.$ext endif # Compute Annual Climatology # -------------------------- /bin/rm -f $fname.clim.ANN.${begdate}_*.$ext set ANNfiles = `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 /bin/mv $fname.clim.ANN*.$ext $fname.clim.ANN.${begdate}_${enddate}.$ext # Create Grads Data Description File (DDF) for Monthly Climatology # ---------------------------------------------------------------- /bin/rm -f clim.tabl set year = `echo $begdate | cut -c1-4` set month = `echo $begdate | cut -c5-6` set expdsc = `grep EXPDSC: $source/HISTORY.rc | cut -d" " -f2` 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 $source/$collection/$fname.clim.M%m2.${begdate}_${enddate}.$ext > clim.tabl echo TITLE $expdsc >> clim.tabl echo OPTIONS template >> clim.tabl echo TDEF time 12 LINEAR 00:00Z01${MON}${year} 1mo >> clim.tabl /bin/rm -f djf.tabl set year = `echo $DEC | cut -c1-4` set month = `echo $DEC | 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 $source/$collection/$fname.clim.DJF.${begdate}_${enddate}.$ext > djf.tabl echo TITLE $expdsc >> djf.tabl echo OPTIONS template >> djf.tabl echo TDEF time 1 LINEAR 00:00Z01${MON}${year} 1mo >> djf.tabl /bin/rm -f mam.tabl set year = `echo $MAR | cut -c1-4` set month = `echo $MAR | 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 $source/$collection/$fname.clim.MAM.${begdate}_${enddate}.$ext > mam.tabl echo TITLE $expdsc >> mam.tabl echo OPTIONS template >> mam.tabl echo TDEF time 1 LINEAR 00:00Z01${MON}${year} 1mo >> mam.tabl /bin/rm -f jja.tabl set year = `echo $JUN | cut -c1-4` set month = `echo $JUN | 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 $source/$collection/$fname.clim.JJA.${begdate}_${enddate}.$ext > jja.tabl echo TITLE $expdsc >> jja.tabl echo OPTIONS template >> jja.tabl echo TDEF time 1 LINEAR 00:00Z01${MON}${year} 1mo >> jja.tabl /bin/rm -f son.tabl set year = `echo $SEP | cut -c1-4` set month = `echo $SEP | 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 $source/$collection/$fname.clim.SON.${begdate}_${enddate}.$ext > son.tabl echo TITLE $expdsc >> son.tabl echo OPTIONS template >> son.tabl echo TDEF time 1 LINEAR 00:00Z01${MON}${year} 1mo >> son.tabl /bin/rm -f ann.tabl set year = `echo $ANN | cut -c1-4` set month = `echo $ANN | 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 $source/$collection/$fname.clim.ANN.${begdate}_${enddate}.$ext > ann.tabl echo TITLE $expdsc >> ann.tabl echo OPTIONS template >> ann.tabl echo TDEF time 1 LINEAR 00:00Z01${MON}${year} 1mo >> ann.tabl end # End Collections Loop