#!/bin/bash

# ----------------------------------------------------------------
# RPC Project :
# Run RPC_GEOSOL_vectime_calibration : Calibrate a L1 Vectime file
#                                      for GEOS/SOL/ULF
#
# P. Robert, LPP, 2011-03-21
# ----------------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=9
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 : Calibrate a L1 GEOS/SOL/ULF RFF Vectime file"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   VTL1.rff VTL2.rff Fdet Fc F1 F2 Step N-Kern N_shift Apod"
   echo ""
   echo "    VTL1.rff : name of an input  vectime RFF file"
   echo "    VTL2.rff : name of an output vectime RFF file"
   echo "        Fdet : detrend frequency (0. for classis despin)"
   echo "        Fc   : Frequency cut-off for calibration"
   echo "        Fmin : frequency min for filtering (Min=0 => Fc)"
   echo "        Fmax : frequency max for filtering (Max=0 => Nyquist)"
   echo "        N_Kern : Kernel size"
   echo "        N_shift : for sliding window"
   echo "        Apod  : trapezium (t) or Gaussian (g)"
   echo " ex:"
   echo " $appli GEOS1_ULF_VTL1_19770531.rff \\ "
   echo "        GEOS1_ULF_VTL2_19770531.rff \\ "
   echo "                0. 0.1 0.5 0.  1024 2 g"
   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`

# remove RPC_ from RPC command

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

# creating appli.in from arguments list

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

echo $1  > $appli.in
echo $2 >> $appli.in

shift 2

echo $1 >> $appli.in
echo $2 >> $appli.in
echo $3   $4 >> $appli.in
echo $5 >> $appli.in
echo $6 >> $appli.in
echo $7 >> $appli.in

# run appli.exe 

. run_appli.bash $appli
err=$?
exit $err
