Fortran compiling error

  • Fortran
  • Thread starter s_hy
  • Start date
  • #1
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
 

Answers and Replies

  • #2
1,679
3
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
61
0
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
jtbell
Mentor
15,764
4,006
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
1,679
3
"u" is not declared as an array but you are indexing it as if it is a two-dimensional array.
 
  • #6
61
0
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
35,000
6,753
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
61
0
thank you...i'll try it...
 
  • #9
61
0
still the same error came out :((
 
  • #10
jtbell
Mentor
15,764
4,006
What does your new declaration statement look like, exactly?
 

Related Threads on Fortran compiling error

  • Last Post
Replies
4
Views
2K
Replies
1
Views
2K
Replies
2
Views
5K
  • Last Post
Replies
4
Views
7K
Replies
3
Views
9K
Replies
1
Views
3K
  • Last Post
Replies
4
Views
4K
  • Last Post
Replies
3
Views
10K
  • Last Post
Replies
6
Views
2K
Replies
2
Views
14K
Top