function [new_var]=make_edge_contour(var,pressure,prof_prov,section)
% This a cheap way to make clean plots at the bottom or edges of plots
% where you profile depths vary creating horizontal interpolation anomalies.
% All it does is interpolate the shallower column with the last good value 
% of the adjacent profile.
%
% INPUTS: desired variable, pressure, max depths vector of each station,
% and the section call, i.e. '27N'
%
% OUTPUTS: The interpolated matrix of desired variable
%
% Written by JH 

% if 0,
% new_sal=sal_prov;
% sal_end=new_sal((max(max(prs))+1),1)-0.1;
% pressure=pressure';
% 
% for ii = 1:5
% jj=find(isnan(new_sal(:,ii)));
% new_sal(100000,ii)=sal_end;
% x1=[jj(1)-1;800];
% x2=[jj(1):800-1];
% %new_sal(jj,ii)=interp1(pressure((jj(1)-1:end-2)),new_sal((jj(1)-1:end-2),ii),pressure((jj(1)-1:end-2)),'nearest')
% %new_sal(jj,ii)=interp1(pressure(x1,ii),new_sal(x1,ii),pressure(x2,ii),'nearest')
% new_sal(x2,ii)=interp1(pressure(x1),new_sal(x1,ii),pressure(x2),'linear')
% 
% clear jj x1 x2
% end
% end;

%new_var=oxygen_prov;
prs=pressure';
new_var=var;


%%%%%%%%%%%%%%%%%%%%%%% for providence section %%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'prov'),
for i = 0:3,
end1=new_var(prof_prov(4-i),4-i);
new_var(prof_prov(4-i),5-i)=end1;
x1=[prof_prov(5-i);prof_prov(4-i)];
x2=[prof_prov(5-i):prof_prov(4-i)-1];
new_var(x2,5-i)=interp1(prs(x1),new_var(x1,5-i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%% for 27 section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%from east to west
if 0,
if strcmp(section,'27N'),
for i = 0:5,
end1=new_var(prof_prov(2+i),2+i);
new_var(prof_prov(2+i),1+i)=end1;
x1=[prof_prov(1+i);prof_prov(2+i)];
x2=[prof_prov(1+i):prof_prov(2+i)-1];
new_var(x2,1+i)=interp1(prs(x1),new_var(x1,1+i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
end;
%from west to east
if strcmp(section,'27N'),
for i = 0:5,
end1=new_var(prof_prov(8-i),8-i);
new_var(prof_prov(8-i),9-i)=end1;
x1=[prof_prov(9-i);prof_prov(8-i)];
x2=[prof_prov(9-i):prof_prov(8-i)-1];
new_var(x2,9-i)=interp1(prs(x1),new_var(x1,9-i),prs(x2),'linear');
clear end1 x1 x2;
end;
end; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%% for 26 section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'26N'),
for i = 0:3,
end1=new_var(prof_prov(2+i),2+i);
new_var(prof_prov(2+i),1+i)=end1;
x1=[prof_prov(1+i);prof_prov(2+i)];
x2=[prof_prov(1+i):prof_prov(2+i)-1];
new_var(x2,1+i)=interp1(prs(x1),new_var(x1,1+i),prs(x2),'linear');
clear end1 x1 x2;
end;


for ii = 0:5,
end1=new_var(prof_prov(10-ii),10-ii);
new_var(prof_prov(10-ii),11-ii)=end1;
x1=[prof_prov(11-ii);prof_prov(10-ii)];
x2=[prof_prov(11-ii):prof_prov(10-ii)-1];
new_var(x2,11-ii)=interp1(prs(x1),new_var(x1,11-ii),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%% GOMECC2 LA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if strcmp(section,'la'),
for i = 0:7,
end1=new_var(prof_prov(8-i),8-i);
new_var(prof_prov(8-i),9-i)=end1;
x1=[prof_prov(9-i);prof_prov(8-i)];
x2=[prof_prov(9-i):prof_prov(8-i)-1];
new_var(x2,9-i)=interp1(prs(x1),new_var(x1,9-i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%% for 27 section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'27N_GOMECC2'),
for i = 0:6,
end1=new_var(prof_prov(2+i),2+i);
new_var(prof_prov(2+i),1+i)=end1;
x1=[prof_prov(1+i);prof_prov(2+i)];
x2=[prof_prov(1+i):prof_prov(2+i)-1];
new_var(x2,1+i)=interp1(prs(x1),new_var(x1,1+i),prs(x2),'linear');
clear end1 x1 x2;
end;

if 0,
for ii = 0:3,
end1=new_var(prof_prov(11-ii),11-ii);
new_var(prof_prov(11-ii),12-ii)=end1;
x1=[prof_prov(12-ii);prof_prov(11-ii)];
x2=[prof_prov(12-ii):prof_prov(11-ii)-1];
new_var(x2,12-ii)=interp1(prs(x1),new_var(x1,12-ii),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%% for Tampa section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'Tampa'),
for ii = 0:3,
end1=new_var(prof_prov(9-ii),9-ii);
new_var(prof_prov(9-ii),10-ii)=end1;
x1=[prof_prov(10-ii);prof_prov(9-ii)];
x2=[prof_prov(10-ii):prof_prov(9-ii)-1];
new_var(x2,10-ii)=interp1(prs(x1),new_var(x1,10-ii),prs(x2),'linear');
clear end1 x1 x2;
end;
end;

if strcmp(section,'Tampa_oxy'),
for ii = 0:4,
end1=new_var(prof_prov(9-ii),9-ii);
new_var(prof_prov(9-ii),10-ii)=end1;
x1=[prof_prov(10-ii);prof_prov(9-ii)];
x2=[prof_prov(10-ii):prof_prov(9-ii)-1];
new_var(x2,10-ii)=interp1(prs(x1),new_var(x1,10-ii),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%% for Georgia section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'georgia'),
for i = 1:10,
end1=new_var(prof_prov(2+i),2+i);
new_var(prof_prov(2+i),1+i)=end1;
x1=[prof_prov(1+i);prof_prov(2+i)];
x2=[prof_prov(1+i):prof_prov(2+i)-1];
new_var(x2,1+i)=interp1(prs(x1),new_var(x1,1+i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for NC section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'nc'),
for i = 0:1,
end1=new_var(prof_prov(4-i),4-i);
new_var(prof_prov(4-i),3-i)=end1;
x1=[prof_prov(3-i);prof_prov(4-i)];
x2=[prof_prov(3-i):prof_prov(4-i)-1];
new_var(x2,3-i)=interp1(prs(x1),new_var(x1,3-i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for NJ section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'nj'),
for i = 0,
%end1=new_var(prof_prov(8-i),8-i);
end1=new_var(150,8);
new_var(150,7-i)=end1;
x1=[prof_prov(7-i);150];
x2=[prof_prov(7-i):150-1];
new_var(x2,7-i)=interp1(prs(x1),new_var(x1,7-i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%% for W section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'w'),
for i = 0:3,
end1=new_var(prof_prov(2+i),2+i);
new_var(prof_prov(2+i),1+i)=end1;
x1=[prof_prov(1+i);prof_prov(2+i)];
x2=[prof_prov(1+i):prof_prov(2+i)-1];
new_var(x2,1+i)=interp1(prs(x1),new_var(x1,1+i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%% for NH section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(section,'nh'),
for i = 0:2,
end1=new_var(prof_prov(2+i),2+i);
new_var(prof_prov(2+i),1+i)=end1;
x1=[prof_prov(1+i);prof_prov(2+i)];
x2=[prof_prov(1+i):prof_prov(2+i)-1];
new_var(x2,1+i)=interp1(prs(x1),new_var(x1,1+i),prs(x2),'linear');
clear end1 x1 x2;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%pcolor(lon,pressure,new_var);
   %shading interp
   %revyaxis
% 
% figure
% for ii=1:9
%     plot(new_var(:,ii),pressure,'-r')
%     hold on;
% end;