/* FILE: par_coo_pk.c * PURPOSE: * (1) Open the qdphot5_ParS->CooS * (2) Find stars on the image using the PEAKER algorithm * (3) Put results into the qdphot5_ParS->CooS * AUTHOR: Kenneth J. Mighell (mighell@noao.edu) * LANGUAGE: ANSI C * DATE: 2001JUL03 * COPYRIGHT: (C) 2001 Assoc. of Universities for Research in Astronomy Inc. */ #include "mx.h" #include "qdphot.h" #define DEBUG (MX_FALSE) int qdphot5_ParS_CooS_Peaker_f3 ( qdphot5_ParS *ParS, qdphot5_ImageS *ImageS1, int coodim_p ){ char mxfunc[] = "qdphot5_ParS_CooS_Peaker_f3"; int mxstatus = 0; int mxnstr; int nstr; int x; int y; int xx; int yy; double pixel; double neighbor; int bingo; int y0; int x0; int yy0; int xx0; int true = MX_TRUE; int false = MX_FALSE; int id; int nx; int ny; double **buff1; double peakmin; double peakmax; int coodim; int j; nx = ImageS1->nxi; ny = ImageS1->nyi; buff1 = ImageS1->matrixd; mxnstr = ParS->mxstars; peakmin = ImageS1->mnpeak; peakmax = ImageS1->mxpeak; if (peakmin==peakmax) { peakmin = -QDPHOT_BIG; peakmax = QDPHOT_BIG; } /* allocate ParS->CooS if necessary */ coodim = ParS->coodim; if ( coodim > 0 ) goto start; coodim = coodim_p; if ( coodim < 1 ) { mxstatus = 1; sprintf ( MX.tmpmsg, "# coodim_p < 1\n" ); goto mx_error2; } ParS->coodim = coodim; ParS->CooS = (qdphot5_CooS *)malloc(sizeof(qdphot5_CooS)*ParS->coodim); if ( (qdphot5_CooS *)NULL == ParS->CooS ) { mxstatus = 2; sprintf ( MX.tmpmsg, "# ParS->CooS could not be allocated\n" ); goto mx_error2; } start: nstr = 0; for (y=6; y<=(ny-5); ++y) { y0 = y - 1; for (x=6; x<=(nx-5); ++x) { x0 = x - 1; pixel = buff1[y0][x0]; if ( (pixel>=peakmin) && (pixel<=peakmax) ) { bingo = true; for (yy=y-1; yy<=(y+1); ++yy) { yy0 = yy - 1; for (xx=x-1; xx<=(x+1); ++xx) { xx0 = xx - 1; if (bingo) { neighbor = buff1[yy0][xx0]; if (neighbor>pixel) { bingo = false; goto check; } else { if (neighbor==pixel) { if ((xx!=x)||(yy!=y)) { if (((xx<=x)&&(yy<=y))||((xx>x)&&(yy0)&&(nstr>=mxnstr)) goto shut_down; j = nstr; nstr++; id = nstr; if (j == coodim) { mxstatus = 3; sprintf( MX.tmpmsg, "# Yikes! j == coodim (array bounds exceeded)\n" ); goto mx_error2; } /* put true X and Y into ParS->CooS */ ParS->CooS[j].xd = x + (ImageS1->llx0i); ParS->CooS[j].yd = y + (ImageS1->lly0i); ParS->CooS[j].idi = id; if (DEBUG) printf( "%8.2f %8.2f %7d\n", ParS->CooS[j].xd, ParS->CooS[j].yd, ParS->CooS[j].idi ); } /* if bingo */ } /* if */ } /* for x */ } /* for y */ shut_down: ok: mxstatus = 0; goto bye; mx_error1: mxp_tmpmsg_init_f0(); mx_error2: mxp_errmsg_append_f3 (mxfunc, mxstatus, MX.tmpmsg); goto bye; bye: ParS->coostars = nstr; return(mxstatus); } #undef DEBUG /* end-of-file */