Michael:
Thanks for your response. I did have the "use mod1" in the actual
application but failed to include it in the code fragment I put in the
email. I checked your code with my compiler and it does work. This
suggests that I have a more serious problem with memory somewhere else
in the code. If I comment out any reference to the offending variables,
the code runs and gives the "right" answer.
Thanks,
Ben
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf
Of Michael Metcalf
Sent: Thursday, February 12, 2004 5:27 AM
To: [log in to unmask]
Subject: Re: memory allocation in conjuction with modules
----- Original Message -----
From: "Ben Blackwell" <[log in to unmask]>
To: <[log in to unmask]>
Sent: 12 February 2004 12:28
Subject: memory allocation in conjuction with modules
> I am having difficulty with memory allocation when the variables were
> declared in a module. For example,
>
Your code is incomplete, in particular lacking a use statement. The
following works perfectly well:
MODULE MOD1
REAL, DIMENSION(:), ALLOCATABLE :: A, B
END MODULE MOD1
PROGRAM MAIN
use mod1
REAL, DIMENSION(:), ALLOCATABLE :: C, D
integer :: status
num_node = 2
max_num_tstep = 3
ALLOCATE(C(NUM_NODE), STAT=STATUS)
ALLOCATE(D(NUM_NODE), STAT=STATUS)
ALLOCATE(A(MAX_NUM_TSTEP), STAT=STATUS)
ALLOCATE(B(MAX_NUM_TSTEP), STAT=STATUS)
c = 1
d = 2
a = 3
b = 4
print *, c(1), d(1), a(1), b(1)
END PROGRAM MAIN
Regards,
Mike Metcalf
|