Home > Archive > Fortran > July 2006 > Compiler invalid KIND specifier
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Compiler invalid KIND specifier
|
|
| Eli Luong 2006-07-06, 7:00 pm |
| I'm trying to compile an f90 file on the FTN95 Plato IDE, but the
compiler is giving me a Invalid KIND specifier. I'm sure this code
compiles, because it compiles/builds fine on the Compaq Visual Fortran6
(or something similar), but I don't have immediate access to the
machine that has it right now and so I'm trying to use an alternate
compiler, but it does not seem to be working.
The error line usually has something like this: REAL(8) cx, cy, cz
Is there an easy way to fix this so I can compile here?
Thanks.
| |
| Paul Van Delst 2006-07-06, 7:00 pm |
| Eli Luong wrote:
> I'm trying to compile an f90 file on the FTN95 Plato IDE, but the
> compiler is giving me a Invalid KIND specifier. I'm sure this code
> compiles, because it compiles/builds fine on the Compaq Visual Fortran6
> (or something similar), but I don't have immediate access to the
> machine that has it right now and so I'm trying to use an alternate
> compiler, but it does not seem to be working.
>
> The error line usually has something like this: REAL(8) cx, cy, cz
>
> Is there an easy way to fix this so I can compile here?
Quickly, you could try something like
integer, parameter :: dp=KIND(1.0d) ! I think this is the correct syntax
real(dp) :: cx, cy, cz
It may be that the kind value "8" is meaningless in FTN95 (I don't know having never used
that particular compiler). Hardwired kind values like that (where, basically, 4==real*4,
8==real*8) are not portable since not every vendor adopted the 4, 8 values to signify
single and double precision (some chose 1, 2). Maybe CVF did the former and FTN95 did the
latter...?
But, apart from that, a better solution (in my opinion) is to always use a type_kinds
module, e.g.:
module type_kinds
implicit none
private
public :: sp, dp
integer, parameter :: sp=selected_real_kind(6)
integer, parameter :: dp=selected_real_kind(15)
end module type_kinds
and then use it where needed,
program blah
use type_kinds
implicit none
real(dp) :: cx, cy, cz
.... etc
end program blah
cheers,
paulv
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
| |
| Richard Maine 2006-07-06, 7:00 pm |
| Eli Luong <eliluong@gmail.com> wrote:
> I'm sure this code
> compiles, because it compiles/builds fine on the Compaq Visual Fortran6
> (or something similar),
That does not imply that the code is valid or portable... and indeed it
isn't.
> The error line usually has something like this: REAL(8) cx, cy, cz
Yep. Somone has used hard-wired KIND values (the 8). Those are not
portable and are regularly recommended against here... but lots of
people ignore the recommendation, including whoever wrote that code. I
don;t know what the corresponding value is for the compiler you are
using, though I might guess 2 instead of 8.
Kind values are compiler specific. The values that work on one compiler
will not necessarily work on another.
It is possible to do this portably, but it is a bit more verbose. I've
advocated a less verbose form of the common cases (such as this one) for
the next version of the standard, but for now, you need something like:
1. First step. Do this one in any case. replace all the real(8) forms by
something like real(r_kind), where the r_kind can be any name of your
own choosing. I personally use the name r_kind, but the name choice is
yours. Some people use something short like dp.
2. Second step. Define a parameter with the name you specified. You can
do this any of three ways.
a. Use the selected_real_kind intrinsic. This allows you to portably
specify precision in a machine-independent way. Something like
integer, parameter :: r_kind = selected_real_kind(12)
which asks for art least 12 decimal digits of precision.
b. If you know you want double precision, you can use the somewhat
shorter kind() intrinsic as in
integer, parameter :: r_kind=kind(0.0d0)
c. If you really want to hard-wire teh numeric value for some reason,
you can do it like
integer. parameter :: r_kind = 8
The last option is not portable in that the value 8 won't be right for
all compilers, but at least you will only have to change it in one
place. I recommend one of the first two options in most cases, reserving
the hard-wired number for special cases that are quite rare.
3. Third step. Put the definition from step 2 into an include file or
module and include or use it everywhere that it is needed. That is far
better than having the same thing repearted muliple times, which would
cause maintenance problems if you ever neede to change it.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
| |
| Eli Luong 2006-07-06, 7:00 pm |
|
>
> 3. Third step. Put the definition from step 2 into an include file or
> module and include or use it everywhere that it is needed. That is far
> better than having the same thing repearted muliple times, which would
> cause maintenance problems if you ever neede to change it.
>
> --
Wow, thanks for the thorough explanation. I would change it, but I'm
not sure if it's time efficient to do so, given my level of experience
with fortran. This code is used for a simulation for research, which
takes input from a C++ program I had been modifying. The fortran
program runs calculations for input to a third C++ program, and I
wanted to figure out why the fortran code was returning errors when I
ran the original compiled executable.
| |
| Herman D. Knoble 2006-07-07, 7:59 am |
| Eli: I believe that the following declaration is Standard and will work
consistently across compilers:
real(kind(1.D0)), dimension(10) :: x
Skip Knoble
On 6 Jul 2006 11:33:13 -0700, "Eli Luong" <eliluong@gmail.com> wrote:
-|I'm trying to compile an f90 file on the FTN95 Plato IDE, but the
-|compiler is giving me a Invalid KIND specifier. I'm sure this code
-|compiles, because it compiles/builds fine on the Compaq Visual Fortran6
-|(or something similar), but I don't have immediate access to the
-|machine that has it right now and so I'm trying to use an alternate
-|compiler, but it does not seem to be working.
-|
-|The error line usually has something like this: REAL(8) cx, cy, cz
-|
-|Is there an easy way to fix this so I can compile here?
-|
-|Thanks.
| |
| David Flower 2006-07-07, 7:59 am |
|
Eli Luong wrote:
> I'm trying to compile an f90 file on the FTN95 Plato IDE, but the
> compiler is giving me a Invalid KIND specifier. I'm sure this code
> compiles, because it compiles/builds fine on the Compaq Visual Fortran6
> (or something similar), but I don't have immediate access to the
> machine that has it right now and so I'm trying to use an alternate
> compiler, but it does not seem to be working.
>
> The error line usually has something like this: REAL(8) cx, cy, cz
>
> Is there an easy way to fix this so I can compile here?
>
> Thanks.
I think that you will find that the equivalent KIND value under FTN95
for an 8-byte floating-point quantity is 3.
In fact, all the KIND types are idiosyncratic, for more information,
refer to 'Kind Parameters for intrinsic types' in 'Help for FTN95' ,
probably under:
Programs
Salford Software
Salford Software FTN95
Dave Flower
| |
| Ian Bush 2006-07-07, 7:59 am |
| Herman D. Knoble wrote:
> Eli: I believe that the following declaration is Standard
Yup, I agree
> and will work
> consistently across compilers:
>
> real(kind(1.D0)), dimension(10) :: x
>
But quite what do you mean by consistently ? The precision and range
may differ from machine to machine,
Ian
| |
| Herman D. Knoble 2006-07-07, 7:59 am |
| Ian: Thanks. By consistent I mean that compilers will accept it.
In practice, it will also give consistent results for IEEE processors
(e.g., Intel Pentium processors).
Skip
On Fri, 07 Jul 2006 13:37:00 +0000, Ian Bush <I.J.Bush@nospam.dl.ac.uk> wrote:
-|Herman D. Knoble wrote:
-|
-|> Eli: I believe that the following declaration is Standard
-|
-|Yup, I agree
-|
-|> and will work
-|> consistently across compilers:
-|>
-|> real(kind(1.D0)), dimension(10) :: x
-|>
-|
-|But quite what do you mean by consistently ? The precision and range
-|may differ from machine to machine,
-|
-|Ian
| |
| Richard E Maine 2006-07-07, 6:59 pm |
| David Flower <DavJFlower@AOL.COM> wrote:
> I think that you will find that the equivalent KIND value under FTN95
> for an 8-byte floating-point quantity is 3.
Really? Not 2?
Not that it really matters, as hard-wiring kind numbers like this is a
bad idea (as illustrated by the OP's post). But I'm curious. I've seen a
scheme where 8-byte floats are kind=2 (because they are the second
floating kind), but I don't think I've seen 3.
Not that it couldn't be, but you have me curious as to whether it is
indeed 3 or you just misstated it (perhaps thinking of 10- or 16-byte
reals, if it supports either of those).
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| David Flower 2006-07-07, 6:59 pm |
|
Richard E Maine wrote:
> David Flower <DavJFlower@AOL.COM> wrote:
>
>
> Really? Not 2?
>
> Not that it really matters, as hard-wiring kind numbers like this is a
> bad idea (as illustrated by the OP's post). But I'm curious. I've seen a
> scheme where 8-byte floats are kind=2 (because they are the second
> floating kind), but I don't think I've seen 3.
>
> Not that it couldn't be, but you have me curious as to whether it is
> indeed 3 or you just misstated it (perhaps thinking of 10- or 16-byte
> reals, if it supports either of those).
>
> --
> Richard Maine | Good judgment comes from experience;
> email: my first.last at org.domain| experience comes from bad judgment.
> org: nasa, domain: gov | -- Mark Twain
You are quite right - I took my eye off the ball!
However, the values are idiosyncratic, for example 1, 2, 4, and 8 byte
INTEGERs are KINDs 1, 2, 3 and 4
Apologies for misinforming the group
Dave Flower
| |
|
| Eli Luong wrote in message <1152210793.582343.285860@p79g2000cwp.googlegroups.com>...
>I'm trying to compile an f90 file on the FTN95 Plato IDE, but the
>compiler is giving me a Invalid KIND specifier. I'm sure this code
>compiles, because it compiles/builds fine on the Compaq Visual Fortran6
>(or something similar), but I don't have immediate access to the
>machine that has it right now and so I'm trying to use an alternate
>compiler, but it does not seem to be working.
>
>The error line usually has something like this: REAL(8) cx, cy, cz
>
>Is there an easy way to fix this so I can compile here?
The above line is simply not portable.
The kind (specified here as 8) does not have to mean anything
on any given compiler.
Portable is:
integer: parameter :: dp = kind (1.0d0)
real (dp) :: cx, cy, cz
|
|
|
|
|