%**************************************************************************
%This function reads measurement data from a file.  The columns
%are z, measured voltages, and the calculated
%fields.  No checks on the calculated fields are performed.
%
%Input:
%file_name, name of the measurement data file
%
%Output:
%header, header information of the data file
%z, z positions of the measurements (m)
%bx, measurements of the Bx field (T)
%by, measurements of the By field (T)
%bz, measurements of the Bz field (T)
%
%Zack Wolf, 6/1/11

function [header, z, bx, by, bz] = read_meas_hd_radia(file_name)

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

%Extract the header information
%Read down to the comment line
ii = 0;
while 1
    in_line = fgetl(fid);
    ii = ii +1;
    header{ii} = in_line;
    if findstr('[mm]', in_line) > 0
        break;
    end
end

%Continue reading until the data begins
%Look for the column headers
while 1
   in_line = fgets(fid);
   if findstr('-----', in_line) > 0
       break;
   end
end

%Read the data
data_array = fscanf(fid, '%f %f %f', [3, inf]);
% z = data_array(1, :) / 1000;  %(m)
% bx = data_array(2, :) / 10000;  %(T)
% bz = data_array(3, :) / 10000;  %(T)
% by = data_array(4, :) / 10000;  %(T)
z = data_array(1, :) / 1000;  %(m)
bx = data_array(2, :);  %(T)
by = data_array(3, :);  %(T)
bz = zeros(1, length(by));

%Close the file
fclose(fid);

%Done