fortran90

expand a dense matrix

亡梦爱人 提交于 2020-01-23 04:03:11
问题 What would be the most efficient way to expand a dense matrix with new columns in FORTRAN? Say T is a dense matrix m by n and I would like to make it m by n+1. One strategy I could think of : Reallocate at each step and assign the last column or would there be some better ways, such as allocating some space before and checking if that is sufficient and if not do the reallocation kind of stuff? Any ideas? 回答1: Assuming m and n are in some sense not exceedingly large, so that your matrices fit

What does “%” mean / do in Fortran?

て烟熏妆下的殇ゞ 提交于 2020-01-22 08:54:04
问题 I am trying to read some Fortran code, but can not determine what the % (percentage sign) does. It is in a line like: x = a%rho * g * (-g*a%sigma + m%gb * m%ca * (1.6 * a%rho+g)) What does it do? 回答1: In Fortran 90 they allow you to create structures like in C++. It basically acts as the dot (.) operator. From http://www.lahey.com/lookat90.htm : Structures (Derived Types) You can group your data using derived types. This enables users to combine intrinsic types (including arrays and pointers)

Write array to file by columns

房东的猫 提交于 2020-01-21 16:44:49
问题 Is there a way to write columns to a file one by one? For example, I would like to write: write(1,*) 1 write(1,*) 2 And then write (possibly in another subroutine) write(1,*) 3 write(1,*) 4 in such a way that will produce an output file in the format: 1 3 2 4 without combining the arrays (e.g.) write(1,*) 1,3 write(1,*) 2,4 I'm thinking that there may be a way to move the "pointer" (of file location) back to the beginning and add spaces or something, but I really have no idea if this is

Write array to file by columns

风流意气都作罢 提交于 2020-01-21 16:43:12
问题 Is there a way to write columns to a file one by one? For example, I would like to write: write(1,*) 1 write(1,*) 2 And then write (possibly in another subroutine) write(1,*) 3 write(1,*) 4 in such a way that will produce an output file in the format: 1 3 2 4 without combining the arrays (e.g.) write(1,*) 1,3 write(1,*) 2,4 I'm thinking that there may be a way to move the "pointer" (of file location) back to the beginning and add spaces or something, but I really have no idea if this is

Are local variables in procedures automatically private when using OpenMP?

帅比萌擦擦* 提交于 2020-01-17 03:35:27
问题 I am relatively new to using OpenMP with Fortran 90. I know that local variables in called subroutines are automatically private when using a parallel do loop. Is the same true for functions that are called from the parallel do loop? Are there any differences between external functions and functions defined in the main program? I would assume that external functions behave the same as subroutines, but I am specifically curious about functions in main program. Thanks! 回答1: The local variables

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

Fortran double precision converted to Python float

余生颓废 提交于 2020-01-16 05:04:44
问题 I have the following subroutine in generation.f90 SUBROUTINE generation(t, prob) IMPLICIT NONE INTEGER, INTENT(IN) :: t REAL(8), INTENT(OUT) :: prob INTEGER :: nT2, c Do some stuff with t, nT2 and c prob = nT2/(DBLE(1.0)*c) END SUBROUTINE generation I want to use it in Python, so I wrap it with f2py f2py -c -m generation generation.f90 --fcompiler=gnu95 Then in ipython I do from generation import * a = generation(10000); type(a) and I get float . I checked the C file testmodule.c generated

f2py complication due parameter array dimensions being defined in modules / common blocks

喜你入骨 提交于 2020-01-16 04:46:27
问题 I have the following subroutine in Fortran 90: subroutine foo(bar) use spam ! dimension n is defined in the module spam implicit none real*8 bar(n) .... end subroutine foo Since the array dimension n is defined in module spam , I am getting errors during the compilation of the C wrapper functions (generated by f2py ), like error: ‘n’ undeclared (first use in this function) Because the C wrapper function does not have any reference to spam or n . What should be the solution to this? I am

Fortran 90 - to transmit values from main subroutine to the functions and other subroutines

痴心易碎 提交于 2020-01-15 05:14:26
问题 I hope everyone's doing good. I presently have a project at work and I'm having a hard time dealing with some programming techniques. To summarize my project, I have to modify some codes on Fortran so that it can be adapted to be used on a simulation software called PRO/II. All the functions and subroutines have already been written. However, to make the codes compatible with PRO/II, I have to change the way of assigning some input data (input by the user himself) on Fortran. In fact, before,