Saving own Types inside Arrays

62 views Asked by At

I'm having a problem compiling a program with GFortran, or two to be precise.

First, my code is:

Type :: zeit
    INTEGER :: Stunde, Minute
    real :: Sekunde
END Type

TYPE :: ergebnis
    CHARACTER(LEN=30):: Nachname, Vorname
    TYPE(Zeit)::Laufzeit
END TYPE

type(ergebnis), allocatable :: Liste(:)

Which contains these:

SUBROUTINE leseliste(k)
    type(ergebnis) :: Liste
    integer :: i, k
    character(len=30) :: vorN, nachN
    integer :: stun, minu
    real :: seku


    do i=1, k
        WRITE (*, *) "Laeufername und Zeit:"
        Read (*, *) vorN, nachN, stun, minu, seku
        Liste(i:1) = ergebnis(vorN, nachN, zeit(stu, minu, seku))
    enddo
END SUBROUTINE

I then allocate my List with a read variable and call the leseliste-subroutine.

But GFortran won't compile because:

Aufgabe14.f95:33:3:

Liste(i:1) = Laeufer(vorN, nachN, Ergebnislaeufer(stu, minu, seku))
1
Error: Unclassifiable statement at (1)
Aufgabe14.f95:41:5:

USE Zeitmodul
 1
Fatal Error: Can't open module file ‘zeitmodul.mod’ for reading at (1):   Datei oder Verzeichnis nicht gefunden
compilation terminated.

Anyone, who can help me? Thanks in advance!

1

There are 1 answers

0
Alex On

You code is a little messed up, first you create one object

type(ergebnis) :: Liste

and then you want to use it like a array

Liste(i:1) = ergebnis(vorN, nachN, zeit(stu, minu, seku))

make Liste a arrray

type(ergebnis), allocatable :: Liste(:)

and then allocate it,

allocate(Liste(1:10), stat=status)  

and don't forget to deallocate when you don't need Liste anymore

deallocate(Liste, stat=status)