#!/bin/csh -f


# Set and Echo Variables
# ----------------------
set arch  = `uname`
set host  = `hostname`
set cdir  = `pwd`

set name  = `echo $host`; if ( ($name =~ pfe*) || ($name =~ r[0-9]*i[0-9]*n[0-9]*) ) set host = pleiades

set name  = `echo $host | cut -b 1-8` ; if( $name == 'discover' ) set host = $name
set name  = `echo $host | cut -b 1-3` ; if( $name == 'vis'      ) set host = discover
set name  = `echo $host | cut -b 1-4` ; if( $name == 'borg'     ) set host = discover
set name  = `echo $host | cut -b 1-4` ; if( $name == 'warp'     ) set host = discover
set name  = `echo $host | cut -b 1-4` ; if( $name == 'dali'     ) set host = discover

if( $arch == 'Linux'    ) then
    if( $host == 'pleiades' ) then
                              setenv TOPODIR      /nobackup/gmao_SIteam/ModelData/bcs/Ganymed-4_0/TOPO
                              setenv VERIFICATION /nobackup/gmao_SIteam/ModelData/verification
                              setenv OPENGADIR    /nobackup/gmao_SIteam/Utilities/opengrads/Contents
                              setenv GAVERSION    2.0.1.oga.1
                              setenv GRADS_LOC    ${OPENGADIR}

                              setenv PATH         ${OPENGADIR}:${PATH}
                              set    path =     ( ${OPENGADIR} ${path} )
                              setenv GRADS      `which grads`
                              setenv GXYAT      `which gxyat`

                              setenv ImagMag_bin  /nasa/pkgsrc/sles12/2016Q4/bin
                              setenv PATH         ${PATH}:${ImagMag_bin}
                              set    path =     ( ${path} ${ImagMag_bin} )
    else if( $host == 'discover' ) then
                              setenv TOPODIR      /discover/nobackup/ltakacs/bcs/Ganymed-4_0/TOPO
                              setenv NCCS_SHARE   ${SHARE}/gmao_ops/
                              setenv VERIFICATION ${NCCS_SHARE}/verification
                              setenv OPENGADIR    ${SHARE}/gmao_ops/opengrads/Contents
                              setenv GAVERSION    2.0.1.oga.1
                              setenv GRADS_LOC    ${OPENGADIR}

                              setenv PATH         ${OPENGADIR}:${PATH}
                              set    path =     ( ${OPENGADIR} ${path} )
                              setenv GRADS      `which grads`
                              setenv GXYAT      `which gxyat`

                              setenv ImagMag_bin  ${NCCS_SHARE}/bin
                              setenv PATH         ${PATH}:${ImagMag_bin}
                              set    path =     ( ${path} ${ImagMag_bin} )
    else
                              # Here we assume GEOS-5 desktop. These edits are mainly to enable use of the
                              # dc script to view native cube-sphere output. They do not enable the complete
                              # plotting package of GEOS-5.

                              setenv TOPODIR      /ford1/share/gmao_SIteam/ModelData/bcs/Ganymed-4_0/TOPO
                              setenv VERIFICATION /ford1/share/gmao_SIteam/ModelData/verification # Note: A dead link, but needed
                              setenv OPENGADIR    /ford1/local/opengrads/Contents/opengrads
                              setenv GRADS_LOC    ${OPENGADIR}
                           
                              setenv PATH         ${OPENGADIR}:${PATH}
                              set    path =     ( ${OPENGADIR} ${path} )
                              setenv GRADS      `which grads`
                              setenv GXYAT      `which gxyat`

                              # For ImageMagick, assume any desktop will have it. If not, GMAO Support
                              # can install it

    endif
endif


# Set GRADS Environment Variables
# -------------------------------
setenv  GEOSUTIL @CMAKE_INSTALL_PREFIX@
setenv  GASCRP $GEOSUTIL/plots/grads_util
setenv  GAUDFT $GEOSUTIL/plots/grads_util/udft_$arch.tools
setenv  GAUDXT $GEOSUTIL/plots/grads_util/udxt

if(! -e $GAUDFT) then
set SEDFILE=`mktemp`
cat > $SEDFILE << EOF
s?GEOSUTIL?$GEOSUTIL?g
s?ARCH?$arch?g
EOF
sed -f $SEDFILE $GASCRP/udft.template > $GAUDFT
endif

# Link VERIFICATION Directories
# -----------------------------------------------------------------------------------

# VERIFICATION.SRB
# ---------------------
set dirs = `echo olrc olrcf radnetg radnetgc radswt tpw cldtt albedo             \
            lwgnet lwgnetc lwgnetcf lwgup lwgupc lwgupcf lwgdwn lwgdwnc lwgdwncf \
            swgnet swgnetc swgnetcf swgup swgupc swgupcf swgdwn swgdwnc swgdwncf `
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.SRB.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.SRB.rc  .
end

# VERIFICATION.ERBE
# ----------------------
set dirs = `echo osr osrc osrcf olr olrc olrcf nettoa nettoac toacf`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.ERBE.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.ERBE.rc  .
end

# VERIFICATION.CERES_EBAF-TOA_Ed4.0
# --------------------------------------
set dirs = `echo toacf tseries osrcf osrc osr radswt olrc olr olrcf nettoac nettoa`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.CERES_EBAF-TOA_Ed4.0.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.CERES_EBAF-TOA_Ed4.0.rc  .
end

