%**************************************************************************
%This function gets the gap from the header of the
%undulator data file.
%
%Input:
%header, header from the undulator data file
%
%Output:
%gap, undulator gap (m)
%
%Zachary Wolf
%6/14/16

function [gap] = util_get_gap_header(header)

%Initialize
gap = 0;
        
%Find the comment
[r, c] = size(header);
for ii = 1 : c
    if strfind(header{ii}, 'Comment:') > 0
        comment_str = header{ii};
        break;
    end
end

%Get the gap
[gap, count] = sscanf(comment_str, 'Comment: Phase matching; gap = %fmm');
if count == 1
    gap = gap * 1.e-3;  %(m)
else
    error(['Could not read gap from header: ', comment_str]);
end

%Done
