Commit 4f850936 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Set constant variables to const.

parent 6881eb4e
Pipeline #9206 failed with stage
in 0 seconds
......@@ -93,8 +93,8 @@ size_t binReadF77Block(int fileID, int byteswap)
void binWriteF77Block(int fileID, int byteswap, size_t blocksize)
{
static unsigned int s[4] = {0, 8, 16, 24};
unsigned long ublocksize = (unsigned long) blocksize;
static const unsigned int s[4] = {0, 8, 16, 24};
const unsigned long ublocksize = (unsigned long) blocksize;
unsigned char f77block[4];
switch (HOST_ENDIANNESS)
......
......@@ -27,25 +27,12 @@ int days_per_month(int calendar, int year, int month)
{
int daysperyear = calendar_dpy(calendar);
const int *dpm;
if ( daysperyear == 360 ) dpm = month_360;
else if ( daysperyear == 365 ) dpm = month_365;
else dpm = month_366;
int dayspermonth = 0;
if ( month >= 1 && month <= 12 )
dayspermonth = dpm[month-1];
/*
else
fprintf(stderr, "days_per_month: month %d out of range\n", month);
*/
if ( daysperyear == 0 && month == 2 )
{
if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
dayspermonth = 29;
else
dayspermonth = 28;
}
const int *dpm = (daysperyear == 360) ? month_360 : ((daysperyear == 365) ? month_365 : month_366);
int dayspermonth = ( month >= 1 && month <= 12 ) ? dpm[month-1] : 0;
if (daysperyear == 0 && month == 2)
dayspermonth = ((year%4 == 0 && year%100 != 0) || year%400 == 0) ? 29 : 28;
return dayspermonth;
}
......@@ -55,11 +42,11 @@ int days_per_year(int calendar, int year)
{
int daysperyear = calendar_dpy(calendar);
if ( daysperyear == 0 )
if (daysperyear == 0)
{
if ( year == 1582 && (calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN) )
if (year == 1582 && (calendar == CALENDAR_STANDARD || calendar == CALENDAR_GREGORIAN))
daysperyear = 355;
else if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
else if ((year%4 == 0 && year%100 != 0) || year%400 == 0)
daysperyear = 366;
else
daysperyear = 365;
......@@ -71,8 +58,6 @@ int days_per_year(int calendar, int year)
static void decode_day(int dpy, int days, int *year, int *month, int *day)
{
int i = 0;
*year = (days-1) / dpy;
days -= (*year*dpy);
......@@ -81,6 +66,7 @@ static void decode_day(int dpy, int days, int *year, int *month, int *day)
else if ( dpy == 365 ) dpm = month_365;
else if ( dpy == 366 ) dpm = month_366;
int i = 0;
if ( dpm )
for ( i = 0; i < 12; i++ )
{
......@@ -112,7 +98,7 @@ static int64_t encode_day(int dpy, int year, int month, int day)
void encode_caldaysec(int calendar, int year, int month, int day, int hour, int minute, int second,
int64_t *julday, int *secofday)
{
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
if ( dpy == 360 || dpy == 365 || dpy == 366 )
*julday = encode_day(dpy, year, month, day);
......@@ -126,7 +112,7 @@ void encode_caldaysec(int calendar, int year, int month, int day, int hour, int
void decode_caldaysec(int calendar, int64_t julday, int secofday,
int *year, int *month, int *day, int *hour, int *minute, int *second)
{
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
if ( dpy == 360 || dpy == 365 || dpy == 366 )
decode_day(dpy, julday, year, month, day);
......@@ -142,7 +128,7 @@ void decode_caldaysec(int calendar, int64_t julday, int secofday,
#ifdef TEST
static int date_to_calday(int calendar, int date)
{
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
int year, month, day;
cdiDecodeDate(date, &year, &month, &day);
......@@ -160,14 +146,14 @@ static int date_to_calday(int calendar, int date)
static int calday_to_date(int calendar, int calday)
{
int year, month, day;
int dpy = calendar_dpy(calendar);
const int dpy = calendar_dpy(calendar);
if ( dpy == 360 || dpy == 365 || dpy == 366 )
decode_day(dpy, calday, &year, &month, &day);
else
decode_julday(calendar, calday, &year, &month, &day);
int date = cdiEncodeDate(year, month, day);
const int date = cdiEncodeDate(year, month, day);
return date;
}
......
......@@ -103,7 +103,7 @@ static int cdfOpenFile(const char *filename, const char *mode, int *filetype)
{
case 'r':
{
int status = cdf_open(filename, readmode, &ncid);
const int status = cdf_open(filename, readmode, &ncid);
if ( status > 0 && ncid < 0 ) ncid = CDI_ESYSTEM;
#ifdef HAVE_NETCDF4
else
......
This diff is collapsed.
......@@ -23,8 +23,8 @@ bool strStartsWith(const char *vstr, const char *cstr)
bool is_equal = false;
if (vstr && cstr)
{
size_t clen = strlen(cstr);
size_t vlen = strlen(vstr);
const size_t clen = strlen(cstr);
const size_t vlen = strlen(vstr);
if (clen <= vlen) is_equal = (memcmp(vstr, cstr, clen) == 0);
}
return is_equal;
......@@ -74,8 +74,8 @@ bool is_timeaxis_units(const char *timeunits)
{
bool status = false;
size_t len = strlen(timeunits);
char *tu = (char *) Malloc((len+1)*sizeof(char));
const size_t len = strlen(timeunits);
char *tu = (char *) malloc((len+1)*sizeof(char));
memcpy(tu, timeunits, (len+1) * sizeof(char));
char *ptu = tu;
......@@ -96,7 +96,7 @@ bool is_timeaxis_units(const char *timeunits)
}
}
Free(tu);
free(tu);
return status;
}
......
......@@ -241,11 +241,11 @@ void cdfDefineCellMethods(stream_t *streamptr, int cdiID, int varID, int fileID,
taxis_t *taxis = &streamptr->tsteps[0].taxis;
if (!taxis->has_bounds) return;
int time_varid = streamptr->basetime.ncvarid;
const int time_varid = streamptr->basetime.ncvarid;
char timeVarName[CDI_MAX_NAME];
cdf_inq_varname(fileID, time_varid, timeVarName);
int stepType = vlistInqVarTsteptype(cdiID, varID);
const int stepType = vlistInqVarTsteptype(cdiID, varID);
const char *cellMethod = NULL;
if (stepType == TSTEP_AVG) cellMethod = "mean";
......@@ -282,7 +282,7 @@ void cdfDefineAttributes(int cdiID, int varID, int fileID, int ncvarID)
if ( atttype == CDI_DATATYPE_TXT )
{
size_t attSize = (size_t)attlen*sizeof(char);
const size_t attSize = (size_t)attlen*sizeof(char);
char *atttxt = (char *)resizeBuf(&attBuf, &attBufSize, attSize);
cdiInqAttTxt(cdiID, varID, attname, attlen, atttxt);
len = (size_t)attlen;
......@@ -292,7 +292,7 @@ void cdfDefineAttributes(int cdiID, int varID, int fileID, int ncvarID)
atttype == CDI_DATATYPE_INT16 || atttype == CDI_DATATYPE_UINT16 ||
atttype == CDI_DATATYPE_INT32 || atttype == CDI_DATATYPE_UINT32 )
{
size_t attSize = (size_t)attlen*sizeof(int);
const size_t attSize = (size_t)attlen*sizeof(int);
int *attint = (int *)resizeBuf(&attBuf, &attBufSize, attSize);
cdiInqAttInt(cdiID, varID, attname, attlen, &attint[0]);
len = (size_t)attlen;
......@@ -308,7 +308,7 @@ void cdfDefineAttributes(int cdiID, int varID, int fileID, int ncvarID)
}
else if ( atttype == CDI_DATATYPE_FLT32 || atttype == CDI_DATATYPE_FLT64 )
{
size_t attSize = (size_t)attlen * sizeof(double);
const size_t attSize = (size_t)attlen * sizeof(double);
double *attflt = (double *)resizeBuf(&attBuf, &attBufSize, attSize);
cdiInqAttFlt(cdiID, varID, attname, attlen, attflt);
len = (size_t)attlen;
......@@ -372,7 +372,7 @@ void cdf_get_gmapvarname(int gridID, char *gmapvarname)
if ( !gmapname[0] )
{
int projID = gridInqProj(gridID);
const int projID = gridInqProj(gridID);
if ( projID != CDI_UNDEFID )
{
pgridID = projID;
......@@ -528,7 +528,7 @@ void cdfDefineCoordinates(const stream_t *streamptr, int ncvarID, int nczvarID,
{
char name[CDI_MAX_NAME]; name[0] = 0;
cdf_inq_varname(fileID, ncyvarID, name);
size_t len = strlen(name);
const size_t len = strlen(name);
cdf_put_att_text(fileID, ncvarID, "CDI_grid_latitudes", len, name);
}
......@@ -537,7 +537,7 @@ void cdfDefineCoordinates(const stream_t *streamptr, int ncvarID, int nczvarID,
{
char name[CDI_MAX_NAME]; name[0] = 0;
cdf_inq_varname(fileID, ncrpvarID, name);
size_t len = strlen(name);
const size_t len = strlen(name);
cdf_put_att_text(fileID, ncvarID, "CDI_grid_reduced_points", len, name);
}
}
......
......@@ -13,7 +13,7 @@
#include "namespace.h"
/* the single image implementation */
// the single image implementation
int cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, size_t nmiss)
{
// May fail if memtype == MEMTYPE_FLOAT and the file format does not support single precision writing.
......@@ -31,7 +31,7 @@ int cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, s
// check taxis
if ( streamptr->curTsID == CDI_UNDEFID ) streamDefTimestep(streamID, 0);
int filetype = streamptr->filetype;
const int filetype = streamptr->filetype;
switch (cdiBaseFiletype(filetype))
{
......@@ -134,9 +134,8 @@ void streamWriteVarF(int streamID, int varID, const float *data, size_t nmiss)
if ( myCdiStreamWriteVar_(streamID, varID, MEMTYPE_FLOAT, (const void *) data, nmiss) )
{
// In case the file format does not support single precision writing,
// we fall back to double precision writing, converting the data
// on the fly.
int vlistID = streamInqVlist(streamID);
// we fall back to double precision writing, converting the data on the fly.
const int vlistID = streamInqVlist(streamID);
size_t elementCount = gridInqSize(vlistInqVarGrid(vlistID, varID));
elementCount *= (size_t) zaxisInqSize(vlistInqVarZaxis(vlistID, varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
......@@ -164,7 +163,7 @@ int cdiStreamWriteVarSlice(int streamID, int varID, int levelID, int memtype, co
// check taxis
if ( streamptr->curTsID == CDI_UNDEFID ) streamDefTimestep(streamID, 0);
int filetype = streamptr->filetype;
const int filetype = streamptr->filetype;
switch (cdiBaseFiletype(filetype))
{
......@@ -260,7 +259,7 @@ void streamWriteVarSliceF(int streamID, int varID, int levelID, const float *dat
{
// In case the file format does not support single precision writing,
// we fall back to double precision writing, converting the data on the fly.
size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
const size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
for ( size_t i = elementCount; i--; ) conversionBuffer[i] = (double) data[i];
streamWriteVarSlice(streamID, varID, levelID, conversionBuffer, nmiss);
......@@ -279,7 +278,7 @@ void streamWriteVarChunk(int streamID, int varID,
myCdiStreamWriteVarChunk_(streamID, varID, MEMTYPE_DOUBLE, rect, data, nmiss);
}
/* single image implementation */
// single image implementation
void cdiStreamWriteVarChunk_(int streamID, int varID, int memtype,
const int rect[][2], const void *data, size_t nmiss)
{
......@@ -289,7 +288,7 @@ void cdiStreamWriteVarChunk_(int streamID, int varID, int memtype,
// streamDefineTaxis(streamID);
int filetype = streamptr->filetype;
const int filetype = streamptr->filetype;
switch (cdiBaseFiletype(filetype))
{
......@@ -404,8 +403,8 @@ void streamWriteRecordF(int streamID, const float *data, size_t nmiss)
// In case the file format does not support single precision writing,
// we fall back to double precision writing, converting the data on the fly.
stream_t *streamptr = stream_to_pointer(streamID);
int varID = streamptr->record->varID;
size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
const int varID = streamptr->record->varID;
const size_t elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
double *conversionBuffer = (double *) Malloc(elementCount*sizeof(*conversionBuffer));
for ( size_t i = elementCount; i--; ) conversionBuffer[i] = (double) data[i];
streamWriteRecord(streamID, conversionBuffer, nmiss);
......
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