Download presentation

Presentation is loading. Please wait.

1
**NAG Workshop and Surgery**

6 December 2001 Using the NAG Library from LabVIEW John Keightley NPL, Centre for Ionising Radiation Metrology

2
**Outline of Talk Basics of calling the NAG DLLs from LabVIEW**

Similarities with C/C++ calling conventions Introduction to LabVIEW “Call Library Function” Problems I’ve encountered so far !! Complex Numbers 2D Arrays must be TRANSPOSED ! Functions and Subroutines Character Strings returned via function name Arrays MUST be large enough to hold output Example

3
**Parameter Types in Fortran and LabVIEW**

INTEGER I32 or “signed long int” REAL Double (8 bytes) LOGICAL COMPLEX double re, double im CHARACTER*n Blank character string, I32 for string length EXTERNAL ? ? ? ? ? Don’t know how !!

4
**BASICS Very similar approach to C/C++ Ie: C++ header from NAG help**

C/C++ headers are VERY useful in determining calling notation for LabVIEW NB : Stdcall(WINAPI) calling convention Ie: C++ header from NAG help extern void __stdcall E02ACF( CONST double x[], CONST double y[], CONST int *n, double aa[], CONST int *m1, double *ref );

5
**LAbVIEW “Call Library Function”**

“Advanced” Functions Palette from VI diagram

6
**Complex Numbers Example A02ABF :Complex Modulus**

FORTRAN : real FUNCTION A02ABF(XR,XI) real XR,XI Refer to C/C++ headers (type definitions) typedef struct { double re,im; } Complex; ??? “Call Library Function” does not allow pointer to a “cluster” !! Refer to C/C++ header for A02ABF extern double __stdcall A02ABF( CONST double *xxr, CONST double *xxi );

7
A02ABF : LabVIEW Call

8
**2D Arrays In FORTRAN : In LabVIEW Thus, MUST TRANSPOSE arrays**

Column major order In LabVIEW Row major order (Same as C/C++) Thus, MUST TRANSPOSE arrays BEFORE inputting to NAG functions in the DLLs AFTER retrieving output from the DLLs. Can use LabVIEW “Transpose 2D Array” function from the Array palette ! or use the NAG routine F01CRF (more complicated as you need to know the size of the array to start with)

9
**FORTRAN Subroutines and Functions**

SUBROUTINE returns VOID FUNCTION returns a value !! eg: SUBROUTINE X05AAF(ITIME) INTEGER ITIME(7) time data array passed through parameter list CHARACTER*30 FUNCTION X05ABF(ITIME) INTEGER ITIME(7) function returns a character array

10
**Returning a character string via a function name**

CHARACTER*30 FUNCTION X05ABF(ITIME) INTEGER ITIME(7) Fortran has no NULL TERMINATED strings: Instead it uses TWO parameters for strings character string AND an int for string length cannot return TWO values !! Refer to C headers for solution : extern void __stdcall X05ABF (char [], int, CONST int itime[] ); 1st 2 parameters refer to string which was being returned via function name ? ! ??????

11
**Correct Calling Convention: returning a character string**

12
**A Simple Example : E02ADF and E02AEF Curve Fitting and Interpolation by Chebyshev Polynomials**

Program Reads Input Data : Least Squares Fitting by method of Chebyshev Polynomials E02ADF Interpolation of values E02AEF

13
**Curve Fitting by Chebshev Polynomials**

14
**Curve Fitting by Chebshev Polynomials**

15
**Curve Fitting by Chebshev Polynomials Interpolation**

16
**MY BIG PROBLEM : EXTERNAL calls**

Example : C05AJF : locates zero of a user supplied continuous function C/C++ header extern void __stdcall C05AJF( double *x, CONST double *eps, CONST double *eta, double (__stdcall *f)(double *), CONST int *nfmax, int *ifail );

17
**EXTERNAL calls : C05AJF #include <math.h>**

#include <stdio.h> #include "nagmk19.h“ main(){ double eps, eta, x; int ifail, k, nfmax; double __stdcall f(double *); for (k=1; k<=2; k++){ eps = k==1 ? 0.1e-3 : 0.1e-4; x = 1.0; eta = 0.0; nfmax = 200; ifail = 1; C05AJF(&x,&eps,&eta,f,&nfmax,&ifail); if (ifail==0) printf("With eps = %e root = %f\n",eps,x); else{ printf("ifail = %d\n",ifail); if (ifail==3 | ifail==4) printf("With eps = %e final value = %f\n",eps,x); } return 0; double __stdcall f(double *x) { return exp(-*x) - *x; EXTERNAL calls : C05AJF

18
**EXTENAL CALLS I DON’T KNOW HOW TO DO THIS IN LabVIEW !!**

ie: I need a pointer to the user supplied function !!! LabVIEW call library function doesn’t help me ! Wrapper DLL in C++ required ???

19
**Conclusion Use LabVIEW “Call Library Function”**

LabVIEW calls are VERY SIMILAR to those in C/C++ Use NAG C headers for help ! Still to resolve issues with EXTERNAL calls to user supplied functions !! Nick Williamson from National Instruments is looking into this Wrapper DLL in C/C++ ?? I can help anyone wanting to use the NAG DLLs from LabVIEW !

Similar presentations

OK

1 Pointers: Parameter Passing and Return. 2 Passing Pointers to a Function Pointers are often passed to a function as arguments Allows data items within.

1 Pointers: Parameter Passing and Return. 2 Passing Pointers to a Function Pointers are often passed to a function as arguments Allows data items within.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on fiscal policy in india 2010 Ppt on waves tides and ocean currents activity Ppt on solar energy utilization Ppt on surface area and volume of cube cuboid and cylinder Ppt on right to information act 2005 Ppt on solar energy conservation Download ppt on market around us Ppt on pin photodiode Ppt on high sea sales meaning Ppt on carbon and its compounds for 10 class