| New Reply |
having problem to understand kind notation in fortran 90 |
Share Thread | Thread Tools |
| Apr26-12, 12:34 AM | #1 |
|
|
having problem to understand kind notation in fortran 90
hi all,
i have codes for 1d fdtd maxwell equation. the problem i am facing right now is some error regarding the kind notation. Code:
!1d fdtd Simulation in free space
subroutine fd1d01(f0,miu,delta,S,E0)
implicit none
real :: f0
real :: miu
real :: delta
real :: S
real :: E0
integer :: iinit
integer :: ilast
real :: Ca
real :: Da
integer (kind = 2) :: i
integer (kind = 5) :: n
real :: tdelta
real :: c
real,dimension(:,:),allocatable :: Ez
real,dimension(:,:),allocatable :: Hy
real, parameter :: pi = 3.14159265
real :: Cb
real :: Db
real :: lambda
real :: alpha
character(len=20) ::filename
allocate (Ez(-1:103,-1:503))
allocate (Hy(-1:103,-1:503))
f0 = 1.0
miu = 1.0
delta = 1.0
S = 1.0
E0 = 1.0
iinit = 0
ilast = 100
c = 3.e8
lambda = c/f0
print *,'lambda=',lambda
alpha = 0.04*lambda
print *,'alpha=',alpha
tdelta = 1.0*alpha/(S*c)
print*, 'tdelta=',tdelta
!initialization
do i = iinit,ilast
Ez(iinit+1/2,0) = 0
Hy(iinit+1,0) = 0
end do
Ca = 1.0
Cb = tdelta/(delta*alpha)
Da = 1.0
Db = tdelta/(miu*alpha)
!write (filename, "('ez',I3.3,'.dat')") n
!open (unit=130,file=filename)
do n = 1,500
write (filename, "('ez',I3.3,'.dat')") n
open (unit=130,file=filename)
do i = iinit+1,ilast
Ez(real(i-0.5,n+0.5)) = Ca*(Ez(real(i-0.5,n-0.5))) + Cb*(Hy(i,n)-Hy(i-1,n))
Hy(i,n+1) = Da*(Hy(i,n)) + Db*(Ez(real(i+0.5,n+0.5))-Ez(real(i-0.5,n+0.5)))
Write (130,*) i-0.5, Ez(real (i-0.5,n+0.5))
end do !i
!plane wave source
Ez(1./2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
close (unit=130)
end do !n
end SUBROUTINE fd1d01
Code:
subroutines.f90:15.17:
integer (kind = 5) :: n
1
Error: Kind 5 not supported for type INTEGER at (1)
subroutines.f90:62.4:
do n = 1,500
1
Error: Symbol 'n' at (1) has no IMPLICIT type
subroutines.f90:76.5:
Ez(1./2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
1
Warning: Extension: REAL array index at (1)
make: *** [subroutines.o] Error 1
thank you |
| Apr26-12, 10:18 AM | #2 |
|
Mentor
|
It seems to me that on the computer you are compiling this code, kind = 5 is not supported for integer types. You are asking the compiler to allocate half the normal size for an integer, but the compiler can't do this.
I would either take the kind part out of this line of code Code:
integer (kind = 5) :: n Here's a link to some info as pertains to the GNU fortran compiler - http://gcc.gnu.org/onlinedocs/gcc-3....-Notation.html |
| Apr26-12, 09:26 PM | #3 |
|
|
hi mark44,
i did change KIND= 2, but some error came out as below: Code:
subroutines.f90:68.17:
Ez(real(i-0.5,n+0.5)) = Ca*(Ez(real(i-0.5,n-0.5))) + Cb*(Hy(i,n)-Hy(i-1,n))
1
Error: 'kind' argument of 'real' intrinsic at (1) must be INTEGER
subroutines.f90:68.45:
Ez(real(i-0.5,n+0.5)) = Ca*(Ez(real(i-0.5,n-0.5))) + Cb*(Hy(i,n)-Hy(i-1,n))
1
Error: 'kind' argument of 'real' intrinsic at (1) must be INTEGER
subroutines.f90:69.70:
Hy(i,n+1) = Da*(Hy(i,n)) + Db*(Ez(real(i+0.5,n+0.5))-Ez(real(i-0.5,n+0.5)))
1
Error: 'kind' argument of 'real' intrinsic at (1) must be INTEGER
subroutines.f90:71.38:
Write (130,*) i-0.5, Ez(real (i-0.5,n+0.5))
1
Error: 'kind' argument of 'real' intrinsic at (1) must be INTEGER
subroutines.f90:76.5:
Ez(1./2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
1
Warning: Extension: REAL array index at (1)
thank you |
| Apr27-12, 12:14 AM | #4 |
|
Mentor
|
having problem to understand kind notation in fortran 90
Most or all of your errors seem to be that your array indexes for the Ez array are real, not integer.
I'm not sure what you're trying to do in this line: Code:
Ez(real(i-0.5,n+0.5))= Ca*(Ez(real(i-0.5,n-0.5))) + Cb*(Hy(i,n)-Hy(i-1,n)) Your Ez array is two-dimensional - each index needs to be an integer value, not a floating point value. Why do you have indexes that are obviously fractional? Notice that all five errors point out problems in how you are indexing your Ez array. |
| Apr27-12, 07:51 AM | #5 |
Recognitions:
|
IMO, "kind" is a good idea with a very dumb implementation. The good idea is that you can describe what range of values (for integers) or precision (for reals) your program needs, and the compiler can then select the best way to implement this depending on the hardware (32 or 64 bit systems, etc).
The very dumb implementation is that there is NO standardization of what the different integers that denote "kinds" represent, and sometimes no obvious logic either. For example GNU fortran uses KIND=2 to mean "integers of twice the normal length" (that seem logical enough), but KIND=5 means "half the normal length", and "KIND = 7" means "integers large enough to hold a pointer". Yeah, right, it's obvious to everybody that's what 5 and 7 mean ![]() Even worse, GNU says it might change the definitions the definitions in future, so even old "GNU-compatible" code will break. http://gcc.gnu.org/onlinedocs/gcc-3....-Notation.html And other compilers might use KIND=2 to mean "2-byte integers", which are "half the normal length" compared with GNU's interpretation of "twice the normal length". |
| May9-12, 08:47 PM | #6 |
|
|
i have make some change. it's compiled but with some warning
Code:
!1d fdtd Simulation in free space
subroutine fd1d01(f0,miu,delta,S,E0)
implicit none
real :: f0
real :: miu
real :: delta
real :: S
real :: E0
integer :: iinit
integer :: ilast
integer :: i
integer :: n
double precision :: Ca
double precision :: Da
double precision :: tdelta
double precision :: c
double precision,allocatable :: Ez(:,:)
double precision,allocatable :: Hy(:,:)
real, parameter :: pi = 3.14159265
double precision :: Cb
double precision :: Db
double precision :: lambda
double precision :: alpha
character(len=20) :: filename
allocate (Ez(-0.5:103,-0.5:503))
allocate (Hy(-0.5:103,-0.5:503))
f0 = 1.0
miu = 1.0
delta = 1.0
S = 1.0
E0 = 1.0
iinit = 0
ilast = 100
c = 3.e8
lambda = c/f0
alpha = 0.04*lambda
tdelta = 1.0*alpha/(S*c)
!initialization
Ez = 0
Hy = 0
Ca = 1.0
Cb = tdelta/(delta*alpha)
Da = 1.0
Db = tdelta/(miu*alpha)
do n = 1,500
write (filename, "('ez',I3.3,'.dat')") n
open (unit=130,file=filename)
do i = iinit+1,ilast
Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n))
Hy(i,n+1.) = Da*(Hy(i,n)) + Db*(Ez(i+1./2,n+1./2)-Ez(i-1./2,n+1./2))
! Print*, 'i+1./2=',i+1./2,'i-1./2=',i-1./2
Write (130,*) i-1./2, Ez(i-1./2,n+1./2)
end do !i
!plane wave source
Ez(1./2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
close (unit=130)
end do !n
end SUBROUTINE fd1d01
Code:
gfortran -g -I/usr/include -c main.f90
gfortran -g -I/usr/include -c subroutines.f90
subroutines.f90:27.13:
allocate (Ez(-0.5:103,-0.5:503))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:27.22:
allocate (Ez(-0.5:103,-0.5:503))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:28.13:
allocate (Hy(-0.5:103,-0.5:503))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:28.22:
allocate (Hy(-0.5:103,-0.5:503))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:65.6:
Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:65.13:
Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:65.63:
Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:65.30:
Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:65.37:
Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:66.8:
Hy(i,n+1.) = Da*(Hy(i,n)) + Db*(Ez(i+1./2,n+1./2)-Ez(i-1./2,n+1./2))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:66.56:
Hy(i,n+1.) = Da*(Hy(i,n)) + Db*(Ez(i+1./2,n+1./2)-Ez(i-1./2,n+1./2))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:66.63:
Hy(i,n+1.) = Da*(Hy(i,n)) + Db*(Ez(i+1./2,n+1./2)-Ez(i-1./2,n+1./2))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:66.38:
Hy(i,n+1.) = Da*(Hy(i,n)) + Db*(Ez(i+1./2,n+1./2)-Ez(i-1./2,n+1./2))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:66.45:
Hy(i,n+1.) = Da*(Hy(i,n)) + Db*(Ez(i+1./2,n+1./2)-Ez(i-1./2,n+1./2))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:70.27:
Write (130,*) i-1./2, Ez(i-1./2,n+1./2)
1
Warning: Extension: REAL array index at (1)
subroutines.f90:70.34:
Write (130,*) i-1./2, Ez(i-1./2,n+1./2)
1
Warning: Extension: REAL array index at (1)
subroutines.f90:75.5:
Ez(1./2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
1
Warning: Extension: REAL array index at (1)
gfortran -g -I/usr/include -o main main.o subroutines.o -L/usr/lib64/liblapack -L/usr/lib64/libblas
Main finished.
thank you |
| May10-12, 12:40 AM | #7 |
|
Mentor
|
This is what I said a couple of posts back (emphasis added). Did you read it?
|
| May10-12, 02:12 AM | #8 |
|
|
mark 44,
i read your reply, and i make change...but somehow it came out with lib64 error and so on. maybe i misunderstood, ( my english is freaking bad, and fortran for me is just a few months experience)....i've change this part allocate (Ez(-0.5:103,-0.5:503)) allocate (Hy(-0.5:103,-0.5:503)) into allocate (Ez(-2:100,0:501)) allocate (Hy(-2:100,0:501)) or allocate (Ez(0:100,0:500)) allocate (Hy(0:100,0:500)) and then this error came out: *** glibc detected *** ./main: free(): invalid pointer: 0x00007fdb92dbf010 *** and so on. or is it the warning came out because of this algorithm Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n)) i just translate the finite difference expression for maxwell equations from taflove's book into fortran language. please highlight me...which part i should change. and very big thank you for your time |
| May10-12, 10:06 AM | #9 |
|
Mentor
|
I might be wrong, but I think the above statements should be something like this: Code:
allocate(Ez(101, 501), STAT = status) Do a web search for "fortran allocate" for more information. Ez(i-1./2,n+1./2) = Ca*(Ez(i-1./2,n-1./2)) + Cb*(Hy(i,n)-Hy(i-1.,n)) The indexes in an array have to be integer numbers. You can't access the element whose index is 3.5, for example. You have to change your code so that you store values at integer indexes in the arrays. |
| New Reply |
| Thread Tools | |
Similar Threads for: having problem to understand kind notation in fortran 90
|
||||
| Thread | Forum | Replies | ||
| Fortran help: high precision intrinsic functions (kind = 16)...... | Engineering, Comp Sci, & Technology Homework | 1 | ||
| what kind of math notation is this? | General Math | 3 | ||
| A kind of Tensor notation? | Special & General Relativity | 4 | ||
| Help to a FORTRAN newbie with KIND, please! | Programming & Comp Sci | 4 | ||
| What kind of math is needed to understand relativity | Special & General Relativity | 3 | ||