46 #include "uves_physmod_cstacen.h"
55 #define _POSIX_SOURCE 1
60 #define PI 3.14159265358979325e0
71 #define MINVAL 1.0e-37
83 #define GCHIMAX 5.0e+16
87 #define MYMIN(a,b) ((a) > (b) ? (b) : (a))
88 #define MYMAX(a,b) ((b) > (a) ? (b) : (a))
146 float* xout,
float* yout,
float* xerr,
float* yerr,
147 float* xsig,
float* ysig,
float* xyval,
int* stat )
150 int npix[2], imap[4];
151 float xypos[2], xyerr[2], xysig[2];
156 imap[0] = image[0] - 1;
157 imap[1] = image[1] - 1;
158 imap[2] = image[2] - 1;
159 imap[3] = image[3] - 1;
168 *xout = xypos[0] + 1;
169 *yout = xypos[1] + 1;
192 res = (a) > 0 ? floor(a+0.5) : -floor(a-0.5);
226 static int Ckapsig(
float *val,
int nval,
int iter,
float akap,
227 float *cons,
float *rms,
int *npts )
245 if ( nval < 2 )
return (-1);
251 for (ii=0; ii<nval; ii++) mean += val[ii];
252 mean /= (float) (nval);
258 vsq = (
float *) cpl_calloc( nval,
sizeof(
float ));
261 for (ii=0; ii<nval; ii++)
263 vsq[ii] = val[ii] * val[ii];
264 delv = MYMAX( 0.0, vsq[ii] + msq - (2.0 * mean * val[ii]));
268 *rms = (float) sqrt( MYMAX( MINVAL, dels / (nval-1)));
269 clip = akap * (*rms);
275 for (it=0; it<iter; it++)
281 for ( ii = 0; ii < nval; ii++ )
283 if ( fabs( val[ii] - mean ) < (double) clip )
286 delv = MYMAX( 0.0, vsq[ii] + msq - 2.0 * mean * val[ii]);
292 if ( nr <= 2 || nr == nr_old )
goto end_of_it;
298 *rms = (float) sqrt( MYMAX( MINVAL, dels / (nr-1)));
330 static int MATINV(
double (*matrix)[MAXPAR],
int nfree )
346 for ( ii = 0; ii < nfree; ii++ ) per[ii] = ii;
348 for ( jj = 0; jj < nfree; jj++ )
350 double rowmax = fabs( matrix[jj][jj] );
352 for ( ii = jj + 1; ii < nfree; ii++ )
354 if ( fabs( matrix[ii][jj] ) > rowmax )
356 rowmax = fabs( matrix[ii][jj] );
361 if (fabs(matrix[row][jj]) < SMALL)
366 for ( kk = 0; kk < nfree; kk++ )
368 even = matrix[jj][kk];
369 matrix[jj][kk] = matrix[row][kk];
370 matrix[row][kk] = even;
377 even = 1.0 / matrix[jj][jj];
378 for (ii=0; ii<nfree; ii++)
379 matrix[ii][jj] *= even;
380 matrix[jj][jj] = even;
381 for (kk=0; kk<jj; kk++)
383 mjk = matrix[jj][kk];
384 for ( ii = 0; ii < jj; ii++ )
385 matrix[ii][kk] -= matrix[ii][jj] * mjk;
386 for ( ii = jj + 1; ii < nfree; ii++ )
387 matrix[ii][kk] -= matrix[ii][jj] * mjk;
388 matrix[jj][kk] = -even * mjk;
391 for ( kk = jj + 1; kk < nfree; kk++ )
393 mjk = matrix[jj][kk];
394 for ( ii = 0; ii < jj; ii++ )
395 matrix[ii][kk] -= matrix[ii][jj] * mjk;
396 for ( ii = jj + 1; ii < nfree; ii++ )
397 matrix[ii][kk] -= matrix[ii][jj] * mjk;
398 matrix[jj][kk] = -even * mjk;
402 for ( ii = 0; ii < nfree; ii++ )
404 for ( kk = 0; kk < nfree; kk++ )
406 hv[per[kk]] = matrix[ii][kk];
408 for ( kk = 0; kk < nfree; kk++)
410 matrix[ii][kk] = hv[kk];
434 double z = fabs( xx );
435 double t = 1.0 / (1.0 + (0.5 * z));
453 double zz = -z * z - 1.26551223 + t * ( 1.00002368 + t *
454 ( 0.37409196 + t * ( 0.09678418 + t *
455 (-0.18628806 + t * ( 0.27886807 + t *
456 (-1.13520398 + t * ( 1.48851587 + t *
457 (-0.82215223 + t * 0.17087277 ))))))));
465 double ans = t * zozo;
468 return (xx >= 0.0 ? ans : 2.0 - ans);
483 static double GAUSFU(
double xx,
double *gpar )
489 static int init = TRUE;
490 static double sqrt_2;
496 sqrt_2 = sqrt( 2.0 );
497 rc1 = sqrt(PI)/sqrt_2;
501 rc = 1.0 / (sqrt_2 * gpar[2]);
503 dd =
ERFCC(rc * (dd - 0.5)) -
ERFCC(rc * (dd + 0.5));
504 return ( gpar[3] + rc1 * gpar[0] * gpar[2] * dd );
521 static void GAUSDE(
double xdat,
double *gpar,
double *deriv )
531 static double sqrt_2;
534 static int init = TRUE;
539 sqrt_2 = sqrt( 2.0 );
543 temp = sqrt_2 * gpar[2];
544 tempp = xdat - gpar[1];
545 x1 = (tempp - 0.5) / temp;
546 x2 = (tempp + 0.5) / temp;
547 zz = tempp / gpar[2] ;
549 if ( ((zz * zz) - 50.0) < 0.0 )
551 deriv[0] = (
GAUSFU( xdat, gpar ) - gpar[3]) / gpar[0];
552 double zx = (-x1) * x1;
564 deriv[1] = gpar[0] * dv2;
570 deriv[2] = deriv[1] * zz;
573 for (jj=0; jj<3; jj++) deriv[jj] = 0.0;
596 static float FCHIS(
double *data,
int ndim,
int nfree,
int mode,
double *dfit) {
608 for (ii=0; ii<ndim; ii++)
614 weight = -1. / *data;
615 else if ( *data == 0 )
623 double diff = (*data) - (*dfit);
625 chisq += weight * diff * diff;
627 return (chisq / nfree);
662 static int LSQFIT(
double *xdat,
double *data,
int ndim,
663 double *gpar,
float *lamda,
double *dfit,
664 double *chisqr,
double *sigma )
676 double b[MAXPAR], beta[MAXPAR], deriv[MAXPAR],
677 array[MAXPAR][MAXPAR], alpha[MAXPAR][MAXPAR];
680 nfree = ndim - MAXPAR;
682 if ( nfree < 1 || fabs( (
double) *gpar ) < SMALL )
return (1);
687 for (ii=0; ii<MAXPAR; ii++)
690 for (jj=0; jj<=ii; jj++) alpha[ii][jj] = 0.0;
693 for (ii=0; ii<ndim; ii++)
695 GAUSDE( xdat[ii], gpar, deriv );
697 for (jj=0; jj<MAXPAR; jj++)
699 beta[jj] += (data[ii] -
GAUSFU( xdat[ii], gpar )) * deriv[jj];
700 for (kk=0; kk<=jj; kk++)
701 alpha[jj][kk] += deriv[jj] * deriv[kk];
705 for (ii=0; ii<MAXPAR; ii++)
707 for (jj=0; jj<=ii; jj++)
708 alpha[jj][ii] = alpha[ii][jj];
716 if (
MATINV(alpha,MAXPAR) == 1)
return (2);
718 *sigma = MYMAX( 0.0, alpha[1][1] );
723 for (ii=0; ii<ndim; ii++)
724 dfit[ii] =
GAUSFU( xdat[ii], gpar );
726 chisq1 =
FCHIS( data, ndim, nfree, 0, dfit );
730 for ( jj = 0; jj < MAXPAR; jj++ )
732 for ( kk = 0; kk < MAXPAR; kk++ )
734 if (fabs( alpha[jj][jj] ) < 1.e-15 || fabs( alpha[kk][kk] ) < 1.e-15)
736 array[jj][kk] = alpha[jj][kk] /
737 sqrt( alpha[jj][jj] * alpha[kk][kk] ) ;
739 array[jj][jj] = 1.0 + *lamda;
742 (void)
MATINV( array, MAXPAR );
744 for ( jj = 0; jj < MAXPAR; jj++ )
747 for ( kk = 0; kk < MAXPAR ; kk++ )
749 b[jj] += beta[kk] * array[jj][kk] /
750 sqrt( alpha[jj][jj] * alpha[kk][kk] );
756 for (ii=0; ii<ndim; ii++)
757 dfit[ii] =
GAUSFU( xdat[ii], b );
759 *chisqr =
FCHIS( data, ndim, nfree, 0, dfit );
761 if ( chisq1 - *chisqr < 0.0 )
772 for (jj=0; jj<MAXPAR; jj++) gpar[jj] = b[jj];
800 static void Crhox(
float *p_img,
int *npix,
int *image,
801 int *lnew,
double *krx )
804 register int nxdim=0;
836 nrx = image[1] - image[0] + 1;
837 nry = lnew[1] - lnew[0] + 1;
839 p_img += nxdim * (image[2] + lnew[0]);
841 for (ix=0; ix<nrx; ix++)
844 for (iy=0; iy<nry*nxdim; iy+=nxdim) sum += p_img[iy];
872 static void Crhoy(
float *p_img,
int *npix,
int *image,
873 int *lnew,
double *kry )
876 register int nxdim=0;
907 nrx = lnew[1] - lnew[0] + 1;
908 nry = image[3] - image[2] + 1;
910 p_img += (nxdim * image[2]) + (image[0] + lnew[0]);
912 for (iy=0; iy<nry; iy++)
915 for (ix=0; ix<nrx; ix++) sum += p_img[ix];
945 static int Cserch(
double *marg,
int ndim,
int ign,
946 int *lmin,
int *lmax,
float *s_cent,
float *s_width )
969 iend = ndim - ign -1;
973 work = (
double *) cpl_calloc( ndim ,
sizeof(
double ));
979 double drmn = 0., drmx = 0.0;
980 for (ii = ibgn; ii < iend; ii++ )
982 diff = marg[ii+1] - marg[ii-1];
983 work[ii] = marg[ii+2] - marg[ii-2] + (2 * diff);
984 if ( work[ii] >= drmx )
1002 if ( ndim - imax > imin )
1006 for ( ii = imax+1; ii < iend; ii++ )
1008 if ( work[ii] < drmn )
1019 for ( ii = ibgn; ii < imin; ii++ )
1021 if ( work[ii] >= drmx )
1033 *s_cent = ((float)(imax + imin)) * 0.5;
1034 *s_width = imin - imax;
1037 for ( ii = imax; ii <= imin; ii++ ) sum += work[ii];
1040 if ( fabs(diff) > SMALL)
1042 dxk = sum * *s_width / ( (*s_width+1.0)*diff );
1052 else if (indx >= ndim)
1054 *s_cent = (float)(ndim-1);
1063 if (ql < 2)
goto next_step;
1067 if (ql <= 0 )
goto next_step;
1068 if (ql == 1)
goto lo5;
1069 if (ql == 2)
goto lo4;
1070 if (ql == 3)
goto lo3;
1072 if (marg[ql] > marg[ql-4])
goto low_loop;
1074 if (marg[ql] > marg[ql-3])
goto low_loop;
1076 if (marg[ql] > marg[ql-2])
goto low_loop;
1078 if (marg[ql] > marg[ql-1])
goto low_loop;
1089 if (ii < 3)
goto end_of_it;
1094 if (ii == 1 )
goto end_of_it;
1095 if (ii == 2)
goto hi5;
1096 if (ii == 3)
goto hi4;
1097 if (ii == 4)
goto hi3;
1099 if (marg[ql] > marg[ql+4])
goto hi_loop;
1101 if (marg[ql] > marg[ql+3])
goto hi_loop;
1103 if (marg[ql] > marg[ql+2])
goto hi_loop;
1105 if (marg[ql] > marg[ql+1])
goto hi_loop;
1109 (void) cpl_free( (
char *) work );
1160 float* xypos,
float* xyerr,
float* xysig,
float* xyval )
1193 for (ix=0; ix<4; ix++)
1194 ifram[ix] = image[ix] + 1;
1195 nrx = ifram[1] - ifram[0] + 1;
1196 nry = ifram[3] - ifram[2] + 1;
1198 xypos[0] = (ifram[0] + ifram[1]) * 0.5;
1199 xypos[1] = (ifram[2] + ifram[3]) * 0.5;
1200 xyerr[0] = xyerr[1] = 0.0;
1201 xysig[0] = xysig[1] = 0.0;
1206 if ( meth !=
'G' && meth !=
'g' )
1212 p_img += (ifram[0] - 1) + (npix[0] * (ifram[2] - 1));
1218 nval = (2 * nrx) + (2 * (nry-2));
1219 p_edge = (
float *) cpl_calloc( nval ,
sizeof(
float ));
1221 for (ix=0; ix<nrx;ix++)
1222 *p_edge++ = p_img[ix];
1225 for (iy=0; iy<(nry-2); iy++)
1227 *p_edge++ = p_img[0];
1228 *p_edge++ = p_img[nrx - 1];
1231 for (ix=0; ix<nrx; ix++) *p_edge++ = p_img[ix];
1236 p_edge = (
float *) cpl_calloc( nval ,
sizeof(
float ));
1238 for (ix=0; ix<nrx;ix++)
1239 *p_edge++ = p_img[ix];
1245 (void)
Ckapsig( p_edge, nval, 5, 2.0, &bgval, &rms, &bgnr );
1246 (void) cpl_free( (
char *) p_edge );
1253 for (it=0; it<MMXITER; it++)
1255 sumi = xmom = ymom = 0.0;
1256 p_img += ifram[0] - 1 + (npix[0] * (ifram[2] - 1));
1257 for (iy=0; iy<nry; iy++)
1259 for (ix=0; ix<nrx; ix++)
1261 if ( (source = p_img[ix] - bgval) > clip )
1264 xmom += source * (ifram[0] + ix);
1265 ymom += source * (ifram[2] + iy);
1272 if ((nrx < 3) || (nry < 3))
1279 xypos[0] = xmom / sumi;
1280 xypos[1] = ymom / sumi;
1285 xypos[0] = (ifram[0] + ifram[1]) * 0.5;
1286 xypos[1] = (ifram[2] + ifram[3]) * 0.5;
1290 *xyval = p_img[indx + ((*npix) * indy)];
1296 xypos[0] = xmom / sumi;
1297 xypos[1] = ymom / sumi;
1301 if ( xold == xypos[0] && yold == xypos[1] )
1304 double xdif, ydif, xrms, yrms;
1306 xrms = yrms = sumi = 0.0;
1307 p_img += ifram[0] - 1 + (npix[0] * (ifram[2] - 1));
1308 for (iy=0; iy<nry; iy++ )
1310 for (ix=0; ix<nrx; ix++)
1312 if ( (source = p_img[ix] - bgval) > clip )
1314 xdif = (ifram[0] + ix) - xypos[0];
1315 ydif = (ifram[2] + iy) - xypos[1];
1316 xrms += fabs( source * xdif *xdif );
1317 yrms += fabs( source * ydif *ydif );
1327 *xyval = p_img[indx];
1328 xysig[0] = (float) sqrt(xrms /(sumi+ *xyval - bgval));
1329 xysig[1] = (float) sqrt(yrms /(sumi+ *xyval - bgval));
1330 xyerr[0] = (float) (xysig[0] / sqrt( (
double) (nr - 1)));
1331 xyerr[1] = (float) (xysig[1] / sqrt( (
double) (nr - 1)));
1342 xypos[0] = (ifram[0] + ifram[1]) * 0.5;
1343 xypos[1] = (ifram[2] + ifram[3]) * 0.5;
1346 *xyval = p_img[indx + ((*npix) * indy)];
1354 if ( (*xyval = p_img[indx] - bgval) <= clip )
1356 xysig[0] = xysig[1] = 0.0;
1366 kk = npix[0] * (iy - 1);
1368 source = p_img[ix-1 + kk] - bgval;
1369 while ( source > clip && ix >= istr )
1372 source = p_img[ix-1 + kk] - bgval;
1378 source = p_img[ix-1 + kk] - bgval;
1379 while ( source > clip && ix <= iend )
1382 source = p_img[ix-1 + kk] -bgval;
1388 source = p_img[ix-1 + kk] - bgval;
1389 while ( source > clip && iy >= istr )
1392 source = p_img[ix-1 + (*npix *(iy-1))] -bgval;
1398 source = p_img[ix-1 + kk] - bgval;
1399 while ( source > clip && iy <= iend )
1402 source = p_img[ix-1 + (*npix *(iy-1))] -bgval;
1405 nrx = ifram[1] - ifram[0] + 1;
1406 nry = ifram[3] - ifram[2] + 1;
1422 int found, ierr, xlim[2], ylim[2], lnew[2];
1423 float lamda, xcent, ycent, xwidth, ywidth;
1424 double chisqr, oldchi, sigma, *krx, *kry, *gfit, *xpos, *yfit,
1430 lnew[0] = (nry / 4);
1431 lnew[1] = nry - (nry / 4) - 1;
1438 krx = (
double *) cpl_calloc(nrx ,
sizeof(
double));
1439 Crhox(p_img,npix,image,lnew,krx);
1440 ierr =
Cserch(krx,nrx,IGNORE,xlim,xlim+1,&xcent,&xwidth);
1444 nval = xlim[1] - xlim[0] + 1;
1445 xpos = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1446 yfit = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1447 gfit = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1448 for (ii=0; ii<nval; ii++)
1450 xpos[ii] = xlim[0] + ii;
1451 yfit[ii] = krx[xlim[0] + ii];
1461 gpar[3] = (krx[xlim[0]] + krx[xlim[1]]) / 2;
1462 (void) cpl_free( (
char *) krx );
1466 while ( ! found && it++ < GMXITER )
1469 ierr =
LSQFIT(xpos,yfit,nval,gpar,&lamda,gfit,&chisqr,&sigma);
1475 else if ( (oldchi - chisqr)/ chisqr < GCHIFND )
1482 ierr =
LSQFIT(xpos,yfit,nval,gpar,&lamda,gfit,&chisqr,&sigma);
1490 sumi = (float)(gpar[1] + image[0]);
1492 if ( indx < 0 || indx >= *npix )
1498 (void) cpl_free( (
char *) xpos );
1499 (void) cpl_free( (
char *) yfit );
1500 (void) cpl_free( (
char *) gfit );
1502 if ( found == TRUE )
1506 xysig[0] = (float) gpar[2];
1507 xyerr[0] = (float) sqrt( sigma * chisqr );
1509 *xyval = p_img[indx];
1518 krx = (
double *) cpl_calloc( nrx ,
sizeof(
double ));
1519 kry = (
double *) cpl_calloc( nry ,
sizeof(
double ));
1523 Crhox( p_img, npix, image, lnew, krx );
1524 ierr =
Cserch( krx, nrx, IGNORE, xlim, xlim+1, &xcent, &xwidth );
1525 lnew[0] = MYMAX( xlim[0],
CGN_NINT(xcent - (2 * xwidth)));
1526 lnew[1] = MYMIN( xlim[1],
CGN_NINT(xcent + (2 * xwidth)));
1528 Crhoy( p_img, npix, image, lnew, kry );
1529 ierr =
Cserch( kry, nry, IGNORE, ylim, ylim+1, &ycent, &ywidth );
1530 lnew[0] = MYMAX( ylim[0],
CGN_NINT(ycent - (2 * ywidth)));
1531 lnew[1] = MYMIN( ylim[1],
CGN_NINT(ycent + (2 * ywidth)));
1533 Crhox( p_img, npix, image, lnew, krx );
1534 ierr =
Cserch( krx, nrx, IGNORE, xlim, xlim+1, &xcent, &xwidth );
1535 lnew[0] = MYMAX( xlim[0],
CGN_NINT(xcent - (2 * xwidth)));
1536 lnew[1] = MYMIN( xlim[1],
CGN_NINT(xcent + (2 * xwidth)));
1538 Crhoy( p_img, npix, image, lnew, kry );
1539 ierr =
Cserch( kry, nry, IGNORE, ylim, ylim+1, &ycent, &ywidth );
1543 nval = xlim[1] - xlim[0] + 1;
1544 xpos = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1545 yfit = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1546 gfit = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1547 for (ii=0; ii<nval; ii++)
1549 xpos[ii] = xlim[0] + ii;
1550 yfit[ii] = krx[xlim[0] + ii];
1560 gpar[3] = (krx[xlim[0]] + krx[xlim[1]]) / 2;
1561 (void) cpl_free( (
char *) krx );
1565 while ( ! found && it++ < GMXITER )
1568 ierr =
LSQFIT(xpos,yfit,nval,gpar,&lamda,gfit,&chisqr,&sigma);
1569 if ( ierr != 0 || gpar[2] <= 0.0 )
1574 else if ( (oldchi - chisqr)/ chisqr < GCHIFND )
1581 ierr =
LSQFIT(xpos,yfit,nval,gpar,&lamda,gfit,&chisqr,&sigma);
1589 sumi = (float)(gpar[1] + image[0]);
1591 if ( indx < 0 || indx >= *npix )
1598 (void) cpl_free( (
char *) xpos );
1599 (void) cpl_free( (
char *) yfit );
1600 (void) cpl_free( (
char *) gfit );
1602 if ( found == TRUE )
1605 xysig[0] = (float) gpar[2];
1606 xyerr[0] = (float) sqrt( sigma * chisqr );
1610 nval = ylim[1] - ylim[0] + 1;
1611 xpos = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1612 yfit = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1613 gfit = (
double *) cpl_calloc( nval ,
sizeof(
double ));
1615 for (ii=0; ii<nval; ii++)
1617 xpos[ii] = ylim[0] + ii;
1618 yfit[ii] = kry[ylim[0] + ii];
1628 gpar[3] = (kry[ylim[0]] + kry[ylim[1]]) / 2;
1632 while ( ! found && it++ < GMXITER )
1635 ierr =
LSQFIT(xpos,yfit,nval,gpar,&lamda,gfit,&chisqr,&sigma );
1636 if ( ierr != 0 || gpar[2] <= 0.0 )
1641 else if ( (oldchi - chisqr)/ chisqr < GCHIFND )
1648 ierr =
LSQFIT(xpos,yfit,nval,gpar,&lamda,gfit,&chisqr,&sigma);
1657 sumi = (float) (gpar[1] + image[2]);
1659 if ( indy < 0 || indy >= npix[1] )
1665 indx += (*npix) * indy;
1667 (void) cpl_free( (
char *) xpos );
1668 (void) cpl_free( (
char *) yfit );
1669 (void) cpl_free( (
char *) gfit );
1671 if ( found == TRUE )
1674 xysig[1] = (float) gpar[2];
1675 xyerr[1] = (float) sqrt( sigma * chisqr );
1676 *xyval = p_img[indx];
1679 (void) cpl_free( (
char *) kry );
static int CGN_NINT(float a)
finds absolute value of nearest integer
static void Crhox(float *p_img, int *npix, int *image, int *lnew, double *krx)
compute X-marginal vector KRX.
static int LSQFIT(double *xdat, double *data, int ndim, double *gpar, float *lamda, double *dfit, double *chisqr, double *sigma)
least squares fit to a non-linear function
int uves_physmod_stacen(float *p_img, int dimx, int dimy, char meth, int *image, float *xout, float *yout, float *xerr, float *yerr, float *xsig, float *ysig, float *xyval, int *stat)
Routines used to do Gaussian fit to a line.
static float FCHIS(double *data, int ndim, int nfree, int mode, double *dfit)
evaluate reduced chi square for fit to data
static double ERFCC(double xx)
returns complementary error function EFC( xx )
int uves_physmod_cstacen(char meth, float *p_img, int *npix, int *image, float *xypos, float *xyerr, float *xysig, float *xyval)
Routines used to do Gaussian fit to a line.
static double GAUSFU(double xx, double *gpar)
static int Cserch(double *marg, int ndim, int ign, int *lmin, int *lmax, float *s_cent, float *s_width)
search a star from a marginal distribution
static int MATINV(double(*matrix)[MAXPAR], int nfree)
calculate the inverse of a matrix
static void GAUSDE(double xdat, double *gpar, double *deriv)
evaluates derivatives of function for least squares search with shape of a gaussian distribution ...
static void Crhoy(float *p_img, int *npix, int *image, int *lnew, double *kry)
compute Y-marginal vector KRY.
static int Ckapsig(float *val, int nval, int iter, float akap, float *cons, float *rms, int *npts)
selects a constant mean through a kap*sig clipping