VIRCAM Pipeline  1.3.4
seeing.c
1 /* $Id: seeing.c,v 1.4 2010-09-09 12:09:57 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
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: 2010-09-09 12:09:57 $
24  * $Revision: 1.4 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #include <stdio.h>
29 #include <math.h>
30 
31 #include "imcore.h"
32 #include "util.h"
33 #include "floatmath.h"
34 
35 static void sortit (float [], int);
36 
39 /*---------------------------------------------------------------------------*/
78 /*---------------------------------------------------------------------------*/
79 
80 extern void 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 
124 static 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: not supported by cvs2svn $
157 Revision 1.3 2010/06/03 12:15:31 jim
158 A few mods to get rid of compiler warnings
159 
160 Revision 1.2 2009/09/09 09:42:25 jim
161 modified to use CPL defined macros for constants
162 
163 Revision 1.1 2005/09/13 13:25:31 jim
164 Initial entry after modifications to make cpl compliant
165 
166 
167 */
void 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