!
! @ sexa value range result [digit]
!
! where range is 180 for Degrees, and 12 for Hours
! Digit is the (optional) number of decimal digits
!
define double hms h m s mas is value range scale
define char hh*2 mm*2 ss*2
!
let range &2
!
define integer digit
if (range.eq.12) then
  let digit 3
else if (range.eq.180) then
  let digit 2
else
  message e sexa "Invalid range "'range'
  return error
endif
if ("no&4".ne."no") then
   let digit &4
   let digit min(4,digit)
   let digit max(2,digit)
endif
define char aa*'digit'
let scale 10^digit
!
let value &1
!
let hms abs(&2|pi*value)
let h int(hms)
let hms 60d0*(hms-h)
let m int(hms)
let hms 60d0*(hms-m)
let s nint(scale*hms)/scale
if (s.ge.60D0) then
   let s s-60d0
   let m m+1
endif
if (m.gt.60d0) then
  let m m-60d0
  let h h+1d0
endif
!
let is int(s)
let mas scale*(s-is)
!
let mm m /format i2.2
let ss is /format i2.2
let aa mas /format i'digit'.'digit'
if (value.gt.0) then
  let &3 'h':'mm':'ss'.'aa'
else
  let &3 -'h':'mm':'ss'.'aa'
endif
