(x14,x76,x77) ; Records resolution in text file
;
; SOURCE: saveres.pam  New: Nov 2003  al
;                      Rewrite: June 2004 al
;
; MASTER COPY: /net/bali/usr1/spider/docs/techs/recon/newprogs/
;
; PURPOSE:  Calculates and records resolution in doc file.
;    Determines where the Fourier shell correlation drops below threshold
;    (either 0.5 or 0.15), and at this point, identify the corresponding
;    spatial frequency.   resolution = pixel size/spatial frequency
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  -------------------- Parameters -----------------------------------
;
x40 = 0.5                    ; Cutoff threshold for FSC curve
x41 = 1                      ; Use the Nth time curve crosses the threshold
;
; x14        Nyquist frequency  (Sent from caller)        
; x76        Iteration          (Sent from caller)    
; x77        Group              (Sent from caller)    

; -------------------- Input files -----------------------------------
; [dres_input]    (Sent from caller);  Doc file with resolution curve
; -------------------------- Output files ---------------------------
; [dbpr_resol]    (Sent from caller)
; -------------- END BATCH HEADER ---------------------------------

FR                              ; Read from caller
?dres input file?[dres_input]

FR                              ; Read from caller
?res output file?[dbpr_resol]

x42 = 1                         ; Counter to compare with x41

UD N, x51                       ; Size of input doc file = img. size
[dres_input]                    ; Resolutions doc. file

UD IC 3,x21,x22,x23             ; Get first line (x21 = previous, x31 = current)
[dres_input]                    ; Resolutions doc. file

DO LB1 x50=3,x51

   UD IC x50,x31,x32,x33
   [dres_input]                 ; Resolutions doc. file

   IF (x33.LT.x40) THEN
      IF (x23.GT.x40) THEN
         IF (x42.EQ.x41) THEN
            GOTO LB2            ; x21,31 = freq, x23,33 = fsc
         ELSE
            x42 = x42 + 1
         ENDIF
      ENDIF
   ENDIF

   x21 = x31 
   x23 = x33
LB1

LB2

UD ICE
[dres_input]                  ; Resolutions doc. file

x60 = x23-x33
x61 = (x40-x33)/x60
x62 = x31 - (x61 * (x31-x21)) ; Interpolated spatial freq.=x62
x66 = 0.5/(x14*x62)           ; Resolution = pixel size/spatial frequency

IF(x77.EQ.0.0)THEN
   IF (x76.EQ.1) THEN
      SD /    Iteration  resolution
      [dbpr_resol]
   ENDIF

   SD x76,x76,x66
   [dbpr_resol]
   ;VM
   ;echo "Iteration: {**x76}  Res: {%f6.2%x66}" >> [dbpr_resol].$DATEXT
ELSE
   IF (x76.EQ.1) THEN
      SD /    Iteration  group   resolution
      [dbpr_resol]
   ENDIF

   SD x76,x76,x77,x66
   [dbpr_resol]
   ;VM
   ;echo "Iteration: {**x76}  Group: {***x77}  {%f6.2%x66}" >> [dbpr_resol].$DATEXT
ENDIF

RE
;