mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
now testing that endianness can only be set on atomic ints and floats
This commit is contained in:
parent
1a6351dab2
commit
965da1de01
@ -796,7 +796,27 @@ reportchunking(dfalt?"extra: default: ":"extra: user: ",var);
|
||||
|
||||
/* Is the user setting the endianness? */
|
||||
if (endianness)
|
||||
{
|
||||
/* Setting endianness is only premitted on atomic integer and
|
||||
* atomic float types. */
|
||||
switch (var->type_info->hdr.id)
|
||||
{
|
||||
case NC_BYTE:
|
||||
case NC_SHORT:
|
||||
case NC_INT:
|
||||
case NC_FLOAT:
|
||||
case NC_DOUBLE:
|
||||
case NC_UBYTE:
|
||||
case NC_USHORT:
|
||||
case NC_UINT:
|
||||
case NC_INT64:
|
||||
case NC_UINT64:
|
||||
break;
|
||||
default:
|
||||
return NC_EINVAL;
|
||||
}
|
||||
var->type_info->endianness = *endianness;
|
||||
}
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ main(int argc, char **argv)
|
||||
if (nc_insert_compound(ncid, typeid, BILLY, NC_COMPOUND_OFFSET(struct billy_bob, billy), NC_INT)) ERR;
|
||||
if (nc_insert_compound(ncid, typeid, BOB, NC_COMPOUND_OFFSET(struct billy_bob, bob), NC_INT)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME1, typeid, 0, NULL, &varid)) ERR;
|
||||
if (nc_def_var_endian(ncid, varid, NC_ENDIAN_BIG)) ERR;
|
||||
if (nc_def_var_endian(ncid, varid, NC_ENDIAN_BIG) != NC_EINVAL) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
|
@ -174,7 +174,6 @@ main(int argc, char **argv)
|
||||
int data_in;
|
||||
|
||||
/* Create the test file with two scalar vars. */
|
||||
nc_set_log_level(4);
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_var(ncid, CLAIR, NC_INT, 0, NULL, &varid1)) ERR;
|
||||
if (nc_def_var_endian(ncid, varid1, NC_ENDIAN_BIG)) ERR;
|
||||
@ -196,5 +195,35 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing scalar big endian vars...");
|
||||
{
|
||||
int ncid, enumid;
|
||||
int bigid, littleid;
|
||||
int endian_in;
|
||||
/* Note: if no zero valued enum, then causes ncdump error */
|
||||
int econst0 = 0;
|
||||
int econst1 = 1;
|
||||
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
|
||||
|
||||
if (nc_def_enum(ncid, NC_INT, "enum_t", &enumid)) ERR;
|
||||
if (nc_insert_enum(ncid, enumid, "econst0", &econst0)) ERR;
|
||||
if (nc_insert_enum(ncid, enumid, "econst1", &econst1)) ERR;
|
||||
|
||||
if (nc_def_var(ncid, "little", enumid, 0, NULL, &littleid)) ERR;
|
||||
if (nc_def_var(ncid, "big", enumid, 0, NULL, &bigid)) ERR;
|
||||
|
||||
if (nc_def_var_endian(ncid, littleid, NC_ENDIAN_LITTLE) != NC_EINVAL) ERR;
|
||||
if (nc_def_var_endian(ncid, bigid, NC_ENDIAN_BIG) != NC_EINVAL) ERR;
|
||||
|
||||
/* Note that it is important to set endian ness before testing it */
|
||||
if (nc_inq_var_endian(ncid, littleid, &endian_in)) ERR;
|
||||
if (endian_in) ERR;
|
||||
if (nc_inq_var_endian(ncid, bigid, &endian_in)) ERR;
|
||||
if (endian_in) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user