Q: Checking the size of a non-allocated array?



Running Windows XP, Intel Pentium 4, Intel 9.1 compiler

I have written some code that checks the size of a passed array as
shown below. For a fixed size array (the first call from myprog), the
subroutine mysub will call size(x,1) and get a legitimate non-zero
result. Once I know there is an array I can legitimately access, then
I can fill it with something. For an allocatable array that is not
currently allocated (the second call from myprog), subroutine mysub
will call size(x,1) and get zero (at least with my setup). This lets
the subroutine know not to try to access the elements, and it will
return without doing anything. Problem is, the documentation I have
been reading says size(x,1) for an unallocated array x is undefined.
So I suspect I am doing something that works with my setup but is not
part of the standard. Is this true? And if so, then how can I code
the subroutine to know if the passed array can be accessed? I would
like to code the subroutine to gracefully check for this type of
problem, but if I can't use size() then how do I do it?


module mymodule
contains

subroutine mysub(x)
!-ARG
integer x(:)
!-----
if( size(x,1) /= 0 ) then ! how do I know this will work?
x(1) = 1
endif
return
end subroutine mysub

end mymodule

!************************************

program myprog
use mymodule
!-LOC
integer y(5)
integer, allocatable :: x(:)
!-----
call mysub(y) ! this call should be ok
call mysub(x) ! this call invokes size(x,1), which may not be
ok
! rest of the code
end program myprog


.



Relevant Pages

  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)
  • VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)
  • Re: memory leak help!
    ... a loop from the main program. ... REPLACE THE NEW COMPLEX INTO ORIGINAL ARRAY x ... END OF SUBROUTINE SCEUA ... IMPLICIT NONE ...
    (comp.lang.fortran)
  • VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)