Make sure you didn't declare A and B elsewhere in the code - those are
pretty common variable names, and bringing in A into a scope where there is
an A would confuse the compiler.
Test that by renaming A and B in the USE statement - call them something
unusual, like _my_A_.
Use mod1,_my_A_ => A,_my_B_ => B
This will rename the A and B arrays in the main program, so the compiler
won't be confused by the presence in scope of other A's and B's.
If the problem then goes away, you likely do have this "name clash."
Alvaro
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of
Ben Blackwell
Sent: Thursday, February 12, 2004 7:47 AM
To: [log in to unmask]
Subject: Re: memory allocation in conjuction with modules
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
|