src/k_projection_table.c
IDL_LONG k_projection_table(float *rmatrix,
														IDL_LONG nk,
														IDL_LONG nv,
														float *vmatrix,
														float *lambda,
														IDL_LONG nl,
														float *zvals,
														IDL_LONG nz,
														IDL_LONG *filter_n,
														float *filter_lambda,
														float *filter_pass,
														float band_shift,
														IDL_LONG maxn)
{
	float scale,currlam;
	IDL_LONG i,l,k,v,indxoff;

	/* make local copies of vmatrix */
	cr_gmatrix=(float *) malloc(nl*sizeof(float));
	cr_vmatrix=(float *) malloc(nv*nl*sizeof(float));
	cr_lambda=(float *) malloc((nl+1)*sizeof(float));
	cr_nv=nv;
	cr_nl=nl;
	for(i=0;i<nv*nl;i++) 
		cr_vmatrix[i]=vmatrix[i];
	for(i=0;i<=nl;i++) 
		cr_lambda[i]=lambda[i];
	for(i=0;i<nl;i++) {
		currlam=0.5*(cr_lambda[i]+cr_lambda[i+1]);
		cr_gmatrix[i]=ABFNU*LIGHTSPEED/(currlam*currlam);
	}
	
	/* make r matrix */
	for(k=0;k<nk;k++) {
		/* create filter */
		cr_filter_n=filter_n[k];
		cr_filter_lambda=(float *) malloc(cr_filter_n*sizeof(float));
		cr_filter_pass=(float *) malloc(cr_filter_n*sizeof(float));
		for(l=0;l<cr_filter_n;l++) {
			cr_filter_lambda[l]=filter_lambda[maxn*k+l]/(1.+band_shift);
			cr_filter_pass[l]=filter_pass[maxn*k+l];
		} /* end for l */

		/* create scale factor for filter by projection onto the AB source */
		cr_z=0.;
		cr_project_matrix=cr_gmatrix;
		scale=1./cr_integrate();

		/* loop over redshifts */
		for(i=0;i<nz;i++) {
			indxoff=k*nv*nz+i;
			cr_z=zvals[i];
			for(v=0;v<nv;v++) {
				cr_project_matrix=&(cr_vmatrix[v*cr_nl]);
				rmatrix[indxoff+v*nz]=scale*cr_integrate();
			} /* end for */
		} /* end for i */

		/* deallocate memory */
		FREEVEC(cr_filter_lambda);
		FREEVEC(cr_filter_pass);
	} /* end for k */

	/* deallocate local vmatrix */
	FREEVEC(cr_vmatrix);
	FREEVEC(cr_gmatrix);
	FREEVEC(cr_lambda);
	
	return(1);
}
/* Create the rmatrix, a lookup table which speeds analysis */
Create the rmatrix, a lookup table which speeds analysis
Create the rmatrix a lookup table which speeds analysis
IDL_LONG k_projection_table(float *rmatrix,
														IDL_LONG nk,
														IDL_LONG nv,
														float *vmatrix,
														float *lambda,
														IDL_LONG nl,
														float *zvals,
														IDL_LONG nz,
														IDL_LONG *filter_n,
														float *filter_lambda,
														float *filter_pass,
														float band_shift,
														IDL_LONG maxn)
{
	float scale,currlam;
	IDL_LONG i,l,k,v,indxoff;
	cr_gmatrix=(float *) malloc(nl*sizeof(float));
	cr_vmatrix=(float *) malloc(nv*nl*sizeof(float));
	cr_lambda=(float *) malloc((nl+1)*sizeof(float));
	cr_nv=nv;
	cr_nl=nl;
	for(i=0;i<nv*nl;i++) 
		cr_vmatrix[i]=vmatrix[i];
	for(i=0;i<=nl;i++) 
		cr_lambda[i]=lambda[i];
	for(i=0;i<nl;i++) {
		currlam=0.5*(cr_lambda[i]+cr_lambda[i+1]);
		cr_gmatrix[i]=ABFNU*LIGHTSPEED/(currlam*currlam);
	}
	for(k=0;k<nk;k++) {
		cr_filter_n=filter_n[k];
		cr_filter_lambda=(float *) malloc(cr_filter_n*sizeof(float));
		cr_filter_pass=(float *) malloc(cr_filter_n*sizeof(float));
		for(l=0;l<cr_filter_n;l++) {
			cr_filter_lambda[l]=filter_lambda[maxn*k+l]/(1.+band_shift);
			cr_filter_pass[l]=filter_pass[maxn*k+l];
		} 
		cr_z=0.;
		cr_project_matrix=cr_gmatrix;
		scale=1./cr_integrate();
		for(i=0;i<nz;i++) {
			indxoff=k*nv*nz+i;
			cr_z=zvals[i];
			for(v=0;v<nv;v++) {
				cr_project_matrix=&(cr_vmatrix[v*cr_nl]);
				rmatrix[indxoff+v*nz]=scale*cr_integrate();
			} 
		} 
		FREEVEC(cr_filter_lambda);
		FREEVEC(cr_filter_pass);
	} 
	FREEVEC(cr_vmatrix);
	FREEVEC(cr_gmatrix);
	FREEVEC(cr_lambda);
	return(1);
}
IDL_LONG k_projection_table ( float * rmatrix , IDL_LONG nk , IDL_LONG nv , float * vmatrix , float * lambda , IDL_LONG nl , float * zvals , IDL_LONG nz , IDL_LONG * filter_n , float * filter_lambda , float * filter_pass , float band_shift , IDL_LONG maxn ) { float scale , currlam ; IDL_LONG i , l , k , v , indxoff ; cr_gmatrix = ( float * ) malloc ( nl * sizeof ( float ) ) ; cr_vmatrix = ( float * ) malloc ( nv * nl * sizeof ( float ) ) ; cr_lambda = ( float * ) malloc ( ( nl + 1 ) * sizeof ( float ) ) ; cr_nv = nv ; cr_nl = nl ; for ( i = 0 ; i < nv * nl ; i ++ ) cr_vmatrix [ i ] = vmatrix [ i ] ; for ( i = 0 ; i <= nl ; i ++ ) cr_lambda [ i ] = lambda [ i ] ; for ( i = 0 ; i < nl ; i ++ ) { currlam = 0.5 * ( cr_lambda [ i ] + cr_lambda [ i + 1 ] ) ; cr_gmatrix [ i ] = ABFNU * LIGHTSPEED / ( currlam * currlam ) ; } for ( k = 0 ; k < nk ; k ++ ) { cr_filter_n = filter_n [ k ] ; cr_filter_lambda = ( float * ) malloc ( cr_filter_n * sizeof ( float ) ) ; cr_filter_pass = ( float * ) malloc ( cr_filter_n * sizeof ( float ) ) ; for ( l = 0 ; l < cr_filter_n ; l ++ ) { cr_filter_lambda [ l ] = filter_lambda [ maxn * k + l ] / ( 1. + band_shift ) ; cr_filter_pass [ l ] = filter_pass [ maxn * k + l ] ; } cr_z = 0. ; cr_project_matrix = cr_gmatrix ; scale = 1. / cr_integrate ( ) ; for ( i = 0 ; i < nz ; i ++ ) { indxoff = k * nv * nz + i ; cr_z = zvals [ i ] ; for ( v = 0 ; v < nv ; v ++ ) { cr_project_matrix = & ( cr_vmatrix [ v * cr_nl ] ) ; rmatrix [ indxoff + v * nz ] = scale * cr_integrate ( ) ; } } FREEVEC ( cr_filter_lambda ) ; FREEVEC ( cr_filter_pass ) ; } FREEVEC ( cr_vmatrix ) ; FREEVEC ( cr_gmatrix ) ; FREEVEC ( cr_lambda ) ; return ( 1 ) ; }
Create the rmatrix, a lookup table which speeds analysis
Create the rmatrix a lookup table which speeds analysis
/* make local copies of vmatrix */ /* make r matrix */ /* create filter */ /* end for l */ /* create scale factor for filter by projection onto the AB source */ /* loop over redshifts */ /* end for */ /* end for i */ /* deallocate memory */ /* end for k */ /* deallocate local vmatrix */