%**************************************************************************
%This function outputs analysis comparison results to the data file.
%
%Input:
%dat_file, data file for results
%date_num, number giving the date of the measurement
%input_name, name of each dataset
%k_eff, Keff for each measurement
%dk_eff, difference between Keff for each measurement and the nominal value
%t_ave, average undulator temperature (C)
%dt_ave, difference between average undulator temperature and 20 C (C)
%dx_corr_k, x shift to compensate for K set different from Knom (m)
%dx_corr_t, x shift to compensate for T different from 20 C (m)
%dx_corr_k_t, x shift to compensate for both K and T difference from Knom and 20 C (m)
%
%Zachary Wolf, 3/30/09

function [] = k_comp_dat_results(dat_file, date_num, input_name, k_eff, dk_eff, t_ave, dt_ave, dx_corr_k, dx_corr_t, dx_corr_k_t)

%Open the data file
fid = fopen(dat_file, 'a');

%Write the values to the data file
fprintf(fid, '\r\n\r\n');
fprintf(fid, '                                 Corrections To Fiducialization          \r\n');
fprintf(fid, '\r\n');
fprintf(fid, '   Date         Name        Keff       dKeff      dX_K     Temp     dTemp     dX_T      dX_KT \r\n');
fprintf(fid, '                                                (micron)    (C)      (C)    (micron)  (micron)\r\n');
fprintf(fid, '-----------  -----------  ---------  ---------  --------  -------  -------  --------  --------\r\n');
for ii = 1 : length(t_ave)
    fprintf(fid, '%11s  %-11s  %9.6f  %9.6f  %8.1f  %7.3f  %7.3f  %8.1f  %8.1f\r\n', ...
        datestr(date_num(ii), 'dd-mmm-yyyy'), input_name{ii}, k_eff(ii), dk_eff(ii), dx_corr_k(ii) * 1.e6, t_ave(ii), dt_ave(ii), dx_corr_t(ii) * 1.e6, dx_corr_k_t(ii) * 1.e6);
end
%Close the file
fclose(fid);

%Done
