Hi,
You can call one integral function in another integrand function directly. I know it is literally nonintuitive, so I wrote a simple example below that may help to understand:
It is supposed that I have a function like:

The following integral routine shows how to calculate a nested integral:
#include <OC_nag.h>
static docuble NAG_CALL f_callback_1(double x, Nag_User *comm)
{
int *use_comm = (int *)comm->p;
return (x*x);
}
double nag_d01sjc_1()
{
double a = 0.0;
double b = 2.0; // integration interval
double epsabs, abserr, epsrel, result;
// you may use epsabs and epsrel and this quantity to enhance your desired precision
// when not enough precision encountered
epsabs = 0.0;
epsrel = 0.0001;
// The max number of sub-intervals needed to evaluate the function in the integral
// The more diffcult the integrand the larger max_num_subint should be
// For most problems 200 to 500 is adequate and recommmended
int max_num_subint = 200;
Nag_QuadProgress qp;
NagError fail;
Nag_User comm;
static int use_comm[1] = {1};
comm.p = (Pointer)&use_comm;
d01sjc(f_callback_1, a, b, epsabs, epsrel, max_num_subint,&result, &abserr, &qp, &comm, &fail);
// For the error other than the following three errors which are due to bad input parameters
// or allocation failure NE_INT_ARG_LT NE_BAD_PARAM NE_ALLOC_FAIL
// You will need to free the memory allocation before calling the integration routine again to
// avoid memory leakage
if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
{
NAG_FREE(qp.sub_int_beg_pts);
NAG_FREE(qp.sub_int_end_pts);
NAG_FREE(qp.sub_int_result);
NAG_FREE(qp.sub_int_error);
}
return result;
}
static double NAG_CALL f_callback_2(double y, Nag_User *comm)
{
int *use_comm = (int *)comm->p;
return (nag_d01sjc_1()*y);
}
void nag_d01sjc_2()
{
double c = 0.0;
double d = 3.0;
double epsabs, abserr, epsrel, result;
epsabs = 0.0;
epsrel = 0.0001;
int max_num_subint = 200;
Nag_QuadProgress qp;
NagError fail;
Nag_User comm;
static int use_comm[1] = {1};
comm.p = (Pointer)&use_comm;
d01sjc(f_callback_2, c, d, epsabs, epsrel, max_num_subint,&result, &abserr, &qp, &comm, &fail);
if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
{
NAG_FREE(qp.sub_int_beg_pts);
NAG_FREE(qp.sub_int_end_pts);
NAG_FREE(qp.sub_int_result);
NAG_FREE(qp.sub_int_error);
}
printf("%10.6f", result);
}
Hope it helps.
Regards,
Yuki
OriginLab