void run_avoid_navigation_move_target_waypoint(void)
{
  // TODO:

  // Use flightplan: LINE p1-p2
  // WP_p1 -> WP_p2

  // Align the nose with the direction of motion:
  int32_t dx = waypoints[WP_p2].x - waypoints[WP_p1].x;
  int32_t dy = waypoints[WP_p2].y - waypoints[WP_p1].y;
  // nav_heading = atan2() // INT32_ANGLE_FRAC

  //nav_set_heading_towards_waypoint(WP_p1);

  dx *= dx;
  dy *= dy;

  uint8_t avg = average_bin();
  if (avg > 10)
  {
    // There is danger!!
  }
}
Exemple #2
0
void fit_halo_profile(struct halo *HALO)
{
	double c=0, r=0, rho0, rho0_halo, rs, chi, gof, per; 
	double *x, *y, *e, *R, *y_th, *x_bin, *y_bin, *e_bin, rMin, rMax; 
	int bins, skip, N, j=0;

		r = HALO->Rvir;
		c = HALO->c; 
		bins = HALO->n_bins;
		skip = HALO->neg_r_bins;

		N = bins - skip;

		rho0 = HALO->rho0;
		rs = HALO->r2;

		x = (double*) calloc(N, sizeof(double));
		y = (double*) calloc(N, sizeof(double));
		e = (double*) calloc(N, sizeof(double));
		R = (double*) calloc(N, sizeof(double));
		
		for(j=0; j<N; j++)
		{
			x[j] = HALO->radius[j+skip];
			y[j] = HALO->rho[j+skip];
			e[j] = HALO->err[j+skip];
			R[j] = HALO->radius[j+skip]/r;
		}

			best_fit_nfw(rho0, rs, N, x, y, e);

			HALO->fit_nfw.rho0 = rho0;
			HALO->fit_nfw.rs = rs;
			HALO->fit_nfw.c = HALO->Rvir/rs;

			y_th = (double*) calloc(bins-skip,sizeof(double));

		for(j=skip; j<bins; j++)
		{
			y_th[j-skip] = nfw(HALO->radius[j], HALO->fit_nfw.rs, HALO->fit_nfw.rho0);
			//fprintf(stderr, "%d) R=%e, %e %e  %e\n", j, R[j-skip], rho0, y[j-skip], y_th[j-skip]);
		}

	// Various estimators for the goodness of fit
	chi = chi_square(y_th, y, e, N);
	gof = goodness_of_fit(y_th, y, N);
	per = percentage_error(y_th, y, N);
	
	chi /= (double) (bins-skip);

	HALO->fit_nfw.chi = chi;
	HALO->fit_nfw.gof = gof;
	HALO->fit_nfw.per = per;

		x_bin = (double*) calloc(BIN_PROFILE+1, sizeof(double));
		y_bin = (double*) calloc(BIN_PROFILE, sizeof(double));
		e_bin = (double*) calloc(BIN_PROFILE, sizeof(double));

		rMin = 2 * Rvir_frac_min;
		rMax = F_MAX * 1.01; //HALO->radius[bins-1]/r;
		x_bin = log_stepper(rMin, rMax, BIN_PROFILE+1);

		average_bin(R, y, x_bin, y_bin, e_bin, BIN_PROFILE+1, N);

	for(j=0; j<BIN_PROFILE; j++)
	{
		HALO->nfw.x[j] = 0.5 * (x_bin[j] + x_bin[j+1]);
		HALO->nfw.y[j] = y_bin[j];
		//fprintf(stderr, "%d  %e  %e\n", j, x_bin[j+1], y_bin[j]);
	}

	free(x);
	free(y);
	free(R);
	free(y_th);
	free(e);
//	fprintf(stderr, "ThisTask=%d, skip=%d, bins=%d, rho=%f, rs=%f, ChiSquare=%lf, Red=%lf\n", 
//		ThisTask, skip, bins, rho0, rs, chi_sq, chi_sq/(bins-skip));
}
// Sort subhalo velocity distribution and radial velocity distribution
void sort_velocity_distribution()
{
	int totSub=0, totHost=0, h=0, i=0, j=0, k=0, m=0, n=0, nBins=0;
	int *vel_y=NULL;	
	double vHost=0, vel_0=0, velMax=0, velMin=0, vDiff=0, sum=0, r=0; 
	double *vel=NULL, *vel_x=NULL, *all_r=NULL, *vel_r=NULL, *bin_r=NULL, *vel_err=NULL;

	totSub = SubStructure.N_sub;
	totHost = SubStructure.N_host;
	nBins = (int) (F_SUB * Settings.n_bins); 
	
	fprintf(stdout, "\nSorting sub halo velocity distribution.\n");
	Settings.tick=0;
	
	vel = (double*) calloc(totSub, sizeof(double));
	vel_x = (double*) calloc(nBins, sizeof(double));
	vel_y = (int*) calloc(nBins-1, sizeof(int));
	all_r = (double*) calloc(totSub, sizeof(double));
	bin_r = (double*) calloc(nBins, sizeof(double));
	vel_r = (double*) calloc(nBins-1, sizeof(double));
	vel_err = (double*) calloc(nBins-1, sizeof(double));

		for(i=0; i<totHost; i++) 
		{
			k = SubStructure.host[i].index;

			for(j=0; j<SubStructure.host[i].n_sub; j++) 
			{
				n = SubStructure.host[i].sub_index[j];
				r = 0;

				// Sort velocity difference
				sum = 0;
				for(m=0; m<3; m++)
					sum += pow2(Haloes[k].V[m]);
				vHost = sqrt(sum);

				sum = 0;
				for(m=0; m<3; m++)
					sum += pow2(Haloes[k].V[m] - Haloes[n].V[m]);
				vDiff = sqrt(sum);

				vel[h] = vDiff/vHost;

				// Sort velocity difference as a function of radius
				for(m=0; m<3; m++)
					sum += pow2(Haloes[k].X[m] - Haloes[n].X[m]);

				r = sqrt(sum);

				all_r[h] = r/Haloes[k].Rvir;
				h++;
			}	
		}	

			velMin = F_MIN * minimum(vel,totSub); 
			velMax = F_MAX * maximum(vel,totSub);
			vel_x = log_stepper(velMin, velMax, nBins);
			lin_bin(vel, vel_x, nBins, totSub, vel_y);

			bin_r = log_stepper(RMIN, RMAX, nBins);

			average_bin(all_r, vel, bin_r, vel_r, vel_err, nBins, totSub);

			HaloProperties[HALO_INDEX].vel_0 = vel_0;

		for(i=0; i<nBins-1; i++)
		{
			HaloProperties[HALO_INDEX].vel_sub_r[i] = vel_r[i];
			HaloProperties[HALO_INDEX].vel_sub[i] = 0.5 * (vel_x[i]+vel_x[i+1]);
			HaloProperties[HALO_INDEX].n_vel_sub[i] = vel_y[i];
			HaloProperties[HALO_INDEX].p_vel_sub[i] = (double) vel_y[i]/totSub;
		}
	
	free(vel);
	free(vel_x);
	free(vel_y);

	fprintf(stdout, "\n");
}
void sub_properties_per_host_halo(void)
{
	int i=0, j=0, k=0, l=0, m=0, nHost=0, totHost=0, Nsub=0, NsubTh=1, nBins=0, NsubTot=0, NsubTotTh=0;
	int *costh_bin_y, *cosphi_bin_y, *r_sub_bin_y, *n_sub_cum_bin, *all_n_bin;
	double rMin, rMax, R, V, M, Rvir, Vhost;
	double sum, cMax, cMin, cpMax, cpMin, ct=0, anis=0;
	double *costh, *costh_bin, *cosphi, *cosphi_bin, *err; 
	double *r_sub, *r_sub_bin, *v_sub, *v_sub_bin, *m_sub, *m_sub_bin, *m_sub_cum_bin;
	double *all_r_sub, *all_n_sub, *all_v_sub, *all_m_sub, *all_phi_sub, *all_theta_sub;
	double *all_n_sub_bin, *all_v_sub_bin, *all_m_sub_bin; 
	double *all_n_c_sub_bin, *all_m_c_sub_bin; 
	int *all_p_phi_sub_bin, *all_p_theta_sub_bin;

	INFO_MSG("Computing sub properties per each halo");

	totHost = SubStructure.N_host;
	nBins = (int) (F_SUB * Settings.n_bins); 
	
	all_phi_sub = (double*) calloc(1, sizeof(double));
	all_theta_sub = (double*) calloc(1, sizeof(double));
	all_r_sub = (double*) calloc(1, sizeof(double));
	all_n_sub = (double*) calloc(1, sizeof(double));
	all_v_sub = (double*) calloc(1, sizeof(double));
	all_m_sub = (double*) calloc(1, sizeof(double));

	all_v_sub_bin = (double*) calloc(nBins-1, sizeof(double));
	all_n_sub_bin = (double*) calloc(nBins-1, sizeof(double));
	all_m_sub_bin = (double*) calloc(nBins-1, sizeof(double));
	all_n_c_sub_bin = (double*) calloc(nBins-1, sizeof(double));
	all_m_c_sub_bin = (double*) calloc(nBins-1, sizeof(double));
	all_p_phi_sub_bin = (int*) calloc(nBins-1, sizeof(int));
	all_p_theta_sub_bin = (int*) calloc(nBins-1, sizeof(int));
	all_n_bin = (int*) calloc(nBins-1, sizeof(int));

		r_sub_bin = (double*) calloc(nBins, sizeof(double));
		cosphi_bin = (double*) calloc(nBins, sizeof(double));
		costh_bin = (double*) calloc(nBins, sizeof(double));
		err = (double*) calloc(nBins-1, sizeof(double));

			v_sub_bin = (double*) calloc(nBins-1, sizeof(double));
			m_sub_bin = (double*) calloc(nBins-1, sizeof(double));
			r_sub_bin_y = (int*) calloc(nBins-1, sizeof(int));
			cosphi_bin_y = (int*) calloc(nBins-1, sizeof(int));
			costh_bin_y = (int*) calloc(nBins-1, sizeof(int));

			// Allocate different bins
			cMax = 1; //F_MAX * maximum(costh, NsubTh); 
			cMin = 0; //F_MIN * minimum(costh, NsubTh); 

			cpMax = 1; //F_MAX * maximum(cosphi, Nsub); 
			cpMin = 0; //F_MIN * minimum(cosphi, Nsub);
				
			rMin = 0.1; //F_MIN * minimum(r_sub, Nsub);
			rMax = 1.1; //F_MAX * maximum(r_sub, Nsub);

			r_sub_bin = lin_stepper(rMin, rMax, nBins);
			costh_bin = lin_stepper(cMin, cMax, nBins);
		        cosphi_bin = lin_stepper(cpMin, cpMax, nBins);

#ifdef CROSS_CORRELATION
		for(i=0; i<totHost; i++)
		{
			int id = -1;
			k = SubStructure.host[i].index;
			id = find_cross_correlated_halo(k);

			if(Haloes[k].Mvir > Settings.Mprint && id > 0)
#else
		for(i=0; i<totHost; i++)
		{
			k = SubStructure.host[i].index;
		//	fprintf(stderr, "computing properties for halo %d, nsub %d, M=%e\n", k, Nsub,
		//		Settings.Mprint);
			if(Haloes[k].Mvir > Settings.Mprint)
#endif
			{
			        Nsub = SubStructure.host[i].n_sub;
	
				Rvir = Haloes[k].Rvir;
				Vhost = sqrt(pow2(Haloes[k].V[0])+pow2(Haloes[k].V[1])+pow2(Haloes[k].V[2]));
				NsubTh = 0;

				m_sub_cum_bin = (double*) calloc(nBins-1, sizeof(double));
				n_sub_cum_bin = (int*) calloc(nBins-1, sizeof(int));

				costh = (double*) calloc(1, sizeof(double));
				cosphi = (double*) calloc(Nsub, sizeof(double));
				r_sub = (double*) calloc(Nsub, sizeof(double));
				v_sub = (double*) calloc(Nsub, sizeof(double));
				m_sub = (double*) calloc(Nsub, sizeof(double));

				nHost++;

			for(j=0; j<Nsub; j++)			 
			{

				//fprintf(stderr, "computing properties for halo %d\n", k);

				sum = 0; ct = 0; R = 0; anis = 0; V=0; 
				NsubTot++;

				all_phi_sub = realloc(all_phi_sub, NsubTot * sizeof(double));
				all_r_sub = realloc(all_r_sub, NsubTot * sizeof(double));
				all_v_sub = realloc(all_v_sub, NsubTot * sizeof(double));
				all_m_sub = realloc(all_m_sub, NsubTot * sizeof(double));
				all_n_sub = realloc(all_n_sub, NsubTot * sizeof(double));

				l = SubStructure.host[i].sub_index[j];

				// Center of mass distance host-satellite 
				for(m=0; m<3; m++)
				{	
					sum += pow2(Haloes[l].X[m] - Haloes[k].X[m]);
				}

				R = sqrt(sum);
				r_sub[j] = R/Rvir;
				all_r_sub[NsubTot-1] = R/Rvir;
				all_n_sub[NsubTot-1] = 1./(float) Nsub;

				// Fraction of subhalo mass
				m_sub[j] = Haloes[l].Mvir / Haloes[k].Mvir;
				all_m_sub[NsubTot-1] = Haloes[l].Mvir / Haloes[k].Mvir;

				sum = 0;
				// Center of mass velocity difference host vs. sub
				for(m=0; m<3; m++)
				{
					sum += pow2(Haloes[l].V[m] - Haloes[k].V[m]);
				}

				V = sqrt(sum);
				v_sub[j] = V/Vhost;
				all_v_sub[NsubTot-1] = V/Vhost;

				// SubHalo axis alignment to the halo center
				for(m=0; m<3; m++)
				{
					ct += Haloes[l].Ea[m]*(Haloes[l].X[m] - Haloes[k].X[m]);
				}

				if(Haloes[l].n_part > N_SUB_MIN)
				{
					ct = ct / R;
					NsubTh++;
					NsubTotTh++;
					costh = realloc(costh, NsubTh * sizeof(double)); 
					all_theta_sub = realloc(all_theta_sub, NsubTotTh * sizeof(double)); 

					costh[NsubTh-1] = sqrt(ct*ct);
					all_theta_sub[NsubTotTh-1] = sqrt(ct*ct); 
				}

				// Alignment of subhaloes wrt the host major axis
				for(m=0; m<3; m++)
					anis += Haloes[k].Ea[m]*(Haloes[l].X[m] - Haloes[k].X[m]);
					anis = anis / R;

				cosphi[j] = sqrt(anis*anis); 
				all_phi_sub[NsubTot-1] = sqrt(anis*anis); 

			} // End loop on the subhaloes

			// Now gather and print for each halo
			lin_bin(costh, costh_bin, nBins, NsubTh, costh_bin_y);
			lin_bin(cosphi, cosphi_bin, nBins, Nsub, cosphi_bin_y);
			lin_bin(r_sub, r_sub_bin, nBins, Nsub, r_sub_bin_y);

			average_bin(r_sub, v_sub, r_sub_bin, v_sub_bin, err, nBins, Nsub);
			average_bin(r_sub, m_sub, r_sub_bin, m_sub_bin, err, nBins, Nsub);

			double_cum_bin(m_sub_bin, m_sub_cum_bin, nBins-1);
			cum_bin(r_sub_bin_y, n_sub_cum_bin, nBins-1);

#ifdef PRINT_HALO
		if(Haloes[k].Mvir > Settings.Mprint)
			print_sub_per_host(k, nBins, NsubTh, nHost, r_sub_bin, r_sub_bin_y, n_sub_cum_bin, 
				v_sub_bin, m_sub_bin, m_sub_cum_bin, costh_bin, costh_bin_y, cosphi_bin, cosphi_bin_y, 
					r_sub, m_sub, v_sub, cosphi);
#endif
	
		free(costh);
		free(cosphi);
		free(v_sub);
		free(m_sub);
		free(r_sub);

		free(m_sub_cum_bin);
		free(n_sub_cum_bin); 
		} // End if host > M
	} // End loop on hosts

			average_bin(all_r_sub, all_n_sub, r_sub_bin, all_n_sub_bin, err, nBins, NsubTot);
			average_bin(all_r_sub, all_v_sub, r_sub_bin, all_v_sub_bin, err, nBins, NsubTot);
			average_bin(all_r_sub, all_m_sub, r_sub_bin, all_m_sub_bin, err, nBins, NsubTot);

			lin_bin(all_r_sub, r_sub_bin, nBins, NsubTot, all_n_bin);
			lin_bin(all_phi_sub, cosphi_bin, nBins, NsubTot, all_p_phi_sub_bin);
			lin_bin(all_theta_sub, costh_bin, nBins, NsubTotTh, all_p_theta_sub_bin);

			double_cum_bin(all_m_sub_bin, all_m_c_sub_bin, nBins-1);
			double_cum_bin(all_n_sub_bin, all_n_c_sub_bin, nBins-1);

			print_all_sub_per_host(nBins, NsubTot, NsubTotTh, 
				all_n_bin, r_sub_bin, all_n_sub_bin, all_n_c_sub_bin,
					all_v_sub_bin, all_m_sub_bin, all_m_c_sub_bin, 
						costh_bin, all_p_theta_sub_bin, cosphi_bin, all_p_phi_sub_bin);

		INFO_MSG("Printed sub properties per host halo");
	
	free(all_phi_sub);
	free(all_theta_sub);
	free(all_r_sub);
	free(all_n_sub);
	free(all_v_sub);
	free(all_m_sub);

	free(all_v_sub_bin); 
	free(all_n_sub_bin); 
	free(all_m_sub_bin); 
	free(all_n_c_sub_bin);
	free(all_m_c_sub_bin); 
	free(all_p_phi_sub_bin);
	free(all_p_theta_sub_bin);
	free(all_n_bin);

	free(err);
	free(r_sub_bin);
	free(cosphi_bin);
	free(costh_bin);
	free(v_sub_bin);
	free(m_sub_bin);
	free(r_sub_bin_y);
	free(cosphi_bin_y);
	free(costh_bin_y);
}



// Number of sub haloes per r-bin
void n_r_subhalo()
{
	int h=0, i=0, j=0, k=0, m=0, host=0, cum=0, totSub=0, totHost=0, nBins=0; 
	double r, sum=0, sub_frac=0;
	double *R=NULL, *all_r=NULL, *sub_r=NULL, *err_n_r=NULL, *all_n_r=NULL, *n_bin=NULL;
	int *bin_n_r;

	totSub = SubStructure.N_sub;
	totHost = SubStructure.N_host;
	nBins = (int) (F_SUB * Settings.n_bins); 

	fprintf(stdout, "\nSubhalo N(<R)\n");
	Settings.tick=0;

	all_r = (double*) calloc(totSub, sizeof(double));
	sub_r = (double*) calloc(totSub, sizeof(double));
	R = (double*) calloc(nBins, sizeof(double));
	n_bin = (double*) calloc(nBins-1, sizeof(double));
	bin_n_r = (int*) calloc(nBins-1, sizeof(int));
	all_n_r = (double*) calloc(nBins-1, sizeof(double));
	err_n_r = (double*) calloc(nBins-1, sizeof(double));

		R = log_stepper(RMIN, RMAX, nBins);

		for(i=0; i<totHost; i++)
		{
			host = SubStructure.host[i].index;

		if(SubStructure.host[i].n_sub > SUB_MIN)
		{
			for(j=0; j<SubStructure.host[i].n_sub; j++)
			{
				sum = 0;
				sub_frac = 1.; ///(double)SubStructure.host[i].n_sub;

				k = SubStructure.host[i].sub_index[j];

				for(m=0; m<3; m++)
					sum += pow2(Haloes[host].X[m] - Haloes[k].X[m]);

				r = sqrt(sum);

			//	fprintf(stderr, "host=%d sub=%d r=%f frac=%f\n", host, k, r, sub_frac);

				all_r[j] = r/Haloes[host].Rvir;
				sub_r[j] = sub_frac;
			}
	
			//average_bin(all_r, sub_r, R, bin_n_r, err_n_r, nBins, j);
			lin_bin(all_r, R, nBins, j, bin_n_r);

			for(k=0; k<nBins-1; k++)
			{
				if(bin_n_r[k] != bin_n_r[k])
				{
					bin_n_r[k] = 0;
				}

				if(bin_n_r[k] > 0.)
				{
					n_bin[k]++;
					all_n_r[k] += bin_n_r[k]; 
			//fprintf(stderr, "%d) bin_n_r=%lf, all_n_r=%lf n=%f\n", k, bin_n_r[k], all_n_r[k], n_bin[k]);
				}
				///SubStructure.host[i].n_sub;
			}
			}
		}

	//	RMIN = minimum(all_r, totSub); 
	//	RMAX = maximum(all_r, totSub);

	//	R = lin_stepper(RMIN, RMAX, nBins);

	//	average_bin(all_r, sub_r, R, bin_n_r, err_n_r, nBins, totSub);
			
	//	cum_bin(bin_n_r, all_n_r, nBins);
	
	sum = 0;
	double sum1 = 0;

	for(j=0; j<nBins-1; j++) 
	{
		//i = nBins -j -1;
		i = nBins -j -2;
		HaloProperties[HALO_INDEX].r_sub[i] = 0.5 * (R[i] + R[i+1]);
		HaloProperties[HALO_INDEX].n_r_sub[i] = all_n_r[i]/n_bin[i];
		sum1 += n_bin[i];
		sum += all_n_r[i]/sum1;
		//fprintf(stderr,"%d) sum=%f, sum1=%f\n", i, sum, sum1);
		HaloProperties[HALO_INDEX].cum_n_r_sub[i] = sum; 
	}

	free(R); 	
	free(all_r); 
	free(sub_r); 
	free(bin_n_r); 
	free(err_n_r); 
	free(all_n_r);

	fprintf(stdout, "\n");
}
Exemple #5
0
void sort_web_statistics()
{
	int NWeb, NType, Ns, i=0, j=0, k=0, l=0;
	int *dm_bin_int, *cum_dm_bin_int;
	double w_gas, w_dm;
	double dmMax, dmMin, *dm_bin, *dm_bin_e; 
	double *dm_bin_T, *dm_bin_alpha, *dm_bin_gas;	
	double *delta_dm, *alpha_dm, *p_alpha_dm;
	double *delta_gas, *T_gas, *alpha_gas, *p_alpha_gas;
	double *delta_tot, *alpha_tot, *p_alpha_tot;
	
	double *param;

	NWeb = Settings.c_web_size;
	w_gas = 0.046 / 0.27;
	w_dm = 1 - w_gas;
	Ns = 5;

	// Do a general statistics of the eigenvalue-types
	eigenvalue_statistics();

	// Now sort statistics per node type
	// i = 0 is the global statistics
	for(i=0; i<5; i++)
	{
		k = 0;
		l = 0;
		NType = WebInfoDm.N[i];
		
		fprintf(stderr, "Found %d nodes of type %d.\n", NType, i);
		dm_bin = malloc((BIN_SIZE+1)*sizeof(double));
		dm_bin_e = malloc((BIN_SIZE)*sizeof(double));
		dm_bin_T = malloc((BIN_SIZE)*sizeof(double));
		dm_bin_alpha = malloc((BIN_SIZE)*sizeof(double));
		dm_bin_gas = malloc((BIN_SIZE)*sizeof(double));
		dm_bin_int = malloc((BIN_SIZE)*sizeof(int));
		cum_dm_bin_int = malloc((BIN_SIZE)*sizeof(int));

		fprintf(stderr, "Allocating %.2f MB for type analysis...", (double) Ns*NType*sizeof(double)/1024/1024);
		alpha_dm  = malloc(NType * sizeof(double));
		delta_dm  = malloc(NType * sizeof(double));
		delta_gas = malloc(NType * sizeof(double));
		delta_tot = malloc(NType * sizeof(double));
		T_gas = malloc(NType * sizeof(double));
		fprintf(stderr, "Done.\n");	 

		param = malloc(2 * sizeof(double));

#	pragma omp parallel for					\
	private(k, j) 						\
	shared(i, alpha_dm, delta_dm, delta_gas, delta_tot) 	\
	shared(TWeb, VWeb, NWeb, w_dm, w_gas, T_gas, WebInfoDm)	
	for(j=0; j<NType; j++)
	{
		if(i == 0)
		{
			delta_dm[j] =  VWeb[j].dens;	
#ifdef GAS
			delta_gas[j] = TWeb[j].dens;	
			delta_tot[j] = w_gas * TWeb[j].dens + w_dm * VWeb[j].dens;	

			T_gas[j] = u2TK(TWeb[j].temp);
#endif	
			if(delta_dm[j]!=0.0)
				alpha_dm[j] = T_gas[j] / delta_dm[j];

		}
		else
		{
			k = WebInfoDm.ids[i-1][j];

			delta_dm[j] = VWeb[k].dens;	
#ifdef GAS
			delta_gas[j] = TWeb[k].dens;	
			delta_tot[j] = w_gas * TWeb[k].dens + w_dm * VWeb[k].dens;	
			T_gas[j] = u2TK(TWeb[k].temp);
#endif
			if(delta_dm[j]!=0.0)
				alpha_dm[j] = T_gas[j] / delta_dm[j];	

		}
	}	

			// Now bin into histograms
			dmMin = F_MIN * nonzero_minimum(delta_dm, NType);
			dmMax = F_MAX * maximum(delta_dm, NType);
	
		//fprintf(stderr, "min=%f, max=%f, dm[1]=%f\n", dmMin, dmMax, delta_dm[1]);

			dm_bin = log_stepper(dmMin, dmMax, BIN_SIZE+1);
			
			lin_bin(delta_dm, dm_bin, BIN_SIZE+1, NType, dm_bin_int);
			cum_bin(dm_bin_int, cum_dm_bin_int, BIN_SIZE);
			average_bin(delta_dm, T_gas, dm_bin, dm_bin_T, dm_bin_e, BIN_SIZE+1, NType);
			average_bin(delta_dm, alpha_dm, dm_bin, dm_bin_alpha, dm_bin_e, BIN_SIZE+1, NType);
			average_bin(delta_dm, delta_gas, dm_bin, dm_bin_gas, dm_bin_e, BIN_SIZE+1, NType);

			param[0] = 1.;
			param[1] = average(T_gas, BIN_SIZE);

			param = best_fit_power_law(delta_gas, T_gas, dm_bin_e, BIN_SIZE, param);
	
			fprintf(stderr, "Best Fit PowerLaw a=%f, A=%f\n", param[0], param[1]);
			WebInfoDm.a[i] = param[0];
			WebInfoDm.A[i] = param[1];

		for(j=0; j<BIN_SIZE; j++)
		{
			//fprintf(stderr, "%d) dm[%d]=%f, T_bin[%d]=%f\n", i, j, dm_bin[j], j, dm_bin_T[j]);
			//fprintf(stderr, "%d) dm[%d]=%f, alpha_bin[%d]=%f\n", i, j, dm_bin[j], j, dm_bin_alpha[j]);
			//fprintf(stderr, "%d) dm[%d]=%f, gas_bin[%d]=%f\n", i, j, dm_bin[j], j, dm_bin_gas[j]);

			// Overdensity values
			WebInfoDm.delta[i][j] = 0.5 * (dm_bin[j] + dm_bin[j+1]);
			WebInfoDm.N_dm[i][j] = dm_bin_int[j];
			WebInfoDm.N_dm_cum[i][j] = cum_dm_bin_int[j];
			WebInfoDm.delta_gas[i][j] = dm_bin_gas[j];
			WebInfoDm.T_vs_delta[i][j] = dm_bin_T[j];
		}

		free(delta_gas);
		free(delta_tot);
		free(delta_dm);
		free(alpha_dm);
		free(T_gas);

		free(dm_bin);
		free(dm_bin_e);
		free(dm_bin_T);
		free(dm_bin_int);
		free(dm_bin_gas);
		free(dm_bin_alpha);
	}
}