% Description: This code returns the mean annual temperature (MAT) and mean
% annual precipitation (MAP) for any terrestrial lat x long coordinates using
% data set described in New et al (2000).
% 
% Input: latitude and longitude (in decimal degrees with N and E > 0 and W and S <0)
% Output: mean annual precipitation MAP (mm y-1) and mean annual temperature
% MAT, (degrees C)
% 
% References: New, Mark, David Lister, Mike Hulme, and Ian Makin. 2002. A 
% high resolution data set of surface climate over global land areas. Climate 
% Research 21:1-25
% paper describing dataset:  http://www.cru.uea.ac.uk/cru/data/tmc/new_et_al_10minute_climate_CR.pdf
% additional files required: Tglobal10min.mat and Pglobal10min.mat can be found at 
% http://www.cru.uea.ac.uk/cru/data/tmc/grid_10min_tmp.dat.gz
% http://www.cru.uea.ac.uk/cru/data/tmc/grid_10min_pre.dat.gz
% 
clear;
T=importdata('Tglobal10min.mat');
P=importdata('Pglobal10min.mat');
%% Input lat and long values here
lat = input ('LATITUDE:  ');
long= input ('LONGITUDE:   ');
%% difference between input coordinates and each coordinate in the file
dlat=T(:,1)-lat;
dlong=T(:,2)-long;
%dist is distance from each point and lat x long entered (hypotenuse)
dist=sqrt(dlat.^2+dlong.^2);
%find index of point closest to given coordinate
[mindiff, mmix]=min(dist);
if mindiff<=0.5;
    MAT=mean(T(mmix,3:14))
    MAPa=sum(P(mmix,3:14))
else;
    input (‘This is the Ocean’);
end;
