%**************************************************************************
%fiducialization.m
%
%This function reads measurement data from a Hall probe scan along the beam
%axis and from the pointed magnet center location program.  It calculates
%where the beam axis is relative to tooling balls on the fiducialization
%magnets.
%
%Zachary Wolf, 1/5/08

function [] = fiducialization()

%Clear the workspace
clear

%Set parameter values by executing the parameter file
fiducialization_param;

%Make the parameter structure
param.input_zscan_file = INPUT_ZSCAN_FILE;
param.output_file_dir = OUTPUT_FILE_DIR;

%Output files
dat_file = [param.output_file_dir, 'fiducialization.dat'];
mat_file = [param.output_file_dir, 'fiducialization.mat'];

%Read the zscan measurements
[zscan_header, zm, bx, by] = read_meas_zvxybxyh(param.input_zscan_file);

%Initialize the data file
fid_dat_init(dat_file, param, zscan_header);

%Get the zscan temperature and (x, y) position of the scan
zscan_temp = temp_get_und_temp(zscan_header);
[zscan_x_pos, zscan_y_pos] = fid_get_zscan_xy_pos(zscan_header);

%Write a summary of the zscan measurements to the data file
fid_dat_zscan_info(dat_file, zscan_temp, zscan_x_pos, zscan_y_pos);

%Output the measurement data
save(mat_file, 'param', 'zscan_header');

%Done
