C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.            RAD_ALL.20359 
C                                                                                  RAD_ALL.20360 
C Use, duplication or disclosure of this code is subject to the                    RAD_ALL.20361 
C restrictions as set forth in the contract.                                       RAD_ALL.20362 
C                                                                                  RAD_ALL.20363 
C                Meteorological Office                                             RAD_ALL.20364 
C                London Road                                                       RAD_ALL.20365 
C                BRACKNELL                                                         RAD_ALL.20366 
C                Berkshire UK                                                      RAD_ALL.20367 
C                RG12 2SZ                                                          RAD_ALL.20368 
C                                                                                  RAD_ALL.20369 
C If no contract has been raised with this copy of the code, the use,              RAD_ALL.20370 
C duplication or disclosure of it is strictly prohibited.  Permission              RAD_ALL.20371 
C to do so must first be obtained in writing from the Head of Numerical            RAD_ALL.20372 
C Modelling at the above address.                                                  RAD_ALL.20373 
C ******************************COPYRIGHT******************************            RAD_ALL.20374 
C                                                                                  RAD_ALL.20375 
!+ Subroutine to set moist aerosol properties independent of bands.                RAD_ALL.20376 
!                                                                                  RAD_ALL.20377 
! Method:                                                                          RAD_ALL.20378 
!       The mean relative humidities are calculated and pointers to                RAD_ALL.20379 
!       the lookup tables are set.                                                 RAD_ALL.20380 
!                                                                                  RAD_ALL.20381 
! Current Owner of Code: J. M. Edwards                                             RAD_ALL.20382 
!                                                                                  RAD_ALL.20383 
! History:                                                                         RAD_ALL.20384 
!       Version         Date                    Comment                            RAD_ALL.20385 
!       4.0             27-07-95                Original Code                      RAD_ALL.20386 
!                                               (J. M. Edwards)                    RAD_ALL.20387 
!       4.3             17-12-96                Code extended to permit            RAD_ALL.20388 
!                                               use with both moist                RAD_ALL.20389 
!                                               and dry aerosols.                  RAD_ALL.20390 
!                                               (J. M. Edwards)                    RAD_ALL.20391 
!                                                                                  RAD_ALL.20392 
! Description of Code:                                                             RAD_ALL.20393 
!   FORTRAN 77  with extensions listed in documentation.                           RAD_ALL.20394 
!                                                                                  RAD_ALL.20395 
!- ---------------------------------------------------------------------           RAD_ALL.20396 
      SUBROUTINE SET_MOIST_AEROSOL_PROPERTIES(IERR                                 RAD_ALL.20397 
     &   , N_PROFILE, N_LAYER                                                      RAD_ALL.20398 
     &   , L_LAYER, N_AEROSOL, I_AEROSOL_PARAMETRIZATION, NHUMIDITY                RAD_ALL.20399 
     &   , WATER_MIX_RATIO, T, P, DELTA_HUMIDITY                                   RAD_ALL.20400 
     &   , MEAN_REL_HUMIDITY, I_HUMIDITY_POINTER                                   RAD_ALL.20401 
     &   , NPD_PROFILE, NPD_LAYER, NPD_AEROSOL_SPECIES                             RAD_ALL.20402 
     &   )                                                                         RAD_ALL.20403 
!                                                                                  RAD_ALL.20404 
!                                                                                  RAD_ALL.20405 
!                                                                                  RAD_ALL.20406 
      IMPLICIT NONE                                                                RAD_ALL.20407 
!                                                                                  RAD_ALL.20408 
!                                                                                  RAD_ALL.20409 
!     SIZES OF DUMMY ARRAYS.                                                       RAD_ALL.20410 
      INTEGER   !, INTENT(IN)                                                      RAD_ALL.20411 
     &     NPD_PROFILE                                                             RAD_ALL.20412 
!             MAXIMUM NUMBER OF PROFILES                                           RAD_ALL.20413 
     &   , NPD_LAYER                                                               RAD_ALL.20414 
!             MAXIMUM NUMBER OF LAYERS                                             RAD_ALL.20415 
     &   , NPD_AEROSOL_SPECIES                                                     RAD_ALL.20416 
!             MAXIMUM NUMBER OF AEROSOLS                                           RAD_ALL.20417 
!                                                                                  RAD_ALL.20418 
!     INCLUDE COMDECKS.                                                            RAD_ALL.20419 
!     ------------------------------------------------------------------           ERROR3A.2     
!     COMDECK FOR TWO-STREAM RADIATION CODE.                                       ERROR3A.3     
!                                                                                  ERROR3A.4     
!     MODULE TO SET ERROR FLAGS IN THE RADIATION CODE.                             ERROR3A.5     
!                                                                                  ERROR3A.6     
      INTEGER                                                                      ERROR3A.7     
     &     I_NORMAL                                                                ERROR3A.8     
