Fortran Understanding Fortran's Kinds to Type Parameters and Their Meanings

  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
AI Thread Summary
The discussion centers on understanding the output of the Fortran intrinsic module iso_fortran_env, specifically the kind parameters for different data types. Users inquire about the significance of the numbers displayed for real_kinds, logical_kinds, character_kinds, and integer_kinds. The numbers represent the kind parameters, which are processor-dependent and typically indicate the size in bytes used to represent each type. For instance, real_kinds outputs like 4, 8, 10, and 16 correspond to single, long, double, and quadruple precision, respectively. The conversation highlights that while the book referenced may be outdated, it correctly notes that these kind parameters do not directly correlate with the number of decimal digits of precision but rather with the memory allocation for the data types. Users also reflect on their experiences with older Fortran versions, emphasizing the evolution of programming languages.
MathematicalPhysicist
Science Advisor
Gold Member
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.
 
Technology news 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.
 
Yes, it mentions the number of bytes as the last sentence.
 
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
4
Views
2K
Replies
8
Views
2K
Replies
7
Views
3K
Replies
20
Views
6K
Replies
16
Views
2K
Replies
2
Views
2K
Back
Top