- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm trying to use the following type of "template" in fortran, but I have some question about the implementation.
The code compile and run without problem with the intel compiler, but if I try to use other compilers (sun,gfortran,g95), I have some compilation errors ( different errors for each compiler ):
------- print_coord.f90 -------
subroutine print_coord(coord)
real(8), dimension(3), intent(in) :: coord
print*,coord
end subroutine print_coord
-----------------------------------------
------- print_data_type.i90 -------
!module DATA_TYPE_mod
!use data_type_module, only: data_type => point_t
private
interface print_type_coord
subroutine print_coord(point)
import:: data_type
type(data_type), intent(in) :: point
end subroutine print_coord
end interface print_type_coord
public:: print_type_coord
!end module DATA_TYPE_mod
---------------------------------------------
------- test.f90 -------
module types
public
type point_t
real(8), dimension(3) :: coord
integer :: id
end type point_t
type sphere_t
real(8), dimension(3) :: coord
real(8) :: radius
integer :: id
end type sphere_t
end module types
!--
module point_mod
use types, only: data_type => point_t
include "print_data_type.i90"
end module point_mod
!--
module sphere_mod
use types, only: data_type => sphere_t
include "print_data_type.i90"
end module sphere_mod
!--
program test
use types
use point_mod, only: print_point_coord => print_type_coord
use sphere_mod, only: print_sphere_coord => print_type_coord
type(point_t) :: point
type(sphere_t) :: sphere
point = point_t( (/0.0,0.0,0.0/) , 1 )
sphere = sphere_t( (/1.0,1.0,1.0/), 0.5, 2 )
call print_point_coord(point)
call print_sphere_coord(sphere)
end program test
---------------------------------
I don't know if the fortran 2003 standard permit "import" a renamed type.
Maybe someone can help me with this, or with a better way of make "templates" in fortran.
thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An extra question about this is: if I have two public types with the same name (data_type), is it possible some kind of problem or conflict when the "import" statement is used??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So if you have something like this:
module a
type data_type
integer i
end type data_type
end module a
module b
type data_type
real r
end type data_type
end module b
program foo
use a
use b
at this point, data_type cannot be referenced - even if the type declarations were "the same", they are different declarations according to the language. You could do this:
use a, a_type => data_type
use b
now you have access to both definitions, though with different names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
module a
type data_type
integer i
end type data_type
contains
subroutine foo1(data)
type(data_type), intent(in) :: data
print*,data
end subroutine foo1
end module a
program foo
use a, a_type => data_type
type(a_type) :: a_data
...
call foo1(a_data)
...
The rename can affect the access to some routine ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hope the other compilers enable this, for the portability problem. I believe is really useful this way of "templates" for not write different files with the same routines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My earlier comments regarding the behavior of IMPORT stand - I did not mean to imply that deliberately mismatching argument types was standard-conforming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure if this is not allowed by the standard or directly is not in the standard this possiblity.
The thing is find a way of use some kind of "template" style for the programing.
I ask the same in the SUN Compiler forum and the answer was equivalent. But the sun compiler generate a warning in the compilation of the files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran standard, at present, does not allow for a deliberate type mismatch. The standard way to do this is through generic procedures, but this would require different procedures for each combination of type, kind and rank. You may be able to make it work if you don't mind violating the standard, but this is implementation-dependent.
There is a proposal being circulated around the Fortran committee for syntax that would selectively relax interface checking rules. Most compilers already implement this with implementation-dependent syntax (Intel's is !DEC$ ATTRIBUTES NO_ARG_CHECK), but there is disagreement among committee members as to what it should look like and what it should mean.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page