Setting up Environment for AGCM Sandbox

From GEOS-5
Jump to navigation Jump to search

Given the large number of directories in the GEOS5 agcm model it can be useful to set up your environment to make navigating your sandbox easier. This page will document one way of doing this. This is especially useful if you have multiple copies of the GEOS5 model that you might have checked out (a stable release and your development sandbox for example). This method assumes you have checked out a copy of the model previously and you are running c shell. This method also assumes that all of your models are kept in the same parent directory and that the GEOSagcm directory is itself inside another folder. For example you if you have 2 models on discover at NCCS they would need to be organized as:

/discover/nobackup/username/models/model1/GEOSagcm
/discover/nobackup/username/models/model2/GEOSagcm


You will need two files in your home directory or somewhere else in your path. First is geostagx, shown below. You will need to set the MODELDIR variable in this script to where ever you have chosen to keep your models.

 
#!/bin/tcsh -f

set BLACK   = "\033[30m"
set RED     = "\033[31m"
set GREEN   = "\033[32m"
set YELLOW  = "\033[33m"
set BLUE    = "\033[34m"
set MAGENTA = "\033[35m"
set CYAN    = "\033[36m"
set WHITE   = "\033[37m"
set RESET   = "\033[0m"
set BOLD    = "\033[1m"
set COLORS  = `echo $BLACK $RED $GREEN $YELLOW $BLUE $MAGENTA $CYAN $WHITE $RESET`


set C1 = $RED
set C2 = $BLUE
set CN = $RESET

set MODELDIR = /discover/swdev/username/models
# Create ~/.geostag for modules and aliases
# Note:  Variable GEOSTAG will point to the directory from CVS containing: src
# ----------------------------------------------------------------------------
if( .$1 == . ) then
     if( -e ~/.geostag ) then
          set dummy = `grep ESMADIR ~/.geostag | cut -d" " -f3`
