function animate(startChannel,endChannel,increment,curColormap,displayAxis,playTimes,playDirection,projection,figNum,txtMessage)
%Animates through selected channels in an AIRS file
%Input: filename, pathname, an array of bands selected, axis to display on
%       number of times to play movie, the direction to play
%       optional txtMessage field to display when stepping through
%Kevin Baggett
%Thu Nov  7 17:39:52 GMT 2002

switch playDirection
    case 'Forward'
        bandStart=startChannel;
        bandIncrement=increment;
        bandEnd=endChannel;
    case 'Backward'
        bandStart=endChannel;
        bandIncrement=increment*-1;
        bandEnd=startChannel;
    case 'Step Forward'
        keyboard
        bandStart=startChannel;
        bandIncrement=increment;
        bandEnd=endChannel;
        if nargin==9
            set(txtMessage,'Visible','on');
        end
    case 'Step Backward'
        bandStart=endChannel;
        bandIncrement=increment*-1;
        bandEnd=startChannel;
        if nargin==9
            set(txtMessage,'Visible','on');
        end
end

axes(displayAxis);
set(displayAxis,'Visible','On');
h1=guidata(1);
count=0;
for bandNum=bandStart:bandIncrement:bandEnd
    count=count+1;
    wavenumber=h1.wavenumbers(bandNum);
    %currentRad=reshape(h1.radiances(bandNum,:),90,135);
    currentRad=squeeze(h1.radiances(bandNum,:,:));
    cla;
    plotSingleImage(currentRad, h1.latitude, h1.longitude,...
        figNum,{'colorbar','magentaMap',projection});
    colormap(curColormap);
	set(gca,'XTick',[],'YTick',[]);
	title(sprintf('Current Wavenumber: %s cm^{-1}',num2str(wavenumber)));
    if strcmp(playDirection,'Step Forward')|strcmp(playDirection,'Step Backward')
        if bandNum~=bandEnd
            waitforbuttonpress; %wait except for last time through loop
        end
    else
        try % error occurs if closing during get frame
            M(count) = getframe(gca,[0 0 380 380]);
        catch
        end
    end
end

if strcmp(playDirection,'Forward')|strcmp(playDirection,'Backward')
    set(displayAxis,'Visible','Off');
	try
        playBands=[playTimes-1,bandStart:bandIncrement:bandEnd];
        movie(M,playBands,0.75); %error occurs if closing movie prematurely
	catch
	end
end
try
    movie2avi(M,'temp.avi','fps',1);
catch
end
if nargin==8
    set(txtMessage,'Visible','off');
end
