Understanding Fortran's Kinds to Type Parameters and Their Meanings

  • Context: Fortran 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 2K views
Messages
4,662
Reaction score
372
I read the following paragraph in the book: "Guide to Fortran 2008 programming":
It is possible to determine which kind parameters are available for each type on
your system by using the parameters real_kinds , integer_kinds , logical_kinds ,
and character_kinds in the intrinsic module iso_fortran_env .

And then they provide a programming code:
Fortran:
program kinds
use iso_fortran_env
implicit none
print *, real_kinds
end program kinds

I can of course change real to integer to logical to character etc.

But I don't understand what are the numbers that are shown in the screen? what do they designate?

For real_kinds I get:
4 8 10 16

For logical_kinds I get:
1 2 4 8 16

For character_kinds I get:
1 4

and for integer_kinds the same as logical.

What do these numbers designate?

The text doesn't clarify it to me.
 
on Phys.org
@jedishrfu I think I get it now.
For the real there are four kinds: single,long,double and quadruple.

In the book for real there are only 3 kinds for real, but it's a bit outdated the book. Here's the paragraph:
The kind parameter is an integer. These numbers are processor dependent, so that
kind parameters 1, 2, and 3 might be single, double, and quadruple precision; or on a
different system, kind parameters 4, 8, and 16 could be used for the same things. There
are at least two real and complex kinds and at least one kind for the integer, logical,
and character data types. There must be an integer kind capable of representing all 18-
digit integers. Note that the value of the kind parameter is not usually the number of
decimal digits of precision or range; on many systems, it is the number of bytes used to
represent the value.
 
It's been more than 10 years since I wrote any Fortran, (and I never used Fortran beyond F77) but I think the values being returned are the declarable byte values for the variables.

For example, LOGICAL*1 would declare a logical variable using 1 byte, REAL*16 would be a 16 byte REAL variable, and so on.

[edit] jedishrfu beat me to this. evidently I'm not the only old Fortran guy on here.
 
Mono Kakata said:
It's been more than 10 years since I wrote any Fortran, (and I never used Fortran beyond F77) but I think the values being returned are the declarable byte values for the variables.

For example, LOGICAL*1 would declare a logical variable using 1 byte, REAL*16 would be a 16 byte REAL variable, and so on.

[edit] jedishrfu beat me to this. evidently I'm not the only old Fortran guy on here.

I'm a robot, I don't age and I don't forget anything / Also Google is my personal friend. (Pay no attention to that man behind the curtain!)

My fortran was fortran-IV and a derivative called Fortran-Y after that it was C to shining C++ and now Java!