double cosmology::pe_fraction_fwd(double mvir0,double z0,double z1){ if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){ std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl; init_pe_rho_rdelta_phys_Zhao(mvir0,z0); } if(z0>=z1){ std::cout<<"# z0 should be smaller than z1 and z2\n"; return 0; } /// Calculate the total mass evolution double mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc); double rvir1=rvir_from_mvir(mvir1,z1); rvir1=rvir1/(1+z1); double cvir1=gsl_spline_eval(cvir_mah_Zhao_spline,z1,cvir_mah_Zhao_acc); double rs1=rvir1/cvir1; double rvir0=rvir_from_mvir(mvir0,z0); rvir0=rvir0/(1+z0); /// Calculate the pseudo-evolution component double Mpe=mvir1/mu(cvir1)*( mu(rvir0/rs1) - mu(rvir1/rs1) ); return Mpe/(mvir0-mvir1); }
int jac (double t, const double y[], double *dfdy, double dfdt[], void *params) { ODEparams * pa = (ODEparams *)params; double alpha = gsl_spline_eval(pa->a_spline,t, pa->a_acc); double beta = gsl_spline_eval(pa->b_spline,t, pa->b_acc); double gamma=pa->gamma,gamma2=gamma*gamma; double yy=y[1],x=y[0]; /* double * p = (double *)params;*/ gsl_matrix_view dfdy_mat = gsl_matrix_view_array (dfdy, 2, 2); gsl_matrix * m = &dfdy_mat.matrix; /* 0 1 -k -2*c*y -(p-b)-cx^2 */ gsl_matrix_set (m, 0, 0, 0.0); gsl_matrix_set (m, 0, 1, 1.0); gsl_matrix_set (m, 1, 0, -beta*gamma2 - 3*gamma2*x*x - 2*gamma*x*yy + 2*gamma2*x - gamma*yy); gsl_matrix_set (m, 1, 1, -gamma*x*x - gamma*x); dfdt[0] = 0.0; dfdt[1] = 0.0; return GSL_SUCCESS; }
double cosmology::Mcaustic_from_Mvir(double mvir0,double z0){ if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){ std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl; init_pe_rho_rdelta_phys_Zhao(mvir0,z0); } double eps=1.0e-2; double z1=z0*(1.+eps); /// Calculate the total mass evolution double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc); double z1step=pow(10.,log10(1.+z1)+0.2)-1.0; double Mvir1_step=gsl_spline_eval(mah_Zhao_spline,z1step,mah_Zhao_acc); double dlogMdloga_1=-(log10(Mvir1)-log10(Mvir1_step))/( log10(1.+z1) - log10(1.+z1step) ); // First calculate concentration of these halos double conc1= gsl_spline_eval(cvir_mah_Zhao_spline,z1,cvir_mah_Zhao_acc); //conc(Mvir1,z1); // Get the c200_mean of these halos double c200m_1=getcDel(conc1,z1,200.0); // Normalization factor for the Rt-R200m relation, based on Benedikt's new // fitting formulae double norm_1=0.42+0.40*Omega(z1); double c_caustic_1=c200m_1*norm_1*( 1.+2.15*exp(-dlogMdloga_1/1.96) ); double Mcaustic1=Mvir1*mu(c_caustic_1)/mu(conc1); return Mcaustic1; }
double cosmology::pe_fraction(double mvir0,double z0,double z1,double z2){ if(!bool_pe_rho_rdelta_phys_Zhao || mvir0!=Mvir_for_pe || z0!=z_for_pe){ std::cout<<"# Initializing physical density profile for "<<mvir0<<" at z="<<z0<<std::endl<<std::endl; init_pe_rho_rdelta_phys_Zhao(mvir0,z0); } if(z0>z1 || z0>z2){ std::cout<<"# z0 should be smaller than z1 and z2\n"; return 0; } if(z2<z1){ std::cout<<"# z1 should be smaller than z2\n"; return 0; } /// Calculate the total mass evolution double Mvir1=gsl_spline_eval(mah_Zhao_spline,z1,mah_Zhao_acc); double Mvir2=gsl_spline_eval(mah_Zhao_spline,z2,mah_Zhao_acc); //mofz=(Mvir1+Mvir2)/2.; double Rvir1=rvir_from_mvir(Mvir1,z1); Rvir1=Rvir1/(1+z1); double Rvir2=rvir_from_mvir(Mvir2,z2); Rvir2=Rvir2/(1+z2); /// Calculate the pseudo-evolution component double Mpe=gsl_spline_eval_integ(pe_rho_rdelta_phys_Zhao_spline,Rvir2,Rvir1,pe_rho_rdelta_phys_Zhao_acc); //std::cout<<"DEBUG: "<<Mpe<<" "<<Mvir2-Mvir1<<std::endl; //printf("DEBUG : %e %e %e %e \n",Mvir1,Rvir1,Mvir2,Rvir2); //exit(101); return Mpe/(Mvir1-Mvir2); }
int compute_itegral(const gsl_vector *k, const void * p, gsl_vector *out){ //delta=phase_f(k)+phc_f(k); omega= 2.0*k struct fit_params * fp = (struct fit_params *)p; double L=10.0, result, error; gsl_function F; struct student_params params; params.mu=fp->mu; params.sig=fp->sig; params.skew=fp->skew; params.nu=fp->nu; F.function = &itegral_student; F.params = ¶ms; if ( params.nu < -1. ) { gsl_vector_set_zero(out); return GSL_SUCCESS; } gsl_integration_workspace * w = gsl_integration_workspace_alloc (10000); for (int i=0; i< k->size; i++){ double kv=gsl_vector_get(k, i); params.delta= gsl_spline_eval(splines.pha_spline, kv, splines.acc) + \ gsl_spline_eval(splines.phc_spline, kv, splines.acc); params.omega=2.*kv; params.lam = gsl_spline_eval(splines.lam_spline, kv, splines.acc); //printf("%12.5f %12.5f %12.5f %12.5f %12.5f %12.5f\n", kv, params.delta, params.lam, params.mu, params.sig, params.skew ); gsl_integration_qag(&F, 0.1, L, 0., 1e-8, 1000, GSL_INTEG_GAUSS51, w, &result, &error); //gsl_integration_qawo (&F, 0., 0., 1e-7, 100, w, int_table, &result, &error); //amp=N*S02*mag_f(k_var)*np.power(k_f(k_var), kweight-1.0)*tmp result*=double(N)*(-1.*fp->S02)*gsl_spline_eval(splines.mag_spline, kv, splines.acc)/kv; gsl_vector_set(out, i, result); } gsl_integration_workspace_free (w); return GSL_SUCCESS;}
// angular average for Mhat in integration region I for given s (<z^n*M> with // n={0,1}) void M_avg_1(complex_spline M, complex *M_avg, double *s, double a, double b, double c, double d, char plusminus, char kappa_pm, int N, int n) { int i, N_int; double eps, error, s_minus, s_plus, sigma; N_int = 1500; eps = 1.0e-10; gsl_interp_accel *acc = gsl_interp_accel_alloc(); gsl_integration_workspace *w = gsl_integration_workspace_alloc(N_int); gsl_function F; gsl_function G; double f_re(double z, void *params) { double sigma = *(double *)params; double f; if (n == 0) { f = gsl_spline_eval(M.re, z, acc); } else if (n == 1) { f = (z - sigma) * gsl_spline_eval(M.re, z, acc); } else if (n == 2) { f = pow(z - sigma, 2.0) * gsl_spline_eval(M.re, z, acc); } // if (isnan(f)==1) { // printf("%d %.3e %.3e\n",n,z,sigma); // } return f; }
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(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(spline, l, acc); gsl_spline_free (spline); gsl_interp_accel_free (acc); return (float)ret; } asfPrintError("Impossible."); }
double bath_js03_gt_i_cached(js03_lineshape_func *f, double t) { if(t>=0.0) { return (f->gamma*gsl_spline_eval(f->BATH_JS03_gt_i_Spline,t,f->BATH_JS03_gt_i_Spline_Acc)); } else { return (f->gamma*gsl_spline_eval(f->BATH_JS03_gt_i_Spline,-1.0*t,f->BATH_JS03_gt_i_Spline_Acc)); } }
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; }
/** Set important class members to values at time t (as specified in * CRLumLookup). */ void Particles::SetMembers(double t) { if (t < TminInternal || t > TmaxInternal) { cout << "Particles::SetMembers: Time (" << t << "yrs vs {" << TminInternal << "," << TmaxInternal << "}) outside boundaries." << endl; cout << " -> Using values from previous time step. If you don't want " "this, you have to extend " << endl; cout << " your Lookups (Luminosity,R,V,B,N etc) or set constant values " "(via e.g. SetBField()). " << endl; return; } Constants = {LumConstant, NConstant, BConstant, eMaxConstant, escapeTimeConstant}; splines = {LumLookup, NLookup, BFieldLookup, eMaxLookup, escapeTimeLookup}; accs = {accLum, accN, accBField, acceMax, accescapeTime}; vals = {&Lum, &N, &BField, &eMax, &escapeTime}; vs = {LumVector, NVector, BVector, eMaxVector, escapeTimeVector}; for (unsigned int i = 0; i < Constants.size(); i++) { *vals[i] = -1.; if (Constants[i]) *vals[i] = Constants[i]; else if (splines[i] == NULL) continue; else *vals[i] = gsl_spline_eval(splines[i], t, accs[i]); } R = V = adLossCoeff = 0.; if(RConstant && VConstant) { R = VConstant*yr_to_sec + RConstant; V = VConstant; } else if(RConstant && !VConstant) { R = RConstant; V = 0.; } else { R = yr_to_sec*V; V = VConstant; } if(RVector.size() && t > RVector[0][0] && t < RVector[RVector.size() - 1][0]) R = gsl_spline_eval(RLookup, t, accR); if(VVector.size() && t > VVector[0][0] && t < VVector[VVector.size() - 1][0]) V = gsl_spline_eval(VLookup, t, accV); if (R && V) adLossCoeff = V / R; return; }
int tester(const std::string & input_file) { //temperature std::vector<Scalar> T0,Tz; read_temperature<Scalar>(T0,Tz,input_file); gsl_interp_accel * acc = gsl_interp_accel_alloc(); gsl_spline * spline = gsl_spline_alloc(gsl_interp_cspline, T0.size()); // GLS takes only double, raaaaahhhh std::vector<double> gsl_x_point(T0.size(),0); std::vector<double> gsl_y_point(T0.size(),0); for(unsigned int i = 0; i < T0.size(); i++) { gsl_x_point[i] = (const double)Tz[i]; gsl_y_point[i] = (const double)T0[i]; } const double * x = &gsl_x_point[0]; const double * y = &gsl_y_point[0]; gsl_spline_init(spline, x, y, T0.size()); Planet::AtmosphericTemperature<Scalar,std::vector<Scalar> > temperature(Tz,T0); //neutral, ionic, altitude int return_flag(0); const Scalar tol = (std::numeric_limits<Scalar>::epsilon() * 100. < 6e-17)?6e-17: std::numeric_limits<Scalar>::epsilon() * 100.; for(Scalar z = 600.; z < 1401.; z += 10) { Scalar neu_temp = gsl_spline_eval(spline,z,acc); Scalar neu_dtemp = gsl_spline_eval_deriv(spline,z,acc); Scalar ion_temp = gsl_spline_eval(spline,z,acc); Scalar ion_dtemp = gsl_spline_eval_deriv(spline,z,acc); Scalar e_temp = electron_temperature(z); Scalar de_dtemp = delectron_temperature(z); return_flag = check(temperature.neutral_temperature(z), neu_temp, tol, "neutral temperature") || check(temperature.dneutral_temperature_dz(z), neu_dtemp, tol, "neutral temperature differentiate") || check(temperature.ionic_temperature(z), ion_temp, tol, "ionic temperature") || check(temperature.dionic_temperature_dz(z), ion_dtemp, tol, "ionic temperature differentiate") || check(temperature.electronic_temperature(z), e_temp, tol, "electron temperature") || check(temperature.delectronic_temperature_dz(z), de_dtemp, tol, "electron temperature differentiate") || return_flag; } gsl_spline_free(spline); gsl_interp_accel_free(acc); return return_flag; }
double f_im_cv(double z, void *params) { double x = *(double *)params; double fct; if (z < a) { fct = (gsl_spline_eval(M_hat[0].im, z, acc1) - gsl_spline_eval(M_hat[0].im, x, acc1)) / (pow(a - z, 1.5) * (z - x)); } else { fct = (gsl_spline_eval(M_hat[1].im, z, acc2) - gsl_spline_eval(M_hat[1].im, x, acc2)) / (pow(z - a, 1.5) * (z - x)); } return fct; }
int func (double t, const double y[], double f[], void *params) { ODEparams * pa = (ODEparams *)params; double alpha=gsl_spline_eval(pa->a_spline,t, pa->a_acc); double beta=gsl_spline_eval(pa->b_spline,t, pa->b_acc); double gamma=pa->gamma,gamma2=gamma*gamma; double yy=y[1],x=y[0]; f[0] = yy; f[1] = alpha*gamma2 - beta*gamma2*x-gamma2*x*x*x - gamma*x*x*yy+gamma2*x*x - gamma*x*yy; return GSL_SUCCESS; }
double f_im(double z, void *params) { double sigma = *(double *)params; double f; if (n == 0) { f = gsl_spline_eval(M.im, z, acc); } else if (n == 1) { f = (z - sigma) * gsl_spline_eval(M.im, z, acc); } else if (n == 2) { f = pow(z - sigma, 2.0) * gsl_spline_eval(M.im, z, acc); } // if (isnan(f)==1) { // printf("%d %.3e %.3e\n",n,z,sigma); // } return f; }
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); }
double Pk_CAMB(gsl_spline *Pow, gsl_interp_accel *a, double mu, double k) { double power = gsl_spline_eval(Pow, k, a); //power *= (b + mu*mu*f)*(b + mu*mu*f); return power; }
double integrand(double lR, void*params){ double R = exp(lR); integrand_params pars=*(integrand_params *)params; gsl_spline*spline = pars.spline;//Delta_Sigma(R) spline gsl_interp_accel*acc = pars.acc; return R*R*gsl_spline_eval(spline,R,acc); }
/// The concentration parameter form a file. Note that the mass should be Mvir in h^{-1} Msun double cosmology::c_gen(double M, double z) { /// First initialize if not initialized if (!bool_gen){ init_gen(z); }else if(z!=z_gen){ init_gen(z); } /// Spline interpolate double xM=log10(M); double concen; if(xM<xMmin){ concen=cMmin+dymin*(xM-xMmin); }else{ if(xM>xMmax){ concen=cMmax+dymax*(xM-xMmax); }else{ concen=gsl_spline_eval(gen_spline,xM,gen_acc); } } //std::cout<<xM<<" "<<concen<<std::endl; return pow(10.,concen); }
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); }
/// Calculate the variance of the power spectrum on a mass scale M in h^{-1} Msun /// numerically by interpolating double cosmology::varM_TH_num(double M, double z) { // if(!bool_init_varM_TH_spline) { //std::cout<<"# I called it: varM_TH_spline"<<std::endl; init_varM_TH_spline(); } double logm=log(M)/log(10.); double result; if(logm>5.0&&logm<18.0) { result=gsl_spline_eval (varM_TH_num_spline,logm, varM_TH_num_acc); } else { std::cout<<"# "<<"varM_TH_num_spline: Interpolation not possible M not within range "<<M<<std::endl; //exit(0); result=log10(varM_TH(M,0.0)); } result = pow(10.,result); if(z!=z_glob){ result=result*pow(growthfactor_num(z),2.); }else{ result=result*pow(gf_glob,2.); } return result; }
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); }
scalar sasfit_sd_cspline8(scalar x, sasfit_param * param) { scalar tmp, xcs[10], ycs[10]; int i; SASFIT_ASSERT_PTR(param); // assert pointer param is valid if (x < XMIN) return 0; if (x > XMAX) return 0; if (XMIN > XMAX) { tmp = XMAX; XMAX = XMIN; XMIN = tmp; } xcs[0]=XMIN; ycs[0]=0; xcs[9]=XMAX; ycs[9]=0; for (i=1; i<=8; i++) { xcs[i] = XMIN+i*(XMAX-XMIN)/(8.0+1.0); ycs[i] = param->p[1+i]; } gsl_spline_init(sdcspline8_T, xcs, ycs, 10); return gsl_spline_eval (sdcspline8_T, x, acc_cspline); }
/// Calculate Delta^2L numerically with k in h Mpc^{-1} double cosmology::Delta2_L_num(double k, double z) { // if(!bool_init_PSL0) { init_powerspectra_L(); } double logk=log10(k); double result; if(logk>kmin&&logk<kmax) { result=gsl_spline_eval (PSL0_spline,logk, PSL0_acc); } else if (logk<=kmin) { //std::cout<<"# "<<"PSL_spline: Interpolation not possible k not within range "<<k<<std::endl; //exit(0); //result=log10(Delta2_L(k,z)); //result=1.0e-30; //Extrapolate now result=PSL0_ylow+PSL0_dlow*(logk-PSL0_xlow); } else if (logk>=kmax) { result=PSL0_yhigh+PSL0_dhigh*(logk-PSL0_xhigh); } result = pow(10.,result); if(z!=z_glob){ result=result*pow(growthfactor_num(z),2.); }else{ result=result*pow(gf_glob,2.); } return result; }
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 }
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); } }
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 }
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); }
double cMorph::AkimaInterpolate(const double factor, double v1, double v2, double v3, double v4, double v5, double v6, const bool angular) { if (angular) { QList<double*> vals; vals << &v1 << &v2 << &v3 << &v4 << &v5 << &v6; NearestNeighbourAngle(vals); } double x[] = { -2, -1, 0, 1, 2, 3 }; double y[] = { v1, v2, v3, v4, v5, v6 }; // more info: http://www.alglib.net/interpolation/spline3.php gsl_spline_init(splineAkimaPeriodic, x, y, listSize); double value = gsl_spline_eval(splineAkimaPeriodic, factor, interpolationAccelerator); if (angular) { return LimitAngle(value); } else { return value; } }
double bath_js03_f_gt_i(double tau, void *params) { js03_bath_func *bf; double Ctau,t; tmp_bft *bft=params; bf=bft->bf; t=bft->t; if(tau>=0) { Ctau=gsl_spline_eval(bf->BATH_JS03_Ct_i_Spline,tau,bf->BATH_JS03_Ct_i_Spline_Acc); } else { Ctau=-1.0*gsl_spline_eval(bf->BATH_JS03_Ct_i_Spline,-1.0*tau,bf->BATH_JS03_Ct_i_Spline_Acc); } return (Ctau*(t-tau)); }
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; }