32 |
* Compile with: gcc -lm -o wwl wwl.c |
* Compile with: gcc -lm -o wwl wwl.c |
33 |
* |
* |
34 |
* $Log$ |
* $Log$ |
35 |
|
* Revision 1.6 2003/08/10 16:48:48 fillods |
36 |
|
* Added wwl_dist(), which computes distance in Km between 2 locators. |
37 |
|
* logfile/EDI needs such a function. |
38 |
|
* |
39 |
* Revision 1.5 2003/06/24 07:29:42 fillods |
* Revision 1.5 2003/06/24 07:29:42 fillods |
40 |
* allow locator computation with partial information (use center of grid for missing part). Fix a bug in error msg with invalid locator. |
* allow locator computation with partial information (use center of grid for missing part). Fix a bug in error msg with invalid locator. |
41 |
* |
* |
70 |
extern preferencestype preferences; |
extern preferencestype preferences; |
71 |
extern GtkWidget *mainwindow; |
extern GtkWidget *mainwindow; |
72 |
|
|
73 |
|
/* return distance in Km */ |
74 |
|
gdouble |
75 |
|
wwl_dist (gchar * my, gchar * dx) |
76 |
|
{ |
77 |
|
gint strlen_dx; |
78 |
|
gdouble z, y, n, h, x, w, t, s, v, u, c, d; |
79 |
|
gchar my_wwl[7], dx_wwl[7] = "AA55MM"; |
80 |
|
|
81 |
|
if (strlen (my) != 6) |
82 |
|
{ |
83 |
|
return -1; |
84 |
|
} |
85 |
|
|
86 |
|
strlen_dx = strlen (dx); |
87 |
|
if (strlen_dx < 2 || strlen_dx > 6) |
88 |
|
{ |
89 |
|
return -1; |
90 |
|
} |
91 |
|
|
92 |
|
strcpy (my_wwl, my); |
93 |
|
memcpy (dx_wwl, dx, strlen_dx); |
94 |
|
|
95 |
|
my_wwl[0] = toupper (my_wwl[0]); |
96 |
|
z = my_wwl[0] - 65; |
97 |
|
my_wwl[1] = toupper (my_wwl[1]); |
98 |
|
y = my_wwl[1] - 65; |
99 |
|
n = my_wwl[2] - 48; |
100 |
|
h = my_wwl[3] - 48; |
101 |
|
my_wwl[4] = toupper (my_wwl[4]); |
102 |
|
x = my_wwl[4] - 65; |
103 |
|
my_wwl[5] = toupper (my_wwl[5]); |
104 |
|
w = my_wwl[5] - 65; |
105 |
|
|
106 |
|
if (my_wwl[0] < 65 || my_wwl[0] > 88 || my_wwl[1] < 65 || my_wwl[1] > 88 || |
107 |
|
my_wwl[2] < 48 || my_wwl[2] > 57 || my_wwl[3] < 48 || my_wwl[3] > 57 || |
108 |
|
my_wwl[4] < 65 || my_wwl[4] > 88 || my_wwl[5] < 65 || my_wwl[5] > 88) |
109 |
|
{ |
110 |
|
return -1; |
111 |
|
} |
112 |
|
|
113 |
|
t = z * 20 - 180 + n * 2 + x / 12 + 1.0 / 24; |
114 |
|
t = t * 3.1415926 / 180; |
115 |
|
s = y * 10 - 90 + h + w / 24 + 1.0 / 48; |
116 |
|
s = s * 3.1415926 / 180; |
117 |
|
|
118 |
|
dx_wwl[0] = toupper (dx_wwl[0]); |
119 |
|
z = dx_wwl[0] - 65; |
120 |
|
dx_wwl[1] = toupper (dx_wwl[1]); |
121 |
|
y = dx_wwl[1] - 65; |
122 |
|
n = dx_wwl[2] - 48; |
123 |
|
h = dx_wwl[3] - 48; |
124 |
|
dx_wwl[4] = toupper (dx_wwl[4]); |
125 |
|
x = dx_wwl[4] - 65; |
126 |
|
dx_wwl[5] = toupper (dx_wwl[5]); |
127 |
|
w = dx_wwl[5] - 65; |
128 |
|
|
129 |
|
if (dx_wwl[0] < 65 || dx_wwl[0] > 88 || dx_wwl[1] < 65 || dx_wwl[1] > 88 || |
130 |
|
dx_wwl[2] < 48 || dx_wwl[2] > 57 || dx_wwl[3] < 48 || dx_wwl[3] > 57 || |
131 |
|
dx_wwl[4] < 65 || dx_wwl[4] > 88 || dx_wwl[5] < 65 || dx_wwl[5] > 88) |
132 |
|
{ |
133 |
|
return -1; |
134 |
|
} |
135 |
|
|
136 |
|
v = z * 20 - 180 + n * 2 + x / 12 + 1.0 / 24; |
137 |
|
v = v * 3.1415926 / 180; |
138 |
|
u = y * 10 - 90 + h + w / 24 + 1.0 / 48; |
139 |
|
u = u * 3.1415926 / 180; |
140 |
|
|
141 |
|
c = cos (s) * cos (u) * cos (v - t) + sin (s) * sin (u); |
142 |
|
d = 1 - c * c; |
143 |
|
|
144 |
|
return abs ((atan (sqrt (d) / c) * 6371.33) + .5); |
145 |
|
} |
146 |
|
|
147 |
static gchar * |
static gchar * |
148 |
wwl (gchar * my, gchar * dx) |
wwl (gchar * my, gchar * dx) |
149 |
{ |
{ |