disp('read_sondeProfile_edouard');
%This program reads stored dropsonde profiles from each of 4 platforms
%The file is a matlab .mat file.

%select the aircraft by uncommenting the one you want
%flt='01_27';%G4
% flt='I1';%P3
 %flt='GH';%global hawk
 %flt='H1';%P3

way_raw_images='D:\P3\sonde\images\';
way_raw_files='D:\P3\sonde\data\';

rhahh=[];
zhh=[];
Uhh=[];
tahh=[];
lathh=[];
lonhh=[];
Phh=[];
qahh=[];
udirhh=[];
jdxh=[];

xdir2=dir([way_raw_files '*.mat']);xdir2.name
for i=1:11
%     fnm=xdir2(i).name;
%     load([way_raw_files fnm]);
zh=[];rhah=[];Uh=[];tah=[];lath=[];lonh=[];Ph=[];qah=[];jdx=[];
xdir2(i).name
sondex=load([way_raw_files xdir2(i).name], 'jdxh', 'zhh','Uhh','rhahh','tahh','lathh','lonhh','Phh','qahh','udirhh');
rhah=sondex.rhahh;
zh=sondex.zhh;
Uh=sondex.Uhh;
tah=sondex.tahh;
lath=sondex.lathh;
lonh=sondex.lonhh;
Ph=sondex.Phh;
qah=sondex.qahh;
udirh=sondex.udirhh;
jdx=sondex.jdxh;
jk=length(lath);
[i mon dttn hr mn sec]=datevec(jdx);

[nn nm]=size(zh);
disp(['Number of profiles= ' num2str(nm)]) 


%select a profile to plot
% jj=10;
% ii=find(zhh(:,jj)>0);size(ii);
% disp(['Max Altitude= ' num2str(zhh(length(ii),jj)) ' m']) 
% figure;
% subplot(1,2,1);plot(Uhh(:,jj),zhh(:,jj)/1e3);ylabel('Alt (km)');xlabel('U (m/s)');title(['Edouard ' flt ' 2014 '  num2str(mon(jj)) '/' num2str(dttn(jj)) ' '  num2str(hr(jj)+mn(jj)/60)]);ylim([0 5]);
% subplot(1,2,2);plot(rhahh(:,jj),zhh(:,jj)/1e3,[100 100],[0  15],'--');;xlabel('RH water-ice (%)');xlim([0 105]);ylim([0 5]);

jk=length(jdx);
rhahh=[rhahh rhah(1:4000,1:jk)];
zhh=[zhh zh(1:4000,1:jk)];
Uhh=[Uhh  Uh(1:4000,1:jk)];
tahh=[tahh tah(1:4000,1:jk)];
lathh=[lathh lath(1:jk)];
lonhh=[lonhh lonh(1:jk)];
Phh=[Phh Ph(1:4000,1:jk)];
qahh=[qahh qah(1:4000,1:jk)];
udirhh=[udirhh udirh(1:4000,1:jk)];
jdxh=[jdxh jdx(1:jk)];

end;
prtit=0;
if prtit;
        save([way_raw_files 'all\ATOMIC_P3_sonde_all.mat'], 'jdxh', 'zhh','Uhh','rhahh','tahh','lathh','lonhh','Phh','qahh','udirhh');
end;
