

cd /Volumes/User/ccox/Documents/Projects/2019/ASFS/data_tests/Apr_19_outside/



d = dir('ASFS_Test_met_crd_20190419*.dat');
met.dn = [];
met.pr = [];
for k = 1:length(d)
   tmp = importdata(d(k).name,',',4); 
   dn = datenum(tmp.textdata(5:end,1),'yyyy-mm-dd HH:MM:SS');
   met.dn = [met.dn; dn];
   met.pr = [met.pr; tmp.data(:,2)];
end


d = dir('ASFS_Test_slow_crd_20190419*.dat');
slow.dn = [];
slow.pr = [];
for k = 1:length(d)
   tmp = importdata(d(k).name,',',4); 
   dn = datenum(tmp.textdata(5:end,1),'yyyy-mm-dd HH:MM:SS');
   slow.dn = [slow.dn; dn];
   slow.pr = [slow.pr; tmp.data(:,47)];
end



d = dir('ASFS_Test_fast_crd_20190419*.dat');
fast.dn = [];
fast.pr = [];
for k = 1:length(d)
    tmp = importdata(d(k).name); 
   
    ds = char(tmp.textdata(:,1));
    rep = strings(length(ds),2); rep(:) = '0';
    ds(:,end-1:end) = rep;
   
    dn = datenum(ds,'yyyy-mm-dd HH:MM:SS');
    ms = tmp.data(:,1)./86400;
    fast.dn = [fast.dn; dn + ms];
    fast.pr = [fast.pr; tmp.data(:,11).*10];
end
fast.pr(fast.pr > 850) = NaN;
fast.pr(fast.pr < 600) = NaN;


