Simple Fortran Reading Values and Calculations

Click For Summary
SUMMARY

The discussion focuses on developing a Fortran program to read data from a file named grpdatas_r500_108.tab, extract a specific value from the fourth column of the first row, perform calculations involving a variable fov, and output the results to a file called halo.108.reg. Key steps include using the OPEN, READ, and WRITE statements for file handling. The calculation performed is r200px = r200 * 1024 * 500. / fov / .73, which requires understanding the syntax and structure of Fortran programming.

PREREQUISITES
  • Basic understanding of Fortran syntax and structure
  • Familiarity with file handling in Fortran, including OPEN, READ, and WRITE statements
  • Knowledge of data types and variable declaration in Fortran
  • Ability to perform mathematical calculations and understand variable manipulation
NEXT STEPS
  • Study Fortran file handling techniques, focusing on OPEN, READ, and WRITE syntax
  • Learn about variable declaration and data types in Fortran
  • Research how to extract specific data from formatted files in Fortran
  • Explore advanced Fortran features such as unformatted read statements
USEFUL FOR

This discussion is beneficial for undergraduate students learning Fortran, researchers needing to manipulate data files, and anyone interested in performing calculations using Fortran programming.

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!
 
Technology 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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K