fortran

Overflow in a random number generator and 4-byte vs. 8-byte integers

别来无恙 提交于 2021-02-05 10:54:37
问题 The famous linear congruential random number generator also known as minimal standard use formula x(i+1)=16807*x(i) mod (2^31-1) I want to implement this using Fortran. However, as pointed out by "Numerical Recipes", directly implement the formula with default Integer type (32bit) will cause 16807*x(i) to overflow. So the book recommend Schrage’s algorithm is based on an approximate factorization of m. This method can still implemented with default integer type. However, I am wondering

How to reverse a chain of characters?

无人久伴 提交于 2021-02-05 09:36:36
问题 I have to create a program that reverses phrases . For example: when I write hello guys , I want syug olleh This is what I have for the moment but I don't know how to reverse the characters in the board phraseT : program reversing implicit none character(len=20),dimension(1:20)::phraseT character(len=20)::phrase,reverse integer::i,x write(*,*)"write a phrase :" read(*,'(a)')phrase x=len(trim(phrase)) nomT(1:20)=" " do i=1,x nomT(i:i)=trim(phrase(i:i)) end do write(*,*)nomT end program

Error in implicit declaration in Fortran

喜你入骨 提交于 2021-02-05 09:30:51
问题 I have checked all the formats of the implicit type declaration but have not been able to find out the error in the following line . I have been running the code using f77 to compile this. implicit real*4 (a-h,o-z) while running the program it gives the following error for the above statement. implicit real*4 (a-h,o-z) 1 Error: Unexpected character in variable list at (1) 回答1: A few basic rules if you are using F77 or earlier versions. Put the implicit line first Columns 1-5 are for labels

Correct implementation of an explicit interface in Fortran

与世无争的帅哥 提交于 2021-02-05 09:30:10
问题 I am struggling with explicit interfaces in Fortran. In one instance, the compiler has requested that I write an explicit interface when I attempt to use an assumed-shape array as a dummy argument for a function or subroutine (i.e., procedure): Explicit interface required for ... assumed-shape argument . For example, this would appear like REAL, INTENT(IN OUT) :: dummy_array(:) in a subroutine. The (:) in the declaration of the array means that the compiler takes care of passing information

Strange Function Call behavior

我与影子孤独终老i 提交于 2021-02-05 09:12:51
问题 I am quite new to Fortran and I was 'playing' with functions. I found a quite weird behavior in a very simple program that I cannot justify in any way. Here is the simple code: Real*8 Function gamma(v) Implicit None Real*8 :: v gamma = 1.0_8 / Sqrt(1.0_8 - v ** 2) End Function gamma Program test_gamma Implicit None Real*8 :: v = 0.5_8, gamma print *,"Gamma = ", 1.0_8 / Sqrt(1.0_8 - v ** 2) End Program This prints the exact result: 1.1547005383792517 but if I use the function call, doing the

Strange Function Call behavior

核能气质少年 提交于 2021-02-05 09:12:17
问题 I am quite new to Fortran and I was 'playing' with functions. I found a quite weird behavior in a very simple program that I cannot justify in any way. Here is the simple code: Real*8 Function gamma(v) Implicit None Real*8 :: v gamma = 1.0_8 / Sqrt(1.0_8 - v ** 2) End Function gamma Program test_gamma Implicit None Real*8 :: v = 0.5_8, gamma print *,"Gamma = ", 1.0_8 / Sqrt(1.0_8 - v ** 2) End Program This prints the exact result: 1.1547005383792517 but if I use the function call, doing the

Error linking C and Fortran in installation of library

家住魔仙堡 提交于 2021-02-05 09:11:20
问题 I'm installing LoopTools version 2.15 (http://www.feynarts.de/looptools/LT25Guide.pdf), a library which evaluates special functions needed in physics. I had already installed it on a computer with Linux, and am now trying to install it on a Mac. I had to install a fortran compiler, which I did easily through macports. However, the following error appears when I try to install the package: looking for gcc... /usr/bin/clang looking for g++... /usr/bin/clang++ looking for fortran... /opt/local

Error linking C and Fortran in installation of library

女生的网名这么多〃 提交于 2021-02-05 09:01:32
问题 I'm installing LoopTools version 2.15 (http://www.feynarts.de/looptools/LT25Guide.pdf), a library which evaluates special functions needed in physics. I had already installed it on a computer with Linux, and am now trying to install it on a Mac. I had to install a fortran compiler, which I did easily through macports. However, the following error appears when I try to install the package: looking for gcc... /usr/bin/clang looking for g++... /usr/bin/clang++ looking for fortran... /opt/local

How to pass array to a procedure which is passed as an argument to another procedure using Fortran

房东的猫 提交于 2021-02-05 08:49:12
问题 I am trying to pass the name of another subroutine_b and an array to a generic subroutine_a. This subroutine_a is supposed to pass the array to subroutine_b and get back its computed value. Following is the code that I have written: module pass_subroutine_mod1 implicit none private public :: ave_value, fx contains subroutine ave_value( func, x, y, ave ) ! Calculate average of y which is passed on from another function `func`. ! external :: func double precision, intent(in), dimension(:) :: x

In Fortran2003, is 1D Assumed shape array interoperable with C?

佐手、 提交于 2021-02-05 08:36:06
问题 In Fortran 2003, the allocatable array is not interoperable with C. I suppose this has something to do with additional array information stored in memory which might disturb the C interpretation. But what if I declare a dummy argument as 1D assumed shape array? for example subroutine outter_subroutine(ma, size_ma) integer :: size_ma integer :: ma(size_ma) call fortran_subroutine(ma) end subroutine !----------------------------- subroutine fortran_subroutine(a) integer, intent(in) :: a(:)