mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-24 16:04:40 +08:00
9983b9d911
re pull request https://github.com/Unidata/netcdf-c/pull/405 re pull request https://github.com/Unidata/netcdf-c/pull/446 Notes: 1. This branch is a cleanup of the magic.dmh branch. 2. magic.dmh was originally merged, but caused problems with parallel IO. It was re-issued as pull request https://github.com/Unidata/netcdf-c/pull/446. 3. This branch + pull request replace any previous pull requests and magic.dmh branch. Given an otherwise valid netCDF file that has a corrupted header, the netcdf library currently crashes. Instead, it should return NC_ENOTNC. Additionally, the NC_check_file_type code does not do the forward search required by hdf5 files. It currently only looks at file position 0 instead of 512, 1024, 2048,... Also, it turns out that the HDF4 magic number is assumed to always be at the beginning of the file (unlike HDF5). The change is localized to libdispatch/dfile.c See https://support.hdfgroup.org/release4/doc/DSpec_html/DS.pdf Also, it turns out that the code in NC_check_file_type is duplicated (mostly) in the function libsrc4/nc4file.c#nc_check_for_hdf. This branch does the following. 1. Make NC_check_file_type return NC_ENOTNC instead of crashing. 2. Remove nc_check_for_hdf and centralize all file format checking NC_check_file_type. 3. Add proper forward search for HDF5 files (but not HDF4 files) to look for the magic number at offsets of 0, 512, 1024... 4. Add test tst_hdf5_offset.sh. This tests that hdf5 files with an offset are properly recognized. It does so by prefixing a legal file with some number of zero bytes: 512, 1024, etc. 5. Off-topic: Added -N flag to ncdump to force a specific output dataset name.
63 lines
1.9 KiB
C
63 lines
1.9 KiB
C
/* This is part of the netCDF package.
|
|
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
|
See COPYRIGHT file for conditions of use.
|
|
|
|
Test netcdf-4 variables.
|
|
$Id: tst_large.c,v 1.5 2009/05/18 10:26:24 ed Exp $
|
|
*/
|
|
|
|
#include <nc_tests.h>
|
|
#include "err_macros.h"
|
|
#include "netcdf.h"
|
|
#include "ncdispatch.h"
|
|
|
|
#define FILE_NAME "tst_large.nc"
|
|
#define NUMDIMS 2 /* rank of each variable in tests */
|
|
#define DIM1 2048
|
|
#define DIM2 2097153 /* DIM1*DIM2*sizeof(char) > 2**32 */
|
|
|
|
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
|
|
printf("\n*** Testing netcdf-4 large files.\n");
|
|
printf("**** testing simple fill value attribute creation...");
|
|
{
|
|
int ncid, varid, dimids[NUMDIMS];
|
|
size_t index[NUMDIMS] = {0, 0};
|
|
signed char vals[DIM2];
|
|
signed char char_val_in;
|
|
size_t start[NUMDIMS] = {0, 0}, count[NUMDIMS] = {1, DIM2};
|
|
int j;
|
|
|
|
/* Create phony data. */
|
|
for (j = 0; j < DIM2; j++)
|
|
vals[j] = 9 * (j + 11); /* note vals[j] is 99 when j==0 */
|
|
|
|
/* Create file with 2 dims and one var. */
|
|
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
|
if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
|
|
if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR;
|
|
if (nc_def_dim(ncid, "dim2", DIM2, &dimids[1])) ERR;
|
|
if (nc_def_var(ncid, "var", NC_BYTE, NUMDIMS, dimids, &varid)) ERR;
|
|
if (nc_enddef(ncid)) ERR;
|
|
|
|
/* Write one slice, then close. */
|
|
if (nc_put_vara_schar(ncid, varid, start, count, vals)) ERR;
|
|
if (nc_close(ncid)) ERR;
|
|
|
|
/* Reopen and read a value. */
|
|
/* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
|
|
/* if (nc_inq_varid(ncid, "var", &varid)) ERR; */
|
|
/* if (nc_get_var1_schar(ncid, varid, index, &char_val_in)) ERR; */
|
|
/* if (char_val_in != 99) /\* see above, the value written when start[0]==0, j==0 *\/ */
|
|
/* ERR; */
|
|
/* if (nc_close(ncid)) ERR; */
|
|
}
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
|
}
|