;     This subroutine inputs the data frames, computes the iteration constant,
;     and records defined regions by setting bits in the template.  As per the
;     algorithm discussed in the paper the logarithm of each data frame is 
;     taken.  To avoid problems of variations in the average intensity each 
;     logged data frame is renormalized to have a zero average.
;     To increase the maximum allowed exposures, 
;     redefine the integer array TMP approriately,
;     and do not forget to change the value of nxp 
;     in the parameter statement in the main body. 
;     Variable assignments are:
;     a1,a2 = the real*4 displacements stored in the image header of each data
;             frame.  -jint rounds these values and reverses their signs.  The 
;             sign reversal is necessary to remain consistent with the 
;             arbitrary choice of camera movement wrt the image rather than
;             the more usual choice of vice versa.
;     bitnum = number-1 of bit to set of TMP.  (Recall bits run from 0-7)


PRO GETEXP,CON,DAT,TMP,normc,xdsp,ydsp,dcx,dcy,nxp,xp,locut,hicut,icut,rr,undef
      xdsp=intarr(nxp) & ydsp=xdsp & xcenter=intarr(16) & ycenter=xcenter
      DAT=fltarr(dcx,dcy,2) & radius=fltarr(16)

      normc(1)=0.0
l98:  print,'Enter start,end picture numbers'
      read, num1,num2
      if (num1 ge num2) then begin
	 print,'num1 > num2 '
	 goto,l98
      endif
      npts=dcx*dcy
      iq=0
      for numq=num1,num2 do begin
         fnam='ccdffcal'+strtrim(string(numq),2)
	 fzrd,fnam,DAT(*,*,0),hdr
	 xcenter(iq) = fix(hdr.center(0))
	 ycenter(iq) = fix(hdr.center(1))
	 radius(iq)  = float(hdr.radius)
	 xdsp(iq)=-(xcenter(iq)-xcenter(0))
	 ydsp(iq)=-(ycenter(iq)-ycenter(0))
	 print,'iq,xdsp,ydsp,r,norm',iq,xdsp(iq),ydsp(iq),radius(iq),normc(iq)
         npix=0
         if (icut eq 0) then $
;	   Use the intensity as cutting critiria.
	   insub=where((DAT(*,*,0) gt locut) and (DAT(*,*,0) le hicut),npix) $
	 else $
;	   Use the radius here. 
	   insub=where((DAT(*,*,0) gt locut) and (DAT(*,*,0) le hicut) and $
                 (shift(dist(max(dcx,dcy)),xcenter(iq),ycenter(iq)) le radius(iq)),npix)
         DAT(insub)=alog10(DAT(insub)) + normc(iq)
	 TMP(insub)=TMP(insub) OR ishft(1,iq-1)
	 print,'Bad Pixels In [',numq,']=',npix       
	 if (numq eq num1) then goto,l19
	 ir=1
         for numr=num1,(numq-1) do begin
            fnam='ccdffcal'+strtrim(string(numr),2)
	    fzrd,fnam,DAT(*,*,1),hdr
	    insub=where(ishft(TMP,1-ir) and 1)
	    DAT(insub+npts)=alog10(DAT(insub+npts)) + normc(ir)

	    insub=where(CON ne undef)
	    dspsub=insub(where(ishft(TMP(insub),1-iq) and 1))
	    disp=xdsp(iq)-xdsp(ir)+dcy*(ydsp(iq)-ydsp(ir))
	    dspsub=dspsub+disp
	    dspsub=dspsub(where(dspsub ge 0) and (dspsub le npts-1))
	    dspsub=dspsub(where(DAT(dspsub+npts) ne undef))
	    dspsub=dspsub(where(ishft(TMP(dspsub),1-ir) and 1))
	    sub=dspsub-disp
	    CON(sub)=CON(sub)+DAT(sub)-DAT(dspsub+npts)

	    dspsub=insub(where(ishft(TMP(insub),1-ir) and 1))
	    disp=xdsp(ir)-xdsp(iq)+dcy*(ydsp(ir)-ydsp(iq))
	    dspsub=dspsub+disp
	    dspsub=dspsub(where(dspsub ge 0) and (dspsub le npts-1))
	    dspsub=dspsub(where(DAT(dspsub) ne undef))
	    dspsub=dspsub(where(ishft(TMP(dspsub),1-iq) and 1))
	    sub=dspsub-disp
	    CON(sub)=CON(sub)+DAT(sub+npts)-DAT(dspsub)

         endfor
l19:	 iq=iq+1
      endfor
l320: xp=iq
;-----set the void to undefined.
      insub=where(TMP eq 0,iundef)
      if iundef ne 0 then CON(insub)=undef
      print,iundef,' Undefined pixels'
      RETURN
      end

