Commit 26eb0ae5 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

stream_cdf: grid cleanup

parent 9b0114f2
......@@ -757,6 +757,7 @@ int main(int argc, char *argv[])
if ( rTable )
{
itableID = tableInq(-1, 0, rTable);
if ( itableID != CDI_UNDEFID ) cdiDefTableID(itableID);
otableID = itableID;
}
......
......@@ -130,6 +130,7 @@ extern "C" {
#define GRID_LAEA 13 /* Lambert Azimuthal Equal Area */
#define GRID_SINUSOIDAL 14 /* Sinusoidal */
#define GRID_REFERENCE 15 /* Reference to the grid */
#define GRID_PROJECTION 16 /* Projected coordiantes */
/* ZAXIS types */
......
......@@ -37,6 +37,7 @@ char *Grids[] = {
/* 13 */ "laea",
/* 14 */ "sinusoidal",
/* 15 */ "reference",
/* 16 */ "projection",
};
......@@ -165,11 +166,10 @@ int grid_from_pointer(grid_t *ptr)
return (idx);
}
static
void grid_init_entry(grid_t *gridptr)
{
gridptr->self = grid_from_pointer(gridptr);
void grid_init(grid_t *gridptr)
{
gridptr->self = CDI_UNDEFID;
gridptr->type = CDI_UNDEFID;
gridptr->mask = NULL;
gridptr->mask_gme = NULL;
......@@ -230,6 +230,32 @@ void grid_init_entry(grid_t *gridptr)
gridptr->yunits[0] = 0;
gridptr->xstdname[0] = 0;
gridptr->ystdname[0] = 0;
gridptr->name = NULL;
}
void grid_free(grid_t *gridptr)
{
if ( gridptr->mask ) free(gridptr->mask);
if ( gridptr->mask_gme ) free(gridptr->mask_gme);
if ( gridptr->xvals ) free(gridptr->xvals);
if ( gridptr->yvals ) free(gridptr->yvals);
if ( gridptr->area ) free(gridptr->area);
if ( gridptr->xbounds ) free(gridptr->xbounds);
if ( gridptr->ybounds ) free(gridptr->ybounds);
if ( gridptr->rowlon ) free(gridptr->rowlon);
if ( gridptr->reference ) free(gridptr->reference);
if ( gridptr->name ) free(gridptr->name);
grid_init(gridptr);
}
static
void grid_init_entry(grid_t *gridptr)
{
grid_init(gridptr);
gridptr->self = grid_from_pointer(gridptr);
}
static
......
......@@ -62,10 +62,14 @@ typedef struct {
char ystdname[CDI_MAX_NAME];
char xunits[CDI_MAX_NAME];
char yunits[CDI_MAX_NAME];
char *name;
}
grid_t;
void grid_init(grid_t *gridptr);
void grid_free(grid_t *gridptr);
const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID);
......
......@@ -4899,6 +4899,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
int nvatts;
size_t nvertex;
grid_t grid;
grid_t proj;
int gridindex;
size_t size = 0, xsize, ysize;
char name[256];
......@@ -4991,7 +4992,8 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
if ( ncvars[ncvarid].gridtype == UNDEFID || ncvars[ncvarid].gridtype == GRID_GENERIC )
if ( ydimid == xdimid ) ncvars[ncvarid].gridtype = GRID_UNSTRUCTURED;
memset(&grid, 0, sizeof(grid_t));
grid_init(&grid);
grid_init(&proj);
grid.prec = DATATYPE_FLT64;
grid.trunc = ncvars[ncvarid].truncation;
......@@ -5329,6 +5331,11 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
grid.type = GRID_LAEA;
else if ( strcmp(attstring, "lambert_conformal_conic") == 0 )
grid.type = GRID_LCC2;
else if ( strcmp(attstring, "lambert_cylindrical_equal_area") == 0 )
{
proj.type = GRID_PROJECTION;
proj.name = strdup(attstring);
}
}
else if ( strcmp(attname, "earth_radius") == 0 )
{
......@@ -5382,8 +5389,12 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
}
if ( CDI_Debug )
Message("grid: type = %d, size = %d, nx = %d, ny %d",
grid.type, grid.size, grid.xsize, grid.ysize);
{
Message("grid: type = %d, size = %d, nx = %d, ny %d",
grid.type, grid.size, grid.xsize, grid.ysize);
Message("proj: type = %d, size = %d, nx = %d, ny %d",
proj.type, proj.size, proj.xsize, proj.ysize);
}
ncvars[ncvarid].gridID = varDefGrid(vlistID, grid, 1);
......@@ -5391,11 +5402,8 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
streamptr->xdimID[gridindex] = xdimid;
streamptr->ydimID[gridindex] = ydimid;
if ( grid.xvals ) free(grid.xvals);
if ( grid.yvals ) free(grid.yvals);
if ( grid.xbounds ) free(grid.xbounds);
if ( grid.ybounds ) free(grid.ybounds);
if ( grid.area ) free(grid.area);
grid_free(&grid);
grid_free(&proj);
if ( CDI_Debug )
Message("gridID %d %d %s", ncvars[ncvarid].gridID, ncvarid, ncvars[ncvarid].name);
......
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