XMM-Newton SAS Home Page
XMM-Newton Science Analysis System


ssclib (ssclib-4.36.1) [xmmsas_20230412_1735-21.0.0]


Calculate the indices(i,j) on the new frame converted from the old frame.

Particularly useful in subroutines.

  interface calcIndicesFromIndices
    subroutine calcIndicesFromIndicesDblDbl(oldIndices, newIndices, oldLbound, newLbound)
      real(double), intent(in)    :: oldIndices(:)
      real(double), intent(out)   :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesDblDbl

    subroutine calcIndicesFromIndicesDblI32(oldIndices, newIndices, oldLbound, newLbound)
      real(double),   intent(in)  :: oldIndices(:)
      integer(int32), intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesDblI32
  
    subroutine calcIndicesFromIndicesDblI16(oldIndices, newIndices, oldLbound, newLbound)
      real(double),   intent(in)  :: oldIndices(:)
      integer(int16), intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesDblI16
  
    subroutine calcIndicesFromIndicesSglSgl(oldIndices, newIndices, oldLbound, newLbound)
      real(single),   intent(in)  :: oldIndices(:)
      real(single),   intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesSglSgl
  
    subroutine calcIndicesFromIndicesSglI32(oldIndices, newIndices, oldLbound, newLbound)
      real(single),   intent(in)  :: oldIndices(:)
      integer(int32), intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesSglI32
  
    subroutine calcIndicesFromIndicesSglI16(oldIndices, newIndices, oldLbound, newLbound)
      real(single),   intent(in)  :: oldIndices(:)
      integer(int16), intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesSglI16
  
    subroutine calcIndicesFromIndicesI32I32(oldIndices, newIndices, oldLbound, newLbound)
      integer(int32), intent(in)  :: oldIndices(:)
      integer(int32), intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesI32I32
  
    subroutine calcIndicesFromIndicesI16I16(oldIndices, newIndices, oldLbound, newLbound)
      integer(int16), intent(in)  :: oldIndices(:)
      integer(int16), intent(out) :: newIndices(size(oldIndices))
      integer, intent(in)           :: oldLbound(size(oldIndices))
      integer, intent(in), optional :: newLbound(size(oldIndices))
    end subroutine calcIndicesFromIndicesI16I16
  end interface

This calculates the indices (i,j) on the new frame converted from those on the old frame. The most likely case is to get a pair of indices of an array in a subroutine/function, all the lbound-s of which must be 1, from the old pair of indices, where the lbound-s can be arbitrary.

newLbound(:) is in default 1 (if not given).

The following is an example for a 1-dimension array.

  integer :: ary(5:8)
  ary(7) = -99	! i=7 is the 3rd element in the array.
  call aSub(iPoints=(/7/), lbounds=lbound(ary))

  subroutine aSub(iPoints, lbounds)
    integer, intent(in) :: iPoints(:), lbounds(:)
    integer :: outAry(size(iPoints))

    call getIndicesFromIndices(iPoints, outAry, lbounds)
    print *, outAry		! => 3
    ! nb., the old index=7 corresponds to index=3 in the current context.
  end subroutine aSub



XMM-Newton SOC -- 2023-04-16