1 / 20

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

NAG Workshop and Surgery 6 December 2001. Using the NAG Library from LabVIEW John Keightley NPL, Centre for Ionising Radiation Metrology. Outline of Talk. Basics of calling the NAG DLLs from LabVIEW Similarities with C/C++ calling conventions Introduction to LabVIEW “Call Library Function”

dudley
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NAG Workshop and Surgery 6 December 2001 Using the NAG Library fromLabVIEWJohn KeightleyNPL, 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

  4. BASICS • Very similar approach to C/C++ • 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. “Advanced” Functions Palette from VI diagram LAbVIEW “Call Library Function”

  6. Complex NumbersExample 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 : • 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 E02AEFCurve 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 PolynomialsInterpolation

  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; }

  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 !

More Related