1#!/bin/sh
2
3if test "x$srcdir" = x ; then srcdir=`pwd`; fi
4. ../test_common.sh
5
6# For a netCDF-4 build, test nccopy on netCDF files in this directory
7
8if test -f tst_comp2${ext} ; then ${execdir}/tst_comp2 ; fi
9
10
11set -e
12echo ""
13
14# These files are actually in $srcdir in distcheck builds, so they
15# need to be handled differently.
16# ref_tst_compounds2 ref_tst_compounds3 ref_tst_compounds4
17TESTFILES='tst_comp tst_comp2 tst_enum_data tst_fillbug
18 tst_group_data tst_nans tst_opaque_data tst_solar_1 tst_solar_2
19 tst_solar_cmp tst_special_atts tst_string_data tst_unicode'
20
21if test "x$NC_VLEN_NOTEST" = x ; then
22TESFILES="$TESTFILES tst_vlen_data"
23fi
24
25echo "*** Testing netCDF-4 features of nccopy on ncdump/*.nc files"
26for i in $TESTFILES ; do
27    echo "*** Test nccopy $i.nc copy_of_$i.nc ..."
28    ${NCCOPY} $i.nc copy_of_$i.nc
29${NCDUMP} -n copy_of_$i $i.nc > tmp.cdl
30${NCDUMP} copy_of_$i.nc > copy_of_$i.cdl
31#    echo "*** compare " with copy_of_$i.cdl
32    diff copy_of_$i.cdl tmp.cdl
33    rm copy_of_$i.nc copy_of_$i.cdl tmp.cdl
34done
35# echo "*** Testing compression of deflatable files ..."
36./tst_compress
37echo "*** Test nccopy -d1 can compress a classic format file ..."
38${NCCOPY} -d1 tst_inflated.nc tst_deflated.nc
39if test `wc -c < tst_deflated.nc` -ge  `wc -c < tst_inflated.nc`; then
40    exit 1
41fi
42echo "*** Test nccopy -d1 can compress a netCDF-4 format file ..."
43${NCCOPY} -d1 tst_inflated4.nc tst_deflated.nc
44if test `wc -c < tst_deflated.nc` -ge  `wc -c < tst_inflated4.nc`; then
45    exit 1
46fi
47echo "*** Test nccopy -d1 -s can compress a classic model netCDF-4 file even more ..."
48${NCCOPY} -d1 -s tst_inflated.nc tmp.nc
49if test `wc -c < tmp.nc` -ge  `wc -c < tst_inflated.nc`; then
50    exit 1
51fi
52echo "*** Test nccopy -d1 -s can compress a netCDF-4 file even more ..."
53${NCCOPY} -d1 -s tst_inflated4.nc tmp.nc
54if test `wc -c < tmp.nc` -ge  `wc -c < tst_inflated4.nc`; then
55    exit 1
56fi
57echo "*** Test nccopy -d0 turns off compression, shuffling of compressed, shuffled file ..."
58${NCCOPY} -d0 tst_inflated4.nc tmp.nc
59${NCDUMP} -sh tmp.nc > tmp.cdl
60if fgrep '_DeflateLevel' < tmp.cdl ; then
61    exit 1
62fi
63if fgrep '_Shuffle' < tmp.cdl ; then
64    exit 1
65fi
66rm tst_deflated.nc tst_inflated.nc tst_inflated4.nc tmp.nc tmp.cdl
67
68echo "*** Testing nccopy -d1 -s on ncdump/*.nc files"
69for i in $TESTFILES ; do
70    echo "*** Test nccopy -d1 -s $i.nc copy_of_$i.nc ..."
71    ${NCCOPY} -d1 -s $i.nc copy_of_$i.nc
72${NCDUMP} -n copy_of_$i $i.nc > tmp.cdl
73${NCDUMP} copy_of_$i.nc > copy_of_$i.cdl
74#    echo "*** compare " with copy_of_$i.cdl
75    diff copy_of_$i.cdl tmp.cdl
76    rm copy_of_$i.nc copy_of_$i.cdl tmp.cdl
77done
78./tst_chunking
79echo "*** Test that nccopy -c can chunk and unchunk files"
80${NCCOPY} -M0 tst_chunking.nc tmp.nc
81${NCDUMP} tmp.nc > tmp.cdl
82${NCCOPY} -c dim0/,dim1/1,dim2/,dim3/1,dim4/,dim5/1,dim6/ tst_chunking.nc tmp-chunked.nc
83${NCDUMP} -n tmp tmp-chunked.nc > tmp-chunked.cdl
84diff tmp.cdl tmp-chunked.cdl
85${NCCOPY} -c dim0/,dim1/,dim2/,dim3/,dim4/,dim5/,dim6/ tmp-chunked.nc tmp-unchunked.nc
86${NCDUMP} -n tmp tmp-unchunked.nc > tmp-unchunked.cdl
87diff tmp.cdl tmp-unchunked.cdl
88${NCCOPY} -c // tmp-chunked.nc tmp-unchunked.nc
89${NCDUMP} -n tmp tmp-unchunked.nc > tmp-unchunked.cdl
90diff tmp.cdl tmp-unchunked.cdl
91echo "*** Test that nccopy -c works as intended for record dimension default (1)"
92${NCGEN} -b -o tst_bug321.nc $srcdir/tst_bug321.cdl
93${NCCOPY} -k nc7 -c"lat/2,lon/2" tst_bug321.nc tmp.nc
94${NCDUMP} -n tst_bug321 tmp.nc > tmp.cdl
95diff -b $srcdir/tst_bug321.cdl tmp.cdl
96# echo "*** Test that nccopy compression with chunking can improve compression"
97rm tst_chunking.nc tmp.nc tmp.cdl tmp-chunked.nc tmp-chunked.cdl tmp-unchunked.nc tmp-unchunked.cdl
98
99echo "*** All nccopy tests passed!"
100exit 0
101