Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

function or math problem

$
0
0
I'm working with two scripts, trying to put the functionality of script 2 into script 1.  Script 2 reads a .gpx (GPS track) file containing track points with latitude and longitude information, looks for stops, and compares the stop points with another database file containing known locations, finding the closest match.  Both scripts contain multiple UDF's.  When I wrote script 2 with this in mind, I wrote script 2 with nothing but UDFs; the first thing script 2 does (after declaring some global variables) is to call the first UDF, which is the main routine, which itself calls other UDFs.

I then cut and pasted the entire contents of script 2 into script 1, checking that there are no variable name conflicts.  The only changes I made to the script 2 functions were to return back to the main script 1 GUI rather than exiting at the end  Depending on user interaction, the UDF which was the main part of script 2 is called, which then calls the other UDFs that were in script 2 and are now in script 1.  The problem is, it doesn't work.

I don't expect people to wade through all of both scripts, but the problem seems to originate in one of the smaller UDFs from script 2.  This function takes two pairs of latitude and longitude, and calculates the distance between the two:

[ autoit ]      
Func _LLDist($lat1, $lon1, $lat2, $lon2) ;using Sinnott's formula for great circle distance between two points ;first convert degrees to radians for trig functions, using ACos(-1) to derive pi ConsoleWrite("1197 " & $lat1 & ", " & $lon1 & "; " & $lat2 & ", " & $lon2) $lat1 = $lat1 * (ACos(-1) / 180) $lon1 = $lon1 * (ACos(-1) / 180) $lat2 = $lat2 * (ACos(-1) / 180) $lon2 = $lon2 * (ACos(-1) / 180) Local $R = 3440.064794816415 ; Earth radius in nautical miles (6371000 meters) Local $dlon = $lon2 - $lon1 Local $dlat = $lat2 - $lat1 Local $a = (Sin($dlat / 2)) ^ 2 + Cos($lat1) * Cos($lat2) * (Sin($dlon / 2)) ^ 2 Local $c = 2 * ASin(Sqrt($a)) Local $d = $R * $c ConsoleWrite(" 1208 dist - " & $d & @CRLF) Return $d EndFunc ;==>_LLDist

If I run script 2 by itself, I get correct console output:

1197 41.38123769313097, -72.50517829321325; 41.38124062679708, -72.50517854467034 1208 dist - 0.000176502556754481

If I run script 1 on the same data, I get:

1197 41.38123769313097, -72.50517829321325; 41.38124062679708, -72.50517854467034 1208 dist - -1.#IND

As you can see, the input data is the same but the output is not.

Additionally, after this happens, other data in some arrays seems to get corrupted, and, for example, an array value that's supposed to range from 1-20,000 or so shows values like -9223372036854762545.  A divide by zero causing a memory corruption?  Or something else?

Any ideas?

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>