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 7 of 9 Topic 8166 of 8775
Post > Topic >>

Re: modify data at a specific line and columns

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

On Apr 23, 12:54=A0pm, elijah <mily...@[EMAIL PROTECTED]
> wrote:
> > So you want to replace the contents in print positions 11 to 20 with
> > something else? Again, you want to over-write the old data with the
> > new, leaving the length of the original line unchanged?
>
> yes that's what I want to do

Try something like this:

implicit none
character*200 s
integer ierr, n

n=3D0
open(10,file=3D'file.txt')
open(11,file=3D'file1.txt')
do
  read(10,'(a)',iostat=3Dierr) s
  if (ierr /=3D 0) exit
  n=3Dn+1
  if (n =3D=3D 178) s(11:20) =3D '1234567890'
  write(11,'(a)') trim(s)
end do
close(10)
close(11)
end

-------------
1. This is free format source code. Other features are
1a. Exit exits the DO ... END DO loop
1b. One line IF
1c. DO .. END DO loop - no index variable
 2. Several "magic" numbers & constants in program - adjust as needed.
-- 200 =3D maximum length of input line
-- 178 =3D target line to change
-- 11 =3D first print column to change
-- 20 =3D last print column to change
-- string literal =3D replace part of target with this
-- input and output file names
3. On input, lines are padded at the end with spaces up to 200
characters.
4. On output trim() removes trailing spaces, otherwise the output
would be 200 characters wide (+ end of line).
5. One possible GOTCHA - make sure that the replacement string is
exactly 10 characters long.
Fortran does not read or write variable length strings as does BASIC.
In BASIC, the length of a string depends on what is input.
Since your input lines are variable length, the program tries to
prserve this by assuming that the input file does not contain trailing
spaces.

HTH

-- 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 Mon Oct 13 3:04:33 CDT 2008.