Say I  have a data file in plain text, which starts with some lines that 
describe matrix sizes, etc, for the data that follows.  For example, the 
first line might be
9 2 2 1.3

To read this file, in C I would use something like this call to scanf:
scanf("%d%d%d%lf",&n,&nup,&ndn,&a);

How do I do this in julia?  There doesn't seem to be a simple, obvious way. 
 Of course, you can read the line as a string, and parse it using regular 
expressions, but this is much messier than the call to scanf.

Here is a solution:
getline() = readdlm(IOBuffer(readline()),Any) 

n,nup,ndn,a = getline()

This seems to work reliably.  (For example, it doesn't choke if there 
happen to be two spaces between some of the numbers.) 

It is also obscure and doesn't give any warnings if some of the types 
aren't what was expected. It also seems inefficient if you try to read a 
lot of data this way.

Questions:  Why isn't something like this (but better) built in to julia? 
 Is there some nice method that I've missed that does this better?  Can 
this getline() function be improved? 

Reply via email to