// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: get_obs_time(double, double)
void get_obs_time(double jd_obs, double obs_tow)
{
double o_frac;
double delta;
static double max_delta = 0.0;

   // Convert jd_obs to gregorian time values.  Since the gregorian() function
   // can have round-off errors the the range of 0.0001 seconds we do some
   // tom-foolery to attempt to use obs_tow value to get the seconds exactly
   // what the receiver sent (jd_obs is used to get the rest of the date/time)

   gregorian(1, jd_obs);

   o_frac = obs_tow - (double) (int) obs_tow;
   delta = fabs(g_frac - o_frac);
   if((delta > max_delta) && (delta < 0.5)) max_delta = delta;
   if(delta > (1.0-JD_OBS_ROUND)) delta = (1.0-delta);

if(show_debug_info) sprintf(debug_text4, "g_frac:%.7f  o_frac:%.7f  delta:%.7f", g_frac,o_frac, delta);
   if(delta < (JD_OBS_ROUND*1.0)) { // gregorian fraction is close to observation fraction
      // if the two fractions are on each side of the 1 second threshold we
      // cant substute the observation fraction for the gregorian fraction since
      // that could cause the seconds value to be wrong and cause a backwards
      // time step.
      if((o_frac < JD_OBS_ROUND) && (g_frac > (1.0-JD_OBS_ROUND))) {
         //  bump the year/month/day hours/minutes/seconds and use o_frac
         gregorian(1, jd_obs+jtime(0,0,0,0.1));  // bump time past any roundoff error
         g_frac = o_frac;
//if(rinex_file) write_rinex_line(rinex_file, "time bump!", "COMMENT");  //rnx
      }
      else if((g_frac < JD_OBS_ROUND) && (o_frac > (1.0-JD_OBS_ROUND))) {
         gregorian(1, jd_obs-jtime(0,0,0,0.1)); // do a negative time bump
         g_frac = o_frac;
//if(rinex_file) write_rinex_line(rinex_file, "negative time bump!", "COMMENT");  //rnx
      }
      else {  // it's safe to replace gregorian() value with obs_tow value
         g_frac = o_frac; 
      }
   }
if(show_debug_info) sprintf(debug_text3, "g_frac:%.7f  o_frac:%.7f  delta:%.7f  maxd:%.7f", g_frac,o_frac, delta,max_delta);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
movl $0x1, %edi
callq 0x11dd00
movsd -0x10(%rbp), %xmm0
cvttsd2si -0x10(%rbp), %eax
cvtsi2sd %eax, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x23d589(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
subsd -0x18(%rbp), %xmm0
movaps 0x3ff71(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
ucomisd 0x2aa903(%rip), %xmm0   # 0x3d9c38
jbe 0x12f353
movsd 0x3fd51(%rip), %xmm0    # 0x16f090
ucomisd -0x20(%rbp), %xmm0
jbe 0x12f353
movsd -0x20(%rbp), %xmm0
movsd %xmm0, 0x2aa8e5(%rip)   # 0x3d9c38
movsd -0x20(%rbp), %xmm0
movsd 0x5efe8(%rip), %xmm1    # 0x18e348
ucomisd %xmm1, %xmm0
jbe 0x12f378
movsd 0x3fcfa(%rip), %xmm0    # 0x16f068
subsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x148725(%rip), %rax    # 0x277aa4
cmpb $0x0, (%rax)
je 0x12f3ae
leaq 0x23d50d(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
movsd -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm2
leaq 0x26ebd0(%rip), %rdi    # 0x39df70
leaq 0x66d58(%rip), %rsi     # 0x1960ff
movb $0x3, %al
callq 0x9060
movsd 0x5ef12(%rip), %xmm0    # 0x18e2c8
ucomisd -0x20(%rbp), %xmm0
jbe 0x12f4af
movsd 0x5eeff(%rip), %xmm0    # 0x18e2c8
ucomisd -0x18(%rbp), %xmm0
jbe 0x12f42e
leaq 0x23d4c1(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
movsd 0x5ef65(%rip), %xmm1    # 0x18e348
ucomisd %xmm1, %xmm0
jbe 0x12f42e
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
xorl %edx, %edx
movsd 0x3fd2b(%rip), %xmm0    # 0x16f128
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x11dd00
movsd -0x18(%rbp), %xmm0
leaq 0x23d470(%rip), %rax    # 0x36c898
movsd %xmm0, (%rax)
jmp 0x12f4ad
movsd 0x5ee92(%rip), %xmm0    # 0x18e2c8
leaq 0x23d45b(%rip), %rax    # 0x36c898
ucomisd (%rax), %xmm0
jbe 0x12f49b
movsd -0x18(%rbp), %xmm0
movsd 0x5eef8(%rip), %xmm1    # 0x18e348
ucomisd %xmm1, %xmm0
jbe 0x12f49b
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
xorl %edx, %edx
movsd 0x3fcbe(%rip), %xmm0    # 0x16f128
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
subsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x11dd00
movsd -0x18(%rbp), %xmm0
leaq 0x23d403(%rip), %rax    # 0x36c898
movsd %xmm0, (%rax)
jmp 0x12f4ab
movsd -0x18(%rbp), %xmm0
leaq 0x23d3f1(%rip), %rax    # 0x36c898
movsd %xmm0, (%rax)
jmp 0x12f4ad
jmp 0x12f4af
leaq 0x1485ee(%rip), %rax    # 0x277aa4
cmpb $0x0, (%rax)
je 0x12f4ed
leaq 0x23d3d6(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
movsd -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm2
movsd 0x2aa760(%rip), %xmm3   # 0x3d9c38
leaq 0x26e941(%rip), %rdi    # 0x39de20
leaq 0x66c3e(%rip), %rsi     # 0x196124
movb $0x4, %al
callq 0x9060
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)