# 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 ************************************


tuv_data = read("../TUV_Data")


# more efficient - get all the GRIB keys in one function call
# and ask for the results to be grouped by key
metadata = grib_get(tuv_data, ['level:l', 'units:s'], 'key')
print(metadata)

levs = metadata[1]
print(levs)

units = metadata[2]
print('all units: ', units)

k = find(units, 'K', 'all')
print('indexes of k: ', k)



# perform a simple filtering of the fieldset using these indexes
result = nil
for i = 1 to count(k) do
    result = result & tuv_data[k[i]]
end for

return result
