the problem of declaring a function in the interface 
Author Message
 the problem of declaring a function in the interface

I might miss a basic point but I can't find what's the problem here.

within the interface, I declared the result variable "up_mv_mul" as
allocatable but why does it not recognize?

I appreciate
-----------------------------------------------------------------------------------------------------------------
Compile Error Message

"functions.f", 1514-199 (S) Array up_mv_mul is a deferred-shape array
but does not have the POINTER or ALLOCATABLE attributes
** def_fncs   === End of Compilation 1 ===
** functions   === End of Compilation 2 ===
1501-511  Compilation failed for file functions.f.
-------------------------------------------------------------------------------------------------------------
module def_fncs
  interface
     function up_mv_mul(A,x)
       use const
       implicit none
       real(dp), dimension(:,:), intent(in) :: A
       real(dp), dimension(:), intent(in) :: x
       real(dp), dimension(:), allocatable  :: up_mv_mul
     end function up_mv_mul
  end interface
end module def_fncs

module functions
  use const
  use cheb_grid
  implicit none
contains
  function up_mv_mul(A,x)
    implicit none
    real(dp), dimension(:,:), intent(in) :: A
    real(dp), dimension(:), intent(in) :: x
    real(dp), dimension(:), allocatable :: up_mv_mul
    allocate(up_mv_mul(10))
  end function up_mv_mul
end module functions



Tue, 06 May 2008 08:27:43 GMT  
 the problem of declaring a function in the interface
Hello,

Quote:

> I might miss a basic point but I can't find what's the problem here.

> within the interface, I declared the result variable "up_mv_mul" as
> allocatable but why does it not recognize?

Because you're using a fortran 95 compiler,
and allocatable function results are a Fortran 2003 feature.

Quote:
> I appreciate
> -----------------------------------------------------------------------------------------------------------------
> Compile Error Message

> "functions.f", 1514-199 (S) Array up_mv_mul is a deferred-shape array
> but does not have the POINTER or ALLOCATABLE attributes
> ** def_fncs   === End of Compilation 1 ===
> ** functions   === End of Compilation 2 ===
> 1501-511  Compilation failed for file functions.f.

Is this xlf?  I'm not sure I recognize it.
I know IBM is adding f03 features rather quickly,
but apparently, the release of xlf you have
doesn't support allocatable function results.

You might inquire with your compiler vendor
if a new release is planned which will support
allocatable function results.

Quote:
> -------------------------------------------------------------------------------------------------------------
> module def_fncs
>   interface
>      function up_mv_mul(A,x)
>        use const
>        implicit none
>        real(dp), dimension(:,:), intent(in) :: A
>        real(dp), dimension(:), intent(in) :: x
>        real(dp), dimension(:), allocatable  :: up_mv_mul
>      end function up_mv_mul
>   end interface
> end module def_fncs

> module functions
>   use const
>   use cheb_grid
>   implicit none
> contains
>   function up_mv_mul(A,x)
>     implicit none
>     real(dp), dimension(:,:), intent(in) :: A
>     real(dp), dimension(:), intent(in) :: x
>     real(dp), dimension(:), allocatable :: up_mv_mul
>     allocate(up_mv_mul(10))
>   end function up_mv_mul
> end module functions

HTH

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Tue, 06 May 2008 08:42:57 GMT  
 the problem of declaring a function in the interface
right this is xlf. Thank you, Dan

But the funny thing is that in the function precedure below, there is
no error.
then that looks like it supports the allocatable function procedure.

When I take "allocatable" out in the interface block and the function
procedure, still I have the same error.
This time the errors point to the both.

I just need a function result array.
Is there any way I can code a function with a result array in an
interface and a procedure?

thank you.



Tue, 06 May 2008 22:47:40 GMT  
 the problem of declaring a function in the interface
Hello,

Work-around number one is, if allocatable can't be used
for whatever reason, try using pointers instead.  You
lose some safety and efficiency, but you just have
to be careful and muddle through until your compiler
supports allocatable function results.

Second choice might be to rewrite as a subroutine.

Quote:

> right this is xlf. Thank you, Dan

> But the funny thing is that in the function precedure below, there is
> no error.
> then that looks like it supports the allocatable function procedure.

> When I take "allocatable" out in the interface block and the function
> procedure, still I have the same error.
> This time the errors point to the both.

> I just need a function result array.
> Is there any way I can code a function with a result array in an
> interface and a procedure?

> thank you.

Your welcome.

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Tue, 06 May 2008 23:47:45 GMT  
 the problem of declaring a function in the interface

Quote:

> When I take "allocatable" out in the interface block and the function
> procedure, still I have the same error.
> This time the errors point to the both.

Yes. I was wondering about that diagnosis. Although this is an f2003 (or
f95+TR) feature, the error message didn't sound like it was griping
about that.

Off-hand the code looks ok to me, and NAG accepts it happily (other than
griping about allocatable functions being an extension and about unused
dummy args) once I replace the USE const with a definition of dp and
comment out the other USE.

