Re: [Q] Skipping input

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: [Q] Skipping input

John C. Campbell-2

[hidden email] (Krzysztof Gozdziewski) writes...

| I have following problem: I want to read data from text file. The file
| is organized in such a wy, that in its first two lines there is some
| description, next  are some lines with numbers, next two lines
| of comments, numbers, comments, etc.

This is a common question and the answer (aside from using sed or awk
outside of Octave) is to use the C-style IO functions.  These
functions are completely flexible yet tedious to use.  If you are
processing lots of data files with the same format then the overhead
(your time spend coding) will be much smaller than if you have to
parse each data file differently.  I wrote some code that would use
'fgets' to get a string from a file, then I used 'sscanf' to scan that
string for strings and numbers.

The use of these functions (sscanf, fscanf, scanf, gets, printf,
sprintf, fprintf, getc, fseek, ftell, frewind, etc) is well documented
in Octave but you could also use your favorite C book to get the
flavor of these functions.

John

--------
John C. Campbell                    :  
[hidden email]                  :  
University of Texas-Austin          :  
Dept. of Chemical Engineering       :