function d = rd_airsChanPropFile(filename);
%
% function d = rd_airsChanPropFile(filename);
%
% read information from an AIRS Channel Properties File
% (e.g. L2.I.channel_prop.v6.0.1.anc)
%
% inputs:
%  filename:  name of file to read (optional)
%
% outputs:
%  d:      structure of output data
%

if nargin == 0
 [fname,pname] = uigetfile;
 filename = fullfile(pname,fname);
end

d.filename = filename;

fid = fopen(filename,'r');

i = 0;
while 1
  pos = ftell(fid);
  nl = fgetl(fid);
  if nl(1) == '!'
    i = i + 1;
    d.Header{i} = nl;
  else
    break
  end
end

fseek(fid,pos,'bof');

len = [5 9 6 5 7 6 8 8 8 6 3 3 3 9];
istart = cumsum(len)-len+1;

%[a,cnt] = fscanf(fid,'%5i%9.3f %5s%5i%7.4f%6.3f%8.4f%8.1f%8.1f%6.3f%3i%3i%3i %8s',1)

i=0;
while 1
  nl = fgetl(fid);
  if nl ~= -1
    i = i + 1;
%    disp(i)
    d.Channel_number(i) = eval(nl(istart(1):istart(1)+len(1)-1));
    d.wavenumber(i) = eval(nl(istart(2):istart(2)+len(2)-1));
    d.Array_name{i} = nl(istart(3):istart(3)+len(3)-1);
    d.Cal_chan_index(i) = eval(nl(istart(4):istart(4)+len(4)-1));
    d.NeDT(i) = eval(nl(istart(5):istart(5)+len(5)-1));
    d.FWHM(i) = eval(nl(istart(6):istart(6)+len(6)-1));
    d.Cij(i) = eval(nl(istart(7):istart(7)+len(7)-1));
    d.centroid_x(i) = eval(nl(istart(8):istart(8)+len(8)-1));
    d.centroid_y(i) = eval(nl(istart(9):istart(9)+len(9)-1));
    d.RTA_Fit_Error(i) = eval(nl(istart(10):istart(10)+len(10)-1));
    d.AB_State(i) = eval(nl(istart(11):istart(11)+len(11)-1));
    d.Rad_Qual(i) = eval(nl(istart(12):istart(12)+len(12)-1));
    d.Bad_Flag(i) = eval(nl(istart(13):istart(13)+len(13)-1));
    d.Comments{i} = nl(istart(14):istart(14)+len(14)-1);
  else
    break
  end
end

fclose(fid);


