Help to a FORTRAN newbie with KIND, please

  • Context: Fortran 
  • Thread starter Thread starter balthamossa2b
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
SUMMARY

The discussion focuses on the use of the KIND keyword in FORTRAN, specifically with Microsoft Powerstation. The user encountered limitations when attempting to define long integers using KIND greater than 4, which is not supported for integer types. The conversation highlights the use of INTEGER*8 for long integers and the importance of using SELECTED_INT_KIND for defining integer precision in a module. The example provided illustrates how to create a module for precision definitions, allowing for easier adjustments when porting code to different architectures.

PREREQUISITES
  • Understanding of FORTRAN syntax and data types
  • Familiarity with Microsoft Powerstation compiler
  • Knowledge of INTEGER and REAL data types in FORTRAN
  • Experience with modules and parameter definitions in FORTRAN
NEXT STEPS
  • Research the use of SELECTED_INT_KIND and SELECTED_REAL_KIND in FORTRAN
  • Explore the differences between INTEGER* and INTEGER(KIND=) declarations
  • Learn about compiler-specific behaviors in FORTRAN, particularly with Microsoft Powerstation
  • Investigate best practices for defining precision in large FORTRAN projects
USEFUL FOR

FORTRAN developers, particularly those working with numerical simulations or computational fluid dynamics, will benefit from this discussion. It is also useful for anyone transitioning code between different architectures or compilers.

balthamossa2b
Messages
1
Reaction score
0
Hi, I'm starting with FORTRAN (I have Microsoft Powerstation) and I was experimenting with KIND. Specifically, what I wanted was:

integer (kind=8):: list of variables



But the compiler doesn't let me use KIND with integers if kind>4, and I really need to use long integers. Can someone point out what I'm doing wrong, please?

Thanks in advance.
 
Technology news on Phys.org
I don't know this for a fact, but I believe the KIND keyword applies only to REAL variables, and the choices are 1, 2, and 3. These represent 4-byte, 8-byte, and 10-byte reals.

For integers, I believe you can specify the size of storage as INTEGER*1, INTEGER*2, INTEGER*4, and INTEGER*8. You'll need to look at your compiler documentation to get a definitive answer.
 
In a large CFD code that I use, we have a module that looks like this:
Code:
MODULE Precision_Def
  IMPLICIT NONE

  PRIVATE

  PUBLIC :: i_def,      r_def,      & ! precision for calculation
            i_def_sp,   r_def_sp,   & ! single precision (4 byte)
            i_def_dp,   r_def_dp,   & ! double precision (8 byte)
            intDef,     realDef

  INTEGER, PARAMETER :: i_def    = SELECTED_INT_KIND(8),   &
                        r_def    = SELECTED_REAL_KIND(12), &
                        i_def_sp = SELECTED_INT_KIND(9),   &
                        r_def_sp = SELECTED_REAL_KIND(6),  &
                        i_def_dp = SELECTED_INT_KIND(16),  &
                        r_def_dp = SELECTED_REAL_KIND(12), &
                        intDef   = i_def,                  &
                        realDef  = r_def


END MODULE Precision_Def
Then, when we creat variables in subroutines, etc, they look like this:
Code:
INTEGER(KIND=i_def) :: ...
REAL(KIND=r_def) :: ...
Again as mentioned, it amy be compiler specific, although we've compiled and ran using both g95 and ifort.
 
KIND values are compiler specific (which seems pretty silly but that is what the standard says). minger's answer seems like the way to go -- although I quite like the real*8 and integer*8 type declarations.
 
The nice thing about a module defining it, is e.g. if you decide you want to port over to a 64-bit machine and want to run a higher precision, you can just change the one module, rather than every single subroutine where variables are declared.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 59 ·
2
Replies
59
Views
11K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K