fortran

Is it possible to determine which Fortran compiler generated a “.mod” file?

三世轮回 提交于 2021-02-04 13:46:06
问题 Say I have a package already installed on my machine and I want to figure out if I need to regenerate the module include files ( .mod ) to make them compatible with the rest of my compilation. Is there any way to do this? 回答1: If the module is built using gfortran then using strings on the mod file (on Linux) will provide the compiler name and the version number. However, for Intel, the strings command will only show the compiler version number. 回答2: I had a similar problem at some point with

Preserve bounds in allocation in intrinsic assignment

梦想的初衷 提交于 2021-02-04 07:27:12
问题 I am using automatic allocation on assignment to calculate the difference of two arrays, with bounds starting at 0: program main implicit none integer, allocatable :: a(:), b(:), c(:) allocate(a(0:10)) allocate(b(0:10)) a = 1 b = 2 write (*,*) lbound(a) write (*,*) lbound(b) c = b - a write (*,*) lbound(c) end program main Both, gfortran and ifort give the output: 0 0 1 Why doesn't c have the same bounds as a and b? Is there a short and concise (without an explicit allocate) way of making

How to declare the type of a function that returns an array in Fortran?

二次信任 提交于 2021-02-04 07:26:31
问题 I have function that returns an array, say function f(A) implicit none real, intent(in) :: A(5) real, intent(out) :: f(5) f = A+1 end My question is, how can I define f in the main program unit? E.g. program main implicit none real :: A(5) real, dimension(5), external :: f ! does not work ... end 回答1: You need an explicit interface. You can do this in a few ways. Explicitly in the scoping unit that calls f : interface function f(A) implicit none real, intent(in) :: A(5) real :: f(5) end

How to declare the type of a function that returns an array in Fortran?

こ雲淡風輕ζ 提交于 2021-02-04 07:26:07
问题 I have function that returns an array, say function f(A) implicit none real, intent(in) :: A(5) real, intent(out) :: f(5) f = A+1 end My question is, how can I define f in the main program unit? E.g. program main implicit none real :: A(5) real, dimension(5), external :: f ! does not work ... end 回答1: You need an explicit interface. You can do this in a few ways. Explicitly in the scoping unit that calls f : interface function f(A) implicit none real, intent(in) :: A(5) real :: f(5) end

Undefined reference to 'main' when compiling a module

核能气质少年 提交于 2021-02-04 05:05:14
问题 I am learning Fortran, and I'm stuck trying to compile a module for later use. In the main program I have this, which asks for two numbers and then calls the function in the module: use exponentiate integer::a,b write *, 'A' read *, 'a write *, 'B' read *, 'b write *,expo(a,b) (I haven't tried that out because I need to compile the module first, but that's not the issue) Then, on another file I have this code, which (If I understood anything correctly) is just a standard module with a

Passing an array to a subroutine that expects a different shape

北城以北 提交于 2021-02-02 09:37:04
问题 I have a 1-dimensional work array real(8), allocatable :: work(:) which is passed to a subroutine that operates on a 2-dimensional array pure subroutine f(work, dim1, dim2) real(8), intent(out) :: work(dim1, dim2) integer, intent(in) :: dim1, dim2 ... What is the difference in the following ways of passing the array? call f(work, dim1, dim2) call f(work(1), dim1, dim2) Are they the same in that they just pass the pointer to the first array element or is there some extra overhead with either

Passing an array to a subroutine that expects a different shape

一笑奈何 提交于 2021-02-02 09:34:30
问题 I have a 1-dimensional work array real(8), allocatable :: work(:) which is passed to a subroutine that operates on a 2-dimensional array pure subroutine f(work, dim1, dim2) real(8), intent(out) :: work(dim1, dim2) integer, intent(in) :: dim1, dim2 ... What is the difference in the following ways of passing the array? call f(work, dim1, dim2) call f(work(1), dim1, dim2) Are they the same in that they just pass the pointer to the first array element or is there some extra overhead with either

Use fgsl in fortran: how to compile with gfortran

空扰寡人 提交于 2021-01-29 20:55:35
问题 I am trying to do something basic, but I can't find the relevant information on how to compile. I tried the following without success: gfortran testintegral.f90 -lgsl -lgslcblas testintegral.f90:19.6: use fgsl 1 Fatal Error: Can't open module file 'fgsl.mod' for reading at (1): No such file The file is taken from http://de.wikibooks.org/wiki/Fortran:_FGSL#Beispiel:_Numerische_Integration (page in german but readily understandable) so I suppose it is OK. Maybe the syntax of the compilation

Borwein’s algorithm for the calculation of Pi in Fortran is converging too fast

半城伤御伤魂 提交于 2021-01-29 18:39:25
问题 The following implementation of Borwein’s algorithm with quartic convergence in Fortran admittedly calculates Pi, but converges simply too fast. In theory, a converges quartically to 1/π. On each iteration, the number of correct digits is therefore quadrupled. ! pi.f90 program main use, intrinsic :: iso_fortran_env, only: real128 implicit none real(kind=real128), parameter :: CONST_PI = acos(-1._real128) real(kind=real128) :: pi integer :: i do i = 1, 10 pi = borwein(i) print '("Pi (n = ", i3

Use fgsl in fortran: how to compile with gfortran

空扰寡人 提交于 2021-01-29 18:36:27
问题 I am trying to do something basic, but I can't find the relevant information on how to compile. I tried the following without success: gfortran testintegral.f90 -lgsl -lgslcblas testintegral.f90:19.6: use fgsl 1 Fatal Error: Can't open module file 'fgsl.mod' for reading at (1): No such file The file is taken from http://de.wikibooks.org/wiki/Fortran:_FGSL#Beispiel:_Numerische_Integration (page in german but readily understandable) so I suppose it is OK. Maybe the syntax of the compilation