PRO PMTRAS_DBASE_DUMP, dbsolution
;
; Generates ascii display of PMTRAS database in structure, dbsolution
; Output is written to PMTRAS_DBASE_DUMP.out
;
;  5-May-2003 	gh 	Initial version
; 16-Jul-2003	gh 	Added output line count to IDL log
;					Display est_error, av_offset and rms_outset in milliradians instead of radians.
; 20-Jul-2003	gh	Updated stars. tagnames to 'intensity' and 'rms_scatter'.
; 21-Jul-2003	gh	Added column headings
; 22-Jul-03 	gh	Add roll_phase output.
; 23-Jul-03		gh	Add roll period and boundary phase output in place of roll_phase.
; 22-Sep-03 	gh	Minor format change
; 15-Dec-03		gh	Revert to roll_phase(mr) in output
;				gh	Add Date and Time in addition to sctime.
;
TWOPI	= 2.*!DPI
npt = N_ELEMENTS(dbsolution)
OPENW,  dumplun, 'PMTRAS_DBASE_DUMP.out', /GET_LUN
PRINTF, dumplun, '                     PMTRAS_DBASE_DUMP OUTPUT'
PRINTF, dumplun
PRINTF, dumplun, '   sctime      date      time    period   phase   est_err qual'
PRINTF, dumplun, '                                    s       mr       mr       HRN ndet inten <offset> scatter'
PRINTF, dumplun
nline = 5								; Running count of output lines
; Begin loop over output lines.
FOR n=0,npt-1 DO BEGIN
	roll_period 	= dbsolution[n].roll_period
	sctimen			= dbsolution[n].sctime
	sctimestruct 	= {seconds: sctimen, bmicro: 0L}
	utdisplay		= hsi_sctime2any(sctimestruct, /ECS)
	phase			= dbsolution[n].roll_phase * 1.D-3							; roll phase in mr
	PRINTF, dumplun, sctimen, utdisplay, roll_period, phase, dbsolution[n].est_error*1000., $
					dbsolution[n].roll_quality, FORMAT='(I11, 1X, A19, F9.6, F9.3, F8.3, I4)'
	js = dbsolution[n].starcount
	FOR j=0,js-1 DO BEGIN
		PRINTF, dumplun,    dbsolution[n].stars[j].id,    					$
							dbsolution[n].stars[j].detections, 				$
							dbsolution[n].stars[j].intensity,				$
							dbsolution[n].stars[j].av_offset*1000., 		$
							dbsolution[n].stars[j].rms_scatter*1000.,	FORMAT='(I66, I3, F6.0, 2F9.2)'
	ENDFOR
	nline = nline + js + 1
ENDFOR
CLOSE, dumplun
PRINT, 'PMTRAS_DBASE_DUMP: Printed', nline, ' lines to PMTRAS_DBASE_DUMP.OUT'
END
