!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ l-old-plot-spectrum
!
! &1: spectrum structure
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Intensity scale
if (scale[1].ne.0.or.scale[2].ne.0) then
   let true%scale scale
else
   greg1\limits /var &1%x &1%y
   let true%scale 'user_ymin' 'user_ymax'
endif
!
! Plot the histogram
greg1\limits true%vrange%v[1] true%vrange%v[2] true%scale[1] true%scale[2]
if (do%fill) then
   if (exist(&1%wmin).and.exist(&1%wmax)) then
      greg1\histogram &1%x[&1%wmin:&1%wmax] &1%y[&1%wmin:&1%wmax] /fill 5 /base 0
   else
      greg1\histogram &1%x &1%y /fill 5 /base 0
   endif
endif
greg1\histogram &1%x &1%y
!
! Box + Legend
!
! First, define legends + labels
if exist(&1%ylegend) then
   @ l-old-box-setup.cube dummy spectrum '&1%ylegend'
else
   @ l-old-box-setup.cube dummy spectrum
endif
! Second, define axis limits
define logical rcoord
if (true%coord.eq."rel") then
   let rcoord yes
else if (true%coord.eq."abs") then
   let rcoord no
else
   message e plot-spectrum "Unknown coordinate type: "'do%coord'
   return base
endif
if (true%vcoord.eq."vel") then
   if (rcoord) then
      greg1\limits true%vrange%v[1]-vsys true%vrange%v[2]-vsys true%scale[1] true%scale[2]
   else
      greg1\limits true%vrange%v[1] true%vrange%v[2] true%scale[1] true%scale[2]
   endif
else if (true%vcoord.eq."fre") then
   if (rcoord) then
      greg1\limits true%vrange%f[1]-aaa1%restfre true%vrange%f[2]-aaa1%restfre true%scale[1] true%scale[2]
   else
      greg1\limits true%vrange%f[1] true%vrange%f[2] true%scale[1] true%scale[2]
   endif
else if (true%vcoord.eq."pix") then
   if (rcoord) then
      ! This ones needs to be modified
      greg1\limits true%vrange%p[1] true%vrange%p[2] true%scale[1] true%scale[2]
   else
      greg1\limits true%vrange%p[1] true%vrange%p[2] true%scale[1] true%scale[2]
   endif
else
   message e plot-spectrum "Unknown coordinate type: "'do%vcoord'
   return base
endif
! Third, plot
@ l-old-box.cube label
! Reset axis limits to physical units
greg1\limits true%vrange%v[1] true%vrange%v[2] = =
!
! Define default marking scheme
if (mark.eq."*") then
   let true%mark "both"
else
   let true%mark 'mark' /lower
endif
! Draw mark
if (true%mark.ne."none") then
   if (true%mark.eq."offset".or.true%mark.eq."both") then
      greg1\draw text -1 -1 "("'true%pos%p[1]'","'true%pos%p[2]'")" 1 /char 9
   endif
   if (true%mark.eq."pixel".or.true%mark.eq."both") then
      define double xpos ypos
      let xpos 0.01*nint(100*true%pos%s[1])
      let ypos 0.01*nint(100*true%pos%s[2])
      greg1\draw text 1 -1 "("'xpos'"`,"'ypos'"`)" 3 /char 7
   endif
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
