pro align_prep, index, xx, yy, sc, code, $
    ;------------------------- Alignment parameters
    ref_image=ref_image0, $
    helio=helio0, date_helio=date_helio, $
    suncoord=suncoord0, $
    ffi_shift=ffi_shift, $
    ccdcoord=ccdcoord0, $
    qroll=qroll, $
    roll=roll, $
    qdebug=qdebug, qstop=qstop
;


pf=min(gt_pfi_ffi(index,/true_ffi))
ffi=keyword_set(ffi_shift)
if (n_elements(ref_image0) ne 0) then begin
    siz = size(ref_image0)
    typ = siz( siz(0)+1 )
    if (typ ne 8) then ref_image = index(ref_image0) else ref_image = ref_image0
end
;---------------------------------------- Figure out the pointing coordinates to register to
;
code = 2                        ;default is to register relative to sun center
if (keyword_set(helio0)) then code = 1          ;using heliocentric coorinates
if (keyword_set(suncoord0)) or ffi then code = 2    ;using coordinates relative to sun center
if (keyword_set(ccdcoord0)) then code = 3           ;using fixed IDL coordinates
;
if (code eq 1) or (code eq 2) then begin
    sc = sxt_cen(index, roll=roll)      ;need the sun center locations (in FR pixels)
end

case code of
    1: begin        ;heliocentric
    if ((n_elements(helio0) lt 2) or (n_elements(date_helio) eq 0)) then begin  ;did not come in defined
        if (n_elements(ref_image) eq 0) then begin
        helio = gt_center(index(0), /helio)         ;use the coordinates of the first image
        date_helio = anytim2ints(index(0))
        end else begin
        helio = gt_center(ref_image, /helio)
        date_helio = anytim2ints(ref_image)
        end
    end else begin
        helio = helio0
    end
      end
     2: begin       ;coordinates relative to sun center
    if not ffi or not pf and (n_elements(suncoord0) lt 2) then begin    ;did not come in defined
        if (n_elements(ref_image) eq 0) then begin
        sunc = gt_center(index, /angle)
        suncoord = fltarr(2)
        suncoord(0) = total(sunc(0,*)) / n_elements(index)  ;take the sun center position for all PFI images
        suncoord(1) = total(sunc(1,*)) / n_elements(index)  ;and average them to get the center position
        end else begin
        if not pf then suncoord = gt_center(ref_image, /angle) else $
           suncoord = gt_center(ref_image, /angle,roll=0.0) ; /angle   - FOV center to sun center in arcsec
                                    ;    (0,*) = angle in E/W direction with W positive
                                    ;    (1,*) = angle in N/S direction with N positive
        end
    end else begin
        if not ffi then suncoord = suncoord0
    end
      end
     3: begin
    if (n_elements(ccdcoord0) lt 2) then begin                  ;did not come in defined
        if (n_elements(ref_image) eq 0) then begin
        ccd = gt_center(index)
        ccdcoord = intarr(2)
        ccdcoord(0) = total(ccd(0,*)) / n_elements(index)   ;take the sun center position for all PFI images
        ccdcoord(1) = total(ccd(1,*)) / n_elements(index)   ;and average them to get the center position
        end else begin
        ccdcoord = gt_center(ref_image)
        end
    end else begin
        ccdcoord = ccdcoord0
    end
      end
endcase
;
;---------------------------------------- Figure out the offsets
;
fs = gt_sxt_axis(index, /rel_xray)      ;filter shift in full resolution pixels relative to the x-ray axis (2xN)
                        ;NB = (-0.36, 1.47) and NB image is NE of X-ray image
                        ;so we need to start farther left, and higher on the CCD to compensate ==> + fs
arcsec_per_pix = gt_pix_size()

case code of
    1: begin
        suncoord = reform(track_h2a(index, helio, date_helio))  ;need heliocentric motion (in arcsec)
        xy = conv_a2p(suncoord, index)              ; Added call to conv_a2p for correct
                xx = xy(0,*)                        ;   coordinate conversion (GLS - 25-Apr-99)
                yy = xy(1,*)
    end
    2: begin
        case 1 of
           ffi : begin                  ;Don't use roll for FFIs.  LWA 12-Nov-2005.
              ffi_shift = reform(rebin(ffi_shift,2,n_elements(index),/sample))
              xy = conv_a2p(ffi_shift,index,roll=0.0)           ; Added call to conv_a2p for correct
           end
           pf and not ffi : begin
              suncoord = reform(rebin(suncoord,2,n_elements(index),/sample))
              xy = conv_a2p(suncoord,index,roll=0.0)
           end
           else : begin   
              suncoord = reform(rebin(suncoord,2,n_elements(index),/sample))
              xy = conv_a2p(suncoord,index)         
           end
        endcase
        xx = xy(0,*)
        yy = xy(1,*)
    end
    3: begin
    xx = ccdcoord(0) + fltarr(n_elements(index))
    yy = ccdcoord(1) + fltarr(n_elements(index))
       end
endcase

end