1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
#!/bin/sh
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
. ../test_common.sh
# get some config.h parameters
if test -f ${top_builddir}/config.h ; then
if fgrep -e '#define NETCDF_ENABLE_CDF5 1' ${top_builddir}/config.h >/dev/null ; then
HAVE_CDF5=1
else
HAVE_CDF5=0
fi
else
echo "Cannot locate config.h"
exit 1
fi
# It is unreasonable to test actual lengths of files
# (even netcdf-3 files).
#However, the files created in this script are used in later ones
${NCGEN} -b ${srcdir}/small.cdl
${NCGEN} -b ${srcdir}/small2.cdl
# This shell script tests lengths of small netcdf files and tests
# that rewriting a numeric value doesn't change file length
# $Id: tst_lengths.sh,v 1.10 2008/08/07 00:07:52 ed Exp $
# cat > rewrite-scalar.c << EOF
# #include <stdio.h>
# #include <netcdf.h>
# #define ERR do {fflush(stdout); fprintf(stderr, "Error, %s, line: %d\n", __FILE__, __LINE__); return(1);} while (0)
# int
# main(int ac, char *av[]) {
# int ncid, varid, data[] = {42};
# if (nc_open(av[1], NC_WRITE, &ncid)) ERR;
# if (nc_inq_varid(ncid, av[2], &varid)) ERR;
# if (nc_put_var_int(ncid, varid, data)) ERR;
# if (nc_close(ncid)) ERR;
# return 0;
# }
# EOF
# cat > test-len.sh << 'EOF'
# # test that length of file $1 is $2
# len=`ls -l $1|awk '{print $5}'`
# if [ $len = $2 ]; then
# exit 0
# else
# echo "### Failure: file $1 has length $len instead of expected $2"
# exit 1
# fi
# EOF
# chmod +x ./test-len.sh
# cc -g -o rewrite-scalar -I../libsrc rewrite-scalar.c -L../libsrc -lnetcdf
# echo "netcdf small {variables: byte t; data: t = 1;}" > small.cdl
set -e
echo ""
echo "*** testing length of classic file"
${NCGEN} -b ${srcdir}/small.cdl
if test `wc -c < small.nc` != 68; then
exit 1
fi
#echo "*** testing length of classic file written with NOFILL"
#${NCGEN} -b -x ${srcdir}/small.cdl
#if test `wc -c < small.nc` != 68; then
# exit 1
#fi
echo "*** testing length of rewritten classic file"
${NCGEN} -b ${srcdir}/small.cdl && ${execdir}/rewrite-scalar small.nc t
#if test `wc -c < small.nc` != 68; then
# exit 1
#fi
echo "*** testing length of rewritten classic file written with NOFILL"
${NCGEN} -b -x ${srcdir}/small.cdl && ${execdir}/rewrite-scalar small.nc t
#if test `wc -c < small.nc` != 68; then
# exit 1
#fi
echo "*** testing length of 64-bit offset file"
${NCGEN} -b -k64-bit-offset ${srcdir}/small.cdl
#if test `wc -c < small.nc` != 72; then
# exit 1
#fi
echo "*** testing length of 64-bit offset file written with NOFILL"
${NCGEN} -b -k64-bit-offset -x ${srcdir}/small.cdl
#if test `wc -c < small.nc` != 72; then
# exit 1
#fi
echo "*** testing length of rewritten 64-bit offset file"
${NCGEN} -b -k64-bit-offset ${srcdir}/small.cdl && ${execdir}/rewrite-scalar small.nc t
#if test `wc -c < small.nc` != 72; then
# exit 1
#fi
echo "*** testing length of rewritten 64-bit offset file written with NOFILL"
${NCGEN} -b -k64-bit-offset -x ${srcdir}/small.cdl && ${execdir}/rewrite-scalar small.nc t
#if test `wc -c < small.nc` != 72; then
# exit 1
#fi
# The following tests only occur if we have CDF5.
if test "x$HAVE_CDF5" = x1 ; then
echo "*** testing length of 64-bit data file"
${NCGEN} -b -k64-bit-data ${srcdir}/small.cdl
if test `wc -c < small.nc` != 104; then
exit 1
fi
echo "*** testing length of 64-bit data file"
${NCGEN} -b -5 ${srcdir}/small.cdl
if test `wc -c < small.nc` != 104; then
exit 1
fi
echo "*** testing length of 64-bit data file written with NOFILL"
${NCGEN} -b -5 -x ${srcdir}/small.cdl
#if test `wc -c < small.nc` != 104; then
# exit 1
#fi
echo "*** testing length of rewritten 64-bit data file"
${NCGEN} -b -5 ${srcdir}/small.cdl && ${execdir}/rewrite-scalar small.nc t
# Watch out, it appears that the CDF-5 files are being rounded up to next page size
# So, we need to truncate them wrt nul's in order to check size.
# Bad hack, but what else can I do?
if test `${execdir}/nctrunc <small.nc |wc -c` != 104; then
exit 1
fi
echo "*** testing length of rewritten 64-bit data file written with NOFILL"
${NCGEN} -b -5 -x ${srcdir}/small.cdl && ${execdir}/rewrite-scalar small.nc t
#if test `wc -c < small.nc` != 104; then
# exit 1
#fi
# End HAVE_CDF5 block.
fi
# test with only one record variable of type byte or short, which need
# not be 4-byte aligned
echo "*** testing length of one-record-variable classic file"
${NCGEN} -b ${srcdir}/small2.cdl
#if test `wc -c < small2.nc` != 101; then
# exit 1
#fi
# The following tests only occur if we have CDF5.
if test "x$HAVE_CDF5" = x1 ; then
echo "*** testing length of one-record-variable 64-bit data file"
${NCGEN} -b -5 ${srcdir}/small2.cdl
if test `wc -c < small2.nc` != 161; then
exit 1
fi
echo "*** testing length of one-record-variable 64-bit data file"
${NCGEN} -b -5 ${srcdir}/small2.cdl
if test `wc -c < small2.nc` != 161; then
exit 1
fi
echo "*** testing length of one-record-variable 64-bit data file written with NOFILL"
${NCGEN} -b -5 -x ${srcdir}/small2.cdl
if test `wc -c < small2.nc` != 161; then
exit 1
fi
#end HAVE_CDF5 block
fi
echo "*** testing length of one-record-variable classic file written with NOFILL"
${NCGEN} -b -x ${srcdir}/small2.cdl
if test `wc -c < small2.nc` != 101; then
exit 1
fi
echo "*** testing length of one-record-variable classic file written with NOFILL"
${NCGEN} -b -x ${srcdir}/small2.cdl
if test `wc -c < small2.nc` != 101; then
exit 1
fi
echo "*** testing length of one-record-variable classic file written with NOFILL"
${NCGEN} -b -x ${srcdir}/small2.cdl
#if test `wc -c < small2.nc` != 101; then
# exit 1
#fi
echo "*** testing length of one-record-variable 64-bit offset file"
${NCGEN} -b -k64-bit-offset ${srcdir}/small2.cdl
#if test `wc -c < small2.nc` != 105; then
# exit 1
#fi
echo "*** testing length of one-record-variable 64-bit offset file written with NOFILL"
${NCGEN} -b -k64-bit-offset -x ${srcdir}/small2.cdl
#if test `wc -c < small2.nc` != 105; then
# exit 1
#fi
|