process_reading(time_t rtc_time, struct timespec *system_time)
{
  double rtc_fast;

  accumulate_sample(rtc_time, system_time);

  switch (operating_mode) {
    case OM_NORMAL:

      if (n_samples_since_regression >= N_SAMPLES_PER_REGRESSION) {
        run_regression(1, &coefs_valid, &coef_ref_time, &coef_seconds_fast, &coef_gain_rate);
        n_samples_since_regression = 0;
        maybe_autotrim();
      }
      
      break;
    case OM_INITIAL:
      if (n_samples_since_regression >= 8) {
        handle_initial_trim();
      }
      break;
    case OM_AFTERTRIM:
      if (n_samples_since_regression >= 8) {
        handle_relock_after_trim();
      }
      break;
    default:
      assert(0);
      break;
  }  


  if (logfileid != -1) {
    rtc_fast = (rtc_time - system_time->tv_sec) - 1.0e-9 * system_time->tv_nsec;

    LOG_FileWrite(logfileid, "%s %14.6f %1d  %14.6f  %12.3f  %2d  %2d %4d",
            UTI_TimeToLogForm(system_time->tv_sec),
            rtc_fast,
            coefs_valid,
            coef_seconds_fast, coef_gain_rate * 1.0e6, n_samples, n_runs, measurement_period);
  }    

}
process_reading(time_t rtc_time, struct timespec *system_time)
{
  double rtc_fast;

  accumulate_sample(rtc_time, system_time);

  switch (operating_mode) {
    case OM_NORMAL:

      if (n_samples_since_regression >= N_SAMPLES_PER_REGRESSION) {
        run_regression(1, &coefs_valid, &coef_ref_time, &coef_seconds_fast, &coef_gain_rate);
        n_samples_since_regression = 0;
        maybe_autotrim();
      }
      
      break;
    case OM_INITIAL:
      if (n_samples_since_regression >= 8) {
        handle_initial_trim();
      }
      break;
    case OM_AFTERTRIM:
      if (n_samples_since_regression >= 8) {
        handle_relock_after_trim();
      }
      break;
    default:
      assert(0);
      break;
  }  


  if (logfileid != -1) {
    rtc_fast = (rtc_time - system_time->tv_sec) - 1.0e-9 * system_time->tv_nsec;

    LOG_FileWrite(logfileid, "%s %14.6f %1d  %14.6f  %12.3f  %2d  %2d %4d",
            UTI_TimeToLogForm(system_time->tv_sec),
            rtc_fast,
            coefs_valid,
            coef_seconds_fast, coef_gain_rate * 1.0e6, n_samples, n_runs, measurement_period);
  }    

}