seeing.c

00001 /* $Id: seeing.c,v 1.4 2010/09/09 12:09:57 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2010/09/09 12:09:57 $
00024  * $Revision: 1.4 $
00025  * $Name: vcam-1_3_2 $
00026  */
00027 
00028 #include <stdio.h>
00029 #include <math.h>
00030 
00031 #include "imcore.h"
00032 #include "util.h"
00033 #include "floatmath.h"
00034 
00035 static void sortit (float [], int);
00036 
00039 /*---------------------------------------------------------------------------*/
00078 /*---------------------------------------------------------------------------*/
00079 
00080 extern void seeing(ap_t *ap, int nrows, float *ellipt, float *pkht, 
00081                    float **areal, float *work, float *fwhm) {
00082     int i,ii,iaper;
00083     float aper,delaper,area,logf5t,logf2,arg;
00084 
00085     /* Convenience variables */
00086 
00087     logf5t = logf(0.5/ap->thresh);
00088     logf2 = logf(2.0);
00089 
00090     /* Do the seeing calculation */
00091 
00092     ii = 0;
00093     for (i = 0; i < nrows; i++) {
00094         if (ellipt[i] < 0.2 && pkht[i] < 30000.0 && pkht[i] > 10.0*ap->thresh) {
00095             aper = (logf5t + logf(pkht[i]))/logf2 + 1.0;
00096             iaper = (int)aper;
00097             delaper = aper - iaper;
00098             if (iaper > 0 && iaper < NAREAL && areal[1][i] > 0.0) {
00099                 area = (1.0-delaper)*areal[iaper-1][i] + 
00100                     delaper*areal[iaper][i];
00101                 work[ii++] = CPL_MATH_2_SQRTPI*sqrtf(area);
00102             }
00103         }
00104     }
00105 
00106     /* Sort the resulting array and choose a location that allows for
00107        contamination by galaxies */
00108 
00109     if (ii >= 3) {    
00110         sortit(work,ii);
00111         *fwhm = work[ii/3 - 1];
00112 
00113         /* Allow for finite pixel size */
00114 
00115         arg = 0.25*CPL_MATH_PI*powf(*fwhm,2.0) - 1;
00116         *fwhm = 2.0*sqrt(MAX(0.0,arg/CPL_MATH_PI));
00117     } else 
00118         *fwhm = 0.0;
00119 
00120 }
00121 
00124 static void sortit (float ia[], int n) {
00125     int i, j, ii, jj, ifin;
00126     float it;
00127  
00128     jj = 4;
00129     while (jj < n) 
00130         jj = 2 * jj;
00131     jj = MIN(n,(3 * jj)/4 - 1);
00132     while (jj > 1) {
00133         jj = jj/2;
00134         ifin = n - jj;
00135         for (ii = 0; ii < ifin; ii++) {
00136             i = ii;
00137             j = i + jj;
00138             if (ia[i] <= ia[j]) 
00139                 continue;
00140             it = ia[j];
00141             do {
00142                 ia[j] = ia[i];
00143                 j = i;
00144                 i = i - jj;
00145                 if (i < 0) 
00146                     break;
00147             } while (ia[i] > it);
00148             ia[j] = it;
00149         }
00150     }
00151     return;
00152 }
00153 
00154 /*
00155 
00156 $Log: seeing.c,v $
00157 Revision 1.4  2010/09/09 12:09:57  jim
00158 Added docs
00159 
00160 Revision 1.3  2010/06/03 12:15:31  jim
00161 A few mods to get rid of compiler warnings
00162 
00163 Revision 1.2  2009/09/09 09:42:25  jim
00164 modified to use CPL defined macros for constants
00165 
00166 Revision 1.1  2005/09/13 13:25:31  jim
00167 Initial entry after modifications to make cpl compliant
00168 
00169 
00170 */

Generated on 5 Mar 2013 for VIRCAM Pipeline by  doxygen 1.6.1