MODULE PRMTRS_STMAS_CLOUD

  ! LAPS PARAMETERS
  CHARACTER*9          :: LAPSAST            ! LAPS ASCII TIME
  INTEGER              :: LAPSI4T            ! LAPS I4TIME
  INTEGER              :: ICYCLE             ! LAPS CYCLE TIME

  REAL                 :: RMISSING           ! LAPS DEFAULT MISSING VALUE (YUANFU)
  REAL                 :: BADSFCDT           ! LAPS DEFAULT BAD SURFACE (YUANFU)
  REAL    ,ALLOCATABLE :: LATITUDE(:,:)      ! LAPS LATITUDE OF THE GRID (YUANFU)
  REAL    ,ALLOCATABLE :: LONGITUD(:,:)      ! LAPS LONGITUDE OF THE GRID (YUANFU)
  REAL    ,ALLOCATABLE :: TOPOGRPH(:,:)      ! LAPS LONGITUDE OF THE GRID (YUANFU)
  ! REAL    ,ALLOCATABLE :: LAPSRADW(:)        ! LAPS RADIAL WIND (YUANFU)
  REAL    ,ALLOCATABLE :: Z_FCSTGD(:)        ! VERTICAL LEVEL OF MODEL OR LAPS

  ! END OF LAPS PARAMETERS.

  ! GPS PROCESSING PARAMETERS:
  ! SPECIFIC GAS CONSTANT FOR WATER VAPOR:
  REAL    ,  PARAMETER :: RV_GAS=461
  ! COEFFICIENTS OF REFRACTIVITY AT MICROWAVE FREQUENCIES:
  REAL    ,  PARAMETER :: K2_RFC=22.1
  REAL    ,  PARAMETER :: K3_RFC=373900

  ! BUFR PARAMETERS:
  REAL    ,  PARAMETER :: BUFRMISS = 10.0E10 ! MISSING VALUE IN REAL FOR BUFR DATA
  REAL    ,  PARAMETER :: BADFLAG = -999.9   ! MISSING VALUE

  INTEGER ,  PARAMETER :: MAXDIMS=4          ! NUMBER OF TOTAL DIMENSION
  INTEGER ,  PARAMETER :: TMGOBS_CHANNEL=32  ! CHANNEL FOR TMG FILE
  INTEGER ,  PARAMETER :: PIGOBS_CHANNEL=33  ! CHANNEL FOR TMG FILE
  INTEGER              :: BGTHOBS            ! NOT USE BACKGROUND UNTIL NOBSGRID LESS THAN BGTHOBS
  INTEGER              :: GRDLEVL            ! GRID LEVEL
  INTEGER              :: NUMGRID(MAXDIMS)   ! NUMBER OF GRID FOR EVERY DIMENSION
  INTEGER              :: INIGRID(MAXDIMS)   ! INITIAL NUMBER OF GRID FOR EVERY DIMENSION
  INTEGER              :: MAXGRID(MAXDIMS)   ! MAX NUMBER OF GRID FOR EVERY DIMENSION
  INTEGER              :: NTMPGRD(MAXDIMS)   ! NUMBER OF OLD GRID FOR EVERY DIMENSION
  INTEGER              :: FCSTGRD(MAXDIMS)   ! NUMBER OF OLD GRID FOR EVERY DIMENSION
  INTEGER              :: NUMDIMS            ! NUMBER OF DIMENSION VALID
  INTEGER              :: NGPTOBS            ! NUMBER OF GRID POINT PER OBSERVATION
  INTEGER              :: NUMSTAT            ! NUMBER OF STATE
  INTEGER              :: NALLOBS            ! NUMBER OF TOTAL OBSERVATION VALID
  INTEGER ,ALLOCATABLE :: NOBSTAT(:)         ! NUMBER OF VARIETY OF OBSERVATION VALID
  INTEGER              :: NUMVARS            ! NUMBER OF TOTAL CONTROL VARIABLES VALID
  INTEGER              :: IFBKGND            ! WHETHER USE BACKGROUND OR NOT, 1 IS YES, 0 IS NOT
  INTEGER              :: IFBOUND            ! WHETHER USE BOUND OR NOT, 1 IS YES, 0 IS NOT
  INTEGER              :: IFPCDNT            ! WHETHER USE PURE PRESSURE COORDINATE, 1 IS YES, 0 IS NOT
  INTEGER              :: IF_TEST            ! WHETHER RUN FOR TEST CASE, 1 IS FOR THE TEST CASE, ADDED BY ZHONGJIE HE
  INTEGER              :: FNSTGRD            ! THE FINEST GRID LEVEL
  INTEGER              :: IFREPET            ! WHETHERE RUN THE MUTIGRID FRAME IN MONOTONOUS OR REPEATEDLY, 0 FOR MONOTONOUS, 1 FOR REPEATEDLY
  INTEGER              :: ITREPET            ! THE TIMES TO REPEAT

  REAL    ,ALLOCATABLE :: PENAL0X(:)         ! INITIAL X DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL0Y(:)         ! INITIAL Y DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL0Z(:)         ! INITIAL Z DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL0T(:)         ! INITIAL T DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_X(:)         ! X DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_Y(:)         ! Y DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_Z(:)         ! Z DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_T(:)         ! T DIRECTION PENALTY COEFFICENT
  REAL                 :: PNLT0PU            ! INITIAL GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND U
  REAL                 :: PNLT0PV            ! INITIAL GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND V
  REAL                 :: PNLT_PU            ! GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND U
  REAL                 :: PNLT_PV            ! GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND V
  REAL                 :: GRDSPAC(MAXDIMS)   ! GRID SPACING
  REAL                 :: ORIPSTN(MAXDIMS)   ! ORIGINAL POSITION OF THE STUDY DOMAIN
  REAL                 :: COSTFUN            ! COST FUNCTION
  REAL    ,ALLOCATABLE :: GRADINT(:,:,:,:,:) ! GRADIENT OF COST FUNCTION
  CHARACTER(LEN=100)   :: OBSFILE            ! OBSERVATION FILE NAME

  INTEGER              :: COSSTEP            ! THE ITERATE STEPS BEFORE MIDDLE GRID LEVEL
  INTEGER              :: MIDGRID            ! MIDDLE GRID LEVEL WHERE THE ITERATE STEP CHANGED
  INTEGER              :: FINSTEP            ! THE ITERATE STEPS AFTER MIDDLE GRID LEVEL

  INTEGER              :: U_CMPNNT           ! U COMPONENT INDEX
  INTEGER              :: V_CMPNNT           ! V COMPONENT INDEX
  INTEGER              :: W_CMPNNT           ! W COMPONENT INDEX
  INTEGER              :: PRESSURE           ! PRESSURE INDEX
  INTEGER              :: TEMPRTUR           ! TEMPERATURE INDEX
  INTEGER              :: HUMIDITY           ! SPECIFIC HUMIDITY INDEX
