Modify ncdap_test/test_nstride_cached.c

to use a dataset on remotetest instead
of an external server.
This commit is contained in:
Dennis Heimbigner 2014-07-01 10:39:18 -06:00
parent 49a32df7d4
commit 39a5bf5efa
3 changed files with 71 additions and 55 deletions

View File

@ -257,7 +257,7 @@ e::
cc -E -g -c ${E}.c ${INCL} -I../oc2 >${E}.txt
##################################################
T=test_varm3
T=test_nstride_cached
v::
cc -g -c ${T}.c ${INCL}

View File

@ -41,22 +41,36 @@ Problem was two-fold:
cc vars_whoi_test.c -g -o vars_whoi_test_4211 /usr/local/netcdf_4211/lib/libnetcdf.a /usr/local/hdf5_189/lib/libhdf5_hl.a /usr/local/hdf5_189/lib/libhdf5.a /usr/local/lib/libz.a -L/usr/lib64 -lc -lm -lcurl
cc vars_whoi_test.c -g -o vars_whoi_test /home/users/ansley/local/x86_nc43/lib/libnetcdf.a /usr/local/hdf5_189/lib/libhdf5_hl.a /usr/local/hdf5_189/lib/libhdf5.a /usr/local/lib/libz.a -L/usr/lib64 -lc -lm -lcurl
Closing and reopening the dataset between the two reads fixes the
incorrect data return
Setting the count to one less in the full data read also fixes the
incorrect data return
*/
/* Closing and reopening the dataset between the two reads fixes the
incorrect data return */
/* Setting the count to one less in the full data read also fixes the
incorrect data return */
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include "netcdf.h"
static int verbose = 0;
#define VERBOSE 1
/*
2014-07-01: (DMH) Changed the URL to use one from remotetest server.
to remove dependence on an external server.
*/
/*
static char* URL="http://geoport.whoi.edu/thredds/dodsC/coawst_4/use/fmrc/coawst_4_use_best.ncd";
Float64 lon_rho[eta_rho = 336][xi_rho = 896];
Float64 lat_rho[eta_rho = 336][xi_rho = 896];
*/
static char* URL="https://remotetest.unidata.ucar.edu/thredds/dodsC/testdods/rtofs.nc";
#define VAR1 "Latitude"
#define VAR2 "Longitude"
#define XSIZE 850
#define YSIZE 712
int
main()
@ -69,10 +83,10 @@ main()
size_t start[5], count[5];
ptrdiff_t stride[5], tmp_ptrdiff_t;
int pass = 1;
int nelems = XSIZE*YSIZE;
int idim, ndim;
//float dat[301060];
float *dat = (float*)malloc(sizeof(float)*301060);
float *dat = (float*)malloc(sizeof(float)*nelems);
float sdat[10];
for (idim=0; idim<5; idim++) {
@ -95,110 +109,111 @@ main()
exit(0);
}
ncstatus = nc_inq_varid(ncid, "lon_rho", &varid);
ncstatus = nc_inq_varid(ncid, VAR1, &varid);
ndim=2;
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Read lon_rho data w/o strides\n");
printf("Read %s data w/o strides\n",VAR1);
printf(" \n");
}
#endif
start[0] = 0;
start[1] = 0;
start[2] = 0;
start[3] = 0;
count[0] = 336;
count[1] = 896;
count[0] = XSIZE;
count[1] = YSIZE;
stride[0] = 1;
stride[1] = 1;
if(verbose) {
#ifdef VERBOSE
for (idim=0; idim<ndim; idim++)
printf("start[%1d]=%3lu count[%1d]=%3lu stride[%1d]=%3lu\n",
idim,start[idim],idim,count[idim],idim,stride[idim]);
}
#endif
ncstatus = nc_get_vars_float (ncid, varid, start, count, stride, (float*) dat);
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Print some of lon_rho\n");
printf("Print some of %s\n",VAR1);
printf(" \n");
for (i=0; i<10; i++)
printf("lon_rho[%d] = %f\n",i,dat[i]);
printf("%s[%d] = %f\n",VAR1,i,dat[i]);
printf(" \n");
for (i=301045; i<301055; i++)
printf("lon_rho[%d] = %f\n",i,dat[i]);
for (i=(nelems-11); i<(nelems-1); i++)
printf("%s[%d] = %f\n",VAR1,i,dat[i]);
printf(" \n");
}
#endif
memset((void*)dat,0,sizeof(dat));
/* Read a second variable */
ncstatus = nc_inq_varid(ncid, "lat_rho", &varid);
ncstatus = nc_inq_varid(ncid, VAR2, &varid);
ndim=2;
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Read lat_rho data w/o strides\n");
printf("Read %s data w/o strides\n",VAR2);
printf(" \n");
}
#endif
start[0] = 0;
start[1] = 0;
start[2] = 0;
start[3] = 0;
count[0] = 336;
count[1] = 896;
count[0] = XSIZE;
count[1] = YSIZE;
stride[0] = 1;
stride[1] = 1;
if(verbose) {
#ifdef VERBOSE
for (idim=0; idim<ndim; idim++)
printf("start[%d]=%3lu count[%d]=%3lu stride[%d]=%3lu\n",
idim, start[idim], idim, count[idim], idim, stride[idim]);
}
#endif
ncstatus = nc_get_vars_float (ncid, varid, start, count, stride, (float*) dat);
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Print some of lat_rho\n");
printf("Print some of %s\n",VAR2);
printf(" \n");
for (i=0; i<10; i++)
printf("lat_rho[%d] = %f\n",i,dat[i]);
printf("%s[%d] = %f\n",VAR2,i,dat[i]);
printf(" \n");
printf(" \n");
for (i=301045; i<301055; i++)
printf("lon_rho[%d] = %f\n",i,dat[i]);
for (i=(nelems-11); i<(nelems-1); i++)
printf("%s[%d] = %f\n",VAR2,i,dat[i]);
printf(" \n");
}
#endif
memset((void*)dat,0,sizeof(dat));
/* close and reopen the dataset, then the below read is correct */
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Close and reopen the dataset\n");
}
#endif
ncstatus = nc_close (ncid);
ncstatus = nc_open(URL, NC_NOWRITE, &ncid);
@ -206,14 +221,14 @@ if(verbose) {
/* ----------------------------------------------------- */
/* Read a subset of the data with strides */
ncstatus = nc_inq_varid(ncid, "lon_rho", &varid);
ncstatus = nc_inq_varid(ncid, VAR1, &varid);
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Read a subset of lon_rho data with strides\n");
printf("Read a subset of %s data with strides\n",VAR1);
printf(" \n");
}
#endif
start[0] = 250;
start[1] = 704;
@ -224,38 +239,39 @@ if(verbose) {
stride[0] = 2;
stride[1] = 4;
if(verbose) {
#ifdef VERBOSE
for (idim=0; idim<ndim; idim++)
printf("start[%1d]=%3lu count[%1d]=%3lu stride[%1d]=%3lu\n",
idim,start[idim],idim,count[idim],idim,stride[idim]);
}
#endif
memset((void*)sdat,0,sizeof(sdat));
ncstatus = nc_get_vars_float (ncid, varid, start, count, stride, (float*) sdat);
printf("status = %d\n", ncstatus);
/* Verify that all read values are 67 <= n < 68 */
/* Verify that all read values are 50 <= n < 51 */
for (i=0; i<10; i++) {
if(!(sdat[i] <= -67 && sdat[i] > -68)) {
printf("lon_rho[%d] = %f\n",i,sdat[i]);
if(sdat[i] <= 50.0 || sdat[i] > 51.0) {
printf("Out of range: %s[%d] = %f\n",VAR1, i,sdat[i]);
pass = 0;
}
}
if(verbose) {
#ifdef VERBOSE
printf(" \n");
printf("********************\n");
printf("Print values read. They should all be -67.xxxx \n");
printf("Print values read. They should all be 50.xxxx \n");
printf(" \n");
for (i=0; i<10; i++)
printf("lon_rho[%d] = %f\n",i,sdat[i]);
}
printf("%s[%d] = %f\n",VAR1,i,sdat[i]);
#endif
ncstatus = nc_close (ncid);
if(!pass) {
printf("*** FAIL: lon_rho value out of range.\n");
printf("*** FAIL: %s value out of range.\n",VAR1);
exit(1);
}

View File

@ -33,7 +33,7 @@ makeoc::
base=`basename $$f` ; \
cat $$f | tr -d ' ' >${THISDIR}/$$base; \
done
rm -f ocdebug.h
rm -f ocdebug.h XGetopt.[ch]
sed -e 's|^[#]if 1|#if 0|g' \
< ${OCDIR}/ocdebug.h | tr -d '\r' >./ocdebug.h
# This should match the bison command in Makefile.am