Commit 1b781cd0 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function tableInqEntry().

parent 6ffe1bf8
......@@ -438,9 +438,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
vlistInqVarUnits(vlistID, varID, units);
int tableID = vlistInqVarTable(vlistID, varID);
if ( !name[0] ) tableInqParName(tableID, code, name);
if ( !longname[0] ) tableInqParLongname(tableID, code, longname);
if ( !units[0] ) tableInqParUnits(tableID, code, units);
if ( !name[0] ) tableInqEntry(tableID, code, -1, name, longname, units);
if ( name[0] )
{
sprintf(varname, "%s", name);
......
......@@ -1218,8 +1218,9 @@ int tableInqNumber(void);
int tableInqNum(int tableID);
int tableInqModel(int tableID);
void tableInqEntry(int tableID, int id, int ltype, char *name, char *longname, char *units);
int tableInqParCode(int tableID, char *name, int *code);
int tableInqParName(int tableID, int code, char *name);
int tableInqParLongname(int tableID, int code, char *longname);
int tableInqParUnits(int tableID, int code, char *units);
......
......@@ -3267,9 +3267,11 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
int code = vlistInqVarCode(vlistID, varID);
if ( cdiDefaultTableID != CDI_UNDEFID )
{
char buf[CDI_MAX_NAME]; buf[0] = 0;
tableInqParName(cdiDefaultTableID, code, buf);
if ( buf[0] )
char name[CDI_MAX_NAME]; name[0] = 0;
char longname[CDI_MAX_NAME]; longname[0] = 0;
char units[CDI_MAX_NAME]; units[0] = 0;
tableInqEntry(cdiDefaultTableID, code, -1, name, longname, units);
if ( name[0] )
{
vlistDestroyVarName(vlistID, varID);
vlistDestroyVarLongname(vlistID, varID);
......@@ -3277,13 +3279,9 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
if ( varTableID != CDI_UNDEFID )
{
vlistDefVarName(vlistID, varID, buf);
buf[0] = 0;
tableInqParLongname(cdiDefaultTableID, code, buf);
if ( buf[0] ) vlistDefVarLongname(vlistID, varID, buf);
buf[0] = 0;
tableInqParUnits(cdiDefaultTableID, code, buf);
if ( buf[0] ) vlistDefVarUnits(vlistID, varID, buf);
vlistDefVarName(vlistID, varID, name);
if ( longname[0] ) vlistDefVarLongname(vlistID, varID, longname);
if ( units[0] ) vlistDefVarUnits(vlistID, varID, units);
}
else
{
......
......@@ -776,51 +776,50 @@ void tableFWriteC(FILE *ptfp, int tableID)
}
int tableInqParCode(int tableID, char *varname, int *code)
void tableInqEntry(int tableID, int id, int ltype, char *name, char *longname, char *units)
{
int err = 1;
if ( ((tableID >= 0) & (tableID < MAX_TABLE)) | (tableID == CDI_UNDEFID) ) { } else
Error("Invalid table ID %d", tableID);
if ( tableID != CDI_UNDEFID && varname != NULL )
if ( tableID != CDI_UNDEFID )
{
int npars = parTable[tableID].npars;
for ( int item = 0; item < npars; item++ )
{
if ( parTable[tableID].pars[item].name
&& strcmp(parTable[tableID].pars[item].name, varname) == 0 )
{
*code = parTable[tableID].pars[item].id;
err = 0;
break;
}
if ( parTable[tableID].pars[item].id == id )
{
if ( name && parTable[tableID].pars[item].name )
strcpy(name, parTable[tableID].pars[item].name);
if ( longname && parTable[tableID].pars[item].longname )
strcpy(longname, parTable[tableID].pars[item].longname);
if ( units && parTable[tableID].pars[item].units )
strcpy(units, parTable[tableID].pars[item].units);
break;
}
}
}
return err;
}
int tableInqParName(int tableID, int code, char *varname)
int tableInqParCode(int tableID, char *varname, int *code)
{
int err = 1;
if ( tableID >= 0 && tableID < MAX_TABLE )
if ( tableID != CDI_UNDEFID && varname != NULL )
{
int npars = parTable[tableID].npars;
for ( int item = 0; item < npars; item++ )
{
if ( parTable[tableID].pars[item].id == code )
{
if ( parTable[tableID].pars[item].name )
strcpy(varname, parTable[tableID].pars[item].name); //FIXME: This may overrun the supplied buffer!
if ( parTable[tableID].pars[item].name
&& strcmp(parTable[tableID].pars[item].name, varname) == 0 )
{
*code = parTable[tableID].pars[item].id;
err = 0;
break;
}
break;
}
}
}
else if ( tableID == CDI_UNDEFID )
{ }
else
Error("Invalid table ID %d", tableID);
return err;
}
......
......@@ -802,22 +802,16 @@ void cdi_generate_vars(stream_t *streamptr)
int pdis, pcat, pnum;
cdiDecodeParam(param, &pnum, &pcat, &pdis);
char name[CDI_MAX_NAME]; name[0] = 0;
tableInqParName(cdiDefaultTableID, pnum, name);
char longname[CDI_MAX_NAME]; longname[0] = 0;
char units[CDI_MAX_NAME]; units[0] = 0;
tableInqEntry(cdiDefaultTableID, pnum, -1, name, longname, units);
if ( name[0] )
{
if ( tableID != CDI_UNDEFID )
{
vlistDefVarName(vlistID, varID, name);
{
char longname[CDI_MAX_NAME]; longname[0] = 0;
tableInqParLongname(cdiDefaultTableID, pnum, longname);
if ( longname[0] ) vlistDefVarLongname(vlistID, varID, longname);
}
{
char units[CDI_MAX_NAME]; units[0] = 0;
tableInqParUnits(cdiDefaultTableID, pnum, units);
if ( units[0] ) vlistDefVarUnits(vlistID, varID, units);
}
if ( longname[0] ) vlistDefVarLongname(vlistID, varID, longname);
if ( units[0] ) vlistDefVarUnits(vlistID, varID, units);
}
else
tableID = cdiDefaultTableID;
......
......@@ -474,8 +474,9 @@ void vlistInqVarName(int vlistID, int varID, char *name)
{
int code = pnum;
int tableID = vlistptr->vars[varID].tableID;
if ( tableInqParName(tableID, code, name) != 0 )
sprintf(name, "var%d", code);
name[0] = 0;
tableInqEntry(tableID, code, -1, name, NULL, NULL);
if ( !name[0] ) sprintf(name, "var%d", code);
}
else
{
......@@ -525,7 +526,7 @@ char* vlistCopyVarName(int vlistId, int varId)
{
int tableId = vlistptr->vars[varId].tableID;
char name[CDI_MAX_NAME]; name[0] = 0;
tableInqParName(tableId, number, name);
tableInqEntry(tableId, number, -1, name, NULL, NULL);
if ( name[0] )
result = strdup(name);
else
......
......@@ -5,6 +5,7 @@
int main()
{
assert(tableInqParName(-1, -1, NULL) != 0);
tableInqEntry(-1, -1, -1, NULL, NULL, NULL);
//assert(tableInqEntry(-1, -1, -1, NULL, NULL, NULL) != 0);
return EXIT_SUCCESS;
}
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