;+ ; NAME: ; smei_frm_update ; PURPOSE: ; Update headers of SMEI Fits frames ; CATEGORY: ; camera/idl/frm ; CALLING SEQUENCE: PRO smei_frm_update, cframe, $ shutter_open=shutter_open, $ bad_quat=bad_quat, $ new_quat=new_quat, $ just_bad=just_bad, $ on=on, $ off=off ; INPUTS: ; cframe scalar; type: string ; fully-qualified name of SMEI frame ; OPTIONAL INPUT PARAMETERS: ; /shutter_open if set the value of the 'shutter-open' flag is changed ; /just_bad if set the value of the 'just_bad' flag is changed ; /on by default the flag setting is reversed. ; /on explicitly sets the flag to 'on' ; /off /off explicitly sets the flag to 'off' ; new_quat=new_quat ; array[4]; type: double ; new quaternion to be put in frame header. ; (if new_quat is set, then the bad_quat flag is ; explicitly set to zero). ; OUTPUTS: ; Changes are written directly into the disk file ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; GetFileSpec, SetFileSpec, smei_getfile, InitVar ; PROCEDURE: ; Only one header entry can be changed in one frame at a time. ; MODIFICATION HISTORY: ; MAR-2004, Paul Hick (UCSD/CASS) ; JUL-2006, Paul Hick (UCSD/CASS) ; Added /on and /off keywords ; Added /bad_quat keyword ; OCT-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added new_quat keyword ;- IF n_elements(cframe) NE 1 THEN BEGIN message, /info, 'one file at a time, please' RETURN ENDIF InitVar, on , /key InitVar, off, /key IF on AND off THEN BEGIN message, /info, 'on AND off ??? Pullease.' RETURN ENDIF cframe = cframe[0] SetFileSpec, cframe IF GetFileSpec(upto='dir') EQ '' OR GetFileSpec(from='type') EQ '' THEN BEGIN message, /info, 'specify fully qualified file name, please' RETURN ENDIF cfile = smei_getfile(cframe, /exact, count=count) IF count EQ 0 THEN BEGIN message, /info, cframe+' not found' RETURN ENDIF hdr = smei_getfile(cfile, /exist, /get_hdr) gzip = GetFileSpec(cfile,part='type') EQ '.gz' CASE gzip OF 0: cfile_ = cfile 1: BEGIN spawn, 'gunzip -v '+cfile cfile_ = GetFileSpec(cfile, upto='name') IF (file_search(cfile_))[0] EQ '' THEN RETURN ; Read-only filesystem ?? END ENDCASE hdr_updated = 0 IF IsType(shutter_open, /defined) THEN BEGIN IF (NOT on AND NOT off) OR $ (on AND hdr.shutter EQ 0) OR $ (off AND hdr.shutter EQ 1) THEN BEGIN message, /info, '"shutter-open" flag from ' + $ ('"'+['closed','open']+'"')[hdr.shutter]+' to ' + $ ('"'+['open','closed']+'"')[hdr.shutter] hdr.shutter = 1-hdr.shutter hdr_updated = 1 ENDIF ELSE IF on THEN BEGIN message, /info, '"shutter-open" flag already set to "open"' ENDIF ELSE IF off THEN BEGIN message, /info, '"shutter-open" flag already set to "closed"' ENDIF ELSE $ message, 'oops' ENDIF IF IsType(just_bad, /defined) THEN BEGIN IF (NOT on AND NOT off) OR $ (on AND hdr.just_bad EQ 0) OR $ (off AND hdr.just_bad EQ 1) THEN BEGIN message, /info, '"just-bad" flag from ' + $ ('"'+['off','on']+'"')[hdr.just_bad]+' to ' + $ ('"'+['on','off']+'"')[hdr.just_bad] hdr.just_bad = 1-hdr.just_bad hdr_updated = 1 ENDIF ELSE IF on THEN BEGIN message, /info, '"just_bad" flag already set to "on"' ENDIF ELSE IF off THEN BEGIN message, /info, '"just_bad" flag already set to "off"' ENDIF ELSE $ message, 'oops' ENDIF IF IsType(bad_quat, /defined) THEN BEGIN IF (NOT on AND NOT off) OR $ (on AND hdr.bad_quat EQ 0) OR $ (off AND hdr.bad_quat EQ 1) THEN BEGIN message, /info, '"bad_quat" flag from ' + $ ('"'+['off','on']+'"')[hdr.bad_quat]+' to ' + $ ('"'+['on','off']+'"')[hdr.bad_quat] hdr.bad_quat = 1-hdr.bad_quat hdr_updated = 1 ENDIF ELSE IF on THEN BEGIN message, /info, '"bad_quat" flag already set to "on"' ENDIF ELSE IF off THEN BEGIN message, /info, '"bad_quat" flag already set to "off"' ENDIF ELSE $ message, 'oops' ENDIF IF IsType(new_quat, /defined) THEN BEGIN IF n_elements(new_quat) NE 4 OR NOT IsType(new_quat,/double) THEN message, 'oops' FOR i=0,3 DO fxhmodify, cfile_, 'QUAT'+strcompress(i+1,/rem), new_quat[i] hdr.bad_quat = 0 hdr_updated = 1 ENDIF IF hdr_updated THEN fxhmodify, cfile_, 'FLAGS', smei_frm_flag(hdr) IF gzip THEN spawn, 'gzip -v '+cfile_ RETURN & END