begin procedure demo-accept-binary
  ! We need a binary file for this test...
!   define real r4[4,10]
!   accept r4 /binary toto.bin ! 8
!   exa r4[1]
  !
  define character*4 cc[4,10]
  accept cc /binary toto.bin
  exa cc[1]
end procedure demo-accept-binary
!
begin procedure demo-accept-array
  !
  message i demo-accept-array "Checking ACCEPT /ARRAY [/FORMAT]"
  !
  ! Build some data
  sic out gag_scratch:demo-accept-array.dat
  for i 1 to 8
    say '(i-1)*10' '(i-1)*10+1' '(i-1)*10+2' '(i-1)*10+3' '(i-1)*10+4' /format i4 i4 i4 i4 i4
  next
  sic out
  ! type gag_scratch:demo-accept-array.dat
  !
  ! No /FORMAT
  define real r4[5,8]
  accept r4 /array gag_scratch:demo-accept-array.dat
  ! Check values
  for i 1 to 8
    for j 1 to 5
      if r4[j,i].ne.'(i-1)*10+(j-1)' then
        message e demo-accept-array "Error reading file:"
        type gag_scratch:demo-accept-array.dat
        for k 1 to 8
          examine r4['k']
        next k
        return error
      endif
    next j
  next i
  !
  ! With adapted /FORMAT
  define integer i4[5,8]
  accept i4 /array gag_scratch:demo-accept-array.dat  /format "5(i4)"
  ! Check values
  for i 1 to 8
    for j 1 to 5
      if i4[j,i].ne.'(i-1)*10+(j-1)' then
        message e demo-accept-array "Error reading file:"
        type gag_scratch:demo-accept-array.dat
        for k 1 to 8
          examine i4['k']
        next k
        return error
      endif
    next j
  next i
  !
  sic delete gag_scratch:demo-accept-array.dat
  !
end procedure demo-accept-array
!
begin procedure demo-accept-column-noformat
  !
  message i demo-accept-array "Checking ACCEPT /COLUMN (no /FORMAT)"
  !
  ! Build some data with comment lines
  define integer nline
  let nline 8
  sic out gag_scratch:demo-accept-column.dat
  for i 1 to nline
    say "Hello"'i' '(i-1)*10+1' '(i-1)*10+2' '(i-1)*10+3.5' '(i-1)*10+4.5'  -
      /format A8 i4 i4 F8.2 F9.3
    if (i.eq.3)  say "! Some comment"
    if (i.eq.5)  say " "  ! A blank line
  next
  sic out
  ! type gag_scratch:demo-accept-column.dat
  !
  ! Check reading with no /FORMAT
  define character*20 c[5]  ! Skip reading 2 first lines and last one, less 2 comment lines
  define real  r /like c  ! Mismatch type on purpose for column #3
  define double d /like c
  accept c * r * d /column gag_scratch:demo-accept-column.dat /line 3 9
  ! Check the values
  for j 1 to 5
    if r[j].ne.'(j+1)*10+2'.or.d[j].ne.'(j+1)*10+4.5' then
      message e demo-accept-column "Error reading file:"
      type gag_scratch:demo-accept-column.dat
      examine c r d
      return error
    endif
  next
  del /var c r d
  !
  sic delete gag_scratch:demo-accept-column.dat
  !
end procedure demo-accept-column-noformat
!
begin procedure demo-accept-column-format
  !
  message i demo-accept-array "Checking ACCEPT /COLUMN /FORMAT"
  !
  ! Check with /FORMAT
  ! Build some data without comment lines
  define integer nline
  let nline 8
  sic out gag_scratch:demo-accept-column.dat
  for i 1 to nline
    say "Hello"'i' '(i-1)*10+1' '(i-1)*10+2' '(i-1)*10+3.5' '(i-1)*10+4.5'  -
      /format A8 i4 i4 F8.2 F9.3
  next
  sic out
  ! type gag_scratch:demo-accept-column.dat
  !
  define integer i[5]  ! Correct type for column 3
  define double d /like i
  ! Note that we use format "F4.0" for reading the integer column,
  ! because internal code reads in double precision floats and
  ! then converts back to integer...
  accept i d /column gag_scratch:demo-accept-column.dat /line 3 7 -
    /format 8X,4X,F4.0,8X,F9.3
  ! Check the values
  for j 1 to 5
    if i[j].ne.'(j+1)*10+2'.or.d[j].ne.'(j+1)*10+4.5' then
      message e demo-accept-column "Error reading file:"
      type gag_scratch:demo-accept-column.dat
      examine i d
      return error
    endif
  next
  del /var i d
  sic delete gag_scratch:demo-accept-column.dat
  !
end procedure demo-accept-column-format

! @ demo-accept-binary
@ demo-accept-array
@ demo-accept-column-noformat
@ demo-accept-column-format
