Fortran Debugging Fortran Program: Getting Fluxconv Value

AI Thread Summary
The discussion centers around a Fortran program designed to read star data from a file and calculate flux values. The user is struggling with the variable 'fluxconv', which only retains the last value assigned to it after looping through records for each star. The issue arises because 'fluxconv' is treated as a simple variable rather than an array or a cumulative sum. The user seeks clarification on how to modify the program to retain all calculated flux values for further processing, specifically to compute a mean value. Additionally, there are inquiries about reading and writing multiple filenames in Fortran, as well as general comments on improving the program. The conversation highlights the importance of understanding variable scope and data structures in programming for effective data manipulation.
big man
Messages
241
Reaction score
0
Hey,

I wasn't sure whether or not to put this in the homework section or not because I need to complete this code for an assignment, but I thought that someone with fortran knowledge might have a better chance of seeing it in this section.

PROGRAM testing

! Variable declarations
CHARACTER input*100 ! buffer for holding a line of data from a file
INTEGER, PARAMETER :: DATAFILE = 30, STDIN = 5, STDOUT = 6
INTEGER numRecords, & ! number of records for each star
starNum, &
flag, &
numRepetitions
REAL (KIND=8) :: barycentricJD, bMag, deltaBMag, backgroundB, &
vMag, deltaVMag, backgroundV, fluxconv, mean, std, zeromean

REAL (KIND=8), PARAMETER :: F0=0.0000000216

! Program Start

! Read information from the keyboard
WRITE(STDOUT,*) "Enter number of stars to read in: "
READ(STDIN,*) numRepetitions

! Open the .dat file
OPEN( FILE = 'TYC_EP.dat', UNIT = DATAFILE, STATUS = 'OLD', IOSTAT = IOStat )

DO I = 1, numRepetitions ! read in numRepetitions stars
READ (DATAFILE, "(a)") input ! read header information for current star
READ(input(6:10), FMT="(I5)") starNum ! extract star number from header info
READ(input(14:16), FMT="(I3)") numRecords ! extract number of transits for current star

WRITE (STDOUT,*) "Star number is: ", starNum
WRITE (STDOUT, *) "Number of records is: ", numRecords

fluxconvsum=0

DO J = 1, numRecords
READ (DATAFILE,"(a)") input
READ(input(1:50), "(F10.1,1X,F6.3,1X,F5.3,1X,F6.2,1X,F6.3,1X, F5.3,1X, F6.2)") &
barycentricJD, bMag, deltaBMag, backgroundB, &
vMag, deltaVMag, backgroundV
READ(input(83:84), "(I2)") flag
fluxconv=F0*(10**(-bMag/2.5))
fluxconvsum=fluxconvsum+fluxconv
WRITE(STDOUT,*) barycentricJD," ", bMag, " ", deltaBMag," ",&
backgroundB," ", vMag," ", deltaVMag," ",&
" ", backgroundV, " ",flag, " ", fluxconv

END DO ! End of loop for reading in each record
mean=(fluxconvsum)/numRecords
WRITE(STDOUT, *) "MEAN", mean, fluxconv

END DO ! End of loop for reading in each starCLOSE(DATAFILE)

END PROGRAM testing

I'm no expert in fortran (well actually I've never done programming ever and I'm really bad at it) and this program has essentially been created by trial and error from my lecture notes and I've been lucky up until this moment. In the loop for the "reading in each record" I will get 111 individual entries for fluxconv (for the first star), but then I write fluxconv outside of the loop it only returns the very last value of fluxconv. All I want to know is why this is? If I know this then I should be able to sort it out and then proceed to zero mean the data.

I'd appreciate any help at all
Thanks
 
Last edited:
Technology news on Phys.org
I don't mean to be a bother, but could you put [ code ] and [ /code ] (without the spaces) around your code to make it more readable, so that whatever indenting you do isn't ignored by the forums software?
 
In the loop for the "reading in each record" I will get 111 individual entries for fluxconv (for the first star), but then I write fluxconv outside of the loop it only returns the very last value of fluxconv.

