00001
00002
00003
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
00022
00023 logf5t = logf(0.5/ap->thresh);
00024 logf2 = logf(2.0);
00025
00026
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
00042
00043
00044 if (ii >= 3) {
00045 sortit(work,ii);
00046 *fwhm = work[ii/3 - 1];
00047
00048
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
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
00095
00096
00097
00098
00099