From 2c17123ec50c61a9dc30a7ea24e1bbe04cee16af Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 23 May 2016 13:19:48 +1200 Subject: [PATCH] Support correcting for grid convergence Grid convergence is now corrected for when using automatically calculated declinations (*declination auto ). Requested by Mateusz Golicz on the mailing list. --- src/cavern.c | 3 ++- src/cavern.h | 2 ++ src/commands.c | 26 ++++++++++++++++++++++++++ src/datain.c | 6 +++++- tests/Makefile.am | 1 + tests/cavern.tst | 2 +- tests/cmd_declination_auto.out | 4 ++-- tests/cmd_declination_auto.pos | 26 +++++++++++++------------- tests/cmd_declination_auto.svx | 2 +- tests/cmd_declination_conv.out | 24 ++++++++++++++++++++++++ tests/cmd_declination_conv.pos | 3 +++ tests/cmd_declination_conv.svx | 11 +++++++++++ 12 files changed, 91 insertions(+), 19 deletions(-) rewrite tests/cmd_declination_auto.pos (78%) create mode 100644 tests/cmd_declination_conv.out create mode 100644 tests/cmd_declination_conv.pos create mode 100644 tests/cmd_declination_conv.svx diff --git a/src/cavern.c b/src/cavern.c index 54cdcea9..266426ba 100644 --- a/src/cavern.c +++ b/src/cavern.c @@ -1,6 +1,6 @@ /* cavern.c * SURVEX Cave surveying software: data reduction main and related functions - * Copyright (C) 1991-2003,2004,2005,2010,2011,2013,2014,2015 Olly Betts + * Copyright (C) 1991-2003,2004,2005,2010,2011,2013,2014,2015,2016 Olly Betts * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -178,6 +178,7 @@ main(int argc, char **argv) pcs->meta = NULL; pcs->proj = NULL; pcs->declination = HUGE_REAL; + pcs->convergence = 0.0; /* Set up root of prefix hierarchy */ root = osnew(prefix); diff --git a/src/cavern.h b/src/cavern.h index f52e01c8..fb37be78 100644 --- a/src/cavern.h +++ b/src/cavern.h @@ -333,6 +333,8 @@ typedef struct Settings { * meaningful if date1 != -1. */ real declination; + /* Grid convergence. */ + real convergence; meta_data * meta; } settings; diff --git a/src/commands.c b/src/commands.c index 37969610..400b00b1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -40,6 +40,25 @@ #include "readval.h" #include "str.h" +//// Extracted from proj.4 projects (yuck, but grass also does this): +struct DERIVS { + double x_l, x_p; /* derivatives of x for lambda-phi */ + double y_l, y_p; /* derivatives of y for lambda-phi */ +}; + +struct FACTORS { + struct DERIVS der; + double h, k; /* meridinal, parallel scales */ + double omega, thetap; /* angular distortion, theta prime */ + double conv; /* convergence */ + double s; /* areal scale factor */ + double a, b; /* max-min scale error */ + int code; /* info as to analytics, see following */ +}; + +int pj_factors(projLP, projPJ *, double, struct FACTORS *); +//// + static projPJ proj_wgs84; static void @@ -1647,6 +1666,12 @@ cmd_declination(void) pcs->dec_z = z; /* Invalidate cached declination. */ pcs->declination = HUGE_REAL; + { + projLP lp = { x, y }; + struct FACTORS factors = { 0 }; + pj_factors(lp, proj_out, 0.0, &factors); + pcs->convergence = factors.conv; + } } else { /* *declination D UNITS */ int units = get_units(BIT(Q_DECLINATION), fFalse); @@ -1654,6 +1679,7 @@ cmd_declination(void) return; } pcs->z[Q_DECLINATION] = -v * factor_tab[units]; + pcs->convergence = 0; } } diff --git a/src/datain.c b/src/datain.c index fce1b20b..f522395a 100644 --- a/src/datain.c +++ b/src/datain.c @@ -865,6 +865,9 @@ handle_compass(real *p_var) if (pcs->z[Q_DECLINATION] != HUGE_REAL) { declination = -pcs->z[Q_DECLINATION]; } else if (pcs->declination != HUGE_REAL) { + /* Cached value calculated for a previous compass reading taken on the + * same date (by the 'else' just below). + */ declination = pcs->declination; } else { if (!pcs->meta || pcs->meta->days1 == -1) { @@ -876,8 +879,9 @@ handle_compass(real *p_var) /* thgeomag() takes (lat, lon, h, dat) - i.e. (y, x, z, date). */ declination = thgeomag(pcs->dec_y, pcs->dec_x, pcs->dec_z, dat); } + declination -= pcs->convergence; /* We cache the calculated declination as the calculation is relatively - * expensive. We also calculate an "assumed 0" answer so that we only + * expensive. We also cache an "assumed 0" answer so that we only * warn once per such survey rather than for every line with a compass * reading. */ pcs->declination = declination; diff --git a/tests/Makefile.am b/tests/Makefile.am index 97bd7f98..3ecdd9c1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -100,6 +100,7 @@ cmd_date.svx cmd_datebad.svx cmd_datebad.out cmd_datebad2.svx cmd_datebad2.out\ cmd_calibrate.svx cmd_calibrate.out cmd_calibrate.pos\ cmd_declination.svx cmd_declination.out cmd_declination.pos\ cmd_declination_auto.svx cmd_declination_auto.out cmd_declination_auto.pos\ +cmd_declination_conv.out cmd_declination_conv.pos cmd_declination_conv.svx\ unconnected-bug.svx unconnected-bug.out\ eswap.svx eswap.espec eswapx.3d\ eswap-break.svx eswap-break.espec eswap-breakx.3d\ diff --git a/tests/cavern.tst b/tests/cavern.tst index b3761ec7..2b7fba78 100755 --- a/tests/cavern.tst +++ b/tests/cavern.tst @@ -61,7 +61,7 @@ testdir=`(cd "$testdir" && pwd)` bad_units_qlist\ percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\ nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\ - cmd_calibrate cmd_declination cmd_declination_auto\ + cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_conv\ lech level 2fixbug dot17 3dcorner\ unconnected-bug\ declination.dat ignore.dat backread.dat nomeasure.dat\ diff --git a/tests/cmd_declination_auto.out b/tests/cmd_declination_auto.out index 861258f0..e591f164 100644 --- a/tests/cmd_declination_auto.out +++ b/tests/cmd_declination_auto.out @@ -21,8 +21,8 @@ Total length of survey legs = 165.23m ( 165.23m adjusted) Total plan length of survey legs = 161.98m Total vertical length of survey legs = 5.00m Vertical range = 4.87m (from a.1 at 1234.00m to c.3 at 1229.13m) -North-South range = 107.57m (from d.2 at 5282107.57m to a.1 at 5282000.00m) -East-West range = 6.39m (from a.1 at 410600.00m to d.1 at 410593.61m) +North-South range = 107.61m (from d.2 at 5282107.61m to a.1 at 5282000.00m) +East-West range = 6.27m (from a.1 at 410600.00m to d.1 at 410593.73m) 5 1-nodes. 4 2-nodes. 3 3-nodes. diff --git a/tests/cmd_declination_auto.pos b/tests/cmd_declination_auto.pos dissimilarity index 78% index bb05a6b5..076c3932 100644 --- a/tests/cmd_declination_auto.pos +++ b/tests/cmd_declination_auto.pos @@ -1,13 +1,13 @@ -( Easting, Northing, Altitude ) -(410600.00, 5282000.00, 1234.00 ) 1 -(410600.00, 5282000.00, 1234.00 ) a.1 -(410593.61, 5282007.62, 1232.95 ) a.2 -(410593.61, 5282008.84, 1233.08 ) a.3 -(410593.61, 5282007.62, 1232.95 ) b.1 -(410593.61, 5282007.62, 1231.95 ) b.2 -(410593.61, 5282007.62, 1231.95 ) c.1 -(410593.61, 5282007.62, 1230.95 ) c.2 -(410594.29, 5282007.18, 1229.13 ) c.3 -(410593.61, 5282007.62, 1230.95 ) d.1 -(410596.58, 5282107.57, 1230.95 ) d.2 -(410595.33, 5282057.59, 1230.95 ) d.2a +( Easting, Northing, Altitude ) +(410600.00, 5282000.00, 1234.00 ) 1 +(410600.00, 5282000.00, 1234.00 ) a.1 +(410593.73, 5282007.72, 1232.95 ) a.2 +(410593.74, 5282008.94, 1233.08 ) a.3 +(410593.73, 5282007.72, 1232.95 ) b.1 +(410593.73, 5282007.72, 1231.95 ) b.2 +(410593.73, 5282007.72, 1231.95 ) c.1 +(410593.73, 5282007.72, 1230.95 ) c.2 +(410594.40, 5282007.26, 1229.13 ) c.3 +(410593.73, 5282007.72, 1230.95 ) d.1 +(410598.24, 5282107.61, 1230.95 ) d.2 +(410595.52, 5282057.68, 1230.95 ) d.2a diff --git a/tests/cmd_declination_auto.svx b/tests/cmd_declination_auto.svx index b314af65..e8f799d8 100644 --- a/tests/cmd_declination_auto.svx +++ b/tests/cmd_declination_auto.svx @@ -33,7 +33,7 @@ *date 2000.12.25 1 2 100.0 000 0 ; Regression test for bug fixed in 1.2.27 - cavern caches the declination, -; but fails to invalidate the cache when the declination coordindates are +; but fails to invalidate the cache when the declination coordinates are ; changed, only when the date changed. *declination auto 0490600 5282000 1234 1 2a 50.0 000 0 diff --git a/tests/cmd_declination_conv.out b/tests/cmd_declination_conv.out new file mode 100644 index 00000000..c2a5c16f --- /dev/null +++ b/tests/cmd_declination_conv.out @@ -0,0 +1,24 @@ + +Removing trailing traverses... + +Concatenating traverses... + +Simplifying network... + +Calculating network... + +Calculating traverses... + +Calculating trailing traverses... + +Calculating statistics... + +Survey contains 2 survey stations, joined by 1 leg. +There are 0 loops. +Total length of survey legs = 1000.00m (1000.00m adjusted) +Total plan length of survey legs = 1000.00m +Total vertical length of survey legs = 0.00m +Vertical range = 0.00m (from test.1 at 2500.00m to test.1 at 2500.00m) +North-South range = 999.57m (from test.1 at 5260999.57m to test.0 at 5260000.00m) +East-West range = 29.36m (from test.1 at 328029.36m to test.0 at 328000.00m) + 2 1-nodes. diff --git a/tests/cmd_declination_conv.pos b/tests/cmd_declination_conv.pos new file mode 100644 index 00000000..5e4c3f1d --- /dev/null +++ b/tests/cmd_declination_conv.pos @@ -0,0 +1,3 @@ +( Easting, Northing, Altitude ) +(328000.00, 5260000.00, 2500.00 ) test.0 +(328029.36, 5260999.57, 2500.00 ) test.1 diff --git a/tests/cmd_declination_conv.svx b/tests/cmd_declination_conv.svx new file mode 100644 index 00000000..92591ecd --- /dev/null +++ b/tests/cmd_declination_conv.svx @@ -0,0 +1,11 @@ +; pos=yes warn=0 +; Adapted from example posted by Mateusz Golicz to the mailing list +*begin test +*date 2015.08.01 +*cs UTM33N +*cs out UTM33N +*fix 0 328000 5260000 2500 +*declination auto 328000 5260000 2500 +*data normal from to tape compass clino +0 1 1000 356.9275 0 +*end test -- 2.11.4.GIT