1
/* @(#)getdat.c 19.1 (ES0-DMD) 02/25/03 14:07:38 */
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 (c) 1993 European Southern Observatory
32
.AUTHOR R.M. van Hees IPG-ESO Garching
33
.KEYWORDS low level plot routine
35
.PURPOSE extract a subimage from a FRAME and smoothes it (option)
36
input: int imf file id of related MIDAS frame
37
int maxsize maximum number of pixels stored
38
int *npix standart descriptor of the frame
39
float *image contains in pixel units
40
int ism smooting parameter
41
in/output: float *p_img pointer to the output frame
43
.COMMENTS only two dimensional frames
44
uses (little bit more than): 4 * 2 * maxsize Mbyte memory
47
#include <plot_def.h> Symbols used by the PLT interfaces
48
#include <midas_def.h> Prototypes for MIDAS interfaces
50
.VERSION 1.1 14-Dec-1993 rewritten: reads in chunks, RvH
51
1.0 26-Nov-1993 Created by R.M. van Hees
52
------------------------------------------------------------*/
54
* Define _POSIX_SOURCE to indicate
55
* that this is a POSIX program
57
#define _POSIX_SOURCE 1
60
* definition of the used functions in this module
65
* define some macros and constants
67
#include <midas_def.h>
71
* here start the code of the function
73
void GETDAT( imf, maxsize, npix, image, ism, p_img )
74
int imf, maxsize, *npix, ism;
78
register int ic, ix, iy;
80
int actvals, chunks, felem, imdum, ism1, ism2, navrg, nc, nr, nrcol, nrline,
81
nrrow, size, ifram[4];
85
if ( ism < 0 ) ism = 0;
88
* get sub-frame dimensions
90
ifram[0] = NINT( MYMIN( image[0], image[1] ));
91
ifram[1] = NINT( MYMAX( image[0], image[1] ));
92
ifram[2] = NINT( MYMIN( image[2], image[3] ));
93
ifram[3] = NINT( MYMAX( image[2], image[3] ));
96
* determine size of the sub image
98
nrcol = ifram[1] - ifram[0] + 1;
99
nrrow = ifram[3] - ifram[2] + 1;
102
* we can extract NRLINes of data from the original
104
nrline = (int) floor( (double) maxsize / (double) *npix );
105
nrline = MYMIN( nrrow + 2 * ism, nrline );
108
* this means effectively that the number of rows and chunks equals
110
if ( (nrrow = nrline - 2 * ism) < 1 )
111
SCETER( 1, "*** FATAL: GETDAT, maxsize too small given the smooth factor" );
112
chunks = (int) ceil( (double) (ifram[3] - ifram[2] + 1) / nrrow );
115
* allocate virual memory and scratch space
117
size = nrline * *npix;
118
(void) SCFCRE( "DUMMY", D_R4_FORMAT, F_X_MODE, F_IMA_TYPE, size, &imdum );
119
(void) SCFMAP( imdum, F_X_MODE, 1, size, &actvals, &cpntr );
122
{ felem = *npix * (ifram[2] - 1) + 1;
123
for ( ic = 0; ic < chunks; ic++ )
124
{ (void) SCFGET( imf, felem, size, &actvals, cpntr );
126
pntr = (float *) cpntr;
127
pntr += ifram[0] - 1;
128
for ( nr = 0; nr < nrrow; nr++ )
129
{ for ( nc = 0; nc < nrcol; nc++ ) *p_img++ = *(pntr + nc);
135
get next first pixel to read, number of rows and siz eof the data block
138
nrrow = MYMIN((ifram[3]-ifram[2]+1) - (ic+1) * nrrow, nrline );
139
size = nrrow * *npix;
143
{ for ( ic = 0; ic < chunks; ic++ )
144
{ felem = *npix * MYMAX( ifram[2] + ic * nrrow - ism - 1, 0 ) + 1;
145
(void) SCFGET( imf, felem, size, &actvals, cpntr );
147
ism1 = MYMIN( ism, ifram[2] - 1 + ic * nrrow );
148
ism2 = MYMIN( ism, npix[1] - ifram[2] + 1 - (ic+1) * nrrow );
149
nrline = nrrow + ism1 + ism2;
150
nrrow = MYMIN((ifram[3] - ifram[2]+1) - ic * nrrow, nrrow );
152
pntr = (float *) cpntr;
153
pntr += ism1 * *npix + ifram[0] - 1;
154
for ( nr = 0; nr < nrrow; nr++ )
155
{ for ( nc = 0; nc < nrcol; nc++ )
158
for ( iy = -ism; iy <= ism; iy++ )
159
{ if ( nr+iy+ism1 >= 0 && nr+iy < nrline )
160
{ for ( ix = -ism; ix <= ism; ix++ )
161
{ if ( nc+ix >= 0 && nc+ix < *npix )
162
{ register int k = nc+ix+iy* *npix;
170
*p_img++ = avrg / navrg;
179
* release the allocated memory
181
(void) SCFCLO( imdum );