; Rotate and shift images for Alignment
; 
; SOURCE: alignsh.spi  
;                         Added alignment stack op Nov 2006 ArDean Leith
;
; PURPOSE: Rotate and shift images according to parameters  
;          determined earlier by 'AP SH'. 
;          (Not needed if already done in: apshgrp.spi)
;
; MASTER COPY: /net/bali/usr1/spider/docs/techs/recon/newprogs/
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  --------------- Input files ----------------------------------------

FR G                                     
[defgrps]../Power_Spectra/order_defgrps ; Defocus groups selection file

FR G
[align_parameters]align_01_***          ; Alignment parameter files

FR G
[stk]data{***[grp]}@                    ; Unaligned image stack file

; --------------- Output file  ----------------------------------

FR G
[aligned_images]dala01_{***[grp]}@      ; Rotated, shifted (aligned) images

; -------------- END BATCH HEADER ---------------------------------

UD N,[numgrps]                     ; Get number of defocus groups 
[defgrps]

DO LB1 [numgrp]=1,[numgrps]        ; Loop over all defocus groups

   UD IC [numgrp], [grp]           ; Get current defocus group number 
   [defgrps]                       ; Defocus group selection file

   VM
   echo  ' 'Aligning group: {****[grp]}     

   ; Parameter order in doc file: PHI,THETA,PSI, REF#,IMG#, ROT,SX,SY

   RT SQ                           ; Rotate & shift the images
   [stk]                           ; Input image stack
   [aligned_images]                ; Output image stack
   (6,0,7,8)                       ; Reg. numbers for angle, scale, x, & y shift
   [align_parameters][grp]         ; Alignment angles doc. file         
LB1

; Finished with incore group selection doc. file
UD ICE
[defgrps]                          ; Defocus group selection file

VM
echo  ' '     

EN

;