0

When I run the code given below, it always gives me the following error:

bash: cannot execute binary file exec format error fortran 

Also, the file "file" is not being created at the location mentioned in the code. I've a 64-bit processor and 64-bit version of Ubuntu 16.04, so that does not appear to be the issue. Can someone please point out where I'm wrong?

program sandpile_model implicit none integer, parameter :: len = 20 integer, dimension(len,len) :: square !real, dimension(len,len) :: blah !open(unit=1,file="\\home\\sandpile\\fortran\\file") !dummy variables integer :: i,j,d do i=1,len do j=1,len square(i,j)=2 end do end do do d=1,10000 square((len/2)-1,(len/2)-1)=square((len/2)-1,(len/2)-1)+1 if(square((len/2)-1,(len/2)-1)>3) then call toppling((len/2)-1,(len/2)-1) end if end do !open(unit=1,file="\\home\\sandpile\\fortran\\file") do i=1,len do j=1,len write(1,*), i,'\t',j,'\t',square(i,j) end do print*, '\n' end do end program sandpile_model !This subroutine specifies the evolution rules of the model recursive subroutine toppling(x,y) !implicit none integer, parameter :: len = 20 integer, dimension(len,len) :: square !real, dimension(len,len) :: blah integer, intent(in) :: x,y square(x,y)=square(x,y)-4 square(x+1,y)=square(x+1,y)+1 if(square(x+1,y)>3) then call toppling(x+1,y) end if square(x-1,y)=square(x-1,y)+1 if(square(x-1,y)>3) then call toppling(x-1,y) end if square(x,y+1)=square(x,y+1)+1 if(square(x,y+1)>3) then call toppling(x,y+1) end if square(x,y-1)=square(x,y-1)+1 if(square(x,y-1)>3) then call toppling(x,y-1) end if end subroutine toppling 
9
  • 1
    How are you running your code, i.e. which commands are you giving. Commented Jun 22, 2018 at 13:42
  • by "./try.o" try.o is the executable file Commented Jun 22, 2018 at 13:45
  • How did you create try.o? Commented Jun 22, 2018 at 13:46
  • "gfortran -c try.f90" Commented Jun 22, 2018 at 13:48
  • This is creating an object not an executable. In this case try gfortran try.f90 Commented Jun 22, 2018 at 13:53

1 Answer 1

3

The problem appears here that an attempt is made to run an object file and not an executable.

Very small / limited instructions:

  • To create an object file: gfortran -c <fortran file>
  • To create an executable: gfortran <fortran file>

When using multiple source files:

  • Create objects from the individual files and link the together by means of gfortran <object files>
  • Create executable directly from source files gfortran <fortran files>

Note:

  • order of the files might be important
  • It might be necessary to link libraries as well into the executable (`-l option)
  • Name of the output file can be specified by means of the -ooption

Further initial reading:

  • compiler documentation
  • man gfortran
  • man make for automation in more complex situations.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.