// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %r15d, %r15d
testq %rdi, %rdi
je 0xcbd04
leaq 0x15cb4f(%rip), %rax    # 0x2283ec
cmpl $0x0, (%rax)
je 0xcbd04
movl %esi, %r14d
movq %rdi, %rbx
xorl %r12d, %r12d
pushq $0x1
popq %r15
cmpl $0x3e7, %r15d           # imm = 0x3E7
je 0xcb8d0
movl %r15d, %edi
callq 0xca5f4
cmpl $0x1, %eax
sbbl $-0x1, %r12d
incl %r15d
jmp 0xcb8b3
leaq 0x22bc99(%rip), %r15    # 0x2f7570
movsd (%r15), %xmm0
leaq 0x22bc95(%rip), %rax    # 0x2f7578
movsd (%rax), %xmm1
callq 0xcb71f
leaq 0x22bdc5(%rip), %r13    # 0x2f76b8
movsd (%r13), %xmm0
ucomisd 0x2776f(%rip), %xmm0    # 0xf3070
jae 0xcb9b0
leaq 0x22bd9a(%rip), %rax    # 0x2f76a8
movl (%rax), %r9d
leaq 0x22bd94(%rip), %rax    # 0x2f76ac
movl (%rax), %r10d
cmpl %r9d, 0x88ef6(%rip)     # 0x154818
jne 0xcba50
leaq 0x22bd81(%rip), %rax    # 0x2f76b0
movl (%rax), %esi
cmpl %r10d, 0x88ee4(%rip)    # 0x15481c
jne 0xcba59
cmpl %esi, 0x88edc(%rip)     # 0x154820
jne 0xcba59
movsd 0x29909e(%rip), %xmm1   # 0x3649f0
ucomisd %xmm0, %xmm1
jne 0xcba59
jp 0xcba59
leaq 0x15cc1f(%rip), %rax    # 0x228588
cmpl $0x0, (%rax)
je 0xcba59
movups 0x51ff2(%rip), %xmm0    # 0x11d96b
leaq 0x25a8a0(%rip), %rsi    # 0x326220
movaps %xmm0, 0x20(%rsi)
movups 0x51fd0(%rip), %xmm0    # 0x11d95b
movaps %xmm0, 0x10(%rsi)
movupd 0x51fb4(%rip), %xmm0    # 0x11d94b
movapd %xmm0, (%rsi)
movw $0x21, 0x30(%rsi)
leaq 0x4bd28(%rip), %rdx     # 0x1176d0
movq %rbx, %rdi
callq 0xb2e38
movsd 0x299040(%rip), %xmm0   # 0x3649f8
pushq $0x1
popq %rdi
callq 0xbfac2
leaq 0x15c9c9(%rip), %rbx    # 0x228390
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xcb9ff
leaq 0x22bcd2(%rip), %rax    # 0x2f76a8
movl (%rax), %edx
leaq 0x22bccd(%rip), %rax    # 0x2f76ac
movl (%rax), %ecx
leaq 0x22bcc8(%rip), %rax    # 0x2f76b0
movl (%rax), %r8d
movsd (%r13), %xmm0
leaq 0x51f85(%rip), %rsi     # 0x11d97d
movb $0x1, %al
callq 0x9560
movsd (%r15), %xmm0
pushq $0x1
popq %rdi
callq 0xbfac2
movq (%rbx), %rdi
xorl %r15d, %r15d
testq %rdi, %rdi
je 0xcbd04
leaq 0x22bc86(%rip), %rax    # 0x2f76a8
movl (%rax), %edx
leaq 0x22bc81(%rip), %rax    # 0x2f76ac
movl (%rax), %ecx
leaq 0x22bc7c(%rip), %rax    # 0x2f76b0
movl (%rax), %r8d
movsd (%r13), %xmm0
leaq 0x51f82(%rip), %rsi     # 0x11d9c6
movb $0x1, %al
callq 0x9560
jmp 0xcbd04
leaq 0x22bc59(%rip), %rax    # 0x2f76b0
movl (%rax), %esi
movl %r9d, 0x88db8(%rip)     # 0x154818
movl %r10d, 0x88db5(%rip)    # 0x15481c
movl %esi, 0x88db3(%rip)     # 0x154820
movsd %xmm0, 0x298f7b(%rip)   # 0x3649f0
leaq 0x22b8d8(%rip), %rax    # 0x2f7354
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b8d8(%rip), %rax    # 0x2f7364
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b8d8(%rip), %rax    # 0x2f7374
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b8d8(%rip), %rax    # 0x2f7384
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b8d8(%rip), %rax    # 0x2f7394
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b8d8(%rip), %rax    # 0x2f73a4
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b874(%rip), %rax    # 0x2f7350
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b874(%rip), %rax    # 0x2f7360
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b878(%rip), %rax    # 0x2f7370
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b87c(%rip), %rax    # 0x2f7380
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b880(%rip), %rax    # 0x2f7390
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b884(%rip), %rax    # 0x2f73a0
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b830(%rip), %rax    # 0x2f7358
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b834(%rip), %rax    # 0x2f7368
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b838(%rip), %rax    # 0x2f7378
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b83c(%rip), %rax    # 0x2f7388
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b840(%rip), %rax    # 0x2f7398
cmpl $0x0, (%rax)
jne 0xcbb69
leaq 0x22b844(%rip), %rax    # 0x2f73a8
cmpl $0x0, (%rax)
je 0xcbb76
leaq 0x15c880(%rip), %rax    # 0x2283f0
movl $0x1, (%rax)
leaq 0x15ca03(%rip), %rax    # 0x228580
movsd (%rax), %xmm1
ucomisd 0x29ef7(%rip), %xmm1    # 0xf5a80
jae 0xcbbf6
xorl %r15d, %r15d
testl %r14d, %r14d
movl $0x0, %r13d
cmovel %r12d, %r13d
leaq 0x22bb02(%rip), %rax    # 0x2f76a4
movl (%rax), %eax
pushq $0x64
popq %rcx
cltd
idivl %ecx
leaq 0x22baeb(%rip), %rax    # 0x2f769c
movl (%rax), %ecx
leaq 0x22bae6(%rip), %rax    # 0x2f76a0
movl (%rax), %r8d
cvtsi2sd %esi, %xmm1
addsd %xmm1, %xmm0
subq $0x8, %rsp
leaq 0x51e67(%rip), %rsi     # 0x11da37
movq %rbx, %rdi
movb $0x1, %al
pushq %r13
pushq $0x0
pushq %r10
callq 0x9560
addq $0x20, %rsp
testl %r14d, %r14d
je 0xcbc49
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x9480
jmp 0xcbc42
leaq 0x22baa7(%rip), %rax    # 0x2f76a4
movl (%rax), %edx
leaq 0x22ba96(%rip), %rax    # 0x2f769c
movl (%rax), %ecx
leaq 0x22ba91(%rip), %rax    # 0x2f76a0
movl (%rax), %r8d
cvtsi2sd %esi, %xmm1
addsd %xmm1, %xmm0
subq $0x8, %rsp
leaq 0x51dea(%rip), %rsi     # 0x11da0f
movq %rbx, %rdi
movb $0x1, %al
pushq %r12
pushq $0x0
pushq %r10
callq 0x9560
addq $0x20, %rsp
testl %r14d, %r14d
je 0xcbd00
pushq $0x2
jmp 0xcbd02
movq %r13, -0x40(%rbp)
movq %rbx, -0x38(%rbp)
pushq $0x1
popq %r14
movl %r14d, %eax
xorl %ebx, %ebx
cmpl $0x3e7, %r14d           # imm = 0x3E7
je 0xcbcef
movl %r15d, -0x2c(%rbp)
movl %eax, %r15d
movl %r14d, %edi
callq 0xca5f4
testl %eax, %eax
je 0xcbcde
movl %eax, %r13d
movl %r14d, %edi
callq 0xca3aa
movq -0x38(%rbp), %rdi
leaq 0x51dcd(%rip), %rsi     # 0x11da5d
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x9560
movl -0x2c(%rbp), %r15d
incl %r15d
incl %ebx
cmpl -0x40(%rbp), %ebx
je 0xcbced
cmpl $0xd, %r12d
setae %al
cmpl $0xc, %r15d
sete %cl
andb %al, %cl
xorl %eax, %eax
cmpb $0x1, %cl
jne 0xcbce5
leaq 0x51d9c(%rip), %rdi     # 0x11da64
pushq $0x21
popq %rsi
pushq $0x1
popq %rdx
movq -0x38(%rbp), %rcx
callq 0x9750
xorl %eax, %eax
xorl %r15d, %r15d
jmp 0xcbce5
movl %r15d, %eax
movl -0x2c(%rbp), %r15d
incl %r14d
jmp 0xcbc5a
xorl %eax, %eax
orl %r15d, %eax
movq -0x38(%rbp), %rsi
je 0xcbd00
pushq $0xa
popq %rdi
callq 0x9480
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq