function fname = dteds(latlim,lonlim,level)
%DTEDS U.S. Department of Defense Digital Terrain Elevation Data (DTED) file names
%
%  fname = dteds(latlim,lonlim) return 'Level 0' DTED file names 
%  (directory and name) required to cover the geographic region specified by
%  LATLIM and LONLIM.
%
%  fname = dteds(latlim,lonlim,level) return DTED file names 
%  (directory and name) required to cover the geographic region specified by
%  LATLIM and LONLIM.  Valid inputs for the LEVEL of the DTED files include
%  0, 1, or 2.
%
%  DTED files contain digitial elevation maps covering 1 by 1 degree 
%  quadrangles at horizontal resolutions ranging from about 1 kilometer to 1 
%  meter.  The 1 kilometer data is available online at 
%      http://164.214.2.59/geospatial/products/DTED/dted.html 
%  The higher resolution data is available to the U.S. Department of Defense 
%  and its contractors from the National Imagery and Mapping Agency (NIMA).
%
%  A third-party description of the DTED data may be found at
%        http://www.fas.org/irp/program/core/dted.htm
%  Detailed official documentation is available at 
%        http://164.214.2.59/publications/specs/printed/DTED/dted1-2.doc.
%
% See also DTED

%  Copyright 1996-2000 Systems Planning and Analysis, Inc. and The MathWorks, Inc.
%  Written by:  L. Job, W. Stumpf (6-1-98)
%  $Revision: 1.5 $ $Date: 2000/06/19 18:19:49 $

% DTED format specification document: http://164.214.2.59/publications/specs/printed/DTED/dted1-2.doc

% DTED0 is 120x120
% DTED1 is 1201x1201
%
% except at higher latitudes, where there are fewer longitude records

% error checking for input arguments
switch nargin
	case 2
		level = num2str(0);
		ext = ['dt',level];
	case 3
		level = num2str(level);
		ext = ['dt',level];
	otherwise		
		error('Incorrect Number of Input Arguments')
end

% round the limits since DTED is read in 1 deg x 1 deg square tiles
latmin = floor(latlim(1));
latmax = floor(latlim(2));
lonmin = floor(lonlim(1));
lonmax = floor(lonlim(2));

% define columns and rows for tiles to be read
uniquelons = [lonmin:lonmax];
uniquelats = [latmin:latmax];
londir{length(uniquelons)} = '';
latdir{length(uniquelats)} = '';
dtedfile{length(uniquelons),length(uniquelats)} = '';

% redefine uniquelons if lonlim extends across the International Dateline
if lonmin > lonmax
	indx1 = [lonmin:179];
	indx2 = [-180:lonmax];
	uniquelons = [indx1 indx2];
end	

for i = 1:length(uniquelons);
	switch sign(uniquelons(i))
		case 0
			londir{i} = [filesep,'DTED',filesep,'E000',filesep];
		case 1
			str = num2str(uniquelons(i));
			if length(str)<3
				londir{i} = [filesep,'DTED',filesep,'E0',str,filesep];
			else
				londir{i} = [filesep,'DTED',filesep,'E',str,filesep];
			end	
		case -1
			str = num2str(abs(uniquelons(i)));
			if length(str)<3
				londir{i} = [filesep,'DTED',filesep,'W0',str,filesep];
			else
				londir{i} = [filesep,'DTED',filesep,'W',str,filesep];
			end	
	end
end	

for i = 1:length(uniquelats);
	switch sign(uniquelats(i))
		case 0
			latdir{i} = ['N00.',ext]
		case 1
			str = num2str(uniquelats(i));
			if length(str)<2
				latdir{i} = ['N0',str,'.',ext];
			else
				latdir{i} = ['N',str,'.',ext];
			end	
		case -1
			str = num2str(abs(uniquelats(i)));
			if length(str)<2
				latdir{i} = ['S0',str,'.',ext];
			else
				latdir{i} = ['S',str,'.',ext];
			end	
	end
end	

% define the file names
numberoffiles = length(uniquelats)*length(uniquelons);

% assume that all required files can be found in the default root directory
fileexist = 1;

% check to see if directories exist
for i = 1:length(uniquelons)
	for j = 1:length(uniquelats)
		fname{i,j} = lower([londir{i},latdir{j}]);
	end
end
fname = fname(:);






