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!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

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