[go: up one dir, main page]

Menu

[073328]: / tests / testloc.c  Maximize  Restore  History

Download this file

217 lines (184 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Very simple test program to check locator convertion against some other --SF
* This is mainly to test longlat2locator and locator2longlat functions.
*
* 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.
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hamlib/rotator.h>
int main (int argc, char *argv[]) {
char recodedloc[13], *loc1, *loc2, sign;
double lon1, lat1, lon2, lat2;
double distance, az, mmm, sec;
int deg, min, retcode, loc_len, nesw = 0;
if (argc < 2) {
fprintf(stderr, "Usage: %s <locator1> <precision> [<locator2>]\n", argv[0]);
exit(1);
}
loc1 = argv[1];
loc_len = argc > 2 ? atoi(argv[2]) : strlen(loc1)/2;
loc2 = argc > 3 ? argv[3] : NULL;
printf("Locator1:\t%s\n", loc1);
/* hamlib function to convert maidenhead to decimal degrees */
retcode = locator2longlat(&lon1, &lat1, loc1);
if (retcode != RIG_OK) {
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lon1, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Longitude:\t%f\t%c%d %d' %.2f\"\n", lon1, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */
lon1 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lon:\t%f\n", lon1);
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lon1, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon1, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */
lon1 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lon1);
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lat1, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat1, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */
lat1 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lat:\t%f\n", lat1);
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lat1, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat1, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */
lat1 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lat1);
/* hamlib function to convert decimal degrees to maidenhead */
retcode = longlat2locator(lon1, lat1, recodedloc, loc_len);
if (retcode != RIG_OK) {
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
exit(2);
}
printf(" Recoded:\t%s\n", recodedloc);
if (loc2 == NULL)
exit(0);
/* Now work on the second locator */
printf("\nLocator2:\t%s\n", loc2);
retcode = locator2longlat(&lon2, &lat2, loc2);
if (retcode != RIG_OK) {
fprintf(stderr, "locator2longlat() failed with malformed input.\n");
exit(2);
}
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lon2, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Longitude:\t%f\t%c%d %d' %.2f\"\n", lon2, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */
lon2 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lon:\t%f\n", lon2);
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lon2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lon:\t%f\t%c%d %.3f'\n", lon2, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */
lon2 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lon2);
/* hamlib function to convert decimal degrees to deg, min, sec */
retcode = dec2dms(lat2, &deg, &min, &sec, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dms() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" Latitude:\t%f\t%c%d %d' %.2f\"\n", lat2, sign, deg, min, sec);
/* hamlib function to convert deg, min, sec to decimal degrees */
lat2 = dms2dec(deg, min, sec, nesw);
printf(" Recoded lat:\t%f\n", lat2);
/* hamlib function to convert decimal degrees to deg decimal minutes */
retcode = dec2dmmm(lat2, &deg, &mmm, &nesw);
if (retcode != RIG_OK) {
fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n");
exit(2);
}
if (nesw == 1)
sign = '-';
else
sign = '\0';
printf(" GPS lat:\t%f\t%c%d %.3f'\n", lat2, sign, deg, mmm);
/* hamlib function to convert deg, decimal min to decimal degrees */
lat2 = dmmm2dec(deg, mmm, nesw);
printf(" Recoded GPS:\t%f\n", lat2);
/* hamlib function to convert decimal degrees to maidenhead */
retcode = longlat2locator(lon2, lat2, recodedloc, loc_len);
if (retcode != RIG_OK) {
fprintf(stderr, "longlat2locator() failed, precision out of range.\n");
exit(2);
}
printf(" Recoded:\t%s\n", recodedloc);
retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az);
if (retcode != RIG_OK) {
fprintf(stderr, "QRB error: %d\n", retcode);
exit(2);
}
dec2dms(az, &deg, &min, &sec, &nesw);
printf("\nDistance: %.6fkm\n", distance);
if (nesw == 1)
sign = '-';
else
sign = '\0';
/* Beware printf() rounding error! */
printf("Bearing: %.2f, %c%d %d' %.2f\"\n", az, sign, deg, min, sec);
exit(0);
}