#!/bin/bash
######################################################################################
#
# This script moves the original nxm.sys.dat directory under
# nxm.sys.test, and vice versa
#
# Author: Zachary Matthews
# Since:  NeXtMidas 4.1.3
# Note:   Experimental version first appeared in NeXtMidas 4.0.0
#         and was in NMROOT/swap/datNXM/dat_move.sh
#
######################################################################################

NMROOT_TMP=`realpath ${0}`
for i in {1..4}
do
  NMROOT_TMP=`dirname ${NMROOT_TMP}`
done
NMROOT=${NMROOT_TMP}

sysDir=${NMROOT}/nxm/sys
origDatDir=${NMROOT}/nxm/sys/dat
testDir=${NMROOT}/nxm/sys/test

if [ ! -d ${testDir}/dat ] ; then
  echo ""
  echo "Moving nxm.sys.dat into nxm.sys.test..."
  mv ${origDatDir} ${testDir}
  mkdir ${origDatDir}
  filesToKeep=(kwconv_plat2blue.tbl testxy3000.prm world.dbf world.shp world.shx)
  for file in ${filesToKeep[@]}
  do
    cp ${testDir}/dat/${file} ${origDatDir}
  done
else
  echo ""
  echo "Moving nxm.sys.test.dat back into nxm.sys..."
  rm -rf ${origDatDir}
  mv ${testDir}/dat ${sysDir}
fi
