Esempio n. 1
0
guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
			GObexFunc complete_func, gpointer user_data,
			GError **err, guint8 first_hdr_id, ...)
{
	struct transfer *transfer;
	GObexPacket *req;
	va_list args;

	transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
	transfer->data_producer = data_func;

	va_start(args, first_hdr_id);
	req = g_obex_packet_new_valist(G_OBEX_OP_PUT, FALSE,
							first_hdr_id, args);
	va_end(args);

	g_obex_packet_add_body(req, put_get_data, transfer);

	transfer->req_id = g_obex_send_req(obex, req, -1, transfer_response,
								transfer, err);
	if (transfer->req_id == 0) {
		transfer_free(transfer);
		return 0;
	}

	return transfer->id;
}
Esempio n. 2
0
guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
			GObexDataProducer data_func, GObexFunc complete_func,
			gpointer user_data, GError **err)
{
	struct transfer *transfer;

	g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

	if (g_obex_packet_get_operation(req, NULL) != G_OBEX_OP_PUT)
		return 0;

	transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
	transfer->data_producer = data_func;

	g_obex_packet_add_body(req, put_get_data, transfer);

	transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
					transfer_response, transfer, err);
	if (transfer->req_id == 0) {
		transfer_free(transfer);
		return 0;
	}

	g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);

	return transfer->id;
}
Esempio n. 3
0
static void transfer_complete(struct transfer *transfer, GError *err)
{
	transfer->complete_func(transfer->obex, err, transfer->user_data);
	/* Check if the complete_func removed the transfer */
	if (g_slist_find(transfers, transfer) == NULL)
		return;
	transfer_free(transfer);
}
Esempio n. 4
0
static void transfer_complete(struct transfer *transfer, GError *err)
{
	guint id = transfer->id;

	g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);

	transfer->complete_func(transfer->obex, err, transfer->user_data);
	/* Check if the complete_func removed the transfer */
	if (find_transfer(id) == NULL)
		return;

	transfer_free(transfer);
}
Esempio n. 5
0
void manager_unregister_transfer(struct obex_transfer *transfer)
{
	struct obex_session *os;

	if (transfer == NULL)
		return;

	os = transfer->session;

	if (transfer->status == TRANSFER_STATUS_ACTIVE)
		emit_transfer_completed(transfer, os->offset == os->size);

	g_dbus_unregister_interface(connection, transfer->path,
							TRANSFER_INTERFACE);

	transfer_free(transfer);
}
Esempio n. 6
0
struct obex_transfer *manager_register_transfer(struct obex_session *os)
{
	struct obex_transfer *transfer;
	static unsigned int id = 0;

	transfer = g_new0(struct obex_transfer, 1);
	transfer->path = g_strdup_printf("%s/session%u/transfer%u",
					SESSION_BASE_PATH, os->id, id++);
	transfer->session = os;

	if (!g_dbus_register_interface(connection, transfer->path,
				TRANSFER_INTERFACE,
				transfer_methods, NULL,
				transfer_properties, transfer, NULL)) {
		error("Cannot register Transfer interface.");
		transfer_free(transfer);
		return NULL;
	}

	return transfer;
}
Esempio n. 7
0
guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
			GObexDataProducer data_func, GObexFunc complete_func,
			gpointer user_data, GError **err)
{
	struct transfer *transfer;

	if (g_obex_packet_get_operation(req, NULL) != G_OBEX_OP_PUT)
		return 0;

	transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
	transfer->data_producer = data_func;

	g_obex_packet_add_body(req, put_get_data, transfer);

	transfer->req_id = g_obex_send_req(obex, req, -1, transfer_response,
								transfer, err);
	if (transfer->req_id == 0) {
		transfer_free(transfer);
		return 0;
	}

	return transfer->id;
}
Esempio n. 8
0
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_;

}
Esempio n. 9
0
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_;

}
Esempio n. 10
0
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_;

}
Esempio n. 11
0
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_;

}
Esempio n. 12
0
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_;

}