%**************************************************************************
%This function writes to a text file By and Bx vs z along a line
%whose x and y positions are specified.  The closest line with calculated
%data points is used.
%
%Input:
%dat_file, data file for results
%block, structure containing the block information
%charge, structure containing the magnetic charge information
%mag_field, structure containing the magnetic field information
%x_val_req, requested x position of line to plot B along (m)
%y_val_req, requested y position of line to plot B along (m)
%
%Zachary Wolf, 4/2/08

function ppm_dat_byx_vs_z(dat_file, mag_field, x_val_req, y_val_req)

%Write the results to the data file
fid = fopen(dat_file, 'a');
[x_close, ix_close] = min(abs(mag_field.x - x_val_req));
x_val = mag_field.x(ix_close(1));
[y_close, iy_close] = min(abs(mag_field.y - y_val_req));
y_val = mag_field.y(iy_close(1));
index_array = find((mag_field.x == x_val) & (mag_field.y == y_val) == 1);
fprintf(fid, '\r\n');
fprintf(fid, 'Simulated By and Bx vs z:\r\n');
fprintf(fid, 'x = %f m\r\n', x_val);
fprintf(fid, 'y = %f m\r\n', y_val);
fprintf(fid, '\r\n');
fprintf(fid, '     Z           By           Bx     \r\n');
fprintf(fid, '    (m)          (T)          (T)    \r\n');
fprintf(fid, '-----------  -----------  -----------\r\n');
fprintf(fid, '%11.6f  %11.6f  %11.6f\r\n', [mag_field.z(index_array); mag_field.by(index_array); mag_field.bx(index_array)]);
fclose(fid);

%Done
