Fortran Simple Fortran Reading Values and Calculations

AI Thread Summary
The discussion focuses on self-teaching Fortran for an undergraduate research project, specifically developing a program to read data from a file, perform calculations, and output results to a new file. The user is attempting to open a file named "grpdatas_r500_108.tab" to read the radius value (r200) from the fourth column of the first row. They also need to define a variable called "fov," which is located in .out files within the same directory. The calculation involves converting r200 to r200px using a specific formula and then writing the result to a file named "halo.108.reg." The user seeks clarification on the syntax for file operations in Fortran, particularly for the OPEN, READ, and WRITE statements. They provide a code snippet but express uncertainty about the fov variable's location and the overall syntax structure. The mention of unformatted read statements suggests an interest in exploring different data reading methods for efficiency.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
5K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
6
Views
2K
Back
Top