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

Changed clevels to cvals and all strings do not contain termination 0

parent 123d4138
......@@ -1019,8 +1019,8 @@ int zaxisInqLevels(int zaxisID, double levels[]);
/* zaxisInqCLen: Get maximal string length of character Z-axis */
int zaxisInqCLen(int zaxisID);
/* zaxisInqCLevels: Get all string values of a character Z-axis */
int zaxisInqCLevels(int zaxisID, char ***clevels);
/* zaxisInqCVals: Get all string values of a character Z-axis */
int zaxisInqCVals(int zaxisID, char ***clevels);
/* zaxisDefLevel: Define one level of a Z-axis */
void zaxisDefLevel(int zaxisID, int levelID, double levels);
......
......@@ -1447,7 +1447,7 @@ void cdfDefZaxisChar(stream_t *streamptr, int zaxisID, char *axisname, int *dimI
/* Get Stringvalues */
char **cvals = NULL;
cvals = zaxisInqCLevelsPtr(zaxisID);
cvals = zaxisInqCValsPtr(zaxisID);
if ( cvals )
{
......
......@@ -624,12 +624,13 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
if ( zaxisType == ZAXIS_CHAR )
{
cvals1 = zaxisInqCLevelsPtr(zaxisID);
cvals1 = zaxisInqCValsPtr(zaxisID);
size_t clen1 = (size_t)zaxisInqCLen(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] == ' ' )
size_t testlen = clen1;
while ( cvals1[levID][testlen] == ' ' )
testlen--;
if ( clen2 < testlen )
clen2 = testlen;
......@@ -640,9 +641,8 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
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;
cvals2[levID2] = Malloc((size_t)(clen2) * sizeof (char));
memcpy(cvals2[levID2], cvals1[levID], clen2*sizeof(char));
levID2++;
}
}
......
......@@ -790,16 +790,13 @@ void zaxisDefCvals(int zaxisID, const char **cvals, size_t clen)
if ( cvals && clen )
{
if ( zaxisptr->cvals != NULL )
zaxisptr->cvals = NULL;
zaxisptr->clength = clen;
zaxisptr->cvals = (char**) Malloc(size*sizeof(char *));
for ( size_t ilev = 0; ilev < size; ++ilev )
{
zaxisptr->cvals[ilev] = Malloc((clen+1)*sizeof(char));
memcpy(zaxisptr->cvals[ilev],cvals[ilev], clen);
zaxisptr->cvals[ilev][clen] = '\0';
zaxisptr->cvals[ilev] = Malloc(clen*sizeof(char));
memcpy(zaxisptr->cvals[ilev],cvals[ilev], clen*sizeof(char));
}
reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
}
......@@ -999,7 +996,7 @@ const double *zaxisInqLevelsPtr(int zaxisID)
}
char **zaxisInqCLevelsPtr(int zaxisID)
char **zaxisInqCValsPtr(int zaxisID)
{
char **cvals = NULL;
zaxis_t *zaxisptr = zaxis_to_pointer(zaxisID);
......@@ -1051,7 +1048,7 @@ int zaxisInqCLen(int zaxisID)
return size;
}
int zaxisInqCLevels(int zaxisID, char ***clevels)
int zaxisInqCVals(int zaxisID, char ***clevels)
{
int size = 0;
size_t clen = 0;
......@@ -1061,14 +1058,13 @@ int zaxisInqCLevels(int zaxisID, char ***clevels)
{
size = zaxisptr->size;
clen = zaxisptr->clength;
if ( clevels && size && clen )
if ( size && clen )
{
(*clevels) = Malloc(size*sizeof(char*));
for ( int i = 0; i < size; i++ )
{
(*clevels)[i] = Malloc((clen+1)*sizeof(char));
memcpy((*clevels)[i], zaxisptr->cvals[i], clen);
(*clevels)[i][clen] = '\0';
(*clevels)[i] = Malloc(clen*sizeof(char));
memcpy((*clevels)[i], zaxisptr->cvals[i], clen*sizeof(char));
}
}
}
......
......@@ -64,7 +64,7 @@ const resOps *getZaxisOps(void);
const char *zaxisInqNamePtr(int zaxisID);
const double *zaxisInqLevelsPtr(int zaxisID);
char **zaxisInqCLevelsPtr(int zaxisID);
char **zaxisInqCValsPtr(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