Simple Fortran Reading Values and Calculations

In summary, the conversation is about self-teaching Fortran for a research position and developing a program that opens a file, reads a value, does calculations, and prints it into a new file. The steps involved include opening the data file, reading the desired value, defining a variable, performing a calculation, and printing the result in a new file. The speaker also mentions needing help with understanding the syntax for certain functions.
  • #1
obeythepoof
1
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
  • #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.
 

What is Fortran and how is it used in scientific computing?

Fortran is a high-level programming language that is commonly used in scientific computing. It is particularly well suited for numerical calculations and mathematical operations. Fortran is used to write code for simulations, data analysis, and other scientific applications.

How do I read values from a file in Fortran?

To read values from a file in Fortran, you can use the READ statement. This statement allows you to specify the format of the data and the variables where the data will be stored. You can also use the OPEN statement to open the file before reading from it.

What are the different types of data that can be read and stored in Fortran?

Fortran supports several data types, including integers, real numbers, and characters. You can also use arrays to store multiple values of the same data type. Additionally, Fortran has built-in support for complex numbers and logical values.

How can I perform calculations in Fortran?

Fortran has a wide range of mathematical functions and operators that allow you to perform calculations. These include basic arithmetic operations like addition, subtraction, multiplication, and division, as well as more advanced functions such as trigonometric, exponential, and statistical functions.

Can Fortran be used for parallel computing?

Yes, Fortran has features that make it suitable for parallel computing. This includes support for parallel programming models such as OpenMP and MPI, as well as built-in parallel constructs like DO concurrent loops and parallel array operations. These features allow Fortran programs to take advantage of multiple processors or cores for faster execution.

Similar threads

  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
571
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
4
Views
732
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
7K
Back
Top