function NewCh=buildNewChannel(filename,box,Chns,op)

%function NewCh=buildNewChannel(Chns,op)
%This function returns a linear combination
%of MODIS channels.
%Paolo Antonelli
%Thu Jul 26 21:11:56 UTC 2001
%
%Input: 
%        filename: MODIS filename
%        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(Chns~=0);
Chns=Chns(nch);

for chnum=1:length(Chns)

   isMetaCh=(Chns(chnum) > 36);

   if (~isMetaCh)
        if Chns(chnum)<20 | Chns(chnum)==26
           imagedata=modis_level1b_read(filename, Chns(chnum), {'latitude','longitude','reflectance'},box);
           Mimage(chnum,:,:)=imagedata.mimage;
        else
           imagedata=modis_level1b_read(filename, Chns(chnum), {'latitude','longitude','temperature'},box);
           Mimage(chnum,:,:)=imagedata.mimage;
        end
   else
        ChStr=sprintf('MetaCh%d',chnum); 
        if (isfield(Modis,ChStr))
           Mimage(chnum,:,:)=Modis.MetaCh(Chns(chnum));
        else
           disp([ChStr ' does not exist, please build it before using it']);
           return
        end
  end
end


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

return
