Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/dev_pos_struct.pro'
;+
; NAME:
;	dev_pos_struct
; PURPOSE:
;	Recreate the device-axis structure array from FITS header info.
;	Called by pro header_from_fits.
; CALLING:
;	dev_axes = dev_pos_struct( fh_devpos, dev_axes )
; INPUTS:
;	fh_devpos =
;	dev_axes = empty array of device-axis structures.
; OUTPUTS:
;	Function returns an array of structures with positions of device-axes.
; EXTERNAL CALLS:
;	pro sxpar
;	function N_struct
; HISTORY:
;	Written: Frank Varosi NASA/GSFC 1993.
;-

function dev_pos_struct, fh_devpos, dev_axes

	Ndevax = N_struct( dev_axes )
	Npos = N_elements( fh_devpos )

	if (Ndevax LE 0) then begin
		message,"second arg. must be device axes structure",/INFO
		return, 0
	   endif

	if (Npos LE 1) then begin
		message,"first arg. must be FITS header (string array)",/INFO
		return, dev_axes
	   endif

	Npos = fix( total( strlen( fh_devpos ) GT 0 ) )

	if (Npos LE 1) then begin
		message,"FITS header is not an array",/INFO
		return, dev_axes
	   endif

	np = (Ndevax < Npos)-1

	dev_axes(0:np).dev_name = strmid( fh_devpos(0:np), 0, 7 )
	dev_axes(0:np).name = strmid( fh_devpos(0:np), 7, 1 )
	dev_axes(0:np).alias = strtrim( strmid( fh_devpos(0:np), 32, 60 ), 2 )
	positions = get_words( strmid( fh_devpos(0:np), 11, 18 ) )

	if N_elements( positions ) EQ (2*(np+1)) then begin
		ix = 2 * indgen( np+1 )
		dev_axes(0:np).position = float( positions(ix) )
		dev_axes(0:np).units = strtrim( positions(ix+1), 2 )
	 endif else $
	   dev_axes(0:np).position = float( strmid( fh_devpos(0:np), 11, 18 ) )

return, dev_axes
end