Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help to a FORTRAN newbie with KIND, please!

  1. Dec 25, 2009 #1
    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.
  2. jcsd
  3. Dec 25, 2009 #2


    Staff: Mentor

    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.
  4. Dec 27, 2009 #3


    User Avatar
    Science Advisor

    In a large CFD code that I use, we have a module that looks like this:
    Code (Text):

    MODULE Precision_Def


      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 (Text):

    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.
  5. Dec 29, 2009 #4
    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.
  6. Dec 29, 2009 #5


    User Avatar
    Science Advisor

    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Help FORTRAN newbie Date
I need help in Fortran please -- Bairstow's method & Newton-Raphson Nov 26, 2016
Need help with FORTRAN Jun 8, 2016
Fortran compile error I can't figure out Jan 15, 2016
Help about Fortran Sep 13, 2015
Fortran newbie help Aug 31, 2006