summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2014-02-09 03:26:18 +0100
committerDirk Engling <erdgeist@erdgeist.org>2014-02-09 03:26:18 +0100
commitec0bcde794bcb6fa2a93e09a7c1a64dd69e96260 (patch)
treec1488cf94c6c5aa1ab833b199801a33c947215f7 /src
parent1355cf71ab12e382f72aa7ac2cfaa4bc06936127 (diff)
Make convertcoords properly work with empty lines
Diffstat (limited to 'src')
-rw-r--r--src/convertcoords.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/convertcoords.c b/src/convertcoords.c
index 3297d8f..37d780a 100644
--- a/src/convertcoords.c
+++ b/src/convertcoords.c
@@ -3,32 +3,38 @@
3#include <math.h> 3#include <math.h>
4int main(int argc, char *argv[]) 4int main(int argc, char *argv[])
5{ 5{
6 double x = atof(argv[1]); 6 double x, y;
7 double y = atof(argv[2]); 7 char buf[64];
8 int in;
9 while( fgets( buf, sizeof(buf), stdin ) )
10 {
11 if( sscanf( buf, "%lf %lf", &x, &y ) == 2 ) {
12 double R = 6365000;
13 double fe = 5200000;
14 double fn = 1200000;
15 double ph0 = 0.5235977; // 30deg
16 double ph1 = 0.7853980; // 45deg
17 double ph2 = 0.9599309; // 55deg
18 double l0 = 0.1745329; // 10deg
8 19
9 double R = 6365000; 20 double xs = (x-fe)/R;
10 double fe = 5200000; 21 double ys = (y-fn)/R;
11 double fn = 1200000; 22 double ph0_s = 0.25*M_PI+0.5*ph0;
12 double ph0 = 0.5235977; // 30deg 23 double ph1_s = 0.25*M_PI+0.5*ph1;
13 double ph1 = 0.7853980; // 45deg 24 double ph2_s = 0.25*M_PI+0.5*ph2;
14 double ph2 = 0.9599309; // 55deg
15 double l0 = 0.1745329; // 10deg
16 25
17 double xs = (x-fe)/R; 26 double n = log(cos(ph1)/cos(ph2))/log(tan(ph2_s)/tan(ph1_s));
18 double ys = (y-fn)/R; 27 double F = cos(ph1)*pow(tan(ph1_s),n)/n;
19 double ph0_s = 0.25*M_PI+0.5*ph0; 28 double r0 = F / pow(tan(ph0_s),n);
20 double ph1_s = 0.25*M_PI+0.5*ph1; 29 double r = sqrt(pow(xs,2)+pow(r0-ys,2));
21 double ph2_s = 0.25*M_PI+0.5*ph2; 30 double th = atan(xs/(r0-ys));
22 31
23 double n = log(cos(ph1)/cos(ph2))/log(tan(ph2_s)/tan(ph1_s)); 32 double lon = l0+th/n;
24 double F = cos(ph1)*pow(tan(ph1_s),n)/n; 33 double lat = 2.0*atan(pow(F/r,1.0/n))-0.5*M_PI;
25 double r0 = F / pow(tan(ph0_s),n);
26 double r = sqrt(pow(xs,2)+pow(r0-ys,2));
27 double th = atan(xs/(r0-ys));
28 34
29 double lon = l0+th/n; 35 printf("%lf\t%lf\n", lat*180.0/M_PI, lon*180.0/M_PI);
30 double lat = 2.0*atan(pow(F/r,1.0/n))-0.5*M_PI; 36 } else
31 37 printf("\t\n");
32 printf("%f %f", lat*180.0/M_PI, lon*180.0/M_PI); 38 }
33 return 0; 39 return 0;
34} 40}