Re: How to select a subset of an array in Fortran 90





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]

.



Relevant Pages

  • Using pointers in fortran 95
    ... IMPLICIT none ... SUBROUTINE Start ... TYPE, DIMENSION, POINTER:: neigh ...
    (comp.lang.fortran)
  • Re: How to select a subset of an array in Fortran 90
    ... Leonard W. Howell, Jr. ... > dimension N, and I would like SELECT to return an array B of dimension M<=N ... > SUBROUTINE SELECT ...
    (comp.lang.fortran)
  • Re: using dot_product from c++
    ... real, dimension(:)::vec1,vec2! ... subroutine vectorProduct ... Why do I get a 0 value from Fortran subroutine? ... vecpro.f90:: undefined reference to ...
    (comp.lang.fortran)
  • Re: Procedure Pointer (Components) with no explicit interface and with implicit typing
    ... in principle, I can assign to it either a function nor a subroutine, e.g. ... "7.4.2.2 Procedure pointer assignment" ... "If proc-pointer-object has an implicit interface and is explicitly ... external:: func, sub ...
    (comp.lang.fortran)
  • Re: Neq Max Limit
    ... you are passing incorrect arguments to a subroutine. ... One may be the array size and another an array. ... dimension y,dy ... PRINT *,i at the top of the outer loop may tell you if the program is ...
    (comp.lang.fortran)