For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > interface block and kind parameter









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author interface block and kind parameter
gtg531e

2005-08-17, 10:01 pm

Hi, everybody,

I have the following problem.
I want to pass one function as an argument
to another function (see piece of code below).
When I used normal reals everything worked
without problems.
But when I tried to use function
"selected_real_kind(..)"
to define my own reals. Compilator stops
(I tried different compilators)
in the interface block and complains
like this

ifort:
Error: A kind type parameter must be a compile-time constant.

g95 :
Variable 'real14' at (1) cannot appear in an initialization expression

nag f90 :
"REAL14" is used in a constant expression, therefore it must be a constant.


May be I do not notice something obvious.
Can you explain me, please, what is going
on and how to fix it.


!=======================================
======================================
module testint

implicit none

integer, parameter :: real14=selected_real_kind(14,200)

contains

complex(kind=real14) function in1z(func,x_min,x_max,tolerance)

implicit none

integer :: point
integer :: step

real(kind=real14), intent(in) :: x_min
real(kind=real14), intent(in) :: x_max
real(kind=real14) :: x_
real(kind=real14), intent(in) :: tolerance
real(kind=real14) :: spacing

complex(kind=real14) :: auxsum

interface
complex(kind=real14) function func(x)
real(kind=real14), intent(in) :: x !< stops compilation here
end function func
end interface

.........
.........


--
igor.
James Van Buskirk

2005-08-18, 4:03 am

"gtg531e" <gtg531e@prism.gatech.edu> wrote in message
news:de0s1q$o7k$1@news-int.gatech.edu...

> interface
> complex(kind=real14) function func(x)
> real(kind=real14), intent(in) :: x !< stops compilation here
> end function func
> end interface


Yeah, that's a 'feature' of f95: you can't inject context from
the current scope into INTERFACE blocks. In this form, you can
fix it up by creating a separate module which defines your named
constant real14 and then USE this module in module testint as
well as separately in your interface block above. Here, I just
did this yesterday to test g95's calling convention:

! File: testf.f90
module mykinds
implicit none
integer, parameter :: ik8 = selected_int_kind(18)
end module mykinds

program testf
use mykinds
implicit none
interface
function testa()
use mykinds
implicit none
integer(ik8) testa
end function testa
end interface

write(*,'(1x,z16.16)') testa()
end program testf

! End of file: testf.f90

# File: testa.s
..globl _testa_

..data

..text
..align 4

_testa_:
movl $0x00000001, %eax
movl $0x00000012, %edx
ret
# End of file: testa.s

In this case the only way to create an explicit interface,
if desired, is via an INTERFACE block. Note how mykinds
must be USEd in both the containing program unit (PROGRAM
TESTF) and the INTERFACE block.

Results of test:

C:\g95_MINGW\test>as testa.s -otesta.o

C:\g95_MINGW\test>g95 testf.f90 testa.o -otestf

C:\g95_MINGW\test>testf
0000001200000001

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


gtg531e

2005-08-18, 5:59 pm

Thanks, it works now.



James Van Buskirk wrote:

> "gtg531e" <gtg531e@prism.gatech.edu> wrote in message
> news:de0s1q$o7k$1@news-int.gatech.edu...
>
>
> Yeah, that's a 'feature' of f95: you can't inject context from
> the current scope into INTERFACE blocks. In this form, you can
> fix it up by creating a separate module which defines your named
> constant real14 and then USE this module in module testint as
> well as separately in your interface block above. Here, I just
> did this yesterday to test g95's calling convention:
>
> ! File: testf.f90
> module mykinds
> implicit none
> integer, parameter :: ik8 = selected_int_kind(18)
> end module mykinds
>
> program testf
> use mykinds
> implicit none
> interface
> function testa()
> use mykinds
> implicit none
> integer(ik8) testa
> end function testa
> end interface
>
> write(*,'(1x,z16.16)') testa()
> end program testf
>
> ! End of file: testf.f90
>
> # File: testa.s
> .globl _testa_
>
> .data
>
> .text
> .align 4
>
> _testa_:
> movl $0x00000001, %eax
> movl $0x00000012, %edx
> ret
> # End of file: testa.s
>
> In this case the only way to create an explicit interface,
> if desired, is via an INTERFACE block. Note how mykinds
> must be USEd in both the containing program unit (PROGRAM
> TESTF) and the INTERFACE block.
>
> Results of test:
>
> C:\g95_MINGW\test>as testa.s -otesta.o
>
> C:\g95_MINGW\test>g95 testf.f90 testa.o -otestf
>
> C:\g95_MINGW\test>testf
> 0000001200000001
>


--
igor.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com