%load sonde matlab file a do a few simple plots.
 ddds=input('Input yearday ddd ','s')
load(['D:\P3\sonde\' ddds '\data\ATOMIC_P3_sonde_' ddds '.mat']);
thet=(tahh+273.16).*(1010./Phh).^0.287-273.16;%air theta
tdew=[];[mn mm]=size(jdxh);for i=1:mm;tdew(:,i)=tdewrh([Phh(:,i) tahh(:,i) rhahh(:,i)]);end;
jk=1;figure;plot(tahh(:,jk), zhh(:,jk),tdew(:,jk),zhh(:,jk),thet(:,jk),zhh(:,jk),'.');xlabel('Temperature (C)');ylabel('Altitude (m)');
legend('Tair','Tdew','Tpotential');
LCLbias=nanmeanx(10+(tahh(2,:)-tdew(2,:))/.008 - (100+(tahh(20,:)-tdew(20,:))/.008));
figure;plot(lonhh,10+(tahh(2,:)-tdew(2,:))/.008,'-x',lonhh,100+(tahh(20,:)-tdew(20,:))/.008,'-o');xlabel('Longitude (deg)');ylabel('LCL (m)');
legend('10-m Met','100-m Met');

jk=8:10;figure;
subplot(1,2,1);semilogy(thet(:,jk),zhh(:,jk),'-o');ylim([0 200]);
subplot(1,2,2);semilogy(qahh(:,jk),zhh(:,jk),'-o');ylim([0 200]);


Nx=[];zhmn=[];qamn=[];Umn=[];rhmn=[];Pmn=[];tamn=[];thetmn=[];Ni=[];sqamn=[];sUmn=[];stamn=[];
Nt=[];zhmntp=[];qamntp=[];Umntp=[];rhmntp=[];Pmntp=[];tamntp=[];
lonmn=-58;lonmx=-50;
for i=1:2000;
    ik=find(~isnan(rhahh(i,:)) & lonhh>=lonmn & lonhh<lonmx);
    Nx(i)=length(ik);
    if Nx(i)>2;
        zhmn(i)=nanmedian(zhh(i,ik));
        qamn(i)=nanmedianx(qahh(i,ik)); sqamn(i)=nanstdx(qahh(i,ik));
        Umn(i)=nanmedianx(Uhh(i,ik));sUmn(i)=nanstdx(Uhh(i,ik));
        tamn(i)=nanmeanx(tahh(i,ik));  stamn(i)=nanstdx(tahh(i,ik));      
        thetmn(i)=nanmedianx(thet(i,ik));
        rhmn(i)=nanmeanx(rhahh(i,ik));
        Pmn(i)=nanmeanx(Phh(i,ik));    
        Nx(i)=length(ik);
    end;
%     ik=find(~isnan(rhahh(i,:)) & lathh<latline);
%     Ny(i)=length(ik);
%     if Ny(i)>2;
%         zhmntp(i)=nanmedian(zhh(i,ik));
%         qamntp(i)=nanmeanx(qahh(i,ik));
%         Umntp(i)=nanmeanx(Uhh(i,ik));
%         tamntp(i)=nanmeanx(tahh(i,ik));
%         rhmntp(i)=nanmeanx(rhahh(i,ik));
%         Pmntp(i)=nanmeanx(Phh(i,ik));                
%     end;
%    
%     rhmx(i)=max(rhahh(i,:));

end;%

figure;
subplot(1,2,1);semilogy(thetmn,zhmn,'-o');ylim([0 200]);grid
subplot(1,2,2);semilogy(qamn,zhmn,'-o');ylim([0 200]);grid

figure;plot(stamn,zhmn,'-o',sqamn,zhmn,'-o',sUmn,zhmn,'-o');;grid;legend('sig  ta','sig qa','sig U');xlim([0 6]);ylim([0 7500])


