错误:(1)处的意外数组引用(编译器g95 -std = F)

时间:2014-05-14 11:20:47

标签: arrays fortran

我为大学项目制作了掷骰子计划。当编程和编译我的电脑(macbook)没有问题,然后我移动大学服务器(ubuntu 12)上的所有内容并添加一个情节模块而不改变"滚动"码。现在编译器给了我这个错误:

In file 000_Dados.f95:61

     dados(j)=int(rnum(j)*6 + 1)
                    1
Error: Unexpected array reference at (1)

我的代码如下(我强调了错误行):

program dice

use graph
use mcf_tipos

real(kind=doble), dimension(1:5)                  :: rnum          !! random number
integer(kind=int), dimension(1:5)                 :: dados         !! dices
integer(kind=int), dimension(0:5)                 :: count        !!
real(kind=doble), dimension(0:5)                  :: prob
integer(kind=int)                                 :: ax, n, i, j, k, l, m

!plot variables

character(len=132), dimension (1:6)     :: datafile
integer, dimension(1:6)                 :: x,y,tipo
character(len=132), dimension(1:3)      :: alabel

!open datafiles

open(unit=0,file="0ax.dat", status="replace", action="readwrite")
open(unit=1,file="1ax.dat", status="replace", action="readwrite")
open(unit=2,file="2ax.dat", status="replace", action="readwrite")
open(unit=3,file="3ax.dat", status="replace", action="readwrite")
open(unit=4,file="4ax.dat", status="replace", action="readwrite")
open(unit=5,file="5ax.dat", status="replace", action="readwrite")

!inizialize variables

forall (l=0:5)
count(l)=0
prob(l)=0
end forall

!first null data line

write (unit=0, fmt="(i8, t10, f10.6)"), 0, prob(0)
write (unit=1, fmt="(i8, t10, f10.6)"), 0, prob(1)
write (unit=2, fmt="(i8, t10, f10.6)"), 0, prob(2)
write (unit=3, fmt="(i8, t10, f10.6)"), 0, prob(3)
write (unit=4, fmt="(i8, t10, f10.6)"), 0, prob(4)
write (unit=5, fmt="(i8, t10, f10.6)"), 0, prob(5)

!!! THE PROGRAM BEGINS !!!

print *, "¿cuantos tiros?"
read *, n



do i=1,n
    call random_number(rnum)
    ax=0

    !!Roll dices!!

    do j=1,5

!!!!!!!!!!!!!!!!!!!HERE'S THE ERROR!!!!!!!!!!!!!!!!!!!

        dados(j)=int(rnum(j)*6 + 1)
        if (dados(j)==1) then
        ax=ax+1         !!AX Count
        endif
    end do

    !! Count to Probability

    select case(ax)
    case(0)
        count(0)=count(0)+1
        prob(0)=real(count(0))/i
    case(1)
        count(1)=count(1)+1
        prob(1)=real(count(1))/i
    case(2)
        count(2)=count(2)+1
        prob(2)=real(count(2))/i
    case(3)
        count(3)=count(3)+1
        prob(3)=real(count(3))/i
    case(4)
        count(4)=count(4)+1
        prob(4)=real(count(4))/i
    case(5)
        count(5)=count(5)+1
        prob(5)=real(count(5))/i
    end select

    !! write data !!

    write (unit=0, fmt="(i8, t10, f10.6)"), i, prob(0)
    write (unit=1, fmt="(i8, t10, f10.6)"), i, prob(1)
    write (unit=2, fmt="(i8, t10, f10.6)"), i, prob(2)
    write (unit=3, fmt="(i8, t10, f10.6)"), i, prob(3)
    write (unit=4, fmt="(i8, t10, f10.6)"), i, prob(4)
    write (unit=5, fmt="(i8, t10, f10.6)"), i, prob(5)

end do

do k=0,5
print *, "La probabilidad que salgan ", k,  " ases entre 5 dados es ", prob(k)*100, "%"
end do

!!CLOSE DATA FILES!!

close(unit=0)
close(unit=1)
close(unit=2)
close(unit=3)
close(unit=4)
close(unit=5)

!!PLOT OPTIONS!!

datafile(1)="0ax.dat"
datafile(2)="1ax.dat"
datafile(3)="2ax.dat"
datafile(4)="3ax.dat"
datafile(5)="4ax.dat"
datafile(6)="5ax.dat"

forall (m=1:5)
x(m)=1
y(m)=2
tipo(m)=1
end forall

alabel(1)="n tiros"
alabel(2)="probabilidad"

!!PLOT!!

call plot(datafile,x,y,axeslabel=alabel,type=tipo)

end program dice

1 个答案:

答案 0 :(得分:2)

您使用dobleint作为种类,因此它们可能是您包含的其中一个模块中声明的整数参数。因为int现在是一个整数参数,所以它会覆盖int内在函数。

因此,请查看graph / mcf_tipos源代码并删除int分配,将其更改为例如my_int_kind

使用例如,这可能是一个好主意。 iso_fortran_env代替,然后你有类型的参数,给你特定的尺寸,例如:

use iso_fortran_env

real(real64) :: rnum(5)
integer(int32) :: dados(5)

然后摆脱你自己定义的种类。