%  FIRST RUN alldata_tropicPacific.m
% So data is already 10N-10S/ 110E-80W

% This program pads the time dimension (with NaN) so they align
% Also makes the units the same (hPa)

% NINE DATASETS 
%CDAS: Jan 1950 Mar 2012  (A)
%ERA40: Jan 1958 Aug 2002 (E)
%20thC: Jan 1900 Dec 2010 (F)
%CFSR: Jan 1979 Mar 2012  (G)
%MERRA: Jan 1979 Feb 2012 (H)
%ERA-INT: Jan 1979 Jan 2012 (I)
%ERSLP     (B)
%HADSLP    (C)
%KaplanSLP (D)

% Reshape Pacific basin (69 lon x 9 lat)
latl = 9;
lonl = 69;
latd = latl.*lonl;

inityr = 1900;
finyr = 2012;
noyrz = (finyr - inityr)+1;

mthidx = [1:12];
mx = repmat(mthidx,1,noyrz);
yrs = [inityr:inityr+noyrz-1];
b = repmat(yrs,12,1);
yx= b(:);

%Time increments (jan 1900 - mar 2012... max interval)
maxtim = 1347;
mx1 = mx(1:maxtim);
yx1 = yx(1:maxtim)';

timA = 747;%CDAS (jan 1950)
timB = 1176 %ERSLP (jan 1900)
timC = 1260; %HADSLP (Jan 1900)
timD = 1219; %Kaplan (Jan 1900)
timE = 536; %ERA40 (Jan 1958)
timF = 1332; %20thC (jan 1900)
timG = 399; %CSR (jan 1979)
timH = 398; %MERRA (jan 1979)
timI = 397; %ERA-INT (jan 1979)

aA = reshape(anomslpA,latd,timA);
tA = reshape(eqslpoA,latd,timA);
aB = reshape(anomslpB,latd,timB);
tB = reshape(eqslpoB,latd,timB);
aC = reshape(anomslpC,latd,timC);
tC = reshape(eqslpoC,latd,timC);
aD = reshape(anomslpD,latd,timD);
tD = reshape(eqslpoD,latd,timD);
aE = reshape(anomslpE,latd,timE);
tE = reshape(eqslpoE,latd,timE);
aF = reshape(anomslpF,latd,timF);
tF = reshape(eqslpoF,latd,timF);
aG = reshape(anomslpG,latd,timG);
tG = reshape(eqslpoG,latd,timG);
aH = reshape(anomslpH,latd,timH);
tH = reshape(eqslpoH,latd,timH);
aI = reshape(anomslpI,latd,timI);
tI = reshape(eqslpoI,latd,timI);
clear anomslpA eqslpoA anomslpB eqslpoB anomslpC eqslpoC anomslpD eqslpoD ...
    anomslpE eqslpoE anomslpF eqslpoF anomslpG eqslpoG anomslpH eqslpoH ...
    anomslpI eqslpoI

% Need to pad data so match up (all data should equal "maxtim")
% 1950 start
pd50 = repmat(NaN,latd,600);
% 1958 start
pd58 = repmat(NaN,latd,696);
% 1979 start
pd79 = repmat(NaN,latd,948);
% CDAS
aA = [pd50 aA];
tA = [pd50 tA];
% ERA40
aE = [pd58 aE];
tE = [pd58 tE];
% CFSR
aG = [pd79 aG];
tG = [pd79 tG];
% MERRA
aH = [pd79 aH];
tH = [pd79 tH];
% ERA-I
aI = [pd79 aI];
tI = [pd79 tI];
% Now worry about recent points
% ERSLP
[x t] = size(tB);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tB = [tB pd];
aB = [aB pd];
clear x t fpd pd;
% HadSLP
[x t] = size(tC);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tC = [tC pd];
aC = [aC pd];
clear x t fpd pd;
% Kaplan
[x t] = size(tD);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tD = [tD pd];
aD = [aD pd];
clear x t fpd pd;
% ERA40
[x t] = size(tE);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tE = [tE pd];
aE = [aE pd];
clear x t fpd pd;
% 20thC
[x t] = size(tF);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tF = [tF pd];
aF = [aF pd];
clear x t fpd pd;
% CFSR
[x t] = size(tG);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tG = [tG pd];
aG = [aG pd];
clear x t fpd pd;
% MERRA
[x t] = size(tH);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tH = [tH pd];
aH = [aH pd];
clear x t fpd pd;
% ERAI
[x t] = size(tI);
fpd = maxtim - t;
pd = repmat(NaN,latd,fpd);
tI = [tI pd];
aI = [aI pd];
clear x t fpd pd;

% Same units 
aI = aI./100;
aH = aH./100;
aG = aG./100;
aF = aF./100;
aE = aE./100;
aA = aA./100;
