#!/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 # # +-======-+ ####################################################################### # Batch Parameters for Run Job ####################################################################### #PBS -l walltime=@RUN_T #@RUN_P #PBS -N @RUN_N #@RUN_Q #@BATCH_GROUP ####################################################################### # System Settings ####################################################################### umask 022 limit stacksize unlimited ####################################################################### # Architecture Specific Environment Variables ####################################################################### setenv ARCH `uname` setenv SITE @SITE setenv GEOSDIR @GEOSDIR setenv GEOSBIN @GEOSBIN setenv RUN_CMD "@RUN_CMD" setenv GCMVER @GCMVER source $GEOSBIN/g5_modules setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${BASEDIR}/${ARCH}/lib ####################################################################### # Experiment Specific Environment Variables ####################################################################### setenv EXPID @EXPID setenv EXPDIR @EXPDIR setenv HOMDIR @HOMDIR setenv SCRDIR $EXPDIR/scratch ####################################################################### # Create Experiment Sub-Directories ####################################################################### if (! -e $EXPDIR/restarts ) mkdir -p $EXPDIR/restarts if (! -e $EXPDIR/holding ) mkdir -p $EXPDIR/holding if (! -e $EXPDIR/archive ) mkdir -p $EXPDIR/archive if (! -e $EXPDIR/post ) mkdir -p $EXPDIR/post if (! -e $EXPDIR/plot ) mkdir -p $EXPDIR/plot if (! -e $SCRDIR ) mkdir -p $SCRDIR ####################################################################### # Set Experiment Run Parameters ####################################################################### set NX = `grep NX: $HOMDIR/AGCM.rc | cut -d':' -f2` set NY = `grep NY: $HOMDIR/AGCM.rc | cut -d':' -f2` set AGCM_IM = `grep AGCM_IM: $HOMDIR/AGCM.rc | cut -d':' -f2` set AGCM_JM = `grep AGCM_JM: $HOMDIR/AGCM.rc | cut -d':' -f2` set AGCM_LM = `grep AGCM_LM: $HOMDIR/AGCM.rc | cut -d':' -f2` set OGCM_IM = `grep OGCM_IM: $HOMDIR/AGCM.rc | cut -d':' -f2` set OGCM_JM = `grep OGCM_JM: $HOMDIR/AGCM.rc | cut -d':' -f2` set END_DATE = `grep END_DATE: $HOMDIR/CAP.rc | cut -d':' -f2` set NUM_SGMT = `grep NUM_SGMT: $HOMDIR/CAP.rc | cut -d':' -f2` set FSEGMENT = `grep FCST_SEGMENT: $HOMDIR/CAP.rc | cut -d':' -f2` set USE_SHMEM = `grep USE_SHMEM: $HOMDIR/CAP.rc | cut -d':' -f2` >>>COUPLED<<>>COUPLED<< $NCPUS ) then echo "CPU Resources are Over-Specified" echo "--------------------------------" echo "Allotted NCPUs: $NCPUS" echo "Specified NX : $NX" echo "Specified NY : $NY" exit endif endif endif ####################################################################### # Move to Scratch Directory and Copy RC Files from Home Directory ####################################################################### cd $SCRDIR /bin/rm -rf * /bin/ln -sf $EXPDIR/RC/* . /bin/cp $EXPDIR/cap_restart . /bin/cp -f $HOMDIR/*.rc . /bin/cp -f $HOMDIR/*.nml . ####################################################################### # Create Strip Utility to Remove Multiple Blank Spaces ####################################################################### set FILE = strip /bin/rm $FILE cat << EOF > $FILE #!/bin/ksh /bin/mv \$1 \$1.tmp touch \$1 while read line do echo \$line >> \$1 done < \$1.tmp exit EOF chmod +x $FILE ####################################################################### # Create HISTORY Collection Directories ####################################################################### set collections = '' foreach line ("`cat HISTORY.rc`") set firstword = `echo $line | awk '{print $1}'` set firstchar = `echo $firstword | cut -c1` set secondword = `echo $line | awk '{print $2}'` if ( $firstword == "::" ) goto done if ( $firstchar != "#" ) then set collection = `echo $firstword | sed -e "s/'//g"` set collections = `echo $collections $collection` if ( $secondword == :: ) goto done endif if ( $firstword == COLLECTIONS: ) then set collections = `echo $secondword | sed -e "s/'//g"` endif end done: foreach collection ( $collections ) if (! -e $EXPDIR/$collection ) mkdir $EXPDIR/$collection if (! -e $EXPDIR/holding/$collection ) mkdir $EXPDIR/holding/$collection end ####################################################################### # Link Boundary Datasets ####################################################################### setenv BCSDIR @BCSDIR setenv SSTDIR @SSTDIR setenv CHMDIR @CHMDIR setenv BCRSLV @ATMOStag_@OCEANtag setenv DATELINE DC setenv EMISSIONS @EMISSIONS >>>COUPLED<<>>COUPLED<<>>DATAOCEAN<< $FILE #!/bin/csh -f >>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>FVCUBED<<>>FVCUBED<<>>FVCUBED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>DATAOCEAN<<> $FILE >>>DATAOCEAN<<> $FILE >>>DATAOCEAN<<> $FILE chmod +x linkbcs /bin/cp linkbcs $EXPDIR ####################################################################### # Get C2L History weights/index file for Cubed-Sphere ####################################################################### set C_NPX = `echo $AGCM_IM | awk '{printf "%5.5i", $1}'` set C_NPY = `echo $AGCM_JM | awk '{printf "%5.5i", $1}'` set H_NPX = `echo @HIST_IM | awk '{printf "%5.5i", $1}'` set H_NPY = `echo @HIST_JM | awk '{printf "%5.5i", $1}'` set c2l_file = "${C_NPX}x${C_NPY}_c2l_${H_NPX}x${H_NPY}.bin" if (-e $BCSDIR/$BCRSLV/${c2l_file}) /bin/ln -s $BCSDIR/$BCRSLV/${c2l_file} . ####################################################################### # Get Executable and RESTARTS ####################################################################### /bin/cp $EXPDIR/GEOSgcm.x . set rst_files = `cat AGCM.rc | grep "RESTART_FILE" | grep -v VEGDYN | grep -v "#" | cut -d ":" -f1 | cut -d "_" -f1-2` set rst_file_names = `cat AGCM.rc | grep "RESTART_FILE" | grep -v VEGDYN | grep -v "#" | cut -d ":" -f2` set chk_files = `cat AGCM.rc | grep "CHECKPOINT_FILE" | grep -v "#" | cut -d ":" -f1 | cut -d "_" -f1-2` set chk_file_names = `cat AGCM.rc | grep "CHECKPOINT_FILE" | grep -v "#" | cut -d ":" -f2` # Remove possible bootstrap parameters (+/-) # ------------------------------------------ set dummy = `echo $rst_file_names` set rst_file_names = '' foreach rst ( $dummy ) set length = `echo $rst | awk '{print length($0)}'` set bit = `echo $rst | cut -c1` if( "$bit" == "+" | \ "$bit" == "-" ) set rst = `echo $rst | cut -c2-$length` set rst_file_names = `echo $rst_file_names $rst` end # Copy Restarts to Scratch Directory # ---------------------------------- foreach rst ( $rst_file_names ) if(-e $EXPDIR/$rst ) /bin/cp $EXPDIR/$rst . & end wait >>>COUPLED<<>>COUPLED<<< /bin/cp -r $EXPDIR/RESTART ${EXPDIR}/restarts/RESTART.${edate} cd $EXPDIR/restarts tar cf restarts.${edate}.tar $EXPID.*.${edate}.${GCMVER}.${BCTAG}_${BCRSLV} /bin/rm -rf `/bin/ls -d -1 $EXPID.*.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}` cd $SCRDIR endif ################################################################## ###### ###### Perform multiple iterations of Model Run ###### ################################################################## @ counter = 1 while ( $counter <= ${NUM_SGMT} ) /bin/rm -f EGRESS /bin/cp -f $HOMDIR/CAP.rc . ./strip CAP.rc # Set Time Variables for Current_(c), Ending_(e), and Segment_(s) dates # --------------------------------------------------------------------- set nymdc = `cat cap_restart | cut -c1-8` set nhmsc = `cat cap_restart | cut -c10-15` set nymde = `cat CAP.rc | grep END_DATE: | cut -d: -f2 | cut -c2-9` set nhmse = `cat CAP.rc | grep END_DATE: | cut -d: -f2 | cut -c11-16` set nymds = `cat CAP.rc | grep JOB_SGMT: | cut -d: -f2 | cut -c2-9` set nhmss = `cat CAP.rc | grep JOB_SGMT: | cut -d: -f2 | cut -c11-16` # Compute Time Variables at the Finish_(f) of current segment # ----------------------------------------------------------- set nyear = `echo $nymds | cut -c1-4` set nmonth = `echo $nymds | cut -c5-6` set nday = `echo $nymds | cut -c7-8` set nhour = `echo $nhmss | cut -c1-2` set nminute = `echo $nhmss | cut -c3-4` set nsec = `echo $nhmss | cut -c5-6` @ dt = $nsec + 60 * $nminute + 3600 * $nhour + 86400 * $nday set nymdf = $nymdc set nhmsf = $nhmsc set date = `$GEOSBIN/tick $nymdf $nhmsf $dt` set nymdf = $date[1] set nhmsf = $date[2] set year = `echo $nymdf | cut -c1-4` set month = `echo $nymdf | cut -c5-6` set day = `echo $nymdf | cut -c7-8` @ month = $month + $nmonth while( $month > 12 ) @ month = $month - 12 @ year = $year + 1 end @ year = $year + $nyear @ nymdf = $year * 10000 + $month * 100 + $day if( $nymdf > $nymde ) set nymdf = $nymde if( $nymdf == $nymde ) then if( $nhmsf > $nhmse ) set nhmsf = $nhmse endif set yearc = `echo $nymdc | cut -c1-4` set yearf = `echo $nymdf | cut -c1-4` # For Non-Reynolds SST, Modify local CAP.rc Ending date if Finish time exceeds Current year boundary # -------------------------------------------------------------------------------------------------- if( @OCEANtag != DE0360xPE0180 ) then if( $yearf > $yearc ) then @ yearf = $yearc + 1 @ nymdf = $yearf * 10000 + 0101 set oldstring = `cat CAP.rc | grep END_DATE:` set newstring = "END_DATE: $nymdf $nhmsf" /bin/mv CAP.rc CAP.tmp cat CAP.tmp | sed -e "s?$oldstring?$newstring?g" > CAP.rc endif endif # Select proper MERRA-2 GOCART Emission RC Files # (NOTE: MERRA2-DD has same transition date) # ---------------------------------------------- if( ${EMISSIONS} == MERRA2 | \ ${EMISSIONS} == MERRA2-DD ) then set MERRA2_Transition_Date = 20000401 if( $nymdc < ${MERRA2_Transition_Date} ) then set MERRA2_EMISSIONS_DIRECTORY = $GEOSDIR/$ARCH/etc/$EMISSIONS/19600101-20000331 if( $nymdf > ${MERRA2_Transition_Date} ) then set nymdf = ${MERRA2_Transition_Date} set oldstring = `cat CAP.rc | grep END_DATE:` set newstring = "END_DATE: $nymdf $nhmsf" /bin/mv CAP.rc CAP.tmp cat CAP.tmp | sed -e "s?$oldstring?$newstring?g" > CAP.rc endif else set MERRA2_EMISSIONS_DIRECTORY = $GEOSDIR/$ARCH/etc/$EMISSIONS/20000401-present endif if( $AGCM_LM == 72 ) then /bin/cp --remove-destination ${MERRA2_EMISSIONS_DIRECTORY}/*.rc . else set files = `/bin/ls -1 ${MERRA2_EMISSIONS_DIRECTORY}/*.rc` foreach file ($files) /bin/rm -f `basename $file` /bin/rm -f dummy /bin/cp $file dummy cat dummy | sed -e "s|/L72/|/L${AGCM_LM}/|g" | sed -e "s|z72|z${AGCM_LM}|g" > `basename $file` end endif endif if(-e ExtData.rc ) /bin/rm -f ExtData.rc set extdata_files = `/bin/ls -1 *_ExtData.rc` cat $extdata_files > ExtData.rc # Link Boundary Conditions for Appropriate Date # --------------------------------------------- setenv YEAR $yearc ./linkbcs if (! -e tile.bin) then $RUN_CMD 1 $GEOSBIN/binarytile.x tile.data tile.bin endif # Test Saltwater Restart for Number of tiles correctness # ------------------------------------------------------ if ( -x $GEOSBIN/rs_numtiles.x ) then set N_SALT_TILES_EXPECTED = `grep '^ *0' tile.data | wc -l` set N_SALT_TILES_FOUND = `$RUN_CMD 1 $GEOSBIN/rs_numtiles.x saltwater_internal_rst | grep Total | awk '{print $3}'` if ( $N_SALT_TILES_EXPECTED != $N_SALT_TILES_FOUND ) then echo "Error! Found $N_SALT_TILES_FOUND tiles in saltwater. Expect to find $N_SALT_TILES_EXPECTED tiles." echo "Your restarts are probably for a different ocean." exit 7 endif endif # Environment variables for MPI, etc # ---------------------------------- @SETENVS @GPUSTART # Run GEOSgcm.x # ------------- if( $USE_SHMEM == 1 ) $GEOSBIN/RmShmKeys_sshmpi.csh @ NPES = $NX * $NY $RUN_CMD $NPES ./GEOSgcm.x if( $USE_SHMEM == 1 ) $GEOSBIN/RmShmKeys_sshmpi.csh @GPUEND if( -e EGRESS ) then set rc = 0 else set rc = -1 endif echo GEOSgcm Run Status: $rc ####################################################################### # Rename Final Checkpoints => Restarts for Next Segment and Archive # Note: cap_restart contains the current NYMD and NHMS ####################################################################### set edate = e`cat cap_restart | cut -c1-8`_`cat cap_restart | cut -c10-11`z # Move Intermediate Checkpoints to RESTARTS directory # --------------------------------------------------- /bin/mv -f *_checkpoint.* ${EXPDIR}/restarts # Rename Final Checkpoints for Archive # ------------------------------------ set checkpoints = `/bin/ls -1 *_checkpoint` foreach checkpoint ($checkpoints) set chk_type = `/usr/bin/file -Lb --mime-type $checkpoint` if ( $chk_type =~ "application/octet-stream" ) then set ext = bin else set ext = nc4 endif /bin/mv $checkpoint $EXPID.${checkpoint}.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.$ext $GEOSBIN/stripname _checkpoint _rst $EXPID.${checkpoint}.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.$ext end # Remove Initial RESTARTS # ----------------------- set restarts = `/bin/ls -1 *_rst` /bin/rm $restarts # Copy Renamed Final Checkpoints to RESTARTS directory # ---------------------------------------------------- set restarts = `/bin/ls -1 $EXPID.*_rst.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.*` foreach restart ($restarts) /bin/cp $restart ${EXPDIR}/restarts end # Remove EXPID from RESTART name # ------------------------------ set restarts = `/bin/ls -1 $EXPID.*_rst.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.*` foreach restart ($restarts) $GEOSBIN/stripname $EXPID. '' $restart end # Remove DATE and VERSION Stamps from RESTART name # ------------------------------------------------ set restarts = `/bin/ls -1 *_rst.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.*` foreach restart ($restarts) $GEOSBIN/stripname .${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.\* '' $restart end # TAR ARCHIVED RESTARTS # --------------------- cd $EXPDIR/restarts if( $FSEGMENT == 00000000 ) then tar cf restarts.${edate}.tar $EXPID.*.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.* /bin/rm -rf `/bin/ls -d -1 $EXPID.*.${edate}.${GCMVER}.${BCTAG}_${BCRSLV}.*` endif cd $SCRDIR ####################################################################### # Move HISTORY Files to Holding Directory ####################################################################### # Check for files waiting in /holding # ----------------------------------- set waiting_files = `/bin/ls -1 $EXPDIR/holding/*/*nc4` set num_waiting_files = $#waiting_files # Move current files to /holding # ------------------------------ foreach collection ( $collections ) /bin/mv `/bin/ls -1 *.${collection}.*` $EXPDIR/holding/$collection end >>>COUPLED<<<# MOM-Specific Output Files >>>COUPLED<<<# ------------------------- >>>COUPLED<<< set dsets="ocean_month" >>>COUPLED<<< foreach dset ( $dsets ) >>>COUPLED<<< set num = `/bin/ls -1 $dset.nc | wc -l` >>>COUPLED<<< if($num != 0) then >>>COUPLED<<< if(! -e $EXPDIR/MOM_Output) mkdir -p $EXPDIR/MOM_Output >>>COUPLED<<< /bin/mv $SCRDIR/$dset.nc $EXPDIR/MOM_Output/$dset.${edate}.nc >>>COUPLED<<< endif >>>COUPLED<<< end >>>COUPLED<<< ####################################################################### # Submit Post-Processing and Forecasts ####################################################################### cd $EXPDIR/post foreach collection ( $collections ) # Note: Change $collections to "ALL" to run Single Post Job /bin/rm -f sedfile cat > sedfile << EOF s/@POST_O/gcm_post.${collection}.${edate}/g s/@COLLECTION/$collection/g EOF sed -f sedfile gcm_post.j > gcm_post.jtmp chmod 755 gcm_post.jtmp qsub gcm_post.jtmp /bin/rm -f gcm_post.jtmp /bin/rm -f sedfile sleep 5 end cd $SCRDIR if( $FSEGMENT != 00000000 ) then set REPLAY_BEG_DATE = `grep BEG_REPDATE: $HOMDIR/CAP.rc | cut -d':' -f2` set REPLAY_END_DATE = `grep END_REPDATE: $HOMDIR/CAP.rc | cut -d':' -f2` set nday = `echo $FSEGMENT | cut -c7-8` @ dt = 10800 - 86400 * $nday set date = `$GEOSBIN/tick $nymdc $nhmsc $dt` set nymdz = $date[1] set nhmsz = $date[2] if( $nymdz >= ${REPLAY_BEG_DATE} & \ $nymdz <= ${REPLAY_END_DATE} ) then $EXPDIR/forecasts/gcm_forecast.setup $nymdz $nymdz $FSEGMENT TRUE endif endif ####################################################################### # Update Iteration Counter ####################################################################### set enddate = `echo $END_DATE | cut -c1-8` set capdate = `cat cap_restart | cut -c1-8` if ( $capdate < $enddate ) then @ counter = $counter + 1 else @ counter = ${NUM_SGMT} + 1 endif end ####################################################################### # Re-Submit Job ####################################################################### foreach rst ( `/bin/ls -1 *_rst` ) /bin/rm -f $EXPDIR/$rst end /bin/rm -f $EXPDIR/cap_restart foreach rst ( `/bin/ls -1 *_rst` ) /bin/cp $rst $EXPDIR/$rst & end wait /bin/cp cap_restart $EXPDIR/cap_restart >>>COUPLED<<