// File: /workspace/github_cpp_makefile_star2_O1/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 0x16d4a1(%rip), %rax    # 0x23e360
cmpq $0x0, (%rax)
je 0xd1284
leaq 0x16d544(%rip), %rax    # 0x23e414
cmpb $0x0, (%rax)
je 0xd1284
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
leaq 0x14a4ac(%rip), %rbx    # 0x21b3a0
movslq (%rbx), %r14
leaq 0x14a36a(%rip), %r15    # 0x21b268
movslq (%r15), %r12
leaq 0x14a368(%rip), %rax    # 0x21b270
movslq (%rax), %r13
movq $0x1, (%rbx)
leaq 0x14a417(%rip), %rax    # 0x21b330
movq (%rax), %rax
movq %rax, (%r15)
xorl %edi, %edi
callq 0x18f2e
movq %r14, (%rbx)
movq %r12, (%r15)
leaq 0x14a33d(%rip), %rax    # 0x21b270
movq %r13, (%rax)
leaq 0x16ca23(%rip), %rbx    # 0x23d960
movw $0x23, (%rbx)
movl $0x1, %edi
callq 0xc3105
movl $0x1, %edi
callq 0xc3105
movl $0x1, %edi
callq 0xc3105
movupd 0x60f06(%rip), %xmm0    # 0x131e6e
movapd %xmm0, (%rbx)
movl $0x3a7363, 0x10(%rbx)   # imm = 0x3A7363
movl $0x1, %edi
callq 0xc3105
movl $0xd4, %r12d
addq 0x7ef86(%rip), %r12     # 0x14ff10
leaq -0x140(%rbp), %r15
xorl %r14d, %r14d
movl $0x40, (%r12)
movl %r14d, %edi
callq 0x13a37
movapd %xmm0, %xmm1
movapd 0x381d0(%rip), %xmm0    # 0x109180
andpd %xmm0, %xmm1
movapd %xmm1, -0x40(%rbp)
movl $0x4, (%r12)
movl %r14d, %edi
callq 0x13a37
andpd 0x381af(%rip), %xmm0    # 0x109180
addsd -0x40(%rbp), %xmm0
movapd %xmm0, -0x40(%rbp)
movl $0x1, (%r12)
movl %r14d, %edi
callq 0x13a37
andpd 0x3818d(%rip), %xmm0    # 0x109180
addsd -0x40(%rbp), %xmm0
ucomisd 0x38118(%rip), %xmm0    # 0x109118
jne 0xd1008
jnp 0xd1249
leaq 0x16c951(%rip), %rbx    # 0x23d960
movw $0x23, (%rbx)
movl $0x1, %edi
callq 0xc3105
movq -0xd4(%r12), %rdx
movq %rbx, %rdi
leaq 0x60e52(%rip), %rsi     # 0x131e82
xorl %eax, %eax
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movq -0xd4(%r12), %rsi
movq %r15, %rdi
callq 0x9340
movq %r15, %rdi
callq 0x9899
leaq 0x14a382(%rip), %rax    # 0x21b3e2
cmpb $0x0, (%rax)
je 0xd120e
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 0xd1095
movb $0x20, (%rax)
movl $0x1, (%r12)
movl %r14d, %edi
callq 0x13a37
leaq 0x16c8b4(%rip), %rdi    # 0x23d960
leaq 0x60deb(%rip), %r13     # 0x131e9e
movq %r13, %rsi
leaq 0x26e683(%rip), %rdx    # 0x33f740
leaq -0x140(%rbp), %r15
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl $0x2, (%r12)
movl %r14d, %edi
callq 0x13a37
leaq 0x16c871(%rip), %rbx    # 0x23d960
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26e644(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl $0x4, (%r12)
movl %r14d, %edi
callq 0x13a37
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26e613(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl $0x8, (%r12)
movl %r14d, %edi
callq 0x13a37
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26e5e2(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl $0x10, (%r12)
movl %r14d, %edi
callq 0x13a37
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26e5b1(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl $0x20, (%r12)
movl %r14d, %edi
callq 0x13a37
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26e580(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl $0x40, (%r12)
movl %r14d, %edi
callq 0x13a37
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x26e54f(%rip), %rdx    # 0x33f740
movq %r15, %rcx
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movl -0x40(%rbp), %eax
movl %eax, (%r12)
jmp 0xd1249
movl -0x140(%rbp), %eax
cmpl $0x54414c, %eax         # imm = 0x54414C
je 0xd1226
cmpl $0x4e4f4c, %eax         # imm = 0x4E4F4C
jne 0xd1069
movupd 0x60c5e(%rip), %xmm0    # 0x131e8c
leaq 0x16c72b(%rip), %rax    # 0x23d960
movapd %xmm0, (%rax)
movw $0x29, 0x10(%rax)
movl $0x1, %edi
callq 0xc3105
incq %r14
addq $0xe8, %r12
cmpq $0x14, %r14
jne 0xd0f94
leaq 0x16c6fc(%rip), %rax    # 0x23d960
movw $0x23, (%rax)
movl $0x1, %edi
callq 0xc3105
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq