on error return 
! 
define character text*40 texta*30 textb*20
define logical landscape 
define real sigma
define real k__line
if .not.exist(do_box) then
   define real boxs xbox ybox  /global
   define logical do_box  /global
   let do_box .true.
endif
! 
let landscape page_x.gt.page_y 
if (.not.do_box).and.(boxs.gt.0) then
  if (landscape) then 
    set box xbox+boxs page_x ybox page_y-0.1 
  else 
    set box xbox xbox+boxs ybox+boxs page_y-0.1 
  endif 
else
  let xbox 6*character_size ! was 5
  let ybox 3*character_size 
  if (landscape) then 
    let boxs min(page_x-0.1-xbox-12*character_size,page_y-ybox-0.1) ! was 13
    if (boxs.lt.0) then 
        say "F-HEADER, Page to small - change page or decrease character size" 
      quit all 
    endif 
    set box xbox+boxs page_x ybox page_y-0.1 
  else 
    let boxs min(page_x-xbox-0.1,page_y-13*character_size-0.1) 
    if (boxs.lt.0) then 
      say "F-HEADER, Page to small - change page or decrease character size" 
      quit all 
    endif 
    set box xbox xbox+boxs ybox+boxs page_y-0.1 
  endif 
endif
if (do_header) then 
  box n n n 
  !
  set expand 1.0
  let text 'model_name'
  let k__line -1
  draw text .5 k__line 'text' 6 /box 7
  let k__line k__line-1 
  !
  let text 'kname[kind]'" ("'nfields'" fields)" 
  draw text .5 k__line 'text' 6 /box 7
  let k__line k__line-1
  !
  if exist(text1) then
     draw text .5 k__line 'text1' 6 /box 7
     let k__line k__line-0.8
  endif
  if exist(text2) then
     draw text .5 k__line 'text2' 6 /box 7
     let k__line k__line-0.8
  endif
  if exist(text3) then
     draw text .5 k__line 'text3' 6 /box 7
     let k__line k__line-0.8
  endif
  let k__line k__line-0.2
  !
  set expand 0.8 
  let text "\\iFrequency:\\i "'nint(freq)'" GHz" 
  dra text .5 k__line 'text' 6 /box 7
  let k__line k__line-1 
  if ("&1a".eq."a") then
     set box xbox xbox+boxs ybox ybox+boxs 
     return
  endif
  ! 
  if (&1%major.ne.0) then 
    define integer imajor iminor ipa 
    if (&1%minor.gt.1.0) then 
      let imajor nint(&1%major*180*3600|pi*10) 
      let iminor nint(&1%minor*180*3600|pi*10) 
      let ipa nint(&1%pa*180.0|pi) 
      let text "\\iBeam:\\i "'0.1*imajor'" x "'0.1*iminor'" PA "'ipa'"^" 
    else 
      let imajor nint(&1%major*180*3600|pi*100) 
      let iminor nint(&1%minor*180*3600|pi*100) 
      let ipa nint(&1%pa*180.0|pi) 
      let text "\\iBeam:\\i "'0.01*imajor'" x "'0.01*iminor'" PA "'ipa'"^" 
    endif 
    define real lambda jyperk 
    let lambda 2.99792458e8|&1%restfre*1e-6 
    let jyperk 2.0*1.38e3*pi*&1%major*&1%minor|4.|log(2.0)|lambda^2 
  else 
    let text "\\iBeam:\\i (no clean beam)" 
  endif 
  dra text .5 k__line 'text' 6 /box 7
  let k__line k__line-1 
  ! 
  define character sic_precis*8
  let sic_precis 'sic%precision'
  ! 
  let space_type 'space_type' /upper
  if (spacing.lt.0).or.(space_type.eq."USER") then 
    let text "\\iLevels :\\i ("'&1%unit'")"
    dra text .5 k__line 'text' 6 /box 7 
    let k__line k__line-1
    !
    sic precision single
    define integer j jmax
    define double levels /like greg%levels
    let levels greg%levels
    let j 1
    let text " "
    set char character_size*0.8
    if (landscape) then
       let jmax 5
    else
       let jmax 10
    endif
    for i 1 to greg%nlevel
      if (levels[i].gt.&1%min.and.levels[i].lt.&1%max) then
        let text 'text'" "'levels[i]'
        if (j.eq.jmax) then
           draw text .5 k__line text 6 /box 7
           let j 1
           let k__line k__line-0.70
           let text " "
        else
           let j j+1
        endif
      endif
    next
    if (j.ne.1) then
      draw text .5 k__line text 6 /box 7
      let k__line k__line-1
    else
      let k__line k__line-0.30
    endif    
    set char character_size*1.25
  else
    sic precis single
    let texta " " 
    if (&1%unit.eq."Jy".or.&1%unit.eq."Jy/beam") then 
      if (&1%major.ne.0) then 
        let jyperk = true_spacing|jyperk 
        if (&1%unit.eq."Jy") then 
          let text "Jy " 
        else 
          let text "Jy/beam" 
        endif 
        let texta '0.01*nint(jyperk*100.)'" K " 
      else 
        let text '&1%unit' 
      endif 
    else 
      let text '&1%unit' 
    endif 
    !
    defin double range expo mant round_spacing
    if (true_spacing.gt.0.0) then
       if (true_spacing.gt.0.1) then	
          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 text "\\iLevel step:\\i "'round_spacing'" "'text' 
       else 
          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 text "\\iLevel step:\\i "'round_spacing'" m"'text' 
       endif
       if (&1%noise.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
          let textb 'round_spacing'
          if (texta.eq." ") then
             let texta "            --  "'textb'" \gs"
          else
             let texta "  "'texta'"   --  "'textb'" \gs"
          endif
       endif
       dra text .5 k__line 'text' 6 /box 7 
       let k__line k__line-1
       dra text .5 k__line 'texta' 6 /box 7 
       let k__line k__line-1
    endif
  endif 
  sic precision 'sic_precis'
  ! 
  ! the exact spelling of the LET commands is mandatory 
  ! (MASK is in a widget menu). 
  if (mark.ne."CHANNEL".and.mark.ne."NONE") then 
    if (&1%unit3.eq."RA") then 
      let mark "RA Offset" 
    else if (&1%unit3.eq."DEC") then 
      let mark "DEC Offset" 
    else if (mark.ne."FREQUENCY") then 
      let mark "VELOCITY" 
    endif 
  endif 
  ! 
  sic\sic date 
  if (landscape) then 
    dra text 0.0 1.5 "'SYS_INFO'" 5 0 /box 2 
    dra text 0.0 0.5 "'SYS_DATE'" 5 0 /box 2 
  else 
    dra text -0.5 0.0 "'SYS_INFO'" 5 90 /box 4 
    dra text -1.5 0.0 "'SYS_DATE'" 5 90 /box 4 
  endif 
  ! 
endif
set box xbox xbox+boxs ybox ybox+boxs 
!

