function CloseWindow(windowOrScreen)
% CloseWindow(windowOrScreen)
%
% OBSOLETE: SetClut and the other files in the PsychBeta:TenBitInterface
% directory represent an initial attempt to provide support for 10-bit
% DACs. It was successful, but has been superceded by a more universal
% solution provided by LoadClut. Please use LoadClut, which works with
% the standard Screen 'OpenWindow', without the artificial restrictions
% of OpenWindow.m.
% 
% Complement to OpenWindow. 
%
% The attempt to save (in OpenWindow) and restore (here) the CLUT doesn't
% work because Screen GetClut (based on Apple's cscGetEntries) returns the
% clut AFTER transformation by the gamma table. This makes restoring hard.
% 
% See also OpenWindow, SetClut, SetColor.
%
% 2/1/02  dhb  Wrote it.
% 3/27/02 dhb  Save/restore gamma, but doesn't work.
% 3/37/02 dhb  Dummy open/close at end.  This does restore defaults.

global GAMMA10

screenNumber=Screen(windowOrScreen,'WindowScreenNumber');
if ~exist('GAMMA10','var') | ~isfield(GAMMA10,'openWindowTrue') | isempty(GAMMA10.openWindowTrue) | ~GAMMA10.openWindowTrue(screenNumber+1)
	error('CloseWindow: window not opened with OpenWindow');
end

if ScreenDacBits(screenNumber)>8
	Screen(windowOrScreen,'Gamma',GAMMA10.oldGamma{screenNumber+1});
end

GAMMA10.openWindowTrue(screenNumber+1) = 0;
Screen(windowOrScreen,'Close');

% Restore Mac defaults.
% w = Screen(screenNumber,'OpenWindow',0,[],16);
% Screen(w,'Close');
