#Metview Macro

#MARS retrieval
mars_hirs = retrieve(
		type	:	"mfb",
		repres	:	"bu",
		obsgroup	:	"hirs",
		time	:	00,
		resol	:	"",
		filter	:	"select lat, lon, obsvalue, vertco_reference_1"
		)

#Run odb_filter to get distinct channel list and read it into a vector
ch=values(odb_filter(odb_query:"select distinct vertco_reference_1@body as ch", 
                    odb_data: mars_hirs),"ch")

#Create a vector to store stdev for each channel
std_val=vector(count(ch))

#Compute the stdev for each channel using odb_filter  
for i=1 to count(ch) do
	db=odb_filter(
			odb_query: "select stdev(obsvalue) as val where vertco_reference_1 = " & ch[i],
			odb_data: mars_hirs
		)
				
	std_val[i]=values(db,"val")	
end for

#Print the results
for i=1 to count(ch) do
	print("Channel: ",ch[i]," Stdev: ",std_val[i],newline)
end for	

