%   Powered by He Yanchun, PKU,NZC
%   $Revision: 1.0  $  $Date: 2009/03/27 19:13:41 $

%%
clear all;
close all;

%% Define Constants

%% Define Vars

%% Load Data

% lat=nc_varget('ucur.1982.nc','lat');
% lon=nc_varget('ucur.1982.nc','lon');
load grid.mat plat plon ;
% ucur=nc_varget('ucur.1982.nc','ucur',[11 0 0 0 ],[1 1 -1 -1]);
% vcur=nc_varget('vcur.1982.nc','vcur',[11 0 0 0 ],[1 1 -1 -1]);
% [6,0,0,0],[1,1,-1,-1]) denote the 7th month,1st level
mxlu=nc_varget('H04S5_2d_1983.07_rotted.nc','mxlu');
mxlv=nc_varget('H04S5_2d_1983.07_rotted.nc','mxlv');
% ucur=double(ucur);
% vcur=double(vcur);
% salt(find(salt<4))=NaN;   %get rid of the missing value.
mxlu(end+1,:)=mxlu(1,:);
mxlv(end+1,:)=mxlv(1,:);
plat(end+1,:)=plat(1,:);
plon(end+1,:)=plon(1,:);
lat=plat;lon=plon;
ucur=mxlu;vcur=mxlv;
clear mxlu mxlv plat plon;
%% Compute

speed=sqrt(ucur.*ucur+vcur.*vcur);
%% Plot Figures

axesm eqdcylin;
setm(gca,'Frame','on','MeridianLabel','on',...
	'MLabelParallel','south','MLabelLocation',30,...
	'ParallelLabel','on','PLabelLocation',20,...
	'MapLatLimit',[-85 -10],'MapLonLimit',[-60 30]);
pcolorm(lat,lon,speed);
% shading flat;
caxis([0 max(max(speed))+0.1])
load hotres.mat
colormap(cmap);
colorbar;
axis tight
set(gcf,'Position',[0 400 1024 768],'Renderer','Painters');
h_cb=colorbar('location','southoutside');
pos=get(h_cb,'position');
pos(2)=pos(2)*1;
pos(4)=pos(4)/2; % half height of original size.
set(h_cb,'position',pos)

% ucur(120,163)=1.0;
% vcur(120,163)=0;
% h_q=quiverm(lat([1:2:end,120],[1:2:end,163]),lon([1:2:end,120],...
%     [1:2:end,163]),vcur([1:2:end,120],[1:2:end,163]),...
%     ucur([1:2:end,120],[1:2:end,163]),4);
% h_q=quiverm(lat(1:2:end,1:2:end),lon(1:2:end,1:2:end),...
%     vcur(1:2:end,1:2:end),ucur(1:2:end,1:2:end),4);
h_q=quiverm(lat,lon,vcur,ucur,8);
set(h_q,'color','k');

geoshow('landareas.shp','facecolor',[0.8 0.8 0.8]);
set(gca,'dataaspectratio',[1 1 1]);

% textm(lat(120,163),lon(120,163),'1 m/s');
% textm(-85,100,'1 m/s');
textm(-74,5,['max  =',num2str(max(max(speed))),' m/s']);
textm(-76,5,['min   =',num2str(min(min(speed))),' m/s']);
textm(-78,5,['mean=',num2str(mean(mean(speed(find(~isnan(speed)))))),' m/s']);

xlabel('','fontsize',12,'fontweight','bold');
ylabel('','fontsize',12,'fontweight','bold');
title('Micom Monthly Mean Ocean Surface Current @ Jul,1983',...
    'fontsize',12,'fontweight','bold')
title('');

%% Save the Figures and Data

% save filename.mata b;
% print -dpng -r300 micom_uvcurrent_sur_atlantic30s_198307.png
% print -deps -r300 micom_uvcurrent_sur_atlantic30s_198307.eps