10
#include <midas_def.h>
13
#include <proto_nrutil.h>
14
#include <proto_mutil.h>
20
#define max(A,B) ((A) > (B) ? (A) : (B))
21
#define min(A,B) ((A) < (B) ? (A) : (B))
28
int Method, Npix[2], Order;
29
double Start[2], Step[2];
32
void normalize (float[], float[], float[], float[], int[], int[],
34
void smooth (float[], float[], int, int);
47
int nax, kun, knul, tid, imno1, imno2;
48
int col, ncol, nslits, acol, arow, nsort, select;
50
int slit[MAXSLITS], upper[MAXSLITS], lower[MAXSLITS];
54
char inframe[60], table[60], outframe[60], method[20];
55
float *inimage, *outimage;
56
char unit[64], inst[72], line[80];
61
/* get into Midas and get parameters */
65
strcpy(unit,""), strcpy(inst,""); /* Purify */
67
SCKGETC ("IN_A", 1, 60, &iav, inframe);
68
SCKGETC ("IN_B", 1, 60, &iav, table);
69
SCKGETC ("OUT_A", 1, 60, &iav, outframe);
70
SCKGETC ("INPUTC", 1, 20, &iav, method);
71
SCKRDI ("INPUTI", 1, 4, &iav, parm, &kun, &knul);
75
SCTPUT ("\n ----------------------- ");
76
sprintf (line, "Input image: %s ", inframe);
78
sprintf (line, "Input table: %s ", table);
80
sprintf (line, "Output image: %s ", outframe);
82
SCTPUT ("\nInput parameters: \n");
84
if (!strncmp (method, "MED", 3) || !strncmp (method, "med", 3))
87
sprintf (line, "Smoothing method: Median");
89
sprintf (line, "Window width: %i\n", Order);
95
sprintf (line, "Smoothing method: Polynomial");
97
sprintf (line, "Order of fit: %i\n", Order);
101
/* map input and output file */
103
SCIGET (inframe, D_R4_FORMAT, F_I_MODE, F_IMA_TYPE,
104
2, &nax, Npix, Start, Step, inst, unit, (char **)&inimage, &imno1);
106
SCIPUT (outframe, D_R4_FORMAT, F_O_MODE, F_IMA_TYPE,
107
nax, Npix, Start, Step, inst, unit, (char **)&outimage, &imno2);
111
TCTOPN (table, F_I_MODE, &tid);
112
TCIGET (tid, &col, &ncol, &nsort, &acol, &arow);
113
TCCSER (tid, ":slit",&icol[0]);
114
TCCSER (tid, ":ystart",&icol[1]);
115
TCCSER (tid, ":yend",&icol[2]);
118
for (i = 1; i <= ncol; i++)
120
TCSGET(tid, i, &select);
122
TCRRDR (tid, i, 3, icol, moscol, null);
123
slit[nslits] = (int) moscol[0];
124
lower[nslits] = (int) ((moscol[1]-Start[1])/Step[1]) + 1;
125
upper[nslits] = (int) ((moscol[2]-Start[1])/Step[1]) + 1;
132
/* reserve space for arrays */
134
buff = (float *) osmmget (Npix[0] * sizeof (float));
135
buff2 = (float *) osmmget (Npix[0] * sizeof (float));
137
normalize (inimage, outimage, buff, buff2, slit, upper, lower, nslits);
139
osmmfree((char *) buff);
140
osmmfree((char *) buff2);
151
normalize (float inframe[], float outframe[], float rval[],
152
float yval[], int slit[], int upper[], int lower[],
156
normalize ( inframe, outframe, rval, yval, slit, upper, lower, nslits)
157
float inframe[],outframe[],rval[],yval[];
158
int slit[],upper[],lower[],nslits;
164
int i, nslit, j, k, jj;
167
SCTPUT (" slit no. ");
169
/* init outframe to zero */
171
for (j = 0; j < Npix[1]; j++)
173
for (i = 0; i < Npix[0]; i++)
175
jj = j * Npix[0] + i;
181
/* loop over all slitlets */
183
for (nslit = 0; nslit < nslits ; nslit++)
185
sprintf (line, " %4i", slit[nslit]);
188
/* average all rows in one slitlet */
190
for (j = 0; j < Npix[0]; j++)
192
for (j = lower[nslit] - 1; j < upper[nslit]; j++)
194
for (k = 0; k < Npix[0]; k++)
196
jj = j * Npix[0] + k;
197
rval[k] = rval[k] + inframe[jj];
201
nrow = upper[nslit] - lower[nslit] + 1.0;
202
for (j = 0; j < Npix[0]; j++)
203
rval[j] = rval[j] / nrow;
210
smooth (rval, yval, Npix[0], Order);
215
fit_poly (rval, yval, 1.0, 1.0, Npix[0], Order);
220
/* now loop through the rows of one slitlet and normalize */
222
for (j = lower[nslit] -1 ; j < upper[nslit]; j++)
224
for (k = 0; k < Npix[0]; k++)
226
jj = j * Npix[0] + k;
227
outframe[jj] = inframe[jj] / yval[k];
232
SCTPUT (" ----------------------- ");
237
smooth (float rval[], float yval[], int npix, int order)
240
smooth ( rval, yval, npix, order )
245
/* median filtering of one row: rval in, yval out */
251
first = (order - 1) / 2;
252
last = npix - first - 1;
254
for (j = first; j <= last; j++)
256
yval[j] = pik_median (order, &rval[j - 2]);
260
for (j = 0; j < first; j++)
261
yval[j] = yval[first];
262
for (j = last + 1; j < npix; j++)
263
yval[j] = yval[last];