Debian Codegraph @

stdred/ccdred/proc/ccdreduce.prg

raw
1 ! @(#)ccdreduce.prg 19.1 (ESO-DMD) 02/25/03 14:16:01
2 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 !.COPYRIGHT (C) 1993 European Southern Observatory
4 !.IDENT ccdreduce.prg
5 !.AUTHOR Rein H. Warmels, ESO-Garching
6 !.KEYWORDS Direct imaging, CCD package, REDUCE/CCD
7 !.PURPOSE Do the reduction of an single science image or a series of
8 ! science frames stored in a MIDAS table.
9 !.USE REDUCE/CCD p1 p2
10 !. where p1 = input table of science frames or single frame
11 !. p2 = output frame (only in case of single frame input)
12 !.ALGORYTHM: The procedure checks for the valid input and continues with
13 !. the pipeline reduction. In case a single frame input is given
14 !. calibration frames are taken for the CCD keywords exp_FRM;
15 !. for the reduction of the science frames stored in a MIDAS
16 !. table the calibration frames are assumed to be available in this
17 ! table.
18 !. Each single frame is reduced in the procedure ccdredfrm.
19 !.NOTE The individual procedures check if one operation was already done
20 !. by checking the descriptor CCDSTAT. The CCDSTAT descriptor values
21 !. represent the following status:
22 !. CCDSTAT(1) for overscan correction
23 !. CCDSTAT(2) for trimming the frame
24 !. CCDSTAT(3) for bad pixel correction
25 !. CCDSTAT(4) for bias subtraction
26 !. CCDSTAT(5) for dark current subtraction
27 !. CCDSTAT(6) for flat fielding
28 !. CCDSTAT(7) for bad pixel correction
29 !. CCDSTAT(8) for fringing correction
30 !.VERSION: 920731 RHW Creation
31 !.VERSION: 930728 RHW Improve layout and structure
32 !.VERSION: 940113 RHW Change for the DO association table
33 !-------------------------------------------------------
34 DEFINE/PARAM P1 {CCD_IN} C "Enter CCD input table or frame:"
35 DEFINE/PARAM P3 N C "Overwrite existing reduced output frame"
36 !
37 ! *** keyword saving
38 DEFINE/LOCAL CCDIN/C/1/60 " " ALL
39 DEFINE/LOCAL CCDOUT/C/1/60 " " ALL
40 DEFINE/LOCAL CCDTBL/C/1/60 "{CCD_IN}"
41 DEFINE/LOCAL BSFRM/C/1/60 "{SC_BSFRM}"
42 DEFINE/LOCAL DKFRM/C/1/60 "{SC_DKFRM}"
43 DEFINE/LOCAL FFFRM/C/1/60 "{SC_FFFRM}"
44 DEFINE/LOCAL ILFRM/C/1/60 "{SC_ILFRM}"
45 DEFINE/LOCAL FRFRM/C/1/60 "{SC_FRFRM}"
46 !
47 DEFINE/LOCAL TBL/I/1/1 0
48 DEFINE/LOCAL TABL/C/1/60 " " ALL
49 DEFINE/LOCAL SELECT/C/1/60 " " ALL
50 DEFINE/LOCAL NCA/I/1/1 0
51 DEFINE/LOCAL NRA/I/1/1 0
52 DEFINE/LOCAL IRA/I/1/1 0
53 DEFINE/LOCAL IDOT/I/1/1 0
54 !
55 CCDCMD = "REDUCE/CCD" ! store the command and keywords
56 !
57 ! *** first check for single frame of input table
58 TBL = M$INDEX(P1,".tbl") ! search for .bdf
59 IF TBL .EQ. 0 THEN ! frame input
60 IF M$EXIST("{P1}.bdf") .EQ. 0 THEN ! check existence
61 WRITE/OUT "*** FATAL: Missing CCD input frame {P1}"
62 RETURN
63 ELSE
64 CCDIN = "{P1}"
65 ENDIF
66
67 ELSE ! reduction table input
68 IF M$EXIST(P1) .EQ. 0 THEN ! check exsistence
69 WRITE/OUT "*** FATAL: Missing CCD input table {P1}"
70 RETURN
71 ELSE
72 CCD_IN = "{P1}"
73 CCDIN = "{CCD_IN}"
74 SELECT = "{{CCDIN},TSELTABL(1:60)}"
75 IF SELECT(1:1) .NE. " " .AND. SELECT .NE. "-" THEN
76 TABL = "middummtbl.tbl"
77 COPY/TABLE {P1} {TABL} ! copy only selected part
78 ELSE
79 TABL = "{CCDIN}"
80 ENDIF
81
82 SET/FORMAT I3
83 NCA = {{TABL},TBLCONTR(3)}
84 NRA = {{TABL},TBLCONTR(4)} ! check number of rows
85 IF NRA .EQ. 0 THEN
86 GOTO DONE
87 ENDIF
88 ENDIF
89 !
90 ! *** collect the input/output science frame and calibration frames
91 WRITE/OUT "Start processing science frames in table {P1}"
92 IRA = 0
93 NXTFRM:
94 IRA = IRA + 1
95 CCDIN = "{{TABL},:{SC_COL},@{IRA}}" ! get input image name
96 WRITE/OUT " "
97 !
98 IF SC_BSCOR(1:1) .EQ. "y" THEN ! bias correc. wanted?
99 IF M$EXISTC(TABL,BS_COL) .EQ. -1 THEN
100 WRITE/OUT "*** FATAL: No BIAS column defined; *** REDUCTION STOPPED"
101 GOTO FINISH
102 ELSE
103 SET/MIDAS OUTPUT=LOGONLY
104 SC_BSFRM = "{{TABL},:{BS_COL},@{IRA}}"
105 SET/MIDAS OUTPUT=YES
106 IF SC_BSFRM(1:1) .EQ. " " THEN
107 WRITE/OUT "{CCDIN}: No master BIAS defined; ** NO REDUCTION ***"
108 GOTO DONE
109 ENDIF
110 ENDIF
111 ENDIF
112 !
113 IF SC_DKCOR(1:1) .EQ. "y" THEN ! dark correc. wanted?
114 IF M$EXISTC(TABL,DK_COL) .EQ. -1 THEN
115 WRITE/OUT "*** FATAL: No DARK column defined; *** REDUCTION STOPPED"
116 GOTO FINISH
117 ELSE
118 SET/MIDAS OUTPUT=LOGONLY
119 SC_DKFRM = "{{TABL},:{DK_COL},@{IRA}}"
120 SET/MIDAS OUTPUT=YES
121 IF SC_DKFRM(1:1) .EQ. " " THEN
122 WRITE/OUT "{CCDIN}: No master DARK defined; *** NO REDUCTION ***"
123 GOTO DONE
124 ENDIF
125 ENDIF
126 ENDIF
127 !
128 IF SC_FFCOR(1:1) .EQ. "y" THEN ! flat correc. wanted?
129 IF M$EXISTC(TABL,FF_COL) .EQ. -1 THEN
130 WRITE/OUT -
131 "*** FATAL: No FLAT column defined; *** REDUCTION STOPPED ***"
132 GOTO FINISH
133 ELSE
134 SET/MIDAS OUTPUT=LOGONLY
135 SC_FFFRM = "{{TABL},:{FF_COL},@{IRA}}"
136 SET/MIDAS OUTPUT=YES
137 IF SC_FFFRM(1:1) .EQ. " " THEN
138 WRITE/OUT "{CCDIN}: No master FLAT defined; NO REDUCTION ***"
139 GOTO DONE
140 ENDIF
141 ENDIF
142 ENDIF
143 !
144 IF SC_ILCOR(1:1) .EQ. "y" THEN ! ill correc. wanted?
145 IF M$EXISTC(TABL,IL_COL) .EQ. -1 THEN
146 WRITE/OUT -
147 "*** FATAL: No ILLUMINATION column defined; *** REDUCTION STOPPED"
148 GOTO FINISH
149 ELSE
150 SET/MIDAS OUTPUT=LOGONLY
151 SC_ILFRM = "{{TABL},:{IL_COL},@{IRA}}"
152 SET/MIDAS OUTPUT=YES
153 IF SC_ILFRM(1:1) .EQ. " " THEN
154 WRITE/OUT -
155 "{CCDIN}: No master ILLUMINATION defined; NO REDUCTION ***"
156 GOTO DONE
157 ENDIF
158 ENDIF
159 ENDIF
160
161 IF SC_FRCOR(1:1) .EQ. "y" THEN ! fringe correc. wanted?
162 IF M$EXISTC(TABL,FR_COL) .EQ. -1 THEN
163 WRITE/OUT "*** FATAL: No FRINGE column defined; *** REDUCTION STOPPED"
164 GOTO FINISH
165 ELSE
166 SET/MIDAS OUTPUT=LOGONLY
167 SC_FRFRM = "{{TABL},:{FR_COL},@{IRA}}"
168 SET/MIDAS OUTPUT=YES
169 IF SC_FRFRM(1:1) .EQ. " " THEN
170 WRITE/OUT "{CCDIN}: No master FRINGE defined; NO REDUCTION ***"
171 GOTO DONE
172 ENDIF
173 ENDIF
174 ENDIF
175 ENDIF
176 !
177 ! *** get the input data either a single frame input or from the table
178 IDOT = M$INDEX(CCDIN,".") - 1
179 IF IDOT .GT. 0 THEN
180 CCDIN = "{CCDIN(1:{IDOT})}"
181 ELSE
182 CCDIN = "{CCDIN}"
183 ENDIF
184
185 IF TBL .GT. 0 THEN
186 SET/MIDAS OUTPUT=LOGONLY
187 SELECT/TABL {TABL} :{SC_COL}.EQ."{CCDIN}.mt".OR. :{SC_COL}.EQ."{CCDIN}.bdf"
188 SET/MIDAS OUTPUT=YES
189 ENDIF
190
191 IF M$EXIST("{CCDIN}.bdf") .EQ. 0 THEN ! check exsistence
192 WRITE/OUT "*** WARNING: Missing input frame {CCDIN}; *** NO REDUCTION"
193 GOTO DONE
194 ENDIF
195 !
196 ! *** determine the output frame
197 IF TBL .EQ. 0 THEN
198 DEFINE/PARAM P2 "{CCDIN}_red" IMA "Enter the calibrated output frame:"
199 CCDOUT = "{P2}"
200 ELSE
201 CCDOUT = "{CCDIN}_reduc" ! reduce output image name
202 ENDIF
203 IDOT = M$INDEX(CCDOUT,".") - 1
204 IF IDOT .GT. 0 THEN
205 CCDOUT = "{CCDOUT(1:{IDOT})}"
206 ELSE
207 CCDOUT = "{CCDOUT}"
208 ENDIF
209 !
210 IF M$EXIST("{CCDOUT}.bdf") .EQ. 1 .AND. P3 .EQ. "N" THEN ! find if output exists
211 WRITE/OUT "{CCDIN}: Reduced frame {CCDOUT} already exist *** NO REDUCTION"
212 ELSE
213 @s ccdredfrm {CCDIN} {CCDOUT}
214 WRITE/OUT " "
215 if {Q1} .lt. 0 then
216 write/out "{CCDIN}: ERROR - Reduction failed!"
217 goto FINISH
218 endif
219 ENDIF
220 !
221 ! *** done for this frame
222 DONE:
223 IF TBL .EQ. 0 THEN
224 WRITE/OUT "*** ALL DONE *** Reduction frame {P1} *** ALL DONE ***"
225 ELSE
226 IF IRA .LT. {NRA} THEN
227 GOTO NXTFRM
228 ELSE
229 WRITE/OUT " "
230 IF NRA .EQ. 0 THEN
231 WRITE/OUT "*** WARNING: Selection in input table is empty *** ALL DONE ***"
232 ELSE
233 WRITE/OUT "*** ALL DONE *** Input table {P1} *** ALL DONE ***"
234 ENDIF
235 SET/MIDAS OUTPUT=LOGONLY
236 IF SELECT(1:1) .NE. " " .AND. SELECT .NE. "-" THEN
237 SELECT/TABL {P1} {SELECT} ! reset selection
238 ELSE
239 SELECT/TABL {P1} ALL ! ALL selection
240 ENDIF
241 SET/MIDAS OUTPUT=YES
242 DELETE/TABLE middummtbl.tbl NO
243 ENDIF
244 ENDIF
245 !
246 ! *** done for all
247 FINISH:
248 ! *** restore keyword setting
249 CCD_IN = "{CCDTBL}"
250 SC_BSFRM = "{BSFRM}"
251 SC_DKFRM = "{DKFRM}"
252 SC_FFFRM = "{FFFRM}"
253 SC_ILFRM = "{ILFRM}"
254 SC_FRFRM = "{FRFRM}"
255 RETURN
256
257
258
259