Grid Functions

Functions for creating, opening, querying, modifying, and saving grid data, including node values, spacing, and validity checks.

MTK_Grid_Close()

Close a grid and release any memory used.

Note:  This call does not save any changes.

Signature
int MTK_Grid_Close(MTK_Grid* grid);
Parameters grid: Pointer to an MTK_Grid struct.
Return Value 0 on success; any other value indicates failure.

MTK_Grid_GetExtent()

Query the extent of a grid.

Signature
int MTK_Grid_GetExtent(
    MTK_Grid* grid,
    double* lowerBoundX, double* lowerBoundY,
    double* upperBoundX, double* upperBoundY
    );
Parameters
  • grid: Pointer to an MTK_Grid struct.
  • lowerBoundX, lowerBoundY: Lower-left corner coordinates.
  • upperBoundX, upperBoundY: Upper-right corner coordinates.
Return Value 0 on success; any other value indicates failure.

MTK_Grid_GetNodeValue()

Query the value of a grid node.

Signature
int MTK_Grid_GetNodeValue(
    MTK_Grid* grid, const int& i, const int& j,
    double* value, int* mask
    );
Parameters
  • grid: Pointer to an MTK_Grid struct.
  • i: X node index (0+).
  • j: Y node index (0+).
  • value: Node value.
  • mask: Node mask value (1 = active, 0 = inactive).
Return Value 0 on success; any other value indicates failure.

MTK_Grid_GetSpacing()

Query the cell sizes of a grid.

Signature
int MTK_Grid_GetSpacing(
    MTK_Grid* grid, double* cellSizeX, double* cellSizeY);
Parameters
  • grid: Pointer to an MTK_Grid struct.
  • cellSizeX, cellSizeY: Cell size in X and Y directions.
Return Value 0 on success; any other value indicates failure.

MTK_Grid_IsValid()

Query the validity of a grid.

Signature
int MTK_Grid_IsValid(MTK_Grid* grid);
Parameters grid: Pointer to an MTK_Grid struct.
Return Value
  • 1: Valid
  • 0: Invalid
  • -1: Failed

MTK_Grid_New()

Create a grid with the given structure, but with no data.

Note:  This call does not create an actual file.

Signature
MTK_Grid* MTK_Grid_New(
    const double& lowerBoundX, const double& lowerBoundY,
    const double& upperBoundX, const double& upperBoundY,
    const double& cellSizeX, const double& cellSizeY
    );
Parameters
  • lowerBoundX, lowerBoundY: Lower-left corner coordinates.
  • upperBoundX, upperBoundY: Upper-right corner coordinates.
  • cellSizeX, cellSizeY: Grid cell size in X and Y directions.
Return Value Pointer to an MTK_Grid struct on success; NULL pointer on failure.

MTK_Grid_NumNodes()

Query the number of nodes in each direction of a grid.

Signature
int MTK_Grid_NumNodes(
    MTK_Grid* grid, int* numberInX, int* numberInY);
Parameters
  • grid: Pointer to an MTK_Grid struct.
  • numberInX, numberInY: Number of nodes in the X and Y directions.
Return Value 0 on success; any other value indicates failure.

MTK_Grid_Open()

Open an existing grid file.

Signature
MTK_Grid* MTK_Grid_Open(const char* name);
Parameters name: Grid filename.
Return Value Pointer to an MTK_Grid struct on success; NULL on failure.

MTK_Grid_Save()

Save the grid to a file.

Signature
int MTK_Grid_Save(
    MTK_Grid* grid, const char* name);
Parameters
  • grid: Pointer to an MTK_Grid struct.
  • name: Grid filename.
Return Value 0 on success; any other value indicates failure.

MTK_Grid_SetNodeValue()

Set the value of a grid node.

Signature
int MTK_Grid_SetNodeValue(
    MTK_Grid* grid, const int& i, const int& j,
    const double& value, const int& mask
    );
Parameters
  • grid: Pointer to an MTK_Grid struct.
  • i, j: X and Y node indices (0+).
  • value: Node value.
  • mask: Node mask (1 = active, 0 = inactive).
Return Value 0 on success; any other value indicates failure.