1
/* @(#)fit_back.c 19.1 (ESO-IPG) 02/25/03 14:21:24 */
10
1) compute median between orders
11
2) smoothing splines along lines, compute background values at grid-points
12
3) bi-cubic splines over the grid-points
13
4) evaluate splines at all points
17
/* general Midas includes */
19
#include <midas_def.h>
22
/* FEROS specific includes */
25
#include <proto_nrutil.h>
26
#include <proto_mutil.h>
32
float xval[], float yval[], float **ya, float **y2a,
33
int npix[], int imno, int m, int n,
34
int nact, float **centers, int xysize[], int bgdist, int fibmode
38
xval, yval, ya, y2a, npix, imno, m, n, nact,
39
centers, xysize, bgdist, fibmode
41
int npix[], imno, nact, m, n, xysize[], bgdist, fibmode;
42
float **ya, **y2a, xval[], yval[], **centers;
45
int i, ii, j, jj, k, iarr1, iy, actvals, center;
46
int splwidth[2], splwin[2];
47
float *arr1, *xpos, *ypos, *imagex1;
48
double xxd, *xn, *fn, *w, *a, *b, *c, *d, ausg[3];
52
weight = 1.0e-06; /* smoothing parameter, this is a magic number ? */
54
splwin[0] = xysize[0];
55
splwin[1] = xysize[1];
56
splwidth[0] = splwin[0] * 2 + 1;
57
splwidth[1] = splwin[0] * 2 + 1;
59
xn = dvector(0, 2*nact + 2); /* alloc mem for vars */
60
fn = dvector(0, 2*nact + 2);
61
w = dvector(0, 2*nact + 2);
62
a = dvector(0, 2*nact + 2);
63
b = dvector(0, 2*nact + 2);
64
c = dvector(0, 2*nact + 2);
65
d = dvector(0, 2*nact + 2);
67
imagex1 = vector(0, npix[0] * splwidth[1]);
69
arr1 = vector (0, splwidth[0] * splwidth[1] + 1);
70
xpos = vector (1, 2*nact + 1);
71
ypos = vector (1, 2*nact + 1);
73
/* init various arrays */
75
for(k = 1; k <= n; k++ ) /* for each row */
81
SCFGET(imno, (j - splwin[1]) * npix[0] + 1, npix[0] * splwidth[1],
82
&actvals, (char *) imagex1); /* data are at *imagex1 */
84
/* loop over the orders */
87
for (i = 1; i <= nact; i++) /* for all orders */
90
/* between two orders if sufficient space */
92
if ( (i > 1) && (centers[i][j] - centers[i-1][j]) > bgdist)
94
xposs = (centers[i][j] + centers[i-1][j]) / 2;
97
if (center > splwin[0] && center < npix[0] - splwin[0])
101
for(jj = -splwin[0]; jj <= splwin[0]; jj++)
103
for (iy = 0; iy < splwidth[1]; iy++)
104
arr1[++iarr1] = imagex1[center + jj + iy * npix[0]];
108
ypos[ii] = select_pos((int) iarr1/2 , iarr1 , arr1);
112
/* between the fibers for fiber mode 2 */
116
xposs = (centers[i][j]);
118
center = (int) xposs;
121
populate array for median filtering,
122
this needs more work, e.g.
123
median over a number of lines
126
if (center > splwin[0] && center < npix[0] - splwin[0])
130
for(jj = -splwin[0]; jj <= splwin[0]; jj++)
132
for (iy = 0; iy < splwidth[1]; iy++)
133
arr1[++iarr1] = imagex1[center + jj + iy * npix[0]];
137
ypos[ii] = select_pos((int) iarr1/2 , iarr1 , arr1);
142
for(i = 0; i < ii; i++)
144
xn[i] = (double) xpos[i + 1];
145
fn[i] = (double) ypos[i + 1];
149
/* smoothing spline in X-direction and compute new grid:
150
see Engeln-Muellges & Reuther, 1990; BI Wissenschaftsverlag Mannheim;
151
Formelsammlung zur numerischen Mathematik mit C-Programmen, page 236f
154
status = glspnp(ii - 1, xn, fn, w, 2, 0.0, 0.0, a, b, c, d);
156
for(i = 1; i <= m; i++)
158
xxd = spval(ii - 1, (double) xval[i], a, b, c, d, xn, ausg);
159
ya[i][k] = (float) xxd;
161
/* smoothed function values at x[i = 1 to m] are in ya[i][k] for any row
166
/* to compute second derivatives, see Recipes, pg. 128 - we need
167
an rectangular grid.*/
169
splie2(xval, yval, ya, m, n, y2a);
171
free_dvector(xn, 0, 2*nact + 2);
172
free_dvector(fn, 0, 2*nact + 2);
173
free_dvector(w, 0, 2*nact + 2);
174
free_dvector(a, 0, 2*nact + 2);
175
free_dvector(b, 0, 2*nact + 2);
176
free_dvector(c, 0, 2*nact + 2);
177
free_dvector(d, 0, 2*nact + 2);
179
free_vector(imagex1, 0, npix[0] * splwidth[1]);
180
free_vector(arr1, 0, (splwidth[0] * splwidth[1] + 1));
181
free_vector(xpos, 1,2*nact + 1);
182
free_vector(ypos, 1, 2*nact + 1);