Commit 05d8fe7c authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

add datatype UINT8

parent 23d916be
......@@ -2,6 +2,7 @@
* using GRIB library version 1.2.0
* add support for netCDF4 classic with deflate option
* add datatype UINT8
* streamClose: use taxisDestroy to release memory
* cdfInqContents: skip time variable with type = NC_CHAR
* ptaxisCopy: don't overwrite item 'self' (bug fix)
......
......@@ -489,6 +489,7 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
else if ( prec > 0 && prec <= 32 ) sprintf(pstr, "P%d", prec);
else if ( prec == DATATYPE_FLT32 ) strcpy(pstr, "F32");
else if ( prec == DATATYPE_FLT64 ) strcpy(pstr, "F64");
else if ( prec == DATATYPE_UINT8 ) strcpy(pstr, "U8");
else if ( prec == DATATYPE_INT8 ) strcpy(pstr, "I8");
else if ( prec == DATATYPE_INT16 ) strcpy(pstr, "I16");
else if ( prec == DATATYPE_INT32 ) strcpy(pstr, "I32");
......@@ -668,30 +669,86 @@ static void printShortinfo(int streamID, int vlistID, int vardis)
static void setDefaultDataType(char *datatypestr)
{
static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1};
int datatype = -1;
int nbits = -1;
enum {D_UINT, D_INT, D_FLT};
int dtype = -1;
if ( *datatypestr == 'i' || *datatypestr == 'I' )
{
dtype = D_INT;
datatypestr++;
}
else if ( *datatypestr == 'u' || *datatypestr == 'U' )
{
dtype = D_UINT;
datatypestr++;
}
else if ( *datatypestr == 'f' || *datatypestr == 'F' )
{
dtype = D_FLT;
datatypestr++;
}
if ( isdigit((int) *datatypestr) )
{
datatype = atoi(datatypestr);
if ( datatype < 10 )
nbits = atoi(datatypestr);
if ( nbits < 10 )
datatypestr += 1;
else
datatypestr += 2;
if ( datatype > 0 && datatype < 32 ) DefaultDataType = datatype;
else if ( datatype == 32 )
if ( dtype == -1 )
{
if ( DefaultFileType == FILETYPE_GRB )
DefaultDataType = DATATYPE_PACK32;
if ( nbits > 0 && nbits < 32 ) DefaultDataType = nbits;
else if ( nbits == 32 )
{
if ( DefaultFileType == FILETYPE_GRB )
DefaultDataType = DATATYPE_PACK32;
else
DefaultDataType = DATATYPE_FLT32;
}
else if ( nbits == 64 ) DefaultDataType = DATATYPE_FLT64;
else
DefaultDataType = DATATYPE_FLT32;
{
fprintf(stderr, "Unsupported number of bits %d!\n", nbits);
fprintf(stderr, "Use 32/64 for filetype nc, srv, ext, ieg and 1-32 for grb.\n");
exit(EXIT_FAILURE);
}
}
else if ( datatype == 64 ) DefaultDataType = DATATYPE_FLT64;
else
{
fprintf(stderr, "Unsupported datatype %d!\n", datatype);
fprintf(stderr, "Use 32/64 for filetype nc, srv, ext, ieg and 1-32 for grb.\n");
exit(EXIT_FAILURE);
if ( dtype == D_INT )
{
if ( nbits == 8 ) DefaultDataType = DATATYPE_INT8;
else if ( nbits == 16 ) DefaultDataType = DATATYPE_INT16;
else if ( nbits == 32 ) DefaultDataType = DATATYPE_INT32;
else
{
fprintf(stderr, "Unsupported number of bits = %d for datatype INT!\n", nbits);
exit(EXIT_FAILURE);
}
}
/*
else if ( dtype == D_UINT )
{
if ( nbits == 8 ) DefaultDataType = DATATYPE_UINT8;
else
{
fprintf(stderr, "Unsupported number of bits = %d for datatype UINT!\n", nbits);
exit(EXIT_FAILURE);
}
}
*/
else if ( dtype == D_FLT )
{
if ( nbits == 32 ) DefaultDataType = DATATYPE_FLT32;
else if ( nbits == 64 ) DefaultDataType = DATATYPE_FLT64;
else
{
fprintf(stderr, "Unsupported number of bits = %d for datatype FLT!\n", nbits);
exit(EXIT_FAILURE);
}
}
}
}
......
......@@ -84,6 +84,7 @@ extern "C" {
#define DATATYPE_INT8 208
#define DATATYPE_INT16 216
#define DATATYPE_INT32 232
#define DATATYPE_UINT8 308
/* internal data types */
......
......@@ -288,11 +288,12 @@ int cdfInqDatatype(int xtype)
{
int datatype;
if ( xtype == NC_BYTE ) datatype = DATATYPE_INT8;
else if ( xtype == NC_SHORT ) datatype = DATATYPE_INT16;
else if ( xtype == NC_INT ) datatype = DATATYPE_INT32;
else if ( xtype == NC_FLOAT ) datatype = DATATYPE_FLT32;
else datatype = DATATYPE_FLT64;
if ( xtype == NC_BYTE ) datatype = DATATYPE_INT8;
/* else if ( xtype == NC_CHAR ) datatype = DATATYPE_UINT8; */
else if ( xtype == NC_SHORT ) datatype = DATATYPE_INT16;
else if ( xtype == NC_INT ) datatype = DATATYPE_INT32;
else if ( xtype == NC_DOUBLE ) datatype = DATATYPE_FLT64;
else datatype = DATATYPE_FLT32;
return (datatype);
}
......@@ -304,6 +305,7 @@ int cdfDefDatatype(int datatype)
int xtype;
if ( datatype == DATATYPE_INT8 ) xtype = NC_BYTE;
/* else if ( datatype == DATATYPE_UINT8 ) xtype = NC_CHAR; */
else if ( datatype == DATATYPE_INT16 ) xtype = NC_SHORT;
else if ( datatype == DATATYPE_INT32 ) xtype = NC_INT;
else if ( datatype == DATATYPE_FLT64 ) xtype = NC_DOUBLE;
......@@ -2673,7 +2675,8 @@ void cdfWriteVarDP(int streamID, int varID, double *data, int nmiss)
}
}
if ( dtype == DATATYPE_INT8 || dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 )
if ( dtype == DATATYPE_UINT8 || dtype == DATATYPE_INT8 ||
dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 )
{
for ( i = 0; i < nvals; i++ ) data[i] = NINT(data[i]);
}
......@@ -3001,7 +3004,8 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, double *data, int n
}
}
if ( dtype == DATATYPE_INT8 || dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 )
if ( dtype == DATATYPE_UINT8 || dtype == DATATYPE_INT8 ||
dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 )
{
for ( i = 0; i < nvals; i++ ) data[i] = NINT(data[i]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment