def validate_lag(Tplot, chrono):
  """Return T_lag:
   - equal to Tplot with fallback: HMM.t.Tplot.
   - no longer than HMM.t.T.
   Also return corresponding K_lag, a_lag."""

  # Defaults
  if Tplot is None:
    Tplot = chrono.Tplot
  
  # Rename
  T_lag = Tplot

  assert T_lag >= 0

  # Validate
  t2 = chrono.tt[-1]
  t1 = max(chrono.tt[0], t2-T_lag)
  T_lag = t2-t1
  
  K_lag = int(T_lag / chrono.dt) + 1 # Lag in indices
  a_lag = K_lag//chrono.dkObs + 1    # Lag in obs indices

  return T_lag, K_lag, a_lag