!             ERROR FREE CONDITION                                                 ERROR3A.9     
     &   , I_ERR_FATAL                                                             ERROR3A.10    
!             FATAL ERROR: IMMEDIATE RETURN                                        ERROR3A.11    
     &   , I_ABORT_CALCULATION                                                     ERROR3A.12    
!             CALCULATION ABORTED                                                  ERROR3A.13    
     &   , I_MISSING_DATA                                                          ERROR3A.14    
!             MISSING DATA ERROR: CONDITIONAL                                      ERROR3A.15    
     &   , I_ERR_IO                                                                ERROR3A.16    
!             I/O ERROR                                                            ERROR3A.17    
     &   , I_ERR_RANGE                                                             ERROR3A.18    
!             INTERPOLATION RANGE ERROR                                            ERROR3A.19    
     &   , I_ERR_EXIST                                                             ERROR3A.20    
!             EXISTENCE ERROR                                                      ERROR3A.21    
!                                                                                  ERROR3A.22    
      PARAMETER(                                                                   ERROR3A.23    
     &     I_NORMAL=0                                                              ERROR3A.24    
     &   , I_ERR_FATAL=1                                                           ERROR3A.25    
     &   , I_ABORT_CALCULATION=2                                                   ERROR3A.26    
     &   , I_MISSING_DATA=3                                                        ERROR3A.27    
     &   , I_ERR_IO=4                                                              ERROR3A.28    
     &   , I_ERR_RANGE=5                                                           ERROR3A.29    
     &   , I_ERR_EXIST=6                                                           ERROR3A.30    
     &   )                                                                         ERROR3A.31    
!                                                                                  ERROR3A.32    
!     ------------------------------------------------------------------           ERROR3A.33    
!     ------------------------------------------------------------------           AERPRM3A.2     
!     COMDECK FOR TWO-STREAM RADIATION CODE.                                       AERPRM3A.3     
!                                                                                  AERPRM3A.4     
!     MODULE TO SET THE AEROSOL PARAMETRIZATIONS.                                  AERPRM3A.5     
!                                                                                  AERPRM3A.6     
      INTEGER                                                                      AERPRM3A.7     
     &     IP_AEROSOL_PARAM_DRY                                                    AERPRM3A.8     
!             PARAMETRIZATION FOR DRY AEROSOLS                                     AERPRM3A.9     
     &   , IP_AEROSOL_PARAM_MOIST                                                  AERPRM3A.10    
!             PARAMETRIZATION FOR MOIST AEROSOLS                                   AERPRM3A.11    
     &   , IP_AEROSOL_UNPARAMETRIZED                                               AERPRM3A.12    
!             OBSERVATIONAL AEROSOL DATA                                           AERPRM3A.13    
!                                                                                  AERPRM3A.14    
      PARAMETER(                                                                   AERPRM3A.15    
     &     IP_AEROSOL_PARAM_DRY=1                                                  AERPRM3A.16    
     &   , IP_AEROSOL_PARAM_MOIST=2                                                AERPRM3A.17    
     &   , IP_AEROSOL_UNPARAMETRIZED=3                                             AERPRM3A.18    
     &   )                                                                         AERPRM3A.19    
!                                                                                  AERPRM3A.20    
!     ------------------------------------------------------------------           AERPRM3A.21    
!     ------------------------------------------------------------------           STDIO3A.2     
!     COMDECK FOR TWO-STREAM RADIATION CODE.                                       STDIO3A.3     
!                                                                                  STDIO3A.4     
!     MODULE TO SET UNIT NUMBERS FOR STANDARD I/O.                                 STDIO3A.5     
!                                                                                  STDIO3A.6     
      INTEGER                                                                      STDIO3A.7     
     &     IU_STDIN                                                                STDIO3A.8     
!             UNIT NUMBER FOR STANDARD INPUT                                       STDIO3A.9     
     &   , IU_STDOUT                                                               STDIO3A.10    
!             UNIT NUMBER FOR STANDARD OUTPUT                                      STDIO3A.11    
     *   , IU_ERR                                                                  STDIO3A.12    
!             UNIT NUMBER FOR ERROR MESSAGES                                       STDIO3A.13    
!                                                                                  STDIO3A.14    
      PARAMETER(                                                                   STDIO3A.15    
     &     IU_STDIN=5                                                              STDIO3A.16    
     &   , IU_STDOUT=6                                                             STDIO3A.17    
     *   , IU_ERR=6                                                                STDIO3A.18    
     &   )                                                                         STDIO3A.19    
