1
/* @(#)zima.c 19.1 (ES0-DMD) 02/25/03 14:01:10 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.COPYRIGHT: Copyright (c) 1994 European Southern Observatory,
34
.AUTHOR K. Banse IPG-ESO Garching
35
.KEYWORDS bulk data frame, pixel values
36
.PURPOSE get data values at given real pixel no's. of an image
37
.ALGORITHM a list of real pixel no's. is scanned and corresponding data
38
values of input array are stored in output array
39
bilinear interpolation is used to obtain values for real pixels
40
not falling exactly in the grid of coordinates for pixel no's.
41
falling on the upward border lines in x or y, interpolation
42
is done only in x or y, i.e. the border grid points are duplicated
44
calculate also dynamic range on the fly
46
call as Czima( p_in, npix, xpixl, ypixl, ndim, p_out, fmin, fmax )
49
float *p_in input array of data
50
int *npix dimension of input data
51
float *xpixl buffer with real pixel no's. in x
52
float *ypixl buffer with real pixel no's. in y
53
int ndim dimension of XPIXL + YPIXL
56
float *p_out output array of data
57
float *fmin minimum value of output array
58
float *fmax max value ...
62
.VERSIONS 1.00 940606 from ZIMA.FOR R.M. van Hees
63
.VERSIONS 1.10 941122 fix it , KB
64
------------------------------------------------------------*/
66
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
68
#define _POSIX_SOURCE 1
70
#include <midas_def.h>
78
void Czima(float *p_in,int *npix,float *xpixl,float *ypixl,int ndim,
79
float *p_out,float *fmin,float *fmax)
82
void Czima(p_in,npix,xpixl,ypixl,ndim,p_out,fmin,fmax)
84
float *p_in, *p_out, *xpixl, *ypixl, *fmin, *fmax;
91
int indxx, indxy, indx1, indx2, indx3, indx4;
92
float val, xfrac, yfrac;
96
if (*npix <= 1) /* only 1-D in Y */
99
indx1 = ypixl[nn] - 1;
102
else if (indx1 > (npix[1]-1))
104
*fmin = *fmax = p_in[indx1];
106
for (nn=0; nn<ndim; nn++)
108
cindx = ypixl[nn] - 1.0; /* move to [0,npix-1] */
114
else if (cindx > (float) (npix[1]-1))
122
yfrac = cindx - indx1;
126
if (indx2 > (npix[1]-1))
129
val = p_in[indx1] + (yfrac * (p_in[indx2] - p_in[indx1]));
133
else if ( *fmax < val )
140
else if (npix[1] <= 1) /* only 1-D in X */
143
indx1 = xpixl[nn] - 1;
146
else if (indx1 > (npix[0]-1))
148
*fmin = *fmax = p_in[indx1];
150
for (nn=0; nn<ndim; nn++)
152
cindx = xpixl[nn] - 1.0; /* move to [0,npix-1] */
158
else if (cindx > (float) (npix[0]-1))
166
xfrac = cindx - indx1;
170
if (indx2 > (*npix-1))
173
val = p_in[indx1] + (xfrac * (p_in[indx2] - p_in[indx1]));
177
else if ( *fmax < val )
188
nsize = npix[0] * npix[1];
191
indx1 = xpixl[nn] - 1;
194
else if (indx1 > (npix[0]-1))
196
indx2 = ypixl[nn] - 1;
199
else if (indx2 > (npix[1]-1))
201
indx1 += (indx2*npix[0]);
202
*fmin = *fmax = p_in[indx1];
204
for (nn=0; nn<ndim; nn++)
206
cindx = xpixl[nn] - 1.0; /* move to [0,npix-1] */
212
else if (cindx >= (float) (npix[0]-1))
220
xfrac = cindx - indxx;
223
cindx = ypixl[nn] - 1.0; /* move to [0,npix-1] */
229
else if (cindx >= (float) (npix[1]-1))
237
yfrac = cindx - indxy;
240
indx1 = indxx + ((*npix) * indxy);
242
indx3 = indx1 + (*npix);
243
if ((indxx + 1) >= *npix ) /* are we out of grid in x? */
245
if (indx2 >= nsize) /* also out in y? */
248
val = p_in[indx1] + ( yfrac * (p_in[indx3] - p_in[indx1]) );
252
if (indx3 >= nsize) /* are we out of grid in y? */
253
val = p_in[indx1] + ( xfrac * (p_in[indx2] - p_in[indx1]) );
258
+ xfrac * (p_in[indx2] - p_in[indx1])
259
+ yfrac * (p_in[indx3] - p_in[indx1])
260
+ xfrac * yfrac * (p_in[indx1] - p_in[indx2]
261
- p_in[indx3] + p_in[indx4]);
267
else if ( *fmax < val )