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