// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: write_rinex_obs_header(_IO_FILE*, int)
int write_rinex_obs_header(FILE *file, int no_obs_output)
{
int i;
int no_obs;
int prn;
int p;
char gnss;
int frac;
int col_count;
int out_count;
static int last_hr = (-1);
static int last_min = (-1);
static int last_sec = (-1);
static double last_frac;
static int last_year = 0, last_month = 0,last_day = (-1);
static int last_hours = 0, last_minutes = 0 ,last_seconds = 0;

   // write observation data header for tracked sats
//NEW_RCVR

   if(file == 0) return 0;
   if(rinex_header_written == 0) return 0;

   i = 0;
   for(prn=1; prn<MAX_PRN; prn++) {  // count number of tracked sats
      if(good_raw(prn) == 0) continue;
      ++i;
   }
// if(i == 0) return 0;

   get_obs_time(jd_obs, obs_tow);

   if(g_frac >= 1.0) {
      goto jd_fault;
   }
   frac = (int) (g_frac * 1.0E7);

   if(last_hr != g_hours) ;
   else if(last_min != g_minutes) ;
   else if(last_sec != g_seconds) ;
   else if(last_frac != g_frac) ;
   else if(rinex_fix) {
      sprintf(out, "#! skipped duplicate RINEX observation timestamp!");
      write_rinex_line(file, out, "COMMENT");

      jd_fault:
      gregorian(1, last_jd_obs);
      if(debug_file) fprintf(debug_file, "#! skipped duplicate RINEX observation:  last: %02d:%02d:%02d g_frac:%f\n", g_hours,g_minutes,g_seconds, g_frac);
      gregorian(1, jd_obs);
      if(debug_file) fprintf(debug_file, "                                         this: %02d:%02d:%02d g_frac:%f\n", g_hours,g_minutes,g_seconds, g_frac);
      return 0;
   }

   last_hr = g_hours;     // another duplicate data block prevention check
   last_min = g_minutes;
   last_sec = g_seconds;
   last_frac = g_frac;


#define GOOD_LLI ' '  // '4'
#define BAD_LLI  '1'  // '5'
#define P_MODE   '4'  // tracking P code

   if(have_l1_phase || have_l2_phase || have_l5_phase || have_l6_phase || have_l7_phase || have_l8_phase || 
      have_l1_doppler || have_l2_doppler || have_l5_doppler || have_l6_doppler || have_l7_doppler || have_l8_doppler ||
      have_l1_range || have_l2_range || have_l5_range || have_l6_range || have_l7_range || have_l8_range) {  // dual freq observations
      rinex_obs_written = 1;  // OPUS does not like comments within observation records
   }

   if(rinex_fmt >= 3.0) { // observation header
      fprintf(file, "> %04d %02d %02d %02d %02d%11.7f%3d%3d\n", g_year,g_month,g_day, g_hours,g_minutes,(double)g_seconds+g_frac, 0, i);
      if(no_obs_output) return 2;
      no_obs = 0;
   }
   else {
      if(no_obs_output) i = 0;
      fprintf(file,  " %02d %02d %02d %02d %02d%11.7f%3d%3d", g_year%100,g_month,g_day, g_hours,g_minutes,(double)g_seconds+g_frac, 0, i);
      if(no_obs_output) {
         fprintf(file, "\n");
         return 2;
      }

      no_obs = 1;
      col_count = 0;
      out_count = 0;
      for(prn=1; prn<MAX_PRN; prn++) {  // output list of sats in the observation
         gnss = good_raw(prn);
         if(gnss == 0) continue;
         no_obs = 0;

         p = rinex_prn(prn);  // convert receiver PRN number to RINEX prn value

         fprintf(file, "%c%02d", gnss, p);
         ++col_count;
         ++out_count;
         if(out_count == i) break;
         if((i > 12) && (col_count == 12)) {  // we need a continuation line
            fprintf(file, "\n                                ");
            col_count = 0;
         }
      }
      if(col_count || no_obs) fprintf(file, "\n");
   }

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x12f522
movl $0x0, -0x4(%rbp)
jmp 0x12faa9
leaq 0x16e0a3(%rip), %rax    # 0x29d5cc
cmpl $0x0, (%rax)
jne 0x12f53a
movl $0x0, -0x4(%rbp)
jmp 0x12faa9
movl $0x0, -0x18(%rbp)
movl $0x1, -0x20(%rbp)
cmpl $0x3e7, -0x20(%rbp)     # imm = 0x3E7
jge 0x12f574
movl -0x20(%rbp), %edi
callq 0x12d520
cmpl $0x0, %eax
jne 0x12f560
jmp 0x12f569
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x12f548
leaq 0x23d1d5(%rip), %rax    # 0x36c750
movsd (%rax), %xmm0
leaq 0x23d1d2(%rip), %rax    # 0x36c758
movsd (%rax), %xmm1
callq 0x12f2d0
leaq 0x23d302(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
movsd 0x3fac6(%rip), %xmm1    # 0x16f068
ucomisd %xmm1, %xmm0
jb 0x12f5ad
jmp 0x12f663
movsd 0x3fbfb(%rip), %xmm0    # 0x16f1b0
leaq 0x23d2dc(%rip), %rax    # 0x36c898
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movl 0x9a24b(%rip), %eax     # 0x1c9818
leaq 0x23d2b4(%rip), %rcx    # 0x36c888
cmpl (%rcx), %eax
je 0x12f5dd
jmp 0x12f736
movl 0x9a239(%rip), %eax     # 0x1c981c
leaq 0x23d2a2(%rip), %rcx    # 0x36c88c
cmpl (%rcx), %eax
je 0x12f5f3
jmp 0x12f734
movl 0x9a227(%rip), %eax     # 0x1c9820
leaq 0x23d290(%rip), %rcx    # 0x36c890
cmpl (%rcx), %eax
je 0x12f609
jmp 0x12f732
movsd 0x2aa62f(%rip), %xmm0   # 0x3d9c40
leaq 0x23d280(%rip), %rax    # 0x36c898
ucomisd (%rax), %xmm0
jne 0x12f622
jp 0x12f622
jmp 0x12f627
jmp 0x12f730
leaq 0x16e13a(%rip), %rax    # 0x29d768
cmpl $0x0, (%rax)
je 0x12f72e
leaq 0x26bdc2(%rip), %rdi    # 0x39b400
leaq 0x66f4e(%rip), %rsi     # 0x196593
movb $0x0, %al
callq 0x9060
movq -0x10(%rbp), %rdi
leaq 0x26bda9(%rip), %rsi    # 0x39b400
leaq 0x60c4e(%rip), %rdx     # 0x1902ac
callq 0x10d750
movsd 0x2aa5f5(%rip), %xmm0   # 0x3d9c60
movl $0x1, %edi
callq 0x11dd00
leaq 0x16def4(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x12f6c1
leaq 0x16dee7(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x23d1f5(%rip), %rax    # 0x36c888
movl (%rax), %edx
leaq 0x23d1f0(%rip), %rax    # 0x36c88c
movl (%rax), %ecx
leaq 0x23d1eb(%rip), %rax    # 0x36c890
movl (%rax), %r8d
leaq 0x23d1e9(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
leaq 0x66f0b(%rip), %rsi     # 0x1965c5
movb $0x1, %al
callq 0x9550
leaq 0x23d088(%rip), %rax    # 0x36c750
movsd (%rax), %xmm0
movl $0x1, %edi
callq 0x11dd00
leaq 0x16de93(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x12f722
leaq 0x16de86(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x23d194(%rip), %rax    # 0x36c888
movl (%rax), %edx
leaq 0x23d18f(%rip), %rax    # 0x36c88c
movl (%rax), %ecx
leaq 0x23d18a(%rip), %rax    # 0x36c890
movl (%rax), %r8d
leaq 0x23d188(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
leaq 0x66ef3(%rip), %rsi     # 0x19660e
movb $0x1, %al
callq 0x9550
movl $0x0, -0x4(%rbp)
jmp 0x12faa9
jmp 0x12f730
jmp 0x12f732
jmp 0x12f734
jmp 0x12f736
leaq 0x23d14b(%rip), %rax    # 0x36c888
movl (%rax), %eax
movl %eax, 0x9a0d3(%rip)     # 0x1c9818
leaq 0x23d140(%rip), %rax    # 0x36c88c
movl (%rax), %eax
movl %eax, 0x9a0c8(%rip)     # 0x1c981c
leaq 0x23d135(%rip), %rax    # 0x36c890
movl (%rax), %eax
movl %eax, 0x9a0bd(%rip)     # 0x1c9820
leaq 0x23d12e(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
movsd %xmm0, 0x2aa4ca(%rip)   # 0x3d9c40
leaq 0x23cdb7(%rip), %rax    # 0x36c534
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cdb7(%rip), %rax    # 0x36c544
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cdb7(%rip), %rax    # 0x36c554
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cdb7(%rip), %rax    # 0x36c564
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cdb7(%rip), %rax    # 0x36c574
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cdb7(%rip), %rax    # 0x36c584
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd53(%rip), %rax    # 0x36c530
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd53(%rip), %rax    # 0x36c540
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd57(%rip), %rax    # 0x36c550
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd5b(%rip), %rax    # 0x36c560
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd5f(%rip), %rax    # 0x36c570
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd63(%rip), %rax    # 0x36c580
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd0f(%rip), %rax    # 0x36c538
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd13(%rip), %rax    # 0x36c548
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd17(%rip), %rax    # 0x36c558
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd1b(%rip), %rax    # 0x36c568
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd1f(%rip), %rax    # 0x36c578
cmpl $0x0, (%rax)
jne 0x12f86a
leaq 0x23cd23(%rip), %rax    # 0x36c588
cmpl $0x0, (%rax)
je 0x12f877
leaq 0x16dd5f(%rip), %rax    # 0x29d5d0
movl $0x1, (%rax)
leaq 0x16dee2(%rip), %rax    # 0x29d760
movsd (%rax), %xmm0
movsd 0x3f956(%rip), %xmm1    # 0x16f1e0
ucomisd %xmm1, %xmm0
jb 0x12f920
movq -0x10(%rbp), %rdi
leaq 0x23cfe5(%rip), %rax    # 0x36c884
movl (%rax), %edx
leaq 0x23cfd4(%rip), %rax    # 0x36c87c
movl (%rax), %ecx
leaq 0x23cfcf(%rip), %rax    # 0x36c880
movl (%rax), %r8d
leaq 0x23cfcd(%rip), %rax    # 0x36c888
movl (%rax), %r9d
leaq 0x23cfc7(%rip), %rax    # 0x36c88c
movl (%rax), %r10d
leaq 0x23cfc1(%rip), %rax    # 0x36c890
cvtsi2sdl (%rax), %xmm0
leaq 0x23cfbe(%rip), %rax    # 0x36c898
addsd (%rax), %xmm0
movl -0x18(%rbp), %eax
leaq 0x66d6f(%rip), %rsi     # 0x196657
xorl %r11d, %r11d
movl %r10d, (%rsp)
movl $0x0, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x1, %al
callq 0x9550
cmpl $0x0, -0x14(%rbp)
je 0x12f914
movl $0x2, -0x4(%rbp)
jmp 0x12faa9
movl $0x0, -0x1c(%rbp)
jmp 0x12faa2
cmpl $0x0, -0x14(%rbp)
je 0x12f92d
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x23cf4c(%rip), %rax    # 0x36c884
movl (%rax), %eax
movl $0x64, %ecx
cltd
idivl %ecx
leaq 0x23cf33(%rip), %rax    # 0x36c87c
movl (%rax), %ecx
leaq 0x23cf2e(%rip), %rax    # 0x36c880
movl (%rax), %r8d
leaq 0x23cf2c(%rip), %rax    # 0x36c888
movl (%rax), %r9d
leaq 0x23cf26(%rip), %rax    # 0x36c88c
movl (%rax), %r10d
leaq 0x23cf20(%rip), %rax    # 0x36c890
cvtsi2sdl (%rax), %xmm0
leaq 0x23cf1d(%rip), %rax    # 0x36c898
addsd (%rax), %xmm0
movl -0x18(%rbp), %eax
leaq 0x66cf6(%rip), %rsi     # 0x19667f
xorl %r11d, %r11d
movl %r10d, (%rsp)
movl $0x0, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x1, %al
callq 0x9550
cmpl $0x0, -0x14(%rbp)
je 0x12f9c7
movq -0x10(%rbp), %rdi
leaq 0x68c72(%rip), %rsi     # 0x198626
movb $0x0, %al
callq 0x9550
movl $0x2, -0x4(%rbp)
jmp 0x12faa9
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x1, -0x20(%rbp)
cmpl $0x3e7, -0x20(%rbp)     # imm = 0x3E7
jge 0x12fa82
movl -0x20(%rbp), %edi
callq 0x12d520
movb %al, -0x25(%rbp)
movsbl -0x25(%rbp), %eax
cmpl $0x0, %eax
jne 0x12fa06
jmp 0x12fa74
movl $0x0, -0x1c(%rbp)
movl -0x20(%rbp), %edi
callq 0x12d020
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movsbl -0x25(%rbp), %edx
movl -0x24(%rbp), %ecx
leaq 0x66c7b(%rip), %rsi     # 0x1966a5
movb $0x0, %al
callq 0x9550
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x12fa4d
jmp 0x12fa82
cmpl $0xc, -0x18(%rbp)
jle 0x12fa72
cmpl $0xc, -0x30(%rbp)
jne 0x12fa72
movq -0x10(%rbp), %rdi
leaq 0x66c48(%rip), %rsi     # 0x1966ac
movb $0x0, %al
callq 0x9550
movl $0x0, -0x30(%rbp)
jmp 0x12fa74
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x12f9e3
cmpl $0x0, -0x30(%rbp)
jne 0x12fa8e
cmpl $0x0, -0x1c(%rbp)
je 0x12faa0
movq -0x10(%rbp), %rdi
leaq 0x68b8d(%rip), %rsi     # 0x198626
movb $0x0, %al
callq 0x9550
jmp 0x12faa2
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)