void eval_zforce(int nR,
		 double *R,
		 double *z,
		 int npot,
		 int * pot_type,
		 double * pot_args,
		 double *out,
		 int * err){
  int ii;
  //Set up the potentials
  struct potentialArg * potentialArgs= (struct potentialArg *) malloc ( npot * sizeof (struct potentialArg) );
  parse_leapFuncArgs_Full(npot,potentialArgs,pot_type,pot_args);
  //Run through and evaluate
  for (ii=0; ii < nR; ii++){
    *(out+ii)= calczforce(*(R+ii),*(z+ii),0.,0.,npot,potentialArgs);
  }
  for (ii=0; ii < npot; ii++) {
    if ( (potentialArgs+ii)->i2drforce )
      interp_2d_free((potentialArgs+ii)->i2drforce) ;
    if ((potentialArgs+ii)->accxrforce )
      gsl_interp_accel_free ((potentialArgs+ii)->accxrforce );
    if ((potentialArgs+ii)->accyrforce )
      gsl_interp_accel_free ((potentialArgs+ii)->accyrforce );
    if ( (potentialArgs+ii)->i2dzforce )
      interp_2d_free((potentialArgs+ii)->i2dzforce) ;
    if ((potentialArgs+ii)->accxzforce )
      gsl_interp_accel_free ((potentialArgs+ii)->accxzforce );
    if ((potentialArgs+ii)->accyzforce )
      gsl_interp_accel_free ((potentialArgs+ii)->accyzforce );
    free((potentialArgs+ii)->args);
  }
  free(potentialArgs);
}
예제 #2
0
파일: bath_js03.c 프로젝트: yuanchung/qdas
void js03_lineshape_func_free(js03_lineshape_func *f)
{
  gsl_interp_accel_free(f->BATH_JS03_gt_r_Spline_Acc);
  gsl_interp_accel_free(f->BATH_JS03_gt_i_Spline_Acc);
  gsl_spline_free(f->BATH_JS03_gt_r_Spline);
  gsl_spline_free(f->BATH_JS03_gt_i_Spline);
}
예제 #3
0
파일: test.c 프로젝트: JoveU/MC_DiJet_old
/**
 * Tests that a given interpolation type reproduces the data points it is given,
 * and then tests that it correctly reproduces additional values.
 * 
 * @param xarr the x values of the points that define the function
 * @param yarr the y values of the points that define the function
 * @param zarr the values of the function at the points specified by xarr and yarr
 * @param xsize the length of xarr
 * @param ysize the length of yarr
 * @param xval the x values of additional points at which to calculate interpolated values
 * @param yval the y values of additional points at which to calculate interpolated values
 * @param zval the expected results of the additional interpolations
 * @param zxval the expected results of the x derivative calculations
 * @param zyval the expected results of the y derivative calculations
 * @param zxxval the expected results of the xx derivative calculations
 * @param zyyval the expected results of the yy derivative calculations
 * @param zxyval the expected results of the xy derivative calculations
 * @param test_size the length of xval, yval, zval, etc.
 * @param T the interpolation type
 */
int test_interp2d(const double xarr[], const double yarr[], const double zarr[],    // interpolation data
                  size_t xsize, size_t ysize,                                       // sizes of xarr and yarr
                  const double xval[], const double yval[],                         // test points
                  const double zval[],                                              // expected results
                  const double zxval[], const double zyval[],
                  const double zxxval[], const double zyyval[], const double zxyval[],
                  size_t test_size,                                                 // number of test points
                  const interp2d_type* T) {
    gsl_interp_accel *xa, *ya;
    int status = 0;
    size_t xi, yi, zi, i;

    xa = gsl_interp_accel_alloc();
    ya = gsl_interp_accel_alloc();
    interp2d* interp = interp2d_alloc(T, xsize, ysize);
    interp2d_spline* interp_s = interp2d_spline_alloc(T, xsize, ysize);

    unsigned int min_size = interp2d_type_min_size(T);
    gsl_test_int(min_size, T->min_size, "interp2d_type_min_size on %s", interp2d_name(interp));

    interp2d_init(interp, xarr, yarr, zarr, xsize, ysize);
    interp2d_spline_init(interp_s, xarr, yarr, zarr, xsize, ysize);
    // First check that the interpolation reproduces the given points
    for (xi = 0; xi < xsize; xi++) {
        double x = xarr[xi];
        for (yi = 0; yi < ysize; yi++) {
            double y = yarr[yi];
            
            zi = INDEX_2D(xi, yi, xsize, ysize);
            test_single_low_level(&interp2d_eval, &interp2d_eval_e, interp, xarr, yarr, zarr, x, y, xa, ya, zarr, zi);
            test_single_low_level(&interp2d_eval_no_boundary_check, &interp2d_eval_e_no_boundary_check, interp, xarr, yarr, zarr, x, y, xa, ya, zarr, zi);
            test_single_high_level(&interp2d_spline_eval, &interp2d_spline_eval_e, interp_s, x, y, xa, ya, zarr, zi);
        }
    }
    // Then check additional points provided
    for (i = 0; i < test_size; i++) {
        double x = xval[i];
        double y = yval[i];
        
        test_single_low_level(&interp2d_eval,         &interp2d_eval_e,          interp, xarr, yarr, zarr, x, y, xa, ya, zval, i);
        test_single_low_level(&interp2d_eval_deriv_x, &interp2d_eval_deriv_x_e,  interp, xarr, yarr, zarr, x, y, xa, ya, zxval, i);
        test_single_low_level(&interp2d_eval_deriv_y, &interp2d_eval_deriv_y_e,  interp, xarr, yarr, zarr, x, y, xa, ya, zyval, i);
        test_single_low_level(&interp2d_eval_deriv_xx,&interp2d_eval_deriv_xx_e, interp, xarr, yarr, zarr, x, y, xa, ya, zxxval, i);
        test_single_low_level(&interp2d_eval_deriv_yy,&interp2d_eval_deriv_yy_e, interp, xarr, yarr, zarr, x, y, xa, ya, zyyval, i);
        test_single_low_level(&interp2d_eval_deriv_xy,&interp2d_eval_deriv_xy_e, interp, xarr, yarr, zarr, x, y, xa, ya, zxyval, i);
        
        test_single_high_level(&interp2d_spline_eval,         &interp2d_spline_eval_e,          interp_s, x, y, xa, ya, zval, i);
        test_single_high_level(&interp2d_spline_eval_deriv_x, &interp2d_spline_eval_deriv_x_e,  interp_s, x, y, xa, ya, zxval, i);
        test_single_high_level(&interp2d_spline_eval_deriv_y, &interp2d_spline_eval_deriv_y_e,  interp_s, x, y, xa, ya, zyval, i);
        test_single_high_level(&interp2d_spline_eval_deriv_xx,&interp2d_spline_eval_deriv_xx_e, interp_s, x, y, xa, ya, zxxval, i);
        test_single_high_level(&interp2d_spline_eval_deriv_yy,&interp2d_spline_eval_deriv_yy_e, interp_s, x, y, xa, ya, zyyval, i);
        test_single_high_level(&interp2d_spline_eval_deriv_xy,&interp2d_spline_eval_deriv_xy_e, interp_s, x, y, xa, ya, zxyval, i);

        test_single_low_level(&interp2d_eval_no_boundary_check, &interp2d_eval_e_no_boundary_check, interp, xarr, yarr, zarr, x, y, xa, ya, zval, i);
    }
    gsl_interp_accel_free(xa);
    gsl_interp_accel_free(ya);
    interp2d_free(interp);
    return status;
}
void eval_potential(int nR,
		    double *R,
		    double *z,
		    int npot,
		    int * pot_type,
		    double * pot_args,
		    double *out,
		    int * err){
  int ii;
  //Set up the potentials
  struct potentialArg * potentialArgs= (struct potentialArg *) malloc ( npot * sizeof (struct potentialArg) );
  parse_actionAngleArgs(npot,potentialArgs,pot_type,pot_args);
  //Run through and evaluate
  for (ii=0; ii < nR; ii++){
    *(out+ii)= evaluatePotentials(*(R+ii),*(z+ii),npot,potentialArgs);
  }
  for (ii=0; ii < npot; ii++) {
    if ( (potentialArgs+ii)->i2d )
      interp_2d_free((potentialArgs+ii)->i2d) ;
    if ((potentialArgs+ii)->accx )
      gsl_interp_accel_free ((potentialArgs+ii)->accx);
    if ((potentialArgs+ii)->accy )
      gsl_interp_accel_free ((potentialArgs+ii)->accy);
    free((potentialArgs+ii)->args);
  }
  free(potentialArgs);
}
예제 #5
0
static float
interp_demData(float *demData, int nl, int ns, double l, double s)
{
  if (l<0 || l>=nl-1 || s<0 || s>=ns-1) {
    return 0;
  }

  int ix = (int)s;
  int iy = (int)l;

  int bilinear = l<3 || l>=nl-3 || s<3 || s>=ns-3;
  //int bilinear = 1;
  if (bilinear) {

    float p00 = demData[ix   + ns*(iy  )];
    float p10 = demData[ix+1 + ns*(iy  )];
    float p01 = demData[ix   + ns*(iy+1)];
    float p11 = demData[ix+1 + ns*(iy+1)];

    return (float)bilinear_interp_fn(s-ix, l-iy, p00, p10, p01, p11);
  }
  else {

    double ret, x[4], y[4], xi[4], yi[4];
    int ii;

    for (ii=0; ii<4; ++ii) {
      y[0] = demData[ix-1 + ns*(iy+ii-1)];
      y[1] = demData[ix   + ns*(iy+ii-1)];
      y[2] = demData[ix+1 + ns*(iy+ii-1)];
      y[3] = demData[ix+2 + ns*(iy+ii-1)];

      x[0] = ix - 1;
      x[1] = ix;
      x[2] = ix + 1;
      x[3] = ix + 2;

      gsl_interp_accel *acc = gsl_interp_accel_alloc ();
      gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 4);    
      gsl_spline_init (spline, x, y, 4);
      yi[ii] = gsl_spline_eval_check(spline, s, acc);
      gsl_spline_free (spline);
      gsl_interp_accel_free (acc);

      xi[ii] = iy + ii - 1;
    }

    gsl_interp_accel *acc = gsl_interp_accel_alloc ();
    gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 4);    
    gsl_spline_init (spline, xi, yi, 4);
    ret = gsl_spline_eval_check(spline, l, acc);
    gsl_spline_free (spline);
    gsl_interp_accel_free (acc);
 
    return (float)ret;
  }
  
  asfPrintError("Impossible.");
}
예제 #6
0
int load_lens(int l_size ,int* l_values){
	
	double* lens_data = malloc( sizeof(double)*MAXLINES*3);
	int* lens_len = malloc( sizeof(int));
	
	load_txt_dbl(lens_data_file, 3, lens_data, lens_len);
	
	int lens_size = *lens_len;
	int lmax = (int)get_lmax();
// 	printf("lmax %d\t%d\n",lmax,lens_size);
	double l_raw[lens_size];
	double cltt_raw[lens_size];
	double cltp_raw[lens_size];
	
	int i,j;
	double pt;
	
	j=0;
	for (i=0; i<lmax+1; i++){
		l_raw[i] = lens_data[j++];
		cltt_raw[i] = lens_data[j++];
		cltp_raw[i] = lens_data[j++];
	}
	
	if (l_values[l_size-1]>l_raw[lmax]){
		printf("lens do not contain enough l's, max data %d max lens: %d\n", l_values[l_size-1], (int)l_raw[lmax]);
		return 1;
		exit;
	}
	
	
	gsl_spline* sptt =  gsl_spline_alloc (gsl_interp_cspline, lmax+1);
	gsl_spline* sptp =  gsl_spline_alloc (gsl_interp_cspline, lmax+1);
	gsl_interp_accel* acctt = gsl_interp_accel_alloc();
	gsl_interp_accel* acctp = gsl_interp_accel_alloc();
	
	gsl_spline_init(sptt,l_raw,cltt_raw,lmax+1);
	gsl_spline_init(sptp,l_raw,cltp_raw,lmax+1);
	
	for (i=0; i<l_size; i++){
		pt = (double)l_values[i];
		lens_tt[i] = 0.0;
		lens_tp[i] = 0.0;
		if(pt!=0){
			lens_tt[i] = gsl_spline_eval(sptt,pt,acctt);
			lens_tp[i] = gsl_spline_eval(sptp,pt,acctp);
		}
	}
	
	gsl_spline_free(sptt);
	gsl_spline_free(sptp);
	gsl_interp_accel_free(acctt);
	gsl_interp_accel_free(acctp);
	
	return 0;
}
예제 #7
0
void TrajectoryControl::pathSpline_destroy(spline_param* x_path,
		spline_param* y_path, spline_param* ds_path) {
	// Distruggo gli oggetti spline
	gsl_spline_free(x_path->spline_coeff);
	gsl_interp_accel_free(x_path->accumulator);

	gsl_spline_free(y_path->spline_coeff);
	gsl_interp_accel_free(y_path->accumulator);

	gsl_spline_free(ds_path->spline_coeff);
	gsl_interp_accel_free(ds_path->accumulator);
}
예제 #8
0
void free_lens_corr_func(lensCorrFunc lcf)
{
  if(lcf->splineM != NULL)
    gsl_spline_free(lcf->splineM);
  if(lcf->accelM != NULL)
    gsl_interp_accel_free(lcf->accelM);
    
  if(lcf->splineP != NULL)
    gsl_spline_free(lcf->splineP);
  if(lcf->accelP != NULL)
    gsl_interp_accel_free(lcf->accelP);
  
  free(lcf);
}
예제 #9
0
파일: bath_js03.c 프로젝트: yuanchung/qdas
int bath_js03_free_params()
{
  int i;
  
  i=0;
  while(BATH_JS03OpBra[i]>0) {
    gsl_interp_accel_free(BATH_JS03BathFunc[i].BATH_JS03_Ct_r_Spline_Acc);
    gsl_interp_accel_free(BATH_JS03BathFunc[i].BATH_JS03_Ct_i_Spline_Acc);
    gsl_spline_free(BATH_JS03BathFunc[i].BATH_JS03_Ct_r_Spline);
    gsl_spline_free(BATH_JS03BathFunc[i].BATH_JS03_Ct_i_Spline);
    i++;
  }

  return 0;
}
예제 #10
0
void cosmology::cosmo_free(){
    if(verbose){
    std::cout<<"# Cosmo free destructor\n";
    }
    if(bool_zhao){
        gsl_interp_accel_free(zhao_acc);
        gsl_spline_free(zhao_spline);
        bool_zhao=false;
    }
    if(bool_gen){
        gsl_interp_accel_free(gen_acc);
        gsl_spline_free(gen_spline);
        bool_gen=false;
    }
}
예제 #11
0
파일: power.cpp 프로젝트: sbird/S-GenIC
PowerSpec_Tabulated::~PowerSpec_Tabulated()
{
        //Free memory for power table
        delete[] kmatter_table;
        delete[] pmatter_table;
        gsl_interp_free(pmat_interp);
        gsl_interp_accel_free(pmat_interp_accel);
        //Free memory for transfer table
        delete[] ktransfer_table;
        for (int i=0; i<N_TYPES_TAB;i++) {
            delete[] transfer_table[i];
            gsl_interp_free(trans_interp[i]);
            gsl_interp_accel_free(trans_interp_accel[i]);
        }
}
예제 #12
0
void calc_rforce(int nR,
		 double *R,
		 int nz,
		 double *z,
		 int npot,
		 int * pot_type,
		 double * pot_args,
		 double *out,
		 int * err){
  int ii, jj, tid, nthreads;
#ifdef _OPENMP
  nthreads = omp_get_max_threads();
#else
  nthreads = 1;
#endif
  double * row= (double *) malloc ( nthreads * nz * ( sizeof ( double ) ) );
  //Set up the potentials
  struct potentialArg * potentialArgs= (struct potentialArg *) malloc ( npot * sizeof (struct potentialArg) );
  parse_leapFuncArgs_Full(npot,potentialArgs,pot_type,pot_args);
  //Run through the grid and calculate
  int chunk= CHUNKSIZE;
#pragma omp parallel for schedule(static,chunk) private(ii,tid,jj)	\
  shared(row,npot,potentialArgs,R,z,nR,nz)
  for (ii=0; ii < nR; ii++){
#ifdef _OPENMP
    tid= omp_get_thread_num();
#else
    tid = 0;
#endif
    for (jj=0; jj < nz; jj++){
      *(row+jj+tid*nz)= calcRforce(*(R+ii),*(z+jj),0.,0.,npot,potentialArgs);
    }
    put_row(out,ii,row+tid*nz,nz); 
  }
  for (ii=0; ii < npot; ii++) {
    if ( (potentialArgs+ii)->i2drforce )
      interp_2d_free((potentialArgs+ii)->i2drforce ) ;
    if ((potentialArgs+ii)->accrforce )
      gsl_interp_accel_free ((potentialArgs+ii)->accrforce );
    if ( (potentialArgs+ii)->i2dzforce )
      interp_2d_free((potentialArgs+ii)->i2dzforce ) ;
    if ((potentialArgs+ii)->acczforce )
      gsl_interp_accel_free ((potentialArgs+ii)->acczforce );
    free((potentialArgs+ii)->args);
  }
  free(potentialArgs);
  free(row);
}
예제 #13
0
MfCumulative::~MfCumulative()
{
  gsl_interp_free(interp);
  gsl_interp_accel_free(acc);

  free(M_array);
}
예제 #14
0
파일: demo.c 프로젝트: BrianGladman/gsl
int
main (void)
{
  int i;
  double xi, yi;
  double x[10], y[10];

  printf ("#m=0,S=2\n");

  for (i = 0; i < 10; i++)
    {
      x[i] = i + 0.5 * sin (i);
      y[i] = i + cos (i * i);
      printf ("%g %g\n", x[i], y[i]);
    }

  printf ("#m=1,S=0\n");

  {
    gsl_interp_accel *acc = gsl_interp_accel_alloc ();
    gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 10);
    gsl_spline_init (spline, x, y, 10);

    for (xi = x[0]; xi < x[9]; xi += 0.01)
      {
        double yi = gsl_spline_eval (spline, xi, acc);
        printf ("%g %g\n", xi, yi);
      }
    gsl_spline_free (spline);
    gsl_interp_accel_free(acc);
  }
}
예제 #15
0
double calc_corr_at_R(double R,double*k,double*P,int Nk,int N,double h){
  double zero,psi,x,t,dpsi,f,PIsinht;
  double PI_h = PI/h;
  double PI_2 = PI*0.5;
  gsl_spline*Pspl = gsl_spline_alloc(gsl_interp_cspline,Nk);
  gsl_spline_init(Pspl,k,P,Nk);
  gsl_interp_accel*acc= gsl_interp_accel_alloc();

  double sum = 0;
  int i;
  for(i=0;i<N;i++){
    zero = i+1;
    psi = h*zero*tanh(sinh(h*zero)*PI_2);
    x = psi*PI_h;
    t = h*zero;
    PIsinht = PI*sinh(t);
    dpsi = (PI*t*cosh(t)+sinh(PIsinht))/(1+cosh(PIsinht));
    if (dpsi!=dpsi) dpsi=1.0;
    f = x*get_P(x,R,k,P,Nk,Pspl,acc);
    sum += f*sin(x)*dpsi;
  }

  gsl_spline_free(Pspl),gsl_interp_accel_free(acc);
  return sum/(R*R*R*PI*2);
}
예제 #16
0
UNUSED static REAL8 XLALSimInspiralNRWaveformGetRefTimeFromRefFreq(
  UNUSED LALH5File* file,
  UNUSED REAL8 fRef
)
{
  #ifndef LAL_HDF5_ENABLED
  XLAL_ERROR(XLAL_EFAILED, "HDF5 support not enabled");
  #else
  /* NOTE: This is an internal function, it is expected that fRef is scaled
   * to correspond to the fRef with a total mass of 1 solar mass */
  LALH5File *curr_group = NULL;
  gsl_vector *omega_t_vec = NULL;
  gsl_vector *omega_w_vec = NULL;
  gsl_interp_accel *acc;
  gsl_spline *spline;
  REAL8 ref_time;
  curr_group = XLALH5GroupOpen(file, "Omega-vs-time");
  ReadHDF5RealVectorDataset(curr_group, "X", &omega_t_vec);
  ReadHDF5RealVectorDataset(curr_group, "Y", &omega_w_vec);
  acc = gsl_interp_accel_alloc();
  spline = gsl_spline_alloc(gsl_interp_cspline, omega_w_vec->size);
  gsl_spline_init(spline, omega_w_vec->data, omega_t_vec->data,
                  omega_t_vec->size);
  ref_time = gsl_spline_eval(spline, fRef * (LAL_MTSUN_SI * LAL_PI), acc);
  gsl_vector_free(omega_t_vec);
  gsl_vector_free(omega_w_vec);
  gsl_spline_free(spline);
  gsl_interp_accel_free(acc);
  return ref_time;
  #endif
}
예제 #17
0
UNUSED static REAL8 XLALSimInspiralNRWaveformGetInterpValueFromGroupAtPoint(
  UNUSED LALH5File* file,                 /**< Pointer to HDF5 file */
  UNUSED const char *groupName,           /**< Name of group in HDF file */
  UNUSED REAL8 ref_point                  /**< Point at which to evaluate */
  )
{
  #ifndef LAL_HDF5_ENABLED
  XLAL_ERROR(XLAL_EFAILED, "HDF5 support not enabled");
  #else
  LALH5File *curr_group = NULL;
  gsl_vector *curr_t_vec = NULL;
  gsl_vector *curr_y_vec = NULL;
  gsl_interp_accel *acc;
  gsl_spline *spline;
  REAL8 ret_val;
  curr_group = XLALH5GroupOpen(file, groupName);
  ReadHDF5RealVectorDataset(curr_group, "X", &curr_t_vec);
  ReadHDF5RealVectorDataset(curr_group, "Y", &curr_y_vec);
  acc = gsl_interp_accel_alloc();
  spline = gsl_spline_alloc(gsl_interp_cspline, curr_t_vec->size);
  gsl_spline_init(spline, curr_t_vec->data, curr_y_vec->data,
                  curr_t_vec->size);
  ret_val = gsl_spline_eval(spline, ref_point, acc);
  gsl_vector_free(curr_t_vec);
  gsl_vector_free(curr_y_vec);
  gsl_spline_free (spline);
  gsl_interp_accel_free (acc);
  return ret_val;
  #endif
}
예제 #18
0
void spline(double *YY, 
		double *X, double *Y, double *XX, int m1, int m2) {

	// m1: length of discrete extremas
	// m2: length of original data points

	gsl_interp_accel *acc = gsl_interp_accel_alloc ();
  	const gsl_interp_type *t = gsl_interp_cspline; 
  	gsl_spline *spline = gsl_spline_alloc (t, m1);

	/* Core function */

  	gsl_spline_init (spline, X, Y, m1);

	double m;
	
	if (m1 > 2 ) {
		for (int j = 0; j < m2; j++) {
			YY[j] = gsl_spline_eval (spline, XX[j], acc);
		} // end of for-j
	} // end of if

	else {
		m = (Y[1] - Y[0]) / (X[1] - X[0]);
		for (int j = 0; j < m2; j++) {
			YY[j] = Y[0] + m * (XX[j] - X[0]);		
		} // end of for-j
	} //end of else

	// delete[] xd;
	gsl_spline_free (spline);
  	gsl_interp_accel_free (acc);

}
int calc_ave_delta_sigma_in_bin(double*R,int NR,double*delta_sigma,
				double lRlow,double lRhigh,
				double*ave_delta_sigma){
  int status = 0;

  gsl_spline*spline = gsl_spline_alloc(gsl_interp_cspline,NR);
  gsl_spline_init(spline,R,delta_sigma,NR);
  gsl_interp_accel*acc= gsl_interp_accel_alloc();
  gsl_integration_workspace * workspace
    = gsl_integration_workspace_alloc(workspace_size);

  integrand_params*params=malloc(sizeof(integrand_params));
  params->acc=acc;
  params->spline=spline;
  params->workspace=workspace;

  double Rlow=exp(lRlow),Rhigh=exp(lRhigh);

  do_integral(ave_delta_sigma,lRlow,lRhigh,params);
  *ave_delta_sigma *= 2./(Rhigh*Rhigh-Rlow*Rlow);

  gsl_spline_free(spline),gsl_interp_accel_free(acc);
  gsl_integration_workspace_free(workspace);
  free(params);
  return 0;
}
예제 #20
0
pdf_redshift::~pdf_redshift()
{
  gsl_interp_accel_free(accelerator);
  gsl_interp_free(interpolator);
  free(x);
  free(y);
}
예제 #21
0
int
main (void)
{
  int N = 4;
  double x[4] = {0.00, 0.10,  0.27,  0.30};
  double y[4] = {0.15, 0.70, -0.10,  0.15}; /* Note: first = last 
                                               for periodic data */

  gsl_interp_accel *acc = gsl_interp_accel_alloc ();
  const gsl_interp_type *t = gsl_interp_cspline_periodic; 
  gsl_spline *spline = gsl_spline_alloc (t, N);

  int i; double xi, yi;

  printf ("#m=0,S=5\n");
  for (i = 0; i < N; i++)
    {
      printf ("%g %g\n", x[i], y[i]);
    }

  printf ("#m=1,S=0\n");
  gsl_spline_init (spline, x, y, N);

  for (i = 0; i <= 100; i++)
    {
      xi = (1 - i / 100.0) * x[0] + (i / 100.0) * x[N-1];
      yi = gsl_spline_eval (spline, xi, acc);
      printf ("%g %g\n", xi, yi);
    }
  
  gsl_spline_free (spline);
  gsl_interp_accel_free (acc);
  return 0;
}
예제 #22
0
/*
 * Free the allocated data types
 */
