I'm a little stuck with some errors related to Fortran array constructors. Maybe you can help me understand the errors? I have two questions in particular (see below).
My minimal working example is:
program debug
use ieee_arithmetic
implicit none
integer :: ii
real, parameter :: KZERO = 1
real, parameter :: LAMBDA = 1.3
integer, parameter :: pad = 5
integer, parameter :: nsh = 60 + 2*pad
integer, parameter :: top=nsh-pad, bot=pad+1
real(kind=8), parameter :: dt2 = 1.0D-5/2
real(kind=8), parameter :: VK_SS = 6.0D-10
real(kind=8), parameter :: VM_SS = 6.0D-05
real(kind=8), parameter,dimension(nsh) :: k = [(KZERO*LAMBDA**(ii-pad), ii=1, nsh)]
real(kind=8), parameter,dimension(nsh) :: NUK_K = [(-dt2*VK_SS*k(ii)**2, ii=1, nsh)]
real(kind=8), parameter,dimension(nsh) :: NUK_M = [(-dt2*VM_SS*k(ii)**2, ii=1, nsh)]
real(kind=8), parameter, dimension(nsh) :: A = [(.0,ii=1,pad), ( REAL(exp(NUK_K(ii))), ii=bot, top), (.0,ii=1,pad)]
real(kind=8), parameter, dimension(nsh) :: B = [(.0,ii=1,pad), ( REAL( NUK_M(ii) ), ii=bot, top), (.0,ii=1,pad)]
!real(kind=8), parameter, dimension(nsh) :: C = [(.0,ii=1,pad), ( REAL(exp(NUK_M(ii))), ii=bot, top), (.0,ii=1,pad)]
print *,A
print *,'-------------------------'
print *,B
print *,'-------------------------'
!print *,C
end program debug
First question: How come I need to typecast with REAL() in the constructor where A,B and C are defined? If I do not, I get this error:
/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64/ifort -o debug debug.f90
debug.f90(23): error #7113: Each ac-value expression in an array-constructor must have the same type and type parameters. [EXP]
real(kind=8), parameter, dimension(nsh) :: A = [(.0,ii=1,pad), ( exp(NUK_K(ii)), ii=bot, top), (.0,ii=1,pad)]
--------------------------------------------------------------------^
...but the do-loop elements are already of REAL kind=8 since NUK_K is?
Second question: when I uncomment the line defining C (also by an array constructor), I get the following error:
/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64/ifort -o debug debug.f90
debug.f90(25): warning #7919: The value was too small when converting to REAL(KIND=4); the result is zero.
real(kind=8), parameter, dimension(nsh) :: C = [(.0,ii=1,pad), ( REAL(exp(NUK_M(ii))), ii=bot, top), (.0,ii=1,pad)]
--------------------------------------------------------------------^
debug.f90(25): error #7768: This operation on this data type is currently inaccurate.
real(kind=8), parameter, dimension(nsh) :: C = [(.0,ii=1,pad), ( REAL(exp(NUK_M(ii))), ii=bot, top), (.0,ii=1,pad)]
--------------------------------------------------------------------^
..the warning is OK since I guess it means that the compiler is suggesting exp(-[large number]) -> 0, right? But how do I deal with the error "This operation on this data type is currently inaccurate." ?
I hope you can help me since I've being going at this problem for a long time now!
EDIT
First of all, thank you very much for the helpful answers! I appreciate it a lot. However, the inaccuracy problem remains. Any ideas? My initial guess was to use quads instead of doubles and thereafter cast the result as doubles (quads are not natively supported by my CPU). This does not work either. My new minimal working example is (note I removed the zero-padding to make the example simpler):
program debug
use ieee_arithmetic
use ISO_Fortran_env
implicit none
integer, parameter :: rd = real64
integer, parameter :: rq = real128
integer, parameter :: df = rq ! Default float kind
real(df), parameter :: KZERO = 1
real(df), parameter :: LAMBDA = 1.3
integer, parameter :: pad = 5
integer, parameter :: nsh = 60 + 2*pad
integer, parameter :: top=nsh-pad, bot=pad+1
real(df), parameter :: dt2 = 1.0D-5/2
real(df), parameter :: VK_SS = 6.0D-10
real(df), parameter :: VM_SS = 6.0D-05
integer :: ii
real(df), parameter,dimension(nsh) :: k = [(KZERO*LAMBDA**(ii-pad), ii=1, nsh)]
real(df), parameter,dimension(nsh) :: NUK_K = [(-dt2*VK_SS*k(ii)**2, ii=1, nsh)]
real(df), parameter,dimension(nsh) :: NUK_M = [(-dt2*VM_SS*k(ii)**2, ii=1, nsh)]
real(df), parameter, dimension(nsh) :: A = [ ( exp(NUK_K(ii)) , ii=1, nsh) ]
real(df), parameter, dimension(nsh) :: B = [ ( NUK_M(ii) , ii=1, nsh) ]
real(df), parameter, dimension(nsh) :: C = [ ( exp(NUK_M(ii)) , ii=1, nsh) ]
print *,A
print *,'-------------------------'
print *,B
print *,'-------------------------'
print *,C
end program debug
But this still gives the error
/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64/ifort -o debug debug.f90
debug.f90(30): error #7768: This operation on this data type is currently inaccurate.
real(df), parameter, dimension(nsh) :: C = [ ( exp(NUK_M(ii)) , ii=1, nsh) ]
--------------------------------------------------^