function S = readcal(FileName)
% READCAL   - Read Calibration files used for Oasis Specpr instruments
%
% Use as: S = readcal(FileName)
%
% Inputs: FileName = name of the radiometer cal file to be read
% Ouputs: S        = An array of structures. Each 'layer' represents one line of 
%                    calibration info. The structure has the following fields
%                    name, bank, chan, type, coef, lims, unit

% Brian Schlining
% 25 Aug 1999

%===========
% Open File
%===========
if ~nargin
   [infile inpath] = uigetfile('*.*','Select Radiometer Calibration file',0,0);
   if infile == 0
      S = [];
      return                            % Return if CANCEL is selected
   end
   FileName = [inpath infile];
end

%===========
% Read File
%===========
fid    = fopen(FileName,'r');				 % Open File
n = 0;
while ~feof(fid)
   s = fgetl(fid);
   if isempty(s) | strcmp(s(1),'#')
      % Do Nothing
   else
      n = n + 1;
      S(n) = parse(s);
   end
end
fclose(fid);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION PARSE
%   Breaks apart a line of calibration info
function S = parse(s)


[bank    s] = strtok(s);
[channel s] = strtok(s);
[types   s] = strtok(s);
[name    s] = strtok(s);
[a       s] = strtok(s);
[b       s] = strtok(s);
[c       s] = strtok(s);
[cmin    s] = strtok(s);
[cmax    s] = strtok(s);
[units   s] = strtok(s);

S.name = name;
S.bank = sscanf(bank,'%f');
S.chan = sscanf(channel,'%f');
S.type = sscanf(types,'%f');
S.coef = [sscanf(a,'%f') sscanf(b,'%f') sscanf(c,'%f')];
S.lims = [sscanf(cmin,'%f') sscanf(cmax,'%f')];
S.unit = units;



