!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ l-old-vrange.cube
! &1: aaa
! &2: range
! &3: true%vrange
!
! The sign of (range[2]-range[1]) implies the direction of the plotted velocity axis
! Default is increasing velocity
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Sanity Check
if (&1%f_axis.eq.0) then
   message w vrange "No frequency axis in data cube"
   let &3%p 1
   let &3%v 0
   return
endif
!
! Find velocity axis
define integer vaxis
let vaxis &1%f_axis
!
! Define true%vrange values
if (&2[1].ne.0.or.&2[2].ne.0) then
   ! range[1] or range[2] != 0 => Use the user-defined range (ie assume that a zero value is valid)
   if (&1%convert[3,vaxis].ne.0) then
      ! Velocity increment != 0 => Plotted direction identical to range direction
      let &3%v &2
   else
      ! Velocity increment = 0 => Problem
      say " "
      message e vrange "velocity increment (&1%convert[3,"'vaxis'"]) is zero valued"
      say " "
      return base
   endif
   let &3%p &1%convert[1,vaxis]+(&3%v-&1%convert[2,vaxis])/&1%convert[3,vaxis]
else
   ! range[1] = range[2] = 0
   ! => Default to full velocity range in lmv cube in increasing velocity order
   if (&1%convert[3,vaxis].gt.0) then
      ! Velocity increment > 0 => Plotted direction identical to natural direction
      let &3%p 1 &1%dim[vaxis]
   else if (&1%convert[3,vaxis].lt.0) then
      ! Velocity increment < 0 => Plotted direction identical to natural direction
      let &3%p &1%dim[vaxis] 1
   else
      ! Velocity increment = 0 => Problem
      say " "
      message e vrange "velocity increment (&1%convert[3,"'vaxis'"]) is zero valued"
      say " "
      return base
   endif
   ! Then define true%vrange%v accordingly
   let &3%v &1%convert[2,vaxis]+(&3%p-&1%convert[1,vaxis])*&1%convert[3,vaxis]
endif
!
! Define true%vrange%f accordingly
let &3%f &1%restfre+(&3%p-&1%convert[1,vaxis])*&1%freqres
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
