1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
.IDENTIFIER mo_shift.c
30
.AUTHOR R.H. Warmels IPG-ESO Garching
31
.KEYWORDS alignment software
33
.PURPOSE Routine to compute the shift for each subframe
35
#include <ccd_def.h> Symbols used by the ccd package
36
.VERSION 1.0 16-May-1995 creation
39
------------------------------------------------------------*/
42
* Define _POSIX_SOURCE to indicate
43
* that this is a POSIX program
45
#define _POSIX_SOURCE 1
48
* definition of the used functions in this module
58
extern void MO_INDICES();
64
MO_SHIFTS -- Compute the input and output frame column limits and the
68
void MO_SHIFTS(inim, outim, xrshifts, yrshifts, xcshifts, ycshifts,
69
ic1, ic2, il1, il2, oc1, oc2, ol1, ol2, deltax, deltay)
105
nxsize = MO_NCOLS - MO_NXOVERLAP;
106
nysize = MO_NROWS - MO_NYOVERLAP;
107
c1ref = (MO_NXRSUB - 1) * nxsize + 1 + MO_XREF;
108
c2ref = c1ref + MO_NCOLS - 1;
109
l1ref = (MO_NYRSUB - 1) * nysize + 1 + MO_YREF;
110
l2ref = l1ref + MO_NROWS - 1;
111
nimages = MO_NXSUB * MO_NYSUB;
113
for ( i = 1; i <= nimages; i++)
116
Compute the indices of each subraster.
118
MO_INDICES(i, &j, &k, MO_NXSUB, MO_NYSUB, MO_CORNER, MO_RASTER, MO_ORDER);
120
Compute the indices of the input subraster.
122
stat = SCDRDI(inim,"NPIX",1,3,&iav,npix,&uni,&nulo);
125
ic1[i-1] = MYMAX(1, MYMIN (1 + (j - 1) * nxsize, nimcols));
126
ic2[i-1] = MYMIN(nimcols, MYMAX(1, ic1[i-1] + MO_NCOLS - 1));
127
il1[i-1] = MYMAX(1, MYMIN(1 + (k - 1) * nysize, nimlines));
128
il2[i-1] = MYMIN(nimlines, MYMAX(1, il1[i-1] + MO_NROWS - 1));
131
Compute the shift relative to the input subraster.
133
MO_MKSHIFT(xrshifts, yrshifts, xcshifts, ycshifts,
134
MO_NXSUB, MO_NYSUB, j, k, MO_NXRSUB,
135
MO_NYRSUB, MO_ORDER, &deltax[i-1], &deltay[i-1]);
136
ideltax = NINT (deltax[i-1]);
137
ideltay = NINT (deltay[i-1]);
140
Get the output buffer.
142
oc1[i-1] = c1ref + (j - MO_NXRSUB) * MO_NCOLS + ideltax;
143
oc2[i-1] = c2ref + (j - MO_NXRSUB) * MO_NCOLS + ideltax;
144
ol1[i-1] = l1ref + (k - MO_NYRSUB) * MO_NROWS + ideltay;
145
ol2[i-1] = l2ref + (k - MO_NYRSUB) * MO_NROWS + ideltay;
150
MO_FSHIFTS -- Compute the input and output columns limits
153
void MO_FSHIFTS(inim, outim, deltax, deltay,
154
ic1, ic2, il1, il2, oc1, oc2, ol1, ol2)
186
nxsize = MO_NCOLS - MO_NXOVERLAP;
187
nysize = MO_NROWS - MO_NYOVERLAP;
188
c1ref = (MO_NXRSUB - 1) * nxsize + 1 + MO_XREF;
189
c2ref = c1ref + MO_NCOLS - 1;
190
l1ref = (MO_NYRSUB - 1) * nysize + 1 + MO_YREF;
191
l2ref = l1ref + MO_NROWS - 1;
192
nimages = MO_NXSUB * MO_NYSUB;
194
for ( i = 1; i <= nimages; i++)
197
Compute the indices of each subraster.
199
MO_INDICES(i, &j, &k, MO_NXSUB, MO_NYSUB, MO_CORNER, MO_RASTER, MO_ORDER);
201
Compute the indices of the input subraster.
203
stat = SCDRDI(inim,"NPIX",1,3,&iav,npix,&uni,&nulo);
206
ic1[i-1] = MYMAX (1, MYMIN (1 + (j - 1) * nxsize, nimcols));
207
ic2[i-1] = MYMIN (nimcols, MYMAX (1, ic1[i-1] + MO_NCOLS - 1));
208
il1[i-1] = MYMAX (1, MYMIN (1 + (k - 1) * nysize, nimlines));
209
il2[i-1] = MYMIN (nimlines, MYMAX (1, il1[i-1] + MO_NROWS - 1));
212
Compute the shift relative to the input subraster.
214
ideltax = NINT (deltax[i-1]);
215
ideltay = NINT (deltay[i-1]);
218
Get the output buffer.
220
oc1[i-1] = c1ref + (j - MO_NXRSUB) * MO_NCOLS + ideltax;
221
oc2[i-1] = c2ref + (j - MO_NXRSUB) * MO_NCOLS + ideltax;
222
ol1[i-1] = l1ref + (k - MO_NYRSUB) * MO_NROWS + ideltay;
223
ol2[i-1] = l2ref + (k - MO_NYRSUB) * MO_NROWS + ideltay;
230
MO_MKSHIFT -- Routine to compute the total shift for each subframe.
233
void MO_MKSHIFT(xrshift, yrshift, xcshift, ycshift, nxsub, nysub,
234
xsubindex, ysubindex, nxrsub, nyrsub, order, deltax, deltay)
236
float (*xrshift)[MAXFRM]; /* x row shifts */
237
float (*yrshift)[MAXFRM]; /* y row shifts */
238
float (*xcshift)[MAXFRM]; /* x column shifts */
239
float (*ycshift)[MAXFRM]; /* y column shifts */
240
int nxsub; /* number of subraster in the x direction */
241
int nysub; /* number of subrasters in the y direction */
242
int xsubindex; /* x index subraster */
243
int ysubindex; /* y index subraster */
244
int nxrsub; /* x index of reference subraster */
245
int nyrsub; /* y index of reference subraster */
246
char *order; /* row or column order */
247
float *deltax; /* total x shift */
248
float *deltay; /* total y shift */
256
if (strcmp(order,MO_COLUMN) == 0)
258
if (ysubindex < nyrsub)
259
for (j = ysubindex; j <= nyrsub - 1; j++)
261
*deltax = *deltax + xcshift[xsubindex-1][j-1];
262
*deltay = *deltay + ycshift[xsubindex-1][j-1];
265
else if (ysubindex > nyrsub)
266
for (j = nyrsub + 1; j <= ysubindex; j++)
268
*deltax = *deltax + xcshift[xsubindex-1][j-1];
269
*deltay = *deltay + ycshift[xsubindex-1][j-1];
272
if (xsubindex < nxrsub)
273
for (j = xsubindex; j <= nxrsub - 1; j++)
275
*deltax = *deltax + xrshift[j-1][nyrsub-1];
276
*deltay = *deltay + yrshift[j-1][nyrsub-1];
279
else if (xsubindex > nxrsub)
280
for (j = nxrsub + 1; j <= xsubindex; j++)
282
*deltax = *deltax + xrshift[j-1][nyrsub-1];
283
*deltay = *deltay + yrshift[j-1][nyrsub-1];
289
if (xsubindex < nxrsub)
290
for (j = xsubindex; j <= nxrsub - 1; j++)
292
*deltax = *deltax + xrshift[j-1][ysubindex-1];
293
*deltay = *deltay + yrshift[j-1][ysubindex-1];
296
else if (xsubindex > nxrsub)
297
for (j = nxrsub + 1; j <= xsubindex; j++)
299
*deltax = *deltax + xrshift[j-1][ysubindex-1];
300
*deltay = *deltay + yrshift[j-1][ysubindex-1];
303
if (ysubindex < nyrsub)
304
for (j = ysubindex; j <= nyrsub - 1; j++)
306
*deltax = *deltax + xcshift[nxrsub-1][j-1];
307
*deltay = *deltay + ycshift[nxrsub-1][j-1];
310
else if (ysubindex > nyrsub)
311
for (j = nyrsub + 1; j <= ysubindex; j++)
313
*deltax = *deltax + xcshift[nxrsub-1][j-1];
314
*deltay = *deltay + ycshift[nxrsub-1][j-1];