#!/bin/bash

[ $IRSPP_HOME ] || { echo "Please define environment variable IRSPP_HOME"; exit 1; }

[ -f $IRSPP_HOME/bin/irspp_env.sh ] || { echo "Error: cannot find $IRSPP_HOME/bin/irspp_env.sh"; exit 1; }

. $IRSPP_HOME/bin/irspp_env.sh

TOPDIR=$(cd ..; pwd)

#input and output files

mkdir -p $TOPDIR/output
infile_cov=$TOPDIR/output/irs_covariance.nc
namelistfile=irs_generate_pcs.nl
outfile=$TOPDIR/output/irs_pcs.nc

[ -f $infile_cov ] || { echo "Error: covariance file $infile_cov does not exist"; \
  echo "You need to first run ./run_irs_covariance.sh"; exit 1; }

#Run the executable

irs_generate_pcs.exe -i $infile_cov -n $namelistfile -o $outfile
status=$?

[ $status = 0 ] && echo "$0 finished" || echo "irs_generate_pcs.exe failed with status $status"
