Commit c03ae90d authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Added a function to define a character z-axis

parent 3c70e59a
......@@ -1414,6 +1414,70 @@ void cdfDefZaxisUUID(stream_t *streamptr, int zaxisID)
}
}
static
void cdfDefZaxisChar(stream_t *streamptr, int zaxisID, char *axisname, int *dimID, size_t dimlen, int xtype, int zaxisindex)
{
int fileID = streamptr->fileID;
int ncvarID = CDI_UNDEFID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
/* Check StrlenID */
char strlen[7] = "strlen\0";
size_t clen = (size_t) zaxisInqCLen(zaxisID);
if ( clen == 0 )
Error("Maximal string length value is 0.\nA given character axis requires a dimension to save the maximal string length.");
int strlenID = CDI_UNDEFID;
strlenID = checkDimName(fileID, clen, strlen);
if ( strlenID == CDI_UNDEFID ) cdf_def_dim(fileID, strlen, clen, &strlenID);
/* Check 'areatype'dimID */
char dimname[CDI_MAX_NAME+3]; dimname[0] = 0;
cdiZaxisInqKeyStr(zaxisID, CDI_KEY_DIMNAME, CDI_MAX_NAME, dimname);
*dimID = checkDimName(fileID, dimlen, dimname);
if ( !(dimlen > 1) )
Error("A character axis requires at least 2 strings.");
if ( dimname[0] == 0 ) { memcpy(dimname, "area_type", 10); dimname[10] = 0; }
if ( *dimID == CDI_UNDEFID ) cdf_def_dim(fileID, dimname, dimlen, dimID);
int dimIDs[2];
dimIDs[0] = *dimID;
dimIDs[1] = strlenID;
/* Get Stringvalues */
char **cvals = NULL;
cvals = zaxisInqCLevelsPtr(zaxisID);
if ( cvals )
{
/* Define variable and its attributes */
cdf_def_var(fileID, axisname, NC_CHAR, 2, dimIDs, &ncvarID);
cdfPutGridStdAtts(fileID, ncvarID, zaxisID, 'Z', &gridInqsZ);
cdf_put_att_text(fileID, ncvarID, "axis", 1, "Z");
cdfDefineAttributes(zaxisID, CDI_GLOBAL, fileID, ncvarID);
streamptr->nczvarID[zaxisindex] = ncvarID;
/* Write Stringvalues */
int status = 0;
size_t start[2], count[2];
start[1] = 0;
count[0] = 1;
count[1] = clen;
for (int i = 0; i < dimlen; i++)
{
start[0] = i;
status = nc_put_vara_text(fileID, ncvarID, start, count, cvals[i]);
}
}
cdf_enddef(fileID);
streamptr->ncmode = 2;
}
static
void cdfDefZaxis(stream_t *streamptr, int zaxisID)
{
......@@ -1487,6 +1551,8 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
cdfDefineAttributes(zaxisID, CDI_GLOBAL, fileID, ncvarid);
if ( natts > 0 && streamptr->ncmode == 2 ) cdf_enddef(fileID);
}
else if ( type == ZAXIS_CHAR )
cdfDefZaxisChar(streamptr, zaxisID, axisname, &dimID, dimlen, xtype, zaxisindex);
else
{
dimID = checkDimName(fileID, dimlen, dimname);
......@@ -1581,7 +1647,7 @@ void cdf_def_mapping(stream_t *streamptr, int gridID)
cdiGridInqKeyStr(gridID, CDI_KEY_MAPPING, CDI_MAX_NAME, gmapvarname);
int fileID = streamptr->fileID;
cdf_redef(fileID);
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
int ncvarid;
int ncerrcode = nc_def_var(fileID, gmapvarname, (nc_type) NC_INT, 0, NULL, &ncvarid);
......
......@@ -21,6 +21,7 @@ typedef struct {
zkey_double_t p0value;
double *vals;
char **cvals;
int clength;
double *lbounds;
double *ubounds;
double *weights;
......@@ -63,6 +64,7 @@ const resOps *getZaxisOps(void);
const char *zaxisInqNamePtr(int zaxisID);
const double *zaxisInqLevelsPtr(int zaxisID);
char **zaxisInqCLevelsPtr(int zaxisID);
void zaxisResize(int zaxisID, int size);
......
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