%**************************************************************************
%This function writes the parameter information to the data file.
%
%Input:
%dat_file, data file for results
%param, structure containing program parameters
%   output_file_dir     %Directory for output files
%   end_pm1_dir         %Direction of the field in the first upper block, convention: up = 1, right = 2, down = 3, left = 4
%   end_pm_num_z_pos    %Number of z positions (ie. upper blocks) in the undulator ends
%   end_pm_br(n)        %Remnant field in the end blocks (T)
%   end_pm_dim(n, 3)    %Magnet block dimensions for each end block in coordinate system tied to block [w_x, w_y, w_z] (m) 
%   end_spacer_dim(n)   %Thickness of the spacer after each end block (m)
%   ctr_pm_num_z_pos    %Number of z positions (ie. upper blocks) in the undulator center
%   ctr_pm_br           %Remnant field in the center blocks (T)
%   ctr_pm_dim(3)       %Magnet block dimensions for each center block in coordinate system tied to block [w_x, w_y, w_z] (m) 
%   ctr_spacer_dim      %Thickness of the spacer after each center block (m)
%   und_gap             %Undulator gap (m)
%   und_h_gap           %Horizontal gap between upper and lower EPU quadrants (m)
%   und_period          %Undulator period (m)
%   und_q1_z_shift      %Shift along z of quadrant 1 (m)
%   und_q2_z_shift      %Shift along z of quadrant 2 (m)
%   und_q3_z_shift      %Shift along z of quadrant 3 (m)
%   und_q4_z_shift      %Shift along z of quadrant 4 (m)
%   pm_div_size         %Permanent magnet segmentation size along each axis for equivalent charges (m)
%   field_pos(n, 3)     %Positions where field is calculated, [x(n), y(n), z(n)] coordinates (m)
%
%Zachary Wolf, 8/30/10

function [] = ppm_und_dat_param_epu(dat_file, param)

%Write the parameter information to the data file
fid = fopen(dat_file, 'a');
fprintf(fid, '\r\n');
fprintf(fid, 'Simulation Parameters:\r\n');
fprintf(fid, 'Output file directory = %s\r\n', param.output_file_dir);
fprintf(fid, 'Upper first block field direction = %i\r\n', param.end_pm1_dir);
fprintf(fid, 'End number of z positions (upper blocks) = %i\r\n', param.end_pm_num_z_pos);
for ii = 1 : param.end_pm_num_z_pos
    fprintf(fid, 'End Block %i:\r\n', ii);
    fprintf(fid, '  Remnant field = %f T\r\n', param.end_pm_br(ii));
    fprintf(fid, '  Dimensions [Wx, Wy, Wz] = [%f, %f, %f] m\r\n', param.end_pm_dim(ii, 1), param.end_pm_dim(ii, 2), param.end_pm_dim(ii, 3));
    fprintf(fid, '  Spacer thickness = %f m\r\n', param.end_spacer_dim(ii));
end
fprintf(fid, 'Center number of z positions (upper blocks) = %i\r\n', param.ctr_pm_num_z_pos);
fprintf(fid, 'Center blocks remnant field = %f T\r\n', param.ctr_pm_br);
fprintf(fid, 'Center blocks dimensions [Wx, Wy, Wz] = [%f, %f, %f] m\r\n', param.ctr_pm_dim(1), param.ctr_pm_dim(2), param.ctr_pm_dim(3));
fprintf(fid, 'Center spacer thickness = %f m\r\n', param.ctr_spacer_dim);
fprintf(fid, 'Undulator gap = %f m\r\n', param.und_gap);
fprintf(fid, 'Undulator horizontal gap between rows = %f m\r\n', param.und_h_gap);
fprintf(fid, 'Undulator period = 4 (Wz + spacer) = %f m\r\n', param.und_period);
fprintf(fid, 'Undulator Q1 z-shift = %f m\r\n', param.und_q1_z_shift);
fprintf(fid, 'Undulator Q2 z-shift = %f m\r\n', param.und_q2_z_shift);
fprintf(fid, 'Undulator Q3 z-shift = %f m\r\n', param.und_q3_z_shift);
fprintf(fid, 'Undulator Q4 z-shift = %f m\r\n', param.und_q4_z_shift);
fprintf(fid, 'PM block division size for charges = %f m\r\n', param.pm_div_size);
fclose(fid);

%Done
