Fortran Fortran77-- retrieve data from large source

AI Thread Summary
The discussion revolves around extracting data from multiple output files generated by a chemical model of Titan's atmosphere, specifically focusing on sections labeled with chemical names like HC5N. The user is new to programming and seeks guidance on handling up to 1000 files containing data for 459 chemical species, each with 124 data points. Suggestions include researching Fortran commands such as OPEN, READ, and FORMAT to read the files. It is noted that if the data is primarily for post-processing or visualization, more modern tools may be preferable. The conversation emphasizes starting with simpler examples to grasp the necessary programming concepts before tackling the larger dataset. Additionally, using command-line tools like grep is suggested as an alternative for data extraction.
Carl Loomis-Anderson
Messages
6
Reaction score
1
I'm currently doing a chemical model of Titan's atmosphere and the simulation outputs several files (up to 1000) and I need to get an array of data out of them from a specific section labeled with a chemical name (i.e HC5N) that has an arbitrary number of values (usually above 100). I've seen this kind of question posted before however I'm new to programming and don't quite understand some of the jargon and the scope of previous posts that I've seen has been quite small.
 
Technology news on Phys.org
You'll have to give more details about the structure of the file.
 
  • Like
Likes BvU
The output file is as such:

CHEMA
0.000000D00 0.000000D00...

CHEMB
0.000000D00 0.000000D00...

there are a total of 459 different chemical species with 124 different points of data.
 
Carl Loomis-Anderson said:
however I'm new to programming and don't quite understand some of the jargon
What you're calling "jargon" is probably the syntax of the language. A program that you write will need to open up to 1000 files generated by the simulation, and read the data from them. I suggest you do some research on the Fortran OPEN statement, as well as the READ statement and the FORMAT statement.

After you have done those things, see what you can come up with for code, and we'll take a look.
 
Carl Loomis-Anderson said:
I'm currently doing a chemical model of Titan's atmosphere and the simulation outputs several files (up to 1000) and I need to get an array of data out of them from a specific section labeled with a chemical name (i.e HC5N) that has an arbitrary number of values (usually above 100).
So, the simulation code is in Fortran 77 and it produces those output files. It is not yet clear to me what you like to do with the arrays that you wish to extract. Do these arrays serve as input of other computational Fortran code or would you like to use them for visualization, for example?

The answer can be "both", of course, but I am just curious. If you like to use these arrays only for post-processing and visualization, there may be more modern and user friendly tools available.
 
Carl Loomis-Anderson said:
CHEMA
0.000000D00 0.000000D00...

CHEMB
0.000000D00 0.000000D00...

there are a total of 459 different chemical species with 124 different points of data.

So each one of CHEMA, CHEMB, etc. has exactly 124 numbers on the next line?
 
Put your problem on the back burner for a while and start with a simple file like:

mychema
1 2 3 4 5
mychemb
6 7 8 9 10
mychemc
11 12 13

Now type that in using Notepad (even better download Notepad++), save it as say myfile.txt. That's a start ok. Now, read up on the FORTRAN open and read commands and now put myfile.txt on the back burner with the other one. Now, instead, just work through the on-line examples I suspect they will have dealing with the open and read commands. Get those down, then apply what you've learned to then open and read myfile.txt. get to the point where you can read all of it, then use an if construct to pull out the mychemb record like (pseudo-code):

If (record=="mychemb")
{
mydata=read(myfile.txt)
}

Just get that much working where the data is in mydata. May need to process it further with type casting or whatever. The data may be in string format. Will need to know how to convert strings to numbers. Google that one as well. Just get the 6 7 8 9 10 working first then move on to your problem.
 
Carl Loomis-Anderson said:
The output file is as such:

CHEMA
0.000000D00 0.000000D00...

CHEMB
0.000000D00 0.000000D00...

there are a total of 459 different chemical species with 124 different points of data.
There may be better tools than Fortran-77 for this.

Consider using something simple like $ grep -A 1 CHEMA file*.dat
 

Similar threads

Replies
6
Views
2K
Replies
27
Views
7K
Replies
2
Views
3K
Replies
4
Views
16K
Replies
6
Views
3K
Replies
13
Views
4K
Replies
5
Views
3K
Replies
1
Views
18K
Back
Top