BandPassFilterFFT::~BandPassFilterFFT() {
	delete[] f;
	delete[] fcache;
	gsl_interp_accel_free(faccel);
	gsl_fft_complex_wavetable_free (wavetable);
	gsl_fft_complex_workspace_free (workspace);
}
예제 #23
0
void polymodel(void)
{
  gsl_interp_accel *pmsplacc = gsl_interp_accel_alloc();
  bodyptr p;
  real rad, phi, vel, psi, vr, vp, a, E, J;
  vector rhat, vtmp, vper;

  for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) {
    rad = rad_m(xrandom(0.0, mtot));
    phi = gsl_spline_eval(pmspline, (double) rad, pmsplacc);
    vel = pick_v(phi);
    psi = pick_psi();
    vr = vel * rcos(psi);
    vp = vel * rsin(psi);
    Mass(p) = mtot / nbody;
    pickshell(rhat, NDIM, 1.0);
    MULVS(Pos(p), rhat, rad);
    pickshell(vtmp, NDIM, 1.0);
    a = dotvp(vtmp, rhat);
    MULVS(vper, rhat, - a);
    ADDV(vper, vper, vtmp);
    a = absv(vper);
    MULVS(vper, vper, vp / a);
    MULVS(Vel(p), rhat, vr);
    ADDV(Vel(p), Vel(p), vper);
    Phi(p) = phi;
    E = phi + 0.5 * rsqr(vel);
    J = rad * ABS(vp);
    Aux(p) = Kprime * rpow(phi1 - E, npol - 1.5) * rpow(J, 2 * mpol);
  }
  gsl_interp_accel_free(pmsplacc);
}
예제 #24
0
cMorph::~cMorph()
{
	gsl_spline_free(splineAkimaPeriodic);
	gsl_interp_accel_free(interpolationAccelerator);
	splineAkimaPeriodic = NULL;
	interpolationAccelerator = NULL;
}
void regrid_sed(double z,double *plam,double *pval,long finelength, \
				long sedlength,double *fineplam,double *finepval) {
	
    long ii;
    double x[sedlength],y[sedlength];
	
    for (ii=0;ii<sedlength;ii++) {
        x[ii] = *(plam+ii) * (1.0 + z);
        y[ii] = *(pval+ii);
    }
	
    gsl_interp_accel *acc = gsl_interp_accel_alloc();
    gsl_spline *spline    = gsl_spline_alloc(gsl_interp_cspline, sedlength);
    
    gsl_spline_init(spline, x, y, sedlength);
	
    for (ii=0; ii < finelength; ii++) {
        if (*(fineplam+ii)/(1.0 + z) < *(plam+0)) {
            *(finepval+ii) = 0.0;
        } else {
            *(finepval+ii) = gsl_spline_eval (spline, *(fineplam+ii), acc);
        }
        if (*(finepval+ii) < 0.0)
            *(finepval+ii) = 0.0;
    }
	
    gsl_spline_free(spline);
    gsl_interp_accel_free(acc);
}
예제 #26
0
파일: mixing.cpp 프로젝트: Ingwar/amuse
void smoothing_integrate(smoothing_params &params, int n) {
  int n_int = 2*n;

  params.acc_y = gsl_interp_accel_alloc();
  params.int_y = gsl_interp_alloc(gsl_interp_linear, n);
  params.n     = n;
  gsl_interp_init(params.int_y, params.arr_x, params.arr_y, n);

  /* setup integration workspace */

  gsl_integration_workspace *w = gsl_integration_workspace_alloc(n_int);
  gsl_function F; 
  F.function = &smoothing_integrand;
  F.params   = &params;
  
  double eps_abs = 0.0, eps_rel = 0.01;
  double result, error;
  gsl_set_error_handler_off();
 
  for (int i = 0; i < n; i++) {
    params.x = params.arr_x[i];
    params.h = 0.1; //0.1*params.x + 1.0e-4;

    gsl_integration_qag(&F, 
			params.x - 2*params.h, params.x + 2*params.h,
			eps_abs, eps_rel,
			n_int, 1,
			w, &result, &error);
    params.smoothed_y[i] = result;
  }
  
  gsl_integration_workspace_free(w);
  gsl_interp_accel_free(params.acc_y);
  gsl_interp_free(params.int_y);
}
예제 #27
0
// -----------------------------------------------------------------------------
void hand_anim_end()
{
	DEBUGLOGB;

#ifdef _USEGSL
#ifdef _USEGSL_STATIC

	gsl_interp_free(g_curveTerp);
	gsl_interp_accel_free(g_curveAccl);

#else

	if( g_pLLibok )
	{
		g_gsl_interp_free(g_curveTerp);
		g_gsl_interp_accel_free(g_curveAccl);

		lib::destroy(g_pLLib);
		g_pLLib   =  NULL;
		g_pLLibok =  false;
	}

#endif

	g_curveTerp = NULL;
	g_curveAccl = NULL;

#endif

	DEBUGLOGE;
}
예제 #28
0
void Interpolation::calculateOutputData(double *x, double *y)
{
	gsl_interp_accel *acc = gsl_interp_accel_alloc ();
	const gsl_interp_type *method;
	switch(d_method)
	{
		case 0:
			method = gsl_interp_linear;
			break;
		case 1:
			method = gsl_interp_cspline;
			break;
		case 2:
			method = gsl_interp_akima;
			break;
	}

	gsl_spline *interp = gsl_spline_alloc (method, d_n);
	gsl_spline_init (interp, d_x, d_y, d_n);

    double step = (d_to - d_from)/(double)(d_points - 1);
    for (int j = 0; j < d_points; j++)
	{
	   x[j] = d_from + j*step;
	   y[j] = gsl_spline_eval (interp, x[j], acc);
	}

	gsl_spline_free (interp);
	gsl_interp_accel_free (acc);
}
예제 #29
0
void free_lens_power_spectrum(lensPowerSpectra lps)
{
  if(lps->spline != NULL)
    gsl_spline_free(lps->spline);
  if(lps->accel != NULL)
    gsl_interp_accel_free(lps->accel);
  free(lps);
}
예제 #30
0
UNUSED static UINT4 XLALSimInspiralNRWaveformGetDataFromHDF5File(
  UNUSED REAL8Vector** output,            /**< Returned vector uncompressed */
  UNUSED LALH5File* pointer,              /**< Pointer to HDF5 file */
  UNUSED REAL8 totalMass,                 /**< Total mass of system for scaling */
  UNUSED REAL8 startTime,                 /**< Start time of veturn vector */
  UNUSED size_t length,                   /**< Length of returned vector */
  UNUSED REAL8 deltaT,                    /**< Sample rate of returned vector */
  UNUSED const char *keyName              /**< Name of vector to uncompress */
  )
{
  #ifndef LAL_HDF5_ENABLED
  XLAL_ERROR(XLAL_EFAILED, "HDF5 support not enabled");
  #else
  UINT4 idx;
  size_t comp_data_length;
  REAL8 massTime;
  gsl_interp_accel *acc;
  gsl_spline *spline;
  gsl_vector *knotsVector, *dataVector;
  LALH5File *group = XLALH5GroupOpen(pointer, keyName);
  knotsVector=dataVector=NULL;

  ReadHDF5RealVectorDataset(group, "X", &knotsVector);
  ReadHDF5RealVectorDataset(group, "Y", &dataVector);

  *output = XLALCreateREAL8Vector(length);

  comp_data_length = dataVector->size;
  /* SPLINE STUFF */
  acc = gsl_interp_accel_alloc();
  spline = gsl_spline_alloc(gsl_interp_cspline, comp_data_length);
  gsl_spline_init(spline, knotsVector->data, dataVector->data,
                  comp_data_length);

  for (idx = 0; idx < length; idx++)
  {
    massTime = (startTime + idx*deltaT) / (totalMass * LAL_MTSUN_SI);
    /* This if statement is used to catch the case where massTime at idx=0
     * ends up at double precision smaller than the first point in the
     * interpolation. In this case set it back to exactly the first point.
     * Sanity checking that we are not trying to use data below the
     * interpolation range is done elsewhere.
     */
    if ((idx == 0) && (massTime < knotsVector->data[0]))
    {
      massTime = knotsVector->data[0];
    }
    (*output)->data[idx] = gsl_spline_eval(spline, massTime, acc);
  }

  gsl_vector_free(knotsVector);
  gsl_vector_free(dataVector);
  gsl_spline_free (spline);
  gsl_interp_accel_free (acc);

  return XLAL_SUCCESS;
  #endif
}