!                                                                                  STDIO3A.20    
!     ------------------------------------------------------------------           STDIO3A.21    
!                                                                                  RAD_ALL.20423 
!     DUMMY ARGUMENTS.                                                             RAD_ALL.20424 
      INTEGER   !, INTENT(OUT)                                                     RAD_ALL.20425 
     &     IERR                                                                    RAD_ALL.20426 
!             ERROR FLAG                                                           RAD_ALL.20427 
!                                                                                  RAD_ALL.20428 
      INTEGER   !, INTENT(IN)                                                      RAD_ALL.20429 
     &     N_PROFILE                                                               RAD_ALL.20430 
!             NUMBER OF PROFILES                                                   RAD_ALL.20431 
     &   , N_LAYER                                                                 RAD_ALL.20432 
!             NUMBER OF LAYERS                                                     RAD_ALL.20433 
     &   , N_AEROSOL                                                               RAD_ALL.20434 
!             NUMBER OF AEROSOL SPECIES                                            RAD_ALL.20435 
     &   , I_AEROSOL_PARAMETRIZATION(NPD_AEROSOL_SPECIES)                          RAD_ALL.20436 
!             PARAMETRIZATIONS OF AEROSOL                                          RAD_ALL.20437 
!             SPECIES                                                              RAD_ALL.20438 
     &   , NHUMIDITY(NPD_AEROSOL_SPECIES)                                          RAD_ALL.20439 
!             NUMBER OF HUMIDITY VALUES                                            RAD_ALL.20440 
      INTEGER   !, INTENT(OUT)                                                     RAD_ALL.20441 
     &     I_HUMIDITY_POINTER(NPD_PROFILE, NPD_LAYER)                              RAD_ALL.20442 
!             POINTERS TO LOOK-UP TABLES                                           RAD_ALL.20443 
      LOGICAL   !, INTENT(IN)                                                      RAD_ALL.20444 
     &     L_LAYER                                                                 RAD_ALL.20445 
!             LAYER FLAG                                                           RAD_ALL.20446 
      REAL      !, INTENT(IN)                                                      RAD_ALL.20447 
     &     WATER_MIX_RATIO(NPD_PROFILE, 0: NPD_LAYER)                              RAD_ALL.20448 
!             MIXING RATIO OF WATER VAPOUR                                         RAD_ALL.20449 
     &   , T(NPD_PROFILE, 0: NPD_LAYER)                                            RAD_ALL.20450 
!             TEMPERATURES                                                         RAD_ALL.20451 
     &   , P(NPD_PROFILE, 0: NPD_LAYER)                                            RAD_ALL.20452 
!             PRESSURES                                                            RAD_ALL.20453 
      REAL      !, INTENT(OUT)                                                     RAD_ALL.20454 
     &     MEAN_REL_HUMIDITY(NPD_PROFILE, NPD_LAYER)                               RAD_ALL.20455 
!             MEAN HUMIDITIES OF LAYERS                                            RAD_ALL.20456 
     &   , DELTA_HUMIDITY                                                          RAD_ALL.20457 
!             INCREMENT IN HUMIDITY                                                RAD_ALL.20458 
!                                                                                  RAD_ALL.20459 
!                                                                                  RAD_ALL.20460 
!     LOCAL VARIABLES.                                                             RAD_ALL.20461 
      INTEGER                                                                      RAD_ALL.20462 
     &     I                                                                       RAD_ALL.20463 
!             LOOP VARIABLE                                                        RAD_ALL.20464 
     &   , J                                                                       RAD_ALL.20465 
!             LOOP VARIABLE                                                        RAD_ALL.20466 
     &   , L                                                                       RAD_ALL.20467 
!             LOOP VARIABLE                                                        RAD_ALL.20468 
     &   , NHUMIDITY_COMMON                                                        RAD_ALL.20469 
!             COMMON NUMBER OF HUMIDITIES FOR MOIST AEROSOLS                       RAD_ALL.20470 
      REAL                                                                         RAD_ALL.20471 
     &     MIX_RATIO_SAT(NPD_PROFILE, 0: NPD_LAYER)                                RAD_ALL.20472 
!             SATURATED HUMIDITY MIXING RATIO                                      RAD_ALL.20473 
!                                                                                  RAD_ALL.20474 
!     SUBROUTINES CALLED:                                                          RAD_ALL.20475 
      EXTERNAL                                                                     RAD_ALL.20476 
     &     QSAT_WAT                                                                RAD_ALL.20477 
