disp('prt_STRATUS_2017_flux_hr');
fclose('all');
clear flux1hr;

f = fullfile(da_path,['STRATUS_2017_flux_hr_',datasetv,'_',dcname,'.txt']);
flist = fopen(f,'w');

thet1rel2 = thet1rel;
thet1rel2(thet1rel2<0) = thet1rel2(thet1rel2<0)+360;

npz = length(jda);
flux1hr(1,1:npz) = jda';           % date
flux1hr(2,1:npz) = yushp;          % uship
flux1hr(3,1:npz) = v1;             % u true
flux1hr(4,1:npz) = thet1;          % true dir
flux1hr(5,1:npz) = v1rel;          % u rel
flux1hr(6,1:npz) = thet1rel2;      % rel dir - save in 0-360 deg format
flux1hr(7,1:npz) = yhead;          % ship heading
flux1hr(8,1:npz) = y1(:,20)';      % SST seasnake
flux1hr(9,1:npz) = y4(:,5)';       % Ta best
flux1hr(10,1:npz) = y4(:,4)';      % qs best
flux1hr(11,1:npz) = y4(:,7)';      % qa best
flux1hr(12,1:npz) = yhsc;          % hs covariance
flux1hr(13,1:npz) = yhsib;         % hs ID
flux1hr(14,1:npz) = yhsb;          % hs bulk
flux1hr(15,1:npz) = yhlc_bl;       % hl blend of cov results
flux1hr(16,1:npz) = yhlib_lic;     % hl ID
flux1hr(17,1:npz) = yhlb;          % hl bulk
flux1hr(18,1:npz) = taucx;         % stress stream-wise covariance
flux1hr(19,1:npz) = taucy;         % stress cross-stream covariance
flux1hr(20,1:npz) = tauib;         % stress ID
flux1hr(21,1:npz) = taub;          % stress bulk
flux1hr(22,1:npz) = y4(:,8)';      % rs best
flux1hr(23,1:npz) = y4(:,9)';      % rl best
flux1hr(24,1:npz) = y4(:,11)';     % ORG rain rate
flux1hr(25,1:npz) = yj;            % ship plume contam index
flux1hr(26,1:npz) = y1(:,44)';     % tilt of good data
flux1hr(27,1:npz) = yjm;           % maneuver index
switch IDflag
    case 'a'
        flux1hr(28,1:npz) = y1(:,138)';    % ct
        flux1hr(29,1:npz) = y1(:,140);     % cql
        flux1hr(30,1:npz) = y1(:,134)';    % cu
        flux1hr(31,1:npz) = y1(:,136)';    % cw
    case 'b'
        flux1hr(28,1:npz) = y1(:,139)';    % ct
        flux1hr(29,1:npz) = y1(:,141);     % cql
        flux1hr(30,1:npz) = y1(:,135)';    % cu
        flux1hr(31,1:npz) = y1(:,137)';    % cw
end
flux1hr(32,1:npz) = yhrain;        % Rain heat flux
flux1hr(33,1:npz) = hl_webar';     % Hl webb flux
flux1hr(34,1:npz) = y1(:,151)';    % lat
flux1hr(35,1:npz) = y1(:,150)';    % lon
flux1hr(36,1:npz) = y1(:,27)';     % zu
flux1hr(37,1:npz) = y1(:,28)';     % zt
flux1hr(38,1:npz) = y1(:,29)';     % zq
flux1hr(39,1:npz) = ysog;          % uship scs
flux1hr(40,1:npz) = v1_scs;        % u true scs
flux1hr(41,1:npz) = thet1_scs;     % true dir scs
flux1hr(42,1:npz) = ycog;          % ship course scs
flux1hr(43,1:npz) = y1(:,6)';      % Ts scs, raw ship measurement
flux1hr(44,1:npz) = y1(:,3)';      % T scs
flux1hr(45,1:npz) = y4(:,4)';      % qs scs
flux1hr(46,1:npz) = y4(:,7)';      % qa scs
flux1hr(47,1:npz) = y1(:,7)';      % rs scs
flux1hr(48,1:npz) = y1(:,8)';      % rl scs
flux1hr(49,1:npz) = y3(:,4)'*NaN;  % w'c' licor - NOT COMPUTED
flux1hr(50,1:npz) = y3(:,2)';      % Specific Humidity from Licor (g/kg)
flux1hr(51,1:npz) = y3(:,12)';     % Stv of Specific Humidity from Licor (g/kg)
flux1hr(52,1:npz) = y3(:,4)';      % CO2 concentration from Licor (umol/mol)
flux1hr(53,1:npz) = y3(:,14)';     % Stv of CO2 concentration from Licor (umol/mol)
flux1hr(54,1:npz) = y4(:,10)';     % atmospheric pressure best (mbar), sea level
flux1hr(55,1:npz) = v1';           % Wind speed (m/s) relative to earth
flux1hr(56,1:npz) = thet1';        % Wind direction (deg) from relative to earth
flux1hr(57,1:npz) = rnl_hr';       % net longwave heat flux
flux1hr(58,1:npz) = hnetb_hr';     % net heat flux, bulk, W/m2 hourly
flux1hr(59,1:npz) = hnet_hr';      % net heat flux, turb, W/m2 hourly
flux1hr(60,1:npz) = yu03n';        % 3m neutral windspeed, COARE 3.5
flux1hr(61,1:npz) = yt03n';        % 3m neutral temperature, COARE 3.5
flux1hr(62,1:npz) = yrh03';        % 3m RH, COARE 3.5
flux1hr(63,1:npz) = y1(:,4)';      % scs RH
flux1hr(64,1:npz) = y1(:,5)';      % scs Pmb, sea level
flux1hr(65,1:npz) = y1(:,169)';    % PSD WXT RH, %

% vectorized print, 65 columns
% prepare format string for numeric data
fmtStr = '';
fmtStr = strcat('\r\n', fmtStr);
for i = 1:65
    fmtStr = strcat('%12.6f ', fmtStr);
end
fprintf(flist,fmtStr,flux1hr);
fclose('all');
disp(['File written as ' f]);

% save copy in .mat format
dfl = fullfile(da_path,['STRATUS_2017_flux_hr_',datasetv,'_',dcname,'.mat']);
flux1hr = flux1hr';
save(dfl,'flux1hr');


