Re: How to select a subset of an array in Fortran 90
- From: "[JvO]" <jvo_36@xxxxxxxxxxx>
- Date: 30 Jun 2005 07:31:22 -0700
Leonard W. Howell, Jr. schreef:
> I'm trying to do the following but w/o any success:
>
> I need a subroutine - call it SELECT - this is passed an array A, say of
> dimension N, and I would like SELECT to return an array B of dimension M<=N
> where B is a subset of A constructed according to some criteria. For
> example, I might have
>
> SUBROUTINE SELECT(A,N, RANGE, B, M)
>
> and B could be the elements of A between Range(1) and Range(2).
>
> I thought I could define B like
>
> WHERE (A<=Range(2) .AND. A >= Range(1))
> B=A
> Endwhere
To start with, WHERE can not be used in this case, unless A is a scalar
or
A and B heve the same shape :-)
So you will have to do the selection manually (in a loop or so).
BTW, you seem to know the size of B (== M) when calling SELECT,
so where is the real problem ?
If I misunderstand this, the alternative is to declare B as a POINTER,
allocate it to the desired size, and return this size in M.
SUBROUTINE SELECT(A,N, RANGE, B, M)
integer :: N, A(N), range(2), B(:), M
pointer :: B
etc.
> I am having trouble with the variable dimension of B in the subroutine so
> any help would be appreciated, Leonard
[JvO]
.
- References:
- How to select a subset of an array in Fortran 90
- From: Leonard W. Howell, Jr.
- How to select a subset of an array in Fortran 90
- Prev by Date: HELP ME, please
- Next by Date: Re: HELP ME, please
- Previous by thread: Re: How to select a subset of an array in Fortran 90
- Next by thread: HELP ME - HOW THIS ERROR?
- Index(es):
Relevant Pages
|