fortran2003

Type bound procedure overloading in Fortran 2003

佐手、 提交于 2019-12-22 08:38:30
问题 I've been programming in Java for a few years; however, I'm now taking a course which uses Fortran as example code (77 standard). Although I've always viewed Fortran as an ancient language, I decided to try out the latest implementation of the 2003 standard using the gfortran compiler to see its merits for myself. So far, I've been surprised with the modern features, but I have run into one issue which is demonstrated by the example below. module mod1 type type1 real :: x real :: y contains

Nested derived type with overloaded assignment

假如想象 提交于 2019-12-21 12:18:21
问题 I have a derived type ( wrapper ) containing an other derived type ( over ). For the latter the assignment operator have been overloaded. As the assignment of derived types happens per default componentwise, I'd expect that assigning two instances of wrapper would invoke the overloaded assignment for over at some point. However, using the program below, it does not seem to be the case. The overloaded assignment is only invoked if I also overload the assignment for wrapper containing an

Polymorphism in fortran

大憨熊 提交于 2019-12-20 03:34:11
问题 I have a code similar to: Module C_sys use class_A implicit none Private Type, public :: C_sys_type private logical :: Ao_set = .false. type(A) :: Ao Contains Private Procedure, public :: get_Ao Procedure, public :: set_Ao End Type C_sys_type interface C_sys_type Procedure C_sys_type_constructor end interface C_sys_type Contains type(C_sys_type) elemental function C_sys_type_constructor(Ao) result(C_sys) type(A), intent(in), optional :: Ao C_sys % Ao = Ao C_sys % Ao_set = .true. end function

Is there an alternative to GETCWD() in Fortran 2003-2008

此生再无相见时 提交于 2019-12-19 07:09:21
问题 The GNU Extension to the GNU Fortran compiler provides the subroutine GETCWD() that well, gets the current working directory. However, my code has to be portable to the ifort and nagfor compiler as well and I use F2003 features. So, is there an alternative to GETCWD() for F2003 and later? I have the standard here but it's quite sizeable and I've been going through it for a while now and haven't found anything useful... 回答1: You can also use the ISO_C_Binding and call the corresponding C

fortran class declaration of dummy argument

醉酒当歌 提交于 2019-12-13 15:02:28
问题 I would like to have a derived type, a , which is empty. From this derived type I would like to define further types which extend a. Suppose all of these type extensions contain some generic procedure name, value , i.e value => valuea1 , value => valuea2 , etc. If I then want to pass variables of class a to some other procedure, I need to declare the relevant dummy argument of that procedure with class(a) . If I do this, however, then referencing the value of the dummy argument leads to

There is no matching specific subroutine for this type bound generic subroutine call

試著忘記壹切 提交于 2019-12-12 01:48:15
问题 I have a type with two bound procedures (GetAsScalar & GetAsList) under a generic procedure (GetValue): type, extends(TObject) :: TKeyword character(len=:), allocatable :: fValue contains procedure, private :: GetAsScalar procedure, private :: GetAsList generic :: GetValue => & GetAsScalar, & GetAsList end type TKeyword The routines signatures are these: subroutine GetAsScalar (this, value, status) !Arguments------------------------------------------------------------- class(TKeyword) :: this

Reading a file of lists of integers in Fortran

最后都变了- 提交于 2019-12-11 21:09:58
问题 I would like to read a data file with a Fortran program, where each line is a list of integers. Each line has a variable number of integers, separated by a given character (space, comma...). Sample input: 1,7,3,2 2,8 12,44,13,11 I have a solution to split lines, which I find rather convoluted: module split implicit none contains function string_to_integers(str, sep) result(a) integer, allocatable :: a(:) integer :: i, j, k, n, m, p, r character(*) :: str character :: sep, c character(:),

access operators “[ ], ( ), { }” overloading in Fortran 90 or 2003

∥☆過路亽.° 提交于 2019-12-11 03:43:19
问题 Can I overload entry access operators [], () or {} for derived data types in FORTRAN 2003? In the following example, I want to define access scheme for the derived data type "custom". type custom integer, dimension(:), allocatable :: a end type custom type(custom) :: t ! after some initialization ! ..... ! ..... ! ..... ! t%a( (/ 1, 2, 5 /) ) ! return entries located in positions 1, 2, and 5 t{ (/ 1, 2, 5 /) } ! ?????? I want to define what stuff it should return How can I do that? Update:

Polymorphism allocation in a SELECT TYPE construct

和自甴很熟 提交于 2019-12-11 03:02:50
问题 I am trying to define a subroutine which allocates different types of arrays. Here is a simplified version of the code: subroutine Allocation1(Vec) class(*), allocatable, intent(out) :: Vec(:) select type(Vec) type is(real(8)) allocate(Vec(10)); Vec = 0.D0 type is(complex(8)) allocate(Vec(10)); Vec = (0.D0,0.D0) type is(integer) allocate(Vec(10)); Vec = 0 endselect endsubroutine Allocation1 But I got three error messages that I don't understand: error #8306: Associate name defined in

Fortran function returning unallocated array causes segmentation fault

邮差的信 提交于 2019-12-11 00:29:08
问题 I'm struggling with some Modern Fortran wrappers to some MPI scatter/gather routines. I am trying to have a wrapper interface that only has an array on input and returns the MPI-operated result on output, for several derived types, doing something like this: type(mytype), allocatable :: chunk(:),whole(:) ! [...] chunk descends from previous parts of the code ! Get global array whole = gatherv(array=chunk,receiver_node=cpuid) I'm doing this using functions that return allocatable arrays.