# 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 load_list_tools()
	print("list tools loaded")
end load_list_tools

function filter_list(ll:list,filter:list)

	res = []
	for i = 1 to count(ll) do
		if (ll[1] not in filter) then
			res = res & [ll[i]]
		end if
	end for

end filter_list

object unique_list(filter:list)
	global list
	list=[]

	function add(value)
		if (not there(value)) then
			list = list & [value]
		end if
	end add

	function there(value)
		if (value in filter) then
			return 1
		end if
		if (value in list) then
			return 1
		end if
		return 0
	end there

	function list()
		return list
	end list
end unique_list

function unique_list()
	return unique_list([])
end unique_list

function index_of(value,ll:list)
	for i = 1 to count(ll) do
		if (ll[i] = value) then
			return i
		end if
	end for
	return 0
end index_of
