; Create selection file
 ;
 ; PURPOSE: Interactively create a selection doc file listing 
 ;          existing micrograph file numbers. Can handle
 ;          missing file numbers. 
 ;
 ; SOURCE:  spider/docs/techs/recon1/Procs/make-mic-list.spi 
 ;
 ; USAGE:   clean ; spider spi/dat @make-mic-list

 ; ---------------------- Input files -------------------------------

 [micrographs] = 'raw****'         ; Micrograph name template

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

 [out-file] = '../sel_micrograph'  ; Selection file name

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

 RR [first]
   ? Starting file number ?

 RR [last]
   ? Ending file number ?

 DE                              ; If output doc file already exists, delete it
   [out-file]
 SD /   MICROGRAPH-NUMBER
   [out-file]                    ; Doc file  (output)

 SYS
   echo "  Finding micrographs...."

 ; Initialize micrograph-counter
 [mics] = 0

 ; Loop through micrographs, check if micrograph exists

 DO  [mic-num] = [first],[last]  ; Loop through micrographs ---------

    ; Check if micrograph exists
    IQ FI [mic-exists]
      [micrographs][mic-num]

    ; If micrograph exists...
    IF ( [mic-exists] == 1 ) THEN

        ; Increment micrograph counter
        [mics] = [mics] + 1

        ; Write number to selection doc file
        SD [mics], [mic-num]
          [out-file]           ; Doc file  (output)
    ENDIF
 ENDDO                         ; End micrograph-loop ----------------

 ; Close doc
 SD E
   [out-file]                  ; Doc file  (closed)

 SYS
   echo ; echo "  Found: {%I0%[mics]} micrographs" ; echo

 EN