Commit d90efc2a authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Replace memcmp with dedicated compare function.

parent 6a81e2bd
#ifndef CDI_DATETIME_H
#define CDI_DATETIME_H
typedef struct
{
long date;
long time;
}
DateTime;
static inline int
datetimeCmp(DateTime dt1, DateTime dt2)
{
return 2 * ((dt1.date > dt2.date) - (dt1.date < dt2.date))
+ (dt1.time > dt2.time) - (dt1.time < dt2.time);
}
#endif
/*
* Local Variables:
* c-file-style: "Java"
......
......@@ -2,6 +2,7 @@
# include "config.h"
#endif
#include <limits.h>
#include <stdio.h>
// #include <float.h> /* FLT_EPSILON */
......@@ -588,7 +589,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
int fileID;
int param = 0;
int level1 = 0, level2 = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0;
DateTime datetime, datetime0 = { LONG_MIN, LONG_MIN };
int tsID;
size_t readsize;
unsigned nrecords, recID;
......@@ -713,7 +714,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
{
if ( recID < nrecs ) break;
if ( warn_time )
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 )
if ( datetimeCmp(datetime, datetime0) != 0 )
{
gribWarning("Inconsistent verification time!", nrecs_scanned, tsID+1, paramstr, level1, level2);
warn_time = FALSE;
......@@ -721,7 +722,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
}
else
{
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( datetimeCmp(datetime, datetime0) != 0 ) break;
if ( recID < nrecs )
{
......@@ -815,7 +816,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
int fileID;
int param = 0;
int level1 = 0, level2 = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0;
DateTime datetime, datetime0 = { LONG_MIN, LONG_MIN };
int tsID;
int varID, gridID;
size_t readsize;
......@@ -986,7 +987,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
{
if ( streamptr->tsteps[tsID].records[recID].used )
{
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( datetimeCmp(datetime, datetime0) != 0 ) break;
gribWarning("Parameter already exist, skipped!", nrecs_scanned, tsID+1, paramstr, level1, level2);
continue;
......@@ -1068,7 +1069,7 @@ int cgribexScanTimestep(stream_t * streamptr)
int fileID;
int param = 0;
int level1 = 0, level2 = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0;
DateTime datetime, datetime0 = { LONG_MIN, LONG_MIN };
int vrecID, recID;
int warn_numavg = TRUE;
size_t readsize;
......@@ -1242,7 +1243,7 @@ int cgribexScanTimestep(stream_t * streamptr)
char paramstr[32];
cdiParamToString(param, paramstr, sizeof(paramstr));
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( datetimeCmp(datetime, datetime0) != 0 ) break;
if ( CDI_Debug )
gribWarning("Parameter already exist, skipped!", nrecs_scanned, tsID+1, paramstr, level1, level2);
......
......@@ -2,6 +2,7 @@
# include "config.h"
#endif
#include <limits.h>
#include <stdio.h>
#include <string.h>
......@@ -261,7 +262,7 @@ void extScanTimestep1(stream_t *streamptr)
int rxysize = 0;
int param = 0;
int rcode = 0, rlevel = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0;
DateTime datetime0 = { LONG_MIN, LONG_MIN };
int tsID;
int varID;
long recsize;
......@@ -312,8 +313,6 @@ void extScanTimestep1(stream_t *streamptr)
}
else
{
datetime.date = vdate;
datetime.time = vtime;
compVar.param = param;
compVar.level = rlevel;
for ( recID = 0; recID < nrecs; recID++ )
......@@ -324,7 +323,8 @@ void extScanTimestep1(stream_t *streamptr)
if ( memcmp(&compVar0, &compVar, sizeof(extcompvar_t)) == 0 ) break;
}
if ( recID < nrecs ) break;
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) )
DateTime datetime = { .date = vdate, .time = vtime};
if ( datetimeCmp(datetime, datetime0) )
Warning("Inconsistent verification time for code %d level %d", rcode, rlevel);
}
......
......@@ -892,7 +892,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
if( datetime0.date == 10101 && datetime0.time == 0 )
{
if( memcmp(&datetime, &datetime0, sizeof(datetime)) || !nrecs ) //Do we really need this condition? I have included it in order not to change the number of times gribapiGetDataDateTime() etc. get called. But if those are sideeffect-free, this condition should be removed.
if( datetimeCmp(datetime, datetime0) || !nrecs ) //Do we really need this condition? I have included it in order not to change the number of times gribapiGetDataDateTime() etc. get called. But if those are sideeffect-free, this condition should be removed.
{
datetime0 = datetime;
......@@ -1169,7 +1169,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
if ( cdiInventoryMode == 1 ) break;
else
{
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( datetimeCmp(datetime, datetime0) != 0 ) break;
gribWarning("Parameter already exist, skipped!", nrecs_scanned, tsID+1, varname, param, level1, level2);
continue;
......@@ -1407,7 +1407,7 @@ int gribapiScanTimestep(stream_t * streamptr)
{
if ( streamptr->tsteps[tsID].records[recID].used )
{
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( datetimeCmp(datetime, datetime0) != 0 ) break;
if ( CDI_Debug )
gribWarning("Parameter already exist, skipped!", nrecs_scanned, tsID+1, varname, param, level1, level2);
......
......@@ -2,6 +2,7 @@
# include "config.h"
#endif
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -841,7 +842,7 @@ void iegScanTimestep1(stream_t *streamptr)
int tabnum;
int param = 0;
int rcode = 0, rlevel = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0;
DateTime datetime0 = { LONG_MIN, LONG_MIN };
int tsID;
int varID;
size_t recsize;
......@@ -896,8 +897,6 @@ void iegScanTimestep1(stream_t *streamptr)
}
else
{
datetime.date = vdate;
datetime.time = vtime;
compVar.param = param;
compVar.level = rlevel;
for ( recID = 0; recID < nrecs; recID++ )
......@@ -908,7 +907,8 @@ void iegScanTimestep1(stream_t *streamptr)
if ( memcmp(&compVar0, &compVar, sizeof(IEGCOMPVAR)) == 0 ) break;
}
if ( recID < nrecs ) break;
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) )
DateTime datetime = { .date = vdate, .time = vtime};
if ( datetimeCmp(datetime, datetime0) )
Warning("Inconsistent verification time for param %d level %d", param, rlevel);
}
......
......@@ -261,7 +261,7 @@ void srvScanTimestep1(stream_t *streamptr)
int rxsize = 0, rysize = 0;
int param = 0;
int rcode = 0, rlevel = 0, vdate = 0, vtime = 0;
DateTime datetime, datetime0;
DateTime datetime0 = { LONG_MIN, LONG_MIN };
int tsID;
int varID;
off_t recpos;
......@@ -313,8 +313,6 @@ void srvScanTimestep1(stream_t *streamptr)
}
else
{
datetime.date = vdate;
datetime.time = vtime;
compVar.param = param;
compVar.level = rlevel;
for ( recID = 0; recID < nrecs; recID++ )
......@@ -325,7 +323,8 @@ void srvScanTimestep1(stream_t *streamptr)
if ( memcmp(&compVar0, &compVar, sizeof(SRVCOMPVAR)) == 0 ) break;
}
if ( recID < nrecs ) break;
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) )
DateTime datetime = { .date = vdate, .time = vtime };
if ( datetimeCmp(datetime, datetime0) )
Warning("Inconsistent verification time for code %d level %d", rcode, rlevel);
}
......
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