Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

strange problem of DATA statement

Hanbing_P_
Beginner
680 Views

      When I assign initial values to variables using the DATA statement, such as ,

integer(kind=4):: nss
DATA nss /86400/

then I print out the value of nss, the result is 86527. I don't konw why this happens.

In the same way

integer(kind=4) ::month(12)
DATA month/31,28,31,30,31,30,31,31,30,31,30,31/

then I print out the value of month(1), the result is 255. So odd , isn't it ? Can someone help me to give an explanation for this ? Thank you very much.

The compile which I am using is IVF14.0 integrated with VS2012.

 

0 Kudos
2 Replies
andrew_4619
Honored Contributor III
680 Views

Some thing to try: The data constants 86400, 31, 28,.... are of default kind which would normally be 4 but this can be changed by compiler options or directives. Try 86400_4 31_4,28_4. BTW I am not keen on data statements I think the more modern forms below are better as it puts the declaration and initialisation in one place.

! for data constants that do not ever need to change
integer(kind=4), parameter :: month(12)=(/31,28,31,30,31,30,31,31,30,31,30,31/)

! or for just initialisation
integer(kind=4) :: month(12)=(/31,28,31,30,31,30,31,31,30,31,30,31/)

 

0 Kudos
mecej4
Honored Contributor III
680 Views

Here is a short program that contains the lines of code that Hanbing P. gave in #1. 

program hbpx
implicit none
integer(kind=4):: nss
DATA nss /86400/
integer(kind=4) ::month(12)
DATA month/31,28,31,30,31,30,31,31,30,31,30,31/
!
write(*,*)nss,month(1)
end program

The results are as expected, with IFort 14.0.4.237. I would not expect any version of a widely used compiler to have bugs of the type described. I suspect that either the description is incorrect or that there are other unreported circumstances present that may be responsible for incorrect output.

0 Kudos
Reply