mirror of https://github.com/ecmwf/eccodes.git
ECC-1212: MARS key mapping for local time templates (Part 03)
This commit is contained in:
parent
34fd416e98
commit
0f6a86cc77
|
@ -85,6 +85,7 @@ if (numberOfForecastsUsedInLocalTime > 1) {
|
||||||
yearOfForecastUsedInLocalTime, monthOfForecastUsedInLocalTime, dayOfForecastUsedInLocalTime,
|
yearOfForecastUsedInLocalTime, monthOfForecastUsedInLocalTime, dayOfForecastUsedInLocalTime,
|
||||||
hourOfForecastUsedInLocalTime, minuteOfForecastUsedInLocalTime, secondOfForecastUsedInLocalTime):hidden;
|
hourOfForecastUsedInLocalTime, minuteOfForecastUsedInLocalTime, secondOfForecastUsedInLocalTime):hidden;
|
||||||
|
|
||||||
|
if (selectedIndex >=0 && selectedIndex < numberOfForecastsUsedInLocalTime) {
|
||||||
meta selectedYear element(yearOfForecastUsedInLocalTime, selectedIndex);
|
meta selectedYear element(yearOfForecastUsedInLocalTime, selectedIndex);
|
||||||
meta selectedMonth element(monthOfForecastUsedInLocalTime, selectedIndex);
|
meta selectedMonth element(monthOfForecastUsedInLocalTime, selectedIndex);
|
||||||
meta selectedDay element(dayOfForecastUsedInLocalTime, selectedIndex);
|
meta selectedDay element(dayOfForecastUsedInLocalTime, selectedIndex);
|
||||||
|
@ -105,4 +106,5 @@ if (numberOfForecastsUsedInLocalTime > 1) {
|
||||||
alias mars.date = dateOfForecastUsedInLocalTime : dump;
|
alias mars.date = dateOfForecastUsedInLocalTime : dump;
|
||||||
alias mars.time = timeOfForecastUsedInLocalTime : dump;
|
alias mars.time = timeOfForecastUsedInLocalTime : dump;
|
||||||
alias mars.step = endStep;
|
alias mars.step = endStep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sets val to the 'index' of the closes date */
|
||||||
static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -194,7 +195,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
long ymdLocal, hmsLocal, yearLocal, monthLocal, dayLocal, hourLocal, minuteLocal, secondLocal;
|
long ymdLocal, hmsLocal, yearLocal, monthLocal, dayLocal, hourLocal, minuteLocal, secondLocal;
|
||||||
double jLocal = 0;
|
double jLocal = 0;
|
||||||
double minDiff = DBL_MAX;
|
double minDiff = DBL_MAX;
|
||||||
size_t i = 0, minIndex = 0;
|
size_t i = 0;
|
||||||
size_t size = 0; /* number of elements in the array keys - should be = numberOfForecastsUsedInLocalTime */
|
size_t size = 0; /* number of elements in the array keys - should be = numberOfForecastsUsedInLocalTime */
|
||||||
|
|
||||||
/* These relate to the forecast dates and times in Section 4 */
|
/* These relate to the forecast dates and times in Section 4 */
|
||||||
|
@ -203,6 +204,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
grib_accessor_closest_date* self = (grib_accessor_closest_date*)a;
|
grib_accessor_closest_date* self = (grib_accessor_closest_date*)a;
|
||||||
grib_handle* h = grib_handle_of_accessor(a);
|
grib_handle* h = grib_handle_of_accessor(a);
|
||||||
grib_context* c = a->context;
|
grib_context* c = a->context;
|
||||||
|
*val = -1; /* initialise to an invalid index */
|
||||||
|
|
||||||
if ((err = grib_get_long_internal(h, self->numForecasts, &num_forecasts)) != GRIB_SUCCESS) return err;
|
if ((err = grib_get_long_internal(h, self->numForecasts, &num_forecasts)) != GRIB_SUCCESS) return err;
|
||||||
Assert(num_forecasts > 1);
|
Assert(num_forecasts > 1);
|
||||||
|
@ -215,8 +217,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
dayLocal = ymdLocal;
|
dayLocal = ymdLocal;
|
||||||
|
|
||||||
if ((err= grib_get_long(h, self->timeLocal, &hmsLocal)) != GRIB_SUCCESS) return err;
|
if ((err= grib_get_long(h, self->timeLocal, &hmsLocal)) != GRIB_SUCCESS) return err;
|
||||||
hourLocal = hmsLocal / 10000;
|
hourLocal = hmsLocal / 100;
|
||||||
hmsLocal %= 10000;
|
hmsLocal %= 100;
|
||||||
minuteLocal = hmsLocal / 100;
|
minuteLocal = hmsLocal / 100;
|
||||||
hmsLocal %= 100;
|
hmsLocal %= 100;
|
||||||
secondLocal = hmsLocal;
|
secondLocal = hmsLocal;
|
||||||
|
@ -256,37 +258,15 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||||
double jval = 0, diff = 0;
|
double jval = 0, diff = 0;
|
||||||
grib_datetime_to_julian(yearArray[i], monthArray[i], dayArray[i], hourArray[i], minuteArray[i], secondArray[i], &jval);
|
grib_datetime_to_julian(yearArray[i], monthArray[i], dayArray[i], hourArray[i], minuteArray[i], secondArray[i], &jval);
|
||||||
diff = jLocal - jval;
|
diff = jLocal - jval;
|
||||||
if (diff >0 && diff < minDiff) {
|
if (diff >= 0 && diff < minDiff) {
|
||||||
minDiff = diff;
|
minDiff = diff;
|
||||||
minIndex = i;
|
*val = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*val = minIndex;
|
if (*val == -1) {
|
||||||
//*val = 1;
|
grib_context_log(c, GRIB_LOG_ERROR, "Failed to find a date/time amongst forecasts used in local time");
|
||||||
|
return GRIB_DECODING_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return GRIB_SUCCESS;
|
return GRIB_SUCCESS;
|
||||||
//return GRIB_NOT_IMPLEMENTED;
|
|
||||||
#if 0
|
|
||||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date);
|
|
||||||
if (ret != GRIB_SUCCESS)
|
|
||||||
return ret;
|
|
||||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->hour, &hour);
|
|
||||||
if (ret != GRIB_SUCCESS)
|
|
||||||
return ret;
|
|
||||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->minute, &minute);
|
|
||||||
if (ret != GRIB_SUCCESS)
|
|
||||||
return ret;
|
|
||||||
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->second, &second);
|
|
||||||
if (ret != GRIB_SUCCESS)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
year = date / 10000;
|
|
||||||
date %= 10000;
|
|
||||||
month = date / 100;
|
|
||||||
date %= 100;
|
|
||||||
day = date;
|
|
||||||
|
|
||||||
ret = grib_datetime_to_julian(year, month, day, hour, minute, second, val);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,6 +227,7 @@
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_change_alternative_row_scanning.c" />
|
<ClCompile Include="..\..\..\src\grib_accessor_class_change_alternative_row_scanning.c" />
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_change_scanning_direction.c" />
|
<ClCompile Include="..\..\..\src\grib_accessor_class_change_scanning_direction.c" />
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_check_internal_version.c" />
|
<ClCompile Include="..\..\..\src\grib_accessor_class_check_internal_version.c" />
|
||||||
|
<ClCompile Include="..\..\..\src\grib_accessor_class_closest_date.c" />
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_codeflag.c" />
|
<ClCompile Include="..\..\..\src\grib_accessor_class_codeflag.c" />
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_codetable.c" />
|
<ClCompile Include="..\..\..\src\grib_accessor_class_codetable.c" />
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_codetable_title.c" />
|
<ClCompile Include="..\..\..\src\grib_accessor_class_codetable_title.c" />
|
||||||
|
|
|
@ -207,6 +207,9 @@
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_check_internal_version.c">
|
<ClCompile Include="..\..\..\src\grib_accessor_class_check_internal_version.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\src\grib_accessor_class_closest_date.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\..\src\grib_accessor_class_codeflag.c">
|
<ClCompile Include="..\..\..\src\grib_accessor_class_codeflag.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
Loading…
Reference in New Issue