!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ l-old-position
!
! &1: aaa
! &2: do%pos
! &3: true%pos
! &4: ndim (optional)
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Useful variables
define integer jaxis[2] kaxis ndim
!
! Find X and Y axis number
let jaxis '&1%x_axis' '&1%y_axis'
!
! Find number of positions
if ("&4none".eq."none") then
   let ndim 1
else
   let ndim 2
endif
!
! Loop over X and Y axis
for iaxis 1 to 2
   ! Alias iaxis number to a simple variable for readability
   let kaxis jaxis[iaxis]
   ! Sanity check
   if (kaxis.eq.0) then
      ! iaxis does not exist => Try something clever...
      if (iaxis.eq.1) then
         message w position "No X axis in data cube"
      else
         message w position "No Y axis in data cube"
      endif
      ! Default to reference pixel
      if (ndim.eq.1) then
         let &3%s[iaxis] 0.0
         let &3%r[iaxis] 0.0
         let &3%p[iaxis] &1%convert[1,iaxis]
      else
         let &3%s[iaxis,] 0.0
         let &3%r[iaxis,] 0.0
         let &3%p[iaxis,] &1%convert[1,iaxis]
      endif
   else
      ! iaxis exist => Use its information
      if (&1%convert[3,kaxis].eq.0) then
         ! Axis increment = 0 => Problem
         say " "
         message e position "&1%convert[3,"'kaxis'"] is zero valued"
         say " "
         return base
      else
         ! Axis increment is defined => Continue
         ! The default behavior (i.e. &2[iaxis].eq.0) is treated in the general case below
         if (ndim.eq.1) then
            let &3%s[iaxis] &2[iaxis]
            let &3%r[iaxis] &2[iaxis]*sec
            let &3%p[iaxis] &1%convert[1,kaxis]+(&3%r[iaxis]-&1%convert[2,kaxis])/&1%convert[3,kaxis]
         else
            let &3%s[iaxis,] &2[iaxis,]
            let &3%r[iaxis,] &2[iaxis,]*sec
            let &3%p[iaxis,] &1%convert[1,kaxis]+(&3%r[iaxis,]-&1%convert[2,kaxis])/&1%convert[3,kaxis]
         endif
      endif
   endif
next iaxis
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
