[hamradio-commits] [wwl] 01/11: Imported Upstream version 1.3+db

Iain Learmonth irl-guest at moszumanska.debian.org
Mon Aug 10 22:33:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

irl-guest pushed a commit to branch master
in repository wwl.

commit d4ce94b17589236adedc2e65e8d291058cdcc178
Author: Iain R. Learmonth <irl at fsfe.org>
Date:   Mon Aug 10 22:01:03 2015 +0100

    Imported Upstream version 1.3+db
---
 INSTALL  |  13 ++++
 Makefile |  52 ++++++++++++++
 wwl.1    |  49 +++++++++++++
 wwl.c    | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 360 insertions(+)

diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..7e2bf59
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,13 @@
+set PREFIX in Makefile to the path to /bin
+i.e.
+PREFIX?=        /usr/local
+set MANPREFIX to the path to man pages
+i.e.
+MANPREFIX?=     /usr/local/man
+set MAN1PREFIX to where man1 pages go
+i.e. 
+MAN1PREFIX?=    ${MANPREFIX}/man1
+
+The Makefile will make wwl and link wwl to locator.
+
+- 73 Diane VA3DB
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4160fee
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
+# September 2007
+# Diane Bruce <va3db at amsat.org>
+
+PREFIX?=	/usr/local
+MANPREFIX?=	/usr/local/man
+MAN1PREFIX?=	${MANPREFIX}/man1
+LN?=		ln
+INSTALL?=	install
+GZIP?=		gzip
+CP?=		cp
+RM?=		rm
+MKDIR?=		mkdir
+TAR?=		tar
+RELEASE=	wwl+db-1.3
+
+all: wwl locator
+
+wwl:	wwl.c 
+	$(CC) $(CFLAGS) -o wwl wwl.c -lm
+
+locator: wwl
+	${RM} -f locator
+	${LN} -s wwl locator
+
+install:	all
+	${RM} -f ${PREFIX}/bin/locator
+	${RM} -f ${PREFIX}/bin/wwl
+	${INSTALL}	wwl ${PREFIX}/bin/wwl
+	${LN} -s ${PREFIX}/bin/wwl ${PREFIX}/bin/locator
+	${INSTALL} wwl.1 ${MAN1PREFIX}/wwl.1
+	${GZIP} -f ${MAN1PREFIX}/wwl.1
+	${LN} -s ${MAN1PREFIX}/wwl.1.gz ${MAN1PREFIX}/locator.1.gz
+	
+deinstall:
+	${RM} -f ${PREFIX}/bin/wwl
+	${RM} -f ${PREFIX}/bin/locator
+	${RM} -f ${MAN1PREFIX}/wwl.1.gz
+	${RM} -f ${MAN1PREFIX}/locator.1.gz
+
+release:
+	@${RM} -rf ${RELEASE}
+	@${MKDIR} ${RELEASE}
+	@${CP} Makefile ${RELEASE}
+	@${CP} wwl.c ${RELEASE}
+	@${CP} wwl.1 ${RELEASE}
+	@${CP} INSTALL ${RELEASE}
+	${TAR} cvfz ${RELEASE}.tar.gz ${RELEASE}
+	@${RM} -rf ${RELEASE}
+
+clean:
+	rm -f wwl *~ wwl locator *.o
+	rm -rf ${RELEASE}.tar.gz ${RELEASE}
diff --git a/wwl.1 b/wwl.1
new file mode 100644
index 0000000..e0718eb
--- /dev/null
+++ b/wwl.1
@@ -0,0 +1,49 @@
+.Dd October 7, 2007
+.Os FreeBSD
+.Dt wwl 1
+.Sh NAME
+.Nm wwl 
+.Nd Maidenhead locator utility
+.Sh SYNOPSIS
+This program does Maidenhead calculations of distance and bearing
+for any two Maidenhead locators given on the command line; Alternatively
+the program may be used to return the Latitude and Longitude of
+a single Maidenhead grid square when invoked as locator.
+.\" .Sh RETURN VALUES
+.Sh EXAMPLES
+wwl fn25di jo55ei
+.br
+qrb: 5810 kilometers, azimuth: 46 degrees
+.Pp
+wwl jo55 ec41
+.br
+qrb: 15996 kilometers, azimuth: 216 degrees
+.Pp
+locator FN25di
+.br
+Locator    : FN25DI
+.br
+Coordinates: Long: (W) -75.75 Lat : (N) 45.3333
+.Pp
+locator jo55ei
+.br
+Locator    : JO55EI
+.br
+Coordinates: Long: (E) 10.33 Lat : (N) 55.3333
+.Pp
+locator ec41
+.br
+Locator    : EC41AA
+.br
+Coordinates: Long: (W) -92.00 Lat : (S) -69.0000
+.Sh HISTORY
+.Pp
+wwl, Originally by IK0ZSN Mirko Caserta <ik0zsn at amsat.org>
+.Pp
+locator, originally written by Harald M.
+Stauss harald.stauss at web.de DO1JHS @ DB0GR.#BLN.DEU.EU
+.Pp
+There is no code from the original (dead?) version of wwl or
+the original (dead?) version of locator in this version.
+.Sh AUTHORS
+Diane Bruce (VA3DB) db at db.net	   
diff --git a/wwl.c b/wwl.c
new file mode 100644
index 0000000..c91b78c
--- /dev/null
+++ b/wwl.c
@@ -0,0 +1,246 @@
+/*
+ * Program: wwl
+ * 
+ * This program combines two handy hamradio Maindensquare programs into one.
+ * When used as locator, it will take the Maindenhead square on the
+ * command line and write it back out as lat / long.
+ * When used as wwl, it will calculate distance and azimuth
+ * between the two Maidenhead squares given.
+ * If only four characters of the Maidenhead square is given, this
+ * program will auto fill in the missing two chars with 'AA'
+ *
+ * This version by va3db db at db.net db at FreeBSD.org Oct 1 2007
+ * rewritten completely. There were equator crossing bugs in the original
+ * (dead) version of wwl on sunsite, so I rewrote it from scratch.
+ *
+ * wwl     -- Originally by IK0ZSN Mirko Caserta <ik0zsn at amsat.org>
+ * locator -- originally written by Harald M.
+ * Stauss harald.stauss at web.de DO1JHS @ DB0GR.#BLN.DEU.EU
+ * There is no code from the original (dead?) version of wwl or
+ * the original (dead?) version of locator in this version.
+ *
+ * The bearing/distance code is from Amateur Radio Software by John
+ * Morris, GM4ANB.
+ *
+ * <db at FreeBSD.ORG> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this code, except you may not
+ * license it under any form of the GPL.
+ * A postcard or QSL card showing me you appreciate
+ * this code would be nice. Diane Bruce va3db
+ */
+
+#include <stdio.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <math.h>
+#include <string.h>
+
+#define SCRATCH_WWL_LEN 9
+#define WWL_LEN		6
+#define EARTHRADIUS	6371.33
+
+volatile char *rcs="$Id: wwl.c,v 1.12 2007/10/15 19:53:08 db Exp db $";
+
+struct location {
+  double latitude;
+  double longitude;
+};
+
+static int is_valid_locator(const char wwl[]);
+static struct location convert_locator(char *wwl);
+static void upstring(char *s);
+static void bearing_dist(struct location *my_location,
+	struct location *dx_location, int *dist, int *bearing);
+static double rad_to_deg(double radians);
+static double deg_to_rad(double degrees);
+
+static int locator = 0;	/* Doing locator instead of wwl ? */
+
+int
+main (int argc, char **argv)
+{
+	int l, p;
+	struct location my_location, dx_location;
+	char my_wwl[SCRATCH_WWL_LEN], dx_wwl[SCRATCH_WWL_LEN];
+
+	if (argc < 2) {
+		printf("wwl/locator by va3db 1.0\n");
+		printf("wwl home_locator dx_locator or\n");
+		printf("locator locator\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (strcmp(basename(argv[0]), "locator") == 0) {
+		locator = 1;
+		if (argc != 2) {
+			fprintf(stderr,
+				"Usage: locator wwl\n");
+			exit(EXIT_FAILURE);
+		}
+	}  else {
+		if (argc != 3) {
+			fprintf(stderr,
+				"Usage: wwl home_locator dx_locator\n");
+			exit(EXIT_FAILURE);
+		}
+	}
+
+	snprintf(my_wwl, sizeof(my_wwl), "%sAA", argv[1]);
+	my_wwl[WWL_LEN] ='\0';
+	my_location = convert_locator(my_wwl);
+	if(!is_valid_locator(my_wwl)) {
+		fprintf(stderr, "%s: not a valid locator\n", my_wwl);
+		exit(EXIT_FAILURE);
+	}
+
+	if(locator) {
+		printf("Locator    : %s\n", my_wwl);
+		printf("Coordinates: Long: (%c) %.2f Lat : (%c) %.4f\n",
+		       (my_location.longitude < 0.) ? 'W' : 'E',
+		       rad_to_deg(my_location.longitude),
+		       (my_location.latitude > 0.) ? 'N' : 'S',
+		       rad_to_deg(my_location.latitude));
+		exit(EXIT_SUCCESS);
+	}
+
+	snprintf(dx_wwl, sizeof(dx_wwl), "%sAA", argv[2]);
+	dx_wwl[WWL_LEN] ='\0';
+	dx_location = convert_locator(dx_wwl);
+	if (!is_valid_locator(dx_wwl)) {
+		printf("%s: not a valid locator\n", dx_wwl);
+		exit(EXIT_FAILURE);
+	}
+
+	bearing_dist(&my_location, &dx_location, &p, &l);
+	printf("qrb: %d kilometers, azimuth: %d degrees\n", p, l);
+
+	exit(EXIT_SUCCESS);
+}
+
+/*
+ * is_valid_locator
+ * check for valid locator
+ *
+ * inputs	- string to locator
+ * output	- 1 if valid locator 0 if not
+ * side effects	-
+ */
+
+static int
+is_valid_locator(const char wwl[])
+{
+	if (strlen(wwl) != WWL_LEN)
+		return 0;
+
+	if (wwl[0] < 'A' || wwl[0] > 'R' ||
+	    wwl[1] < 'A' || wwl[1] > 'R' ||
+	    wwl[2] < '0' || wwl[2] > '9' ||
+	    wwl[3] < '0' || wwl[3] > '9' ||
+	    wwl[4] < 'A' || wwl[4] > 'X' ||
+	    wwl[5] < 'A' || wwl[5] > 'X' ) 
+		return(0);
+	else
+		return(1);
+}
+
+/*
+ * convert_locator
+ *
+ * inputs	- string to convert
+ * output	- return a struct location
+ * side effects	- none
+ */
+
+static struct location
+convert_locator(char *wwl)
+{
+	struct location loc;
+	upstring(wwl);
+
+	loc.latitude = (double)(wwl[1] - 'A') * 10 - 90 +
+		(double)(wwl[3] - '0') + (double)(wwl[5] - 'A') / 24 + 1 / 48;
+	loc.latitude = deg_to_rad(loc.latitude);
+	loc.longitude = (double)(wwl[0] - 'A') * 20. - 180. +
+		(double)(wwl[2] - '0') * 2 +
+		(double)(wwl[4] - 'A') / 12 + 1 / 24;
+	loc.longitude = deg_to_rad(loc.longitude);
+	return(loc);
+}
+
+/*
+ * upstring
+ * convert string to upper case
+ *
+ * inputs	- string to convert to upper case modified in place
+ */
+static void
+upstring(char *s)
+{
+	while(*s != '\0') {
+		*s = toupper(*s);
+		s++;
+	}
+}
+
+/*
+ * Convert degrees to radians
+ *
+ * input	- degrees
+ * output	- radians
+ * side effects	- none
+ */
+static double
+deg_to_rad(double degrees)
+{
+	return(degrees/180.) * M_PI;
+}
+
+/*
+ * Convert radians to degrees
+ *
+ * input	- radians
+ * output	- degrees
+ * side effects	- none
+ */
+static double
+rad_to_deg(double radians)
+{
+	return((radians/M_PI) * 180.);
+}
+
+/*
+ *
+ * Given location of start and location of end, calculate
+ * bearing and azimuth
+ *
+ * inputs	- pointer to my location
+ *		- pointer to dx location
+ * 		- pointer to result for dist
+ *		- pointer to result for bearing
+ * output	- dist and bearing as integer
+ * side effects	- none
+ */
+static void
+bearing_dist(struct location *my_location, struct location *dx_location,
+	     int *dist, int *bearing)
+{
+	double co, he, e, hn, n, ca, az;
+
+	hn = my_location->latitude;
+	he = my_location->longitude;
+	n = dx_location->latitude;
+	e = dx_location->longitude;
+
+	co = cos(he - e) * cos(hn) * cos(n) + sin(hn) * sin(n);
+	ca = atan2(sqrt(1 - pow(co,2)), co); 
+	az = atan2(sin(e - he) * cos(n) * cos(hn), sin(n) - sin(hn) * cos(ca));
+	if( az < 0)
+		az += 2 * M_PI;
+
+	/* Round up azimuth */
+	*bearing = (double)((int)((rad_to_deg(az) * 10.) + 5))/10;
+	/* Round up distance */
+	*dist = (double)((int)(EARTHRADIUS * ca * 10. + 5))/10;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/wwl.git



More information about the pkg-hamradio-commits mailing list