HP MLIB User's Guide Vol. 2 7th Ed.
1092 HP MLIB User’s Guide
Examples
Calling functions
The method of calling a VECLIB function subprogram depends on its data type.
The following examples show how to call some Fortran function subprograms
from C. The function prototypes in veclib.h cast the function return values to
the proper data types.
REAL functions
The program in Figure A-2 computes the dot product of two double (Fortran
REAL*8) vectors of length 2 using the VECLIB subprogram DDOT.
Figure A-2 Calling a real-valued function from C
#include <stdio.h>
#include <veclib.h>
main ()
{
int one = 1;
int two = 2;
double s;
static double x[2] = { 1.0, -2.0};
static double y[2] = {-3.0, -2.0};
s = ddot (&two, x, &one, y, &one);
printf ("ddot = %f\n", s);
}
COMPLEX functions
Figure A-3 illustrates how to call complex16_t (Fortran COMPLEX*16)
VECLIB function subprogram ZDOTC.
Figure A-3 Calling a complex-valued function from C
#include <stdio.h>
#include <veclib.h>
main ()
{
int one = 1;
int two = 2;
complex16_t s;
static complex16_t x[2] = {{-1.0, 2.0},{ 2.0,-3.0} };
static complex16_t y[2] = {{ 3.0,-1.0},{ 2.0, 1.0} };
s = zdotc (&two, x, &one, y, &one);
printf ("zdotc = (%f,%f)\n", s.re, s.im);
}