// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r14
pushq %rbx
subq $0x30, %rsp
movaps %xmm1, -0x20(%rbp)
movl $0x1, %edi
movsd %xmm0, -0x28(%rbp)
callq 0xd0c46
movapd -0x20(%rbp), %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
leaq 0x22fbc7(%rip), %rbx    # 0x30d6b8
movsd (%rbx), %xmm0
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
andpd 0x2b67b(%rip), %xmm3    # 0x109180
ucomisd 0x29cedb(%rip), %xmm3   # 0x37a9e8
jbe 0xddb25
movsd 0x2b551(%rip), %xmm2    # 0x109068
ucomisd %xmm3, %xmm2
jbe 0xddb25
movsd %xmm3, 0x29cec3(%rip)   # 0x37a9e8
movsd 0x2b543(%rip), %xmm4    # 0x109070
subsd %xmm3, %xmm4
movsd 0x4dbef(%rip), %xmm2    # 0x12b728
cmpltsd %xmm3, %xmm2
andpd %xmm2, %xmm4
andnpd %xmm3, %xmm2
orpd %xmm4, %xmm2
leaq 0x13ad73(%rip), %r14    # 0x2188c4
cmpb $0x0, (%r14)
movapd %xmm1, -0x20(%rbp)
movapd %xmm2, -0x40(%rbp)
je 0xddb80
leaq 0x261228(%rip), %rdi    # 0x33ed90
leaq 0x55938(%rip), %rsi     # 0x1334a7
movb $0x3, %al
callq 0x9060
movapd -0x40(%rbp), %xmm2
movapd -0x20(%rbp), %xmm1
movsd 0x4db10(%rip), %xmm0    # 0x12b698
ucomisd %xmm2, %xmm0
jbe 0xddbe1
ucomisd %xmm1, %xmm0
movsd (%rbx), %xmm3
jbe 0xddbac
ucomisd 0x4db88(%rip), %xmm3    # 0x12b728
jbe 0xddbac
movsd 0x4db86(%rip), %xmm0    # 0x12b730
jmp 0xddbc4
ucomisd %xmm3, %xmm0
jbe 0xddbdd
ucomisd 0x4db6e(%rip), %xmm1    # 0x12b728
jbe 0xddbdd
movsd 0x4db74(%rip), %xmm0    # 0x12b738
addsd -0x28(%rbp), %xmm0
movl $0x1, %edi
callq 0xd0c46
movapd -0x20(%rbp), %xmm1
movapd -0x40(%rbp), %xmm2
movsd %xmm1, (%rbx)
cmpb $0x0, (%r14)
je 0xddc10
movsd (%rbx), %xmm0
movsd 0x29cdf5(%rip), %xmm3   # 0x37a9e8
leaq 0x261046(%rip), %rdi    # 0x33ec40
leaq 0x558cb(%rip), %rsi     # 0x1334cc
movb $0x4, %al
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x9060
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq