VIRCAM Pipeline  2.3.12
polynm.c
1 /*
2 
3 $Id: polynm.c,v 1.3 2015/09/22 15:09:20 jim Exp $
4 
5 * This file is part of the CASU Pipeline utilities
6 * Copyright (C) 2015 European Southern Observatory
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <stdlib.h>
24 #include "imcore.h"
25 #include "floatmath.h"
26 #include "util.h"
27 
28 /* least-squares fit of order m polynomial to n data points */
29 
30 extern void imcore_polynm (float xdat[], float xcor[], int n, float polycf[],
31  int m, int ilim) {
32  double a[25][25], b[25], temp;
33  int i, j, k;
34 
35 /* if(n < m) bomboutx(1, "polynm: too few data points"); */
36 /* if(m > 25) bomboutx(1, "polynm: order of polynomial too large"); */
37 
38  /* clear arrays */
39  for(i = 0; i < 25; i++) {
40  b[i] = 0.0;
41  for(j = 0; j < 25; j++) a[i][j] = 0.0;
42  }
43 
44  /* cumulate sums */
45  for(i = 0; i < n; i++) {
46  for(k = 0; k < m; k++) {
47  temp = 1.0;
48  if(k+ilim != 0)temp = pow(xcor[i], (float) (k+ilim));
49  b[k] += xdat[i]*temp;
50 
51  for(j = 0; j <= k; j++) {
52  temp = 1.0;
53  if(k+j+2*ilim != 0)temp = pow(xcor[i], (float) (k+j+2*ilim));
54  a[j][k] += temp;
55  }
56  }
57  }
58 
59  for(k = 1; k < m; k++) {
60  for(j = 0; j < k; j++) a[k][j] = a[j][k];
61  }
62 
63  /* solve linear equations */
64  imcore_solve(a, b, m);
65 
66  for(i = 0; i < m; i++) polycf[i] = b[i];
67 }
68 
69 /*
70 
71 $Log: polynm.c,v $
72 Revision 1.3 2015/09/22 15:09:20 jim
73 Fixed guards and comments
74 
75 Revision 1.2 2015/08/12 11:16:55 jim
76 Modified procedure names to protect namespace
77 
78 Revision 1.1.1.1 2015/06/12 10:44:32 jim
79 Initial import
80 
81 Revision 1.2 2014/04/09 09:09:51 jim
82 Detabbed
83 
84 Revision 1.1.1.1 2013/08/27 12:07:48 jim
85 Imported
86 
87 
88 */