Error: Unclassifiable statement

2,621 views
Skip to first unread message

Gyanendra Pokharel

unread,
Feb 20, 2012, 8:31:22 PM2/20/12
to gg...@googlegroups.com
Dear all, I am having a problem in the following code. The error is 

 In file mcmc.f90:23

  function aloglike(alpha,beta)
 1
Error: Unclassifiable statement at (1)
 In file mcmc.f90:68

  end function aloglike
    1
Error: Expecting END PROGRAM statement at (1)

Can some one suggest me in this issue.


Here is my code:

module  mcmc

implicit none
real::aloglike

end module mcmc

program metropoli
  use mcmc
  implicit none



  interface
     subroutine sub1(aout,bout)
      use mcmc
       implicit none
       real, intent(out)::aout, bout
     end subroutine sub1
  end interface

  function aloglike(alpha,beta)

    real::alpha, beta, loglike
    real :: dist1,dist2,prob1,prob2
    integer :: t,i,j,k,l
    real, dimension(1:625):: x
    real, dimension(1:625):: y
    integer, dimension(1:625):: inftime
    !alpha = 0.5
    !beta = 2.0

    open(10, file = 'epidemic.txt', form = 'formatted')
    do l = 1,625
       read(10,*,end = 200) x(l), y(l), inftime(l)
    enddo
200 continue

    loglike = 0.0
 do t=1,10
       do i=1,625
          if(inftime(i)==0 .or. t < (inftime(i)-1)) then
             dist1 = 0.0
             do  j = 1, 625
                if(t >= inftime(j) .and. inftime(j)/=0)then
                   dist1 = dist1 + sqrt((x(i) - x(j))**2 + (y(i) - y(j))**2)**(-beta)
                endif
             enddo
             prob1 = 1 - exp(-alpha * dist1)
             loglike = loglike + log(1 - prob1)
          endif

          if(inftime(i) .eq. (t+1)) then
             dist2 = 0.0
             do k=1, 625
                if(t >= inftime(k) .and. inftime(k)/=0) then
                   dist2 = dist2 + sqrt((x(i) - x(k))**2 + (y(i) - y(k))**2)**(-beta)
                endif
             enddo
             prob2 = 1 - exp(-alpha * dist2)
            loglike = loglike + log(prob2)
          endif
       enddo
    enddo
    aloglike = loglike
    print *,aloglike
  end function aloglike
end program metropoli


Doug

unread,
Feb 20, 2012, 11:12:59 PM2/20/12
to gg95
Hi,

Put the "end program" line before the function.

Doug

On Feb 20, 8:31 pm, Gyanendra Pokharel <gyanendra.pokha...@gmail.com>
wrote:

Gyanendra Pokharel

unread,
Feb 21, 2012, 12:01:29 AM2/21/12
to t...@sentex.net, gg...@googlegroups.com
Thanks Doug,
I am able to remove the error with your suggestion but when I gave the print command  print *, aloglike(alpha,beta), it shows the error 

 In file mcmc.f90:67

    print *,aloglike(alpha,beta)
                   1
Error: Syntax error in PRINT statement at (1)

If the function "alolike" is well defined, when it shows the error in the print command? I gave the print command right before the command "end function aloglike"
GP 

--
You received this message because you are subscribed to the Google Groups "gg95" group.
To post to this group, send email to gg...@googlegroups.com.
To unsubscribe from this group, send email to gg95+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gg95?hl=en.


Skyler Byas

unread,
Oct 2, 2012, 4:14:30 PM10/2/12
to gg...@googlegroups.com, t...@sentex.net
try this
print (*,*) aloglike

Skyler Byas

unread,
Oct 2, 2012, 4:16:00 PM10/2/12
to gg...@googlegroups.com, t...@sentex.net
Or if that doesnt work try

print(*,*) aloglike(alpha,beta)

ziggy76

unread,
Oct 3, 2012, 11:35:29 AM10/3/12
to gg...@googlegroups.com, t...@sentex.net
The proper syntax for the print command is
PRINT *, aloglike(alpha,beta)
and not
PRINT(*,*) aloglike(alpha,beta)
this last syntax is used with the WRITE command :
WRITE(*,*) aloglike(alpha,beta)
which is exactly the same as the PRINT * example.

I had some problems with what is called recursive output. In your program you have a PRINT statement inside the function, this last one being called inside another PRINT statement.
So you have a PRINT inside a PRINT.
I think that this is not safe.

Ziggy.

jfh

unread,
Oct 7, 2012, 9:06:33 PM10/7/12
to gg...@googlegroups.com, t...@sentex.net
Recursive i/o is illegal in F95. Later versions of the Fortran standard allow it in certain circumstances. Some compilers allow it in even more. Read the manual(s) for your own compiler(s) but be aware that people with other compilers may not be able to run your programs. That may well include you when you change compilers.

John Harper   

evan

unread,
Nov 5, 2012, 1:39:32 PM11/5/12
to gg...@googlegroups.com
The first line of the function definition should be
function aloglike(alpha,beta) result(loglike)

ziggy76

unread,
Nov 6, 2012, 11:31:08 AM11/6/12
to gg...@googlegroups.com

Hi Evan,
I don't agree with you : you can use the function definition without the result keyword, and the result has the same name as the function.
If I remember well, the result construction is only indispensable in special cases like recursive functions.

  function aloglike(alpha,beta)
    real :: aloglike, loglike
.....
    aloglike = loglike
.....
  end function aloglike

Ziggy.
 

evan

unread,
Nov 7, 2012, 4:20:15 AM11/7/12
to gg...@googlegroups.com
True, I haven't noticed the aloglike = loglike.
Reply all
Reply to author
Forward
0 new messages