Commit 0b600b6d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Refactor cdf_define_code_and_param().

parent 5fd27bfa
......@@ -3042,6 +3042,43 @@ void cdf_sort_varname(int *varids, const int nvars, const ncvar_t *ncvars)
for ( int i = 0; i < nvars; i++ ) Message("sorted varids[%d] = %d", i, varids[i]);
}
static
void cdf_define_code_and_param(int vlistID, int varID)
{
if ( vlistInqVarCode(vlistID, varID) == -varID-1 )
{
char name[CDI_MAX_NAME]; name[0] = 0;
vlistInqVarName(vlistID, varID, name);
const size_t len = strlen(name);
if ( len > 3 && isdigit((int) name[3]) )
{
if ( strStartsWith(name, "var") )
{
vlistDefVarCode(vlistID, varID, atoi(name+3));
// vlistDestroyVarName(vlistID, varID);
}
}
else if ( len > 4 && isdigit((int) name[4]) )
{
if ( strStartsWith(name, "code") )
{
vlistDefVarCode(vlistID, varID, atoi(name+4));
// vlistDestroyVarName(vlistID, varID);
}
}
else if ( len > 5 && isdigit((int) name[5]) )
{
if ( strStartsWith(name, "param") )
{
int pnum = -1, pcat = 255, pdis = 255;
sscanf(name+5, "%d.%d.%d", &pnum, &pcat, &pdis);
vlistDefVarParam(vlistID, varID, cdiEncodeParam(pnum, pcat, pdis));
// vlistDestroyVarName(vlistID, varID);
}
}
}
}
static
void cdf_define_institut_and_model_id(int vlistID, int varID)
{
......@@ -3233,41 +3270,7 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
if ( varids ) Free(varids);
for ( int varID = 0; varID < nvars; varID++ )
{
if ( vlistInqVarCode(vlistID, varID) == -varID-1 )
{
char name[CDI_MAX_NAME]; name[0] = 0;
vlistInqVarName(vlistID, varID, name);
const size_t len = strlen(name);
if ( len > 3 && isdigit((int) name[3]) )
{
if ( strStartsWith(name, "var") )
{
vlistDefVarCode(vlistID, varID, atoi(name+3));
// vlistDestroyVarName(vlistID, varID);
}
}
else if ( len > 4 && isdigit((int) name[4]) )
{
if ( strStartsWith(name, "code") )
{
vlistDefVarCode(vlistID, varID, atoi(name+4));
// vlistDestroyVarName(vlistID, varID);
}
}
else if ( len > 5 && isdigit((int) name[5]) )
{
if ( strStartsWith(name, "param") )
{
int pnum = -1, pcat = 255, pdis = 255;
sscanf(name+5, "%d.%d.%d", &pnum, &pcat, &pdis);
vlistDefVarParam(vlistID, varID, cdiEncodeParam(pnum, pcat, pdis));
// vlistDestroyVarName(vlistID, varID);
}
}
}
}
for ( int varID = 0; varID < nvars; varID++ ) cdf_define_code_and_param(vlistID, varID);
for ( int varID = 0; varID < nvars; varID++ ) cdf_define_institut_and_model_id(vlistID, varID);
}
......
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