;pro soho_roll_log, outfil=outfil, infil=infil 

;NAME:
;       soho_roll_log
;PURPOSE:
;       Program that grabs the current SOHO roll value with
;       get_soho_roll.pro
;HISTORY:
;       6-Apr-2004 (SEG) - I made this to create a simple text file with the
;                          current SOHO roll value in it.  It will run every 10 min 
;                          via cron (go_soho_roll_log) and at some point 
;	                   will be used by mk_mdi_fits.pro to determine the 
;                          current roll value so we do not have to edit 
;                          mk_mdi_fits.pro every time the SOHO roll changes. 
;


if (n_elements(outfil) eq 0) then outfil = '/mdisw/dbase/cal/info/roll_data.txt'
if (n_elements(infil) eq 0) then infil = '/mdisw/dbase/cal/info/roll_data.txt'

openr, lun, infil, /get_lun
readf, lun, old_roll
free_lun, lun
old_roll=float(old_roll)

new_roll=get_soho_roll() 

if (new_roll ne old_roll) then begin
	spawn, 'cp /soho-archive/public/data/ancillary/attitude/roll/nominal_roll_attitude.dat /mdisw/dbase/cal/info/roll_data2.txt'
 	openw, lun, outfil,/get_lun
	printf, lun, new_roll
	free_lun, lun
        new_rollstr = string(new_roll)   
	old_rollstr = string(old_roll)
    	userid = 'mdi-ops@mdisas.nascom.nasa.gov'
	subject = 'Roll Value Update'
	msg = ['The current SOHO roll value has changed from', old_rollstr,$
               'to be', new_rollstr, $
               ''] 
	mail, msg, user=userid, subj=subject 
end

end
 
