finding specific indices with pointer array

前端 未结 3 1662
北海茫月
北海茫月 2021-01-25 13:24

I am relatively new to Fortran and break my head about one thing for hours now:

I want to write a subroutine for finding the indexes for specific elements in a real 1D

3条回答
  •  佛祖请我去吃肉
    2021-01-25 13:42

    If succinctness (rather than performance) floats your boat... consider:

    FUNCTION find_indexes_for_specific_elements_in_a_real_1D_array(array, min)  &
        RESULT(indices)
      REAL, INTENT(IN) :: array(:)
      REAL, INTENT(IN) :: min
      INTEGER, ALLOCATABLE :: indices(:)
      INTEGER :: i
      indices = PACK([(i,i=1,SIZE(array))], array >= min)
    END FUNCTION find_indexes_for_specific_elements_in_a_real_1D_array
    

    [Requires F2003. Procedures that have assumed shape arguments and functions with allocatable results need to have an explicit interface accessible where they are referenced, so all well behaved Fortran programmers put them in a module.]

提交回复
热议问题