[REBOL] Re: Line reduction
From: larry:ecotope at: 5-Jul-2001 12:09
Hi Aaron,
You can avoid having to read all the rows of data by using open/direct and
skip. I made a small test file from the data in your post:
>> print read %test.r
1.093027 1.505329 0.826303
1.451725 1.226740 0.827948
1.698870 0.956003 0.829593
1.691551 0.693989 0.831238
1.792217 0.430279 0.832883
1.892038 0.167986 0.834528
1.919743 -0.092959 0.836173
1.093027 1.505329 0.826303
Then asuming you will want the the numbers in the file to be REBOL numbers
with each row in a block, you can do something like this:
>> out: make block! (size? %test.r) / 25 ;preset approx. size of block
== []
>> f: open/read/direct/lines %test.r ;avoids buffering
; f: skip f 1 will skip every other line
; if you just want the lines as text use "append out x" below
>> while [x: copy/part f 1][append/only out load to-string x f: skip f 1]
>> close f
>> print mold out
[[1.093027 1.505329 0.826303
] [1.69887 0.956003 0.829593
] [1.792217 0.430279 0.832883
] [1.919743 -9.2959E-2 0.836173
]]
>>
Let me know if it is any faster.
HTH
-Larry