Viewing contents of file '../idllib/ghrs/pro/calfos_ccs5.pro'
pro calfos_ccs5,name,config,pattern,h,nshift
;+
;			CALFOS_CCS5
;
; Read sky NSHIFT table
;
; CALLING SEQUENCE:
;	calfos_ccs5,name,config,pattern,h,nshift
;
; INPUTS:
;	name - ccs5 table name
;	config - configuration vector (from CALFOS_RD)
;	pattern - pattern vector (from CALFOS_RD)
;	
; INPUT/OUTPUTS:
;	h - FITS header for the observation
;
; OUTPUTS:
;	nshift - vector of nshift positions
;		nshift(0) = sky in upper aperture
;		nshift(1) = sky in lower aperture
;
; HISTORY:
;	version 1.0  D. Lindler  Jan 1990
;-
;---------------------------------------------------------------------------
;
; read table
;
	fname = strtrim(name)
	if fname eq '' then return		;Do we need the values?
	tab_read,fname,tcb,tab
;
; add history
;
	hist = 'Sky aperture NSHIFT table: '+fname
	sxaddhist,hist,h
	if !dump gt 0 then print,hist
;
; extract columns to be searched
;
	detector = strtrim(config(0))
	fgwa_id = strtrim(config(3))
	aper_id = strtrim(config(1))
	nxsteps = pattern(3)

	det = tab_val(tcb,tab,'DETECTOR')
	fgwa = tab_val(tcb,tab,'FGWA_ID')
	aper = tab_val(tcb,tab,'APER_ID')
	nxs = tab_val(tcb,tab,'NXSTEPS')
	aper_pos = tab_val(tcb,tab,'APER_POS')
	nshifts = tab_val(tcb,tab,'NSHIFT')

	nrows = n_elements(det)
;
; search table for correct configuration
;
	nshift = replicate (-999,2)

	for i=0,nrows-1 do begin
		if (strtrim(fgwa(i)) eq fgwa_id) then $
		if (strtrim(det(i)) eq detector) then $
		if (strtrim(aper(i)) eq aper_id) then $
		if (nxs(i) eq nxsteps) then begin
			case strtrim(aper_pos(i)) of
			  'UPPER': nshift(0) = nshifts(i)
			  'LOWER': nshift(1) = nshifts(i)
			  else:
			endcase
		endif
	endfor

	if max(nshift) eq -999 then begin
		print,"CALFOS_ccs5- no row found in ccs5 for the "+ $
			"observation's configuration"
		retall
	endif
;
; if only one aperture position found, set other to negative of it
;
	if nshift(0) eq -999 then nshift(0) = -nshift(1)
	if nshift(1) eq -999 then nshift(1) = -nshift(0)

return
end