PRO Applog, msg openw, unit, 'Reko_Log', /append, /get print, msg printf, unit, msg free_lun, unit END FUNCTION Maketime, jultime, DATE=date caldat, jultime, month, day, year, hrs, mins, secs secs = fix(secs+.5) IF secs EQ 60 THEN BEGIN secs = 0 mins = mins+1 IF mins EQ 60 THEN BEGIN mins = 0 hrs = hrs+1 ENDIF ENDIF IF keyword_set(date) THEN $ return, nnumber(year, 4)+nnumber(month, 2)+nnumber(day, 2) $ ELSE $ return, nnumber(hrs, 2)+nnumber(mins, 2)+nnumber(secs, 2) END PRO Waitforfinish, num n_comps = 12 print, 'Entering wait loop' ;;; Check the current status of the reko. If neccessary, ;;; spawn an additional IDL to help doing the reko spawn, 'cat Reko/results/seq', seq IF fix(seq(0)) LT 0.94*num THEN $ spawn, 'cd Reko; nohup /opt/rsi/idl/bin/idl ../dosp &' ;;; wait for the last parts to finish FOR nc=2*n_comps, 1, -1 DO BEGIN nnc = strtrim(num-nc+1, 2) WHILE ((f=(findfile('Reko/results/teilbild'+nnc))(0) EQ '')) $ DO wait, 1 ENDFOR ;;; check that *all* are there f=findfile('Reko/results/teilbild*', count=nf) IF nf NE num THEN BEGIN cmd = 'for i in `seq -w '+strtrim(num, 2)+'`'+ $ '; do [ -f Reko/results/teilbild$i ] || echo $i ; done' spawn, cmd, missing cd, 'Reko', current=olddir sp_mask, init_variables('allvars.dat'), missing cd, olddir ENDIF spawn, 'sync' END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Main program starts here close, /all ;;; Create neccessary directories IF NOT file_test('FITS', /dir) THEN spawn, 'mkdir FITS' IF NOT file_test('Tars', /dir) THEN spawn, 'mkdir Tars' IF NOT file_test('flat+noise', /dir) THEN spawn, 'mkdir flat+noise' IF NOT file_test('tmpdir', /dir) THEN spawn, 'mkdir tmpdir' IF NOT file_test('Reko', /dir) THEN spawn, 'mkdir Reko' spawn,'ln -sf ../flat+noise Reko/' ;;; These variables have to be defined for each burst series. ;;; Cams(0) is used as 'master', and it is assumed that for each file ;;; in there, there is a pendant in the Cams(i) directory with the ;;; sequential number not further off than +/- 2 ;;; Id defines the wavelength of the camera ;;; Naming conventions: ;;; Target-ch12345-yyyymmdd-hhmmss. ;;; e.g., AR8704-gb-0000-19991020-081730.fits ;;; AR8704-ca-2140-19991020-081730.fits ;;; AR8704-ha+0250-19991020-081730.fits base = 'SunScan' fs = '-' Cams = ['C1', 'C2', 'C3', 'C4'] Id = ['ca', 'gb', 'bc', 'rc'] ;;; example for 2 Ca-positions with different extensions ;pext = [['', '', '', '1'], ['', '', '', '2']] ;npmo = 2 ;;; example for 'normal' use pext = ['', '', '', ''] npmo = 1 pmod = 0 lam = ['-0000', '-0000', '-0000', '-0000'] ;;; Fucking Cams are not linear! Try to compensate ;;; no measured values for this day - use those of July 13 gamm = [[0., 0.], [0., 0.], [0.089, 414.], [0.057, 170.]] ;;; Decide if subimage tracking should be done notrack = 0 ;;; Define and fill the control structure filreg = 'RAW/'+Cams(0)+'/SUN*' files = findfile(filreg) fdat = long(strmid(files, 16, 10)) num = n_elements(fdat) n_cams = n_elements(Cams) ntot = num*n_cams Burstinfo = replicate({ raw: 'dummy', $ Id: 'ch', $ parfile: 'dummy', $ Jultime: 1d0, $ Date: 'dummy', $ Tim: 'dummy', $ Name: 'dummy', $ Gamma: [1., 0.] }, ntot) FOR i=0, num-1 DO BEGIN ix = i*n_cams Burstinfo[ix].raw = files(i) ;;; The timestamps of the other cameras can be off by a few ;;; seconds. Look for them. FOR j=1, n_cams-1 DO BEGIN fn = (findfile('RAW/'+Cams(j)+'/SUNPROBE-'+ $ strtrim(fdat(i), 2)+'-F*'))(0) IF fn EQ '' THEN BEGIN FOR dt=-2, 2 DO BEGIN tfn = findfile('RAW/'+Cams(j)+'/SUNPROBE-'+ $ strtrim(fdat(i)+dt, 2)+'-F*') IF tfn(0) NE '' THEN fn = tfn(0) ENDFOR ENDIF IF fn EQ '' THEN stop Burstinfo[ix+j].raw = fn ENDFOR Burstinfo[ix:ix+n_cams-1].jultime = fdat(i)/86400d0+2440587.5 Burstinfo[ix:ix+n_cams-1].tim = maketime(Burstinfo[ix].jultime) Burstinfo[ix:ix+n_cams-1].date = maketime(Burstinfo[ix].jultime, /DATE) FOR j=0, n_cams-1 DO BEGIN Burstinfo[ix+j].id = id(j) Burstinfo[ix+j].parfile = 'Par/allvars_'+id(j)+pext(j, pmod)+'.dat' Burstinfo[ix+j].name=base+fs+id(j)+lam(j)+fs+ $ Burstinfo[ix+j].date+fs+Burstinfo[ix+j].tim+'.fits' Burstinfo[ix+j].gamma = gamm(*, j) ENDFOR pmod = (pmod +1) MOD npmo ENDFOR stop db = 0 ;;; bursts already done - for correct counting in logfile ;;; Loop N preprocesses burst N+1, starts reko of burst N+1 and ;;; connects burst N ;;; Therefore, special care has to be taken for the first and the ;;; last loop. start = 0 ;GOTO, weiter spawn, 'cp '+Burstinfo(start).parfile+' allvars.dat' sps = init_variables('allvars.dat') n_ok = write_rawdata(Burstinfo(start).raw, sps.N_Image, $ gamma=Burstinfo(start).gamma) IF n_ok NE sps.N_Image THEN BEGIN applog, 'Burst '+strtrim(start+db, 2)+ $ ': Dropout in data, N_Image reduced to '+strtrim(N_ok, 2) sps.N_Image = N_ok write_parfile, 'allvars.dat', sps ENDIF IF (db EQ 0) AND (start LT n_cams) THEN $ pre_speckle, sps, /INMEM, NO_TRACK=notrack $ ELSE $ pre_speckle, sps, /INMEM, /NO_FLATGEN, /SKIP_NOISE, NO_TRACK=notrack Weiter: spawn, 'mv results support allvars.dat Reko/' spawn, '(touch Reko/startreko; sleep 60; rm Reko/startreko)&' spawn, 'rm -f raw/rawdata' FOR burst=start, ntot-1 DO BEGIN ;;; check for special connection sequence. In the loop so it ;;; can be changed while running. IF file_test('queue.save') THEN restore, 'queue.save' ELSE queue = 0b ;;; Preprocess the next burst (unless this is the last loop) IF burst LT ntot-1 THEN BEGIN b1 = burst+1 spawn, 'cp '+Burstinfo(b1).parfile+' allvars.dat' sps = init_variables('allvars.dat') n_ok = write_rawdata(Burstinfo(b1).raw, sps.N_Image, $ gamma=Burstinfo(b1).gamma) IF n_ok NE sps.N_Image THEN BEGIN applog, 'Burst '+strtrim(b1+db, 2)+ $ ': Dropout in data, N_Image reduced to '+strtrim(N_ok, 2) sps.N_Image = N_ok write_parfile, 'allvars.dat', sps ENDIF ;;; the first burst for each camera has to create summed ;;; dark, flat and noise IF b1+db LT n_cams THEN $ pre_speckle, sps, /INMEM, NO_TRACK=notrack $ ELSE $ pre_speckle, sps, /INMEM, /NO_FLATGEN, /SKIP_NOISE, NO_TRACK=notrack ENDIF ;;; Now we have to wait until the previous reconstruction is ;;; finished. waitforfinish, sps.S_n ;;; switch directories and start Reko IF burst LT ntot-1 THEN BEGIN spawn, 'mv results support allvars.dat tmpdir/' spawn, 'mv Reko/allvars.dat Reko/results Reko/support .' spawn, 'mv tmpdir/* Reko/ ; sleep 10; sync' spawn, '(touch Reko/startreko; sleep 60; rm Reko/startreko)&' spawn, 'rm raw/rawdata' ENDIF ELSE BEGIN spawn, 'mv Reko/allvars.dat Reko/results Reko/support .' ENDELSE ;;; now we are working with the data of series 'burst'. ;;; first, start the Backup cmd = '( touch tar_running ; tar cfz Tars/'+ $ Burstinfo(burst).tim+fs+Burstinfo(burst).id+'.tgz '+ $ 'results/schrittweite results/teilbild* support/stf'+$ ' results/langzeitbild results/alpha results/referenzbild '+$ ' support/flaeche support/ruhdimensionen '+$ ' support/basisdimensionen allvars.dat ; rm tar_running) &' spawn, cmd ;;; Read the correct variables and start connecting sps = init_variables('allvars.dat') catch, Error_Status IF Error_Status NE 0 THEN BEGIN applog, 'Burst '+strtrim(burst+db, 2)+ $ ': An error occured during connect!' ENDIF ELSE BEGIN ;;; check alpha. For values < 12% use drop-in for connect alpha = 0. openr, unit, sps.ResDir + 'alpha', /get readf, unit, alpha free_lun, unit drop = (alpha le 12 ? 1 : 0) IF n_elements(queue) EQ sps.S_n THEN $ p=connect(sps, queue, /INT, /SAFE, /ENHANCE, DROP=drop) $ ELSE $ p=connect(sps, /INT, /SAFE, /ENHANCE, ORD=5, DROP=drop) IF min(p) LE 0 THEN $ applog, 'Burst '+strtrim(burst+db, 2)+': Min data <= 0!' save_result, p, 'FITS/'+Burstinfo(burst).name, sps, $ jd=Burstinfo(burst).jultime applog, 'Burst '+strtrim(burst+db, 2)+': Saved as '+ $ Burstinfo(burst).name ENDELSE catch, /cancel ;;; make sure tar is finished, then clean dirs spawn, 'while [ -f tar_running ]; do sleep 1; done', /sh spawn, 'rm -rf results support allvars.dat' ENDFOR END