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

Simple Fortran Reading Values and Calculations

  1. Mar 10, 2010 #1
    I am trying to self-teach myself Fortran for an undergrad research position. A basic program that I am trying to develop is something will open a file, read a single value from a large table of data, do some calculations with it, and print it into a new file. I was hoping to get a little advice about how to approach this.

    Specifically I know I'm supposed to:
    1. Open a file called /.../grpdatas_r500_108.tab
    2. Read the radius, called r200, which is in the 4th column of the 1st row
    3. define fov, and it can be found in the .out files in the same directory as the above file
    4. Do the following calculation: r200px=r200*1024*500./fov/.73
    5. Print in a file called halo.108.reg

    I was hoping someone could explain to me some of the simple syntax as well, as I am having troubles understanding everything that goes in the parenthesis for OPEN, READ, WRITE, etc.

    Thanks a million to anyone who can help!
     
  2. jcsd
  3. Mar 11, 2010 #2

    minger

    User Avatar
    Science Advisor

    I'm not sure where this fov variable is (inside file or what), but here's a go without the header and variable declaration

    Code (Text):

    open(11,file='grpdatas_r500_108.tab', form='formatted')
    open(12,file='halo.108.reg',form='formatted')
    do i,1,nPts
      read(11,*) col1,col2,col3,r200
      r200px=r200*1024*500./fov/.73
      write(12,*) r200px
    end do
     
    Unformatted read statements can be quite helpful.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Simple Fortran Reading Values and Calculations
  1. Fortran read (Replies: 9)

  2. FORTRAN READ problems (Replies: 5)

  3. Read file in fortran (Replies: 2)

Loading...