# 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_mxn_subframes
#
# Syntax        : list mvl_mxn_subframes (number, number)
#
# Author (date) : Anonymous (--/--/2003)
#
# Category      : LAYOUT
#
# OneLineDesc   : Generates a regular grid of subframes
#
# Description   : Creates a list of subframes, arranged in a
#                 regular mxn grid. This list is suitable for
#                 input into the function plot_page().
#
# Parameters    : subframe_cols - the number of subframes along the width
#                                 of the frame.
#                 subframe_rows - the number of subframes along the height
#                                 of the frame.
#
# Return Value  : The list of subframes
#
# Dependencies  : None
#
# Example Usage : 
#		  # create a list of subframes over 2 columns and 3 rows
#		  subframe_list = mvl_mxn_subframes (2, 3)
#
#		  # create a frame divided into these subframes
#		  frame   = plot_page( sub_pages	: subframe_list )
#
#		  # create a display window with this page
#		  dw = plot_superpage ( pages : [frame])
#
# **************************************************************************

function mvl_mxn_subframes (subframe_cols: number, subframe_rows: number)

	subdelta_x = 100 / subframe_cols
	subdelta_y = 100 / subframe_rows
	subframe_list = []

	for i = 1 to subframe_rows do
		hi_pos = subdelta_y * (i-1)
		lo_pos = subdelta_y * i
		for j = 1 to subframe_cols do
			left_pos  = subdelta_x * (j-1)
			right_pos = subdelta_x * j
			subframe = plot_subpage(
					top	: hi_pos,
					bottom  : lo_pos,
					left    : left_pos,
					right   : right_pos
					)
			subframe_list = subframe_list & [subframe]
		end for
	end for

	return subframe_list

end mvl_mxn_subframes
