#Metview Macro

#Read odb
mydb = read("AIREP.odb")

#Perform the query - the output is an ODB
filter_u = odb_filter(
		odb_query	:	"select " &
					"  lat@hdr as lat, " &
					"  lon@hdr as lon, " &
					"  obsvalue@body as u, " &
					"where " &
					"  obstype@hdr = 2 and " &
					"  varno@body = 3 and " &		
					"  vertco_reference_1@body < 25000 ",
		odb_data	:	mydb
		)


#Perform the query - the output is an ODB
filter_v = odb_filter(
		odb_query	:	"select " &
					"  lat@hdr as lat, " &
					"  lon@hdr as lon, " &
					"  obsvalue@body as v, " &
					"where " &
					"  obstype@hdr = 2 and " &
					"  varno@body = 4 and " &		
					"  vertco_reference_1@body < 25000 ",
		odb_data	:	mydb
		)
		
#Acces values from the result	
lat = values(filter_u,"lat")
lon = values(filter_u,"lon")
u = values(filter_u,"u")
v = values(filter_v,"v") 

#Build geopoints for visualisation
geo=create_geo(count(lat),"xy_vector")
geo=set_latitudes(geo,lat)
geo=set_longitudes(geo,lon)
geo=set_values(geo,u)
geo=set_value2s(geo,v)

#Define wind plotting
colour_wind = mwind(
		wind_advanced_method	:	"on",
		wind_arrow_unit_velocity	:	50.0,
		wind_thinning_factor	:	1.0,
		wind_advanced_colour_max_level_colour	:	"red",
		wind_advanced_colour_min_level_colour	:	"blue",
		wind_advanced_colour_direction	:	"clockwise"
		)
		
#Define title
title = mtext(
		text_line_count	:	3,
		text_line_1	:	"Date: 2010-12-22 Time: 00",
		text_line_2	:	"Obstype: Aircraft  Param: Wind above 250 hPa",
		text_line_3	:	"Type: MFB"
		)

#Visualise
plot(geo,colour_wind,title)
	