function []=kh_plot_subduction_proportions(Aw,Af,Ah,w_lat,w_lon,d,dep,method)
%
% Calculates the relative proportion contribution to density change coming
% from warming, freshening and heave.  Grids it and plots it on a 2D map
%
% Af,Aw,Ah= levels*profiles 
% w_lat,w_lon=1*profiles
% dep=depth level wanting to plot
% d=neutral density depths (levels*1)
% Method='squared'= Calc proportions (absolute values), grids, plots.
%       'r2'=Grids and plots
%       'nothing'=Calc proportions (leaving in neg and pos), grid, plots

% Squared method
if strncmp(method,'squared',1)==1
    pAw=100*abs(Aw)./(abs(Aw)+abs(Af)+abs(Ah)); 
    pAf=100*abs(Af)./(abs(Aw)+abs(Af)+abs(Ah)); 
    pAh=100*abs(Ah)./(abs(Aw)+abs(Af)+abs(Ah)); 
    gAf=kh_interp_ignore(pAf,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    gAw=kh_interp_ignore(pAw,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    gAh=kh_interp_ignore(pAh,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    kh_pcolor(gAf(:,:,dep),[1:1:60],1); title(['Percentage Af (removing negatives) on ',num2str(d(dep)/10)]);
    figure; kh_pcolor(gAw(:,:,dep),[1:1:60],1); title(['Percentage Aw (removing negatives) on ',num2str(d(dep)/10)]);
    figure; kh_pcolor(gAh(:,:,dep),[1:1:60],1); title(['Percentage Ah (removing negatives) on ',num2str(d(dep)/10)]);
end

% Squared method (contribution to sea level - can be >100 or <0 as leaves in negative numbers)
if strncmp(method,'nothing',1)==1
    pAw=100*Aw./(Aw+Af+Ah); 
    pAf=100*Af./(Aw+Af+Ah); 
    pAh=100*Ah./(Aw+Af+Ah); 
    gAf=kh_interp_ignore(pAf,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    gAw=kh_interp_ignore(pAw,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    gAh=kh_interp_ignore(pAh,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    kh_pcolor(gAf(:,:,dep),[-100:1:100],2); title(['Percentage Af (contribution to SL change) on ',num2str(d(dep)/10)]);
    figure; kh_pcolor(gAw(:,:,dep),[-100:1:100],2); title(['Percentage Aw (contribution to SL change) on ',num2str(d(dep)/10)]);
    figure; kh_pcolor(gAh(:,:,dep),[-100:1:100],2); title(['Percentage Ah (contribution to SL change) on ',num2str(d(dep)/10)]);
end

% R^2 (proportion of variance) method.  Coming from eqn18 bindoff 1994
if strncmp(method,'r2',1)==1
    gAf=kh_interp_ignore(Af*100,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    gAw=kh_interp_ignore(Aw*100,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    gAh=kh_interp_ignore(Ah*100,w_lat,w_lon,[ones(40*1)*100],5,[5 10],'3D');
    kh_pcolor(gAf(:,:,dep),[1:1:100],1); title(['Percentage R^2 Af on ',num2str(d(dep)/10)]);
    figure; kh_pcolor(gAw(:,:,dep),[1:1:100],1); title(['Percentage R^2 Aw on ',num2str(d(dep)/10)]);
    figure; kh_pcolor(gAh(:,:,dep),[1:1:100],1); title(['Percentage R^2 Ah on ',num2str(d(dep)/10)]);
end