#!/bin/ksh

#PATH_PROG="/data/sva/iasi_l1c/bin"
#PATH_LOGS="/data/sva/iasi_l1c/logs"

typeset -i NbrOptionOblig=0
while [ $# -ge 1 ]
do
  case $1 in
    -f) shift 1;file="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));;
    -logs) shift 1;file_logs="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));;
    *) print '' $1 'is not an option';exit 1;;
  esac
  shift 1
done

if [ $NbrOptionOblig -ne 2 ]; then
  echo $*
  echo "USAGE : -f <file_name> -logs <file_logs>"
  exit 1
fi


conf_file="conf.txt"
while read line
do
        ll=${#line}

        if [[ -n $(echo $line | grep PATH_PROG) ]] ; then
                chem=`expr $ll - 11`
                temp=`echo $line | cut -c11-$ll`
                PATH_PROG=$temp
        fi
        if [[ -n $(echo $line | grep PATH_LOGS) ]] ; then
                chem=`expr $ll - 11`
                temp=`echo $line | cut -c11-$ll`
                PATH_LOGS=$temp
        fi
        if [[ -n $(echo $line | grep PATH_SUN_WEB_SERVICES) ]] ; then
                chem=`expr $ll - 23`
                temp=`echo $line | cut -c23-$ll`
                PATH_SUN_WEB_SERVICES=$temp
        fi
        if [[ -n $(echo $line | grep PATH_Orbiasi_l1b) ]] ; then
                chem=`expr $ll - 18`
                temp=`echo $line | cut -c18-$ll`
                PATH_Orbiasi_l1b=$temp
        fi
	if [[ -n $(echo $line | grep PATH_TEMP) ]] ; then
                chem=`expr $ll - 11`
                temp=`echo $line | cut -c11-$ll`
                PATH_TEMP=$temp
        fi
	

done < $conf_file


ind=0
while read line
do
	ind=$((ind+1))	 
	param[$ind]="$line"
done < $file 


$PATH_PROG/IASI_mot_2004_l1b_all_spots_V1.0 -d ${param[3]} -s ${param[5]} -iasi ${param[4]} -lat ${param[6]} -lon ${param[7]} -idtm ${param[8]} -idjn ${param[9]} -rd ${param[10]} -logs $file_logs -req ${param[11]}_${param[1]}

var=$?

echo "PATH_PROG/IASI_mot_2004_l1b_all_spots_V1.0 executing ... " >> $file_logs 
echo "$PATH_PROG/IASI_mot_2004_l1b_all_spots_V1.0 -d ${param[3]} -s ${param[5]} -iasi ${param[4]} -lat ${param[6]} -lon ${param[7]} -idtm ${param[8]} -idjn ${param[9]} -rd ${param[10]} -logs $file_logs -req ${param[11]}_${param[1]}" >> $file_logs

exit $var



