fortran90

generate a sequence array in fortran

可紊 提交于 2021-02-07 05:34:15
问题 Is there an intrinsic in Fortran that generates an array containing a sequence of numbers from a to b, similar to python's range() >>> range(1,5) [1, 2, 3, 4] >>> range(6,10) [6, 7, 8, 9] ? 回答1: No, there isn't. You can, however, initialize an array with a constructor that does the same thing, program arraycons implicit none integer :: i real :: a(10) = (/(i, i=2,20, 2)/) print *, a end program arraycons 回答2: If you need to support floats, here is a Fortran subroutine similar to linspace in

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

Passing character strings of different lengths to functions in Fortran

北战南征 提交于 2021-02-05 07:18:12
问题 I am using Fortran 90 with the gfortran compiler as part of cygwin. I want to write a function that will create a series of new folders into a directory that is also passed as a parameter along with a number that is the maximum number of new consecutively numbered folders. Since I have to declare the length of the characters (ie strings) but also want to universally be able to pass different paths, I tried to pass the trimmed strings to the function. program main implicit none character(len =

This FORTRAN code shouldn't compile. Is there a reason why it does?

邮差的信 提交于 2021-02-05 05:55:26
问题 The following code compiles, but I do not think that it should. As you can see, the output is garbage. This is a minimal failing example of something that bit me hard in a large project I work on. My question is - why does the compiler not complain? Is this a compiler limitation, or is this somehow "expected behaviour", and I've missed something? I'm using gfortran 4.6.3. module dataModule integer :: datum1 = int(1) integer :: datum2 = int(2) end module dataModule program moduleTest use

How can I read a 2D file which content is not separated by spaces in Fortran

可紊 提交于 2021-01-27 23:13:33
问题 I have a matrix stored in a file (number.txt), like this: 12323456 54254311 76534522 How can I read such matrix in Fortran, so the result would be: 1 2 3 2 3 4 5 6 5 4 2 5 4 3 1 1 7 6 5 3 4 5 2 2 It is very easy to separate these columns using awk and read it in Fortran. But, I would like to know if I can do all this using only Fortran. After I am done with I will need to multiple this matrix by its transpose. 回答1: Fortran formatted input and output is based on fields . Fields are not

How can I read a 2D file which content is not separated by spaces in Fortran

十年热恋 提交于 2021-01-27 22:04:10
问题 I have a matrix stored in a file (number.txt), like this: 12323456 54254311 76534522 How can I read such matrix in Fortran, so the result would be: 1 2 3 2 3 4 5 6 5 4 2 5 4 3 1 1 7 6 5 3 4 5 2 2 It is very easy to separate these columns using awk and read it in Fortran. But, I would like to know if I can do all this using only Fortran. After I am done with I will need to multiple this matrix by its transpose. 回答1: Fortran formatted input and output is based on fields . Fields are not

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

gfortran compilation error: Size of 'put' argument of 'random_seed' intrinsic at (1) too small [duplicate]

孤人 提交于 2021-01-24 07:38:35
问题 This question already has an answer here : What's wrong with my random number generator in Fortran 95 please? (1 answer) Closed 5 years ago . I am trying to compile the following code with gfortran program perm_field implicit double precision(a-h,o-z) parameter (pi=3.14159) allocatable :: perm(:),alog_perm_all(:),u(:),xi(:),& perm_zone(:),alog_perm(:) integer :: seed(2) external dgemm open(unit=1,file='input.dat') open(unit=3,file='random_log_perm.dat',access='append') open(unit=31,file=

gfortran compilation error: Size of 'put' argument of 'random_seed' intrinsic at (1) too small [duplicate]

南笙酒味 提交于 2021-01-24 07:35:51
问题 This question already has an answer here : What's wrong with my random number generator in Fortran 95 please? (1 answer) Closed 5 years ago . I am trying to compile the following code with gfortran program perm_field implicit double precision(a-h,o-z) parameter (pi=3.14159) allocatable :: perm(:),alog_perm_all(:),u(:),xi(:),& perm_zone(:),alog_perm(:) integer :: seed(2) external dgemm open(unit=1,file='input.dat') open(unit=3,file='random_log_perm.dat',access='append') open(unit=31,file=