From ec0bcde794bcb6fa2a93e09a7c1a64dd69e96260 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 9 Feb 2014 03:26:18 +0100 Subject: Make convertcoords properly work with empty lines --- src/convertcoords.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'src/convertcoords.c') 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 @@ #include int main(int argc, char *argv[]) { - double x = atof(argv[1]); - double y = atof(argv[2]); + double x, y; + char buf[64]; + int in; + while( fgets( buf, sizeof(buf), stdin ) ) + { + if( sscanf( buf, "%lf %lf", &x, &y ) == 2 ) { + double R = 6365000; + double fe = 5200000; + double fn = 1200000; + double ph0 = 0.5235977; // 30deg + double ph1 = 0.7853980; // 45deg + double ph2 = 0.9599309; // 55deg + double l0 = 0.1745329; // 10deg - double R = 6365000; - double fe = 5200000; - double fn = 1200000; - double ph0 = 0.5235977; // 30deg - double ph1 = 0.7853980; // 45deg - double ph2 = 0.9599309; // 55deg - double l0 = 0.1745329; // 10deg + double xs = (x-fe)/R; + double ys = (y-fn)/R; + double ph0_s = 0.25*M_PI+0.5*ph0; + double ph1_s = 0.25*M_PI+0.5*ph1; + double ph2_s = 0.25*M_PI+0.5*ph2; - double xs = (x-fe)/R; - double ys = (y-fn)/R; - double ph0_s = 0.25*M_PI+0.5*ph0; - double ph1_s = 0.25*M_PI+0.5*ph1; - double ph2_s = 0.25*M_PI+0.5*ph2; + double n = log(cos(ph1)/cos(ph2))/log(tan(ph2_s)/tan(ph1_s)); + double F = cos(ph1)*pow(tan(ph1_s),n)/n; + double r0 = F / pow(tan(ph0_s),n); + double r = sqrt(pow(xs,2)+pow(r0-ys,2)); + double th = atan(xs/(r0-ys)); - double n = log(cos(ph1)/cos(ph2))/log(tan(ph2_s)/tan(ph1_s)); - double F = cos(ph1)*pow(tan(ph1_s),n)/n; - double r0 = F / pow(tan(ph0_s),n); - double r = sqrt(pow(xs,2)+pow(r0-ys,2)); - double th = atan(xs/(r0-ys)); + double lon = l0+th/n; + double lat = 2.0*atan(pow(F/r,1.0/n))-0.5*M_PI; - double lon = l0+th/n; - double lat = 2.0*atan(pow(F/r,1.0/n))-0.5*M_PI; - - printf("%f %f", lat*180.0/M_PI, lon*180.0/M_PI); + printf("%lf\t%lf\n", lat*180.0/M_PI, lon*180.0/M_PI); + } else + printf("\t\n"); + } return 0; } -- cgit v1.2.3