seeing.c

00001 /* 
00002 
00003 $Id: seeing.c,v 1.1 2005/09/13 13:25:31 jim Exp $
00004 
00005 */
00006 
00007 #include <stdio.h>
00008 #include <math.h>
00009 
00010 #include "imcore.h"
00011 #include "util.h"
00012 #include "floatmath.h"
00013 
00014 static void sortit (float [], int);
00015 
00016 extern void seeing(ap_t *ap, int nrows, float *ellipt, float *pkht, 
00017                    float **areal, float *work, float *fwhm) {
00018     int i,ii,iaper;
00019     float aper,delaper,area,logf5t,logf2,arg;
00020 
00021     /* Convenience variables */
00022 
00023     logf5t = logf(0.5/ap->thresh);
00024     logf2 = logf(2.0);
00025 
00026     /* Do the seeing calculation */
00027 
00028     ii = 0;
00029     for (i = 0; i < nrows; i++) {
00030         if (ellipt[i] < 0.2 && pkht[i] < 30000.0 && pkht[i] > 10.0*ap->thresh) {
00031             aper = (logf5t + logf(pkht[i]))/logf2 + 1.0;
00032             iaper = (int)aper;
00033             delaper = aper - iaper;
00034             if (iaper > 0 && iaper < NAREAL && areal[1][i] > 0.0) {
00035                 area = (1.0-delaper)*areal[iaper-1][i] + delaper*areal[iaper][i];
00036                 work[ii++] = M_2_SQRTPI*sqrtf(area);
00037             }
00038         }
00039     }
00040 
00041     /* Sort the resulting array and choose a location that allows for
00042        contamination by galaxies */
00043 
00044     if (ii >= 3) {    
00045         sortit(work,ii);
00046         *fwhm = work[ii/3 - 1];
00047 
00048         /* Allow for finite pixel size */
00049 
00050         arg = 0.25*M_PI*powf(*fwhm,2.0) - 1;
00051         *fwhm = 2.0*sqrt(MAX(0.0,arg/M_PI));
00052     } else 
00053         *fwhm = 0.0;
00054 
00055     /* Message if in verbose mode */
00056 
00057     if (verbose) 
00058         printf("Estimated FWHM (pixels) = %8.1f\nNo. of objects used     = %8i\n",
00059                *fwhm,ii);
00060 }
00061 
00062 static void sortit (float ia[], int n) {
00063     int i, j, ii, jj, ifin;
00064     float it;
00065  
00066     jj = 4;
00067     while (jj < n) 
00068         jj = 2 * jj;
00069     jj = MIN(n,(3 * jj)/4 - 1);
00070     while (jj > 1) {
00071         jj = jj/2;
00072         ifin = n - jj;
00073         for (ii = 0; ii < ifin; ii++) {
00074             i = ii;
00075             j = i + jj;
00076             if (ia[i] <= ia[j]) 
00077                 continue;
00078             it = ia[j];
00079             do {
00080                 ia[j] = ia[i];
00081                 j = i;
00082                 i = i - jj;
00083                 if (i < 0) 
00084                     break;
00085             } while (ia[i] > it);
00086             ia[j] = it;
00087         }
00088     }
00089     return;
00090 }
00091 
00092 /*
00093 
00094 $Log: seeing.c,v $
00095 Revision 1.1  2005/09/13 13:25:31  jim
00096 Initial entry after modifications to make cpl compliant
00097 
00098 
00099 */

Generated on Wed Apr 10 04:01:55 2013 for VIRCAM Pipeline by  doxygen 1.5.1