fortran90

Fortran 90 compiling issue: undefined reference to <modulename>

帅比萌擦擦* 提交于 2019-12-21 03:58:23
问题 I'm having trouble trying to compile a simple fortran program which uses a module in the same directory. I have 2 files: test1.f90 which contains the program and modtest.f90 which contains the module. This is test1.f90: program test use modtest implicit none print*,a end program test This is modtest.f90: module modtest implicit none save integer :: a = 1 end module modtest Both files are in the same directory. I compile modtest.f90 and test.f90 like this: gfortran -c modtest.f90 gfortran -o

Overloading functions with Fortran

亡梦爱人 提交于 2019-12-20 17:39:55
问题 In Fortran 90, we can overload functions with an interface. However, according to this site, we cannot define these functions with the same arguments name. With gfortran, it does not seem to be a problem as the following code works well enough: interface check module procedure check_int, check_real end interface contains subroutine check_int(cur, dname, func_name, fname) integer, allocatable, intent(in) :: cur(:) character(*) :: dname, func_name, fname ... end subroutine subroutine check_real

Getting the ith permutation of a list

不想你离开。 提交于 2019-12-20 07:49:14
问题 I need a fortran code that calculates the ith permutation of a given list {1,2,3,...,n}, without computing all the permutations, that are n!. Is there anyone that can help me? Thank you in advance. 回答1: I solved my problem. In the following I show you both the Mathematica and Fortran codes I implemented. If you have any advise for improve them, do not esitate to comment. MATHEMATICA (example: 10° permutation of {1,2,3,4,5}) n = 5; i = 10; p = Range[n]; ithPermutation = p; Do[f = (n - k)!; d =

way Fortran handles empty spaces

♀尐吖头ヾ 提交于 2019-12-20 04:15:23
问题 I would like to have some clarifications about the way Fortran handles "empty" characters in strings. Let us assume we have this situation: program main implicit none test('AB') end program where function test(name) implicit none character(10) :: name character(3) :: cutname write(*,*) '-'//name//'-' ! Gives output "-AB -" ! Space has then been added at the end cutname(1:3) = name(1:3) write(*,*) '1-'//cutname//'-' ! Gives output "-AB -" ! It seems there is a space then at the end ! of

Unclassifiable statement and other errors in an IF in Fortran

你。 提交于 2019-12-20 03:52:19
问题 I have the code: if i < n then x = topsep(1) y = topsep(2) realvor(n,1) = x + dx realvor(n,2) = x + dy imvor(n,1) = (realvor(n,1)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2) imvor(n,2) = (realvor(n,2)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2) tf = .TRUE. else x = botsep(1) y = botsep(2) realvor(n,1) = x + dx realvor(n,2) = y - dy imvor(n,1) = (realvor(n,1)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2) imvor(n,2) = (realvor(n,2)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2) tf = .FALSE.

Subroutine with array element as argument

五迷三道 提交于 2019-12-20 03:30:26
问题 In my program subroutine stlstp passing work(2,1) as parameter to stlfts(...) subroutine. work(2,1) will be double value at that index, but how subroutine converting it as single dimension array x(n) ? When I print x value in stlfts(...) subroutine, it is printing elements of n size, example: STLFTS....X,,, 0.0000000000000000 1.4964418382246345E-317 1.48978578 58438612E-317 1.4964339331743010E-317 1.4964418382246345E-317 4.3367611401 .... My understanding is, except 1st value, all other

How to get the name of a file acting as stdin/stdout?

浪子不回头ぞ 提交于 2019-12-20 02:47:26
问题 I'm having the following problem. I want to write a program in Fortran90 which I want to be able to call like this: ./program.x < main.in > main.out Additionally to "main.out" (whose name I can set when calling the program), secondary outputs have to be written and I wanted them to have a similar name to either "main.in" or "main.out" (they are not actually called "main"); however, when I use: INQUIRE(UNIT=5,NAME=sInputName) The content of sInputName becomes "Stdin" instead of the name of the

Dynamic function creation from another function

馋奶兔 提交于 2019-12-19 19:42:09
问题 I have a Fortran 90 subroutine which takes a function as an argument, and I would like to pass a modified version of that function into another subroutine. I want the program to look something like this: subroutine foo(f, ...) real :: pt(2), dir(2) interface function f(x) result(y) real, intent(in) :: x(2) real :: y end function f end interface pt = ... dir = ... !! Somehow create g(x) = f(pt + x*dir) call bar(g) end subroutine foo subroutine bar(g) interface function g(x) result(y) real,

Storing a Variable with a Multi-Dimensional Index in Fortran

有些话、适合烂在心里 提交于 2019-12-19 11:29:23
问题 Question Consider the following code: program example implicit none integer, parameter :: n_coeffs = 1000 integer, parameter :: n_indices = 5 integer :: i real(8), dimension(n_coeffs) :: coeff integer, dimension(n_coeffs,n_indices) :: index do i = 1, n_coeffs coeff(i) = real(i*3,8) index(i,:) = [2,4,8,16,32]*i end do end For any 5 dimensional index I need to obtain the associated coefficient, without knowing or calculating i . For instance, given [2,4,8,16,32] I need to obtain 3.0 without

Converting data stored in Fortran 90 binaries to human readable format

一世执手 提交于 2019-12-19 11:28:21
问题 In your experience, in Fortran 90, what is the best way to store large arrays in output files? Previously, I had been trying to write large arrays to ASCII text files. For example, I would do something like this (thanks to the recommendation at the bottom of the page In Fortran 90, what is a good way to write an array to a text file, row-wise?): PROGRAM testing1 IMPLICIT NONE INTEGER :: i, j, k INTEGER, DIMENSION(4,10) :: a k=1 DO i=1,4 DO j=1,10 a(i,j)=k k=k+1 END DO END DO OPEN(UNIT=12,