function [flat,flon]=convertll(lat,lon) % convert string positions into numeric decimal degrees % input latitude and longitude, each in a character string % output lat and lon in +/- floating point degrees %%% START USGS BOILERPLATE -------------% There is no published documentation for these programs- use the % internal comments and help function. % Programs written in Matlab- as early as 7.2.0.232 (R2006a) and % most recent modifications in v7.8.0 (R2009a) % Programs ran on PC with Windows XP Professional OS, and RHEL4 linux. % % "Although this program has been used by the USGS, no warranty, % expressed or implied, is made by the USGS or the United States % Government as to the accuracy and functioning of the program % and related program material nor shall the fact of distribution % constitute any such warranty, and no responsibility is assumed % by the USGS in connection therewith." %%% END USGS BOILERPLATE -------------- % programmer: Susan A. Tarbell % date: June 4, 1999 % computer: PC % operating system: Windows NT % Matlab Version 5.3.0.10183 (R11) on PCWIN if isempty(lat) == 1 disp('Status: There is no global latitude value. Default value used.') flat=99.9; else latsign=+1; llat=length(lat); if lat(llat) == 'n' | lat(llat) == 'N' latsign = 1; lat=lat(1:llat-1); % remove N sign llat=length(lat); % re-establish length of latitude elseif lat(llat) == 's' | lat(llat) == 'S' latsign = -1; lat=lat(1:llat-1); % remove S sign llat=length(lat); % re-establish length of latitude elseif lat(1) == '-' latsign = -1; lat =lat(2:llat); % remove negative sign llat=length(lat); % re-establish length of latitude else disp('latitude fell through the loop, therefore it must already be degrees!'); end if lat(llat) == ' ' lat=lat(1:llat-1); % remove an ending space (if any) llat=length(lat); % re-establish length of latitude end % remove an ending space latm=0; % initialize value lats=0; % initialize value flat=[]; spac=find(lat == ' '); % find spaces if isempty(spac) == 1 % no spaces, assume either whole degrees or decimal degrees flat=str2num(lat); elseif length(spac) == 1 % get degrees, assume the rest is in decimal minutes latd=str2num(lat(1:spac(1)-1)); latm=str2num(lat((spac(1)+1):llat)); elseif length(spac) == 2 % assume minutes and seconds latd=str2num(lat(1:spac(1)-1)); latm=str2num(lat((spac(1)+1):(spac(2)-1))); lats=str2num(lat((spac(2)+1):llat)); end if isempty(flat) == 1 % flat is empty so get the individual components lats=lats/60; flatm=(latm+lats)/60; flat=latd+flatm; end flat=flat*latsign; end % now do longitude if isempty(lat) == 1 disp('Status: There is no global longitude value. Default value used.') flon=999.9; else lonsign=+1; llon=length(lon); if lon(llon) == 'e' | lon(llon) == 'E' lonsign = 1; lon=lon(1:llon-1); % remove e sign llon=length(lon); % re-establish length of lonitude elseif lon(llon) == 'w' | lon(llon) == 'W' lonsign = -1; lon=lon(1:llon-1); % remove w sign llon=length(lon); % re-establish length of lonitude elseif lon(1) == '-' lonsign = -1; lon =lon(2:llon); % remove negative sign llon=length(lon); % re-establish length of lonitude else disp('longitude fell through the loop! therefore it must already be degrees'); end if lon(llon) == ' ' lon=lon(1:llon-1); % remove an ending space (if any) llon=length(lon); % re-establish length of lonitude end % remove an ending space lonm=0; % initialize value lons=0; % initialize value flon=[]; spac=find(lon == ' '); % find spaces if isempty(spac) == 1 % no spaces, assume either whole degrees or decimal degrees flon=str2num(lon); elseif length(spac) == 1 % get degrees, assume the rest is in decimal minutes lond=str2num(lon(1:spac(1)-1)); lonm=str2num(lon((spac(1)+1):llon)); elseif length(spac) == 2 % assume minutes and seconds lond=str2num(lon(1:spac(1)-1)); lonm=str2num(lon((spac(1)+1):(spac(2)-1))); lons=str2num(lon((spac(2)+1):llon)); end if isempty(flon) == 1 % flon is empty so get the individual components lons=lons/60; flonm=(lonm+lons)/60; flon=lond+flonm; end flon=flon*lonsign; end % - - - - - - - - - - - - - - - - end function - - - - - - - - - - - - - - - - - - - -