Why isn't my Fortran program running properly?

In summary, the program for the thermodynamics class will not print any errors, but it does not display what errors were encountered.
  • #1
FortranFreaks
7
0
We made a program for our thermo class and when we go to run it, it tells us errors were encountered but will not display what errors it has. It won't print out anything. I appreciate any help you guys have to offer.

Print *, 'Nicholas Grover / Corey Demers'
Print *, 'Thermodynamics II FORTRAN problem'
C 4/16/06


C Program Thermo
Implicit None

Real T2, T3, T5, thN, Tpe
Real Wcs, Wts, Wc, Wt, Wnet, regN, Qh, Qr
Integer rv, T4


Print *, 'Pr Temp Nreg Nth Wnet'
Print *, '============================='


Do 10 rv = 4,4,2
Do 20 T4 = 1620, 4, 360
Do 30 regN = 0,.05,19

Call Compressor(Wc,rv,Wcs)
Call Turbine(Wts,Wt,T5,rv,regN,T4)
Call HighHEX(T3,T2,T5,Tpe,Qr,Qh,regN,rv)

Wnet = Wt - Wc
thN = Wnet/Qh

Print 40, rv,T4,regN,thN,Wnet

30 Continue
20 Continue
10 Continue

40 Format(1x,F1.0,F8.0,F7.2,F6.2,F7.2)
END


C *--------------------------------------------------------------*
Subroutine Compressor(Wc,rv,Wcs)

Real Wc,T2,Wcs
Integer rv

T2=540*rv**(.4/1.4)
Wcs= .24*(540-T2)
Wc=(Wcs/.81)

END
C *--------------------------------------------------------------*

C *--------------------------------------------------------------*
Subroutine Turbine(Wts,Wt,T5,rv,regN,T4)

Real Wts,Wt,T5,dP,regN
Integer T4,rv

dP=(.5*regN)/(1-regN)
P2=rv*14.7
P4=dP+P2
P5=14.7+dP
T5=T4*(P5/P4)**(.4/1.4)
Wts=(-.24)*(T5-T4)
Wt=Wts*.87

END
C *--------------------------------------------------------------*
Subroutine HighHEX(T3,T2,T5,Tpe,Qr,Qh,regN,rv)

Real T3,T2,T5,Tpe,Qr,Qh,regN
integer rv

T2=540*rv**(.4/1.4)
T3=T2+(T5-T2)*regN
Tpe=T3+180
Qr=(-.24)*(Tpe-3060)
Qh=Qr*(-1)

END
C *---------------------------------------------------------------*

Thanks again!
 
Technology news on Phys.org
  • #2


FortranFreaks said:
We made a program for our thermo class and when we go to run it, it tells us errors were encountered but will not display what errors it has. It won't print out anything. I appreciate any help you guys have to offer.

Print *, 'Nicholas Grover / Corey Demers'
Print *, 'Thermodynamics II FORTRAN problem'
C 4/16/06


C Program Thermo
Implicit None

Real T2, T3, T5, thN, Tpe
Real Wcs, Wts, Wc, Wt, Wnet, regN, Qh, Qr
Integer rv, T4


Print *, 'Pr Temp Nreg Nth Wnet'
Print *, '============================='


Do 10 rv = 4,4,2
Do 20 T4 = 1620, 4, 360
Do 30 regN = 0,.05,19

Call Compressor(Wc,rv,Wcs)
Call Turbine(Wts,Wt,T5,rv,regN,T4)
Call HighHEX(T3,T2,T5,Tpe,Qr,Qh,regN,rv)

Wnet = Wt - Wc
thN = Wnet/Qh

Print 40, rv,T4,regN,thN,Wnet

30 Continue
20 Continue
10 Continue

40 Format(1x,F1.0,F8.0,F7.2,F6.2,F7.2)
END


C *--------------------------------------------------------------*
Subroutine Compressor(Wc,rv,Wcs)

Real Wc,T2,Wcs
Integer rv

