%**************************************************************************
%This function sets the program parameters.
%
%Output:
%param, structure containing program parameters
%   output_file_dir     %Directory for output files
%   pm_div_size         %Permanent magnet segmentation size along each axis for equivalent charges (m)
%   pm_br               %Permanent magnet remnant field (T)
%   pm_m(3)             %Magnetic moment per unit volume in coordinate system tied to block [m_x, m_y, m_z] (A/m)
%   pm_dim(3)           %Magnet block dimension in each direction, in coordinate system tied to block [w_x, w_y, w_z] (m)
%   pm_rot(3x3)         %Rotation matrix, rotate the block about its center, direction cosines R_ij = e_rot_i . e_orig_j
%   pm_trans(3)         %Translate the rotated block in x, y, and z in global coordinates parallel to the original block coordinates [t_x, t_y, t_z] (m)
%   field_pos(nx3)      %Positions where field is calculated, [x(n), y(n), z(n)] coordinates (m)
%
%Zachary Wolf, 4/5/10

function [param] = pm_block_rect_sim_param()

%Global
global mu_0;

%Define the parameters-----

%Output file information
OUTPUT_FILE_DIR = 'C:\Magdata\Variable Phase Undulator\Lambda_u 55cm\PM Block\';

%Permanent magnet segmentation size along each axis for equivalent charges
PM_DIV_SIZE = .001;  %(m)

%Permanent magnet remnamt field
PM_BR = 1.2;  %(T)

%Magnetic moment per unit volume, coordinates tied to block
PM_M = (PM_BR / mu_0) * [0, 1, 0];  %(A/m)

%Permanent magnet dimension in x, y, and z, coordinates tied to block
%PM_DIM = [.0508, .0508, .0127];  %(m)
%PM_DIM = [.07, .07, .055 / 4];  %(m)
PM_DIM = [.07, .07, .1];  %(m)

%Rotate the magnet block about its center, direction cosine matrix R_ij = e_rot_i . e_orig_j
% theta = 90 * pi / 180;
% PM_ROT = [ 1, 0,          0          ;...
%            0, cos(theta), sin(theta) ;...
%            0, -sin(theta), cos(theta)];
%PM_ROT = [ cos(theta), sin(theta), 0;...
%          -sin(theta), cos(theta), 0;...
%           0,          0,          1];
PM_ROT = [1, 0, 0;...
          0, 1, 0;...
          0, 0, 1];

%Translate the rotated block in x, y, and z in global coordinates parallel to the original block coordinates
PM_TRANS = [0, 0, 0];  %(m)

%Positions where field is calculated
%FIELD_POS_X = -.04 : .004 : .04;
FIELD_POS_X = 0;
%FIELD_POS_Y = -.04 : .004 : .04;
FIELD_POS_Y = PM_DIM(2) / 2 + .0001 : .001 : PM_DIM(2) / 2 + .02;
%FIELD_POS_Z = [0, PM_DIM(3) / 2 + .0001];
%FIELD_POS_Z = 0;
FIELD_POS_Z = -.04 : .004 : .04;

%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.pm_div_size = PM_DIV_SIZE;
param.pm_br = PM_BR;
param.pm_m = PM_M;
param.pm_dim = PM_DIM;
param.pm_rot = PM_ROT;
param.pm_trans = PM_TRANS;
param.field_pos = FIELD_POS;

%Done
