Commit 73c6dba4 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

netCDF4: added support for attribute type NC_BYTE, NC_UBYTE

parent 05edd21a
2016-06-17 Uwe Schulzweida
* netCDF4: added support for attribute type NC_USHORT and NC_UINT
* netCDF4: added support for attribute type NC_BYTE, NC_UBYTE, NC_USHORT and NC_UINT
2016-06-10 Uwe Schulzweida
......
......@@ -190,15 +190,18 @@ void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID)
len = (size_t)attlen;
cdf_put_att_text(fileID, ncvarID, attname, len, atttxt);
}
else if ( atttype == DATATYPE_INT16 || atttype == DATATYPE_INT32 ||
atttype == DATATYPE_UINT16 || atttype == DATATYPE_UINT32 )
else if ( atttype == DATATYPE_INT8 || atttype == DATATYPE_UINT8 ||
atttype == DATATYPE_INT16 || atttype == DATATYPE_UINT16 ||
atttype == DATATYPE_INT32 || atttype == DATATYPE_UINT32 )
{
size_t attSize = (size_t)attlen*sizeof(int);
int *attint = (int *)resizeBuf(&attBuf, &attBufSize, attSize);
vlistInqAttInt(vlistID, varID, attname, attlen, &attint[0]);
len = (size_t)attlen;
nc_type xtype = (atttype == DATATYPE_INT16) ? NC_SHORT :
nc_type xtype = (atttype == DATATYPE_INT8) ? NC_BYTE :
(atttype == DATATYPE_INT16) ? NC_SHORT :
#if defined (HAVE_NETCDF4)
(atttype == DATATYPE_UINT8) ? NC_UBYTE :
(atttype == DATATYPE_UINT16) ? NC_USHORT :
(atttype == DATATYPE_UINT32) ? NC_UINT :
#endif
......
......@@ -489,6 +489,20 @@ bool xtypeIsFloat(nc_type xtype)
return isFloat;
}
static
bool xtypeIsInt(nc_type xtype)
{
bool isInt = xtype == NC_SHORT || xtype == NC_INT
|| xtype == NC_BYTE
#if defined (HAVE_NETCDF4)
|| xtype == NC_USHORT || xtype == NC_UINT
|| xtype == NC_UBYTE
#endif
;
return isInt;
}
static
int cdfInqDatatype(int xtype, bool lunsigned)
{
......@@ -5999,23 +6013,21 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
cdf_inq_attlen(ncid, ncvarid, attname, &attlen);
cdf_inq_atttype(ncid, ncvarid, attname, &attrtype);
if ( attrtype == NC_SHORT || attrtype == NC_INT
#if defined (HAVE_NETCDF4)
|| attrtype == NC_USHORT || attrtype == NC_UINT
#endif
)
if ( xtypeIsInt(attrtype) )
{
int attint[attlen];
cdfGetAttInt(ncid, ncvarid, attname, (int)attlen, attint);
int datatype = (attrtype == NC_SHORT) ? DATATYPE_INT16 :
(attrtype == NC_BYTE) ? DATATYPE_INT8 :
#if defined (HAVE_NETCDF4)
(attrtype == NC_UBYTE) ? DATATYPE_UINT8 :
(attrtype == NC_USHORT) ? DATATYPE_UINT16 :
(attrtype == NC_UINT) ? DATATYPE_UINT32 :
#endif
DATATYPE_INT32;
vlistDefAttInt(vlistID, varID, attname, datatype, (int)attlen, attint);
}
else if ( attrtype == NC_FLOAT || attrtype == NC_DOUBLE )
else if ( xtypeIsFloat(attrtype) )
{
double attflt[attlen];
cdfGetAttDouble(ncid, ncvarid, attname, (int)attlen, attflt);
......
......@@ -336,7 +336,7 @@ The function @func{vlistDefAttInt} defines an integer attribute.
*/
int vlistDefAttInt(int vlistID, int varID, const char *name, int type, int len, const int *ip)
{
return vlist_def_att(DATATYPE_INT, type, vlistID, varID, name, (size_t)len, (size_t)len * sizeof (int), ip);
return vlist_def_att(DATATYPE_INT, type, vlistID, varID, name, (size_t)len, (size_t)len * sizeof(int), ip);
}
/*
......@@ -360,7 +360,7 @@ The function @func{vlistDefAttFlt} defines a floating point attribute.
*/
int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
{
return vlist_def_att(DATATYPE_FLT, type, vlistID, varID, name, (size_t)len, (size_t)len * sizeof (double), dp);
return vlist_def_att(DATATYPE_FLT, type, vlistID, varID, name, (size_t)len, (size_t)len * sizeof(double), dp);
}
/*
......@@ -405,7 +405,7 @@ The function @func{vlistInqAttInt} gets the values(s) of an integer attribute.
*/
int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip)
{
return vlist_inq_att(DATATYPE_INT, vlistID, varID, name, (size_t)mlen * sizeof (int), ip);
return vlist_inq_att(DATATYPE_INT, vlistID, varID, name, (size_t)mlen * sizeof(int), ip);
}
/*
......@@ -427,7 +427,7 @@ The function @func{vlistInqAttFlt} gets the values(s) of a floating point attrib
*/
int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, double *dp)
{
return vlist_inq_att(DATATYPE_FLT, vlistID, varID, name, (size_t)mlen * sizeof (double), dp);
return vlist_inq_att(DATATYPE_FLT, vlistID, varID, name, (size_t)mlen * sizeof(double), dp);
}
/*
......@@ -449,7 +449,7 @@ The function @func{vlistInqAttTxt} gets the values(s) of a text attribute.
*/
int vlistInqAttTxt(int vlistID, int varID, const char *name, int mlen, char *tp)
{
return vlist_inq_att(DATATYPE_TXT, vlistID, varID, name, (size_t)mlen * sizeof (char), tp);
return vlist_inq_att(DATATYPE_TXT, vlistID, varID, name, (size_t)mlen * sizeof(char), tp);
}
enum {
......
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