Commit d976d55a authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Use table instead of conditionals.

parent 32a04d02
...@@ -766,21 +766,26 @@ void cdfDefForecastTimeUnits(char *unitstr, int timeunit) ...@@ -766,21 +766,26 @@ void cdfDefForecastTimeUnits(char *unitstr, int timeunit)
static static
void cdfDefCalendar(int fileID, int ncvarid, int calendar) void cdfDefCalendar(int fileID, int ncvarid, int calendar)
{ {
size_t len; size_t len = 0;
char calstr[80]; const char *calstr;
static const struct { int calCode; const char *calStr; } calTab[] = {
calstr[0] = 0; { CALENDAR_STANDARD, "standard" },
{ CALENDAR_PROLEPTIC, "proleptic_gregorian" },
if ( calendar == CALENDAR_STANDARD ) strcpy(calstr, "standard"); { CALENDAR_NONE, "none" },
else if ( calendar == CALENDAR_PROLEPTIC ) strcpy(calstr, "proleptic_gregorian"); { CALENDAR_360DAYS, "360_day" },
else if ( calendar == CALENDAR_NONE ) strcpy(calstr, "none"); { CALENDAR_365DAYS, "365_day" },
else if ( calendar == CALENDAR_360DAYS ) strcpy(calstr, "360_day"); { CALENDAR_366DAYS, "366_day" },
else if ( calendar == CALENDAR_365DAYS ) strcpy(calstr, "365_day"); };
else if ( calendar == CALENDAR_366DAYS ) strcpy(calstr, "366_day"); enum { calTabSize = sizeof calTab / sizeof calTab[0] };
len = strlen(calstr); for (size_t i = 0; i < calTabSize; ++i)
if (calTab[i].calCode == calendar)
if ( len ) cdf_put_att_text(fileID, ncvarid, "calendar", len, calstr); {
calstr = calTab[i].calStr;
len = strlen(calstr);
cdf_put_att_text(fileID, ncvarid, "calendar", len, calstr);
break;
}
} }
......
Supports Markdown
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