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
%################## Cruise informations  ##################################################################
cruise='ATOMIC';             % Cruise name  
year='2020';               % year (deprecated--make year into a double) 
yyyy='2020';               % year (string)
ship='P3';               % Research vessel
%%%%%%%%%%%%%%%%%%%%%%%%% Starts process %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% use known day/hour; prompt for it if unknown
if ~exist('ddd','var')
    ddds=input('Input yearday  ','s');
    ddd=str2double(ddds);
else
    ddds=sprintf('%03i',ddd);
end
[m,d]=yd2md(str2double(yyyy), ddd);
Vdate=[str2double(yyyy) m d];
% if ~exist('shr','var')
% %     if 0
%         shrs=input('Input start hr  ','s');
%         shr=str2double(shrs);
%     else
%         shr=0;
%     end
% % end
% if ~exist('ehr','var')
% %     if 0
%         ehrs=input('Input end hr  ','s');
%         ehr=str2double(ehrs);
%     else % use hours 0-23 by default
%         ehr=23;
%     end
% % end
% 
big_dir='E:\DATA\ATOMIC\P3\sonde\';

disp('fockewe2')
% W-band radar files
way_raw_data_sonde=[big_dir ddds '\frd\'];
way_raw_images_sonde=[big_dir ddds '\Raw_images\'];


%way_cloud_data_wband=[big_dir '\RHB\reports\'];
%##################%##################%##################%##################%##################%##################


% way_raw_images='C:\data\cwf\Dropbox\DOC\CLIMATE\CalWater2\aircraft\2015\sonde\figs\';
% way_raw_files='C:\data\cwf\Dropbox\DOC\CLIMATE\CalWater2\aircraft\2015\sonde\';

rhahh=[];
zhh=[];
Uhh=[];
tahh=[];
lathh=[];
lonhh=[];
Phh=[];
qahh=[];
jdxh=[];
mx=[];
xdir2=dir([way_raw_data_sonde '*.nc']);xdir2.name;
ff=xdir2.name;
mx=length(ff);

for i=1:mx
%     fnm=xdir2(i).name;
%     load([way_raw_files fnm]);

fname=[way_raw_data_sonde xdir2(i).name]
sondex=read_netcdfFile2(fname);

%sondex=load([way_raw_files xdir2(i).name], 'jdxh', 'zhh','Uhh','rhahh','tahh','lathh','lonhh','Phh','qahh');
rhah=sondex.rh;
zh=sondex.alt;
Uh=sondex.wspd;
Dirh=sondex.wdir;
tah=sondex.tdry;
lath=sondex.lat;
lonh=sondex.lon;
Ph=sondex.pres;
qa=qair_p3([tah Ph rhah/100]);
qah=qa;
yy=ff(2:5);mon=ff(6:7);dttn=ff(8:9);hr=ff(11:12);mn=ff(13:14);sec=ff(15:16);
yyn=str2num(yy);monn=str2num(mon);dyn=str2num(dttn);hrn=str2num(hr);mnn=str2num(mn);secn=str2num(sec);
jdx=datenum(yyn,monn,dyn,hrn,mnn,secn)-datenum(2019,12,31);
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:3000,1:jk)];
zhh=[zhh zh(1:3000,1:jk)];
Uhh=[Uhh  Uh(1:4000,1:jk)];
tahh=[tahh tah(1:3000,1:jk)];
lathh=[lath lath(1:jk)];
lonhh=[lonh lonh(1:jk)];
Phh=[Phh Ph(1:3000,1:jk)];
qahh=[qahh qah(1:3000,1:jk)];
jdxh=[jdxh jdx(1:jk)];

end;

