function getc123,file, h, GET_BKG=get_bkg, RUNNING_DIFF=running_diff

;
;PURPOSE: 
;     Reads image from input filename and returns image which has 
;	been corrected for bias and exposure time and converted to
;	DN/sec and resized to 1024x1024
;
;INPUTS:
; file STRING:		file to get the image from
;
;KEYWORDS:
;	GET_BKG		keyword saying to take ratio with background model;
;			0 = no ratio; 1 = current model; 2 = any_year model
;	RUNNING_DIFF	return running difference images
;
;OUTPUTS:	result  FLTARR
;		h	STRUCT structure containing image header
;		
;
;ROUTINES CALLED:
;    	lasco_readfits
;	GETBKGIMG
;
; AUTHOR:	Nathan Rich, NRL, 1999/02/02
;
; HISTORY:
;	Replaces GETC2C3NORM2.pro
;
; MODIFIED:
;	2000/02	N. Rich - GET_BKG=2 means ANY_YEAR
;	 5/31/01, N.Rich - Replace ANCIL_DATA with LASCO_DATA
;

COMMON get_im, 		on_s,on_times,ff_ratio, hdr, prev, pylonim

;im = fltarr(1024,1024)
dbias = 0

;print,'Reading file ',file
IF strpos(file,'gz') NE -1 THEN im0 = read_gzip_fits(file,h) ELSE $
im0 = lasco_readfits(file,h)

IF keyword_set(GET_BKG) THEN IF get_bkg EQ 2 THEN any_year=1 ELSE any_year=0

;any_year=0
sz = size(im0)
;IF median(im0) NE 0 THEN BEGIN

IF sz(0) NE 0 and strpos(h.polar,'P') EQ -1 THEN BEGIN
   im = img2dnpersec(im0,h)	; applies offset bias, exptime corr
   im = reduce_std_size(im,h,/full)
   IF KEYWORD_SET(GET_BKG) THEN BEGIN
	bkg = GETBKGIMG(h,mh,ANY_YEAR=any_year,/FFV)
	bkg = bkg/mh.exptime
	good = where(bkg NE 0)

	im(good) = temporary(im(good))/bkg(good)
   ENDIF
ENDIF ELSE im = im0

IF h.detector EQ 'C3' THEN BEGIN
   IF datatype(pylonim) EQ 'UND' THEN BEGIN
        maskdir=GETENV('LASCO_DATA')+'/calib/'
        print,'Reading ',maskdir+'c3clearmask2.fts'
        pylonim=readfits(maskdir+'c3clearmask2.fts')
   ENDIF
   m = median(im)
   pylgtm = where(im GT 1.5*m and pylonim EQ 2)
   IF pylgtm(0) NE -1 THEN im(pylgtm)=m
ENDIF

IF keyword_set(RUNNING_DIFF) THEN rim = (im - prev)>0 ELSE rim = im

prev = im

return,rim

END ; getc2c3norm2
