Simple Fortran Reading Values and Calculations

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
obeythepoof
Messages
1
Reaction score
0
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!
 
Physics news on Phys.org
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.