Why is My Fortran Code Not Working?

  • Fortran
  • Thread starter Petar Mali
  • Start date
  • Tags
    Code Fortran
In summary, the conversation discusses a programming issue where the code is not functioning properly. The program involves calculations and uses constants and variables such as N, Ntot, t, U, rho, Umstag, and eaftot. The program also includes a loop and a read and write function. The issue may be caused by a mistake in using the constant 2.do instead of 2.d0.
  • #1
Petar Mali
290
0
I'm new in programing. Does enybody knows why this don't work.

implicit none
integer i,N,Ntot,istag
real*8 t,U,tpin,k,eg,mstag
real*8 rho,Umstag,Urho
real*8 eaf,eaftot,lambdaminus

write(6,*) 'N,Ntot,t,U'
read (5,*) N,Ntot,t,U
write(36,*) Ntot/2+1

tpin=8.d0*datan(1.do)/dfloat(N)
rho=dfloat(Ntot)/dfloat(N)
Urho=U*rho/2.do

do 1000 istag,Ntot,2

mstag=dfloat(istag)/dfloat(N)
Umstag=U*mstag/2.do

eaftot=0.do
do 200,i=-Ntot/4+1,Ntot/4
k=tpin*dfloat(i)
ek=-2.do*t*dcos(k)
lambdaminus=-dsqrt(ek*ek+Umstag*Umstag)
lambdaminus=lambdaminus+Urho
eaftot=eaftot+lambdaminus
200 continue
eaftot=2.do*eaftot/dfloat(N)-U*(rho*rho-mstag*mstag)/4.do

write(36,990)
990 format(i6,f16.6)

1000 continue
end
 
Technology news on Phys.org
  • #2
Please define "this don't work". What is it supposed to do and what does it actually do? What error messages do you get, if any, and when? (when you try to compile the program, or when you try to run it?)
 
  • #3
Your constants like 2.do should be 2.d0 (with a zero, not a letter o).

If that doesn't fix your problem ... what [STRIKE]Christo[/STRIKE] JT Bell said.
 
Last edited by a moderator:
  • #4
Tnx. That was mistake.
 
Last edited:
  • #5


It is difficult to determine the exact issue without more information or a specific error message. However, some potential problems with the code could be:

1. The use of implicit none is not consistent throughout the code. It is recommended to use it at the beginning of the code to avoid any unintended implicit declarations.

2. The use of real*8 is not a standard way of declaring real variables in Fortran. It is recommended to use the intrinsic function "kind" to specify the desired precision, for example: real(kind=8) t, U, tpin, k, eg, mstag, rho, Umstag, Urho, eaf, eaftot, lambdaminus.

3. The code does not include any comments or explanations of what each section is supposed to do. This can make it difficult for others to understand and debug the code.

4. The code includes non-standard functions such as dfloat and datan. It is recommended to use the standard Fortran functions such as real, double precision, and atan instead.

5. The code does not include any error handling or checks for invalid input values. This could lead to unexpected results or crashes.

6. The do loop at line 20 (do 1000 istag,Ntot,2) appears to have a typo, as the variable "istag" is not defined anywhere in the code. It is recommended to use a variable that has been previously defined or to declare "istag" as an integer.

Overall, it is important to carefully review and test the code, and to consult with more experienced programmers or resources for assistance in troubleshooting any issues.
 

1. What is Fortran and why is it used for coding?

Fortran is a high-level programming language that was originally developed for scientific and engineering applications. It is particularly well-suited for numerical computations and is used for creating efficient and reliable code for mathematical and scientific calculations.

2. What are some common problems encountered when coding in Fortran?

Some common problems with Fortran code include syntax errors, logical errors, and compatibility issues with newer versions of the language. It is also important to properly manage memory usage and avoid common pitfalls such as floating-point precision errors.

3. How can I debug my Fortran code?

There are several tools available for debugging Fortran code, such as the GNU Debugger (GDB) and the Intel Debugger (IDB). These tools allow you to step through your code, set breakpoints, and track the values of variables to identify and fix any errors.

4. Can I use Fortran to create graphical user interfaces (GUIs)?

While Fortran is primarily used for scientific and numerical computation, it is possible to create GUIs using the Fortran language. There are libraries and frameworks available, such as FLTK and Fortran GTK, that allow you to create GUIs in Fortran.

5. How can I optimize my Fortran code for better performance?

To optimize Fortran code, it is important to understand the specific algorithms and data structures being used and to implement them efficiently. Additionally, utilizing compiler optimizations and parallel processing techniques can greatly improve the performance of Fortran code.

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
26
Views
3K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
8
Views
5K
  • Programming and Computer Science
Replies
7
Views
13K
  • Programming and Computer Science
2
Replies
54
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top