forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

problems array valued functions

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
AntonioGJerez



Joined: 01 Jun 2015
Posts: 9
Location: Spain

PostPosted: Sat Jun 20, 2015 2:35 pm    Post subject: problems array valued functions Reply with quote

Dear all

I have found several problems with array valued functions. They are probably my fault. Nevertheless I think the diagnosis of the compiler may be better.

This is the first example. It fails at runtime if compiled with /CHECKMATE depending on whether an unused variable N is passed to the function via USE or not


Code:
   module global
      integer::N=1
      interface fun
       function fun(A,B)
        REAL,intent(in)::A(:),B(:)
        REAL fun(size(A),size(B))
       end function fun
     end interface
     end module

     program bug6
     use global,only:fun     
     REAL A(4),B(4,4)
     A=(/1.,2.,3.,4./)
     B=fun(A,A)
     PRINT*,B
     end program

     function fun(A,B)
     use global,only:N   ! Crashes (integer overflow) due to this line if
                                 !compiled with /CHECKMATE !!!!
     implicit none
     REAL,intent(in)::A(:),B(:)
     REAL fun(size(A),size(B))
     fun=5.                ! the error message points to this line
     end function fun


Probably the reference at N should be included in the interface too.
In fact, this versión does not fail:

Code:
     module Nmodule
     integer::N=1
     end module
     
     module global
      interface fun
       function fun(A,B)
        use Nmodule
        REAL,intent(in)::A(:),B(:)
        REAL fun(size(A),size(B))
       end function fun
     end interface
     end module

     program bug6fixed
     use global,only:fun     
     REAL A(4),B(4,4)
     A=(/1.,2.,3.,4./)
     B=fun(A,A)
     PRINT*,B
     end program

     function fun(A,B)
     use Nmodule
     implicit none
     REAL,intent(in)::A(:),B(:)
     REAL fun(size(A),size(B))
     fun=5.
     end function fun


Regards
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2267
Location: Sydney

PostPosted: Fri Jul 10, 2015 8:54 am    Post subject: Reply with quote

Is the following what you wanted ?
Code:
   module global
     integer::N=1
     contains
      function fun(A,B)
      implicit none
      REAL,intent(in)::A(:),B(:)
      REAL fun(size(A),size(B))
      fun=5.                ! the error message points to this line
      end function fun           
   end module global

      program bug6
      use global,only:fun     
      REAL A(4),B(4,4)
      A=(/1.,2.,3.,4./)
      B=fun(A,A)
      PRINT*,B
      end program


I would get the program working, before applying ",only" to the use statement. Why the reference to N ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group