%**************************************************************************
%This function writes the parameter information to the data file.
%
%Input:
%dat_file, data file for results
%param, structure containing required program parameters
%	input_file_dir      %Input file directory
%   input_file_name     %Input file name
%   input_file_type     %Input file type, gives file format
%   corr_required       %Logical variable, apply a correction to the measured fields, true or false
%   corr_bx_mult        %Multiplicative correction factor for Bx
%   corr_by_mult        %Multiplicative correction factor for By
%   corr_bx_add         %Additive constant correction for Bx (T)
%   corr_by_add         %Additive constant correction for By (T)
%   corr_bxy_add_file   %Correction file name including directory, additive for Bx and By, 'none' for no correction
%   corr_bxy_add_file_type  %Correction file type, gives format
%   gamma               %Lorentz factor
%   nom_lambda_u        %Nominal undulator period (m)
%   nom_k_value         %Nominal undulator K parameter value
%   nom_lambda_r        %Nominal radiation wavelength (m)
%   num_poles           %Number of poles in the undulator
%   num_end_poles       %Number of poles used to determine end effects
%   cell_length         %Cell length, undulator length plus drift length at each end
%   nom_phase_cell      %Nominal phase change through the cell (rad)
%   nom_phase_match     %Nominal phase from the cell boundary to the first pole after the end poles (rad)
%   num_pole_stat       %Number of poles to use for entrance and exit phase error statistics
%
%Zachary Wolf, 1/13/06

function [] = epu_anal_dat_param(dat_file, param)

%Physical constants
global Q_ELEC;               %Electron charge (C)
global M_ELEC;               %Electron mass (kg)
global C_LIGHT;              %Speed of light (m/s)

%Calculate the beam energy
elec_energy = param.gamma * M_ELEC * C_LIGHT^2;  %Joules
elec_energy = elec_energy * (1 / 1.60217733e-19);  %eV
elec_energy = elec_energy * (1 / 1.e9);  %GeV

%Write the parameter information to the data file
fid = fopen(dat_file, 'a');
fprintf(fid, '\r\n');
fprintf(fid, 'Analysis Parameters:\r\n');
fprintf(fid, 'Input file directory = %s\r\n', param.input_file_dir);
fprintf(fid, 'Input file name = %s\r\n', param.input_file_name);
fprintf(fid, 'Input file type = %s\r\n', param.input_file_type);
fprintf(fid, 'Correction required = %i\r\n', param.corr_required);
fprintf(fid, 'Correction, Bx multiplicative factor = %f \r\n', param.corr_bx_mult);
fprintf(fid, 'Correction, By multiplicative factor = %f \r\n', param.corr_by_mult);
fprintf(fid, 'Correction, Bx additive constant = %f T\r\n', param.corr_bx_add);
fprintf(fid, 'Correction, By additive constant = %f T\r\n', param.corr_by_add);
fprintf(fid, 'Correction Bxy additive file = %s\r\n', param.corr_bxy_add_file);
fprintf(fid, 'Correction Bxy additive file type = %s\r\n', param.corr_bxy_add_file_type);
fprintf(fid, 'Set field integrals required = %i \r\n', param.set_i1xy_required);
fprintf(fid, 'Set value for I1X = %f Tm\r\n', param.set_i1x);
fprintf(fid, 'Set value for I1y = %f Tm\r\n', param.set_i1y);
fprintf(fid, 'Electron gamma = %f\r\n', param.gamma);
fprintf(fid, 'Electron energy = %f Gev\r\n', elec_energy);
fprintf(fid, 'Nominal undulator period = %f m\r\n', param.nom_lambda_u);
fprintf(fid, 'Nominal K value = %f\r\n', param.nom_k_value);
fprintf(fid, 'Nominal radiation wavelength = %e m\r\n', param.nom_lambda_r);
fprintf(fid, 'Number of undulator poles = %i\r\n', param.num_poles);
fprintf(fid, 'Number of end poles (used in analysis) = %i\r\n', param.num_end_poles);
fprintf(fid, 'Cell length = %f m\r\n', param.cell_length);
fprintf(fid, 'Nominal phase change through cell = %f rad\r\n', param.nom_phase_cell);
fprintf(fid, 'Nominal phase of pole after end poles = %f rad\r\n', param.nom_phase_match);
fprintf(fid, 'Number of poles for entrance and exit phase error statistics = %i\r\n', param.num_pole_stat);
fclose(fid);

%Done
