What is causing my Fortran compiling error in my physics code?

In summary: Subroutine ReadParam' Print*,'io status =',iostatus Print*,'End of File encountered.' END IFreturnend SUBROUTINE ReadParamIn summary, the conversation was about a user experiencing compiling errors with their code and asking for help to understand the errors. They shared their code and asked for suggestions on how to fix it. The conversation also included a discussion on stability conditions and the use of subroutines to help with the calculations. The expert summarizer provided a shortened version of the conversation without any additional comments or replies.
  • #1
s_hy
61
0
Dear physics forumers,

I have some compiling error regarding my codes as below:

gfortran -g -I/usr/include -c main.f90
main.f90:121.6:

u(t+1,x) = alpha**2 * u(t,x+1) / 2.0D+00 + ( 1.0D+00-alpha**2 ) * u(t,x) &
1
Error: Unclassifiable statement at (1)
main.f90:129.6:

u(t+1,x) = alpha**2 * u(t, x+1) + 2.0D+00 * (1.0D+00-alpha**2) * u(t, x) &
1
Error: Unclassifiable statement at (1)
main.f90:169.6:

u(1,1:x_num+1) = sin(2.0D+0 * pi * real (j-1)/x_num)
1
Error: Unclassifiable statement at (1)
main.f90:60.49:

call fd1d_wave ( x_num, x1, x2, t_num, t1, t2, c,u )
1
Warning: Invalid procedure argument at (1)
make: *** [main.o] Error 1


try to change to some column..still not solved. Anyone can help me to understand the error?

thank you
 
Technology news on Phys.org
  • #2
Post the entire program. If that is the entire program, you have not declared the variables and the compiler is confused by the x and t being treated as integers.
 
  • #3
hi antiphon,

this is the entire codes.

Program Main

IMPLICIT NONE

integer :: t_num
integer :: x_num
real :: t1
real :: t2
real :: x1
real :: x2
real :: c
real :: u

call ReadParam(x_num,x1,x2,t_num,t1,t2,c,u)
write(*,*) 'This is from Subroutine ReadParam'

!call fd1d_wave_01()

!write ( *, '(a)' ) ' '
!write ( *, '(a)' ) 'FD1D_WAVE_TEST'
!write ( *, '(a)' ) ' '

return

END PROGRAM Main

SUBROUTINE fd1d_wave_01()
implicit none
integer, parameter :: t_num = 40
integer , parameter :: x_num = 15
real :: c
integer :: i
integer :: j
real :: t1
real :: t2
real :: time
real :: u
real :: x(0:x_num)
real :: x1
real :: x2
external u_x1_01
external u_x2_01
external u_t1_01
external ut_t1_01
!call ReadParam(x_num,x1,x2,t_num,t1,t2,c,u)
!
x1 = 0.0D+00
x2 = 1.5D+00

do i = 0, x_num
x(i) = ( real ( x_num - i) * x1 &
+ real ( i) * x2 ) &
/ real ( x_num )
end do

t1 = 0.0D+00
t2 = 4.0D+00
c = 1.0D+00

call fd1d_wave ( x_num, x1, x2, t_num, t1, t2, c,u )
!
! Plot the solution as it evolves in time.
!
do j = 0, t_num
time = ( real ( t_num - j) * t1 &
+ real ( j) * t2 ) &
/ real ( t_num )
write ( *, '(2x,i4,2x,f10.4)' ) j, time, u(j,x_num)
end do

open (unit=13,file='output.dat',action='write',status='unknown', &
form='unformatted')
write(13) x,time
close(unit=13)

return
end

!FD1D_WAVE computes a finite difference solution of the 1D wave equation.
SUBROUTINE fd1d_wave (x_num,x1,x2,t_num,t1,t2,c,u)
implicit none
integer :: t_num
integer :: x_num
integer :: t
integer :: x
real :: alpha
real :: c
real :: t_delta
real :: t1
real :: t2
real :: u
real :: ut(x_num+1)
real :: x_delta
real :: x1
real :: x2

