コード例 #1
0
/* Create the rmatrix, a lookup table which speeds analysis */
IDL_LONG k_binspec(float *lambda,
									 float *spectrum,
									 float *newlambda,
									 float *newspectrum,
									 IDL_LONG nl,
									 IDL_LONG nnewl)
{
	float lammin,lammax,scale,currlam;
	IDL_LONG i,l,k,v,indxoff;
	
	/* make local copies of vmatrix */
	rb_spectrum=(float *) malloc(nl*sizeof(float));
	rb_lambda=(float *) malloc(nl*sizeof(float));
	rb_nl=nl;
	for(i=0;i<nl;i++) rb_spectrum[i]=spectrum[i];
	for(i=0;i<nl;i++) rb_lambda[i]=lambda[i];
	
	for(i=0;i<nnewl;i++) 
		newspectrum[i]=k_qromo(rb_pixel,newlambda[i], 
													 newlambda[i+1],k_midpnt);
	
	/* deallocate local vmatrix */
	FREEVEC(rb_spectrum);
	FREEVEC(rb_lambda);
	
	return(1);
} /* end create_r */
コード例 #2
0
ファイル: k_fit_spec.c プロジェクト: astropy/kcorrect
IDL_LONG k_fit_spec(float *coeffs,
                    float *flux,
                    float *ivar,
                    float *templates,
                    IDL_LONG nt,
                    IDL_LONG nl,
                    float tolerance,
                    IDL_LONG maxiter,
                    IDL_LONG *niter,
                    float *chi2,
                    IDL_LONG verbose)
{
  int i,j,jp,k;
	float *invcovar=NULL,*bb=NULL,*xx=NULL,offset;

	invcovar=(float *) malloc(nt*nt*sizeof(float));
	bb=(float *) malloc(nt*sizeof(float));
	xx=(float *) malloc(nt*sizeof(float));

  i=0;

  /*    b. calculate A */
  for(j=0;j<nt;j++) 
    for(jp=j;jp<nt;jp++) 
      invcovar[j*nt+jp]=0;
  for(j=0;j<nt;j++) 
    for(jp=j;jp<nt;jp++) 
      for(k=0;k<nl;k++) 
        invcovar[j*nt+jp]+=templates[j*nl+k]*templates[jp*nl+k]*
          ivar[i*nl+k];
  for(j=0;j<nt;j++) 
    for(jp=0;jp<j;jp++) 
      invcovar[j*nt+jp]=invcovar[jp*nt+j];
  
  /*    c. calculate b */
  for(j=0;j<nt;j++) bb[j]=0.;
  for(j=0;j<nt;j++) 
    for(k=0;k<nl;k++) 
      bb[j]-=templates[j*nl+k]*flux[i*nl+k]*ivar[i*nl+k];
  
  /*    d. calculate offset to chi2 */
  offset=0.;
  for(k=0;k<nl;k++) 
    offset+=flux[i*nl+k]*flux[i*nl+k]*ivar[i*nl+k];
  offset*=0.5;
  
  /* 3. run the iteration */
  for(j=0;j<nt;j++) xx[j]=1.;
  k_nonneg_solve(xx,invcovar,bb,offset,nt,tolerance,maxiter,niter, 
                 &(chi2[i]),verbose);
  
  for(j=0;j<nt;j++) coeffs[i*nt+j]=xx[j];

	FREEVEC(invcovar);
	FREEVEC(bb);
	FREEVEC(xx);

	return(1);
} /* end k_fit_spec */
コード例 #3
0
ファイル: InterfaceManager.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : deleteAllFrames
// -----------------------------------------------------------------
void InterfaceManager::deleteAllFrames()
{
	FREEVEC(m_pFrameList);
	FREEVEC(m_pTopDisplayList);

    m_pTooltip = NULL;
    m_fTooltipTime = 0;
    m_pClickedObjects[0] = m_pClickedObjects[1] = NULL;
    m_pPointedObject = NULL;
}
コード例 #4
0
ファイル: AI.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : ~AI
// -----------------------------------------------------------------
AI::~AI()
{
	FREEVEC(pActionsList);
	FREE(json);
	FREE(dialogs);
	FREE(pTimetable);
}
コード例 #5
0
ファイル: dsigma.c プロジェクト: MCTwo/DEIMOS
int dsigma(float *image, 
					 int nx, 
					 int ny,
					 int sp,
					 float *sigma)
{
	float tot;
  int i,j,dx,dy, ndiff;

	if(nx==1 && ny==1) {
		(*sigma)=0.;
		return(0);
	}

	dx=50;
	if(dx>nx/4) dx=nx/4;
	if(dx<=0) dx=1;

	dy=50;
	if(dy>ny/4) dy=ny/4;
	if(dy<=0) dy=1;
	
	diff=(float *) malloc(2*nx*ny*sizeof(float));
	ndiff=0;
	for(j=0;j<ny;j+=dy) {
		for(i=0;i<nx;i+=dx) {
			if(i<nx-sp) {
				diff[ndiff]=fabs(image[i+j*nx]-image[i+sp+j*nx]);
				ndiff++;
			}
			if(j<ny-sp) {
				diff[ndiff]=fabs(image[i+j*nx]-image[i+(j+sp)*nx]);
				ndiff++;
			}
		}
	}

	if(ndiff<=1) {
		(*sigma)=0.;
		return(0);
	}

	if(ndiff<=10) {
		tot=0.;
		for(i=0;i<ndiff;i++)
			tot+=diff[i]*diff[i];
		(*sigma)=sqrt(tot/(float) ndiff);
		return(0);
	}

	(*sigma)=(dselip((int) floor(ndiff*0.68),ndiff,diff))/sqrt(2.);
	
	FREEVEC(diff);

	return(1);
} /* end dsigma */
コード例 #6
0
ファイル: guiTabbedFrame.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : ~guiTabbedFrame
//  Destructor
// -----------------------------------------------------------------
guiTabbedFrame::~guiTabbedFrame()
{
    m_pDoc = NULL;   // it's going to be deleted below
    // We need to explicitly delete all guiDocuments as they won't be deleted from guiTabbedFrame_Document destructor
	for (guiTabbedFrame_Document* &pDoc : m_pDocumentsList) {
        delete pDoc->m_pDoc;
    }
    // Now we can delete the list
    FREEVEC(m_pDocumentsList);
    FREE(m_pTabsGeometry);
}
コード例 #7
0
ファイル: InterfaceManager.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : display
// -----------------------------------------------------------------
void InterfaceManager::display()
{
    FREEVEC(m_pTopDisplayList);
    Color plain(1, 1, 1, 1);
    Color alpha(1, 1, 1, 0.65f);

	for (guiFrame* &pFrm : m_pFrameList) {
        if (pFrm != m_pTooltip) {
        	pFrm->displayAt(0, 0, plain, alpha);
        }
    }

	for (TopDisplayObject* &pObj : m_pTopDisplayList) {
		pObj->display();
    }

    if (m_pTooltip != NULL) {
        alpha.a = 0.85f;
        m_pTooltip->displayAt(0, 0, plain, alpha);
    }
}
コード例 #8
0
ファイル: InterfaceManager.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : resetSharedPointers
// -----------------------------------------------------------------
void InterfaceManager::resetSharedPointers(guiObject * pObj)
{
    if (pObj == NULL)
    {
        m_pClickedObjects[0] = m_pClickedObjects[1] = NULL;
        m_pPointedObject = NULL;
        m_pTooltip->setVisible(false);
        FREEVEC(m_pTopDisplayList);
    }
    else
    {
        if (pObj == m_pClickedObjects[0]) {
            m_pClickedObjects[0] = NULL;
        }
        if (pObj == m_pClickedObjects[1]) {
            m_pClickedObjects[1] = NULL;
        }
        if (pObj == m_pPointedObject) {
            m_pPointedObject = NULL;
        }
    }
}
コード例 #9
0
ファイル: test_dfind.c プロジェクト: olebole/astrometry.net
static int old_dfind(int *image, int nx, int ny, int *object) {
	int i, ip, j, jp, k, kp, l, ist, ind, jst, jnd, igroup, minearly, checkearly, tmpearly;
	int ngroups;

	int* mapgroup = (int *) malloc((size_t) nx * ny * sizeof(int));
	int* matches = (int *) malloc((size_t) nx * ny * 9 * sizeof(int));
	int* nmatches = (int *) malloc((size_t) nx * ny * sizeof(int));

	if (!mapgroup || !matches || !nmatches) {
		fprintf(stderr, "Failed to allocate memory in dfind.c\n");
		exit(-1);
	}

	for (k = 0;k < nx*ny;k++)
		object[k] = -1;
	for (k = 0;k < nx*ny;k++)
		mapgroup[k] = -1;
	for (k = 0;k < nx*ny;k++)
		nmatches[k] = 0;
	for (k = 0;k < nx*ny*9;k++)
		matches[k] = -1;

	/* find matches */
	for (j = 0;j < ny;j++) {
		jst = j - 1;
		jnd = j + 1;
		if (jst < 0)
			jst = 0;
		if (jnd > ny - 1)
			jnd = ny - 1;
		for (i = 0;i < nx;i++) {
			ist = i - 1;
			ind = i + 1;
			if (ist < 0)
				ist = 0;
			if (ind > nx - 1)
				ind = nx - 1;
			k = i + j * nx;
			if (image[k]) {
				for (jp = jst;jp <= jnd;jp++)
					for (ip = ist;ip <= ind;ip++) {
						kp = ip + jp * nx;
						if (image[kp]) {
							matches[9*k + nmatches[k]] = kp;
							nmatches[k]++;
						}
					}
			} /* end if */
		}
	}

	/* group pixels on matches */
	igroup = 0;
	for (k = 0;k < nx*ny;k++) {
		if (image[k]) {
			minearly = igroup;
			for (l = 0;l < nmatches[k];l++) {
				kp = matches[9 * k + l];
				checkearly = object[kp];
				if (checkearly >= 0) {
					while (mapgroup[checkearly] != checkearly) {
						checkearly = mapgroup[checkearly];
					}
					if (checkearly < minearly)
						minearly = checkearly;
				}
			}

			if (minearly == igroup) {
				mapgroup[igroup] = igroup;
				for (l = 0;l < nmatches[k];l++) {
					kp = matches[9 * k + l];
					object[kp] = igroup;
				}
				igroup++;
			} else {
				for (l = 0;l < nmatches[k];l++) {
					kp = matches[9 * k + l];
					checkearly = object[kp];
					if (checkearly >= 0) {
						while (mapgroup[checkearly] != checkearly) {
							tmpearly = mapgroup[checkearly];
							mapgroup[checkearly] = minearly;
							checkearly = tmpearly;
						}
						mapgroup[checkearly] = minearly;
					}
				}
				for (l = 0;l < nmatches[k];l++) {
					kp = matches[9 * k + l];
					object[kp] = minearly;
				}
			}
		}
	}

	ngroups = 0;
	for (i = 0;i < nx*ny;i++) {
		if (mapgroup[i] >= 0) {
			if (mapgroup[i] == i) {
				mapgroup[i] = ngroups;
				ngroups++;
			} else {
				mapgroup[i] = mapgroup[mapgroup[i]];
			}
		}
	}

	if (ngroups == 0)
		goto bail;

	for (i = 0;i < nx*ny;i++)
        if (object[i] >= 0)
            object[i] = mapgroup[object[i]];

	for (i = 0;i < nx*ny;i++)
		mapgroup[i] = -1;
	igroup = 0;
	for (k = 0;k < nx*ny;k++) {
		if (image[k] > 0 && mapgroup[object[k]] == -1) {
			mapgroup[object[k]] = igroup;
			igroup++;
		}
	}

	for (i = 0;i < nx*ny;i++)
		if (image[i] > 0)
			object[i] = mapgroup[object[i]];
		else
			object[i] = -1;

bail:
	FREEVEC(matches);
	FREEVEC(nmatches);
	FREEVEC(mapgroup);

	return (1);
}
コード例 #10
0
ファイル: dsmooth.c プロジェクト: Carl4/astrometry.net
// Original version of dsmooth, non-separated kernel.
int dsmooth(float *image,
            int nx,
            int ny,
            float sigma,
            float *smooth)
{
	int i, j, npix, half, ip, jp, ist, jst, isto, jsto, ind, jnd, ioff, joff;
	float invvar, total, scale, dx, dy;
	float* kernel;

	/* make kernel */
	npix = 2 * ((int) ceilf(3. * sigma)) + 1;
	half = npix / 2;
	kernel =  malloc(npix * npix * sizeof(float));
	invvar = 1. / sigma / sigma;
	for (i = 0;i < npix;i++)
		for (j = 0;j < npix;j++) {
			dx = ((float) i - 0.5 * ((float)npix - 1.));
			dy = ((float) j - 0.5 * ((float)npix - 1.));
			kernel[i + j*npix] = exp( -0.5 * (dx * dx + dy * dy) * invvar);
		}
	total = 0.;
	for (i = 0;i < npix;i++)
		for (j = 0;j < npix;j++)
			total += kernel[i + j * npix];
	scale = 1. / total;
	for (i = 0;i < npix;i++)
		for (j = 0;j < npix;j++)
			kernel[i + j*npix] *= scale;

	for (j = 0;j < ny;j++)
		for (i = 0;i < nx;i++)
			smooth[i + j*nx] = 0.;

	for (j = 0;j < ny;j++) {
		jsto = jst = j - half;
		jnd = j + half;
		if (jst < 0)
			jst = 0;
		if (jnd > ny - 1)
			jnd = ny - 1;
		for (i = 0;i < nx;i++) {
			isto = ist = i - half;
			ind = i + half;
			if (ist < 0)
				ist = 0;
			if (ind > nx - 1)
				ind = nx - 1;
			for (jp = jst;jp <= jnd;jp++)
				for (ip = ist;ip <= ind;ip++) {
					ioff = ip - isto;
					joff = jp - jsto;
					smooth[ip + jp*nx] += image[i + j * nx] *
					                      kernel[ioff + joff * npix];
				}
		}
	}

	FREEVEC(kernel);

	return (1);
} /* end photfrac */
コード例 #11
0
ファイル: dmedsmooth.c プロジェクト: NGTS/astrometry.net
int dmedsmooth(const float *image,
               const uint8_t *masked,
               int nx,
               int ny,
               int halfbox,
               float *smooth)
{
    int i, j, ip, jp, ist, jst, nb, ind, jnd, sp;
    int xoff, yoff, nm, nxgrid, nygrid;
    int ypsize, ymsize, xpsize, xmsize;
    float dx, dy, xkernel, ykernel;

    float *arr = NULL;
    int *xgrid = NULL;
    int *ygrid = NULL;
    float *grid = NULL;
    int *xlo = NULL;
    int *xhi = NULL;
    int *ylo = NULL;
    int *yhi = NULL;

    /* get grids */
    sp = halfbox;
    nxgrid = MAX(1, nx / sp) + 2;
    //printf("nxgrid %i\n", nxgrid);
    // "xgrid" are the centers.
    // "xlo" are the (inclusive) lower-bounds
    // "xhi" are the (inclusive) upper-bounds
    // the grid cells may overlap.
    xgrid = (int *) malloc((size_t)nxgrid * sizeof(int));
    xlo = (int *) malloc((size_t)nxgrid * sizeof(int));
    xhi = (int *) malloc((size_t)nxgrid * sizeof(int));
    xoff = (nx - 1 - (nxgrid - 3) * sp) / 2;
    for (i = 1;i < nxgrid - 1;i++)
        xgrid[i] = (i - 1) * sp + xoff;
    xgrid[0] = xgrid[1] - sp;
    xgrid[nxgrid - 1] = xgrid[nxgrid - 2] + sp;
    for (i = 0;i < nxgrid;i++) {
        xlo[i] = MAX(xgrid[i] - sp, 0);
        xhi[i] = MIN(xgrid[i] + sp, nx-1);
        //printf("xlo[%i],xhi[%i] = %i,%i\n", i, i, xlo[i], xhi[i]);
    }

    nygrid = MAX(1, ny / sp) + 2;
    //printf("nygrid %i\n", nygrid);
    ylo = (int *) malloc(nygrid * sizeof(int));
    yhi = (int *) malloc(nygrid * sizeof(int));
    ygrid = (int *) malloc(nygrid * sizeof(int));
    yoff = (ny - 1 - (nygrid - 3) * sp) / 2;
    for (i = 1;i < nygrid - 1;i++)
        ygrid[i] = (i - 1) * sp + yoff;
    ygrid[0] = ygrid[1] - sp;
    ygrid[nygrid - 1] = ygrid[nygrid - 2] + sp;

    for (i = 0;i < nygrid;i++) {
        ylo[i] = MAX(ygrid[i] - sp, 0);
        yhi[i] = MIN(ygrid[i] + sp, ny-1);
        //printf("ylo[%i],yhi[%i] = %i,%i\n", i, i, ylo[i], yhi[i]);
    }

    // the median-filtered image (subsampled on a grid).
    grid = (float *) malloc((size_t)(nxgrid * nygrid) * sizeof(float));

    arr = (float *) malloc((size_t)((sp * 2 + 5) * (sp * 2 + 5)) * sizeof(float));

    for (j=0; j<nygrid; j++) {
        for (i=0; i<nxgrid; i++) {
            nb = 0;
            for (jp=ylo[j]; jp<=yhi[j]; jp++) {
                const float* imageptr = image + xlo[i] + jp * nx;
                float f;
                if (masked) {
                    const uint8_t* maskptr = masked + xlo[i] + jp * nx;
                    for (ip=xlo[i]; ip<=xhi[i]; ip++, imageptr++, maskptr++) {
                        if (*maskptr)
                            continue;
                        f = (*imageptr);
                        if (!isfinite(f))
                            continue;
                        arr[nb] = f;
                        nb++;
                    }
                } else {
                    for (ip=xlo[i]; ip<=xhi[i]; ip++, imageptr++) {
                        f = (*imageptr);
                        if (!isfinite(f))
                            continue;
                        arr[nb] = f;
                        nb++;
                    }
                }
            }
            if (nb > 1) {
                nm = nb / 2;
                grid[i + j*nxgrid] = dselip(nm, nb, arr);
            } else {
                grid[i + j*nxgrid] = image[(long)xlo[i] + ((long)ylo[j]) * nx];
            }
        }
    }
    FREEVEC(xlo);
    FREEVEC(ylo);
    FREEVEC(xhi);
    FREEVEC(yhi);
    FREEVEC(arr);

    for (j = 0;j < ny;j++)
        for (i = 0;i < nx;i++)
            smooth[i + j*nx] = 0.;
    for (j = 0;j < nygrid;j++) {
        jst = (long) ( (float) ygrid[j] - sp * 1.5);
        jnd = (long) ( (float) ygrid[j] + sp * 1.5);
        if (jst < 0)
            jst = 0;
        if (jnd > ny - 1)
            jnd = ny - 1;
        ypsize = sp;
        ymsize = sp;
        if (j == 0)
            ypsize = ygrid[1] - ygrid[0];
        if (j == 1)
            ymsize = ygrid[1] - ygrid[0];
        if (j == nygrid - 2)
            ypsize = ygrid[nygrid - 1] - ygrid[nygrid - 2];
        if (j == nygrid - 1)
            ymsize = ygrid[nygrid - 1] - ygrid[nygrid - 2];
        for (i = 0;i < nxgrid;i++) {
            ist = (long) ( (float) xgrid[i] - sp * 1.5);
            ind = (long) ( (float) xgrid[i] + sp * 1.5);
            if (ist < 0)
                ist = 0;
            if (ind > nx - 1)
                ind = nx - 1;
            xpsize = sp;
            xmsize = sp;
            if (i == 0)
                xpsize = xgrid[1] - xgrid[0];
            if (i == 1)
                xmsize = xgrid[1] - xgrid[0];
            if (i == nxgrid - 2)
                xpsize = xgrid[nxgrid - 1] - xgrid[nxgrid - 2];
            if (i == nxgrid - 1)
                xmsize = xgrid[nxgrid - 1] - xgrid[nxgrid - 2];

            for (jp = jst;jp <= jnd;jp++) {
                // Interpolate with a kernel that is two parabolas spliced
                // together: in [-1.5, -0.5] and [0.5, 1.5], 0.5 * (|y|-1.5)^2
                // so at +- 0.5 it has value 0.5.
                // at +- 1.5 it has value 0.
                // in [-0.5, 0.5]: 0.75 - (y^2)
                // so at +- 0.5 it has value 0.5
                // at 0 it has value 0.75
                dy = (float)(jp - ygrid[j]);
                if (dy >= 0) {
                    dy /= (float)ypsize;
                } else {
                    dy /= (float)(-ymsize);
                }
                if ((dy >= 0.5) && (dy < 1.5))
                    ykernel = 0.5 * (dy - 1.5) * (dy - 1.5);
                else if (dy < 0.5)
                    ykernel = 0.75 - (dy * dy);
                else
                    // ykernel = 0
                    continue;
                for (ip = ist; ip <= ind; ip++) {
                    dx = (float)(ip - xgrid[i]);
                    if (dx >= 0) {
                        dx /= (float)xpsize;
                    } else {
                        dx /= (float)(-xmsize);
                    }
                    if ((dx >= 0.5) && (dx < 1.5))
                        xkernel = 0.5 * (dx - 1.5) * (dx - 1.5);
                    else if (dx < 0.5)
                        xkernel = 0.75 - (dx * dx);
                    else
                        // xkernel = 0
                        continue;
                    smooth[ip + jp*nx] += xkernel * ykernel * grid[i + j * nxgrid];
                }
            }
        }
    }

    FREEVEC(grid);
    FREEVEC(xgrid);
    FREEVEC(ygrid);

    return 1;
}
コード例 #12
0
ファイル: Character.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : ~Character
// -----------------------------------------------------------------
Character::~Character()
{
	FREEVEC(inventory);
}
コード例 #13
0
ファイル: InterfaceManager.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : ~InterfaceManager
// -----------------------------------------------------------------
InterfaceManager::~InterfaceManager()
{
	FREEVEC(m_pFrameList);
	FREEVEC(m_pTopDisplayList);
    guiContainer::deleteStatic();
}
コード例 #14
0
int main(int argc,
				 char **argv)
{
	IDL_LONG i,j,k,c,ndim,nchunk,ncurrchunk,*sizes=NULL;
	char vfile[2000],lfile[2000],ffile[2000],path[2000];
	char vmatrixfile[2000],lambdafile[2000],filterfile[2000];

	/* read arguments */
	strcpy(vfile,"vmatrix.default.dat");
	strcpy(lfile,"lambda.default.dat");
	strcpy(ffile,"sdss_filters.dat");
	sprintf(path,"%s/data/templates",getenv("KCORRECT_DIR"));
	i=0;
	while(1) {
		int option_index = 0;
 		static struct option long_options[] =
			{
				{"vfile", 1, 0, 0}, 
				{"lfile", 1, 0, 0},
				{"path", 1, 0, 0},
				{"ffile", 1, 0, 0},
				{"band-shift", 1, 0, 0},
				{"redshift", 1, 0, 0},
				{"help", 0, 0, 0}
			};
		static const char short_options[]="v:l:p:f:b:r:h";
		static const char short_options_c[]="vlpfbrh";

		c=getopt_long(argc, argv, short_options, long_options, &option_index);
		if(c==-1) break;
		if(c==0) c=short_options_c[option_index];
		switch(c) {
		case 'v':
			strcpy(vfile,optarg);
			break; 
		case 'l':
			strcpy(lfile,optarg);
			break; 
		case 'p':
			strcpy(path,optarg);
			break; 
		case 'f':
			strcpy(ffile,optarg);
			break; 
		case 'b':
			band_shift=atof(optarg);
			break; 
		case 'r':
			all_redshift=atof(optarg);
			break; 
		case 'h':
      USAGE;
      exit(1);
			break; 
		case '?':
			break;
		default: 
			printf("fit_coeffs: getopt returned character code 0%o ??\n", c);
		}
		i++;
	}
	if(argc<0) {
    USAGE;
		exit(1);
	} /* end if */

	/* get file names */
	sprintf(vmatrixfile,"%s/%s",path,vfile);
	sprintf(lambdafile,"%s/%s",path,lfile);
	sprintf(filterfile,"%s/%s",path,ffile);

	/* read in templates */
	k_read_ascii_table(&vmatrix,&ndim,&sizes,vmatrixfile);
	nl=sizes[1];
	nv=sizes[0];
	FREEVEC(sizes);
	k_read_ascii_table(&lambda,&ndim,&sizes,lambdafile);
	if(sizes[0]!=nl+1) {
		fprintf(stderr,"vmatrix and lambda files incompatible (nl==%d vs sizes[0]=%d).\n",nl,sizes[0]);
		exit(1);
	} /* end if */
	FREEVEC(sizes);

	/* load in the filters */
	k_load_filters(&filter_n,&filter_lambda,&filter_pass,&maxn,&nk,filterfile);

	/* create the rmatrix; this is a big matrix which tabulates the
     projection of each basis element b onto each filter k, as a
     function of redshift; you only have to project onto the filters
     here, since every other spectrum you will project onto the
     filters will be a linear combination of the basis elements b; you
     interpolate the rmatrix to get a particular redshift */
	rmatrix=(float *) malloc(nz*nv*nk*sizeof(float));
	zvals=(float *) malloc(nz*sizeof(float));
	for(i=0;i<nz;i++)
		zvals[i]=zmin+(zmax-zmin)*((float)i+0.5)/(float)nz;
	k_projection_table(rmatrix,nk,nv,vmatrix,lambda,nl,zvals,nz,filter_n,
										 filter_lambda,filter_pass,band_shift,maxn);

	/* reconstruct the magggies */
	nchunk=20;
	redshift=(float *) malloc((nchunk+1)*sizeof(float));
	maggies=(float *) malloc((nchunk+1)*nk*sizeof(float));
	coeffs=(float *) malloc((nchunk+1)*nv*sizeof(float));
	fscanf(stdin,"%f",&(redshift[0]));
	while(!feof(stdin)) {
		for(i=0;i<nchunk && !feof(stdin);i++) {
      if(all_redshift!=-1.) redshift[i]=all_redshift;
			for(j=0;j<nv;j++)
				fscanf(stdin,"%f",&(coeffs[i*nv+j]));
			fscanf(stdin,"%f",&(redshift[i+1]));
		} /* end for i */
		ncurrchunk=i;
		/* no direct constraints on the coeffs are included in this fit */
		k_reconstruct_maggies(zvals,nz,rmatrix,nk,nv,coeffs,redshift,maggies, 
                          ncurrchunk);
		for(i=0;i<ncurrchunk;i++) {
			fprintf(stdout,"%e ",redshift[i]);
			for(k=0;k<nk;k++)
				fprintf(stdout,"%e ",maggies[i*nk+k]);
			fprintf(stdout,"\n");
		} /* end for i */
		redshift[0]=redshift[ncurrchunk];
	}

	return(0);
} /* end main */
コード例 #15
0
ファイル: lf_eep.c プロジェクト: astropy/kcorrect
IDL_LONG lf_eep(float *in_redshift,
                float *in_absmag,
                float *in_absmmin,
                float *in_absmmax,
                IDL_LONG in_ngals,
                float in_sample_absmmin,
                float in_sample_absmmax,
                float *in_absmk,
                float *in_phi,
                float *in_phi_err,
                float *in_covar,
                IDL_LONG in_nbin,
                IDL_LONG calc_err,
                float *in_weight)
{
    float like;
    int i,j;

    tolerance=1.e-5;
    minn=0;
    interp_choice=1;

    /*
     * copy in data
     */
    ngals=in_ngals;
    galaxy_redshift=(float *) malloc(ngals*sizeof(float));
    galaxy_absmag=(float *) malloc(ngals*sizeof(float));
    galaxy_absmmin=(float *) malloc(ngals*sizeof(float));
    galaxy_absmmax=(float *) malloc(ngals*sizeof(float));
    galaxy_weight=(float *) malloc(ngals*sizeof(float));
    for(i=0; i<ngals; i++) {
        galaxy_redshift[i]=in_redshift[i];
        galaxy_absmag[i]=in_absmag[i];
        galaxy_absmmin[i]=in_absmmin[i];
        galaxy_absmmax[i]=in_absmmax[i];
        galaxy_weight[i]=in_weight[i];
    } /* end for i */
    nbin=in_nbin;
    absmk=(float *) malloc((nbin+1)*sizeof(float));
    phi=(float *) malloc(nbin*sizeof(float));
    phi_err=(float *) malloc(nbin*sizeof(float));
    galaxy_lum=(float *) malloc(sizeof(float)*ngals);
    factor=(float *) malloc(sizeof(float)*ngals);
    sample_absmmin=in_sample_absmmin;
    sample_absmmax=in_sample_absmmax;
    lumk=(float *) malloc(sizeof(float)*(nbin+1));
    num=(IDL_LONG *) malloc(sizeof(IDL_LONG)*(nbin));
    covar=(float *) malloc(sizeof(float)*nbin*nbin);

    /*
     * Allocate memory
     */
    A=(float *) malloc(ngals*nbin*sizeof(float));
    B=(float *) malloc(ngals*nbin*sizeof(float));
    Asum=(float *) malloc(ngals*sizeof(float));
    Bsum=(float *) malloc(ngals*sizeof(float));

    /* initialize phi */
    for(i=0; i<nbin; i++)
        phi[i]=0.1;

    /*
     * Define some parameters
     */
    like=eepfit_fit(0.);

    /*
     * Calculate the errors
     */
    if(calc_err) {
        printf("Calculate errors ...\n");
        fflush(stdout);
        phierrors_lf(phi,phi_err,covar,lumk,A,B,Asum,Bsum,ngals,nbin);
    }

    for(i=0; i<nbin; i++)
        for(j=0; j<nbin; j++)
            in_covar[i*nbin+j]=covar[i*nbin+j];
    for(i=0; i<nbin; i++) {
        in_phi[i]=0.4*log(10.)*exp(0.5*(log(lumk[i])+log(lumk[i+1])))*phi[i];
        in_phi_err[i]=phi_err[i];
    }
    for(i=0; i<=nbin; i++)
        in_absmk[i]=absmk[i];

    FREEVEC(covar);
    FREEVEC(galaxy_lum);
    FREEVEC(factor);
    FREEVEC(num);
    FREEVEC(lumk);
    FREEVEC(A);
    FREEVEC(Asum);
    FREEVEC(B);
    FREEVEC(Bsum);
    FREEVEC(galaxy_absmag);
    FREEVEC(galaxy_absmmin);
    FREEVEC(galaxy_absmmax);
    FREEVEC(galaxy_redshift);
    FREEVEC(phi);
    FREEVEC(phi_err);
    FREEVEC(absmk);
    return(1);
} /* end lf_eep */
コード例 #16
0
ファイル: MovingObject.cpp プロジェクト: jotak/RPGProject
// -----------------------------------------------------------------
// Name : ~MovingObject
// -----------------------------------------------------------------
MovingObject::~MovingObject()
{
	FREEVEC(m_Movements);
}