Re: Insert string at the first line of a file.
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Re: Insert string at the first line of a file.         


Author: tianyf
Date: Jul 22, 2007 08:02

On Jul 20, 6:52 pm, ima...@freenet.de wrote:
> Hello,
>
> I want to insert a string or a line at the first line of an existing
> file. Therefore I used the REWIND command or POSITION= clause with
> value 'REWIND' in the OPEN-command to get to the first line of the
> file. But when I insert the line the whole file is overwritten and
> contains only the new line.
>
> I'm using the Fortran free format, my OS is Linux and intel is the
> fortran compiler.
>
> Thanks in advance!
>
> The neccessary cutout of my code:
>
> WRITE(6,*)'Input file?'
> READ(6,*)filename
> WRITE(6,*)'Insert file?'
> READ(6,*)insert ...
Show full article (1.21Kb)
5 Comments
Re: Insert string at the first line of a file.         


Author: Louis Krupp
Date: Jul 22, 2007 08:25

tianyf@gmail.com wrote:
> On Jul 20, 6:52 pm, ima...@freenet.de wrote:
>> Hello,
>>
>> I want to insert a string or a line at the first line of an existing
>> file. Therefore I used the REWIND command or POSITION= clause with
>> value 'REWIND' in the OPEN-command to get to the first line of the
>> file. But when I insert the line the whole file is overwritten and
>> contains only the new line.
>>
>> I'm using the Fortran free format, my OS is Linux and intel is the
>> fortran compiler.
>>
>> Thanks in advance!
>>
>> The neccessary cutout of my code:
>>
>> WRITE(6,*)'Input file?'
>> READ(6,*)filename
>> WRITE(6,*)'Insert file?' ...
Show full article (1.66Kb)
no comments
Re: Insert string at the first line of a file.         


Author: Gary Scott
Date: Jul 22, 2007 09:26

Louis Krupp wrote:
> tianyf@gmail.com wrote:
>
>> On Jul 20, 6:52 pm, ima...@freenet.de wrote:
>>
>>> Hello,
>>>
>>> I want to insert a string or a line at the first line of an existing
>>> file. Therefore I used the REWIND command or POSITION= clause with
>>> value 'REWIND' in the OPEN-command to get to the first line of the
>>> file. But when I insert the line the whole file is overwritten and
>>> contains only the new line.
>>>
>>> I'm using the Fortran free format, my OS is Linux and intel is the
>>> fortran compiler.
>>>
>>> Thanks in advance!
>>>
>>> The neccessary cutout of my code:
>>> ...
Show full article (2.18Kb)
no comments
Re: Insert string at the first line of a file.         


Author: Dr Ivan D. Reid
Date: Jul 22, 2007 11:58

On Sun, 22 Jul 2007 11:26:02 -0500, Gary Scott sbcglobal.net>
wrote in newssvr23.news.prodigy.net>:
> Louis Krupp wrote:
>> You can do that now ... in Perl. You can read a file into an array of
>> lines, you can insert lines into the array, you can delete lines from
>> the array, and you can write it all back to a new file, all in a few
>> lines of code. There's no point in trying to do absolutely *everything*
>> in Fortran if you can avoid it.
> ...or REXX or Python or Ruby or Expect or EXEC2 or VOS JCL or even
> Script/GML
>> Just don't try to do number crunching in Perl.

Or python it would seem -- tomorrow I have to rewrite an O(N4)
ROOT histogram comparison subroutine in something a bit faster than python.
860 secs for two 100x100 histos
-- I didn't wait for the 200x200 case.

--
Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
KotPT -- "for stupidity above and beyond the call of duty".
no comments
Re: Insert string at the first line of a file.         


Author: jwm
Date: Jul 23, 2007 08:55

On Jul 22, 9:02 am, "tia...@gmail.com" gmail.com> wrote:
> How about writing a non-standard Fortran routine
> "textfile_insert_lines(file,line,str_to_insert)"? To make sure it
> works also in Windows platform, I prefer to using loops to read and
> write files line by line.
>
> I do not have this kind of needs now (but maybe some time in the
> future). So, I'd like to receive such a copy if there is one. :)

Right now, I don't have the need of such routine as well, but I just
wrote it...

program insert_string
!COMMAND LINE: insert_string FILE STRING LINE

implicit none

integer :: nArgs = 3, line, i, len, status
character(50) :: ErrString
character(LEN = 260), allocatable :: Arg(:)

nArgs = COMMAND_ARGUMENT_COUNT()
if (nArgs /= 3) stop ' The number of arguments is wrong'

allocate (Arg(nArgs))
Show full article (4.32Kb)
no comments
Re: Insert string at the first line of a file.         


Author: tianyf
Date: Jul 23, 2007 23:31

On Jul 23, 11:55 pm, jwm gmail.com> wrote:
> On Jul 22, 9:02 am, "tia...@gmail.com" gmail.com> wrote:
>
>> How about writing a non-standard Fortran routine
>> "textfile_insert_lines(file,line,str_to_insert)"? To make sure it
>> works also in Windows platform, I prefer to using loops to read and
>> write files line by line.
>
>> I do not have this kind of needs now (but maybe some time in the
>> future). So, I'd like to receive such a copy if there is one. :)
>
> Right now, I don't have the need of such routine as well, but I just
> wrote it...
>
> program insert_string
> !COMMAND LINE: insert_string FILE STRING LINE
>
> implicit none
>
> integer :: nArgs = 3, line, i, len, status ...
Show full article (4.81Kb)
no comments