Although I don't see anything obviously wrong, two points make me
slightly wonder about other issues.

1. In what context do you ever make use of the def_fncs module?  In
particular, it has an interface body for up_mv_mul, which is the name a
module procedure in the other module. You do no need and cannot have an
interface body for a module procedure. Since these are in different
modules, they don't necessarily clash, so it isn't technically wrong....
yet. But it is sure confusing, and as soon as you try to use both
modules at the same time, there will be a clash.

2. I assume that "use const" is to get the dp parameter, but what is the
"USE cheb_grid"? I don't see what is in it, raising the possibility of
clashes. Since it doesn't appear to be needed in the code swhown, that
also raises the question of whether you exerpted this from a larger
module, which might have had other things contributing to the problem.

I guess my question boils down to wondering whether this is a complete
sample illustrating the problem? Since the problem is in compilation
instead of in execution, we don't need a runnable sample, but I'd like
to verify with a compilable one. This looks *AWFULLY* close. Get rid of
the "USE cheb_grid", either provide a trivial const module defining DP
or just hack in a replacement definition for it for illustrative
purposes. Make sure you really have nothing else in teh file. Then see
if you get the same error. Oh, and since the 2 modules are independent
and can't even be used together, I'd also be tempted to put them in
separate files; shouldn't matter, but there is always a possibility that
something is getting confused in the compiler by having them together
(if information from the first module isn't completely cleared out
before processingthe second).

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Wed, 07 May 2008 00:02:43 GMT  
 the problem of declaring a function in the interface

Quote:

>> -----------------------------------------------------------------------------------------------------------------
>> Compile Error Message

>> "functions.f", 1514-199 (S) Array up_mv_mul is a deferred-shape array
>> but does not have the POINTER or ALLOCATABLE attributes
>> ** def_fncs   === End of Compilation 1 ===
>> ** functions   === End of Compilation 2 ===
>> 1501-511  Compilation failed for file functions.f.

> Is this xlf?  I'm not sure I recognize it.
> I know IBM is adding f03 features rather quickly,
> but apparently, the release of xlf you have
> doesn't support allocatable function results.

> You might inquire with your compiler vendor
> if a new release is planned which will support
> allocatable function results.

Looks very much like xlf. I'm pretty sure than the allocatable TR
stuff was in xlf 8, and given that 10 has just been realeased it suggests
that the OPs compiler is a bit old,

Ian



Fri, 09 May 2008 18:52:28 GMT  
 the problem of declaring a function in the interface
As Richard suggested, I separated two modules in different files and
try not to use "use" and took out unnessary part now.

------------- Error Messsge
----------------------------------------------
xlf95 -c -qmoddir=MODDIR -IMODDIR def_fncs.f

"def_fncs.f", 1514-199 (S) Array a is a deferred-shape array but does
not have the POINTER or ALLOCATABLE attributes.
** def_fncs   === End of Compilation 1 ===
1501-511  Compilation failed for file def_fncs.f.

----------------- functions.f ---------------------------------------
module functions
  INTEGER, PARAMETER :: DP = KIND(1.0D0)
  implicit none
contains
  function A(x)
    implicit none
    real(dp), dimension(:), intent(in) :: x
    real(dp), dimension(:), allocatable   :: A
  end function A
end module functions

-----       def_fncs.f
odule def_fncs
  interface
     function A(x)
       INTEGER, PARAMETER :: DP = KIND(1.0D0)
       implicit none
       real(dp), dimension(:), intent(in) :: x
       real(dp), dimension(:), allocatable   :: A
     end function A
  end interface
end module def_fncs
---------------------------------------------------------------------------------------------------



Sat, 10 May 2008 04:15:56 GMT  
 the problem of declaring a function in the interface

Quote:

> As Richard suggested, I separated two modules in different files and
> try not to use "use" and took out unnessary part now.

  [elided]

Well, that does make it pretty clear now. Nice, completely
self-contained check case with perfectly fine code. If the compiler
claims to support the allocatable TR, then this would be a compiler bug
(and it is the kind of bug report that compiler-writers love, being
small and self-contained).

The only remaining question would be whether the version of the
copmpiler that you have claims to support the TR. Well, not quite the
only question, as even if the compiler didn't support the TR, I'd say
that the error message was misleading enough to merit a bug report.

If your version of xlf is current, I'd suggest submitting this as a bug
report.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Sat, 10 May 2008 05:01:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Declaring interface MSSOAPinit

2. Declaring COM-interfaces in Python?

3. compilation problem with module function interface definition

4. Problems with Allecro CL Foreign Function interface/unsigned values

5. Weird foreign function interface problem:

6. Kcl C function interface problem

7. Declare Function : passing a structure

8. A question about "declare function"

9. Need to Declare a QuickTime function on Win, but dunno which's Win QT DLL

10. CW 2.003 and declaring C-functions?

11. Does Declaring Functions Take Syst Memory

12. functions need declaring before use

 

 
Powered by phpBB® Forum Software