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 the data from file

Tags:
  1. Mar 11, 2016 #1
    Hello, I have data in file and I want to read the data into variable in fortran to save memory caculation. I want to know: When I open file inputdata, whether fortran have any notices about the way it read data into variables? (like mathematica: each open file, we just read in the order anyway)
     
  2. jcsd
  3. Mar 11, 2016 #2

    jedishrfu

    Staff: Mentor

    You can find examples via google.

    Here's a tutorial on it:

    http://www.math.hawaii.edu/~hile/fortran/fort7.htm

    It also depends on the type of input file like if its a text file or a binary file file access would be somewhat different
    or if it was a netcdf file where you'd need to use netcdf apis to read/write to it.
     
  4. Mar 11, 2016 #3
    Thanks. In case, I have the data file like:
    1 2 3 4 5
    6 7 8 9 10
    4 5 1 5 8
    9 6 3 2 1
    7 4 2 1 13
    and I want to create the coeff A of equations system
    A= 1 2 3 5
    4 5 1 8
    9 6 3 1
    Whether or not I can take these data from the file by statement?
     
  5. Mar 11, 2016 #4

    Mark44

    Staff: Mentor

    Yes, this is pretty straightforward to do. What have you tried so far? You shouldn't expect us to write the code for you, though.
     
    Last edited: Mar 12, 2016
  6. Mar 11, 2016 #5
    No. I mean I am a new one in programing. So many concept in fortran I dont Know.
    I just want to know whether it can do that or not and How to do that. In my code, [A]= [1]+[2]+[3]+[4] so many matrices so that I try to find more about reading array data from file on webs.
     
    Last edited by a moderator: Mar 12, 2016
  7. Mar 12, 2016 #6

    Mark44

    Staff: Mentor

    It's not clear to me what you're trying to do. From what you show above, the pattern appears to be
    1. Read in the contents of a row, and store the 1st, 2nd, 3rd, and 5th item in the array, skipping the 4th item.
    2. Skip the next row.
    3. Repeat steps 1 and 2.

    However, the numbers you show in your array A don't follow this pattern when you get to the 4th row. Is that a mistake?
     
  8. Mar 13, 2016 #7
    I want to solve the equation system by fortran and Laplack subroutine. And the first thing to do is create the matrix coeff A. I think
    Thank. To be clear, my problem is solve equations system
    https://drive.google.com/file/d/0BwK2cNv1sXawbWx6N21LQXMtME0/view?usp=sharing [Broken]
    By the way, Can you give me a example about statement: skip the row while reading data from file and read the any rows from input file?
    Thanks a lot.
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      51.6 KB
      Views:
      30
    Last edited by a moderator: May 7, 2017
  9. Mar 13, 2016 #8

    jtbell

    User Avatar

    Staff: Mentor

    A read() statement normally reads one line from the file. To skip a line, simply use a read() statement that does not list any input variables:

    Code (Fortran):

          read (ifile, *)
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Fortran: reading the data from file
Loading...