#! /usr/bin/env bash

#- in order to save disc space, take *.bin files
#- from this dir:
fromDir="../../tutorial_global_oce_latlon/input"

fileList=`( cd $fromDir ; echo bathymetry.bin lev_?.bin )`

#echo 'fileList=' $fileList

#- and do a symbolic link in the current directory
#   (if the file does not already exist)
if test -d $fromDir ; then
  lnkList='files:'
  for xx in $fileList
  do
    if test -r ${fromDir}/$xx ; then
      if test ! -r $xx ; then
        lnkList=${lnkList}" "$xx
        ln -sf ${fromDir}/$xx .
      fi
    fi
  done
  echo ' link' $lnkList "from dir:" $fromDir
else
  echo " Error:" $fromDir "not a directory"
fi

# now link forcing files to yearly names, this is really faking it, since
# we use the same files for 1991 and 1992, but it is just a test after all
fileList="lev_sss.bin lev_sst.bin ncep_emp.bin ncep_qnet.bin trenberth_taux.bin trenberth_tauy.bin"
if test -d $fromDir ; then
  lnkList='files:'
  for xx in $fileList
  do
    if test -r ${fromDir}/$xx ; then
      if test ! -r ${xx}_1991 ; then
        lnkList=${lnkList}" "${xx}_1991
        ln -sf ${fromDir}/$xx ./${xx}_1991
      fi
      if test ! -r ${xx}_1992 ; then
        lnkList=${lnkList}" "${xx}_1992
        ln -sf ${fromDir}/${xx} ./${xx}_1992
      fi
    fi
  done
  echo ' link' $lnkList "from dir:" $fromDir
else
  echo " Error:" $fromDir "not a directory"
fi
