Calling IMSL routines (FORTRAN) from C
Dan Koft
koft at elbereth.rutgers.edu
Thu May 30 02:00:38 AEST 1991
Please help me if you can. I have a C program that I want to call an
IMSL routine called QDAGI, the code in FORTRAN looks like:
CALL QDAGI(F, BOUND, INTERV, ERRABS, ERRREL, RESULT, ERREST)
Where (from the IMSL manual):
F - User supplied function to be integrated. The form is F(X),
where: X - Independant variable (Input), F - The function
value (Output). F must be declared EXTERNAL in the calling
program.
BOUND - Finite bound of the integration range (Input). Ignored if
INTERV=2.
INTERV - Flag indicating integration range (Input). If INTERV is -1
the interval is -infinity to BOUND; if 1, BOUND to +infinity;
if 2 -infinity to +infinity.
ERRABS - Absolute accuracy desired (Input).
ERRREL - Relative accuracy desired (Input).
RESULT - Estimate of the integral from A to B of F (Output).
ERREST - Estimate of the absolute value of the error (Output).
I have tried all the ways I could think of to call this function
without proper results. Below is the test program from the IMSL
manual as I have translated it to C.
#include <stdio.h>
#include <math.h>
#define Abs(x) ( (x)>0? (x) : (-x))
double F(double x);
extern void qdagi(double *F(), double *bound, int *interv, double *errabs,
double *errel, double *result, double *errest);
main()
{
double abs,bound,errabs,errest,error,errrel,exact,ppi,result;
int interv = 1;
bound = 0.0;
errabs = 0.0;
errrel = 0.001;
qdagi((&)F(),&bound,&interv,&errabs,&errrel,&result,&errest);
/* The above line is where I believe the problem lies*/
ppi = 3.1415926;
exact = -ppi * log(10.)/20.;
error = Abs(result - exact);
printf(" Computed = %8.3f exact = %8.3f\nError ", result, exact);
printf("estimate = %f error = %f\n", errest, error);
}
double F(double x)
{
double temp;
temp = log(x)/(1. + pow((10. * x),2.0));
return temp;
}
--
[=============================================================================]
Dan Koft Email: koft at elbereth.rutgers.edu
RU-CS, Rutgers University {backbone}!rutgers!elbereth!koft
SERC, Busch Campus Phone: (908) 932-3216
Piscataway, NJ 08855
[=============================================================================]
More information about the Comp.lang.c
mailing list