file=uipickfiles('FilterSpec','E:/C17FSR/0813-70/*.hpl');
AnalDir='E:/C17FSR/Analysis/0813-70/';
nfiles=length(file);
for j=1:nfiles
    [datapath, filename, ext, versn] = fileparts(char(file(j)));
    if ~exist(AnalDir,'dir')
        mkdir(AnalDir)
    end
    writedir(j)=cellstr(AnalDir);
    files(j)=cellstr(filename);
end
for jfiles=1:nfiles
    [vad,profile,lidar]=pro_analysis(char(file(jfiles)),16,15,1.02);
    
    filename=['User1_70_',datestr(profile.time,'yyyymmdd_HHMMSS'),'_profile.mat'];

    textfile=fullfile(char(writedir(jfiles)),[char(files(jfiles)),'_profile.dat']);
    prtid=print_file(textfile,profile,vad);
    textfile=fullfile(char(writedir(jfiles)),filename);
    save(textfile,'profile','lidar');
    ind=find(profile.turb'./(profile.Vh+0.01)>0.7);
    Vhor=profile.Vh;
    %Vhor(ind)=NaN;
    hfig=figure('Position',[100,100 1200 640]);
    set(hfig,'Name',['Wind Conditions ',datestr(vad.start_time),' UTC'],'NumberTitle','off')
    subplot(1,4,1)
    plot(1.94384*profile.Vh,3.2808*profile.heights','linewidth',3)
    grid on
    haxe1=gca;
    set(haxe1,'fontsize',12,'fontweight','b')
    xlabel('Horizontal Wind (knt)','fontsize',14,'fontweight','b')
    ylabel('Height AGL (ft)','fontsize',14,'fontweight','b')
    axis(haxe1,[0 40 0 4000])
    set(haxe1,'XTick',[0 10 20 30 40])
    subplot(1,4,2)
    scatter(profile.theta,3.2808*profile.heights,'linewidth',3)
    grid on
    haxe2=gca;
    set(haxe2,'fontsize',12,'fontweight','b')
    xlabel('Direction','fontsize',14,'fontweight','b')
    axis([0 360 0 4000])
    set(haxe2,'XTick',[0 90 180 270 360])
    subplot(1,4,3)
    plot(1.94384*profile.w,3.2808*profile.heights,'linewidth',3)
    grid on
    haxe3=gca;
    set(haxe3,'fontsize',12,'fontweight','b')
    xlabel('Vertical Wind (knt)','fontsize',14,'fontweight','b')
    axis([-10 10 0 4000])
    set(haxe3,'XTick',[-10 -5 0 5 10])
    text(-30,4300,['Wind Conditions ',datestr(vad.start_time),' UTC'],'fontsize',14,'fontweight','b')
    subplot(1,4,4)
    plot(1.94384*profile.turb,3.2808*profile.heights,'linewidth',3)
    grid on
    haxe4=gca;
    set(haxe4,'fontsize',12,'fontweight','b')
    xlabel('Variance (knt)','fontsize',14,'fontweight','b')
    axis([0 10 0 4000])
    set(haxe4,'XTick',[0 5 10])
    filename=['User1_70_',datestr(profile.time,'yyyymmdd_HHMMSS'),'_profile.png'];

    textfile=fullfile(char(writedir(jfiles)),filename);
    saveas(hfig,textfile)
    pause(1)
    close(hfig)
end
