mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
Corrected an issue observed on centos7.
This commit is contained in:
parent
a98df356d9
commit
189499a10e
@ -1,9 +1,9 @@
|
||||
/* This is part of the netCDF package. Copyright 2005-2011,
|
||||
/* This is part of the netCDF package. Copyright 2005-2018,
|
||||
University Corporation for Atmospheric Research/Unidata. See
|
||||
COPYRIGHT file for conditions of use.
|
||||
|
||||
Test that NetCDF-4 can read HDF4 files.
|
||||
Ed Hartnett
|
||||
Ed Hartnett, Ward Fisher
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <nc_tests.h>
|
||||
@ -30,12 +30,12 @@ create_hdf4_file()
|
||||
int test_val = 42;
|
||||
int i, j;
|
||||
int count = 0;
|
||||
|
||||
|
||||
/* Create some data. */
|
||||
for (i = 0; i < LAT_LEN; i++)
|
||||
for (j = 0; j < LON_LEN; j++)
|
||||
data_out[i][j] = count++;
|
||||
|
||||
|
||||
/* Create a file with one SDS, containing our phony data. */
|
||||
sd_id = SDstart(FILE_NAME, DFACC_CREATE);
|
||||
sds_id = SDcreate(sd_id, PRES_NAME, DFNT_INT32, NDIMS2, dim_size);
|
||||
@ -58,16 +58,17 @@ main(int argc, char **argv)
|
||||
|
||||
/* Create our test file. */
|
||||
if (create_hdf4_file()) ERR;
|
||||
|
||||
|
||||
printf("*** testing data conversion...");
|
||||
{
|
||||
int ncid;
|
||||
size_t start[NDIMS2] = {0, 0}, count[NDIMS2] = {LAT_LEN, LON_LEN};
|
||||
int data_int[LAT_LEN * LON_LEN];
|
||||
short data_short[LAT_LEN * LON_LEN];
|
||||
int data_int2[LAT_LEN * LON_LEN];
|
||||
float data_float[LAT_LEN * LON_LEN];
|
||||
double data_double[LAT_LEN * LON_LEN];
|
||||
int data_int[LAT_LEN * LON_LEN];
|
||||
short data_short[LAT_LEN * LON_LEN];
|
||||
int data_int2[LAT_LEN * LON_LEN];
|
||||
float data_float[LAT_LEN * LON_LEN];
|
||||
double data_double[LAT_LEN * LON_LEN];
|
||||
int i = 0;
|
||||
|
||||
/* Open HDF4 file with netCDF. */
|
||||
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
|
||||
@ -79,27 +80,27 @@ main(int argc, char **argv)
|
||||
|
||||
/* Read data as short. */
|
||||
if (nc_get_vara_short(ncid, 0, start, count, data_short)) ERR;
|
||||
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
for (i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
if (data_short[i] != (short)i) ERR;
|
||||
|
||||
/* Read data as int. */
|
||||
if (nc_get_vara_int(ncid, 0, start, count, data_int)) ERR;
|
||||
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
for (i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
if (data_int[i] != i) ERR;
|
||||
|
||||
/* NULL count is treated as meaing entire variable. */
|
||||
if (nc_get_vara_int(ncid, 0, start, NULL, data_int2)) ERR;
|
||||
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
for (i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
if (data_int2[i] != i) ERR;
|
||||
|
||||
/* Read data as float. */
|
||||
if (nc_get_vara_float(ncid, 0, start, count, data_float)) ERR;
|
||||
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
for (i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
if (data_float[i] != (float)i) ERR;
|
||||
|
||||
/* Read data as double. */
|
||||
if (nc_get_vara_double(ncid, 0, start, count, data_double)) ERR;
|
||||
for (int i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
for (i = 0; i < LAT_LEN * LON_LEN; i++)
|
||||
if (data_double[i] != (double)i) ERR;
|
||||
|
||||
/* Close the file. */
|
||||
|
Loading…
Reference in New Issue
Block a user