function [start, stop] = nscatcols(minlon, maxlon, lon_matrix)
%
% Function to find the column indices which contain the man and max lon values.
% Sort of a horible bounding box problem...
%
% $Id: nscatcols.m,v 1.7 1998/11/09 20:26:57 dbyrne Exp $

% $Log: nscatcols.m,v $
% Revision 1.7  1998/11/09 20:26:57  dbyrne
% *** empty log message ***
%
% Revision 1.1  1998/05/17 14:18:09  dbyrne
% *** empty log message ***
%
% Revision 1.1  1997/12/09 03:43:53  jimg
% Added.
%

% Note that the satellite swath will fall on the Earth at an angle, so you
% have to exhaustively search the matrix.

% Similarly as in the situation of searching rows, the Ascending/Descending
% of the orbits must be considered to find the start and stop columns.
% Ascending: start column should searched from top left; stop, bottom right.
% Descending: start, top right; stop, bottom right.-
% Liang Dec.26,97

% Also declared a global variable in nscatrows.m

global ascend;
global million;
global zero;


rows = size(lon_matrix, 1);
cols = size(lon_matrix, 2);

indx = find(lon_matrix(:,:) == 0.);

if(rows <= 5)
  start = 1;
  stop = 48;
else


if (ascend == 1)

    l = 1;
    while ( l < cols & max(0.01*lon_matrix(:, l)) < minlon )
	l = l + 1;
    end

    if( l > 1 )
      	start = l - 1;
    else
	start = l;
    end

    % Remove zeros.
    lon_matrix(indx) = million(indx);

    l = cols;
    while( l > 1 & min(0.01*lon_matrix(:, l)) > maxlon)
	l = l - 1;
    end

    if ( l < cols )
	stop = l + 1;
    else
 	stop = l;
    end

    % Retrive zeros.
    lon_matrix(indx) = zero(indx);

else

    % Descending

    % Remove zeros.
    lon_matrix(indx) = million(indx);

    l = 1;
    while (l < cols & min(0.01*lon_matrix( :, l)) > maxlon)
        l = l + 1;
    end

    if ( l > 1 )
    	start = l - 1;
    else
	start = l;
    end

    % Retrive zeros.
    lon_matrix(indx) = zero(indx);


    l = cols;
    while (l > 1 & max(0.01*lon_matrix( :, l)) < minlon)
	l = l - 1;
    end

    if ( l < cols )
	stop = l + 1;
    else
 	stop = l;
    end
end

end

return;


