; Generates CTF correction profiles for micrographs
 ;
 ; PURPOSE: Converts EMAN2 coordinates file to SPIDER format.
            Outputs coordinates of window centers. 
 ;
 ; SOURCE:  spider/docs/techs/recon1/Procs/eman2spi.spi
 ;
 ; REQUIRES: emancoords2spiderdoc.py
 ;
 ; USAGE:    clean ; spider spi/dat @eman2spi

 ; ---------------------- Inputs ----------------------

 [sel_mic]    = '../sel_micrograph                       ; Micrograph list  (one)

 [eman_coords] = '../Micrographs/mic{****[mic-num]}.box  ; EMAN coordinates (one / micrograph)

 ; ----------------------- Output -----------------------

 [win_dir]       = 'win'                                 ; Directory for selection docs

 [coords_dir]    = 'coords'                              ; Directory for coordinate docs

![spider_coords] = '[coords_dir]/sndc_{****[mic-num]}'   ; SPIDER center coordinates doc files (one / micrograph)
 [spider_coords] = '[coords_dir]/pkcoor_{****[mic-num]}' ; SPIDER center coordinates doc files (one / micrograph)

 [mic_part_list] = '[win_dir]/sel_part_{****[mic-num]}'  ; Particle selection doc files (one / micrograph)

 [summary_doc]   = 'summary-eman2spi'                    ; Summary docfiles             (one / micrograph)

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

 ; Prepare summary doc
 DE
   [summary_doc]
 SD /       MICNUM    NUMPARTICLES
   [summary_doc]

 [particle-counter] = 0

 ; Create directories if necessary
 SYS
   mkdir -p [win_dir]  [coords_dir]

 ; Get # of micrographs
 UD N [num-mics]
   [sel_mic]

 DO [mic-key] = 1, [num-mics] ; Loop through micrographs ----------

    ; Get micrograph #
    UD IC [mic-key], [mic-num]
      [sel_mic]

    ; Run Python script
    SYS
      emancoords2spiderdoc.py [eman_coords] [spider_coords].$DATEXT

    ; Get # of particles
    UD N [mic-parts]
      [spider_coords]
    
    ; Write selection doc
    DOC CREATE
      [mic_part_list]
      1                   ; Column # to populate
      1-[mic-parts]

    ; Write to summary
    SD [mic-key], [mic-num], [mic-parts]
      [summary_doc]

    ; Update cumulative counter
    [particle-counter] = [particle-counter] + [mic-parts]
 ENDDO               ; End micrograph-loop -----------------------

 SYS
   echo ; echo " Converted: {%I0%[particle-counter]} coordinates from {%I0%[num-mics]} micrographs"

 ; Close doc
 UD ICE
   [sel_mic]
 SD /           NUM_MICS   NUMPARTICLES
   [summary_doc]
 SD -1, [num-mics],[particle-counter]
   [summary_doc]
 SD E
   [summary_doc]

 EN D

 ; Modified 2013-10-16
 ;    2013-10-16 (agl) -- modernized
 ;    2012-07-19 (trs) -- creates output directories if needed
 ;    2012-04-06 (trs) -- added sel_part output
 ;