;+
; NAME:
;   SXT_CADENCES
; PURPOSE:
;     Estimate nominal cadence based on bitrate, fov, flush count.
;     Has capability of predicting cadence for non-ideal setups.
; CATEGORY:
;     Yohkoh
; CALLING SEQUENCE:
; INPUTS:
;     User is prompted for fov size, flush count, FFI/PFI-dom state, and DPE.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; OUTPUTS:
; COMMON BLOCKS:
; SIDE EFFECTS:
; RESTRICTIONS:
;     Flush inputs must be decimal, not hex.
; MODIFICATION HISTORY:
;     04-jun-98, DMcK, written in rough form
;     08-jun-98, DMcK, added estimation of resultant cadence for 
;			'marginal' DPEs
;      7-oct-98, S.L.Freeland renamed 'cadences' to 'sxt_cadences'
;
;     Eventually want to allow hex input for 'A', since F is a commonly
;	used value....DMcK
;-
pro sxt_cadences
input,'How many rows, north-south?',NS,2
input,'How many blocks east-west?',EW,2
print,'What is the flush count setting A/B/C ? (4/1/1 is common)'
print,' (NOTE: This must be decimal, not hex.)'
input,' A = ?',a,4
input,' B = ?',b,1
input,' C = ?',c,1
input,'Input (0) for FFI dom or (1) for PFI dom:',dom,0
framerate=8.0-dom*6.0
nom_cad=(ew*framerate)*ns
fls=(a*4.*0.0081)+(b*0.045)
; print,' (That makes a flush latency of ',fls,'seconds.)'

; Add 0.360 seconds for filter latency and recommand long word
filter_latency=0.360

read_time=ew*1.0
max_exp=(ew*framerate)-fls-read_time-filter_latency
print,' '
print,' In QT/HI the nominal cadence for ',strtrim(fix(ns),1),$
	' NS * ',strtrim(fix(ew),1),' EW'
print,'  is ',strtrim(fix(nom_cad),1),$
	' seconds, as long as the exposure is less than'
print,max_exp,' seconds; i.e., max DPE is ',$
	strtrim(fix(exptim2dpe(max_exp*1000.)),1)

; Now do QT/MED

framerate=framerate*8.0
read_time=ew*8.0
nom_cad=(ew*framerate)*ns
max_exp=(ew*framerate)-fls-read_time-filter_latency

print,' '
print,' In QT/Med the nominal cadence for ',strtrim(fix(ns),1),$
	' NS * ',strtrim(fix(ew),1),' EW'
print,'  is ',strtrim(fix(nom_cad),1),$
	' seconds, as long as the exposure is less than'
print,max_exp,' seconds; i.e., max DPE is ',$
	strtrim(fix(exptim2dpe(max_exp*1000.)),1)


; Second part -- take a DPE and estimate what the 
; resultant cadence will be.
print,'  '
print,'  '
input,'  What DPE did you want to use?',dpe_in
exposure=(gt_dpe(dpe_in,/conv))/1000.0

; In QT/Hi,
framerate=8.0-dom*6.0
read_time=1.0*ew
ew_cadence=exposure+read_time+fls+filter_latency
; then round up to nearest integer-multiple of framerate
  ;print,'  '
  ; print,' ew_cadence is', ew_cadence
ew_cadence=(fix((ew_cadence/framerate)+1.))*framerate
  ; print,' rounded ew_cadence is', ew_cadence

; BUT -- ew_cadence has to be no smaller than ew*framerate!
if (ew_cadence lt ew*framerate) then ew_cadence=ew*framerate

; then multiply by extent in north-south direction
expected_cadence=ns*ew_cadence
print,'  '

print,' Expected cadence for DPE = ',strtrim(fix(dpe_in),1),' is ',$
strtrim(fix(expected_cadence),1),' seconds in QT/Hi, and '

; do the qt/med calculation
framerate=framerate*8.0
read_time=8.0*ew
ew_cadence=exposure+read_time+fls+filter_latency
ew_cadence=(fix((ew_cadence/framerate)+1.))*framerate
if (ew_cadence lt ew*framerate) then ew_cadence=ew*framerate

expected_cadence=ns*ew_cadence

print,'  ',strtrim(fix(expected_cadence),1),' seconds in QT/Med.'
print,'  '

; eventually put some switch here to try another without ending the program
end