([prj-radius],[grp],[iter]) ; Merge Volumes at end of defocus group loop
; SOURCE:       endmerge.pam         ArDean Leith  Nov 2000
;               []                   ArDean Leith  Dec 2005
;               maxim                ArDean Leith  Dec 2006

; MASTER COPY:  /net/bali/usr1/spider/docs/techs/recon/programs
;
; INPUT REGISTERS: 
;   [prj-radius]           Radius of restored object 
;   [grp]                  Group number
;   [next-iter]            Iteration number
;
;  '##' denotes iteration,  '##+' denotes next iteration, and '***' denotes group
; INPUT FILES:
;   [order_select]         input/order_select            Group selection doc file  
;   [sel_particles]        work/defgrp***/select         Particle selection doc file
;   [sel_particles_even]   work/defgrp***/selecteven     Particle selection doc file 
;   [sel_particles_odd]    work/defgrp***/selectodd      Particle selection doc file         
;   [next_group_align]     final/defgrp***/align##+      Alignment parameter doc file 
;   [next_aligned_images]  work/dala##_***@              Aligned images    
;
; OUTPUT FILES:
;   [next_group_bpr]       final/defgrp***/bpr##+        Final reconstructed volume
;   [next_group_bpr]_odd   final/defgrp***/bpr_##+_odd   Final odd reconstructed volume 
;   [next_group_bpr]_even  final/defgrp***/bpr_##+_even  Final even reconstructed volume 
;   [next_group_dbpr]      final/defgrp***/dbpr##+       Resolution doc file 
;
; CALLS: none
;......................................................................

[next-iter]=[iter]+1

VM
echo " endmerge starting for Group: {***[grp]}"
VM
date '+ TIME: %x  %X'

FI X [maxim]               ; Find total number of images (not same as in group selection)
[next_aligned_images]      ; Aligned images                    (input)
(26)                       ; Header location for number of images in file 

DE
_8@                        ; If not deleted may overflow existing stack

;                          ; Calculate volumes using 'BP CG' for increased resolution

CP                         ; Load aligned projections into inline stack #8
[next_aligned_images]      ; Aligned images                    (input)
_8@                        ; Inline stack                      (output)
[maxim]                    ; Number of images (Not all in use)

BP CG                      ; Back Projection using conjugate gradients
_8@******                  ; Template for image files          (input)
[sel_particles]            ; Particle selection doc. file      (input)
[prj-radius]               ; Radius of restored object
[next_group_align]         ; Alignment parameters doc file     (input)
N                          ; Does volume have symmetries
[next_group_bpr]           ; Reconstructed volume file         (output)
(1.0E-5,0.0)               ; Error limit, chi^2 limit:
(25,1)                     ; Iteration limit, mode
(2000)                     ; Lambda

MY FL
;                          ; Two additional 'BP' runs to assess resolution

BP CG                      ; Back Projection - 3D, conjugate gradients
_8@******                  ; Template for image files          (input)
[sel_particles_odd]        ; Odd particle selection doc. file  (input)
[prj-radius]               ; Radius of restored object
[next_group_align]         ; Alignment parameters doc file     (input)
N                          ; Does volume have symmetries
[next_group_bpr]_odd       ; Reconstructed odd volume          (output)
(1.0E-5,0.0)               ; Error limit, chi^2 limit
(25,1)                     ; Iteration limit, mode
(2000)                     ; Lambda

MY FL
BP CG                      ; Back Projection - 3D, conjugate gradients
_8@******                  ; Template for 2D image file        (input)
[sel_particles_even]       ; Even particle selection doc. file (input)
[prj-radius]               ; Radius of restored object
[next_group_align]         ; Alignment parameters doc file     (input)
N                          ; Does volume have symmetries
[next_group_bpr]_even      ; Reconstructed even volume         (output)
(1.0E-5,0.0)               ; Error limit, chi^2 limit
(25,1)                     ; Iteration limit, mode
(2000)                     ; Lambda

RF 3                       ; Phase Residual & Fourier shell correlation
[next_group_bpr]_odd       ; Odd volume                       (input)
[next_group_bpr]_even      ; Even volume                      (input)
(0.5)                      ; Ring width
(0.2,2.0)                  ; Scale factor
C                          ; Missing cone or wedge
(90.0)                     ; Max. tilt angle
(3)                        ; Factor for noise comparison
[next_group_dbpr]          ; Resolution doc file - dbpr       (output)

MY FL
RE
;