summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md34
-rw-r--r--gridcal.c14
2 files changed, 44 insertions, 4 deletions
diff --git a/README.md b/README.md
index 6aa4d19..6315c3e 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,41 @@
gridcal -- compute the great-circle distance between two grid locators
======================================================================
-`gridcal` computed the short-path great-circle distance between two grid
+`gridcal` computes the short-path great-circle distance between two grid
locators. The Grid Locator System divides Earth into a series of
rectangles identified by a combination of letters and numbers, so that
the approximate position of a point can be expressed with a short
identifier like IO91vl.
+Usage: gridcal <loc1> [<loc2> [<pwr>]]
+
+If `gridcal` is given only one locator, it prints on output the latitude
+and longitude of the centre of the corresponding grid square:
+
+ gridcal IO91vl
+ IO91vl 51.4792 -0.208333 0.898481 -0.0036361
+
+With two locators as input, `gridcal` prints on output the two locators
+and their great-circle distance, both in km and miles:
+
+ gridcal IO91vl JN65od
+ IO91vl JN65od 1213.71 754.164
+
+If `gridcal` is given as third numerical argument, that number is
+considered a "power" value in Watts, and `gridcal` will print on output
+a longer line containing the two locators, the distance in km and miles,
+the power value, and the corresponding km/W and miles/W:
+
+ gridcal IO91vl JN65od 1.2
+ IO91vl JN65od 1213.71 754.164 1.2 1011.42 628.47
+
+The latter can be useful to check if a QSO with another ham radio
+station qualifies for one of the thousand miles per Watt awards.
+
+
+Dependencies
+============
+
+`gridcal` is written in ANSI C has no dependencies.
+
+
diff --git a/gridcal.c b/gridcal.c
index 97e8cf9..6e552b4 100644
--- a/gridcal.c
+++ b/gridcal.c
@@ -15,8 +15,16 @@
#include <ctype.h>
#define MIN(a,b) ((a)>(b)?(b):(a))
+#define R 6371
-double R = 6371;
+#ifndef M_PI
+#define M_PI 3.14159265358979323846 /* pi */
+#endif
+
+
+#ifndef M_PI_2
+#define M_PI_2 1.57079632679489661923 /* pi/2 */
+#endif
typedef struct {
double lat;
@@ -26,7 +34,7 @@ typedef struct {
void usage(char *argv0){
- printf("Usage: %s <grid1> <grid2> [<pwr>]", argv0);
+ printf("Usage: %s <loc1> [<loc2> [<pwr>]]", argv0);
exit(1);
}
@@ -117,7 +125,7 @@ int main(int argc, char *argv[]){
loc1[n1] = '\0';
check_input(loc1);
grid_to_latlon(loc1, &c1);
- printf("%s %g %g\n", loc1, c1.lat, c1.lon);
+ printf("%s %g %g %g %g\n", loc1, c1.lat*180/M_PI, c1.lon*180/M_PI, c1.lat, c1.lon);
exit(0);
}