- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am working on an example using classes from the Guide to Fortran 2008 Programming. I want to see if classes will help in what I am trying to do. I have worked with classes in other languages .
Here is the part of the code that I get an error from.
module v_q_module
use vehicle_module
implicit none
private
type :: node_type
class(vehicle_type), allocatable :: v
end type node_type
type, public :: q_type
private
type(node_type), dimension(:), allocatable :: vehicles
contains
procedure :: empty, is_empty, insert, remove, print_licenses
end type q_type
contains
subroutine empty(q)
class(q_type), intent(out) :: q
q%vehicles = [ node_type :: ]
end subroutine empty
end module v_q_module
The error is the following:
C:\Michael\traffic_simulation\traffic_simulation\module2.f90(19): error #5082: Syntax error, found '::' when expecting one of: , : (/ ]
C:\Michael\traffic_simulation\traffic_simulation\module2.f90(19): error #6478: A type-name must not be used as a variable. [NODE_TYPE]
compilation aborted for C:\Michael\traffic_simulation\traffic_simulation\module2.f90 (code 1)
All the reading I have done tells me that this line should be a valid statement.
q%vehicles = [ node_type :: ]
Thanks.
Michael
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is a bug in Intel Fortran compiler, please submit a support request if you can at Intel Online Service Center.
A couple of suggestions:
- Try another compiler or two if you can to guide your learning of modern Fortran e.g., open-source gfortran (https://gcc.gnu.org/wiki/GFortran) and if possible, another commercial compiler - see point 2,
- Consider participating in Fortran language discourse at https://fortran-lang.discourse.group/. where you can find more options and resources re: Fortran and other compilers, etc..
Note this variant below of your code in the original post. It works as I expect using gfortran:
module vehicle_module
type :: vehicle_type
end type
end module
module v_q_module
use vehicle_module
implicit none
private
type :: node_type
class(vehicle_type), allocatable :: v
end type node_type
type, public :: q_type
private
type(node_type), dimension(:), allocatable :: vehicles
contains
procedure :: empty, get_num_vehicles
end type q_type
contains
subroutine empty(q)
class(q_type), intent(out) :: q
q%vehicles = [ node_type :: ]
end subroutine empty
function get_num_vehicles(q) result(num)
class(q_type), intent(in) :: q
integer :: num
num = 0
if ( allocated(q%vehicles) ) num = size(q%vehicles)
end function
end module v_q_module
use v_q_module
type(q_type) :: foo
call foo%empty()
print *, "number of vehicles in foo = ", foo%get_num_vehicles(), "; expected is 0."
end
number of vehicles in foo = 0 ; expected is 0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FortranFan,
Thanks for the advice. I would have to do the extra stuff at home. We are bound to the Intel complier at work. This project is something that I am doing to make a contribution at work when I do not have an upgrade project for the current application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@kolber__Michael wrote:
.. We are bound to the Intel complier at work. This project is something that
I am doing to make a contribution at work when I do not have an upgrade
project for the current application
You can consider a workaround based on an "original" facility in Fortran for dynamic memory i.e., the ALLOCATE statement:
allocate( q%vehicles(0) )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is fixed in the nightly builds here for the ifort BETA in the oneAPI HPC Toolkit. It's still a bug in the current beta08 release of this kit. But the nightly build which is going into the oneAPI HPC Toolkit for the next beta, beta09, has this working:
rwgreen:~/quad/u1198085$ module load comp/nightlybuild
rwgreen:~/quad/u1198085$ ifort -O0 -what -o repro repro.f90
Intel(R) Fortran 2021.1-1898
rwgreen@orcsle156:~/quad/u1198085$ ./repro
number of vehicles in foo = 0 ; expected is 0.
rwgreen:~/quad/u1198085$ cat repro.f90
module vehicle_module
type :: vehicle_type
end type
end module
module v_q_module
use vehicle_module
implicit none
private
type :: node_type
class(vehicle_type), allocatable :: v
end type node_type
type, public :: q_type
private
type(node_type), dimension(:), allocatable :: vehicles
contains
procedure :: empty, get_num_vehicles
end type q_type
contains
subroutine empty(q)
class(q_type), intent(out) :: q
q%vehicles = [ node_type :: ]
end subroutine empty
function get_num_vehicles(q) result(num)
class(q_type), intent(in) :: q
integer :: num
num = 0
if ( allocated(q%vehicles) ) num = size(q%vehicles)
end function
end module v_q_module
use v_q_module
type(q_type) :: foo
call foo%empty()
print *, "number of vehicles in foo = ", foo%get_num_vehicles(), "; expected is 0."
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I remember reporting a similar bug a long time ago. I wonder what's different about this case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page