Re: defining an arbitrary type in your newer Fortrans
- From: Walter Spector <w6ws_xthisoutx@xxxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 18:16:58 GMT
Ancient_Hacker wrote:
Hmmm, Getting Back to using Fortran after a few decades of absence, I
assume there's been some enhancements sine CDC FTN 4.1,
Welcome back!
In your basic newer languages I've been using in the interim, you can
define types, like in Pascal "type" or C's "typedef". yes, I know, in
C it's not really a new type but more like a macro....
Note that one of the reasons 'typedef' is nice in C is that for, say,
an 'int', you never know whether next week it needs to be a 'long' or
a 'long long' or a 'size_t' or who knows what.
In Fortran, 'kinds' are used for this parameterization. Your
example:
REAL * 8, DIMENSION (100, : ) :: TwoDimmer
has a couple of problems. First, the '* 8' is non-Standard 'byte count'
extension. It should really specify a kind - REAL(KIND=8) or more simply
REAL(8). (The second problem is the (100,:) part - which probably isn't
what you want.)
The KIND is parameterizable:
INTEGER, PARAMETER :: dbl_k = 8 ! Double precision kind (on some compilers)
REAL(dbl_k), ALLOCATABLE, DIMENSION(:,:) :: TwoDimmer
The KIND values are compiler dependant, so a hard-coded '8' is not a good
thing to use in portable code. Some compilers use values of 1 and 2 (for
single and double precision.) So you can often use the KIND intrinsic function
to obtain the values you need:
INTEGER, PARAMETER :: dbl_k = KIND (1.0d0) ! Double precision kind
REAL(dbl_k), ALLOCATABLE, DIMENSION(:,:) :: TwoDimmer
For more extensive encapsulation, derived types are the way to go.
W.
.
- Follow-Ups:
- Re: defining an arbitrary type in your newer Fortrans
- From: Ancient_Hacker
- Re: defining an arbitrary type in your newer Fortrans
- References:
- defining an arbitrary type in your newer Fortrans
- From: Ancient_Hacker
- defining an arbitrary type in your newer Fortrans
- Prev by Date: Re: defining an arbitrary type in your newer Fortrans
- Next by Date: Re: defining an arbitrary type in your newer Fortrans
- Previous by thread: Re: defining an arbitrary type in your newer Fortrans
- Next by thread: Re: defining an arbitrary type in your newer Fortrans
- Index(es):
Relevant Pages
|