PRO wlcefixfits, fits_name
;
;+ wlcefixfits.pro
;
; Fix FITS header of a Skylab ATM/WLCE image.
;
; Andrew L. Stanger   HAO/NCAR     9 Apr 1998
; 20 Aug 1998: remove blank lines at end of header.
; 21 Oct 1998: change INSTRUME to ATM-S052, add DETECTOR = '35MM FILM'
;-

fits_outname = fits_name

;--- Read FITS file header (hdu) and pixel data (img).

img = readfits (fits_name, hdu, /noscale)

;--- Remove extra comment lines in FITS header.

hdu [186] = 'END                                                                             '
FOR i = 187, 215 DO $
hdu [i] = '                                                                                '
;--- Find image min/max.

datamin = MIN (img) * 1.0E-11
datamax = MAX (img) * 1.0E-11
dispmin = datamin
dispmax = datamax
print, 'dispmin/max: ', dispmin, dispmax

;--- Exposure duration.

exposure = FXPAR (hdu, "EXPOSURE")
expdur = float (exposure)
FXADDPAR, hdu, 'EXPDUR',   expdur, ' EXPOSURE DURATION (SECONDS).'

;--- Compute spacecraft roll in degrees.

roll = FXPAR (hdu, 'ROLL')		; arcmin
scroll = - roll / 60.0			; degrees

;--- Replace '.' with ':' in Observation Time. 

otime = FXPAR (hdu, 'TIME-OBS')
print, 'otime: ', otime
hour   = strmid (otime, 0, 2)
minute = strmid (otime, 3, 2)
second = strmid (otime, 6, 2)
otime = hour + ':' + minute + ':' + second
print, 'otime: ', otime
print, 'size (otime): ', size (otime)

;--- Shorten various names in parameter strings.

FXADDPAR, hdu, 'ORIGIN',   'HAO:SKYLAB',   ' HIGH ALTITUDE OBSERVATORY'
;FXADDPAR, hdu, 'INSTRUME', 'ATM:S052',     ' SKYLAB EXPERIMENT DESIGNATION'
FXADDPAR, hdu, 'INSTRUME', '35MM FILM',     ' B/W 35MM FILM CAMERA'
FXADDPAR, hdu, 'TELESCOP', 'ATM:WLCE',      ' WHITE LIGHT CORONAGRAPH EXPERIMENT'
;FXADDPAR, hdu, 'DETECTOR', '35MM FILM',    ' B/W 35MM FILM CAMERA'
FXADDPAR, hdu, 'OBJECT',   'SUN:CORONA',    ''
FXADDPAR, hdu, 'TYPE-OBS', 'WHITE LIGHT' , ' VISIBLE BANDPASS [300 - 700 NM]'

FXADDPAR, hdu, 'TIME-OBS', otime, ' OBSERVATION TIME: HH:MM:SS [UT]'

;--- BSCALE=1.0E+10 in header is incorrect.  It should be 1.0E-11.

FXADDPAR, hdu, 'BSCALE',   1.0E-11, ' PHYSICAL VALUE = BZERO + BSCALE * (ARRAY VALUE)'

;--- Set coordinate rotation to specify solar north.

FXADDPAR, hdu, 'CROTA1',   scroll,  ' [DEGREES]'
FXADDPAR, hdu, 'CROTA2',   scroll,  ' [DEGREES]'

;--- Insert pixel min/max values.

FXADDPAR, hdu, 'DATAMIN',  datamin, ' DATA MINIMUM [BSUN]'
FXADDPAR, hdu, 'DATAMAX',  datamax, ' DATA MAXIMUM [BSUN]'
FXADDPAR, hdu, 'DISPMIN',  dispmin, ' DISPLAY MINIMUM [BSUN]'
FXADDPAR, hdu, 'DISPMAX',  dispmax, ' DISPLAY MAXIMUM [BSUN]'

hdu = STRUPCASE (hdu)

;--- Write FITS image back to disk.

WRITEFITS, fits_outname, img, hdu

END