function [s,l,Name,Type,Class,Subclass] = ReadAsterSpectra(filename)

% Read spectrum from Aster spectral library.

% Liam Pedersen, CMU/NASA ARC, June 1999
% All rights reserved.
% version 1.0 

% files are of form: ------------------------------------
%
%Name: Calcite CaCO_3
%Type: Mineral
%Class: Carbonates
%Subclass: 
%Particle Size: 45-125um
%Sample No.: C-3A
%Owner: JPL
%Wavelength Range: VNIR-SWIR
%Origin: Italy
%Collected by Ward's
%Description:  Travertine 
%
%
%Measurement: Hemispherical reflectance
%First Column: X
%Second Column: Y
%X Units:  Wavelength (micrometers)
%Y Units:  Reflectance (percent)
%First X Value:   0.40
%Last X Value:   2.50
%Number of X Values:  826
%Additional Information: c03aa.txt
%
%  [wavelengths(um)]  [reflectance(%)]

% open file
fid = fopen(filename,'rt');
if (fid == -1) % file not found
   s = -1;
   return
end

% Read header information

% Name :
L = fgets(fid);
[t,L] = strtok(L);  Name = L(1:length(L)-1);
if (isempty(Name) | isspace(Name))
   Name = '*';
end

% Type
L = fgets(fid);
[t,L] = strtok(L);  [Type,L] = strtok(L);
if (isempty(Type) | isspace(Type))
   Type = '*';
end

% Class
L = fgets(fid);
[t,L] = strtok(L);  [Class,L] = strtok(L);
if (isempty(Class) | isspace(Class))
   Class = '*';
end

% Subclass
L = fgets(fid);
[t,L] = strtok(L);  [Subclass,L] = strtok(L);
if (isempty(Subclass) | isspace(Subclass))
   Subclass = '*';
end

% skip rest of header
for i = 1:22
   L = fgets(fid);
end

% either at eof or at 1st line of numbers
[A,count] = fscanf(fid,'%g %g',[2 inf]);

% close input stream
fclose(fid);

% ensure sorted in ascending order
A = sortrows(A',1);

% scale results.
L = A(:,1)'*1000;  % scale to nm from um
S = A(:,2)'/100;   % scale to fraction in [0,1] from percent value

% ensure monotonic
dL = diff(L);
i = find(dL > 0);
L = L(i);
S = S(i);

% interpolate to 1 nm intervals, wavelength range up to 2500 nm
N = length(L);
minL = max([L(1) 400]); maxL = min([L(N) 2500]);
l = minL:maxL;
s = (interp1(L,S,l,'linear'))';
l = l';

