!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ l-old-level
!
! &1: aaa
!
! Define contour levels for nice plotting of AAA
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Reset minimum and maximum level values
let true%level%min -1
let true%level%max -1
!
! Need true%scale values => Compute them
@ l-old-scale.cube &1
!
! Nothing more to be done when user defined levels
if (spacing.lt.0) then
  return
endif
!
! Use true scale values
define real tmin tmax
let tmin min(true%scale[1],true%scale[2])
let tmax max(true%scale[1],true%scale[2])
!
!let tmin &1%min
!let tmax &1%max
!
! Check whether there is a range of values
if (tmin.eq.tmax) then
   message w levels "&1 has no range: max = min = "'tmin'
   return
endif
!
! Kind of spacing
let true%space 'do%space' /lower
if (true%space.eq."*") then
   let true%space "lin"
endif
if (true%space.eq."exp") then
   ! Exponential spacings
   if (spacing.ge.0) then
      let true%spacing spacing
      greg2\levels -2*true%spacing -1*true%spacing  1*true%spacing -
             2*true%spacing  4*true%spacing  8*true%spacing -
            16*true%spacing 32*true%spacing 64*true%spacing
   else
      message f levels "set spacing to a positive value"
      return base
   endif
else if (true%space.eq."lin") then
   ! Linear spacings
   define real range expo mant
   ! Definition of true%spacing
   if (spacing.ne.0) then
      ! User defined
      let true%spacing spacing
   else
      ! Default value
      let range log10(tmax-tmin)
      let expo int(range+20.)-21
      let mant range-expo-1
      if (mant.lt.0.25) then
         let true%spacing 10**expo
      else if (mant.lt.0.60) then
         let true%spacing 2.*10**expo
      else if (mant.lt.0.90) then
         let true%spacing 5.*10**expo
      else
         let true%spacing 10**(expo+1)
      endif
   endif
   ! Definition of levels
   define integer n1 n2
   let n1 nint(tmin/true%spacing)
   let n2 nint(tmax/true%spacing)
   if (n1.lt.0.and.n2.gt.0) then
      greg2\levels true%spacing*n1 to -0.95*true%spacing by true%spacing true%spacing to true%spacing*(n2+0.05) by true%spacing
   else if (n1.gt.0) then
      let n1 max(n1,1)
      greg2\levels true%spacing*n1 to true%spacing*(n2+0.05) by true%spacing
   else if (n1.lt.0.and.n2.lt.0) then
      let n1 -max(-n1,1)
      greg2\levels true%spacing*n1 to true%spacing*(n2+0.05) by true%spacing
   else if (n1.lt.0.and.n2.eq.0) then
      let n1 -max(-n1,1)
      greg2\levels true%spacing*n1 to -0.95*true%spacing by true%spacing
   else if (n1.eq.0.and.n2.ne.0) then
      greg2\levels true%spacing*(n1+1) to true%spacing*(n2+0.05) by true%spacing
   else if (n1.eq.0.and.n2.eq.0) then
      message w level "No level in range"
      greg2\levels true%spacing
   endif
   ! Save minimum and maximum level values for later use
   let true%level%min true%spacing*n1
   let true%level%max true%spacing*n2
else
   message e level "Unknown spacing type: "'true%space'
   return base
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
