
!*    YOMOBFUN - STATEMENT FUNCTIONS FOR OBS. PROCESSING

!        D. VASILJEVIC    ECMWF    09/09/1991

!**   MODIFICATIONS
!     -------------
!     2007-May-30   D. Tan         Unreject functions for Aeolus DWL
!     ------------------------------------------------------------------
#ifdef DOC

!     IBITS (INVAR,IPOS,ICOVR)=AND(SHIFTR(INVAR,IPOS),ICOVR)
!     STATEMENT FUNCTION TO UNPACK ANY BIT PATTERN

!     VARIABLE   / TYPE /                   MEANING                    /
!     --------     -----                    --------
!     IBITST         I        STATEMENT FUNCTION
!     INVAR          I        WORD TO BE UNPACKED
!     IPOS           I        BIT POSITION OF BIT STRUCT. TO BE UNPACKED
!     ICOVR          I        NO. OF BIT OCC. BY THE BIT STRUCTURE
!     not used

!     INSERT(INVAR,INVAL,IBIT)=INVAR.OR.(SHIFTL(INVAL,IBIT))
!     STATEMENT FUNCTION TO INSERT ANY BIT PATTERN

!     VARIABLE   / TYPE /                   MEANING                    /
!     --------     -----                    --------
!     INSERT         I        STATEMENT FUNCTION
!     INVAR          I        WORD TO APPLY FUN. ON
!     INVAL          I        BIT PATTERN TO BE INSERTED
!     IBIT           I        BIT POSITION

!     WE CHANGED SHIFTL T0 ISHFT AND .OR. TO IOR



!     ICHBPT(IVAR,IBP,IBO)    =IVAR.AND.
!    &                      (SHIFTL(177777777777777777777B,IBP+IBO).OR.
!                            SHIFTR(177777777777777777777B,64 -IBP)   )
!     STATEMENT FUNCTION TO CHANGE BIT PATTERN OF ONES TO ZEROS

!     VARIABLE   / TYPE /                   MEANING                    /
!     --------     -----                    --------
!     ICHBPT         I        STATEMENT FUNCTION
!     IVAR           I        INPUT WORD TO BE DEALT WITH
!     IBP            I        BIT POSITION OF BIT PATTERN
!     IBO            I        NUMBER OF BITS TAKEN BY BIT PATTERN
!     not used

!***********************************************************************
!     WIND COMPONENTS

!     UCOM(PDD,PFF)= -PFF * SIN(PDD*RADIANS)
!     VCOM(PDD,PFF)= -PFF * COS(PDD*RADIANS)

#endif
!     INSERT(INVAR,INVAL,INBIT)=INVAR.OR.(SHIFTL(INVAL,INBIT))

INTEGER(KIND=JPIM) :: INSERT,INVAR,INVAL,INBIT
INSERT(INVAR,INVAL,INBIT) = IOR(INVAR,ISHFT(INVAL,INBIT))
REAL(KIND=JPRB) :: ZINSERT, ZINVAR
ZINSERT(ZINVAR,INVAL,INBIT) = IOR(INT(ZINVAR),ISHFT(INVAL,INBIT))
INTEGER(KIND=JPIM) :: INTREA
REAL(KIND=JPRB) :: ZARG
INTREA(ZARG)=MIN(MAX(-2147483647,INT(ZARG)),2147483647)
REAL(KIND=JPRB) :: REAINT
INTEGER(KIND=JPIM) :: IARG
REAINT(IARG)=REAL(MIN(MAX(-2147483647,IARG),2147483647),JPRB)

INTEGER(KIND=JPIM) :: ICHSTAT_ACTIVE, ICHSTAT_PASSIVE, ICHSTAT_REJECT, ICHSTAT_BLACKLST
ICHSTAT_ACTIVE(IARG)   = INSERT(IARG, 1, 0)
ICHSTAT_PASSIVE(IARG)  = INSERT(IARG, 1, 1)
ICHSTAT_REJECT(IARG)   = INSERT(IARG, 1, 2)
ICHSTAT_BLACKLST(IARG) = INSERT(IARG, 1, 3)

REAL(KIND=JPRB) :: ZCHSTAT_ACTIVE, ZCHSTAT_PASSIVE, ZCHSTAT_REJECT, ZCHSTAT_BLACKLST
ZCHSTAT_ACTIVE(ZARG)   = ZINSERT(ZARG, 1, 0)
ZCHSTAT_PASSIVE(ZARG)  = ZINSERT(ZARG, 1, 1)
ZCHSTAT_REJECT(ZARG)   = ZINSERT(ZARG, 1, 2)
ZCHSTAT_BLACKLST(ZARG) = ZINSERT(ZARG, 1, 3)

INTEGER(KIND=JPIM) :: ICHSTAT_BLINFO
ICHSTAT_BLINFO(IARG, INVAL) = INSERT(IARG,INVAL,4)

REAL(KIND=JPRB) :: ZCHSTAT_BLINFO
ZCHSTAT_BLINFO(ZARG, INVAL) = ZINSERT(ZARG,INVAL,4)

INTEGER(KIND=JPIM) :: ICHEV1, ICHEV2, IEVNT
ICHEV1(IARG, IEVNT) = INSERT(IARG, 1, IEVNT-1)
ICHEV2(IARG, IEVNT) = INSERT(IARG, 1, IEVNT-1)

REAL(KIND=JPRB) :: ZCHEV1, ZCHEV2
ZCHEV1(ZARG, IEVNT) = ZINSERT(ZARG, 1, IEVNT-1)
ZCHEV2(ZARG, IEVNT) = ZINSERT(ZARG, 1, IEVNT-1)

INTEGER(KIND=JPIM), PARAMETER :: IREJECTED         = 4
INTEGER(KIND=JPIM), PARAMETER :: IREJECTED_REVERSE = IEOR(IREJECTED,-1)

INTEGER(KIND=JPIM) :: ICHSTAT_UNREJECT
ICHSTAT_UNREJECT(IARG) = IAND(IARG,IREJECTED_REVERSE)

REAL(KIND=JPRB) :: ZCHSTAT_UNREJECT
ZCHSTAT_UNREJECT(ZARG) = ICHSTAT_UNREJECT(INT(ZARG))
!     ------------------------------------------------------------------
