2001-12-27 22:01:34 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/*
|
2001-12-27 22:01:34 +00:00
|
|
|
|
* Very simple test program to check locator convertion against some other --SF
|
|
|
|
|
* This is mainly to test longlat2locator and locator2longlat functions.
|
|
|
|
|
*
|
2003-09-12 03:15:23 +00:00
|
|
|
|
* Takes at least two arguments, which is a locator and desired locater
|
|
|
|
|
* precision in pairs, e.g. EM19ov is three pairs. precision is limited
|
|
|
|
|
* to >= 1 or <= 6. If two locators are given, then the qrb is also
|
|
|
|
|
* calculated.
|
|
|
|
|
*
|
2004-01-16 21:19:03 +00:00
|
|
|
|
* $Id: testloc.c,v 1.12 2004-01-16 21:19:03 fillods Exp $
|
2003-09-12 03:15:23 +00:00
|
|
|
|
*
|
2001-12-27 22:01:34 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2004-01-16 21:19:03 +00:00
|
|
|
|
#include <string.h>
|
2001-12-27 22:01:34 +00:00
|
|
|
|
#include <hamlib/rotator.h>
|
|
|
|
|
|
|
|
|
|
|
2003-08-21 03:11:27 +00:00
|
|
|
|
int main (int argc, char *argv[]) {
|
2003-11-03 04:26:37 +00:00
|
|
|
|
char recodedloc[13], *loc1, *loc2, sign;
|
2003-09-12 03:15:23 +00:00
|
|
|
|
double lon1, lat1, lon2, lat2;
|
2003-11-03 04:26:37 +00:00
|
|
|
|
double distance, az, mmm, sec;
|
|
|
|
|
int deg, min, retcode, loc_len, nesw = 0;
|
2001-12-27 22:01:34 +00:00
|
|
|
|
|
2004-01-16 21:19:03 +00:00
|
|
|
|
if (argc < 2) {
|
2003-08-21 20:22:06 +00:00
|
|
|
|
fprintf(stderr, "Usage: %s <locator1> <precision> [<locator2>]\n", argv[0]);
|
2003-08-19 21:28:22 +00:00
|
|
|
|
exit(1);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loc1 = argv[1];
|
2004-01-16 21:19:03 +00:00
|
|
|
|
loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1)/2;
|
2003-08-21 20:22:06 +00:00
|
|
|
|
loc2 = argc > 3 ? argv[3] : NULL;
|
2001-12-27 22:01:34 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf("Locator1:\t%s\n", loc1);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert maidenhead to decimal degrees */
|
2002-08-22 23:42:20 +00:00
|
|
|
|
retcode = locator2longlat(&lon1, &lat1, loc1);
|
2003-08-19 21:28:22 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2002-08-22 23:42:20 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* hamlib function to convert decimal degrees to deg, min, sec */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dms(lon1, °, &min, &sec, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" Longitude:\t%f\t%c%d<> %d' %.2f\"\n", lon1, sign, deg, min, sec);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
|
|
|
|
/* hamlib function to convert deg, min, sec to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lon1 = dms2dec(deg, min, sec, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded lon:\t%f\n", lon1);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dmmm(lon1, °, &mmm, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" GPS lon:\t%f\t%c%d<> %.3f'\n", lon1, sign, deg, mmm);
|
2002-08-22 23:42:20 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* hamlib function to convert deg, decimal min to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lon1 = dmmm2dec(deg, mmm, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded GPS:\t%f\n", lon1);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert decimal degrees to deg, min, sec */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dms(lat1, °, &min, &sec, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" Latitude:\t%f\t%c%d<> %d' %.2f\"\n", lat1, sign, deg, min, sec);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
|
|
|
|
/* hamlib function to convert deg, min, sec to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lat1 = dms2dec(deg, min, sec, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded lat:\t%f\n", lat1);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dmmm(lat1, °, &mmm, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" GPS lat:\t%f\t%c%d<> %.3f'\n", lat1, sign, deg, mmm);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
|
|
|
|
/* hamlib function to convert deg, decimal min to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lat1 = dmmm2dec(deg, mmm, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded GPS:\t%f\n", lat1);
|
2002-08-22 23:42:20 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* hamlib function to convert decimal degrees to maidenhead */
|
|
|
|
|
retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
|
2003-08-21 20:37:10 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded:\t%s\n", recodedloc);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
|
|
|
|
|
if (loc2 == NULL)
|
2003-08-21 20:22:06 +00:00
|
|
|
|
exit(0);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* Now work on the second locator */
|
|
|
|
|
printf("\nLocator2:\t%s\n", loc2);
|
|
|
|
|
|
2002-08-22 23:42:20 +00:00
|
|
|
|
retcode = locator2longlat(&lon2, &lat2, loc2);
|
2003-08-19 21:28:22 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2002-08-22 23:42:20 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* hamlib function to convert decimal degrees to deg, min, sec */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dms(lon2, °, &min, &sec, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" Longitude:\t%f\t%c%d<> %d' %.2f\"\n", lon2, sign, deg, min, sec);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
|
|
|
|
/* hamlib function to convert deg, min, sec to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lon2 = dms2dec(deg, min, sec, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded lon:\t%f\n", lon2);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dmmm(lon2, °, &mmm, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" GPS lon:\t%f\t%c%d<> %.3f'\n", lon2, sign, deg, mmm);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
|
|
|
|
/* hamlib function to convert deg, decimal min to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lon2 = dmmm2dec(deg, mmm, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded GPS:\t%f\n", lon2);
|
2002-08-22 23:42:20 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* hamlib function to convert decimal degrees to deg, min, sec */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dms(lat2, °, &min, &sec, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" Latitude:\t%f\t%c%d<> %d' %.2f\"\n", lat2, sign, deg, min, sec);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
|
|
|
|
/* hamlib function to convert deg, min, sec to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lat2 = dms2dec(deg, min, sec, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded lat:\t%f\n", lat2);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert decimal degrees to deg decimal minutes */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
retcode = dec2dmmm(lat2, °, &mmm, &nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
printf(" GPS lat:\t%f\t%c%d<> %.3f'\n", lat2, sign, deg, mmm);
|
2002-08-22 23:42:20 +00:00
|
|
|
|
|
2003-09-12 03:15:23 +00:00
|
|
|
|
/* hamlib function to convert deg, decimal min to decimal degrees */
|
2003-11-03 04:26:37 +00:00
|
|
|
|
lat2 = dmmm2dec(deg, mmm, nesw);
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded GPS:\t%f\n", lat2);
|
|
|
|
|
|
|
|
|
|
/* hamlib function to convert decimal degrees to maidenhead */
|
|
|
|
|
retcode = longlat2locator(lon2, lat2, recodedloc, loc_len);
|
2003-08-21 20:37:10 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
|
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2003-09-12 03:15:23 +00:00
|
|
|
|
printf(" Recoded:\t%s\n", recodedloc);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
|
2002-08-22 23:42:20 +00:00
|
|
|
|
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (retcode != RIG_OK) {
|
2003-08-21 20:37:10 +00:00
|
|
|
|
fprintf(stderr, "QRB error: %d\n", retcode);
|
|
|
|
|
exit(2);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
}
|
2003-09-12 03:15:23 +00:00
|
|
|
|
|
2003-11-03 04:26:37 +00:00
|
|
|
|
dec2dms(az, °, &min, &sec, &nesw);
|
2003-10-28 01:01:06 +00:00
|
|
|
|
printf("\nDistance: %.6fkm\n", distance);
|
2003-11-03 04:26:37 +00:00
|
|
|
|
if (nesw == 1)
|
|
|
|
|
sign = '-';
|
|
|
|
|
else
|
|
|
|
|
sign = '\0';
|
|
|
|
|
/* Beware printf() rounding error! */
|
|
|
|
|
printf("Bearing: %.2f, %c%d<> %d' %.2f\"\n", az, sign, deg, min, sec);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
|
2003-08-21 20:37:10 +00:00
|
|
|
|
exit(0);
|
2001-12-27 22:01:34 +00:00
|
|
|
|
}
|