سؤال

I made a roll dice program for a university project. When programing and compiling on my pc (macbook) no problems, then I move everything on university server (ubuntu 12) and added a plot module without changing anything in the "rolling" code. Now compiler gives me this error:

In file 000_Dados.f95:61

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

My code is the following (i've emphasized the error line):

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
هل كانت مفيدة؟

المحلول

You use doble and int as kinds, so they are probably integer parameters declared in one of those modules you include. Because int is now an integer parameter, it overrides the int intrinsic function.

So, go look into graph/mcf_tipos source code and get rid of the int assignment, change it to e.g. my_int_kind.

It might be a good idea to use e.g. iso_fortran_env instead, then you have kind parameters that give you specific sizes, e.g.:

use iso_fortran_env

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

and then get rid of your own defined kinds.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top