Michael <mwpowellnm@[EMAIL PROTECTED]
> wrote:
> type grid
> real(kind = rkind), pointer :: x(:)
> real(kind = rkind), pointer :: y(:)
> real(kind = rkind), pointer :: sigmaz(:)
> real(kind = rkind), allocatable :: zg(:,:)
> end type grid
....
> type (grid), intent(out) :: grid_dat
>
> After a couple of these function calls, we end up two calls deep in a
> function with the following operation attempted,
>
> allocate(grid_dat%x(idim), grid_dat%y(jdim), grid_dat
> %sigmaz(kdim), grid_dat%zg(idim, jdim), stat = allocerr)
>
> Now, the first time through, for m_grid, the call succeeds. We
> allocate memory properly. The second time through, for c_grid,
> however, the call fails. We consistently fail allocating memory for
> grid_dat%zg.
Hmm. As some others mentioned, lots of things could be going on here.
When messing with things like pointers, it is possible to get memory
badly enough corrupted that apparently unrelated things will fail in
apparently unrelated places. But then, you say it appears consistent, so
maybe things aren't that bad.
If it consistently failes on the second time through, that makes me
think about things like traying to allocate an allocatable that is
already allocated. That isn't allowed. I could well imagine the variable
getting allocated the first time through, and then failing on the second
time because the variable is already allocated.
Now the intent(out) ought to automatically deallocate grid_dat%sz on
entry. Actually, I haven't checked to find exactly where the standard
says that, but intuitively, that's the way it seems like it ought to be,
so I suspect the standard says it and I'm too lazy right now to check.
But...
That's a bit subtle. I wonder if the compiler might miss doing it. In
any case, I'd personally deallocate the thing when I was done with each
time anyway. Call it just a style preference on my part. You might try
it just to see if that happens to solve the problem. It "shouldn't" make
any difference, but I'd think it worth trying.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain


|