Debugging Fortran Program: Getting Fluxconv Value

In summary: First, the explicit scheme is used to determine the thermodynamic state equation and the example 8.1 is used to determine the one dimensional transient heat conduction equation. Next, the initial conditions are specified, and the boundary conditions are determined. Finally, the numerical solution is achieved by using the finite volume method.
  • #1
big man
254
1
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
  • #2
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?
 
  • #3
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).
 
  • #4
How can I open, read, write multiple filenames in fortran90 using linux?
 
  • #5
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
 

1. What is debugging and why is it important when working with Fortran programs?

Debugging is the process of identifying and fixing errors or bugs in a computer program. It is important when working with Fortran programs because it allows the programmer to ensure the program runs correctly and produces the desired output.

2. How can I debug a Fortran program to get the "Fluxconv" value?

To debug a Fortran program and get the "Fluxconv" value, you can use a debugger tool such as GDB or a Fortran integrated development environment (IDE) like Intel Fortran. These tools allow you to step through the program line by line, inspect variables, and track the flow of the program to identify any errors.

3. What are common causes of errors when trying to get the "Fluxconv" value in a Fortran program?

Common causes of errors when trying to get the "Fluxconv" value in a Fortran program include typos or syntax errors in the code, incorrect use of variables or functions, and logical errors in the program's algorithm. It is also possible that the input data is not formatted correctly, leading to incorrect calculations and errors in the "Fluxconv" value.

4. How can I prevent errors when trying to get the "Fluxconv" value in my Fortran program?

To prevent errors when trying to get the "Fluxconv" value in your Fortran program, it is important to follow good coding practices such as using meaningful variable names, commenting your code, and testing your program with different input values. It is also helpful to use a debugger tool or IDE to identify and fix any errors during the development process.

5. What should I do if I am still unable to get the correct "Fluxconv" value after debugging my Fortran program?

If you are still unable to get the correct "Fluxconv" value after debugging your Fortran program, it may be helpful to seek assistance from other programmers or consult online resources and forums specific to Fortran programming. It is also important to carefully review your code and check for any potential errors or issues that may be causing the incorrect output.

Similar threads

  • Programming and Computer Science
Replies
4
Views
585
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
Back
Top