#!/bin/bash
# This script needs to be run before the  cmake  command for CMake
# builds. It should be called from all cmake scripts. 
#
# This script copies default i/o files to the build directory (rather
# than autogenerating them with the python script)


# List of files to copy
# These will have the '.default' stripped from their names
files=(libglide/glide_io.F90.default
       libglint/glint_io.F90.default
       libglint/glint_mbal_io.F90.default)

echo
echo "Automated copy of default versions of glide_io.F90,"
echo "glint_io.F90, glint_mbal_io.F90 to build directory"
echo

mkdir -p fortran_autogen_srcs
pushd fortran_autogen_srcs

if [ $# -eq 1 ];
  then
    export CISM_SOURCE_DIR=$1 
  else
    export CISM_SOURCE_DIR=../../../
echo $1
fi
echo "Auto-copy-io script is using CISM source directory: "
echo $CISM_SOURCE_DIR


for fl in ${files[*]}; do
    newfile=`basename $fl .default`
    echo "  --making copy of $newfile"
    cp -p $CISM_SOURCE_DIR/$fl $newfile
done

popd

