#!/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=@CONVERT_T #@CONVERT_P #PBS -N @CONVERT_N #@RUN_Q #@BATCH_GROUP ####################################################################### # System Environment Variables ####################################################################### umask 022 limit stacksize unlimited @SETENVS ####################################################################### # Architecture Specific Environment Variables ####################################################################### setenv ARCH `uname` setenv SITE @SITE setenv GEOSBIN @GEOSBIN setenv RUN_CMD "@RUN_CMD" setenv GCMVER @GCMVER echo "Sourcing g5_modules in $GEOSBIN" source $GEOSBIN/g5_modules >& /dev/null setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${BASEDIR}/${ARCH}/lib ####################################################################### # Experiment Specific Environment Variables ####################################################################### setenv EXPID @EXPID setenv EXPDIR @EXPDIR setenv CNVDIR @CNVDIR setenv HOMDIR @HOMDIR setenv SCRDIR $CNVDIR/scratch setenv ORGDIR $CNVDIR/original_restarts setenv RSTDIR $CNVDIR/converted_restarts ####################################################################### # Create Experiment Sub-Directories ####################################################################### if (! -e $SCRDIR) mkdir -p $SCRDIR if (! -e $RSTDIR) mkdir -p $RSTDIR if (! -e $ORGDIR) mkdir -p $ORGDIR ####################################################################### # Clear Restarts Sub-Directories ####################################################################### /bin/rm -f $RSTDIR/* >& /dev/null /bin/rm -f $ORGDIR/* >& /dev/null ####################################################################### # 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` >>>COUPLED<<>>COUPLED<<>>FVLATLON<<>>FVCUBED<<>>DATAOCEAN<<>>COUPLED<<& /dev/null /bin/ln -sf $EXPDIR/RC/* . /bin/cp -f $HOMDIR/*.rc . if(-e ExtData.rc ) /bin/rm -f ExtData.rc set extdata_files = `/bin/ls -1 *_ExtData.rc` cat $extdata_files > ExtData.rc ####################################################################### # Determine where and what type our restarts are ####################################################################### unsetenv FNDDIR set fv_rst = `cat AGCM.rc | grep "^DYN_INTERNAL_RESTART_FILE" | cut -d ":" -f2` if (-e $CNVDIR/$fv_rst ) then setenv FNDDIR $CNVDIR else if (-e $HOMDIR/$fv_rst ) then setenv FNDDIR $HOMDIR else if (-e $EXPDIR/$fv_rst ) then setenv FNDDIR $EXPDIR endif if ( ! $?FNDDIR ) then echo "Couldn't find a dynamics internal restart file." echo "Note also that this code does not support prefixes to restart file names." exit 4 endif set filetype = `/usr/bin/file -Lb --mime-type $FNDDIR/$fv_rst` set fileext = `echo $fv_rst | tail - -c 5` if ( $filetype =~ "application/x-hdf*" ) then set fromformat = "NetCDF4" set fromtype = "pnc4" set fromext = ".nc4" set toformat = "binary" set totype = "binary" set toext = ".bin" else set fromformat = "binary" set fromtype = "binary" set fromext = ".bin" set toformat = "NetCDF4" set totype = "pnc4" set toext = ".nc4" endif if ( $fileext == "_rst" ) then set fromext = "" endif echo "Found $fromformat $fv_rst in $FNDDIR" echo "Converting from $fromformat restarts to $toformat restarts" ####################################################################### # Copy cap_restart into SCRDIR ####################################################################### echo "Copying cap_restart into $SCRDIR for BCs" if (-e $FNDDIR/cap_restart) then /bin/cp $FNDDIR/cap_restart . else echo "Couldn't find cap_restart in $FNDDIR. Please place" echo "cap_restart in the same directory as the restarts." exit 5 endif ####################################################################### # Link Boundary Datasets ####################################################################### setenv BCSDIR @BCSDIR setenv SSTDIR @SSTDIR setenv CHMDIR @CHMDIR setenv BCRSLV ${ATMOStag}_${OCEANtag} setenv DATELINE DC >>>COUPLED<<>>COUPLED<<>>DATAOCEAN<<>>OSTIA<< $FILE #!/bin/csh -f >>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>DATAOCEAN<<>>FVCUBED<<>>FVCUBED<<>>FVCUBED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>COUPLED<<>>FVCUBED<<>>FVCUBED<<>>FVCUBED<< $FILE EXPID: Convert EXPDSC: Convert restarts COLLECTIONS: :: _EOF_ ####################################################################### # Use sed to alter AGCM.rc to do the conversion ####################################################################### sed -r -i -e "/RESTART_TYPE:/ s/binary|pbinary|pnc4/$fromtype/" \ -e "/CHECKPOINT_TYPE:/ s/binary|pbinary|pnc4/$totype/" \ -e "/NX:/ s/[0-9][0-9]*/@CNV_NX/" \ -e "/NY:/ s/[0-9][0-9]*/@CNV_NY/" \ -e "/AEROCLIM/ d" AGCM.rc # Remove any suffixes # ------------------- sed -r -i -e "/CHECKPOINT_FILE:/ s/.nc4|.bin//" \ -e "/RESTART_FILE:/ s/.nc4|.bin//" AGCM.rc sed -r -i -e "/CHECKPOINT_FILE:/ s#(.*FILE:)(\s*)(.*)#\1\2\3$toext#" AGCM.rc if ( $fromext != "_rst" ) then sed -r -i -e "/RESTART_FILE:/ s/rst/rst$fromext/" AGCM.rc endif sed -r -i -e "/DYCORE: / a DEFAULT_CHECKPOINT_TYPE: $totype" AGCM.rc # Add pluses to files to allow for extra fields (or change - to +) # ---------------------------------------------------------------- #if ( $toformat == "NetCDF4" ) then #sed -r -i -e '/RESTART_FILE:\s*-/ s#(.*FILE:)(\s*)(-)(.*)#\1\2+\4#' \ #-e '/RESTART_FILE:\s*[a-z]/ s#(.*FILE:)(\s*)(.*)#\1\2+\3#' AGCM.rc #endif ####################################################################### # Use sed to restore VEGDYN_INTERNAL_RESTART_TYPE ####################################################################### sed -r -i -e "/VEGDYN_INTERNAL_RESTART_TYPE:/ s/$fromtype/binary/" AGCM.rc # If a plus is added above, we must remove the one on vegdyn # ---------------------------------------------------------- #if ( $toformat == "NetCDF4" ) then #sed -r -i -e '/VEGDYN_INTERNAL_RESTART_FILE:/ s#\+vegdyn#vegdyn#' AGCM.rc #endif ####################################################################### # 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 @ n = 0 set found_rst_files = '' set found_rst_types = '' foreach rst ( $rst_file_names ) @ n = $n + 1 if(-e $FNDDIR/$rst ) then set found_rst_files = `echo $found_rst_files $rst` set found_rst_types = `echo $found_rst_types $rst_files[$n]` endif end ####################################################################### # Copy and Link Restarts for Conversion Run ####################################################################### echo "Copying original restarts into $ORGDIR" foreach rst ( $rst_file_names ) if(-e $FNDDIR/$rst ) then /bin/cp $FNDDIR/$rst $ORGDIR /bin/ln -s $ORGDIR/$rst . endif end /bin/cp $FNDDIR/cap_restart $ORGDIR >>>COUPLED<< $NCPUS ) then echo "CPU Resources are Over-Specified" echo "--------------------------------" echo "Allotted NCPUs: $NCPUS" echo "Specified NX : $NX" echo "Specified NY : $NY" exit 6 endif endif endif ####################################################################### # Testing Saltwater Restart ####################################################################### 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 ################################################################## # Do the conversion with GEOSgcm.x ################################################################## @ NPES = $NX * $NY echo "Running GEOSgcm.x to do the conversion ..." set LOGFILE = "$CNVDIR/GEOSgcm.log" /bin/rm $LOGFILE >& /dev/null # Assume gcm_setup set these properly for the local platform /bin/rm -f EGRESS @SETENVS $RUN_CMD $NPES ./GEOSgcm.x >& $LOGFILE if( -e EGRESS ) then set rc = 0 else set rc = -1 endif if ( $rc != 0 ) then /bin/cat $LOGFILE echo " " echo "GEOSgcm.x failed and returned with exit code $rc" exit $rc else echo "Conversion successful!" endif ####################################################################### # Now copy the checkpoints into $RSTDIR ####################################################################### set numrst = `echo $found_rst_types | wc -w` set numchk = `echo $chk_files | wc -w` @ n = 1 @ z = $numchk + 1 while ( $n <= $numrst ) if ( -e $found_rst_files[$n] ) then @ m = 1 while ( $m <= $numchk ) if( $chk_files[$m] == $found_rst_types[$n] || ) then /bin/mv $chk_file_names[$m] $RSTDIR/$found_rst_files[$n]$toext @ m = $numchk + 999 else @ m = $m + 1 endif end wait if( $m == $z ) then echo "Warning!! Could not find CHECKPOINT/RESTART match for: " $chk_files[$n] exit endif endif @ n = $n + 1 end # Copy over cap_restart as well # ----------------------------- cp cap_restart $RSTDIR/ echo "Converted restarts moved into ${RSTDIR}" exit 0