clear;

load data/sounding.mat;

z=height;

t_par(1)=temperature(1);
td_par(1)=dew_point(1);

z_lcl=124*(t_par-td_par);

for k=1:length(z)-1
  if z(k)<=z_lcl
      t_par(k+1)=t_par(k)-0.0098*(z(k+1)-z(k));
  elseif z(k) > z_lcl & z(k) <= 2000
      t_par(k+1)=t_par(k)-0.004*(z(k+1)-z(k));
  elseif z(k) >2000 & z(k) <= 5000
      t_par(k+1)=t_par(k)-0.005*(z(k+1)-z(k));
  elseif z(k) >5000 & z(k) <= 6000
      t_par(k+1)=t_par(k)-0.006*(z(k+1)-z(k));
  elseif z(k) >6000 & z(k) <= 7000    
      t_par(k+1)=t_par(k)-0.007*(z(k+1)-z(k));
  elseif z(k) >7000 & z(k) <= 8000
      t_par(k+1)=t_par(k)-0.008*(z(k+1)-z(k));
  else
      t_par(k+1)=t_par(k)-0.0098*(z(k+1)-z(k));
  end
  
end  

plot(temperature,height/1000);
hold on;
plot(dew_point,height/1000,'r');
plot(t_par,height/1000,'g');
axis([-50,10,0,10]);
hold off;