diff --git a/nc_test/CMakeLists.txt b/nc_test/CMakeLists.txt index 14f59379f..209bacdd0 100644 --- a/nc_test/CMakeLists.txt +++ b/nc_test/CMakeLists.txt @@ -59,7 +59,7 @@ IF(LARGE_FILE_TESTS) ENDIF() IF(BUILD_DISKLESS) - SET(TESTFILES ${TESTFILES} tst_diskless tst_diskless3 tst_diskless4) + SET(TESTFILES ${TESTFILES} tst_diskless tst_diskless3 tst_diskless4 tst_diskless5) IF(USE_NETCDF4) SET(TESTFILES ${TESTFILES} tst_diskless2) ENDIF() @@ -87,6 +87,7 @@ IF(BUILD_UTILITIES) IF(LARGE_FILE_TESTS) add_sh_test(nc_test run_diskless2) ENDIF(LARGE_FILE_TESTS) + add_sh_test(nc_test run_diskless5) ENDIF(BUILD_DISKLESS) ENDIF(BUILD_UTILITIES) @@ -102,5 +103,5 @@ ENDIF() ## Specify files to be distributed by 'make dist' FILE(GLOB CUR_EXTRA_DIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.sh) SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} CMakeLists.txt Makefile.am) -SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} test_get.m4 test_put.m4 test_read.m4 test_write.m4 ref_tst_diskless2.cdl) +SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} test_get.m4 test_put.m4 test_read.m4 test_write.m4 ref_tst_diskless2.cdl tst_diskless5.cdl) ADD_EXTRA_DIST("${CUR_EXTRA_DIST}") diff --git a/nc_test/Makefile.am b/nc_test/Makefile.am index 5d327dde2..8e03ff31f 100644 --- a/nc_test/Makefile.am +++ b/nc_test/Makefile.am @@ -59,7 +59,7 @@ check_PROGRAMS += $(TESTPROGRAMS) # Build Diskless test helpers if BUILD_DISKLESS -check_PROGRAMS += tst_diskless tst_diskless3 tst_diskless4 +check_PROGRAMS += tst_diskless tst_diskless3 tst_diskless4 tst_diskless5 if USE_NETCDF4 check_PROGRAMS += tst_diskless2 endif @@ -69,7 +69,7 @@ TESTS = $(TESTPROGRAMS) if BUILD_UTILITIES if BUILD_DISKLESS -TESTS += run_diskless.sh +TESTS += run_diskless.sh run_diskless5.sh if BUILD_MMAP TESTS += run_mmap.sh endif @@ -97,11 +97,12 @@ endif # USE_VALGRIND_TESTS # Distribute the .c files so that m4 isn't required on the users # machine. EXTRA_DIST = test_get.m4 test_put.m4 run_valgrind_tests.sh \ -run_diskless.sh run_diskless2.sh run_mmap.sh run_pnetcdf_test.sh \ +run_diskless.sh run_diskless2.sh run_diskless5.sh \ +run_mmap.sh run_pnetcdf_test.sh \ test_read.m4 test_write.m4 # ref_tst_diskless2.cdl is for diff comparison and to produce tst_diskless2.c -EXTRA_DIST += ref_tst_diskless2.cdl CMakeLists.txt +EXTRA_DIST += ref_tst_diskless2.cdl tst_diskless5.cdl CMakeLists.txt # Only clean these on maintainer-clean, because they require m4 to # regenerate. diff --git a/nc_test/run_diskless5.sh b/nc_test/run_diskless5.sh new file mode 100644 index 000000000..858e54079 --- /dev/null +++ b/nc_test/run_diskless5.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +if test "x$srcdir" = x ; then srcdir=`pwd`; fi +. ../test_common.sh + +set -e + +#Constants +CDL5=tst_diskless5.cdl +FILE5=tst_diskless5.nc + +echo "" +rm -f $FILE5 +# Generate FILE5 +${NCGEN} -3 -lb -o ${FILE5} ${srcdir}/${CDL5} + +echo "" +${execdir}/tst_diskless5 + +# cleanup +rm -f $FILE5 + +exit diff --git a/nc_test/tst_diskless5.c b/nc_test/tst_diskless5.c new file mode 100644 index 000000000..6c945c153 --- /dev/null +++ b/nc_test/tst_diskless5.c @@ -0,0 +1,4327 @@ +#include +#include +#include +#include +#include +#include +#include "netcdf.h" +#include "netcdf_mem.h" + +#undef MEM +#define DISKLESS +#define USEINT + +#undef DUMP +#undef DEBUG + +#ifdef MEM +static int mem = 1; +#else +static int mem = 0; +#endif + +#ifdef DISKLESS +#define MODE NC_NOCLOBBER|NC_DISKLESS +static int diskless = 1; +#else +#define MODE NC_NOCLOBBER +static int diskless = 0; +#endif + +#define PATH "tst_diskless5.nc" + +#ifdef USEINT +#define T int +#define NC_GET_VARA nc_get_vara_int +static const char* type = "int"; +#else +#define T float +#define NC_GET_VARA nc_get_vara_float +static const char* type = "float"; +#endif + +#define HRAPY 200 +#define HRAPX 333 + +static T amountofprecip[HRAPY*HRAPX]; + +#ifdef DEBUG +static void fill(); +#endif + +static size_t value_count[] = {HRAPY, HRAPX}; +static size_t start[] = {0, 0}; + +int +main(int argc, const char* argv[]) +{ + int status; + int ncid; + int rh_id; + T rh_vals[HRAPY*HRAPX]; + size_t i; +#ifdef MEM + int fd; + char buffer[1000000]; + size_t count; + off_t off; +#endif + + fprintf(stderr,"PATH: %s\n",PATH); + fprintf(stderr,"FLAGS: MEM=%d DISKLESS=%d TYPE=%s\n",mem,diskless,type); + +#ifdef DEBUG + fill(); +#endif + +#ifdef MEM + fd = open(PATH,O_RDONLY); + if(fd < 0) { + fprintf(stderr,"could not open foo.nc\n"); + assert(0); + } + off = lseek(fd,0,SEEK_END); + lseek(fd,0,SEEK_SET); + fprintf(stderr,"off=%lld\n",off); + count = (size_t)read(fd, buffer, sizeof(buffer)); + fprintf(stderr,"count=%u |rh_vals|=%u\n",count,sizeof(rh_vals)); + close(fd); +#endif + +#ifdef MEM + status = nc_open_mem(PATH, MODE, count, buffer, &ncid); +#else + status = nc_open(PATH, MODE, &ncid); +#endif + if(status != NC_NOERR) { + fprintf(stderr,"%s\n",nc_strerror(status)); + assert(0); + } + status = nc_inq_varid(ncid, "amountofprecip", &rh_id); + if(status != NC_NOERR) { + fprintf(stderr,"%s\n", nc_strerror(status)); + assert(0); + } + status = NC_GET_VARA(ncid, rh_id, start, value_count, rh_vals); + if(status != NC_NOERR) { + fprintf(stderr,"%s", nc_strerror(status)); + assert(0); + } + nc_close(ncid); + fprintf(stderr,"|amountofprecip|=%d\n",HRAPY*HRAPX); + for(i=0;i