%function geoid = selectGeoid(geoidStr)
%  geoid = selectGeoid() returns global currentGeoid
%  geoid = selectGeoid('select') opens a listdlg
%  geoid = selectGeoid(geoid) returns almanac('earth',geoid,'meters')
function geoid = selectGeoid(geoidStr)
	global currentGeoid

if nargin == 0,
	if isempty(currentGeoid),
		geoid = selectGeoid('select');
	else 
		geoid = currentGeoid;
	end
	return
end

if strcmp(geoidStr,'select'),
	geoids = getGeoids;
	[index,ok] = listdlg('PromptString','Select an ellipsoid:', ...
		'SelectionMode','single','Name','Select world model','ListString',geoids,'InitialValue',14);
	if isempty(index),
		geoid = selectGeoid('select');
		return
	end
	geoidStr = geoids{index};
end

if strcmp(geoidStr,'wgs84'),
	geoid = wgs84;
else
	geoid = almanac('earth',geoidStr,'meters');
end
currentGeoid = geoid;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function geoids = getGeoids

geoids{1} = 'everest';         %1830 Everest ellipsoid
geoids{2} = 'bessel';          %1841 Bessel ellipsoid
geoids{3} = 'airy';            %1849 Airy ellipsoid
geoids{4} = 'clarke66';        %1866 Clarke ellipsoid
geoids{5} = 'clarke80';        %1880 Clarke ellipsoid
geoids{6} = 'international';   %1924 International ellipsoid
geoids{7} = 'krasovsky';       %1940 Krasovsky ellipsoid
geoids{8} = 'wgs60';           %1960 World Geodetic System ellipsoid
geoids{9} = 'iau65';           %1965 International Astronomical Union ellipsoid
geoids{10} = 'wgs66';          %1966 World Geodetic System ellipsoid
geoids{11} = 'iau68';          %1968 International Astronomical Union ellipsoid
geoids{12} = 'wgs72';          %1972 World Geodetic System ellipsoid
geoids{13} = 'grs80';          %1980 Geodetic Reference System ellipsoid
geoids{14} = 'wgs84';		   %1984 World Geodetic System ellipsoid
