Fortran Help to a FORTRAN newbie with KIND, please

  • Thread starter Thread starter balthamossa2b
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion revolves around using the KIND attribute in FORTRAN, particularly for defining long integers. The original poster is facing issues with the compiler not allowing KIND values greater than 4 for integers, which is essential for their work. It is clarified that the KIND keyword is primarily applicable to REAL variables, with specific choices for precision. For integers, alternative declarations like INTEGER*1, INTEGER*2, INTEGER*4, and INTEGER*8 are available. The conversation highlights the importance of consulting compiler documentation for definitive guidance. A practical example is provided, showcasing a module that defines precision parameters for integers and reals, allowing for easier adjustments when porting code to different architectures. The use of modules for defining precision is emphasized as a best practice, enabling streamlined changes across multiple subroutines.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
3
Views
2K
Replies
4
Views
2K
Replies
14
Views
5K
Replies
3
Views
3K
Replies
59
Views
11K
Replies
2
Views
2K
Replies
5
Views
2K
Back
Top