# Metview Macro
# Define our range of dates
date_start = 2012-07-27
num_days = 16
# Build our set of dates and values for the curves
dates = nil
values_sin = nil
values_cos = nil
for i = 0 to num_days by hour(6) do
dates = dates & ([date_start + i])
values_sin = values_sin & [sin(i)]
values_cos = values_cos & [cos(i)]
end for
# graph plotting attributes
graph_attrib_sin = pgraph
(
legend : "on",
legend_user_text : "sin curve",
graph_line_colour : "blue",
graph_line_style : "dash"
)
graph_attrib_cos = pgraph
(
legend : "on",
legend_user_text : 'cos curve',
graph_line_colour : "red"
)
# define the curves and associate them with the plotting attributes
curve_def_sin = curve
(
x_values : dates,
y_values : values_sin,
attributes : graph_attrib_sin
)
curve_def_cos = curve
(
x_values : dates,
y_values : values_cos,
attributes : graph_attrib_cos
)
# define the plot's title and legend attributes
text_plot = ptext
(
text_automatic : "no",
text_user : "yes",
text_line_1 : "Example curve plot"
)
# Define the output media
to_screen = output
(
format : "screen"
)
to_psfile = output
(
format : "postscript",
destination : "file",
ncopies : 1,
file_name : "curves.ps"
)
# Check the runmode and decide which media to putput the plot to
mode = runmode()
if (mode = "execute") then setoutput(to_psfile)
else if (mode = "batch") then setoutput(to_psfile)
else if (mode = "visualise") then setoutput(to_screen)
else fail("Only execute, batch and visualise allowed")
end if
# Call function to build layout (defined at end of macro)
dw = build_layout (dates)
# Plot the curves
plot (dw, curve_def_sin,text_plot)
plot (dw, curve_def_cos,text_plot)
#################################################################
#
# End of Main Macro
#
#################################################################
# Function to build the layout
function build_layout(dates : list)
horizontal_axis = paxis
(
axis_type : 'date',
axis_date_min_value : dates [1],
axis_date_max_value : dates [count(dates)],
axis_date_type : 'days'
)
vertical_axis = paxis
(
axis_title_text : 'y-axis title',
axis_orientation : 'vertical'
)
curveview = curveview
(
horizontal_axis : horizontal_axis,
vertical_axis : vertical_axis
)
page1 = plot_page
(
view : curveview
)
_display_window_ = plot_superpage
(
pages : [page1]
)
return _display_window_
end build_layout