% d = dir('ASFS_Test_slow_crd_20190419.dat');
% slow.dn  = [];
% slow.pr  = [];
% slow.prs = [];
% for k = 1:length(d)
%     
%    filename = d(k).name;
%    startRow = 5;
%    formatSpec = '%q%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%C%C%C%C%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
%    fileID = fopen(filename,'r');
%    dataArray = textscan(fileID, formatSpec, 'Delimiter', ',', 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
%    fclose(fileID);
%    tmp = table(dataArray{1:end-1}, 'VariableNames', {'TIMESTAMP','gps_lat_Avg','gps_lon_Avg','gps_hdg_Avg','gps_alt_Avg','gps_qc','gps_nsat_Avg','metek_InclX_Avg1','metek_InclY_Avg1','PTemp_Avg','batt_volt_Avg','counts_main_Tot','call_time_mainscan_Avg','call_time_modbus_sr301_Avg','call_time_modbus_sr302_Avg','call_time_modbus_vaisala_Avg','call_time_sdi1_Avg','call_time_sdi2_Avg','call_time_efoy_Avg','sr30_swu_DegC_Avg','sr30_swu_DegC_Std','sr30_swu_Irr_Avg','sr30_swu_Irr_Std','sr30_swu_IrrC_Avg','sr30_swu_IrrC_Std','sr30_swd_DegC_Avg','sr30_swd_DegC_Std','sr30_swd_Irr_Avg','sr30_swd_Irr_Std','sr30_swd_IrrC_Avg','sr30_swd_IrrC_Std','spn1_tot_Wm2_Avg','spn1_tot_Wm2_Std','spn1_dif_Wm2_Avg','spn1_dif_Wm2_Std','apogee_body_T_Avg','apogee_body_T_Std','apogee_targ_T_Avg','apogee_targ_T_Std','sr50_dist_Avg','sr50_dist_Std','vaisala_RH_Avg','vaisala_RH_Std','vaisala_T_Avg','vaisala_T_Std','vaisala_Td_Avg','vaisala_Td_Std','vaisala_P_Avg','vaisala_P_Std','metek_x_Avg1','metek_x_Std1','metek_y_Avg1','metek_y_Std1','metek_z_Avg1','metek_z_Std1','ir20_lwu_mV_Avg','ir20_lwu_mV_Std','ir20_lwu_Case_R_Avg','ir20_lwu_Case_R_Std','ir20_lwu_DegC_Avg','ir20_lwu_DegC_Std','ir20_lwu_Wm2_Avg','ir20_lwu_Wm2_Std','ir20_lwd_mV_Avg','ir20_lwd_mV_Std','ir20_lwd_Case_R_Avg','ir20_lwd_Case_R_Std','ir20_lwd_DegC_Avg','ir20_lwd_DegC_Std','ir20_lwd_Wm2_Avg','ir20_lwd_Wm2_Std','fp_A_mV_Avg','fp_A_mV_Std','fp_A_Wm2_Avg','fp_A_Wm2_Std','fp_B_mV_Avg','fp_B_mV_Std','fp_B_Wm2_Avg','fp_B_Wm2_Std','licor_co2_Avg1','licor_co2_Std1','licor_h2o_Avg1','licor_h2o_Std1','licor_co2_str_out_Avg','licor_co2_str_out_Std','sr30_swu_fantach_Avg','sr30_swu_heatA_Avg','sr30_swd_fantach_Avg','sr30_swd_heatA_Avg','ir20_lwu_fan_Avg','ir20_lwd_fan_Avg','efoy_Error','efoy_Status','efoy_FuellSt_Avg','efoy_Ubat_Avg','efoy_Laus_Avg','efoy_Tst_Avg','efoy_Tint_Avg','efoy_Twt_Avg'});
%    clearvars filename delimiter startRow formatSpec fileID dataArray ans;
%    
%    dn = datenum(table2array(tmp(:,1)),'yyyy-mm-dd HH:MM:SS');
%    slow.dn = [slow.dn; dn];
%    slow.pr = [slow.pr; table2array(tmp(:,48))];
%    slow.prs = [slow.prs; table2array(tmp(:,49))];
% end
% 
% 
% d = dir('ASFS_Test_fast_crd_20190418*.dat');
% fast.dn  = [];
% fast.pr  = [];
% fast.x   = [];
% for k = 1:length(d)
%     k
%     filename = d(k).name;
%     formatSpec = '%q%q%q%q%q%q%q%q%q%q%q%q%q%q%[^\n\r]';
%     fileID = fopen(filename,'r');
%     dataArray = textscan(fileID, formatSpec, 'Delimiter',',', 'TextType', 'string', 'HeaderLines' ,5-1,  'ReturnOnError', false);
%     fclose(fileID);
% 
%     
%     ds = char(dataArray{1});
%     rep = strings(length(ds),2); rep(:) = '0';
%     ds(:,end-1:end) = rep;
%     dn = datenum(ds,'yyyy-mm-dd HH:MM:SS');
%     ms = str2double(dataArray{3})./86400;
%     fast.dn = [fast.dn; dn + ms];
%     fast.pr = [fast.pr; str2double(dataArray{13}).*10];
%     fast.x  = [fast.x; str2double(dataArray{4})];
% end
% fast.pr(fast.pr > 880) = NaN;   
%     
%     

f = naninterp(fast.pr);


%fast2 = sgolayfilt(f,3,(20*5)+1);
fast2 = movmean(f,20*5);
fast3 = movmean(f,20*1);
fcomp = interp1(fast.dn,fast2,met.dn);

cmap = lines;
clf;
plot(fast.dn,fast.pr,'color',cmap(1,:)); hold on;
plot(fast.dn,fast2-1.7986,'color',cmap(6,:));
plot(slow.dn,slow.pr,'color',cmap(7,:))
plot(met.dn,met.pr,'color',cmap(2,:)); 
legend('Licor 20 Hz','Licor 5s mean -1.8 hPa','Vailsala 1 min mean','Vaisala 5s sample');
datetick('x','mmmdd-hh','keepticks','keeplimits');
xlabel('Time UTC');
ylabel('Pressure [hPa]');
grid on;
title('ASFS April 18-19, 2019 overnight');
set(gca,'fontname','times','fontsize',12);
set(gcf,'PaperPositionMode','manual');
set(gcf,'PaperUnits','centimeters');
set(gcf,'PaperPosition',[0 0 20 16]);
print -dpng -r300 pres.png