#         echo " "
#         echo "Enter GEOSTAG: $dummy (Default)"
#         set tag = $<
#         if( .$tag == . ) set tag = $dummy
#         echo " "

          set items = `/bin/ls -1 $MODELDIR`
          set tags  = ''
          foreach item ($items)
             if( -d $MODELDIR/$item ) then
             if( -e $MODELDIR/$item/GEOSagcm ) set tags = `echo $tags $MODELDIR/$item/GEOSagcm`
             endif
          end
          if( $#tags != 0 ) then
              echo " "
              echo "Enter GEOSTAG Index to use:"
              echo "---------------------------"
              @ n = 0
              foreach tag ($tags)
              @ n = $n + 1
                if( $tag == $dummy ) then
                   @ ndum = $n
                    echo ${C1}"   $n  $tag (Current)"${CN}
                else
                    echo "   $n  $tag"
                endif
              end
              set tag_index = $<
              if( .$tag_index == . ) then
                   set tag_index = $ndum
              endif
              set tag       = $tags[$tag_index]
          else
              echo " "
              echo "Enter GEOSTAG: "
              set tag = $<
          endif
     else
          set items = `/bin/ls -1 $MODELDIR`
          set tags  = ''
          foreach item ($items)
             if( -d $MODELDIR/$item ) then
             if( -e $MODELDIR/$item/GEOSagcm ) set tags = `echo $tags $MODELDIR/$item/GEOSagcm`
             endif
          end
          if( $#tags != 0 ) then
HERE:
              echo " "
              echo "Enter GEOSTAG Index to use:"
              echo "---------------------------"
              @ n = 0
              foreach tag ($tags)
              @ n = $n + 1
              echo "   $n  $tag"
              end
              set tag_index = $<
              if( .$tag_index == . ) GOTO HERE
              set tag       = $tags[$tag_index]
              set tag       = $tags[$tag_index]
          else
              echo " "
              echo "Enter GEOSTAG: "
              set tag = $<
          endif
     endif
else
          set tag = $1
endif

     if(             -e $tag/src           ) then
                                             set dummy = $tag
else if(             -e $tag/GEOSagcm/src  ) then
                                             set dummy = $tag/GEOSagcm
else
           echo " "
           echo \!\!\! Note:  geostag not executed.
           echo \!\!\! Note:  GEOSTAG should point to the model directory which contains: src
           echo " "
           exit
endif

if( -e ~/.geostag ) /bin/rm ~/.geostag
echo \#\!/bin/csh -f                                         >  ~/.geostag
echo                        setenv ESMADIR $dummy            >> ~/.geostag

chmod 755 ~/.geostag

Next is g5env

#!/bin/csh -f

set arch = `uname`

echo ARCH: $arch
# Aliases for GEOS GCM Directories
# --------------------------------
if( $?prompt ) then
echo " "
echo "Creating GEOSGCM aliases ..."
echo "         ESMADIR: $ESMADIR"
set sources =     `find $ESMADIR -name src                     | grep -v $arch`
alias src     "cd $sources[1]"
alias gcm     "cd `find $ESMADIR -name GEOSgcm_GridComp        | grep -v $arch`"
alias iau     "cd `find $ESMADIR -name GEOSmkiau_GridComp      | grep -v $arch`"
alias shared  "cd `find $ESMADIR -name GEOS_Shared             | grep -v $arch`"
alias gfio    "cd `find $ESMADIR -name GMAO_gfio               | grep -v $arch`"
alias cshared "cd `find $ESMADIR -name Chem_Shared             | grep -v $arch`"
alias hermes  "cd `find $ESMADIR -name GMAO_hermes             | grep -v $arch`"
alias base    "cd `find $ESMADIR -name GEOS_Base               | grep -v $arch`"
alias cbase   "cd `find $ESMADIR -name Chem_Base               | grep -v $arch`"
alias util    "cd `find $ESMADIR -name GEOS_Util               | grep -v $arch`"
alias post    "cd `find $ESMADIR -name post                    | grep -v $arch`"
alias plots   "cd `find $ESMADIR -name plots                   | grep -v $arch`"
alias pilgrim "cd `find $ESMADIR -name GMAO_pilgrim            | grep -v $arch`"
alias agcm    "cd `find $ESMADIR -name GEOSagcm_GridComp       | grep -v $arch`"
alias ogcm    "cd `find $ESMADIR -name GEOSogcm_GridComp       | grep -v $arch`"
alias phys    "cd `find $ESMADIR -name GEOSphysics_GridComp    | grep -v $arch`"
alias dyn     "cd `find $ESMADIR -name GEOSsuperdyn_GridComp   | grep -v $arch`"
alias sdyn    "cd `find $ESMADIR -name GEOSsuperdyn_GridComp   | grep -v $arch`"
alias fv      "cd `find $ESMADIR -name FVdycore_GridComp       | grep -v $arch`"
alias fv3     "cd `find $ESMADIR -name FVdycoreCubed_GridComp  | grep -v $arch`"
alias aries   "cd `find $ESMADIR -name ARIESg3_GridComp        | grep -v $arch`"
alias gwd     "cd `find $ESMADIR -name GEOSgwd_GridComp        | grep -v $arch`"
alias surf    "cd `find $ESMADIR -name GEOSsurface_GridComp    | grep -v $arch`"
alias turb    "cd `find $ESMADIR -name GEOSturbulence_GridComp | grep -v $arch`"
alias rad     "cd `find $ESMADIR -name GEOSradiation_GridComp  | grep -v $arch`"
alias satsim  "cd `find $ESMADIR -name GEOSsatsim_GridComp     | grep -v $arch`"
alias solar   "cd `find $ESMADIR -name GEOSsolar_GridComp      | grep -v $arch`"
alias irrad   "cd `find $ESMADIR -name GEOSirrad_GridComp      | grep -v $arch`"
alias moist   "cd `find $ESMADIR -name GEOSmoist_GridComp      | grep -v $arch`"
alias gmi     "cd `find $ESMADIR -name GMIchem_GridComp        | grep -v $arch`"
alias chem    "cd `find $ESMADIR -name GEOSchem_GridComp       | grep -v $arch`"
alias gaas    "cd `find $ESMADIR -name GAAS_GridComp           | grep -v $arch`"
alias pchem   "cd `find $ESMADIR -name GEOSpchem_GridComp      | grep -v $arch`"
alias gocart  "cd `find $ESMADIR -name GOCART_GridComp         | grep -v $arch`"
alias carma   "cd `find $ESMADIR -name CARMAchem_GridComp      | grep -v $arch`"
alias land    "cd `find $ESMADIR -name GEOSland_GridComp       | grep -v $arch`"
alias lake    "cd `find $ESMADIR -name GEOSlake_GridComp       | grep -v $arch`"
alias landice "cd `find $ESMADIR -name GEOSlandice_GridComp    | grep -v $arch`"
alias salt    "cd `find $ESMADIR -name GEOSsaltwater_GridComp  | grep -v $arch`"
alias catch   "cd `find $ESMADIR -name GEOScatch_GridComp      | grep -v $arch`"
alias mapl    "cd `find $ESMADIR -name MAPL_Base               | grep -v $arch`"

alias appl    "cd `find_dir GEOSgcm_App     Application`"
endif

# Set ESMADIR and Module Environment
# ----------------------------------
echo ""
source $ESMADIR/src/g5_modules

setenv         GEOSUTIL $ESMADIR/src/GMAO_Shared/GEOS_Util
setenv GASCRP $GEOSUTIL/plots/grads_util
setenv GAUDFT $GEOSUTIL/plots/grads_util/udft_$arch.tools
setenv GADDIR /discover/nobackup/projects/gmao/share/dao_ops/opengrads/dat/

# Set alias for hdfdump
# ---------------------
if( -e $BASEDIR/$arch/bin/hdfdump ) then
        alias hdfdump '$BASEDIR/$arch/bin/hdfdump'
else
        alias hdfdump '$BASEDIR/$arch/bin/ncdump'
endif

set path = (~/bin/$arch $BASEDIR/$arch/bin $path)
unsetenv LD_LIBRARY_PATH
  setenv LD_LIBRARY_PATH ${LIBRARY_PATH}:${BASEDIR}/${arch}/lib

# Echo Results
# ------------
echo ""
echo " BASEDIR: $BASEDIR"
echo ""
echo " ESMADIR: $ESMADIR"
echo "GEOSUTIL: $GEOSUTIL"
echo ""
module list
echo ""

Finally you will need an alias in your run script to souce these files. Here I have chosen to call the alias geostag

alias geostag 'geostagx \!* ; source ~/.geostag ; source ~/g5env'

When you execute the alias geostag it will source geostagx and g5env. Geostagx will search the model directory for all the occurences of $MODELDIR/*/GEOSagcm, list these directories in a numbered list and ask the user to select one. Once the user has make their choice the geostagx sets the $ESMADIR enviroment variable for that particular sandbox. It will also write the value of the $ESMADIR variable to a .geostag file in the users home directory. If the .geostag file already exists that model will be shown in a different color when running geostagx. Next the g5env file will be sourced. Sourcing this will source the g5_modules file on for the sandbox you have chosen and set aliases to various directories within the model. For example now to get to the MAPL_Base directory you simply have to type mapl.