; Prepare selected alignment paramaters file
;
; SOURCE: sel_align.bat
;
; PURPOSE: Prepare alignment pararameter files for refinement
;
; MASTER COPY: /net/bali/usr1/spider/docs/techs/recon/newprogs/
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  ------------ Input files ---------------------------------------

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

FR G
[part_by_group]../Reconstruction/df{***x77}/seltotal ; Particle selection file by defocus group

FR G
[ser]../Particles/win/ser{******x55}                 ; Particle images

FR G
[ali]../Alignment/ali/sar{******x55}                 ; Aligned particle images 

FR G
[align_parameters]../Alignment/align_01_{***x77}     ; Alignment file template

; --------------- Output files  -------------------------------------
FR G
[data]input/data{***x77}@{******x56}      ; Stack files with original images

FR G
[dala]input/dala01_{***x77}@{******x56}   ; Stack files with aligned  images

FR G
[new_align_parameters]input/align_01_{***x77} ; Alignment file template

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

MD
TR OFF                           ; Decreases results file output
MD
VB OFF

UD N,x20                         ; Get number of defocus groups 
[defocus_group_sel]

DO LB2 x11=1,x20                ; Loop over all defocus groups

   ; Get current group number 
   UD x11,x77                   ; Current defocus group number = x77
   [defocus_group_sel]          ; Defocus group selection file
 
   UD N,X71                     ; Get number of particles for this group
   [part_by_group]

   DO LB1 x56=1,x71             ; Loop over all particles (x56=new number)

      UD IC,x56,x55             ; Get particle number=x55
      [part_by_group]

      UD IC x55, x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,x41,x42,x43,x44,x45  ; Get alignment parameters for this particle
      [align_parameters]        ; Old alignment file template

      SD   x56, x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,x41,x42,x43,x44,x45  ; Get alignment parameters for this particle
      [new_align_parameters]    ; New alignment file template

   LB1

   UD ICE                       ; Finished with this defocus group
   [part_by_group]

LB2

EN 
;