1
C===========================================================================
2
C Copyright (C) 1995-2008 European Southern Observatory (ESO)
4
C This program is free software; you can redistribute it and/or
5
C modify it under the terms of the GNU General Public License as
6
C published by the Free Software Foundation; either version 2 of
7
C the License, or (at your option) any later version.
9
C This program is distributed in the hope that it will be useful,
10
C but WITHOUT ANY WARRANTY; without even the implied warranty of
11
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
C GNU General Public License for more details.
14
C You should have received a copy of the GNU General Public
15
C License along with this program; if not, write to the Free
16
C Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
19
C Correspondence concerning ESO-MIDAS should be addressed as follows:
20
C Internet e-mail: midas@eso.org
21
C Postal address: European Southern Observatory
22
C Data Management Division
23
C Karl-Schwarzschild-Strasse 2
24
C D 85748 Garching bei Muenchen
26
C===========================================================================
29
C +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
C.VERSION: 1.0 ESO-FORTRAN Conversion, AA 11:28 - 7 DEC 1987
33
C.LANGUAGE: F77+ESOext
35
C.AUTHOR: J.D.Ponz, but I did not code it!
38
C program FRIPPLE version 1.0 851030
39
C correct some bugs 900619 MP
45
C correct 1-D images for periodic modulation (FRIPLE)
48
C Fold flux with period, calculate mean flux per phase bin, determine
49
C deviation from total mean, adjust to mean level.
52
C the following keywords are used:
53
C IN_A/C/1/8 name of input image
55
C INPUTI/I/1/2 first and last pixel to be considered
56
C OUT_A/C/1/8 name of ripple corrected image
61
C --------------------------------------------------------------------
66
CHARACTER*60 INIMA,OUTIMA
67
CHARACTER*80 OUTEXT,HISTOR
68
CHARACTER IDENT*72,CUNIT*64
69
INTEGER NAXIS,NPIX,ISTAT,IAV
70
INTEGER*8 PNTRIN,PNTRO
71
INTEGER RANGE(2),ERROR(2),NWORK
74
INTEGER KUN,KNUL,IMIN,IMOUT
75
REAL PERIOD,AMP(500),TEST
77
DOUBLE PRECISION DSTART(3),DSTEP(3)
79
INCLUDE 'MID_INCLUDE:ST_DEF.INC'
82
INCLUDE 'MID_INCLUDE:ST_DAT.INC'
85
C ... set up MIDAS environment
89
C ... get name of input frame, map it
91
CALL STKRDC('IN_A',1,1,60,IAV,INIMA,KUN,KNUL,ISTAT)
92
IF (ISTAT.NE.0) GO TO 20
93
CALL STIGET(INIMA,D_R4_FORMAT,F_I_MODE,F_IMA_TYPE,1,NAXIS,NPIX,
94
+ DSTART,DSTEP,IDENT,CUNIT,PNTRIN,IMIN,ISTAT)
95
IF (ISTAT.NE.0) GO TO 20
97
CALL STTPUT('ERROR: input frame must be one-dimensional',
103
C ... get name of output frame, map it
105
CALL STKRDC('OUT_A',1,1,60,IAV,OUTIMA,KUN,KNUL,ISTAT)
106
CALL STIPUT(OUTIMA,D_R4_FORMAT,F_O_MODE,F_IMA_TYPE,NAXIS,NPIX,
107
+ DSTART,DSTEP,IDENT,CUNIT,PNTRO,IMOUT,ISTAT)
109
C ... get period, branch according to type (integer or real) of
110
C ... period to subroutines IAMPLT or RAMPLT to find
111
C ... amplitude of modulation
113
CALL STKRDR('INPUTR',1,1,IAV,PERIOD,KUN,KNUL,ISTAT)
115
CALL STKRDI('INPUTI',1,2,IAV,RANGE,KUN,KNUL,ISTAT)
117
TEST = PERIOD - INT(PERIOD)
118
C ! period near-integer?
119
IF (TEST*NPIX/PERIOD.LT.0.05) THEN
121
CALL IAMPLT(MADRID(PNTRIN),PERIOD,RANGE,AMP) ! no, real
122
ELSE ! use a fixed number of 20 phase bins
125
C ... in this case, map SCRAT file to hold intermediate results
126
C ... first, determine number of pixels needed
128
SCNPIX = INT(20*NPIX/PERIOD)
130
CALL TDMGET(NWORK,SCRPTR,ISTAT)
131
CALL RAMPLT(MADRID(PNTRIN),SCNPIX,PERIOD,RANGE,AMP,
135
C ... communicate results:
137
CALL STTPUT('Results:',ISTAT)
139
WRITE (OUTEXT,9000) I,I + 3,AMP(I),AMP(I+1),AMP(I+2),
141
CALL STTPUT(OUTEXT,ISTAT)
144
C ... the ripple correction is, then, done by subroutines
145
C ... IRIPC and RRIPC, respectively
147
IF (TEST*NPIX/PERIOD.LT.0.05) THEN
148
CALL IRIPC(MADRID(PNTRIN),NPIX,PERIOD,RANGE,AMP,
151
CALL RRIPC(MADRID(PNTRIN),NPIX,PERIOD,RANGE,AMP,
152
+ MADRID(SCRPTR),SCNPIX,MADRID(PNTRO))
155
C ... copy descriptor LHCUTS
157
CALL STDCOP(IMIN,IMOUT,4,'LHCUTS',ISTAT)
159
C ... copy and update descriptor HISTOR
161
CALL STDCOP(IMIN,IMOUT,4,'HISTORY',ISTAT)
162
CALL STKRDC('HISTORY',1,1,80,IAV,HISTOR,KUN,KNUL,ISTAT)
163
CALL STDWRC(IMOUT,'HISTOR',1,HISTOR,-1,80,KUN,ISTAT)
170
C ... direct trouble makers here:
173
CALL STKWRI('PROGSTAT',ERROR,1,2,KUN,ISTAT)
177
9000 FORMAT ('Phase bins No.',I3,' to',I3,' have ','amplitudes ',
183
SUBROUTINE IAMPLT(IN,PERIOD,RANGE,AMP)
186
INTEGER NCYCL,I,J,RANGE(2),IPER, IR1, IR2
187
REAL PERIOD,IN(1),AMP(500),SUM(500),MEAN
188
C ! consider only integer number of cycles
189
NCYCL = INT((RANGE(2)-RANGE(1)+1)/PERIOD)
196
C ... build up flux in phase bins
197
C ... to compensate for slopes in input data, refer to mean
201
IR2 = RANGE(1) + (NCYCL-1)*PERIOD
202
DO 40 I = IR1, IR2,IPER
205
MEAN = MEAN + IN(I+J-1)
206
20 CONTINUE ! average flux in one cycle
209
SUM(J) = SUM(J) + IN(I+J-1)/MEAN
213
C ... division into mean flux yields the relative amplitude of
232
SUBROUTINE IRIPC(IN,NPIX,PERIOD,RANGE,AMP,OUT)
235
INTEGER RANGE(2),NPIX,OFF,PHASE,I,J,INDX,IPER
236
REAL IN(1),OUT(1),PERIOD,AMP(500)
238
C ... take into account possible phase offset introduced if RANGE
239
C ... was not defaulted to [1,NPIX]
241
OFF = NINT(((RANGE(1)-1.)/PERIOD-INT((RANGE(1)-1.)/PERIOD))*
245
DO 20 I = 1,NPIX,IPER
248
IF (INDX.GT.NPIX) GO TO 30
250
IF (PHASE.GT.PERIOD) PHASE = PHASE - PERIOD ! do the FRIPLE compensation
251
OUT(INDX) = IN(INDX)*AMP(PHASE)
260
SUBROUTINE RAMPLT(IN,SCNPIX,PERIOD,RANGE,AMP,SCRAT)
262
INTEGER RANGE(2),PIXLO,PIXHI,I,J,SCNPIX,BIN,START,OFF,END
263
REAL PERIOD,IN(1),AMP(500),SUM(20),FRACLO,FRACHI,XLO,XHI,MEAN,
270
C ... rebin to stepsize corresponding to one phasebin
271
C ... the algorithm is a pure projection, no interpolation is done
272
C ... (since the origin and nature of the ripple are not known)
275
DO 30 I = 1,SCNPIX ! ith pixel extends from i to i+1 in both spaces
276
XLO = (I-1)*STEP + 1 ! lower and upper limit of projected output pixel
279
PIXHI = INT(XHI) ! all in same output pixel
280
IF ((PIXHI-PIXLO).EQ.0) THEN
282
SCRAT(I) = FRACLO*IN(PIXLO) ! at least two output pixels hit
284
FRACLO = PIXLO + 1 - XLO
286
SCRAT(I) = FRACLO*IN(PIXLO) + FRACHI*IN(PIXHI) ! if in fact more than two
287
DO 20 J = PIXLO + 1,PIXHI - 1
288
SCRAT(I) = SCRAT(I) + IN(J)
294
C ... evaluate the periodicity over the given range
295
C ... do so over an integer number of periods
296
C ... compensate for a slope in the input data by averaging over
297
C ... one cycle of 20 pixels each
299
START = 20*INT((RANGE(1)-1.)/PERIOD) + 1 ! phase offset due to zeropoint used
300
OFF = 20*INT((RANGE(1)-1.)/PERIOD) + 1 - START
301
END = 20*INT((RANGE(2)-1.)/PERIOD) + 1
302
DO 60 I = START,END,20
305
MEAN = MEAN + SCRAT(I+J-1)
309
C BIN = JMOD(I+J-1+OFF,20) + 1
310
BIN = MOD(I+J-1+OFF,20) + 1
311
SUM(BIN) = SUM(BIN) + SCRAT(I+J-1)/MEAN
315
C ... division into mean value yields the relative amplitudes of
334
SUBROUTINE RRIPC(IN,NPIX,PERIOD,RANGE,AMP,SCRAT,SCNPIX,OUT)
337
INTEGER RANGE(2),NPIX,SCNPIX,I,J,BIN,PIXLO,PIXHI
338
REAL IN(1),OUT(1),PERIOD,AMP(500),XLO,XHI,FRACLO,FRACHI,
341
DO 10 I = 1,NPIX ! initialize output frame to zero
345
C ... here the amplitude correction is done
348
C BIN = JMOD(I,20) + 1
350
SCRAT(I) = SCRAT(I)*AMP(BIN)
353
C ... finally rebin to step = 1 (as in the input frame)
354
C ... the algorithm is a pure projection, no interpolation is done
355
C ... (since the origin and nature of the ripple are not known)
362
PIXHI = INT(XHI) ! all into one output pixel
363
IF ((PIXHI-PIXLO).EQ.0) THEN
365
OUT(I) = OUT(I) + FRACLO*SCRAT(PIXLO) ! at least two output pixels hit
367
FRACLO = PIXLO + 1 - XLO
369
OUT(I) = OUT(I) + FRACLO*SCRAT(PIXLO) +
370
+ FRACHI*SCRAT(PIXHI) ! if in fact more than two hit
371
DO 30 J = PIXLO + 1,PIXHI - 1
372
OUT(I) = OUT(I) + SCRAT(J)