Commit e220cdee authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cdfReadVarSlice: fix bug with DATATYPE_UINT8

parent 3c8d9f83
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
* Version 1.7.2 released * Version 1.7.2 released
2016-04-27 Uwe Schulzweida
* cdfReadVarSlice: fix bug with DATATYPE_UINT8
2016-04-04 Uwe Schulzweida 2016-04-04 Uwe Schulzweida
* GRIB1/GRIB_API (accumulation) encoding error [Bug #6638] * GRIB1/GRIB_API (accumulation) encoding error [Bug #6638]
......
...@@ -578,15 +578,13 @@ void cdf_read_var(stream_t *streamptr, int varID, int memtype, void *data, int * ...@@ -578,15 +578,13 @@ void cdf_read_var(stream_t *streamptr, int varID, int memtype, void *data, int *
static static
void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data, int *nmiss) void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data, int *nmiss)
{ {
size_t start[4];
size_t count[4];
if ( CDI_Debug ) if ( CDI_Debug )
Message("streamID = %d varID = %d levelID = %d", streamptr->self, varID, levelID); Message("streamID = %d varID = %d levelID = %d", streamptr->self, varID, levelID);
int vlistID = streamptr->vlistID; int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID; int fileID = streamptr->fileID;
size_t start[4], count[4];
bool swapxy; bool swapxy;
cdfGetSliceSlapDescription(streamptr, varID, levelID, &swapxy, &start, &count); cdfGetSliceSlapDescription(streamptr, varID, levelID, &swapxy, &start, &count);
...@@ -604,19 +602,20 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data ...@@ -604,19 +602,20 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
data[i] = (double) data_fp[i]; data[i] = (double) data_fp[i];
Free(data_fp); Free(data_fp);
} }
else if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_UINT8 )
{
nc_type xtype;
cdf_inq_vartype(fileID, ncvarid, &xtype);
if ( xtype == NC_BYTE )
{
for ( size_t i = 0; i < gridsize; i++ )
if ( data[i] < 0 ) data[i] += 256;
}
}
else else
{ {
cdf_get_vara_double(fileID, ncvarid, start, count, data); cdf_get_vara_double(fileID, ncvarid, start, count, data);
if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_UINT8 )
{
nc_type xtype;
cdf_inq_vartype(fileID, ncvarid, &xtype);
if ( xtype == NC_BYTE )
{
for ( size_t i = 0; i < gridsize; i++ )
if ( data[i] < 0 ) data[i] += 256;
}
}
} }
if ( swapxy ) transpose2dArrayDP(ysize, xsize, data); if ( swapxy ) transpose2dArrayDP(ysize, xsize, data);
...@@ -636,15 +635,13 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data ...@@ -636,15 +635,13 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
static static
void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data, int *nmiss) void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data, int *nmiss)
{ {
size_t start[4];
size_t count[4];
if ( CDI_Debug ) if ( CDI_Debug )
Message("streamID = %d varID = %d levelID = %d", streamptr->self, varID, levelID); Message("streamID = %d varID = %d levelID = %d", streamptr->self, varID, levelID);
int vlistID = streamptr->vlistID; int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID; int fileID = streamptr->fileID;
size_t start[4], count[4];
bool swapxy; bool swapxy;
cdfGetSliceSlapDescription(streamptr, varID, levelID, &swapxy, &start, &count); cdfGetSliceSlapDescription(streamptr, varID, levelID, &swapxy, &start, &count);
...@@ -662,19 +659,20 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data, ...@@ -662,19 +659,20 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
data[i] = (float) data_dp[i]; data[i] = (float) data_dp[i];
Free(data_dp); Free(data_dp);
} }
else if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_UINT8 )
{
nc_type xtype;
cdf_inq_vartype(fileID, ncvarid, &xtype);
if ( xtype == NC_BYTE )
{
for ( size_t i = 0; i < gridsize; i++ )
if ( data[i] < 0 ) data[i] += 256;
}
}
else else
{ {
cdf_get_vara_float(fileID, ncvarid, start, count, data); cdf_get_vara_float(fileID, ncvarid, start, count, data);
if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_UINT8 )
{
nc_type xtype;
cdf_inq_vartype(fileID, ncvarid, &xtype);
if ( xtype == NC_BYTE )
{
for ( size_t i = 0; i < gridsize; i++ )
if ( data[i] < 0 ) data[i] += 256;
}
}
} }
if ( swapxy ) transpose2dArraySP(ysize, xsize, data); if ( swapxy ) transpose2dArraySP(ysize, xsize, data);
......
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