([iter],[num-grps],[prj-radius],[qsub]) ; Creates reference projections on parallel cluster
 ;
 ; SOURCE: spider/docs/techs/recon1/Procs/pub-prjrefs.spi
 ;         Reference projections parallelized   ArDean Leith  Jan 2016
 ;
 ; PURPOSE: Create stacks stacks of reference projections ('PJ 3F') from both subset reference volumes 
 ;          in parallel. Waits for all subscribing nodes to finish their projections. 

 ; I/O Registers & files are set in: refine-settings.spi
 ;
 ; INPUT REGISTERS:
 ;   [iter]               Current iteration
 ;   [num-grps]           Number of parallel groups 
 ;   [prj-radius]         Projection radius 
 ;   [qsub]               Queing system (PBS vs PubSub) 
 ;
 ; INPUT FILES: (##' denotes iteration,  '%' denotes subset, and '***' denotes group)
 ;   [iter_refangs]       work/ref_angs_##            Reference angles doc file       (one/iter)      
 ;   [vol_s]              final/vol_##_s%             Current subset reference volume (two/iter) 
 ;
 ; OUTPUT FILES: 
 ;   [ref_projs_s]        work/ref_projs_##_s%        Reference projections stacks (two/iter)
 ;
 ; PROCEDURES CALLED:
 ;   pub-submit                  pub-submit.spi
 ;   .. publish/qsub                   qsub.pbs
 ;   .. pub-refine-start   pub-refine-start          
 ;   .... refine-settings   refine-settings.spi            
 ;   .... refine-prjloop     refine-prjloop.spi            
 ;
 ; -------------------------------- END BATCH HEADER ----------------------------

 ; Create stacks holding projections from both current reference volumes in parallel.

 UD N [num-angs]                ; Get number of reference images used
   [iter_refangs]               ; Reference images angles doc. file    (input)

 SYS
   echo  "  Iteration: {%I0%[iter]}  Projecting: [vol]_s1 and [vol]_s2  Angles: {%I0%[num-angs]}" 

 IF ( [num-grps] <= 1 ) THEN  
   ; No need for parallel jobs just use a single projection per subvolume and return

   DO [s] = 1,2                 ; Loop over subvolumes
     PJ 3F                      ; Projection operation
       [vol_s]                  ; Current reference volume             (input) 
       [prj-radius]             ; Radius of object
       1-[num-angs]             ; Reference angles used    
       [iter_refangs]           ; Reference angles doc file            (input)
       [ref_projs_s]@******     ; Reference projection stack template  (output) 
   ENDDO                        ; End of: Loop over subvolumes

 ELSE

   ; Project reference volumes in parallel and wait for all parallel jobs to finish

   [task] = 2                  ; pub-refine-start will start: refine-prjloop 
   [run1] = './spider $PRJEXT/$DATEXT @pub-refine-start '
 
   @pub-submit([iter],[num-grps],[task],[qsub])
      [run1]                   ; Script that runs projection in parallel

   SYS
     echo "  Consolidate group reference projection stacks into single stack for each subvolume"

   DO [s] = 1,2                ; Loop over subvolumes
     CP TO STK                 ; Merge stacks into single stack
       [ref_projs_s]_***@      ; Template for reference stacks       (input) 
       1-[num-grps]            ; File numbers   
       1                       ; Initial image in output stack
       [ref_projs_s]@          ; Combined stack                      (output)
   ENDDO                       ; End of: Loop over subvolumes
 ENDIF

 RE
 ;