Commit 9b1f4239 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Changed data type of gridsize from int to size_t.

parent fc8de8b5
......@@ -921,6 +921,7 @@ int main(int argc, char *argv[])
printShortinfo(streamID1, vlistID1, Vardis);
}
int idum;
int tsID = 0;
if ( Info || fname2 )
while ( (nrecs = streamInqTimestep(streamID1, tsID)) > 0 )
......@@ -941,7 +942,8 @@ int main(int argc, char *argv[])
for ( recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, data, &nmiss);
streamReadRecord(streamID1, data, &idum);
nmiss = idum;
number = vlistInqVarNumber(vlistID1, varID);
gridID = vlistInqVarGrid(vlistID1, varID);
......@@ -969,7 +971,7 @@ int main(int argc, char *argv[])
if ( Move )
streamCopyRecord(streamID2, streamID1);
else
streamWriteRecord(streamID2, data, nmiss);
streamWriteRecord(streamID2, data, idum);
}
}
}
......@@ -1000,7 +1002,8 @@ int main(int argc, char *argv[])
for ( levelID = 0; levelID < levelsize; levelID++ )
{
double level = zaxisInqLevels(zaxisID, NULL) ? zaxisInqLevel(zaxisID, levelID) : levelID+1;
streamReadVarSlice(streamID1, varID, levelID, data, &nmiss);
streamReadVarSlice(streamID1, varID, levelID, data, &idum);
nmiss = idum;
if ( Info )
printInfo(vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
......
......@@ -72,8 +72,8 @@ void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], s
} while(0)
if ( tsteptype != TSTEP_CONSTANT ) addDimension((size_t)tsID, 1);
if ( zid != CDI_UNDEFID ) addDimension(0, (size_t)zaxisInqSize(zaxisID));
if ( yid != CDI_UNDEFID ) addDimension(0, (size_t)gridInqYsize(gridID));
if ( xid != CDI_UNDEFID ) addDimension(0, (size_t)gridInqXsize(gridID));
if ( yid != CDI_UNDEFID ) addDimension(0, gridInqYsize(gridID));
if ( xid != CDI_UNDEFID ) addDimension(0, gridInqXsize(gridID));
#undef addDimension
assert(ndims <= (int)(sizeof(*start)/sizeof(**start)));
......@@ -506,7 +506,7 @@ void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
cdf_get_vara_double(fileID, ncvarid, start, count, data);
size_t size = (size_t)gridInqSize(gridID)*(size_t)zaxisInqSize(zaxisID);
size_t size = gridInqSize(gridID)*(size_t)zaxisInqSize(zaxisID);
double missval = vlistInqVarMissval(vlistID, varID);
const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
double validRange[2];
......@@ -538,7 +538,7 @@ void cdfReadVarSP(stream_t *streamptr, int varID, float *data, int *nmiss)
cdf_get_vara_float(fileID, ncvarid, start, count, data);
size_t size = (size_t)gridInqSize(gridID) * (size_t)zaxisInqSize(zaxisID);
size_t size = gridInqSize(gridID) * (size_t)zaxisInqSize(zaxisID);
double missval = vlistInqVarMissval(vlistID, varID);
const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
double validRange[2];
......@@ -575,9 +575,9 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
int ncvarid = streamptr->vars[varID].ncvarid;
int gridId = vlistInqVarGrid(vlistID, varID);
size_t gridsize = (size_t)gridInqSize(gridId);
size_t xsize = (size_t)gridInqXsize(gridId);
size_t ysize = (size_t)gridInqYsize(gridId);
size_t gridsize = gridInqSize(gridId);
size_t xsize = gridInqXsize(gridId);
size_t ysize = gridInqYsize(gridId);
if ( vlistInqVarDatatype(vlistID, varID) == CDI_DATATYPE_FLT32 )
{
......@@ -632,9 +632,9 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
int ncvarid = streamptr->vars[varID].ncvarid;
int gridId = vlistInqVarGrid(vlistID, varID);
size_t gridsize = (size_t)gridInqSize(gridId);
size_t xsize = (size_t)gridInqXsize(gridId);
size_t ysize = (size_t)gridInqYsize(gridId);
size_t gridsize = gridInqSize(gridId);
size_t xsize = gridInqXsize(gridId);
size_t ysize = gridInqYsize(gridId);
if ( vlistInqVarDatatype(vlistID, varID) == CDI_DATATYPE_FLT64 )
{
......
......@@ -349,7 +349,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
vlistInqVarDimorder(vlistID, varID, &dimorder);
size_t gridsize = (size_t)(gridInqSize(gridID));
size_t gridsize = gridInqSize(gridID);
bool lchunk = (gridsize >= 16);
int gridtype = gridInqType(gridID);
int gridindex = nc_grid_index(streamptr, gridID);
......@@ -1066,7 +1066,7 @@ void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data
if ( nmiss > 0 ) cdfDefVarMissval(streamptr, varID, dtype, 1);
size_t nvals = (size_t)(gridInqSize(gridID)) * (size_t)(zaxisInqSize(zaxisID));
size_t nvals = gridInqSize(gridID) * (size_t)(zaxisInqSize(zaxisID));
cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals, xsize, ysize, swapxy, start, count, memtype, data, nmiss);
}
......@@ -1167,7 +1167,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
if ( nmiss > 0 ) cdfDefVarMissval(streamptr, varID, dtype, 1);
size_t nvals = (size_t)(gridInqSize(gridID)) * (size_t)(zaxisInqSize(zaxisID));
size_t nvals = gridInqSize(gridID) * (size_t)(zaxisInqSize(zaxisID));
cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals,
xsize, ysize, swapxy, start, count, memtype, data, nmiss);
......@@ -1257,7 +1257,7 @@ void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
if ( nmiss > 0 ) cdfDefVarMissval(streamptr, varID, dtype, 1);
size_t nvals = (size_t)(gridInqSize(gridID));
size_t nvals = gridInqSize(gridID);
cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals, xsize, ysize, swapxy, start, count, memtype, data, nmiss);
}
......
......@@ -384,7 +384,7 @@ int streamInqCurTimestepID(int streamID);
const char *streamFilename(int streamID);
const char *streamFilesuffix(int filetype);
off_t streamNvals(int streamID);
size_t streamNvals(int streamID);
int streamInqNvars(int streamID);
......
......@@ -241,7 +241,7 @@ typedef struct {
int fileID;
int filemode;
int nrecs; /* number of records */
off_t numvals;
size_t numvals;
char *filename;
Record *record;
svarinfo_t *vars;
......
#ifndef EXSE_H
#define EXSE_H
#include <limits.h>
enum {
EXSE_SINGLE_PRECISION = 4,
EXSE_DOUBLE_PRECISION = 8,
};
static inline
void exse_check_gridsize(const char *format, size_t gridsize)
{
if ( gridsize > INT_MAX ) Error("%s format grid size (%zu) limit exceeded (%zu)!", format, gridsize, INT_MAX);
}
#endif
......@@ -152,23 +152,19 @@ void grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
if (scanModeIN != cdiGribDataScanningMode.value)
{
int gridID;
int varID, levelID;
int vlistID;
//int zip;
int gridsize, nmiss = 0;
int nmiss = 0;
vlistID = streamptr1->vlistID;
varID = streamptr1->tsteps[tsID].records[recID].varID;
levelID = streamptr1->tsteps[tsID].records[recID].levelID;
int vlistID = streamptr1->vlistID;
int varID = streamptr1->tsteps[tsID].records[recID].varID;
int levelID = streamptr1->tsteps[tsID].records[recID].levelID;
//gribbuffer = (unsigned char *) streamptr->record->buffer;
// allocate above ..
gridID = vlistInqVarGrid(vlistID, varID);
gridsize = gridInqSize(gridID);
int gridID = vlistInqVarGrid(vlistID, varID);
gridsize = vlistGridsizeMax(vlistID);
size_t gridsize = vlistGridsizeMax(vlistID);
if ( vlistNumber(vlistID) != CDI_REAL ) gridsize *= 2;
double * data = (double *) malloc(gridsize*sizeof(double));
double *data = (double *) malloc(gridsize*sizeof(double));
//int missval = vlistInqVarMissval(vlistID, varID);
//streamptr->numvals += gridsize;
......@@ -241,7 +237,7 @@ void grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
if ( CDI_Debug )
Message("gridID = %d zaxisID = %d", gridID, zaxisID);
size_t datasize = (size_t)gridInqSize(gridID);
size_t datasize = gridInqSize(gridID);
#ifdef HAVE_LIBCGRIBEX
if ( filetype == CDI_FILETYPE_GRB )
......@@ -293,12 +289,12 @@ void grb_write_var(stream_t *streamptr, int varID, int memtype, const void *data
{
int vlistID = streamptr->vlistID,
gridID = vlistInqVarGrid(vlistID, varID),
gridsize = gridInqSize(gridID),
zaxisID = vlistInqVarZaxis(vlistID, varID),
nlevs = zaxisInqSize(zaxisID);
size_t gridsize = gridInqSize(gridID),
double missval = vlistInqVarMissval(vlistID, varID);
size_t chunkLen = (size_t)gridsize;
size_t chunkLen = gridsize;
if ( memtype == MEMTYPE_FLOAT )
for ( int levelID = 0; levelID < nlevs; levelID++ )
{
......
......@@ -1438,7 +1438,7 @@ void streamWriteContents(int streamID, char *cname)
#endif
// This function is used in CDO!
off_t streamNvals(int streamID)
size_t streamNvals(int streamID)
{
stream_t *streamptr = stream_to_pointer(streamID);
return streamptr->numvals;
......
......@@ -189,7 +189,7 @@ cdfDefSPorFC(stream_t *streamptr, int gridID, int gridindex,
{
ncgrid_t *ncgrid = streamptr->ncgrid;
size_t dimlen = (size_t)(gridInqSize(gridID))/2;
size_t dimlen = gridInqSize(gridID)/2;
int iz;
int dimID;
......
......@@ -2,10 +2,6 @@
# include "config.h"
#endif
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "dmemory.h"
#include "error.h"
......@@ -112,14 +108,14 @@ void extReadRecord(stream_t *streamptr, double *data, int *nmiss)
double missval = vlistInqVarMissval(vlistID, varID);
int gridID = vlistInqVarGrid(vlistID, varID);
int size = gridInqSize(gridID);
size_t size = gridInqSize(gridID);
streamptr->numvals += size;
*nmiss = 0;
if ( vlistInqVarNumber(vlistID, varID) == CDI_REAL )
{
for ( int i = 0; i < size; i++ )
for ( size_t i = 0; i < size; i++ )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -128,7 +124,7 @@ void extReadRecord(stream_t *streamptr, double *data, int *nmiss)
}
else
{
for ( int i = 0; i < 2*size; i+=2 )
for ( size_t i = 0; i < 2*size; i+=2 )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -154,7 +150,8 @@ void extDefRecord(stream_t *streamptr)
header[1] = pnum;
header[2] = streamptr->record->level;
int gridID = streamptr->record->gridID;
header[3] = gridInqSize(gridID);
exse_check_gridsize("EXTRA", gridInqSize(gridID));
header[3] = (int) gridInqSize(gridID);
extrec_t *extp = (extrec_t*) streamptr->record->exsep;
extDefDatatype(streamptr->record->prec, &extp->prec, &extp->number);
......@@ -172,7 +169,7 @@ void extWriteRecord(stream_t *streamptr, const double *data)
}
static
void extAddRecord(stream_t *streamptr, int param, int level, int xysize,
void extAddRecord(stream_t *streamptr, int param, int level, size_t xysize,
size_t recsize, off_t position, int prec, int number)
{
int vlistID = streamptr->vlistID;
......@@ -650,7 +647,7 @@ void extReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
int fileID = streamptr->fileID;
/* NOTE: tiles are not supported here! */
double missval = vlistInqVarMissval(vlistID, varID);
int gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
int tsid = streamptr->curTsID;
off_t currentfilepos = fileGetPos(fileID);
......@@ -669,7 +666,7 @@ void extReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
*nmiss = 0;
if ( vlistInqVarNumber(vlistID, varID) == CDI_REAL )
{
for ( int i = 0; i < gridsize; i++ )
for ( size_t i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -678,7 +675,7 @@ void extReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
}
else
{
for ( int i = 0; i < 2*gridsize; i+=2 )
for ( size_t i = 0; i < 2*gridsize; i+=2 )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -693,7 +690,7 @@ void extReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID);
int vlistID = streamptr->vlistID;
size_t gridsize = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t nlevs = (size_t) streamptr->vars[varID].recordTable[0].nlevs;
for ( size_t levID = 0; levID < nlevs; levID++)
......@@ -716,7 +713,9 @@ void extWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
header[0] = streamptr->tsteps[tsID].taxis.vdate;
header[1] = pnum;
header[2] = (int)(zaxisInqLevel(vlistInqVarZaxis(vlistID, varID), levID));
header[3] = gridInqSize(vlistInqVarGrid(vlistID, varID));
int gridID = vlistInqVarGrid(vlistID, varID);
exse_check_gridsize("EXTRA", gridInqSize(gridID));
header[3] = (int) gridInqSize(gridID);
extrec_t *extp = (extrec_t*) streamptr->record->exsep;
extDefDatatype(vlistInqVarDatatype(vlistID, varID), &extp->prec, &extp->number);
......@@ -732,7 +731,7 @@ void extWriteVarDP(stream_t *streamptr, int varID, const double *data)
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID);
int vlistID = streamptr->vlistID;
size_t gridsize = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t nlevs = (size_t) zaxisInqSize(vlistInqVarZaxis(vlistID, varID));
for ( size_t levID = 0; levID < nlevs; levID++ )
......
......@@ -2,13 +2,7 @@
# include "config.h"
#endif
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include "dmemory.h"
......@@ -108,12 +102,12 @@ void iegReadRecord(stream_t *streamptr, double *data, int *nmiss)
double missval = vlistInqVarMissval(vlistID, varID);
int gridID = vlistInqVarGrid(vlistID, varID);
int size = gridInqSize(gridID);
size_t size = gridInqSize(gridID);
streamptr->numvals += size;
*nmiss = 0;
for ( int i = 0; i < size; i++ )
for ( size_t i = 0; i < size; i++ )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -249,8 +243,10 @@ void iegDefGrid(int *gdb, int gridID)
int projtype = CDI_UNDEFID;
if ( gridtype == GRID_PROJECTION && gridInqProjType(gridID) == CDI_PROJ_RLL ) projtype = CDI_PROJ_RLL;
int xsize = gridInqXsize(gridID);
int ysize = gridInqYsize(gridID);
size_t xsize = gridInqXsize(gridID);
size_t ysize = gridInqYsize(gridID);
exse_check_gridsize("IEG", xsize*ysize);
if ( gridtype == GRID_GENERIC )
{
......@@ -313,8 +309,8 @@ void iegDefGrid(int *gdb, int gridID)
IEG_G_ResFac(gdb) = iresfac;
IEG_G_NumLon(gdb) = xsize;
IEG_G_NumLat(gdb) = ysize;
IEG_G_NumLon(gdb) = (int)xsize;
IEG_G_NumLat(gdb) = (int)ysize;
IEG_G_FirstLat(gdb) = (int)lround(yfirst*resfac);
IEG_G_LastLat(gdb) = (int)lround(ylast*resfac);
IEG_G_FirstLon(gdb) = (int)lround(xfirst*resfac);
......@@ -324,7 +320,7 @@ void iegDefGrid(int *gdb, int gridID)
IEG_G_LonIncr(gdb) = 0;
if ( gridtype == GRID_GAUSSIAN )
IEG_G_LatIncr(gdb) = ysize/2;
IEG_G_LatIncr(gdb) = (int)ysize/2;
else
{
IEG_G_LatIncr(gdb) = (int)lround(yinc*resfac);
......@@ -535,10 +531,10 @@ void iegWriteRecord(stream_t *streamptr, const double *data)
iegrec_t *iegp = (iegrec_t*) record->exsep;
int fileID = streamptr->fileID;
int gridsize = gridInqSize(record->gridID);
size_t gridsize = gridInqSize(record->gridID);
double refval = data[0];
for ( int i = 1; i < gridsize; i++ )
for ( size_t i = 1; i < gridsize; i++ )
if ( data[i] < refval ) refval = data[i];
iegp->refval = refval;
......@@ -583,8 +579,8 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
grid_t *grid = (grid_t *)Malloc(sizeof (*grid));
grid_init(grid);
cdiGridTypeInit(grid, gridtype, IEG_G_NumLon(gdb)*IEG_G_NumLat(gdb));
int xsize = IEG_G_NumLon(gdb);
int ysize = IEG_G_NumLat(gdb);
size_t xsize = (size_t)IEG_G_NumLon(gdb);
size_t ysize = (size_t)IEG_G_NumLat(gdb);
grid->x.size = xsize;
grid->y.size = ysize;
grid->x.inc = 0;
......@@ -683,7 +679,7 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
#if 0
static
void iegCmpRecord(stream_t *streamptr, int tsID, int recID, off_t position, int param,
int level, int xsize, int ysize)
int level, size_t xsize, size_t ysize)
{
int varID = 0;
int levelID = 0;
......@@ -1176,7 +1172,7 @@ void iegReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
int fileID = streamptr->fileID;
/* NOTE: tiles are not supported here! */
double missval = vlistInqVarMissval(vlistID, varID);
int gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
int tsid = streamptr->curTsID;
off_t currentfilepos = fileGetPos(fileID);
......@@ -1191,7 +1187,7 @@ void iegReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
fileSetPos(fileID, currentfilepos, SEEK_SET);
*nmiss = 0;
for ( int i = 0; i < gridsize; i++ )
for ( size_t i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -1205,7 +1201,7 @@ void iegReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID);
int vlistID = streamptr->vlistID;
size_t gridsize = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t nlevs = (size_t) streamptr->vars[varID].recordTable[0].nlevs;
for ( size_t levID = 0; levID < nlevs; levID++)
......@@ -1241,10 +1237,10 @@ void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
iegp->dprec = iegDefDatatype(vlistInqVarDatatype(vlistID, varID));
int gridsize = gridInqSize(gridID);
size_t gridsize = gridInqSize(gridID);
double refval = data[0];
for ( int i = 1; i < gridsize; i++ )
for ( size_t i = 1; i < gridsize; i++ )
if ( data[i] < refval ) refval = data[i];
iegp->refval = refval;
......@@ -1259,7 +1255,7 @@ void iegWriteVarDP(stream_t *streamptr, int varID, const double *data)
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID);
int vlistID = streamptr->vlistID;
size_t gridsize = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t nlevs = (size_t) zaxisInqSize(vlistInqVarZaxis(vlistID, varID));
for ( size_t levID = 0; levID < nlevs; levID++ )
......
......@@ -130,7 +130,7 @@ void streamReadVarF(int streamID, int varID, float *data, int *nmiss)
{
// In case the file format does not support single precision reading,
// we fall back to double precision reading, converting the data on the fly.
size_t elementCount = (size_t) gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
elementCount *= (size_t) zaxisInqSize(vlistInqVarZaxis(streamInqVlist(streamID), varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
streamReadVar(streamID, varID, conversionBuffer, nmiss);
......@@ -235,7 +235,7 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
if ( cdiStreamReadVarSlice(streamID, varID, levelID, MEMTYPE_DOUBLE, data, nmiss) )
{
Warning("Unexpected error returned from cdiStreamReadVarSlice()!");
size_t elementCount = (size_t)gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
memset(data, 0, elementCount * sizeof(*data));
}
}
......@@ -264,7 +264,7 @@ void streamReadVarSliceF(int streamID, int varID, int levelID, float *data, int
{
// In case the file format does not support single precision reading,
// we fall back to double precision reading, converting the data on the fly.
size_t elementCount = (size_t) gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
streamReadVarSlice(streamID, varID, levelID, conversionBuffer, nmiss);
for ( size_t i = elementCount; i--; ) data[i] = (float) conversionBuffer[i];
......@@ -348,7 +348,7 @@ void streamReadRecordF(int streamID, float *data, int *nmiss)
int vrecID = streamptr->tsteps[tsID].curRecID;
int recID = streamptr->tsteps[tsID].recIDs[vrecID];
int varID = streamptr->tsteps[tsID].records[recID].varID;
size_t elementCount = (size_t) gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
streamReadRecord(streamID, conversionBuffer, nmiss);
for ( size_t i = elementCount; i--; ) data[i] = (float) conversionBuffer[i];
......
......@@ -2,11 +2,6 @@
# include "config.h"
#endif
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dmemory.h"
#include "error.h"
......@@ -107,12 +102,12 @@ void srvReadRecord(stream_t *streamptr, double *data, int *nmiss)
double missval = vlistInqVarMissval(vlistID, varID);
int gridID = vlistInqVarGrid(vlistID, varID);
int size = gridInqSize(gridID);
size_t size = gridInqSize(gridID);
streamptr->numvals += size;
*nmiss = 0;
for ( int i = 0; i < size; i++ )
for ( size_t i = 0; i < size; i++ )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -153,8 +148,10 @@ void srvDefRecord(stream_t *streamptr)
if ( gridInqSize(gridID) != xsize*ysize )
Error("Internal problem with gridsize!");
header[4] = xsize;
header[5] = ysize;
exse_check_gridsize("SERVICE", gridInqSize(gridID));
header[4] = (int)xsize;
header[5] = (int)ysize;
header[6] = 0;
header[7] = 0;
......@@ -175,7 +172,7 @@ void srvWriteRecord(stream_t *streamptr, const double *data)
}
static
void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ysize,
void srv_add_record(stream_t *streamptr, int param, int level, size_t xsize, size_t ysize,
size_t recsize, off_t position, int prec)
{
int vlistID = streamptr->vlistID;
......@@ -646,7 +643,7 @@ void srvReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
int fileID = streamptr->fileID;
/* NOTE: tiles are not supported here! */
double missval = vlistInqVarMissval(vlistID, varID);
int gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
int tsid = streamptr->curTsID;
off_t currentfilepos = fileGetPos(fileID);
......@@ -663,7 +660,7 @@ void srvReadVarSliceDP(stream_t *streamptr, int varID, int levID, double *data,
fileSetPos(fileID, currentfilepos, SEEK_SET);
*nmiss = 0;
for ( int i = 0; i < gridsize; i++ )
for ( size_t i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(data[i], missval) || DBL_IS_EQUAL(data[i], (float)missval) )
{
data[i] = missval;
......@@ -677,7 +674,7 @@ void srvReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID);
int vlistID = streamptr->vlistID;
size_t gridsize = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t nlevs = (size_t) streamptr->vars[varID].recordTable[0].nlevs;
for ( size_t levID = 0; levID < nlevs; levID++)
......@@ -714,6 +711,8 @@ void srvWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
if ( gridInqSize(gridID) != xsize*ysize )
Error("Internal problem with gridsize!");
exse_check_gridsize("SERVICE", gridInqSize(gridID));
header[4] = xsize;
header[5] = ysize;
header[6] = 0;
......@@ -735,7 +734,7 @@ void srvWriteVarDP(stream_t *streamptr, int varID, const double *data)
if ( CDI_Debug ) Message("streamID = %d varID = %d", streamptr->self, varID);
int vlistID = streamptr->vlistID;
size_t gridsize = (size_t) gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID, varID));
size_t nlevs = (size_t) zaxisInqSize(vlistInqVarZaxis(vlistID, varID));