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

« back to all changes in this revision

Viewing changes to prim/plot/libsrc/getdat.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
/* @(#)getdat.c 19.1 (ES0-DMD) 02/25/03 14:07:38 */
 
2
/*===========================================================================
 
3
  Copyright (C) 1995 European Southern Observatory (ESO)
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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, 
 
18
  MA 02139, USA.
 
19
 
 
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 
 
26
                        GERMANY
 
27
===========================================================================*/
 
28
 
 
29
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
30
.COPYRIGHT   (c) 1993 European Southern Observatory
 
31
.IDENTifer   GETDAT
 
32
.AUTHOR      R.M. van Hees IPG-ESO Garching
 
33
.KEYWORDS    low level plot routine
 
34
.LANGUAGE    C
 
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
 
42
 
 
43
.COMMENTS    only two dimensional frames
 
44
             uses (little bit more than): 4 * 2 * maxsize Mbyte memory
 
45
             
 
46
.ENVIRONment MIDAS
 
47
             #include <plot_def.h>      Symbols used by the PLT interfaces
 
48
             #include <midas_def.h>     Prototypes for MIDAS interfaces
 
49
 
 
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
------------------------------------------------------------*/
 
53
/*
 
54
 * Define _POSIX_SOURCE to indicate
 
55
 * that this is a POSIX program
 
56
 */
 
57
#define  _POSIX_SOURCE 1
 
58
 
 
59
/*
 
60
 * definition of the used functions in this module
 
61
 */
 
62
#include <math.h>
 
63
 
 
64
/*
 
65
 * define some macros and constants
 
66
 */
 
67
#include <midas_def.h>
 
68
#include <plot_def.h>
 
69
 
 
70
/*
 
71
 * here start the code of the function
 
72
 */
 
73
void GETDAT( imf, maxsize, npix, image, ism, p_img )
 
74
int   imf, maxsize, *npix, ism;
 
75
float *image, *p_img;
 
76
 
 
77
{
 
78
register int ic, ix, iy;
 
79
 
 
80
int    actvals, chunks, felem, imdum, ism1, ism2, navrg, nc, nr, nrcol, nrline,
 
81
       nrrow, size, ifram[4];
 
82
float  avrg, *pntr;
 
83
char   *cpntr;
 
84
 
 
85
if ( ism < 0 ) ism = 0;
 
86
 
 
87
/*
 
88
 * get sub-frame dimensions
 
89
 */
 
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] ));
 
94
 
 
95
/*
 
96
 * determine  size of the sub image
 
97
 */
 
98
nrcol  = ifram[1] - ifram[0] + 1;
 
99
nrrow  = ifram[3] - ifram[2] + 1;
 
100
 
 
101
/*
 
102
 * we can extract NRLINes of data from the original
 
103
 */
 
104
nrline = (int) floor( (double) maxsize / (double) *npix );
 
105
nrline = MYMIN( nrrow + 2 * ism, nrline ); 
 
106
 
 
107
/*
 
108
 * this means effectively that the number of rows and chunks equals
 
109
 */
 
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 );
 
113
 
 
114
/*
 
115
 * allocate virual memory and scratch space
 
116
 */
 
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 );
 
120
 
 
121
if ( ism == 0 )
 
122
   { felem = *npix * (ifram[2] - 1) + 1;
 
123
     for ( ic = 0; ic < chunks; ic++ )
 
124
         { (void) SCFGET( imf, felem, size, &actvals, cpntr ); 
 
125
          
 
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);
 
130
 
 
131
                 pntr += *npix;
 
132
               }
 
133
 
 
134
/*
 
135
 get next first pixel to read, number of rows and siz eof the data block
 
136
 */
 
137
           felem += size;
 
138
           nrrow = MYMIN((ifram[3]-ifram[2]+1) - (ic+1) * nrrow, nrline );
 
139
           size  = nrrow * *npix;
 
140
         }
 
141
   }
 
142
else
 
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 ); 
 
146
 
 
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 );
 
151
          
 
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++ ) 
 
156
                     { navrg = 0;
 
157
                       avrg  = 0.0;
 
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;
 
163
                                             avrg += *(pntr + k);
 
164
                                             navrg++;
 
165
                                           }
 
166
                                      }
 
167
                                 }
 
168
                           }
 
169
                       if ( navrg > 0 )
 
170
                          *p_img++ = avrg / navrg;
 
171
                       else
 
172
                          *p_img++ = 0.0;
 
173
                     }
 
174
                 pntr += *npix;
 
175
               }
 
176
         }
 
177
   }
 
178
/*
 
179
 * release the allocated memory
 
180
 */
 
181
(void) SCFCLO( imdum );
 
182
 
 
183
return;
 
184
}