Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/def_imhd_struct.pro'
;+
; NAME:
;	def_imhd_struct
; PURPOSE:
;	Define and return header structure containing info about MAMA image.
; CALLING:
;	To create empty structure:
;
;		header = def_imhd_struct( hx, hy )
;
;	or if structure variable is obtained by calling get_macq_status:
;
;		header = def_imhd_struct( STATUS_STRUCT = status_info )
; KEYWORDS:
;	STATUS_STRUCT = structure variable obtained from
;		function get_macq_status containing info about MAMA status,
;		or function get_ccd_status containing info about CCD status,
;		this info is copied to image header.
; INPUTS:
;	hx, hy = size of hot spot array (but usually keyword STATUS is used).
; OUTPUT:
;	Function returns the image header structure variable.
; EXTERNAL CALLS:
;	pro copy_struct
; HISTORY:
;	Frank Varosi NASA/GSFC 1993.
;	F.V. 1994, generalize to hold CCD info also.
;	F.V. 1994, added sub-structure for device axes.
;-

function def_imhd_struct, hx, hy, STATUS_STRUCT=status_info

	if N_struct( status_info ) EQ 1 then begin
		if max( tag_names( status_info ) EQ "HOT_LOC" ) then begin
			hLoc = status_info.Hot_Loc + [ [1,1], [-1,-1] ]
			hsz = ( hLoc(*,1) - hLoc(*,0) +1 ) > 1
			HotSpot = Lonarr( hsz(0), hsz(1) )
			hLoc = transpose( hLoc )
			det_name = "MAMA"
		  endif else begin
			HotSpot = Lonarr( 1 )
			hLoc = intarr(2,2)
			det_name = "CCD"
		   endelse
	  endif else begin
		if N_elements( hx ) NE 1 then hx=1
		if N_elements( hy ) NE 1 then hy=1
		HotSpot = Lonarr( hx>1, hy>1 )
		hLoc = intarr(2,2)
		det_name = ""
	   endelse

	hdr = {	stime:"",		$
		grating:"",		$
		Lamp:"",		$
		object:"",		$
		environment:"",		$
		measurement:"",		$
		detector:"",		$
		comment:"",		$
		filename:"",		$
		directory:"",		$
		flat_field:"",		$
		amplifier:0,		$
		pbytes:0,		$
		psize:0,		$
		res:0, 			$
		x0:0, y0:0,		$
		nx:0, ny:0,		$
		ydhms:intarr(5),	$
		counts:0L,		$
		dtime:0.0,		$
		WaveLength:0.0,		$
		dev_axes: device_axes( 20,/INIT ),	$
		dev_pos: strarr(20),	$
		max:0L,			$
		min:0L,			$
		max_Loc: intarr(2),	$
		stdev:0.0,		$
		mean:0.0,		$
		sigma_noise: fltarr(4),	$
		offset: intarr(4),	$
		offsub:0,		$
		orig_counts:0L,		$
		Hot_counts:0L,		$
		Hot_Loc: hLoc,		$
		HotSpot: HotSpot	}

	if N_struct( status_info ) EQ 1 then begin

		copy_struct, status_info, hdr, EXCEPT="Hot_Loc"

		wlf = where( status_info.startt EQ 10b, nlf )
		if (nlf GT 0) then wlf = wlf(nlf-1)-1 $
			      else wlf = N_elements( status_info.startt )-1
		hdr.detector = det_name
		hdr.stime = det_name + " @ " + $
			strtrim( status_info.startt(0:wlf), 2 )
	   endif

return, hdr
end