netcdf-c/nc_test/test_write.m4

2507 lines
85 KiB
Plaintext
Raw Normal View History

2016-10-13 15:17:31 +08:00
dnl This is m4 source.
dnl Process using m4 to produce 'C' language file.
dnl
dnl This file is supposed to be the same as PnetCDF's test_write.m4
dnl
dnl If you see this line, you can ignore the next one.
/* Do not edit this file. It is produced from the corresponding .m4 source */
dnl
/*
* Copyright (C) 2003, Northwestern University and Argonne National Laboratory
* See COPYRIGHT notice in top-level directory.
*/
/* $Id: test_write.m4 2655 2016-11-25 21:03:48Z wkliao $ */
2016-10-13 15:17:31 +08:00
dnl
dnl The command-line m4 macro "PNETCDF" is to differentiate PnetCDF and netCDF
dnl in terms of function prefix names (ncmpi_ vs. nc_), integer data types
dnl (MPI_Offset vs. size_t), and function name substrings for external data
dnl types.
dnl
#include <sys/types.h> /* open() */
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <unistd.h> /* read() */
2010-06-03 21:24:43 +08:00
#include "tests.h"
#include "math.h"
2016-10-13 15:17:31 +08:00
define(`EXPECT_ERR',`error("expecting $1 but got %s",nc_err_code_name($2));')dnl
2016-10-13 15:17:31 +08:00
define(`IntType', `ifdef(`PNETCDF',`MPI_Offset',`size_t')')dnl
define(`PTRDType',`ifdef(`PNETCDF',`MPI_Offset',`ptrdiff_t')')dnl
define(`TestFunc',`ifdef(`PNETCDF',`test_ncmpi_$1',`test_nc_$1')')dnl
define(`APIFunc', `ifdef(`PNETCDF',`ncmpi_$1',`nc_$1')')dnl
2016-10-13 15:17:31 +08:00
define(`FileOpen', `ifdef(`PNETCDF',`ncmpi_open(comm, $1, $2, info, $3)', `file_open($1, $2, $3)')')dnl
define(`FileCreate',`ifdef(`PNETCDF',`ncmpi_create(comm, $1, $2, info, $3)', `file_create($1, $2, $3)')')dnl
define(`FileDelete',`ifdef(`PNETCDF',`ncmpi_delete($1,$2)',`nc_delete($1)')')dnl
define(`Def_Vars', `ifdef(`PNETCDF',`def_vars($1,$2)',`def_vars($1)')')dnl
define(`Put_Atts', `ifdef(`PNETCDF',`put_atts($1,$2,$3)',`put_atts($1)')')dnl
define(`Put_Vars', `ifdef(`PNETCDF',`put_vars($1,$2)',`put_vars($1)')')dnl
define(`Check_File',`ifdef(`PNETCDF',`check_file($1,$2,$3)',`check_file($1)')')dnl
define(`Check_Atts',`ifdef(`PNETCDF',`check_atts($1,$2,$3)',`check_atts($1)')')dnl
define(`Check_Vars',`ifdef(`PNETCDF',`check_vars($1,$2)',`check_vars($1)')')dnl
define(`VarArgs', `ifdef(`PNETCDF',`int numVars',`void')')dnl
define(`AttVarArgs',`ifdef(`PNETCDF',`int numGatts, int numVars',`void')')dnl
define(`GetVar1TYPE',`ifdef(`PNETCDF',`ncmpi_get_var1_$1_all',`nc_get_var1_$1')')dnl
define(`PutVar1TYPE',`ifdef(`PNETCDF',`ncmpi_put_var1_$1_all',`nc_put_var1_$1')')dnl
define(`PutVar1', `ifdef(`PNETCDF',`ncmpi_put_var1_all($1,$2,$3,$4,$5,$6)', `nc_put_var1($1,$2,$3,$4)')')dnl
define(`PutVar', `ifdef(`PNETCDF',`ncmpi_put_var_all( $1,$2,$3,$4,$5)', `nc_put_var( $1,$2,$3)')')dnl
define(`PutVara', `ifdef(`PNETCDF',`ncmpi_put_vara_all($1,$2,$3,$4,$5,$6,$7)', `nc_put_vara($1,$2,$3,$4,$5)')')dnl
define(`PutVars', `ifdef(`PNETCDF',`ncmpi_put_vars_all($1,$2,$3,$4,$5,$6,$7,$8)', `nc_put_vars($1,$2,$3,$4,$5,$6)')')dnl
define(`PutVarm', `ifdef(`PNETCDF',`ncmpi_put_varm_all($1,$2,$3,$4,$5,$6,$7,$8,$9)', `nc_put_varm($1,$2,$3,$4,$5,$6,$7)')')dnl
2010-06-03 21:24:43 +08:00
/*
* Test APIFunc(create)
* For mode in NC_NOCLOBBER, NC_CLOBBER do:
2010-06-03 21:24:43 +08:00
* create netcdf file 'scratch.nc' with no data, close it
2016-10-13 15:17:31 +08:00
* test that it can be opened, do APIFunc(inq) to check nvars = 0, etc.
2010-06-03 21:24:43 +08:00
* Try again in NC_NOCLOBBER mode, check error return
* On exit, delete this file
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(create)(void)
2010-06-03 21:24:43 +08:00
{
int clobber; /* 0 for NC_NOCLOBBER, 1 for NC_CLOBBER */
2010-06-03 21:24:43 +08:00
int err;
int ncid;
2016-10-13 15:17:31 +08:00
int ndims; /* number of dimensions */
int nvars; /* number of variables */
int ngatts; /* number of global attributes */
int recdim; /* id of unlimited dimension */
int nok=0;
2010-06-03 21:24:43 +08:00
for (clobber = 0; clobber < 2; clobber++) {
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, clobber ? NC_CLOBBER : NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR)
error("create: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileOpen(scratch, NC_NOWRITE, &ncid);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(inq)(ncid, &ndims, &nvars, &ngatts, &recdim);
IF (err != NC_NOERR)
error("inq: %s", APIFunc(strerror)(err));
else IF (ndims != 0)
error("inq: wrong number of dimensions returned, %d", ndims);
else IF (nvars != 0)
error("inq: wrong number of variables returned, %d", nvars);
else IF (ngatts != 0)
error("inq: wrong number of global atts returned, %d", ngatts);
else IF (recdim != -1)
error("inq: wrong record dimension ID returned, %d", recdim);
ELSE_NOK
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EEXIST)
2016-10-13 15:17:31 +08:00
error("expecting NC_EEXIST but got %s", nc_err_code_name(err));
ELSE_NOK
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
error("remove of %s failed", scratch);
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(redef)
* (In fact also tests APIFunc(enddef) - called from TestFunc(enddef))
2010-06-03 21:24:43 +08:00
* BAD_ID
* attempt redef (error) & enddef on read-only file
* create file, define dims & vars.
2010-06-03 21:24:43 +08:00
* attempt put var (error)
* attempt redef (error) & enddef.
* put vars
* attempt def new dims (error)
* redef
* def new dims, vars.
* put atts
* enddef
* put vars
* close
* check file: vars & atts
* check reopening with NC_WRITE and adding new dims, atts, vars
2010-06-03 21:24:43 +08:00
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(redef)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
2016-10-13 15:17:31 +08:00
int ncid; /* netcdf id */
2010-06-03 21:24:43 +08:00
/* used to force effective test of ncio->move() in redef */
IntType sizehint = 8192;
2010-06-03 21:24:43 +08:00
int dimid; /* dimension id */
int varid; /* variable id */
int varid1; /* variable id */
2016-10-13 15:17:31 +08:00
int nok=0, err;
2010-06-03 21:24:43 +08:00
const char * title = "Not funny";
double var;
char name[NC_MAX_NAME];
2016-10-13 15:17:31 +08:00
IntType length;
int fmt_variant1, fmt_variant2;
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* BAD_ID tests */
err = APIFunc(redef)(BAD_ID);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(enddef)(BAD_ID);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
/* read-only tests */
err = FileOpen(testfile, NC_NOWRITE, &ncid);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(redef)(ncid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EPERM)
2016-10-13 15:17:31 +08:00
error("expecting NC_EPERM but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(enddef)(ncid);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
/* tests using scratch file */
ifdef(`PNETCDF',`dnl
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);',`dnl
err = file__create(scratch, NC_NOCLOBBER, 0, &sizehint, &ncid);')
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
ifdef(`PNETCDF',,`dnl
/* limit for ncio implementations which have infinite chunksize */
if(sizehint > 32768) sizehint = 16384;')
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
Put_Atts(ncid, numGatts, numVars);
err = APIFunc(inq_varid)(ncid, "d", &varid);
IF (err != NC_NOERR)
error("inq_varid: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
var = 1.0;
2016-10-13 15:17:31 +08:00
ifdef(`PNETCDF', `
err = ncmpi_begin_indep_data(ncid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EINDEFINE)
error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err));')dnl
2016-10-13 15:17:31 +08:00
err = PutVar1TYPE(double)(ncid, varid, NULL, &var);
2010-06-03 21:24:43 +08:00
IF (err != NC_EINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err));
ifdef(`PNETCDF', `
err = ncmpi_end_indep_data(ncid);
IF (err != NC_ENOTINDEP)
error("expecting NC_ENOTINDEP but got %s", nc_err_code_name(err));')dnl
2016-10-13 15:17:31 +08:00
err = APIFunc(redef)(ncid);
IF (err != NC_EINDEFINE)
error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
ELSE_NOK
Put_Vars(ncid, numVars);
err = APIFunc(def_dim)(ncid, "abc", sizehint, &dimid);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
err = APIFunc(redef)(ncid);
IF (err != NC_NOERR)
error("redef: %s", APIFunc(strerror)(err));
ELSE_NOK
2016-10-13 15:17:31 +08:00
err = APIFunc(set_fill)(ncid, NC_NOFILL, NULL);
IF (err != NC_NOERR)
error("set_fill: %s", APIFunc(strerror)(err));
2016-10-13 15:17:31 +08:00
err = APIFunc(def_dim)(ncid, "abc", sizehint, &dimid);
IF (err != NC_NOERR)
error("def_dim: %s", APIFunc(strerror)(err));
err = APIFunc(def_var)(ncid, "abcScalar", NC_INT, 0, NULL, &varid);
IF (err != NC_NOERR)
error("def_var: %s", APIFunc(strerror)(err));
err = APIFunc(def_var)(ncid, "abc", NC_INT, 1, &dimid, &varid1);
IF (err != NC_NOERR)
error("def_var: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
{
2016-10-13 15:17:31 +08:00
int dimids[NDIMS +1];
int ii = 0;
for(ii = 0; ii < NDIMS; ii++) dimids[ii] = ii;
2016-10-13 15:17:31 +08:00
dimids[NDIMS] = dimid;
err = APIFunc(def_var)(ncid, "abcRec", NC_INT, NDIMS, dimids, &varid1);
IF (err != NC_NOERR)
error("def_var: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(put_att_text)(ncid, NC_GLOBAL, "title", 1+strlen(title), title);
IF (err != NC_NOERR)
error("put_att_text: %s", APIFunc(strerror)(err));
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
var = 1.0;
2016-10-13 15:17:31 +08:00
ifdef(`PNETCDF', `
err = ncmpi_end_indep_data(ncid);
IF (err != NC_ENOTINDEP)
error("expecting NC_ENOTINDEP but got %s", nc_err_code_name(err));')dnl
2016-10-13 15:17:31 +08:00
err = PutVar1TYPE(double)(ncid, varid, NULL, &var);
IF (err != NC_NOERR)
error("put_var1_double: %s", APIFunc(strerror)(err));
err = APIFunc(inq_format)(ncid, &fmt_variant1);
IF (err)
error("inq_format: %s", APIFunc(strerror)(err));
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
/* check scratch file written as expected */
Check_File(scratch, numGatts, numVars); /* checks all except "abc" stuff added above */
IF ((err = FileOpen(scratch, NC_NOWRITE, &ncid)))
error("open: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(inq_dim)(ncid, dimid, name, &length)))
error("inq_dim: %s", APIFunc(strerror)(err));
IF (strcmp(name, "abc") != 0)
error("Unexpected dim name");
IF (length != sizehint)
error("Unexpected dim length");
IF ((err = GetVar1TYPE(double)(ncid, varid, NULL, &var)))
error("get_var1_double: %s", APIFunc(strerror)(err));
IF (var != 1.0)
error("get_var1_double: unexpected value");
IF ((err = APIFunc(close)(ncid)))
error("close: %s", APIFunc(strerror)(err));
/* open scratch file for writing, add another dim, var, att, then check */
IF ((err = FileOpen(scratch, NC_WRITE, &ncid)))
error("open: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(redef)(ncid)))
error("redef: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(def_dim)(ncid, "def", sizehint, &dimid)))
error("def_dim: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(def_var)(ncid, "defScalar", NC_INT, 0, NULL, &varid)))
error("def_var: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(def_var)(ncid, "def", NC_INT, 1, &dimid, &varid1)))
error("def_var: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(put_att_text)(ncid, NC_GLOBAL, "Credits", 1+strlen("Thanks!"), "Thanks!")))
error("put_att_text: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(enddef)(ncid)))
error("enddef: %s", APIFunc(strerror)(err));
var = 2.0;
IF ((err = PutVar1TYPE(double)(ncid, varid, NULL, &var)))
error("put_var1_double: %s", APIFunc(strerror)(err));
IF ((err = APIFunc(close)(ncid)))
error("close: %s", APIFunc(strerror)(err));
2016-10-13 15:17:31 +08:00
/* check scratch file written as expected */
Check_File(scratch, numGatts, numVars);
2016-10-13 15:17:31 +08:00
err = FileOpen(scratch, NC_NOWRITE, &ncid);
IF (err)
2016-10-13 15:17:31 +08:00
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(inq_dim)(ncid, dimid, name, &length);
IF (err)
2016-10-13 15:17:31 +08:00
error("inq_dim: %s", APIFunc(strerror)(err));
IF (strcmp(name, "def") != 0)
2016-10-13 15:17:31 +08:00
error("Unexpected dim name");
IF (length != sizehint)
2016-10-13 15:17:31 +08:00
error("Unexpected dim length");
err = GetVar1TYPE(double)(ncid, varid, NULL, &var);
IF (err)
2016-10-13 15:17:31 +08:00
error("get_var1_double: %s", APIFunc(strerror)(err));
IF (var != 2.0)
2016-10-13 15:17:31 +08:00
error("get_var1_double: unexpected value");
/* make sure format variant hasn't changed from when created */
err = APIFunc(inq_format)(ncid, &fmt_variant2);
IF (err)
error("inq_format: %s", APIFunc(strerror)(err));
IF (fmt_variant1 != fmt_variant2)
error("enddef changed format variant");
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err)
2016-10-13 15:17:31 +08:00
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(enddef)
* Simply calls TestFunc(redef) which tests both APIFunc(redef) & APIFunc(enddef)
2010-06-03 21:24:43 +08:00
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(enddef)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
2016-10-13 15:17:31 +08:00
ifdef(`PNETCDF',
`return test_ncmpi_redef(numGatts, numVars);',
`return test_nc_redef();')
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(sync)
2010-06-03 21:24:43 +08:00
* try with bad handle, check error
* try in define mode, check error
* try writing with one handle, reading with another on same netCDF
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(sync)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
int ncidw; /* netcdf id for writing */
int ncidr; /* netcdf id for reading */
2016-10-13 15:17:31 +08:00
int nok=0, err;
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* BAD_ID test */
err = APIFunc(sync)(BAD_ID);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* create scratch file & try APIFunc(sync) in define mode */
err = FileCreate(scratch, NC_NOCLOBBER, &ncidw);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(sync)(ncidw);
2010-06-03 21:24:43 +08:00
IF (err != NC_EINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* write using same handle */
2010-06-03 21:24:43 +08:00
def_dims(ncidw);
2016-10-13 15:17:31 +08:00
Def_Vars(ncidw, numVars);
Put_Atts(ncidw, numGatts, numVars);
err = APIFunc(enddef)(ncidw);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
Put_Vars(ncidw, numVars);
err = APIFunc(sync)(ncidw);
IF (err != NC_NOERR)
error("sync of ncidw failed: %s", APIFunc(strerror)(err));
ELSE_NOK
/* open another handle, APIFunc(sync), read (check) */
err = FileOpen(scratch, NC_NOWRITE, &ncidr);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(sync)(ncidr);
IF (err != NC_NOERR)
error("sync of ncidr failed: %s", APIFunc(strerror)(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
check_dims(ncidr);
2016-10-13 15:17:31 +08:00
Check_Atts(ncidr, numGatts, numVars);
Check_Vars(ncidr, numVars);
/* close both handles */
err = APIFunc(close)(ncidr);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = APIFunc(close)(ncidw);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(abort)
2010-06-03 21:24:43 +08:00
* try with bad handle, check error
* try in define mode before anything written, check that file was deleted
2016-10-13 15:17:31 +08:00
* try after APIFunc(enddef), APIFunc(redef), define new dims, vars, atts
2010-06-03 21:24:43 +08:00
* try after writing variable
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(abort)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid; /* netcdf id */
int err;
int ndims;
int nvars;
int ngatts;
2016-10-13 15:17:31 +08:00
int nok=0;
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* BAD_ID test */
err = APIFunc(abort)(BAD_ID);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* create scratch file & try APIFunc(abort) in define mode */
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
Put_Atts(ncid, numGatts, numVars);
err = APIFunc(abort)(ncid);
IF (err != NC_NOERR)
error("abort of ncid failed: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(close)(ncid); /* should already be closed */
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
err = FileDelete(scratch, info); /* should already be deleted */
2016-10-26 04:11:16 +08:00
ifdef(`PNETCDF',
`IF (err != NC_ENOENT && err != NC_EFILE)
error("expecting NC_ENOENT or NC_EFILE but got %s", nc_err_code_name(err));',
`IF (err != ENOENT && err != NC_EIO)
error("expecting ENOENT or NC_EIO but got %s", nc_err_code_name(err));')dnl
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/*
* create scratch file
* do APIFunc(enddef) & APIFunc(redef)
* define new dims, vars, atts
* try APIFunc(abort): should restore previous state (no dims, vars, atts)
*/
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
err = APIFunc(redef)(ncid);
IF (err != NC_NOERR)
error("redef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
Put_Atts(ncid, numGatts, numVars);
err = APIFunc(abort)(ncid);
IF (err != NC_NOERR)
error("abort of ncid failed: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(close)(ncid); /* should already be closed */
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
err = FileOpen(scratch, NC_NOWRITE, &ncid);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(inq)(ncid, &ndims, &nvars, &ngatts, NULL);
IF (err != NC_NOERR)
error("inq: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (ndims != 0)
error("ndims should be 0");
IF (nvars != 0)
error("nvars should be 0");
IF (ngatts != 0)
error("ngatts should be 0");
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
/* try APIFunc(abort) in data mode - should just close */
err = FileCreate(scratch, NC_CLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
Put_Atts(ncid, numGatts, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
Put_Vars(ncid, numVars);
err = APIFunc(abort)(ncid);
IF (err != NC_NOERR)
error("abort of ncid failed: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(close)(ncid); /* should already be closed */
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
Check_File(scratch, numGatts, numVars);
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(def_dim)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
* try in data mode, check error
* check that returned id is one more than previous id
* try adding same dimension twice, check error
* try with illegal sizes, check error
2016-10-13 15:17:31 +08:00
* make sure unlimited size works, shows up in APIFunc(inq_unlimdim)
2010-06-03 21:24:43 +08:00
* try to define a second unlimited dimension, check error
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(def_dim)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid;
2016-10-13 15:17:31 +08:00
int err; /* status */
int i, nok=0;
2010-06-03 21:24:43 +08:00
int dimid; /* dimension id */
2016-10-13 15:17:31 +08:00
IntType length;
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* BAD_ID test */
err = APIFunc(def_dim)(BAD_ID, "abc", 8, &dimid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* data mode test */
err = FileCreate(scratch, NC_CLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
err = APIFunc(def_dim)(ncid, "abc", 8, &dimid);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
/* define-mode tests: unlimited dim */
err = APIFunc(redef)(ncid);
IF (err != NC_NOERR)
error("redef: %s", APIFunc(strerror)(err));
err = APIFunc(def_dim)(ncid, dim_name[0], NC_UNLIMITED, &dimid);
IF (err != NC_NOERR)
error("def_dim: %s", APIFunc(strerror)(err));
ELSE_NOK
IF (dimid != 0)
2016-10-13 15:17:31 +08:00
error("Unexpected dimid");
ELSE_NOK
err = APIFunc(inq_unlimdim)(ncid, &dimid);
IF (err != NC_NOERR)
error("inq_unlimdim: %s", APIFunc(strerror)(err));
IF (dimid != 0)
2016-10-13 15:17:31 +08:00
error("Unexpected recdim");
err = APIFunc(inq_dimlen)(ncid, dimid, &length);
IF (length != 0)
2016-10-13 15:17:31 +08:00
error("Unexpected length");
err = APIFunc(def_dim)(ncid, "abc", NC_UNLIMITED, &dimid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EUNLIMIT)
2016-10-13 15:17:31 +08:00
error("expecting NC_EUNLIMIT but got %s", nc_err_code_name(err));
ELSE_NOK
2011-11-14 12:20:19 +08:00
/* define-mode tests: remaining dims */
2010-06-03 21:24:43 +08:00
for (i = 1; i < NDIMS; i++) {
2016-10-13 15:17:31 +08:00
err = APIFunc(def_dim)(ncid, dim_name[i-1], dim_len[i], &dimid);
IF (err != NC_ENAMEINUSE)
error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(def_dim)(ncid, BAD_NAME, dim_len[i], &dimid);
IF (err != NC_EBADNAME)
error("expecting NC_EBADNAME but got %s", nc_err_code_name(err));
ELSE_NOK
ifdef(`PNETCDF', ,`if(sizeof(long) > 4) /* Fix: dmh 11/4/2011: works only if sizeof(long) > 4 */')
2016-10-13 16:26:08 +08:00
{
err = APIFunc(def_dim)(ncid, dim_name[i], (IntType)(NC_UNLIMITED-1), &dimid);
2016-10-13 16:26:08 +08:00
IF (err != NC_EDIMSIZE)
error("expecting NC_EDIMSIZE but got %s", nc_err_code_name(err));
ELSE_NOK
}
2016-10-13 15:17:31 +08:00
err = APIFunc(def_dim)(ncid, dim_name[i], dim_len[i], &dimid);
IF (err != NC_NOERR)
error("def_dim: %s", APIFunc(strerror)(err));
ELSE_NOK
IF (dimid != i)
error("Unexpected dimid");
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* Following just to expand unlimited dim */
Def_Vars(ncid, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
Put_Vars(ncid, numVars);
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* Check all dims */
2010-06-03 21:24:43 +08:00
check_dims(ncid);
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(rename_dim)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
2016-10-13 15:17:31 +08:00
* check that proper rename worked with APIFunc(inq_dim)
2010-06-03 21:24:43 +08:00
* try renaming to existing dimension name, check error
* try with bad dimension handle, check error
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(rename_dim)(void)
2010-06-03 21:24:43 +08:00
{
int ncid;
2016-10-13 15:17:31 +08:00
int err, nok=0; /* status */
2010-06-03 21:24:43 +08:00
char name[NC_MAX_NAME];
2016-10-13 15:17:31 +08:00
/* BAD_ID test */
err = APIFunc(rename_dim)(BAD_ID, 0, "abc");
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* main tests */
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid);
2016-10-13 15:17:31 +08:00
err = APIFunc(rename_dim)(ncid, BAD_DIMID, "abc");
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADDIM)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADDIM but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(rename_dim)(ncid, 2, "abc");
IF (err != NC_NOERR)
error("rename_dim: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_dimname)(ncid, 2, name);
2010-06-03 21:24:43 +08:00
IF (strcmp(name, "abc") != 0)
error("Unexpected name: %s", name);
2016-10-13 15:17:31 +08:00
err = APIFunc(rename_dim)(ncid, 0, "abc");
2010-06-03 21:24:43 +08:00
IF (err != NC_ENAMEINUSE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(def_var)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
* try with bad name, check error
* scalar tests:
2016-10-13 15:17:31 +08:00
* check that proper define worked with APIFunc(inq_var)
2010-06-03 21:24:43 +08:00
* try redefining an existing variable, check error
* try with bad datatype, check error
* try with bad number of dimensions, check error
* try in data mode, check error
* check that returned id is one more than previous id
* try with bad dimension ids, check error
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(def_var)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid;
int varid;
2016-10-13 15:17:31 +08:00
int err, nok=0; /* status */
2010-06-03 21:24:43 +08:00
int i;
int ndims;
int natts;
char name[NC_MAX_NAME];
int dimids[MAX_RANK];
nc_type datatype;
2016-10-13 15:17:31 +08:00
/* BAD_ID test */
err = APIFunc(def_var)(BAD_ID, "abc", NC_SHORT, 0, NULL, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* scalar tests */
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(def_var)(ncid, "abc", NC_SHORT, 0, NULL, &varid);
IF (err != NC_NOERR)
error("def_var: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_var)(ncid, varid, name, &datatype, &ndims, dimids, &natts);
IF (err != NC_NOERR)
error("inq_var: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (strcmp(name, "abc") != 0)
error("Unexpected name: %s", name);
IF (datatype != NC_SHORT)
error("Unexpected datatype");
IF (ndims != 0)
error("Unexpected rank");
2016-10-13 15:17:31 +08:00
err = APIFunc(def_var)(ncid, BAD_NAME, NC_SHORT, 0, NULL, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADNAME)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADNAME but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(def_var)(ncid, "abc", NC_SHORT, 0, NULL, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENAMEINUSE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(def_var)(ncid, "ABC", BAD_TYPE, -1, dimids, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADTYPE)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADTYPE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(def_var)(ncid, "ABC", NC_SHORT, -1, dimids, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EINVAL)
2016-10-13 15:17:31 +08:00
error("expecting NC_EINVAL but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
err = APIFunc(def_var)(ncid, "ABC", NC_SHORT, 0, dimids, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
/* general tests using global vars */
err = FileCreate(scratch, NC_CLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid);
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
err = APIFunc(def_var)(ncid, var_name[i], var_type[i], var_rank[i],
2010-06-03 21:24:43 +08:00
var_dimid[i], &varid);
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR)
error("def_var: %s", APIFunc(strerror)(err));
ELSE_NOK
IF (varid != i)
error("Unexpected varid");
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* try bad dim ids */
2010-06-03 21:24:43 +08:00
dimids[0] = BAD_DIMID;
2016-10-13 15:17:31 +08:00
err = APIFunc(def_var)(ncid, "abc", NC_SHORT, 1, dimids, &varid);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADDIM)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADDIM but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test PutVar1
2010-06-03 21:24:43 +08:00
*/
int
2016-10-13 15:17:31 +08:00
TestFunc(put_var1)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int i, err, ncid, nok=0;
IntType j, index[MAX_RANK];
double value[1];
2016-10-13 15:17:31 +08:00
double buf[1]; /* (void *) buffer */
ifdef(`PNETCDF', `MPI_Datatype datatype;')
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2016-10-13 15:17:31 +08:00
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
/* check if can detect a bad file ID */
err = PutVar1(BAD_ID, 0, NULL, NULL, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVar1(ncid, BAD_VARID, NULL, NULL, 1, MPI_DATATYPE_NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
value[0] = 5; /* reset to a value within bounds */
ifdef(`PNETCDF', `datatype = nc_mpi_type(var_type[i]);')
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVar1(ncid, i, NULL, value, 1, datatype);
if (var_rank[i] == 0) { /* scalar variable */
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
2016-10-13 15:17:31 +08:00
ELSE_NOK
')dnl
/* test NC_EINVALCOORDS */
for (j = 0; j < var_rank[i]; j++) index[j] = 0;
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
index[j] = var_shape[i][j]; /* out of boundary check */
err = PutVar1(ncid, i, index, value, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
index[j] = 0;
2010-06-03 21:24:43 +08:00
}
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_nels[i]; j++) {
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
value[0] = hash(var_type[i], var_rank[i], index);
if (inRange(value[0], var_type[i])) {
err = dbl2nc(value[0], var_type[i], buf);
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR)
error("error in dbl2nc var:%s type:%s",
var_name[i],s_nc_type(var_type[i]));
err = PutVar1(ncid, i, index, buf, 1, datatype);
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
2016-10-13 15:17:31 +08:00
ELSE_NOK
}
2010-06-03 21:24:43 +08:00
}
}
2016-10-13 15:17:31 +08:00
Check_Vars(ncid, numVars);
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test PutVara
2010-06-03 21:24:43 +08:00
* Choose a random point dividing each dim into 2 parts
* Put 2^rank (nslabs) slabs so defined
* Redefine buffer for each put.
2016-10-13 15:17:31 +08:00
* At end check all variables using Check_Vars
2010-06-03 21:24:43 +08:00
*/
int
2016-10-13 15:17:31 +08:00
TestFunc(put_vara)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int d, i, k, err, nslabs, ncid, nok=0;
IntType j, nels;
2016-10-13 15:17:31 +08:00
IntType start[MAX_RANK];
IntType edge[MAX_RANK];
IntType index[MAX_RANK];
IntType mid[MAX_RANK];
double buf[MAX_NELS]; /* (void *) buffer */
char *p; /* (void *) pointer */
2010-06-03 21:24:43 +08:00
double value;
ifdef(`PNETCDF', `MPI_Datatype datatype;')
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2016-10-13 15:17:31 +08:00
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
/* check if can detect a bad file ID */
err = PutVara(BAD_ID, 0, start, edge, buf, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVara(ncid, BAD_VARID, start, edge, buf, 1, MPI_DATATYPE_NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
buf[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVara(BAD_ID, i, start, edge, buf, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
ifdef(`PNETCDF', `datatype = nc_mpi_type(var_type[i]);')
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_rank[i]; j++) {
start[j] = 0;
edge[j] = 1;
}
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVara(ncid, i, NULL, NULL, buf, 1, datatype);
if (var_rank[i] == 0) { /* scalar variable */
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
2016-10-13 15:17:31 +08:00
ELSE_NOK
/* for non-scalar variables, argument count cannot be NULL */
err = PutVara(ncid, i, start, NULL, buf, 1, datatype);
if (var_rank[i] == 0) {
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EEDGE) {
EXPECT_ERR(NC_EEDGE, err)
}
2016-10-13 15:17:31 +08:00
ELSE_NOK
')dnl
/* first test when edge[*] > 0 */
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVara(ncid, i, start, edge, buf, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
edge[j] = var_shape[i][j] + 1;
err = PutVara(ncid, i, start, edge, buf, 1, datatype);
IF (err != NC_EEDGE)
EXPECT_ERR(NC_EEDG, err)
ELSE_NOK
edge[j] = 1;
2010-06-03 21:24:43 +08:00
}
/* Check correct error returned when nothing to put, when edge[*]==0 */
for (j = 0; j < var_rank[i]; j++) edge[j] = 0;
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVara(ncid, i, start, edge, buf, 0, datatype);
#ifdef RELAX_COORD_BOUND
IF (err != NC_NOERR) /* allowed when edge[j]==0 */
EXPECT_ERR(NC_NOERR, err)
#else
IF (err != NC_EINVALCOORDS) /* not allowed even when edge[j]==0 */
EXPECT_ERR(NC_EINVALCOORDS, err)
#endif
ELSE_NOK
start[j] = var_shape[i][j]+1; /* out of boundary check */
err = PutVara(ncid, i, start, edge, buf, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
}
for (j = 0; j < var_rank[i]; j++) edge[j] = 1;
2016-10-13 15:17:31 +08:00
/* Choose a random point dividing each dim into 2 parts */
/* put 2^rank (nslabs) slabs so defined */
2010-06-03 21:24:43 +08:00
nslabs = 1;
for (j = 0; j < var_rank[i]; j++) {
mid[j] = roll( var_shape[i][j] );
nslabs *= 2;
}
2016-10-13 15:17:31 +08:00
/* bits of k determine whether to put lower or upper part of dim */
2010-06-03 21:24:43 +08:00
for (k = 0; k < nslabs; k++) {
nels = 1;
for (j = 0; j < var_rank[i]; j++) {
if ((k >> j) & 1) {
start[j] = 0;
edge[j] = mid[j];
}else{
start[j] = mid[j];
edge[j] = var_shape[i][j] - mid[j];
}
nels *= edge[j];
}
2016-10-13 15:17:31 +08:00
p = (char *) buf;
for (j = 0; j < nels; j++) {
err = toMixedBase(j, var_rank[i], edge, index);
IF (err != 0) error("error in toMixedBase");
2016-10-13 15:17:31 +08:00
for (d = 0; d < var_rank[i]; d++)
index[d] += start[d];
value = hash(var_type[i], var_rank[i], index);
if (!inRange(value, var_type[i]))
value = 0;
err = dbl2nc(value, var_type[i], p);
IF (err != NC_NOERR)
error("error in dbl2nc");
p += nctypelen(var_type[i]);
2010-06-03 21:24:43 +08:00
}
err = PutVara(ncid, i, start, edge, buf, nels, datatype);
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR)
error("%s", APIFunc(strerror)(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
}
2016-10-13 15:17:31 +08:00
Check_Vars(ncid, numVars);
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test PutVars
2010-06-03 21:24:43 +08:00
* Choose a random point dividing each dim into 2 parts
* Put 2^rank (nslabs) slabs so defined
* Choose random stride from 1 to edge
* Redefine buffer for each put.
2016-10-13 15:17:31 +08:00
* At end check all variables using Check_Vars
2010-06-03 21:24:43 +08:00
*/
int
2016-10-13 15:17:31 +08:00
TestFunc(put_vars)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid, d, i, k, err, nslabs, nok=0;
PTRDType nstarts; /* number of different starts */
IntType j, m, nels;
2016-10-13 15:17:31 +08:00
IntType start[MAX_RANK];
IntType edge[MAX_RANK];
IntType index[MAX_RANK];
IntType index2[MAX_RANK];
IntType mid[MAX_RANK];
IntType count[MAX_RANK];
IntType sstride[MAX_RANK];
PTRDType stride[MAX_RANK];
2010-06-03 21:24:43 +08:00
double buf[MAX_NELS]; /* (void *) buffer */
2016-10-13 15:17:31 +08:00
char *p; /* (void *) pointer */
2010-06-03 21:24:43 +08:00
double value;
ifdef(`PNETCDF', `MPI_Datatype datatype;')
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2016-10-13 15:17:31 +08:00
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
/* check if can detect a bad file ID */
err = PutVars(BAD_ID, 0, NULL, NULL, NULL, NULL, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVars(ncid, BAD_VARID, NULL, NULL, NULL, NULL, 1, MPI_DATATYPE_NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
buf[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVars(BAD_ID, i, NULL, NULL, NULL, buf, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
ifdef(`PNETCDF', `datatype = nc_mpi_type(var_type[i]);')
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_rank[i]; j++) {
start[j] = 0;
edge[j] = 1;
stride[j] = 1;
}
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVars(ncid, i, NULL, NULL, NULL, buf, 1, datatype);
if (var_rank[i] == 0) { /* scalar variable */
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
2016-10-13 15:17:31 +08:00
ELSE_NOK
/* for non-scalar variables, argument count cannot be NULL */
err = PutVars(ncid, i, start, NULL, NULL, buf, 1, datatype);
if (var_rank[i] == 0) {
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EEDGE) {
EXPECT_ERR(NC_EEDGE, err)
}
2016-10-13 15:17:31 +08:00
ELSE_NOK
')dnl
/* first test when edge[*] > 0 */
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == 0) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVars(ncid, i, start, edge, stride, buf, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
edge[j] = var_shape[i][j] + 1; /* edge error check */
err = PutVars(ncid, i, start, edge, stride, buf, 1, datatype);
IF (err != NC_EEDGE)
EXPECT_ERR(NC_EEDG, err)
ELSE_NOK
edge[j] = 1;
stride[j] = 0; /* strided edge error check */
err = PutVars(ncid, i, start, edge, stride, buf, 1, datatype);
IF (err != NC_ESTRIDE)
EXPECT_ERR(NC_ESTRIDE, err)
ELSE_NOK
stride[j] = 1;
2010-06-03 21:24:43 +08:00
}
/* Check correct error returned even when nothing to put */
for (j = 0; j < var_rank[i]; j++) edge[j] = 0;
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == 0) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVars(ncid, i, start, edge, stride, buf, 0, datatype);
#ifdef RELAX_COORD_BOUND
IF (err != NC_NOERR) /* allowed when edge[j]==0 */
EXPECT_ERR(NC_NOERR, err)
#else
IF (err != NC_EINVALCOORDS) /* not allowed even when edge[j]==0 */
EXPECT_ERR(NC_EINVALCOORDS, err)
#endif
ELSE_NOK
start[j] = var_shape[i][j]+1; /* out of boundary check */
err = PutVars(ncid, i, start, edge, stride, buf, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
}
for (j = 0; j < var_rank[i]; j++) edge[j] = 1;
2016-10-13 15:17:31 +08:00
/* Choose a random point dividing each dim into 2 parts */
/* put 2^rank (nslabs) slabs so defined */
2010-06-03 21:24:43 +08:00
nslabs = 1;
for (j = 0; j < var_rank[i]; j++) {
mid[j] = roll( var_shape[i][j] );
nslabs *= 2;
}
2016-10-13 15:17:31 +08:00
/* bits of k determine whether to put lower or upper part of dim */
/* choose random stride from 1 to edge */
2010-06-03 21:24:43 +08:00
for (k = 0; k < nslabs; k++) {
nstarts = 1;
for (j = 0; j < var_rank[i]; j++) {
if ((k >> j) & 1) {
start[j] = 0;
edge[j] = mid[j];
}else{
start[j] = mid[j];
edge[j] = var_shape[i][j] - mid[j];
}
sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1;
stride[j] = (PTRDType)sstride[j];
2010-06-03 21:24:43 +08:00
nstarts *= stride[j];
}
for (m = 0; m < nstarts; m++) {
err = toMixedBase(m, var_rank[i], sstride, index);
IF (err != 0) error("error in toMixedBase");
2010-06-03 21:24:43 +08:00
nels = 1;
for (j = 0; j < var_rank[i]; j++) {
count[j] = 1 + (edge[j] - index[j] - 1) / (IntType)stride[j];
2010-06-03 21:24:43 +08:00
nels *= count[j];
index[j] += start[j];
}
2016-10-13 15:17:31 +08:00
/* Random choice of forward or backward */
2010-06-03 21:24:43 +08:00
/* TODO
if ( roll(2) ) {
for (j = 0; j < var_rank[i]; j++) {
index[j] += (count[j] - 1) * (IntType)stride[j];
2010-06-03 21:24:43 +08:00
stride[j] = -stride[j];
}
}
*/
2016-10-13 15:17:31 +08:00
p = (char *) buf;
for (j = 0; j < nels; j++) {
err = toMixedBase(j, var_rank[i], count, index2);
IF (err != 0) error("error in toMixedBase");
2016-10-13 15:17:31 +08:00
for (d = 0; d < var_rank[i]; d++)
index2[d] = index[d] + index2[d] * (IntType)stride[d];
2016-10-13 15:17:31 +08:00
value = hash(var_type[i], var_rank[i], index2);
if (!inRange(value, var_type[i]))
value = 0;
err = dbl2nc(value, var_type[i], p);
IF (err != NC_NOERR)
error("error in dbl2nc");
p += nctypelen(var_type[i]);
}
err = PutVars(ncid, i, index, count, stride, buf, nels, datatype);
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
2016-10-13 15:17:31 +08:00
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
}
}
2016-10-13 15:17:31 +08:00
Check_Vars(ncid, numVars);
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test PutVarm
2010-06-03 21:24:43 +08:00
* Choose a random point dividing each dim into 2 parts
* Put 2^rank (nslabs) slabs so defined
* Choose random stride from 1 to edge
* Buffer is bit image of whole external variable.
* So all puts for a variable put different elements of buffer
2016-10-13 15:17:31 +08:00
* At end check all variables using Check_Vars
2010-06-03 21:24:43 +08:00
*/
int
2016-10-13 15:17:31 +08:00
TestFunc(put_varm)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid, nok=0;
2010-06-03 21:24:43 +08:00
int i;
int k;
int err;
int nslabs;
IntType j, m;
PTRDType nstarts; /* number of different starts */
2016-10-13 15:17:31 +08:00
IntType start[MAX_RANK];
IntType edge[MAX_RANK];
IntType index[MAX_RANK];
IntType mid[MAX_RANK];
IntType count[MAX_RANK];
IntType sstride[MAX_RANK];
PTRDType stride[MAX_RANK];
PTRDType imap[MAX_RANK];
PTRDType imap2[MAX_RANK];
ifdef(`PNETCDF', `IntType bufcount;')
2010-06-03 21:24:43 +08:00
double buf[MAX_NELS]; /* (void *) buffer */
2016-10-13 15:17:31 +08:00
char *p; /* (void *) pointer */
2010-06-03 21:24:43 +08:00
double value;
ifdef(`PNETCDF', `MPI_Datatype datatype;')
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2016-10-13 15:17:31 +08:00
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
/* check if can detect a bad file ID */
err = PutVarm(NC_EBADID, 0, NULL, NULL, NULL, NULL, NULL, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
/* check if can detect a bad variable ID */
err = PutVarm(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL, 1, MPI_DATATYPE_NULL);
IF (err != NC_ENOTVAR)
EXPECT_ERR(NC_ENOTVAR, err)
ELSE_NOK
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
assert(var_rank[i] <= MAX_RANK);
assert(var_nels[i] <= MAX_NELS);
buf[0] = 5; /* reset to a value within bounds */
/* check if can detect a bad file ID */
err = PutVarm(BAD_ID, i, NULL, NULL, NULL, NULL, buf, 1, MPI_DATATYPE_NULL);
IF (err != NC_EBADID)
EXPECT_ERR(NC_EBADID, err)
ELSE_NOK
ifdef(`PNETCDF', `datatype = nc_mpi_type(var_type[i]);')
2010-06-03 21:24:43 +08:00
for (j = 0; j < var_rank[i]; j++) {
start[j] = 0;
edge[j] = 1;
stride[j] = 1;
imap[j] = 1;
}
ifdef(`PNETCDF',`dnl
/* for non-scalar variables, argument start cannot be NULL */
err = PutVarm(ncid, i, NULL, NULL, NULL, NULL, buf, 1, datatype);
if (var_rank[i] == 0) { /* scalar variable */
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EINVALCOORDS) {
EXPECT_ERR(NC_EINVALCOORDS, err)
}
ELSE_NOK
/* for non-scalar variables, argument count cannot be NULL */
err = PutVarm(ncid, i, start, NULL, NULL, NULL, buf, 1, datatype);
if (var_rank[i] == 0) {
IF (err != NC_NOERR) EXPECT_ERR(NC_NOERR, err)
}
else IF (err != NC_EEDGE) {
EXPECT_ERR(NC_EEDGE, err)
2010-06-03 21:24:43 +08:00
}
ELSE_NOK
')dnl
/* first test when edge[*] > 0 */
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == 0) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVarm(ncid, i, start, edge, stride, imap, buf, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
edge[j] = var_shape[i][j] + 1; /* edge error check */
err = PutVarm(ncid, i, start, edge, stride, imap, buf, 1, datatype);
IF (err != NC_EEDGE)
EXPECT_ERR(NC_EEDG, err)
ELSE_NOK
edge[j] = 1;
stride[j] = 0; /* strided edge error check */
err = PutVarm(ncid, i, start, edge, stride, imap, buf, 1, datatype);
IF (err != NC_ESTRIDE)
EXPECT_ERR(NC_ESTRIDE, err)
ELSE_NOK
stride[j] = 1;
}
/* Check correct error returned even when nothing to put */
for (j = 0; j < var_rank[i]; j++) edge[j] = 0;
for (j = 0; j < var_rank[i]; j++) {
if (var_dimid[i][j] == 0) continue; /* skip record dim */
start[j] = var_shape[i][j];
err = PutVarm(ncid, i, start, edge, stride, imap, buf, 0, datatype);
#ifdef RELAX_COORD_BOUND
IF (err != NC_NOERR) /* allowed when edge[j]==0 */
EXPECT_ERR(NC_NOERR, err)
#else
IF (err != NC_EINVALCOORDS) /* not allowed even when edge[j]==0 */
EXPECT_ERR(NC_EINVALCOORDS, err)
#endif
ELSE_NOK
start[j] = var_shape[i][j]+1; /* out of boundary check */
err = PutVarm(ncid, i, start, edge, stride, imap, buf, 1, datatype);
IF (err != NC_EINVALCOORDS)
EXPECT_ERR(NC_EINVALCOORDS, err)
ELSE_NOK
start[j] = 0;
}
for (j = 0; j < var_rank[i]; j++) edge[j] = 1;
2016-10-13 15:17:31 +08:00
if (var_rank[i] > 0) {
int jj = var_rank[i] - 1;
imap[jj] = nctypelen(var_type[i]); /* netCDF considers imap in bytes */
imap[jj] = 1; /* PnetCDF considers imap in elements */
for (; jj > 0; jj--)
imap[jj-1] = imap[jj] * (PTRDType)var_shape[i][jj];
2016-10-13 15:17:31 +08:00
}
p = (char *) buf;
for (j = 0; j < var_nels[i]; j++) {
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
2016-10-13 15:17:31 +08:00
value = hash(var_type[i], var_rank[i], index);
if (!inRange(value, var_type[i]))
value = 0;
err = dbl2nc(value, var_type[i], p);
IF (err != NC_NOERR)
error("error in dbl2nc");
p += nctypelen(var_type[i]);
}
2016-10-13 15:17:31 +08:00
/* Choose a random point dividing each dim into 2 parts */
/* put 2^rank (nslabs) slabs so defined */
2010-06-03 21:24:43 +08:00
nslabs = 1;
for (j = 0; j < var_rank[i]; j++) {
mid[j] = roll( var_shape[i][j] );
nslabs *= 2;
}
2016-10-13 15:17:31 +08:00
/* bits of k determine whether to put lower or upper part of dim */
/* choose random stride from 1 to edge */
2010-06-03 21:24:43 +08:00
for (k = 0; k < nslabs; k++) {
nstarts = 1;
for (j = 0; j < var_rank[i]; j++) {
if ((k >> j) & 1) {
start[j] = 0;
edge[j] = mid[j];
}else{
start[j] = mid[j];
edge[j] = var_shape[i][j] - mid[j];
}
sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1;
stride[j] = (PTRDType)sstride[j];
imap2[j] = imap[j] * (PTRDType)sstride[j];
2010-06-03 21:24:43 +08:00
nstarts *= stride[j];
}
for (m = 0; m < nstarts; m++) {
2016-10-13 15:17:31 +08:00
if (var_rank[i] == 0 && i%2 == 0) {
err = PutVarm(ncid, i, NULL, NULL, NULL, NULL, buf, 1, datatype);
2016-10-13 15:17:31 +08:00
} else {
err = toMixedBase(m, var_rank[i], sstride, index);
IF (err != 0) error("error in toMixedBase");
2016-10-13 15:17:31 +08:00
for (j = 0; j < var_rank[i]; j++) {
count[j] = 1 + (edge[j] - index[j] - 1) / (IntType)stride[j];
2016-10-13 15:17:31 +08:00
index[j] += start[j];
}
/* Random choice of forward or backward */
2010-06-03 21:24:43 +08:00
/* TODO
2016-10-13 15:17:31 +08:00
if ( roll(2) ) {
for (j = 0; j < var_rank[i]; j++) {
index[j] += (count[j] - 1) * (IntType)stride[j];
2016-10-13 15:17:31 +08:00
stride[j] = -stride[j];
}
}
2010-06-03 21:24:43 +08:00
*/
2016-10-13 15:17:31 +08:00
j = fromMixedBase(var_rank[i], index, var_shape[i]);
p = (char *) buf + (int)j * nctypelen(var_type[i]);
ifdef(`PNETCDF', `for (bufcount=1,j=0; j<var_rank[i]; j++) bufcount *= count[j];')
err = PutVarm(ncid, i, index, count, stride, imap2, p, bufcount, datatype);
2016-10-13 15:17:31 +08:00
}
IF (err != NC_NOERR)
EXPECT_ERR(NC_NOERR, err)
2016-10-13 15:17:31 +08:00
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
}
}
2016-10-13 15:17:31 +08:00
Check_Vars(ncid, numVars);
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(rename_var)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
* try with bad variable handle, check error
* try renaming to existing variable name, check error
2016-10-13 15:17:31 +08:00
* check that proper rename worked with APIFunc(inq_varid)
2010-06-03 21:24:43 +08:00
* try in data mode, check error
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(rename_var)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid;
int varid;
2016-10-13 15:17:31 +08:00
int err, nok=0;
2010-06-03 21:24:43 +08:00
int i;
char name[NC_MAX_NAME];
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(rename_var)(ncid, BAD_VARID, "newName");
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTVAR)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* Prefix "new_" to each name */
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
err = APIFunc(rename_var)(BAD_ID, i, "newName");
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(rename_var)(ncid, i, var_name[numVars-1]);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENAMEINUSE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err));
ELSE_NOK
strcpy(name, "new_");
strcat(name, var_name[i]);
err = APIFunc(rename_var)(ncid, i, name);
IF (err != NC_NOERR)
error("rename_var: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_varid)(ncid, name, &varid);
IF (err != NC_NOERR)
error("inq_varid: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (varid != i)
2016-10-13 15:17:31 +08:00
error("Unexpected varid");
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* Change to data mode */
/* Try making names even longer. Then restore original names */
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
strcpy(name, "even_longer_");
strcat(name, var_name[i]);
err = APIFunc(rename_var)(ncid, i, name);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTINDEFINE)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(rename_var)(ncid, i, var_name[i]);
IF (err != NC_NOERR)
error("rename_var: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_varid)(ncid, var_name[i], &varid);
IF (err != NC_NOERR)
error("inq_varid: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (varid != i)
2016-10-13 15:17:31 +08:00
error("Unexpected varid");
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
Put_Vars(ncid, numVars);
Check_Vars(ncid, numVars);
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
int
2016-10-13 15:17:31 +08:00
TestFunc(put_att)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid, nok=0;
2010-06-03 21:24:43 +08:00
int varid;
int i;
int j;
2016-10-13 15:17:31 +08:00
IntType k;
2010-06-03 21:24:43 +08:00
int err;
double buf[MAX_NELS]; /* (void *) buffer */
char *p; /* (void *) pointer */
2016-10-13 15:17:31 +08:00
char *name; /* of att */
nc_type datatype; /* of att */
IntType length; /* of att */
2010-06-03 21:24:43 +08:00
double value;
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
varid = VARID(i);
2010-06-03 21:24:43 +08:00
for (j = 0; j < NATTS(i); j++) {
2016-10-13 15:17:31 +08:00
name = ATT_NAME(i,j);
datatype = ATT_TYPE(i,j);
length = ATT_LEN(i,j);
err = APIFunc(put_att)(BAD_ID, varid, name, datatype, length, buf);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(put_att)(ncid, varid, BAD_NAME, datatype, length, buf);
IF (err != NC_EBADNAME)
error("expecting NC_EBADNAME but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(put_att)(ncid, BAD_VARID, name, datatype, length, buf);
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTVAR)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(put_att)(ncid, varid, name, BAD_TYPE, length, buf);
IF (err != NC_EBADTYPE)
error("expecting NC_EBADTYPE but got %s", nc_err_code_name(err));
ELSE_NOK
p = (char *) buf;
for (k=0; k<length; k++) {
value = hash(datatype, -1, &k);
if (!inRange(value, datatype))
value = 0;
err = dbl2nc(value, datatype, p);
IF (err != NC_NOERR)
error("error in dbl2nc");
p += nctypelen(datatype);
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(put_att)(ncid, varid, name, datatype, length, buf);
IF (err != NC_NOERR)
error("%s", APIFunc(strerror)(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
}
2016-10-13 15:17:31 +08:00
Check_Atts(ncid, numGatts, numVars);
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(copy_att)
2010-06-03 21:24:43 +08:00
* try with bad source or target netCDF handles, check error
* try with bad source or target variable handle, check error
* try with nonexisting attribute, check error
* check that NC_GLOBAL variable for source or target works
* check that new attribute put works with target in define mode
* check that old attribute put works with target in data mode
* check that changing type and length of an attribute work OK
* try with same ncid for source and target, different variables
* try with same ncid for source and target, same variable
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(copy_att)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid_in;
int ncid_out;
int varid;
2016-10-13 15:17:31 +08:00
int err, nok=0;
2010-06-03 21:24:43 +08:00
int i;
2016-10-13 15:17:31 +08:00
int j=0;
2010-06-03 21:24:43 +08:00
char *name; /* of att */
nc_type datatype; /* of att */
2016-10-13 15:17:31 +08:00
IntType length; /* of att */
2010-06-03 21:24:43 +08:00
char value;
2016-10-13 15:17:31 +08:00
err = FileOpen(testfile, NC_NOWRITE, &ncid_in);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = FileCreate(scratch, NC_NOCLOBBER, &ncid_out);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid_out);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid_out, numVars);
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
varid = VARID(i);
for (j = 0; j < NATTS(i); j++) {
name = ATT_NAME(i,j);
2016-10-13 15:17:31 +08:00
err = APIFunc(copy_att)(ncid_in, BAD_VARID, name, ncid_out, varid);
IF (err != NC_ENOTVAR)
error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(copy_att)(ncid_in, varid, name, ncid_out, BAD_VARID);
IF (err != NC_ENOTVAR)
error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(copy_att)(BAD_ID, varid, name, ncid_out, varid);
IF (err != NC_EBADID)
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(copy_att)(ncid_in, varid, name, BAD_ID, varid);
IF (err != NC_EBADID)
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(copy_att)(ncid_in, varid, "noSuch", ncid_out, varid);
IF (err != NC_ENOTATT)
error("expecting NC_ENOTATT but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(copy_att)(ncid_in, varid, name, ncid_out, varid);
IF (err != NC_NOERR)
error("copy_att: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(copy_att)(ncid_in, varid, name, ncid_out, varid);
2016-10-13 15:17:31 +08:00
IF (err != NC_NOERR)
error("source = target: %s", APIFunc(strerror)(err));
ELSE_NOK
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid_in);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
/* Close scratch. Reopen & check attributes */
err = APIFunc(close)(ncid_out);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileOpen(scratch, NC_WRITE, &ncid_out);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
Check_Atts(ncid_out, numGatts, numVars);
/*
* change to define mode
* define single char. global att. ':a' with value 'A'
* This will be used as source for following copies
*/
err = APIFunc(redef)(ncid_out);
IF (err != NC_NOERR)
error("redef: %s", APIFunc(strerror)(err));
err = APIFunc(put_att_text)(ncid_out, NC_GLOBAL, "a", 1, "A");
IF (err != NC_NOERR)
error("put_att_text: %s", APIFunc(strerror)(err));
/*
* change to data mode
* Use scratch as both source & dest.
* try copy to existing att. change type & decrease length
* rename 1st existing att of each var (if any) 'a'
* if this att. exists them copy ':a' to it
*/
err = APIFunc(enddef)(ncid_out);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
if (NATTS(i) > 0 && ATT_LEN(i,j) > 0) {
err = APIFunc(rename_att)(ncid_out, i, att_name[i][0], "a");
IF (err != NC_NOERR)
error("rename_att: %s", APIFunc(strerror)(err));
err = APIFunc(copy_att)(ncid_out, NC_GLOBAL, "a", ncid_out, i);
IF (err != NC_NOERR)
error("copy_att: %s", APIFunc(strerror)(err));
ELSE_NOK
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid_out);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
/* Reopen & check */
err = FileOpen(scratch, NC_WRITE, &ncid_out);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
if (NATTS(i) > 0 && ATT_LEN(i,j) > 0) {
err = APIFunc(inq_att)(ncid_out, i, "a", &datatype, &length);
IF (err != NC_NOERR)
error("inq_att: %s", APIFunc(strerror)(err));
IF (datatype != NC_CHAR)
error("Unexpected type");
IF (length != 1)
error("Unexpected length");
err = APIFunc(get_att_text)(ncid_out, i, "a", &value);
IF (err != NC_NOERR)
error("get_att_text: %s", APIFunc(strerror)(err));
IF (value != 'A')
error("Unexpected value");
}
}
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid_out);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(rename_att)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
* try with bad variable handle, check error
* try with nonexisting att name, check error
* try renaming to existing att name, check error
2016-10-13 15:17:31 +08:00
* check that proper rename worked with APIFunc(inq_attid)
2010-06-03 21:24:43 +08:00
* try in data mode, check error
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(rename_att)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid;
int varid;
int err;
int i;
int j;
2016-10-13 15:17:31 +08:00
IntType k;
2010-06-03 21:24:43 +08:00
int attnum;
char *attname;
char name[NC_MAX_NAME];
char oldname[NC_MAX_NAME];
char newname[NC_MAX_NAME];
int nok = 0; /* count of valid comparisons */
nc_type datatype;
nc_type atttype;
2016-10-13 15:17:31 +08:00
IntType length;
IntType attlength;
2016-10-13 15:17:31 +08:00
char text[MAX_NELS];
2010-06-03 21:24:43 +08:00
double value[MAX_NELS];
double expect;
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(rename_att)(ncid, BAD_VARID, "abc", "newName");
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTVAR)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
Put_Atts(ncid, numGatts, numVars);
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
varid = VARID(i);
for (j = 0; j < NATTS(i); j++) {
2016-10-13 15:17:31 +08:00
attname = ATT_NAME(i,j);
err = APIFunc(rename_att)(BAD_ID, varid, attname, "newName");
IF (err != NC_EBADID)
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(rename_att)(ncid, varid, "noSuch", "newName");
IF (err != NC_ENOTATT)
error("expecting NC_ENOTATT but got %s", nc_err_code_name(err));
ELSE_NOK
strcpy(newname, "new_");
strcat(newname, attname);
err = APIFunc(rename_att)(ncid, varid, attname, newname);
IF (err != NC_NOERR)
error("rename_att: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_attid)(ncid, varid, newname, &attnum);
IF (err != NC_NOERR)
error("inq_attid: %s", APIFunc(strerror)(err));
IF (attnum != j)
error("Unexpected attnum");
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* Close. Reopen & check */
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileOpen(scratch, NC_WRITE, &ncid);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
varid = VARID(i);
for (j = 0; j < NATTS(i); j++) {
2016-10-13 15:17:31 +08:00
attname = ATT_NAME(i,j);
atttype = ATT_TYPE(i,j);
attlength = ATT_LEN(i,j);
strcpy(newname, "new_");
strcat(newname, attname);
err = APIFunc(inq_attname)(ncid, varid, j, name);
IF (err != NC_NOERR)
error("inq_attname: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (strcmp(name, newname) != 0)
2016-10-13 15:17:31 +08:00
error("inq_attname: unexpected name");
err = APIFunc(inq_att)(ncid, varid, name, &datatype, &length);
IF (err != NC_NOERR)
error("inq_att: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (datatype != atttype)
2016-10-13 15:17:31 +08:00
error("inq_att: unexpected type");
2010-06-03 21:24:43 +08:00
IF (length != attlength)
2016-10-13 15:17:31 +08:00
error("inq_att: unexpected length");
2010-06-03 21:24:43 +08:00
if (datatype == NC_CHAR) {
2016-10-13 15:17:31 +08:00
err = APIFunc(get_att_text)(ncid, varid, name, text);
IF (err != NC_NOERR)
error("get_att_text: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
for (k = 0; k < attlength; k++) {
expect = hash(datatype, -1, &k);
IF (text[k] != (char)(signed)expect)
2016-10-13 15:17:31 +08:00
error("get_att_text: unexpected value");
2010-06-03 21:24:43 +08:00
}
} else {
2016-10-13 15:17:31 +08:00
err = APIFunc(get_att_double)(ncid, varid, name, value);
IF (err != NC_NOERR)
error("get_att_double: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
for (k = 0; k < attlength; k++) {
expect = hash(datatype, -1, &k);
2016-10-13 15:17:31 +08:00
if (inRange(expect, datatype)) {
IF (!equal(value[k],expect,datatype,NCT_DOUBLE))
error("get_att_double: unexpected value");
2010-06-03 21:24:43 +08:00
}
}
}
}
}
2016-10-13 15:17:31 +08:00
/* Now in data mode */
/* Try making names even longer. Then restore original names */
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2010-06-03 21:24:43 +08:00
varid = VARID(i);
for (j = 0; j < NATTS(i); j++) {
2016-10-13 15:17:31 +08:00
attname = ATT_NAME(i,j);
strcpy(oldname, "new_");
strcat(oldname, attname);
strcpy(newname, "even_longer_");
strcat(newname, attname);
err = APIFunc(rename_att)(ncid, varid, oldname, newname);
IF (err != NC_ENOTINDEFINE)
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(rename_att)(ncid, varid, oldname, attname);
IF (err != NC_NOERR)
error("rename_att: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_attid)(ncid, varid, attname, &attnum);
IF (err != NC_NOERR)
error("inq_attid: %s", APIFunc(strerror)(err));
IF (attnum != j)
error("Unexpected attnum");
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(del_att)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
* try with bad variable handle, check error
* try with nonexisting att name, check error
* check that proper delete worked using:
2016-10-13 15:17:31 +08:00
* APIFunc(inq_attid), APIFunc(inq_natts), APIFunc(inq_varnatts)
2010-06-03 21:24:43 +08:00
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(del_att)(AttVarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid;
2016-10-13 15:17:31 +08:00
int err, nok=0;
2010-06-03 21:24:43 +08:00
int i;
int j;
int attnum;
int natts;
int numatts;
int varid;
char *name; /* of att */
2016-10-13 15:17:31 +08:00
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(del_att)(ncid, BAD_VARID, "abc");
2010-06-03 21:24:43 +08:00
IF (err != NC_ENOTVAR)
2016-10-13 15:17:31 +08:00
error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
Put_Atts(ncid, numGatts, numVars);
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
varid = VARID(i);
numatts = NATTS(i);
2010-06-03 21:24:43 +08:00
for (j = 0; j < numatts; j++) {
2016-10-13 15:17:31 +08:00
name = ATT_NAME(i,j);
err = APIFunc(del_att)(BAD_ID, varid, name);
IF (err != NC_EBADID)
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(del_att)(ncid, varid, "noSuch");
IF (err != NC_ENOTATT)
error("expecting NC_ENOTATT but got %s", nc_err_code_name(err));
ELSE_NOK
err = APIFunc(del_att)(ncid, varid, name);
IF (err != NC_NOERR)
error("del_att: %s", APIFunc(strerror)(err));
ELSE_NOK
err = APIFunc(inq_attid)(ncid, varid, name, &attnum);
IF (err != NC_ENOTATT)
error("expecting NC_ENOTATT but got %s", nc_err_code_name(err));
if (i < 0) {
err = APIFunc(inq_natts)(ncid, &natts);
IF (err != NC_NOERR)
error("inq_natts: %s", APIFunc(strerror)(err));
IF (natts != numatts-j-1)
error("natts: expected %d, got %d", numatts-j-1, natts);
}
err = APIFunc(inq_varnatts)(ncid, varid, &natts);
IF (err != NC_NOERR)
error("inq_natts: %s", APIFunc(strerror)(err));
IF (natts != numatts-j-1)
error("natts: expected %d, got %d", numatts-j-1, natts);
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* Close. Reopen & check no attributes left */
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileOpen(scratch, NC_WRITE, &ncid);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(inq_natts)(ncid, &natts);
IF (err != NC_NOERR)
error("inq_natts: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (natts != 0)
2016-10-13 15:17:31 +08:00
error("natts: expected %d, got %d", 0, natts);
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
varid = VARID(i);
err = APIFunc(inq_varnatts)(ncid, varid, &natts);
IF (err != NC_NOERR)
error("inq_natts: %s", APIFunc(strerror)(err));
IF (natts != 0)
error("natts: expected %d, got %d", 0, natts);
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* restore attributes. change to data mode. try to delete */
err = APIFunc(redef)(ncid);
IF (err != NC_NOERR)
error("redef: %s", APIFunc(strerror)(err));
Put_Atts(ncid, numGatts, numVars);
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
2015-08-16 06:26:35 +08:00
for (i = -1; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
varid = VARID(i);
numatts = NATTS(i);
2010-06-03 21:24:43 +08:00
for (j = 0; j < numatts; j++) {
2016-10-13 15:17:31 +08:00
name = ATT_NAME(i,j);
err = APIFunc(del_att)(ncid, varid, name);
IF (err != NC_ENOTINDEFINE)
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));
ELSE_NOK
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
/*
2016-10-13 15:17:31 +08:00
* Test APIFunc(set_fill)
2010-06-03 21:24:43 +08:00
* try with bad netCDF handle, check error
* try in read-only mode, check error
* try with bad new_fillmode, check error
* try in data mode, check error
* check that proper set to NC_FILL works for record & non-record variables
* (note that it is not possible to test NC_NOFILL mode!)
* close file & create again for test using attribute _FillValue
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(set_fill)(VarArgs)
2010-06-03 21:24:43 +08:00
{
int ncid;
int varid;
int err;
int i;
IntType j;
2010-06-03 21:24:43 +08:00
int old_fillmode;
int nok = 0; /* count of valid comparisons */
char text = 0;
double value = 0;
double fill;
2016-10-13 15:17:31 +08:00
IntType index[MAX_RANK];
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* bad ncid */
err = APIFunc(set_fill)(BAD_ID, NC_NOFILL, &old_fillmode);
2010-06-03 21:24:43 +08:00
IF (err != NC_EBADID)
2016-10-13 15:17:31 +08:00
error("expecting NC_EBADID but got %s", nc_err_code_name(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* try in read-only mode */
err = FileOpen(testfile, NC_NOWRITE, &ncid);
IF (err != NC_NOERR)
error("open: %s", APIFunc(strerror)(err));
err = APIFunc(set_fill)(ncid, NC_NOFILL, &old_fillmode);
2010-06-03 21:24:43 +08:00
IF (err != NC_EPERM)
2016-10-13 15:17:31 +08:00
error("expecting NC_EPERM but got %s", nc_err_code_name(err));
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
/* create scratch */
err = FileCreate(scratch, NC_NOCLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* BAD_FILLMODE */
err = APIFunc(set_fill)(ncid, BAD_FILLMODE, &old_fillmode);
2010-06-03 21:24:43 +08:00
IF (err != NC_EINVAL)
2016-10-13 15:17:31 +08:00
error("expecting NC_EINVAL but got %s", nc_err_code_name(err));
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* proper calls */
err = APIFunc(set_fill)(ncid, NC_NOFILL, &old_fillmode);
IF (err != NC_NOERR)
error("set_fill: %s", APIFunc(strerror)(err));
IF (old_fillmode != NC_NOFILL)
2010-06-03 21:24:43 +08:00
error("Unexpected old fill mode: %d", old_fillmode);
2016-10-13 15:17:31 +08:00
err = APIFunc(set_fill)(ncid, NC_FILL, &old_fillmode);
IF (err != NC_NOERR)
error("set_fill: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
IF (old_fillmode != NC_NOFILL)
error("Unexpected old fill mode: %d", old_fillmode);
2016-10-13 15:17:31 +08:00
/* define dims & vars */
2010-06-03 21:24:43 +08:00
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
/* Change to data mode. Set fillmode again */
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
err = APIFunc(set_fill)(ncid, NC_FILL, &old_fillmode);
ifdef(`PNETCDF',
`IF (err != NC_ENOTINDEFINE)
error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err));',
`IF (err)
2010-06-03 21:24:43 +08:00
error("nc_set_fill: %s", nc_strerror(err));
IF (old_fillmode != NC_FILL)
2016-10-13 15:17:31 +08:00
error("Unexpected old fill mode: %d", old_fillmode);')dnl
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* Write record number NRECS to force writing of preceding records */
/* Assumes variable cr is char vector with UNLIMITED dimension */
err = APIFunc(inq_varid)(ncid, "cr", &varid);
IF (err != NC_NOERR)
error("inq_varid: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
index[0] = NRECS;
2016-10-13 15:17:31 +08:00
ifdef(`PNETCDF', `
for (i=0; i<=index[0]; i++)
err = APIFunc(fill_var_rec)(ncid, varid, i);')dnl
err = PutVar1TYPE(text)(ncid, varid, index, &text);
IF (err != NC_NOERR)
error("put_var1_text_all: %s", APIFunc(strerror)(err));
/* get all variables & check all values equal default fill */
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
ifdef(`PNETCDF', `if (var_dimid[i][0] == RECDIM) continue; /* skip record variables */')
2016-10-13 15:17:31 +08:00
switch (var_type[i]) {
case NC_CHAR: fill = (double)NC_FILL_CHAR; break;
case NC_BYTE: fill = (double)NC_FILL_BYTE; break;
case NC_SHORT: fill = (double)NC_FILL_SHORT; break;
case NC_INT: fill = (double)NC_FILL_INT; break;
case NC_FLOAT: fill = (double)NC_FILL_FLOAT; break;
case NC_DOUBLE: fill = (double)NC_FILL_DOUBLE; break;
case NC_UBYTE: fill = (double)NC_FILL_UBYTE; break;
case NC_USHORT: fill = (double)NC_FILL_USHORT; break;
case NC_UINT: fill = (double)NC_FILL_UINT; break;
case NC_INT64: fill = (double)NC_FILL_INT64; break;
case NC_UINT64: fill = (double)NC_FILL_UINT64; break;
2016-10-13 15:17:31 +08:00
default: assert(0);
}
for (j = 0; j < var_nels[i]; j++) {
2010-06-03 21:24:43 +08:00
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
2016-10-13 15:17:31 +08:00
if (var_type[i] == NC_CHAR) {
err = GetVar1TYPE(text)(ncid, i, index, &text);
IF (err != NC_NOERR)
error("get_var1_text_all failed: %s", APIFunc(strerror)(err));
value = text;
} else {
err = GetVar1TYPE(double)(ncid, i, index, &value);
IF (err != NC_NOERR)
error("get_var1_double_all failed: %s", APIFunc(strerror)(err));
}
IF (value != fill && fabs((fill - value)/fill) > DBL_EPSILON)
error("\n\t\t%s Value expected: %-23.17e,\n\t\t read: %-23.17e\n",
var_name[i],fill, value);
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
}
2016-10-13 15:17:31 +08:00
/* close scratch & create again for test using attribute _FillValue */
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileCreate(scratch, NC_CLOBBER, &ncid);
IF (err != NC_NOERR) {
error("create: %s", APIFunc(strerror)(err));
return nok;
2010-06-03 21:24:43 +08:00
}
def_dims(ncid);
2016-10-13 15:17:31 +08:00
Def_Vars(ncid, numVars);
2010-06-03 21:24:43 +08:00
2016-10-13 15:17:31 +08:00
/* set _FillValue = 42 for all vars */
fill = 42;
text = 42;
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
if (var_type[i] == NC_CHAR) {
err = APIFunc(put_att_text)(ncid, i, "_FillValue", 1, &text);
IF (err != NC_NOERR)
error("put_att_text: %s", APIFunc(strerror)(err));
} else {
err = APIFunc(put_att_double)(ncid, i, "_FillValue",var_type[i],1,&fill);
IF (err != NC_NOERR)
error("put_att_double: %s", APIFunc(strerror)(err));
}
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
/* data mode. write records */
err = APIFunc(enddef)(ncid);
IF (err != NC_NOERR)
error("enddef: %s", APIFunc(strerror)(err));
2010-06-03 21:24:43 +08:00
index[0] = NRECS;
2016-10-13 15:17:31 +08:00
ifdef(`PNETCDF', `
for (i=0; i<=index[0]; i++)
err = APIFunc(fill_var_rec)(ncid, varid, i);')dnl
err = PutVar1TYPE(text)(ncid, varid, index, &text);
IF (err != NC_NOERR)
error("put_var1_text_all: %s", APIFunc(strerror)(err));
/* get all variables & check all values equal 42 */
2015-08-16 06:26:35 +08:00
for (i = 0; i < numVars; i++) {
2016-10-13 15:17:31 +08:00
if (var_dimid[i][0] == RECDIM) continue; /* skip record variables */
for (j = 0; j < var_nels[i]; j++) {
2010-06-03 21:24:43 +08:00
err = toMixedBase(j, var_rank[i], var_shape[i], index);
IF (err != 0) error("error in toMixedBase");
2016-10-13 15:17:31 +08:00
if (var_type[i] == NC_CHAR) {
err = GetVar1TYPE(text)(ncid, i, index, &text);
IF (err != NC_NOERR)
error("get_var1_text_all failed: %s", APIFunc(strerror)(err));
value = text;
} else {
err = GetVar1TYPE(double)(ncid, i, index, &value);
IF (err != NC_NOERR)
error("get_var1_double_all failed: %s", APIFunc(strerror)(err));
}
IF (value != fill)
error(" %s Value expected: %g, read: %g\n", var_name[i],fill, value);
ELSE_NOK
2010-06-03 21:24:43 +08:00
}
}
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
2010-06-03 21:24:43 +08:00
error("remove of %s failed", scratch);
2016-10-13 15:17:31 +08:00
return nok;
2010-06-03 21:24:43 +08:00
}
2016-10-13 15:17:31 +08:00
2010-06-03 21:24:43 +08:00
/* This function gets the version of a netCDF file, 1 is for netCDF
classic, 2 for 64-bit offset format, (someday) 3 for HDF5 format,
2015-08-16 06:26:35 +08:00
5 for 64-bit data format (CDF-5).
2010-06-03 21:24:43 +08:00
*/
#define MAGIC_NUM_LEN 4
static
int
APIFunc(get_file_version)(char *path, int *version)
2010-06-03 21:24:43 +08:00
{
2016-10-13 15:17:31 +08:00
int fd;
ssize_t read_len;
2010-06-03 21:24:43 +08:00
char magic[MAGIC_NUM_LEN];
/* Need two valid pointers - check for NULL. */
if (!version || !path)
return NC_EINVAL;
/* Figure out if this is a netcdf or hdf5 file. */
2016-10-13 15:17:31 +08:00
fd = open(path, O_RDONLY, 0600);
if (fd == -1) return errno;
read_len = read(fd, magic, MAGIC_NUM_LEN);
if (-1 == close(fd)) return errno;
if (read_len == -1)
return errno;
2016-10-13 15:17:31 +08:00
if (read_len != MAGIC_NUM_LEN) {
printf("Error: reading NC magic string unexpected short read\n");
return 0;
}
2016-10-13 15:17:31 +08:00
if (strncmp(magic, "CDF", MAGIC_NUM_LEN-1)==0) {
if (magic[MAGIC_NUM_LEN-1] == NC_FORMAT_CLASSIC ||
magic[MAGIC_NUM_LEN-1] == NC_FORMAT_64BIT_OFFSET ||
magic[MAGIC_NUM_LEN-1] == NC_FORMAT_CDF5)
*version = magic[MAGIC_NUM_LEN-1];
2010-06-03 21:24:43 +08:00
else
2016-10-13 15:17:31 +08:00
return NC_ENOTNC;
2010-06-03 21:24:43 +08:00
}
/* tomorrow, tomorrow, I love you tomorrow, you're always a day
2016-10-13 15:17:31 +08:00
away! */
2010-06-03 21:24:43 +08:00
/*if (magic[1] == 'H' && magic[2] == 'D' && magic[3] == 'F')
*version = 3;*/
return NC_NOERR;
}
/*
* Test APIFunc(set_default_format)
2010-06-03 21:24:43 +08:00
* try with bad default format
* try with NULL old_formatp
* try in data mode, check error
* check that proper set to NC_FILL works for record & non-record variables
* (note that it is not possible to test NC_NOFILL mode!)
* close file & create again for test using attribute _FillValue
*/
2016-10-13 15:17:31 +08:00
int
TestFunc(set_default_format)(void)
2010-06-03 21:24:43 +08:00
{
2016-10-13 15:17:31 +08:00
int ncid, nok=0;
2010-06-03 21:24:43 +08:00
int err;
int i;
2016-10-13 15:17:31 +08:00
int version=1;
2010-06-03 21:24:43 +08:00
int old_format;
/* bad format */
2016-10-13 15:17:31 +08:00
err = APIFunc(set_default_format)(BAD_DEFAULT_FORMAT, &old_format);
2010-06-03 21:24:43 +08:00
IF (err != NC_EINVAL)
2016-10-13 15:17:31 +08:00
error("expecting NC_EINVAL but got %s", nc_err_code_name(err));
ELSE_NOK
2010-06-03 21:24:43 +08:00
/* NULL old_formatp */
2016-10-13 15:17:31 +08:00
err = APIFunc(set_default_format)(NC_FORMAT_64BIT_OFFSET, NULL);
IF (err != NC_NOERR)
error("null old_fortmatp: status = %d", err);
ELSE_NOK
2010-06-03 21:24:43 +08:00
/* Cycle through available formats. */
for(i=NC_FORMAT_CLASSIC; i<NC_FORMAT_64BIT_DATA; i++)
2010-06-03 21:24:43 +08:00
{
if (i == NC_FORMAT_NETCDF4 || i == NC_FORMAT_NETCDF4_CLASSIC)
continue; /* test classic formats only */
2016-10-13 15:17:31 +08:00
if ((err = APIFunc(set_default_format)(i, NULL)))
error("setting classic format: status = %d", err);
2016-10-13 15:17:31 +08:00
ELSE_NOK
err = FileCreate(scratch, NC_CLOBBER, &ncid);
if (err != NC_NOERR)
error("bad nc_create: status = %d", err);
err = APIFunc(put_att_text)(ncid, NC_GLOBAL, "testatt", sizeof("blah"), "blah");
2016-10-13 15:17:31 +08:00
if (err != NC_NOERR)
error("bad put_att: status = %d", err);
2016-10-13 15:17:31 +08:00
err = APIFunc(close)(ncid);
if (err != NC_NOERR)
error("bad close: status = %d", err);
2016-10-13 15:17:31 +08:00
err = APIFunc(get_file_version)(scratch, &version);
if (err != NC_NOERR)
error("bad file version = %d", err);
2015-08-16 06:26:35 +08:00
if (version != i) {
#if 0
2015-08-16 06:26:35 +08:00
if (i == 4) {
if (version == 3) continue;
2016-10-13 15:17:31 +08:00
printf("expect version 3 but got %d (file=%s)",version,scratch);
2015-08-16 06:26:35 +08:00
continue;
}
#endif
2016-10-13 15:17:31 +08:00
printf("expect version %d but got %d (file=%s)",i,version,scratch);
error("bad file version = %d", version);
}
2010-06-03 21:24:43 +08:00
}
/* Remove the left-over file. */
2016-10-26 04:11:16 +08:00
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
error("remove of %s failed", scratch);
2016-10-26 04:11:16 +08:00
2016-10-13 15:17:31 +08:00
return nok;
}
/*
* Test FileDelete
* create netcdf file 'scratch.nc' with no data, close it
* delete the file
*/
int
TestFunc(delete)(void)
{
int err, nok=0;;
int ncid;
err = FileCreate(scratch, NC_CLOBBER, &ncid);
IF (err != NC_NOERR)
error("error creating scratch file %s, status = %d\n", scratch,err);
err = APIFunc(close)(ncid);
IF (err != NC_NOERR)
error("close: %s", APIFunc(strerror)(err));
err = FileDelete(scratch, info);
IF (err != NC_NOERR)
error("remove of %s failed", scratch);
ELSE_NOK
return nok;
2010-06-03 21:24:43 +08:00
}