%**************************************************************************
%This function reads measurement data from a DESY data file.  The columns
%are z and the calculated By field.  
%
%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, 6/12/04

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

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

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

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

%DESY uses mm, convert to m
z = z / 1000.;

%Close the file
fclose(fid);

%Done