; Creates gnuplot file of resolution curves
;
; SOURCE: plotref.spi 
;
; PURPOSE: Plots resolution curves for each iteration of refinement 
;
; MASTER COPY: /net/bali/usr1/spider/docs/techs/recon/newprogs/
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  ------------ Input files ----------------------------------------

FR G
[order]../Reconstruction/order_defocus  ; file with number of defocus groups

FR G
[dir]final                       ; directory with all these document files

FR G
[resolution]resolutions      ; file that has number of iterations

FR G
[dres]dres{**x11}           ; iteration resolution curves

FR G
[dbpr]dbpr{**x11}_{***x12}   ; resolution curves for defocus groups
                                   ; x11 = iteration, x12 = def group

FR G
[combined]dbpr{**x11}            ; combined resolution curve 

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

FR G
[gnuplot_iter]plot_refi      ; text file of gnuplot commands (iterations)

FR G
[gnuplot_dfgr]plot_refd     ; text file of gnuplot commands (def groups)

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

UD N,x50
[dir]/[resolution]

VM
\rm -f [gnuplot_iter]
 
VM 
echo #!/bin/sh > [gnuplot_iter]

VM 
echo set title \"$DATEXT refinement: iterations \" >> [gnuplot_iter]

VM 
echo set xlabel \"Frequency\" >> [gnuplot_iter]

VM 
echo set data style lines >> [gnuplot_iter]

; use a black line (color = -1) for the final curve
VM 
echo set linestyle 32 lt -1 >> [gnuplot_iter]


VM 
echo "f(x) = 0.5" >> [gnuplot_iter]

VM 
echo plot \\ >> [gnuplot_iter]

DO LB1 x11 = 2,x50

   FR L
   [dcurve][dir]/[dres].$DATEXT 

   IF (x11.EQ.x50) THEN   ; last curve gets a thick black line (ls 32)
      VM
      echo \"[dcurve]\" using 3:5 title \"[dres]\" ls 32, \\ >> [gnuplot_iter]
   ELSE
      VM
      echo \"[dcurve]\" using 3:5 title \"[dres]\" , \\ >> [gnuplot_iter]
   ENDIF
LB1

VM
echo "f(x) notitle" >> [gnuplot_iter]

VM                         
gnuplot -persist [gnuplot_iter] &

VM                         
cat [gnuplot_iter] &

; ==================================================================
; x11 should be final iteration


UD N,x51   ; get the number of defocus groups
[order]

VM
\rm -f [gnuplot_dfgr]
 
VM 
echo #!/bin/sh > [gnuplot_dfgr]
VM 
echo set title \"$DATEXT refinement: defocus groups \" >> [gnuplot_dfgr]
VM 
echo set xlabel \"Frequency\" >> [gnuplot_dfgr]
VM 
echo set data style lines >> [gnuplot_dfgr]

; use a black line (color = -1) for the combined curve
VM 
echo set linestyle 31 lt -1 >> [gnuplot_dfgr]

;VM 
;echo "f(x) = 0.5" >> [gnuplot_dfgr]

VM 
echo plot \\ >> [gnuplot_dfgr]

DO LB2 x12 = 1,x51

   FR L
   [dfcurve][dir]/[dbpr].$DATEXT 

   VM
   echo \"[dfcurve]\" using 3:5 title \"[dbpr]\", \\ >> [gnuplot_dfgr]

LB2

; the combined curve, uses linestyle defined above (ls 31)
VM
echo \"[dir]/[combined].$DATEXT\" using 3:5 title \"[combined]\" ls 31 >> [gnuplot_dfgr]

;VM
;echo "f(x) notitle" >> [gnuplot_dfgr]

VM                         
gnuplot -persist [gnuplot_dfgr] &

VM                         
cat [gnuplot_dfgr] &

EN D
 
;