fortran

Fortran: Passing a member procedure to an external function

让人想犯罪 __ 提交于 2021-01-27 20:11:56
问题 How do I point to a type-bound procedure? Say that I have some external subroutine that takes as an argument a pointer to a function that accepts only one argument. call integrator(f0) This will work if the function f0 is defined somewhere so that it looks like function f0(x) result(val) ... do something... end function But now I have a type SomeClass with some type-bound procedures. One of these type-bound procedures is function integrand(this,x) result(val) class(SomeClass), intent(in) ::

What is the canonical way to allocate and construct polymorphic objects in Fortran?

那年仲夏 提交于 2021-01-27 19:51:32
问题 I want to create an array of polymorphic objects which have constructors taking different dummy arguments depending on their dynamic type. Having read about user-defined and structure constructors, I see no way to apply these concepts to dynamically allocated objects. Having a background in C++, I was used to the notion that I could use one and the same constructor "member function" when allocating objects either dynamically or on the stack, but how can I explicitly call user-defined Fortran

Fortran order of operations for exponents

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 18:51:27
问题 I'm translating some Fortran into Javascript and the order of operations for exponents is pretty opaque to me for a particular class of equations. Here's an example of the Fortran equation: x = 1+a*b**c*c**d Exponents in Fortran are designated with the ** operator. This page gives some hints: Arithmetic expressions are evaluated in accordance with the following priority rules: All exponentiations are performed first; consecutive exponentiations are performed from right to left. All

Restart a loop in Fortran

落花浮王杯 提交于 2021-01-27 13:42:55
问题 I have an algorithm that looks like this: 10 WRITE (*,*) "Start" DO I = 1, 10 WRITE (*,*) "Step" IF(I .EQ. 5) then go to 10 END IF END DO I want to restart the loop, when that if statement executes. However, I don't want to have to use a go to, I tried this: 10 WRITE (*,*) "Start" DO I = 1, 10 WRITE (*,*) "Step" IF(I .EQ. 5) then I = 0; CYCLE END IF END DO But then I get the error that I can't redefine the I variable, inside a loop. So I'm not sure how to approach this. Any help would be much

趋势预测:2021年五大流行的编程语言

社会主义新天地 提交于 2021-01-27 12:23:46
如果没有编程语言,现在的世界就不会存在。想象一下没有电脑、数字技术和互联网的生活,没有Instagram和TikTok。这会让我们的生活举步维艰,而且并不是不可能发生。 所有的语言都有自己的目的。有些用于编写移动应用程序,有些用于处理微控制器,还有一些用于创建桌面程序或分析。但也有一些情况下,一个问题可以用不同的语言解决。 编程语言的历史 当编程语言还没有诞生的时候,第一批程序员用数字来编写操作机器的指令。他们必须记住一个机器代码表,而不是像现在这样记住一些基本的算法和语言的原理。不久之后,编译器出现了,这让程序员的工作变得更容易,编译器是把程序员的话翻译成机器代码的程序。汇编语言成为第一种编程语言。 考虑到特定类型的处理器的特性,汇编语言是一种最低层次的编程语言。最低的并不意味着不好。这意味着语言操作符专注于特定的处理器指令,并且接近于机器代码。汇编语言的出现极大地改进了程序员的生活,因为现在,他们可以用近乎通用语言的字符组成的指令来编写程序,而不是用0和1。这种语言是编程领域的一个突破,因为它允许编写小型程序而受到欢迎。汇编程序的启动和运行速度比机器代码慢,但编写代码要容易得多。编程语言就是这样开始了蓬勃发展。 20世纪50年代,IBM为个人需求开发了第一个算法语言。它被命名为FORTRAN。那时候1已经有几种语言可以将算术表达式转换为机器代码

Fortran 90 doesn't keep lower/upper array bounds after copy to another allocatable array

孤者浪人 提交于 2021-01-27 12:21:26
问题 This doesn't work program main implicit none integer :: nx = 3 integer :: ny = 5 integer :: nz = 8 real, allocatable, dimension(:,:,:) :: A real, allocatable, dimension(:,:) :: B allocate(A(nx,0:ny,nz) ) ! ...do something with array A and at some point cope a slice of A to B: B = A(:,:,1) ! in this case B is (1:nx, 1: ny+1) end program main The code above automatically allocates B and copies A(:,:,1) to B. However it doesn't keep the lower/upper bound of 0/ny, instead B has its lower bound to

Passing arrays as smaller than they actually are

那年仲夏 提交于 2021-01-27 12:03:51
问题 In the following code, I declare an array mass with 20 elements. When passed to the subroutine foo , foo is told that mass has only 10 elements. However, I can still access the 20th element. My questions are: Why can I pass an array to a subroutine and tell the subroutine the wrong size for the array? Why can I still access the 20th element even though the subroutine thinks it only has 10 elements? Would any changes I make to the 20th element in the array while in foo remain with the array

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

Sign of infinity on division by zero

家住魔仙堡 提交于 2021-01-27 10:52:24
问题 I've implemented code to find the polar coordinates of a point in 2D space. if the point lies in the 1st or 2nd Quadrant, 0<=theta<=pi and if it lies in the 3rd or 4th Quadrant, -pi <= theta <= 0 . module thetalib contains real function comp_theta( x1, x2) implicit none real , intent(in) :: x1, x2 real :: x1p, x2p real :: x1_c=0.0, x2_c=0.0 real :: pi=4*atan(1.0) x1p = x1 - x1_c x2p = x2 - x2_c ! - Patch !if ( x1p == 0 .and. x2p /= 0 ) then ! comp_theta = sign(pi/2.0, x2p) !else ! comp_theta

Sign of infinity on division by zero

 ̄綄美尐妖づ 提交于 2021-01-27 10:52:02
问题 I've implemented code to find the polar coordinates of a point in 2D space. if the point lies in the 1st or 2nd Quadrant, 0<=theta<=pi and if it lies in the 3rd or 4th Quadrant, -pi <= theta <= 0 . module thetalib contains real function comp_theta( x1, x2) implicit none real , intent(in) :: x1, x2 real :: x1p, x2p real :: x1_c=0.0, x2_c=0.0 real :: pi=4*atan(1.0) x1p = x1 - x1_c x2p = x2 - x2_c ! - Patch !if ( x1p == 0 .and. x2p /= 0 ) then ! comp_theta = sign(pi/2.0, x2p) !else ! comp_theta