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

Set constant variables to const.

parent a6dec296
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#include <sys/stat.h>
......@@ -11,40 +11,11 @@
#include "namespace.h"
#ifdef HAVE_LIBNETCDF
/*
#if ! defined (MIN_BUF_SIZE)
# define MIN_BUF_SIZE 131072L
#endif
static size_t ChunkSizeMin = MIN_BUF_SIZE;
*/
void cdf_create(const char *path, int cmode, int *ncidp)
{
int oldfill;
size_t initialsz = 0, chunksizehint = 0;
/*
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
struct stat filestat;
char basename[1024];
char *pend;
pend = strrchr(path, '/');
if ( pend == 0 )
strcpy(basename, "./");
else
{
memcpy(basename, path, pend-path);
basename[pend-path] = 0;
}
if ( stat(basename, &filestat) != 0 )
SysError(basename);
chunksizehint = (size_t) filestat.st_blksize * 4;
#endif
if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
*/
#if defined(__SX__) || defined(ES)
chunksizehint = 16777216; /* 16 MB */
#endif
......@@ -57,13 +28,11 @@ void cdf_create(const char *path, int cmode, int *ncidp)
int status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d mode = %d file = %s", *ncidp, cmode, path);
if ( CDF_Debug || status != NC_NOERR )
Message("chunksizehint %d", chunksizehint);
Message("ncid = %d mode = %d chunksizehint = %zu file = %s", *ncidp, cmode, chunksizehint, path);
if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
int oldfill;
status = nc_set_fill(*ncidp, NC_NOFILL, &oldfill);
if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
......@@ -74,8 +43,6 @@ int cdf_open(const char *path, int omode, int *ncidp)
{
int status = 0;
bool dapfile = false;
struct stat filestat;
size_t chunksizehint = 0;
#ifdef HAVE_LIBNC_DAP
if ( strncmp(path, "http:", 5) == 0 || strncmp(path, "https:", 6) == 0 ) dapfile = true;
......@@ -87,8 +54,10 @@ int cdf_open(const char *path, int omode, int *ncidp)
}
else
{
struct stat filestat;
if ( stat(path, &filestat) != 0 ) SysError(path);
size_t chunksizehint = 0;
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
chunksizehint = (size_t) filestat.st_blksize * 4;
if ( chunksizehint > (size_t) filestat.st_size ) chunksizehint = (size_t) filestat.st_size;
......@@ -140,11 +109,11 @@ void cdf_enddef(int ncid)
void cdf__enddef(const int ncid, const size_t hdr_pad)
{
const size_t v_align = 4UL; /* [B] Alignment of beginning of data section for fixed variables */
const size_t v_minfree = 0UL; /* [B] Pad at end of data section for fixed size variables */
const size_t r_align = 4UL; /* [B] Alignment of beginning of data section for record variables */
const size_t v_align = 4UL; // [B] Alignment of beginning of data section for fixed variables
const size_t v_minfree = 0UL; // [B] Pad at end of data section for fixed size variables
const size_t r_align = 4UL; // [B] Alignment of beginning of data section for record variables
/* nc_enddef(ncid) is equivalent to nc__enddef(ncid, 0, 4, 0, 4) */
// nc_enddef(ncid) is equivalent to nc__enddef(ncid, 0, 4, 0, 4)
int status = nc__enddef(ncid, hdr_pad, v_align, v_minfree, r_align);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
......@@ -490,8 +459,7 @@ void cdf_put_vara_float(int ncid, int varid, const size_t start[],
}
void cdf_get_vara_int(int ncid, int varid, const size_t start[],
const size_t count[], int *dp)
void cdf_get_vara_int(int ncid, int varid, const size_t start[], const size_t count[], int *dp)
{
int status = nc_get_vara_int(ncid, varid, start, count, dp);
......@@ -502,8 +470,7 @@ void cdf_get_vara_int(int ncid, int varid, const size_t start[],
}
void cdf_get_vara_double(int ncid, int varid, const size_t start[],
const size_t count[], double *dp)
void cdf_get_vara_double(int ncid, int varid, const size_t start[], const size_t count[], double *dp)
{
int status = nc_get_vara_double(ncid, varid, start, count, dp);
......@@ -514,8 +481,7 @@ void cdf_get_vara_double(int ncid, int varid, const size_t start[],
}
void cdf_get_vara_float(int ncid, int varid, const size_t start[],
const size_t count[], float *fp)
void cdf_get_vara_float(int ncid, int varid, const size_t start[], const size_t count[], float *fp)
{
int status = nc_get_vara_float(ncid, varid, start, count, fp);
......@@ -526,8 +492,7 @@ void cdf_get_vara_float(int ncid, int varid, const size_t start[],
}
void cdf_get_vara_text(int ncid, int varid, const size_t start[],
const size_t count[], char *tp)
void cdf_get_vara_text(int ncid, int varid, const size_t start[], const size_t count[], char *tp)
{
int status = nc_get_vara_text(ncid, varid, start, count, tp);
......@@ -659,8 +624,7 @@ void cdf_get_var_double(int ncid, int varid, double *dp)
}
void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out,
int varid_out)
void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
{
int status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
......@@ -671,8 +635,7 @@ void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out,
}
void cdf_put_att_text(int ncid, int varid, const char *name, size_t len,
const char *tp)
void cdf_put_att_text(int ncid, int varid, const char *name, size_t len, const char *tp)
{
int status = nc_put_att_text(ncid, varid, name, len, tp);
......@@ -683,8 +646,7 @@ void cdf_put_att_text(int ncid, int varid, const char *name, size_t len,
}
void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype,
size_t len, const int *ip)
void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype, size_t len, const int *ip)
{
int status = nc_put_att_int(ncid, varid, name, xtype, len, ip);
......@@ -695,8 +657,7 @@ void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype,
}
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype,
size_t len, const float *dp)
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype, size_t len, const float *dp)
{
int status = nc_put_att_float(ncid, varid, name, xtype, len, dp);
......@@ -707,8 +668,7 @@ void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype,
}
void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype,
size_t len, const double *dp)
void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype, size_t len, const double *dp)
{
int status = nc_put_att_double(ncid, varid, name, xtype, len, dp);
......@@ -729,6 +689,7 @@ void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#if defined (HAVE_NETCDF4)
......@@ -779,8 +740,7 @@ void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
}
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
size_t *lenp)
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
{
int status = nc_inq_att(ncid, varid, name, xtypep, lenp);
......
......@@ -337,7 +337,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
size_t iax = 0;
char axis[5];
int fileID = streamptr->fileID;
const int fileID = streamptr->fileID;
if ( CDI_Debug )
Message("streamID = %d, fileID = %d, varID = %d", streamptr->self, fileID, varID);
......@@ -345,12 +345,12 @@ int cdfDefVar(stream_t *streamptr, int varID)
if ( streamptr->vars[varID].ncvarid != CDI_UNDEFID )
return streamptr->vars[varID].ncvarid;
int vlistID = streamptr->vlistID;
int gridID = vlistInqVarGrid(vlistID, varID);
int zaxisID = vlistInqVarZaxis(vlistID, varID);
int timetype = vlistInqVarTimetype(vlistID, varID);
int code = vlistInqVarCode(vlistID, varID);
int param = vlistInqVarParam(vlistID, varID);
const int vlistID = streamptr->vlistID;
const int gridID = vlistInqVarGrid(vlistID, varID);
const int zaxisID = vlistInqVarZaxis(vlistID, varID);
const int timetype = vlistInqVarTimetype(vlistID, varID);
const int param = vlistInqVarParam(vlistID, varID);
int code = vlistInqVarCode(vlistID, varID);
int pnum, pcat, pdis;
cdiDecodeParam(param, &pnum, &pcat, &pdis);
......@@ -358,10 +358,10 @@ int cdfDefVar(stream_t *streamptr, int varID)
vlistInqVarDimorder(vlistID, varID, &dimorder);
size_t gridsize = gridInqSize(gridID);
const size_t gridsize = gridInqSize(gridID);
bool lchunk = (gridsize >= 16);
int gridtype = gridInqType(gridID);
int gridindex = nc_grid_index(streamptr, gridID);
const int gridtype = gridInqType(gridID);
const int gridindex = nc_grid_index(streamptr, gridID);
if ( gridtype != GRID_TRAJECTORY )
{
xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
......@@ -370,8 +370,8 @@ int cdfDefVar(stream_t *streamptr, int varID)
if ( yid != CDI_UNDEFID ) cdf_inq_dimlen(fileID, yid, &ysize);
}
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
int zid = streamptr->zaxisID[zaxisindex];
const int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
const int zid = streamptr->zaxisID[zaxisindex];
bool zaxis_is_scalar = false;
if ( zid == CDI_UNDEFID ) zaxis_is_scalar = zaxisInqScalar(zaxisID) > 0;
......@@ -383,7 +383,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
Error("Internal problem, dimension order missing!");
}
int tid = streamptr->basetime.ncdimid;
const int tid = streamptr->basetime.ncdimid;
if ( vlistHasTime(vlistID) && timetype != TIME_CONSTANT )
{
......@@ -440,7 +440,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
}
if ( CDI_Debug )
fprintf(stderr, "chunktype %d chunks %zu %zu %zu %zu\n", chunktype, chunks[0], chunks[1], chunks[2], chunks[3]);
fprintf(stderr, "lchunk %d chunktype %d chunks %zu %zu %zu %zu\n", lchunk, chunktype, chunks[0], chunks[1], chunks[2], chunks[3]);
char varname[CDI_MAX_NAME];
char name[CDI_MAX_NAME]; name[0] = 0;
......@@ -452,7 +452,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
vlistInqVarStdname(vlistID, varID, stdname);
vlistInqVarUnits(vlistID, varID, units);
int tableID = vlistInqVarTable(vlistID, varID);
const int tableID = vlistInqVarTable(vlistID, varID);
if ( !name[0] ) tableInqEntry(tableID, code, -1, name, longname, units);
if ( name[0] )
{
......@@ -509,8 +509,8 @@ int cdfDefVar(stream_t *streamptr, int varID)
/* if ( streamptr->ncmode == 2 ) cdf_redef(fileID); */
int dtype = vlistInqVarDatatype(vlistID, varID);
nc_type xtype = cdfDefDatatype(dtype, streamptr);
const int dtype = vlistInqVarDatatype(vlistID, varID);
const nc_type xtype = cdfDefDatatype(dtype, streamptr);
cdf_def_var(fileID, name, xtype, ndims, dims, &ncvarid);
......@@ -576,9 +576,8 @@ int cdfDefVar(stream_t *streamptr, int varID)
if ( gridtype != GRID_GENERIC && gridtype != GRID_LONLAT && gridtype != GRID_GAUSSIAN &&
gridtype != GRID_PROJECTION && gridtype != GRID_CURVILINEAR && gridtype != GRID_CHARXY )
{
size_t len = strlen(gridNamePtr(gridtype));
if ( len > 0 )
cdf_put_att_text(fileID, ncvarid, "CDI_grid_type", len, gridNamePtr(gridtype));
const size_t len = strlen(gridNamePtr(gridtype));
if ( len > 0 ) cdf_put_att_text(fileID, ncvarid, "CDI_grid_type", len, gridNamePtr(gridtype));
}
char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0;
......@@ -593,8 +592,8 @@ int cdfDefVar(stream_t *streamptr, int varID)
}
else if ( gridtype == GRID_LONLAT && xid == CDI_UNDEFID && yid == CDI_UNDEFID && gridsize == 1 )
{
int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
const int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
const int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
if ( ncyvarID != CDI_UNDEFID )
{
size_t len = strlen(coordinates);
......@@ -611,9 +610,9 @@ int cdfDefVar(stream_t *streamptr, int varID)
else if ( gridtype == GRID_UNSTRUCTURED || gridtype == GRID_CURVILINEAR )
{
char cellarea[CDI_MAX_NAME] = "area: ";
int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
int ncavarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_A];
const int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
const int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
const int ncavarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_A];
// CMOR order: coordinates = "lat lon"
if ( cdiCoordinatesLonLat )
{
......@@ -663,7 +662,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
}
else if ( gridtype == GRID_SPECTRAL || gridtype == GRID_FOURIER )
{
int gridTruncation = gridInqTrunc(gridID);
const int gridTruncation = gridInqTrunc(gridID);
axis[iax++] = '-';
axis[iax++] = '-';
cdf_put_att_text(fileID, ncvarid, "axis", iax, axis);
......@@ -673,14 +672,14 @@ int cdfDefVar(stream_t *streamptr, int varID)
{
if ( gridInqXIsc(gridID) )
{
int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
const int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
size_t len = strlen(coordinates);
if ( len ) coordinates[len++] = ' ';
cdf_inq_varname(fileID, ncxvarID, coordinates+len);
}
else if ( gridInqYIsc(gridID) )
{
int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
const int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
size_t len = strlen(coordinates);
if ( len ) coordinates[len++] = ' ';
cdf_inq_varname(fileID, ncyvarID, coordinates+len);
......@@ -692,10 +691,10 @@ int cdfDefVar(stream_t *streamptr, int varID)
/* if ( xtype == NC_BYTE || xtype == NC_SHORT || xtype == NC_INT ) */
{
double addoffset = vlistInqVarAddoffset(vlistID, varID);
double scalefactor = vlistInqVarScalefactor(vlistID, varID);
bool laddoffset = IS_NOT_EQUAL(addoffset, 0);
bool lscalefactor = IS_NOT_EQUAL(scalefactor, 1);
const double addoffset = vlistInqVarAddoffset(vlistID, varID);
const double scalefactor = vlistInqVarScalefactor(vlistID, varID);
const bool laddoffset = IS_NOT_EQUAL(addoffset, 0);
const bool lscalefactor = IS_NOT_EQUAL(scalefactor, 1);
if ( laddoffset || lscalefactor )
{
......@@ -714,7 +713,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
if ( dtype == CDI_DATATYPE_UINT8 && xtype == NC_BYTE )
{
int validrange[2] = {0, 255};
const int validrange[2] = {0, 255};
cdf_put_att_int(fileID, ncvarid, "valid_range", NC_SHORT, 2, validrange);
cdf_put_att_text(fileID, ncvarid, "_Unsigned", 4, "true");
}
......@@ -767,10 +766,10 @@ void cdfEndDef(stream_t *streamptr)
if ( streamptr->accessmode == 0 )
{
int fileID = streamptr->fileID;
int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
int nvars = streamptr->nvars;
int nvars = streamptr->nvars;
for ( int varID = 0; varID < nvars; varID++ )
cdfDefVar(streamptr, varID);
......
......@@ -144,7 +144,7 @@ void cdfDefTime(stream_t* streamptr)
if ( streamptr->basetime.ncvarid != CDI_UNDEFID ) return;
int fileID = streamptr->fileID;
const int fileID = streamptr->fileID;
if ( streamptr->ncmode == 0 ) streamptr->ncmode = 1;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
......@@ -152,12 +152,10 @@ void cdfDefTime(stream_t* streamptr)
taxis_t *taxis = &streamptr->tsteps[0].taxis;
const char *taxis_name = (taxis->name && taxis->name[0]) ? taxis->name : default_name ;
cdf_def_dim(fileID, taxis_name, NC_UNLIMITED, &time_dimid);
streamptr->basetime.ncdimid = time_dimid;
nc_type xtype = (taxis->datatype == CDI_DATATYPE_FLT32) ? NC_FLOAT : NC_DOUBLE;
const nc_type xtype = (taxis->datatype == CDI_DATATYPE_FLT32) ? NC_FLOAT : NC_DOUBLE;
cdf_def_var(fileID, taxis_name, xtype, 1, &time_dimid, &time_varid);
streamptr->basetime.ncvarid = time_varid;
......@@ -165,15 +163,13 @@ void cdfDefTime(stream_t* streamptr)
#if defined (HAVE_NETCDF4)
if ( streamptr->filetype == CDI_FILETYPE_NC4 || streamptr->filetype == CDI_FILETYPE_NC4C )
{
size_t chunk = 512;
const size_t chunk = 512;
cdf_def_var_chunking(fileID, time_varid, NC_CHUNKED, &chunk);
}
#endif
{
static const char timeStr[] = "time";
cdf_put_att_text(fileID, time_varid, "standard_name", sizeof(timeStr) - 1, timeStr);
}
static const char timeStr[] = "time";
cdf_put_att_text(fileID, time_varid, "standard_name", sizeof(timeStr) - 1, timeStr);
if ( taxis->longname && taxis->longname[0] )
cdf_put_att_text(fileID, time_varid, "long_name", strlen(taxis->longname), taxis->longname);
......@@ -184,27 +180,16 @@ void cdfDefTime(stream_t* streamptr)
streamptr->basetime.ncvarboundsid = time_bndsid;
}
{
char unitstr[CDI_MAX_NAME];
cdfDefTimeUnits(unitstr, taxis);
size_t len = strlen(unitstr);
if ( len )
{
cdf_put_att_text(fileID, time_varid, "units", len, unitstr);
/*
if ( taxis->has_bounds )
cdf_put_att_text(fileID, time_bndsid, "units", len, unitstr);
*/
}
}
char unitstr[CDI_MAX_NAME];
cdfDefTimeUnits(unitstr, taxis);
size_t len = strlen(unitstr);
if (len) cdf_put_att_text(fileID, time_varid, "units", len, unitstr);
// if ( len && taxis->has_bounds ) cdf_put_att_text(fileID, time_bndsid, "units", len, unitstr);
if ( taxis->calendar != -1 )
{
cdfDefCalendar(fileID, time_varid, taxis->calendar);
/*
if ( taxis->has_bounds )
cdfDefCalendar(fileID, time_bndsid, taxis->calendar);
*/
// ( taxis->has_bounds ) cdfDefCalendar(fileID, time_bndsid, taxis->calendar);
}
if ( taxis->type == TAXIS_FORECAST )
......@@ -213,23 +198,15 @@ void cdfDefTime(stream_t* streamptr)
cdf_def_var(fileID, "leadtime", xtype, 1, &time_dimid, &leadtimeid);
streamptr->basetime.leadtimeid = leadtimeid;
{
static const char stdname[] = "forecast_period";
cdf_put_att_text(fileID, leadtimeid, "standard_name", sizeof(stdname) - 1, stdname);
}
static const char stdname[] = "forecast_period";
cdf_put_att_text(fileID, leadtimeid, "standard_name", sizeof(stdname) - 1, stdname);
{
static const char lname[] = "Time elapsed since the start of the forecast";
cdf_put_att_text(fileID, leadtimeid, "long_name", sizeof(lname) - 1, lname);
}
static const char lname[] = "Time elapsed since the start of the forecast";
cdf_put_att_text(fileID, leadtimeid, "long_name", sizeof(lname) - 1, lname);
{
char unitstr[CDI_MAX_NAME];
cdfDefForecastTimeUnits(unitstr, taxis->fc_unit);
size_t len = strlen(unitstr);
if ( len )
cdf_put_att_text(fileID, leadtimeid, "units", len, unitstr);
}
cdfDefForecastTimeUnits(unitstr, taxis->fc_unit);
len = strlen(unitstr);
if ( len ) cdf_put_att_text(fileID, leadtimeid, "units", len, unitstr);
}
cdf_put_att_text(fileID, time_varid, "axis", 1, "T");
......
......@@ -1610,8 +1610,6 @@ void resize_opt_grib_entries(var_t *var, int nentries)
{
if (var->opt_grib_kvpair_size >= nentries)
{
if ( CDI_Debug )
Message("data structure has size %d, no resize to %d needed.", var->opt_grib_kvpair_size, nentries);
return; /* nothing to do; array is still large enough */
}
else
......
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