!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Compute integrated emission between first and last plane taking
! blanking into account
! J.Pety 2004
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
define character fullname*256 newname*256
let fullname 'name'"."'type'
if file(fullname) then
   @ p_load.greg aaa
   if (aaa%convert[3,3].eq.0.0) then
      message e area "velocity increment is zero valued!"
      return base
   endif
   !
   define integer true_first true_last true_step true_nchan
   if (first.eq.0) then
      let true_first 1
   else
      let true_first first
   endif
   if (last.eq.0) then
      let true_last max(1,aaa%dim[3])
   else
      let true_last last
   endif
   !
   if (true_first.gt.true_last) then
      let true_step -1
      let true_nchan true_first-true_last+1
   else
      let true_step +1
      let true_nchan true_last-true_first+1
   endif
   !
   let newname 'name'"-area-"'true_first'"-"'true_last'
   define image area 'newname'"."'type' real /like aaa[1]
   define integer mask /like aaa[1]
   let area% aaa%
   let area%convert[3] 0.0
   let area%unit  'aaa%unit'".km/s"
   let area%unit3 ""
   let area%velres  aaa%velres*true_nchan*true_step
   let area%freqres aaa%freqres*true_nchan*true_step
   let area%f_axis 0
   let area%noise aaa%noise*abs(aaa%convert[3,3])*sqrt(true_nchan)
   let area%rms   aaa%rms*abs(aaa%convert[3,3])*sqrt(true_nchan)
   let area 0
   let mask 0
   for i true_first to true_last by true_step
      let area area+aaa[i] /where abs(aaa[i]-aaa%blank[1]).gt.aaa%blank[2]
      let mask mask+1      /where abs(aaa[i]-aaa%blank[1]).le.aaa%blank[2]
   next
   let area area*abs(aaa%convert[3,3])
   let area aaa%blank[1] /where mask.gt.0
   delete /var area mask
   let name 'newname'
   say "Name set to "'name'
   vector\header 'name'"."'type' /extrema
else
   message e area ""'fullname'" does not exist"
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
