// File: /workspace/github_cpp_makefile_star2_O2/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 $0xd8, %rsp
movl %esi, -0x30(%rbp)
leaq 0x14529a(%rip), %r12    # 0x205398
cmpq $0x0, (%r12)
jle 0xc066b
movq %rdi, %r14
leaq 0x1682f5(%rip), %rax    # 0x228408
movl $0x1, (%rax)
leaq 0x237fa0(%rip), %rdi    # 0x2f80c0
leaq 0x4b1dc(%rip), %rsi     # 0x10b303
callq 0x9a22
testq %rax, %rax
je 0xc0147
movq %rax, %rbx
pushq $0x32
popq %rdi
movq %rax, %rsi
callq 0x9480
movq %rbx, %rdi
callq 0x9360
leaq 0x142742(%rip), %rax    # 0x202890
movl (%rax), %eax
movq %rax, -0x38(%rbp)
cmpb $0x70, -0x30(%rbp)
leaq 0x44d9d(%rip), %rax     # 0x104efc
leaq 0x38b61(%rip), %r15     # 0xf8cc7
cmoveq %rax, %r15
movb $0x0, -0x80(%rbp)
leaq 0x145307(%rip), %rax    # 0x20547c
cmpb $0x0, (%rax)
je 0xc01a1
leaq 0x1452ef(%rip), %rax    # 0x205470
cmpq $0x0, (%rax)
je 0xc01a1
callq 0x10e43
leaq 0x5bd2e(%rip), %rsi     # 0x11bec1
leaq -0x80(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x145200(%rip), %r13    # 0x2053a8
movq (%r13), %rax
movq %rax, -0x60(%rbp)
leaq 0x2372ed(%rip), %rax    # 0x2f74a4
movzbl (%rax), %eax
movl %eax, -0x44(%rbp)
leaq 0x145070(%rip), %rax    # 0x205234
movb (%rax), %al
movb %al, -0x2a(%rbp)
leaq 0x2377a4(%rip), %rax    # 0x2f7974
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x16820d(%rip), %rcx    # 0x2283ea
movb (%rcx), %al
movb %al, -0x29(%rbp)
leaq 0x16825f(%rip), %rax    # 0x228448
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
leaq 0x16816b(%rip), %rax    # 0x228360
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movb $0x0, (%rcx)
leaq 0x166c5a(%rip), %rbx    # 0x226e60
leaq -0x100(%rbp), %rdi
movq %rbx, %rsi
callq 0x9330
movq (%r12), %rax
movq %rax, (%r13)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9330
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0x9100
testq %rax, %rax
jne 0xc024c
movq %rbx, %rdi
callq 0x9120
movl $0x676f6c2e, (%rbx,%rax) # imm = 0x676F6C2E
movb $0x0, 0x4(%rbx,%rax)
leaq 0x166c0d(%rip), %rdi    # 0x226e60
leaq 0x47ebb(%rip), %rsi     # 0x108115
callq 0x9090
pushq $0xa
popq %rbx
testq %rax, %rax
je 0xc0273
leaq 0x1681da(%rip), %r14    # 0x228448
jmp 0xc0300
leaq 0x166be6(%rip), %rdi    # 0x226e60
leaq 0x571d7(%rip), %rsi     # 0x117458
callq 0x9090
testq %rax, %rax
leaq 0x1681b8(%rip), %r14    # 0x228448
jne 0xc0300
leaq 0x166bc7(%rip), %rdi    # 0x226e60
leaq 0x571bd(%rip), %rsi     # 0x11745d
callq 0x9090
pushq $0x14
popq %rbx
testq %rax, %rax
jne 0xc0300
leaq 0x166bac(%rip), %rdi    # 0x226e60
leaq 0x571a7(%rip), %rsi     # 0x117462
callq 0x9090
testq %rax, %rax
jne 0xc0300
leaq 0x166b94(%rip), %rdi    # 0x226e60
leaq 0x57194(%rip), %rsi     # 0x117467
callq 0x9090
testq %rax, %rax
je 0xc02e2
pushq $0x1e
popq %rbx
jmp 0xc0300
leaq 0x166b77(%rip), %rdi    # 0x226e60
leaq 0x5717c(%rip), %rsi     # 0x11746c
callq 0x9090
xorl %ecx, %ecx
testq %rax, %rax
pushq $0x1e
popq %rbx
cmovel %ecx, %ebx
movl %ebx, (%r14)
callq 0xe7aa
cmpl $0x0, (%r14)
je 0xc032a
leaq 0x16804b(%rip), %rax    # 0x228360
andq $0x0, (%rax)
leaq 0x168038(%rip), %rax    # 0x228358
movq (%rax), %rdi
callq 0xb2773
jmp 0xc0340
leaq 0x168027(%rip), %rax    # 0x228358
movq (%rax), %rsi
leaq 0x166b25(%rip), %rdi    # 0x226e60
callq 0x9a22
movq %rax, %rdi
testq %rax, %rax
je 0xc045e
leaq 0x16800d(%rip), %rax    # 0x228360
movq %rdi, (%rax)
movq %rdi, -0x50(%rbp)
callq 0xb5513
leaq 0x1680ae(%rip), %rax    # 0x228414
cmpb $0x0, (%rax)
je 0xc03d6
leaq 0x1675ee(%rip), %rdi    # 0x227960
leaq 0x5bb75(%rip), %rsi     # 0x11beee
leaq 0x166ae0(%rip), %rdx    # 0x226e60
leaq -0x80(%rbp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x9060
pushq $0x1
popq %rdi
callq 0xb25f5
leaq 0x168ba1(%rip), %rax    # 0x228f3e
cmpb $0x0, (%rax)
jne 0xc03d6
leaq 0x236f4f(%rip), %rax    # 0x2f72f8
cmpl $0x0, (%rax)
je 0xc03d6
leaq 0x236d53(%rip), %rax    # 0x2f7108
movsd (%rax), %xmm0
leaq 0x1675a0(%rip), %rdi    # 0x227960
leaq 0x5bb4c(%rip), %rsi     # 0x11bf13
movb $0x1, %al
callq 0x9060
pushq $0x1
popq %rdi
callq 0xb25f5
movq -0x38(%rbp), %rax
leal 0x4(%rax), %ebx
cmpl $0x0, (%r14)
je 0xc03ee
leaq 0x167f76(%rip), %rax    # 0x228360
andq $0x0, (%rax)
leaq 0x167f63(%rip), %rax    # 0x228358
movq (%rax), %rax
cmpb $0x61, (%rax)
leaq 0x5bb1e(%rip), %rax     # 0x11bf20
leaq 0x5bb37(%rip), %rsi     # 0x11bf40
cmoveq %rax, %rsi
leaq 0x265e0c(%rip), %r14    # 0x326220
leaq 0x166a45(%rip), %r8     # 0x226e60
xorl %r13d, %r13d
leaq -0x80(%rbp), %rdx
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x9060
leaq 0x142456(%rip), %rax    # 0x20288c
movl (%rax), %esi
pushq $0xb
popq %rdx
movl %ebx, %edi
movq %r14, %rcx
callq 0xe2d2
leaq 0x144de8(%rip), %rax    # 0x205234
movb $0x1, (%rax)
cmpb $0x70, -0x30(%rbp)
jne 0xc048a
leaq 0x144e0c(%rip), %rax    # 0x205268
jmp 0xc0491
leaq 0x265dbb(%rip), %rbx    # 0x326220
leaq 0x5ba69(%rip), %rsi     # 0x11bed5
leaq 0x1669ed(%rip), %rdx    # 0x226e60
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x214df
jmp 0xc05e3
leaq 0x144e9f(%rip), %rax    # 0x205330
movq (%rax), %r15
movq -0x38(%rbp), %rax
addl $0x6, %eax
movq %rax, -0x38(%rbp)
pushq $0x1
popq %r14
movq %r14, %rax
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
divq %rcx
movq %rax, %rbx
movq %r14, %rax
xorl %edx, %edx
movl $0x1388, %ecx           # imm = 0x1388
divq %rcx
cmpb $0x70, -0x30(%rbp)
je 0xc04d6
leaq 0x144e5b(%rip), %rcx    # 0x205328
cmpq (%rcx), %r15
je 0xc05af
imulq $0x1388, %rax, %r12     # imm = 0x1388
decq %r12
movq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xbdef2
leaq 0x237481(%rip), %rax    # 0x2f7974
orb $0x2, 0x1(%rax)
callq 0xc067d
cmpq %r13, %r12
jne 0xc0509
pushq $0xa
popq %rdi
callq 0x1bdb5
imulq $0x2710, %rbx, %rax     # imm = 0x2710
cmpq %r13, %rax
jne 0xc054d
leaq 0x265d04(%rip), %rbx    # 0x326220
movq %rbx, %rdi
leaq 0x5ba38(%rip), %rsi     # 0x11bf5e
movq %r13, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x142355(%rip), %rax    # 0x20288c
movl (%rax), %esi
movq -0x38(%rbp), %rdi
pushq $0xb
popq %rdx
movq %rbx, %rcx
callq 0xe2d2
callq 0xaa05
incq %r13
cmpb $0x70, -0x30(%rbp)
jne 0xc0591
leaq 0x142327(%rip), %rax    # 0x202884
movslq (%rax), %rax
leaq 0x144e39(%rip), %rcx    # 0x2053a0
imulq (%rcx), %rax
leaq 0x144e5e(%rip), %rcx    # 0x2053d0
movslq (%rcx), %rcx
cqto
idivq %rcx
cmpq %rax, %r13
jge 0xc05af
leaq 0x144db2(%rip), %rax    # 0x205338
movq (%rax), %rax
decq %rax
cmpq %rax, %r13
jge 0xc05af
incq %r15
leaq 0x144d85(%rip), %rax    # 0x205320
cmpq (%rax), %r15
movl $0x0, %eax
cmovgeq %rax, %r15
incq %r14
jmp 0xc04a3
leaq 0x167daa(%rip), %rax    # 0x228360
movq -0x50(%rbp), %rbx
movq %rbx, (%rax)
callq 0xc0849
callq 0xbfd20
leaq 0x167e7a(%rip), %r14    # 0x228448
cmpl $0x0, (%r14)
je 0xc05db
callq 0xb2b9e
jmp 0xc05e3
movq %rbx, %rdi
callq 0x9360
leaq 0x167e1e(%rip), %r13    # 0x228408
leaq 0x144db7(%rip), %rax    # 0x2053a8
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x167deb(%rip), %rax    # 0x2283ea
movb -0x29(%rbp), %cl
movb %cl, (%rax)
leaq 0x236e99(%rip), %rax    # 0x2f74a4
movl -0x44(%rbp), %ecx
movl %ecx, (%rax)
leaq 0x144c1d(%rip), %rax    # 0x205234
movb -0x2a(%rbp), %cl
movb %cl, (%rax)
movl -0x40(%rbp), %ecx
orl $0x200, %ecx            # imm = 0x200
leaq 0x237348(%rip), %rax    # 0x2f7974
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, (%r14)
leaq 0x167d25(%rip), %rax    # 0x228360
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x166817(%rip), %rdi    # 0x226e60
leaq -0x100(%rbp), %rsi
callq 0x9330
callq 0xb1018
andl $0x0, (%r13)
leaq 0x237a5a(%rip), %rdi    # 0x2f80c0
callq 0xa15d
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq