Working out distance between places, using OS grid references and a program in Tcl
In Great Britain, locations have Ordnance Survey grid reference positions which place them to within 100 metres. Our
training centre / hotel is at ST907633 - that's
100 km square ST
90.7 km into that square from the west side
63.3 km into that squate from the south side
One of the requirements that I've got at present is to take 597 survey inputs from the
TransWilts survey we did last October and come up with some metrics of journey length. From previous work I have details of all the stations on the network, including their OS references,
[here], and I've got the layout of the 100 km squares in a data file
[here].
As I'm teaching a
Tcl course this week, I've chosen to write my distance calculation code in that language. Here's the program in use - calculating the dictance from Melksham to Swindon, and from Swindon on to London Paddington.
munchkin:survey grahamellis$ tclsh distance_between
What are the grid reference on your journey (space separated?)
ST899646 SU149853 TQ265814
32.46
111.67
munchkin:survey grahamellis$
(Take a look at
the source code which is commented if you want to see the logic in Tcl. It makes strong use of string handling and lists in Tcl, and you'll see examples of
for,
foreach and
while loops too - they make an excellent comparison)
(written 2015-03-11)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T203 - Tcl/Tk - Conditionals and Loops [210] Joining lists in Tcl. Indirect variables in Tcl. - (2005-02-12)
[1401] Tcl - using [] or {} for conditions in an if (and while) - (2007-10-23)
[1477] Decisions - small ones, or big ones? - (2007-12-18)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[2261] Tcl - nice and nasty - (2009-06-29)
[2471] A short form of if ... then ... else - (2009-10-23)
[2681] Tcl - a great engineering language - (2010-03-17)
[3189] Tcl - the danger of square brackets in a while command - (2011-03-02)
[3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
[3570] Trapping errors in Tcl - the safety net that catch provides - (2012-01-06)
[3571] Comparing loop commands in Tcl - (2012-01-06)
[4322] Learning to Program - the conditional statement (if) - (2014-11-21)
[4323] Learning to program - Loop statements such as while - (2014-11-22)
T206 - Tcl/Tk - Lists [144] Tcl sandwich - lists in Tcl - (2004-12-08)
[463] Splitting the difference - (2005-10-13)
[781] Tcl - lappend v concat - (2006-06-27)
[1282] Stringing together Tcl scripts - (2007-07-29)
[1283] Generating traffic for network testing - (2007-07-29)
[1334] Stable sorting - Tcl, Perl and others - (2007-09-06)
[1402] Tcl - append v lappend v concat - (2007-10-23)
[1405] Sorting in Tcl - lists and arrays - (2007-10-24)
[1601] Replacing the last comma with an and - (2008-04-04)
[2468] What are Tcl lists? - (2009-10-22)
[2472] split and join in tcl and expect - (2009-10-23)
[3285] Extracting data from a string / line from file - Tcl - (2011-05-10)
[3394] The difference between lists and strings - Tcl - (2011-08-16)
[3415] User defined sorting and other uses of callbacks in Tcl and Tk - (2011-09-02)
[3582] Tcl collections - lists, dicts and array - (2012-01-16)
[3583] Expanding a list of parameters in Tcl - {*} and eval - (2012-01-17)
[3618] lists and struct::list in Tcl - Introduction to struct::list and examples - (2012-02-18)
[4209] Lists in Tcl - fundamentals in a commented source code example - (2013-11-16)
[4454] Everything is a string - even a list - (2015-03-11)
T205 - Tcl/Tk - String Handling in Tcl [404] How to check that a string contains a number in Tcl - (2005-08-06)
[779] The fragility of pancakes - and better structures - (2006-06-26)
[943] Matching within multiline strings, and ignoring case in regular expressions - (2006-11-25)
[1403] Square Bracket protection in Tcl - (2007-10-23)
[1410] Tcl / regsub - changing a string and using interesting bits - (2007-10-27)
[3192] Tcl - Some example of HOW TO in handling data files and formats - (2011-03-04)
[3576] Tcl - apparently odd behaviour of string trimleft - (2012-01-13)
[4205] Regular Expression Substitution - Tcl - (2013-11-12)
Some other Articles
Managing the window size (and layout) in Tcl/TkA new Tcl/tk example - a window to show system statusTest framework for TCL - Tcltest - some examplesObjects in Tcl - iTcl - updated first steps exampleWorking out distance between places, using OS grid references and a program in TclTcl variable names - no real limits!Binary data handling - Python and PerlRunning an operating system command from your Python program - the new way with the subprocess moduleDeciding whether to use parameters, conditional statements or subclasses