#!/bin/bash

#Handler script for IRIS input pipes. Used by IRIS to convert OdimHDF5 file to IRIS RAW.
#Calls odimhdf52pb and pb2raw converters one by one to generate IRIS RAW output.

i=0
for arg; do
    argNum=0
    if [[ "$arg" == --ip* ]]
    then
        argNum=$((i + 1))
        input=${!argNum}
    elif [[ "$arg" == --op* ]]
    then
        argNum=$((i + 1))
        output=${!argNum}
    fi
    i=$((i + 1))
done

#Create temp directory if not already present
mkdir -p $(echo $IRIS_TEMP)odimhdf52raw

$(echo $IRIS_PIPES)odimhdf52pb $(echo "$input --op=$(echo $IRIS_TEMP)odimhdf52raw/odimhdf52raw_temp") &>> $(echo $IRIS_LOG)odimhdf52raw.log
$(echo $IRIS_PIPES)pb2raw $(echo "--ip=$(echo $IRIS_TEMP)odimhdf52raw/odimhdf52raw_temp $output") &>> $(echo $IRIS_LOG)odimhdf52raw.log
rm $(echo $IRIS_TEMP)odimhdf52raw/odimhdf52raw_temp &>> $(echo $IRIS_LOG)odimhdf52raw.log