NAG Workshop and Surgery

Slides:



Advertisements
Similar presentations
NAG Workshop and Surgery
Advertisements

1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Copyright  Hannu Laine C++-programming Part 5 Strings.
Lecture 20 Arrays and Strings
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
CS 106 Introduction to Computer Science I 12 / 04 / 2006 Instructor: Michael Eckmann.
CS100A, Fall 1997, Lecture 241 CS100A, Fall 1997 Lecture 24, Tuesday 25 November (There were no written notes for lecture 23 on Nov. 20.) Data Structures.
Introduction to Computers and Programming Class 22 Character Arrays (Strings) Professor Avi Rosenfeld.
Design of an ODE Solver Environment. System of ODEs Consider the system of ODEs: Typically solved by forward Euler or 4th order Runge-Kutta.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
Looping and Counting Lecture 3 Hartmut Kaiser
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
General comments [1]  array is a fixed sized group in which the elements are of the same type  The general form of array's definition is as follows:
CS 1704 Introduction to Data Structures and Software Engineering.
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.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT:10 Advance Pointer Array, String and Dynamic Memory Allocation CS2311 Computer Programming.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
What do I need to Know For My Assignment?. C Pointer Review To declare a pointer, we use the * operator. This is similar to but different from using *
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Object Oriented Programming Lecture 2: BallWorld.
Java Programming Language Lecture27- An Introduction.
‘C’ Programming Structures and Commands
Chapter 8 Arrays, Strings and Pointers
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
APPENDIX a WRITING SUBROUTINES IN C
A bit of C programming Lecture 3 Uli Raich.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Computer Programming BCT 1113
Functions, Part 2 of 2 Topics Functions That Return a Value
C Programming Tutorial – Part I
Alberto Fassò Endre Futó
Command Line Arguments
Lecture-5 Arrays.
C Short Overview Lembit Jürimägi.
Student Book An Introduction
C Basics.
Strings A string is a sequence of characters treated as a group
CSCI206 - Computer Organization & Programming
Arrays in C.
Instructor: Ioannis A. Vetsikas
Lecture 6 C++ Programming
Arrays C provides the option to the user to combine similar data types into a single entity It followed contiguous.
Multiple Dimension Arrays
Strings.
Built-In (a.k.a. Native) Types in C++
Arrays and Pointers Reference: Chapter , 4.11 CMSC 202.
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
7 Arrays.
C++ Pointers and Strings
Fundamental Programming
Outline Announcements Differences between FORTRAN and C
Arrays C provides the option to the user to combine similar data types into a single entity It followed contiguous.
Arrays.
Programming Languages and Paradigms
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Arrays, Part 1 of 2 Topics Definition of a Data Structure
C++ Pointers and Strings
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

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” 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

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 !!

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

LAbVIEW “Call Library Function” “Advanced” Functions Palette from VI diagram

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

A02ABF : LabVIEW Call

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)

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

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 ? ! ??????

Correct Calling Convention: returning a character string

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

Curve Fitting by Chebshev Polynomials

Curve Fitting by Chebshev Polynomials

Curve Fitting by Chebshev Polynomials Interpolation

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

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

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 ???

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 !