%**************************************************************************
%This function writes fringe field information to the data file.
%
%Input:
%dat_file, data file for results
%b_name, field name 'Bx' or 'By'
%int_b_dz_fringe_lim, limit specifying the end of the fringe field (Tm)
%z_field_start, z position where the fringe field starts at the entrance end (m)
%z_field_end, z position where the fringe field ends at the exit end (m)
%z_dev_enter, device entrance z position (m)
%z_dev_exit, device exit z position (m)
%len_fringe_enter, length of the fringe field at the entrance (m)
%len_fringe_exit, length of the fringe field at the exit (m)
%
%Zachary Wolf
%8/5/11

function [] = field_dat_fringe_fields(dat_file, b_name, int_b_dz_fringe_lim, z_field_start, z_field_end, z_dev_enter, z_dev_exit, len_fringe_enter, len_fringe_exit)

%Check
if ((z_field_start >= z_dev_enter) || (z_field_end <= z_dev_exit))
    return;
end

%Write fringe field integral information to the data file
fid = fopen(dat_file, 'a');
fprintf(fid, '\r\n');
fprintf(fid, [b_name, ' End Fields:\r\n']);
fprintf(fid, 'Z position of device entrance = %8.4f m\r\n', z_dev_enter);
fprintf(fid, 'Z position of device exit = %8.4f m\r\n', z_dev_exit);
fprintf(fid, 'Length of device = %8.4f m\r\n', z_dev_exit - z_dev_enter);
fprintf(fid, 'Field integral limit specifying the end of the fringe field = %13.4e Tm\r\n', int_b_dz_fringe_lim);
fprintf(fid, 'Z position where entrance Int B dz at limit = %8.4f m\r\n', z_field_start);
fprintf(fid, 'Z position where exit Int B dz at limit = %8.4f m\r\n', z_field_end);
fprintf(fid, 'Magnetic length entrance = %8.4f m\r\n', len_fringe_enter);
fprintf(fid, 'Magnetic length exit = %8.4f m\r\n', len_fringe_exit);
fprintf(fid, 'Magnetic length total = %8.4f m\r\n', z_field_end - z_field_start);
fclose(fid);

%Done