%******************************************************************
% This script is for Figure 1
%
% Input:  cor_mm_fit.mat -from Zhu et al (2017)
% Output: Figure1.eps
%
% Written by Xiaoting Zhu, 2017 (xzhu@geomar.de)
%******************************************************************

%%--- BEGIN: global initialization ----------------------
close all;
clear all;
clc;

crfolder = pwd  % current folder: script folder
rtfolder = [crfolder '/../'];  % root folder
dtfolder_supp = [rtfolder 'Greatbatch2018_data/ERA40_exp/'];
dtfolder = [rtfolder 'Greatbatch2018_data/Zhu2017/'];  % data folder

set(0,'defaultfigurecolor',[1 1 1])
addpath([rtfolder 'mtools/cmocean_v1.1/cmocean']);
addpath([rtfolder 'mtools/altmany-export_fig-9ac0917']);
addpath([rtfolder 'mtools/fix_matlab_eps-master']);

lont=[120:20:290];
lonstr={'120\circE' '140\circE' '160\circE' '180\circ'...
         '160\circW' '140\circW' '120\circW' '100\circW' '80\circW'}; 
latt = [-10:5:10];
latstr = {'10\circS' '5\circS' 'EQ' '5\circN' '10\circN'};

%%--- Read data ---------------------
cd(dtfolder)
load('cor_mm_fit.mat')
lat = ncread([dtfolder_supp 'mode_1_000000000001_eta_out.nc.trange'],'LATITUDE');
lon = ncread([dtfolder_supp 'mode_1_000000000001_eta_out.nc.trange'],'LONGITUDE');

%%--- Read tide gauge locations ---------
loc_num = {'1164','1329','1371','1645','927'};
loc_nam = {'RABAUL','KANTON','CHRISTMAS','BALTRA','SANCRIST'};
loc_lon=[152.18,188.28,202.52,269.72,270.38];
loc_lat=[  -4.2, -2.82,  1.98, -0.43, -0.90];

%%--- Plot Figure 1 ----------------------
figure('position',[50 50 600 210])
contourf(lon,lat,cor_matrix',[-1.:0.1:1.],'edgecolor','none');    
cmp=cmocean('balance');  % sea level cmp     
colormap(cmp)
caxis([-1. 1.])

hold on
scatter(loc_lon,loc_lat,'sw','filled')
text(loc_lon(1:end-2)+2,loc_lat(1:end-2),loc_nam(1:end-2),'color','w')
text(loc_lon(end)-20,loc_lat(end-1)-1.4,loc_nam(end),'color','w')
text(loc_lon(end-1)-15,loc_lat(end)+1.4,loc_nam(end-1),'color','w')

set(gca,'xtick',lont,'xticklabel',lonstr,'TickDir','out')
set(gca,'ytick',latt,'yticklabel',latstr,'TickDir','out')
hc=colorbar
     fff = [-1.:0.2:1.];
     for ii=1:length(fff)
     sfff{ii} = sprintf('%.1f',fff(ii));
     end
set(hc,'ytick',fff,'yticklabel',sfff)

%%--- Save Figure 1 ---------------
cd(rtfolder)
export_fig('Figure1.eps')
export_fig('Figtest.eps')
system(['python ' rtfolder 'mtools/fix_matlab_eps-master/fix_matlab_eps.py Figtest.eps Figure1.eps']);


