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:\DATA\ATOMIC\P3\wband\';

prtit_hr=0;
prtday=1;
prtall=1;
year='2020';
cruise='ATOMIC';
fltn=['017' '019' '023' '024' '031' '034' '035' '036' '040' '041' '042'];
yyyy=2020;
graphdevice='-dpng';
graphformat='.png';

P3_doyh=[];
P3_hhh=[];
P3_lath=[];
P3_lonh=[];%P3nav.LONref;P3_lon=P3_lon(ii);
P3_altrefh=[];%P3nav.ALTref;P3_altref=P3_altref(ii);
P3_pitchrefh=[];%P3nav.PITCHref-1.1;P3_pitchref=P3_pitchref(ii);%+ for nose up, 1.1 correction for radar pitch offset
P3_rollrefh=[];%P3nav.ROLLref;P3_rollref=P3_rollref(ii);%for left wind up
P3_cogh=[];%P3nav.TRKd;P3_cog=P3_cog(ii);%COG
P3_Windspeedh=[];%P3nav.WSd;P3_Windspeed=P3_Windspeed(ii);%flight level U
P3_WindDirh=[];%P3nav.DAd;P3_WindDir=P3_WindDir(ii);%flight level dir
P3_sfmrUh=[];%P3nav.SfmrWS1;P3_sfmrU=P3_sfmrU(ii);%Microwave 10-m wind 118
P3_sfmrRh=[];%P3nav.SfmrRainRate1;P3_sfmrR=P3_sfmrR(ii);%117
P3_ssth=[];%P3nav.TRadD1;P3_sst=P3_sst(ii);%119
P3_GSh=[];%P3nav.GSd;P3_GS=P3_GS(ii);%SOG in m/s
P3_Hedh=[];%P3nav.THDGref;P3_Hed=P3_Hed(ii);%aircraft heading
P3_TASh=[];%P3nav.TDc;P3_TAS=P3_TAS(ii);
P3_pressh=[];%P3nav.PSc;P3_press=P3_press(ii);
P3_Tdh=[];%P3nav.TDc;P3_Td=P3_Td(ii);
P3_Tah=[];%P3nav.TAd;P3_Ta=P3_Ta(ii);
P3_Qh=[];%P3nav.HUM_ABSd;P3_Q=P3_Q(ii);
P3_RHh=[];%P3nav.HUM_RELd;P3_RH=P3_RH(ii);
P3_TradDh=[];%P3nav.TRadD1;P3_TradD=P3_TradD(ii);%IR sst?
P3_TradSh=[];%P3nav.TRadS1;P3_TradS=P3_TradS(ii);
P3_cabh=[];%P3nav.PCAB1;P3_cab=P3_cab(ii);
P3_wvelh=[];%P3nav.UWZd;P3_wvel=P3_wvel(ii);
P3_uvelh=[];%P3nav.UWZd;P3_wvel=P3_wvel(ii);
P3_vvelh=[];%P3nav.UWZd;P3_wvel=P3_wvel(ii);


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=[];
k=3*(i-1)+1:3*i;
xdir2=dir([way_raw_files fltn(k) '\Motion\*.nc']);xdir2.name
way_raw_motion_wband=[way_raw_files fltn(k) '\Motion\'];
[m,d]=yd2md(str2double(year), str2num(fltn(k)));
Vdate=[str2double(year) m d];
ddd=d;
read_P3navdata_FLTLVL_atomic_AC_nc;
%sondex=load([way_raw_files xdir2(i).name]);
jk=length(P3_lat);
[i mon dttn hr mn sec]=datevec(jdx);
P3_doyh=[P3_doyh' P3_doy*ones(length(P3_hh),1)']';
P3_hhh=[P3_hhh' P3_hh']';
P3_lath=[P3_lath' P3_lat']';
P3_lonh=[P3_lonh' P3_lon']';%
P3_altrefh=[P3_altrefh' P3_altref']';%
P3_pitchrefh=[P3_pitchrefh' P3_pitchref']';%
P3_rollrefh=[P3_rollrefh' P3_rollref']';%
P3_cogh=[P3_cogh' P3_cog']';%
P3_Windspeedh=[P3_Windspeedh' P3_Windspeed']';%
P3_WindDirh=[P3_WindDirh' P3_WindDir']';%
P3_sfmrUh=[P3_sfmrUh' P3_sfmrU']';%
P3_sfmrRh=[P3_sfmrRh' P3_sfmrR']';%
P3_ssth=[P3_ssth' P3_sst']';%
P3_GSh=[P3_GSh' P3_GS']';%
P3_Hedh=[P3_Hedh' P3_Hed']';%
P3_TASh=[P3_TASh' P3_TAS']';%
P3_pressh=[P3_pressh' P3_press']';%
P3_Tdh=[P3_Tdh' P3_Td']';%
P3_Tah=[P3_Tah' P3_Ta']';%
P3_Qh=[P3_Qh' P3_Q']';%
P3_RHh=[P3_RHh' P3_RH']';%
P3_TradDh=[P3_TradDh' P3_TradD']';%
P3_TradSh=[P3_TradSh' P3_TradS']';%
P3_cabh=[P3_cabh' P3_cab']';%
P3_wvelh=[P3_wvelh' P3_wvel']';%
P3_uvelh=[P3_uvelh' P3_uvel']';%
P3_vvelh=[P3_vvelh' P3_vvel']';%


if prtday;
    save([way_raw_files '\ATOMIC_P3_FLTLVL' fltn(k) '.mat'], 'P3_doy','P3_hh','P3_lat','P3_lon','P3_altref','P3_pitchref','P3_rollref','P3_cog','P3_Windspeed','P3_WindDir','P3_sfmrU','P3_sfmrR','P3_GS','P3_Hed','P3_TAS','P3_press','P3_Td','P3_Ta','P3_Q','P3_RH','P3_TradD','P3_TradS','P3_cab','P3_wvel','P3_uvel','P3_vvel');
end;

end;

if prtall;
        save([way_raw_files '\ATOMIC_P3_FLTLVL_all.mat'], 'P3_doyh','P3_hhh','P3_lath','P3_lonh','P3_altrefh','P3_pitchrefh','P3_rollrefh','P3_cogh','P3_Windspeedh','P3_WindDirh','P3_sfmrUh','P3_sfmrRh','P3_GSh','P3_Hedh','P3_TASh','P3_pressh','P3_Tdh','P3_Tah','P3_Qh','P3_RHh','P3_TradDh','P3_TradSh','P3_cabh','P3_wvelh','P3_uvelh','P3_vvelh');
end;
