NAG Workshop and Surgery

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Introduction to C Programming
Pointers.
C Structures Basics of structures Typedef. Data Hierarchy Byte –8 bits (ASCII character ‘A’ = ) Field –Group of characters (character string “Fred”)
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.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
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.
Character and String definitions, algorithms, library functions Characters and Strings.
Managing Memory Static and Dynamic Memory Type Casts Allocating Arrays of Dynamic Size Resizing Block of Memory Returning Memory from a Function Avoiding.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Chapter 10.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Pointers A pointer is a variable that contains memory address as its value. A variable directly contains a specific value. A pointer contains an address.
Introduction to Computers and Programming Class 22 Character Arrays (Strings) Professor Avi Rosenfeld.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Chapter 8 Arrays and Strings
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Design of an ODE Solver Environment. System of ODEs Consider the system of ODEs: Typically solved by forward Euler or 4th order Runge-Kutta.
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
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.
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
Chapter 8 Arrays and Strings
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
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.
COP Structures Instructor: Diego Rivera-Gutierrez I’m back baby!
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
1 Chapter 7 Arrays. 2 Topics 7.1 Arrays Hold Multiple Values 7.2 Accessing Array Elements 7.3 No Bounds Checking in C Array Initialization 7.5 Processing.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
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:
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Introduction to Computers and Programming Class 24 Structures (structs) Professor Avi Rosenfeld.
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.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Arrays. C++ Style Data Structures: Arrays(1) An ordered set (sequence) with a fixed number of elements, all of the same type, where the basic operation.
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.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Java Programming Language Lecture27- An Introduction.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
APPENDIX a WRITING SUBROUTINES IN C
Computer Programming BCT 1113
C Programming Tutorial – Part I
Alberto Fassò Endre Futó
C Basics.
Strings A string is a sequence of characters treated as a group
Arrays and Pointers Reference: Chapter , 4.11 CMSC 202.
C++ Pointers and Strings
NAG Workshop and Surgery
C++ Pointers and Strings
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 !