help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: textscan preserving all whitespace


From: Philip Nienhuis
Subject: Re: textscan preserving all whitespace
Date: Fri, 12 Sep 2014 09:21:44 -0700 (PDT)

rmales wrote
> Thanks to the two of you who have given prompt replies.  I tried them both
> as is, and did not get the needed results, both failed.   However, taking
> the suggestion of Philip Nienhuis to add the whitespace to the textscan,
> the resulting code below worked perfectly:
> 
> fid = fopen('ODOC');
> tot = textscan (fid, '%s', 'delimiter', '\n', 'whitespace', '');
> tot = tot{:};
> fclose(fid);
> 
> 
> I neglected to make clear in the original post that the file I am reading
> is mixed text and numeric, basically legacy from an old Fortran program.  
> 
> Here is what more of the file looks like.   The old matlab script I am
> converting is pulling information out of this, and is cognizant of the
> individual field positions in each line.   After I get all this done, I
> will certainly be proposing drastic changes to the approach to modernize
> it.
> 
> COMPUTATION OPTION ILINE=  1
> Alongshore gradient IQYDY=  0
> ILINE cross-shore lines are computed together
> 
> COMPUTATION OPTION IPROFL =  1
> Profile evolution is computed from Time = 0.0
> to Time =       18000.0  for NTIME =    5
> 
> NO ROLLER is included in computation
> 
> NO wave and current interaction included
> 
> WAVE OVERTOPPING, OVERFLOW AND SEEPAGE
> Runup wire height (m)                   RWH=    0.020
> Initial crest location for L=1           JCREST=   301
> Initial crest height (m) for L=1        RCREST=    8.000
> Swash velocity parameter              AWD=    1.600
> Output exceedance probability        EWD=    0.015
> 
> This is in addition to segments of the file that have the numeric
> formatting from my previous post.

Yes, this sort of files (chaotic header followed by neatly lined-up data
columns) is exactly what we use the textscan script for.

Yet I think Ben's 1st suggestion, followed by cell2mat(), could be faster
than textscan.
What you want in the end is a character array, as that allows easy isolation
of individual data columns (if needed followed by str2double).

If you were to change some procedures, I'd look at the FORTRAN program first
;-)
Although...  it looks like the file header can easily be parsed using regexp
- relying on "individual field positions" often turns out to be quite
fragile.

Philip




--
View this message in context: 
http://octave.1599824.n4.nabble.com/textscan-preserving-all-whitespace-tp4666470p4666480.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]