~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to stdred/ccdred/libsrc/mo_shift.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1995-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
.IDENTIFIER  mo_shift.c
 
30
.AUTHOR      R.H. Warmels IPG-ESO Garching
 
31
.KEYWORDS    alignment software
 
32
.LANGUAGE    C
 
33
.PURPOSE     Routine to compute the shift for each subframe
 
34
.ENVIRONment MIDAS
 
35
             #include <ccd_def.h>      Symbols used by the ccd package
 
36
.VERSION     1.0     16-May-1995   creation
 
37
 
 
38
 090721         last  modif
 
39
------------------------------------------------------------*/
 
40
 
 
41
/*
 
42
 * Define _POSIX_SOURCE to indicate
 
43
 * that this is a POSIX program
 
44
 */
 
45
#define  _POSIX_SOURCE 1
 
46
 
 
47
/*
 
48
 * definition of the used functions in this module
 
49
 */
 
50
#include <stdio.h>
 
51
#include <string.h>
 
52
#include <stdlib.h>
 
53
#include <math.h>
 
54
 
 
55
#include <ccd_def.h>
 
56
 
 
57
extern int  SCDRDI();
 
58
extern void MO_INDICES();
 
59
void MO_MKSHIFT();
 
60
 
 
61
 
 
62
 
 
63
/*
 
64
 MO_SHIFTS -- Compute the input and output frame column limits and the 
 
65
              x and y shifts 
 
66
 */
 
67
 
 
68
void MO_SHIFTS(inim, outim, xrshifts, yrshifts, xcshifts, ycshifts, 
 
69
                       ic1, ic2, il1, il2, oc1, oc2, ol1, ol2, deltax, deltay)
 
70
 
 
71
int     inim;
 
72
int     outim;
 
73
float   *xrshifts;
 
74
float   *yrshifts;
 
75
float   *xcshifts;
 
76
float   *ycshifts;
 
77
int     *ic1;
 
78
int     *ic2;
 
79
int     *il1;
 
80
int     *il2;
 
81
int     *oc1;
 
82
int     *oc2;
 
83
int     *ol1;
 
84
int     *ol2;
 
85
float   *deltax;
 
86
float   *deltay;
 
87
 
 
88
{       
 
89
int     i, iav;
 
90
int     ideltax;
 
91
int     ideltay;
 
92
int     j;
 
93
int     k;
 
94
int     nimages;
 
95
int     nxsize, nysize;
 
96
int     nimcols;
 
97
int     nimlines;
 
98
int     npix[3];
 
99
int     c1ref, c2ref;
 
100
int     l1ref, l2ref;
 
101
int     nulo;
 
102
int     stat;
 
103
int     uni;
 
104
 
 
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;
 
112
 
 
113
for ( i = 1; i <= nimages; i++)
 
114
   {
 
115
/*
 
116
 Compute the indices of each subraster.
 
117
 */
 
118
   MO_INDICES(i, &j, &k, MO_NXSUB, MO_NYSUB, MO_CORNER, MO_RASTER, MO_ORDER);
 
119
/*
 
120
 Compute the indices of the input subraster.
 
121
 */
 
122
    stat       = SCDRDI(inim,"NPIX",1,3,&iav,npix,&uni,&nulo);
 
123
    nimcols    = npix[0];
 
124
    nimlines   = npix[1];
 
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));
 
129
 
 
130
/*
 
131
 Compute the shift relative to the input subraster.
 
132
 */
 
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]);
 
138
 
 
139
/*
 
140
 Get the output buffer.
 
141
 */
 
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;
 
146
  }  
 
147
}
 
148
 
 
149
/*
 
150
 MO_FSHIFTS -- Compute the input and output columns limits
 
151
 */
 
152
 
 
153
void MO_FSHIFTS(inim, outim, deltax, deltay, 
 
154
                        ic1, ic2, il1, il2, oc1, oc2, ol1, ol2)
 
155
 
 
156
int     inim;
 
157
int     outim;
 
158
float   *deltax;
 
159
float   *deltay;
 
160
int     *ic1;
 
161
int     *ic2;
 
162
int     *il1;
 
163
int     *il2;
 
164
int     *oc1;
 
165
int     *oc2;
 
166
int     *ol1;
 
167
int     *ol2;
 
