VIRCAM Pipeline 2.3.15
seeing.c
1/* $Id: 4
2 *
3 * This file is part of the CASU Pipeline utilities
4 * Copyright (C) 2015 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: jim $
23 * $Date: 2015/08/12 11:16:55 $
24 * $Revision: 1.3 $
25 * $Name: $
26 */
27
28#include <stdio.h>
29#include <math.h>
30
31#include "imcore.h"
32#include "util.h"
33#include "floatmath.h"
34
35static void sortit (float [], int);
36
39/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80extern void imcore_seeing(ap_t *ap, int nrows, float *ellipt, float *pkht,
81 float **areal, float *work, float *fwhm) {
82 int i,ii,iaper;
83 float aper,delaper,area,logf5t,logf2,arg;
84
85 /* Convenience variables */
86
87 logf5t = logf(0.5/ap->thresh);
88 logf2 = logf(2.0);
89
90 /* Do the seeing calculation */
91
92 ii = 0;
93 for (i = 0; i < nrows; i++) {
94 if (ellipt[i] < 0.2 && pkht[i] < 30000.0 && pkht[i] > 10.0*ap->thresh) {
95 aper = (logf5t + logf(pkht[i]))/logf2 + 1.0;
96 iaper = (int)aper;
97 delaper = aper - iaper;
98 if (iaper > 0 && iaper < NAREAL && areal[1][i] > 0.0) {
99 area = (1.0-delaper)*areal[iaper-1][i] +
100 delaper*areal[iaper][i];
101 work[ii++] = CPL_MATH_2_SQRTPI*sqrtf(area);
102 }
103 }
104 }
105
106 /* Sort the resulting array and choose a location that allows for
107 contamination by galaxies */
108
109 if (ii >= 3) {
110 sortit(work,ii);
111 *fwhm = work[ii/3 - 1];
112
113 /* Allow for finite pixel size */
114
115 arg = 0.25*CPL_MATH_PI*powf(*fwhm,2.0) - 1;
116 *fwhm = 2.0*sqrt(MAX(0.0,arg/CPL_MATH_PI));
117 } else
118 *fwhm = 0.0;
119
120}
121
124static void sortit (float ia[], int n) {
125 int i, j, ii, jj, ifin;
126 float it;
127
128 jj = 4;
129 while (jj < n)
130 jj = 2 * jj;
131 jj = MIN(n,(3 * jj)/4 - 1);
132 while (jj > 1) {
133 jj = jj/2;
134 ifin = n - jj;
135 for (ii = 0; ii < ifin; ii++) {
136 i = ii;
137 j = i + jj;
138 if (ia[i] <= ia[j])
139 continue;
140 it = ia[j];
141 do {
142 ia[j] = ia[i];
143 j = i;
144 i = i - jj;
145 if (i < 0)
146 break;
147 } while (ia[i] > it);
148 ia[j] = it;
149 }
150 }
151 return;
152}
153
154/*
155
156$Log: seeing.c,v $
157Revision 1.3 2015/08/12 11:16:55 jim
158Modified procedure names to protect namespace
159
160Revision 1.2 2015/08/07 13:06:54 jim
161Fixed copyright to ESO
162
163Revision 1.1.1.1 2015/06/12 10:44:32 jim
164Initial import
165
166Revision 1.2 2014/04/09 09:09:51 jim
167Detabbed
168
169Revision 1.1.1.1 2013/08/27 12:07:48 jim
170Imported
171
172
173*/
void imcore_seeing(ap_t *ap, int nrows, float *ellipt, float *pkht, float **areal, float *work, float *fwhm)
Work out the median seeing.
Definition: seeing.c:80