#!/bin/sh

# Create the required output directory names if they have been removed
# from the model Project OutputPath (due to moves by archive scripts etc).
# Use either as a stand-alone or as a call from other scripts such as "ArchiveRun".
# It will not overwrite existing directories.

# Calls the following ELM scripts:
# none included

# As with all ELM scripts, stay with Bourne shell (/bin/sh) for universal application.


if test $# != 2
  then
    echo "###### Error: 2 args expected:"
    echo "Give the *existing* base output path, and the model Project Name"
    echo "e.g., mkOutDirs /myDirectory/structure/ myProj."
    echo "The required ./myProj/ ./myProj/Output/ and ./myProj/Output/* directories" 
    echo "will be added to the existing base output path."
    exit
fi


OutputPath=$1
ProjName=$2

######
# check that the base model OutPutPath exists (only needed if run in stand-alone mode,
# as other scripts that call this have already checked the base path)
if test -d "$OutputPath"
  then
  # kinda junky here! solaris didn't like a "! test -d xyz"
  	this=that;
  else
    echo "###### Error: $OutputPath "
    echo "does not exist on your network ."
    echo "Give a valid base directory for model output."
    exit
fi

######
# only need this new Project directory name for new Projects
if
    test -d $OutputPath/$ProjName
then
  # kinda junky here! solaris didn't like a "! test -d xyz"
  this=that
else
    echo "Creating dir $OutputPath/$ProjName"
    mkdir $OutputPath/$ProjName
fi
######
# only need this new Output directory name for new Projects
if
    test -d $OutputPath/$ProjName/Output
then
  # kinda junky here! solaris didn't like a "! test -d xyz"
  this=that
else
    echo "Creating dir $OutputPath/$ProjName/Output"
    mkdir $OutputPath/$ProjName/Output
fi

######
# make the required Animation* directories
echo "Creating Animation directories in $OutputPath/$ProjName/Output ..."

dir=Animation
i=1
newdir=0
while (test $i != 61)
do
  if
    test -d $OutputPath/$ProjName/Output/$dir$i
  then
  # kinda junky here! solaris didn't like a "! test -d xyz"
  this=that
  else
    newdir=`expr $newdir + 1`
    mkdir $OutputPath/$ProjName/Output/$dir$i
    #echo "Creating dir $OutputPath/$ProjName/Output/$dir$i "
  fi
  i=`expr $i + 1`
done
echo "Created $newdir Animation directories in $OutputPath/$ProjName/Output/"

######
# now make the other required directories
other="Canal PtSer Debug Budget"
for i in $other
do
  if
    test -d $OutputPath/$ProjName/Output/$i
  then
  # kinda junky here! solaris didn't like a "! test -d xyz"
  this=that
  else
    mkdir $OutputPath/$ProjName/Output/$i
    echo "Creating dir $OutputPath/$ProjName/Output/$i "
  fi
done

######
echo "Done with setting up any needed directories in $OutputPath/$ProjName/Output/"
echo "***"
