Esempio n. 1
0
void dqag0(double (*f)(double), double a, double b, double epsabs, double epsrel, double *result, double *abserr, double *work, long int lwork, long int *iwork, long int liwork, int *ifail)
{
//
//     based on quadpack routine
//
//     dqag0 is a general purpose integrator which calculates
//     an approximation to the integral of a function over a finite
//     interval (a,b)
//
//     dqag0 itself is essentially a dummy routine whose function is to
//     partition the work arrays work and iwork for use by dqags.
//     work is partitioned into 4 arrays each of size lwork/4.
//     iwork is a single array in dqags.
//
//     .. scalar arguments ..
      
      int ibl, iel, ier, irl, limit;
//     .. subroutine references ..
//     dqags
//     ..
//     check that minimum workspace requirements are met
      if (lwork<4) 
      {
      	ier = 6;
      	*ifail = 1;
      	return;
      }
  
      if (liwork<lwork/8+2)
      {
      	ier = 6;
      	*ifail = 1;
      	return;
      }
//     limit = upper bound on number of subintervals
      limit = lwork/4;
//     set up base addresses for work arrays
      ibl = limit + 1;
      iel = limit + ibl;
      irl = limit + iel;
//     perform integration
      dqags(f, a, b, fabs(epsabs), fabs(epsrel), &(work[1]),&(work[ibl]), &(work[iel]), &(work[irl]), limit, iwork, liwork, result, abserr, &ier);
      
      if (ier!=0) {*ifail = 1;}
      else {*ifail = 0;}
      return;
 }//dqag0
Esempio n. 2
0
int main()
{
	double a,b,epsabs,epsrel,abserr;
	double resabs,resasc;
	double y;
	int neval,ier;
		
	a = 0.0;
	b = 1.0;
    epsabs = 0.0;
    epsrel = 1e-3;
	
    y=dqags(efunc,a,b,epsabs,epsrel,&abserr,&neval,&ier,0);

	printf("dqags integral = %.17lg\n",y);
	printf("abserr = %.17lg, neval = %d, ier = %d\n",
		abserr,neval,ier);
    return 0;
}
Esempio n. 3
0
double Iinv( Lgm_MagModelInfo *mInfo ) {


    double	a, b;
    double	epsabs, epsrel, result, abserr;
    double  resabs, resasc;
    int		key, neval, ier, limit, lenw, last, iwork[501];
    double	work[2002];
    _qpInfo	*qpInfo;


    /*
     *  Type-cast our data structure to a generic type.
     *  The structure holds auzilliary info we need down 
     *  in the function calls.
     */
    qpInfo = (_qpInfo *)mInfo;



    /*
     *  Limits of integration.
     */
    a = mInfo->Sm_South;
    b = mInfo->Sm_North;


    /*
     *   set tolerances. 
     */
    //epsabs = mInfo->epsabs;
    //epsrel = mInfo->epsrel;
    epsabs = mInfo->Lgm_I_Integrator_epsabs;
    epsrel = mInfo->Lgm_I_Integrator_epsrel;


    /*
     *  Init some vars used in I_integrand() (these are not declared static in
     *  I_integrand() in order to avoid making it non-reentrant).
     */
    mInfo->Lgm_I_integrand_S         = 0.0;
    mInfo->Lgm_I_integrand_FirstCall = TRUE;
    mInfo->Lgm_n_I_integrand_Calls    = 0;

                                                                                                                                                                             


    if ( mInfo->Lgm_I_Integrator == DQAGS ) {

        /*
         *  Use DQAGS
         */
        limit = 500; lenw = 4*limit; key = 6;
        dqags(I_integrand, qpInfo, a, b, epsabs, epsrel, &result, &abserr, &neval, &ier, limit, lenw, &last, iwork, work, mInfo->VerbosityLevel );

    } else if ( mInfo->Lgm_I_Integrator == DQK21 ) {

        /*
         *  Use DQK21
         */
        dqk21(I_integrand, qpInfo, a, b, &result, &abserr, &resabs, &resasc);

    } else {

        /*
         *  Unknown Integrator
         */
        printf("Iinv: Unknown integrator. Lgm_Inv_Integrator = %d\n", mInfo->Lgm_n_I_integrand_Calls );
        result = -9e99;

    }


    return( result );

}