!
! procedure reduce.mira for online data processing
!
on error continue
!
file in ~/data
!
define integer iscan ispec found lastScan 
define logical writeClass
!
let ispec      &1 ! FEBE number for spectrum to be plotted
let writeClass &2 ! write or do not write CLASS spectra
!
if writeClass then
   if file("~/spectraOdp.30m") then
      file out ~/spectraOdp.30m
   else
      file out ~/spectraOdp.30m new
   endif
endif
!
found = 0
find
var list
if exist(list) then
   found = list%found
else
   for /while found.eq.0
      sic wait 10
      find
      var list
      if exist(list) then
         found = list%found
      endif
   next
endif
!
scan list%attribute'found'%scan
var data 
var scan
!
lastScan = 0
!
for /while .true.
    if (list%attribute'found'%scan.ne.lastScan) then
       lastScan = list%attribute'found'%scan
       for i 1 to list%found
           iscan = list%attribute'i'%scan

	   if list%attribute'iscan'%backend.ne."CONTINUU" then

              scan 'iscan' 

              if scan%data%be[ispec].ne.10 then 
	         if scan%header%scantype.eq."calibrate" then
	            view 'ispec'
	         else
	            cal ALL
	            view 'ispec'
	            if writeClass then
                       m\write /febe all
	            endif
                 endif
              endif
        
           endif
       next
    endif
    sic wait 10
    find /new
    found = list%found
next
!
