point

 

 Remember me

Register  |   Lost password?

 

 

MoneyScience Financial Training: Introduction to QuantLib Development with Luigi Ballabio - September 22-24, London, UK- Click For Further Information



Using NAG .NET methods in LabVIEW

Mon, 12 Sep 2011 03:41:09 GMT

Recently we were asked by users at a few European universities about how to call the NAG Library from within the popular LabVIEW programming environment. They're interested in doing this because they wanted to supplement the functionality of their LabVIEW applications using some of the numerical routines offered by NAG. We already have some preliminary material on our website which describes a few aspects of using the NAG Fortran Library in LabVIEW, but alternative approaches (which could be viewed by some as reflecting more modern programming paradigms such as object orientation) are also possible. Specifically, we’ve been taking a look at calling routines from the NAG Library for .NET from LabVIEW, and we describe some of this work here.

We begin building a LabVIEW application by creating a blank virtual instrument (VI) using, for example, the Blank VI option on LabVIEW’s Getting Started splash screen. This brings up two windows: a front panel and a block diagram. The former contains the user interface of the VI which the user creates using controls and indicators, each of which is selected from a palette of options. Code to control the objects in the front panel is added by the user to the block diagram; this is a manifestation of LabVIEW’s visual programming paradigm, which sees an application as being made up of a collection of nodes that are connected together in a way which reflects the flow of data between them.

Our simple example application is built around the NAG method g01aa, which calculates the mean, standard deviation and various other statistical quantities from a set of ungrouped data (details about the documentation for the NAG Library for .NET is available here, while the documentation for the g01aa routine in the NAG Fortran library is here). To load the method, we first bring up the Functions Palette, using the option on the View menu on the block diagram window. Next, we open the Connectivity collection from the palette, and then the .NET item. This palette contains a variety of functions for creating .NET objects, setting properties or calling methods on those objects. We select the Invoke Node item – which invokes methods or performs actions on an object – and drag it onto the block diagram in order to initialize it.

To specify the class on which to execute the property, we right-click on the node and select Select Class >> .NET >> Browse.... This brings up the Select Object From Assembly dialog box. If the NAG Library is not listed in the Assembly component, then we find it (typically in a location like C:/Program Files/NAG/NAG Library for .NET/) using the Browse... component, choosing either NAGLibrary32.dll or NAGLibrary64.dll, depending on our machine architecture. Double-clicking on the NagLibrary item in the Objects component on the dialog box then shows the objects which are available in this assembly; in our example we select G01, followed by OK to load it into the Property Node. To select the desired method from within the G01 class, we right-click once again on the node and select Create >> Method for NAGLibrary.G01 class >> g01aa (note that the items on the method menu explicitly show the function argument list, including the .NET types; they’re also prefixed with [S] if they’re a static .NET method). This creates a node corresponding to a new instance of the g01aa method in the block diagram (see figure 1).

The next step in building our demo is to add LabVIEW controls and indicators to handle, respectively, the input and output of our application. These get placed on the front panel and corresponding objects appear on the block diagram, where they’re then connected to other objects to specify the flow of data and control through the program. In our application (see figure 2), we use a Numeric Indicator to display each output quantity from g01aa, and a Numeric Control within an Array shell control to allow the user to enter the data values for which the routine will calculate the statistics (see here for more information on creating and using array controls in LabVIEW).

The block diagram of our application is shown in Figure 3. Along with the objects corresponding to the controls and indicators described above, we’ve also used the Array Size function to determine the number of elements in the Data values array. The output from this is used as input for g01aa's input parameter n (i.e., the length of the array x, which contains the data values), and also as the dimension size input parameter for the Initialize Array function. The other input parameter for this function is element, which specifies the value to which all elements of the array are to be set; we use a DBL Numeric Constant to set this to zero, and the resultant array is used as input for g01aa's input parameter wt, which is the array used to weight the data values in the in the calculation. In fact, in this example, all values are weighted equally; we specify this by using a Numeric Constant to set g01aa's input parameter iwt to zero (see the g01aa documentation for more details).

Although simple in application, this example has hopefully given a flavour of the way in which the NAG library for .NET can be used within LabVIEW. Other methods which are offered by the library address the more complicated problems of local and global optimization of multivariate functions, pseudo and quasi random number generation, wavelet transforms, least-squares and eigenvalue determination, curve and surface fitting, summation of series and interpolation; more details about its functionality are available here.

If you have any questions about this work (or want to know more about using the NAG Fortran Library or the NAG C Library with LabVIEW), then please get in touch. I’d really love to hear from users (or prospective users) of NAG and/or LabVIEW, and want to build new examples that will be useful to researchers in this area.

Finally, I’m grateful to my colleague Jeremy Walton for his help in preparing this post, and his interest in this work.

, , , , , , , , , , , , , , ,