function changeChannel
% Allows the user to change the AIRS channel to be displayed
% Kevin Baggett
% Fri Aug  9 16:40:58 GMT 2002

h=guidata(1);
if ~isfield(h,'radiances')
	s='L1B_AIRS_Science';
	start='[]';
	stride='[]';
	edge='[]';
	flist={'radiances','spectral_freq','Latitude','Longitude','Time'};
	level1BData=read_eos_fields([h.PathName h.FileName],s,flist{:},start,stride,edge);
   	wavenumbers=level1BData.spectral_freq(h.goodChannelIndex);
	rad=level1BData.radiances(h.goodChannelIndex,:);
    index=find(wavenumbers >= h.minWavenumber & wavenumbers <=h.maxWavenumber);
    wavenumbers=wavenumbers(index);
    rad=rad(index,:);
    h.latitude=flipdim(level1BData.Latitude',2);
    h.longitude=flipdim(level1BData.Longitude',2);
    h.time=level1BData.Time(1);
    clear level1BData;
    guidata(1,h);
else
    wavenumbers=h.wavenumbers;
    rad=h.radiances;
end

f=openfig('selectChannel','reuse');
hSel=guihandles(f);
hSel.wavenumbers=wavenumbers; %attach wavenumbers to figure for Selection
guidata(f,hSel);
axes(hSel.axDisplay);
%plot entire spectra for a randomly selected pixel
%r=random('unid',12150); %always 12150 (135x90) AIRS pixels
% random available from statistics toolbox, rand available generally
r=floor(12150*rand(1))+1;
plot(wavenumbers,rad(:,r));
xlabel('Wavenumber (cm^{-1})');
ylabel('Radiance (mW/m^2/ster/cm^{-1})')
randLat=reshape(h.latitude,12150,1);
randLon=reshape(h.longitude,12150,1);

title(sprintf('Spectra at %7.4f, %7.4f (Randomly selected)',randLat(r),randLon(r)));
waitfor(f); % selectedBand and wavenumber attached to main figure here

h=guidata(1); % reload main figure's guidata
currentIndx=find_indx(wavenumbers,h.currentWavenumber);
h.plotRadiances=squeeze(rad(currentIndx,:,:));
wavenumberFromData=wavenumbers(currentIndx);
if ~isfield(h,'radiances')
    % reshape radiance data to AIRS dimensions -135 scanlines, 90 pixels across
    h.plotRadiances=reshape(h.plotRadiances,90,135);
    % flip to make sure orientation is correct
    h.plotRadiances=flipdim(h.plotRadiances',2);
    h.radiances=rad;
    clear rad;
    h.wavenumbers=wavenumbers;
    % permute to get correct orientation
    h.radiances=reshape(h.radiances,length(wavenumbers),90,135);
    h.radiances=permute(h.radiances,[1 3 2]);
    h.radiances=flipdim(h.radiances,3);
end
h.currentVar='Radiance';

plotband(wavenumberFromData,h.time,h.currentVar,h.plotRadiances,h.axDisplay,h.doflipud,h.dofliplr,h.curColormap);

% compute and store brightness temperature values
h.temperature=rad2bt(wavenumberFromData,h.plotRadiances);
h.currentWavenumber=wavenumberFromData;

guidata(1,h);