t_delta = (t2-t1)/real(t_num)
x_delta = (x2-x1)/real(x_num)
alpha = c*t_delta/x_delta
write ( *,'(a)')''
write ( *,'(a,g14.6)') 'Stability condition ALPHA = C * DT/DX = ',alpha
if ( 1.0D+00 < abs ( alpha ) ) then
write ( *, '(a)' )
write ( *, '(a)' ) 'FD1D_WAVE - Warning!'
write ( *, '(a)' ) ' The stability condition |ALPHA| <= 1 fails.'
write ( *, '(a)' ) ' Computed results are liable to be inaccurate.'
end if

!Open(90, File = "abc.dat", ACCESS = 'APPEND')

!the boundary conditions
call u_x1_01
call u_x2_01

!the initial data
call u_t1_01 ( t_num, x_num, u )
call ut_t1_01 ( x_num,ut )

t=1
do x=2, x_num
u(t+1,x) = alpha**2 * u(t,x+1) / 2.0D+00 + ( 1.0D+00-alpha**2 ) * u(t,x) &
+ alpha**2 * u(t,x-1) / 2.0D+00 + t_delta * ut(x)
end do

!All subsequent steps in time rely on two previous rows of solution data

do t=2, t_num
do x=2, x_num
u(t+1,x) = alpha**2 * u(t, x+1) + 2.0D+00 * (1.0D+00-alpha**2) * u(t, x) &
+ alpha**2 * u(t, x-1) - u(t-1,x)
end do
end do
return
end SUBROUTINE fd1d_wave

!new subroutine for U at the boundary X1.
SUBROUTINE u_x1_01
IMPLICIT NONE
real :: u_x1

u_x1 = 0.0D+0

return
end SUBROUTINE u_x1_01

!new subroutine for U at the boundary X2.
SUBROUTINE u_x2_01
implicit none
real ::u_x2
!integer :: t_num
!integer :: x_num
!real :: u(t_num+1,x_num+1)

u_x2 = 0.0D+0

return
end SUBROUTINE u_x2_01

!new subroutine for U at the initial time T1.
SUBROUTINE u_t1_01 ( t_num, x_num, u )
implicit none
integer :: x_num
integer :: t_num
real :: u
integer :: j
real,parameter :: pi= 3.14159

do j=1,x_num+1
u(1,1:x_num+1) = sin(2.0D+0 * pi * real (j-1)/x_num)
end do
return
end SUBROUTINE u_t1_01

!new subroutine for dUdt at initial time T1
SUBROUTINE ut_t1_01 ( x_num, ut )
implicit none

integer :: x_num
real :: ut(x_num+1)

ut(1:x_num+1) = 0.0D+00

return
end SUBROUTINE ut_t1_01

!new subroutine for readparam
SUBROUTINE ReadParam(x_num,x1,x2,t_num,t1,t2,c,u)

IMPLICIT NONE
logical :: oncheck
integer :: iostatus,IOSTAT,idum,test
integer :: t_num
integer :: x_num
integer :: t
integer :: x
!real :: alpha
real :: c
real :: t_delta
real :: t1
real :: t2
real :: u
real :: ut(x_num+1)
real :: x_delta
real :: x1
real :: x2
oncheck=.TRUE.

OPEN (103, FILE='parameters.DAT',status='unknown')

READ (103,*,IOSTAT=iostatus,ERR=1130),t_num
READ (103,*,IOSTAT=iostatus,ERR=1130),x_num
READ (103,*,IOSTAT=iostatus,ERR=1130),t
READ (103,*,IOSTAT=iostatus,ERR=1130),x
!READ (103,*,IOSTAT=iostatus,ERR=1130),alpha
READ (103,*,IOSTAT=iostatus,ERR=1130),c
READ (103,*,IOSTAT=iostatus,ERR=1130),t_delta
READ (103,*,IOSTAT=iostatus,ERR=1130),t1
READ (103,*,IOSTAT=iostatus,ERR=1130),t2
READ (103,*,IOSTAT=iostatus,ERR=1130),u
READ (103,*,IOSTAT=iostatus,ERR=1130),ut(x_num+1)
READ (103,*,IOSTAT=iostatus,ERR=1130),x_delta
READ (103,*,IOSTAT=iostatus,ERR=1130),x1
READ (103,*,IOSTAT=iostatus,ERR=1130),x2
READ (103,*,IOSTAT=iostatus,ERR=1130),test
CLOSE(103)

