%**************************************************************************
%This function writes the field integral data to a file.
%
%Input:
%dat_file, data file for results
%param, parameter structure
%pos, position of measurement (m)
%integ, field integral (Tm or Tm^2)
%
%Zachary Wolf, 9/6/08

function [] = long_coil_dat_integ(dat_file, param, pos, integ)

%Initialize
if strcmp(param.meas_type, 'I1YVSX')  %Iy vs x
    title_str = '   Int By dz vs X    ';
    pos_str = '  X Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int1 By dz';
    integ_unit_str = '   (Tm)   ';
elseif strcmp(param.meas_type, 'I2YVSX')
    title_str = 'Int Int By dz dz vs X';
    pos_str = '  X Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int2 By dz';
    integ_unit_str = '  (Tm^2)  ';
elseif strcmp(param.meas_type, 'I1XVSX')  %Ix vs x
    title_str = '   Int Bx dz vs X    ';
    pos_str = '  X Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int1 Bx dz';
    integ_unit_str = '   (Tm)   ';
elseif strcmp(param.meas_type, 'I2XVSX')
    title_str = 'Int Int Bx dz dz vs X';
    pos_str = '  X Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int2 Bx dz';
    integ_unit_str = '  (Tm^2)  ';
elseif strcmp(param.meas_type, 'I1YVSY')  %Iy vs y
    title_str = '   Int By dz vs Y    ';
    pos_str = '  Y Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int1 By dz';
    integ_unit_str = '   (Tm)   ';
elseif strcmp(param.meas_type, 'I2YVSY')
    title_str = 'Int Int By dz dz vs Y';
    pos_str = '  Y Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int2 By dz';
    integ_unit_str = '  (Tm^2)  ';
elseif strcmp(param.meas_type, 'I1XVSY')  %Ix vs y
    title_str = '   Int Bx dz vs Y    ';
    pos_str = '  Y Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int1 Bx dz';
    integ_unit_str = '   (Tm)   ';
elseif strcmp(param.meas_type, 'I2XVSY')
    title_str = 'Int Int Bx dz dz vs Y';
    pos_str = '  Y Pos  ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Int2 Bx dz';
    integ_unit_str = '  (Tm^2)  ';
else
    title_str = 'Unknown Measurement Type';  %Other
    pos_str = 'Position ';
    pos_unit_str = '   (m)   ';
    integ_str = 'Field Int ';
    integ_unit_str = '(Tm, Tm^2)';
end

%Open the data file
fid = fopen(dat_file, 'a');

%Write the field integrals to the data file
fprintf(fid, '\r\n\r\n\r\n');
fprintf(fid, '   %s    \r\n', title_str);
fprintf(fid, '\r\n');
fprintf(fid, 'Meas  %s  %s\r\n', pos_str, integ_str);
fprintf(fid, ' #    %s  %s\r\n', pos_unit_str, integ_unit_str);
fprintf(fid, '----  ---------  ----------\r\n');
meas_num = 1 : length(pos);
fprintf(fid, '%4i  %9.6f  %10.6f\r\n', [meas_num; pos; integ]);

%Close the data file
fclose(fid);

%Done
