fixed console scrolling? finally?
[spider.git] / cmd / show / muf.pl
1 #!/usr/bin/perl
2 #
3 # show/muf command
4 #
5 # Copyright (c) 1999 Dirk Koopman G1TLH
6 #
7 # $Id$
8 #
9
10 my ($self, $line) = @_;
11 my ($prefix, $hr2) = split /\s+/, $line;
12 return (1, $self->msg('e4')) unless $prefix;
13
14 $hr2 = 2 if !$hr2 || $hr2 < 2;
15 $hr2 = 24 if $hr2 > 24;
16
17 my @out;
18
19 # get prefix data
20 my ($pre, $a) = Prefix::extract($prefix);
21
22 # calc bearings and distance
23 my ($d, $b1, $b2);                              # distance, bearing from TX and from RX
24 my ($lat2, $lon2);              # lats and longs in radians
25 my $lat1 = $self->user->lat;
26 my $lon1 = $self->user->long;
27 if (!$lon1 && !$lat1) {
28         push @out, $self->msg('heade1');
29         $lat1 = $main::mylatitude;
30         $lon1 = $main::mylongitude;
31 }
32 $lat2 = $a->{lat};
33 $lon2 = $a->{long};
34 ($b1, $d) = DXBearing::bdist($lat1, $lon1, $lat2, $lon2);       
35 ($b2, undef) = DXBearing::bdist($lat2, $lon2, $lat1, $lon1);
36
37 # convert stuff into radians
38 $lat1 *= $d2r;
39 $lat2 *= $d2r;
40 $lon1 *= $d2r;
41 $lon2 *= $d2r;
42 $b1 *= $d2r;
43 $b2 *= $d2r;
44 $d = ($d / $R);
45
46 my ($hr1, $day, $month) = (gmtime($main::systime))[2,3,4];
47 $month++;
48 my $flux = Geomag::sfi;
49 my $ssn = Minimuf::spots($flux);
50
51 my $theta;                                              # path angle (rad) 
52 my ($lats, $lons);                              # subsolar coordinates (rad) 
53 my $dB1 = 20;                                   # transmitter output power (dBW) 
54
55 my $delay;                                              # path delay (ms) 
56 my $psi;                                                # sun zenith angle (rad) 
57 my ($ftemp, $gtemp);                    # my $temps 
58 my ($i, $j, $h, $n);                    # int temps 
59 my $offset;                                             # offset for local time (hours) 
60 my $fcF;                                                # F-layer critical frequency (MHz) 
61 my $phiF;                                               # F-layer angle of incidence (rad) 
62 my $hop;                                                # number of ray hops 
63 my $beta1;                                              # elevation angle (rad) 
64 my $dhop;                                               # hop great-circle distance (rad) 
65 my $height;                                             # height of F layer (km) 
66 my $time;                                               # time of day (hour) 
67 my $rsens = -123;                               # RX sensitivity
68
69
70 my @freq = qw(1.8 3.5 7.0 10.1 14.0 18.1 21.0 24.9 28.0 50.0); # working frequencies (MHz) 
71 my $nfreq = @freq;                              # number of frequencies 
72 my @mufE;                                               # maximum E-layer MUF (MHz) 
73 my @mufF;                                               # minimum F-layer MUF (MHz) 
74 my @absorp;                                             # ionospheric absorption coefficient 
75 my @dB2;                                                # receive power (dBm) 
76 my @path;                                               # path length (km) 
77 my @beta;                                               # elevation angle (rad) 
78 my @daynight;                                   # path flags    
79
80 # calculate hops, elevation angle, F-layer incidence, delay.
81 $hop = int ($d / (2 * acos($R / ($R + $hF))));
82 $beta1 = 0;
83 while ($beta1 < $MINBETA) {
84         $hop++;
85         $dhop = $d / ($hop * 2);
86         $beta1 = atan((cos($dhop) - $R / ($R + $hF)) / sin($dhop));
87 }
88 $ftemp = $R * cos($beta1) / ($R + $hF);
89 $phiF = atan($ftemp / sqrt(1 - $ftemp * $ftemp));
90 $delay = ((2 * $hop * sin($dhop) * ($R + $hF)) / cos($beta1) / $VOFL) * 1e6;
91
92 # print summary of data so far
93 push @out, sprintf("RxSens: $rsens dBM SFI:%4.0lf   R:%4.0lf   Month: $month   Day: $day", $flux, $ssn);
94 push @out, sprintf("Power :  %3.0f dBW    Distance:%6.0f km    Delay:%5.1f ms", $dB1, $d * $R, $delay);
95 push @out, sprintf("Location                       Lat / Long           Azim");
96 push @out, sprintf("%-30.30s %-18s    %3.0f", $main::myqth, DXBearing::lltos($lat1*$r2d, $lon1*$r2d), $b1 * $r2d);
97 push @out, sprintf("%-30.30s %-18s    %3.0f", $a->name, DXBearing::lltos($lat2*$r2d, $lon2*$r2d), $b2 * $r2d);
98 my $head = "UT LT  MUF Zen";
99 for ($i = 0; $i < $nfreq; $i++) {
100         $head .= sprintf "%5.1f", $freq[$i];
101 }
102 push @out, $head;
103
104 my $hour;
105
106 # Hour loop: This loop determines the min-hop path and next two
107 # higher-hop paths. It selects the most likely path for each
108 # frequency and calculates the receive power. The F-layer
109 # critical frequency is computed directly from MINIMUF 3.5 and
110 # the secant law.
111
112 $offset = int ($lon2 * 24. / $pi2);
113 for ($hour = $hr1; $hour < $hr2+$hr1; $hour++) {
114     my $dh = $hour;
115         while ($dh >= 24) {
116                 $dh -= 24;
117         };
118         $time = $dh - $offset;
119         $time += 24 if ($time < 0);
120         $time -= 24 if ($time >= 24);
121         my $out = sprintf("%2.0f %2.0f", $dh, $time);
122         $ftemp = Minimuf::minimuf($flux, $month, $day, $dh, $lat1, $lon1, $lat2, $lon2);
123         $fcF = $ftemp * cos($phiF);
124         
125         # Calculate subsolar coordinates.
126         $ftemp = ($month - 1) * 365.25 / 12. + $day - 80.;
127         $lats = 23.5 * $d2r * sin($ftemp / 365.25 * $pi2);
128         $lons = ($dh * 15. - 180.) * $d2r;
129         
130         # Path loop: This loop determines the geometry of the
131         # min-hop path and the next two higher-hop paths. It
132         # calculates the minimum F-layer MUF, maximum E-layer
133         # MUF and ionospheric absorption factor for each
134         # geometry.
135         for ($h = $hop; $h < $hop + 3; $h++) {
136                 
137                 # We assume the F layer height increases during
138                 # the day and decreases at night, as determined
139                 # at the midpoint of the path.
140                 $height = $hF;
141                 $psi = Minimuf::zenith($d / 2, $lat1, $lon1, $b2, $b1, $lats, $lons);
142                 if ($psi < 0) {
143                         $height -= 70.;
144                 } else {
145                         $height += 30;
146                 }
147                 $dhop = $d / ($h * 2.);
148                 $beta[$h] = atan((cos($dhop) - $R / ($R + $height)) / sin($dhop));
149                 $path[$h] = 2 * $h * sin($dhop) * ($R + $height) / cos($beta[$h]);
150                 Minimuf::ion($h, $d, $fcF, $ssn, $lat1, $lon1, $b2, $b1, $lats, $lons, \@daynight, \@mufE, \@mufF, \@absorp);
151         }
152         
153         # Display one line for this hour.
154         $out .= sprintf("%5.1f%4.0f ", $mufF[$hop], 90 - $psi * $r2d);
155         $ftemp = $noise;
156         for ($i = 0; $i < $nfreq; $i++) {
157                 $n = Minimuf::pathloss($hop, $freq[$i], 20, $rsens, 0,  \@daynight, \@beta, \@path, \@mufF, \@mufE, \@absorp, \@dB2);
158                 my $s = Minimuf::ds($n, $rsens, \@dB2, \@daynight);
159                 $out .= " $s"; 
160         }
161         $out =~ s/\s+$//;
162         push @out, $out;
163 }
164
165 return (1, @out);