function profile(ZZ,CC)
%Prepares the global variables Z,C and dCdZ c.m
%and plots the resulting profile

if min(ZZ)<0 | min(CC)<=0,
  error('Velocity should only be defined for z>=0 and c>0');
end

if ~all(size(ZZ)==size(CC));
  error('z and c should be the same size');
end

ZZ=ZZ(:);
CC=CC(:);

clear global Z C dCdZ

global  Z C dCdZ

[Z,iZZ]=sort(ZZ(:));
C=CC(iZZ);

dCdZ=diff(C)./diff(Z);


z=linspace(-Z(end)/10,Z(end)*1.1,100)';
z=sort([z;Z;Z-1e-8]);

[c,dcdz]=veldep(z);

%Plotting
figure(2)
clf
subplot(121);
pl1=plot(C,Z,'rp',c,z);
axis ij
grid on
xlabel('Velocity {\itc}','fontsize',14,'fontweight','demi')
ylabel('Depth{\it z} ','fontsize',14,'fontweight','demi')



subplot(122);
pl2=plot(dCdZ,Z(1:end-1),'rp',dcdz,z);
axis ij
grid on
xlabel('Depth der. of velocity {\itdc/dz}','fontsize',14,'fontweight','demi')
ylabel('Depth{\it z} ','fontsize',14,'fontweight','demi')

set([pl1(1); pl2(1)],'markersize',10,'markerfacecolor','r')