Re: defining an arbitrary type in your newer Fortrans



Hi again

Just read the other thread and now see you are looking for something like a
type alias rather than a record.

Sadly nothing quite like that in Fortran, which is a shame as I use it a lot
in Pascal/Delphi (especially when passing arrays into subroutines).

Paul Holden


"PJH" <abc@xxxxxxxxxxx> wrote in message
news:12mouvafbom6ied@xxxxxxxxxxxxxxxxxxxxx
Welcome back to Fortran.

I am a bit at a loss to understand your reluctance to use "derived data
types", which, speaking as a Delphi programmer myself, are very similar to
the basic Pascal records. The O-O extensions to records in Delphi
(properties and type methods) give a bit more flexibility than basic
Fortran
90/95 deriverd types, but some of this is (I think) included in the Fortan
2003 standard.

Fortran derived types can be given a type name and can contain any other
type or structure (except for allocatable arrays in F90/95, which was a
bit
of a ***-up that has been rectified in F2003). A Fortran Type would look
something like:

type tMyType
integer :: iTypeDef
real :: Value(10)
type (tMyType) :: Child
end type tMyType

The equivalent Pascal record would be

Type
tMyRec = record
iRecDef : integer;
Value(10) : single;
Child : tMyRec;
end;

Accessing elements/fields in a Fortran type instance is done using a %
character, rather than the dot that is used in Pascal and just about every
other language that I have used. I have never understood why the standards
committee decided against the dot notation, maybe someone could educate me
on that issue - I'm sure they had a good reason other than just being
contrary.

The array declaration statement you quote looks odd to me if it is
supposed
to be an example of "new" Fortran - the REAL*8 is legal but not
recommended
syntax. Better would be REAL(8) or even better use a Kind Type Parameter
rather than a literal constant. I suspect you maybe need a better (new
Fortran) reference manual. I would recommend Michael Metcalf's "Fortran
95/2003 Explained", which covers all the new elements of the language very
well.

Hope this helps.

Paul Holden


"Ancient_Hacker" <grg2@xxxxxxxxxxx> wrote in message
news:1164733873.775210.141870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hmmm, Getting Back to using Fortran after a few decades of absence, I
assume there's been some enhancements sine CDC FTN 4.1, so i read the
fine new manuals, and hmmm, ncei to have variable dimensions and
allocatables, and array ops, BUT I don't see one obvious fribble.

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.

But.... I don't see this in Fortran !! And I see a lot of examples
where declarations are clumsily repeated over and over each time,
identical in each case:
REAL * 8, DIMENSION (100, : ) :: TwoDimmer

so it seems you can't define a nice type name in Fortran. Sounds like
an unusual omission.

Is there some good reason for this, or are two pages stuck together in
my PDF file?

P.S. I dont consider "derived types" a good substitute.

Any hints appreciated.





.


Quantcast