1
C @(#)integbin.for 19.1 (ES0-DMD) 02/25/03 14:29:41
2
C===========================================================================
3
C Copyright (C) 1995 European Southern Observatory (ESO)
5
C This program is free software; you can redistribute it and/or
6
C modify it under the terms of the GNU General Public License as
7
C published by the Free Software Foundation; either version 2 of
8
C the License, or (at your option) any later version.
10
C This program is distributed in the hope that it will be useful,
11
C but WITHOUT ANY WARRANTY; without even the implied warranty of
12
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
C GNU General Public License for more details.
15
C You should have received a copy of the GNU General Public
16
C License along with this program; if not, write to the Free
17
C Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
C Corresponding concerning ESO-MIDAS should be addressed as follows:
21
C Internet e-mail: midas@eso.org
22
C Postal address: European Southern Observatory
23
C Data Management Division
24
C Karl-Schwarzschild-Strasse 2
25
C D 85748 Garching bei Muenchen
27
C===========================================================================
30
C +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
C.COPYRIGHT: Copyright (c) 1987 European Southern Observatory,
34
C.VERSION: 1.0 ESO-FORTRAN Conversion, AA 17:13 - 3 DEC 1987
36
C.LANGUAGE: F77+ESOext
41
C program INTEGBIN version 1.0 851028
44
C flux integration over fixed bins in 1-D images
47
C to be used for normalization of spectra or construction of
51
C get central positions of bins and their widths from table (in keyword
52
C NFTAB), integrate flux in image (keyword NFIMA) over bins (where
53
C necessary do a linear interpolation), write results to table
56
C the following keywords are used:
57
C NFIMA/C/1/60 name of input image
58
C NFTAB/C/1/60 name of table with central wavelengths, bin
59
C widths, will also receive fluxes derived
61
C. modif MPeron 130291 add TBTCLO
62
C --------------------------------------------------------------------
66
CHARACTER*60 NFIMA,NFTAB
67
CHARACTER FORM*6,IDENT*72,CUNIT*72
68
INTEGER NPIX,ISTAT,IAV,ERROR(2),ICOL(3),IRCOL(2)
69
INTEGER NCOL,NROW,LL,I,NSC1
71
INTEGER NAXIS,KUN,KNUL
72
INTEGER IMNO,TID,NAC,NAR,DTYPE
74
DOUBLE PRECISION DEND, DSTEP, DSTART, LAMLO, LAMHI
77
INCLUDE 'MID_INCLUDE:TABLES.INC'
79
INCLUDE 'MID_INCLUDE:TABLED.INC'
81
C ... set up MIDAS environment
83
CALL STSPRO('INTEGBIN')
85
C ... get name of input frame, map it
87
CALL STKRDC('NFIMAGE',1,1,60,IAV,NFIMA,KUN,KNUL,ISTAT)
88
IF (ISTAT.NE.0) GO TO 20
89
CALL STIGET(NFIMA,10,0,1,1,NAXIS,NPIX,DSTART,DSTEP,
90
+IDENT,CUNIT,PNTR,IMNO,ISTAT)
91
IF (ISTAT.NE.0) GO TO 20
93
CALL STTPUT('ERROR: input frame must be one-dimensional',
98
DEND = DSTART + (NPIX-1)*DSTEP
100
C ... get name of table
102
CALL STKRDC('NFTABLE',1,1,60,IAV,NFTAB,KUN,KNUL,ISTAT)
103
IF (ISTAT.NE.0) GO TO 20
105
C ... intialize table
107
CALL TBTOPN(NFTAB,2,TID,ISTAT)
108
IF (ISTAT.NE.0) GO TO 20
109
CALL TBIGET(TID,NCOL,NROW,NSC1,NAC,NAR,ISTAT)
110
IF (ISTAT.NE.0) GO TO 20
112
C ... find column 'X_AXIS' (wavelength)
114
CALL TBLSER(TID,'X_AXIS',ICOL(1),ISTAT)
115
IF (ICOL(1).EQ.-1) THEN
117
CALL STTPUT('ERROR: column not found',ISTAT)
120
CALL TBFGET(TID,ICOL(1),FORM,LL,DTYPE,ISTAT)
121
IF (DTYPE.EQ.D_C_FORMAT) THEN
123
CALL STTPUT('ERROR: wrong column format',ISTAT)
127
C ... find column 'BIN_WIDTH'
129
CALL TBLSER(TID,'BIN_WIDTH',ICOL(2),ISTAT)
130
IF (ICOL(2).EQ.-1) THEN
132
CALL STTPUT('ERROR: column not found',ISTAT)
135
CALL TBFGET(TID,ICOL(2),FORM,LL,DTYPE,ISTAT)
136
IF (DTYPE.EQ.D_C_FORMAT) THEN
138
CALL STTPUT('ERROR: wrong column format',ISTAT)
142
C ... find column 'Y_AXIS' (flux)
144
CALL TBLSER(TID,'Y_AXIS',ICOL(3),ISTAT)
145
IF (ICOL(3).EQ.-1) THEN
147
CALL STTPUT('ERROR: column not found',ISTAT)
150
CALL TBFGET(TID,ICOL(3),FORM,LL,DTYPE,ISTAT)
151
IF (DTYPE.EQ.D_C_FORMAT) THEN
153
CALL STTPUT('ERROR: wrong column format',ISTAT)
162
CALL TBRRDR(TID,I,2,IRCOL,DATA,NULL,ISTAT)
163
CURRY = ( .NOT. NULL(1)) .AND. ( .NOT. NULL(2))
164
IF (CURRY) THEN ! lower limit in lambda of bin
165
LAMLO = DATA(1) - DATA(2)/2. ! upper limit in lambda of bin
166
LAMHI = DATA(1) + DATA(2)/2.
167
IF ((LAMLO.GE.DSTART) .AND. (LAMHI.LE.DEND)) THEN
169
C ... let subroutine DOINTG do the job
171
CALL DOINTG(MADRID(PNTR),DSTART,DSTEP,NPIX,LAMLO,LAMHI,
173
CALL TBEWRR(TID,I,ICOL(3),BINFLX,ISTAT)
180
CALL TBTCLO(TID,ISTAT)
184
C ... direct trouble makers here:
187
CALL STKWRI('PROGSTAT',ERROR,1,2,KUN,ISTAT)
193
SUBROUTINE DOINTG(FLUX,DSTART,DSTEP,NPIX,LAMLO,LAMHI,BINFLX)
197
INTEGER NPIX,IPIXHI,IPIXLO,I
198
REAL FLUX(1),PIXLO,PIXHI,FPIXHI,FPIXLO,BINFLX
199
DOUBLE PRECISION DSTART, DSTEP, LAMLO, LAMHI
201
C ... all operations below assume that the flux is evenly distributed
202
C ... ver the pixel and that its coordinates refer to the pixel's
204
C ! first pixel hit (only partly)
205
PIXLO = 0.5 + (LAMLO-DSTART)/DSTEP ! last pixel hit (also only partly)
206
PIXHI = 0.5 + (LAMHI-DSTART)/DSTEP ! nmubers of first ...
207
IPIXLO = INT(PIXLO) ! ... and last pixel
208
IPIXHI = INT(PIXHI) ! fraction of first and ...
209
FPIXLO = IPIXLO + 1 - PIXLO ! ... last pixel to be considered
210
FPIXHI = PIXHI - IPIXHI
212
C ... do a linear interpolation across the first and last pixel,
213
C ... add up the pixels in between, return mean flux per pixel
215
BINFLX = FPIXLO*FLUX(IPIXLO) + FPIXHI*FLUX(IPIXHI)
216
DO 10 I = IPIXLO + 1,IPIXHI - 1
217
BINFLX = BINFLX + FLUX(I)
219
BINFLX = BINFLX/ (IPIXHI-IPIXLO-1+FPIXLO+FPIXHI)