clear all;
close all;

nemodir1='/home/datawork-lops-siam-moawi/SIAMTEAM/xcouvela/NEMOWAVE/ORCA025/ORCA025_ERAIM/2014/';
nemodir2='/home/datawork-lops-siam-moawi/SIAMTEAM/xcouvela/NEMOWAVE/ORCA025/ORCA025_ERAIM_CPL_NEW_BREIV16/AXELL03/';

nemocoord='ORCA025_1d_20140101_20141231_grid_T.nc';

nav_lat=double(ncread([nemodir1,nemocoord],'nav_lat'));
nav_lon=double(ncread([nemodir1,nemocoord],'nav_lon'));
sst=ncread([nemodir1,nemocoord],'tos');
mask=squeeze(sst(:,:,1));
mask(mask==0)=NaN;
mask(~isnan(mask))=1;

%used for m_proj
minLat=min(nav_lat(:));
maxLat=max(nav_lat(:));
minLon=min(nav_lon(:));
maxLon=max(nav_lon(:));

var1='en';

disp('read ENNCPL')
tmpENNCPL=squeeze(ncread([nemodir1,'ORCA025_1d_20140101_20141231_grid_W.nc'],'en',[1 1 2 1],[inf inf 1 90]));
disp('read ENCPL')
tmpENCPL=squeeze(ncread([nemodir2,'ORCA025_1d_20140101_20141231_grid_W.nc'],'en',[1 1 2 1],[inf inf 1 90]));
disp('read ICE')
tmpICE  =ncread([nemodir2,'ORCA025_1d_20140101_20141231_icemod.nc'],'siconc',[1 1 1],[inf inf 90]);


%disp('read ENNCPL')
%tmpENNCPL=squeeze(ncread([nemodir1,'ORCA025_1d_20140101_20141231_grid_W.nc'],'en',[1 1 2 182],[inf inf 1 90]));
%disp('read ENCPL')
%tmpENCPL=squeeze(ncread([nemodir2,'ORCA025_1d_20140101_20141231_grid_W.nc'],'en',[1 1 2 182],[inf inf 1 90]));
%disp('read ICE')
%tmpICE  =ncread([nemodir2,'ORCA025_1d_20140101_20141231_icemod.nc'],'siconc',[1 1 182],[inf inf 90]);

[lat,lon]=reorder_glo(nav_lat,nav_lon);     


for j=1:size(tmpENNCPL,3)
ENNCPL(:,:,j)=reorder_glo(tmpENNCPL(:,:,j),nav_lon);
ENCPL(:,:,j)=reorder_glo(tmpENCPL(:,:,j),nav_lon);
ICE(:,:,j)=reorder_glo(tmpICE(:,:,j),nav_lon);
end

clear tmpENNCPL tmpENCPL tmpICE 

MASK=zeros(size(ENNCPL));
MASK(ENNCPL~=0)=1;
MASK(isnan(ENNCPL))=0;
MASK(MASK==0)=NaN;
MASK(ICE~=0)=NaN; %add ice mask


ENNCPL=ENNCPL.*MASK;
ENCPL=ENCPL.*MASK;

m_proj('Gall-Peters','lon',[minLon maxLon],'lat',[minLat maxLat])

m_pcolor(lon,lat,nanmean((ENCPL-ENNCPL),3));shading flat;colorbar
m_coast('patch',0.3*[.6 .6 .6],'edgecolor','k');
m_grid('box','fancy','tickdir','in','FontSize',15);
%title('NCPL tke/wind cor')

colormap(b2r(-0.02,0.02))
set(gca,'fontsize',13,'fontweight','bold')


%
%plot by Hem
%

%
%js=near(lat(1,:),-25);
%jn=near(lat(1,:),25);
%
%
%figure;
%plot(squeeze(nanmean(nanmean(ENNCPL(:,1:js,:)))),'linewidth',2);
%hold on 
%plot(squeeze(nanmean(nanmean(ENCPL(:,1:js,:)))),'linewidth',2);
%legend('No\_CPL','CPL\_All2');
%set(gca,'fontsize',13,'fontweight','bold')
%title('TKE South Hemisphere')
%
%figure;
%plot(squeeze(nanmean(nanmean(ENNCPL(:,jn:end,:)))),'linewidth',2);
%hold on
%plot(squeeze(nanmean(nanmean(ENCPL(:,jn:end,:)))),'linewidth',2);
%legend('No\_CPL','CPL\_All2');
%set(gca,'fontsize',13,'fontweight','bold')
%title('TKE North Hemisphere')
%
%figure;
%plot(squeeze(nanmean(nanmean(ENNCPL(:,js:jn,:)))),'linewidth',2);
%hold on
%plot(squeeze(nanmean(nanmean(ENCPL(:,js:jn,:)))),'linewidth',2);
%legend('No\_CPL','CPL\_All2')et(gca,'fontsize',13,'fontweight','bold')
%set(gca,'fontsize',13,'fontweight','bold')
%title('TKE Equatorial region')





