2010-06-03 21:24:43 +08:00
|
|
|
/* varm_test */
|
|
|
|
/* acm 9/15/09 */
|
|
|
|
/* ansley.b.manke@noaa.gov */
|
|
|
|
/* test nc_get_varm_float with calls similar to Ferret calls */
|
|
|
|
/* local file is correct results with stride: every second value */
|
|
|
|
/* remote url; incorrect results with stride
|
|
|
|
|
|
|
|
linked with:
|
|
|
|
cc varm_test.c -g -o varm_test /home/nstout/ansley/local/lib/libnetcdf.a -L/usr/lib64 -lc -lm -lcurl
|
|
|
|
|
|
|
|
netcdf.a from the daily snapshot
|
|
|
|
netcdf-4.1-beta2-snapshot2009091100
|
2018-10-31 10:48:12 +08:00
|
|
|
|
|
|
|
TODO: Note that this test uses thredds server
|
2010-06-03 21:24:43 +08:00
|
|
|
*/
|
|
|
|
|
2010-07-30 04:37:05 +08:00
|
|
|
/* This particular test seems to occasionally expose a server error*/
|
|
|
|
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "netcdf.h"
|
2012-07-17 04:34:31 +08:00
|
|
|
#include "ncdispatch.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "nctestserver.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#undef STANDALONE
|
|
|
|
|
2010-07-30 04:37:05 +08:00
|
|
|
#undef DEBUG
|
|
|
|
|
2014-10-05 05:59:16 +08:00
|
|
|
#define TESTPATH "/dodsC/testdods/coads_climatology.nc"
|
2010-06-03 21:24:43 +08:00
|
|
|
#define VAR "SST"
|
|
|
|
|
|
|
|
static float expected_stride1[12] = {
|
|
|
|
29.430857,
|
|
|
|
29.403780,
|
|
|
|
29.325428,
|
|
|
|
29.578333,
|
|
|
|
29.660833,
|
|
|
|
29.378437,
|
|
|
|
29.151943,
|
|
|
|
29.109715,
|
|
|
|
29.114864,
|
|
|
|
29.550285,
|
|
|
|
29.542500,
|
|
|
|
29.500286
|
|
|
|
};
|
|
|
|
|
|
|
|
static float expected_stride2[6] = {
|
|
|
|
29.430857,
|
|
|
|
29.325428,
|
|
|
|
29.660833,
|
|
|
|
29.151943,
|
|
|
|
29.114864,
|
|
|
|
29.542500
|
|
|
|
};
|
|
|
|
|
|
|
|
static float expected_stride3[3] = {
|
|
|
|
29.430857,
|
|
|
|
29.378437,
|
|
|
|
29.542500
|
|
|
|
};
|
|
|
|
|
2010-07-30 04:37:05 +08:00
|
|
|
void
|
|
|
|
check(int status, char* file, int line)
|
|
|
|
{
|
|
|
|
if(status == 0) return;
|
|
|
|
fprintf(stderr,"error: %s at %s:%d\n",nc_strerror(status),file,line);
|
2010-12-18 07:54:09 +08:00
|
|
|
exit(1);
|
2010-07-30 04:37:05 +08:00
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
|
|
|
|
int ncid;
|
|
|
|
int varid;
|
|
|
|
int i,fail;
|
|
|
|
int err;
|
|
|
|
size_t start[5], count[5];
|
|
|
|
ptrdiff_t stride[5], imap[5];
|
2012-02-04 05:31:50 +08:00
|
|
|
int idim;
|
2010-06-03 21:24:43 +08:00
|
|
|
float dat[20];
|
2012-07-17 03:57:58 +08:00
|
|
|
char url[4096];
|
2014-10-05 05:59:16 +08:00
|
|
|
char* svc;
|
2012-02-04 05:31:50 +08:00
|
|
|
#ifdef STANDALONE
|
|
|
|
int ndim;
|
|
|
|
#endif
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2010-07-30 04:37:05 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
oc_loginit();
|
|
|
|
oc_setlogging(1);
|
|
|
|
oc_logopen(NULL);
|
|
|
|
#endif
|
|
|
|
|
2014-10-05 05:59:16 +08:00
|
|
|
/* Find Test Server */
|
2020-01-01 06:42:58 +08:00
|
|
|
svc = nc_findtestserver("thredds",REMOTETESTSERVERS);
|
2014-10-05 05:59:16 +08:00
|
|
|
|
|
|
|
if(svc == NULL) {
|
2020-01-01 06:42:58 +08:00
|
|
|
fprintf(stderr,"WARNING: Cannot locate test server\n");
|
2014-10-05 05:59:16 +08:00
|
|
|
exit(0);
|
2012-07-17 03:57:58 +08:00
|
|
|
}
|
2017-11-24 01:55:24 +08:00
|
|
|
strncpy(url,svc,sizeof(url));
|
|
|
|
strlcat(url,TESTPATH,sizeof(url));
|
2012-07-17 03:57:58 +08:00
|
|
|
printf("*** Test: varm on URL: %s\n",url);
|
2018-10-31 10:48:12 +08:00
|
|
|
free(svc);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-07-17 03:57:58 +08:00
|
|
|
check(err = nc_open(url, NC_NOWRITE, &ncid),__FILE__,__LINE__);
|
2010-07-30 04:37:05 +08:00
|
|
|
check(err = nc_inq_varid(ncid, VAR, &varid),__FILE__,__LINE__);
|
2010-06-03 21:24:43 +08:00
|
|
|
for (idim=0; idim<4; idim++) {
|
|
|
|
start[idim] = 0;
|
|
|
|
count[idim] = 1;
|
|
|
|
stride[idim] = 1;
|
|
|
|
imap[idim] = 1;
|
|
|
|
}
|
2012-02-04 05:31:50 +08:00
|
|
|
#ifdef STANDALONE
|
2010-06-03 21:24:43 +08:00
|
|
|
ndim=3;
|
2012-02-04 05:31:50 +08:00
|
|
|
#endif
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
printf("*** Testing: stride case 1\n");
|
|
|
|
start[1] = 44;
|
|
|
|
start[2] = 66;
|
|
|
|
count[0] = 12;
|
|
|
|
|
|
|
|
#ifdef STANDALONE
|
|
|
|
printf("start = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)start[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("count = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)count[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("stride = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)stride[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("map = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)imap[i]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
err = nc_get_vars_float (ncid, varid, start, count, stride,
|
|
|
|
(float*) dat);
|
|
|
|
printf("vars: %s =",VAR);
|
|
|
|
for(i=0;i<12;i++) printf(" %f",dat[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2011-10-07 04:04:06 +08:00
|
|
|
check(err = nc_get_varm_float (ncid, varid, start, count, stride, imap,(float*) dat),__FILE__,__LINE__);
|
2014-08-27 01:19:32 +08:00
|
|
|
/* check(err = nc_get_vara_float (ncid, varid, start, count, (float*) dat),__FILE__,__LINE__); */
|
2011-09-16 00:57:16 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef STANDALONE
|
|
|
|
printf("varm: %s =",VAR);
|
|
|
|
for(i=0;i<12;i++) printf(" %f",dat[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
fail=0;
|
|
|
|
for(i=0;i<12;i++) {
|
|
|
|
float delta = (dat[i] - expected_stride1[i]);
|
|
|
|
if(delta > 0.0005 || delta < -0.0005) {
|
|
|
|
fprintf(stderr,"*** Failure: unexpected value: delta=%g dat[%d]=%g expected[%d]=%g\n",
|
|
|
|
delta, i, dat[i], i, expected_stride1[i]);
|
|
|
|
fail = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("*** %s: stride case 1\n",(fail?"Fail":"Pass"));
|
|
|
|
|
|
|
|
printf("*** Testing: stride case 2\n");
|
|
|
|
/* case with strides #1 where len % stride == 0 */
|
|
|
|
start[1] = 44;
|
|
|
|
start[2] = 66;
|
|
|
|
count[0] = 6;
|
|
|
|
stride[0] = 2;
|
|
|
|
|
|
|
|
#ifdef STANDALONE
|
|
|
|
printf("start = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)start[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("count = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)count[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("stride = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)stride[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("map = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)imap[i]);
|
|
|
|
printf("\n");
|
|
|
|
|
2010-07-30 04:37:05 +08:00
|
|
|
check(err = nc_get_vars_float(ncid, varid, start, count, stride,
|
|
|
|
(float*) dat),__FILE__,__LINE__);
|
2010-06-03 21:24:43 +08:00
|
|
|
printf("strided.vars: %s =",VAR);
|
|
|
|
for(i=0;i<6;i++) printf(" %f",dat[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
2010-07-30 04:37:05 +08:00
|
|
|
check(err = nc_get_varm_float(ncid, varid, start, count, stride, imap,
|
|
|
|
(float*) dat),__FILE__,__LINE__);
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef STANDALONE
|
|
|
|
printf("strided.varm: %s =",VAR);
|
|
|
|
for(i=0;i<6;i++) printf(" %f",dat[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
fail=0;
|
|
|
|
for(i=0;i<6;i++) {
|
|
|
|
float delta = (dat[i] - expected_stride2[i]);
|
|
|
|
if(delta > 0.0005 || delta < -0.0005) {
|
|
|
|
fprintf(stderr,"*** Failure: unexpected value: delta=%g dat[%d]=%g expected[%d]=%g\n",
|
|
|
|
delta, i, dat[i], i, expected_stride2[i]);
|
|
|
|
fail=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("*** %s: stride case 2\n",(fail?"Fail":"Pass"));
|
|
|
|
|
|
|
|
/* case with strides #2: len % stride != 0 */
|
|
|
|
printf("*** Testing: stride case 3\n");
|
|
|
|
start[1] = 44;
|
|
|
|
start[2] = 66;
|
|
|
|
count[0] = 3;
|
|
|
|
stride[0] = 5;
|
|
|
|
|
|
|
|
#ifdef STANDALONE
|
|
|
|
printf("start = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)start[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("count = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)count[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("stride = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)stride[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("map = ");
|
|
|
|
for(i=0;i<ndim;i++) printf(" %d",(int)imap[i]);
|
|
|
|
printf("\n");
|
|
|
|
|
2010-07-30 04:37:05 +08:00
|
|
|
check(err = nc_get_vars_float(ncid, varid, start, count, stride,
|
|
|
|
(float*) dat),__FILE__,__LINE__);
|
2010-06-03 21:24:43 +08:00
|
|
|
printf("strided.vars: %s =",VAR);
|
|
|
|
for(i=0;i<3;i++) printf(" %f",dat[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
2010-07-30 04:37:05 +08:00
|
|
|
check(err = nc_get_varm_float(ncid, varid, start, count, stride, imap,
|
|
|
|
(float*) dat),__FILE__,__LINE__);
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifdef STANDALONE
|
|
|
|
printf("strided.varm: %s =",VAR);
|
|
|
|
for(i=0;i<3;i++) printf(" %f",dat[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
fail=0;
|
|
|
|
for(i=0;i<3;i++) {
|
|
|
|
float delta = (dat[i] - expected_stride3[i]);
|
|
|
|
if(delta > 0.0005 || delta < -0.0005) {
|
|
|
|
fprintf(stderr,"*** Failure: stride case 2: unexpected value: delta=%g dat[%d]=%g expected[%d]=%g\n",
|
|
|
|
delta, i, dat[i], i, expected_stride3[i]);
|
|
|
|
fail=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("*** %s: stride case 3\n",(fail?"Fail":"Pass"));
|
|
|
|
|
2017-07-06 00:03:48 +08:00
|
|
|
nc_close(ncid);
|
2010-12-18 07:54:09 +08:00
|
|
|
return fail;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
}
|