!
! @ image File [SUBSET Imin Imax Jmin Jmax] [PLANE Iplane Jplane]
!
if ("no&1".eq."no ") then
  message e image "missing argument 1 of command IMAGE"
  say "Syntax: "
  say "@ image File [SUBSET Imin Imax Jmin Jmax] [PLANE Iplane Jplane]"
  return error
endif
!
if (exist(THEONE_FILE)) then
  delete /var ALLONE THEONE THEONE_FILE
endif
!
define logical subset
define integer imin imax jmin jmax nx ny iplane jplane
define image ALLONE &1 read /GLOBAL
define character post*64 key*3
!
let iplane 1
let jplane 1
!
if ("no&2".ne."no") then
  let key &2 /upper
  if (key.eq."SUB") then
     let subset yes
     let imin &3
     let imax &4
     let jmin &5
     let jmax &6
     if ("&7no".ne."no") then
        let key &7 /upper
        if (key.eq."PLA") then
           let iplane &8
           if ("&9no".ne."no") then
             let jplane &9
           endif
        else
           say "Syntax error"
           return error
        endif
     endif
  else if (key.eq."PLA") then
     let iplane &3
     if ("&4no".ne."no") then
        let key &4 /upper
        if (key.eq."SUB") then
           let subset yes
           let imin &5
           let imax &6
           let jmin &7
           let jmax &8
        else
           let jplane &4
           let key &5 /upper
           if (key.eq."SUB") then
              let subset yes
              let imin &6
              let imax &7
              let jmin &8
              let jmax &9
          endif
        endif
     endif
  endif
endif
!
if (allone%ndim.eq.4) then
   let post ","'iplane'","'jplane'"]"
else if (allone%ndim.eq.3) then
   let post ","'iplane'"]"
else
   let post "]"
endif
!
if (subset) then
   let imax min(imax,allone%dim[1])
   let imax max(1,imax)
   let imin min(imin,imax)
   let imin max(1,imin)
   let jmax min(jmax,allone%dim[2])
   let jmax max(1,jmax)
   let jmin min(jmin,jmax)
   let jmin max(1,jmin)
   !
   let nx imax-imin+1
   let ny jmax-jmin+1
   define image THEONE['nx','ny']   *  real /global
   let THEONE% ALLONE%
   let theone%convert[1,1] theone%convert[1,1]+(1-imin)
   let theone%convert[1,2] theone%convert[1,2]+(1-jmin)
   let THEONE ALLONE[imin:imax,jmin:jmax'post'
else
   let nx allone%dim[1]
   let ny allone%dim[2]
   define image THEONE['nx','ny'] * REAL /global
   let THEONE% ALLONE%
   let THEONE ALLONE['post'
endif
let theone%convert[1,3] theone%convert[1,3]+(1-iplane)
let theone%convert[1,4] theone%convert[1,4]+(1-jplane)
!
! Keep it for SPECTRUM
!     !  delete /var ALLONE
!
define character theone_file*128 /global
let theone_file &1
!
define alias  G_PA    theone%PA
define alias  G_MINOR theone%MINOR
define alias  G_MAJOR theone%MAJOR
define alias  G_BEAM theone%BEAM
define alias  G_VELOFF theone%veloff
define alias  G_VELRES theone%velres
define alias  G_RESTFRE theone%restfre
define alias  G_IMAGFRE theone%imagfre
define alias  G_FREQRES theone%freqres
define alias  G_LINE theone%line
define alias  G_YAXI theone%y_axis
define alias  G_XAXI theone%x_axis
define alias  G_ANGLE theone%angle
define alias  G_D0 theone%d0
define alias  G_A0 theone%a0
define alias  G_PTYP theone%ptype
define alias  G_BII theone%bII
define alias  G_LII theone%LII
define alias  G_DEC theone%dec
define alias  G_RA theone%ra
define alias  G_EQUINOX theone%equinox
define alias  G_SOURCE theone%source
define alias  G_COORD  theone%system
define alias  G_UNIT  theone%unit
define alias  G_UNIT4 theone%unit4
define alias  G_UNIT3 theone%unit3
define alias  G_UNIT2 theone%unit2
define alias  G_UNIT1 theone%unit1
define alias  G_MINLOC theone%minloc
define alias  G_MAXLOC theone%maxloc
define alias  G_MIN  theone%min
define alias  G_MAX  theone%max
define alias  G_EXTREMA theone%extrema
define alias  G_BLANK theone%blank
define alias  G_CONVERT theone%convert
define alias  G_DIM theone%dim
define alias  G_NDIM theone%ndim
!
rgdata THEONE /var





