!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure l-header-def
  if .not.exist(&1) then
     define structure &1 /global
  endif
  if .not.exist(&1%source) then
     define character*128 &1%source &1%line &1%freq &1%vsys &1%beam /global
     define character*128 &1%id &1%family &1%flags /global
  endif
end procedure l-header-def
!
begin procedure l-header-load
  go\load &1 /id /into id
  go\load &1 /source /into source
  go\load &1 /line /into line
  go\load &1 /freq /into freq
  go\load &1 /spectralframe /into frame
  go\load &1 /velocity /into vsys
  go\load &1 /beam /into beam
  !
  define double roundedvsys roundedmajor roundedminor roundedpang factor
  let roundedvsys 'vsys%value'
  let roundedmajor 'beam%major'
  let roundedminor 'beam%minor'
  let roundedpang 'beam%pang'
  !
  let roundedvsys nint(roundedvsys*10)/10  ! [km/s] Precision 0.1 km/s
  ! Beam: ensure 3 significant digits
  if (roundedminor.gt.10.0) then
    let factor 10
  else if (roundedminor.gt.1.0) then
    let factor 100
  else if (roundedminor.gt.0.1) then
    let factor 1000
  else
    let factor 10000
  endif
  let roundedmajor nint(roundedmajor*factor)/factor  ! [arcsec] Precision 'factor' arcsec
  let roundedminor nint(roundedminor*factor)/factor  ! [arcsec] Precision 'factor' arcsec
  let roundedpang  nint(roundedpang)                 ! [deg]    Precision 1 deg
  !
  let &2%id 'id%id'
  let &2%family 'id%family'
  let &2%flags 'id%flagstring'
  let &2%source 'source'
  let &2%line 'line'
  let &2%freq 'freq%signal'" "'freq%unit'
  let &2%vsys 'roundedvsys'" "'vsys%unit'" "'frame'
  if (roundedminor.eq.roundedmajor) then
     let &2%beam 'roundedmajor'"`"
  else
     let &2%beam 'roundedmajor'" x "'roundedminor'"` PA "'roundedpang'"^"
  endif
end procedure l-header-load
!
begin procedure l-header-draw-desc
  ! &1: Input structure
  ! &2: x string position in character unit
  ! &3: y string position in character unit
  ! &4: string centering
  ! &5: string angle
  ! &6: string position compared to box
  define character text*128
  let text "  \\iS:\\i "'&1%source'
  let text 'text'"  \\iL:\\i "'&1%line'
  let text 'text'"  "'&1%freq'" @ "'&1%vsys'
  let text 'text'"  \\iB:\\i "'&1%beam'
  greg1\draw text &2 &3 'text' &4 &5 /char &6
end procedure l-header-draw-desc
!
begin procedure l-header-draw-cubeid
  ! &1: Input structure
  ! &2: x string position in character unit
  ! &3: y string position in character unit
  ! &4: string centering
  ! &5: string angle
  ! &6: string position compared to box
  define character text*128
  let text '&1%id'"  "'&1%family'":"'&1%flags'
  greg1\draw text &2 &3 'text' &4 &5 /char &6
end procedure l-header-draw-cubeid
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
