Maidenhead locator converter
I wrote a little program to convert between Maidenhead locators and GPS coordinates. There are plenty of these things out there, and, being a terminal program, it's probably not going to be too useful for you, but I figured I'd put it up anyways.
Here's the source file (C source file, 8.46 KB). It's a txt file because Neocities doesn't allow free accounts to upload a file with a .c extension, even though it's literally just plain text. Just replace the txt in the extension with c. You're smart. You can figure it out.
To build it, just run cc -o maidenhead maidenhead.c -lm
.
(Or, you know, whatever C compiler you wanna use.) This should work on
any system that supports C99 with POSIX extensions. It's pretty basic
stuff. (I mean, hell, it might even work with C89 with POSIX extensions,
but fuck if I know. But it's definitely nothing fancier than C99. I
never bothered to learn features in newer C standards, so I don't use
them.)
To use it, you run the program with one of two sets of options. If you
have a Maidenhead locator and want coordinates, run the program with
-M locator
, where locator
is
the locator you want the coordinates for. If you have coordinates and
want the Maidenhead locator, run the program with
-L latitude longitude
, where
latitude longitude
are the decimal coordinates with
north/east coordinates being positive numbers and south/west coordinates
being negative numbers. (So, for instance, give 30° N 40° W as
30 -40
). By default, it will print the Maidenhead locator
to square precision. If you want more or less, add on the
-p precision
option, where
precision
is an integer between 1 and 5. (1 gives
field (e.g. FN), 2 gives square (e.g. FN31), 3 gives subsquare
(e.g. FN31PR), 4 gives extended squares, and 5 gives extended
subsquares.) If you put in an integer less than 1, it'll give an error.
If you put in an integer more than 5, it'll work, but will still only
give extended subsquare precision. This option does nothing if you're
trying to convert from Maidenhead to coordinates.
A couple of notes and disclaimers:
-
If you give it both
-M
and-L
options, it'll use whichever came last. So, like, using the options-L 38 -43 -M HM45
will convert the locator HM45 into GPS coordinates and ignore the given coordinates. (Actually, I'm only just now realizing that's not true. It'll load the last set of coordinates into the variables for latitude and longitude and so your final coordinates will be off by whatever the last set of coordinates you entered were. Fuck it. I'm leaving it. One, I can't be bothered to go back and fix it. Two, I guess you could use it to figure out what a given coordinate offset from some locator is. So using that set of options would tell you what 38° north and 43° west of HM45 is. Use it as you will, I suppose. Note that this doesn't affect going from coordinates into Maidenhead, just Maidenhead to coordinates.) - When going from a locator to coordinates, it prints the coordinates of the center of the square. This is because IARU says that any locator refers to the center of that locator. So, like, EM refers to 35° N, 90° W.
- Also, when converting from a locator with precision beyond the extended square, it assumes a continuation of the 24/10 pattern. Apparently, so people define extensions differently? So, yeah. Uh, see disclaimer 1 below.
- DISCLAIMER 1: I do not guarantee the accuracy of this beyond the extended square level. Up to that point, it matches up with a different converter I was using for testing, but beyond that it doesn't. I'm pretty sure this is correct based on how IARU defines extended subsquares, but fuck if I know. Use extended subsquares at your own risk.
- DISCLAIMER 2: Strictly speaking, I do not guarantee the accuracy of anything this spits out. It should be correct as long as you gave it valid coordinates or a valid locator, but fuck if I know. Use this at your own risk.
-
DISCLAIMER 3: This program does basically no input
validation. It does not make sure the coordinate you entered are valid
coordinates. If you give it
1337 -420
, it will spit out a Maidenhead locator (maybe). It really only makes sure entered coordinates are valid floats, and that's because it uses theatof
function. It does not make sure locators entered are valid locators. It will spit out coordinates if you give it random characters. I expect you to use your brain and give it valid inputs. If you don't, the behaviour is entirely on you. - Why, yes, the source code does mix tabs and spaces. I wrote it in nano, where I didn't know how to make tabs equal to 2 spaces, so I used spaces. But I wrote the comments in Notepad++, where I thought I had tab to put 2 spaces, but apparently I had it set to make tabs actual tabs that display as 2 spaces. So, yeah. Not gonna fix it. Everyone gets to be pissed off at this code.
I was going to put this under the Clumsy Wolf Public License, but that seems overkill for this stupid, silly little thing, so, uh, fuck it. 0BSD. I'd appreciate credit if you use this as a basis for something else, but, have your fun, I guess.
Zero-Clause BSD
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.