OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
table.c File Reference

Curve and time-series storage, interpolation, and integration. More...

#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "headers.h"
Include dependency graph for table.c:

Macros

#define _CRT_SECURE_NO_DEPRECATE
 

Functions

int table_getNextFileEntry (TTable *table, double *x, double *y)
 Read the next nonblank, noncomment time-series file record.
 
int table_parseFileLine (char *line, TTable *table, double *x, double *y)
 Parse one mutable external time-series line, carrying forward omitted dates.
 
double table_interpolate (double x, double x1, double y1, double x2, double y2)
 Linearly interpolate or extrapolate a table segment.
 
int table_readCurve (char *tok[], int ntoks)
 Reads a tokenized line of data for a curve table.
 
int table_readTimeseries (char *tok[], int ntoks)
 Reads a tokenized line of data for a time series table.
 
int table_addEntry (TTable *table, double x, double y)
 Adds a new x/y entry to a table.
 
void table_deleteEntries (TTable *table)
 Deletes all x/y entries in a table.
 
void table_init (TTable *table)
 Initializes properties when table is first created.
 
int table_validate (TTable *table)
 Checks that table's x-values are in ascending order.
 
int table_getFirstEntry (TTable *table, double *x, double *y)
 Retrieves the first x/y entry in a table.
 
int table_getNextEntry (TTable *table, double *x, double *y)
 Retrieves the next x/y entry in a table.
 
double table_lookup (TTable *table, double x)
 Retrieves the y-value corresponding to an x-value in a table, using interploation if necessary.
 
double table_getSlope (TTable *table, double x)
 Retrieves the slope of the curve at the line segment containing x.
 
double table_lookupEx (TTable *table, double x)
 Retrieves the y-value corresponding to an x-value in a table, using interploation if necessary within the table and linear extrapolation outside of the table.
 
double table_intervalLookup (TTable *table, double x)
 Retrieves the y-value corresponding to the first table entry whose x-value is > x.
 
double table_inverseLookup (TTable *table, double y)
 Retrieves the x-value corresponding to an y-value in a table, using interploation if necessary.
 
double table_getMaxY (TTable *table, double x)
 Finds the largest y value in the initial non-decreasing portion of a table that appear before value x.
 
double table_getStorageVolume (TTable *table, double x)
 Finds volume for a given depth in a Storage Curve table.
 
double table_getStorageDepth (TTable *table, double v)
 Finds depth for a given volume in a Storage Curve table.
 
void table_tseriesInit (TTable *table)
 Initializes the time bracket within a time series table.
 
double table_tseriesLookup (TTable *table, double x, char extend)
 Retrieves the y-value corresponding to a time series date, using interploation if necessary.
 

Detailed Description

Curve and time-series storage, interpolation, and integration.

Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com (OpenSWMM maintenance and extensions)
License
Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.

Macro Definition Documentation

◆ _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_DEPRECATE

Function Documentation

◆ table_addEntry()

int table_addEntry ( TTable * table,
double x,
double y )

Adds a new x/y entry to a table.

Parameters
tablePointer to a TTable structure.
[in]xX value.
[in]yY value.
Returns
TRUE if successful, FALSE if not.
Here is the caller graph for this function:

◆ table_deleteEntries()

void table_deleteEntries ( TTable * table)

Deletes all x/y entries in a table.

Parameters
tablePointer to a TTable structure.

◆ table_getFirstEntry()

int table_getFirstEntry ( TTable * table,
double * x,
double * y )

Retrieves the first x/y entry in a table.

Parameters
tablePointer to a TTable structure.
[out]xX-value of first table entry.
[out]yY-value of first table entry.
Returns
TRUE if successful, FALSE if not.
Note
Also moves the current position pointer (thisEntry) to the 1st entry.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_getMaxY()

double table_getMaxY ( TTable * table,
double x )

Finds the largest y value in the initial non-decreasing portion of a table that appear before value x.

Parameters
tablePointer to a TTable structure.
[in]xAn x-value.
Returns
The maximum y-value for x-values below x.

◆ table_getNextEntry()

int table_getNextEntry ( TTable * table,
double * x,
double * y )

Retrieves the next x/y entry in a table.

Parameters
tablePointer to a TTable structure.
[out]xX-value of next table entry.
[out]yY-value of next table entry.
Returns
TRUE if successful, FALSE if not.
Note
Also updates the current position pointer (thisEntry).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_getNextFileEntry()

int table_getNextFileEntry ( TTable * table,
double * x,
double * y )

Read the next nonblank, noncomment time-series file record.

Parameters
[in,out]tableNon-null borrowed table; reads/advances its open file and may update lastDate through parsing. A null file pointer returns FALSE.
[out]xNon-null caller-owned SWMM calendar date/time in decimal days.
[out]yNon-null caller-owned time-series value in the table's native units.
Returns
TRUE for a parsed record; FALSE at EOF, absent stream, read failure or an invalid noncomment line. Outputs are assigned only on parse success.
Note
Does not close or retain the input stream or output pointers.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_getSlope()

