Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open and Modify an Input File in Fortran 90

Status
Not open for further replies.

golferadam

Technical User
Jun 30, 2003
1
US
I am new so let me begin by thanking in advance anyone that can help me.
I have a simple program that uses data files (contains integers and characters). I want to allow the user to modify the files (i.e. add new ID#s and ID Names). Here is an example of the input file:

5
1 ETHANE C2H6
2 PROPANE C3H8
3 ISOBUTANE C4H10
4 n-PENTANE C5H12
5 n-HEXANE C6H14

As you can see, the integer at the top (5) is the total number of ID#s in the input file. The first thing my code does is read that number. The new data will be assigned to the next higher integer (in this case, 6).
I need to advance to the end of the file and then write the new data. An example would be to advance to the 5th entry, and add a new line of data at the end:

5 n-HEXANE C6H14
6 TOLUENE C7H8 <--- New line

Then I want to update the number at the beginning of the file (in this case 5) and save the file over the old one.
Thanks.
 
Probably the easiest way is to
1) open with STATUS='OLD', read the data into memory and then close the file.
2) Get the new data from the user into memory
3) open with STATUS='REPLACE' and write the data from memory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top