%**************************************************************************
%This function reads undulator row setting data from a file.
%
%Input:
%file_name, name of the measurement data file
%
%Output:
%header, header information of the data file
%mode, undulator mode for the given row settings
%rel_k, relative K values for the given row settings
%z01, row position for quadrant 1 (m)
%z02, row position for quadrant 2 (m)
%z03, row position for quadrant 3 (m)
%z04, row position for quadrant 4 (m)
%
%Zack Wolf
%1/14/15

function [header, mode, rel_k, z01, z02, z03, z04] = read_meas_row_settings(file_name)

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

%Extract the header information
%Read down to the column headers
ii = 0;
while 1
    in_line = fgetl(fid);
    ii = ii +1;
    header{ii} = in_line;
    if findstr('-----', in_line) > 0
        break;
    end
end

%Read the data
ii = 0;
in_line = 0;
while in_line ~= -1
    in_line = fgetl(fid);
    if in_line ~= -1
        ii = ii +1;
        a = sscanf(in_line, '%*i %5s %f %f %f %f %f', 10);
        mode{ii} = char(a(1:5))';
        rel_k(ii) = a(6);
        z01(ii) = a(7);
        z02(ii) = a(8);
        z03(ii) = a(9);
        z04(ii) = a(10);
    end
end

%Close the file
fclose(fid);

%Done