#/usr/bin/ksh
#
# Script to test the -l option to eum2ropp, by emulating Axel's studies.
#

DIR=/data/nwp1/idculv/ROPP/ropp_src/branches/dev/Share/ROPP81_prototype/ropp_io/tools

IFILE0=data/GRAS_1B_M02_20080701000214Z_20080701000329Z_R_O_20150413081448Z_G19_NN.nc

input=$IFILE0



# run with -l to netCDF
output1="eum2ropp_l1a.nc"
echo "Generating netCDF file with level 1a content: " $output1
$DIR/eum2ropp -l $input -o $output1 > /dev/null
echo "r_leo from eum2ropp -l:"
ncdump -h $output1 | grep 'r_leo:reference_frame'
ncks -H -Q -ddim_lev1a,0 -vr_leo $output1
echo ""
echo ""

# run without to netCDF
output2="eum2ropp_l1b.nc"
echo "Generating netCDF file without level 1a content: " $output1
$DIR/eum2ropp $input -o $output2 > /dev/null
echo "r_leo from eum2ropp:"
ncdump -h $output2 | grep 'r_leo:reference_frame'
ncks -H -Q -ddim_lev1a,0 -vr_leo $output2
echo ""
echo ""



# generate bufr from the 2
output3="eum2ropp_l1a.nc.bufr"
echo "Generating BUFR file from ROPP file with level 1a content: " $output3
$DIR/ropp2bufr $output1 -o $output3 > /dev/null
echo "r_leo from eum2ropp -l | ropp2bufr:"
$ROPP_ROOT/gfortran/bin/decbufr -d $output3 | grep 'IN DIRECTION' | head -3
echo ""
echo ""

output4="eum2ropp_l1b.nc.bufr"
echo "Generating BUFR file from ROPP file without level 1a content: " $output4
$DIR/ropp2bufr $output2 -o $output4 > /dev/null
echo "r_leo from eum2ropp | ropp2bufr:"
$ROPP_ROOT/gfortran/bin/decbufr -d $output4 | grep 'IN DIRECTION' | head -3
echo ""
echo ""



# go back to netcdf with the 2
output5="eum2ropp_l1a.nc.bufr.nc"
echo "Generating netCDF file from BUFR file with level 1a content: " $output5
$DIR/bufr2ropp $output3 -o $output5 > /dev/null
echo "r_leo from eum2ropp -l | ropp2bufr | bufr2ropp:"
ncdump -h $output5 | grep 'r_leo:reference_frame'
ncks -H -Q -ddim_lev1a,0 -vr_leo $output5
echo ""
echo ""

output6="eum2ropp_l1b.nc.bufr.nc"
echo "Generating BUFR file from ROPP file without level 1a content: " $output6
$DIR/bufr2ropp $output4 -o $output6 > /dev/null
echo "r_leo from eum2ropp | ropp2bufr | bufr2ropp:"
ncdump -h $output6 | grep 'r_leo:reference_frame'
ncks -H -Q -ddim_lev1a,0 -vr_leo $output6
echo ""
echo ""







echo "**** Axel's equivalent output ***"

# show r_leo of the two
echo "r_leo when going with level 1a:"
ncdump -v r_leo $output5 | tail -5
echo ""
echo ""

# show r_leo of the two
echo "r_leo when going without level 1a:"
ncdump -v r_leo $output6 | tail -5

