Re: defining an arbitrary type in your newer Fortrans



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.
.



Relevant Pages

  • Re: defined operator & assignment speed & memory usage problem
    ... resolve into a single multiply-add, and have it appear in much longer ... all of the projects except mine abandoned Fortran ... programming I'm describing. ... My work involves creating derived types that are reusable for solving ...
    (comp.lang.fortran)
  • Re: It Hurts When I Do This
    ... In this single instance, Fortran has it wrong. ... It leads ... but not for derived types. ... simillar underlying meaning. ...
    (comp.lang.fortran)
  • Re: defining an arbitrary type in your newer Fortrans
    ... Everything is nicely handled by derived types. ... I don't see anything directly comparable in Fortran. ... Fortrans that have a macro preprocessor option, ... Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org ...
    (comp.lang.fortran)
  • Re: defining an arbitrary type in your newer Fortrans
    ... to paste over C's inadequate type system. ... Everything is nicely handled by derived types. ... I don't see anything directly comparable in Fortran. ... Fortrans that have a macro preprocessor option, ...
    (comp.lang.fortran)
  • Re: Subroutine arguments vs module variables
    ... > use derived types to aggregate related arguments into a single ... var = sum**2)/size ... This would be a major break from traditional Fortran and perhaps could ... Returning several function results is a convenient feature of Python, ...
    (comp.lang.fortran)