// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: log_stats()
void log_stats()
{
int old_stat;
DATA_SIZE val;
int id;
char units[SLEN+1];
char *s;
int old_interval;
int old_col0;
int old_last_col;

   // write plot queue statistics (of the plot window when the log file was
   // closed) when the log file is closed

   if(log_file == 0) return;
   if(log_comments == 0) return;

if(1) {
   old_interval = view_interval;   // don't downsample the queue data
   old_col0 = plot_q_col0;
   old_last_col = plot_q_last_col;

   view_interval = 1;
   plot_q_col0 = plot_q_out;
   calc_queue_stats(STOP_AT_Q_END);

   view_interval = old_interval;
   plot_q_col0 = old_col0;
   plot_q_last_col = old_last_col;
}

   sprintf(log_text, "#");
   write_log_comment(1);
   write_log_comment(1);
   write_log_comment(1);
   sprintf(log_text,    "#  Plot statistics:");
   write_log_comment(1);

   for(id=0; id<=FIFTEEN; id++) {
      plot[id].show_stat = SHOW_SPAN;
      val = (DATA_SIZE) fabs(get_stat_val(id));
      plot[id].show_stat = SDEV;
      val += (DATA_SIZE) fabs(get_stat_val(id));
      plot[id].show_stat = RMS;
      val += (DATA_SIZE) fabs(get_stat_val(id));
      if(val == 0.0) continue;    // plot has no data

      sprintf(log_text, "#");
      write_log_comment(1);
      sprintf(log_text, "#     %s:", plot[id].plot_id);
      write_log_comment(1);
      strcpy(units, plot[id].plot_id);
      strupr(units);
      if((plot_loc == 0) && (!strcmp(units, "LAT") || !strcmp(units, "LON"))) {
         sprintf(log_text, "#       (private)");
         write_log_comment(1);
         continue;
      }
      
      old_stat = plot[id].show_stat;
      strcpy(units, plot[id].units);
      s = strchr(units, DEGREES);
      if(s) *s = ' ';

      plot[id].show_stat = RMS;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = AVG;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = SDEV;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = VAR;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = SHOW_MIN;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = SHOW_MAX;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = SHOW_SPAN;
      val = get_stat_val(id);
      sprintf(log_text, "#       %s %.9f %s", stat_id, val, units);
      write_log_comment(1);

      plot[id].show_stat = old_stat;
   }

   sprintf(log_text, "#");
   write_log_comment(1);
}

// Assembly:
leaq 0x16ce08(%rip), %rax    # 0x23e360
cmpq $0x0, (%rax)
je 0xd191d
leaq 0x16ceab(%rip), %rax    # 0x23e414
cmpb $0x0, (%rax)
je 0xd191d
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
leaq 0x149e13(%rip), %rbx    # 0x21b3a0
movslq (%rbx), %r14
leaq 0x149cd1(%rip), %r15    # 0x21b268
movslq (%r15), %r12
leaq 0x149ccf(%rip), %rax    # 0x21b270
movslq (%rax), %r13
movq $0x1, (%rbx)
leaq 0x149d7e(%rip), %rax    # 0x21b330
movq (%rax), %rax
movq %rax, (%r15)
xorl %edi, %edi
callq 0x18f42
movq %r14, (%rbx)
movq %r12, (%r15)
leaq 0x149ca4(%rip), %rax    # 0x21b270
movq %r13, (%rax)
leaq 0x16c38a(%rip), %rbx    # 0x23d960
movw $0x23, (%rbx)
movl $0x1, %edi
callq 0xc36e2
movl $0x1, %edi
callq 0xc36e2
movl $0x1, %edi
callq 0xc36e2
movupd 0x6095d(%rip), %xmm0    # 0x131f5e
movapd %xmm0, (%rbx)
movl $0x3a7363, 0x10(%rbx)   # imm = 0x3A7363
movl $0x1, %edi
callq 0xc36e2
movl $0xd4, %r12d
addq 0x7e8ed(%rip), %r12     # 0x14ff10
leaq -0x140(%rbp), %r15
xorl %r14d, %r14d
movl $0x40, (%r12)
movl %r14d, %edi
callq 0x139a8
movapd %xmm0, %xmm1
movapd 0x37b47(%rip), %xmm0    # 0x109190
andpd %xmm0, %xmm1
movapd %xmm1, -0x40(%rbp)
movl $0x4, (%r12)
movl %r14d, %edi
callq 0x139a8
andpd 0x37b26(%rip), %xmm0    # 0x109190
addsd -0x40(%rbp), %xmm0
movapd %xmm0, -0x40(%rbp)
movl $0x1, (%r12)
movl %r14d, %edi
callq 0x139a8
andpd 0x37b04(%rip), %xmm0    # 0x109190
addsd -0x40(%rbp), %xmm0
ucomisd 0x37a7f(%rip), %xmm0    # 0x109118
jne 0xd16a1
jnp 0xd18e2
leaq 0x16c2b8(%rip), %rbx    # 0x23d960
movw $0x23, (%rbx)
movl $0x1, %edi
callq 0xc36e2
movq -0xd4(%r12), %rdx
movq %rbx, %rdi
leaq 0x608a9(%rip), %rsi     # 0x131f72
xorl %eax, %eax
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movq -0xd4(%r12), %rsi
movq %r15, %rdi
callq 0x9340
movq %r15, %rdi
callq 0x9899
leaq 0x149ce9(%rip), %rax    # 0x21b3e2
cmpb $0x0, (%rax)
je 0xd18a7
movl (%r12), %eax
movl %eax, -0x40(%rbp)
movq -0xcc(%r12), %rsi
movq %r15, %rdi
callq 0x9340
movq %r15, %rdi
movl $0x1, %esi
callq 0x9100
testq %rax, %rax
je 0xd172e
movb $0x20, (%rax)
movl $0x1, (%r12)
movl %r14d, %edi
callq 0x139a8
leaq 0x16c21b(%rip), %rdi    # 0x23d960
leaq 0x60842(%rip), %r13     # 0x131f8e
movq %r13, %rsi
leaq 0x26dfea(%rip), %rdx    # 0x33f740
leaq -0x140(%rbp), %r15
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl $0x2, (%r12)
movl %r14d, %edi
callq 0x139a8
leaq 0x16c1d8(%rip), %rbx    # 0x23d960
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26dfab(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl $0x4, (%r12)
movl %r14d, %edi
callq 0x139a8
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26df7a(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl $0x8, (%r12)
movl %r14d, %edi
callq 0x139a8
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26df49(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl $0x10, (%r12)
movl %r14d, %edi
callq 0x139a8
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26df18(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl $0x20, (%r12)
movl %r14d, %edi
callq 0x139a8
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26dee7(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl $0x40, (%r12)
movl %r14d, %edi
callq 0x139a8
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26deb6(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movl -0x40(%rbp), %eax
movl %eax, (%r12)
jmp 0xd18e2
movl -0x140(%rbp), %eax
cmpl $0x54414c, %eax         # imm = 0x54414C
je 0xd18bf
cmpl $0x4e4f4c, %eax         # imm = 0x4E4F4C
jne 0xd1702
movupd 0x606b5(%rip), %xmm0    # 0x131f7c
leaq 0x16c092(%rip), %rax    # 0x23d960
movapd %xmm0, (%rax)
movw $0x29, 0x10(%rax)
movl $0x1, %edi
callq 0xc36e2
incq %r14
addq $0xe8, %r12
cmpq $0x14, %r14
jne 0xd162d
leaq 0x16c063(%rip), %rax    # 0x23d960
movw $0x23, (%rax)
movl $0x1, %edi
callq 0xc36e2
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq