Commit 4ac77931 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

grid: added function gridDefXdimname() and gridDefYdimname()

parent 5662351e
......@@ -756,6 +756,9 @@ void gridDefYvals(int gridID, const double yvals[]);
/* gridInqYvals: Get all values of a Y-axis */
int gridInqYvals(int gridID, double yvals[]);
/* gridDefXdimname: Define the dimension name of a X-axis */
void gridDefXdimname(int gridID, const char *xdimname);
/* gridDefXname: Define the name of a X-axis */
void gridDefXname(int gridID, const char *xname);
......@@ -774,6 +777,9 @@ void gridDefXunits(int gridID, const char *xunits);
/* gridInqXunits: Get the units of a X-axis */
void gridInqXunits(int gridID, char *xunits);
/* gridDefYdimname: Define the dimension name of a Y-axis */
void gridDefYdimname(int gridID, const char *ydimname);
/* gridDefYname: Define the name of a Y-axis */
void gridDefYname(int gridID, const char *yname);
......
......@@ -152,6 +152,8 @@ void grid_init(grid_t *gridptr)
gridptr->angle = 0.0;
gridptr->lcomplex = 0;
gridptr->hasdims = TRUE;
gridptr->xdimname[0] = 0;
gridptr->ydimname[0] = 0;
gridptr->xname[0] = 0;
gridptr->yname[0] = 0;
gridptr->xlongname[0] = 0;
......@@ -239,51 +241,15 @@ unsigned cdiGridCount(void)
}
static inline void
gridSetXname(grid_t *gridptr, const char *xname)
gridSetName(char *gridstrname, const char *name)
{
strncpy(gridptr->xname, xname, CDI_MAX_NAME);
gridptr->xname[CDI_MAX_NAME - 1] = 0;
}
static inline void
gridSetXlongname(grid_t *gridptr, const char *xlongname)
{
strncpy(gridptr->xlongname, xlongname, CDI_MAX_NAME);
gridptr->xlongname[CDI_MAX_NAME - 1] = 0;
}
static inline void
gridSetXunits(grid_t *gridptr, const char *xunits)
{
strncpy(gridptr->xunits, xunits, CDI_MAX_NAME);
gridptr->xunits[CDI_MAX_NAME - 1] = 0;
}
static inline void
gridSetYname(grid_t *gridptr, const char *yname)
{
strncpy(gridptr->yname, yname, CDI_MAX_NAME);
gridptr->yname[CDI_MAX_NAME - 1] = 0;
}
static inline void
gridSetYlongname(grid_t *gridptr, const char *ylongname)
{
strncpy(gridptr->ylongname, ylongname, CDI_MAX_NAME);
gridptr->ylongname[CDI_MAX_NAME - 1] = 0;
}
static inline void
gridSetYunits(grid_t *gridptr, const char *yunits)
{
strncpy(gridptr->yunits, yunits, CDI_MAX_NAME);
gridptr->yunits[CDI_MAX_NAME - 1] = 0;
strncpy(gridstrname, name, CDI_MAX_NAME);
gridstrname[CDI_MAX_NAME - 1] = 0;
}
void
cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
{
gridptr->type = gridtype;
gridptr->size = size;
......@@ -299,16 +265,16 @@ cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
{
if ( gridtype == GRID_TRAJECTORY )
{
gridSetXname(gridptr, "tlon");
gridSetYname(gridptr, "tlat");
gridSetName(gridptr->xname, "tlon");
gridSetName(gridptr->yname, "tlat");
}
else
{
gridSetXname(gridptr, "lon");
gridSetYname(gridptr, "lat");
gridSetName(gridptr->xname, "lon");
gridSetName(gridptr->yname, "lat");
}
gridSetXlongname(gridptr, "longitude");
gridSetYlongname(gridptr, "latitude");
gridSetName(gridptr->xlongname, "longitude");
gridSetName(gridptr->ylongname, "latitude");
/*
if ( gridtype == GRID_CURVILINEAR )
......@@ -323,8 +289,8 @@ cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
{
gridptr->xstdname = xystdname_tab[grid_xystdname_latlon][0];
gridptr->ystdname = xystdname_tab[grid_xystdname_latlon][1];
gridSetXunits(gridptr, "degrees_east");
gridSetYunits(gridptr, "degrees_north");
gridSetName(gridptr->xunits, "degrees_east");
gridSetName(gridptr->yunits, "degrees_north");
}
break;
......@@ -334,20 +300,20 @@ cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
/* Fall through */
case GRID_GME:
{
gridSetXname(gridptr, "lon");
gridSetYname(gridptr, "lat");
gridSetName(gridptr->xname, "lon");
gridSetName(gridptr->yname, "lat");
gridptr->xstdname = xystdname_tab[grid_xystdname_latlon][0];
gridptr->ystdname = xystdname_tab[grid_xystdname_latlon][1];
gridSetXunits(gridptr, "degrees_east");
gridSetYunits(gridptr, "degrees_north");
gridSetName(gridptr->xunits, "degrees_east");
gridSetName(gridptr->yunits, "degrees_north");
break;
}
case GRID_GENERIC:
{
/* gridptr->xsize = size; */
gridSetXname(gridptr, "x");
gridSetYname(gridptr, "y");
gridSetName(gridptr->xname, "x");
gridSetName(gridptr->yname, "y");
/*
strcpy(gridptr->xstdname, "grid_longitude");
strcpy(gridptr->ystdname, "grid_latitude");
......@@ -362,12 +328,12 @@ cdiGridTypeInit(grid_t *gridptr, int gridtype, int size)
case GRID_SINUSOIDAL:
case GRID_LAEA:
{
gridSetXname(gridptr, "x");
gridSetYname(gridptr, "y");
gridSetName(gridptr->xname, "x");
gridSetName(gridptr->yname, "y");
gridptr->xstdname = xystdname_tab[grid_xystdname_projection][0];
gridptr->ystdname = xystdname_tab[grid_xystdname_projection][1];
gridSetXunits(gridptr, "m");
gridSetYunits(gridptr, "m");
gridSetName(gridptr->xunits, "m");
gridSetName(gridptr->yunits, "m");
break;
}
}
......@@ -619,6 +585,30 @@ void gridName(int gridtype, char *gridname)
strcpy(gridname, gridNamePtr(gridtype));
}
/*
@Function gridDefXdimname
@Title Define the dimension name of a X-axis
@Prototype void gridDefXdimname(int gridID, const char *dimname)
@Parameter
@Item gridID Grid ID, from a previous call to @fref{gridCreate}.
@Item dimname Dimension name of the X-axis.
@Description
The function @func{gridDefXdimname} defines the dimension name of a X-axis.
@EndFunction
*/
void gridDefXdimname(int gridID, const char *xdimname)
{
if ( xdimname && *xdimname )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetName(gridptr->xdimname, xdimname);
gridMark4Update(gridID);
}
}
/*
@Function gridDefXname
@Title Define the name of a X-axis
......@@ -638,12 +628,11 @@ void gridDefXname(int gridID, const char *xname)
if ( xname && *xname )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetXname(gridptr, xname);
gridSetName(gridptr->xname, xname);
gridMark4Update(gridID);
}
}
/*
@Function gridDefXlongname
@Title Define the longname of a X-axis
......@@ -663,7 +652,7 @@ void gridDefXlongname(int gridID, const char *xlongname)
if ( xlongname )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetXlongname(gridptr, xlongname);
gridSetName(gridptr->xlongname, xlongname);
gridMark4Update(gridID);
}
}
......@@ -687,7 +676,31 @@ void gridDefXunits(int gridID, const char *xunits)
if ( xunits )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetXunits(gridptr, xunits);
gridSetName(gridptr->xunits, xunits);
gridMark4Update(gridID);
}
}
/*
@Function gridDefYdimname
@Title Define the dimension name of a Y-axis
@Prototype void gridDefYdimname(int gridID, const char *dimname)
@Parameter
@Item gridID Grid ID, from a previous call to @fref{gridCreate}.
@Item dimname Dimension name of the Y-axis.
@Description
The function @func{gridDefYdimname} defines the dimension name of a Y-axis.
@EndFunction
*/
void gridDefYdimname(int gridID, const char *ydimname)
{
if ( ydimname && *ydimname )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetName(gridptr->ydimname, ydimname);
gridMark4Update(gridID);
}
}
......@@ -711,7 +724,7 @@ void gridDefYname(int gridID, const char *yname)
if ( yname && *yname )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetYname(gridptr, yname);
gridSetName(gridptr->yname, yname);
gridMark4Update(gridID);
}
}
......@@ -735,7 +748,7 @@ void gridDefYlongname(int gridID, const char *ylongname)
if ( ylongname )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetYlongname(gridptr, ylongname);
gridSetName(gridptr->ylongname, ylongname);
gridMark4Update(gridID);
}
}
......@@ -759,7 +772,7 @@ void gridDefYunits(int gridID, const char *yunits)
if ( yunits )
{
grid_t *gridptr = gridID2Ptr(gridID);
gridSetYunits(gridptr, yunits);
gridSetName(gridptr->yunits, yunits);
gridMark4Update(gridID);
}
}
......
......@@ -98,6 +98,8 @@ struct grid_t {
short hasdims;
const char *xstdname;
const char *ystdname;
char xdimname[CDI_MAX_NAME];
char ydimname[CDI_MAX_NAME];
char xname[CDI_MAX_NAME];
char yname[CDI_MAX_NAME];
char xlongname[CDI_MAX_NAME];
......
......@@ -444,12 +444,14 @@ module mo_cdi
public :: gridInqXvals
public :: gridDefYvals
public :: gridInqYvals
public :: gridDefXdimname
public :: gridDefXname
public :: gridInqXname
public :: gridDefXlongname
public :: gridInqXlongname
public :: gridDefXunits
public :: gridInqXunits
public :: gridDefYdimname
public :: gridDefYname
public :: gridInqYname
public :: gridDefYlongname
......@@ -4901,6 +4903,26 @@ contains
end if
end function gridNamePtr
subroutine gridDefXdimname(gridID_dummy, xdimname_dummy)
integer(c_int), value :: gridID_dummy
character(kind = c_char, len = *), intent(in) :: xdimname_dummy
character(kind = c_char) :: xdimname_temp(len(xdimname_dummy) + 1)
integer :: xdimname_i
interface
subroutine lib_gridDefXdimname(gridID_dummy, xdimname_dummy) bind(c, name&
& = 'gridDefXdimname')
import c_char, c_int
integer(c_int), value :: gridID_dummy
character(kind = c_char) :: xdimname_dummy(*)
end subroutine lib_gridDefXdimname
end interface
do xdimname_i = 1, len(xdimname_dummy)
xdimname_temp(xdimname_i) = xdimname_dummy(xdimname_i:xdimname_i)
end do
xdimname_temp(len(xdimname_dummy) + 1) = c_null_char
call lib_gridDefXdimname(gridID_dummy, xdimname_temp)
end subroutine gridDefXdimname
subroutine gridDefXname(gridID_dummy, xname_dummy)
integer(c_int), value :: gridID_dummy
character(kind = c_char, len = *), intent(in) :: xname_dummy
......@@ -5054,6 +5076,26 @@ contains
end do
end subroutine gridInqXunits
subroutine gridDefYdimname(gridID_dummy, ydimname_dummy)
integer(c_int), value :: gridID_dummy
character(kind = c_char, len = *), intent(in) :: ydimname_dummy
character(kind = c_char) :: ydimname_temp(len(ydimname_dummy) + 1)
integer :: ydimname_i
interface
subroutine lib_gridDefYdimname(gridID_dummy, ydimname_dummy) bind(c, name&
& = 'gridDefYdimname')
import c_char, c_int
integer(c_int), value :: gridID_dummy
character(kind = c_char) :: ydimname_dummy(*)
end subroutine lib_gridDefYdimname
end interface
do ydimname_i = 1, len(ydimname_dummy)
ydimname_temp(ydimname_i) = ydimname_dummy(ydimname_i:ydimname_i)
end do
ydimname_temp(len(ydimname_dummy) + 1) = c_null_char
call lib_gridDefYdimname(gridID_dummy, ydimname_temp)
end subroutine gridDefYdimname
subroutine gridDefYname(gridID_dummy, yname_dummy)
integer(c_int), value :: gridID_dummy
character(kind = c_char, len = *), intent(in) :: yname_dummy
......
......@@ -5729,6 +5729,9 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
if ( xdimid == -1 && ydimid == -1 && grid->size == 1 )
gridDefHasDims(ncvars[ncvarid].gridID, FALSE);
if ( xdimid != -1 ) gridDefXdimname(ncvars[ncvarid].gridID, ncdims[xdimid].name);
if ( ydimid != -1 ) gridDefYdimname(ncvars[ncvarid].gridID, ncdims[ydimid].name);
if ( CDI_Debug )
Message("gridID %d %d %s", ncvars[ncvarid].gridID, ncvarid, ncvars[ncvarid].name);
......
Supports Markdown
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