; Plots the number of particles for each projection view
;
; SOURCE: plotviews.spi 
;
; PURPOSE: Plots number of particles for each projection view, group by group.
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  ------------ Parameters ----------------------------------------

 [grp]=-1                    ; For histogram of a single group 
                             ;     set this number to desired group.
                             ; For histograms of all groups set this to -1

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

FR G                                     
[defgrps]sel_group                    ; Defocus groups selection file

FR G
[group_howmany]df{***[grp]}/how_many  ; Histograms by defocus groups

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

FR G
[displaydir]display                   ; Directory for output files

FR G
[gnuplot_commands][displaydir]/jnkplot_how_{***[grp]} ; Individual gnuplot files

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

VM
mkdir -p [displaydir]

[numgrps] =1                       ; Default number of groups 
 IF ([grp] .LE. 0) THEN
   UD N [numgrps]                  ; Get number of groups 
   [defgrps]                       ; Group selection doc file      (input)
ENDIF

DO LB1 [numgrp]=1,[numgrps]        ; Loop over all defocus group(s)

   IF ([numgrps] .GT. 1) THEN
      UD IC [numgrp],[grp]         ; Get current defocus group number
      [defgrps]
   ENDIF
   
   DE                              ; Delete the output files
   [gnuplot_commands]
 
   VM 
   echo #!/bin/sh > [gnuplot_commands].$DATEXT

   VM 
   echo set ylabel \"Particles\" >> [gnuplot_commands].$DATEXT

   VM 
   echo set xlabel \"View\" >> [gnuplot_commands].$DATEXT

   VM 
   echo set title \"Particles vs Views for Group {****[grp]}\" >> [gnuplot_commands].$DATEXT

   VM 
   echo plot \'[group_howmany].$DATEXT\' using 1:3 notitle  with boxes >> [gnuplot_commands].$DATEXT

   VM                         
   gnuplot -persist [gnuplot_commands].$DATEXT &
LB1

VM                                 
echo ' 'Histograms Plotted with: gnuplot script --------
VM                         
cat [gnuplot_commands].$DATEXT 
VM                                      
echo ' '-----------------------
VM                                      
echo ' '

EN D
 
;