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