kopia lustrzana https://github.com/Hamlib/Hamlib
fixed locator and dms conversion and also got rid of trunc usage, fixed misnamed 'bearing' references
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1134 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.4
rodzic
118b86574d
commit
0590079fb5
|
@ -70,8 +70,6 @@ dnl Checks for libraries.
|
||||||
AC_CHECK_FUNC(sin, [MATH_LIBS=""], [MATH_LIBS="-lm"])
|
AC_CHECK_FUNC(sin, [MATH_LIBS=""], [MATH_LIBS="-lm"])
|
||||||
AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"], [], [])
|
AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"], [], [])
|
||||||
|
|
||||||
# trunc is part of C99 only
|
|
||||||
AC_CHECK_LIB([c], [trunc], [], [AC_LIBOBJ(trunc)], [$MATH_LIBS])
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Interactive UNIX requires -linet instead of -lsocket, plus it
|
# Interactive UNIX requires -linet instead of -lsocket, plus it
|
||||||
# needs net/errno.h to define the socket-related error codes.
|
# needs net/errno.h to define the socket-related error codes.
|
||||||
|
@ -309,7 +307,6 @@ AC_SUBST(ROT_BACKENDEPS)
|
||||||
|
|
||||||
AC_SUBST(BINDING_LIST)
|
AC_SUBST(BINDING_LIST)
|
||||||
|
|
||||||
AC_LIBSOURCES([trunc.c])
|
|
||||||
AC_SUBST(INCLUDES)
|
AC_SUBST(INCLUDES)
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile
|
AC_CONFIG_FILES([Makefile
|
||||||
|
|
13
lib/trunc.c
13
lib/trunc.c
|
@ -1,13 +0,0 @@
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#ifndef HAVE_TRUNC
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
double
|
|
||||||
trunc (double x)
|
|
||||||
{
|
|
||||||
return round(x); /* FIXME !! */
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* !HAVE_TRUNC */
|
|
|
@ -2,16 +2,16 @@
|
||||||
* \file src/locator.c
|
* \file src/locator.c
|
||||||
* \brief Ham Radio Control Libraries interface
|
* \brief Ham Radio Control Libraries interface
|
||||||
* \author Stephane Fillod
|
* \author Stephane Fillod
|
||||||
* \date 2000-2001
|
* \date 2000-2002
|
||||||
*
|
*
|
||||||
* Hamlib interface is a frontend implementing wrapper functions.
|
* Hamlib interface is a frontend implementing wrapper functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hamlib Interface - locator and bearing conversion calls
|
* Hamlib Interface - locator and bearing conversion calls
|
||||||
* Copyright (c) 2001 by Stephane Fillod
|
* Copyright (c) 2001-2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: locator.c,v 1.2 2001-12-28 20:33:27 fillods Exp $
|
* $Id: locator.c,v 1.3 2002-08-22 23:42:20 fillods Exp $
|
||||||
*
|
*
|
||||||
* Code to determine bearing and range was taken from the Great Circle,
|
* Code to determine bearing and range was taken from the Great Circle,
|
||||||
* by S. R. Sampson, N5OWK.
|
* by S. R. Sampson, N5OWK.
|
||||||
|
@ -73,7 +73,10 @@
|
||||||
*/
|
*/
|
||||||
double dms2dec(int degrees, int minutes, int seconds)
|
double dms2dec(int degrees, int minutes, int seconds)
|
||||||
{
|
{
|
||||||
|
if (degrees >= 0)
|
||||||
return (double)degrees + (double)minutes/60. + (double)seconds/3600.;
|
return (double)degrees + (double)minutes/60. + (double)seconds/3600.;
|
||||||
|
else
|
||||||
|
return (double)degrees + 1. - (double)minutes/60. - (double)seconds/3600.;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,7 +111,6 @@ void dec2dms(double dec, int *degrees, int *minutes, int *seconds)
|
||||||
sec = (int)floor(st);
|
sec = (int)floor(st);
|
||||||
if (deg < 0 && sec != 0)
|
if (deg < 0 && sec != 0)
|
||||||
sec = 60 - sec;
|
sec = 60 - sec;
|
||||||
|
|
||||||
*degrees = deg;
|
*degrees = deg;
|
||||||
*minutes = min;
|
*minutes = min;
|
||||||
*seconds = sec;
|
*seconds = sec;
|
||||||
|
@ -159,12 +161,12 @@ int locator2longlat(double *longitude, double *latitude, const char *locator)
|
||||||
}
|
}
|
||||||
|
|
||||||
*longitude = 20.0 * (loc[0]-'A') - 180.0 + 2.0 * (loc[2]-'0') +
|
*longitude = 20.0 * (loc[0]-'A') - 180.0 + 2.0 * (loc[2]-'0') +
|
||||||
(loc[4]-'A')/12.0;
|
(loc[4]-'A')/12.0;
|
||||||
if (loc[0] <= 'I' && (loc[2] != '0' || loc[4] != 'A'))
|
if (loc[0] <= 'I' && (loc[2] != '0' || loc[4] != 'A'))
|
||||||
*longitude += 1;
|
*longitude += 1;
|
||||||
|
|
||||||
*latitude = 10.0 * (loc[1]-'A') - 90.0 + (loc[3]-'0') +
|
*latitude = 10.0 * (loc[1]-'A') - 90.0 + (loc[3]-'0') +
|
||||||
(loc[5]-'A')/24.0;
|
(loc[5]-'A')/24.0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -185,48 +187,51 @@ int locator2longlat(double *longitude, double *latitude, const char *locator)
|
||||||
void longlat2locator(double longitude, double latitude, char *locator)
|
void longlat2locator(double longitude, double latitude, char *locator)
|
||||||
{
|
{
|
||||||
double tmp;
|
double tmp;
|
||||||
|
int deg, min, sec;
|
||||||
|
|
||||||
|
tmp = fmod(longitude, 360) + 180.;
|
||||||
|
|
||||||
tmp = longitude + 180.;
|
|
||||||
locator[0] = 'A' + (int)floor(tmp/20.);
|
locator[0] = 'A' + (int)floor(tmp/20.);
|
||||||
tmp = fmod(tmp, 20.);
|
tmp = fmod(tmp, 20.);
|
||||||
locator[2] = '0' + (int)floor(tmp/2.);
|
locator[2] = '0' + (int)floor(tmp/2.);
|
||||||
tmp = 12.5*fmod(tmp, 2.);
|
tmp = 12.*fabs(floor(longitude)-longitude);
|
||||||
locator[4] = 'A' + (int)floor(tmp);
|
locator[4] = 'A' + (int)floor(tmp);
|
||||||
|
|
||||||
tmp = latitude + 90.;
|
tmp = fmod(latitude, 360) + 90.;
|
||||||
locator[1] = 'A' + (int)(tmp/10.);
|
|
||||||
|
locator[1] = 'A' + (int)floor(tmp/10.);
|
||||||
tmp = fmod(tmp, 10.);
|
tmp = fmod(tmp, 10.);
|
||||||
locator[3] = '0' + (int)tmp;
|
locator[3] = '0' + (int)floor(tmp);
|
||||||
tmp = 25. * (tmp - trunc(tmp));
|
tmp = 25. * fabs(floor(latitude)-latitude);
|
||||||
locator[5] = 'A' + (int)tmp;
|
locator[5] = 'A' + (int)floor(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Calculate the bearing and azimuth between two points.
|
* \brief Calculate the distance and bearing between two points.
|
||||||
* \param lon1 The local longitude, decimal degrees
|
* \param lon1 The local longitude, decimal degrees
|
||||||
* \param lat1 The local latitude, decimal degrees
|
* \param lat1 The local latitude, decimal degrees
|
||||||
* \param lon2 The remote longitude, decimal degrees
|
* \param lon2 The remote longitude, decimal degrees
|
||||||
* \param lat2 The remote latitude, decimal degrees
|
* \param lat2 The remote latitude, decimal degrees
|
||||||
* \param bearing The location where to store the bearing
|
* \param distance The location where to store the distance
|
||||||
* \param azimuth The location where to store the azimuth
|
* \param azimuth The location where to store the bearing
|
||||||
*
|
*
|
||||||
* Calculate the QRB between \a lat1,\a lat1 and
|
* Calculate the QRB between \a lat1,\a lat1 and
|
||||||
* \a lon2,\a lat2, and return the bearing in kilometers and
|
* \a lon2,\a lat2, and return the distance in kilometers and
|
||||||
* azimuth in decimal degrees for the short path.
|
* azimuth in decimal degrees for the short path.
|
||||||
*
|
*
|
||||||
* This version also takes into consideration the two points
|
* This version also takes into consideration the two points
|
||||||
* being close enough to be in the near-field, and the antipodal points,
|
* being close enough to be in the near-field, and the antipodal points,
|
||||||
* which are easily calculated.
|
* which are easily calculated.
|
||||||
*
|
*
|
||||||
* \sa bearing_long_path(), azimuth_long_path()
|
* \sa distance_long_path(), azimuth_long_path()
|
||||||
*/
|
*/
|
||||||
int qrb(double lon1, double lat1, double lon2, double lat2,
|
int qrb(double lon1, double lat1, double lon2, double lat2,
|
||||||
double *bearing, double *azimuth)
|
double *distance, double *azimuth)
|
||||||
{
|
{
|
||||||
double delta_long, tmp, arc, cosaz, az;
|
double delta_long, tmp, arc, cosaz, az;
|
||||||
|
|
||||||
if (!bearing || !azimuth)
|
if (!distance || !azimuth)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0))
|
if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0))
|
||||||
|
@ -261,7 +266,7 @@ int qrb(double lon1, double lat1, double lon2, double lat2,
|
||||||
|
|
||||||
if (tmp > .999999) {
|
if (tmp > .999999) {
|
||||||
/* Station points coincide, use an Omni! */
|
/* Station points coincide, use an Omni! */
|
||||||
*bearing = 0.0;
|
*distance = 0.0;
|
||||||
*azimuth = 0.0;
|
*azimuth = 0.0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +279,7 @@ int qrb(double lon1, double lat1, double lon2, double lat2,
|
||||||
* and you get 10800 nm, or whatever units...
|
* and you get 10800 nm, or whatever units...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*bearing = 180.0*ARC_IN_KM;
|
*distance = 180.0*ARC_IN_KM;
|
||||||
*azimuth = 0.0;
|
*azimuth = 0.0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -289,7 +294,7 @@ int qrb(double lon1, double lat1, double lon2, double lat2,
|
||||||
|
|
||||||
/* Short Path */
|
/* Short Path */
|
||||||
|
|
||||||
*bearing = ARC_IN_KM * RADIAN * arc;
|
*distance = ARC_IN_KM * RADIAN * arc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Long Path
|
* Long Path
|
||||||
|
@ -320,9 +325,9 @@ int qrb(double lon1, double lat1, double lon2, double lat2,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bearing_long_path(double bearing)
|
double distance_long_path(double distance)
|
||||||
{
|
{
|
||||||
return (ARC_IN_KM * 360.0) - bearing;
|
return (ARC_IN_KM * 360.0) - distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
double azimuth_long_path(double azimuth)
|
double azimuth_long_path(double azimuth)
|
||||||
|
|
|
@ -16,7 +16,7 @@ int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char recodedloc[8], *loc1, *loc2;
|
char recodedloc[8], *loc1, *loc2;
|
||||||
double lon1, lat1, lon2, lat2;
|
double lon1, lat1, lon2, lat2;
|
||||||
double bearing, az;
|
double distance, az;
|
||||||
int deg, min, sec;
|
int deg, min, sec;
|
||||||
int retcode;
|
int retcode;
|
||||||
|
|
||||||
|
@ -28,12 +28,19 @@ int main (int argc, char *argv[])
|
||||||
loc1 = argv[1];
|
loc1 = argv[1];
|
||||||
loc2 = argc > 2 ? argv[2] : NULL;
|
loc2 = argc > 2 ? argv[2] : NULL;
|
||||||
|
|
||||||
retcode = locator2longlat(&lon1, &lat1, loc1);
|
|
||||||
printf("Locator1: %s\n", loc1);
|
printf("Locator1: %s\n", loc1);
|
||||||
|
retcode = locator2longlat(&lon1, &lat1, loc1);
|
||||||
|
|
||||||
dec2dms(lon1, °, &min, &sec);
|
dec2dms(lon1, °, &min, &sec);
|
||||||
printf(" Longitude: %f, %d° %d' %d\"\n", lon1, deg, min, sec);
|
printf(" Longitude: %f, %d° %d' %d\"\n", lon1, deg, min, sec);
|
||||||
|
lon1 = dms2dec(deg, min, sec);
|
||||||
|
printf(" Recoded lon: %f\n", lon1);
|
||||||
|
|
||||||
dec2dms(lat1, °, &min, &sec);
|
dec2dms(lat1, °, &min, &sec);
|
||||||
printf(" Latitude: %f, %d° %d' %d\"\n", lat1, deg, min, sec);
|
printf(" Latitude: %f, %d° %d' %d\"\n", lat1, deg, min, sec);
|
||||||
|
lat1 = dms2dec(deg, min, sec);
|
||||||
|
printf(" Recoded lat: %f\n", lat1);
|
||||||
|
|
||||||
longlat2locator(lon1, lat1, recodedloc);
|
longlat2locator(lon1, lat1, recodedloc);
|
||||||
recodedloc[6] = '\0';
|
recodedloc[6] = '\0';
|
||||||
printf(" Recoded: %s\n", recodedloc);
|
printf(" Recoded: %s\n", recodedloc);
|
||||||
|
@ -41,24 +48,31 @@ int main (int argc, char *argv[])
|
||||||
if (loc2 == NULL)
|
if (loc2 == NULL)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
retcode = locator2longlat(&lon2, &lat2, loc2);
|
|
||||||
printf("\nLocator2: %s\n", loc2);
|
printf("\nLocator2: %s\n", loc2);
|
||||||
|
retcode = locator2longlat(&lon2, &lat2, loc2);
|
||||||
|
|
||||||
dec2dms(lon2, °, &min, &sec);
|
dec2dms(lon2, °, &min, &sec);
|
||||||
printf(" Longitude: %f, %d° %d' %d\"\n", lon2, deg, min, sec);
|
printf(" Longitude: %f, %d° %d' %d\"\n", lon2, deg, min, sec);
|
||||||
|
lon2 = dms2dec(deg, min, sec);
|
||||||
|
printf(" Recoded lon: %f\n", lon2);
|
||||||
|
|
||||||
dec2dms(lat2, °, &min, &sec);
|
dec2dms(lat2, °, &min, &sec);
|
||||||
printf(" Latitude: %f, %d° %d' %d\"\n", lat2, deg, min, sec);
|
printf(" Latitude: %f, %d° %d' %d\"\n", lat2, deg, min, sec);
|
||||||
|
lat2 = dms2dec(deg, min, sec);
|
||||||
|
printf(" Recoded lat: %f\n", lat2);
|
||||||
|
|
||||||
longlat2locator(lon2, lat2, recodedloc);
|
longlat2locator(lon2, lat2, recodedloc);
|
||||||
recodedloc[6] = '\0';
|
recodedloc[6] = '\0';
|
||||||
printf(" Recoded: %s\n", recodedloc);
|
printf(" Recoded: %s\n", recodedloc);
|
||||||
|
|
||||||
retcode = qrb(lon1, lat1, lon2, lat2, &bearing, &az);
|
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
|
||||||
if (retcode != 0) {
|
if (retcode != 0) {
|
||||||
fprintf(stderr, "QRB error: %d\n", retcode);
|
fprintf(stderr, "QRB error: %d\n", retcode);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
dec2dms(az, °, &min, &sec);
|
dec2dms(az, °, &min, &sec);
|
||||||
printf("\nBearing: %.2fkm\n", bearing);
|
printf("\nDistance: %.2fkm\n", distance);
|
||||||
printf("Azimuth: %f, %d° %d' %d\"\n", az, deg, min, sec);
|
printf("Bearing: %f, %d° %d' %d\"\n", az, deg, min, sec);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue