1
C @(#)substar.for 19.1 (ES0-DMD) 02/25/03 13:23:51
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===========================================================================
29
SUBROUTINE SUBSTR (PAR, MAXPAR, PSF, MAXPSF, MAXEXP,
30
. F, NCOL, NROW, WATCH)
32
C=======================================================================
34
C This subroutine scales and shifts the point-spread function according
35
C to each star's magnitude and centroid, and subtracts the resulting
36
C profile from a copy of the original picture.
38
C OFFICIAL DAO VERSION: 1991 April 18
42
C WATCH (INPUT) governs whether information relating to the progress
43
C of the reductions is to be typed on the terminal screen
46
C=======================================================================
49
INTEGER MAXBOX, MAXPSF, MAXPAR, MAXEXC, MAXEXP
50
PARAMETER (MAXBOX=69, MAXEXC=200)
54
C MAXBOX is the side of the square subarray containing the largest
55
C (circular) PSF that can be subtracted from the picture.
57
C MAXPSF is the largest permissible number of elements on a side of the
58
C (square) look-up table for the point-spread function.
60
C MAXBOX = (MAXPSF-7)/2.
64
REAL F(NCOL,NROW), PSF(MAXPSF,MAXPSF,MAXEXP)
68
INTEGER RDPSF, MAX0, MIN0, INT
72
CHARACTER*30 COOFIL, MAGFIL, PSFFIL, PROFIL, GRPFIL, SWITCH
73
CHARACTER CASE*5, ANSWER*1
74
REAL LOBAD, X, Y, STRMAG, SKY, DX, DY, DYSQ, SCALE, COL, ROW
75
REAL DELTAX, DELTAY, DVDXC, DVDYC, XPSF, YPSF, PSFRAD, DUM
76
REAL HIBAD, THRESH, AP1, PHPADU, READNS, FRAD, WATCH, PSFMAG
78
INTEGER I, J, L, NL, IDUM, NEXC, LX, LY, NX, NY, ISTAR, ID
79
INTEGER ISTAT, IPSTYP, NPSF, NPAR, NEXP, NFRAC
81
COMMON /FILNAM/ COOFIL, MAGFIL, PSFFIL, PROFIL, GRPFIL
83
C-----------------------------------------------------------------------
87
C Get file names and set up the needed numerical constants.
89
CALL TBLANK ! Type a blank line
90
950 CALL GETNAM ('File with the PSF:', PSFFIL)
91
IF ((PSFFIL .EQ. 'END OF FILE') .OR.
92
. (PSFFIL .EQ. 'GIVE UP')) THEN
96
ISTAT = RDPSF (PSFFIL, IPSTYP, PAR, MAXPAR, NPAR,
97
. PSF, MAXPSF, MAXEXP, NPSF, NEXP, NFRAC,
98
. PSFMAG, BRIGHT, XPSF, YPSF)
99
IF (ISTAT .LT. 0) THEN
104
PSFRAD=(REAL(NPSF-1)/2. - 1.)/2.
111
1015 CALL GETNAM ('File with photometry:', PROFIL)
112
IF ((PROFIL .EQ. 'END OF FILE') .OR.
113
. (PROFIL .EQ. 'GIVE UP')) THEN
117
CALL INFILE (2, PROFIL, ISTAT)
118
IF (ISTAT .NE. 0) THEN
119
CALL STUPID ('Error opening input file '//PROFIL)
124
CALL GETYN ('Do you have stars to leave in?', ANSWER)
125
IF (ANSWER .EQ. 'Y') THEN
126
SUBPIC = SWITCH(PROFIL, CASE('.lst'))
127
1025 CALL GETNAM ('File with star list:', SUBPIC)
128
IF ((SUBPIC .EQ. 'END OF FILE') .OR. (SUBPIC .EQ.
133
CALL INFILE (3, SUBPIC, ISTAT)
134
IF (ISTAT .NE. 0) THEN
135
CALL STUPID ('Error opening file '//SUBPIC)
140
CALL RDHEAD (3, NL, IDUM, IDUM, DUM, DUM, DUM, DUM,
144
1036 CALL RDSTAR (3, NL, IEXC(NEXC), DUM, DUM, DUM, DUM)
145
IF (IEXC(NEXC) .EQ. 0) GO TO 1036
146
IF (IEXC(NEXC) .LT. 0) THEN
149
IF (NEXC .LT. MAXEXC) GO TO 1035
151
IF (NEXC .LE. 0) ANSWER = 'N'
155
CALL RDHEAD (2, NL, IDUM, IDUM, LOBAD, HIBAD, THRESH, AP1,
156
. PHPADU, READNS, FRAD)
158
SUBPIC=SWITCH(PROFIL, CASE('s'))
159
CALL GETNAM ('Name for subtracted image:', SUBPIC)
160
IF (SUBPIC .EQ. 'END OF FILE') GO TO 9010 ! CTRL-Z was entered
162
C Copy the input picture verbatim into the output picture.
164
CALL COPPIC (SUBPIC, F, NCOL, NROW, ISTAT)
165
IF (ISTAT .NE. 0) THEN
166
CALL STUPID ('Error creating output image.')
171
IF (WATCH .GT. 0.5) THEN
173
CALL OVRWRT (' Star', 1)
176
C Read the entire image in from the copy.
182
CALL RDARAY ('COPY', LX, LY, NX, NY, NCOL, F, ISTAT)
184
C-----------------------------------------------------------------------
192
2010 CALL RDSTAR (2, NL, ID, X, Y, STRMAG, SKY)
193
IF (ID .LT. 0) GO TO 9000 ! End-of-file encountered
194
IF (ID .EQ. 0) GO TO 2010 ! Ignore a blank line
195
IF ((1.-X .GT. PSFRAD) .OR. (X-COL .GT. PSFRAD) .OR.
196
. (1.-Y .GT. PSFRAD) .OR. (Y-ROW .GT. PSFRAD)) GO TO 2000
197
IF (ANSWER .EQ. 'Y') THEN
200
IF (ID .EQ. IEXC(I)) THEN
203
IF (NEXC .EQ. 0) ANSWER = 'N'
208
IF (STRMAG .GE. 99.) GO TO 2000 ! Ignore a bad star
209
IF (WATCH .GT. 0.5) THEN
210
WRITE (LINE,620) ISTAR
212
CALL OVRWRT (LINE(1:5), 2)
214
DELTAX=(X-1.)/XPSF-1.
215
DELTAY=(Y-1.)/YPSF-1.
216
LX=MAX0(1, INT(X-PSFRAD)+1)
217
LY=MAX0(1, INT(Y-PSFRAD)+1)
218
NX=MIN0(NCOL, INT(X+PSFRAD))
219
NY=MIN0(NROW, INT(Y+PSFRAD))
220
SCALE=10.**(0.4*(PSFMAG-STRMAG))
222
C Subtract the shifted scaled PSF
228
IF (F(I,J) .GT. HIBAD) GO TO 2020
230
IF (DX**2+DYSQ .GE. PSFRSQ) THEN
231
IF (DX .GT. 0.) GO TO 2030
233
F(I,J)=F(I,J)-SCALE*USEPSF(IPSTYP, DX, DY, BRIGHT, PAR,
234
. PSF, NPSF, NPAR, NEXP, NFRAC, DELTAX, DELTAY,
239
GO TO 2000 ! Go to next star
241
C-----------------------------------------------------------------------
246
IF (WATCH .GT. 0.5) CALL OVRWRT (' ', 4)
248
C Write the modified image back into the copy.
254
CALL WRARAY ('COPY', LX, LY, NX, NY, NCOL, F, ISTAT)
256
CALL STUPID (' Done. ')