Understanding Fortran's Kinds to Type Parameters and Their Meanings

  • Context: Fortran 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the kind parameters in Fortran, specifically their meanings and implications for different data types such as real, integer, logical, and character. Participants explore the relationship between these parameters and the byte sizes they represent, as well as the potential variations across different systems.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant inquires about the meaning of the numbers returned by the kind parameters for different data types, noting the output for real_kinds, logical_kinds, character_kinds, and integer_kinds.
  • Another participant suggests that the numbers could represent the size in bytes of the kinds supported by Fortran, but not necessarily what the hardware supports.
  • A later reply clarifies that the kinds for real numbers include single, long, double, and quadruple precision, and notes that the kind parameters are processor dependent.
  • Some participants mention that the value of the kind parameter typically corresponds to the number of bytes used to represent the value, with examples provided for logical and real types.
  • One participant reflects on their past experience with Fortran and reiterates that the values returned are likely the declarable byte values for the variables.

Areas of Agreement / Disagreement

Participants generally agree that the numbers represent byte sizes for the variables, but there is some uncertainty regarding the specific definitions and variations across different systems. No consensus is reached on the exact implications of these parameters.

Contextual Notes

There is mention of the processor dependency of kind parameters, which may affect their interpretation and usage across different systems. Additionally, the discussion touches on the potential for outdated information in reference materials.

Who May Find This Useful

This discussion may be useful for individuals interested in Fortran programming, particularly those looking to understand data type specifications and their implications in different computing environments.

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!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K