!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ c-old-get-spectrum
!
! &1: action
!
! This assumes that the velocity axis is the 3rd axis
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
define character action*5
let action "&1"
!
if (action.ne."inter") then
   ! Load image
   go\oldload 'name'  /syntax hgdf /in aaa1
   !
   ! Define spectrum range and position
   @ l-old-vrange.cube   aaa1 range  true%vrange
   @ l-old-position.cube aaa1 do%pos true%pos
endif
!
! Check velocity range
define integer vblc vtrc vdim dummy
let vblc min(max(true%vrange%p[1],1),aaa1%dim[3])
let vtrc min(max(true%vrange%p[2],1),aaa1%dim[3])
if (vblc.gt.vtrc) then
   let dummy vtrc
   let vtrc vblc
   let vblc dummy
endif
let vdim vtrc-vblc+1
!
! Check spectrum position
if ((true%pos%p[1].lt.1).or.(aaa1%dim[1].lt.true%pos%p[1])) then
   message w single-spectrum "Position ("'true%pos%s[1]'"`,"'true%pos%s[2]'"`) outside field of view"
   return
else if ((true%pos%p[2].lt.1).or.(aaa1%dim[2].lt.true%pos%p[2])) then
   message w single-spectrum "Position ("'true%pos%s[1]'"`,"'true%pos%s[2]'"`) outside field of view"
   return
endif
!
! Define spectrum structure
if exist(single_spectrum) then
   delete /var single_spectrum
endif
define structure single_spectrum /global
define integer single_spectrum%n /global
define double single_spectrum%x['vdim'] single_spectrum%y['vdim'] /global
define character single_spectrum%ylegend*32 /global
!
! Spectrum number of channels
let single_spectrum%n vdim
!
! Define velocity axis
define double velocities['aaa1%dim[3]']
let velocities[i] (i-aaa1%convert[1,3])*aaa1%convert[3,3]+aaa1%convert[2,3]
let single_spectrum%x velocities['vblc':'vtrc']
!
! Define intensity axis
let single_spectrum%y aaa1['true%pos%p[1]','true%pos%p[2]','vblc':'vtrc']
!
! Plot
if (action.ne."inter") then
   @ l-old-plot-spectrum.cube single_spectrum
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
