Simple Fortran Reading Values and Calculations

  • Fortran
  • Thread starter obeythepoof
  • Start date
  • #1

Main Question or Discussion Point

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!
 

Answers and Replies

  • #2
minger
Science Advisor
1,495
2
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:
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.
 

Related Threads on Simple Fortran Reading Values and Calculations

  • Last Post
Replies
9
Views
30K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
5
Views
9K
Replies
12
Views
13K
  • Last Post
Replies
8
Views
1K
  • Last Post
Replies
4
Views
2K
Replies
20
Views
32K
Replies
2
Views
10K
Replies
5
Views
4K
Top