// File: /workspace/github_cpp_makefile_star2_O1/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 0x14a0f5(%rip), %rbx    # 0x21b398
cmpq $0x0, (%rbx)
jle 0xd1853
movq %rdi, %r14
leaq 0x16d151(%rip), %rax    # 0x23e408
movl $0x1, (%rax)
leaq 0x23cdfc(%rip), %rdi    # 0x30e0c0
leaq 0x50010(%rip), %rsi     # 0x1212db
callq 0x9a4d
testq %rax, %rax
je 0xd12ed
movq %rax, %r15
movl $0x32, %edi
movq %rax, %rsi
callq 0x9480
movq %r15, %rdi
callq 0x9370
leaq 0x14759c(%rip), %rax    # 0x218890
movl (%rax), %eax
movq %rax, -0x38(%rbp)
cmpb $0x70, -0x30(%rbp)
leaq 0x49ae3(%rip), %rax     # 0x11ade8
leaq 0x3d8a7(%rip), %r15     # 0x10ebb3
cmoveq %rax, %r15
movb $0x0, -0x90(%rbp)
leaq 0x14a15e(%rip), %rax    # 0x21b47c
cmpb $0x0, (%rax)
je 0xd134d
leaq 0x14a146(%rip), %rax    # 0x21b470
cmpq $0x0, (%rax)
je 0xd134d
callq 0x115ca
leaq 0x60b75(%rip), %rsi     # 0x131eb1
leaq -0x90(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x14a054(%rip), %r13    # 0x21b3a8
movq (%r13), %rax
movq %rax, -0x68(%rbp)
leaq 0x23c141(%rip), %rax    # 0x30d4a4
movzbl (%rax), %eax
movl %eax, -0x44(%rbp)
leaq 0x149ec4(%rip), %rax    # 0x21b234
movb (%rax), %al
movb %al, -0x2a(%rbp)
leaq 0x23c5f8(%rip), %rax    # 0x30d974
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x16d061(%rip), %rcx    # 0x23e3ea
movb (%rcx), %al
movb %al, -0x29(%rbp)
leaq 0x16d0b3(%rip), %rax    # 0x23e448
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
leaq 0x16cfbf(%rip), %rax    # 0x23e360
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movb $0x0, (%rcx)
leaq 0x16baae(%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 0xd13fb
movq %r12, %rdi
callq 0x9120
movl $0x676f6c2e, (%r12,%rax) # imm = 0x676F6C2E
movb $0x0, 0x4(%r12,%rax)
leaq 0x16ba5e(%rip), %rdi    # 0x23ce60
leaq 0x4cc06(%rip), %rsi     # 0x11e00f
callq 0x9090
movl $0xa, %ebx
testq %rax, %rax
je 0xd1424
leaq 0x16d029(%rip), %r12    # 0x23e448
jmp 0xd14b0
leaq 0x16ba35(%rip), %rdi    # 0x23ce60
leaq 0x5c016(%rip), %rsi     # 0x12d448
callq 0x9090
testq %rax, %rax
leaq 0x16d007(%rip), %r12    # 0x23e448
jne 0xd14b0
leaq 0x16ba16(%rip), %rdi    # 0x23ce60
leaq 0x5bffc(%rip), %rsi     # 0x12d44d
callq 0x9090
movl $0x14, %ebx
testq %rax, %rax
jne 0xd14b0
leaq 0x16b9f9(%rip), %rdi    # 0x23ce60
leaq 0x5bfe4(%rip), %rsi     # 0x12d452
callq 0x9090
testq %rax, %rax
jne 0xd14b0
leaq 0x16b9e1(%rip), %rdi    # 0x23ce60
leaq 0x5bfd1(%rip), %rsi     # 0x12d457
callq 0x9090
movl $0x1e, %ebx
testq %rax, %rax
jne 0xd14b0
leaq 0x16b9c4(%rip), %rdi    # 0x23ce60
leaq 0x5bfb9(%rip), %rsi     # 0x12d45c
callq 0x9090
xorl %ecx, %ecx
testq %rax, %rax
cmovel %ecx, %ebx
movl %ebx, (%r12)
callq 0xed2c
cmpl $0x0, (%r12)
je 0xd14df
leaq 0x16ce99(%rip), %rbx    # 0x23e360
movq $0x0, (%rbx)
leaq 0x16ce83(%rip), %rax    # 0x23e358
movq (%rax), %rdi
callq 0xc327f
jmp 0xd14fc
leaq 0x16ce72(%rip), %rax    # 0x23e358
movq (%rax), %rsi
leaq 0x16b970(%rip), %rdi    # 0x23ce60
callq 0x9a4d
leaq 0x16ce64(%rip), %rbx    # 0x23e360
testq %rax, %rax
je 0xd161b
movq %rax, (%rbx)
movq %rax, -0x50(%rbp)
movq %rax, %rdi
callq 0xc6146
leaq 0x16cef9(%rip), %rax    # 0x23e414
cmpb $0x0, (%rax)
je 0xd1592
leaq 0x16c439(%rip), %rdi    # 0x23d960
leaq 0x609b0(%rip), %rsi     # 0x131ede
leaq 0x16b92b(%rip), %rdx    # 0x23ce60
leaq -0x90(%rbp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x9060
movl $0x1, %edi
callq 0xc3105
leaq 0x16d9e7(%rip), %rax    # 0x23ef3e
cmpb $0x0, (%rax)
jne 0xd1592
leaq 0x23bd95(%rip), %rax    # 0x30d2f8
cmpl $0x0, (%rax)
je 0xd1592
leaq 0x23bb99(%rip), %rax    # 0x30d108
movsd (%rax), %xmm0
leaq 0x16c3e6(%rip), %rdi    # 0x23d960
leaq 0x60982(%rip), %rsi     # 0x131f03
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0xc3105
movq -0x38(%rbp), %rax
leal 0x4(%rax), %r14d
cmpl $0x0, (%r12)
je 0xd15a8
movq $0x0, (%rbx)
leaq 0x16cda9(%rip), %rax    # 0x23e358
movq (%rax), %rax
cmpb $0x61, (%rax)
leaq 0x60954(%rip), %rax     # 0x131f10
leaq 0x6096d(%rip), %rsi     # 0x131f30
cmoveq %rax, %rsi
leaq 0x26ac52(%rip), %r13    # 0x33c220
leaq 0x16b88b(%rip), %r8     # 0x23ce60
leaq -0x90(%rbp), %rdx
movq %r13, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x9060
leaq 0x14729c(%rip), %rax    # 0x21888c
movl (%rax), %esi
movl %r14d, %edi
movl $0xb, %edx
movq %r13, %rcx
callq 0xe7d0
leaq 0x149c2b(%rip), %rax    # 0x21b234
movb $0x1, (%rax)
cmpb $0x70, -0x30(%rbp)
jne 0xd164e
leaq 0x149c4f(%rip), %rax    # 0x21b268
jmp 0xd1655
leaq 0x26abfe(%rip), %rbx    # 0x33c220
leaq 0x6089c(%rip), %rsi     # 0x131ec5
leaq 0x16b830(%rip), %rdx    # 0x23ce60
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
leaq 0x16cd1c(%rip), %rbx    # 0x23e360
callq 0x2326e
jmp 0xd17ce
leaq 0x149cdb(%rip), %rax    # 0x21b330
movq (%rax), %r15
je 0xd166a
leaq 0x149cc7(%rip), %rax    # 0x21b328
cmpq (%rax), %r15
je 0xd1799
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 0xcf072
leaq 0x23c2ba(%rip), %rax    # 0x30d974
orb $0x2, 0x1(%rax)
callq 0xd1865
addq -0x58(%rbp), %rbx
jne 0xd16d3
movl $0xa, %edi
callq 0x1cca5
shrq $0xb, %r14
imulq $0x2710, %r14, %rax     # imm = 0x2710
addq %r12, %rax
jne 0xd171e
leaq -0x1(%r13), %rdx
leaq 0x26ab32(%rip), %rbx    # 0x33c220
movq %rbx, %rdi
leaq 0x60856(%rip), %rsi     # 0x131f4e
xorl %eax, %eax
callq 0x9060
leaq 0x147186(%rip), %rax    # 0x21888c
movl (%rax), %esi
movq -0x38(%rbp), %rdi
movl $0xb, %edx
movq %rbx, %rcx
callq 0xe7d0
callq 0xab5f
cmpb $0x70, -0x30(%rbp)
jne 0xd175f
leaq 0x147159(%rip), %rax    # 0x218884
movslq (%rax), %rax
leaq 0x149c6b(%rip), %rcx    # 0x21b3a0
imulq (%rcx), %rax
leaq 0x149c90(%rip), %rcx    # 0x21b3d0
movslq (%rcx), %rcx
cqto
idivq %rcx
cmpq %rax, %r13
jge 0xd1799
leaq 0x149be4(%rip), %rax    # 0x21b338
movq (%rax), %rax
decq %rax
cmpq %rax, %r13
jge 0xd1799
incq %r15
leaq 0x149bb7(%rip), %rax    # 0x21b320
cmpq (%rax), %r15
movl $0x0, %eax
cmovgeq %rax, %r15
decq %r12
incq %r13
decq -0x58(%rbp)
cmpb $0x70, -0x30(%rbp)
je 0xd1686
leaq 0x149b98(%rip), %rax    # 0x21b328
cmpq (%rax), %r15
jne 0xd1686
leaq 0x16cbc0(%rip), %rbx    # 0x23e360
movq -0x50(%rbp), %r14
movq %r14, (%rbx)
callq 0xd1a21
callq 0xd0eb8
leaq 0x16cc90(%rip), %r12    # 0x23e448
cmpl $0x0, (%r12)
je 0xd17c6
callq 0xc36a4
jmp 0xd17ce
movq %r14, %rdi
callq 0x9370
leaq 0x16cc33(%rip), %r13    # 0x23e408
leaq 0x149bcc(%rip), %rax    # 0x21b3a8
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x16cc00(%rip), %rax    # 0x23e3ea
movb -0x29(%rbp), %cl
movb %cl, (%rax)
leaq 0x23bcae(%rip), %rax    # 0x30d4a4
movl -0x44(%rbp), %ecx
movl %ecx, (%rax)
leaq 0x149a32(%rip), %rax    # 0x21b234
movb -0x2a(%rbp), %cl
movb %cl, (%rax)
movl -0x40(%rbp), %ecx
orl $0x200, %ecx            # imm = 0x200
leaq 0x23c15d(%rip), %rax    # 0x30d974
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, (%r12)
movq -0x60(%rbp), %rax
movq %rax, (%rbx)
leaq 0x16b632(%rip), %rdi    # 0x23ce60
leaq -0x110(%rbp), %rsi
callq 0x9340
callq 0xc1a24
movl $0x0, (%r13)
leaq 0x23c872(%rip), %rdi    # 0x30e0c0
callq 0xa1f6
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq