#!/bin/sh

# -----------------------------------------------------------
# RPC Project :
# Run RPC_visu_CLUGEOM: visu of Cluster geometry over 24H
# deduced from rpc_visusatpos, june 2001
# P. Robert, LPP, 2014-03-22
# -----------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36` 
Narg=0
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 CLUGEOM cluster position files"
  echo "$appli   require $Narg argument(s), read get_data_CLUGEOM.resu"
  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 " -------------------------------------------------------------------"
echo " Run of $appli.exe :"
echo " RPC_visu_CLUGEOM : Visualization of Cluster geometry over 24h"
echo " "
echo " File get_data_CLUGEOM.resu must be existing"
echo " (this file is created by RPC_get_data_CLUGEOM)"
echo " "

# test existence du fichier a visualiser

CLUGEOM=get_data_CLUGEOM.resu

if test -f $CLUGEOM
   then echo " content of $CLUGEOM file will be visualize"
   else echo " $CLUGEOM file does not exists"
        echo " $appli36 : *** ERROR ! Command aborted." >&2
        exit 2
fi


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

PS='CLUGEOM.ps'
echo " PS file=$PS"

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

# 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
touch $appli.in

# 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

datim2=`date +%F'  '%H':'%M':'%S `
julsec2=`date +%s`
diff=`expr $julsec2 - $julsec1`

diffm=`echo "scale=2; $diff/60." | bc `

echo ""
echo " Starting time $appli : $datim1"
echo " Ending   time $appli : $datim2"
echo " Duration      $appli : $diff sec.  ($diffm mn.)"

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


