~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/proc/pipeline/set_of_frames.prg

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
! @(#)set_of_frames.prg 19.1 (ESO-DMD) 02/25/03 14:10:54
 
2
! ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
3
!
 
4
! MIDAS procedure set_of_frames.prg for NTT/VLT pipeline
 
5
! K. Banse      970121, 971212, 981125, 990531, 000427, 010903
 
6
!
 
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
 
10
 
11
! use via:  @d set_of_frames p1 p2 p3 p4
 
12
 
13
! p1 = IN or OUT for Input or Output
 
14
! if p1 = IN
 
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
 
20
!
 
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
 
24
!
 
25
! if p1 = OUT
 
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
 
35
!        of products
 
36
 
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
! ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
44
!
 
45
define/param p1 IN c "Enter IN or OUT for Input/Output from/to FITS:"
 
46
!
 
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...
 
52
 
53
! **************
 
54
! here for Input
 
55
!
 
56
! **************
 
57
if p1(1:1) .eq. "I" then
 
58
   set/format i1
 
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
 
64
   ! 
 
65
   if p3(1:1) .ne. "+" then
 
66
      inputi = m$index(p3,",a") 
 
67
      if inputi .lt. 2 inputi = m$index(p3,",A") 
 
68
      if inputi .lt. 2 then
 
69
         define/local catname/c/1/80 {p3} ? +lower
 
70
         create/icat {catname} NULL DO_CLASSIFICATION >Null
 
71
      else
 
72
         define/local catname/c/1/80 " " all +lower
 
73
         inputi = inputi - 1
 
74
         write/keyw catname/c/1/{inputi} {p3}
 
75
      endif
 
76
      catflag(1) = 1
 
77
   endif
 
78
   ! 
 
79
   open/file {p2} READ fc
 
80
   if fc(1) .lt. 0 then
 
81
      write/out Could not open input/reference SetOfFrames {p2} ...
 
82
      outputi(1) = -1
 
83
      return
 
84
   endif
 
85
   ! 
 
86
   ! read from SOF and convert or just list the entries
 
87
   ! 
 
88
   @d sofaux,readin {p4}
 
89
   close/file {fc(1)}
 
90
   outputi(1) = catflag(2)                      !set OUTPUTI(1) to no. of frames
 
91
!
 
92
! ***************
 
93
! here for Output
 
94
 
95
! ***************
 
96
else
 
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:"
 
99
   ! 
 
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
 
109
   set/format i4
 
110
   ! 
 
111
   write/out 
 
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}
 
117
      endif
 
118
   endif
 
119
   !
 
120
   k(1) = m$indexb(p2,".cat")           !check, if catalog
 
121
   if k(1) .lt. 2 then                          !No, single frame
 
122
      write/keyw work {p2}
 
123
      write/keyw fname {p3}
 
124
      goto process_result
 
125
   ! 
 
126
   else                                         !Yes, so p3 must be a SoF
 
127
      loco(2) = 1
 
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
 
133
         endif
 
134
      endif
 
135
      !
 
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)}
 
141
         catal = 0
 
142
         goto process_result
 
143
      else
 
144
         goto cata_loop
 
145
      endif
 
146
     fin_a:
 
147
      catal = 0
 
148
      ! 
 
149
     catal_read_loop:
 
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)}
 
153
      goto process_result
 
154
      !
 
155
      finito:                                   !end of catalog reached
 
156
      outputi(1) = loco
 
157
      goto end_of_it
 
158
   endif
 
159
   ! 
 
160
   ! here we handle a single result frame
 
161
   ! 
 
162
  process_result:
 
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
 
169
   ! 
 
170
   else
 
171
      k(1) = m$ftset(work)                      !test for filetype
 
172
      if k(1) .eq. 1 then
 
173
         k(1) = m$indexb(work,".")
 
174
         write/keyw ftype/c/1/6 {work({k(1)}:)}
 
175
      else
 
176
         write/keyw ftype/c/1/6 ".dat  "
 
177
      endif
 
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...!
 
181
         outputi(2) = -3
 
182
         goto error_out
 
183
      else
 
184
         write/out {work} => file: {inn_a}
 
185
         if fout(1) .gt. 0 then
 
186
            write/file {fout} {work} {inn_a}
 
187
         endif
 
188
         goto end_test                          !look for next file
 
189
      endif
 
190
   endif
 
191
   !
 
192
   k(1) = m$indexb(fname,"/")+1                 !look for output file path
 
193
   write/keyw fbase/c/1/60 "{fname({k(1)}:)} "
 
194
   ! 
 
195
   k(1) = m$len(fname)                          !look for output file type
 
196
   if k .gt. 5 then
 
197
      k(2) = k(1)-4
 
198
      if fname({k(2)}:{k(1)}) .eq. ".fits" then
 
199
         write/keyw ftype/c/1/6 "      "        !we already have a file type
 
200
      elseif k .gt. 6 then
 
201
         k(2) = k(1)-5
 
202
         if fname({k(2)}:{k(1)}) .eq. ".tfits" write/keyw ftype/c/1/6 "      "  
 
203
      endif
 
204
   endif
 
205
   !
 
206
   write/keyw inn_a/c/1/100 "{fname}{ftype} "
 
207
   ! 
 
208
   ! 
 
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
 
211
      outputi(2) = -1
 
212
      goto error_out
 
213
   endif
 
214
   ! 
 
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
 
221
   endif
 
222
   outputi(2) = -4
 
223
   delete/descr {work} origfile no              !don't stop, if descr not there
 
224
   write/keyw outputi/i/1/2 -9999,-5
 
225
   !
 
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
 
232
   else
 
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 
 
236
   endif
 
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...
 
241
         $ chmod a+w {inn_a}
 
242
      else
 
243
         if fout(1) .gt. 0 write/file {fout} {work} NOT converted...
 
244
         ! 
 
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)}:)} ..."
 
248
         outputi(2) = -2
 
249
         goto error_out
 
250
      endif
 
251
   endif
 
252
   if fout(1) .gt. 0 then
 
253
      write/file {fout} {work} {inn_a}
 
254
   endif
 
255
   !
 
256
   if work .eq. p4 then                 !display major product
 
257
      @d sofaux,resdisp
 
258
   endif
 
259
   !
 
260
   -rename simple_fits.fits {inn_a}
 
261
   if m$exist(inn_a) .eq. 0 then                !renaming/moving failed...!
 
262
      outputi(2) = -3
 
263
      goto error_out
 
264
   endif
 
265
   ! 
 
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
 
271
   endif
 
272
   !
 
273
  end_test:
 
274
   if loco(2) .eq. 0 then
 
275
      outputi(1) = 1
 
276
      goto end_of_it
 
277
   else
 
278
      loco = loco+1
 
279
      pipeline(3) = pipeline(3)+1
 
280
      goto catal_read_loop
 
281
   endif
 
282
   ! 
 
283
  error_out:
 
284
   outputi(1) = -(loco+1)               !indicate frame no. where it failed
 
285
   ! 
 
286
  end_of_it:
 
287
   if fout(1) .gt. 0 close/file {fout}
 
288
endif