# Metview Macro

#  **************************** LICENSE START ***********************************
# 
#  Copyright 2015 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 ************************************

# read the 2014 data
jan_2014_temperature = read("era_t2m_jan_2014.grib")

# split into the different times
time_00 = read(time :  0, data : jan_2014_temperature)
time_12 = read(time : 12, data : jan_2014_temperature)

# compute the monthly means for 2014
jan_2014_mean_00 = mean(time_00)
jan_2014_mean_12 = mean(time_12)
jan_2014_means = jan_2014_mean_00 & jan_2014_mean_12


# read the ERA data for the previous 5 years and split into times
jan    = read("era_t2m_jan_2009_2013.grib")
jan_00 = read(data: jan, time: 00) # filter the 00:00 fields
jan_12 = read(data: jan, time: 12) # filter the 12:00 fields

# compute the climatologies, one per time
jan_00_mean = mean(jan_00)
jan_12_mean = mean(jan_12)
jan_means = jan_00_mean & jan_12_mean

# put the 2015 data onto a 5x5 degree grid to match the ERA data
jan_2014_means = read(data: jan_2014_means, grid:[5,5])

# compute the monthly anomalies
jan_anoms = jan_2014_means - jan_means
return jan_anoms

