!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ p_corner.ima VarName [Center [Size]]
! adapted from _corner.greg             J.Pety 2004
! extended to arbitrary type of data    S.Guilloteau 2022
!
! &1: Header Variable
! &2: center
! &3: size
!
! Hypothesis: p_axes called before
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
let sec box%aunit /new double
for i 1 to 2
  !
  ! First find iblc and itrc
  !
  if (&3[i].eq.0) then
    let iblc[i] 1
    let itrc[i] &1%dim[i]
    !
    let rblc[i] &1%convert[2,i]+(iblc[i]-&1%convert[1,i])*&1%convert[3,i]
    let rtrc[i] &1%convert[2,i]+(itrc[i]-&1%convert[1,i])*&1%convert[3,i]
    let sblc[i] rblc[i]/sec
    let strc[i] rtrc[i]/sec
  else
    if (abs(2*&1%convert[3,i]).gt.abs(&3[i]*sec)) then
      say " "
      message e corner "SIZE is smaller than 1 pixel"
      say " "
      return base
    endif
    if (&1%convert[3,i].gt.0) then
      let sblc[i] '&2[i]-&3[i]/2'
      let strc[i] '&2[i]+&3[i]/2'
    else if (&1%convert[3,i].lt.0) then
      let sblc[i] '&2[i]+&3[i]/2'
      let strc[i] '&2[i]-&3[i]/2'
    else
      say " "
      message e corner "&1%convert[3,"'i'"] is zero valued"
      say " "
      return base
    endif
    let rblc[i] sblc[i]*sec
    let rtrc[i] strc[i]*sec
    let iblc[i] &1%convert[1,i]+(rblc[i]-&1%convert[2,i])/&1%convert[3,i]
    let itrc[i] &1%convert[1,i]+(rtrc[i]-&1%convert[2,i])/&1%convert[3,i]
    let iblc[i] max(iblc[i],1)
    let itrc[i] min(itrc[i],&1%dim[i])
  endif
next
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
