clear all;
close all;

compute  = 1 ; 

%if compute

datadir2='/export/home1/ALBATROS/DATA/mldr003_2014/';

mldc=ncread([datadir2,'mldr003_2014_wz_krig_dxk_0.5degmld_dr003_2014_l3.nc'],'mld_dr003');
lonc=ncread([datadir2,'mldr003_2014_wz_krig_dxk_0.5degmld_dr003_2014_l3.nc'],'lon');
latc=ncread([datadir2,'mldr003_2014_wz_krig_dxk_0.5degmld_dr003_2014_l3.nc'],'lat');
missval=ncreadatt([datadir2,'mldr003_2014_wz_krig_dxk_0.5degmld_dr003_2014_l3.nc'],'mld_dr003','missing_value');
mldc(mldc==missval)=NaN;


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/';
%nemodir2='/home/datawork-lops-siam-moawi/SIAMTEAM/xcouvela/NEMOWAVE/ORCA025/ORCA025_ERAIM_CPL_NEW_BREIV16/AXELL03_90J/';

nemocoord='ORCA025_1d_20140101_20141231_grid_T.nc';

nav_lat=double(ncread([nemodir1,nemocoord],'nav_lat'));
nav_lon=double(ncread([nemodir1,nemocoord],'nav_lon'));

jn=near(nav_lat(1,:),25);
js=near(nav_lat(1,:),-25);

ajn=near(latc,25);
ajs=near(latc,-25);


%nav_lat=nav_lat(:,jn:end);
%nav_lon=nav_lon(:,jn:end);

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

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


var1='mldr10_3';

TIME=ncread([nemodir1,'ORCA025_1d_20140101_20141231_grid_T.nc'],'time_counter');
time=TIME/86400+datenum(1900,1,1)+28;
D=datevec(time);

jj=1;
%for d=182:274 
for d=1:365 
disp(num2str(d))
m=D(d,2);
j=D(d,3);
     tmpSSTNCPL=ncread([nemodir1,'ORCA025_1d_20140101_20141231_grid_T.nc'],var1,[1 1 d],[inf inf 1]);
     tmpSSTCPL =ncread([nemodir2,'ORCA025_1d_20140101_20141231_grid_T.nc'],var1,[1 1 d],[inf inf 1]);

     tmpice=ncread([nemodir1,'ORCA025_1d_20140101_20141231_icemod.nc'],'siconc',[1 1 d],[inf inf 1]);
     SSTNCPL(:,:,jj)=reorder_glo(tmpSSTNCPL,nav_lon);
     SSTCPL(:,:,jj) =reorder_glo(tmpSSTCPL,nav_lon);
     ICE(:,:,jj)=reorder_glo(tmpice,nav_lon);

jj=jj+1;

end

MASK=SSTNCPL;
MASK(MASK==0)=NaN;
MASK(~isnan(MASK))=1;

IMASK=ICE;

IMASK(IMASK~=0)=NaN;
IMASK(~isnan(IMASK))=1;
MASK=MASK.*IMASK;

SSTNCPL=SSTNCPL.*MASK;
SSTCPL=SSTCPL.*MASK;

SSTdiffmod=(SSTCPL-SSTNCPL);
DIFFPC=(1-SSTNCPL./SSTCPL)*100;
%DIFFPC=(SSTdiffmod./SSTNCPL-1)*100;

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

figure
m_pcolor(lon,lat,squeeze(nanmean(DIFFPC(:,:,1:90),3)));shading flat;colorbar;
m_coast('patch',0.3*[.6 .6 .6],'edgecolor','k');
m_grid('box','fancy','tickdir','in','FontSize',13);
title('JFM')
set(gca,'fontsize',13,'fontweight','bold')
colormap(b2r(-80,80))
figure
m_pcolor(lon,lat,squeeze(nanmean(DIFFPC(:,:,182:274),3)));shading flat;colorbar;
m_coast('patch',0.3*[.6 .6 .6],'edgecolor','k');
m_grid('box','fancy','tickdir','in','FontSize',13);
title('JAS')
set(gca,'fontsize',13,'fontweight','bold')
colormap(b2r(-80,80))

