# Metview Macro

#  **************************** LICENSE START ***********************************
# 
#  Copyright 2015 ECMWF. This software is distributed under the terms
#  of the Apache License version 2.0. In applying this license, ECMWF does not
#  waive the privileges and immunities granted to it by virtue of its status as
#  an Intergovernmental Organization or submit itself to any jurisdiction.
# 
#  ***************************** LICENSE END ************************************

lat = 51
lon = 1


fs = read("t2m_forecast_24.grib")
vals = nearest_gridpoint(fs, lat, lon)
print(vals)


# extract the date & time from the fields 
dates = valid_date(fs)
print(dates)


time_series_fc = input_visualiser(
    input_x_type        : "date",
    input_y_values      : vals,
    input_date_x_values : dates
    )

graph_fc = mgraph(
    legend               : "on",
    legend_user_text     : "+24h forecast",
    graph_line_colour    : "sky",
    graph_line_thickness : 3
    )

#plot(time_series, graph_fc)


# -----------------------------------------------
# Now do everything again for the analysis data!
# Note that it would be better to do most of the
# work within a function which we could re-use.
# -----------------------------------------------

fs = read("t2m_analysis.grib")
vals = nearest_gridpoint(fs, lat, lon)
print(vals)


date_list = valid_date(fs)
print(date_list)


time_series_an = input_visualiser(
    input_x_type        : "date",
    input_y_values      : vals,
    input_date_x_values : date_list
    )

graph_an = mgraph(
    legend               : "on",
    legend_user_text     : "analysis",
    graph_line_colour    : "red",
    graph_line_thickness : 3
    )

legend = mlegend(legend_display_type : "disjoint",
                 legend_text_font_size : 0.5)

time_axis = maxis(
    axis_type                : "date",
    axis_line_colour         : "black",
    axis_tick_label_height   : 0.5,
    axis_years_label_height  : 0.3,
    axis_months_label_height : 0.3,
    axis_days_label_height   : 0.3
    )


plot(time_series_fc, graph_fc, time_series_an, graph_an, legend, time_axis)