T2=540*rv**(.4/1.4)
Wcs= .24*(540-T2)
Wc=(Wcs/.81)

END
C *--------------------------------------------------------------*

C *--------------------------------------------------------------*
Subroutine Turbine(Wts,Wt,T5,rv,regN,T4)

Real Wts,Wt,T5,dP,regN
Integer T4,rv

dP=(.5*regN)/(1-regN)
P2=rv*14.7
P4=dP+P2
P5=14.7+dP
T5=T4*(P5/P4)**(.4/1.4)
Wts=(-.24)*(T5-T4)
Wt=Wts*.87

END
C *--------------------------------------------------------------*
Subroutine HighHEX(T3,T2,T5,Tpe,Qr,Qh,regN,rv)

Real T3,T2,T5,Tpe,Qr,Qh,regN
integer rv

T2=540*rv**(.4/1.4)
T3=T2+(T5-T2)*regN
Tpe=T3+180
Qr=(-.24)*(Tpe-3060)
Qh=Qr*(-1)

END
C *---------------------------------------------------------------*

Thanks again!

What compiler are you using? Any clues why it won't show you the error messages? Are they maybe getting piped to some error file somewhere?

If you strip the program down (comment out stuff), can you get the simplified version to compile?
 
  • #3
Force 2.0

We tried it without the subroutines but it gave us the same problem.

C Program Thermo
Implicit None

Real T2, T3, T5, thN, Tpe, dP, P2, P4, P5
Real Wcs, Wts, Wc, Wt, Wnet, regN, Qh, Qr
Integer rv, T4 Print *, 'Pr Temp Nreg Nth Wnet'
Print *, '=============================' Do 10 rv = 4,4,2
Do 20 T4 = 1620, 4, 360
Do 30 regN = 0,.05,19

T2=540*rv**(.4/1.4)
Wcs= .24*(540-T2)
Wc=(Wcs/.81)

dP=(.5*regN)/(1-regN)
P2=rv*14.7
P4=dP+P2
P5=14.7+dP
T5=T4*(P5/P4)**(.4/1.4)
Wts=(-.24)*(T5-T4)
Wt=Wts*.87

T2=540*rv**(.4/1.4)
T3=T2+(T5-T2)*regN
Tpe=T3+180
Qr=(-.24)*(Tpe-3060)
Qh=Qr*(-1)

Wnet = Wt - Wc
thN = Wnet/Qh

Print 40, rv,T4,regN,thN,Wnet

30 Continue
20 Continue
10 Continue

40 Format(1x,F1.0,F8.0,F7.2,F6.2,F7.2)
END
 
  • #4
These lines are screwy.
Code:
Do 10 rv = 4,4,2
Do 20 T4 = 1620, 4, 360
Do 30 regN = 0,.05,19
The first one says to do (execute) the code up through line 10, starting with rv = 4, up through rv = 4, in increments of 2.
The second one says to execute the code up through line 20, starting with T4 = 1620, up through T4 = 4, in increments of 360.
The third one says to execute the code up through line 30, starting with regN = 0, up through regN = 0.05, in increments of 19.
I haven't done any Fortran for awhile, but I don't think any of your loops will run at all.

What values do you want rv to have (start, end, increment)? Same for T4 and regN.
 
  • #5
How much do you have to strip out to get it to run? Have you successfully compiled previous programs, or is this your first one?

If you've used this compiler before, has it shown you error messages? Have you looked in its Help files to see if you have to turn on a verbose mode or something?

EDIT -- good catches by Mark. Still seems like the compiler must be tossing those error statements someplace though...
 
  • #6
Even a bad compiler will give a line number where it has trouble.
 
  • #7
