Need Help with Writing Fortran95 Procedure

Click For Summary

Discussion Overview

The discussion revolves around writing a procedure in Fortran95 to read data from multiple input files, perform calculations, and write the results to a single output file. Participants are seeking help with file handling and data processing in Fortran.

Discussion Character

  • Technical explanation
  • Homework-related
  • Exploratory

Main Points Raised

  • One participant describes their goal of reading seven files with the same format and performing calculations based on the data from each file.
  • Another participant suggests a method for opening and writing to multiple files, providing a basic structure for file operations in Fortran.
  • A later reply clarifies the intention to read from each file sequentially and produce separate blocks of calculations in the output file.
  • Some participants express confusion about the data format provided, questioning the relationships between the columns and the meaning of the values.
  • There is a suggestion to initialize arrays for data storage and to use a loop for reading data, but no consensus on the exact implementation is reached.

Areas of Agreement / Disagreement

Participants generally agree on the need to read multiple files and perform calculations, but there is no consensus on the specific implementation details or the interpretation of the data format.

Contextual Notes

Participants have not resolved the assumptions about the data structure or the specific calculations needed. There are also unresolved questions regarding the relationships between the values in the provided data samples.

anna2011
Messages
3
Reaction score
0
Fortran95 HELP!

Hi everyone,

I have problem with writing a procedure in Fortran. I'm a newbie so any help will be appreciated.
So the problem is as follow: I have written a program which reads some data from input file and then calculates some stuff using read values. Now what i have to do is to open more then just one file (seven actually) which have the same format as the previous one, the same extention but different names and the text string is not composed of the same number of letters, just the same extension. When i open all the files then i have to use the procedure i wrote and write all the data in one file.
Can anyone tell me how I can do that, I'm getting crazy becuase of that...

Thanks, in advance
 
Technology news on Phys.org


I think opening and writing is done as follows
Forgive me if I misunderstand your question

open(1,file='file1')
open(2,file='file2')
...
open(7,file='file7')

write(1) variable1
write(2) variable2
...
write(7) variable7

close(1,2,3,4,5,6,7)
 
Last edited:


Hi,
Thanks for quick reply.
So the idea is to read seven files, one by one, read from those files needed values and use the same procedure to calculate some values based on data read from each input file. And then in output file i should have seven separate blocks of calculations, for each input file.

Is this makes things more clear?
 


anna2011 said:
Hi,
Thanks for quick reply.
So the idea is to read seven files, one by one, read from those files needed values and use the same procedure to calculate some values based on data read from each input file. And then in output file i should have seven separate blocks of calculations, for each input file.

Is this makes things more clear?

Hi anna :smile: I am new to FORTRAN as well, but I think you need to do something like this:

1) Initialize some arrays to store the data in
2) Open all of the files
3) Use a "DO" loop to read all of the data into the arrays
4) Close all files

We can help you out, but it would be helpful if you could provide a short sample of one of the 7 files you wish to get data from. Just copy paste the first 5-6 rows of data from a file and wrap them in the "Code" tags located above by using the [URL]http://i12.photobucket.com/albums/a220/saladsamurai/codetags.jpg[/URL] button (this will preserve the formatting).
 
Last edited by a moderator:


Code:
C1        2.1419561858E+00  2.1419561858E+00  4.2839123717E+00  0.0000000000E+00
O2        4.5849316264E+00  4.5849316264E+00  9.1698632528E+00  0.0000000000E+00
N3        4.0198698574E+00  4.0198698574E+00  8.0397397149E+00  0.0000000000E+00
H4        3.0070127032E-01  3.0070127032E-01  6.0140254064E-01  0.0000000000E+00
H5        3.1607842405E-01  3.1607842405E-01  6.3215684811E-01  0.0000000000E+00
N6        4.0198675021E+00  4.0198675021E+00  8.0397350042E+00  0.0000000000E+00
H7        3.0070127037E-01  3.0070127037E-01  6.0140254074E-01  0.0000000000E+00
H8        3.1606930741E-01  3.1606930741E-01  6.3213861481E-01  0.0000000000E+00

hope its enough.

Thanks a lot :)))
 


anna2011 said:
Code:
C1        2.1419561858E+00  2.1419561858E+00  4.2839123717E+00  0.0000000000E+00
O2        4.5849316264E+00  4.5849316264E+00  9.1698632528E+00  0.0000000000E+00
N3        4.0198698574E+00  4.0198698574E+00  8.0397397149E+00  0.0000000000E+00
H4        3.0070127032E-01  3.0070127032E-01  6.0140254064E-01  0.0000000000E+00
H5        3.1607842405E-01  3.1607842405E-01  6.3215684811E-01  0.0000000000E+00
N6        4.0198675021E+00  4.0198675021E+00  8.0397350042E+00  0.0000000000E+00
H7        3.0070127037E-01  3.0070127037E-01  6.0140254074E-01  0.0000000000E+00
H8        3.1606930741E-01  3.1606930741E-01  6.3213861481E-01  0.0000000000E+00

hope its enough.

Thanks a lot :)))
Hmm I'm afraid it's not enough. Could you explain what are those values for your program? These are the written values, the read ones?
Also they are weird (but might be right). For each molecule (or row I'd better say), the first column is equal to the second. And the 3rd column is worth 2 times the first. The last is always 0.

Sybren said:
I think opening and writing is done as follows
Forgive me if I misunderstand your question

open(1,file='file1')
open(2,file='file2')
...
open(7,file='file7')

write(1) variable1
write(2) variable2
...
write(7) variable7

close(1,2,3,4,5,6,7)
You forgot to read the files and do some calculations :)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K