Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: modify data...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 9 Topic 8166 of 8774
Post > Topic >>

Re: modify data at a specific line and columns

by e p chandler <epc8@[EMAIL PROTECTED] > Apr 23, 2008 at 04:22 AM

On Apr 23, 6:08=A0am, elijah <mily...@[EMAIL PROTECTED]
> wrote:
> =A0 =A0 =A0 program main
> =A0 =A0 =A0 =A0 =A0integer ln
> =A0 =A0 =A0 =A0 =A0real =A0 =A0newval,oldval
> =A0 =A0 =A0 =A0 =A0ln=3D178
> =A0 =A0 =A0 =A0 =A0open(unit=3D10,file=3D'file.txt',
> =A0 =A0 =A0& =A0 =A0 =A0
=A0status=3D'old',form=3D'FORMATTED',access=3D'se=
quential')
> =A0 =A0 =A0 =A0 =A0rewind 10
> =A0 =A0 =A0 =A0 =A0do n=3D1,ln-1,1
> =A0 =A0 =A0 =A0 =A0 =A0 if(n.eq.ln)then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0read(10,20)oldval
> =A0 =A0 =A0 =A0 =A0 =A0 endif
> =A0 =A0 =A0 =A0 =A0enddo
> =A0 =A0 =A0 =A0 =A0write(*,*)'Old value was'
> =A0 =A0 =A0 =A0 =A0write(*,20)oldval
> =A0 =A0 =A0 =A0 =A0do n=3D1,ln-1,1
> =A0 =A0 =A0 =A0 =A0 =A0 if(n.eq.ln)then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0write(10,20),newval
> =A0 =A0 =A0 =A0 =A0 =A0 endif
> =A0 =A0 =A0 =A0 =A0enddo
> =A0 =A0 =A0 =A0 =A0write(*,*)'New value is'
> =A0 =A0 =A0 =A0 =A0write(*,20)newval
> =A0 =A020 =A0 =A0format(10x,f10.3)
> =A0 =A0 =A0 =A0 =A0close(10)
> =A0 =A0 =A0 end program

You can not both read and write a sequential file at the same time.
You can read ... modify ... write a direct access file, but this type
of file access requires a fixed record length.

> in the above program I would like to modify the columns 11-20 in line
> 178 of "file.txt". Text file contains lines of different lengths,
> character strings, floating point numbers etc.

1. The usual way to handle this is to use two files. Copy lines as is
from old file to new file. Read the target line, modify it, write it
to the new file. Copy the rest of the source file to the destination
file. Delete the old source file. Rename the destination file.

2. Fortran is not the way I prefer to handle these text modification
tasks. If you only have one line of data to modify, why not use a text
editor and do it manually? Otherwise any one of a number of scripting
languages would be better choices for this task.

3. Without a better idea of what defines a "column", it is difficult
to solve your task.

> It seems that I am unable to locate ****perly the columns and/or the
> line.
> Any help will be much appreciated.

4. Search this newsgroup for other postings on this topic. IMO "How do
I modify a data file, in place?" has joined the ranks of the FAQ in
this newsgroup.

-- e
 




 9 Posts in Topic:
modify data at a specific line and columns
elijah <milyas7@[EMAIL  2008-04-23 03:08:07 
Re: modify data at a specific line and columns
e p chandler <epc8@[EM  2008-04-23 04:22:07 
Re: modify data at a specific line and columns
elijah <milyas7@[EMAIL  2008-04-23 04:47:27 
Re: modify data at a specific line and columns
Arjen Markus <arjen.ma  2008-04-23 04:54:49 
Re: modify data at a specific line and columns
e p chandler <epc8@[EM  2008-04-23 05:10:22 
Re: modify data at a specific line and columns
elijah <milyas7@[EMAIL  2008-04-23 09:54:08 
Re: modify data at a specific line and columns
e p chandler <epc8@[EM  2008-04-23 10:51:43 
Re: modify data at a specific line and columns
"James Van Buskirk&q  2008-04-23 12:01:33 
Re: modify data at a specific line and columns
elijah <milyas7@[EMAIL  2008-04-24 03:32:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 23:34:08 CDT 2008.