#! /bin/sh
# Initialize preact tables
# 07/09/01 C.Ludescher
# May be called from Makefile "make tables"
#
if [ "$1" ]; then
  if [ $1 = "help" -o $1 = "-h" ]; then
    echo "usage: preactinit [restart] [PATH <path of preact_init>] [DATA <dir of ORNL6086.DAT> ]"
    echo "  To initialize:"
    echo "       preactinit  "     
    echo "       preactinit PATH <path of preact_init> "     
    echo "       preactinit DATA <dir of ORNL6086.DAT> "
    echo "       preactinit DATA <dir of ORNL6086.DAT> PATH <path of preact_init> "
    echo "  To delete/initialize:"     
    echo "       preactinit restart "
    echo "       preactinit restart PATH <path of preact_init> "
    echo "       preactinit restart DATA <dir of ORNL6086.DAT> "
    echo "       preactinit restart DATA <dir of ORNL6086.DAT> PATH <path of preact_init> "
      exit
  fi
fi

if [ "$PREACTDIR" ]; then
    while [ -n "$1" ]; do
       case $1 in
        restart )
            if [ -d $PREACTDIR ]; then
                rm -r $PREACTDIR
            fi
            ;;
	DATA )
	    DATA=$2
	    echo "DATA = $DATA"
            shift ;;
	PATH )
	    ppath=$2
	    echo "PATH = $ppath"
            shift ;;
       esac
       shift
    done

    if [ ! -f $PREACTDIR/data/ORNL6086.DAT ]; then
      if [ ! -d $PREACTDIR/data ]; then
         mkdir -p $PREACTDIR/data
      fi
      if [ "$CODESYSDIR" ]; then
        cp $CODESYSDIR/source/preact_init/ornl6086.dat $PREACTDIR/data/ORNL6086.DAT
      elif [ -f ORNL6086.DAT ]; then 
        echo "cp ORNL6086.DAT $PREACTDIR/data/"
        cp ORNL6086.DAT $PREACTDIR/data/
      elif [ -f ../../preact/ORNL6086.DAT ]; then 
        echo "cp ../../preact/ORNL6086.DAT $PREACTDIR/data/"
        cp ../../preact/ORNL6086.DAT $PREACTDIR/data/
      elif [ -n "$DATA" ]; then
        if [ -f $DATA/ORNL6086.DAT ]; then
           echo "cp $DATA/ORNL6086.DAT $PREACTDIR/data/"
           cp $DATA/ORNL6086.DAT $PREACTDIR/data/
        elif [ -f $DATA/preact/ORNL6086.DAT ]; then
           cp $DATA/preact/ORNL6086.DAT $PREACTDIR/data/
        fi
      else
        echo "   >>>>> can not find ORNL6086.DAT <<<<<"
	exit 1
      fi
    fi
    if [ ! -d $PREACTDIR/tables/cx/cxtabl ]; then 
        mkdir -p $PREACTDIR/tables/cx/cxtabl
        mkdir $PREACTDIR/tables/cx/helixt
        mkdir $PREACTDIR/tables/cx/hextbl
        mkdir $PREACTDIR/tables/cx/lilixt
        mkdir $PREACTDIR/tables/cx/phecxt
        mkdir $PREACTDIR/tables/cx/plicxt
        mkdir -p $PREACTDIR/tables/fs/ddntab
        mkdir $PREACTDIR/tables/fs/ddptab
        mkdir $PREACTDIR/tables/fs/dh3tab
        mkdir $PREACTDIR/tables/fs/dttabl
        mkdir $PREACTDIR/tables/fs/h3dtab
        mkdir $PREACTDIR/tables/fs/h3ttab
        mkdir $PREACTDIR/tables/fs/tdtabl
        mkdir $PREACTDIR/tables/fs/th3tab
        mkdir $PREACTDIR/tables/fs/tttabl
        mkdir $PREACTDIR/tables/fs/tttdpc
        mkdir -p $PREACTDIR/tables/ii/hehixt
        mkdir $PREACTDIR/tables/ii/heitbl
        mkdir $PREACTDIR/tables/ii/heliit
        mkdir $PREACTDIR/tables/ii/iitabl
        mkdir $PREACTDIR/tables/ii/liheit
        mkdir $PREACTDIR/tables/ii/lihiit
        mkdir $PREACTDIR/tables/ii/liliit
        mkdir $PREACTDIR/tables/ii/pheiit
        mkdir $PREACTDIR/tables/ii/pliiit
        mkdir -p $PREACTDIR/tables/ei/recomb
        mkdir $PREACTDIR/tables/ei/eionzh
        mkdir $PREACTDIR/tables/ei/eionhe
        mkdir $PREACTDIR/tables/ei/eionli
        mkdir -p $PREACTDIR/tables/sv/cstoph
        mkdir $PREACTDIR/tables/sv/cstphe
        mkdir $PREACTDIR/tables/sv/cstpli
        mkdir $PREACTDIR/tables/sv/ostoph
        mkdir $PREACTDIR/tables/sv/ostphe
        mkdir $PREACTDIR/tables/sv/ostpli
     fi
     if [ "$LOCAL" ]; then
        $LOCAL/exe/preact_init
     elif [ -n "$ppath" ]; then
        $ppath/preact_init
     else
        preact_init
     fi
else
        echo "   >>>>> You must define PREACTDIR <<<<<"
	echo "   >>>>> e.g.: setenv PREACTDIR $HOME/preact"
fi
