/* In setup, the options are obtained and passed to execute via the config object.*/
void * setup(c_datablock * options){
  DATABLOCK_STATUS status=0;
  ave_delsig_config*config = malloc(sizeof(ave_delsig_config));
  status |= c_datablock_get_double(options,OPTION_SECTION,"bin_min",&(config->bin_min));
  status |= c_datablock_get_double(options,OPTION_SECTION,"bin_max",&(config->bin_max));
  status |= c_datablock_get_int(options,OPTION_SECTION,"num_bins",&(config->num_bins));
  if(status){fprintf(stderr,"Error in setup.\n");exit(status);}
  return config;
}
Esempio n. 2
0
int execute(c_datablock * block, void * config_in){
	DATABLOCK_STATUS status=0;
	covariance_config * config = (covariance_config*) config_in;
	int i,j,k;
	int NL;
	FILE *dat;
	char name[200];
	int corrtype=2;
	char sec[30];

	if (corrtype==1) sprintf(sec, "galaxy_shape_cl");
	if (corrtype==2) sprintf(sec, "galaxy_position_cl");

	// set covariance parameters

	double area, neff, sigma_e; //Survey area in deg^2, effective source density, shape dispersion
	int NZ;

	status |= c_datablock_get_int(block, config->survey, "nzbin", &NZ);
	status |= c_datablock_get_double(block, config->survey, "area", &area);
	status |= c_datablock_get_double(block, config->survey, "ngal", &neff);
	status |= c_datablock_get_double(block, config->survey, "shape_dispersion", &sigma_e);
	double ngal[NZ];
	double sig[NZ];

	for (int i ; i<NZ ; ++i){
		ngal[i] = neff/ ((double)NZ);
		sig[i] = sigma_e;
	}

	// allocate arrays
	double *ell;
	status |= c_datablock_get_double_array_1d(block, sec, "l_bins", &ell, &NL);
	double ***ps=bj_alloc_3D(4,NZ*NZ,NL);
	const int ND=NZ*(2*NZ+1);
	double ***cov=bj_alloc_3D(ND,ND,NL);	// [NZ*NZ][NZ*NZ][NL] suffices for individual WL or clustering covariances

	// Load power spectra from the datablock
	char bin[8];
	char section[30];
	double *cl;
	int tmp, sp;
	int lim = 0;
	
	for (j=0;j<NZ;j++) {
		if (corrtype == 1 || corrtype == 2) lim = j;
		if (corrtype == 1){ 
			sp = 0;
			sprintf(section, "galaxy_shape_cl");
		}
		if (corrtype == 2){ 
			sp = 3;
			sprintf(section, "galaxy_position_cl");
		}
		for (k=lim;k<NZ;k++) {
			status|=c_datablock_get_double_array_1d(block, section, bin, &cl, &tmp);
			for (i=0;i<NL;i++) {
				ps[sp][k+j*NZ][i] = cl[i];
				ps[sp][j+k*NZ][i]=ps[sp][k+j*NZ][i];	// symmetrise
			}
		}
	}

	// calculate covariance
	status=pscov(ell,ps,cov,area,ngal,sig,NZ,NL,2);

	printf("%i\n",status);

	// clean up
	bj_free_3D(ps,4,NZ*NZ,NL);
	bj_free_3D(cov,ND,ND,NL);
	free(ell);
	return 0;
}