function getc1im3, on_file, on_obs_time, on_hdr

;
; NAME:		GETC1IM3
;
; PURPOSE:	Returns a legible C1 image which has been on/off 
;		subtracted, etc. Scales for exposure time. 
;
; INPUTS:	off_file:  STRING  name of c1 offline (5309) image
;				   with diskpath
;	Optional:
;		off_obs_time: STRING   date and time of observation
;					of off_file
;		
; KEYWORDS:	none
;
; OUTPUTS:	floating point array
;
; ROUTINES CALLED:
;		find_closest.pro
;		l1_rdfts2.pro
;		reduce_std_size.pro
;
; AUTHOR:	Nathan Rich, June 1997
;
; MODIFIED:	NBR, June 1997	do on/off subtraction
;		NBR, July 1997 	incorporate lines from wmkmovie.pro; add
;				on_tai_times
;		NBR, Sept 1997	add common block get_im; add ff_ratio
;		NBR, Nov 1998	return on_hdr
;   04.05.05, nbr - Don't get centers (done in reduce_std_size); extend get_im
;   04.05.07, nbr - Input on_file and find off_file (instead of vice versa)

COMMON get_im, 	off_s,off_times,ff_ratio, off_hdr, prev, pylonim, l1, ffv


	print,'Loading online file: ',on_file
	printf,l1,'Loading online file: '+on_file
onim = L1_RDFTS2(on_file,on_hdr)
IF onim(0) LT 0 THEN return, -1
on_obs_time = on_hdr.date_obs+' '+on_hdr.time_obs
	print,'online obs_time is ',on_obs_time
;onim = (onim - on_hdr.offset)/on_hdr.exptime


   on_utc= str2utc(on_obs_time)
   on_tai= utc2tai(on_utc)

   sub = FIND_CLOSEST(on_tai,off_times)
   off_file = off_s.diskpath(sub)+'/'+off_s.img_files_filename(sub)
;ENDIF ELSE on_file = on_files

	print,'Loading offline file: ',off_file
	printf,l1,'Loading offline file: '+off_file
offim=L1_RDFTS2(off_file,off_hdr)
IF offim(0) LT 0 THEN return,-1
off_obs_time = off_hdr.date_obs+' '+off_hdr.time_obs
	print,'offline obs_time is ',off_obs_time
;;; done in l1_rdfts2 *** offim = (offim-off_hdr.offset)/off_hdr.exptime
;IF N_PARAMS() GT 1 THEN BEGIN

offsz = SIZE(offim)
onsz = SIZE(onim)
IF offsz(0) EQ 0 OR onsz(0) EQ 0 THEN return,-1

;;; done in l1_rdfts2 *** backgr = GETBKGIMG(on_hdr,bkg_hdr,/ffv)

ref = offim
ref_hdr = off_hdr

;
; ** BOX NORMALIZATION done in L1_RDFTS2 **
;

onim = REDUCE_STD_SIZE(onim, on_hdr, FULL=ffv)   ;** IF ffv=0, make all images 512x512
ref  = REDUCE_STD_SIZE(ref , ref_hdr, FULL=ffv)  ;** IF ffv=0, make all images 512x512
new_image = onim - ref*ff_ratio

;IF on_obs_time GT '1997/07/21 18:00:00' THEN stop
RETURN, new_image

END ; getc1im





;**
;** START C1 (from WMKMOVIE)
;**
;IF KEYWORD_SET(FILL_COL) THEN fillcol=fill_col ELSE fillcol=10
;;find which filter was used
;filter=STRTRIM(filter_all(1),2)
;;set off-band wavelength
;IF filter EQ 'Fe XIV' THEN offband=5309
;IF filter EQ 'Fe X' THEN offband=6380
;IF (filter ne 'Fe XIV') and (filter ne 'Fe X') THEN print,'filter not recognized'
;;find first offband wavelength image
;flag=0
;count=0
;while flag ne 1 DO BEGIN
;	IF FIX(fpwvl_all(count)) EQ offband THEN flag=1
;	count=count+1
;		IF count EQ (len-1) THEN BEGIN
;			flag=1
;			print,'no offband images found'
;		ENDIF
;endwhile
;ref=L1_RDFTS(names(count-1),hdr)

;wset,2
;print,'Displaying onim.'
;tvscl,onim
;stop
;print,'Displaying offim.'
;tvscl,offim

;first_onband=0
;while flag ne 1 DO BEGIN
;	IF FIX(fpwvl_all(first_onband)) ne offband THEN flag=1
;	first_onband=first_onband+1
;		IF count EQ (len-1) THEN BEGIN
;			flag=1
;			print,'no onband images found'
;		ENDIF
;endwhile
;total_off=0
;flag=0
;count all offband images
;FOR i=0,len-1 DO BEGIN
;	IF FIX(fpwvl_all(i)) EQ offband THEN total_off=total_off+1
;ENDFOR
;lblcount=0
;IF filter EQ 'Fe X' THEN factor=0.975 ELSE factor=1.00
;
;IF KEYWORD_SET(FLAT_FIELD) THEN factor=factor*factoroff
;ref=ref*factor*exp_all(0)
;win_index=intarr(len-total_off)
;new_label=strarr(len-total_off)
;c1hdr_ind=bytarr(len)
;yloc=0
;prev = -1
;
;IF KEYWORD_SET(FLAT_FIELD) THEN new_image=new_image*factoron
;

;IF KEYWORD_SET(LOG_SCL) THEN BEGIN
;	new_image=new_image+10
;	b=where(new_image le 0,dummy)
;	IF dummy ne 0 THEN new_image(b)=1
;	new_image=alog10(new_image)*100
;ENDIF
;IF KEYWORD_SET(SQRT_SCL) THEN BEGIN
;   new_image = SQRT((new_image+10)>0)
;ENDIF
;IF KEYWORD_SET(RUNNING_DIFF) THEN BEGIN
;	dummy=new_image
;	new_image=new_image-image
;	image=dummy
;	IF KEYWORD_SET(FIXGAPS) THEN ind0=ind00
;ENDIF
;IF KEYWORD_SET(RADIAL) THEN new_image=new_image/radial
;
;IF KEYWORD_SET(FIXGAPS) THEN ind0 = WHERE(new_image EQ 0)
;
;new_image=fix(new_image)
;new_image= BYTE(((new_image > bmin < bmax)-bmin)*(!D.N_COLORS-1)/(bmax-bmin))
;
;IF KEYWORD_SET(FIXGAPS) THEN BEGIN
;   IF (ind0(0) NE -1) THEN BEGIN			;** gaps in ref image
;      IF ((fixgaps EQ 1) OR (i EQ 0) OR (prev(0) EQ -1)) THEN image(ind0) = ;fillcol $
;      ELSE new_image(ind0) = prev(ind0)	;** fill gaps with prev image
;   ENDIF
;   IF (ind00(0) NE -1) THEN BEGIN			;** gaps in this image
;      IF ((fixgaps EQ 1) OR (i EQ 0) OR (prev(0) EQ -1)) THEN image(ind00) = ;fillcol $
;     ELSE new_image(ind00) = prev(ind00)	;** fill gaps with prev image
;   ENDIF
;ENDIF
;
;prev = new_image
;
;label=new_label
;goodhdr = WHERE(c1hdr_ind EQ 1) & IF (goodhdr(0) NE -1) THEN all_hdr = ;all_hdr(goodhdr)
;**
;** END C1
;**


