#!/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 auto-generates files that were autogenerated as part 
# of the autoconf system.

echo
echo "Auto-generating glide_io.F90 in 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-generate script is using CISM source directory: "
echo $CISM_SOURCE_DIR

##########################
# The following lines generate several *_io.F90 files, based on variable definition files:

echo "  --creating glide_io.F90"

# Save path to source files used in autogeneration
export GLIDE_VARS_PATH=$CISM_SOURCE_DIR/libglide/glide_vars.def
export NCDF_TEMPL_PATH=$CISM_SOURCE_DIR/libglimmer/ncdf_template.F90.in

# Call python script with source file arguments
python3 -V
python3 $CISM_SOURCE_DIR/utils/build/generate_ncvars.py $GLIDE_VARS_PATH $NCDF_TEMPL_PATH

popd