# VERIFICATION.CERES_EBAF
# -----------------------
set dirs = `echo toacf olrc olrcf nettoac tseries nettoa olr osrcf osrc osr radswt`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.CERES_EBAF.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.CERES_EBAF.rc  .
end

# VERIFICATION.COADS
# -----------------------
set dirs = `echo emp speed eflux hflux cldtt taux tauy`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.COADS.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.COADS.rc  .
end

# VERIFICATION.ISCCP
# -----------------------
set dirs = `echo cldhi cldlo cldmd cldtt`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.ISCCP.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.ISCCP.rc  .
end

# VERIFICATION.GSSTF
# -----------------------
set dirs = `echo eflux hflux speed taux tauy tpw`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.GSSTF.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.GSSTF.rc  .
end

# VERIFICATION.ECINTERIM
# ---------------------------
set dirs = `echo hcmp lcmp zcmp zcmp1 tseries precip`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.ECINTERIM.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.ECINTERIM.rc  .
end

# VERIFICATION.ECANA
# -----------------------
set dirs = `echo hcmp lcmp zcmp`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.ECANA.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.ECANA.rc  .
end

# VERIFICATION.ERA5
# ----------------------
set dirs = `echo lwgdwnc lwgdwn lwgnetc lwgnet lwgupc lwgup \
                 swgdwnc swgdwn swgnetc swgnet swgupc swgup \
                 precipcn precipls precip `
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.ERA5.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.ERA5.rc  .
end

# VERIFICATION.GDAS1
# -----------------------
set dirs = `echo hcmp lcmp zcmp`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.GDAS1.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.GDAS1.rc  .
end

# VERIFICATION.NCEP
# ----------------------
set dirs = `echo hcmp lcmp zcmp`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.NCEP.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.NCEP.rc  .
end

# VERIFICATION.GPCP
# ----------------------
set dirs = `echo precip tseries`
foreach dir ($dirs)
cd $GEOSUTIL/plots/$dir
if (! -l VERIFICATION.GPCP.rc) /bin/ln -sf  ../VERIFICATION_RCS/VERIFICATION.GPCP.rc  .
end


# Link Radiation Directories for 5% Cloud-Cleared (cc5) Diagnostics
# -----------------------------------------------------------------------------------
cd $GEOSUTIL/plots
if(! -e lwgupcf_cc5  ) /bin/ln -sf lwgupcf lwgupcf_cc5
if(! -e lwgupc_cc5   ) /bin/ln -sf lwgupc lwgupc_cc5
if(! -e lwgnetcf_cc5 ) /bin/ln -sf lwgnetcf lwgnetcf_cc5
if(! -e lwgnetc_cc5  ) /bin/ln -sf lwgnetc lwgnetc_cc5
if(! -e lwgdwncf_cc5 ) /bin/ln -sf lwgdwncf lwgdwncf_cc5
if(! -e lwgdwnc_cc5  ) /bin/ln -sf lwgdwnc lwgdwnc_cc5
if(! -e olrcf_cc5    ) /bin/ln -sf olrcf olrcf_cc5
if(! -e olrc_cc5     ) /bin/ln -sf olrc olrc_cc5
if(! -e nettoac_cc5  ) /bin/ln -sf nettoac nettoac_cc5
if(! -e toacf_cc5    ) /bin/ln -sf toacf toacf_cc5


# Link Cubed-Sphere FRAC Dataset for dc.gs Utility and CONST_2d Dataset for TopoShade
# -----------------------------------------------------------------------------------
cd $GEOSUTIL/plots/grads_util
if(! -l FRAC_720x4320.nc4)      /bin/ln -sf $TOPODIR/TOPO_CF0720x6C/FRAC_720x4320.nc4 .
if(! -l CONST_2D.2880x1441.nc4) /bin/ln -sf $TOPODIR/TOPO_CF0720x6C/CONST_2D.2880x1441.nc4 .
if(! -l CONST_2D.5760x2881.nc4) /bin/ln -sf $TOPODIR/TOPO_CF1440x6C/CONST_2D.5760x2881.nc4 .
cd $cdir

# Create .cshrc for QuickPlot (Note: unsetenv GAUDXT to removed Arlindo Setup Conflicts)
# --------------------------------------------------------------------------------------
#if( -e .quickplotrc ) /bin/rm .quickplotrc
echo \#\!/bin/csh                                                >  .quickplotrc
echo   setenv VERIFICATION $VERIFICATION                         >> .quickplotrc
echo   setenv LOCHOST $host                                      >> .quickplotrc
echo   setenv GRADS  $GRADS                                      >> .quickplotrc
echo   setenv GXYAT  $GXYAT                                      >> .quickplotrc
echo   setenv GASCRP $GASCRP                                     >> .quickplotrc
echo   setenv GAUDFT $GAUDFT                                     >> .quickplotrc
echo   setenv GAUDXT $GAUDXT                                     >> .quickplotrc
if ( $?GAVERSION ) then
 echo  setenv GAVERSION $GAVERSION                               >> .quickplotrc
endif
echo   "  "                                                      >> .quickplotrc
echo "set path = ( $path $GRADS_LOC $GASCRP )"                   >> .quickplotrc

chmod 755 .quickplotrc
source ./.quickplotrc
