HOW TO CALL THE IMSL FORTRAN LIBRARIES FROM C by ...
HOW TO CALL THE IMSL FORTRAN LIBRARIES FROM C by ...
HOW TO CALL THE IMSL FORTRAN LIBRARIES FROM C by ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
2x3 matrix<br />
1 2 3<br />
1 11 12 13<br />
2 21 22 23<br />
Note that the header file, descrip, is not surrounded with < and > and the structure identifier,<br />
name_desc, is declared, not defined <strong>by</strong> the macro.<br />
4.2 Passing a Function as an Argument<br />
A VMS C function can be passed to a Fortran subroutine as an argument. The following<br />
example shows how to pass a function to <strong>IMSL</strong> routine DQDNG. Note that myfunc<br />
references x as a pointer because Fortran will invoke myfunc and pass the address of x.<br />
#include <br />
#include <br />
/*<br />
* myfunc calculates and returns *x * exp (*x). x is a pointer<br />
* since Fortran calls myfunc and passes an address of x.<br />
*/<br />
double myfunc (x)<br />
double *x;<br />
{<br />
double exp ();<br />
return (*x * exp (*x));<br />
}<br />
main()<br />
{<br />
extern void dqdng ();<br />
double exp(), fabs(), myfunc();<br />
double lower=0.e0, upper=2.e0, errabs=0.e0, errrel=l.e-7;<br />
double result, errest, exact;<br />
/* <strong>IMSL</strong> dqdng integrates a smooth function using a<br />
nonadaptive rule. */<br />
dqdng (myfunc, &lower, &upper, &errabs, &errrel, &result, &errest);<br />
/* The exact answer is already known and it is 1 + exp(2). */<br />
exact = l.0e0 + exp (2. e0);<br />
printf ("\nIntegral of y = x*exp(x) at [0,2].\n\n");<br />
printf ("Exact answer = %8.5f\n", exact);<br />
printf ("<strong>IMSL</strong> dqdng = %8.5f\n", result);<br />
printf ("Error = %l2.5e\n", fabs (exact - result));<br />
20