fortran2003

In Fortran2003, is 1D Assumed shape array interoperable with C?

佐手、 提交于 2021-02-05 08:36:06
问题 In Fortran 2003, the allocatable array is not interoperable with C. I suppose this has something to do with additional array information stored in memory which might disturb the C interpretation. But what if I declare a dummy argument as 1D assumed shape array? for example subroutine outter_subroutine(ma, size_ma) integer :: size_ma integer :: ma(size_ma) call fortran_subroutine(ma) end subroutine !----------------------------- subroutine fortran_subroutine(a) integer, intent(in) :: a(:)

Finalisation in FORTRAN 2003

岁酱吖の 提交于 2021-01-27 11:55:51
问题 According to Fortran Wiki the intel fortran compiler version 14 should support finalisation defined in FORTRAN 2003 standard. I tried to use this feature with ifort 14 , but observed strange behaviour. Following example should show this: module mtypes implicit none type mytype integer, private :: nr contains final :: delete_mytype procedure :: print_mytype end type contains !> \brief Constructs a new mytype !! \return The created mytype !> function init_mytype(number) type(mytype) :: init

Error: If selector expression in SELECT TYPE is not a named variable, associate-name=> shall appear

折月煮酒 提交于 2020-03-16 07:30:31
问题 I am trying to use a type in another type. However, I just cannot make it compile. It is strange to me: the select type thing works in the main program but it doesn't work in a subroutine the type. module ModBuffer implicit none private type, abstract, public :: Buffer contains procedure, public :: Constructor endtype Buffer type, extends(Buffer), public :: BufferR real(8), allocatable, public :: BufData(:,:,:) endtype BufferR type, extends(Buffer), public :: BufferI complex(8), allocatable,

Fortran; looping over file names with common attributes

不羁的心 提交于 2020-01-15 10:37:21
问题 I'm fairly new to Fortran and I am having trouble with my file names, I have a bunch of data in simuln#.res (where 1<#<20), I have multiple different directories with all the same simuln#.res names but they had different input parameters. The code looks like this: character(len=11) :: theFileA character(len=12) :: theFileB character(len=:), allocatable :: fileplace write(*,*) "the directory with the data sets, use quotations" read(*,*) fileplace fileLoop : do j=1,20 if (j .lt. 10) then write

Fortran; looping over file names with common attributes

烈酒焚心 提交于 2020-01-15 10:37:08
问题 I'm fairly new to Fortran and I am having trouble with my file names, I have a bunch of data in simuln#.res (where 1<#<20), I have multiple different directories with all the same simuln#.res names but they had different input parameters. The code looks like this: character(len=11) :: theFileA character(len=12) :: theFileB character(len=:), allocatable :: fileplace write(*,*) "the directory with the data sets, use quotations" read(*,*) fileplace fileLoop : do j=1,20 if (j .lt. 10) then write

Why do the names of overriding arguments have to match those of the abstract interface?

大兔子大兔子 提交于 2020-01-05 03:04:49
问题 Why do the names of arguments in overriding procedures need to match those of the abstract interface? I understand that clearly the TYPE , INTENT , etc of such arguments are required to match the interface, but why should the compiler care what I call my variables? In the following, I've defined a simple abstract utility class containing a single deferred procedure EVAL that takes a double precision argument. !------------------------------------- an abstract utility class ! type, abstract ::

direct indexing on function return value in fortran

☆樱花仙子☆ 提交于 2019-12-24 15:25:51
问题 Is there posibility to use indexing directly on a function's return value? Something like this: readStr()(2:5) where readStr() is a function which returns a character string. In many other languages it is quite possible, but what about Fortran? The syntax in my example of course does not compile. Is there any other syntax to be used? 回答1: No, that is not possible in Fortran. You could, however, alter your function to take an additional index array that determines which elements are returned.

Printing allocatable array in Fortran with gdb: Unhandled dwarf expression opcode 0x97 [duplicate]

谁说胖子不能爱 提交于 2019-12-24 13:25:52
问题 This question already has answers here : Fortran print allocatable array in gdb (3 answers) Closed 4 years ago . I've debugged the following piece of code in Cygwin and Eclipse using gdb as the debugger: program codetest implicit none integer, parameter :: dp = kind(1.0d0) integer, parameter :: N = 10 real(dp), dimension(:), allocatable :: vector integer :: i allocate(vector(1:N)) forall(i = 1:10) vector(i) = sqrt(real(i, dp)) end forall write(*, '(F7.3, 1X)', advance = 'no') (vector(i), i =

Assigning passive values or constants to a user-defined type

非 Y 不嫁゛ 提交于 2019-12-24 07:49:48
问题 So I'm working on an automatic differentiation toolbox in Fortran using operator overloading. I have previously implemented this in C++ but really need to get it to work in Fortran. I have the following module defined in Fortran: module adopov integer :: indexcount integer, parameter :: tape_size = 1000 ! !....... ADtype public :: ADtype type ADtype integer :: index = -1 real :: v = 0.0 ! contains procedure :: oo_asg generic, public :: assignment(=) => oo_asg end type ADtype ! !....... class

Writing a function that accepts any two numbers (any real or any integer)

最后都变了- 提交于 2019-12-24 02:18:08
问题 I have a function that accepts two numbers and I don't care if they are integers or real or 32bits or 64bits. For the example below, I just write it as a simple multiplication. In Fortran 90 you could do this with an interface block, but you'd have to write 16 (!) functions if you wanted to cover all the possible interactions of multiplying two numbers, each of which could be int32, int64, real32, or real64. With Fortran 2003 you have some other options like class(*) for polymorphism and I