// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathui.cpp
// Function: calc_prop_delay(char*)
int calc_prop_delay(char *s)
{
double old_lat, old_lon, old_alt;
struct STATION station;
char lat_s[SLEN+1];
char lon_s[SLEN+1];
char alt_s[SLEN+1];
int n;
char *comma;
int hops;
double dist;
double az;
double delay;
double x_lat,x_lon,x_alt;

   // set lat/lon/altitude
   if(s == 0) return (-1);
   strupr(s);

   old_lat = prop_lat;
   old_lon = prop_lon;
   old_alt = prop_alt;

   comma = s;
   while(comma) {  // convert commas to spaces
      comma = strchr(comma, ',');
      if(comma) *comma = ' ';
      else break;
   }

   if(strstr(s, "LOC")) {
      x_lat = lat;
      x_lon = lon;
      x_alt = alt;
      n = read_default_lla();  // get location from heather.loc file
      lat = x_lat;
      lon = x_lon;
      alt = x_alt;
      if(n != LLA_OK) goto bad_loc;

      sprintf(lat_s, "%.9f", precise_lat*180.0/PI);
      sprintf(lon_s, "%.9f", precise_lon*180.0/PI);
      sprintf(alt_s, "%.9f", 0.0);
      n = 3;
   }
   else {
      n = sscanf(s, "%s %s %s", &lat_s[0],&lon_s[0],&alt_s[0]);
      if(n == 1) {  // iono height not given, default it
         sprintf(lon_s, "%g", iono_height());
         ++n;
      }
   }

   dist = 0.0;
   if(n == 2) {  // location is a time station name, distance, or lat/lon
      strcpy(alt_s, lon_s);
      station = find_station(lat_s);
      if(station.id && station.lat && station.lon) {  // station id given as location
         strcpy(lat_s, station.lat);
         strcpy(lon_s, station.lon);
      }
      else if(strchr(lat_s, 'K')) {  // distance in km
         dist = atof(lat_s);
         strcpy(lat_s, "0.0");
         strcpy(lon_s, "0.0");
      }
      else {  // lat/lon given, fill in ionosphere height
         sprintf(alt_s, "%g", iono_height());
         ++n;
      }
   }
   else if(n != 3) {
      bad_loc:
      prop_lat = old_lat;
      prop_lon = old_lon;
      prop_alt = old_alt;
      return LLA_MISSING;
   }

   prop_lat = parse_coord(0, lat_s);
   prop_lon = parse_coord(1, lon_s);
   prop_alt = parse_alt(alt_s);
   if(prop_alt == 0.0) prop_alt = 0.001;

   if((prop_lat < -90.0) || (prop_lat > 90.0)) {
      prop_lat = old_lat;
      prop_lon = old_lon;
      prop_alt = old_alt;
      return BAD_LAT;
   }
   else if((prop_lon < -180.0) || (prop_lon > 180.0)) {
      prop_lat = old_lat;
      prop_lon = old_lon;
      prop_alt = old_alt;
      return BAD_LON;
   }
   else if((prop_alt < 0.0) || (prop_alt > 1.0E6)) {
      prop_lat = old_lat;
      prop_lon = old_lon;
      prop_alt = old_alt;
      return BAD_ALT;
   }

   prop_lat /= RAD_TO_DEG;
   prop_lon /= RAD_TO_DEG;
   have_prop_lla = (-5);

   hops = find_delay(lat,lon, prop_lat,prop_lon,prop_alt, dist, &dist,&delay);
   az = az_angle(lat,lon, prop_lat,prop_lon);

   if(dist < 1.0) {  // less than 1km away, show meters/feet
      sprintf(debug_text, "%.3f m (%.2f feet)  az=%.3f deg   prop delay %.6f seconds  ionosphere:%.0f km  hops:%d",
          dist*1000.0, dist/1.609344*5280.0, az, delay, prop_alt, hops);
   }
   else {  // show km/miles
      sprintf(debug_text, "%.3f km (%.3f miles)  az=%.3f deg   prop delay %.6f seconds  ionosphere:%.0f km  hops:%d",
          dist, dist/1.609344, az, delay, prop_alt, hops);
   }

   return LLA_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
testq %rdi, %rdi
je 0x31b4d
movq %rdi, %rbx
callq 0x9899
leaq 0x3098f4(%rip), %r13    # 0x33b348
movsd (%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq 0x3098ea(%rip), %r12    # 0x33b350
movsd (%r12), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x3098e0(%rip), %r15    # 0x33b358
movsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movl $0x2c, %esi
callq 0x9100
testq %rax, %rax
je 0x31a9c
movb $0x20, (%rax)
movq %rax, %rdi
jmp 0x31a85
leaq 0xd9335(%rip), %rsi     # 0x10add8
movq %rbx, %rdi
callq 0x9090
testq %rax, %rax
je 0x31b57
leaq 0x2db515(%rip), %rbx    # 0x30cfd0
movsd (%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2db50d(%rip), %r14    # 0x30cfd8
movsd (%r14), %xmm0
movsd %xmm0, -0x68(%rbp)
movq %r12, %r13
movq %r15, %r12
leaq 0x2db4fe(%rip), %r15    # 0x30cfe0
movsd (%r15), %xmm0
movsd %xmm0, -0x60(%rbp)
callq 0x20293
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rbx)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%r14)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, (%r15)
movq %r12, %r15
movq %r13, %r12
leaq 0x30982d(%rip), %r13    # 0x33b348
testl %eax, %eax
je 0x31ba8
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movl $0x4, %ebx
jmp 0x31ffb
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x31ffb
leaq 0xe32bf(%rip), %rsi     # 0x114e1d
leaq -0x270(%rbp), %rdx
leaq -0x170(%rbp), %rcx
leaq -0x370(%rbp), %r8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9360
cmpl $0x1, %eax
jne 0x31c2e
leaq 0x2db983(%rip), %rax    # 0x30d510
movl (%rax), %eax
leal -0xd(%rax), %ecx
cmpl $-0xc, %ecx
jae 0x31c49
movsd 0xd9d85(%rip), %xmm0    # 0x10b928
jmp 0x31c7b
leaq 0x309741(%rip), %rax    # 0x33b2f0
movsd (%rax), %xmm0
mulsd 0xd9c75(%rip), %xmm0    # 0x10b830
divsd 0xd9c65(%rip), %xmm0    # 0x10b828
leaq 0x100d7d(%rip), %rbx    # 0x132947
leaq -0x270(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
leaq 0x309716(%rip), %rax    # 0x33b2f8
movsd 0xd9c46(%rip), %xmm0    # 0x10b830
mulsd (%rax), %xmm0
divsd 0xd9c32(%rip), %xmm0    # 0x10b828
leaq -0x170(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
leaq -0x370(%rbp), %rdi
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
movq $0x0, -0x50(%rbp)
jmp 0x31dd0
movq $0x0, -0x50(%rbp)
cmpl $0x3, %eax
je 0x31dc7
cmpl $0x2, %eax
je 0x31c98
jmp 0x31b23
leaq 0x2db380(%rip), %rcx    # 0x30cfd0
cmpl $0x7, %eax
movl $0xfffffffa, %edx       # imm = 0xFFFFFFFA
movl $0x6, %esi
cmovael %edx, %esi
xorl %edx, %edx
xorpd %xmm0, %xmm0
ucomisd (%rcx), %xmm0
cmoval %esi, %edx
addl %eax, %edx
leaq 0x13868a(%rip), %rax    # 0x16a300
movsd (%rax,%rdx,8), %xmm0
leaq 0xfd855(%rip), %rsi     # 0x12f4d7
leaq -0x170(%rbp), %rdi
movb $0x1, %al
callq 0x9060
movq $0x0, -0x50(%rbp)
leaq -0x370(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9340
leaq 0x1383ee(%rip), %r14    # 0x16a0a0
leaq -0x270(%rbp), %rbx
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x31cdb
movq %rbx, %rsi
callq 0x9090
addq $0x18, %r14
testq %rax, %rax
je 0x31cb9
leaq -0x8(%r14), %rcx
movb $0x1, %al
jmp 0x31cf4
cmpq $0x0, 0x1383ad(%rip)    # 0x16a090
setne %al
leaq 0x1383ab(%rip), %rcx    # 0x16a098
leaq 0x1383ac(%rip), %r14    # 0x16a0a0
movq (%rcx), %rsi
movq (%r14), %rbx
testq %rsi, %rsi
setne %cl
andb %al, %cl
testq %rbx, %rbx
setne %al
andb %cl, %al
leaq -0x270(%rbp), %rdi
cmpb $0x1, %al
jne 0x31d2e
callq 0x9340
leaq -0x170(%rbp), %rdi
movq %rbx, %rsi
callq 0x9340
jmp 0x31dc7
movl $0x4b, %esi
callq 0x9100
testq %rax, %rax
je 0x31d65
leaq -0x270(%rbp), %rbx
movq %rbx, %rdi
callq 0x9470
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, -0x50(%rbp)
movl $0x302e30, %eax         # imm = 0x302E30
movl %eax, (%rbx)
movl %eax, -0x170(%rbp)
jmp 0x31dd0
leaq 0x2db7a4(%rip), %rax    # 0x30d510
movl (%rax), %eax
leal -0xd(%rax), %ecx
cmpl $-0xc, %ecx
jae 0x31d80
movsd 0xd9baa(%rip), %xmm0    # 0x10b928
jmp 0x31db2
leaq 0x2db249(%rip), %rcx    # 0x30cfd0
cmpl $0x7, %eax
movl $0xfffffffa, %edx       # imm = 0xFFFFFFFA
movl $0x6, %esi
cmovael %edx, %esi
xorl %edx, %edx
xorpd %xmm0, %xmm0
ucomisd (%rcx), %xmm0
cmoval %esi, %edx
addl %eax, %edx
leaq 0x138553(%rip), %rax    # 0x16a300
movsd (%rax,%rdx,8), %xmm0
leaq 0xfd71e(%rip), %rsi     # 0x12f4d7
leaq -0x370(%rbp), %rdi
movb $0x1, %al
callq 0x9060
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x270(%rbp), %rsi
xorl %edi, %edi
callq 0x3139b
movsd %xmm0, (%r13)
movl $0x1, %ebx
leaq -0x170(%rbp), %rsi
movl $0x1, %edi
callq 0x3139b
movsd %xmm0, (%r12)
leaq -0x370(%rbp), %rdi
callq 0x30ff6
xorpd %xmm4, %xmm4
cmpeqsd %xmm0, %xmm4
movsd 0xd9b13(%rip), %xmm1    # 0x10b930
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
movlpd %xmm4, (%r15)
movsd (%r13), %xmm2
movapd 0xd7354(%rip), %xmm0    # 0x109190
andpd %xmm2, %xmm0
ucomisd 0xd9ad0(%rip), %xmm0    # 0x10b918
jbe 0x31e6f
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
jmp 0x31ffb
movsd (%r12), %xmm3
movapd 0xd7313(%rip), %xmm0    # 0x109190
andpd %xmm3, %xmm0
ucomisd 0xd99a7(%rip), %xmm0    # 0x10b830
jbe 0x31eb5
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movl $0x2, %ebx
jmp 0x31ffb
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
ja 0x31f9a
ucomisd 0xd7185(%rip), %xmm4    # 0x109050
ja 0x31f9a
movsd 0xd7287(%rip), %xmm0    # 0x109160
divsd %xmm0, %xmm2
movsd %xmm2, (%r13)
divsd %xmm0, %xmm3
movsd %xmm3, (%r12)
leaq 0x30946c(%rip), %rax    # 0x33b360
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
leaq 0x2db0cf(%rip), %r15    # 0x30cfd0
movsd (%r15), %xmm0
leaq 0x2db0cb(%rip), %rbx    # 0x30cfd8
movsd (%rbx), %xmm1
leaq -0x50(%rbp), %r14
leaq -0x58(%rbp), %rsi
movsd -0x30(%rbp), %xmm5
movq %r14, %rdi
callq 0xea27a
movl %eax, -0x38(%rbp)
movsd (%r15), %xmm0
movsd (%rbx), %xmm1
movsd (%r13), %xmm2
movsd (%r12), %xmm3
callq 0xea0f3
movapd %xmm0, %xmm2
movsd (%r14), %xmm5
movsd 0xd711c(%rip), %xmm0    # 0x109070
ucomisd %xmm5, %xmm0
jbe 0x31fc1
movsd 0xd70d6(%rip), %xmm0    # 0x109038
mulsd %xmm5, %xmm0
divsd 0xd99ca(%rip), %xmm5    # 0x10b938
mulsd 0xd99ca(%rip), %xmm5    # 0x10b940
movsd -0x58(%rbp), %xmm3
leaq 0x3093d6(%rip), %rax    # 0x33b358
movsd (%rax), %xmm4
leaq 0x30ca13(%rip), %rdi    # 0x33e9a0
leaq 0xe30a2(%rip), %rsi     # 0x115036
movapd %xmm5, %xmm1
jmp 0x31fef
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movl $0x3, %ebx
jmp 0x31ffb
movapd %xmm5, %xmm1
divsd 0xd996b(%rip), %xmm1    # 0x10b938
movsd -0x58(%rbp), %xmm3
leaq 0x30937f(%rip), %rax    # 0x33b358
movsd (%rax), %xmm4
leaq 0x30c9bc(%rip), %rdi    # 0x33e9a0
leaq 0xe30a2(%rip), %rsi     # 0x11508d
movapd %xmm5, %xmm0
movl -0x38(%rbp), %edx
movb $0x5, %al
callq 0x9060
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq