As a slight optimization, you could note that string works by creating an
IOBuffer and printing the arguments into it, and then converting the result
to a string. Thus, you could skip the extra conversion to a string and back
by making the IOBuffer directly.


On Tuesday, August 12, 2014, Iain Dunning <iaindunn...@gmail.com> wrote:

> No need for macros!
> Its an interesting feature request, maybe open a Github issue so people
> can discuss it.
>
> I think your solution is not terrible, you could generalize it to
>
> readcell(f, nlines) = readdlm(IOBuffer(string([readline(f) for i in
> 1:nlines])))
>
> Then do something like
>
> f = open("mydata","r")
> cells = {}
> while !eof(f)
>   push!(cells, readcell(f, 3))
> end
> close(f)
>
>
>
> On Tuesday, August 12, 2014 10:40:24 AM UTC-4, Jarvist Moore Frost wrote:
>>
>> I’m writing a Julia parser to read in a large output from a Fortran
>> program which is essentially a load of concatenated matrices of differing
>> dimensions. It would be really useful to be able to do something along the
>> lines of readdlm(file,nlines=3) to pull in i.e. the 3x3 matrix you know
>> that follows.
>>
>> Currently I’m resorting to things like:
>>
>>     celltext=string(readline(f),readline(f),readline(f))
>>     cell=readdlm(IOBuffer(celltext))
>>
>> And this really doesn’t feel like a very elegant method (not helped as
>> neither readline nor readlines appear to accept ‘number of lines’ as an
>> argument).
>>
>> Am I missing the Julia way to do things here? Or should I start writing
>> @macros to expand to this level of nitty gritty?
>> ​
>>
>

Reply via email to