Mark44 said:
These lines are screwy.
Code:
Do 10 rv = 4,4,2
Do 20 T4 = 1620, 4, 360
Do 30 regN = 0,.05,19
The first one says to do (execute) the code up through line 10, starting with rv = 4, up through rv = 4, in increments of 2.
The second one says to execute the code up through line 20, starting with T4 = 1620, up through T4 = 4, in increments of 360.
The third one says to execute the code up through line 30, starting with regN = 0, up through regN = 0.05, in increments of 19.
I haven't done any Fortran for awhile, but I don't think any of your loops will run at all.

What values do you want rv to have (start, end, increment)? Same for T4 and regN.

Is this better?
Do 10 rv = 4,10,2
Do 20 T4 = 1620, 2700, 360
Do 30 regN = 0, .95, .05

I need it to do all combinations for
rv: 4, 6, 8, 10
T4: 1620, 1980, 2340, 2700
regN: 0, .4, .5, .6, .7, .8, .9, .95

berkeman said:
How much do you have to strip out to get it to run? Have you successfully compiled previous programs, or is this your first one?

If you've used this compiler before, has it shown you error messages? Have you looked in its Help files to see if you have to turn on a verbose mode or something?

EDIT -- good catches by Mark. Still seems like the compiler must be tossing those error statements someplace though...

I have not used it before but it will run if I make a very basic program. When I first wrote it, it would display all the errors at the bottom and I fixed them one by one until they were all gone. So it no longer displays any errors but will say some were encountered.
 
  • #8
It is giving me this as output

C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f: In program `MAIN__':
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:1:
Print *, 'Nicholas Grover / Corey Demers'
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:7: (continued):
Implicit None
2
Statement at (2) invalid in context established by statement at (1)
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:1:
Print *, 'Nicholas Grover / Corey Demers'
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:9: (continued):
Real T2, T3, T5, thN, Tpe
2
Statement at (2) invalid in context established by statement at (1)
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:1:
Print *, 'Nicholas Grover / Corey Demers'
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:10: (continued):
Real Wcs, Wts, Wc, Wt, Wnet, regN, Qh, Qr
2
Statement at (2) invalid in context established by statement at (1)
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:1:
Print *, 'Nicholas Grover / Corey Demers'
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:11: (continued):
Integer rv, T4
2
Statement at (2) invalid in context established by statement at (1)
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f: In subroutine `compressor':
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:22: warning:
Call Compressor(Wc,rv,Wcs)
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:42: (continued):
Subroutine Compressor(Wc,rv,Wcs)
2
Argument #2 (named `rv') of `compressor' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f: In subroutine `turbine':
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:23: warning:
Call Turbine(Wts,Wt,T5,rv,regN,T4)
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:55: (continued):
Subroutine Turbine(Wts,Wt,T5,rv,regN,T4)
2
Argument #4 (named `rv') of `turbine' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:23: warning:
Call Turbine(Wts,Wt,T5,rv,regN,T4)
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:55: (continued):
Subroutine Turbine(Wts,Wt,T5,rv,regN,T4)
2
Argument #6 (named `t4') of `turbine' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f: In subroutine `highhex':
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:24: warning:
Call HighHEX(T3,T2,T5,Tpe,Qr,Qh,regN,rv)
1
C:\Documents and Settings\Corey\My Documents\THERMO FORTRAN PROBLEM.f:70: (continued):
Subroutine HighHEX(T3,T2,T5,Tpe,Qr,Qh,regN,rv)
2
Argument #8 (named `rv') of `highhex' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
 
  • #9
FortranFreaks said:
Is this better?
Do 10 rv = 4,10,2
Do 20 T4 = 1620, 2700, 360
Do 30 regN = 0, .95, .05

I need it to do all combinations for
rv: 4, 6, 8, 10
T4: 1620, 1980, 2340, 2700
regN: 0, .4, .5, .6, .7, .8, .9, .95

Yes, these look reasonable.
 
  • #10
I think that the compiler is complaining about the two PRINT statements at the top. I believe that they need to be after your declarations, not before them. See if that makes a difference.
 
  • #11
Mark44 said:
I think that the compiler is complaining about the two PRINT statements at the top. I believe that they need to be after your declarations, not before them. See if that makes a difference.

