One little-known feature of Mathcad 15 (and earlier versions) is the ability to connect to Internet data sources. Simply insert a scriptable component into a worksheet, define an input and an output, and insert this VBScript into the component code.
Function IEGetPage(URL) Set IE = CreateObject("InternetExplorer.Application") IE.Navigate URL Do While IE.Busy Loop IEGetPage = IE.Document.Body.outerText IE.Stop IE.Quit End Function
IEGetPage(URL) is a function that downloads the data the URL points to.
This function can be used to define the output of the scriptable component. For example, you could insert the following code into a push button event (PushBtnEvent_Exec)
Outputs(0).value = IEGetPage(Inputs(0).Value)
Outputs(0).value and Inputs(0).Value refer to the first input and output of the scriptable component. In this instance, the input would simply be a URL and the output would be the downloaded data.
So what can I do with this surprisingly cool functionality? Well, the US Geological Survey host constantly updated earthquake data on their website. This data gives the location (i.e. the latitude and longitude) and magnitude of earthquakes over a rolling time period, and can be downloaded as a text file. http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt is a typical example.
This text file is updated several times a day with new earthquake data and can be downloaded straight into Mathcad using the VBScript given above. Check out this Mathcad worksheet (the link is at the bottom of this post).
Once the data the data is in Mathcad, some parsing is needed to strip out headers and other unnecessary information. You can then manipulate and analyse the filtered data.
In the Mathcad worksheet, I’ve plotted the location of earthquakes on a map of North America (the mapping data is low resolution, but it serves its purpose). Here’s what the plot looks like:
My next mini-project (should I get some time off from the salt mines) is to project this earthquake data onto a globe.
I’ve also connected Mathcad to other Internet data sources, including historical stock quotes and foreign exchange rates.