Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

what is the kind definition for integer*4

rasa
Beginner
1,694 Views

A quick question. In the following code, using integer*4 for COM works. I tried to change it to a integer kind definition, but could not get it to work. Can someone explain what's going on.

module Kinds
! -- Integer types
integer, parameter, public :: bi_k = SELECTED_INT_KIND(1) ! Byte integer
integer, parameter, public :: si_k = SELECTED_INT_KIND(4) ! Short integer
integer, parameter, public :: li_k = SELECTED_INT_KIND(8) ! Long integer
integer, parameter, private :: ll_t = SELECTED_INT_KIND(16) ! LLong integer
integer, parameter, public :: lli_k = ( ( ( 1 + SIGN( 1, ll_t ) ) / 2 ) * ll_t ) + &
( ( ( 1 - SIGN( 1, ll_t ) ) / 2 ) * li_k )

end module Kinds


program prog
use Kinds, only: si_k
use IFCOM
!--
implicit none
integer*4 :: status ! This works
! The following definition of status does not work.
!integer (kind = si_k) :: status ! This does not work

continue

call COMINITIALIZE (status)
! -- do stuff ...
call COMUNINITIALIZE()

end program prog

0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,694 Views
You misunderstand SELECTED_INT_KIND. The argument is not size in bytes but rather the number of decimal digits you require to be representable. So for a byte kind you'd want (2), for two bytes, (4), for four bytes (9) and for 8 bytes, (15) would work.

In our implementation, the kind numbers match the bytesize numbers except for COMPLEX, where the kind of the REAL part is used. There exist other implementations which make different choices for KIND numbers. Use SELECTED_INT_KIND and SELECTED_REAL_KIND rather than hard-coding kind numbers.
0 Kudos
rasa
Beginner
1,694 Views
You misunderstand SELECTED_INT_KIND. The argument is not size in bytes but rather the number of decimal digits you require to be representable. So for a byte kind you'd want (2), for two bytes, (4), for four bytes (9) and for 8 bytes, (15) would work.

In our implementation, the kind numbers match the bytesize numbers except for COMPLEX, where the kind of the REAL part is used. There exist other implementations which make different choices for KIND numbers. Use SELECTED_INT_KIND and SELECTED_REAL_KIND rather than hard-coding kind numbers.

Steve. Thanks for the clarification. I agree that I have misunderstood some things. I got some ideas froma website.
http://ram3.chem.sunysb.edu/nucwww/helplib/FORTRAN/DATA/CONSTANTS/INTEGER.html


Are the following kinds correctly defined now?

integer, parameter, public :: bi_k = SELECTED_INT_KIND(4) ! Byte integer
integer, parameter, public :: si_k = SELECTED_INT_KIND(9) ! Short integer
integer, parameter, public :: li_k = SELECTED_INT_KIND(15) ! Long integer
0 Kudos
Steven_L_Intel1
Employee
1,694 Views
I don't know if this is what you intend. It might be. For "short integer" you have the equivalent of INTEGER*4. For "long integer" you have INTEGER*8. You have no value corresponding to INTEGER*2.
0 Kudos
Reply