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