#!/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 # # +-======-+ @ nmax = $#argv # Usage # ----- if( $nmax == 0 ) then echo " " echo "Usage -- To regrid MERRA restarts:" echo "----------------------------------" echo "regrid -nymd YYYYMMDD " echo " -im IM " echo " -jm JM " echo " -out DIRECTORY " echo " " echo " where: YYYYMMDD is the desired Date from the MERRA Re-Analysis" echo " IM is the desired Zonal Dimension for ReGridding" echo " JM is the desired Meridional Dimension for ReGridding" echo " DIRECTORY is the full pathname of the desired OUTPUT location" echo " " echo " ( Note: A regrid.rc file will be automatically generated )" echo " " echo " " echo "Usage -- To regrid Non-MERRA restarts:" echo "--------------------------------------" echo "regrid -rc REGRIDRC " echo " -out DIRECTORY " echo " " echo " where: REGRIDRC is the full pathname of a user-defined regrid.rc file" echo " DIRECTORY is the full pathname of the desired OUTPUT location" echo " " exit 1 endif # Process Input String # -------------------- set regridrc = NULL set nymd = NULL set im = NULL set jm = NULL set OUTDIR = NULL @ n = 1 while( $n <= $nmax ) if( "$argv[$n]" == "-rc" ) then @ n = $n + 1 set regridrc = $argv[$n] endif if( "$argv[$n]" == "-nymd" ) then @ n = $n + 1 set nymd = $argv[$n] endif if( "$argv[$n]" == "-im" ) then @ n = $n + 1 set im = $argv[$n] endif if( "$argv[$n]" == "-jm" ) then @ n = $n + 1 set jm = $argv[$n] endif if( "$argv[$n]" == "-out" ) then @ n = $n + 1 set OUTDIR = $argv[$n] endif @ n = $n + 1 end if( $regridrc != NULL && $nymd != NULL ) then echo " " echo You must only choose ONE method: -rc or -nymd \! echo " " exit endif if( $nymd != NULL && ( $im == NULL | $jm == NULL) ) then echo " " echo You must set Horizontal Dimension: IM \& JM \! echo " " exit endif if( $OUTDIR == NULL ) then echo " " echo You must define an OUTPUT directory \! echo " " exit endif set datetime = `date +%Y%m%d_%H%M%S` set OUTPUT = $OUTDIR/$datetime if(! -e $OUTPUT ) mkdir -p $OUTPUT # Find location of regrid utility # ------------------------------- set REGRID = `which $0` set root = `echo $REGRID | cut -d / -f1` if($root == . ) set REGRID = `echo $cwd`/regrid # Set GEOS Directories # -------------------- @ n = 1 set root = `echo $REGRID | cut -d"/" -f$n` while( .$root == . ) @ n = $n + 1 set root = `echo $REGRID | cut -d"/" -f$n` end setenv ESMADIR '' while( $root != 'src' ) setenv ESMADIR `echo ${ESMADIR}/${root}` @ n = $n + 1 set root = `echo $REGRID | cut -d / -f$n` end set GEOSSRC = $ESMADIR/src set GEOSUTIL = $GEOSSRC/GMAO_Shared/GEOS_Util set MK_RST = $GEOSSRC/GEOSgcs_GridComp/GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/GEOScatch_GridComp/mk_restarts # Get MERRA Data # -------------- if( $nymd != NULL ) then set year = `echo $nymd | cut -c1-4` set month = `echo $nymd | cut -c5-6` set day = `echo $nymd | cut -c7-8` if( $year < 1979 ) then echo " " echo Data is not available before 1979 \! echo " " exit else if ($year < 1989 ) then set archive = /archive/g_proj5/production/GEOSdas-2_1_4/d5_merra_jan79/rs/Y$year/M$month set stream = d5_merra_jan79 else if ($year < 1998 ) then set archive = /archive/g_proj5/production/GEOSdas-2_1_4/d5_merra_jan89/rs/Y$year/M$month set stream = d5_merra_jan89 else set archive = /archive/g_proj5/production/GEOSdas-2_1_4/d5_merra_jan98/rs/Y$year/M$month set stream = d5_merra_jan98 endif set files = `echo fvcore_internal_rst moist_internal_rst catch_internal_rst lake_internal_rst landice_internal_rst saltwater_internal_rst agcm_import_rst pchem_internal_rst` set found = true foreach file ($files) if(! -e $archive/$stream.$file.${nymd}_21z.bin ) set found = false end if( $found == false ) then echo " " echo Date: $nymd is not available \! echo " " echo Available Nearby Dates: set date = `$GEOSUTIL/post/tick $nymd 210000 -864000` set nymd = $date[1] @ NDAY = 1 while( $NDAY <= 21 ) set year = `echo $nymd | cut -c1-4` set month = `echo $nymd | cut -c5-6` set day = `echo $nymd | cut -c7-8` if( $year >= 1979 ) then if ($year < 1989 ) then set archive = /archive/g_proj5/production/GEOSdas-2_1_4/d5_merra_jan79/rs/Y$year/M$month set stream = d5_merra_jan79 else if ($year < 1998 ) then set archive = /archive/g_proj5/production/GEOSdas-2_1_4/d5_merra_jan89/rs/Y$year/M$month set stream = d5_merra_jan89 else set archive = /archive/g_proj5/production/GEOSdas-2_1_4/d5_merra_jan98/rs/Y$year/M$month set stream = d5_merra_jan98 endif set files = `echo fvcore_internal_rst moist_internal_rst catch_internal_rst lake_internal_rst landice_internal_rst saltwater_internal_rst` set found = true foreach file ($files) if(! -e $archive/$stream.$file.${nymd}_21z.bin ) set found = false end endif if( $found == true ) echo " $nymd 210000" set date = `$GEOSUTIL/post/tick $nymd 210000 86400` set nymd = $date[1] @ NDAY = $NDAY + 1 end echo " " exit else echo " " echo "Getting MERRA Data ... " foreach file ($files) dmget $archive/$stream.$file.${nymd}_21z.bin & end wait echo "Done." endif /bin/cp $GEOSUTIL/post/regrid.rc $OUTPUT/regrid.tmpl /bin/rm -f $OUTPUT/sedfile /bin/rm -f $OUTPUT/regrid.rc cat > $OUTPUT/sedfile << EOF s?@BC_TAG?Fortuna-1_4?g s?@IM_OLD?540?g s?@JM_OLD?361?g s?@DYN_INTERNAL_RESTART_FILE?$archive/$stream.fvcore_internal_rst.${nymd}_21z.bin?g s?@MOIST_INTERNAL_RESTART_FILE?$archive/$stream.moist_internal_rst.${nymd}_21z.bin?g s?@CATCH_INTERNAL_RESTART_FILE?$archive/$stream.catch_internal_rst.${nymd}_21z.bin?g s?@LAKE_INTERNAL_RESTART_FILE?$archive/$stream.lake_internal_rst.${nymd}_21z.bin?g s?@LANDICE_INTERNAL_RESTART_FILE?$archive/$stream.landice_internal_rst.${nymd}_21z.bin?g s?@SALTWATER_INTERNAL_RESTART_FILE?$archive/$stream.saltwater_internal_rst.${nymd}_21z.bin?g s?@AGCM_IMPORT_RESTART_FILE?$archive/$stream.agcm_import_rst.${nymd}_21z.bin?g s?@PCHEM_INTERNAL_RESTART_FILE?$archive/$stream.pchem_internal_rst.${nymd}_21z.bin?g s?@GOCART_INTERNAL_RESTART_FILE??g s?@IM_NEW?$im?g s?@JM_NEW?$jm?g EOF sed -f $OUTPUT/sedfile $OUTPUT/regrid.tmpl > $OUTPUT/regrid.rc /bin/rm -f $OUTPUT/sedfile /bin/rm -f $OUTPUT/regrid.tmpl set regridrc = $OUTPUT/regrid.rc endif # Read regrid.rc variables # ------------------------ set BC_TAG = `grep BC_TAG: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set IM_OLD = `grep IM_OLD: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set JM_OLD = `grep JM_OLD: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set DYN = `grep DYN_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set MOIST = `grep MOIST_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set CATCH = `grep CATCH_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set LAKE = `grep LAKE_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set LANDICE = `grep LANDICE_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set SALT = `grep SALTWATER_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set AGCM = `grep AGCM_IMPORT_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set PCHEM = `grep PCHEM_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set GOCART = `grep GOCART_INTERNAL_RESTART_FILE: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set IM_NEW = `grep IM_NEW: $regridrc | cut -d'#' -f1 | cut -d':' -f2` set JM_NEW = `grep JM_NEW: $regridrc | cut -d'#' -f1 | cut -d':' -f2` # Check for completeness # ---------------------- set NOGO = FALSE if( .$BC_TAG == . ) then echo You must supply the INPUT boundary condition tag: BC_TAG set NOGO = TRUE endif if( .$IM_OLD == . ) then echo You must supply the INPUT zonal dimension: IM_OLD set NOGO = TRUE endif if( .$JM_OLD == . ) then echo You must supply the INPUT meridional dimension: JM_OLD set NOGO = TRUE endif if( .$DYN == . ) then echo You must supply the INPUT: DYN_INTERNAL_RESTART_FILE set NOGO = TRUE endif if( .$MOIST == . ) then echo You must supply the INPUT: MOIST_INTERNAL_RESTART_FILE set NOGO = TRUE endif if( .$CATCH == . ) then echo You must supply the INPUT: CATCH_INTERNAL_RESTART_FILE set NOGO = TRUE endif if( .$LAKE == . ) then echo You must supply the INPUT: LAKE_INTERNAL_RESTART_FILE set NOGO = TRUE endif if( .$LANDICE == . ) then echo You must supply the INPUT: LANDICE_INTERNAL_RESTART_FILE set NOGO = TRUE endif if( .$SALT == . ) then echo You must supply the INPUT: SALT_INTERNAL_RESTART_FILE set NOGO = TRUE endif if( .$IM_NEW == . ) then echo You must supply the OUTPUT zonal dimension: IM_NEW set NOGO = TRUE endif if( .$JM_NEW == . ) then echo You must supply the OUTPUT meridional dimension: JM_NEW set NOGO = TRUE endif if( $NOGO == TRUE ) exit set RSLV_OLD = ${IM_OLD}x${JM_OLD} set RSLV_NEW = ${IM_NEW}x${JM_NEW} set BCS_OLD = /discover/nobackup/ltakacs/bcs/$BC_TAG/$RSLV_OLD set BCS_NEW = /discover/nobackup/ltakacs/bcs/Fortuna-2_1/$RSLV_NEW set TOPO_OLD = $BCS_OLD/topo_DYN_ave_${RSLV_OLD}_DC.data set TOPO_NEW = $BCS_NEW/topo_DYN_ave_${RSLV_NEW}_DC.data set TILE_OLD = $BCS_OLD/FV_${RSLV_OLD}_DC_360x180_DE.til set TILE_NEW = $BCS_NEW/FV_${RSLV_NEW}_DC_360x180_DE.til cd $OUTPUT set files = `/bin/ls -1 $DYN $MOIST $AGCM $PCHEM $GOCART $CATCH $LAKE $LANDICE $SALT` foreach file ($files) if( -e `basename $file` ) /bin/rm -f `basename $file` end set files = `/bin/ls -1 $DYN $MOIST $AGCM $PCHEM $GOCART` foreach file ($files) /bin/cp $file . end set DYN = `basename $DYN` set MOIST = `basename $MOIST` if( .$AGCM != . ) set AGCM = `basename $AGCM` if( .$PCHEM != . ) set PCHEM = `basename $PCHEM` if( .$GOCART != . ) set GOCART = `basename $GOCART` if(! -e $GEOSUTIL/post/rs_hinterp.x ) then cd $GEOSUTIL/post gmake install rs_hinterp.x rehash cd $OUTPUT endif $GEOSUTIL/post/rs_hinterp.x -dyn $DYN \ -moist $MOIST \ -topo_old $TOPO_OLD \ -topo_new $TOPO_NEW \ -im $IM_NEW -jm $JM_NEW \ -other $AGCM $PCHEM $GOCART set files = `/bin/ls -1 $DYN $MOIST $AGCM $PCHEM $GOCART` foreach file ($files) if( -e $file ) /bin/rm -f $file end # LAND Regridding # --------------- mkdir land cd land /bin/cp -r $MK_RST . cd mk_restarts/InData set files = `/bin/ls -1 | grep -v CVS | grep -v README` foreach file ($files) /bin/rm -f $file end /bin/ln -s $TILE_OLD . /bin/cp $CATCH . /bin/cp $LAKE . /bin/cp $LANDICE . /bin/cp $SALT . cd ../OutData set files = `/bin/ls -1 | grep -v CVS | grep -v README` foreach file ($files) /bin/rm -f $file end if( -e clsm ) /bin/rm -r clsm /bin/ln -s $TILE_NEW . /bin/ln -s $BCS_NEW/clsm . cd ../ ./mk_Restarts cd OutData set CATCH = `basename $CATCH` set LAKE = `basename $LAKE` set LANDICE = `basename $LANDICE` set SALT = `basename $SALT` set IM = $IM_NEW if( $IM < 1000 ) set IM = 0$IM if( $IM < 100 ) set IM = 0$IM set JM = $JM_NEW if( $JM < 1000 ) set JM = 0$JM if( $JM < 100 ) set JM = 0$JM /bin/mv $CATCH $OUTPUT/$CATCH.${IM}x${JM} /bin/mv $LAKE $OUTPUT/$LAKE.${IM}x${JM} /bin/mv $LANDICE $OUTPUT/$LANDICE.${IM}x${JM} /bin/mv $SALT $OUTPUT/$SALT.${IM}x${JM} cd $OUTPUT /bin/rm -r land /bin/mv *${IM}x${JM} $OUTDIR /bin/mv regrid.rc $OUTDIR cd $OUTDIR /bin/rm -r $OUTPUT