fortran95

Numerical Precision in Fortran 95:

霸气de小男生 提交于 2019-11-27 16:08:29
I have the following Fortran code: Program Strange Real(Kind=8)::Pi1=3.1415926535897932384626433832795028841971693993751058209; Real(Kind=8)::Pi2=3.1415926535897932384626433832795028841971693993751058209_8; Print*, "Pi1=", Pi1; Print*, "Pi2=", Pi2; End Program Strange I compile with gfortran, and the output is: Pi1= 3.1415927410125732 Pi2= 3.1415926535897931 Of course the second is correct, but should this be the case? It seems like Pi1 is being input to memory as a single precision number, and then put into a double precision memory slot. But this seems like an error to me. Am I correct? I do

Can the shape of an array in an interface match multiple fixed array size?

送分小仙女□ 提交于 2019-11-27 07:24:30
问题 I have multiple subroutines with a parameter p which is an array of explicit size like subroutine foo(p) integer,dimension(2),intent(in) ::p end subroutine foo subroutine bar(p) integer,dimension(3),intent(in) ::p end subroutine bar I'd like to call these two functions through an indirect call, but could not find a way to declare an interface that matches both foo and bar signature... Using an assumed array size in the interface for example does not work: subroutine indirect(f,p) integer

getting free unit number in fortran

a 夏天 提交于 2019-11-27 06:02:48
问题 I need to develop a library that opens a file and parses the stuff. The unit number, due to fortran IO style, must be decided by me, but I can't know what other units are open in the client code. Is there a standard function like give_me_any_unit_number_that_is_free() ? 回答1: In fortran 2008, there's a newunit clause to open that you can use integer :: myunit .. open(newunit=myunit,file='file.dat') ... close(myunit) but that's new enough that not all compilers support it yet. If yours doesn't

Fortran: the largest and the smallest integer

為{幸葍}努か 提交于 2019-11-27 03:22:13
问题 Fortran is completely new for me, can anybody help me to solve the follwing problem? I want to find out all the integer kind numbers and the largest and the smallest value for each kind number on my pc. I have code listed below: program intkind implicit none integer :: n=1 integer :: integer_range =1 do while(integer_range /= -1) print*, "kind_number ", selected_int_kind(n) call rang(integer_range) n = n *2 integer_range = selected_int_kind(n) end do contains subroutine rang(largest) integer

Fortran print allocatable array in gdb

扶醉桌前 提交于 2019-11-27 02:11:59
I'm adding some functionality on to an open-source scientific code. I work with a lot of allocatables, but I'm having some trouble printing them properly. For example, I declare and allocate, and then use: real(dp), allocatable :: psi_n_phi(:) ! some other stuff here allocate(psi_n_phi(1:fock_info%nocc(isp))) ! nocc(isp) is simply equal to 1 in this context ! some other stuff here do n = 1, fock_info%nocc(isp) psi_n_phi(n) = dot_product(fock_info%psi(:, n, isp), p) enddo I later get an array mismatch and I am using gdb to figure out why. If I print: (gdb) p psi_n_phi $23 = (0) But this clearly

Is there a standard way to check for Infinite and NaN in Fortran 90/95?

和自甴很熟 提交于 2019-11-26 23:26:39
问题 I've been trying to find a standards-compliant way to check for Infinite and NaN values in Fortran 90/95 but it proved harder than I thought. I tried to manually create Inf and NaN variables using the binary representation described in IEEE 754, but I found no such functionality. I am aware of the intrinsic ieee_arithmetic module in Fortran 2003 with the ieee_is_nan() and ieee_is_finite() intrinsic functions. However it's not supported by all the compilers (notably gfortran as of version 4.9)

What is the purpose of result variables in Fortran?

不羁的心 提交于 2019-11-26 14:37:21
问题 In Fortran, there are two standard ways to return a result from a function. The first one is by assigning the return value of the function to the function name. function foo() integer :: foo foo = 10 end function foo The second form, standardized in Fortran 90 is through a "result" variable. function foo result(res) integer :: res res = 10 end function foo Calling either form of the function returns the value 10. My question is, what was the rationale of the Fortran 90 committee for

Line truncated, Syntax error in argument list

徘徊边缘 提交于 2019-11-26 09:58:06
问题 When I compile the program below, I have an error and a warning in the call Coor_Trans command line as Warning: Line truncated Error: Syntax error in argument list I compile the program several times, but it does not work. Maybe there is something wrong with my call command. program 3D implicit none integer :: i,j,k integer, parameter :: FN=2,FML=5,FMH=5 integer, parameter :: NBE=FN*FML*FMH real, parameter :: pi = 4*atan(1.0) real(kind=4), dimension(1:FN,1:FML+1,1:FMH+1) :: BEXL,BEYL,BEZL