IF (oncheck) THEN
Print*,'t_num=',t_num
Print*,'x_num=',x_num
Print*,'t',t
Print*,'x',x
Print*,'t_delta',t_delta
Print*,'t1',t1
Print*,'t2',t2
Print*,'u',u
Print*,'ut(x_num+1)',ut(x_num+1)
Print*,'x1',x1
Print*,'x2',x2
Print*,'x_delta',x_delta
Print*,'test',test
END IF !oncheck

!########################################################################################
1130 IF (iostatus.GT.0) THEN
Print*,'This is from Subroutine ReadParam'
Print*,'Read ERR encountered. iostatus=',iostatus
STOP
END IF

1135 IF (iostatus.EQ.-1) THEN
! Print*,'This is from Subroutine ReadParam'
! Print*,'EOF encountered. iostatus=',iostatus
END IF

1133 CLOSE(103)
END SUBROUTINE ReadParam
 
  • #4
s_hy said:
SUBROUTINE fd1d_wave (x_num,x1,x2,t_num,t1,t2,c,u)
[...]
real :: u
[...]
u(t+1,x) = alpha**2 * u(t,x+1) / 2.0D+00 + ( 1.0D+00-alpha**2 ) * u(t,x) &

You declare u to be a single real variable, but you use it as an array.

You do the same thing in other places.
 
  • #5
"u" is not declared as an array but you are indexing it as if it is a two-dimensional array.
 
  • #6
jtbell said:
You declare u to be a single real variable, but you use it as an array.

You do the same thing in other places.

thank you for your reply. i am still in beginner level in fortran (used to use matlab, but for the sake of research, my sv asked me to change to fortran)...

from your answer, is that mean i need to disable the declaration for u? and leave is an array...or can u give me details explanation.

thank you for your time..
 
  • #7
No, do not disable the declaration of u. Since you are using it as a two-dimensional array, you should declare it as such.

In section 3 of this linked-to page (http://www.colostate.edu/~pburns/tue/arrays.f90.fm.html [Broken]), there is an example of a two-dimensional array.
 
Last edited by a moderator:
  • #8
thank you...i'll try it...
 
  • #9
still the same error came out :((
 
  • #10
What does your new declaration statement look like, exactly?
 

1. What is a "Fortran compiling error"?

A "Fortran compiling error" is an error that occurs during the process of converting a Fortran program into machine code that can be understood and executed by a computer. This process, called compiling, involves checking the code for syntax errors and translating it into a format that the computer can understand.

2. What causes a Fortran compiling error?

There are several potential causes of a Fortran compiling error, including syntax errors, missing or incorrect library files, and incompatible compiler options. Other common causes include typos, missing or extra punctuation, and using outdated or unsupported Fortran features.

3. How do I fix a Fortran compiling error?

The first step in fixing a Fortran compiling error is to carefully review the error message to identify the specific issue. This may involve checking for typos, using the correct syntax for statements and functions, and ensuring that all necessary libraries and compiler options are included. It may also be helpful to consult online resources or seek assistance from a more experienced programmer.

4. Can a Fortran compiling error be prevented?

While it is impossible to completely prevent all Fortran compiling errors, there are several steps that can be taken to minimize their occurrence. These include using an up-to-date compiler, carefully reviewing code for errors before compiling, and familiarizing oneself with common Fortran syntax and conventions.

5. Are there any tools available to help with Fortran compiling errors?

Yes, there are several tools and resources available to help with Fortran compiling errors. Many compilers include error checking and debugging features, and there are also online forums and communities where programmers can seek assistance from others. Additionally, there are various debugging tools and software packages specifically designed for Fortran programming.

Similar threads

  • Programming and Computer Science
Replies
4
Views
500
  • Programming and Computer Science
Replies
4
Views
26K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
25K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
5K
Back
Top