billgray1234
Programmer
- Mar 14, 2011
- 39
i program in Fortran 90. i have a question about declaring parameterised real variables, as follows.
first, to enable portability between different computers, i'm declaring real variables using the KIND parameter, according to
integer, parameter :: PN_RL = selected_real_kind(p=15)
real(KIND=PN_RL) :: B,C,D etc
where PN_RL stands for 'PrecisioN of ReaL numbers', and B,C,D are real variables.
i have two questions. one involves 'no trailing zeros', and the other involves 'trailing zeros'. the questions are given below.
NO TRAILING ZEROS
i have a number which is 1) real, and 2) constant throughout my program (i.e. i want to declare it as a 'parameter'). for example, the number is B=3.0
from everything i've read on this topic, there doesn't appear to be just one 'correct' way to declare such a variable.
so, my question is:- are any (or all) of the following valid ways to declare this variable? if so, then which one(s)? if there is more than one 'valid' answer, then please say ALL valid answers.
real(KIND=PN_RL),parameter :: B = 3.
real(KIND=PN_RL),parameter :: B = 3.0
real(KIND=PN_RL),parameter :: B = 3._PN_RL
real(KIND=PN_RL),parameter :: B = 3.0_PN_RL
TRAILING ZEROS
similar to the above, but the number is instead B=3.456, and i would like to 'add' some trailing zeros (i will explain why below).
so, my question is:- are any (or all) of the following valid ways to declare this variable? if so, then which one(s)? again, if there is more than one 'valid' answer, then please say ALL valid answers.
real(KIND=PN_RL),parameter :: B = 3.456
real(KIND=PN_RL),parameter :: B = 3.4560
real(KIND=PN_RL),parameter :: B = 3.456_PN_RL
real(KIND=PN_RL),parameter :: B = 3.4560_PN_RL
the reason why i would like to 'add' some trailing zeros is solely for 'appearance', when i'm declaring several variables whose number of decimals is different. for example,
real(KIND=PN_RL),parameter :: B = 3.4560
real(KIND=PN_RL),parameter :: B = 1.2345
real(KIND=PN_RL),parameter :: B = 7.1200
looks neater (to me) than
real(KIND=PN_RL),parameter :: B = 3.456
real(KIND=PN_RL),parameter :: B = 1.2345
real(KIND=PN_RL),parameter :: B = 7.12
also, if (as asked above) the term _PN_RL must be used at the end of each number (in the above), then
real(KIND=PN_RL),parameter :: B = 3.4560_PN_RL
real(KIND=PN_RL),parameter :: B = 1.2345_PN_RL
real(KIND=PN_RL),parameter :: B = 7.1200_PN_RL
looks neater (to me) than
real(KIND=PN_RL),parameter :: B = 3.456_PN_RL
real(KIND=PN_RL),parameter :: B = 1.2345_PN_RL
real(KIND=PN_RL),parameter :: B = 7.12_PN_RL
any help would be appreciated
first, to enable portability between different computers, i'm declaring real variables using the KIND parameter, according to
integer, parameter :: PN_RL = selected_real_kind(p=15)
real(KIND=PN_RL) :: B,C,D etc
where PN_RL stands for 'PrecisioN of ReaL numbers', and B,C,D are real variables.
i have two questions. one involves 'no trailing zeros', and the other involves 'trailing zeros'. the questions are given below.
NO TRAILING ZEROS
i have a number which is 1) real, and 2) constant throughout my program (i.e. i want to declare it as a 'parameter'). for example, the number is B=3.0
from everything i've read on this topic, there doesn't appear to be just one 'correct' way to declare such a variable.
so, my question is:- are any (or all) of the following valid ways to declare this variable? if so, then which one(s)? if there is more than one 'valid' answer, then please say ALL valid answers.
real(KIND=PN_RL),parameter :: B = 3.
real(KIND=PN_RL),parameter :: B = 3.0
real(KIND=PN_RL),parameter :: B = 3._PN_RL
real(KIND=PN_RL),parameter :: B = 3.0_PN_RL
TRAILING ZEROS
similar to the above, but the number is instead B=3.456, and i would like to 'add' some trailing zeros (i will explain why below).
so, my question is:- are any (or all) of the following valid ways to declare this variable? if so, then which one(s)? again, if there is more than one 'valid' answer, then please say ALL valid answers.
real(KIND=PN_RL),parameter :: B = 3.456
real(KIND=PN_RL),parameter :: B = 3.4560
real(KIND=PN_RL),parameter :: B = 3.456_PN_RL
real(KIND=PN_RL),parameter :: B = 3.4560_PN_RL
the reason why i would like to 'add' some trailing zeros is solely for 'appearance', when i'm declaring several variables whose number of decimals is different. for example,
real(KIND=PN_RL),parameter :: B = 3.4560
real(KIND=PN_RL),parameter :: B = 1.2345
real(KIND=PN_RL),parameter :: B = 7.1200
looks neater (to me) than
real(KIND=PN_RL),parameter :: B = 3.456
real(KIND=PN_RL),parameter :: B = 1.2345
real(KIND=PN_RL),parameter :: B = 7.12
also, if (as asked above) the term _PN_RL must be used at the end of each number (in the above), then
real(KIND=PN_RL),parameter :: B = 3.4560_PN_RL
real(KIND=PN_RL),parameter :: B = 1.2345_PN_RL
real(KIND=PN_RL),parameter :: B = 7.1200_PN_RL
looks neater (to me) than
real(KIND=PN_RL),parameter :: B = 3.456_PN_RL
real(KIND=PN_RL),parameter :: B = 1.2345_PN_RL
real(KIND=PN_RL),parameter :: B = 7.12_PN_RL
any help would be appreciated