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);
	LW_index=find(wavenumbers>=500 & wavenumbers <= 1200);
	MW_index=find(wavenumbers>1200 & wavenumbers <= 2000);
	SW_index=find(wavenumbers>2000 & wavenumbers <= 3000);
	
	Longwave.radiances=level1BData.radiances(h.goodChannelIndex(LW_index),:);
	Longwave.wavenumbers=wavenumbers(LW_index);
	Midwave.radiances=level1BData.radiances(h.goodChannelIndex(MW_index),:);
	Midwave.wavenumbers=wavenumbers(MW_index);
	Shortwave.radiances=level1BData.radiances(h.goodChannelIndex(SW_index),:);
	Shortwave.wavenumbers=wavenumbers(SW_index);
else
    wavenumbers=h.wavenumbers;
    LW_index=find(wavenumbers>=500 & wavenumbers <= 1200);
	MW_index=find(wavenumbers>1200 & wavenumbers <= 2000);
	SW_index=find(wavenumbers>2000 & wavenumbers <= 3000);
	
	Longwave.radiances=h.radiances(LW_index,:,:);
	Longwave.wavenumbers=wavenumbers(LW_index);
	Midwave.radiances=h.radiances(MW_index,:,:);
	Midwave.wavenumbers=wavenumbers(MW_index);
	Shortwave.radiances=h.radiances(SW_index,:,:);
	Shortwave.wavenumbers=wavenumbers(SW_index);
end

f=openfig('enterWavenumber','reuse');
hWvn=guihandles(f);
guidata(f,hWvn);
set(hWvn.txtMinLongwave,'String',sprintf('%10.4f',min(Longwave.wavenumbers)));
set(hWvn.txtMaxLongwave,'String',sprintf('%10.4f',max(Longwave.wavenumbers)));
set(hWvn.txtMinMidwave,'String',sprintf('%10.4f',min(Midwave.wavenumbers)));
set(hWvn.txtMaxMidwave,'String',sprintf('%10.4f',max(Midwave.wavenumbers)));
set(hWvn.txtMinShortwave,'String',sprintf('%10.4f',min(Shortwave.wavenumbers)));
set(hWvn.txtMaxShortwave,'String',sprintf('%10.4f',max(Shortwave.wavenumbers)));

waitfor(f); % selectedBand and wavenumber attached to main figure here
h=guidata(1); % reload main figure's guidata
eval(sprintf('currentIndx=find_indx(%s.wavenumbers,h.currentWavenumber);',h.selectedBand));
eval(sprintf('h.plotRadiances=squeeze(%s.radiances(currentIndx,:,:));',h.selectedBand));
eval(sprintf('wavenumberFromData=%s.wavenumbers(currentIndx);',h.selectedBand));
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=[Longwave.radiances; Midwave.radiances; Shortwave.radiances];
    h.wavenumbers=[Longwave.wavenumbers; Midwave.wavenumbers; Shortwave.wavenumbers];
    % permute to get correct orientation
    h.radiances=reshape(h.radiances,length(wavenumbers),90,135);
    h.radiances=flipdim(permute(h.radiances,[1 3 2]),3);
    h.latitude=flipdim(level1BData.Latitude',2);
    h.longitude=flipdim(level1BData.Longitude',2);
    h.time=level1BData.Time(1);
end
h.currentVar='Radiance';

plotband(wavenumberFromData,h.selectedBand,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);
