// File: jkingan[P]ladyheather/heather.cpp
// Function: deglitch_plot_queue(int, double)
void deglitch_plot_queue(int pid, DATA_SIZE sigma)
{
long i;
long count;
long dg_count;
long pcount;
int id, start, end;
int col;
struct PLOT_Q q0, q;
DATA_SIZE sdev, avg;
DATA_SIZE val;

   // replace all queue points that are more than 3 standard deviations away
   // from the average value.  If pid < 0 all plots are deglitched, otherwise
   // only the specified plot is deglitched.


   if(queue_interval == 0) return;
   if(stat_count == 0) return;
   if(pid > (NUM_PLOTS+DERIVED_PLOTS)) return;

   if(pid < 0) {  // do all plots
      start = 0;
      end = (NUM_PLOTS+DERIVED_PLOTS-1);
if(debug_file) {
   fprintf(debug_file, "deglitch all plots: sigma:%g\n", sigma);
}
   }
   else {  // do single specified plot
      start = end = pid;
if(debug_file) {
   fprintf(debug_file, "deglitch plot %s: sigma:%g\n", plot[pid].plot_id,sigma);
}
   }

   count = 0;
   dg_count = 0;
   col = 0;
   i = plot_q_col0;   // deglitch displayed points
   pcount = plot_q_size;
////i = 0;            // deglitch all queue points
   while(pcount) {  // scan the data that is in the plot queue
      --pcount;
      if(i > 0) q0 = get_plot_q(i-1); // previous point
      else      q0 = get_plot_q(i);
      q = get_plot_q(i);              // point to deglitch

      for(id=start; id<=end; id++) {  // deglitch each plots' entries
         if(rcvr_type == CS_RCVR) ;        // don't deglitch message offset/jitter data
         else if(rcvr_type == TICC_RCVR) ;
         else if(id == NINE) continue;
         else if(id == TEN) continue;

         sdev = ((plot[id].sum_yy/stat_count) - ((plot[id].sum_y/stat_count)*(plot[id].sum_y/stat_count)) );
         if(sdev < (DATA_SIZE) 0.0) sdev = (DATA_SIZE) 0.0 - sdev;
         sdev = (DATA_SIZE) sqrt(sdev);

         avg = (DATA_SIZE) (plot[id].sum_y/stat_count);

         val = (DATA_SIZE) q.data[id]/(DATA_SIZE) queue_interval;

         if(val < (avg - (sdev*sigma))) {
            q.data[id] = q0.data[id];
            ++dg_count;
//sprintf(debug_text, "deglitch < %s:  #%ld  queue %ld   sdev:%g  val:%g  avg:%g", plot[id].plot_id, dg_count, i, sdev, val, avg);
if(debug_file) fprintf(debug_file, "deglitch < %s:  #%ld   queue %ld   sdev:%g  val:%g  avg:%g\n", plot[id].plot_id, dg_count, i, sdev, val, avg);
            put_plot_q(i, q);

         }
         else if(val > (avg + (sdev*sigma))) {
            q.data[id] = q0.data[id];
            ++dg_count;
//sprintf(debug_text, "deglitch > %s:  #%ld  queue %ld   sdev:%g  val:%g  avg:%g", plot[id].plot_id, dg_count, i, sdev, val, avg);
if(debug_file) fprintf(debug_file, "deglitch > %s:  #%ld   queue %ld   sdev:%g  val:%g  avg:%g\n", plot[id].plot_id, dg_count, i, sdev, val, avg);
            put_plot_q(i, q);
         }
      }

      ++i;
      if(i >= plot_q_size) i = 0;
      if(++count > plot_q_count) break;  // deglitch all points

      col += plot_mag;    // deglitch displayed points
      if(col >= (PLOT_WIDTH*view_interval)) break;
   }
// sprintf(debug_text3, "count:%ld  col:%d", count,col);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5f0, %rsp            # imm = 0x5F0
movl %edi, -0x4(%rbp)
movsd %xmm0, -0x10(%rbp)
cmpq $0x0, 0x266d0d(%rip)    # 0x27a578
jne 0x13872
jmp 0x13da4
movsd 0x3588f6(%rip), %xmm0   # 0x36c170
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1388a
jp 0x1388a
jmp 0x13da4
cmpl $0x14, -0x4(%rbp)
jle 0x13895
jmp 0x13da4
cmpl $0x0, -0x4(%rbp)
jge 0x138cf
movl $0x0, -0x38(%rbp)
movl $0x13, -0x3c(%rbp)
cmpq $0x0, 0x289cbf(%rip)    # 0x29d570
je 0x138cd
movq 0x289cb6(%rip), %rdi    # 0x29d570
movsd -0x10(%rbp), %xmm0
leaq 0x15c7fa(%rip), %rsi    # 0x1700c0
movb $0x1, %al
callq 0x9550
jmp 0x13916
movl -0x4(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl %eax, -0x38(%rbp)
cmpq $0x0, 0x289c90(%rip)    # 0x29d570
je 0x13914
movq 0x289c87(%rip), %rdi    # 0x29d570
movslq -0x4(%rbp), %rcx
leaq 0x1a942c(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movsd -0x10(%rbp), %xmm0
leaq 0x15c7d1(%rip), %rsi    # 0x1700de
movb $0x1, %al
callq 0x9550
jmp 0x13916
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x40(%rbp)
movq 0x266b14(%rip), %rax    # 0x27a448
movq %rax, -0x18(%rbp)
movq 0x266bc1(%rip), %rax    # 0x27a500
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x13da4
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
jle 0x1398f
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
leaq -0x268(%rbp), %rdi
callq 0x133f0
leaq -0xf0(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
jmp 0x139b7
movq -0x18(%rbp), %rsi
leaq -0x318(%rbp), %rdi
callq 0x133f0
leaq -0xf0(%rbp), %rdi
leaq -0x318(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq -0x18(%rbp), %rsi
leaq -0x3c8(%rbp), %rdi
callq 0x133f0
leaq -0x1a0(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x13d41
cmpq $0x20000, 0x2640b4(%rip) # imm = 0x20000
jne 0x13a00
jmp 0x13a2b
cmpq $0x10000, 0x2640a5(%rip) # imm = 0x10000
jne 0x13a0f
jmp 0x13a29
cmpl $0xc, -0x34(%rbp)
jne 0x13a1a
jmp 0x13d33
cmpl $0xd, -0x34(%rbp)
jne 0x13a25
jmp 0x13d33
jmp 0x13a27
jmp 0x13a29
jmp 0x13a2b
movslq -0x34(%rbp), %rcx
leaq 0x1a92ea(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movsd 0x78(%rax), %xmm1
divsd 0x358723(%rip), %xmm1   # 0x36c170
movslq -0x34(%rbp), %rcx
leaq 0x1a92c8(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movsd 0x68(%rax), %xmm0
divsd 0x358701(%rip), %xmm0   # 0x36c170
movslq -0x34(%rbp), %rcx
leaq 0x1a92a6(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movsd 0x68(%rax), %xmm2
divsd 0x3586df(%rip), %xmm2   # 0x36c170
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1a8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x1a8(%rbp), %xmm0
jbe 0x13ad8
xorps %xmm0, %xmm0
subsd -0x1a8(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
movsd -0x1a8(%rbp), %xmm0
callq 0x9280
movsd %xmm0, -0x1a8(%rbp)
movslq -0x34(%rbp), %rcx
leaq 0x1a9228(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movsd 0x68(%rax), %xmm0
divsd 0x358661(%rip), %xmm0   # 0x36c170
movsd %xmm0, -0x1b0(%rbp)
movslq -0x34(%rbp), %rax
movsd -0x190(%rbp,%rax,8), %xmm0
cvtsi2sdq 0x266a4b(%rip), %xmm1 # 0x27a578
divsd %xmm1, %xmm0
movsd %xmm0, -0x1b8(%rbp)
movsd -0x1b8(%rbp), %xmm1
movsd -0x1b0(%rbp), %xmm2
movsd -0x1a8(%rbp), %xmm0
movsd -0x10(%rbp), %xmm3
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13c42
movslq -0x34(%rbp), %rax
movsd -0xe0(%rbp,%rax,8), %xmm0
movslq -0x34(%rbp), %rax
movsd %xmm0, -0x190(%rbp,%rax,8)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, 0x2899c3(%rip)    # 0x29d570
je 0x13bfc
movq 0x2899ba(%rip), %rdi    # 0x29d570
movslq -0x34(%rbp), %rcx
leaq 0x1a915f(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movsd -0x1a8(%rbp), %xmm0
movsd -0x1b8(%rbp), %xmm1
movsd -0x1b0(%rbp), %xmm2
leaq 0x15c505(%rip), %rsi    # 0x1700fa
movb $0x3, %al
callq 0x9550
movq -0x18(%rbp), %rax
movq %rax, -0x530(%rbp)
leaq -0x478(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq %rsp, %rdi
movl $0x16, %ecx
leaq -0x478(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x530(%rbp), %rdi
callq 0x13680
jmp 0x13d31
movsd -0x1b8(%rbp), %xmm0
movsd -0x1b0(%rbp), %xmm2
movsd -0x1a8(%rbp), %xmm1
movsd -0x10(%rbp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x13d2f
movslq -0x34(%rbp), %rax
movsd -0xe0(%rbp,%rax,8), %xmm0
movslq -0x34(%rbp), %rax
movsd %xmm0, -0x190(%rbp,%rax,8)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, 0x2898d1(%rip)    # 0x29d570
je 0x13cee
movq 0x2898c8(%rip), %rdi    # 0x29d570
movslq -0x34(%rbp), %rcx
leaq 0x1a906d(%rip), %rax    # 0x1bcd20
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movsd -0x1a8(%rbp), %xmm0
movsd -0x1b8(%rbp), %xmm1
movsd -0x1b0(%rbp), %xmm2
leaq 0x15c44f(%rip), %rsi    # 0x170136
movb $0x3, %al
callq 0x9550
movq -0x18(%rbp), %rax
movq %rax, -0x538(%rbp)
leaq -0x528(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq %rsp, %rdi
movl $0x16, %ecx
leaq -0x528(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x538(%rbp), %rdi
callq 0x13680
jmp 0x13d31
jmp 0x13d33
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x139e5
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq 0x2667a8(%rip), %rax    # 0x27a500
jl 0x13d62
movq $0x0, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
cmpq 0x2667a3(%rip), %rax    # 0x27a518
jle 0x13d79
jmp 0x13da4
movl 0x266831(%rip), %eax    # 0x27a5b0
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movslq -0x40(%rbp), %rax
movslq 0x263cd4(%rip), %rcx    # 0x277a64
imulq 0x2667e8(%rip), %rcx    # 0x27a580
cmpq %rcx, %rax
jl 0x13d9f
jmp 0x13da4
jmp 0x13943
addq $0x5f0, %rsp            # imm = 0x5F0
popq %rbp
retq
nopl (%rax)