What are you expecting, or, what is it you're hoping for? -- right now, you are using "fluxconv" as a simple variable and thus, it will only retain the last value assigned to it (the last value at the end of the J cycle for each iteration of I).
 
How can I open, read, write multiple filenames in fortran90 using linux?
 
this is my first fortran program and i tried to learn fortran myself i would like anyone please to comment on this program and if there is an improvement can be done
i appreciate your help and thank you very much





PROGRAM FIRST
! FINITE VOLUME METHOD FOR ONE DIMENSIONAL UNSTEADY STATE HEAT CONDUCTION
! EXPLICIT SCHEME
! EXAMPLE 8.1
!
! THE ONE DIMENSIONAL TRANSIENT HEAT CONDUCTION EQUATION IS D*dT/dt=d/dx(k*dT/dx)
! THE INITIAL CONDITIONS ARE T=200 AT t=0
!
! THE BOUNDARY CONDITIONS ARE: dT/dx=0 at x=0, t>0 and T=0 at x=L, t>0
! THE NUMERICAL SOLUTION WITH THE EXPLICIT METHOD IS GENERATED BY DIVIDING THE
! DOMAIN INTO FIVE EQUAL CONTROL VOLUMES WITH (DELTA X = 0.004 m)
! !
!P*TP=W*TW+E*TE+[P-(W+E)]*TP+Su
!
REAL, DIMENSION (0:50,0:50):: T
INTEGER :: j
REAL :: E,P,W

PRINT*, ' '
!
! AS THE PLATE INITIALLY AT A UNIFORM TEMPERATURE OF 200
! !
DATA T(0,1),T(0,2),T(0,3),T(0,4),T(0,5) /5*200/
!
PRINT*,' '
CALL ONE(E,P,W)
!
PRINT*, T(0,1),T(0,2),T(0,3),T(0,4),T(0,5)
!
DO j=0,19
!
! NODE (1) EQUATION
T(j+1,1)=E/P*T(j,2)+(1-(E/P))*T(j,1)
!
! NODE(2-4)EQUATIONS
T(j+1,2)=W/P*T(j,1)+E/P*T(j,3)+(1-((W/P)+(E/P)))*T(j,2)
T(j+1,3)=W/P*T(j,2)+E/P*T(j,4)+(1-((W/P)+(E/P)))*T(j,3)
T(j+1,4)=W/P*T(j,3)+E/P*T(j,5)+(1-((W/P)+(E/P)))*T(j,4)
!
! NODE (5)EQUATION
T(j+1,5)=W/P*T(j,4)+((1-(3*W/P)))*T(j,5)
!
! THE RESULTS OF 40 SECONDS
PRINT*, T(j+1,1),T(j+1,2),T(j+1,3),T(j+1,4),T(j+1,5)
!
END DO
!
END PROGRAM FIRST

!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SUBROUTINE ONE(E,P,W)
! K : IS THE THERMAL CONDACTIVITY (W/m/K)
! D : IS THE MATERIAL DINSITY TIMES THE SPECIFIC HEAT (J/m3/K)
! DELTAX: IS THE CONTROL VOLUME WIDTH (m)
! DELTAT: IS THE TIME STEP (SECONDS)
REAL :: K, D, DELTAX, DEALTAT
REAL :: E,P,W
!
K=10.00
D=10.00E6
DELTAX=0.004
DELTAT=(D*DELTAX**2)/(2*K)
!
!THE TIME STEP FOR THE EXPLICIT METHOD IS SUBJECT TO THE CONDITION : DELTAT < D*DELTAX**2/2**K
!
PRINT*, 'THE TIME STEP SHOULD BE LESS THAN ',DELTAT, 'SEC'
PRINT*, ' '
PRINT*, 'LET THE TIME STEP '
READ*, DELTAT
E=K/DELTAX
P=(D*DELTAX)/DELTAT
W=E
END SUBROUTINE ONE
 
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
8
Views
1K
Replies
8
Views
4K
Replies
4
Views
2K
Replies
6
Views
3K
Replies
5
Views
2K
Replies
8
Views
4K
Replies
13
Views
4K
Back
Top