#!/bin/bash

# -------------------------------------------------------
# RPC Project :
# Run RPC_vectime_to_mva: transform a vectime into MVA system
# P. Robert, ScientiDev, Feb. 2021
# -------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=2
echo " -------------------------------------------------------------------"
echo $appli $*

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : transform a vectime file   into the MVA coordinates"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   toto1.rff  toto2.rff "
   echo "    toto1.rff : name of  input ULF VTL2 RFF file"
   echo "    toto2.rff : name of output ULF VTL2 RFF file in MVA"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo "$appli36 : *** ERROR ! Command aborted !" >&2
   exit 1
fi

datim1=`date +%F'  '%H':'%M':'%S `
julsec1=`date +%s`

VTL2_ULF=$1
VTL2_MVA=$2

if test ! -f $VTL2_ULF 
   then echo "*** no file $VTL2_ULF" 
        echo "$appli36 : *** ERROR ! Command aborted !" >&2 
        exit 1 
fi


# remove RPC_ from RPC command

appli=`echo $appli | cut -c5-`

echo " -------------------------------------------------------------------"
echo " Run of $appli.exe :"
echo "     - arguments are taken from $appli.in text file"
echo "     - execution report will be available in $appli.out text file"
echo
echo " VTL2 input  file= $1"
echo " VTL2 output file= $2"
echo " Please wait..."
echo ""


# creating appli.in from arguments list

if test -f $appli.in ; then \mv $appli.in $appli.in.old ; fi

echo $VTL2_ULF  > $appli.in
echo $VTL2_MVA >> $appli.in

# run appli.exe 

. run_appli.bash $appli

err=$?
exit $err
