underthewood
Programmer
- Nov 8, 2010
- 4
Hi, im new to fortran, and im using it for a project to perform some simple calculations. Ive already created a prgram that ALMOST does what I need it to, but im having a problem getting the final product.
Basically, I have a table of data, with about 2000 rows and 7 columns.
I have to perform the same calculation on every row, using 2 values from 2 of the columns, 2 already defined constants, and another number that I choose (variable).
Once this calculation is performed on every row, I must sum up all the results, ie I perform the calculation 2000 times then sum together the 2000 results.
Now I have figured out how to do this by choosing a single number for the variable. What I would like to do is do this entire process, but with different values of this variable between a certain range, at certain intervals.
Here is my code:
program clean
integer :: a, N, T
double precision :: g, c2, Z0, J, E, Z
open(10,file="file.txt")
!This is the file that has the 2000 rows of data, 7 columns
N=0
Z=0
Do
Read (10,*,iostat=a)v123,J,Ka,Kc,E,NT,Grade
! These are the headings assigned to each column
if(a==-1)exit
N=N+1
g=0.25
c2=1.4387752
T=1000
! Some definitions. I want to vary T.
Z0=g*((2*J)+1)*(exp((-E*c2)/T))
! This is the equation, where J and E are taken from each row, g and c2 are constants, and T is the value I would like to vary.
Z=Z+Z0
print *, Z
! The summing part of the program.
End Do
open(11,file="Z0s.txt")
write(11,*)T, Z
close(11)
! This bit i want as an output file, writing the final value of Z and the corresponding value of T. Of course, at the moment I only have one value for T so I only get one value for Z, and hence a single row with two columns
print *, 'The number of rows evaluated is:', N
print *, 'The value of Z is:', Z
! This eventually prints the final result for the value of T =1000, and vefifies the number of rows evaluated
End program
So to summarise: I want to read out from a large number of rows, take numeric values from certain columns in these rows, insert them into an equation (and do the equation for every row), then add together the results, but do this for various values of a certain variables within the equation.
How should I modify the code?
Cheers
Dan
Basically, I have a table of data, with about 2000 rows and 7 columns.
I have to perform the same calculation on every row, using 2 values from 2 of the columns, 2 already defined constants, and another number that I choose (variable).
Once this calculation is performed on every row, I must sum up all the results, ie I perform the calculation 2000 times then sum together the 2000 results.
Now I have figured out how to do this by choosing a single number for the variable. What I would like to do is do this entire process, but with different values of this variable between a certain range, at certain intervals.
Here is my code:
program clean
integer :: a, N, T
double precision :: g, c2, Z0, J, E, Z
open(10,file="file.txt")
!This is the file that has the 2000 rows of data, 7 columns
N=0
Z=0
Do
Read (10,*,iostat=a)v123,J,Ka,Kc,E,NT,Grade
! These are the headings assigned to each column
if(a==-1)exit
N=N+1
g=0.25
c2=1.4387752
T=1000
! Some definitions. I want to vary T.
Z0=g*((2*J)+1)*(exp((-E*c2)/T))
! This is the equation, where J and E are taken from each row, g and c2 are constants, and T is the value I would like to vary.
Z=Z+Z0
print *, Z
! The summing part of the program.
End Do
open(11,file="Z0s.txt")
write(11,*)T, Z
close(11)
! This bit i want as an output file, writing the final value of Z and the corresponding value of T. Of course, at the moment I only have one value for T so I only get one value for Z, and hence a single row with two columns
print *, 'The number of rows evaluated is:', N
print *, 'The value of Z is:', Z
! This eventually prints the final result for the value of T =1000, and vefifies the number of rows evaluated
End program
So to summarise: I want to read out from a large number of rows, take numeric values from certain columns in these rows, insert them into an equation (and do the equation for every row), then add together the results, but do this for various values of a certain variables within the equation.
How should I modify the code?
Cheers
Dan