netcdf-c/nc_test/quick_large_files.c

574 lines
19 KiB
C
Raw Normal View History

2010-06-03 21:24:43 +08:00
/*
Copyright 2004-2006, UCAR/Unidata
See COPYRIGHT file for copying and redistribution conditions.
This program (quickly, but not thoroughly) tests the large file
2010-06-03 21:24:43 +08:00
features. It turns off fill mode to quickly create an 8 gb file, and
write one value is written, nothing is read.
$Id: quick_large_files.c,v 1.18 2008/06/05 15:10:16 ed Exp $
*/
#include <config.h>
#include <nc_tests.h>
2016-11-19 06:48:58 +08:00
#include "err_macros.h"
2010-06-03 21:24:43 +08:00
#include <netcdf.h>
#include <stdio.h>
#include <string.h>
#define NUMDIMS 1
#define NUMVARS 2
/* This is the magic number for classic format limits: 2 GiB - 4
bytes. */
#define MAX_CLASSIC_BYTES 2147483644
/* This is the magic number for 64-bit offset format limits: 4 GiB - 4
bytes. */
#define MAX_64OFFSET_BYTES 4294967292
/* Handy for constucting tests. */
#define QTR_CLASSIC_MAX (MAX_CLASSIC_BYTES/4)
/* We will create this file. */
#define FILE_NAME "quick_large_files.nc"
int
main(int argc, char **argv)
{
int ncid, spockid, kirkid, dimids[NUMDIMS], recdimid, scottyid;
2010-06-03 21:24:43 +08:00
int int_val_in, int_val_out = 99;
double double_val_in, double_val_out = 1.79769313486230e+308; /* from ncx.h */
size_t index[2] = {QTR_CLASSIC_MAX-1, 0};
char file_name[NC_MAX_NAME + 1];
/* These are for the revolutionary generals tests. */
int cromwellid, collinsid, washingtonid;
int napoleanid, dimids_gen[4], dimids_gen1[4];
/* All create modes will be anded to this. All tests will be run
twice, with and without NC_SHARE.*/
int cmode_run;
int cflag = NC_CLOBBER;
2016-11-19 06:48:58 +08:00
int res;
2010-06-03 21:24:43 +08:00
printf("\n*** Testing large files, quickly.\n");
for (cmode_run=0; cmode_run<2; cmode_run++)
{
size_t big_index = (size_t)MAX_CLASSIC_BYTES + 10;
2010-06-03 21:24:43 +08:00
/* On second pass, try using NC_SHARE. */
2016-11-19 06:48:58 +08:00
if (cmode_run == 1)
2010-06-03 21:24:43 +08:00
{
cflag |= NC_SHARE;
printf("*** Turned on NC_SHARE for subsequent tests.\n");
}
/* Create a netCDF 64-bit offset format file. Write a value. */
2016-11-19 06:48:58 +08:00
sprintf(file_name, "%s/%s", TEMP_LARGE, FILE_NAME);
2010-06-03 21:24:43 +08:00
printf("*** Creating %s for 64-bit offset large file test...", file_name);
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
if ((res = nc_def_dim(ncid, "longdim", QTR_CLASSIC_MAX, dimids)))
ERR;
/* test bug fix writing record beyond 2**31 */
if ((res = nc_def_dim(ncid, "longerdim", NC_UNLIMITED, &recdimid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "spock", NC_DOUBLE, NUMDIMS,
2010-06-03 21:24:43 +08:00
dimids, &spockid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "kirk", NC_DOUBLE, NUMDIMS,
2010-06-03 21:24:43 +08:00
dimids, &kirkid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "scotty", NC_BYTE, 1,
&recdimid, &scottyid)))
ERR;
2010-06-03 21:24:43 +08:00
if ((res = nc_enddef(ncid)))
ERR;
if ((res = nc_put_var1_double(ncid, kirkid, index, &double_val_out)))
ERR;
if ((res = nc_put_var1_int(ncid, scottyid, &big_index, &int_val_out)))
ERR;
if ((res = nc_get_var1_int(ncid, scottyid, &big_index, &int_val_in)))
ERR;
2016-11-19 06:48:58 +08:00
if (int_val_in != int_val_out)
ERR;
2010-06-03 21:24:43 +08:00
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* How about a meteorological data file about the weather
2016-11-19 06:48:58 +08:00
experience by various generals of revolutionary armies?
2010-06-03 21:24:43 +08:00
This has 3 dims, 4 vars. The dimensions are such that this will
(just barely) not fit in a classic format file. The first three
vars are cromwell, 536870911 bytes, washington, 2*536870911
bytes, and napolean, 536870911 bytes. That's a grand total of
2010-06-03 21:24:43 +08:00
2147483644 bytes. Recall our magic limit for the combined size
of all fixed vars: 2 GiB - 4 bytes, or 2147483644. So you would
think these would exactly fit, unless you realized that
everything is rounded to a 4 byte boundary, so you need to add
some bytes for that (how many?), and that pushes us over the
limit.
2016-11-19 06:48:58 +08:00
2010-06-03 21:24:43 +08:00
We will create this file twice, once to ensure it succeeds (with
64-bit offset format), and once to make sure it fails (with
classic format). Then some variations to check record var
2016-11-19 06:48:58 +08:00
boundaries.
2010-06-03 21:24:43 +08:00
*/
2016-11-19 06:48:58 +08:00
printf("*** Now a 64-bit offset, large file, fixed var test...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[1])))
ERR;
if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2])))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 1, &dimids_gen[0],
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, &dimids_gen[1],
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 1, &dimids_gen[0],
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2],
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* Write a value or two just for fun. */
/*index[0] = QTR_CLASSIC_MAX - 296;
if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out)))
ERR;
if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in)))
ERR;
if (int_val_in != int_val_out)
BAIL2;*/
2016-11-19 06:48:58 +08:00
printf("*** Now writing some values...");
2010-06-03 21:24:43 +08:00
index[0] = QTR_CLASSIC_MAX - 295;
if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out)))
ERR;
if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in)))
ERR;
if (int_val_in != int_val_out)
ERR;
index[0] = QTR_CLASSIC_MAX - 1;
if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out)))
ERR;
if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in)))
ERR;
if (int_val_in != int_val_out)
ERR;
index[0] = QTR_CLASSIC_MAX - 1;
if ((res = nc_put_var1_int(ncid, washingtonid, index, &int_val_out)))
ERR;
if ((res = nc_get_var1_int(ncid, washingtonid, index, &int_val_in)))
ERR;
if (int_val_in != int_val_out)
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* This time it should fail, because we're trying to cram this into
a classic format file. nc_enddef will detect our violations and
give an error. We've*/
2016-11-19 06:48:58 +08:00
printf("*** Now a classic file which will fail...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[1])))
ERR;
if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2])))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 1, &dimids_gen[0],
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, &dimids_gen[1],
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 1, &dimids_gen[0],
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2],
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
ERR;
if ((res = nc_close(ncid)) != NC_EVARSIZE)
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* This will create some max sized 64-bit offset format fixed vars. */
2016-11-19 06:48:58 +08:00
printf("*** Now a 64-bit offset, simple fixed var create test...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
MAX_CLASSIC_BYTES, &dimids_gen[0])))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_SHORT, 1, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_SHORT, 1, dimids_gen,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, dimids_gen,
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* This will exceed the 64-bit offset format limits for one of the
fixed vars. */
2016-11-19 06:48:58 +08:00
printf("*** Now a 64-bit offset, over-sized file that will fail...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
/* max dim size is MAX_CLASSIC_BYTES. */
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
MAX_CLASSIC_BYTES, dimids_gen)))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 1, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, dimids_gen,
2010-06-03 21:24:43 +08:00
&washingtonid)))
if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
ERR;
if ((res = nc_close(ncid)) != NC_EVARSIZE)
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* Now let's see about record vars. First create a 64-bit offset
file with three rec variables, each with the same numbers as
defined above for the fixed var tests. This should all work. */
2016-11-19 06:48:58 +08:00
printf("*** Now a 64-bit offset, record var file...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[1])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[2])))
ERR;
if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[3])))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen,
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2],
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* Now try this record file in classic format. It should fail and
the enddef. Too many bytes in the first record.*/
2016-11-19 06:48:58 +08:00
printf("*** Now a classic file that's too big and will fail...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[1])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
QTR_CLASSIC_MAX, &dimids_gen[2])))
ERR;
if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[3])))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen,
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2],
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
ERR;
if ((res = nc_close(ncid)) != NC_EVARSIZE)
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* Now try this record file in classic format. It just barely
passes at the enddef. Almost, but not quite, too many bytes in
2016-11-19 06:48:58 +08:00
the first record. Since I'm adding a fixed variable (Collins),
I don't get the last record size exemption. */
printf("*** Now a classic file with recs and one fixed will fail...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
2010-06-03 21:24:43 +08:00
MAX_CLASSIC_BYTES, &dimids_gen[1])))
ERR;
if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2])))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2],
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* Try a classic file with several records, and the last record var
with a record size greater than our magic number of 2 GiB - 4
bytes. We'll start with just one oversized record var. This
should work. Cromwell has been changed to NC_DOUBLE, and that
increases his size to 2147483644 (the max dimension size) times
8, or about 16 GB per record. Zowie! (Mind you, Cromwell
certainly had a great deal of revolutionary fervor.)
2016-11-19 06:48:58 +08:00
*/
printf("*** Now a classic file with one large rec var...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
MAX_CLASSIC_BYTES, &dimids_gen[1])))
2010-06-03 21:24:43 +08:00
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
&cromwellid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
index[0] = 0;
index[1] = MAX_CLASSIC_BYTES - 1;
if ((res = nc_put_var1_double(ncid, cromwellid, index, &double_val_out)))
ERR;
if ((res = nc_get_var1_double(ncid, cromwellid, index, &double_val_in)))
ERR;
if (double_val_in != double_val_out)
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* This is a classic format file with an extra-large last record
var. */
printf("*** Now a classic file with extra-large last record var...") ;
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
MAX_CLASSIC_BYTES, &dimids_gen[1])))
2010-06-03 21:24:43 +08:00
ERR;
dimids_gen1[0] = dimids_gen[0];
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
5368, &dimids_gen1[1])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
&cromwellid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
index[0] = 0;
index[1] = MAX_CLASSIC_BYTES - 1;
if ((res = nc_put_var1_double(ncid, cromwellid, index, &double_val_out)))
ERR;
if ((res = nc_get_var1_double(ncid, cromwellid, index, &double_val_in)))
ERR;
if (double_val_in != double_val_out)
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* This is a classic format file with an extra-large second to last
record var. But this time it won't work, because the size
exemption only applies to the last record var. Note that one
dimension is small (5000). */
2016-11-19 06:48:58 +08:00
printf("*** Now a classic file xtra-large 2nd to last var that will fail...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
MAX_CLASSIC_BYTES, &dimids_gen[1])))
2010-06-03 21:24:43 +08:00
ERR;
dimids_gen1[0] = dimids_gen[0];
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
5000, &dimids_gen1[1])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
ERR;
if ((res = nc_close(ncid)) != NC_EVARSIZE)
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* Now try an extra large second to last ver with 64-bit
offset. This won't work either, because the cromwell var is so
large. It exceeds the 4GiB - 4 byte per record limit for record
vars. */
2016-11-19 06:48:58 +08:00
printf("*** Now a 64-bit offset file with too-large rec var that will fail...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
MAX_CLASSIC_BYTES, &dimids_gen[1])))
2010-06-03 21:24:43 +08:00
ERR;
dimids_gen1[0] = dimids_gen[0];
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
5368, &dimids_gen1[1])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
ERR;
if ((res = nc_close(ncid)) != NC_EVARSIZE)
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
/* A 64-bit offset record file that just fits... */
2016-11-19 06:48:58 +08:00
printf("*** Now a 64 bit-offset file that just fits...");
2010-06-03 21:24:43 +08:00
if ((res = nc_create(file_name, cflag|NC_64BIT_OFFSET, &ncid)))
ERR;
if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "political_trouble",
2010-06-03 21:24:43 +08:00
NC_UNLIMITED, &dimids_gen[0])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "revolutionary_fervor",
MAX_CLASSIC_BYTES, &dimids_gen[1])))
2010-06-03 21:24:43 +08:00
ERR;
dimids_gen1[0] = dimids_gen[0];
2016-11-19 06:48:58 +08:00
if ((res = nc_def_dim(ncid, "post_revoultionary_hangover",
2010-06-03 21:24:43 +08:00
MAX_CLASSIC_BYTES, &dimids_gen1[1])))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&washingtonid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Napolean", NC_SHORT, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&napoleanid)))
ERR;
if ((res = nc_def_var(ncid, "Cromwell", NC_SHORT, 2, dimids_gen,
&cromwellid)))
ERR;
2016-11-19 06:48:58 +08:00
if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1,
2010-06-03 21:24:43 +08:00
&collinsid)))
ERR;
if ((res = nc_enddef(ncid)))
ERR;
index[0] = 0;
index[1] = MAX_CLASSIC_BYTES - 1;
if ((res = nc_put_var1_int(ncid, cromwellid, index, &int_val_out)))
ERR;
if ((res = nc_get_var1_int(ncid, cromwellid, index, &int_val_in)))
ERR;
if (int_val_in != int_val_out)
ERR;
if ((res = nc_close(ncid)))
ERR;
2016-11-19 06:48:58 +08:00
printf("ok\n");
2010-06-03 21:24:43 +08:00
} /* end of cmode run */
/* Wow! Everything worked! */
2016-11-19 06:48:58 +08:00
printf("*** Tests successful!\n");
2010-06-03 21:24:43 +08:00
/* Delete the huge data file we created. */
2016-11-19 06:48:58 +08:00
(void) remove(file_name);
2010-06-03 21:24:43 +08:00
return 0;
}