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

  • Thread starter Thread starter s_hy
  • Start date Start date
  • Tags Tags
    Error Fortran
AI Thread Summary
The Fortran compiling errors stem from the incorrect declaration of the variable "u," which is being used as a two-dimensional array but is declared as a single real variable. The compiler reports "Unclassifiable statement" errors due to this mismatch, particularly in the lines where "u" is indexed. To resolve the issue, "u" should be declared as a two-dimensional array, for example, using "real :: u(t_num+1, x_num+1)" to match its usage in the code. Additionally, there are warnings about invalid procedure arguments, indicating potential issues with how subroutine parameters are defined or passed. Correcting the variable declarations and ensuring proper array usage should help eliminate the compiling errors.
s_hy
Messages
57
Reaction score
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
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.
 
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
 
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.
 
"u" is not declared as an array but you are indexing it as if it is a two-dimensional array.
 
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..
 
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 ), there is an example of a two-dimensional array.
 
Last edited by a moderator:
thank you...i'll try it...
 
still the same error came out :((
 
  • #10
What does your new declaration statement look like, exactly?
 

Similar threads

Back
Top