fortran90

Interoperability of C variadic function and Fortran

ε祈祈猫儿з 提交于 2019-12-10 12:57:35
问题 Is there a way to declare a C variadic function and call it from Fortran? I need to call this function to compute some dot products between vectors labeled with a string. My idea was to declare something like the following, where the variable list of arguments contains string literals. If the variable list of arguments is empty, then I would do a lookup among the standard labels and perform the calculation. If the user specified two labels I would retrieve those two vectors and get their dot

FORTRAN: Save array and use in another programme

心不动则不痛 提交于 2019-12-10 12:15:56
问题 Is it possible to create an array in one programme and then use it in other programmes? The array I am looking to create is very large and its creation will take a while so I don't want to make it anew every time I run the main programme but instead just use it after creating it once in the other programme. Because of its size I'm not sure if printing it to file and then reading it back in would not also be quite inefficient? It is an integer array of dimensions 1:300 000 and 100. 回答1: Long

Call Python function from Fortran/C

瘦欲@ 提交于 2019-12-10 09:58:56
问题 I am writing a Fortran code and I would like to use some special functions and methods from Python libraries. This is a Python code: from mpmath import * from scipy.optimize import * def g(A,B,t): return newton(lambda x: (x - A*polylog(1.5, B*exp(-t*x))), 0.0) In fortran code I would like to pass real values A,B,t and get in return the value of g(A,B,t) (possibly complex). This can also be done in C. I would like to mention that mixing Python with other languages is something new to me. 回答1:

CEILING and FLOOR function in Fortran - aren't they supposed to return INTEGERS?

99封情书 提交于 2019-12-10 07:06:04
问题 A quick question regarding the CEILING and FLOOR functions in Fortran 90/95. Based on the documentation: https://gcc.gnu.org/onlinedocs/gfortran/CEILING.html My impression is that they take in REALs, but return INTEGERs. However, as an example, for this simple program, I get: PROGRAM example REAL:: X=-3.4 nintx = NINT(x) ceilx = CEILING(X) floorx = FLOOR(X) WRITE(*,*) nintx, ceilx, floorx END PROGRAM I get -3, -3.00000 and -4.00000. But based on the documentation all return types are INTEGERs

Removing whitespace in string

。_饼干妹妹 提交于 2019-12-09 19:25:43
问题 I have the following code: program main character (len=15) :: abc = "te st tex t" print *, trim(abc) end program main Which outputs: te st tex t I excepted all the whitespace to be removed but it wasn't. How can I remove all the whitespace from the string? 回答1: Trim will remove spaces only at the edges, not in the middle (this is common behaviour on almost all languages/libraries). If you want to remove all spaces in the string, you will have to create your own function to do this, iterating

Calling Fortran subroutine from Julia. Arrays work, but integers don't

自古美人都是妖i 提交于 2019-12-09 18:08:37
问题 I have this simple Fortran 90 program: subroutine apc_wrapper(i, j, k) implicit none integer*8, intent(in) :: i, j integer*8, intent(out) :: k double precision t k = i + js end subroutine compiled as a shared library gfortran -O2 -shared -fPIC apc_wrapper.f90 -o apc_wrapper.so Now, I want to call this subroutine from Julia, with all integer arguments, like this i = 2 j = 3 k = 0 ccall( (:apc_wrapper_, "./apc_wrapper.so"), Void, (Ptr{Int64}, Ptr{Int64}, Ptr{Int64}), &i, &j, &k) But it won't

The mysterious nature of Fortran 90 modules

与世无争的帅哥 提交于 2019-12-09 10:02:01
问题 Fortran 90 modules are evanescent creatures. I was using a (singular) module for a while with some success (compiling using Intel Visual Fortran and Visual Studio 2010). Then I wrote another module and tried to USE it in another function, before receiving this error: error #7002: Error in opening the compiled module file. Check INCLUDE paths. So I deleted the offending module. But now I receive the same error after when trying to access my original module! How can I locate these mysterious

Different CHARACTER lengths (3/4) in array constructor, how to trim strings - fortran

纵饮孤独 提交于 2019-12-09 00:34:34
问题 According to an answer to a similar question, I have declared the characters as indicated here gfortran does not allow character arrays with varying component lengths . However I would like to use a trim function because I need to add spaces to manually pad the names and these variables are then used in another part of the code. Can I trim at the same time as creating the array? Error: Different CHARACTER lengths (3/4) in array constructor at (1) If I add random characters to make them the

fortran format specifier for complex number

末鹿安然 提交于 2019-12-09 00:34:22
问题 Can I specify a format specifier for a complex number in fortran? I have a simple program. program complx1 implicit none complex :: var1 var1 = (10,20) write (*,*) var1 write (*,'(F0.0)') var1 write (*,'(F0.0,A,F0.0)') real(var1), ' + i ' , aimag(var1) end program complx1 Output: ( 10.0000000 , 20.0000000 ) 10. 20. 10. + i 20. I wanted to use inbuilt format for a+bi with some format specifier, instead of one did manually (second last line of program). Obviously F0.0 did not work. Any ideas?

Function which returns multiple values

旧街凉风 提交于 2019-12-08 19:55:37
问题 In Fortran, is it possible to define a function which returns multiple values like below? [a, b] = myfunc(x, y) 回答1: That depends... With functions , it is not possible to have two distinct function results. However, you can have an array of length two returned from the function. function myfunc(x, y) implicit none integer, intent(in) :: x,y integer :: myfunc(2) myfunc = [ 2*x, 3*y ] end function If you need two return values to two distinct variables, use a subroutine instead: subroutine