!added by shuyuan 20100721 for radar reflectivity
  INTEGER              :: ROUR_CMPNNT        ! DENSITY*RAIN WATER MIXING RATIO
  INTEGER              :: ROUS_CMPNNT        ! DENSITY*SNOW WATER MIXING RATIO
!
  INTEGER              :: XSL                ! X COORDINATE INDEX
  INTEGER              :: YSL                ! Y COORDINATE INDEX
  INTEGER              :: PSL                ! PRESSURE INDEX
  INTEGER              :: CSL                ! CORIOLIS FORCE INDEX
  INTEGER              :: DSL                ! DENSITY INDEX

  ! INTEGER ,ALLOCATABLE :: IDXRADWN(:,:)      ! GRID INDICES OF RADIAL WIND

  REAL                 :: XYTRANS            ! COEFFICIENT USED TO TRANSLATE THE X AND Y COORDINATE TO METERS
  REAL                 :: Z_TRANS            ! COEFFICIENT USED TO TRANSLATE THE Z COORDINATE TO METERS

  REAL    ,ALLOCATABLE :: WWW(:,:,:,:)       ! W COMPONENT
  REAL    ,ALLOCATABLE :: XXX(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 1
  REAL    ,ALLOCATABLE :: YYY(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 2
  REAL    ,ALLOCATABLE :: ZZZ(:,:,:,:)       ! HEIGHT OF GENERAL VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: PPP(:)             ! PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: COR(:,:)           ! CORIOLIS FREQUENCY
  REAL    ,ALLOCATABLE :: DEG(:,:)           ! DIRECTION ANGLE
  REAL    ,ALLOCATABLE :: DEN(:,:,:,:)       ! DENSITY
  REAL    ,ALLOCATABLE :: SCL(:)             ! SCALING THE PHYSICAL VARIABLE
  REAL    ,ALLOCATABLE :: SL0(:)             ! DEFAULT SCALING THE PHYSICAL VARIABLE
  REAL                 :: SCP(5)             ! SCALING XXX,YYY,ZZZ OR PPP,COR,DEN
  REAL                 :: ORIVTCL
  REAL    ,ALLOCATABLE :: XX0(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 1
  REAL    ,ALLOCATABLE :: YY0(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 2
  REAL    ,ALLOCATABLE :: ZZ0(:,:,:,:)       ! HEIGHT OF GENERAL VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: ZZB(:)       ! SIGMA LEVEL FOR VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: PP0(:)             ! PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: PPM(:)             ! MULTIGRID PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: CR0(:,:)           ! CORIOLIS FREQUENCY
  REAL    ,ALLOCATABLE :: DG0(:,:)           ! DIRECTION ANGLE
  REAL    ,ALLOCATABLE :: DN0(:,:,:,:)       ! DENSITY
! FOR OBSERVATION
  REAL                 :: OBSRADAR           ! THE OBSERVATION RATIO OF CONVENTION TO RADAR DATA
  REAL                 :: OBS_SFMR           ! THE OBSERVATION RATIO OF CONVENTION TO SFMR DATA
  REAL                 :: OBSREF           ! THE OBSERVATION RATIO OF REF
  REAL    ,ALLOCATABLE :: OBSPOSTN(:,:)      ! COORDINATE OF OBSERVATION POINT
  REAL    ,ALLOCATABLE :: OBSCOEFF(:,:)      ! INTERPOLATION COEFFICENT
  INTEGER ,ALLOCATABLE :: OBSIDXPC(:,:)      ! INDEX OF EVERY NODE PER CELL
  INTEGER ,ALLOCATABLE :: OBSSTATE(:)        ! NUMBER OF OBSERVATION FOR EVERY STATE
  REAL    ,ALLOCATABLE :: OBSVALUE(:)        ! OBSERVATION VALUE
  REAL    ,ALLOCATABLE :: OBSERROR(:)        ! OBSERVATION ERROR
  REAL    ,ALLOCATABLE :: OBSEINF1(:)        ! OBSERVATION EXTRA INFORMATION 1
  REAL    ,ALLOCATABLE :: OBSEINF2(:)        ! OBSERVATION EXTRA INFORMATION 2
  REAL    ,ALLOCATABLE :: OBSEINF3(:)        ! OBSERVATION EXTRA INFORMATION 3

  ! GPSMET WETDELAY DATA:
  INTEGER, PARAMETER :: MAX_GPS = 5000		! TEMPORARILY HARD CODED  !!changefrom 2000 to 5000 20100525 liu
  INTEGER :: NUM_GPS,I4T_GPS			! I4T_GPS: I4TIME OF Jan 1, 1970
  REAL    :: GPS_XYT(3,MAX_GPS),GPS_ELV(MAX_GPS),GPS_TIM(MAX_GPS), &
             GPS_ERR(MAX_GPS),GPS_TPW(MAX_GPS),GPS_WET(MAX_GPS)
  
! FOR GRID POINT VARIABLE
  REAL    ,ALLOCATABLE :: GRDBKGD0(:,:,:,:,:)! GRID BACKGROUND VALUE
  REAL    ,ALLOCATABLE :: GRDBKGND(:,:,:,:,:)! GRID BACKGROUND VALUE
  REAL    ,ALLOCATABLE :: GRDANALS(:,:,:,:,:)! GRID ANALYSIS VALUE
  REAL    ,ALLOCATABLE :: TMPANALS(:,:,:,:,:)! GRID ANALYSIS VALUE

  REAL    ,ALLOCATABLE :: WWWOUT(:,:,:,:)    ! W COMPONENT FOR OUTPUT
  REAL    ,ALLOCATABLE :: DIFFTOUT(:,:,:,:,:)! GRID ANALYSIS VALUE FOR OUTPUR
  REAL    ,ALLOCATABLE :: Z_MAXGID(:)        ! VERTICAL LEVEL OF FINEST ANALYSIS GRID

  REAL                 :: PNLT0HY            ! INITIAL HYDROSTATIC CONDITION PENALTY COEFFICENT. ADDIED BY ZHONGJIE HE
  REAL                 :: PNLT_HY            ! HYDROSTATIC CONDITION PENALTY COEFFICENT. ADDIED BY ZHONGJIE HE
  REAL                 :: TAUL_HY            ! REDUCTION COEFFICENT OF HYDROSTATIC CONDITION PENALTY TERM, ADDIED BY ZHONGJIE HE
  REAL                 :: ENDHYLV            ! THE GRID LEVEL AFTER WHICH THE HYDROSTATIC CONDITION PENALTY TERM IS OMMITTED. ADDED BY ZHONGJIE HE
  REAL                 :: ENDGSLV            ! THE GRID LEVEL AFTER WHICH THE GEOSTROPHIC BALANCE PENALTY TERM IS OMMITTED. ADDED BY ZHONGJIE HE
  REAL                 :: LIMIT_3            ! THE LIMITATION OF HEIGHT TO DECIDE IN WHICH RANGE THE OBSERVATION IS AVIABLE. ADDED BY ZHONGJIE HE
  REAL                 :: LIMIT_4            ! THE LIMITATION OF TIME TO DECIDE IN WHICH RANGE THE OBSERVATION IS AVIABLE. ADDED BY ZHONGJIE HE

  ! ANALYSIS DOMAIN BY YUANFU XIE:
  INTEGER              :: ITIME2(2)          ! ANALYSIS TIME WINDOW

!RUIXIA LIU ADD 20120321
  REAL    ,ALLOCATABLE :: AMSUA(:,:,:,:)
  REAL    ,ALLOCATABLE :: T_SFC_0(:,:,:)
  REAL    ,ALLOCATABLE :: AMSUAGRD(:,:,:,:)  ! SATELLITE MULTIGRID POSITION
  REAL    ,ALLOCATABLE :: T_SFC_GRD(:,:,:)
  REAL    ,ALLOCATABLE :: P_lyr(:)
  REAL    ,ALLOCATABLE :: ozn_lyr(:)
  REAL    ,ALLOCATABLE :: P_lvl(:)
  REAL    ,ALLOCATABLE :: T_SFC(:,:)
  REAL    ,ALLOCATABLE :: PPP1(:)             ! PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: rad(:,:,:,:)
  REAL    ,ALLOCATABLE :: ja(:,:,:,:,:)
  REAL    ,ALLOCATABLE :: T_lyr(:,:,:)
  REAL    ,ALLOCATABLE :: Q_lyr(:,:,:)
  REAL  :: CMAG
  INTEGER  :: INUM2
  CHARACTER(LEN=100)   :: SAT_DA_USE
  CHARACTER(LEN=200)   :: Co_Path
  CHARACTER(LEN=100)   :: Sat_Data_Path(2)   ! ADD AMSU-B BY YUANFU FEB 2013
  CHARACTER(LEN=100)   :: Moist_Unit(2)   ! ADD FOR AMSU-A/B BY YUANFU FEB 2013
  INTEGER  :: NCHBEG,NCHEND
  INTEGER  :: NAMSUB ! YUANFU ADDED FOR COUNTING NUMBER AMSU-B OBS
  INTEGER  ,ALLOCATABLE  :: AMSUID(:,:)
  INTEGER  :: AMSUA_CHANNELS_USED(15),AMSUB_CHANNELS_USED(5) ! YUANFU ADDED FOR CONTROLING AMSU DATA
  REAL  ,ALLOCATABLE :: T_SFC_BKG0(:,:,:)
  REAL    ,ALLOCATABLE :: T_lyr1(:,:,:)
  REAL    ,ALLOCATABLE :: Q_lyr1(:,:,:)
  REAL    ,ALLOCATABLE ::  T_SFC1(:,:)
  REAL    ,ALLOCATABLE :: PPP2(:)
  REAL OZN_lyr1(41)
  REAL  ,  ALLOCATABLE :: rad1(:,:,:,:)
  REAL    ,ALLOCATABLE :: ja1(:,:,:,:,:)
  REAL  ,  ALLOCATABLE :: RAD_AMSUB(:,:,:,:)
  REAL    ,ALLOCATABLE :: JAC_AMSUB(:,:,:,:,:)
  REAL    ,ALLOCATABLE :: P_lvl1(:)
  REAL    ,ALLOCATABLE :: LND(:,:)
  REAL    ,ALLOCATABLE :: LND0(:,:)
  REAL    ,ALLOCATABLE :: LNDGRD(:,:)
  REAL    ,ALLOCATABLE :: LANDTYPE(:)
  REAL    ,ALLOCATABLE :: LNDTY0(:)
!END RUIXIA LIU ADD 20120321

  ! YUANFU XIE ADDS DATA STRUCTURES FOR SATELLITE DATA:
  TYPE SATELLITE_OBS
    INTEGER :: NUMPRO,NUMCHS  ! NUMBER OF PROFILES AND CHANNELS
    INTEGER, ALLOCATABLE :: GRDIDX(:,:)    ! HORIZONTAL GRID LOCATIONS
    INTEGER, ALLOCATABLE :: LNDCVR(:)      ! LAND COVERAGE: LAND:1 WATER:0
    INTEGER, ALLOCATABLE :: LNDTYP(:)      ! LAND TYPE: CRTM LAND OR WATER TYPE
    REAL, ALLOCATABLE    :: SATVAL(:,:)    ! OBSERVED SATELLITE VALUES: CHANNELS X PROFILES
    REAL, ALLOCATABLE    :: ANGLES(:,:)    ! SCAN & ZENITH ANGLES: 4 X PROFILES 
                                           ! (LOCAL & SOLAR ANGLES)
  END TYPE SATELLITE_OBS

  TYPE(SATELLITE_OBS) :: AMSUB(3)          ! YUANFU ADDED AMSUB FEB 2013, MAX 3 TIME FRAME NOW
  TYPE(SATELLITE_OBS) :: AMSUBM(3)         ! YUANFU ADDED AMSUB FOR A MULTIGRID LEVEL FEB 2013, MAX 3 TIME FRAME NOW

CONTAINS

!=================================================================================
!>
!! THIS ROUTINE INITIALIES A SATELLITE OBSERVATION DATA STRUCTURE.
!! 1. ALLOCATE MEMORY;
!! 2. ASSIGN VALUES.
!!
!! \history \n
!! CREATION: MAR. 2013 \n
!! AUTHOR  : YUANFU XIE AT NOAA/ESRL/GSD
!
!=================================================================================
SUBROUTINE SATOBS_INIT(SAT_OBS,NUM_PRO,NUM_CHS,GRD_IDX,LND_CVR,LND_TYP,SAT_VAL,SAT_ANG)

  IMPLICIT NONE

  INTEGER, INTENT(IN) :: NUM_PRO,NUM_CHS,GRD_IDX(2,NUM_PRO)
  INTEGER, INTENT(IN) :: LND_CVR(NUM_PRO),LND_TYP(NUM_PRO)
  REAL,    INTENT(IN) :: SAT_VAL(NUM_CHS,NUM_PRO),SAT_ANG(4,NUM_PRO)

  TYPE(SATELLITE_OBS) :: SAT_OBS

  ! LOCAL VARIABLES:
  INTEGER :: IP,ISTATUS

  ! ALLOCATE:
  ALLOCATE(SAT_OBS%GRDIDX(2,NUM_PRO),SAT_OBS%LNDCVR(NUM_PRO),SAT_OBS%LNDTYP(NUM_PRO), &
           SAT_OBS%SATVAL(NUM_CHS,NUM_PRO),SAT_OBS%ANGLES(4,NUM_PRO), STAT=ISTATUS)

  SAT_OBS%NUMPRO = NUM_PRO
  SAT_OBS%NUMCHS = NUM_CHS
  
  DO IP=1,NUM_PRO
    SAT_OBS%GRDIDX(:,IP) = GRD_IDX(:,IP)
    SAT_OBS%LNDCVR(IP) = LND_CVR(IP)
    SAT_OBS%LNDTYP(IP) = LND_TYP(IP)
    SAT_OBS%SATVAL(:,IP) = SAT_VAL(:,IP)
    SAT_OBS%ANGLES(:,IP) = SAT_ANG(:,IP)
  ENDDO
  
END SUBROUTINE SATOBS_INIT

!=================================================================================
!>
!! THIS ROUTINE PROJECTS A SATELLITE OBSERVATION DATA STRUCTURE ON TO ONE OVER A
!! FINER RESOLUTION.
!!
!! \HISTORY \N
!! CREATION: MAR. 2013
!!
!! \AUTHOR: YUANFU XIE AT NOAA/ESRL/GSD
!
!=================================================================================
SUBROUTINE SATOBS_PROJ(SATOBS1,SATOBS2,LEVEL,IFLAG)

  IMPLICIT NONE

  INTEGER, INTENT(IN)  :: LEVEL
  INTEGER, INTENT(OUT) :: IFLAG
  TYPE(SATELLITE_OBS), INTENT(IN)  :: SATOBS1
  TYPE(SATELLITE_OBS), INTENT(OUT) :: SATOBS2

    ! LOCAL VARIABLES:
  INTEGER :: IP,ISTATUS,IBASE
  REAL    :: SQRT

  IF (LEVEL .LE. 0) THEN
    IFLAG = 0
    PRINT*,'NO PROJECTION IS NEEDED'
    RETURN
  ENDIF
  IBASE = 2**(LEVEL-1)

  SATOBS2%NUMCHS = SATOBS1%NUMCHS
  SATOBS2%NUMPRO = SATOBS1%NUMPRO ! WORST CASE SCENARIO: PROJECTION HAS ALL OBS

  ! ALLOCATE:
  ALLOCATE(SATOBS2%GRDIDX(2,SATOBS2%NUMPRO),SATOBS2%LNDCVR(SATOBS2%NUMPRO), &
           SATOBS2%LNDTYP(SATOBS2%NUMPRO),SATOBS2%ANGLES(4,SATOBS2%NUMPRO), &
           SATOBS2%SATVAL(SATOBS2%NUMCHS,SATOBS2%NUMPRO), STAT=ISTATUS)

  SATOBS2%NUMPRO = 0
  DO IP=1,SATOBS1%NUMPRO
    IF (MOD(SATOBS1%GRDIDX(1,IP)-1,IBASE) .EQ. 0 .AND. &
        MOD(SATOBS1%GRDIDX(2,IP)-1,IBASE) .EQ. 0) THEN
      SATOBS2%NUMPRO = SATOBS2%NUMPRO + 1

      SATOBS2%GRDIDX(:,SATOBS2%NUMPRO) = (SATOBS1%GRDIDX(:,IP)-1)/(2**(LEVEL-1))+1
      SATOBS2%LNDCVR(SATOBS2%NUMPRO) = SATOBS1%LNDCVR(IP)
      SATOBS2%LNDTYP(SATOBS2%NUMPRO) = SATOBS1%LNDTYP(IP)
      SATOBS2%SATVAL(:,SATOBS2%NUMPRO) = SATOBS1%SATVAL(:,IP)
      SATOBS2%ANGLES(:,SATOBS2%NUMPRO) = SATOBS1%ANGLES(:,IP)
    ENDIF
  ENDDO

  IFLAG = 1

END SUBROUTINE SATOBS_PROJ

!=================================================================================
!>
!! THIS	FOLLOWING ROUTINE IS TO DEALLOCATE A SATELLITE_OBS DATA TYPE VARIABLE.
!!
!! \HISTORY \N
!! CREATION: MAR. 2013 \N
!! \AUTHOR: YUANFU XIE AT NOAA/ESRL
!
!=================================================================================

SUBROUTINE SATOBS_DEAD(SATOBS)

  TYPE(SATELLITE_OBS) :: SATOBS

  ! LOCAL VARIABLES:
  INTEGER :: ISTATUS

  SATOBS%NUMPRO = 0
  SATOBS%NUMCHS = 0

  DEALLOCATE(SATOBS%GRDIDX,SATOBS%LNDCVR,SATOBS%LNDTYP,SATOBS%SATVAL,SATOBS%ANGLES, &
             STAT=ISTATUS)

END SUBROUTINE SATOBS_DEAD

END MODULE PRMTRS_STMAS_CLOUD
