Commit 6970e2d2 authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Added zaxistype CHAR in generate_zaxis

parent fb8701f2
...@@ -1435,8 +1435,8 @@ void cdfDefZaxisChar(stream_t *streamptr, int zaxisID, char *axisname, int *dimI ...@@ -1435,8 +1435,8 @@ void cdfDefZaxisChar(stream_t *streamptr, int zaxisID, char *axisname, int *dimI
char dimname[CDI_MAX_NAME+3]; dimname[0] = 0; char dimname[CDI_MAX_NAME+3]; dimname[0] = 0;
cdiZaxisInqKeyStr(zaxisID, CDI_KEY_DIMNAME, CDI_MAX_NAME, dimname); cdiZaxisInqKeyStr(zaxisID, CDI_KEY_DIMNAME, CDI_MAX_NAME, dimname);
*dimID = checkDimName(fileID, dimlen, dimname); *dimID = checkDimName(fileID, dimlen, dimname);
if ( !(dimlen > 1) ) if ( !(dimlen > 0) )
Error("A character axis requires at least 2 strings."); Error("No strings delivered for a character axis.");
if ( dimname[0] == 0 ) { memcpy(dimname, "area_type", 10); dimname[10] = 0; } if ( dimname[0] == 0 ) { memcpy(dimname, "area_type", 10); dimname[10] = 0; }
if ( *dimID == CDI_UNDEFID ) cdf_def_dim(fileID, dimname, dimlen, dimID); if ( *dimID == CDI_UNDEFID ) cdf_def_dim(fileID, dimname, dimlen, dimID);
......
...@@ -443,7 +443,8 @@ vgzZAxisSearch(int id, void *res, void *data) ...@@ -443,7 +443,8 @@ vgzZAxisSearch(int id, void *res, void *data)
static static
int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double *levels, int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double *levels,
const double *lbounds, const double *ubounds, int vctsize, const double *vct) const double *lbounds, const double *ubounds, int vctsize, const double *vct,
const char **cvals, size_t clen)
{ {
int zaxisID = CDI_UNDEFID; int zaxisID = CDI_UNDEFID;
bool zaxisdefined = false; bool zaxisdefined = false;
...@@ -485,6 +486,10 @@ int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double * ...@@ -485,6 +486,10 @@ int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double *
{ {
zaxisID = zaxisCreate(zaxistype, nlevels); zaxisID = zaxisCreate(zaxistype, nlevels);
zaxisDefLevels(zaxisID, levels); zaxisDefLevels(zaxisID, levels);
if ( zaxistype == ZAXIS_CHAR )
zaxisDefCvals(zaxisID, cvals, clen);
if ( has_bounds ) if ( has_bounds )
{ {
zaxisDefLbounds(zaxisID, lbounds); zaxisDefLbounds(zaxisID, lbounds);
...@@ -581,6 +586,8 @@ void vlistCopyFlag(int vlistID2, int vlistID1) ...@@ -581,6 +586,8 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
{ {
int nvct = 0; int nvct = 0;
double *levels = NULL; double *levels = NULL;
char **cvals1 = NULL, **cvals2 = NULL;
size_t clen2 = 0;
double *lbounds = NULL, *ubounds = NULL; double *lbounds = NULL, *ubounds = NULL;
const double *vct = NULL; const double *vct = NULL;
char ctemp[CDI_MAX_NAME]; char ctemp[CDI_MAX_NAME];
...@@ -598,6 +605,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1) ...@@ -598,6 +605,7 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vars1[varID].levinfo[levID].mlevelID = levID2; vars1[varID].levinfo[levID].mlevelID = levID2;
} }
if ( zaxisInqLevels(zaxisID, NULL) ) if ( zaxisInqLevels(zaxisID, NULL) )
{ {
levels = (double *) Malloc((size_t)nlevs2 * sizeof (double)); levels = (double *) Malloc((size_t)nlevs2 * sizeof (double));
...@@ -605,10 +613,8 @@ void vlistCopyFlag(int vlistID2, int vlistID1) ...@@ -605,10 +613,8 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
levID2 = 0; levID2 = 0;
for ( int levID = 0; levID < nlevs; ++levID ) for ( int levID = 0; levID < nlevs; ++levID )
if ( vars1[varID].levinfo[levID].flag ) if ( vars1[varID].levinfo[levID].flag )
{
levels[levID2++] = zaxisInqLevel(zaxisID, levID); levels[levID2++] = zaxisInqLevel(zaxisID, levID);
} }
}
if ( zaxisType == ZAXIS_HYBRID ) if ( zaxisType == ZAXIS_HYBRID )
{ {
...@@ -616,6 +622,31 @@ void vlistCopyFlag(int vlistID2, int vlistID1) ...@@ -616,6 +622,31 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vct = zaxisInqVctPtr(zaxisID); vct = zaxisInqVctPtr(zaxisID);
} }
if ( zaxisType == ZAXIS_CHAR )
{
cvals1 = zaxisInqCLevelsPtr(zaxisID);
for ( int levID = 0; levID < nlevs; ++levID )
if ( vars1[varID].levinfo[levID].flag )
{
size_t testlen = (size_t) strlen(cvals1[levID]);
while ( cvals1[levID][testlen-1] == ' ' )
testlen--;
if ( clen2 < testlen )
clen2 = testlen;
}
cvals2 = (char **) Malloc((size_t)nlevs2 * sizeof (char *));
levID2 = 0;
for ( int levID = 0; levID < nlevs; ++levID )
if ( vars1[varID].levinfo[levID].flag )
{
cvals2[levID2] = Malloc((size_t)(clen2+1) * sizeof (char));
strcpy(cvals2[levID2], cvals1[levID]);
cvals2[levID2][clen2] = 0;
levID2++;
}
}
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) ) if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{ {
lbounds = (double *) Malloc(2 * (size_t)nlevs2 * sizeof (double)); lbounds = (double *) Malloc(2 * (size_t)nlevs2 * sizeof (double));
...@@ -639,9 +670,15 @@ void vlistCopyFlag(int vlistID2, int vlistID1) ...@@ -639,9 +670,15 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
Free(lbounds1); Free(lbounds1);
} }
int zaxisID2 = vlist_generate_zaxis(vlistID2, zaxisType, nlevs2, levels, lbounds, ubounds, nvct, vct); int zaxisID2 = vlist_generate_zaxis(vlistID2, zaxisType, nlevs2, levels, lbounds, ubounds, nvct, vct, (const char **)cvals2, clen2);
if ( levels ) Free(levels); if ( levels ) Free(levels);
if ( lbounds ) Free(lbounds); if ( lbounds ) Free(lbounds);
if ( cvals2 )
{
for ( int levID = 0; levID < nlevs2; ++levID )
Free(cvals2[levID]);
Free(cvals2);
}
zaxisInqName(zaxisID, ctemp); zaxisInqName(zaxisID, ctemp);
zaxisDefName(zaxisID2, ctemp); zaxisDefName(zaxisID2, ctemp);
...@@ -650,6 +687,14 @@ void vlistCopyFlag(int vlistID2, int vlistID1) ...@@ -650,6 +687,14 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
zaxisInqUnits(zaxisID, ctemp); zaxisInqUnits(zaxisID, ctemp);
zaxisDefUnits(zaxisID2, ctemp); zaxisDefUnits(zaxisID2, ctemp);
if ( zaxisType == ZAXIS_CHAR )
{
char dimname[CDI_MAX_NAME+3]; dimname[0] = 0;
cdiZaxisInqKeyStr(zaxisID, CDI_KEY_DIMNAME, CDI_MAX_NAME, dimname);
if ( dimname[0] == 0 ) { memcpy(dimname, "area_type", 10); dimname[10] = 0; }
cdiZaxisDefKeyStr(zaxisID2, CDI_KEY_DIMNAME, CDI_MAX_NAME, dimname);
}
if ( zaxisType == ZAXIS_GENERIC ) zaxisDefLtype(zaxisID2, zaxisInqLtype(zaxisID)); if ( zaxisType == ZAXIS_GENERIC ) zaxisDefLtype(zaxisID2, zaxisInqLtype(zaxisID));
zaxisID = zaxisID2; zaxisID = zaxisID2;
......
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