Sweet! That was the problem, just need to figure out the new problems I'm encountering.
 
  • #13
Does anyone know why my given rv and T4 values are being printed as all zeros?
 
  • #14
Code:
Real T2, T3, T5, thN, Tpe, dP, P2, P4, P5
Real Wcs, Wts, Wc, Wt, Wnet, regN, Qh, Qr
Integer rv, T4

.
.
.

Print 40, rv,T4,regN,thN,Wnet

40 Format(1x,F1.0,F8.0,F7.2,F6.2,F7.2)
First off rv and T4 are declared as Integer types. Your format statement doesn't match these types. The Fx.x field specifiers are for real values, with F1.0 being used to print a real number in a field of width 1 space. The next one, F8.0 is used for T4, printing it in a field of width 8 characters, but with no places to the right of the decimal point. The appropriate specifier for Integer values is I4 or I6, or something big enough to hold the values you need printed. You should ask yourself though, whether Integer is the right type for these two variables. I haven't looked at your code close enough to say one way or the other.

If you fix these things, and you're still getting 0's for rv and T4, then the time-honored way of debugging is to sprinkle PRINT (or WRITE) statements at places in your code where these variables are getting set. Knowing the value of a variable is always better than guessing its value.

That's an obvious place to star
 
  • #15
Thanks for the help! We ended up getting it running.
 
  • #16
Mark44 said:
Code:
Real T2, T3, T5, thN, Tpe, dP, P2, P4, P5
Real Wcs, Wts, Wc, Wt, Wnet, regN, Qh, Qr
Integer rv, T4

.
.
.

Print 40, rv,T4,regN,thN,Wnet

40 Format(1x,F1.0,F8.0,F7.2,F6.2,F7.2)
First off rv and T4 are declared as Integer types. Your format statement doesn't match these types. The Fx.x field specifiers are for real values, with F1.0 being used to print a real number in a field of width 1 space. The next one, F8.0 is used for T4, printing it in a field of width 8 characters, but with no places to the right of the decimal point. The appropriate specifier for Integer values is I4 or I6, or something big enough to hold the values you need printed. You should ask yourself though, whether Integer is the right type for these two variables. I haven't looked at your code close enough to say one way or the other.

If you fix these things, and you're still getting 0's for rv and T4, then the time-honored way of debugging is to sprinkle PRINT (or WRITE) statements at places in your code where these variables are getting set. Knowing the value of a variable is always better than guessing its value.

That's an obvious place to start.

xxxx
 

1. Why is my Fortran program not running?

There could be several reasons why your Fortran program is not running. Some common causes include syntax errors, incorrect input/output statements, and missing or incorrect libraries. It is important to carefully review your code and debug any errors before attempting to run the program.

2. How do I debug my Fortran program?

To debug your Fortran program, you can use a debugger tool such as GDB or a compiler with built-in debugging capabilities. You can also add print statements throughout your code to track the values of variables and identify where the program is encountering errors.

3. Why am I getting a "segmentation fault" error when running my Fortran program?

A "segmentation fault" error is a result of the program trying to access a memory location that it is not allowed to access. This can occur due to an array index out of bounds, a null pointer, or a stack overflow. Check your code for any memory-related errors and make sure to allocate enough memory for your program to run.

4. How can I optimize my Fortran program for faster execution?

To optimize your Fortran program, you can use compiler optimizations such as loop unrolling, vectorization, and parallelization. You can also optimize the algorithm used in your program to reduce the number of operations needed. Additionally, using efficient data structures and avoiding unnecessary I/O operations can also improve the speed of your program.

5. Why is my Fortran program giving different results on different machines?

If your Fortran program is giving different results on different machines, it could be due to differences in the hardware or the compiler settings. Make sure to use the same compiler and compiler options on all machines to ensure consistent results. You should also check for any platform-specific differences that could affect the behavior of your program.

Similar threads

  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
Back
Top