!                                                                                  RAD_ALL.20478 
!                                                                                  RAD_ALL.20479 
!                                                                                  RAD_ALL.20480 
!     SET UP ARRAY OF POINTERS TO INCLUDE THE EFFECTS OF HUMIDITY.                 RAD_ALL.20481 
!     CALCULATE THE SATURATED MIXING RATIO.                                        RAD_ALL.20482 
      DO I=1, N_LAYER                                                              RAD_ALL.20483 
         CALL QSAT_WAT(MIX_RATIO_SAT(1, I), T(1, I), P(1, I)                       RAD_ALL.20484 
     &      , N_PROFILE)                                                           RAD_ALL.20485 
      ENDDO                                                                        RAD_ALL.20486 
!                                                                                  RAD_ALL.20487 
!     DETERMINE THE NUMBER OF HUMIDITIES TO BE USED FOR MOIST                      RAD_ALL.20488 
!     AEROSOLS. THIS MUST BE THE SAME FOR ALL MOIST AEROSOLS                       RAD_ALL.20489 
!     IN THE CURRENT VERSION OF THE CODE.                                          RAD_ALL.20490 
      NHUMIDITY_COMMON=0                                                           RAD_ALL.20491 
      DO J=1, N_AEROSOL                                                            RAD_ALL.20492 
         IF (I_AEROSOL_PARAMETRIZATION(J).EQ.IP_AEROSOL_PARAM_MOIST)               RAD_ALL.20493 
     &         THEN                                                                RAD_ALL.20494 
            IF (NHUMIDITY(J).GT.0) THEN                                            RAD_ALL.20495 
!              SET THE ACTUAL COMMON VALUE.                                        RAD_ALL.20496 
               IF (NHUMIDITY_COMMON.EQ.0) THEN                                     RAD_ALL.20497 
                  NHUMIDITY_COMMON=NHUMIDITY(J)                                    RAD_ALL.20498 
               ELSE IF (NHUMIDITY(J).NE.NHUMIDITY_COMMON) THEN                     RAD_ALL.20499 
!                 THERE IS AN INCONSISTENCY.                                       RAD_ALL.20500 
                  WRITE(IU_ERR, '(/A)')                                            RAD_ALL.20501 
     &               '***ERROR: THE LOOK-UP TABLES FOR MOIST AEROSOLS '            RAD_ALL.20502 
     &               , 'ARE OF DIFFERENT SIZES. THIS IS NOT PERMITTED.'            RAD_ALL.20503 
                  IERR=I_ERR_FATAL                                                 RAD_ALL.20504 
                  RETURN                                                           RAD_ALL.20505 
               ENDIF                                                               RAD_ALL.20506 
            ENDIF                                                                  RAD_ALL.20507 
         ENDIF                                                                     RAD_ALL.20508 
      ENDDO                                                                        RAD_ALL.20509 
!     THE LOOK-UP TABLE IS ASSUMED TO BE UNIFORM IN HUMIDITY.                      RAD_ALL.20510 
      DELTA_HUMIDITY=1.0E+00/(REAL(NHUMIDITY_COMMON)-1.0E+00)                      RAD_ALL.20511 
      DO I=1, N_LAYER                                                              RAD_ALL.20512 
         DO L=1, N_PROFILE                                                         RAD_ALL.20513 
            MEAN_REL_HUMIDITY(L, I)                                                RAD_ALL.20514 
     &         =WATER_MIX_RATIO(L, I)*(1.0E+00-MIX_RATIO_SAT(L, I))                RAD_ALL.20515 
     &         /((1.0E+00-WATER_MIX_RATIO(L, I))*MIX_RATIO_SAT(L, I))              RAD_ALL.20516 
!           CHECK THAT THE MEAN RELATIVE HUMIDITY                                  RAD_ALL.20517 
!           DOES NOT EXCEED OR EQUAL 1.0.                                          RAD_ALL.20518 
            MEAN_REL_HUMIDITY(L, I)=MIN(MEAN_REL_HUMIDITY(L, I)                    RAD_ALL.20519 
     &        , 0.99999)                                                           RAD_ALL.20520 
            I_HUMIDITY_POINTER(L, I)=1                                             RAD_ALL.20521 
     &         +INT(MEAN_REL_HUMIDITY(L, I)*(NHUMIDITY_COMMON-1))                  RAD_ALL.20522 
         ENDDO                                                                     RAD_ALL.20523 
      ENDDO                                                                        RAD_ALL.20524 
!                                                                                  RAD_ALL.20525 
!                                                                                  RAD_ALL.20526 
!                                                                                  RAD_ALL.20527 
                                                                                   RAD_ALL.20528 
      RETURN                                                                       RAD_ALL.20529 
      END        
