# Metview Macro

# **************************** LICENSE START ***********************************
#
# Copyright 2012 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 ************************************

# **************************************************************************
# Function      : mvl_regular_layout
#
# Syntax        : list mvl_regular_layout (definition, number, number,
#                                          number, number)
#
# Author (date) : Anonymous (--/--/2003)
#
# Category      : LAYOUT
#
# OneLineDesc   : Generates a regular grid of frames/subframes
#
# Description   : Creates a list of frames, arranged in a regular grid.
#                 Each frame contains a set of 1 or more subframes, each
#                 arranged in a regular mxn grid. The output is suitable for
#                 input into the function plot_superpage().
#
# Parameters    : the_view    - a view definition to be used with each frame
#                 frame_cols  - the number of frames along the width
#                 frame_rows  - the number of frames along the height
#                 subframe_cols - the number of subframes along the width
#                                 of each frame.
#                 subframe_rows - the number of subframes along the height
#                                 of each frame.
#
# Return Value  : The list of frames
#
# Dependencies  : mvl_mxn_subframes
#
# Example Usage : 
#                 # create a set of frames using the default map view
#                 page_list = mvl_regular_layout (mapview(), 2, 1, 1, 3)
#
#                 # create a display window using this set of pages
#                 dw = plot_superpage( pages : page_list )		
#
# **************************************************************************

function mvl_regular_layout (the_view      : definition,
                             frame_cols    : number, frame_rows    : number,
			     subframe_cols : number, subframe_rows : number)

	delta_x = 100 / frame_cols
	delta_y = 100 / frame_rows

	subframe_list = mvl_mxn_subframes (subframe_cols, subframe_rows)

	frame_list = []
	for i = 1 to frame_rows do
		hi_pos	= delta_y * (i-1)
		lo_pos  = delta_y * i
		for j = 1 to frame_cols do
			left_pos  = delta_x * (j-1)
			right_pos = delta_x * j
			frame   = plot_page(
					top     	: hi_pos,
					bottom  	: lo_pos,
					left    	: left_pos,
					right   	: right_pos,
					sub_pages	: subframe_list, 
					view    	: the_view
					)
			frame_list = frame_list & [frame]
		end for
	end for

	return frame_list

end mvl_regular_layout

# **************************************************************************
# Function      : mvl_regular_layout
#
# Syntax        : list mvl_regular_layout (view, frame_cols, frame_rows,
#                                          subframe_cols, subframe_rows, area)
#
# Author (date) : Anonymous (02/03/2009)
#
# Category      : LAYOUT
#
# OneLineDesc   : Generates a regular grid of frames/subframes within a given area
#
# Description   : Creates a list of frames, arranged in a regular grid.
#                 Each frame contains a set of 1 or more subframes, each
#                 arranged in a regular mxn grid. The output is suitable for
#                 input into the function plot_superpage().
#
# Parameters    : the_view    - a view definition to be used with each frame
#                 frame_cols  - the number of frames along the width
#                 frame_rows  - the number of frames along the height
#                 subframe_cols - the number of subframes along the width
#                                 of each frame.
#                 subframe_rows - the number of subframes along the height
#                                 of each frame.
#		  area		- [TOP,BOTTOM,LEFT,RIGHT], values between 0-100
#
# Return Value  : The list of frames
#
# Dependencies  : mvl_mxn_frames
#
# Example Usage : 
#                 # create a set of frames within a given area using the default map view
#                 page_list = mvl_regular_layout (mapview(), 2, 1, 1, 3, [0,100,0,100])
#
#                 # create a display window using this set of pages
#                 dw = plot_superpage( pages : page_list )		
#
# **************************************************************************

function mvl_regular_layout (the_view     : definition,
                             frame_cols    : number, frame_rows    : number,
			     subframe_cols : number, subframe_rows : number,
			     area          : list)

	dax = area[4] - area[3]
	day = area[2] - area[1]
	delta_x = dax / frame_cols
	delta_y = day / frame_rows

	subframe_list = mvl_mxn_subframes(subframe_cols, subframe_rows)

	frame_list = []
	for j = 1 to frame_rows do
		hi_pos	= delta_y * (j-1) + area[1]
		lo_pos  = delta_y * j + area[1]
		for i = 1 to frame_cols do
			left_pos  = delta_x * (i-1) + area[3]
			right_pos = delta_x * i + area[3]
			frame   = plot_page(
					top     	: hi_pos,
					bottom  	: lo_pos,
					left    	: left_pos,
					right   	: right_pos,
					sub_pages	: subframe_list, 
					view    	: the_view
					)
			frame_list = frame_list & [frame]
		end for
	end for

	return frame_list

end mvl_regular_layout

