Commit 7b08cf44 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added function cdiParamToString

parent fa3e59af
......@@ -260,7 +260,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
zaxisID = vlistInqVarZaxis(vlistID, varID);
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(code, tabnum, 255);
param2str(param, paramstr, sizeof(paramstr));
cdiParamToString(param, paramstr, sizeof(paramstr));
if ( vardis ) vlistInqVarName(vlistID, varID, varname);
......@@ -894,7 +894,7 @@ int main(int argc, char *argv[])
tabnum = tableInqNum(vlistInqVarTable(vlistID1, varID));
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(code, tabnum, 255);
param2str(param, paramstr, sizeof(paramstr));
cdiParamToString(param, paramstr, sizeof(paramstr));
if ( Vardis ) vlistInqVarName(vlistID1, varID, varname);
else strcpy(varname, paramstr);
......@@ -934,7 +934,7 @@ int main(int argc, char *argv[])
tabnum = tableInqNum(vlistInqVarTable(vlistID1, varID));
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(code, tabnum, 255);
param2str(param, paramstr, sizeof(paramstr));
cdiParamToString(param, paramstr, sizeof(paramstr));
if ( Vardis ) vlistInqVarName(vlistID1, varID, varname);
else strcpy(varname, paramstr);
......
......@@ -31,26 +31,6 @@ void time2str(int time, char *timestr, int maxlen)
}
void param2str(int param, char *paramstr, int maxlen)
{
static char func[] = "param2str";
int dis, cat, num;
int len;
cdiDecodeParam(param, &num, &cat, &dis);
if ( dis == 255 && (cat == 255 || cat == 0 ) )
len = sprintf(paramstr, "%d", num);
else if ( dis == 255 )
len = sprintf(paramstr, "%d.%d", num, cat);
else
len = sprintf(paramstr, "%d.%d.%d", num, cat, dis);
if ( len > ( maxlen-1) )
fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", func);
}
void printFiletype(int streamID, int vlistID)
{
int filetype;
......
......@@ -182,7 +182,9 @@ void cdiDefGlobal(const char *string, int val);
/* CDI converter routines */
/* param format: DDDCCCNNN */
/* parameter */
void cdiParamToString(int param, char *paramstr, int maxlen);
void cdiDecodeParam(int param, int *pnum, int *pcat, int *pdis);
int cdiEncodeParam(int pnum, int pcat, int pdis);
......
#include <stdio.h>
void cdiDecodeParam(int param, int *pnum, int *pcat, int *pdis)
{
unsigned int *uparam = (unsigned int *) &param;
......@@ -72,3 +74,23 @@ int cdiEncodeTime(int hour, int minute, int second)
return (time);
}
void cdiParamToString(int param, char *paramstr, int maxlen)
{
static char func[] = "cdiParamToString";
int dis, cat, num;
int len;
cdiDecodeParam(param, &num, &cat, &dis);
if ( dis == 255 && (cat == 255 || cat == 0 ) )
len = sprintf(paramstr, "%d", num);
else if ( dis == 255 )
len = sprintf(paramstr, "%d.%d", num, cat);
else
len = sprintf(paramstr, "%d.%d.%d", num, cat, dis);
if ( len > ( maxlen-1) )
fprintf(stderr, "Internal problem (%s): size of input string is too small!\n", func);
}
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