2012-03-26 09:34:32 +08:00
|
|
|
/** \file \internal
|
|
|
|
Basic diskless API tests.
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2018-12-07 05:56:42 +08:00
|
|
|
Copyright 2018, UCAR/Unidata. See COPYRIGHT file for copying and
|
2012-03-26 09:34:32 +08:00
|
|
|
redistribution conditions.
|
|
|
|
*/
|
|
|
|
|
2018-10-11 03:32:17 +08:00
|
|
|
#define DDBG
|
2012-06-24 03:25:49 +08:00
|
|
|
|
2018-09-05 01:27:47 +08:00
|
|
|
#include "config.h"
|
2012-03-26 09:34:32 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2018-09-05 01:27:47 +08:00
|
|
|
#include "netcdf.h"
|
|
|
|
#include "nc_tests.h"
|
|
|
|
#include "err_macros.h"
|
2012-03-26 09:34:32 +08:00
|
|
|
|
2018-02-25 11:36:24 +08:00
|
|
|
/*
|
|
|
|
netcdf tst_diskless {
|
|
|
|
variables:
|
|
|
|
int resistor_value;
|
|
|
|
float capacitor_value;
|
|
|
|
short number_of_555_timer_chips;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2018-10-11 03:32:17 +08:00
|
|
|
#ifndef NC_NETCDF3
|
|
|
|
#define NC_NETCDF3 0
|
|
|
|
#endif
|
2018-02-25 11:36:24 +08:00
|
|
|
|
2018-10-11 03:32:17 +08:00
|
|
|
#define FLAGS4 (NC_NETCDF4|NC_CLASSIC_MODEL)
|
|
|
|
#define FLAGS3 (NC_NETCDF3)
|
2012-03-26 09:34:32 +08:00
|
|
|
|
|
|
|
#define RESISTOR "resistor_value"
|
2016-10-22 03:24:40 +08:00
|
|
|
#define CAPACITOR "capacitor_value"
|
2012-03-26 09:34:32 +08:00
|
|
|
#define NUM555 "number_of_555_timer_chips"
|
|
|
|
|
2012-06-24 03:25:49 +08:00
|
|
|
#ifdef DDBG
|
|
|
|
#undef ERR
|
|
|
|
void fail(int line) {
|
|
|
|
fflush(stdout);
|
2018-10-11 03:32:17 +08:00
|
|
|
fprintf(stderr,"\nfail: line=%d\n",line);
|
2012-06-24 03:25:49 +08:00
|
|
|
fflush(stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#define ERR fail(__LINE__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Control flags */
|
2023-11-07 05:05:24 +08:00
|
|
|
static int flags, persist, usenetcdf4, use_mmap, diskless;
|
2018-10-11 03:32:17 +08:00
|
|
|
|
|
|
|
char*
|
|
|
|
smode(int mode)
|
|
|
|
{
|
|
|
|
static char ms[8192];
|
|
|
|
ms[0] = '\0';
|
|
|
|
if(mode & NC_NETCDF4)
|
|
|
|
strcat(ms,"NC_NETCDF4");
|
|
|
|
else
|
|
|
|
strcat(ms,"NC_NETCDF3");
|
|
|
|
if(mode & NC_DISKLESS)
|
|
|
|
strcat(ms,"|NC_DISKLESS");
|
|
|
|
if(mode & NC_WRITE)
|
|
|
|
strcat(ms,"|NC_WRITE");
|
|
|
|
if(mode & NC_NOCLOBBER)
|
|
|
|
strcat(ms,"|NC_NOCLOBBER");
|
|
|
|
if(mode & NC_INMEMORY)
|
|
|
|
strcat(ms,"|NC_INMEMORY");
|
|
|
|
if(mode & NC_PERSIST)
|
|
|
|
strcat(ms,"|NC_PERSIST");
|
|
|
|
if(mode & NC_MMAP)
|
|
|
|
strcat(ms,"|NC_MMAP");
|
|
|
|
return ms;
|
|
|
|
}
|
2012-06-24 03:25:49 +08:00
|
|
|
|
2018-09-05 01:27:47 +08:00
|
|
|
/* Remove a file; do not care if it does not exist */
|
2012-03-26 09:34:32 +08:00
|
|
|
static void
|
|
|
|
removefile(int persist, char* filename)
|
|
|
|
{
|
|
|
|
if(persist) {
|
2018-09-05 01:27:47 +08:00
|
|
|
remove(filename);
|
2012-03-26 09:34:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2012-06-24 03:25:49 +08:00
|
|
|
int i;
|
2012-03-26 09:34:32 +08:00
|
|
|
char* filename = "tst_diskless.nc";
|
|
|
|
|
|
|
|
/* Set defaults */
|
|
|
|
persist = 0;
|
|
|
|
usenetcdf4 = 0;
|
2023-11-07 05:05:24 +08:00
|
|
|
use_mmap = 0;
|
2018-10-11 03:32:17 +08:00
|
|
|
diskless = 0;
|
2012-03-26 09:34:32 +08:00
|
|
|
|
|
|
|
for(i=1;i<argc;i++) {
|
|
|
|
if(strcmp(argv[i],"netcdf4")==0) usenetcdf4=1;
|
|
|
|
else if(strcmp(argv[i],"persist")==0) persist=1;
|
2023-11-07 05:05:24 +08:00
|
|
|
else if(strcmp(argv[i],"mmap")==0) use_mmap=1;
|
2018-10-11 03:32:17 +08:00
|
|
|
else if(strcmp(argv[i],"diskless")==0) diskless=1;
|
2019-04-20 10:32:26 +08:00
|
|
|
else if(strncmp(argv[i],"file:",strlen("file:"))==0) {
|
|
|
|
filename = argv[i];
|
|
|
|
filename += strlen("file:");
|
|
|
|
}
|
2012-03-26 09:34:32 +08:00
|
|
|
/* ignore anything not recognized */
|
|
|
|
}
|
|
|
|
|
2020-08-18 09:15:47 +08:00
|
|
|
#ifndef USE_HDF5
|
2018-10-11 03:32:17 +08:00
|
|
|
fprintf(stderr,"netcdf-4 not supported; ignored\n");
|
2012-03-26 09:34:32 +08:00
|
|
|
usenetcdf4 = 0;
|
|
|
|
#endif
|
|
|
|
|
2018-10-11 03:32:17 +08:00
|
|
|
/* Invalid combinations */
|
2023-11-07 05:05:24 +08:00
|
|
|
if(use_mmap && diskless) {fprintf(stderr,"Illegal: mmap+diskless\n"); exit(1);};
|
|
|
|
if(use_mmap && usenetcdf4) {fprintf(stderr,"Illegal: mmap+netcdf4\n"); exit(1);};
|
2012-06-24 03:25:49 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
flags = usenetcdf4?FLAGS4:FLAGS3;
|
2018-10-11 03:32:17 +08:00
|
|
|
if(persist) flags |= NC_PERSIST;
|
2023-11-07 05:05:24 +08:00
|
|
|
if(use_mmap) flags |= NC_MMAP;
|
2018-10-11 03:32:17 +08:00
|
|
|
if(diskless) flags |= NC_DISKLESS;
|
2012-03-26 09:34:32 +08:00
|
|
|
|
2018-10-11 03:32:17 +08:00
|
|
|
printf("\n*** Testing the diskless|mmap API.\n");
|
2012-03-26 09:34:32 +08:00
|
|
|
printf("*** testing diskless file with scalar vars...");
|
|
|
|
{
|
|
|
|
int ncid, varid0, varid1, varid2;
|
|
|
|
int ndims_in, nvars_in, natts_in, unlimdimid_in;
|
|
|
|
char name_in[NC_MAX_NAME + 1];
|
|
|
|
nc_type type_in;
|
2023-12-17 08:41:08 +08:00
|
|
|
float float_data = 3.14F, float_data_in;
|
2012-03-26 09:34:32 +08:00
|
|
|
int int_data = 42, int_data_in;
|
|
|
|
short short_data = 2, short_data_in;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
removefile(persist,filename);
|
|
|
|
|
2018-10-11 03:32:17 +08:00
|
|
|
/* Create a netCDF file (which exists in memory). */
|
2012-03-26 09:34:32 +08:00
|
|
|
if (nc_create(filename, flags, &ncid)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Create some variables. */
|
|
|
|
if (nc_def_var(ncid, RESISTOR, NC_INT, 0, NULL, &varid0)) ERR;
|
|
|
|
if (nc_def_var(ncid, CAPACITOR, NC_FLOAT, 0, NULL, &varid1)) ERR;
|
|
|
|
if (nc_def_var(ncid, NUM555, NC_SHORT, 0, NULL, &varid2)) ERR;
|
|
|
|
if (nc_enddef(ncid)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Write some data to this file. */
|
|
|
|
if (nc_put_vara_int(ncid, varid0, NULL, NULL, &int_data)) ERR;
|
|
|
|
if (nc_put_vara_float(ncid, varid1, NULL, NULL, &float_data)) ERR;
|
|
|
|
if (nc_put_vara_short(ncid, varid2, NULL, NULL, &short_data)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Now check the phony file. */
|
|
|
|
if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdimid_in)) ERR;
|
|
|
|
if (ndims_in != 0 || nvars_in != 3 || natts_in != 0 || unlimdimid_in != -1) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Check variables. */
|
|
|
|
if (nc_inq_var(ncid, varid0, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, RESISTOR) != 0 || type_in != NC_INT || ndims_in != 0 ||
|
2012-03-26 09:34:32 +08:00
|
|
|
natts_in != 0) ERR;
|
|
|
|
if (nc_inq_var(ncid, varid1, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, CAPACITOR) != 0 || type_in != NC_FLOAT || ndims_in != 0 ||
|
2012-03-26 09:34:32 +08:00
|
|
|
natts_in != 0) ERR;
|
|
|
|
if (nc_inq_var(ncid, varid2, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, NUM555) != 0 || type_in != NC_SHORT || natts_in != 0) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Read my absolutely crucial data. */
|
|
|
|
if (nc_get_vara_int(ncid, varid0, NULL, NULL, &int_data_in)) ERR;
|
|
|
|
if (int_data_in != int_data) ERR;
|
|
|
|
if (nc_get_vara_float(ncid, varid1, NULL, NULL, &float_data_in)) ERR;
|
|
|
|
if (float_data_in != float_data) ERR;
|
|
|
|
if (nc_get_vara_short(ncid, varid2, NULL, NULL, &short_data_in)) ERR;
|
|
|
|
if (short_data_in != short_data) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Close the file. */
|
|
|
|
if (nc_close(ncid))
|
2014-08-27 01:19:32 +08:00
|
|
|
abort(); /* ERR; */
|
2012-03-26 09:34:32 +08:00
|
|
|
}
|
|
|
|
SUMMARIZE_ERR;
|
2012-06-24 03:25:49 +08:00
|
|
|
|
|
|
|
if(!usenetcdf4 && persist) {
|
|
|
|
int ncid, varid0, varid1, varid2;
|
2023-12-17 08:41:08 +08:00
|
|
|
float float_data = 3.14F, float_data_in;
|
2012-06-24 03:25:49 +08:00
|
|
|
int int_data = 42, int_data_in;
|
|
|
|
short short_data = 2, short_data_in;
|
|
|
|
|
|
|
|
printf("*** testing diskless open of previously created file...");
|
|
|
|
|
|
|
|
if (nc_open(filename, flags, &ncid)) ERR;
|
|
|
|
|
|
|
|
/* Read and compare */
|
|
|
|
if (nc_inq_varid(ncid, RESISTOR, &varid0)) ERR;
|
|
|
|
if (nc_inq_varid(ncid, CAPACITOR, &varid1)) ERR;
|
|
|
|
if (nc_inq_varid(ncid, NUM555, &varid2)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-06-24 03:25:49 +08:00
|
|
|
if (nc_get_vara_int(ncid, varid0, NULL, NULL, &int_data_in)) ERR;
|
|
|
|
if (int_data_in != int_data) ERR;
|
|
|
|
if (nc_get_vara_float(ncid, varid1, NULL, NULL, &float_data_in)) ERR;
|
|
|
|
if (float_data_in != float_data) ERR;
|
|
|
|
if (nc_get_vara_short(ncid, varid2, NULL, NULL, &short_data_in)) ERR;
|
|
|
|
if (short_data_in != short_data) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-06-24 03:25:49 +08:00
|
|
|
nc_close(ncid);
|
2016-10-22 03:24:40 +08:00
|
|
|
}
|
2012-06-24 03:25:49 +08:00
|
|
|
SUMMARIZE_ERR;
|
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
printf("*** testing creation of simple diskless file...");
|
|
|
|
{
|
|
|
|
#define NDIMS 2
|
|
|
|
#define DIM0_NAME "Fun"
|
|
|
|
#define DIM1_NAME "Money"
|
|
|
|
#define DIM1_LEN 200
|
|
|
|
#define ATT0_NAME "home"
|
|
|
|
#define ATT0_TEXT "earthship"
|
|
|
|
#define VAR0_NAME "nightlife"
|
|
|
|
#define VAR1_NAME "time"
|
|
|
|
#define VAR2_NAME "taxi_distance"
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
int ncid, dimid[NDIMS], dimid_in[NDIMS], varid0, varid1, varid2;
|
|
|
|
int ndims_in, nvars_in, natts_in, unlimdimid_in;
|
|
|
|
char name_in[NC_MAX_NAME + 1], att0_in[NC_MAX_NAME + 1];
|
|
|
|
nc_type type_in;
|
|
|
|
size_t len_in;
|
|
|
|
short short_data[DIM1_LEN];
|
|
|
|
size_t start[1] = {0};
|
|
|
|
size_t count[1] = {DIM1_LEN};
|
|
|
|
int i;
|
2023-12-17 08:41:08 +08:00
|
|
|
float float_data = 42.22F, float_data_in;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* This is some really important data that I want to save. */
|
|
|
|
for (i = 0; i < DIM1_LEN; i++)
|
|
|
|
short_data[i] = i;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
removefile(persist,filename);
|
|
|
|
|
|
|
|
/* Create a netCDF file (which exists only in memory). I am
|
|
|
|
* confident that the world-famous netCDF format is the way to
|
|
|
|
* store my data! */
|
|
|
|
if (nc_create(filename, flags, &ncid)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Create some atts. They will help document my data forever. */
|
|
|
|
if (nc_put_att_text(ncid, NC_GLOBAL, ATT0_NAME,
|
2017-10-27 04:50:21 +08:00
|
|
|
sizeof(ATT0_TEXT), ATT0_TEXT)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Create dimensions: money is limited, but fun is not! */
|
|
|
|
if (nc_def_dim(ncid, DIM0_NAME, NC_UNLIMITED, &dimid[0])) ERR;
|
|
|
|
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimid[1])) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Create some variables. The data they hold must persist
|
|
|
|
* through the ages. */
|
|
|
|
if (nc_def_var(ncid, VAR0_NAME, NC_INT, NDIMS, dimid, &varid0)) ERR;
|
|
|
|
if (nc_def_var(ncid, VAR1_NAME, NC_FLOAT, 0, NULL, &varid1)) ERR;
|
|
|
|
if (nc_def_var(ncid, VAR2_NAME, NC_SHORT, 1, &dimid[1], &varid2)) ERR;
|
|
|
|
if (nc_enddef(ncid)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Write some data to this file. I'm glad I'm saving this
|
|
|
|
* important data in such a safe format! */
|
|
|
|
if (nc_put_vara_float(ncid, varid1, NULL, NULL, &float_data)) ERR;
|
|
|
|
if (nc_put_vara_short(ncid, varid2, start, count, short_data)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Now check the phony file. Is my data safe? */
|
|
|
|
if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdimid_in)) ERR;
|
|
|
|
if (ndims_in != 2 || nvars_in != 3 || natts_in != 1 || unlimdimid_in != 0) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Check attributes - they will be needed by future generations
|
|
|
|
* of scientists to understand my data. */
|
|
|
|
if (nc_get_att_text(ncid, NC_GLOBAL, ATT0_NAME, att0_in)) ERR;
|
2017-10-27 04:50:21 +08:00
|
|
|
att0_in[sizeof(ATT0_TEXT)] = '\0';
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(att0_in, ATT0_TEXT) != 0) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Check dimensions. */
|
|
|
|
if (nc_inq_dim(ncid, dimid[0], name_in, &len_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, DIM0_NAME) != 0 || len_in != 0) ERR;
|
2012-03-26 09:34:32 +08:00
|
|
|
if (nc_inq_dim(ncid, dimid[1], name_in, &len_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, DIM1_NAME) != 0 || len_in != DIM1_LEN) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Check variables. */
|
|
|
|
if (nc_inq_var(ncid, varid0, name_in, &type_in, &ndims_in, dimid_in, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, VAR0_NAME) != 0 || type_in != NC_INT || ndims_in != NDIMS ||
|
2012-03-26 09:34:32 +08:00
|
|
|
dimid_in[0] != 0 || dimid_in[1] != 1 || natts_in != 0) ERR;
|
|
|
|
if (nc_inq_var(ncid, varid1, name_in, &type_in, &ndims_in, dimid_in, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, VAR1_NAME) != 0 || type_in != NC_FLOAT || ndims_in != 0 ||
|
2012-03-26 09:34:32 +08:00
|
|
|
natts_in != 0) ERR;
|
|
|
|
if (nc_inq_var(ncid, varid2, name_in, &type_in, &ndims_in, dimid_in, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, VAR2_NAME) != 0 || type_in != NC_SHORT || ndims_in != 1 ||
|
2012-03-26 09:34:32 +08:00
|
|
|
dimid_in[0] != 1 || natts_in != 0) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Read my absolutely crucial data. */
|
|
|
|
if (nc_get_vara_float(ncid, varid1, NULL, NULL, &float_data_in)) ERR;
|
|
|
|
if (float_data_in != float_data) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Close the file, losing all information. Hey! What kind of
|
|
|
|
* storage format is this, anyway? */
|
|
|
|
if (nc_close(ncid))
|
2014-08-27 01:19:32 +08:00
|
|
|
abort(); /* ERR; */
|
2012-03-26 09:34:32 +08:00
|
|
|
}
|
|
|
|
SUMMARIZE_ERR;
|
|
|
|
printf("*** testing diskless file with scalar vars and type conversion...");
|
|
|
|
{
|
|
|
|
#define DUNE "dune"
|
|
|
|
#define STAR_TREK "capacitor_value"
|
|
|
|
#define STAR_WARS "number_of_555_timer_chips"
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
int ncid, varid0, varid1, varid2;
|
|
|
|
int ndims_in, nvars_in, natts_in, unlimdimid_in;
|
|
|
|
char name_in[NC_MAX_NAME + 1];
|
|
|
|
nc_type type_in;
|
2023-12-17 08:41:08 +08:00
|
|
|
float float_data = 3.14F, float_data_in;
|
2012-03-26 09:34:32 +08:00
|
|
|
int int_data = 42, int_data_in;
|
|
|
|
short short_data = 2, short_data_in;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
removefile(persist,filename);
|
|
|
|
|
|
|
|
/* Create a netCDF file (which exists only in memory). */
|
|
|
|
if (nc_create(filename, flags, &ncid)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Create some variables. */
|
|
|
|
if (nc_def_var(ncid, DUNE, NC_INT, 0, NULL, &varid0)) ERR;
|
|
|
|
if (nc_def_var(ncid, STAR_TREK, NC_FLOAT, 0, NULL, &varid1)) ERR;
|
|
|
|
if (nc_def_var(ncid, STAR_WARS, NC_SHORT, 0, NULL, &varid2)) ERR;
|
|
|
|
if (nc_enddef(ncid)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Write some data to this file. */
|
|
|
|
if (nc_put_vara_int(ncid, varid0, NULL, NULL, &int_data)) ERR;
|
|
|
|
if (nc_put_vara_float(ncid, varid1, NULL, NULL, &float_data)) ERR;
|
|
|
|
if (nc_put_vara_short(ncid, varid2, NULL, NULL, &short_data)) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Now check the phony file. */
|
|
|
|
if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdimid_in)) ERR;
|
|
|
|
if (ndims_in != 0 || nvars_in != 3 || natts_in != 0 || unlimdimid_in != -1) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Check variables. */
|
|
|
|
if (nc_inq_var(ncid, varid0, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, DUNE) != 0 || type_in != NC_INT || ndims_in != 0 ||
|
2012-03-26 09:34:32 +08:00
|
|
|
natts_in != 0) ERR;
|
|
|
|
if (nc_inq_var(ncid, varid1, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, STAR_TREK) != 0 || type_in != NC_FLOAT || ndims_in != 0 ||
|
2012-04-09 06:47:38 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
natts_in != 0) ERR;
|
|
|
|
if (nc_inq_var(ncid, varid2, name_in, &type_in, &ndims_in, NULL, &natts_in)) ERR;
|
2023-12-17 08:06:27 +08:00
|
|
|
if (strcmp(name_in, STAR_WARS) != 0 || type_in != NC_SHORT || natts_in != 0) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Read my absolutely crucial data. */
|
|
|
|
if (nc_get_vara_int(ncid, varid0, NULL, NULL, &int_data_in)) ERR;
|
|
|
|
if (int_data_in != int_data) ERR;
|
|
|
|
if (nc_get_vara_float(ncid, varid1, NULL, NULL, &float_data_in)) ERR;
|
|
|
|
if (float_data_in != float_data) ERR;
|
|
|
|
if (nc_get_vara_short(ncid, varid2, NULL, NULL, &short_data_in)) ERR;
|
|
|
|
if (short_data_in != short_data) ERR;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-03-26 09:34:32 +08:00
|
|
|
/* Close the file. */
|
|
|
|
if (nc_close(ncid))
|
2014-08-27 01:19:32 +08:00
|
|
|
abort(); /* ERR; */
|
2012-03-26 09:34:32 +08:00
|
|
|
}
|
|
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
2016-10-22 03:24:40 +08:00
|
|
|
|
2012-07-31 05:49:16 +08:00
|
|
|
/* Unnecessary exit(0), FINAL_RESULTS returns. */
|
2014-08-27 01:19:32 +08:00
|
|
|
/* exit(0); */
|
2012-03-26 09:34:32 +08:00
|
|
|
}
|