function [data] = read_eos_field(filename,swathname,fieldname,start,stop,edge)

% Read one EOS field by swath name
%
% Usage:
%
% [data] = read_eos_field(filename,swathname,fieldlist,start,stop,edge)
%
% Input
%    filename         : eos_hdf file name; string
%    swathname       : swath name containing fields; string
%    fieldname        : field name; string
%    start,stop,edge  : eos_hdf subsetting parameters; strings
%  
%    Note:  normally start,stop,edge all equal '[]'  
%
% Output
%    data : matrix containing field values in double precision
%

file_id   = hdfsw('open', filename, 'read');
if file_id == -1
  disp(['Open file error: ' filename])
end   

swath_id  = hdfsw('attach',file_id, swathname);
if swath_id == -1
  disp(['Swath attach error: ' swathname])
end   


% read field
%s = ['[data,status]=hdfsw(''readfield''' ',swath_id,''' fieldname ''',start,stop,edge);'];
s = ['[data,status]=hdfsw(''readfield''' ',swath_id,''' fieldname ''',[],[],[]);'];
eval(s);
data = double(data);

if status == -1
  disp(['Read field error: ' fieldname])
end

s = hdfsw('detach',swath_id);
if s == -1
  disp(['Swath detach error: ' swathname])
end   

s = hdfsw('close',file_id);
if s == -1
  disp(['File close error: ' filename])
end

