1
! @(#)set_of_frames.prg 19.1 (ESO-DMD) 02/25/03 14:10:54
2
! ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
! MIDAS procedure set_of_frames.prg for NTT/VLT pipeline
5
! K. Banse 970121, 971212, 981125, 990531, 000427, 010903
7
! a) move a list of frames into local storage as input/reference data
8
! b) move single result frame or catalog of result frames out to Products-dir.
9
! and provide a link to it in $DHS_DATA so Archive knows about it
11
! use via: @d set_of_frames p1 p2 p3 p4
13
! p1 = IN or OUT for Input or Output
15
! convert (or just list) all frames given in an ASCII Set of Frames (SoF)
16
! if catalog name is given all files are named `simpe_name_#' and
17
! entered in that catalog
18
! on return OUTPUTI(1) = no. of input/reference frames processed
19
! = -1 if we couldn't read the SoF
21
! p2 = ASCII file with names of frames
22
! p3 = optional catalog name or catalog,app (for appending to exist. catal)
23
! p4 = Convert or List all frames in SoF, default = CONV
26
! p2 = result frame name (as in current work_dir)
27
! or name of catalog with result frame names (xyz.cat)
28
! p3 = complete output basename
29
! depending upon p2, either basename + extension `.fits' is used to
30
! construct a single result frame
31
! or basename_xy + extension `.fits' (xy in [00,99]) is used to
32
! construct a series of result frames
33
! p4 = name of result frame which should be stored in the archive
34
! p5 = name of ASCII file which will be filled with original + output names
37
! on return OUTPUTI(1) = no. of result frames processed
38
! OUTPUTI(1) = -9999, if procedure failed somehow
39
! OUTPUTI(1) = n (n < 0) indicates a problem working on the nth frame
40
! if OUTPUTI(1) < 0 then OUTPUTI(2) specifies the error more:
41
! -1 = aux. descr. list, -2 = overwrite, -3 = move to Product_Dir.
42
! -4 = delete/descr, -5 = copy/ad
43
! ++++++++++++++++++++++++++++++++++++++++++++++++++++++
45
define/param p1 IN c "Enter IN or OUT for Input/Output from/to FITS:"
47
define/local k/i/1/5 0,0,0,0,0 ? +lower
48
define/local fc/i/1/2 0,0 ? +lower
49
define/local fname/c/1/128 " " all +lower
50
write/keyw base_name/c/1/128 " " all +lower
51
write/keyw outputi/i/1/2 -9999,-9 !in case `set_of_frames' fails...
57
if p1(1:1) .eq. "I" then
59
define/param p2 ? c "Enter SetofFrames (ASCII) file:"
60
define/param p3 + c "Enter catalog name:"
61
define/param p4 CONV c "Enter action:"
62
define/local classif/c/1/32 " " all +lower
63
define/local catflag/i/1/2 0,0 ? +lower
65
if p3(1:1) .ne. "+" then
66
inputi = m$index(p3,",a")
67
if inputi .lt. 2 inputi = m$index(p3,",A")
69
define/local catname/c/1/80 {p3} ? +lower
70
create/icat {catname} NULL DO_CLASSIFICATION >Null
72
define/local catname/c/1/80 " " all +lower
74
write/keyw catname/c/1/{inputi} {p3}
79
open/file {p2} READ fc
81
write/out Could not open input/reference SetOfFrames {p2} ...
86
! read from SOF and convert or just list the entries
90
outputi(1) = catflag(2) !set OUTPUTI(1) to no. of frames
97
define/param p4 + c "Enter name of frame for the archive:"
98
define/param p5 + c "Enter name of ASCII file for file names:"
100
define/local linkflag/i/1/1 {pipeline(8)} !check, if DHS_DATA is defined
101
if linkflag .ne. 0 linkflag = 99 !do the 'ln' stuff
102
define/local loco/i/1/3 0,0,-1
103
define/local work/c/1/100 " " all
104
define/local ftype/c/1/6 ".fits " ? +lower
105
define/local fbase/c/1/60 "{fname} "
106
define/local inn_a/c/1/100 " " all +lower
107
define/local fout/i/1/2 -1,-1
108
define/local mft/i/1/1 0
112
if p5(1:1) .ne. "+" then
113
define/local reco/c/1/200 " " all
114
open/file {p5} write fout
115
if fout(1) .le. 0 then
116
write/out "Could not create ASCII file:" {p5}
120
k(1) = m$indexb(p2,".cat") !check, if catalog
121
if k(1) .lt. 2 then !No, single frame
123
write/keyw fname {p3}
126
else !Yes, so p3 must be a SoF
128
define/local catal/i/1/1 0 !catalog control flag
129
write/keyw base_name {p3}
130
if linkflag .ne. 0 then
131
if pipeline(9) .eq. 1 .and. p4(1:1) .ne. "+" then
132
linkflag = 9 !if we're ON_LINE + have unique result frame
136
cata_loop: !loop through catalog to find
137
store/frame work {p2} 1 fin_a !unique product file
138
if work .eq. p4 then !make product the first out
139
loco(3) = catal !save index in catalog
140
write/keyw fname {base_name}_{pipeline(3)}
150
store/frame work {p2} 1 finito
151
if loco(3) .eq. catal goto catal_read_loop !product already done
152
write/keyw fname {base_name}_{pipeline(3)}
155
finito: !end of catalog reached
160
! here we handle a single result frame
163
! prepare file for `write/decr'
164
mft = m$filtyp(work,".bdf")
165
if mft .eq. 2 then !check type of input file
166
write/keyw ftype/c/1/6 ".tfits" !it's a table
167
else if mft .eq. 1 then
168
write/keyw ftype/c/1/6 ".fits " !it's an image
171
k(1) = m$ftset(work) !test for filetype
173
k(1) = m$indexb(work,".")
174
write/keyw ftype/c/1/6 {work({k(1)}:)}
176
write/keyw ftype/c/1/6 ".dat "
178
write/keyw inn_a/c/1/100 "{fname}{ftype} "
179
-rename {work} {inn_a}
180
if m$exist(inn_a) .eq. 0 then !renaming/moving failed...!
184
write/out {work} => file: {inn_a}
185
if fout(1) .gt. 0 then
186
write/file {fout} {work} {inn_a}
188
goto end_test !look for next file
192
k(1) = m$indexb(fname,"/")+1 !look for output file path
193
write/keyw fbase/c/1/60 "{fname({k(1)}:)} "
195
k(1) = m$len(fname) !look for output file type
198
if fname({k(2)}:{k(1)}) .eq. ".fits" then
199
write/keyw ftype/c/1/6 " " !we already have a file type
202
if fname({k(2)}:{k(1)}) .eq. ".tfits" write/keyw ftype/c/1/6 " "
206
write/keyw inn_a/c/1/100 "{fname}{ftype} "
209
@d sofaux,descfile kuki.dat !build ASCII file "kuki.dat"
210
if q1(1:2) .ne. "OK" then !for all the `write/descr' commands
215
write/descr {work} <kuki.dat
216
if m$existd(work,"arcfile") .eq. 1 then
217
copy/dd {work} arcfile {work} eso.pro.arcfile
218
write/descr {work} eso.pro.arcfile/h/1/40 -
219
"Archive filename of raw data frame "
220
delete/descr {work} arcfile
223
delete/descr {work} origfile no !don't stop, if descr not there
224
write/keyw outputi/i/1/2 -9999,-5
226
if ftype(2:2) .eq. "t" then !is it a table file?
227
create/image empty 0 ? no !Yes.
228
copy/dd {work} *,5 empty !copy all descr's
229
copy/ad {rbname} empty redblock 48
230
write/desc empty datamd5/c/1/32 " "
231
outdisk/sfits empty.bdf,{work} simple_fits.fits !convert to single FITS
233
copy/ad {rbname} {work} redblock 48
234
write/desc {work} datamd5/c/1/32 " "
235
outdisk/sfits {work} simple_fits.fits !convert to single FITS
237
compute/signature simple_fits.fits >Null !calculcate MD5 signature
238
! products should not be overwritten...
239
if m$exist(inn_a) .ne. 0 then !product exists already
240
if pipeline(11) .eq. 1 then !we shall overwrite...
243
if fout(1) .gt. 0 write/file {fout} {work} NOT converted...
245
write/out {inn_a} already exists - we stop!
246
k(1) = m$indexb(inn_a,"/")+1 !skip path specs
247
write/keyw mid$errmess "cannot overwrite product: {inn_a({k(1)}:)} ..."
252
if fout(1) .gt. 0 then
253
write/file {fout} {work} {inn_a}
256
if work .eq. p4 then !display major product
260
-rename simple_fits.fits {inn_a}
261
if m$exist(inn_a) .eq. 0 then !renaming/moving failed...!
266
write/out {work} => FITS file: {inn_a}
267
if linkflag .ne. 0 then !DFS_DATA_REDUCED_OLAS is set
268
write/out *** and is also linked to the Archive ***
269
$sh $MID_PROC/pipeline/DHSlink.sh {inn_a} {fbase}{ftype}
270
if linkflag .ne. 99 linkflag = 0 !link in only 1 result frame
274
if loco(2) .eq. 0 then
279
pipeline(3) = pipeline(3)+1
284
outputi(1) = -(loco+1) !indicate frame no. where it failed
287
if fout(1) .gt. 0 close/file {fout}