; Creates gnuplot file of refinement resolution curves
 ;
 ; SOURCE: spider/docs/techs/recon1/Procs/plot-fsc-curves.spi 
 ;
 ; PURPOSE: Plots FSC resolution curves for each iteration of refinement 
 ;   
 ; PROCEDURE CALLED which sets filenames:
 ;    refine-settings       refine-settings.spi
 ;
 ; INPUT FILES: ('##' denotes iteration)
 ;    [params]     ../params'                Parameter doc file     (one -- optional)  
 ;    [m_fsc]      [out_dir]/fscdoc_m_##'    Iteration FSC curves   (one / iteration)
 ;
 ; OUTPUT FILES:  
 ;    [fscplots]   fsc_iter.gnu              Text file of gnuplot commands 
 ;
 ;  ------------ Parameters ----------------------------------------

 [cut]     = 0.143                  ; Resolution cutoff (Usually: 0.5 or 0.143) 

 [niter]   = 20                     ; Highest iteration to be plotted

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

 ; Input file names and pixsiz
 @refine-settings([pixsiz],[r2],[alignsh],[prj-radius],[iter1],[iter-end],[sphdecon],[smallang-yn],[qsub],[incore-yn],[gold-std],[bp-type])

 [maxspfreq] = 0.5 / [pixsiz]
 ![t]         = 0.25 / [maxspfreq]
 ! echo "f(x) = (x{*{%f5.1%[t]}) notitle" 
 
 SYS 
   echo "  Pixel Size: {%f6.1%[pixsiz]}  Max Spatial Freq: {%f6.2%[maxspfreq]}"

 SYS                                ; Remove gnuplot text file
   \rm -f [fscplots]            
 
 SYS 
   echo set title \"$DATEXT FSC  for Iterations \" >> [fscplots]

 SYS 
   echo set xlabel \"Frequency\" >> [fscplots]

 SYS 
   echo set style data lines     >> [fscplots]

 ; Use a black line (color = -1) for the final curve
 SYS 
   echo set style line 32 lt -1  >> [fscplots]

 ; Define line at resolution cut-off 
 SYS 
   echo "f(x) = {%f4.3%[cut]}"   >> [fscplots]

 SYS 
   echo plot \\                  >> [fscplots]

 DO [iter] = 1,[niter]

   IQ FI [exists]
     [m_fsc]
   IF ( [exists] == 0 ) CYCLE

   IF ( [iter] == [niter] ) THEN   ; Last curve gets a thick black line (ls 32)
      SYS
        echo \"[m_fsc].$DATEXT\" using 3:5 title \"[m_fsc]\" ls 32, \\ >> [fscplots]
   ELSE
      SYS
        echo \"[m_fsc].$DATEXT\" using 3:5 title \"[m_fsc]\" , \\      >> [fscplots]
   ENDIF
 ENDDO

 ; Put line at resolution cut-off 
 SYS
   echo "f(x) notitle"            >> [fscplots]


 SYS                                 
   echo  '  'Displaying plot using: gnuplot -persist [fscplots]; echo   
 SYS                          ; Plot the file                       
   gnuplot -persist [fscplots]  

 EN
 
 ; Modified 2016-03-21
 ;    TO DO: change/add Angstroms to horizontal axis
 ;    2016-03-21 (agl) -- Plots all fsc files up to niter
 ;    2016-01-14 (agl) -- Gold standard file names
 ;    2014-05-14 (agl) -- No longer has group plots
 ;    2013-12-03 (trs) -- Updated deprecated Gnuplot syntax
 ;    2013-12-02 (trs) -- Reporting masked FSC 
 ;    2013-11-28 (trs) -- Plot didn't substitute group numbers

 ;