SUBSE2 Subroutine

public subroutine SUBSE2(X, N, D1, D1min, D1max, D2, D2min, D2max, Y, Ny)

NAME

subse2(3f) - [M_datapac:VECTOR_OPERATION] extract the elements of a vector
which fall into a user-specified subset (two subset variables)

SYNOPSIS

SUBROUTINE SUBSE2(X,N,D1,D1min,D1max,D2,D2min,D2max,Y,Ny)

 REAL(kind=wp) :: D1(:), D1max, D1min, D2(:), D2max, D2min, X(:), Y(:)
 INTEGER       :: N, Ny

DESCRIPTION

This subroutine carries over into Y all observations of the precision
precision vector X for which the corresponding elements in the precision
precision vector D1 are inside the closed (inclusive) interval defined
by D1MIN and D1MAX, and also for which the corresponding elements
in the vector D2 are inside the closed (inclusive)
interval defined by D2MIN and D2MAX.

No observations in X corresponding to elements of D1 or D2 outside
of their respective intervals are carried over into Y.

The input vector X is itself unaltered; those elements of X to be
retained are copied over into the output vector Y.

Thus all observations of X which correspond to elements in D1 which
are smaller than D1MIN or larger than D1MAX, or which correspond to
elements in D2 which are smaller than D2MIN or larger than D2MAX,
are not copied over into Y.

The use of subse2(3f) gives the data analyst the capability
to easily extract subsets of the data prior to data analysis on
each subset.

INPUT ARGUMENTS

X      the vector of (unsorted or sorted) observations.

N      The integer number of observations in the vector x.

D1     A vector which (in conjunction with d2) "defines" the various
       possible subsets of x.

D1MIN  The value which defines in d1 the lower limit
       (inclusively) of the particular subset of interest to be
       retained.

D1MAX  The value which defines in d1 the upper limit
       (inclusively) of the particular subset of interest to be
       retained.

D2     A vector which (in conjunction with d2) "defines" the various
       possible subsets of x.

D2MIN  The value which defines in d2 the lower limit
       (inclusively) of the particular subset of interest to be retained.

D2MAX  The value which defines in d2 the upper limit
       (inclusively) of the particular subset of interest to be retained.

OUTPUT ARGUMENTS

Y      The vector containing only those elements
       of X simultaneously corresponding to values of the D1 vector
       in the interval D1MIN to D1MAX (inclusive), and values of the
       D2 vector in the interval D2MIN to D2MAX (inclusive).

NY     The integer number of retained observations copied into
       the vector Y.

EXAMPLES

Sample program:

program demo_subse2
use M_datapac, only : subse2
implicit none
! call subse2(x,y)
end program demo_subse2

Results:

AUTHOR

The original DATAPAC library was written by James Filliben of the Statistical
Engineering Division, National Institute of Standards and Technology.

MAINTAINER

John Urban, 2022.05.31

LICENSE

CC0-1.0

Arguments

Type IntentOptional Attributes Name
real(kind=wp) :: X(:)
integer :: N
real(kind=wp) :: D1(:)
real(kind=wp) :: D1min
real(kind=wp) :: D1max
real(kind=wp) :: D2(:)
real(kind=wp) :: D2min
real(kind=wp) :: D2max
real(kind=wp) :: Y(:)
integer :: Ny

Source Code

SUBROUTINE SUBSE2(X,N,D1,D1min,D1max,D2,D2min,D2max,Y,Ny)
REAL(kind=wp) :: D1(:), D1max, D1min, D2(:), D2max, D2min, hold, poin1l, poin1u, poin2l, poin2u, X(:), Y(:)
INTEGER       :: i, k, N, ndel, Ny

!     OUTPUT--THE VECTOR Y
!             INTO WHICH HAVE BEEN COPIED
!             ONLY THOSE VALUES OF X WHICH
!             SIMULTANEOUSLY CORRESPOND TO VALUES
!             IN THE D1 AND D2 VECTORS INSIDE
!             (INCLUSIVELY) THE RESPECTIVE
!             INTERVALS OF INTEREST, AND
!             THE INTEGER VALUE NY
!             WHICH GIVES THE NUMBER OF
!             OBSERVATIONS COPIED INTO Y.
!             ALSO, 13 LINES OF SUMMARY INFORMATION
!             WILL BE GENERATED INDICATING
!             1) WHAT THE INTERVAL OF INTEREST WAS
!                IN THE D1 VECTOR;
!             2) WHAT THE INTERVAL OF INTEREST WAS
!                IN THE D2 VECTOR;
!             3) HOW MANY OBSERVATIONS WERE DELETED;
!             4) WHAT THE SAMPLE SIZE OF X WAS (N);
!             5) WHAT THE SAMPLE SIZE OF Y WAS (NY);
!     PRINTING--YES.
!     RESTRICTIONS--THERE IS NO RESTRICTION ON THE MAXIMUM VALUE
!                   OF N FOR THIS SUBROUTINE.

