; Creates gnuplot file of refinement resolution curve
 ;
 ; SOURCE: spider/docs/techs/recon1/Procs/plot-fsc-curve.spi 
 ;
 ; PURPOSE: Plots FSC resolution curve  
 ;   
 ; PROCEDURE CALLED which sets filenames:
 ;    recon-settings    recon-settings.spi
 ;
 ; INPUT FILES: ('##' denotes iteration)
 ;    [next_m_fsc]    [rec_dir]/fscdoc_m_##'   Iteration FSC curves  (one)
 ;
 ; OUTPUT FILES:  
 ;    [fscplot] fsc_01.gnu             Text file of gnuplot commands 
 ;
 ;  ------------ Parameters ----------------------------------------

 [cut]  = 0.143                  ; Resolution cutoff (Usually: 0.5 or 0.143) 
 [iter] = 1                      ; Iteration (for file name) 

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

 ; Input file names and pixsiz
 @recon-settings([pixsiz],[ang-step],[r2],[alignsh],[prj-radius],[winsiz],[incore-yn],[bp-type],[qsub],[masterCPUs],[groupCPUs])
 [iter] = 1                      ; Iteration (for file name) 

 IQ FI [exists]
   [next_m_fsc]
 IF ( [exists] == 0 ) THEN
   SYS
     echo "  File: [next_m_fsc].$DATEXT does not exist"
   EN
 ENDIF

 [maxspfreq] = 0.5 / [pixsiz]
 [t]         = 0.25 / [maxspfreq]
 
 SYS 
   echo "  Pixel Size: {%f6.1%[pixsiz]}  Max Spatial Freq: {%f6.2%[maxspfreq]}"

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

 ; Allow Angstroms symbol
 SYS 
   echo 'set encoding iso_8859_1'         >> [fscplot]
 SYS
   echo set xlabel \"Frequency, 1/\\305\" >> [fscplot]

;; SYS 
;;   echo set xlabel \"Frequency\" >> [fscplot]
 SYS 
   echo 'set xzeroaxis'                   >> [fscplot]
 SYS 
   echo 'set ylabel "FSC"'                >> [fscplot]
   
 SYS 
   echo 'set xtics nomirror'              >> [fscplot]
 x22=2
 SYS
   echo ''set x{%i1%x22}tics \(\"20\" 0.05, \"10\" 0.10, \"7\" 0.143, \"5\" 0.2, \"4\" 0.25, \"3\" 0.333\, \"2\" 0.5\) >> [fscplot]
 ; (SPIDER otherwise substitutes lowercase 'x2' for uppercase 'X2'.)
   
 SYS 
   echo set style data lines     >> [fscplot]

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

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

 SYS 
   echo plot \\                  >> [fscplot]

 SYS
   echo ' '\'[next_m_fsc].$DATEXT\' using \(1/column\(4\)\):5 title \'[next_m_fsc]\' ls 32, \\ >> [fscplot]
;;;echo    \"[next_m_fsc].$DATEXT\" using             3    :5 title \"[next_m_fsc]\" ls 32, \\ >> [fscplot]

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

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

 EN D
 
 ; Modified 2017-07-20
 ;    2016-06-07 (agl) -- Uses @recon-settings
 ;    2016-05-30 (trs) -- added 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

 ;