function newChannel=buildNewChannel(radiances,wavenumbers,box,channels,op,doflipud,dofliplr)

%function NewCh=buildNewChannel(Chns,op)
%This function returns a linear combination
%of MODIS channels.
%Paolo Antonelli
%Thu Jul 26 21:11:56 UTC 2001
%Adapted by Kevin Baggett for AIRS data
% Thu Apr 17 21:03:31 GMT 2003
%
%Input: 
%        Chns: is a two elements array [Ch(i) Ch(j)]
%        op: is the operator to be used in combining 
%           the channels ['-' '+' '*' '/']
%        box: is an array that contains [X0 YO DX DY]
%           where XO and Y0 are the number of rows and 
%           columns to skip in reading the modis file and
%           DX DY are the number of rows/columns to be read 
%           starting from X0 and Y0.
%Output:
%        NewCh = Ch(i) op Ch(j)

nch=find(channels~=0);
channels=channels(nch);

for chNum=1:length(channels)
    indx=find_indx(wavenumbers,channels(chNum));
    % convert to brightness temperature and limit to box
    Mimage(chNum,:,:)=rad2bt(wavenumbers(indx),squeeze(radiances(indx,floor(box(2)):floor(box(2))+round(box(4)),floor(box(1)):floor(box(1))+round(box(3)))));
end


if length(channels)>1
  newChannel=performop(op,Mimage(1,:,:),Mimage(2,:,:));
else
  newChannel=squeeze(Mimage(1,:,:));
end

% flip resulting matrix according to the flip settings
if doflipud
     newChannel=flipud(newChannel);
end
if dofliplr
     newChannel=fliplr(newChannel);
end