1 /* propdelay.c,v 3.1 1993/07/06 01:05:24 jbj Exp
2 * propdelay - compute propagation delays
4 * cc -o propdelay propdelay.c -lm
6 * "Time and Frequency Users' Manual", NBS Technical Note 695 (1977).
10 * This can be used to get a rough idea of the HF propagation delay
11 * between two points (usually between you and the radio station).
14 * propdelay latitudeA longitudeA latitudeB longitudeB
16 * where points A and B are the locations in question. You obviously
17 * need to know the latitude and longitude of each of the places.
18 * The program expects the latitude to be preceded by an 'n' or 's'
19 * and the longitude to be preceded by an 'e' or 'w'. It understands
20 * either decimal degrees or degrees:minutes:seconds. Thus to compute
21 * the delay between the WWVH (21:59:26N, 159:46:00W) and WWV (40:40:49N,
22 * 105:02:27W) you could use:
24 * propdelay n21:59:26 w159:46 n40:40:49 w105:02:27
26 * By default it prints out a summer (F2 average virtual height 350 km) and
27 * winter (F2 average virtual height 250 km) number. The results will be
28 * quite approximate but are about as good as you can do with HF time anyway.
29 * You might pick a number between the values to use, or use the summer
30 * value in the summer and switch to the winter value when the static
31 * above 10 MHz starts to drop off in the fall. You can also use the
32 * -h switch if you want to specify your own virtual height.
36 * propdelay -W n45:17:47 w75:45:22
38 * to find the propagation delays to WWV and WWVH (from CHU in this
41 * propdelay -C n40:40:49 w105:02:27
43 * to find the delays to CHU, and a
45 * propdelay -G n52:03:17 w98:34:18
47 * to find delays to GOES via each of the three satellites.
56 #include "ntp_stdlib.h"
58 extern double sin (double);
59 extern double cos (double);
60 extern double acos (double);
61 extern double tan (double);
62 extern double atan (double);
63 extern double sqrt (double);
65 #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
70 #define EARTHRADIUS (6370.0) /* raduis of earth (km) */
71 #define LIGHTSPEED (299800.0) /* speed of light, km/s */
72 #define PI (3.1415926536)
73 #define RADPERDEG (PI/180.0) /* radians per degree */
74 #define MILE (1.609344) /* km in a mile */
76 #define SUMMERHEIGHT (350.0) /* summer height in km */
77 #define WINTERHEIGHT (250.0) /* winter height in km */
79 #define SATHEIGHT (6.6110 * 6378.0) /* geosync satellite height in km
80 from centre of earth */
82 #define WWVLAT "n40:40:49"
83 #define WWVLONG "w105:02:27"
85 #define WWVHLAT "n21:59:26"
86 #define WWVHLONG "w159:46:00"
88 #define CHULAT "n45:17:47"
89 #define CHULONG "w75:45:22"
91 #define GOES_UP_LAT "n37:52:00"
92 #define GOES_UP_LONG "w75:27:00"
93 #define GOES_EAST_LONG "w75:00:00"
94 #define GOES_STBY_LONG "w105:00:00"
95 #define GOES_WEST_LONG "w135:00:00"
96 #define GOES_SAT_LAT "n00:00:00"
98 char *wwvlat = WWVLAT;
99 char *wwvlong = WWVLONG;
101 char *wwvhlat = WWVHLAT;
102 char *wwvhlong = WWVHLONG;
104 char *chulat = CHULAT;
105 char *chulong = CHULONG;
107 char *goes_up_lat = GOES_UP_LAT;
108 char *goes_up_long = GOES_UP_LONG;
109 char *goes_east_long = GOES_EAST_LONG;
110 char *goes_stby_long = GOES_STBY_LONG;
111 char *goes_west_long = GOES_WEST_LONG;
112 char *goes_sat_lat = GOES_SAT_LAT;
120 char const *progname;
122 static void doit (double, double, double, double, double, char *);
123 static double latlong (char *, int);
124 static double greatcircle (double, double, double, double);
125 static double waveangle (double, double, int);
126 static double propdelay (double, double, int);
127 static int finddelay (double, double, double, double, double, double *);
128 static void satdoit (double, double, double, double, double, double, char *);
129 static void satfinddelay (double, double, double, double, double *);
130 static double satpropdelay (double);
133 * main - parse arguments and handle options
150 while ((c = ntp_getopt(argc, argv, "dh:CWG")) != EOF)
157 height = atof(ntp_optarg);
159 (void) fprintf(stderr, "height %s unlikely\n",
177 if (errflg || (!(Cflag || Wflag || Gflag) && ntp_optind+4 != argc) ||
178 ((Cflag || Wflag || Gflag) && ntp_optind+2 != argc)) {
179 (void) fprintf(stderr,
180 "usage: %s [-d] [-h height] lat1 long1 lat2 long2\n",
182 (void) fprintf(stderr," - or -\n");
183 (void) fprintf(stderr,
184 "usage: %s -CWG [-d] lat long\n",
190 if (!(Cflag || Wflag || Gflag)) {
191 lat1 = latlong(argv[ntp_optind], 1);
192 long1 = latlong(argv[ntp_optind + 1], 0);
193 lat2 = latlong(argv[ntp_optind + 2], 1);
194 long2 = latlong(argv[ntp_optind + 3], 0);
196 doit(lat1, long1, lat2, long2, height, "");
198 doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT,
199 "summer propagation, ");
200 doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT,
201 "winter propagation, ");
205 * Compute delay from WWV
207 lat1 = latlong(argv[ntp_optind], 1);
208 long1 = latlong(argv[ntp_optind + 1], 0);
209 lat2 = latlong(wwvlat, 1);
210 long2 = latlong(wwvlong, 0);
212 doit(lat1, long1, lat2, long2, height, "WWV ");
214 doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT,
215 "WWV summer propagation, ");
216 doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT,
217 "WWV winter propagation, ");
221 * Compute delay from WWVH
223 lat2 = latlong(wwvhlat, 1);
224 long2 = latlong(wwvhlong, 0);
226 doit(lat1, long1, lat2, long2, height, "WWVH ");
228 doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT,
229 "WWVH summer propagation, ");
230 doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT,
231 "WWVH winter propagation, ");
234 lat1 = latlong(argv[ntp_optind], 1);
235 long1 = latlong(argv[ntp_optind + 1], 0);
236 lat2 = latlong(chulat, 1);
237 long2 = latlong(chulong, 0);
239 doit(lat1, long1, lat2, long2, height, "CHU ");
241 doit(lat1, long1, lat2, long2, (double)SUMMERHEIGHT,
242 "CHU summer propagation, ");
243 doit(lat1, long1, lat2, long2, (double)WINTERHEIGHT,
244 "CHU winter propagation, ");
247 lat1 = latlong(goes_up_lat, 1);
248 long1 = latlong(goes_up_long, 0);
249 lat3 = latlong(argv[ntp_optind], 1);
250 long3 = latlong(argv[ntp_optind + 1], 0);
252 lat2 = latlong(goes_sat_lat, 1);
254 long2 = latlong(goes_west_long, 0);
255 satdoit(lat1, long1, lat2, long2, lat3, long3,
256 "GOES Delay via WEST");
258 long2 = latlong(goes_stby_long, 0);
259 satdoit(lat1, long1, lat2, long2, lat3, long3,
260 "GOES Delay via STBY");
262 long2 = latlong(goes_east_long, 0);
263 satdoit(lat1, long1, lat2, long2, lat3, long3,
264 "GOES Delay via EAST");
272 * doit - compute a delay and print it
287 hops = finddelay(lat1, long1, lat2, long2, h, &delay);
288 printf("%sheight %g km, hops %d, delay %g seconds\n",
289 str, h, hops, delay);
294 * latlong - decode a latitude/longitude value
312 * Must be north or south
314 if (*str == 'N' || *str == 'n')
316 else if (*str == 'S' || *str == 's')
322 * East is positive, west is negative
324 if (*str == 'E' || *str == 'e')
326 else if (*str == 'W' || *str == 'w')
335 colon = strchr(str, ':');
348 colon = strchr(cp, ':');
355 arg += atof(buf) / divby;
359 arg += atof(cp) / divby;
368 (void) printf("latitude/longitude %s = %g\n", str, arg);
375 * greatcircle - compute the great circle distance in kilometers
388 l1r = lat1 * RADPERDEG;
389 l2r = lat2 * RADPERDEG;
390 dg = EARTHRADIUS * acos(
391 (cos(l1r) * cos(l2r) * cos((long2-long1)*RADPERDEG))
392 + (sin(l1r) * sin(l2r)));
395 "greatcircle lat1 %g long1 %g lat2 %g long2 %g dist %g\n",
396 lat1, long1, lat2, long2, dg);
402 * waveangle - compute the wave angle for the given distance, virtual
403 * height and number of hops.
415 theta = dg / (EARTHRADIUS * (double)(2 * n));
416 delta = atan((h / (EARTHRADIUS * sin(theta))) + tan(theta/2)) - theta;
418 printf("waveangle dist %g height %g hops %d angle %g\n",
419 dg, h, n, delta / RADPERDEG);
425 * propdelay - compute the propagation delay
438 theta = dg / (EARTHRADIUS * (double)(2 * n));
439 phi = (PI/2.0) - atan((h / (EARTHRADIUS * sin(theta))) + tan(theta/2));
440 td = dg / (LIGHTSPEED * sin(phi));
442 printf("propdelay dist %g height %g hops %d time %g\n",
449 * finddelay - find the propagation delay
461 double dg; /* great circle distance */
462 double delta; /* wave angle */
463 int n; /* number of hops */
465 dg = greatcircle(lat1, long1, lat2, long2);
467 printf("great circle distance %g km %g miles\n", dg, dg/MILE);
470 while ((delta = waveangle(dg, h, n)) < 0.0) {
472 printf("tried %d hop%s, no good\n", n, n>1?"s":"");
476 printf("%d hop%s okay, wave angle is %g\n", n, n>1?"s":"",
479 *delay = propdelay(dg, h, n);
484 * satdoit - compute a delay and print it
497 double up_delay,down_delay;
499 satfinddelay(lat1, long1, lat2, long2, &up_delay);
500 satfinddelay(lat3, long3, lat2, long2, &down_delay);
502 printf("%s, delay %g seconds\n", str, up_delay + down_delay);
506 * satfinddelay - calculate the one-way delay time between a ground station
518 double dg; /* great circle distance */
520 dg = greatcircle(lat1, long1, lat2, long2);
522 *delay = satpropdelay(dg);
526 * satpropdelay - calculate the one-way delay time between a ground station
538 theta = dg / (EARTHRADIUS);
539 k1 = EARTHRADIUS * sin(theta);
540 k2 = SATHEIGHT - (EARTHRADIUS * cos(theta));
542 printf("Theta %g k1 %g k2 %g\n", theta, k1, k2);
543 dist = sqrt(k1*k1 + k2*k2);
544 td = dist / LIGHTSPEED;
546 printf("propdelay dist %g height %g time %g\n", dg, dist, td);