%**************************************************************************
%This function generates fake EPU field data.  It writes the field data to
%an output file.
%
%Zachary Wolf
%8/6/13

function [] = gen_bxyzvsz()

%Clear the workspace
clear

%Get the program parameters
[param] = gen_bxyzvsz_param();

%Make the output file name
dat_file = strcat(param.output_file_dir, 'gen_bxyzvsz.dat');
mat_file = strcat(param.output_file_dir, 'gen_bxyzvsz.mat');

%Initialize the data file
util_dat_init(dat_file);

%Write a message to the data file
msg{1} = ' ';
msg{2} = 'Generate Fake EPU Field Measurements';
msg{3} = '************************************';
util_dat_msg(dat_file, msg);

%Write the parameter values to the data file
gen_dat_param(dat_file, param);

%Calculate the fields
pol_mode = param.pol_mode;
x = param.x;
y = param.y;
z = param.z;
if strcmp(pol_mode, 'LIN_POL_VERT_FIELD')
    [bx, by, bz] = gen_lin_pol_vert_field(param, x, y, z);
elseif strcmp(pol_mode, 'LIN_POL_HORIZ_FIELD')
    [bx, by, bz] = gen_lin_pol_horiz_field(param, x, y, z);
elseif strcmp(pol_mode, 'CIRC_POL_RIGHT_HAND')
    [bx, by, bz] = gen_circ_pol_right_hand(param, x, y, z);
elseif strcmp(pol_mode, 'CIRC_POL_LEFT_HAND')
    [bx, by, bz] = gen_circ_pol_left_hand(param, x, y, z);
else
    error('Unknown polarization mode');
end

%Write the results to the data file
gen_dat_zbxyz(dat_file, z, bx, by, bz);

%Output the results to the mat file
save(mat_file, 'param', 'z', 'bx', 'by', 'bz');

end
