#!/bin/bash

# -----------------------------------------------------------------
# RPC Project :
# Run RPC_get_data_CLUGEOM : give CLUSTER geometry
# Program derived from Roproc rpc_listorbit, 
# P. Robert, CETP, Juin 2001
# Adapted to RPC package P. Robert, LPP, 2013-02-14
# Revision for POS.rff files, ScientiDev, Jan 2021
# -----------------------------------------------------------------

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

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

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : get CLUSTER/GEOMETRY of 4 S/S"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   year month day"
   echo "    ex: $appli 2001 09 23"
   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`

year=$1
month=$2
day=$3

# get 4 S/C positions

RPC_get_data_CLUPOS_4sat $year $month $day

if test $? != 0
   then
   echo "$appli36 : *** ERROR ! Command aborted.">&2
   exit 2
fi

# 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 $appli.resu ; then \mv $appli.resu $appli.resu.old ; fi

cp get_data_CLUPOS_4sat.out $appli.in

echo "Done"
echo " "

# run appli.exe 

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