; 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) 

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

 ; Input file names and pixsiz
 [steptype] = 1
 @recon-settings([steptype],[num-grps],[pixsiz],[ang-step],[r2],[alignsh],[prj-radius],[winsiz],[incore-yn],[bp-type],[qsub])
 [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]

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

 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) = {%f4.3%[cut]}"   >> [fscplot]

 SYS 
   echo plot \\                  >> [fscplot]

 SYS
   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
 
 ; Modified 2016-03-21
 ;    TO DO: change/add Angstroms to horizontal axis
 ;    2016-06-07 (agl) -- Uses @recon-settings
 ;    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

 ;