fortran2008

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

Reading bad values from binary file in Fortran with a defined input procedure

孤人 提交于 2019-12-19 09:29:51
问题 I'm trying to write a simple code, which takes some objects with the same parental abstract class, stores them into a binary file and reads them back. My code looks like this: module m implicit none type :: container class(a), allocatable :: item end type container type, abstract :: a character(20), public :: obj_type integer, public :: num contains procedure :: write_impl => write_a procedure :: read_impl => read_a generic :: write(unformatted) => write_impl generic :: read(unformatted) =>

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

Variables being deleted in Fortran Arrays?

坚强是说给别人听的谎言 提交于 2019-12-12 19:15:33
问题 I have a following code, with an abstract type, inherited type and a short program, where I'm creating an object and storing it in an array. module m implicit none type :: container class(a), allocatable :: item end type container type, abstract :: a integer, public :: num end type a type, extends(a) :: b integer, public :: num2 end type b end module m program mwe use m implicit none class(a), allocatable :: o1 class(container), allocatable :: arr(:) o1 = b(1, 2) allocate(arr(2)) arr(1) =

Using Iso_Fortran_Env to set a function's Kind value

不想你离开。 提交于 2019-12-11 08:42:41
问题 How would one go about using ISO Fortran Env's intrinsic to set a function's return KIND value in a manner which is idiomatic to Fortran 2008? Normally within the main program, I can just use the ISO Fortran intrinsics as follows: program name here use iso_fortran_env implicit none integer, parameter :: double=REAL64 real(kind=double) :: some_variable end program name here But there doesn't seem to be a convenient way to use these intrinsics for external functions, since REAL64 and double

Heterogeneous array of Fortran classes

别说谁变了你拦得住时间么 提交于 2019-12-11 00:16:56
问题 I have an abstract type and several types which inherit from him. Now I need to make an array of instances of those inherited types, but I'm not sure, if it's even possible in Fortran. I've tried to make some wrapper type, like in Creating heterogeneous arrays in Fortran. module m implicit none type, abstract :: a integer, public :: num end type a type, extends(a) :: b end type b type, extends(a) :: c end type c type :: container class(*), allocatable :: ptr end type end module m program mwe

Reading bad values from binary file in Fortran with a defined input procedure

谁都会走 提交于 2019-12-01 08:13:45
I'm trying to write a simple code, which takes some objects with the same parental abstract class, stores them into a binary file and reads them back. My code looks like this: module m implicit none type :: container class(a), allocatable :: item end type container type, abstract :: a character(20), public :: obj_type integer, public :: num contains procedure :: write_impl => write_a procedure :: read_impl => read_a generic :: write(unformatted) => write_impl generic :: read(unformatted) => read_impl end type a type, extends(a) :: b integer, public :: num2 contains procedure :: write_impl =>

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

萝らか妹 提交于 2019-12-01 06:20:25
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... You can also use the ISO_C_Binding and call the corresponding C functions: cwd.c: #ifdef _WIN32 /* Windows */ #include <direct.h> #define GETCWD _getcwd #else /* Unix */