%**************************************************************************
%This function writes to a text file (Int Bx dz) and (Int By dz)
%as a function of x, along a line whose y position is specified.
%The closest line with calculated data points is used.
%
%Input:
%dat_file, data file for results
%field_int, structure containing the field integral information
%y_val_req, requested y position of line for (Int Bxy dz) vs x (m)
%
%Zachary Wolf, 9/30/10

function magic_fingers_dat_intbxydz_vs_x(dat_file, field_int, y_val_req)

%Write the results to the data file
fid = fopen(dat_file, 'a');
[y_close, iy_close] = min(abs(field_int.pos(:, 2) - y_val_req));
y_val = field_int.pos(iy_close(1), 2);
index_array = find(field_int.pos(:, 2) == y_val);
x = field_int.pos(index_array, 1);
int_bx_dz = field_int.int_bx_dz(index_array);
int_by_dz = field_int.int_by_dz(index_array);
fprintf(fid, '\r\n');
fprintf(fid, 'Simulated (Int Bx dz) and (Int By dz) vs x:\r\n');
fprintf(fid, 'y = %f m\r\n', y_val);
fprintf(fid, '     X        Int Bx dz    Int By dz \r\n');
fprintf(fid, '    (m)         (Tm)         (Tm)    \r\n');
fprintf(fid, '-----------  -----------  -----------\r\n');
fprintf(fid, '%11.6f  %11.6f  %11.6f\r\n', [x, int_bx_dz, int_by_dz]');
fclose(fid);

%Done
