%**************************************************************************
%This function sets the program parameters.
%
%Output:
%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, 4/25/10

function [param] = ppm_und_sim_param_epu()

%Specify the parameter values-----

%Output file information
OUTPUT_FILE_DIR = 'C:\Magdata\ADC EPU\B Vert Gap 25mm Zpos234 -300microns\';

%End pm block parameters
END_PM1_DIR = 4;  %(q1 first block, left)
END_PM_NUM_Z_POS = 3;
END_PM_BR = [1.04652, 1.04652, 1.04652];  %(T)
END_PM_DIM(1, :) = [.040000, .040000, .005220];  %(m)
%END_PM_DIM(2, :) = [.040000, .040000, .007170];  %(m)
END_PM_DIM(2, :) = [.040000, .040000, .007110];  %(m)
END_PM_DIM(3, :) = [.040000, .040000, .010430];  %(m)
END_SPACER_DIM = [.002000, .004300, .001200];  %(m)

%Center pm block parameters
CTR_PM_NUM_Z_POS = 64 * 4 + 1;
%CTR_PM_NUM_Z_POS = 10 * 4 + 1;  %Mini
CTR_PM_BR = 1.04652;  %(T)
CTR_PM_DIM = [.040000, .040000, .014220];  %(m)
CTR_SPACER_DIM = .000050;  %(m)

%Undulator parameters
%UND_GAP = .014000;  %Main vertical gap (m)
UND_GAP = .025000;  %Main vertical gap (m)
UND_H_GAP = .001;   %Horizontal gap between rows (m)
UND_PERIOD = 4 * (CTR_PM_DIM(3) + CTR_SPACER_DIM);  %Undulator period calculated from block dimensions (m)
UND_Q1_Z_SHIFT = 0;  %(m)  Longitudinal shifts for polarization and K control
UND_Q2_Z_SHIFT = 0;  %(m)  Q1 = +x +y, Q2 = -x +y, Q3 = -x -y, Q4 = +x -y, z is beam direction, y is up
UND_Q3_Z_SHIFT = 0;  %(m)  Zero shift gives a By planar undulator
UND_Q4_Z_SHIFT = 0;  %(m)
% UND_Q1_Z_SHIFT = UND_PERIOD * 3 / 8;  %(m)  Longitudinal shifts for polarization and K control
% UND_Q2_Z_SHIFT = UND_PERIOD * 3 / 8;  %(m)  Q1 = +x +y, Q2 = -x +y, Q3 = -x -y, Q4 = +x -y, z is beam direction, y is up
% UND_Q3_Z_SHIFT = 0;  %(m)  Zero shift gives a By planar undulator
% UND_Q4_Z_SHIFT = 0;  %(m)
% UND_Q1_Z_SHIFT = UND_PERIOD / 4;  %(m)  Longitudinal shifts for polarization and K control
% UND_Q2_Z_SHIFT = 0;  %(m)  Q1 = +x +y, Q2 = -x +y, Q3 = -x -y, Q4 = +x -y, z is beam direction, y is up
% UND_Q3_Z_SHIFT = UND_PERIOD / 4;  %(m)  Zero shift gives a By planar undulator
% UND_Q4_Z_SHIFT = 0;  %(m)
% UND_Q1_Z_SHIFT = UND_PERIOD / 2;  %(m)  Longitudinal shifts for polarization and K control
% UND_Q2_Z_SHIFT = 0;  %(m)  Q1 = +x +y, Q2 = -x +y, Q3 = -x -y, Q4 = +x -y, z is beam direction, y is up
% UND_Q3_Z_SHIFT = UND_PERIOD / 2;  %(m)  Zero shift gives a By planar undulator
% UND_Q4_Z_SHIFT = 0;  %(m)

%General pm block parameters
PM_DIV_SIZE = .0015;  %(m)

%Positions where field is calculated
FIELD_POS_X = 0;
%FIELD_POS_X = 200.e-6;
%FIELD_POS_X = -.05 : .0005 : .05;
FIELD_POS_Y = 0;
%FIELD_POS_Y = 200.e-6;
FIELD_POS_Z = -1.0 : .0002 : 4.8;
%FIELD_POS_Z = -.5 : .0002 : 1.2;  %Mini
%FIELD_POS_Z = .2385;  %Mini

%Put the field points into an array
FIELD_POS = zeros(length(FIELD_POS_X) * length(FIELD_POS_Y) * length(FIELD_POS_Z), 3);
index = 0;
for ii = 1 : length(FIELD_POS_X)
    for jj = 1 : length(FIELD_POS_Y)
        for kk = 1 : length(FIELD_POS_Z)
            index = index + 1;
            FIELD_POS(index, :) = [FIELD_POS_X(ii), FIELD_POS_Y(jj), FIELD_POS_Z(kk)];
        end
    end
end

%Put the parameters in the param structure-----

%Program parameters
param.output_file_dir = OUTPUT_FILE_DIR;
param.end_pm1_dir = END_PM1_DIR;
param.end_pm_num_z_pos = END_PM_NUM_Z_POS;
param.end_pm_br = END_PM_BR;
param.end_pm_dim = END_PM_DIM;
param.end_spacer_dim = END_SPACER_DIM;
param.ctr_pm_num_z_pos = CTR_PM_NUM_Z_POS;
param.ctr_pm_br = CTR_PM_BR;
param.ctr_pm_dim = CTR_PM_DIM;
param.ctr_spacer_dim = CTR_SPACER_DIM;
param.und_gap = UND_GAP;
param.und_h_gap = UND_H_GAP;
param.und_period = UND_PERIOD;
param.und_q1_z_shift = UND_Q1_Z_SHIFT;
param.und_q2_z_shift = UND_Q2_Z_SHIFT;
param.und_q3_z_shift = UND_Q3_Z_SHIFT;
param.und_q4_z_shift = UND_Q4_Z_SHIFT;
param.pm_div_size = PM_DIV_SIZE;
param.field_pos = FIELD_POS;

%Done

