Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran77-- retrieve data from large source

  1. Nov 18, 2016 #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.
  2. jcsd
  3. Nov 18, 2016 #2


    User Avatar

    Staff: Mentor

    You'll have to give more details about the structure of the file.
  4. Nov 18, 2016 #3
    The output file is as such:

    0.000000D00 0.000000D00...

    0.000000D00 0.000000D00...

    there are a total of 459 different chemical species with 124 different points of data.
  5. Nov 18, 2016 #4


    Staff: Mentor

    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.
  6. Nov 18, 2016 #5


    User Avatar
    Science Advisor
    Education Advisor

    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.
  7. Nov 18, 2016 #6


    User Avatar

    Staff: Mentor

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

    1 2 3 4 5
    6 7 8 9 10
    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")

    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.
  9. Nov 20, 2016 #8


    User Avatar
    Science Advisor

    There may be better tools than Fortran-77 for this.

    Consider using something simple like $ grep -A 1 CHEMA file*.dat
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted