#!/bin/sh

set -e

${MAKE:-make} histget

test ! -f xhistget/xhistget1.nc || rm -f xhistget/xhistget1.nc
test ! -f xhistget/xhistget2.nc || rm -f xhistget/xhistget2.nc
test ! -f xhistget/xhistget3.nc || rm -f xhistget/xhistget3.nc
test ! -f xhistget/xhistget4.nc || rm -f xhistget/xhistget4.nc

./histget 2> xdifs.log

cd xhistget

ncdump xhistget1.nc > xhistget1.cdl
ncdump xhistget2.nc > xhistget2.cdl
ncdump xhistget3.nc > xhistget3.cdl
ncdump xhistget4.nc > xhistget4.cdl

##### fixed-length array data input test ######

echo -n "histget [fixed-length array data input test] ... "

diff xhistget1.cdl xhistget2.cdl > xhistgetdif1.cdl ||

diff xhistgetdif1.cdl - <<EOF
1c1
< netcdf xhistget1 {
---
> netcdf xhistget2 {
EOF

echo "okay"


##### pointer array data input test ######

echo -n "histget [pointer array data input test] ... "

diff xhistget1.cdl xhistget3.cdl > xhistgetdif2.cdl ||

diff xhistgetdif2.cdl - <<EOF
1c1
< netcdf xhistget1 {
---
> netcdf xhistget3 {
EOF

echo "okay"


##### dimension array data input test ######

echo -n "histget [dimension array data input test] ... "

diff xhistget1.cdl xhistget4.cdl > xhistgetdif3.cdl ||

diff xhistgetdif3.cdl - <<EOF
1c1
< netcdf xhistget1 {
---
> netcdf xhistget4 {
EOF

echo "okay"

rm -f ../xdifs.log xhistget?.* xhistgetdif?.cdl

exit 0
