// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: dump_log(char*, unsigned char)
void dump_log(char *name, u08 dump_size)
{
FILE *file;
FILE *lock_file;
char temp_name[128];
long temp_interval;
u08 temp_flags;
u08 temp_pause;
u08 temp_info;
u08 temp_written;
FILE *temp_file;
int temp_fmt;
long i;
long counter;
long val;
int row;
char *s;
char filter[32];

   if(queue_interval <= 0) return;

   doing_log_dump = 1;
   lock_file = topen(lock_name, "w");  // create file tblock to signify dump file is being written
   if(lock_file) {
      fprintf(lock_file, "2");
      fclose(lock_file);
   }

   row = PLOT_TEXT_ROW+4;
   if(dump_size == 'p') s = "plot area";
   else                 s = "queue";

   filter[0] = 0;
   if(filter_log && filter_count) sprintf(filter, "%ld point filtered ", disp_filter_size()); 

   temp_interval = log_interval;
   temp_flags = time_flags;
   temp_pause = pause_data;
   temp_info = have_info;
   temp_written = log_written;
   temp_fmt = log_fmt;
   temp_file = log_file;

   log_written = 0;
   strcpy(temp_name, log_name);

   log_interval = queue_interval;
   strcpy(log_name, name);
   if(!strstr(log_name, ".")) strcat(log_name, ".log");

   if     (strstr(log_name, ".xml")) log_fmt = XML;
   else if(strstr(log_name, ".XML")) log_fmt = XML;
   else if(strstr(log_name, ".gpx")) log_fmt = GPX;
   else if(strstr(log_name, ".GPX")) log_fmt = GPX;
   else if(strstr(log_name, ".kml")) log_fmt = KML;
   else if(strstr(log_name, ".KML")) log_fmt = KML;
//   else if(strstr(log_name, ".obs")) log_fmt = RINEX;  // cannot write RINEX file from queue data
//   else if(strstr(log_name, ".OBS")) log_fmt = RINEX;
   else log_fmt = HEATHER;

   erase_help();
   if(log_fmt != HEATHER) {
      log_file = 0;
      file = open_log_file(log_mode);
   }
   else {
      file = topen(log_name, log_mode);
   }

   if(file == 0) {
      sprintf(out, "Cannot dump log file: %s", log_name);
      edit_error(out);
      goto dump_exit;
   }

   log_file = file;
write_log_header(file, 2);
   if(log_comments) {
      sprintf(log_text, "#TITLE: From log file %s (%s%s data)", log_name, filter, s);
      write_log_comment(1);

      if((luxor == 0) && have_gain) {
         sprintf(log_text, "#OSC_GAIN %f", osc_gain);
         write_log_comment(1);
      }
   }

if(log_fmt != HEATHER) {
   log_file = 0;
}

   if(log_mode[0] == 'a') sprintf(out, "Appending %s%s data to file: %s", filter, s, log_name);
   else                   sprintf(out, "Writing %s%s data to file: %s", filter, s, log_name);
   vidstr(row, PLOT_TEXT_COL, PROMPT_COLOR, out);

   pause_data = 1;
   counter = 0;
   if(dump_size == 'p') {
      i = plot_q_col0;  // dumping the plot area's data
   }
   else {
      i = plot_q_out;   // dumping the full queue
//plot_q_col0 = plot_q_out;

   }
   while((i != plot_q_in) || (dump_size == 'p')) {
      write_q_entry(file, i);
      have_info |= INFO_LOGGED;
      update_pwm();   // if doing pwm temperature control

      ++counter;
      if((counter % LOG_GPS_CHECK) == 0) {   // keep serial data from overruning
         get_pending_gps(10);  //!!!! possible recursion
      }
//    if((counter % 1000L) == 1L) {
      if((counter % LOG_SCREEN_RFSH) == 1L) {
         sprintf(out, "Line %ld", counter-1L);
         vidstr(row+2, PLOT_TEXT_COL, PROMPT_COLOR, out);
         refresh_page();
      }

      if(dump_size == 'p') {
         val = view_interval * (long) PLOT_WIDTH;
         val /= (long) plot_mag;
         if(counter >= val) break;
         if(counter >= (plot_q_count-1)) break;
      }
      if(++i >= plot_q_size) i = 0;
   }

   #ifdef SCI_LOG
      if(sci_file) fclose(sci_file);
      sci_file = 0;
   #endif

   log_file = file;
   #ifdef ADEV_STUFF
      log_adevs();
   #endif

   log_stats();

   if(log_fmt != HEATHER) {
      close_log_file();
   }
   else {
      fclose(file);      // close this log and restore original one
   }

   dump_exit:
   log_interval = temp_interval;
   log_written = temp_written;
   time_flags = temp_flags;
   pause_data = temp_pause;
   have_info = temp_info;
have_info |= INFO_LOGGED;
   log_fmt = temp_fmt;
   log_file = temp_file;
   strcpy(log_name, temp_name);
   show_log_state();

   doing_log_dump = 0;
   path_unlink(lock_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %esi, -0x30(%rbp)
leaq 0x149a5c(%rip), %rbx    # 0x21b398
cmpq $0x0, (%rbx)
jle 0xd1eec
movq %rdi, %r14
leaq 0x16cab8(%rip), %rax    # 0x23e408
movl $0x1, (%rax)
leaq 0x23c763(%rip), %rdi    # 0x30e0c0
leaq 0x4fa57(%rip), %rsi     # 0x1213bb
callq 0x9a47
testq %rax, %rax
je 0xd1986
movq %rax, %r15
movl $0x32, %edi
movq %rax, %rsi
callq 0x9480
movq %r15, %rdi
callq 0x9370
leaq 0x146f03(%rip), %rax    # 0x218890
movl (%rax), %eax
movq %rax, -0x38(%rbp)
cmpb $0x70, -0x30(%rbp)
leaq 0x494de(%rip), %rax     # 0x11ae7c
leaq 0x3d2a2(%rip), %r15     # 0x10ec47
cmoveq %rax, %r15
movb $0x0, -0x90(%rbp)
leaq 0x149ac5(%rip), %rax    # 0x21b47c
cmpb $0x0, (%rax)
je 0xd19e6
leaq 0x149aad(%rip), %rax    # 0x21b470
cmpq $0x0, (%rax)
je 0xd19e6
callq 0x1155b
leaq 0x605cc(%rip), %rsi     # 0x131fa1
leaq -0x90(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x1499bb(%rip), %r13    # 0x21b3a8
movq (%r13), %rax
movq %rax, -0x68(%rbp)
leaq 0x23baa8(%rip), %rax    # 0x30d4a4
movzbl (%rax), %eax
movl %eax, -0x44(%rbp)
leaq 0x14982b(%rip), %rax    # 0x21b234
movb (%rax), %al
movb %al, -0x2a(%rbp)
leaq 0x23bf5f(%rip), %rax    # 0x30d974
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x16c9c8(%rip), %rcx    # 0x23e3ea
movb (%rcx), %al
movb %al, -0x29(%rbp)
leaq 0x16ca1a(%rip), %rax    # 0x23e448
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
leaq 0x16c926(%rip), %rax    # 0x23e360
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movb $0x0, (%rcx)
leaq 0x16b415(%rip), %r12    # 0x23ce60
leaq -0x110(%rbp), %rdi
movq %r12, %rsi
callq 0x9340
movq (%rbx), %rax
movq %rax, (%r13)
movq %r12, %rdi
movq %r14, %rsi
callq 0x9340
movq %r12, %rdi
movl $0x2e, %esi
callq 0x9100
testq %rax, %rax
jne 0xd1a94
movq %r12, %rdi
callq 0x9120
movl $0x676f6c2e, (%r12,%rax) # imm = 0x676F6C2E
movb $0x0, 0x4(%r12,%rax)
leaq 0x16b3c5(%rip), %rdi    # 0x23ce60
leaq 0x4c5f8(%rip), %rsi     # 0x11e09a
callq 0x9090
movl $0xa, %ebx
testq %rax, %rax
je 0xd1abd
leaq 0x16c990(%rip), %r12    # 0x23e448
jmp 0xd1b49
leaq 0x16b39c(%rip), %rdi    # 0x23ce60
leaq 0x5ba6d(%rip), %rsi     # 0x12d538
callq 0x9090
testq %rax, %rax
leaq 0x16c96e(%rip), %r12    # 0x23e448
jne 0xd1b49
leaq 0x16b37d(%rip), %rdi    # 0x23ce60
leaq 0x5ba53(%rip), %rsi     # 0x12d53d
callq 0x9090
movl $0x14, %ebx
testq %rax, %rax
jne 0xd1b49
leaq 0x16b360(%rip), %rdi    # 0x23ce60
leaq 0x5ba3b(%rip), %rsi     # 0x12d542
callq 0x9090
testq %rax, %rax
jne 0xd1b49
leaq 0x16b348(%rip), %rdi    # 0x23ce60
leaq 0x5ba28(%rip), %rsi     # 0x12d547
callq 0x9090
movl $0x1e, %ebx
testq %rax, %rax
jne 0xd1b49
leaq 0x16b32b(%rip), %rdi    # 0x23ce60
leaq 0x5ba10(%rip), %rsi     # 0x12d54c
callq 0x9090
xorl %ecx, %ecx
testq %rax, %rax
cmovel %ecx, %ebx
movl %ebx, (%r12)
callq 0xecb9
cmpl $0x0, (%r12)
je 0xd1b78
leaq 0x16c800(%rip), %rbx    # 0x23e360
movq $0x0, (%rbx)
leaq 0x16c7ea(%rip), %rax    # 0x23e358
movq (%rax), %rdi
callq 0xc385c
jmp 0xd1b95
leaq 0x16c7d9(%rip), %rax    # 0x23e358
movq (%rax), %rsi
leaq 0x16b2d7(%rip), %rdi    # 0x23ce60
callq 0x9a47
leaq 0x16c7cb(%rip), %rbx    # 0x23e360
testq %rax, %rax
je 0xd1cb4
movq %rax, (%rbx)
movq %rax, -0x50(%rbp)
movq %rax, %rdi
callq 0xc678f
leaq 0x16c860(%rip), %rax    # 0x23e414
cmpb $0x0, (%rax)
je 0xd1c2b
leaq 0x16bda0(%rip), %rdi    # 0x23d960
leaq 0x60407(%rip), %rsi     # 0x131fce
leaq 0x16b292(%rip), %rdx    # 0x23ce60
leaq -0x90(%rbp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
leaq 0x16d34e(%rip), %rax    # 0x23ef3e
cmpb $0x0, (%rax)
jne 0xd1c2b
leaq 0x23b6fc(%rip), %rax    # 0x30d2f8
cmpl $0x0, (%rax)
je 0xd1c2b
leaq 0x23b500(%rip), %rax    # 0x30d108
movsd (%rax), %xmm0
leaq 0x16bd4d(%rip), %rdi    # 0x23d960
leaq 0x603d9(%rip), %rsi     # 0x131ff3
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc36e2
movq -0x38(%rbp), %rax
leal 0x4(%rax), %r14d
cmpl $0x0, (%r12)
je 0xd1c41
movq $0x0, (%rbx)
leaq 0x16c710(%rip), %rax    # 0x23e358
movq (%rax), %rax
cmpb $0x61, (%rax)
leaq 0x603ab(%rip), %rax     # 0x132000
leaq 0x603c4(%rip), %rsi     # 0x132020
cmoveq %rax, %rsi
leaq 0x26a5b9(%rip), %r13    # 0x33c220
leaq 0x16b1f2(%rip), %r8     # 0x23ce60
leaq -0x90(%rbp), %rdx
movq %r13, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x9060
leaq 0x146c03(%rip), %rax    # 0x21888c
movl (%rax), %esi
movl %r14d, %edi
movl $0xb, %edx
movq %r13, %rcx
callq 0xe787
leaq 0x149592(%rip), %rax    # 0x21b234
movb $0x1, (%rax)
cmpb $0x70, -0x30(%rbp)
jne 0xd1ce7
leaq 0x1495b6(%rip), %rax    # 0x21b268
jmp 0xd1cee
leaq 0x26a565(%rip), %rbx    # 0x33c220
leaq 0x602f3(%rip), %rsi     # 0x131fb5
leaq 0x16b197(%rip), %rdx    # 0x23ce60
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
leaq 0x16c683(%rip), %rbx    # 0x23e360
callq 0x23027
jmp 0xd1e67
leaq 0x149642(%rip), %rax    # 0x21b330
movq (%rax), %r15
je 0xd1d03
leaq 0x14962e(%rip), %rax    # 0x21b328
cmpq (%rax), %r15
je 0xd1e32
movq -0x38(%rbp), %rax
addl $0x6, %eax
movq %rax, -0x38(%rbp)
movl $0x1, %r13d
movq $-0x1, -0x58(%rbp)
xorl %r12d, %r12d
movq %r13, %rax
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
mulq %rcx
movq %rdx, %r14
movq %rdx, %rax
shrq $0xa, %rax
imulq $0x1388, %rax, %rbx     # imm = 0x1388
movq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xcf706
leaq 0x23bc21(%rip), %rax    # 0x30d974
orb $0x2, 0x1(%rax)
callq 0xd1efe
addq -0x58(%rbp), %rbx
jne 0xd1d6c
movl $0xa, %edi
callq 0x1cce4
shrq $0xb, %r14
imulq $0x2710, %r14, %rax     # imm = 0x2710
addq %r12, %rax
jne 0xd1db7
leaq -0x1(%r13), %rdx
leaq 0x26a499(%rip), %rbx    # 0x33c220
movq %rbx, %rdi
leaq 0x602ad(%rip), %rsi     # 0x13203e
xorl %eax, %eax
callq 0x9060
leaq 0x146aed(%rip), %rax    # 0x21888c
movl (%rax), %esi
movq -0x38(%rbp), %rdi
movl $0xb, %edx
movq %rbx, %rcx
callq 0xe787
callq 0xab54
cmpb $0x70, -0x30(%rbp)
jne 0xd1df8
leaq 0x146ac0(%rip), %rax    # 0x218884
movslq (%rax), %rax
leaq 0x1495d2(%rip), %rcx    # 0x21b3a0
imulq (%rcx), %rax
leaq 0x1495f7(%rip), %rcx    # 0x21b3d0
movslq (%rcx), %rcx
cqto
idivq %rcx
cmpq %rax, %r13
jge 0xd1e32
leaq 0x14954b(%rip), %rax    # 0x21b338
movq (%rax), %rax
decq %rax
cmpq %rax, %r13
jge 0xd1e32
incq %r15
leaq 0x14951e(%rip), %rax    # 0x21b320
cmpq (%rax), %r15
movl $0x0, %eax
cmovgeq %rax, %r15
decq %r12
incq %r13
decq -0x58(%rbp)
cmpb $0x70, -0x30(%rbp)
je 0xd1d1f
leaq 0x1494ff(%rip), %rax    # 0x21b328
cmpq (%rax), %r15
jne 0xd1d1f
leaq 0x16c527(%rip), %rbx    # 0x23e360
movq -0x50(%rbp), %r14
movq %r14, (%rbx)
callq 0xd20d6
callq 0xd1551
leaq 0x16c5f7(%rip), %r12    # 0x23e448
cmpl $0x0, (%r12)
je 0xd1e5f
callq 0xc3cd4
jmp 0xd1e67
movq %r14, %rdi
callq 0x9370
leaq 0x16c59a(%rip), %r13    # 0x23e408
leaq 0x149533(%rip), %rax    # 0x21b3a8
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x16c567(%rip), %rax    # 0x23e3ea
movb -0x29(%rbp), %cl
movb %cl, (%rax)
leaq 0x23b615(%rip), %rax    # 0x30d4a4
movl -0x44(%rbp), %ecx
movl %ecx, (%rax)
leaq 0x149399(%rip), %rax    # 0x21b234
movb -0x2a(%rbp), %cl
movb %cl, (%rax)
movl -0x40(%rbp), %ecx
orl $0x200, %ecx            # imm = 0x200
leaq 0x23bac4(%rip), %rax    # 0x30d974
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, (%r12)
movq -0x60(%rbp), %rax
movq %rax, (%rbx)
leaq 0x16af99(%rip), %rdi    # 0x23ce60
leaq -0x110(%rbp), %rsi
callq 0x9340
callq 0xc1ff4
movl $0x0, (%r13)
leaq 0x23c1d9(%rip), %rdi    # 0x30e0c0
callq 0xa1e1
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq