; Split selection file
;
; SOURCE: oddeven.spi 
;
; PURPOSE: Divides the data set  into two
;          equivalent sets, the odd- vs even-numbered particles.
;
; MASTER COPY: /net/bali/usr1/spider/docs/techs/recon/newprogs/
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  -------------------- Input files -----------------------------------

FR G
[order]order_defocus          ; Selection file for defocus groups

FR G
[seltotal]df{***x77}/seltotal ; Selection files for particles in each defocus group

; -------------------------- Output files ---------------------------

FR G
[seleven]df{***x77}/seleven  ; Selection files for even-numbered particles (one for each defocus group)

FR G
[selodd]df{***x77}/selodd    ; Selection files for odd-numbered particles (one for each defocus group)

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

UD N,x50                 ; Find number of defocus groups
[order]

DO LB1 x77 = 1,x50       ; Loop over all defocus groups

   DE                    ; Delete the output files
   [seleven]

   DE                    ; Delete the output files
   [selodd]

   
   UD N,x20              ; Find number of particles in selected file
   [seltotal]

   x21=-1
   x51=0
   x52=0

   DO LB2 x71=1,x20      ; Loop over all particles

      UD IC,x71,x91
      [seltotal]

      IF (x21.eq.-1) THEN
         x52=x52+1

         SD x52,x91
         [seleven]
 
      ELSE
         x51=x51+1

         SD x51,x91
         [selodd]
      ENDIF
      x21=-x21
   LB2

   SD E
   [seleven]
   SD E
   [selodd]

   UD ICE
   [seltotal]
LB1

EN D
;