derived-types

A Fortran function/subroutine that could return either a real, an integer or a string.

人盡茶涼 提交于 2019-12-20 04:32:56
问题 I would like to know how to create a function that either returns a real, an integer or a string. For example, the call would be write(*,*)dt%get() where get() would return : an integer if dt%isInteger = .true. a real if dt%isReal = .true. a character if dt%isStr = .true. I believe this might be possible by using an abstract interface to make procedure get() point to either procedure getInteger() , getReal() or getStr() but the abstract interface definition needs to define the ouput type

Fortran derived types: Overloaded assignment operator not working with 'PARAMETER' attribute

两盒软妹~` 提交于 2019-12-19 10:26:37
问题 I am using a derived type (bicomplex), and an overload of the assignment operator (=), so that one can assign a real*8 to bicomplex . A MWE of the bicplx module follows: MODULE bicplx type bicomplex COMPLEX*16 :: a COMPLEX*16 :: b end type interface assignment(=) module procedure dble_assign_bicplx end interface contains subroutine dble_assign_bicplx(qleft, xright) implicit none type(bicomplex), intent(out) :: qleft double precision, intent(in) :: xright qleft%a = xright qleft%b = 0.0d0

Cannot assign initial value to derived data type in a module

岁酱吖の 提交于 2019-12-12 02:22:14
问题 In a Fortran module , I'm trying to assign initial value to a derived data type whose component is a procedure pointer, but get an error message: unexpected pointer assignment. In a module , how to assign initial value to a derived type containing a procedure pointer? module pointer_mod use legendrePolynomials implicit none interface function func (z) real*8 :: func real*8, intent (in) :: z end function func end interface type proc_ptr procedure (func), pointer, nopass :: f_ptr end type proc

Creating XmlSerializer that serializes/deserializes derived types correctly

浪尽此生 提交于 2019-12-11 10:49:24
问题 I'm trying to create an XmlSerializer that serialize and deserializes derived types properly. Please take a look at the code below. Any assistance in using XmlAttributeOverrides ad extra types to create proper XmlSerializer and serialize an instance of GetVehicleResponse with VehicleObject as "SUV" object is greatly appreciated. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using InteractiveSoftworks.Framework.Xml; using

cast base class pointer to one of several possible derived type pointer based on condition

半世苍凉 提交于 2019-12-11 05:27:48
问题 I have a base class B and several derived template classes D<int> , D<float> , D<double> , etc. (so more than ten) In my program, I find a situation where I have a B pointer that I KNOW points to an instance one of the D specializations. I also have a unique key that identifies the derived type. So, I want to call the correct derived class method using my base class pointer and the unique type key. I actually want to do this in several places, so the one solution I have come up with is not

Fortran derived types containing derived types to be accessible from C

喜夏-厌秋 提交于 2019-12-09 03:51:27
As an extension to this post , I have derived types which have as members derived types themselves. Example below: module simple use iso_c_binding TYPE SIMPLEF INTEGER :: A INTEGER, POINTER :: B, C(:) END TYPE SIMPLEF TYPE COMPLEXF INTEGER :: X TYPE (SIMPLEF) :: Y END TYPE COMPLEXF end module simple The aim is, as in the post above, to have similar derived types in C and to be able to pass values back and forth to Fortran. The solution can be seen here . However here it's not just a derived type, it is a derived type with a member which is a derived type itself. Would I need to create for

Fortran save procedure as property in derived type

别说谁变了你拦得住时间么 提交于 2019-12-08 08:26:31
问题 Is it possible to store a procedure as a property of a derived type? I was thinking of something along the lines of: module funcs_mod public :: add contains function add(y,z) result (x) integer,intent(in) :: y,z integer :: x x = y + z end function end module module type_A_mod use funcs_mod public :: type_A,set_operator type type_A procedure(),pointer,nopass :: operator end type contains subroutine set_operator(A,operator) external :: operator type(type_A),intent(inout) :: A A%operator =>

Type bound procedure as arguments

和自甴很熟 提交于 2019-12-08 07:03:03
问题 I want to pass a type bound procedures (as an external function) to another function as follows: module mod1 implicit none type type1 real :: a contains procedure,pass :: f end type contains real function f(y,e) class(type1), intent(in) :: y real,intent(in) :: e f=y%a+e end function end module program test use mod1 type(type1) :: t t%a=3e0 write(*,*) s(t%f) contains real function s(g) real,external :: g s=g(5e0)+2e0 end function end program gfortran produces gives this error : write(*,*) s(t

Is it possible to declare a matrix as a derived type in Fortran?

非 Y 不嫁゛ 提交于 2019-12-08 06:46:01
问题 Is it possible to declare a matrix as a derived type in Fortran? For example, can something be done so that the call class(four_by_four_matrix) :: A call A%inv is valid? Where inv is declared as a procedure of four_by_four_matrix ? 回答1: The answer to the question "is it possible?" is yes, it is possible. Just put a 2d array into your type: type four_by_four_matrix real(rp) :: arr(4,4) contains procedure :: inv => four_by_four_matrix_inv end type contains subroutine four_by_four_matrix_inv

Subtypes vs Derived Types in C++

随声附和 提交于 2019-12-08 03:54:53
问题 I recently heard one of my coworkers claim that the concept of a "subtype" is not defined in C++. He claims that "subtypes" are rightly called "derived types" in C++ terminology. Is this true? If I have: class A { }; class B : public A { }; Can I call B a subtype of A? Or is it only valid to call B a "derived type" of A in C++? 回答1: Subtype is not part of the common jargon in C++. The definition in Wikipedia (thanks Chad) is quite broad and in C++ could represent multiple different things,