void init_game(void) { printf("GUI Initialization...\n"); if (TTF_Init() == -1) { fprintf(stderr, "TTF Initlization error: %s\n", TTF_GetError()); exit(1); } font_small = TTF_OpenFont(IMG_PREFIX "font.ttf", 10); font_big = TTF_OpenFont(IMG_PREFIX "font.ttf", 14); if (!font_small || !font_big) { fprintf(stderr, "Unable to open TTF font: %s\n", TTF_GetError()); exit(1); } screen = window_init(); if(!screen) { fprintf(stderr, "Unable to open display. Aborting.\n"); exit(1); } SDL_EnableKeyRepeat(100, 300); sprites = sprites_init(); if(!sprites) { fprintf(stderr, "Unable to initalize sprites. Aborting.\n"); exit(1); } color_black = SDL_MapRGB(screen->format, 0, 0, 0); game_board = MySurfaceCreate(taille_carte_x() * TAILLE_CASE + 2, taille_carte_y() * TAILLE_CASE + 2); game_background = background_init(taille_carte_x(), taille_carte_y()); if(!game_background) { fprintf(stderr, "Unable to load background.\n"); exit(1); } init_jeu(&jeu); sprites = sprites_init(); nouveau_tour(&jeu); render_map(); }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } /****** here you can output the evolution of any background quanitity you are interested in ******/ int index_eta; for (index_eta=0; index_eta<ba.bt_size; index_eta++) { fprintf(stdout, "tau=%e z=%e a=%e H=%e\n", ba.tau_table[index_eta], ba.z_table[index_eta], ba.background_table[index_eta*ba.bg_size+ba.index_bg_a], ba.background_table[index_eta*ba.bg_size+ba.index_bg_H]); } /****** all calculations done, now free the structures ******/ if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (pt.has_perturbations == _TRUE_) { /*********************************************************************/ /* here you can output the source function S(k,tau) of your choice */ /*********************************************************************/ FILE * output; int index_k,index_tau; /* choose a mode (scalar, tensor, ...) */ int index_md=pt.index_md_scalars; /* choose a type (temperature, polarization, grav. pot., ...) */ int index_type=pt.index_tp_t0; /* choose an initial condition (ad, bi, cdi, nid, niv, ...) */ int index_ic=pt.index_ic_ad; output=fopen("output/source.dat","w"); fprintf(output,"# k tau S\n"); for (index_k=0; index_k < pt.k_size[index_md]; index_k++) { for (index_tau=0; index_tau < pt.tau_size; index_tau++) { fprintf(output,"%e %e %e\n", pt.k[index_md][index_k], pt.tau_sampling[index_tau], pt.sources[index_md] [index_ic * pt.tp_size[index_md] + index_type] [index_tau * pt.k_size[index_md] + index_k] ); } fprintf(output,"\n"); } fclose(output); } /****** all calculations done, now free the structures ******/ if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct lensing le; /* for lensing spectra */ struct output op; /* for output files */ struct spectra_nl nl; /* for calculation of non-linear spectra */ ErrorMsg errmsg; if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&le,&op,&nl,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&bs,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } if (primordial_init(&pr,&pt,&pm) == _FAILURE_) { printf("\n\nError in primordial_init \n=>%s\n",pm.error_message); return _FAILURE_; } if (spectra_init(&ba,&pt,&tr,&pm,&sp) == _FAILURE_) { printf("\n\nError in spectra_init \n=>%s\n",sp.error_message); return _FAILURE_; } if (output_init(&ba,&pt,&sp,&op) == _FAILURE_) { printf("\n\nError in output_init \n=>%s\n",op.error_message); return _FAILURE_; } /****** done ******/ int index_mode=0; int index_eta; int index_ic=0; int index_k; double delta_rho_bc,rho_bc; double delta_i,rho_i; double P_bc; int last_index_back; double * pvecback_long; double k,pk; FILE * output; double z,eta; double * tki; if(pt.has_matter_transfers == _FALSE_) { printf("You need to switch on mTk calculation for this code\n"); return _FAILURE_; } output=fopen("output/Pcb.dat","w"); class_alloc(pvecback_long,sizeof(double)*ba.bg_size,errmsg); class_alloc(tki,sizeof(double)*sp.ln_k_size*sp.tr_size,errmsg); z=0.; if(background_eta_of_z(&ba,z,&eta) == _FAILURE_) { printf("\n\nError running background_eta_of_z \n=>%s\n",ba.error_message); return _FAILURE_; } if(background_at_eta(&ba, eta, long_info, normal, &last_index_back, pvecback_long) == _FAILURE_) { printf("\n\nError running background_at_eta \n=>%s\n",ba.error_message); return _FAILURE_; } if (spectra_tk_at_z(&ba,&sp,z,tki) == _FAILURE_) { printf("\n\nError in spectra_tk_at_z \n=>%s\n",sp.error_message); return _FAILURE_; } for (index_k=0; index_k<sp.ln_k_size; index_k++) { k=exp(sp.ln_k[index_k]); delta_rho_bc=0.; rho_bc=0.; /* T_b(k,eta) */ delta_i = tki[index_k*sp.tr_size+sp.index_tr_b]; rho_i = pvecback_long[ba.index_bg_rho_b]; delta_rho_bc += rho_i * delta_i; rho_bc += rho_i; /* T_cdm(k,eta) */ if (ba.has_cdm == _TRUE_) { delta_i = tki[index_k*sp.tr_size+sp.index_tr_cdm]; rho_i = pvecback_long[ba.index_bg_rho_cdm]; delta_rho_bc += rho_i * delta_i; rho_bc += rho_i; } if (primordial_spectrum_at_k(&pm,index_mode,linear,k,&pk) == _FAILURE_) { printf("\n\nError in primordial_spectrum_at_k \n=>%s\n",pm.error_message); return _FAILURE_; } P_bc=pk*pow(delta_rho_bc/rho_bc,2)*2.*_PI_*_PI_/k/k/k; fprintf(output,"%e %e\n",k,P_bc); } /******************/ if (spectra_free(&sp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",sp.error_message); return _FAILURE_; } if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (primordial_init(&pr,&pt,&pm) == _FAILURE_) { printf("\n\nError in primordial_init \n=>%s\n",pm.error_message); return _FAILURE_; } if (nonlinear_init(&pr,&ba,&th,&pt,&pm,&nl) == _FAILURE_) { printf("\n\nError in nonlinear_init \n=>%s\n",nl.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&nl,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } /****** output the transfer functions ******/ printf("Output of transfer functions (l, q, k, nu, Delta)\n"); printf("(in flat space, q=k and nu=inf) \n"); /* 1) select the mode, initial condition, type and multipole of the function you want to plot: */ int index_mode=pt.index_md_scalars; int index_ic =pt.index_ic_ad; int index_type=tr.index_tt_t0; /* 2) here is an illustration of how to output the transfer functions at some (k,l)'s of your choice */ /* int index_l = 0; double q=3.6e-4; double transfer; if (transfer_functions_at_q(&tr, index_mode, index_ic, index_type, index_l, q, &transfer ) == _FAILURE_) { printf("\n\nError in transfer_function_at_k \n=>%s\n",tr.error_message); return _FAILURE_; } printf("%d %e %e\n",tr.l[index_l],q,transfer); */ /* 3) here you can output the full tabulated arrays for all k and l's*/ int index_q; int index_l; double transfer; FILE * output; output=fopen("output/test.trsf","w"); for (index_l=0; index_l<tr.l_size[index_mode]; index_l++) { for (index_q=0; index_q<tr.q_size; index_q++) { /* use this to plot a single type : */ transfer = tr.transfer[index_mode] [((index_ic * tr.tt_size[index_mode] + index_type) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q]; /* or use this to plot the full temperature transfer function: */ /* transfer = tr.transfer[index_mode][((index_ic * tr.tt_size[index_mode] + tr.index_tt_t0) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q] + tr.transfer[index_mode][((index_ic * tr.tt_size[index_mode] + tr.index_tt_t1) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q] + tr.transfer[index_mode][((index_ic * tr.tt_size[index_mode] + tr.index_tt_t2) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q]; */ if (transfer != 0.) { fprintf(output,"%d %e %e %e %e\n", tr.l[index_l], tr.q[index_q], tr.k[index_mode][index_q], tr.q[index_q]/sqrt(ba.sgnK*ba.K), transfer); } } fprintf(output,"\n\n"); //} } fclose(output); /****** all calculations done, now free the structures ******/ if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (nonlinear_free(&nl) == _FAILURE_) { printf("\n\nError in nonlinear_free \n=>%s\n",nl.error_message); return _FAILURE_; } if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed sepctra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error message */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } /********************************************/ /***** output thermodynamics quantities *****/ /********************************************/ int i; double tau; double z; int last_index; double pvecback[30]; double pvecthermo[30]; printf("#1: redshift z\n"); printf("#2: conformal time tau\n"); printf("#3: electron ionization fraction x_e\n"); printf("#4: Thomson scattering rate kappa'\n"); printf("#5: Thomson scattering rate derivative kappa''\n"); printf("#6: Thomson scattering rate derivative kappa'''\n"); printf("#7: exponential of optical depth e^-kappa\n"); printf("#8: visibility function g = kappa' e^-kappa \n"); printf("#9: derivative of visibility function g' \n"); printf("#10: second derivative of visibility function g'' \n"); printf("#11: squared baryon temperature\n"); printf("#12: squared baryon sound speed c_b^2 \n"); printf("#13: baryon drag optical depth tau_d \n"); printf("#14: variation rate \n"); /* first, quantities stored in table */ for (i=0; i < th.tt_size; i++) { background_tau_of_z(&ba,th.z_table[i],&tau); printf("%.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e\n", th.z_table[i], tau, th.thermodynamics_table[i*th.th_size+th.index_th_xe], th.thermodynamics_table[i*th.th_size+th.index_th_dkappa], th.thermodynamics_table[i*th.th_size+th.index_th_ddkappa], th.thermodynamics_table[i*th.th_size+th.index_th_dddkappa], th.thermodynamics_table[i*th.th_size+th.index_th_exp_m_kappa], th.thermodynamics_table[i*th.th_size+th.index_th_g], th.thermodynamics_table[i*th.th_size+th.index_th_dg], th.thermodynamics_table[i*th.th_size+th.index_th_ddg], th.thermodynamics_table[i*th.th_size+th.index_th_Tb], th.thermodynamics_table[i*th.th_size+th.index_th_cb2], th.thermodynamics_table[i*th.th_size+th.index_th_tau_d], th.thermodynamics_table[i*th.th_size+th.index_th_rate] ); } /* the function thermodynamics_at_z knows how to extrapolate at redshifts above the maximum redshift in the table. Here we add to the previous output a few more points at higher redshift. */ for (z = th.z_table[th.tt_size-1]; z < 1000*th.z_table[th.tt_size-1]; z *= 2.) { background_tau_of_z(&ba,z,&tau); background_at_tau(&ba,tau,ba.normal_info,ba.inter_normal,&last_index,pvecback); thermodynamics_at_z(&ba,&th,z,th.inter_normal,&last_index,pvecback,pvecthermo); printf("%.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e\n", z, tau, pvecthermo[th.index_th_xe], pvecthermo[th.index_th_dkappa], pvecthermo[th.index_th_ddkappa], pvecthermo[th.index_th_dddkappa], pvecthermo[th.index_th_exp_m_kappa], pvecthermo[th.index_th_g], pvecthermo[th.index_th_dg], pvecthermo[th.index_th_ddg], pvecthermo[th.index_th_Tb], pvecthermo[th.index_th_cb2], pvecthermo[th.index_th_tau_d], pvecthermo[th.index_th_rate] ); } /****** all calculations done, now free the structures ******/ if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main() { count = 0; struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ FILE * fp; FILE * fp2; char f_tmp[50]; double fbest[NREDSHIFT][LMAX]; int i,j; int num_ct_max=7; int lmax, lmin; int l; /* l starts from 2 (quadrupole) in spectrum calculation, but starts from lmin in calculating Fisher matrix. */ double * psCl; /* power spectrum in 2-D */ double * psCl_fid; double * dCldPara[NVARY]; /* first derivatives: for Fisher matrix */ double * var_cl; /* uncertainty of Cl's */ double z; int iz; double khmax; /* We used fitting formula to get *smallest* nonlinear kh, or the turning point from linear to nonlinear; see the paper or the accompanying mathematica notebook (please email me for it) for detail */ double zs[NREDSHIFT]; double pvecback[100]; double fisher[NVARY][NVARY]= {0}; /* parameter of the telescope */ double tele_res0 = 2.9; /* also FWHM, angular resolution in arc minute, will be in the following converted to radian */ double tele_res; /* angular resolution at z: tele_res = tele_res0*(1+z) */ double tele_temp_sys = 20.; /* system temperature in K; always mK in calculation */ double tele_time_pix; /* observation time per pixel, in [sec] */ double tele_freq = 0.2e6; /* delta_nu in Hz; [tele_] noise = temp_sys / sqrt(freq*time_pix) */ //Two settings are considered in the paper. /* double tele_time_tot = 8. ;//survey time in [yr] int tele_num_beam=100; double tele_fsky = 0.575; */ double tele_time_tot = 1. ;// survey time in [yr] int tele_num_beam=1; double tele_fsky = 0.0005; double noise_ins; double noise_fg = 0.; /* RMS of the residual foreground noise, in mK; currently set to zero, meaning the foreground are all effectively cleaned */ double deltaN; double tmp_cl_noise; double delta_N; double freqH = 1420.4; double freq_step, center_f; struct file_content fc; double tau; double deg2rad = M_PI/180.; double yr2sec = 31556926; tele_res0 = tele_res0/60.*deg2rad; freq_step = freqH*(1./(1.+ZMIN) - 1./(1.+ZMAX))/(NREDSHIFT-1.); center_f=freqH*(1./(1.+ZMIN)); for(iz=0; iz<NREDSHIFT; iz++,center_f-=freq_step) zs[iz] = freqH/center_f-1; for(iz=0;iz<NREDSHIFT; iz++) printf("one z is %f \n",zs[iz]); if (set_fiducial(&fc,errmsg) == _FAILURE_) { printf("\n\nError set fiducial parameters \n=>%s\n",errmsg); return _FAILURE_; } /* read input parameters and compute bessel functions once and for all */ if (input_init(&fc,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } fp2=fopen("fsky_best.dat", "w"); for (iz = 0; iz<NREDSHIFT; iz++) { z = zs[iz]; tele_res = tele_res0 * (1.+z); /* [minute deg] tele_res[minute degree] grows with z */ khmax=0.170255158514253+0.13037369068045573*z-0.10832440336426165* pow(z,2)+0.046760120277751734*pow(z,3) - 0.005948516308501343* pow(z,4); /* fitting formula for minimum NL k-modes */ background_tau_of_z(&ba, z, &tau); lmax = (int) (khmax*ba.h * (ba.conformal_age - tau)); printf("lmax = %d\n", lmax); background_functions(&ba, 1/(1.+z), 1, pvecback); lmin = (int) (ba.conformal_age - tau) * 2*M_PI/(pow(1+z,2)/pvecback[ba.index_bg_H]*freq_step/freqH); printf("lmin = %d\n", lmin); psCl_fid = malloc((lmax+1)*sizeof(double)); var_cl = malloc((lmax+1)*sizeof(double)); for(i=0; i<NVARY; i++) dCldPara[i] = malloc((lmax+1)*sizeof(double)); class_assuming_bessels_computed(&fc,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op, \ z,psCl_fid,lmin,lmax,errmsg); for(i=lmin; i<=lmax; i+=10) printf("psCl_fid[%d] = %e\n", i, psCl_fid[i]); for (i=0; i<NVARY; i++) { /* Vary each parameter and get dCldPara[ipara][il]'s at redshift z. Allocate * an array psCl first; psCl is used only inside the loop, so allocate * and free inside the loop. */ psCl = malloc((lmax+1)*sizeof(double)); vary_parameter(&fc,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op, \ z,psCl,psCl_fid,lmin,lmax,i,dCldPara[i],errmsg); free(psCl); } tele_res=tele_res0 * (1+z); tele_time_pix=tele_time_tot * yr2sec * tele_num_beam * pow(tele_res,2) / (4*M_PI*tele_fsky); /* Radio equation in mK, in consistence with signal * dimension. */ noise_ins = tele_temp_sys*1000. / sqrt(tele_freq*tele_time_pix); delta_N = noise_ins + noise_fg; for (l=lmin; l<=lmax; l++) { tmp_cl_noise = pow(tele_res,2) * pow(delta_N,2) * exp(l*(l+1) * pow(tele_res,2)/(8*log(2))); var_cl[l] = 2./((2*l+1)*tele_fsky) * pow(psCl_fid[l]+tmp_cl_noise, 2); //variance of cl printf("noise vs signal: %e, %e\n", tmp_cl_noise,psCl_fid[l]); fbest[iz][l]=(tele_freq*tele_num_beam*tele_time_tot*yr2sec*psCl_fid[l])/(4*M_PI*pow(tele_temp_sys*1000.,2)*exp(l*(l+1) * pow(tele_res,2)/(8*log(2)))); } if(NVARY != 0) for (i = 0; i<NVARY; i++) for (j = 0; j<NVARY; j++) for (l = lmin; l <= lmax; l++) fisher[i][j] += dCldPara[i][l]*dCldPara[j][l]/var_cl[l]; free(psCl_fid); free(var_cl); for(i=0; i<NVARY; i++) free(dCldPara[i]); } for (iz=0; iz<NREDSHIFT; iz++) { for (l=0; l<LMAX; l++) fprintf(fp2, "%f ", fbest[iz][l]); fprintf(fp2, "\n"); } fclose(fp2); fp = fopen("fisher.mat","w"); for (i=0; i<NVARY; i++) { for (j=0; j<NVARY; j++) { printf("%20.10e ", fisher[i][j]); fprintf(fp, "%20.10e ", fisher[i][j]); } printf("\n"); fprintf(fp, "\n"); } for (i=0; i<NVARY; i++) fprintf(fp, "%s ", fc.name[i]); fprintf(fp, "\n"); for (i=0; i<NVARY; i++) fprintf(fp, "%s ", fc.value[i]); fprintf(fp, "\n"); fclose(fp); /* now free the bessel structure */ if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } return _SUCCESS_; }
int class_assuming_bessels_computed( struct file_content *pfc, struct precision * ppr, struct background * pba, struct thermo * pth, struct perturbs * ppt, struct bessels * pbs, struct transfers * ptr, struct primordial * ppm, struct spectra * psp, struct nonlinear * pnl, struct lensing * ple, struct output * pop, double z, double * psCl, int lmin, int lmax, ErrorMsg errmsg) { /*local variables*/ double pvecback[100]; double T21; int l; double tau; /* conformal age, in unit of Mpc */ double pk_tmp; double k; double * pk_ic; if (input_init(pfc,ppr,pba,pth,ppt,pbs,ptr,ppm,psp,pnl,ple,pop,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(ppr,pba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",pba->error_message); return _FAILURE_; } if (thermodynamics_init(ppr,pba,pth) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",pth->error_message); return _FAILURE_; } if (perturb_init(ppr,pba,pth,ppt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",ppt->error_message); return _FAILURE_; } if (transfer_init(ppr,pba,pth,ppt,pbs,ptr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",ptr->error_message); return _FAILURE_; } if (primordial_init(ppr,ppt,ppm) == _FAILURE_) { printf("\n\nError in primordial_init \n=>%s\n",ppm->error_message); return _FAILURE_; } if (spectra_init(ppr,pba,ppt,ptr,ppm,psp) == _FAILURE_) { printf("\n\nError in spectra_init \n=>%s\n",psp->error_message); return _FAILURE_; } if (nonlinear_init(ppr,pba,pth,ppt,pbs,ptr,ppm,psp,pnl) == _FAILURE_) { printf("\n\nError in nonlinear_init \n=>%s\n",pnl->error_message); return _FAILURE_; } if (lensing_init(ppr,ppt,psp,pnl,ple) == _FAILURE_) { printf("\n\nError in lensing_init \n=>%s\n",ple->error_message); return _FAILURE_; } if (output_init(pba,ppt,psp,pnl,ple,pop) == _FAILURE_) { printf("\n\nError in output_init \n=>%s\n",pop->error_message); return _FAILURE_; } background_functions(pba, 1/(1.+z), 1, pvecback); /* T21 := 7.59*10^-2 h (1+\delta) (1+z)^2 / E(z); * E[z]:= Sqrt[Omega_m(1+z)^3+Omega_l exp(-3 Integrate[(1+w)/a, a])] mK */ T21 = 7.59 * 0.01 * pba->h * pow(1.+z,2) / (pvecback[pba->index_bg_H]/pba->H0); background_tau_of_z(pba, z, &tau); for (l=lmin; l<=lmax; l+=1) { k = l/(pba->conformal_age - tau); /* tau in Mpc; k in spectra_pk_at_k_and_z is in [1/Mpc] */ spectra_pk_at_k_and_z(pba, ppm, psp, k, z, &pk_tmp, pk_ic); /* 3-D vs 2-D: l(l+1)Cl/2PI = k^3 P21(k)/2PI^2, P21(k) = (T21*Y)^2 * P(k) */ /* psCl[l]'s are in mK^2 */ if(l%100==0) printf("z is %e, l is %d, tau is %e, k is %e, pk is %e\n", z, l, tau, k, pk_tmp); psCl[l] = 2*M_PI/(l*1.0*(l+1)) * T21*T21 * pow(k, 3) * pk_tmp/(2*M_PI*M_PI); } /****** all calculations done, now free the structures ******/ if (lensing_free(ple) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",ple->error_message); return _FAILURE_; } if (nonlinear_free(pnl) == _FAILURE_) { printf("\n\nError in nonlinear_free \n=>%s\n",pnl->error_message); return _FAILURE_; } if (spectra_free(psp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",psp->error_message); return _FAILURE_; } if (primordial_free(ppm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",ppm->error_message); return _FAILURE_; } if (transfer_free(ptr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",ptr->error_message); return _FAILURE_; } if (perturb_free(ppt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",ppt->error_message); return _FAILURE_; } if (thermodynamics_free(pth) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",pth->error_message); return _FAILURE_; } if (background_free(pba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",pba->error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&bs,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } /****** output the transfer functions ******/ printf("Output of transfer functions (l, k, Delta)\n"); /* 1) select the mode, initial condition, type and multipole of the function you want to plot: */ int index_mode=pt.index_md_scalars; int index_ic =pt.index_ic_ad; int index_type=tr.index_tt_lcmb; //int index_type=tr.index_tt_density+2; /* 2) here is an illustration of how to output the transfer functions at some (k,l)'s of your choice */ /* int index_l = 0; double k=3.6e-4; double transfer; if (transfer_functions_at_k(&tr, index_mode, index_ic, index_type, index_l, k, &transfer ) == _FAILURE_) { printf("\n\nError in transfer_function_at_k \n=>%s\n",tr.error_message); return _FAILURE_; } printf("%d %e %e\n",tr.l[index_l],k,transfer); */ /* 3) here you can output the full tabulated arrays for all k and l's*/ int index_k; int index_l; double transfer; for (index_l=0; index_l<tr.l_size[index_mode]; index_l++) { //for (index_l=20; index_l<21; index_l++) { for (index_k=0; index_k<tr.k_size[index_mode]; index_k++) { transfer=tr.transfer[index_mode] [((index_ic * tr.tt_size[index_mode] + index_type) * tr.l_size[index_mode] + index_l) * tr.k_size[index_mode] + index_k]; if (transfer != 0.) { printf("%d %e %e\n",tr.l[index_l],tr.k[index_mode][index_k],transfer); } } printf("\n\n"); } /****** all calculations done, now free the structures ******/ if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* precision parameters (1st-order) */ struct precision2 pr2; /* precision parameters (2nd-order) */ struct background ba; /* cosmological background */ struct thermo th; /* thermodynamics */ struct perturbs pt; /* source functions (1st-order) */ struct perturbs2 pt2; /* source functions (2nd-order) */ struct transfers tr; /* transfer functions (1st-order) */ struct bessels bs; /* bessel functions (1st-order) */ struct bessels2 bs2; /* bessel functions (2nd-order) */ struct transfers2 tr2; /* transfer functions (2nd-order) */ struct primordial pm; /* primordial spectra */ struct spectra sp; /* output spectra (1st-order) */ struct nonlinear nl; /* non-linear spectra */ struct lensing le; /* lensed spectra */ struct bispectra bi; /* bispectra */ struct fisher fi; /* fisher matrix */ struct output op; /* output files */ ErrorMsg errmsg; /* error messages */ // =================================================================================== // = Parse arguments = // =================================================================================== /* We introduce the n_args variable to differentiate between CLASS arguments and the arguments for this function */ int n_args = 1; int index_k; /* CLASS/SONG can accept either one argument... */ if (argc == 2 + n_args) { struct stat st; stat (argv[1], &st); int is_dir = (S_ISDIR (st.st_mode) != 0); if (!is_dir) { printf ("ERROR: when giving two arguments, the first one ('%s') should be a run directory\n", argv[1]); return _FAILURE_; } index_k = atoi(argv[2]); } /* ... or two arguments */ else if (argc == 3 + n_args) { index_k = atoi(argv[3]); } else { printf ("usage: %s <ini file> <pre file> <index k>\n", argv[0]); printf (" %s <run_directory> <index k>\n", argv[0]); return _FAILURE_; } // =================================================================================== // = Compute perturbations = // =================================================================================== /* Decrease the argument counter. The reason is that CLASS should be fed only its default arguments, that is the parameter files and, optionally, the run directory */ argc -= n_args; if (input_init_from_arguments(argc,argv,&pr,&ba,&th,&pt,&tr,&pm, &sp,&nl,&le,&bs,&bi,&fi,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (pt.has_perturbations2 == _TRUE_) { if (input2_init_from_arguments(argc,argv,&pr,&pr2,&ba,&th,&pt,&pt2,&tr,&bs,&bs2,&tr2,&pm, &sp,&nl,&le,&bi,&fi,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } /* Compute only the first-order early transfer functions, no matter what is specified in the input files */ pt2.has_early_transfers1_only = _TRUE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (pt.has_perturbations2 == _FALSE_) { if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } } else { if (perturb2_init(&pr,&pr2,&ba,&th,&pt,&pt2) == _FAILURE_) { printf("\n\nError in perturb2_init \n=>%s\n",pt2.error_message); return _FAILURE_; } } /* Run some checks */ if (pt.has_scalars == _FALSE_) { printf ("ERROR: only scalar modes supported by this function\n"); return _FAILURE_; } int index_md = pt.index_md_scalars; if (pt.has_ad == _FALSE_) { printf ("ERROR: only adiabatic modes supported by this function\n"); return _FAILURE_; } int index_ic = pt.index_ic_ad; if ((index_k<0) || (index_k>=pt.k_size[index_md])) { printf ("ERROR: index_k should be between index_k=%d (k=%g) and index_k=%d (k=%g)\n", 0, pt.k[index_md][0], pt.k_size[index_md]-1, pt.k[index_md][pt.k_size[index_md]-1]); return _FAILURE_; } // =================================================================================== // = First or second order? = // =================================================================================== /* Should we show the line-of-sight sources or the quadratic sources? */ short tabulate_los_sources = _FALSE_; /* If we are in standard 1st-order mode, we can only access the line-of-sight sources */ if (pt2.has_perturbations2 == _FALSE_) tabulate_los_sources = _TRUE_; /* Information about the cosmological model */ double h = ba.h; double a_equality = ba.a_eq; fprintf (stderr, "# Cosmological parameters:\n"); fprintf (stderr, "# tau0 = %g, a_equality = %g, Omega_b = %g, Tcmb = %g, Omega_cdm = %g\n", ba.conformal_age, ba.a_eq, ba.Omega0_b, ba.T_cmb, ba.Omega0_cdm); fprintf (stderr, "# omega_lambda = %g, Omega_ur = %g, Omega_fld = %g, h = %g, tau0 = %g\n", ba.Omega0_lambda, ba.Omega0_ur, ba.Omega0_fld, ba.h, ba.conformal_age); fprintf (stderr, "# omega_b = %g, omega_cdm = %g, omega_lambda = %g, omega_ur = %g, omega_fld = %g\n", ba.Omega0_b*h*h, ba.Omega0_cdm*h*h, ba.Omega0_lambda*h*h, ba.Omega0_ur*h*h, ba.Omega0_fld*h*h); /* Info about the used gauge at first order */ fprintf (stderr, "# gauge = "); if (pt.gauge == newtonian) fprintf (stderr, "Newtonian gauge\n"); if (pt.gauge == synchronous) fprintf (stderr, "synchronous gauge\n"); /* Sizes associated to the non-running indices in the ***sources table */ int k_size = pt.k_size[index_md]; int tp_size = pt.tp_size[index_md]; int qs_size; if (pt.has_perturbations2 == _TRUE_) qs_size = pt.qs_size[index_md]; /* Account for overshooting of 'k' */ if(index_k > k_size-1) index_k = k_size-1; if(index_k < 0) index_k = 0; // =================================================================================== // = Print sources = // =================================================================================== /* Print information on 'k' */ double k = pt.k[index_md][index_k]; printf("# k = %g (index_k=%d)\n", pt.k[index_md][index_k], index_k); fprintf (stderr, "# k = %g (index_k=%d)\n", pt.k[index_md][index_k], index_k); /* Vector that will contain background quantities (we are only interested in 'a') */ double * pvecback = malloc(ba.bg_size_short*sizeof(double)); /* Number of rows that will be printed */ int tau_size; double tau_ini, tau_end; if (tabulate_los_sources == _TRUE_) { tau_size = pt.tau_size; tau_ini = pt.tau_sampling[0]; tau_end = pt.tau_sampling[pt.tau_size-1]; } else { tau_size = pt.tau_size_quadsources; tau_ini = pt.tau_sampling_quadsources[0]; tau_end = pt.tau_sampling_quadsources[pt.tau_size_quadsources-1]; }; /* Some debug info */ if (tabulate_los_sources == _TRUE_) fprintf (stderr, "# Number of source types tp_size=%d\n", tp_size); else fprintf (stderr, "# Number of source types qs_size=%d\n", qs_size); fprintf (stderr, "# Will print %d rows from tau=%g to %g\n", tau_size, tau_ini, tau_end); fprintf (stderr, "# Considered mode: index_md=%d\n", index_md); fprintf (stderr, "# Considered initial condition: index_ic=%d\n", index_ic); /* Running index used to number the columns */ int index_print=1; /* First row contains the labels of the different types */ fprintf (stderr, "%11s(%03d) ", "tau", index_print++); // Conformal time fprintf (stderr, "%11s(%03d) ", "a", index_print++); // Scale factor fprintf (stderr, "%11s(%03d) ", "y", index_print++); // Scale factor normalized to equality fprintf (stderr, "%11s(%03d) ", "k_tau", index_print++); // Scale times Conformal time /* Build labels for the line-of-sight sources */ char label[32]; if (tabulate_los_sources == _TRUE_) { for (int index_tp = 0; index_tp < tp_size; ++index_tp) { sprintf(label, "S_%d", index_tp); fprintf (stderr, "%11s(%03d) ", label, index_print++); } } /* Labels for the second-order quadsources */ else { for (int index_tp = 0; index_tp < qs_size; ++index_tp) fprintf (stderr, "%11s(%03d) ", pt.qs_labels[index_md][index_tp], index_print++); } fprintf (stderr, "\n"); // =================================================================================== // = Loop on time = // =================================================================================== for (int index_tau = 0; index_tau < tau_size; ++index_tau) { double tau = (tabulate_los_sources==_TRUE_ ? pt.tau_sampling[index_tau] : pt.tau_sampling_quadsources[index_tau]); /* Extract value of the scale factor */ int dump; background_at_tau( &ba, tau, ba.short_info, ba.inter_normal, &dump, pvecback ); double a = pvecback[ba.index_bg_a]; fprintf (stderr, "%+16g ", tau); fprintf (stderr, "%+16e ", a); fprintf (stderr, "%+16e ", log10(a/a_equality)); fprintf (stderr, "%+16e ", tau*k); /* Line of sight sources */ if (tabulate_los_sources == _TRUE_) { for (int index_tp = 0; index_tp < tp_size; ++index_tp) { double var = pt.sources[index_md][index_ic*tp_size + index_tp][index_tau*k_size + index_k]; fprintf (stderr, "%+16e ", var); } } /* Sources for the second-order system */ else { for (int index_tp = 0; index_tp < qs_size; ++index_tp) { double var = pt.quadsources[index_md][index_ic*qs_size + index_tp][index_tau*k_size + index_k]; fprintf (stderr, "%+16e ", var); } } fprintf (stderr, "\n"); } // end of for(index_tau) // ===================================================================================== // = Free memory = // ===================================================================================== if (pt.has_perturbations2 == _TRUE_) { if (perturb2_free(&pr2, &pt2) == _FAILURE_) { printf("\n\nError in perturb2_free \n=>%s\n",pt2.error_message); return _FAILURE_; } } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions (1st-order) */ struct perturbs2 pt2; /* for source functions (2nd-order) */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&pt2,&bs,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } // Set verbosity to zero (we want to be able to send the output to a file and plot it) ba.background_verbose = 0; th.thermodynamics_verbose = 0; pt.perturbations_verbose = 0; pt2.perturbations2_verbose = 0; // Print arguments (debug) // int jj=0; // printf ("argc = %d\n", argc); // for (jj=0; jj<argc; ++jj) // printf("argv[%d] = %s\n", jj, argv[jj]); // Compute perturbations if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb2_init(&pr,&ba,&th,&pt,&pt2) == _FAILURE_) { printf("\n\nError in perturb2_init \n=>%s\n",pt2.error_message); return _FAILURE_; } // Print tau-sampling according to the chosen wavemode (k1, k2, or cosk1k2) int ii; for (ii=0; ii<pt2.tau_size; ++ii) printf ("%g\n", pt2.tau_sampling[ii]); // ================================================================================= // = Free memory = // ================================================================================= if (perturb2_free(&pr2,&pt2) == _FAILURE_) { printf("\n\nError in perturb2_free \n=>%s\n",pt2.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct output op; struct lensing le; struct spectra sp; /* for output spectra */ struct spectra_nl nl; /* for calculation of non-linear spectra */ ErrorMsg errmsg; if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&le,&op,&nl,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&bs,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } if (primordial_init(&pr,&pt,&pm) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",pm.error_message); return _FAILURE_; } if (spectra_init(&ba,&pt,&tr,&pm,&sp) == _FAILURE_) { printf("\n\nError in spectra_init \n=>%s\n",sp.error_message); return _FAILURE_; } if (trg_init(&pr,&ba,&th,&pm,&sp,&nl) == _FAILURE_) { printf("\n\nError in trg_init \n=>%s\n",nl.error_message); return _FAILURE_; } /****** done ******/ if (trg_free(&nl) == _FAILURE_) { printf("\n\nError in trg_free \n=>%s\n",nl.error_message); return _FAILURE_; } if (spectra_free(&sp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",sp.error_message); return _FAILURE_; } if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }