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

Fortran Reading data from a table file

  1. Dec 29, 2016 #1
    Hello
    I am very new to programming and fortran. I have a text file formatted the following way:

    Name Peter John Sally Joseph Luke Vader etc...
    age XXXX XXXX XXXX XXXX XXXX XXXX XXXX
    height XXXX XXXX XXXX XXXX XXXX XXXX XXXX
    weigh XXXX XXXX XXXX XXXX XXXX XXXX XXXX
    etc...​

    I want fortran to only read the data of the people I ask him to. If I ask for Luke and Sally, I want him to return their respective age, height and weight while assigning them to specific variables.

    I have played around with various do loops with if statements but I cant get it to work properly... I don't know how to do this. Can anyone help ?

    Thank you
     
    Last edited: Dec 29, 2016
  2. jcsd
  3. Dec 29, 2016 #2

    Borg

    User Avatar
    Gold Member

    It would help if you showed what you have attempted so far. Please use the code tags for your code also.
     
  4. Dec 29, 2016 #3

    jedishrfu

    Staff: Mentor

    You could also provide the steps you think need to be done in plain english to accomplish the task.

    Code (Text):

    0 ask for names you want to report on
    1 open file
    2 read line
    3 if line starts with name ...
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted