!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! List the header associated to the current cubeid
!
! This procedure is foreseen to be called by "BIT /HEADER"
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure p-header-def
  if .not.exist(cubego%header) then
     if .not.exist(cubego) then
        define structure cubego /global
     endif
     define structure cubego%header /global
     define structure cubego%header%text /global
     define real cubego%header%text%x cubego%header%text%y cubego%header%text%dy /global
     @ l-header.cube
     @ l-header-def cubego%header
  endif
  @ l-header-load 'cubego%cubes%id[1]' cubego%header
  if (cubeset%panel%true%frame%landscape) then
     let cubego%header%text%x   0.5
     let cubego%header%text%y  -1.0
     let cubego%header%text%dy -1.0
  else
     let cubego%header%text%x   0.75
     let cubego%header%text%y  -0.70
     let cubego%header%text%dy -0.75
  endif
end procedure p-header-def
!
begin procedure p-header-one
  greg1\draw text cubego%header%text%x cubego%header%text%y "&1" 6 0 /box 7
  let cubego%header%text%y cubego%header%text%y+cubego%header%text%dy
end procedure p-header-one
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Shallower "on error" rule
on error return
!
! Box
set\panel 1 /def /position header
greg1\box n n n
!
@ p-header-def
!
greg1\set expand 0.8
@ p-header-one 'cubego%cubes%id[1]'
@ p-header-one 'cubego%header%family'
@ p-header-one 'cubego%header%flags'
@ p-header-one "\\iSource:\\i "'cubego%header%source'
@ p-header-one "\\iLine:\\i "'cubego%header%line'
@ p-header-one "\\iFrequency:\\i "'cubego%header%freq'
@ p-header-one "\\iVelocity:\\i "'cubego%header%vsys'
@ p-header-one "\\iBeam:\\i "'cubego%header%beam'
!
! Contour levels
!!$if (do%contour) then
!!$   define character sic_precision*8
!!$   let sic_precision 'sic%precision'
!!$   sic precision single
!!$   if (spacing.lt.0) then
!!$      ! User defined contour levels
!!$      let text1 "\\iLevels:\\i ("'&1%unit'")"
!!$      let cubego%header%text%y cubego%header%text%y+cubego%header%text%dy
!!$      greg1\draw text cubego%header%text%x cubego%header%text%y text1 6 0 /box 7
!!$      if (.not.exist(greg%levels)) then
!!$         ! Levels have not yet been defined
!!$         message w header "LEVEL command should be used before this plot"
!!$      else
!!$         ! Levels have already been defined => Make a limited, relevant list
!!$         greg1\set expand 0.64
!!$         ! Define maximum number of levels per line
!!$         define integer jmax jlevel
!!$         if (cubeset%panel%true%frame%landscape) then
!!$            let jmax 5
!!$         else
!!$            let jmax 10
!!$         endif
!!$         ! Initialization
!!$         let jlevel 1
!!$         let cubego%header%text%y cubego%header%text%y+cubego%header%text%dy
!!$         let text1 " "
!!$         ! Loop over levels
!!$         for ilevel 1 to greg%nlevel
!!$            ! Print only relevant levels
!!$            if (greg%levels[ilevel].gt.&1%min.and.greg%levels[ilevel].lt.&1%max) then
!!$               ! Added ilevel level to string
!!$               let text1 'text1'" "'greg%levels[ilevel]'
!!$               ! Print string when needed
!!$               if ((jlevel.eq.jmax).or.(ilevel.eq.greg%nlevel)) then
!!$                  greg1\draw text cubego%header%text%x cubego%header%text%y text1 6 0 /box 7
!!$                  let jlevel 1
!!$                  let cubego%header%text%y cubego%header%text%y+0.70*cubego%header%text%dy
!!$                  let text1 " "
!!$               else
!!$                  let jlevel jlevel+1
!!$               endif
!!$            endif
!!$         next ilevel
!!$         let cubego%header%text%y cubego%header%text%y-0.70*cubego%header%text%dy
!!$         greg1\set expand 0.8
!!$      endif
!!$   else
!!$      ! Evenly spaced contour levels
!!$      !
!!$      ! Contour spacing in image unit
!!$      let text1 '&1%unit'
!!$      define double range expo mant round_spacing sigma
!!$      if (true%spacing.gt.0.1) then
!!$         ! Strong source
!!$         let range log10(true%spacing)
!!$         let expo int(range+20.)-21
!!$         let mant range-expo+1
!!$         let round_spacing 0.1*nint(10^mant)*10^expo
!!$         let text1 "\\iLevel step:\\i "'round_spacing'" "'text1'
!!$      else if (true%spacing.gt.0) then
!!$         ! Faint source
!!$         let range log10(true%spacing*1e3)
!!$         let expo int(range+20.)-21
!!$         let mant range-expo+1
!!$         let round_spacing 0.1*nint(10^mant)*10^expo
!!$         let text1 "\\iLevel step:\\i "'round_spacing'" m"'text1'
!!$      endif
!!$      ! Exponential or linear spacing
!!$      if (true%space.eq."exp") then
!!$         let text1 'text1'" ("'true%space'")"
!!$      endif
!!$      let cubego%header%text%y cubego%header%text%y+cubego%header%text%dy
!!$      greg1\draw text cubego%header%text%x cubego%header%text%y text1 6 0 /box 7
!!$      !
!!$      let text1 " "
!!$      ! Associated conversion if needed
!!$      if (&1%unit.eq."Jy".or.&1%unit.eq."Jy/beam") then
!!$         if ((&1%major.ne.0).and.(&1%minor.ne.0)) then
!!$            @ c-jansky.cube &1 "nofeedback"
!!$            let text1 '0.01*nint(true%spacing*kperjy*100.)'" K"
!!$         endif
!!$      endif
!!$      ! And associated number of sigma
!!$      if (&1%noise.ne.0.and.true%spacing.ne.0) then
!!$         let sigma true%spacing/&1%noise
!!$         let range log10(sigma)
!!$         let expo int(range+20.)-21
!!$         let mant range-expo+1
!!$         let round_spacing 0.1*nint(10^mant)*10^expo
!!$         if (text1.eq." ") then
!!$            let text1 "            --  "'round_spacing'" \gs"
!!$         else
!!$            let text1 "  "'text1'"   --  "'round_spacing'" \gs"
!!$         endif
!!$      endif
!!$      !
!!$      if (text1.ne." ") then
!!$         let cubego%header%text%y cubego%header%text%y+cubego%header%text%dy
!!$         greg1\draw text cubego%header%text%x cubego%header%text%y text1 6 0 /box 7
!!$      endif
!!$   endif
!!$   sic precision 'sic_precision'
!!$endif
!
! Box marking
!if (true%mark.ne."none") @ p-header-one "\\iBox marking:\\i "'true%mark'
!
! Planes
!if (true%step[1].ne.0) @ p-header-one "\\iPlanes:\\i ["'true%first[1]'" to "'true%last[1]'" by "'true%step[1]'"]"
!if (true%step[2].ne.0) @ p-header-one "\\iPlanes:\\i ["'true%first[2]'" to "'true%last[2]'" by "'true%step[2]'"]"
!
! User and date
sic\sic date
if (cubeset%panel%true%frame%landscape) then
   greg1\draw text 0.0 2.0 "'sys_info'" 5 0 /box 2
   greg1\draw text 0.0 1.0 "'sys_date'" 5 0 /box 2
else
   greg1\draw text -1.0 0.0 "'sys_info'" 5 90 /box 6
   greg1\draw text -2.0 0.0 "'sys_date'" 5 90 /box 6
endif
greg1\set expand 1.0
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
