pro monitor_center, infil_manual, last, outfil=outfil, nowait=nowait
;+
;NAME:
;	monitor_center
;PURPOSE:
;	To use the function POSITION to find and log the center location of the sun
;SAMPLE CALLING SEQUENCE:
;	monitor_center
;	monitor_center,  '/md82/log/sci160k/960205_225108'
;	monitor_center, infil, last, outfil='monitor_center.iss_offset'
;HISTORY:
;	Written Feb-96 by M.Morrison
;	 7-Mar-96 (MDM) - Modified to not get last image
;	 8-Apr-96 (MDM) - Modified to not do the waiting if using /nowait
;			- Modified to write out the Sequence ID in the output file
;	 8-Apr-96 (MDM) - Changed default OUTFIL
;	 23-May-96 (CED) - Added new DPC
;	 13-Sep-96 (MDM) - Added DPC 404b1fc0
;			- Allowed image to be cropped
;			- Added removing the square-root compression
;	18-Sep-96 (MDM) - Changed call to POINTING to use "contrast=.4"
;			- Added DPC 46481fc0
;			- Modified to use image min for outside of the crop circle
;			- Write out the DPC in addition to the SeqID
;	8-Nov-96 (CED)  - Added DPCs  46451fc0 & 46051fc0
;	27-Mar-97 (JFC) - Changed wait time to 1 minute Per Craig's request
;-
;
;if (n_elements(outfil) eq 0) then outfil = '/usr/people/mdi/monitor_center.txt'
if (n_elements(outfil) eq 0) then outfil = concat_dir(getenv('HOME'), 'monitor_center.txt')
if (n_elements(last) eq 0) then last = -1
;
if (n_elements(last_infil) eq 0) then last_infil = 'xx'
while 1 do begin
    infil = get_last_tfr()
    if (keyword_set(infil_manual)) then begin
	infil = infil_manual
	last_infil = infil
    end
    if (infil ne last_infil) then last = -1
    list_tfi, infil, info, /quiet
    ninfo = n_elements(info)
    qok = indgen(ninfo)
    ;
    nss = 0
    if (data_type(info) eq 8) then ss = where( (qok gt last) and $
		( (info.dpc eq '404b2000'x) or (info.dpc eq '32000'x) or $
		  (info.dpc eq '46051fc0'x) or (info.dpc eq '46451fc0'x) or $
		  (info.dpc eq '46061fc0'x) or (info.dpc eq '46461fc0'x) or $
		  (info.dpc eq '404b1fc0'x) or (info.dpc eq '46481fc0'x) ) , nss)
    for i=0,nss-2 do begin		;don't do the last one
	read_mdi, infil, ss(i), img, head
	sdpc = string(sxpar(head,'dpc'), format='(z8.8)')
	imin = min(img)
	if (strmid(sdpc, 4, 1) eq '1') then imin = (imin/10.)^2
	if (n_elements(img(0,*)) eq 1) then img = mk_dpc_image(1024, img, h=head, missing=imin)	;MDM 13-Sep-96
	if (strmid(sdpc, 4, 1) eq '1') then img = (img/10.)^2
	dattim = gt_day(sxpar(head, 'DATE-OBS'),/str) + '  ' +  sxpar(head, 'TIME-OBS')          ;convert to letter format
	seqid = sxpar(head, 'seqid')
	cen = pointing(img, contrast=.4)
	idev = stdev(img, iavg)
	out = string(dattim,  cen, iavg<99999, idev<99999, seqid, sdpc, $
				format='(a, 3x, 3f8.2, 3x, 2f8.1, 3x, z8.8, 2x, a)')
	print, out
	file_append, outfil, out
	last = ss(i)
    end
    last_infil = infil
    ;
    if (keyword_set(nowait)) then return
    print, 'Waiting 1 minutes'
    wait, 1*60		;wait 1 minutes
end
;
end
