fortran95

Linking FORTRAN and C++ objects files

假如想象 提交于 2019-12-08 01:54:28
I am going to call a C++ function from FORTRAN, for which I am using ISO_C_Binding module. After compaction of the FORTRAN main file and C++ function with commands gfortran -c mlp8.f90 g++ -c mean_cpp.cc Which will create the objects files but in the linking phase as suggested by some members I am going to use the commands g++ mlp8.o mean_cpp.o -o main –lgfortran I.e. using C++ compiler with linking to FORTRAN libraries but it gives error like /Cygnus/cygwin-b20/H-i586-cygwin32/i586-win32/bin/ld: cannot open –lgfortran: No such a file or directory Collect2:ld return 1 exit status So I think

Have a function in fortran return a reference that can be placed on the left-hand-side of an assignment

拥有回忆 提交于 2019-12-07 17:40:38
问题 As stated in the title, I want to directly modify data that I access through a pointer retrieved from a function. Having a reference returned by a function appearing on the l.h.s. of an assignment(=) is no issue in C++ but the following minimal example in fortran errors out: module test_mod implicit none integer, target :: a=1, b=2, c=3 ! some member variables contains function get(i) integer, pointer :: get integer, intent(in) :: i select case (i) case (1) get => a case (2) get => b case (3)

How to provide an explicit interface to a library of Fortran 95+ modules, with implementation hiding

人盡茶涼 提交于 2019-12-07 10:06:59
问题 I'm using gfortran's 95+ extensions. I have a library of utility modules I'd like to link to other projects, i.e. as a library or shared object / dll. However, in Fortran, I don't understand how to split the interface from the implementation in Fortran without maintaining two copies of the module interface. In C, I would separate the interface from the implementation like: api.h ←includes← impl.h ↑ ↑ includes includes ↑ ↑ user.c impl.c Is there a way to achieve the same effects in modern

Automatic width integer descriptor in fortran 90

我的未来我决定 提交于 2019-12-07 09:13:49
问题 I wanted to use automatic integer width descriptor in fortran 90. I referred to Output formatting: too much whitespace in gfortran This question says that I can use I0 and F0,0 for "auto" width. Here is my sample code (complied with GNU Fortran Compiler): PROGRAM MAIN IMPLICIT NONE INTEGER :: i REAL :: j WRITE (*,*) 'Enter integer' READ (*,100) i 100 FORMAT (I0) WRITE (*,*) 'Enter real' READ (*,110) j 110 FORMAT (F0.0) WRITE (*,100) 'Integer = ',i WRITE (*,110) 'Real = ',j END PROGRAM There

Random array / matrix intitialisation in Fortran

拥有回忆 提交于 2019-12-06 10:20:50
Is there a way to initialise a random array without using explicit do-loops? Right now my random matrix initialisation looks like program Main implicit none save integer :: seed, i, j real :: x character(100) :: option real, dimension(10,10) :: matrix if (iargc() > 0) then CALL GETARG(1,option) read(option,*) seed else seed = 1 end if call RANDOM_SEED(seed) do i=1,10 do j=1,10 call RANDOM_NUMBER(x) matrix(i,j) = x end do end do end program But if possible I'd like it to be more along the lines of an implied do-loop array initialisation: program Main implicit none save integer :: seed character

Have a function in fortran return a reference that can be placed on the left-hand-side of an assignment

独自空忆成欢 提交于 2019-12-05 20:15:48
As stated in the title, I want to directly modify data that I access through a pointer retrieved from a function. Having a reference returned by a function appearing on the l.h.s. of an assignment(=) is no issue in C++ but the following minimal example in fortran errors out: module test_mod implicit none integer, target :: a=1, b=2, c=3 ! some member variables contains function get(i) integer, pointer :: get integer, intent(in) :: i select case (i) case (1) get => a case (2) get => b case (3) get => c end select end function get end module test_mod program test use test_mod implicit none

Automatic width integer descriptor in fortran 90

◇◆丶佛笑我妖孽 提交于 2019-12-05 18:09:08
I wanted to use automatic integer width descriptor in fortran 90. I referred to Output formatting: too much whitespace in gfortran This question says that I can use I0 and F0,0 for "auto" width. Here is my sample code (complied with GNU Fortran Compiler): PROGRAM MAIN IMPLICIT NONE INTEGER :: i REAL :: j WRITE (*,*) 'Enter integer' READ (*,100) i 100 FORMAT (I0) WRITE (*,*) 'Enter real' READ (*,110) j 110 FORMAT (F0.0) WRITE (*,100) 'Integer = ',i WRITE (*,110) 'Real = ',j END PROGRAM There is runtime error (unit = 5, file = 'stdin') Fortran runtime error: Positive width required in format Am

How to provide an explicit interface to a library of Fortran 95+ modules, with implementation hiding

十年热恋 提交于 2019-12-05 15:46:33
I'm using gfortran's 95+ extensions. I have a library of utility modules I'd like to link to other projects, i.e. as a library or shared object / dll. However, in Fortran, I don't understand how to split the interface from the implementation in Fortran without maintaining two copies of the module interface. In C, I would separate the interface from the implementation like: api.h ←includes← impl.h ↑ ↑ includes includes ↑ ↑ user.c impl.c Is there a way to achieve the same effects in modern Fortran? Do I need to provide users my library with the .mod files? Single definition of an explicit

How to read comma delimited data file if some data include spaces

China☆狼群 提交于 2019-12-04 19:59:31
I am trying to read a data file which uses comma as delimiter as shown below IPE 80,764,80.14,8.49 IPE 100,1030,171,15.92 However If I read using READ(1,*) var1, var2, var3, var4 It reads IPE and 80 as different data. In other words it counts both commas and spaces as delimiter but I don't want this. How can I tell to my program "hey spaces are not delimiter only commas!" ? One possibility would be to read in the entire line into a string buffer, and look for (some of) the delimiters yourself. Assuming that similar to your example, only the first column contains with whitespaces, you could do

Data type mismatch in fortran

左心房为你撑大大i 提交于 2019-12-04 06:04:28
问题 I've written a rudimentary algorithm in Fortran 95 to calculate the gradient of a function (an example of which is prescribed in the code) using central differences augmented with a procedure known as Richardson extrapolation. function f(n,x) ! The scalar multivariable function to be differentiated integer :: n real(kind = kind(1d0)) :: x(n), f f = x(1)**5.d0 + cos(x(2)) + log(x(3)) - sqrt(x(4)) end function f !=====! !=====! !=====! program gradient !=========================================