%**************************************************************************
%This function reads measurement data from a file.  The columns
%are z and the measured Hall probe voltage.  The field is calculated from a
%nominal calibration.
%
%Input:
%file_name, name of the measurement data file
%
%Output:
%header, header information of the data file
%z, z positions of the measurements (m)
%by, measurements of the By field (T)
%
%Zack Wolf, 7/25/03

function [header, z, by] = read_meas_zvyh(file_name)

%Open the wiggler data file
fid = fopen(file_name, 'r');
if fid == -1
    disp('idanal_read_meas_zvyh: unable to open input file');
end

%Extract the header information
NUM_LINES_HEADER = 1;
for ii = 1 : NUM_LINES_HEADER
    header{ii} = fgetl(fid);
end

%Read the data
data_array = fscanf(fid, '%f %f', [2, inf]);
z = data_array(1, :);
v = data_array(2, :);

%Do a zero field correction
v = v - (-0.0020);

%Convert from voltage to field (1 T = 5 V)
by = v * (1. / 5.);

%Close the file
fclose(fid);

%Open a data file for MA data
%fid = fopen([file_name, '_ma'], 'w');
%data_array = [z * 1000; -by];
%fprintf(fid, '%12.6f, %15.9f\r\n', data_array);
%fclose(fid);

%Done