168
 
 
169
{       
 
170
int     i, iav;
 
171
int     j;
 
172
int     k;
 
173
int     nimages;
 
174
int     nimcols;
 
175
int     nimlines;
 
176
int     npix[3];
 
177
int     nxsize, nysize;
 
178
int     c1ref, c2ref;
 
179
int     l1ref, l2ref;
 
180
int     ideltax;
 
181
int     ideltay;
 
182
int     stat;
 
183
int     uni;
 
184
int     nulo;
 
185
 
 
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;
 
193
 
 
194
for ( i = 1; i <= nimages; i++)
 
195
   {
 
196
/*
 
197
 Compute the indices of each subraster.
 
198
 */
 
199
   MO_INDICES(i, &j, &k, MO_NXSUB, MO_NYSUB, MO_CORNER, MO_RASTER, MO_ORDER);
 
200
/*
 
201
 Compute the indices of the input subraster.
 
202
 */
 
203
    stat       = SCDRDI(inim,"NPIX",1,3,&iav,npix,&uni,&nulo);
 
204
    nimcols    = npix[0];
 
205
    nimlines   = npix[1];
 
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));
 
210
 
 
211
/*
 
212
 Compute the shift relative to the input subraster.
 
213
 */
 
214
    ideltax = NINT (deltax[i-1]);
 
215
    ideltay = NINT (deltay[i-1]);
 
216
 
 
217
/*
 
218
 Get the output buffer.
 
219
 */
 
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;
 
224
  }  
 
225
}  
 
226
 
 
227
 
 
228
 
 
229
/*
 
230
 MO_MKSHIFT -- Routine to compute the total shift for each subframe. 
 
231
*/
 
232
 
 
233
void MO_MKSHIFT(xrshift, yrshift, xcshift, ycshift, nxsub, nysub,
 
234
           xsubindex, ysubindex, nxrsub, nyrsub, order, deltax, deltay)
 
235
 
 
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 */
 
249
 
 
250
{
 
251
int      j;
 
252
 
 
253
*deltax = 0.0;
 
254
*deltay = 0.0;
 
255
 
 
256
if (strcmp(order,MO_COLUMN) == 0)
 
257
   {
 
258
   if (ysubindex < nyrsub)
 
259
      for (j = ysubindex; j <= nyrsub - 1; j++)
 
260
          {
 
261
          *deltax = *deltax + xcshift[xsubindex-1][j-1];
 
262
          *deltay = *deltay + ycshift[xsubindex-1][j-1];
 
263
          }
 
264
 
 
265
   else if (ysubindex > nyrsub)
 
266
      for (j = nyrsub + 1; j <= ysubindex; j++)
 
267
          {
 
268
          *deltax = *deltax + xcshift[xsubindex-1][j-1];
 
269
          *deltay = *deltay + ycshift[xsubindex-1][j-1];
 
270
          }
 
271
   
 
272
   if (xsubindex < nxrsub)
 
273
      for (j = xsubindex; j <= nxrsub - 1; j++)
 
274
          {
 
275
          *deltax = *deltax + xrshift[j-1][nyrsub-1];
 
276
          *deltay = *deltay + yrshift[j-1][nyrsub-1];
 
277
          }
 
278
 
 
279
   else if (xsubindex > nxrsub)
 
280
      for (j = nxrsub + 1; j <= xsubindex; j++)
 
281
          {
 
282
          *deltax = *deltax + xrshift[j-1][nyrsub-1];
 
283
          *deltay = *deltay + yrshift[j-1][nyrsub-1];
 
284
          }
 
285
   }
 
286
 
 
287
else
 
288
   {
 
289
   if (xsubindex < nxrsub)
 
290
      for (j = xsubindex; j <= nxrsub - 1; j++)
 
291
          {
 
292
          *deltax = *deltax + xrshift[j-1][ysubindex-1];
 
293
          *deltay = *deltay + yrshift[j-1][ysubindex-1];
 
294
          }
 
295
 
 
296
   else if (xsubindex > nxrsub)
 
297
      for (j = nxrsub + 1; j <= xsubindex; j++)
 
298
          {
 
299
          *deltax = *deltax + xrshift[j-1][ysubindex-1];
 
300
          *deltay = *deltay + yrshift[j-1][ysubindex-1];
 
301
          }
 
302
   
 
303
   if (ysubindex < nyrsub)
 
304
      for (j = ysubindex; j <= nyrsub - 1; j++)
 
305
          {
 
306
          *deltax = *deltax + xcshift[nxrsub-1][j-1];
 
307
          *deltay = *deltay + ycshift[nxrsub-1][j-1];
 
308
          }
 
309
 
 
310
   else if (ysubindex > nyrsub)
 
311
      for (j = nyrsub + 1; j <= ysubindex; j++)
 
312
          {
 
313
          *deltax = *deltax + xcshift[nxrsub-1][j-1];
 
314
          *deltay = *deltay + ycshift[nxrsub-1][j-1];
 
315
          }
 
316
   }
 
317
}
 
318
 
 
319