Skip to content
Snippets Groups Projects
Commit d25d9d96 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

tstepsInitEntry: change interface.

parent 846bc45e
No related branches found
No related tags found
No related merge requests found
Pipeline #9869 failed
#include <limits.h> #include <limits.h>
#include "dmemory.h"
#include "cdi.h" #include "cdi.h"
#include "cdi_int.h" #include "cdi_int.h"
#include "dmemory.h"
static static
void tstepsInitEntry(stream_t *streamptr, size_t tsID) void tstepsInitEntry(tsteps_t *tstep)
{ {
streamptr->tsteps[tsID].curRecID = CDI_UNDEFID; tstep->curRecID = CDI_UNDEFID;
streamptr->tsteps[tsID].position = 0; tstep->position = 0;
streamptr->tsteps[tsID].records = NULL; tstep->records = NULL;
streamptr->tsteps[tsID].recordSize = 0; tstep->recordSize = 0;
streamptr->tsteps[tsID].nallrecs = 0; tstep->nallrecs = 0;
streamptr->tsteps[tsID].recIDs = NULL; tstep->recIDs = NULL;
streamptr->tsteps[tsID].nrecs = 0; tstep->nrecs = 0;
streamptr->tsteps[tsID].next = 0; tstep->next = 0;
ptaxisInit(&streamptr->tsteps[tsID].taxis); ptaxisInit(&(tstep->taxis));
} }
int tstepsNewEntry(stream_t *streamptr) int tstepsNewEntry(stream_t *streamptr)
{ {
size_t tsID = (size_t)streamptr->tstepsNextID++; const int tsID = streamptr->tstepsNextID++;
size_t tstepsTableSize = (size_t)streamptr->tstepsTableSize; int tstepsTableSize = streamptr->tstepsTableSize;
tsteps_t *tstepsTable = streamptr->tsteps; tsteps_t *tstepsTable = streamptr->tsteps;
/* // If the table overflows, double its size.
If the table overflows, double its size. if (tsID == tstepsTableSize)
*/
if ( tsID == tstepsTableSize )
{ {
if ( tstepsTableSize == 0 ) tstepsTableSize = 1; if (tstepsTableSize == 0) tstepsTableSize = 1;
if ( tstepsTableSize <= INT_MAX / 2) if (tstepsTableSize <= INT_MAX / 2)
tstepsTableSize *= 2; tstepsTableSize *= 2;
else if ( tstepsTableSize < INT_MAX) else if (tstepsTableSize < INT_MAX)
tstepsTableSize = INT_MAX; tstepsTableSize = INT_MAX;
else else
Error("Resizing of tstep table failed!"); Error("Resizing of tstep table failed!");
tstepsTable = (tsteps_t *) Realloc(tstepsTable,
tstepsTableSize * sizeof (tsteps_t)); tstepsTable = (tsteps_t *) Realloc(tstepsTable, (size_t)tstepsTableSize * sizeof(tsteps_t));
} }
streamptr->tstepsTableSize = (int)tstepsTableSize; streamptr->tstepsTableSize = tstepsTableSize;
streamptr->tsteps = tstepsTable; streamptr->tsteps = tstepsTable;
tstepsInitEntry(streamptr, tsID); tsteps_t *curTstep = &streamptr->tsteps[tsID];
tstepsInitEntry(curTstep);
streamptr->tsteps[tsID].taxis.used = true; curTstep->taxis.used = true;
return (int)tsID; return tsID;
} }
void cdiCreateTimesteps(stream_t *streamptr) void cdiCreateTimesteps(stream_t *streamptr)
{ {
if ( streamptr->ntsteps < 0 || streamptr->tstepsTableSize > 0 ) if (streamptr->ntsteps < 0 || streamptr->tstepsTableSize > 0) return;
return;
long ntsteps = (streamptr->ntsteps == 0) ? 1 : streamptr->ntsteps; const int ntsteps = (streamptr->ntsteps == 0) ? 1 : (int)streamptr->ntsteps;
streamptr->tsteps = (tsteps_t *) Malloc((size_t)ntsteps*sizeof(tsteps_t)); streamptr->tsteps = (tsteps_t *) Malloc((size_t)ntsteps * sizeof(tsteps_t));
streamptr->tstepsTableSize = (int)ntsteps; streamptr->tstepsTableSize = ntsteps;
streamptr->tstepsNextID = (int)ntsteps; streamptr->tstepsNextID = ntsteps;
for ( long tsID = 0; tsID < ntsteps; tsID++ ) for (int tsID = 0; tsID < ntsteps; tsID++)
{ {
tstepsInitEntry(streamptr, (size_t)tsID); tsteps_t *curTstep = &streamptr->tsteps[tsID];
streamptr->tsteps[tsID].taxis.used = true; tstepsInitEntry(curTstep);
curTstep->taxis.used = true;
} }
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment