fortran90

Fortran array cannot be returned in function: not a DUMMY variable

北城以北 提交于 2019-12-18 06:49:38
问题 Being new to Fortran 90 free-form, I would really like to know why the following piece of code snippet would not work: program test2 implicit none !!! A program to practice f90 writing. ! Define double precision data integer, parameter :: dp = kind(1.d0) real(dp) :: a(3), b(3) integer :: i a = (/(i, i=1, 3)/) b = (/(i, i=1, 3)/) write (*, *) m31tensorprod(a, b) contains function m31tensorprod(a, b) real(dp), dimension(3), intent(in) :: a, b real(dp), intent(out) :: m31tensorprod(3, 3) integer

Function with more arguments and integration

≯℡__Kan透↙ 提交于 2019-12-17 21:32:31
问题 I have I simple problem but I cannot find a solution anywhere. I have to integrate a function (for example using a Simpson's rule subroutine) but I am obliged to pass to my function more than one argument: one is the variable that I want to integrate later and another one is just a value coming from a different calculation which I cannot perform inside the function. The problem is that the Simpson subroutine only accept f(x) to perform the integral and not f(x,y). After Vladimir suggestions I

How to increase array size on-the-fly in Fortran?

风格不统一 提交于 2019-12-17 18:41:20
问题 My program is running though 3D array, labelling 'clusters' that it finds and then doing some checks to see if any neighbouring clusters have a label higher than the current cluster. There's a second array that holds the 'proper' cluster label. If it finds that the nth adjoining cluster is labelled correctly, that element is assigned to 0, otherwise is assigns it to the correct label (for instance if the nth site has label 2, and a neighbour is labeled 3, the 3rd element of the labelArray is

What does “real*8” mean?

痴心易碎 提交于 2019-12-17 07:30:16
问题 The manual of a program written in Fortran 90 says, "All real variables and parameters are specified in 64-bit precision (i.e. real*8 )." According to Wikipedia, single precision corresponds to 32-bit precision, whereas double precision corresponds to 64-bit precision, so apparently the program uses double precision. But what does real*8 mean? I thought that the 8 meant that 8 digits follow the decimal point. However, Wikipedia seems to say that single precision typically provides 6-9 digits

Procedure with assumed-shape dummy argument must have an explicit interface [duplicate]

我只是一个虾纸丫 提交于 2019-12-17 06:15:29
问题 This question already has an answer here : Module calling an external procedure with implicit interface (1 answer) Closed 2 years ago . I am completely new to Fortran 90 and I am trying to understand how to pass an array to a function. I looked on the web and I could not find any clear and simple enough example, so I decided to post here. I would like the function be able to work on an array of any length (the length of the array should not be one of the parameters of the functions). I tried

How to initialize two-dimensional arrays in Fortran

我怕爱的太早我们不能终老 提交于 2019-12-17 05:03:09
问题 In C you can easily initialize an array using the curly braces syntax, if I remember correctly: int* a = new int[] { 1, 2, 3, 4 }; How can you do the same in Fortran for two-dimensional arrays when you wish to initialize a matrix with specific test values for mathematical purposes? (Without having to doubly index every element on separate statements) The array is either defined by real, dimension(3, 3) :: a or real, dimension(:), allocatable :: a 回答1: You can do that using reshape and shape

Fortran 90 function return pointer

倾然丶 夕夏残阳落幕 提交于 2019-12-14 03:57:06
问题 I saw this question: Fortran dynamic objects and the accepted answer made me question if I wrote the following function safely (without allowing a memory leak) function getValues3D(this) result(vals3D) implicit none type(allBCs),intent(in) :: this real(dpn),dimension(:,:,:),pointer :: vals3D integer,dimension(3) :: s if (this%TF3D) then s = shape(this%vals3D) if (associated(this%vals3D)) then stop "possible memory leak - p was associated" endif allocate(vals3D(s(1),s(2),s(3))) vals3D = this

how I can define variable name with “ write ” command in fortran

ぐ巨炮叔叔 提交于 2019-12-14 03:12:20
问题 I need to define a variable name for different files inside a Fortran code, while I 'm using this commands open(unit=5,file="plot.sm") write(unit=zbin_str,fmt='(f5.2)') zbin plotname="LF_z"//zbin_str//".ps" write(5,"dev postencap" plotname) write(5,"toplabel LF for",//zbin_str//) I'm receiving these errors : Syntax error, found '//' when expecting one of: ( * <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ... write(5,"toplabel LF for",//zbin_str//) error #6355:

How to implement factorial function into code?

笑着哭i 提交于 2019-12-14 02:05:49
问题 So I am using the taylor series to calculate sin(0.75) in fortran 90 up until a certain point, so I need to run it in a do while loop (until my condition is met). This means I will need to use a factorial, here's my code: program taylor implicit none real :: x = 0.75 real :: y integer :: i = 3 do while (abs(y - sin(0.75)) > 10.00**(-7)) i = i + 2 y = x - ((x**i)/fact(i)) print *, y end do end program taylor Where i've written fact(i) is where i'll need the factorial. Unfortunately, Fortran

Integration of Bessel functions in C++/Fortran [closed]

一世执手 提交于 2019-12-13 09:37:15
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . How can I integrate an equation including bessel functions numerically from "0" to "infinity" in Fortran or/and C? I did in matlab, but it's not true for larger inputs and after a specific values , the bessel functions give completely wrong results(there is a restriction in Matlab) 回答1: You can