fortran95

Fortran DO loop, warning to use integer only

删除回忆录丶 提交于 2021-02-15 11:08:55
问题 I installed gfortran on my Ubuntu 15.04 system. While compiling Fortran code, the DO loop asks to take integer parameters only and not real values or variables. That includes the loop variable and the step expression. Why can't it take real values too? The following is a program taken from here, exercise 3.5 of the section nested do loops . program xytab implicit none !constructs a table of z=x/y for values of x from 1 to 2 and !y from 1 to 4 in steps of .5 real :: x, y, z print *, ' x y z'

Same value assignment of multiple variables in a single statement

时光总嘲笑我的痴心妄想 提交于 2020-08-07 07:12:07
问题 Is there a way where I can assign the same value for different variables without constructing an array in a single statement? For example, if I have variables a,b,c,d , and e , can I assign something like a=b=c=d=e=10.0 ? I know that I can do in a single line: a=10.0; b=10.0; c=10.0; d=10.0; e=10.0 But that is not I want since if I want to change the value 10.0 later to something else, I have to make the change everywhere. 回答1: Come on Fortranners, you know you want to ... equivalence(a,b,c,d

Fortran- Inverse Matrix result not same if Decimal is longer

房东的猫 提交于 2020-01-16 16:09:11
问题 My real data is first input but inverse of result is so big. They are same data when you compare with first and second input. There is only difference decimal size. Why is there different result? Because they are same data. How can they have different result? You can see result and input. It is so strange. program test Implicit none double precision,allocatable,dimension(:,:) :: A double precision,allocatable,dimension(:) :: WORK integer ,allocatable,dimension(:) :: ipiv integer :: n,info,M

Fortran- Inverse Matrix result not same if Decimal is longer

孤街醉人 提交于 2020-01-16 16:08:45
问题 My real data is first input but inverse of result is so big. They are same data when you compare with first and second input. There is only difference decimal size. Why is there different result? Because they are same data. How can they have different result? You can see result and input. It is so strange. program test Implicit none double precision,allocatable,dimension(:,:) :: A double precision,allocatable,dimension(:) :: WORK integer ,allocatable,dimension(:) :: ipiv integer :: n,info,M

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

喜你入骨 提交于 2020-01-13 06:55:29
问题 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!" ? 回答1: One possibility would be to read in the entire line into a string buffer, and look for (some of) the delimiters

Calling a subroutine multiple times with different function as argument each time

会有一股神秘感。 提交于 2020-01-06 20:08:10
问题 I'm enough of a novice to not know the terminology, so I can't search the Web for the answer to this. More than once, in programming, I've wanted to do something like this. A and B are subroutines, c and d are functions. A and B each call a function multiple times inside them. call A(c(x)) call A(d(x)) call B(c(x)) call B(d(x)) This structure doesn't work. I'm told that Fortran doesn't support aliasing of functions, at least in this context. (Most search results involving "aliasing" refer to

Convert FORTRAN DEC UNION/MAP extensions to anything else

陌路散爱 提交于 2020-01-05 05:28:07
问题 Edit: Gfortran 6 now supports these extensions :) I have some old f77 code that extensively uses UNIONs and MAPs. I need to compile this using gfortran, which does not support these extensions. I have figured out how to convert all non-supported extensions except for these and I am at a loss. I have had several thoughts on possible approaches, but haven't been able to successfully implement anything. I need for the existing UDTs to be accessed in the same way that they currently are; I can

Smart printing of integers in fortran90

你说的曾经没有我的故事 提交于 2020-01-03 11:25:12
问题 I'm learning Fortran90 after a brief introduction to Fortran77 a few years ago. When printing integers in Fortran, you must specify how many spaces you want to reserve for printing the integer. Consider this program... implicit none integer :: i i = 123 write(*, '(A, I3, A)') "'", i, "'" !3 spaces for output = no padding write(*, '(A, I5, A)') "'", i, "'" !5 is too many, so output is padded write(*, '(A, I2, A)') "'", i, "'" !2 is too few, so output is jibberish write(*, '(A, I:, A)') "'", i,

Smart printing of integers in fortran90

戏子无情 提交于 2020-01-03 11:25:07
问题 I'm learning Fortran90 after a brief introduction to Fortran77 a few years ago. When printing integers in Fortran, you must specify how many spaces you want to reserve for printing the integer. Consider this program... implicit none integer :: i i = 123 write(*, '(A, I3, A)') "'", i, "'" !3 spaces for output = no padding write(*, '(A, I5, A)') "'", i, "'" !5 is too many, so output is padded write(*, '(A, I2, A)') "'", i, "'" !2 is too few, so output is jibberish write(*, '(A, I:, A)') "'", i,

How to implement Structures of Arrays instead of Arrays of Structures in Fortran?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 19:11:08
问题 I'm writing my code on CFD topic with Fortran. After discussing with some friends from computer science, they told me that one could speed up the computation time if one implements Structures of Arrays (SoA) instead of Arrays of Structures (AoS) on his/her code. There are many examples I've seen about this topic's implementation, but most of them are in C or C++. (e.g. https://software.intel.com/en-us/articles/how-to-manipulate-data-structure-to-optimize-memory-use-on-32-bit-intel