%**************************************************************************
%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_period          %Undulator period (m)
%   und_up_z_shift      %Shift along z of upper jaw (m)
%   und_lo_z_shift      %Shift along z of lower jaw (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, 11/16/10

function [param] = ppm_und_sim_param_varphase()

%Specify the parameter values-----

%Output file information
OUTPUT_FILE_DIR = 'C:\Magdata\Variable Phase Undulator\B at XYpos with Zshift\Xpos 0mm Ypos -.2mm Zshift 0 Gap 6.8mm\';

%End pm block parameters
%See Ross' notes, section H
END_PM1_DIR = 1;  %(upper first block, up)
END_PM_NUM_Z_POS = 3;
END_PM_BR = [1.2, 1.2, 1.2];  %(T)
END_PM_DIM(1, :) = [.066000, .057000, (.030000 / 4) / 4];  %(m)
END_PM_DIM(2, :) = [.066000, .057000, (.030000 / 4) / 2];  %(m)
END_PM_DIM(3, :) = [.066000, .057000, (.030000 / 4) * 3 / 4];  %(m)
END_SPACER_DIM = [(.030000 / 4) * 3 / 8, (.030000 / 4) * 3 / 8, .000000];  %(m)

%Center pm block parameters
CTR_PM_NUM_Z_POS = 66 * 4 + 1;
%CTR_PM_NUM_Z_POS = 10 * 4 + 1;  %Mini
CTR_PM_BR = 1.2;  %(T)
CTR_PM_DIM = [.066000, .057000, .030000 / 4];  %(m)
CTR_SPACER_DIM = .000000;  %(m)

%Undulator parameters
UND_GAP = .006800;  %Main vertical gap (m)
UND_PERIOD = 4 * (CTR_PM_DIM(3) + CTR_SPACER_DIM);  %Undulator period calculated from block dimensions (m)
UND_UP_Z_SHIFT = 0;  %(m)  Longitudinal shifts for K control
UND_LO_Z_SHIFT = 0;  %(m)  UP = +y, LO = -y, z is beam direction, y is up
% UND_UP_Z_SHIFT = UND_PERIOD * 3 / 8;  %(m)  Longitudinal shifts for K control
% UND_LO_Z_SHIFT = 0;  %(m)  UP = +y, LO = -y, z is beam direction, y is up

%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 : 3.0;
%FIELD_POS_Z = -.5 : .0002 : 1.0;  %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_period = UND_PERIOD;
param.und_up_z_shift = UND_UP_Z_SHIFT;
param.und_lo_z_shift = UND_LO_Z_SHIFT;
param.pm_div_size = PM_DIV_SIZE;
param.field_pos = FIELD_POS;

%Done

