function getc1im, in_filenames, TIME=time

;
; NAME:		GETC1IM
;
; PURPOSE:	Returns a C1 difference image for the fist instance after
;		the given time. Finds the apprpriate FeXIV Clear continuum
;		(5309 A) image, finds the closest FeXIV Clear online (5302 A)
;		image, subtracts continuum from online, and returns. 
;
; INPUTS:	in_filenames:	an array of filenames for a given day
;		radius:		radius for carrington map
;		
; KEYWORDS:	TIME:	String specifying time for image. If no time is given, 
;			the next image is loaded. Format: '08:45:23'
;		Effective 961017, time is ignored. Files are scanned from beginning
;		of the day, and first one to match is taken.
;
; OUTPUTS:	floating point array, a differenced image
;
; ROUTINES CALLED:
;		fxpar.pro
;		headfits.pro
;		lasco_readfits.pro
;		str_to_sec.pro
;
; AUTHOR:	Nathan Rich, Oct 1996
;
; MODIFIED:	961016 by N. Rich	removed time constraint, so takes first 
;					image each day
;		961017 by N. Rich	added check for each image displayed; normalized
;					exposure time
;

COMMON c1carr, oldtest

n = 1
found = 0
next = 0
wavelength = 0
old = 0
numfiles = n_elements(in_filenames)
errstr=''
ok=''

print,numfiles,' files passed to getc1im.'
;print,'time = ',time
img=fltarr(832,672)
IF numfiles eq 0 THEN RETURN,img


REPEAT BEGIN
   next=0
   IF (in_filenames(n) ne '') THEN BEGIN
	h=headfits(in_filenames(n))
	timeim=fxpar(h,'TIME-OBS')
;print,in_filenames(n)
	parts=str_sep(in_filenames(n),'/')
	date=float(parts(6))
	IF date LE 960718 THEN old = 1 
	IF (floor(fxpar(h,'WAVELENG')) eq 5309) OR old THEN wavelength = 1 $
	   ELSE wavelength = 0
	conditions = strtrim(fxpar(h,'FILTER'),2) eq 'Fe XIV' AND $
		strtrim(fxpar(h,'POLAR'),2) eq 'Clear' AND $
		fxpar(h,'NAXIS1') eq 832 
;print,date,wavelength,conditions
	IF (conditions AND wavelength) THEN BEGIN
	   print,'Loading continuum: ',strmid(in_filenames(n),36,22)
	   continuum=lasco_readfits(in_filenames(n))
	   continuum=25.1*(continuum/fxpar(h,'EXPTIME'))
	   hbef=headfits(in_filenames(n-1))
	   haft=headfits(in_filenames(n+1))
	   timebef=str_to_sec(fxpar(hbef,'TIME-OBS'))
		;print,timebef
	   timeim=str_to_sec(timeim)
		;print, timeim
	   timeaft=str_to_sec(fxpar(haft,'TIME-OBS'))
		;print,timeaft
	   conditionsaft = strtrim(fxpar(haft,'FILTER'),2) eq 'Fe XIV' AND $
		   strtrim(fxpar(haft,'POLAR'),2) eq 'Clear' AND $
		   fxpar(haft,'NAXIS1') eq 832 
	   IF ((timeaft - timeim) lt (timeim - timebef)) AND conditionsaft AND $ 
		((floor(fxpar(haft,'WAVELENG')) eq 5302) OR old)  THEN BEGIN
		   print,'Loading online: ',strmid(in_filenames(n+1),36,22)
		   online=lasco_readfits(in_filenames(n+1))
		   online=25.1*(online/fxpar(haft,'EXPTIME'))
	   ENDIF ELSE BEGIN
		conditionsbef = strtrim(fxpar(hbef,'FILTER'),2) eq 'Fe XIV' AND $
		   strtrim(fxpar(hbef,'POLAR'),2) eq 'Clear' AND $
		   fxpar(hbef,'NAXIS1') eq 832 
;print,strtrim(fxpar(hbef,'FILTER'),2),'  ',conditionsbef
		IF ((floor(fxpar(hbef,'WAVELENG')) eq 5302) OR old) AND conditionsbef $
		     THEN BEGIN
		   print,'Loading online: ',strmid(in_filenames(n-1),36,22)
		   online=lasco_readfits(in_filenames(n-1))
		   online=25.1*(online/fxpar(hbef,'EXPTIME'))
		ENDIF ELSE BEGIN
		   next = 1
		   online=fltarr(832,672)
		ENDELSE
	   ENDELSE
	   
	   img=online-continuum
	   wset,2
	   tvscl,REBIN(img<150>(-10),416,336)

	   testimg=img<100>0
test=total(testimg(188:208,168:504))+total(testimg(624:644,168:504))
diff=ABS(test-oldtest)
print,test,diff
openu,lun,'test_results',/get_lun,/append
printf,lun,test,diff
close,lun
free_lun,lun
oldtest=test


;	   IF (diff GT 3e5) THEN BEGIN
;	      READ,'OK? ',ok
;	      IF (ok EQ '' OR ok EQ 'y' OR ok EQ 'yes') THEN next = 0 ELSE next = 1
;	   ENDIF

;	   pos_scale= ((radius/2.2)*(-62) + 63)*80
;	   neg_scale= ((radius/2.2)*(-78) + 79)*25
;	   img = img<pos_scale>(-1)*neg_scale 
;	   print, 'Scaling C1 between ',pos_scale,' and -',neg_scale

	   IF next THEN found = 0 ELSE found=1
   	ENDIF
   ENDIF

   n = n + 1
ENDREP UNTIL n GE numfiles OR found

IF n GE numfiles THEN BEGIN
   print, 'No suitable files found for ',strmid(in_filenames(0),36,9)
   img(*,*)=0
ENDIF

RETURN, img

END ; getc1im
