function [d] = read_eos_fields(varargin);

% Usage:
%
% [d] = read_eos_fields(filename,swathname,fieldlist,start,stop,edge)
%
% Input
%    filename         : eos_hdf file name; string
%    swathname       : swath name containing fields; string
%    fieldlist        : list of field names; list of strings
%    start,stop,edge  : eos_hdf subsetting parameters; strings
%  
%    Note:  normally start,stop,edge all equal '[]'  
%
% Output
%    d  : structure containing field values in double format
%
%  V 0.9,  L. Strow, July 27, 2001
%

n   = length(varargin);
fn  = varargin{1};
swn = varargin{2};

file_id   = hdfsw('open',fn,'read');
swath_id  = hdfsw('attach',file_id,swn);

% Loop through fieldnames
for i=3:(n-3)
  s0 = [varargin{i}];
  s1 = ['[d.' varargin{i} ',s]=hdfsw(''readfield''' ',swath_id,''' s0 ''',[],[],[]);'];
  eval(s1);
  s2 = ['Error reading field: ' varargin{i}];
  s3 = ['if s == -1; disp(s2);end'];
  eval(s3);
  s4 = ['d.' varargin{i} '= double(d.' varargin{i} ');'];
  eval(s4);
end

s = hdfsw('detach',swath_id);
if s == -1; disp('Swath detach error: L1b');end;   
s = hdfsw('close',file_id);
if s == -1; disp('File close error: L1b');end;

