please help me with this error, Im doing a chi-square program to determinate a correlation between 11 variables and it gaves me the following error: Unclassifiable statement at (1)
subroutine chicuadrado(matriz,val1,n,o)
implicit none
integer::i,j,k,m
real*8::suma1,suma2,total,porcentaje1,porcentaje2
integer,intent(in)::n,o
real*8,allocatable,intent(inout)::matriz(:,:),val1(:,:)
real*8,allocatable::x(:),y(:),chi(:)
allocate(x(n))
allocate(y(n))
allocate(chi(o))
total=0
suma1=0
suma2=0
porcentaje1=0
porcentaje2=0
!bucle para ralizar la suma de todos los elementos de
do j=1,o,1
chi(j)=0
do i=1,n,1
suma1=suma1+matriz(i,j)
suma2=suma2+val1(i,1)
end do
total=suma1+suma2
porcentaje1=suma1/total
porcentaje2=suma2/total
do k=1,n,1
x(k)=porcentaje1*matriz(k,j)
y(k)=porcentaje2*val1(k,1)
end do
do m=1,n,1
(1) chi(j)=chi(j)+(matriz(m,j)-x(m))**2)/x(m)+((val1(m,1)-y(m))**2)/y(m)
end do
end do
write(*,*) chi
deallocate(x)
deallocate(y)
deallocate(chi)
end subroutine
chi(j)=chi(j)+(matriz(m,j)-x(m))**2)/x(m)+((val1(m,1)-y(m))**2)/y(m)
1 0 1 0 1 2 1 2 10 X
Check your parentheses.
Related
This program:
C This program calculates cos(x**2)
PROGRAM COSX_SQUARE
IMPLICIT NONE
INTEGER a
REAL y, r
PRINT*, 'INPUT THE DEGREE'
PRINT*, 'BETWEEN 0 AND 360'
READ*, a
a*(3.141592/180) = y
C This part determines minus sign and calculates the function
IF (a .GT. 90) THEN
r = -(1-(y**4)/2+(y**8)/24-(y**12)/720+(y**16)/40320)
ELSEIF (a .GE. 270) THEN
r = 1-(y**4)/2+(y**8)/24-(y**12)/720+(y**16)/40320
ELSEIF (a .GT. 360) THEN
PRINT*, 'INVALID DEGREE'
PRINT*, 'DEGREE MUST BE BETWEEN 0 AND 360'
ELSEIF (a .LT. 0) THEN
PRINT*, 'INVALID DEGREE'
PRINT*, 'DEGREE MUST BE BETWEEN 0 AND 360'
END IF
PRINT*, 'THE RESULT OF COS', a, 'SQUARE IS = ', r
STOP
END
Gives this error:
a*(3.141592/180)=y
1
Error: Unclassifiable statement at (1)
I already defined a as INTEGER. Why this error keeps coming?
Yep. It is an expression which begins a statement. Maybe change it to
y = a*(3.141592/180)
if that is what you really meant.
For some reason when I compile my code I am given the single error:
49 | sum=sum(num)
| 1
Error: Unclassifiable statement at (1)
But I have already declared it in my subroutine:
subroutine positivesum(a)
implicit none
real::sum,x
character(len=*)::a
integer:: n,stat
real,allocatable,dimension(:):: num
open (2,file=a)
n=-1
stat=0
do while (stat==0)
n=n+1
read(2,*,iostat=stat)x
end do
allocate(num(n))
rewind(2)
do i=1,n
read(2,30) num(i)
end do
30 format (f6.2)
sum=sum(num)
write(*,*) sum
deallocate(num)
end subroutine positivesum
What I want is to add up all the numbers allocated in a file which I have called (not shown here), and have it written in my terminal, but despite having declared the variable 'sum', it gives me this error.
Thanks!
I want to find the maximum of an array T without using maxval in the last 2 parts of my code (marked with **). Unfortunately, it isn't working. It diplays me all the numbers verified only with the if condition without finding the maximum of it. The if condition just takes the first number and compared to other and if verified, display it all I can't my find my error.
Program exo2
Implicit None
Real, Dimension (:,:), Allocatable :: D
integer :: i,Z,A,B,ok
Real :: no_esc_max=1 , no_esc_min=1
Real, Dimension(:) , Allocatable :: T
print*, "entrez le nombre etudies"
read*, A
print*, "entrez le nombre de mesures pour chaque escargot"
read*, B
Allocate(D(A,B), STAT=ok)
Allocate(T(A), STAT=ok)
if (ok/=0) then
print* , "allocation a echoue"
Stop
end if
Do i=1,A
Do z=1,B
Print*, "Escargot",i
Print*,"entrez la vitesse lors de la mesure",z
Read*, D(i,z)
end do
end do
Do i=1,A
print*, D(i,:)
end do
Do i=1,A
Do z=1,B
T(i)=Sum(D(i,:))/z
end do
print*, "moyenne escargot", i , T(i)
end do
! (**) This block seems to have the problem
no_esc_max=T(1)
do i=2,A
if (no_esc_max<T(i)) then
T(i)=no_esc_max
end if
print* , "escargot",i, "est le plus rapide"
end do
no_esc_min=T(1)
do i=2,A
if (no_esc_min>T(i)) then
T(i)=no_esc_min
end if
print*, "escargot", i, "est le moins rapide"
end do
! (**) End of the block
Deallocate (D)
Deallocate (T)
End Program exo2
To print the correct i, you should keep track of the index refering to your max/min value. Additionally, put your print*,'..' commands outside the do-loop. Otherwise, it seems that you are just printing all of them.
This program:
C This program calculates cos(x**2)
PROGRAM COSX_SQUARE
IMPLICIT NONE
INTEGER a
REAL y, r
PRINT*, 'INPUT THE DEGREE'
PRINT*, 'BETWEEN 0 AND 360'
READ*, a
a*(3.141592/180) = y
C This part determines minus sign and calculates the function
IF (a .GT. 90) THEN
r = -(1-(y**4)/2+(y**8)/24-(y**12)/720+(y**16)/40320)
ELSEIF (a .GE. 270) THEN
r = 1-(y**4)/2+(y**8)/24-(y**12)/720+(y**16)/40320
ELSEIF (a .GT. 360) THEN
PRINT*, 'INVALID DEGREE'
PRINT*, 'DEGREE MUST BE BETWEEN 0 AND 360'
ELSEIF (a .LT. 0) THEN
PRINT*, 'INVALID DEGREE'
PRINT*, 'DEGREE MUST BE BETWEEN 0 AND 360'
END IF
PRINT*, 'THE RESULT OF COS', a, 'SQUARE IS = ', r
STOP
END
Gives this error:
a*(3.141592/180)=y
1
Error: Unclassifiable statement at (1)
I already defined a as INTEGER. Why this error keeps coming?
Yep. It is an expression which begins a statement. Maybe change it to
y = a*(3.141592/180)
if that is what you really meant.
I am working my way through "Modern Fortran explained" by Metcalf, Reid, and Cohen and in chapter four it assigns a Fibonacci program as a homework problem. My code below doesn't compile. How can I correct it?
! Fibonacci here we go
integer :: lim, i
lim=0
read *, lim
integer, dimension(lim) :: fib
if( lim >= 1 )
fib(1) = 0
end if
if( lim >= 2 )
fib(2) = 1
end if
if( lim >= 3 )
fib(3) = 1
end if
do i=4, lim
fib(i) = fib(i-2) + fib(i-1)
end do
do i=1, size(fib)
print *, fib(i)
end do
end
Also, here are the errors I am getting. I would attempt to shorten this to what is needed but I am not sure what one needs when looking at Fortran error logs.
Compiling the source code....
$/usr/bin/gfortran /tmp/135997827718658.f95 -o /tmp/135997827718658 2>&1
In file /tmp/135997827718658.f95:7
integer, dimension(lim) :: fib
1
Error: Unexpected data declaration statement at (1)
In file /tmp/135997827718658.f95:9
if( lim >= 1 )
1
Error: Unclassifiable statement in IF-clause at (1)
In file /tmp/135997827718658.f95:10
fib(1) = 0
1
Error: Unclassifiable statement at (1)
In file /tmp/135997827718658.f95:11
end if
1
Error: Expecting END PROGRAM statement at (1)
In file /tmp/135997827718658.f95:13
if( lim >= 2 )
1
Error: Unclassifiable statement in IF-clause at (1)
In file /tmp/135997827718658.f95:14
fib(2) = 1
1
Error: Unclassifiable statement at (1)
In file /tmp/135997827718658.f95:15
end if
1
Error: Expecting END PROGRAM statement at (1)
In file /tmp/135997827718658.f95:17
if( lim >= 3 )
1
Error: Unclassifiable statement in IF-clause at (1)
In file /tmp/135997827718658.f95:18
fib(3) = 1
1
Error: Unclassifiable statement at (1)
In file /tmp/135997827718658.f95:19
end if
1
Error: Expecting END PROGRAM statement at (1)
In file /tmp/135997827718658.f95:22
fib(i) = fib(i-2) + fib(i-1)
1
Error: Statement function at (1) is recursive
Error: Unexpected end of file in '/tmp/135997827718658.f95'
random fixes....
if block should be
if (condition) then
do something
endif
cannot ommit "then".
you cannot go
read *, lim
integer, dimension(lim) :: fib
all the declaration has to come before executable codes. so instead, use allocatable array
integer, dimension(:), allocatable :: fib
read *, lim
allocate(fib(lim))