Commit 2e7067bd authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Prepare grid for alternate derived implementations.

* This will later allow for decomposed and lazily-read grids.
parent 3e9b121c
......@@ -10,6 +10,7 @@
#include "dmemory.h"
#include "error.h"
#include "gribapi.h"
#include "grid.h"
#include <assert.h>
#include <time.h>
......@@ -462,7 +463,7 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
ISEC4_NumValues = ISEC2_NumLon*ISEC2_NumLat;
}
*/
memset(grid, 0, sizeof(grid_t));
grid_init(grid);
size_t datasize;
FAIL_ON_GRIB_ERROR(grib_get_size, gh, "values", &datasize);
......
This diff is collapsed.
......@@ -5,7 +5,35 @@
typedef unsigned char mask_t;
typedef struct {
typedef struct grid_t grid_t;
struct gridVirtTable
{
void (*destroy)(grid_t *gridptr);
void (*duplicateData)(grid_t *gridptrOrig, grid_t *gridptrDup);
void (*defXVals)(grid_t *gridptr, const double *xvals);
void (*defYVals)(grid_t *gridptr, const double *yvals);
void (*defMask)(grid_t *gridptr, const int *mask);
void (*defMaskGME)(grid_t *gridptr, const int *mask);
void (*defXBounds)(grid_t *gridptr, const double *xbounds);
void (*defYBounds)(grid_t *gridptr, const double *ybounds);
void (*defArea)(grid_t *gridptr, const double *area);
double (*inqXVal)(grid_t *gridptr, int index);
double (*inqYVal)(grid_t *gridptr, int index);
int (*inqXVals)(grid_t *gridptr, double *xvals);
int (*inqYVals)(grid_t *gridptr, double *yvals);
const double *(*inqXValsPtr)(grid_t *gridptr);
const double *(*inqYValsPtr)(grid_t *gridptr);
void (*inqArea)(grid_t *gridptr, double *area);
int (*inqMask)(grid_t *gridptr, int *mask);
int (*inqMaskGME)(grid_t *gridptr, int *mask_gme);
int (*inqXBounds)(grid_t *gridptr, double *xbounds);
int (*inqYBounds)(grid_t *gridptr, double *ybounds);
const double *(*inqXBoundsPtr)(grid_t *gridptr);
const double *(*inqYBoundsPtr)(grid_t *gridptr);
};
struct grid_t {
int self;
int type; /* grid type */
int prec; /* grid precision */
......@@ -68,12 +96,14 @@ typedef struct {
char xunits[CDI_MAX_NAME];
char yunits[CDI_MAX_NAME];
char *name;
}
grid_t;
const struct gridVirtTable *vtable;
void *extraData;
};
void grid_init(grid_t *gridptr);
void grid_free(grid_t *gridptr);
grid_t *gridID2Ptr(int gridID);
unsigned cdiGridCount(void);
......
......@@ -167,7 +167,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, double *fsec2, int *isec4,
compyinc = FALSE;
}
memset(grid, 0, sizeof(grid_t));
grid_init(grid);
switch (gridtype)
{
case GRID_LONLAT:
......
......@@ -217,7 +217,7 @@ void extAddRecord(stream_t *streamptr, int param, int level, int xysize,
record->ilevel = level;
grid_t grid;
memset(&grid, 0, sizeof(grid_t));
grid_init(&grid);
grid.type = GRID_GENERIC;
grid.size = xysize;
grid.xsize = xysize;
......
......@@ -673,7 +673,7 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
( IEG_G_GridType(gdb) == 4 ) ? GRID_GAUSSIAN : GRID_GENERIC;
grid_t grid;
memset(&grid, 0, sizeof(grid_t));
grid_init(&grid);
grid.type = gridtype;
grid.size = IEG_G_NumLon(gdb)*IEG_G_NumLat(gdb);
grid.xsize = IEG_G_NumLon(gdb);
......
......@@ -210,7 +210,7 @@ void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ys
record->ilevel = level;
grid_t grid;
memset(&grid, 0, sizeof(grid_t));
grid_init(&grid);
grid.type = GRID_GENERIC;
grid.size = xsize*ysize;
grid.xsize = xsize;
......
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