comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Fast editing of text file?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Fast editing of text file? [message #44495] Tue, 14 June 2005 15:29
t_314159 is currently offline  t_314159
Messages: 2
Registered: June 2005
Junior Member
Hi,
I have a text file that I must access many times during program
execution (1000's of times, really!) and I *always* only need to change
the the text on the 12th line of the file. My question, how to
efficiently access and alter the text of ONLY the 12th line without
altering even a single space or comma on any of the rest of the lines?
And did I mention fast since i've got to loop through this many times?

For example:

--BEGIN FILE---
test file
A
0 1 0
4,5,1
[some text lines I'm not showing here, I'll show my 12th line next]
500, 0.02, 1.00587
[more text lines to the end of file]
--END FILE---

What I need to do is keep the file exactly as is (there's some weird
formatting of spaces, tabs, commas on different lines that a follow-on
old fortran program expects) EXCEPT for the 12th line where I need to
change those 3 #'s every time (I know that line is expected to be
comma+space delimeted).

The only thing I can think of is to:
openr, infile, inFileName, /get_lun;
create a new outfile for write;
loop through infile line by line writing directly to outfile up to, but
not including, the 12th line;
do a newline = strtrim(a,2) + ", " + strtrim(b,2) + ", " + strtrim(c,2)
where a, b, and c are int,float,or double values I need to write on
line 12;
writeu, outfile, newline
continue looping through infile writing lines 13 to EOF to outfile;
free_lun both infile and outfile;
delete the infile;
rename the outfile to the infile's old name;
call the model that works on that text file;
repeat 40,000 times with new values for a, b, c each time;

Is there a better way? Note that significant digits of a, b, c may
change each time so the formatting and # of places each takes will vary
each time. Next time the 3 numbers may be .3, 1000.00003, 0.

Thanks you for the help!!!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Buffer -> Window
Next Topic: Buffer -> Window

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 11:02:20 PDT 2025

Total time taken to generate the page: 0.96175 seconds