!     COMMENT--THE INPUT VECTOR X IS NOT ALTERED
!              BY APPLICATION OF THIS SUBROUTINE.
!              THIS IS A MAJOR DISTINCTION
!              BETWEEN THIS SUBROUTINE AND, SAY,
!              THE SUBSET SUBROUTINE.
!     COMMENT--IN THE END, AFTER THIS SUBROUTINE HAS
!              MADE WHATEVER DELETIONS ARE APPROPRIATE,
!              THE OUTPUT VECTOR Y WILL BE 'PACKED';
!              THAT IS, NO 'HOLES' WILL EXIST IN THE
!              VECTOR Y--ALL OF THE RETAINED ELEMENTS
!              OF Y WILL BE PACKED INTO THE FIRST AVAILABLE
!              LOCATIONS IN Y, WHILE THE REMAINDER
!              OF THE N LOCATIONS IN Y WILL BE ZERO-FILLED.
!     COMMENT--ALTHOUGH THERE
!              MAY BE A CORRESPONDANCE BETWEEN
!              THE ELEMENTS OF THE X AND D1 VECTORS
!              AND ELEMENTS OF THE X AND D2 VECTORS
!              BEFORE APPLICATION OF
!              THIS SUBROUTINE, THERE WILL
!              BE NO CORRESPONDANCE BETWEEN
!              Y AND D1, AND Y AND D2
!              (DUE TO THE PACKING OF
!              THE RETAINED ELEMENTS IN Y)
!              AFTER APPLICATION OF THIS SUBROUTINE.
!
!---------------------------------------------------------------------
!
!     CHECK THE INPUT ARGUMENTS FOR ERRORS
!
      IF ( N<1 ) THEN
         WRITE (G_IO,99001)
99001    FORMAT (' ',                                                   &
     &'***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE SUBSE2 SUBROUTINE IS NON-POSITIVE *****')
         WRITE (G_IO,99002) N
99002    FORMAT (' ','***** THE VALUE OF THE ARGUMENT IS ',I0,' *****')
         RETURN
      ELSE
         IF ( N==1 ) THEN
            WRITE (G_IO,99003)
99003       FORMAT (' ',                                                &
     &'***** NON-FATAL DIAGNOSTIC--THE SECOND INPUT ARGUMENT TO THE SUBSE2 SUBROUTINE HAS THE VALUE 1 *****')
         ELSE
            hold = X(1)
            DO i = 2 , N
               IF ( X(i)/=hold ) GOTO 50
            ENDDO
            WRITE (G_IO,99004) hold
99004       FORMAT (' ',                                                &
     &'***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUMENT (A VECTOR) TO THE SUBSE2 SUBROUTINE HAS ALL ELEMENTS =',E15.8,' *****')
         ENDIF
!
!-----START POINT-----------------------------------------------------
!
 50      continue
         poin1l = D1min
         poin1u = D1max
         IF ( D1min>D1max ) poin1l = D1max
         IF ( D1min>D1max ) poin1u = D1min
!
         poin2l = D2min
         poin2u = D2max
         IF ( D2min>D2max ) poin2l = D2max
         IF ( D2min>D2max ) poin2u = D2min
         k = 0
         DO i = 1 , N
            IF ( D1(i)>=poin1l .AND. D1(i)<=poin1u ) THEN
               IF ( D2(i)>=poin2l .AND. D2(i)<=poin2u ) THEN
                  k = k + 1
                  Y(k) = X(i)
               ENDIF
            ENDIF
         ENDDO
         Ny = k
         ndel = N - Ny
!
!     WRITE OUT A BRIEF SUMMARY
!
         WRITE (G_IO,99005)
99005    FORMAT (' ')
         WRITE (G_IO,99006)
99006    FORMAT (' ','OUTPUT FROM THE SUBSE2 SUBROUTINE--')
         WRITE (G_IO,99007) poin1l , poin1u
99007    FORMAT (' ',7X,'D1 LIMITS (INCLUSIVE)--   ',E15.8,' AND ',     E15.8)
         WRITE (G_IO,99008) poin2l , poin2u
99008    FORMAT (' ',7X,'D2 LIMITS (INCLUSIVE)--   ',E15.8,' AND ',     E15.8)
         WRITE (G_IO,99009)
99009    FORMAT (' ',7X,'ONLY THOSE OBSERVATIONS IN X')
         WRITE (G_IO,99010)
99010    FORMAT (' ',7X,'WILL BE CARRIED OVER INTO Y')
         WRITE (G_IO,99011)
99011    FORMAT (' ',7X,'FOR WHICH THE CORRESPONDING ELEMENTS OF ',     'D1 AND D2')
         WRITE (G_IO,99012)
99012    FORMAT (' ',7X,'ARE SIMULTANEOUSLY WITHIN (INCLUSIVE)')
         WRITE (G_IO,99013)
99013    FORMAT (' ',7X,'EACH SPECIFIED LIMIT.')
         WRITE (G_IO,99014)
99014    FORMAT (' ',7X,'NO OBSERVATIONS OUTSIDE OF THIS INTERVAL')
         WRITE (G_IO,99015)
99015    FORMAT (' ',7X,'HAVE BEEN CARRIED OVER INTO Y.')
         WRITE (G_IO,99016) N
99016    FORMAT (' ',7X,'THE INPUT  NUMBER OF OBSERVATIONS (IN X) IS ', I0)
         WRITE (G_IO,99017) Ny
99017    FORMAT (' ',7X,'THE OUTPUT NUMBER OF OBSERVATIONS (IN Y) IS ', I0)
         WRITE (G_IO,99018) ndel
99018    FORMAT (' ',7X,'THE NUMBER OF OBSERVATIONS DELETED       IS ', I0)
      ENDIF
!
END SUBROUTINE SUBSE2