2018-12-07 06:36:53 +08:00
|
|
|
/*! \file
|
|
|
|
|
|
|
|
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
|
|
|
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
|
|
|
|
2015, 2016, 2017, 2018
|
|
|
|
University Corporation for Atmospheric Research/Unidata.
|
|
|
|
|
|
|
|
See \ref copyright file for more info.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-09-15 05:01:40 +08:00
|
|
|
#include "config.h"
|
2016-01-06 12:26:25 +08:00
|
|
|
#include <nc_tests.h>
|
2016-10-22 01:17:39 +08:00
|
|
|
#include "err_macros.h"
|
2016-01-06 12:26:25 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <netcdf.h>
|
|
|
|
|
|
|
|
#define FILECLASSIC "tst_dimsize_classic.nc"
|
|
|
|
#define FILE64OFFSET "tst_dimsize_64offset.nc"
|
|
|
|
#define FILE64DATA "tst_dimsize_64data.nc"
|
|
|
|
|
|
|
|
#define DIMMAXCLASSIC (NC_MAX_INT - 3)
|
|
|
|
#define DIMMAX64OFFSET (NC_MAX_UINT - 3)
|
2017-09-15 05:01:40 +08:00
|
|
|
|
2018-06-30 10:17:07 +08:00
|
|
|
#ifdef ENABLE_CDF5
|
2016-01-06 12:26:25 +08:00
|
|
|
#define DIMMAX64DATA (NC_MAX_UINT64 - 3)
|
2017-09-15 05:01:40 +08:00
|
|
|
#endif
|
2016-01-06 12:26:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Test that at least the meta-data works
|
|
|
|
for dimension sizes X modes.
|
|
|
|
NC_CLASSIC => NC_INT_MAX - 3
|
|
|
|
NC_64BIT_OFFSET => NC_UINT_MAX - 3
|
|
|
|
NC_64BIT_DATA => NC_UINT64_MAX - 3
|
|
|
|
Note that this will not test the last case when
|
|
|
|
|size_t| == 4.
|
|
|
|
Also, leave the files around so we can test with ncdump.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2016-10-22 01:17:39 +08:00
|
|
|
main(int argc, char **argv)
|
2016-01-06 12:26:25 +08:00
|
|
|
{
|
|
|
|
int ncid;
|
|
|
|
size_t dimsize;
|
|
|
|
int dimid;
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
printf("\n*** Testing Max Dimension Sizes\n");
|
|
|
|
|
2016-01-09 03:55:11 +08:00
|
|
|
printf("\n|size_t|=%lu\n",(unsigned long)sizeof(size_t));
|
2016-01-06 12:26:25 +08:00
|
|
|
|
2017-05-31 06:09:43 +08:00
|
|
|
printf("\n*** Writing Max Dimension Size (%d) For NC_CLASSIC\n",DIMMAXCLASSIC);
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_create(FILECLASSIC, NC_CLOBBER, &ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
dimsize = DIMMAXCLASSIC;
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_def_dim(ncid, "testdim", dimsize, &dimid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_close(ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
|
|
|
|
printf("\n*** Reading Max Dimension Size For NC_CLASSIC\n");
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_open(FILECLASSIC, NC_NOCLOBBER, &ncid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_inq_dimid(ncid, "testdim", &dimid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
if(dimsize != DIMMAXCLASSIC) ERR;
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_close(ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
|
2017-05-31 06:09:43 +08:00
|
|
|
printf("\n*** Writing Max Dimension Size (%u) For NC_64BIT_OFFSET\n",DIMMAX64OFFSET);
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_create(FILE64OFFSET, NC_CLOBBER | NC_64BIT_OFFSET, &ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
dimsize = DIMMAX64OFFSET;
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_def_dim(ncid, "testdim", dimsize, &dimid))) ERRSTAT(stat);
|
2017-05-31 06:09:43 +08:00
|
|
|
if ((stat=nc_enddef(ncid))) ERRSTAT(stat);
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_close(ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
|
|
|
|
printf("\n*** Reading Max Dimension Size For NC_64BIT_OFFSET\n");
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_open(FILE64OFFSET, NC_NOCLOBBER|NC_64BIT_OFFSET, &ncid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_inq_dimid(ncid, "testdim", &dimid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
if(dimsize != DIMMAX64OFFSET) ERR;
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_close(ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
|
2018-06-30 10:17:07 +08:00
|
|
|
#ifdef ENABLE_CDF5
|
2016-01-06 12:26:25 +08:00
|
|
|
if(sizeof(size_t) == 8) {
|
2017-05-31 06:09:43 +08:00
|
|
|
printf("\n*** Writing Max Dimension Size (%llu) For NC_64BIT_DATA\n",DIMMAX64DATA);
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_create(FILE64DATA, NC_CLOBBER | NC_64BIT_DATA, &ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
dimsize = (size_t)DIMMAX64DATA;
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_def_dim(ncid, "testdim", dimsize, &dimid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_close(ncid))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
|
|
|
|
printf("\n*** Reading Max Dimension Size For NC_64BIT_DATA\n");
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_open(FILE64DATA, NC_NOCLOBBER|NC_64BIT_DATA, &ncid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_inq_dimid(ncid, "testdim", &dimid))) ERRSTAT(stat);
|
|
|
|
if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
|
2016-01-06 12:26:25 +08:00
|
|
|
if(dimsize != DIMMAX64DATA) ERR;
|
2016-01-09 03:55:11 +08:00
|
|
|
if ((stat=nc_close(ncid))) ERRSTAT(stat);
|
2016-10-22 01:17:39 +08:00
|
|
|
}
|
2018-06-30 10:17:07 +08:00
|
|
|
#endif /* ENABLE_CDF5 */
|
2016-01-06 12:26:25 +08:00
|
|
|
|
|
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
|
|
|
}
|