Last modified: Tue, 06/21/2016 - 03:36
Demonstration of binary stream file reading
Below is an annotated version of the scriptbinary_read_demo.jnl
yes? go/help binary_read_demo
Create temporary file consisting of REAL*4 values 0:47 and create sample grid for this file
yes? def sym file sDemoPermutedBinaryTest.dat
yes? sp rm -f ($file)
!-> sp rm -f sDemoPermutedBinaryTest.dat
yes? list/i=1:48/form=stream/file=($file) i-1
!-> list/i=1:48/form=stream/file=sDemoPermutedBinaryTest.dat i-1
LISTing to file sDemoPermutedBinaryTest.dat
yes? canc data/all
yes? def axis/x=1:1:1 xax
yes? def axis/y=1:2:1 yax
yes? def axis/z=1:3:1 zax
yes? def axis/t=1:4:1 tax
yes? def grid/x=xax/y=yax/z=zax/t=tax mygrid
Now load the file in "normal order." The first variable (num) should contain the values 0:23, and the second variable will contain thevalues 24:47
yes? file/format=stream/var=num,num1/grid=mygrid ($file)
!-> SET DATA/EZ/format=stream/var=num,num1/grid=mygrid sDemoPermutedBinaryTest.dat
yes? list num
NUM
X: 1
DATA SET: ./sDemoPermutedBinaryTest.dat
1 2
1 2
---- L:1 T: 1
1 / 1: 0.00 1.00
2 / 2: 2.00 3.00
3 / 3: 4.00 5.00
---- L:2 T: 2
1 / 1: 6.00 7.00
2 / 2: 8.00 9.00
3 / 3: 10.00 11.00
---- L:3 T: 3
1 / 1: 12.00 13.00
2 / 2: 14.00 15.00
3 / 3: 16.00 17.00
---- L:4 T: 4
1 / 1: 18.00 19.00
2 / 2: 20.00 21.00
3 / 3: 22.00 23.00
yes? list num1
NUM1
X: 1
DATA SET: ./sDemoPermutedBinaryTest.dat
1 2
1 2
---- L:1 T: 1
1 / 1: 24.00 25.00
2 / 2: 26.00 27.00
3 / 3: 28.00 29.00
---- L:2 T: 2
1 / 1: 30.00 31.00
2 / 2: 32.00 33.00
3 / 3: 34.00 35.00
---- L:3 T: 3
1 / 1: 36.00 37.00
2 / 2: 38.00 39.00
3 / 3: 40.00 41.00
---- L:4 T: 4
1 / 1: 42.00 43.00
2 / 2: 44.00 45.00
3 / 3: 46.00 47.00
Now the file will be loaded and permuted. In the following example, the order is tzyx instead of the default of xyzt
yes? file/format=stream/var=num,num1/grid=mygrid/order=tzyx ($file)
!-> SET DATA/EZ/format=stream/var=num,num1/grid=mygrid/order=tzyx sDemoPermutedBinaryTest.dat
yes? list num
NUM
X: 1
DATA SET: ./sDemoPermutedBinaryTest.dat
1 2
1 2
---- L:1 T: 1
1 / 1: 0.00 12.00
2 / 2: 4.00 16.00
3 / 3: 8.00 20.00
---- L:2 T: 2
1 / 1: 1.00 13.00
2 / 2: 5.00 17.00
3 / 3: 9.00 21.00
---- L:3 T: 3
1 / 1: 2.00 14.00
2 / 2: 6.00 18.00
3 / 3: 10.00 22.00
---- L:4 T: 4
1 / 1: 3.00 15.00
2 / 2: 7.00 19.00
3 / 3: 11.00 23.00
yes? list num1
NUM1
X: 1
DATA SET: ./sDemoPermutedBinaryTest.dat
1 2
1 2
---- L:1 T: 1
1 / 1: 24.00 36.00
2 / 2: 28.00 40.00
3 / 3: 32.00 44.00
---- L:2 T: 2
1 / 1: 25.00 37.00
2 / 2: 29.00 41.00
3 / 3: 33.00 45.00
---- L:3 T: 3
1 / 1: 26.00 38.00
2 / 2: 30.00 42.00
3 / 3: 34.00 46.00
---- L:4 T: 4
1 / 1: 27.00 39.00
2 / 2: 31.00 43.00
3 / 3: 35.00 47.00
Variables can also be part of the permutation. The 'v' option can be used in the order qualifier. In the following example, the order is vxyzt
file/format=stream/var=num,num1/grid=mygrid/order=vxyzt ($file)
!-> SET DATA/EZ/format=stream/var=num,num1/grid=mygrid/order=vxyzt sDemoPermutedBinaryTest.dat
list num
NUM
X: 1
DATA SET: ./sDemoPermutedBinaryTest.dat
1 2
1 2
---- L:1 T: 1
1 / 1: 0.00 2.00
2 / 2: 4.00 6.00
3 / 3: 8.00 10.00
---- L:2 T: 2
1 / 1: 12.00 14.00
2 / 2: 16.00 18.00
3 / 3: 20.00 22.00
---- L:3 T: 3
1 / 1: 24.00 26.00
2 / 2: 28.00 30.00
3 / 3: 32.00 34.00
---- L:4 T: 4
1 / 1: 36.00 38.00
2 / 2: 40.00 42.00
3 / 3: 44.00 46.00
list num1
NUM1
X: 1
DATA SET: ./sDemoPermutedBinaryTest.dat
1 2
1 2
---- L:1 T: 1
1 / 1: 1.00 3.00
2 / 2: 5.00 7.00
3 / 3: 9.00 11.00
---- L:2 T: 2
1 / 1: 13.00 15.00
2 / 2: 17.00 19.00
3 / 3: 21.00 23.00
---- L:3 T: 3
1 / 1: 25.00 27.00
2 / 2: 29.00 31.00
3 / 3: 33.00 35.00
---- L:4 T: 4
1 / 1: 37.00 39.00
2 / 2: 41.00 43.00
3 / 3: 45.00 47.00
sp rm -f ($file)
!-> sp rm -f sDemoPermutedBinaryTest.dat