#!/bin/bash

# -----------------------------------------------------------
# RPC Project :
# Run RPC_visu_ave_spectra : visualization of an average 
# spectrum from a SP.rff file
# P. Robert, LPP, 2013-04-10
# -----------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36` 
Narg=8
version=`RPC_version`

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

if test $# != $Narg || test $hh = 1
  then
  echo "$appli : visualization of a Spectrogram RFF file"
  echo "$appli   require $Narg argument(s), ex:"
  echo "$appli   SP.rff datiso1 datiso2 f1 f2 pmin pmax"
  echo "    SP.rff          : name of a spectro RFF file"
  echo "    datiso1 datiso2 : iso date/time first and end"
  echo "    f1 f2           : frequency bounds to plot"
  echo "    pmin pmax       : min max power for dynamic colors (log values)"
  echo "    XY or LR        : for XYZ or Left Right Z"
  echo " "   
  echo "$appli   toto_SP.rff  2001-09-23T09:00:00.000Z 2001-09-23T11:00:00.000Z  0. 5. 0. 0. XY "
  echo "$appli   toto_SP.rff  0 0  0. 0. 0. 0. XY y"
  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`

echo " -------------------------------------------------------------------"
echo " Run of $appli :"
echo " $appli $*"

SP=$1
T1=$2
T2=$3
f1=$4
f2=$5
p1=$6
p2=$7
XY=`echo $8 | cut -c1-2`

# --------------------------------------------------------------

# remove RPC_ from RPC command

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

# rename possible existing appli.out file

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

# creating appli.in from arguments list

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

echo $SP        > $appli.in
echo $T1       >> $appli.in
echo $T2       >> $appli.in
echo $f1 $f2   >> $appli.in
echo $p1 $p2   >> $appli.in
echo $XY       >> $appli.in

echo " -------------------------------------------------------------------"
echo " Run of $appli.exe :"

PS=`basename $SP .rff`"_ave_spe.ps"

if test -f $PS ; then rm $PS ; fi

# run appli.exe 

. run_appli.bash 
err=$?
if test $err != 0
   then exit $err
fi

# creation eventuelle du pdf,png, visu a l'ecran

run_options_visu.bash $PS 
err=$?
if test $err != 0
   then exit $err
fi

echo " -------------------------------------------------------------------"