double table_getSlope ( TTable * table,
double x )

Retrieves the slope of the curve at the line segment containing x.

Parameters
tablePointer to a TTable structure.
[in]xAn x-value.
Returns
The slope of the curve at x.

◆ table_getStorageDepth()

double table_getStorageDepth ( TTable * table,
double v )

Finds depth for a given volume in a Storage Curve table.

Parameters
tablePointer to a TTable structure.
[in]vA storage volume.
Returns
A storage depth.

◆ table_getStorageVolume()

double table_getStorageVolume ( TTable * table,
double x )

Finds volume for a given depth in a Storage Curve table.

Parameters
tablePointer to a TTable structure.
[in]xA depth value.
Returns
A storage volume.
Here is the call graph for this function:

◆ table_init()

void table_init ( TTable * table)

Initializes properties when table is first created.

Parameters
tablePointer to a TTable structure.

◆ table_interpolate()

double table_interpolate ( double x,
double x1,
double y1,
double x2,
double y2 )

Linearly interpolate or extrapolate a table segment.

Parameters
[in]xQuery coordinate in the same units as x1 and x2.
[in]x1First endpoint coordinate.
[in]y1First endpoint value.
[in]x2Second endpoint coordinate.
[in]y2Second endpoint value in the same units as y1.
Returns
Linear y at x, or the mean of y1 and y2 when abs(x2 - x1) < 1e-20.
Note
x is not restricted to the endpoint interval; no state is changed.
Here is the caller graph for this function:

◆ table_intervalLookup()

double table_intervalLookup ( TTable * table,
double x )

Retrieves the y-value corresponding to the first table entry whose x-value is > x.

Parameters
tablePointer to a TTable structure.
[in]xAn x-value.
Returns
A y-value.

◆ table_inverseLookup()

double table_inverseLookup ( TTable * table,
double y )

Retrieves the x-value corresponding to an y-value in a table, using interploation if necessary.

Parameters
tablePointer to a TTable structure.
[in]yA y-value.
Returns
An x-value.
Note
If y is below the first table entry, then the first x-value is returned; if y is above the last entry, then the last x-value is returned.
Here is the call graph for this function:

◆ table_lookup()

double table_lookup ( TTable * table,
double x )

Retrieves the y-value corresponding to an x-value in a table, using interploation if necessary.

Parameters
tablePointer to a TTable structure.
[in]xAn x-value.
Returns
A y-value.
Note
If x is below the first table entry, then the first y-value is returned; if x is above the last entry, then the last y-value is returned.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_lookupEx()

double table_lookupEx ( TTable * table,
double x )

Retrieves the y-value corresponding to an x-value in a table, using interploation if necessary within the table and linear extrapolation outside of the table.

Parameters
tablePointer to a TTable structure.
[in]xAn x-value.
Returns
A y-value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_parseFileLine()

int table_parseFileLine ( char * line,
TTable * table,
double * x,
double * y )

Parse one mutable external time-series line, carrying forward omitted dates.

Parameters
[in,out]lineNon-null writable null-terminated buffer; strtok inserts terminators and uses shared tokenization state.
[in,out]tableNon-null borrowed table providing lastDate for two-field records; a three-field record updates lastDate after its date parses, even if a later time/value field fails.
[out]xNon-null caller-owned date/time in SWMM decimal days, assigned on success.
[out]yNon-null caller-owned value in table units, assigned on success.
Returns
-1 for blank/comment lines, TRUE for a parsed two/three-field record, or FALSE for invalid fields. Numeric times are hours converted to days.
Note
The buffer and output slots are not retained. strtok makes concurrent or nested parsing unsafe without external coordination.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_readCurve()

int table_readCurve ( char * tok[],
int ntoks )

Reads a tokenized line of data for a curve table.

Parameters
tokArray of string tokens.
[in]ntoksNumber of tokens.
Returns
An error code.
Here is the call graph for this function:

◆ table_readTimeseries()

int table_readTimeseries ( char * tok[],
int ntoks )

Reads a tokenized line of data for a time series table.

Parameters
tokArray of string tokens.
[in]ntoksNumber of tokens.
Returns
An error code.
Here is the call graph for this function:

◆ table_tseriesInit()

void table_tseriesInit ( TTable * table)

Initializes the time bracket within a time series table.

Parameters
tablePointer to a TTable structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_tseriesLookup()

double table_tseriesLookup ( TTable * table,
double x,
char extend )

Retrieves the y-value corresponding to a time series date, using interploation if necessary.

Parameters
tablePointer to a TTable structure.
[in]xA date/time value.
[in]extendTRUE if time series extended on either end.
Returns
A y-value.
Note
If extend is FALSE and date x is outside the range of the table then 0 is returned; if TRUE then the first or last value is returned.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_validate()

int table_validate ( TTable * table)

Checks that table's x-values are in ascending order.

Parameters
tablePointer to a TTable structure.
Returns
Error code.
Here is the call graph for this function:
Here is the caller graph for this function: