#!/bin/bash

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

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

. $IRSPP_INSTALL/bin/irspp_env.sh

TOPDIR=$(cd ..; pwd)

#input and output files

outdir=$TOPDIR/output_5x5_bufr
mkdir -p $outdir
infiles=$(ls $TOPDIR/input/*1B-PC*BODY*.nc)
namelistfile=irs_main_5x5.nl

#process each file with reconstructed radiances

for file in $infiles; do
  echo $file
  filebase=$(basename $file)
  outfile=${filebase%.nc}.bin
  irs_main.exe -i $file -o $outdir/$outfile -n $namelistfile
done
