Re: append to the first line of a text file.... [message #74432] |
Sat, 15 January 2011 05:46 |
ben.bighair
Messages: 221 Registered: April 2007
|
Senior Member |
|
|
On 1/14/11 2:01 PM, George Millward wrote:
>
> I guess I'm just going to have to write a routine to do what I want
> ...something like reading all the current data into a buffer - write
> the new data - then append the buffer onto the new data.
> ...shouldn't be too hard - I was just wondering if there was a
> keyword.
>
Hi,
If you decide to use the buffer approach, then you might want to
consider something like Mike Galloy's MGArrayList.
http://michaelgalloy.com/2006/04/24/collection-package-mgarr aylist.html
It operates just like IDL_Container but works for any data type. It
could be that the new List() thingy in IDL 8 does this kind of stuff,
but I am leashed to IDL 7.1 so I wouldn't know.
Cheers,
Ben
|
|
|
Re: append to the first line of a text file.... [message #74433 is a reply to message #74432] |
Sat, 15 January 2011 00:48  |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
On 14 jan, 20:01, George Millward <george.millw...@noaa.gov> wrote:
> On Jan 14, 10:34 am, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> George Millward writes:
>>> I am wanting to 'append' an ascii file - but instead of appending the
>>> new data to the bottom
>>> I want the new data to be at the top of the file.
>
>>> Does anyone have any suggestions ?
>
>> Have you tried positioning the file pointer to the
>> beginning of the file with POINT_LUN? Worth a try,
>> I guess. You may have to include your own carriage
>> return.
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> David,
>
> Yes, tried that - it just overwrites the first line - same as doing
> openu and printf without /append
>
> ie,
>
> openu, /append
> point_lun, 0
> printf
>
> is the same as:
>
> openu
> printf
>
> At least I think so.
>
> I guess I'm just going to have to write a routine to do what I want
> ...something like reading all the current data into a buffer - write
> the new data - then append the buffer onto the new data.
> ...shouldn't be too hard - I was just wondering if there was a
> keyword.
>
> Thanks anyway.
>
> George.- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -
What about:
new = some array of strings
old = strarr(file_lines(filename))
openu, lun, /GET_LUN, filename
readf, lun, old
point_lun, lun, 0
printf, lun, new, old
free_lun, lun
You might as well replace calling of the "file_lines" function by a
"while ~eof(lun) do" construct or by a call to "skip_lun" function.
|
|
|
Re: append to the first line of a text file.... [message #74435 is a reply to message #74433] |
Fri, 14 January 2011 11:01  |
George Millward
Messages: 29 Registered: February 2000
|
Junior Member |
|
|
On Jan 14, 10:34 am, David Fanning <n...@dfanning.com> wrote:
> George Millward writes:
>> I am wanting to 'append' an ascii file - but instead of appending the
>> new data to the bottom
>> I want the new data to be at the top of the file.
>
>> Does anyone have any suggestions ?
>
> Have you tried positioning the file pointer to the
> beginning of the file with POINT_LUN? Worth a try,
> I guess. You may have to include your own carriage
> return.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
David,
Yes, tried that - it just overwrites the first line - same as doing
openu and printf without /append
ie,
openu, /append
point_lun, 0
printf
is the same as:
openu
printf
At least I think so.
I guess I'm just going to have to write a routine to do what I want
...something like reading all the current data into a buffer - write
the new data - then append the buffer onto the new data.
...shouldn't be too hard - I was just wondering if there was a
keyword.
Thanks anyway.
George.
|
|
|
Re: append to the first line of a text file.... [message #74436 is a reply to message #74435] |
Fri, 14 January 2011 09:34  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
George Millward writes:
> I am wanting to 'append' an ascii file - but instead of appending the
> new data to the bottom
> I want the new data to be at the top of the file.
>
> Does anyone have any suggestions ?
Have you tried positioning the file pointer to the
beginning of the file with POINT_LUN? Worth a try,
I guess. You may have to include your own carriage
return.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|