#! /usr/bin/env bash

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

fileList=`( cd $fromDir ; ls grid_cs32.face00?.bin )`
#echo 'fileList=' $fileList

#- from this dir:

#- 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

#- in order to save disc space, un-gzip files
#- from this dir:
fromDir="../input.viscA4"

fileList=`( cd $fromDir ; echo *.gz | sed 's/\.gz//g' )`
#echo 'fileList=' $fileList

#- copy the gz file in the current directory and unzip
#   (if the file does not already exist)
if test -d $fromDir ; then
  lnkList=''
  for xx in $fileList
  do
    if test -r ${xx}.gz ; then
      if test ! -r $xx -o $xx -ot ${xx}.gz ; then
        # file does not exist or is older than compressed version:
        lnkList=${lnkList}" "$xx
        gunzip -f ${xx}.gz
      fi
    fi
  done
  if test "x$lnkList" != 'x' ; then
    echo -n " unzip files:$lnkList " ; lnkList=';'
  fi
#-- a trick to rename pickup by making a symbolic link in the current directory
      xx='pickup.0000086400'
      yy='pickup.0000072000'
      if test ! -r $xx ; then
        lnkList="$lnkList +link $yy to $xx"
        ln -sf $yy $xx
      fi
  echo "$lnkList"
#------
else
  echo " Error:" $fromDir "not a directory"
fi
