    
canc data/all

sp rm -f permutedBinaryTest.dat
list/i=1:48/form=stream/file=permutedBinaryTest.dat i
sp rm -f junk.dat
list/i=1:5/form=stream/file=junk.dat i


set mode ignore

!
! Following are intentional errors...

!
! Ultra large grid

canc data/all

def axis/x=1:1000000000:1 xax
def axis/y=1:2:1 yax
def axis/z=1:3:1 zax
def axis/t=1:4:1 tax
def grid/x=xax/y=yax/z=zax/t=tax mygrid

file/format=stream/var=num/grid=mygrid junk.dat
load num

!
! Semilarge grid
!

canc data/all

def axis/x=1:1000000000:1 xax
def axis/y=1:1:1 yax
def axis/z=1:1:1 zax
def axis/t=1:1:1 tax
def grid/x=xax/y=yax/z=zax/t=tax mygrid

file/format=stream/var=num/grid=mygrid junk.dat
load num

!
! Non-existent file

canc data/all

def axis/x=1:1:1 xax
def axis/y=1:2:1 yax
def axis/z=1:3:1 zax
def axis/t=1:4:1 tax
def grid/x=xax/y=yax/z=zax/t=tax mygrid

file/format=stream/var=num/grid=mygrid NoSuchFile.dat

! File that doesn't match specified size
file/format=stream/var=num/grid=mygrid junk.dat
load num

! Try listing with V permutation (disable: hangs Ferret)
!list/clobber/file=foobar.dat/form=str/order=badsyntax/i=1:100 i

! Try reading in with V permutation for non-stream data
file/var=num/order=vxyzt/grid=mygrid junk.dat

! Try /type flag with non-stream data
file/type=i2/grid=mygrid junk.dat

! Try /swap flag with non-stream data
file/type=i2/grid=mygrid junk.dat

! Try bad type flag
file/var=num/type=i3/grid=mygrid/form=stream junk.dat

! Try list of types that is smaller than list of variables
file/var=num,num1,num2/type=i2,i1/form=stream junk.dat

canc dat/all
canc mode ignore

!!OK, load file in 'normal order'
file/format=str/var=num,num1/grid=mygrid/order=xyztv permutedBinaryTest.dat
list num
list num1


!---------- A few tests for single-precision, integer, short, byte

! testing real*4 write and read-back
sp rm -f permutedBinaryTest_r4.dat
list/i=1:48/form=stream/file=permutedBinaryTest_r4.dat/outtype=float i

file/format=str/var=num,num1/type=r4/grid=mygrid/order=xyztv permutedBinaryTest_r4.dat
list num
list num1
cancel data 2

! testing integer*4 write and read-back
sp rm -f permutedBinaryTest_int.dat
list/i=1:48/form=stream/file=permutedBinaryTest_int.dat/outtype=int i

file/format=str/var=num,num1/type=i4/grid=mygrid/order=xyztv permutedBinaryTest_int.dat
list num
list num1
cancel data 2

! testing short  write and read-back
sp rm -f permutedBinaryTest_short.dat
list/i=1:48/form=stream/file=permutedBinaryTest_short.dat/outtype=short i

file/format=str/var=num,num1/type=i2/grid=mygrid/order=xyztv permutedBinaryTest_short.dat
list num
list num1
cancel data 2

! testing byte write and read-back
sp rm -f permutedBinaryTest_byte.dat
list/i=1:48/form=stream/file=permutedBinaryTest_byte.dat/outtype=byte i

file/format=str/var=num,num1/type=i1/grid=mygrid/order=xyztv permutedBinaryTest_byte.dat
list num
list num1
cancel data 2
!----------

!! Load file w/o order qualifier (should be same as above)
file/format=str/var=num,num1/grid=mygrid/order=xyztv permutedBinaryTest.dat
list num
list num1


!! Permute tzyxv
file/format=str/var=num,num1/grid=mygrid/order=tzyxv permutedBinaryTest.dat
list num
list num1

!!Try permuted v
file/format=str/var=num,num1/grid=mygrid/order=vxyzt permutedBinaryTest.dat
list num
list num1

!! Test stuff for different data types (files previously generated by matlab)
file/format=str/var=num,num1/grid=mygrid/type=i1 byte.dat
list num1

file/format=str/var=num,num1/grid=mygrid/type=i2 short.dat
list num1

file/format=str/var=num,num1/grid=mygrid/type=i4 int.dat
list num1

file/format=str/var=num,num1/grid=mygrid/type=r4 float.dat
list num1

file/format=str/var=num,num1/grid=mygrid/type=r8 double.dat
list num1


!! Test swapped
file/format=str/var=num,num1/grid=mygrid/swap/type=i1 byteSwapped.dat
list num1

file/format=str/var=num,num1/grid=mygrid/swap/type=i2 shortSwapped.dat
list num1

file/format=str/var=num,num1/grid=mygrid/swap/type=i4 intSwapped.dat
list num1

file/format=str/var=num,num1/grid=mygrid/swap/type=r4 floatSwapped.dat
list num1

file/format=str/var=num,num1/grid=mygrid/swap/type=r8 doubleSwapped.dat
list num1

! Test skip
!file/format=str/var=num,num1/grid=mygrid/type=r8/skip=4/swap skip.dat
! For double-precision Ferret, /skip=4 stops with error, 
! get correct result with /skip=2 (??)
file/format=str/var=num,num1/grid=mygrid/type=r8/skip=2/swap skip.dat
list num1


! Try list of types
file/format=str/var=num,num1/grid=mygrid/type=r8,i1 twoType.dat
list num
list num1

! Grand finale of xyvzt permutation with r4,i2 types
file/format=str/var=num,num1/grid=mygrid/type=r4,i2/order=xyvzt finale.dat
list num
list num1
