CR2RE Pipeline Reference Manual 1.6.7
hdrl_cat_polynm.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "hdrl_cat_polynm.h"
21
22#include "hdrl_cat_solve.h"
23
24
25/*---------------------------------------------------------------------------*/
33/*----------------------------------------------------------------------------*/
34
37/* ---------------------------------------------------------------------------*/
53/* ---------------------------------------------------------------------------*/
54cpl_error_code hdrl_polynm(
55 double xdat[], double xcor[], cpl_size n, double polycf[], cpl_size m, cpl_size ilim)
56{
57 /* Clear arrays */
58 #define sizeAray 25
59 double a[sizeAray][sizeAray];
60 double b[sizeAray];
61 for (cpl_size i = 0; i < sizeAray; i++) {
62
63 b[i] = 0.;
64
65 for (cpl_size j = 0; j < sizeAray; j++) {
66 a[i][j] = 0.;
67 }
68 }
69
70 /* Acumulate sums */
71 for (cpl_size i = 0; i < n; i++) {
72
73 for (cpl_size k = 0; k < m; k++) {
74
75 double temp = 1.;
76
77 if (k+ilim != 0) {
78 temp = pow(xcor[i], (double)(k + ilim));
79 }
80
81 b[k] += xdat[i] * temp;
82
83 for (cpl_size j = 0; j <= k; j++) {
84
85 temp = 1.;
86
87 if (k+j+2*ilim != 0) {
88 temp = pow(xcor[i], (double)(k + j + 2 * ilim));
89 }
90
91 a[j][k] += temp;
92 }
93 }
94 }
95
96 for (cpl_size k = 1; k < m; k++) {
97 for (cpl_size j = 0; j < k; j++) {
98 a[k][j] = a[j][k];
99 }
100 }
101
102 /* solve linear equations */
103 hdrl_solve(a, b, m);
104
105 for (cpl_size i = 0; i < m; i++) {
106 polycf[i] = b[i];
107 }
108
109 return CPL_ERROR_NONE;
110}
111
cpl_error_code hdrl_polynm(double xdat[], double xcor[], cpl_size n, double polycf[], cpl_size m, cpl_size ilim)
Work out the median seeing.
cpl_error_code hdrl_solve(double a[25][25], double b[25], cpl_size m)
Use Gauss-Jordan elimination to solve ax=b.