Bhavesh Valecha
Bhavesh Valecha

Reputation: 1

bash: cannot execute binary file exec format error fortran

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

Upvotes: 0

Views: 2693

Answers (1)

albert
albert

Reputation: 9012

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.

Upvotes: 3

Related Questions