#!/bin/sh

# View and change the model runtime configuration, 
# either as a stand-alone or as a call from other scripts such as "Run".
# Requires the awk pattern files "PatternRunTime" and "PatternOutStep" in the ELM script directory.

# Calls the following ELM scripts:
# PathELM_HOME, PathModel

# As with all ELM scripts, stay with Bourne shell (/bin/sh) for universal application.
# 	Note: for getting a variable from a child shellcommand, ". shellcommand" does similar/same thing 
# 	as "source shellcommand" (latter didn't work in Sun solaris implmentation)


# *******************
# take care of environment variables and paths
# *******************

# let's put an empty line in here to start 
echo ""

####
#### ELM_HOME Path
# determines if the (fundamental) ELM_HOME environment variable appears valid
PathELM_HOME

if test $# = 0
  then
        echo "###### Error:  you must supply a ProjectName argument." 
        echo "Example: Check ELM"
    exit
fi

####
#### portable function for getting yes/no answer
get_yesno()
{
    ANS="X"
    while [ "$ANS" != "y" -a "$ANS" != "n" -a "$ANS" != "Y" -a "$ANS" != "N" ]
    do
		echo  " (y/n): "
        read ANS
    done
}

####
#### Model Path
# establish the base ModelPath for the model Project data/executable from the PathModel script
. PathModel

####
#### Project Name
ProjName=$1
export ProjName


if test -d $ModelPath/$ProjName
  then
    this=that;
  else
    echo "###### Error:  That model Project does not exist."
	echo "Available Project Names in your ModelPath= $ModelPath "
    ls $ModelPath
    exit
fi

####
#### Query the user on changing runtime parameters
echo "***"
echo "Check (view and change) the runtime info in the model-Driver "
echo "and the model-output parms files, for the particular project you selected."
echo "***"
echo ""

####
#uses the awk PatternRunTime criteria to look at selected Driver.parm lines
awk -f ${ELM_HOME}/SME/scripts/PatternRunTime $ModelPath$ProjName/RunParms/Driver.parm
echo ""
echo "** Your input, please: Above are the RunTime parms.  Do you want to edit Driver.parm using vi?"
get_yesno
if [ "$ANS" = "y" -o "$ANS" = "Y" ]
  then 
	vi $ModelPath$ProjName/RunParms/Driver.parm
fi

# clear the screen
clear

#uses the PatternOutStep criteria to look at existing output selections for model variables
echo ""
echo "Variable Name                 Outstep, Animate, Scale, Points"
awk -f ${ELM_HOME}/SME/scripts/PatternOutStep $ModelPath$ProjName/RunParms/Model.outList
echo ""
echo "** Your input, please: Above are the output data.  Do you want to edit Model.outList using vi?"
get_yesno
if [ "$ANS" = "y" -o "$ANS" = "Y" ]
  then 
	vi $ModelPath$ProjName/RunParms/Model.outList
fi
