LCOV - code coverage report
Current view: top level - physics/cosp2/src/src - cosp.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 679 2313 29.4 %
Date: 2025-03-13 19:12:29 Functions: 3 9 33.3 %

          Line data    Source code
       1             : ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       2             : ! Copyright (c) 2015, Regents of the University of Colorado
       3             : ! All rights reserved.
       4             : !
       5             : ! Redistribution and use in source and binary forms, with or without modification, are
       6             : ! permitted provided that the following conditions are met:
       7             : !
       8             : ! 1. Redistributions of source code must retain the above copyright notice, this list of
       9             : !    conditions and the following disclaimer.
      10             : !
      11             : ! 2. Redistributions in binary form must reproduce the above copyright notice, this list
      12             : !    of conditions and the following disclaimer in the documentation and/or other
      13             : !    materials provided with the distribution.
      14             : !
      15             : ! 3. Neither the name of the copyright holder nor the names of its contributors may be
      16             : !    used to endorse or promote products derived from this software without specific prior
      17             : !    written permission.
      18             : !
      19             : ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
      20             : ! EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      21             : ! MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
      22             : ! THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      23             : ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
      24             : ! OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      25             : ! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      26             : ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      27             : ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      28             : !
      29             : ! History:
      30             : ! May 2015- D. Swales - Original version
      31             : ! Mar 2018- R. Guzman - Added OPAQ diagnostics and GLID simulator
      32             : ! Apr 2018- R. Guzman - Added ATLID simulator
      33             : !
      34             : ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      35             : 
      36             : 
      37             : MODULE MOD_COSP
      38             :   USE COSP_KINDS,                  ONLY: wp
      39             :   USE MOD_COSP_CONFIG,             ONLY: R_UNDEF,PARASOL_NREFL,LIDAR_NCAT,LIDAR_NTYPE, SR_BINS,&
      40             :                                          N_HYDRO,RTTOV_MAX_CHANNELS,numMISRHgtBins,      &
      41             :                                          cloudsat_DBZE_BINS,LIDAR_NTEMP,calipso_histBsct,&
      42             :                                          use_vgrid,Nlvgrid,vgrid_zu,vgrid_zl,vgrid_z,    &
      43             :                                          numMODISTauBins,numMODISPresBins,               &
      44             :                                          numMODISReffIceBins,numMODISReffLiqBins,        &
      45             :                                          numISCCPTauBins,numISCCPPresBins,numMISRTauBins,&
      46             :                                          ntau,modis_histTau,tau_binBounds,               &
      47             :                                          modis_histTauEdges,tau_binEdges,nCloudsatPrecipClass,&
      48             :                                          modis_histTauCenters,tau_binCenters,            &
      49             :                                          cloudsat_preclvl,grLidar532_histBsct,atlid_histBsct
      50             :   USE MOD_COSP_MODIS_INTERFACE,      ONLY: cosp_modis_init,       modis_IN
      51             :   USE MOD_COSP_RTTOV_INTERFACE,      ONLY: cosp_rttov_init,       rttov_IN
      52             :   USE MOD_COSP_MISR_INTERFACE,       ONLY: cosp_misr_init,        misr_IN
      53             :   USE MOD_COSP_ISCCP_INTERFACE,      ONLY: cosp_isccp_init,       isccp_IN
      54             :   USE MOD_COSP_CALIPSO_INTERFACE,    ONLY: cosp_calipso_init,     calipso_IN
      55             :   USE MOD_COSP_ATLID_INTERFACE,      ONLY: cosp_atlid_init,       atlid_IN 
      56             :   USE MOD_COSP_GRLIDAR532_INTERFACE, ONLY: cosp_grLidar532_init, grLidar532_IN
      57             :   USE MOD_COSP_PARASOL_INTERFACE,    ONLY: cosp_parasol_init,     parasol_in
      58             :   USE MOD_COSP_CLOUDSAT_INTERFACE,   ONLY: cosp_cloudsat_init,    cloudsat_IN
      59             :   USE quickbeam,                     ONLY: quickbeam_subcolumn,   quickbeam_column, radar_cfg
      60             :   USE MOD_ICARUS,                    ONLY: icarus_subcolumn,      icarus_column
      61             :   USE MOD_MISR_SIMULATOR,            ONLY: misr_subcolumn,        misr_column
      62             :   USE MOD_LIDAR_SIMULATOR,           ONLY: lidar_subcolumn,       lidar_column
      63             :   USE MOD_MODIS_SIM,                 ONLY: modis_subcolumn,       modis_column
      64             :   USE MOD_PARASOL,                   ONLY: parasol_subcolumn,     parasol_column
      65             :   use mod_cosp_rttov,                ONLY: rttov_column
      66             :   USE MOD_COSP_STATS,                ONLY: COSP_LIDAR_ONLY_CLOUD,COSP_CHANGE_VERTICAL_GRID
      67             : 
      68             :   IMPLICIT NONE
      69             : 
      70             :   logical :: linitialization ! Initialization flag
      71             : 
      72             :   ! ######################################################################################
      73             :   ! TYPE cosp_column_inputs
      74             :   ! ######################################################################################
      75             :   type cosp_column_inputs
      76             :      integer :: &
      77             :           Npoints,             & ! Number of gridpoints.
      78             :           Ncolumns,            & ! Number of columns.
      79             :           Nlevels                ! Number of levels.
      80             : 
      81             :      integer,allocatable,dimension(:) :: &
      82             :           sunlit                 ! Sunlit flag                            (0-1)
      83             : 
      84             :      real(wp),allocatable,dimension(:,:) :: &
      85             :           at,                  & ! Temperature                            (K)
      86             :           pfull,               & ! Pressure                               (Pa)
      87             :           phalf,               & ! Pressure at half-levels                (Pa)
      88             :           qv,                  & ! Specific humidity                      (kg/kg)
      89             :           hgt_matrix,          & ! Height of hydrometeors                 (km)
      90             :           hgt_matrix_half        ! Height of hydrometeors at half levels  (km)
      91             : 
      92             :      real(wp),allocatable,dimension(:) :: &
      93             :           land,                & ! Land/Sea mask                          (0-1)
      94             :           skt,                 & ! Surface temperature                    (K)
      95             :           surfelev               ! Surface Elevation                      (m)
      96             :      ! Fields used ONLY by RTTOV
      97             :      integer :: &
      98             :           month                  ! Month for surface emissivty atlas      (1-12)
      99             :      real(wp) :: &
     100             :           zenang,              & ! Satellite zenith angle for RTTOV       (deg)
     101             :           co2,                 & ! CO2                                    (kg/kg)
     102             :           ch4,                 & ! Methane                                (kg/kg)
     103             :           n2o,                 & ! N2O                                    (kg/kg)
     104             :           co                     ! CO                                     (kg/kg)
     105             :      real(wp),allocatable,dimension(:) :: &
     106             :           emis_sfc,            & ! Surface emissivity                     (1)
     107             :           u_sfc,               & ! Surface u-wind                         (m/s)
     108             :           v_sfc,               & ! Surface v-wind                         (m/s)
     109             :           seaice,              & ! Sea-ice fraction                       (0-1)
     110             :           lat,                 & ! Latitude                              (deg)
     111             :           lon                    ! Longitude                              (deg)
     112             :      real(wp),allocatable,dimension(:,:) :: &
     113             :           o3,                  & ! Ozone                                  (kg/kg)
     114             :           tca,                 & ! Total column cloud fraction            (0-1)
     115             :           cloudIce,            & ! Cloud ice water mixing ratio           (kg/kg)
     116             :           cloudLiq,            & ! Cloud liquid water mixing ratio        (kg/kg)
     117             :           fl_rain,             & ! Precipitation (rain) flux              (kg/m2/s)
     118             :           fl_snow                ! Precipitation (snow) flux              (kg/m2/s)
     119             :   end type cosp_column_inputs
     120             : 
     121             :   ! ######################################################################################
     122             :   ! TYPE cosp_optical_inputs
     123             :   ! ######################################################################################
     124             :   type cosp_optical_inputs
     125             :      integer :: &
     126             :           Npoints,             & ! Number of gridpoints.
     127             :           Ncolumns,            & ! Number of columns.
     128             :           Nlevels,             & ! Number of levels.
     129             :           Npart,               & ! Number of cloud meteors for LIDAR simulators.
     130             :           Nrefl                  ! Number of reflectances for PARASOL simulator
     131             :      real(wp) :: &
     132             :           emsfc_lw               ! Surface emissivity @ 11micron
     133             :      real(wp),allocatable,dimension(:,:,:) :: &
     134             :           frac_out,            & ! Cloud fraction
     135             :           tau_067,             & ! Optical depth @ 0.67micron
     136             :           emiss_11,            & ! Emissivity @ 11 micron
     137             :           fracLiq,             & ! Fraction of optical-depth due to liquid (MODIS)
     138             :           asym,                & ! Assymetry parameter @ 3.7micron (MODIS)
     139             :           ss_alb,              & ! Single-scattering albedo @ 3.7micron (MODIS)
     140             :           betatot_calipso,     & ! Lidar backscatter coefficient (calipso @ 532nm)
     141             :           betatot_grLidar532,  & ! Lidar backscatter coefficient (ground-lidar @ 532nm)
     142             :           betatot_atlid,       & ! Lidar backscatter coefficient (atlid @ 355nm)
     143             :           betatot_ice_calipso, & ! Lidar backscatter coefficient ICE (calipso @ 532nm)
     144             :           betatot_liq_calipso, & ! Lidar backscatter coefficient LIQUID (calipso @ 532nm)
     145             :           tautot_calipso,      & ! Lidar Optical thickness (calipso @ 532nm)
     146             :           tautot_grLidar532,   & ! Lidar Optical thickness (ground-lidar @ 532nm)  
     147             :           tautot_atlid,        & ! Lidar Optical thickness (atlid @ 355nm)
     148             :           tautot_ice_calipso,  & ! Lidar Ice Optical thickness (calipso @ 532nm)
     149             :           tautot_liq_calipso,  & ! Lidar Liquid Optical thickness (calipso @ 532nm)
     150             :           z_vol_cloudsat,      & ! Effective reflectivity factor (mm^6/m^3)
     151             :           kr_vol_cloudsat,     & ! Attenuation coefficient hydro (dB/km) 
     152             :           g_vol_cloudsat         ! Attenuation coefficient gases (dB/km)
     153             :      real(wp),allocatable,dimension(:,:) :: &
     154             :           beta_mol_calipso,    & ! Lidar molecular backscatter coefficient (calipso @ 532nm)
     155             :           beta_mol_grLidar532, & ! Lidar molecular backscatter coefficient (ground-lidar @ 532nm) 
     156             :           beta_mol_atlid,      & ! Lidar molecular backscatter coefficient (atlid @ 355nm)
     157             :           tau_mol_calipso,     & ! Lidar molecular optical depth (calipso @ 532nm)
     158             :           tau_mol_grLidar532,  & ! Lidar molecular optical depth (ground-lidar @ 532nm) 
     159             :           tau_mol_atlid,       & ! Lidar molecular optical depth (atlid @ 355nm)
     160             :           tautot_S_liq,        & ! Parasol Liquid water optical thickness, from TOA to SFC
     161             :           tautot_S_ice,        & ! Parasol Ice water optical thickness, from TOA to SFC
     162             :           fracPrecipIce          ! Fraction of precipitation which is frozen (1).
     163             :      type(radar_cfg) :: &
     164             :           rcfg_cloudsat          ! Radar configuration information (CLOUDSAT)
     165             :   end type cosp_optical_inputs
     166             : 
     167             :   ! ######################################################################################
     168             :   ! TYPE cosp_outputs
     169             :   ! ######################################################################################
     170             :   type cosp_outputs
     171             : 
     172             :      ! CALIPSO outputs
     173             :      real(wp),dimension(:,:,:),pointer :: &
     174             :           calipso_betaperp_tot => null(),  & ! Total backscattered signal
     175             :           calipso_beta_tot => null(),      & ! Total backscattered signal
     176             :           calipso_tau_tot => null(),       & ! Optical thickness integrated from top to level z
     177             :           calipso_lidarcldphase => null(), & ! 3D "lidar" phase cloud fraction
     178             :           calipso_lidarcldtype => null(),  & ! 3D "lidar" OPAQ type fraction
     179             :           calipso_cldlayerphase => null(), & ! low, mid, high-level lidar phase cloud cover
     180             :           calipso_lidarcldtmp => null(),   & ! 3D "lidar" phase cloud temperature
     181             :           calipso_cfad_sr => null()          ! CFAD of scattering ratio
     182             :      real(wp), dimension(:,:),pointer :: &
     183             :           calipso_lidarcld => null(),      & ! 3D "lidar" cloud fraction 
     184             :           calipso_cldlayer => null(),      & ! low, mid, high-level, total lidar cloud cover
     185             :           calipso_cldtype => null(),       & ! opaque and thin lidar cloud cover + z_opaque altitude
     186             :           calipso_cldtypetemp => null(),   & ! opaque and thin cloud temperature  
     187             :           calipso_cldtypemeanz => null(),  & ! opaque and thin cloud altitude 
     188             :           calipso_cldtypemeanzse => null(),& ! same as just above with respect to SE
     189             :           calipso_beta_mol => null(),      & ! Molecular backscatter
     190             :           calipso_temp_tot => null()
     191             :      real(wp), dimension(:),pointer :: &
     192             :           calipso_cldthinemis => null(),   & ! thin cloud emissivity 
     193             :           calipso_srbval => null()           ! SR bins in cfad_sr
     194             : 
     195             :      ! GROUND LIDAR outputs
     196             :      real(wp),dimension(:,:,:),pointer :: &  
     197             :           grLidar532_beta_tot => null(),   & ! Total GROUND LIDAR backscattered signal 
     198             :           grLidar532_cfad_sr => null()       ! CFAD of GROUND LIDAR scattering ratio 
     199             :      real(wp), dimension(:,:),pointer :: &  
     200             :           grLidar532_lidarcld => null(),   & ! 3D GROUND "lidar" cloud fraction  
     201             :           grLidar532_cldlayer => null(),   & ! low, mid, high-level, total GROUND lidar cloud cover
     202             :           grLidar532_beta_mol => null()      ! GROUND LIDAR Molecular backscatter 
     203             :      real(wp), dimension(:),pointer :: &  
     204             :           grLidar532_srbval => null()        ! SR bins in cfad_sr
     205             : 
     206             :      ! ATLID outputs
     207             :      real(wp),dimension(:,:,:),pointer :: & 
     208             :           atlid_beta_tot => null(),   & ! Total ATLID backscattered signal 
     209             :           atlid_cfad_sr => null()       ! CFAD of ATLID scattering ratio 
     210             :      real(wp), dimension(:,:),pointer :: & 
     211             :           atlid_lidarcld => null(),   & ! 3D ATLID cloud fraction
     212             :           atlid_cldlayer => null(),   & ! low, mid, high-level, total ATLID cloud cover 
     213             :           atlid_beta_mol => null()      ! ATLID Molecular backscatter 
     214             :      real(wp), dimension(:),pointer :: & 
     215             :           atlid_srbval => null()        ! SR bins in cfad_sr
     216             : 
     217             : 
     218             :      ! PARASOL outputs
     219             :      real(wp),dimension(:,:,:),pointer :: &
     220             :           parasolPix_refl => null()            ! PARASOL reflectances (subcolumn)
     221             :      real(wp),dimension(:,:),pointer :: &
     222             :           parasolGrid_refl => null()           ! PARASOOL reflectances (column)
     223             : 
     224             :      ! CLOUDSAT outputs
     225             :      real(wp),dimension(:,:,:),pointer :: &
     226             :           cloudsat_Ze_tot => null(),         & ! Effective reflectivity factor (Npoints,Ncolumns,Nlevels)
     227             :           cloudsat_cfad_ze => null()           ! Ze CFAD(Npoints,dBZe_bins,Nlevels)
     228             :      real(wp), dimension(:,:),pointer :: &
     229             :           lidar_only_freq_cloud => null(),   & ! (Npoints,Nlevels)
     230             :           cloudsat_precip_cover => null()      ! Radar total cloud amount by CloudSat precip flag (Npoints,dBZe_bins)
     231             :      real(wp),dimension(:),pointer :: &
     232             :           cloudsat_tcc => null(),             &
     233             :           cloudsat_tcc2 => null(),            &          
     234             :           radar_lidar_tcc => null(),         & ! Radar&lidar total cloud amount, grid-box scale (Npoints)
     235             :           cloudsat_pia => null()               ! Radar path integrated attenuation (Npoints)
     236             :           
     237             :      ! ISCCP outputs       
     238             :      real(wp),dimension(:),pointer :: &
     239             :           isccp_totalcldarea => null(), & ! The fraction of model grid box columns with cloud
     240             :                                           ! somewhere in them. (%)
     241             :           isccp_meantb => null(),       & ! Mean all-sky 10.5 micron brightness temperature. (K)
     242             :           isccp_meantbclr => null(),    & ! Mean clear-sky 10.5 micron brightness temperature. (K)
     243             :           isccp_meanptop => null(),     & ! Mean cloud top pressure (mb).
     244             :           isccp_meantaucld => null(),   & ! Mean optical thickness. (1)
     245             :           isccp_meanalbedocld => null()   ! Mean cloud albedo. (1)
     246             :      real(wp),dimension(:,:),pointer ::&
     247             :           isccp_boxtau => null(),       & ! Optical thickness in each column. (1)
     248             :           isccp_boxptop => null()         ! Cloud top pressure in each column. (mb)
     249             :      real(wp),dimension(:,:,:),pointer :: &
     250             :           isccp_fq  => null()             ! The fraction of the model grid box covered by each of
     251             :                                           ! the 49 ISCCP D level cloud types. (%)
     252             : 
     253             :      ! MISR outptus
     254             :      real(wp),dimension(:,:,:),pointer ::   & !
     255             :           misr_fq => null()          ! Fraction of the model grid box covered by each of the MISR
     256             :                            ! cloud types
     257             :      real(wp),dimension(:,:),pointer ::   & !
     258             :           misr_dist_model_layertops => null() !
     259             :      real(wp),dimension(:),pointer ::   & !
     260             :           misr_meanztop => null(), & ! Mean MISR cloud top height
     261             :           misr_cldarea => null()     ! Mean MISR cloud cover area
     262             : 
     263             :      ! MODIS outptus
     264             :      real(wp),pointer,dimension(:) ::      & !
     265             :           modis_Cloud_Fraction_Total_Mean => null(),       & ! L3 MODIS retrieved cloud fraction (total)
     266             :           modis_Cloud_Fraction_Water_Mean => null(),       & ! L3 MODIS retrieved cloud fraction (liq)
     267             :           modis_Cloud_Fraction_Ice_Mean => null(),         & ! L3 MODIS retrieved cloud fraction (ice)
     268             :           modis_Cloud_Fraction_High_Mean => null(),        & ! L3 MODIS retrieved cloud fraction (high)
     269             :           modis_Cloud_Fraction_Mid_Mean => null(),         & ! L3 MODIS retrieved cloud fraction (middle)
     270             :           modis_Cloud_Fraction_Low_Mean => null(),         & ! L3 MODIS retrieved cloud fraction (low )
     271             :           modis_Optical_Thickness_Total_Mean => null(),    & ! L3 MODIS retrieved optical thickness (tot)
     272             :           modis_Optical_Thickness_Water_Mean => null(),    & ! L3 MODIS retrieved optical thickness (liq)
     273             :           modis_Optical_Thickness_Ice_Mean => null(),      & ! L3 MODIS retrieved optical thickness (ice)
     274             :           modis_Optical_Thickness_Total_LogMean => null(), & ! L3 MODIS retrieved log10 optical thickness
     275             :           modis_Optical_Thickness_Water_LogMean => null(), & ! L3 MODIS retrieved log10 optical thickness
     276             :           modis_Optical_Thickness_Ice_LogMean => null(),   & ! L3 MODIS retrieved log10 optical thickness
     277             :           modis_Cloud_Particle_Size_Water_Mean => null(),  & ! L3 MODIS retrieved particle size (liquid)
     278             :           modis_Cloud_Particle_Size_Ice_Mean => null(),    & ! L3 MODIS retrieved particle size (ice)
     279             :           modis_Cloud_Top_Pressure_Total_Mean => null(),   & ! L3 MODIS retrieved cloud top pressure
     280             :           modis_Liquid_Water_Path_Mean => null(),          & ! L3 MODIS retrieved liquid water path
     281             :           modis_Ice_Water_Path_Mean => null()                ! L3 MODIS retrieved ice water path
     282             :      real(wp),pointer,dimension(:,:,:) ::  &
     283             :           modis_Optical_Thickness_vs_Cloud_Top_Pressure => null(), & ! Tau/Pressure joint histogram
     284             :           modis_Optical_Thickness_vs_ReffICE => null(),            & ! Tau/ReffICE joint histogram
     285             :           modis_Optical_Thickness_vs_ReffLIQ => null()               ! Tau/ReffLIQ joint histogram
     286             : 
     287             :      ! RTTOV outputs
     288             :      real(wp),pointer :: &
     289             :           rttov_tbs(:,:) => null() ! Brightness Temperature
     290             : 
     291             :   end type cosp_outputs
     292             : 
     293             : CONTAINS
     294             :   ! ######################################################################################
     295             :   ! FUNCTION cosp_simulator
     296             :   ! ######################################################################################
     297       18576 :   function COSP_SIMULATOR(cospIN,cospgridIN,cospOUT,start_idx,stop_idx,debug)
     298             :     type(cosp_optical_inputs),intent(in),target :: cospIN     ! Optical inputs to COSP simulator
     299             :     type(cosp_column_inputs), intent(in),target :: cospgridIN ! Host model inputs to COSP
     300             : 
     301             :     ! Inputs into the simulators
     302             :     type(isccp_IN)    :: isccpIN    ! Input to the ISCCP simulator
     303             :     type(misr_IN)     :: misrIN     ! Input to the LIDAR simulator
     304             :     type(calipso_IN)  :: calipsoIN  ! Input to the LIDAR simulator
     305             :     type(grLidar532_IN) :: grLidar532IN ! Input to the GROUND LIDAR simulator
     306             :     type(atlid_IN)    :: atlidIN    ! Input to the ATLID simulator 
     307             :     type(parasol_IN)  :: parasolIN  ! Input to the PARASOL simulator
     308             :     type(cloudsat_IN) :: cloudsatIN ! Input to the CLOUDSAT radar simulator
     309        9288 :     type(modis_IN)    :: modisIN    ! Input to the MODIS simulator
     310             :     type(rttov_IN)    :: rttovIN    ! Input to the RTTOV simulator
     311             :     integer,optional  :: start_idx,stop_idx
     312             :     logical,optional  :: debug
     313             : 
     314             :     ! Outputs from the simulators (nested simulator output structure)
     315             :     type(cosp_outputs), intent(inout) :: cospOUT
     316             :     character(len=256),dimension(100) :: cosp_simulator
     317             : 
     318             :     ! Local variables
     319             :     integer :: &
     320             :          i,icol,ij,ik,nError
     321             :     integer,target :: &
     322             :          Npoints
     323             :     logical :: &
     324             :          Lisccp_subcolumn,     & ! On/Off switch for subcolumn ISCCP simulator
     325             :          Lmisr_subcolumn,      & ! On/Off switch for subcolumn MISR simulator
     326             :          Lcalipso_subcolumn,   & ! On/Off switch for subcolumn CALIPSO simulator
     327             :          LgrLidar532_subcolumn,& ! On/Off switch for subcolumn GROUND LIDAR simulator
     328             :          Latlid_subcolumn,     & ! On/Off switch for subcolumn ATLID simulator
     329             :          Lparasol_subcolumn,   & ! On/Off switch for subcolumn PARASOL simulator
     330             :          Lcloudsat_subcolumn,  & ! On/Off switch for subcolumn CLOUDSAT simulator
     331             :          Lmodis_subcolumn,     & ! On/Off switch for subcolumn MODIS simulator
     332             :          Lrttov_subcolumn,     & ! On/Off switch for subcolumn RTTOV simulator
     333             :          Lisccp_column,        & ! On/Off switch for column ISCCP simulator
     334             :          Lmisr_column,         & ! On/Off switch for column MISR simulator
     335             :          Lcalipso_column,      & ! On/Off switch for column CALIPSO simulator
     336             :          LgrLidar532_column,   & ! On/Off switch for column GROUND LIDAR simulator
     337             :          Latlid_column,        & ! On/Off switch for column ATLID simulator
     338             :          Lparasol_column,      & ! On/Off switch for column PARASOL simulator
     339             :          Lcloudsat_column,     & ! On/Off switch for column CLOUDSAT simulator
     340             :          Lmodis_column,        & ! On/Off switch for column MODIS simulator
     341             :          Lrttov_column,        & ! On/Off switch for column RTTOV simulator (not used)
     342             :          Lradar_lidar_tcc,     & ! On/Off switch from joint Calipso/Cloudsat product
     343             :          Lcloudsat_tcc,       & !
     344             :          Lcloudsat_tcc2,      & !         
     345             :          Llidar_only_freq_cloud  ! On/Off switch from joint Calipso/Cloudsat product
     346             :     logical :: &
     347             :          ok_lidar_cfad    = .false., &
     348             :          ok_lidar_cfad_grLidar532 = .false., & 
     349             :          ok_lidar_cfad_atlid = .false., &
     350             :          lrttov_cleanUp   = .false.
     351             :     
     352             :     integer, dimension(:,:),allocatable  :: &
     353        9288 :          modisRetrievedPhase,isccpLEVMATCH
     354             :     real(wp), dimension(:),  allocatable  :: &
     355        9288 :          modisCfTotal,modisCfLiquid,modisMeanIceWaterPath, isccp_meantbclr,     &
     356        9288 :          modisCfIce, modisCfHigh, modisCfMid, modisCfLow,modisMeanTauTotal,     &
     357        9288 :          modisMeanTauLiquid, modisMeanTauIce, modisMeanLogTauTotal,             &
     358        9288 :          modisMeanLogTauLiquid, modisMeanLogTauIce, modisMeanSizeLiquid,        &
     359        9288 :          modisMeanSizeIce, modisMeanCloudTopPressure, modisMeanLiquidWaterPath, &
     360        9288 :          radar_lidar_tcc, cloudsat_tcc, cloudsat_tcc2
     361             :     REAL(WP), dimension(:,:),allocatable  :: &
     362        9288 :          modisRetrievedCloudTopPressure,modisRetrievedTau,modisRetrievedSize,   &
     363        9288 :          misr_boxtau,misr_boxztop,misr_dist_model_layertops,isccp_boxtau,       &
     364        9288 :          isccp_boxttop,isccp_boxptop,calipso_beta_mol,lidar_only_freq_cloud,    &
     365        9288 :          grLidar532_beta_mol,atlid_beta_mol 
     366             :     REAL(WP), dimension(:,:,:),allocatable :: &
     367        9288 :          modisJointHistogram,modisJointHistogramIce,modisJointHistogramLiq,     &
     368        9288 :          calipso_beta_tot,calipso_betaperp_tot, cloudsatDBZe,parasolPix_refl,   &
     369        9288 :          grLidar532_beta_tot,atlid_beta_tot,cloudsatZe_non
     370             :     real(wp),dimension(:),allocatable,target :: &
     371        9288 :          out1D_1,out1D_2,out1D_3,out1D_4,out1D_5,out1D_6,out1D_7,out1D_8,       &
     372        9288 :          out1D_9,out1D_10,out1D_11,out1D_12 
     373             :     real(wp),dimension(:,:,:),allocatable :: &
     374        9288 :        betamol_in,betamoli,pnormi,ze_toti,ze_noni
     375             : 
     376             :     ! Initialize error reporting for output
     377      938088 :     cosp_simulator(:)=''
     378             : 
     379             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     380             :     ! 1) Determine if using full inputs or subset
     381             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     382        9288 :     if (present(start_idx) .and. present(stop_idx)) then
     383        9288 :        ij=start_idx
     384        9288 :        ik=stop_idx
     385             :     else
     386           0 :        ij=1
     387           0 :        ik=cospIN%Npoints
     388             :     endif
     389        9288 :     Npoints = ik-ij+1
     390             : 
     391             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     392             :     ! 2a) Determine which simulators to run and which statistics to compute
     393             :     !    - If any of the subcolumn fields are allocated, then run the subcolumn simulators.
     394             :     !    - If any of the column fields are allocated, then compute the statistics for that
     395             :     !      simulator, but only save the requested fields.
     396             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     397             :     ! Start with all simulators and joint-diagnostics off
     398        9288 :     Lisccp_subcolumn    = .false.
     399        9288 :     Lmisr_subcolumn     = .false.
     400        9288 :     Lcalipso_subcolumn  = .false.
     401        9288 :     LgrLidar532_subcolumn = .false.
     402        9288 :     Latlid_subcolumn    = .false. 
     403        9288 :     Lparasol_subcolumn  = .false.
     404        9288 :     Lcloudsat_subcolumn = .false.
     405        9288 :     Lmodis_subcolumn    = .false.
     406        9288 :     Lrttov_subcolumn    = .false.
     407        9288 :     Lisccp_column       = .false.
     408        9288 :     Lmisr_column        = .false.
     409        9288 :     Lcalipso_column     = .false.
     410        9288 :     LgrLidar532_column = .false.
     411        9288 :     Latlid_column       = .false.
     412        9288 :     Lparasol_column     = .false.
     413        9288 :     Lcloudsat_column    = .false.
     414        9288 :     Lmodis_column       = .false.
     415        9288 :     Lrttov_column       = .false.
     416        9288 :     Lradar_lidar_tcc    = .false.
     417        9288 :     Llidar_only_freq_cloud = .false.
     418        9288 :     Lcloudsat_tcc       = .false.
     419        9288 :     Lcloudsat_tcc2      = .false.
     420             : 
     421             :     ! CLOUDSAT subcolumn
     422        9288 :     if (associated(cospOUT%cloudsat_Ze_tot)) Lcloudsat_subcolumn = .true.
     423             : 
     424             :     ! MODIS subcolumn
     425             :     if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean)                .or.          &
     426             :         associated(cospOUT%modis_Cloud_Fraction_Total_Mean)                .or.          &
     427             :         associated(cospOUT%modis_Cloud_Fraction_Ice_Mean)                  .or.          &
     428             :         associated(cospOUT%modis_Cloud_Fraction_High_Mean)                 .or.          &
     429             :         associated(cospOUT%modis_Cloud_Fraction_Mid_Mean)                  .or.          &
     430             :         associated(cospOUT%modis_Cloud_Fraction_Low_Mean)                  .or.          &
     431             :         associated(cospOUT%modis_Optical_Thickness_Total_Mean)             .or.          &
     432             :         associated(cospOUT%modis_Optical_Thickness_Water_Mean)             .or.          &
     433             :         associated(cospOUT%modis_Optical_Thickness_Ice_Mean)               .or.          &
     434             :         associated(cospOUT%modis_Optical_Thickness_Total_LogMean)          .or.          &
     435             :         associated(cospOUT%modis_Optical_Thickness_Water_LogMean)          .or.          &
     436             :         associated(cospOUT%modis_Optical_Thickness_Ice_LogMean)            .or.          &
     437             :         associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean)           .or.          &
     438             :         associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean)             .or.          &
     439             :         associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean)            .or.          &
     440             :         associated(cospOUT%modis_Liquid_Water_Path_Mean)                   .or.          &
     441        9288 :         associated(cospOUT%modis_Ice_Water_Path_Mean)                      .or.          &
     442             :         associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))               &
     443        9288 :        Lmodis_subcolumn    = .true.
     444             : 
     445             :     ! ISCCP subcolumn
     446        9288 :     if (associated(cospOUT%isccp_boxtau)                                   .or.          &
     447             :         associated(cospOUT%isccp_boxptop))                                               &
     448        9288 :        Lisccp_subcolumn    = .true.
     449             : 
     450             :     ! MISR subcolumn
     451        9288 :     if (associated(cospOUT%misr_dist_model_layertops))                                   &
     452        9288 :        Lmisr_subcolumn     = .true.
     453             : 
     454             :     ! CALIPOSO subcolumn
     455             :     if (associated(cospOUT%calipso_tau_tot)                                .or.          &
     456             :         associated(cospOUT%calipso_beta_mol)                               .or.          &
     457             :         associated(cospOUT%calipso_temp_tot)                               .or.          &
     458        9288 :         associated(cospOUT%calipso_betaperp_tot)                           .or.          &
     459             :         associated(cospOUT%calipso_beta_tot))                                            &
     460        9288 :        Lcalipso_subcolumn  = .true.
     461             : 
     462             :     ! GROUND LIDAR subcolumn 
     463        9288 :     if (associated(cospOUT%grLidar532_beta_mol)                           .or.          &
     464             :         associated(cospOUT%grLidar532_beta_tot))                                        &
     465           0 :        LgrLidar532_subcolumn  = .true. 
     466             : 
     467             :     ! ATLID subcolumn
     468        9288 :     if (associated(cospOUT%atlid_beta_mol)                                 .or.          & 
     469             :         associated(cospOUT%atlid_beta_tot))                                              &
     470           0 :        Latlid_subcolumn  = .true.  
     471             : 
     472             :     ! PARASOL subcolumn
     473        9288 :     if (associated(cospOUT%parasolPix_refl))                                             &
     474        9288 :        Lparasol_subcolumn  = .true.
     475             : 
     476             :     ! RTTOV column
     477        9288 :     if (associated(cospOUT%rttov_tbs))                                                   &
     478           0 :        Lrttov_column    = .true.
     479             : 
     480             :     ! Set flag to deallocate rttov types (only done on final call to simulator)
     481        9288 :     if (size(cospOUT%isccp_meantb) .eq. stop_idx) lrttov_cleanUp = .true.
     482             : 
     483             :     ! ISCCP column
     484             :     if (associated(cospOUT%isccp_fq)                                       .or.          &
     485             :         associated(cospOUT%isccp_meanalbedocld)                            .or.          &
     486             :         associated(cospOUT%isccp_meanptop)                                 .or.          &
     487             :         associated(cospOUT%isccp_meantaucld)                               .or.          &
     488        9288 :         associated(cospOUT%isccp_totalcldarea)                             .or.          &
     489             :         associated(cospOUT%isccp_meantb)) then
     490        9288 :        Lisccp_column    = .true.
     491        9288 :        Lisccp_subcolumn = .true.
     492             :     endif
     493             : 
     494             :     ! MISR column
     495             :     if (associated(cospOUT%misr_cldarea)                                   .or.          &
     496        9288 :         associated(cospOUT%misr_meanztop)                                  .or.          &
     497             :         associated(cospOUT%misr_fq)) then
     498        9288 :        Lmisr_column    = .true.
     499        9288 :        Lmisr_subcolumn = .true.
     500             :     endif
     501             : 
     502             :     ! CALIPSO column
     503             :     if (associated(cospOUT%calipso_cfad_sr)                                .or.          &
     504             :         associated(cospOUT%calipso_lidarcld)                               .or.          &
     505             :         associated(cospOUT%calipso_lidarcldphase)                          .or.          &
     506             :         associated(cospOUT%calipso_lidarcldtype)                           .or.          &
     507             :         associated(cospOUT%calipso_cldlayer)                               .or.          &
     508             :         associated(cospOUT%calipso_cldtype)                                .or.          & 
     509             :         associated(cospOUT%calipso_cldtypetemp)                            .or.          & 
     510             :         associated(cospOUT%calipso_cldtypemeanz)                           .or.          & 
     511             :         associated(cospOUT%calipso_cldtypemeanzse)                         .or.          & 
     512             :         associated(cospOUT%calipso_cldthinemis)                            .or.          &
     513        9288 :         associated(cospOUT%calipso_cldlayerphase)                          .or.          &
     514             :         associated(cospOUT%calipso_lidarcldtmp)) then
     515        9288 :        Lcalipso_column    = .true.
     516        9288 :        Lcalipso_subcolumn = .true.
     517             :     endif
     518             : 
     519             :     ! GROUND LIDAR column 
     520             :     if (associated(cospOUT%grLidar532_cfad_sr)                            .or.          & 
     521        9288 :         associated(cospOUT%grLidar532_lidarcld)                           .or.          & 
     522             :         associated(cospOUT%grLidar532_cldlayer)) then 
     523           0 :        LgrLidar532_column    = .true. 
     524           0 :        LgrLidar532_subcolumn = .true. 
     525             :     endif
     526             : 
     527             :     ! ATLID column 
     528             :     if (associated(cospOUT%atlid_cfad_sr)                                  .or.          & 
     529        9288 :         associated(cospOUT%atlid_lidarcld)                                 .or.          & 
     530             :         associated(cospOUT%atlid_cldlayer)) then  
     531           0 :        Latlid_column    = .true. 
     532           0 :        Latlid_subcolumn = .true.
     533             :     endif
     534             : 
     535             :     ! PARASOL column
     536        9288 :     if (associated(cospOUT%parasolGrid_refl)) then
     537        9288 :        Lparasol_column    = .true.
     538        9288 :        Lparasol_subcolumn = .true.
     539             :     endif
     540             : 
     541             :     ! CLOUDSAT column
     542        9288 :     if (associated(cospOUT%cloudsat_cfad_ze)) then
     543        9288 :        Lcloudsat_column    = .true.
     544        9288 :        Lcloudsat_subcolumn = .true.
     545             :     endif
     546             : 
     547             :     ! MODIS column
     548             :     if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean)                .or.          &
     549             :         associated(cospOUT%modis_Cloud_Fraction_Water_Mean)                .or.          &
     550             :         associated(cospOUT%modis_Cloud_Fraction_Ice_Mean)                  .or.          &
     551             :         associated(cospOUT%modis_Cloud_Fraction_High_Mean)                 .or.          &
     552             :         associated(cospOUT%modis_Cloud_Fraction_Mid_Mean)                  .or.          &
     553             :         associated(cospOUT%modis_Cloud_Fraction_Low_Mean)                  .or.          &
     554             :         associated(cospOUT%modis_Optical_Thickness_Total_Mean)             .or.          &
     555             :         associated(cospOUT%modis_Optical_Thickness_Water_Mean)             .or.          &
     556             :         associated(cospOUT%modis_Optical_Thickness_Ice_Mean)               .or.          &
     557             :         associated(cospOUT%modis_Optical_Thickness_Total_LogMean)          .or.          &
     558             :         associated(cospOUT%modis_Optical_Thickness_Water_LogMean)          .or.          &
     559             :         associated(cospOUT%modis_Optical_Thickness_Ice_LogMean)            .or.          &
     560             :         associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean)           .or.          &
     561             :         associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean)             .or.          &
     562             :         associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean)            .or.          &
     563             :         associated(cospOUT%modis_Liquid_Water_Path_Mean)                   .or.          &
     564        9288 :         associated(cospOUT%modis_Ice_Water_Path_Mean)                      .or.          &
     565             :         associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure)) then
     566        9288 :        Lmodis_column    = .true.
     567        9288 :        Lmodis_subcolumn = .true.
     568             :     endif
     569             : 
     570             :     ! Joint simulator products
     571             :     if (associated(cospOUT%lidar_only_freq_cloud) .or. associated(cospOUT%radar_lidar_tcc) .or. &
     572        9288 :         associated(cospOUT%cloudsat_tcc) .or. associated(cospOUT%cloudsat_tcc2)) then
     573        9288 :        Lcalipso_column     = .true.
     574        9288 :        Lcalipso_subcolumn  = .true.
     575        9288 :        Lcloudsat_column    = .true.
     576        9288 :        Lcloudsat_subcolumn = .true.
     577        9288 :        Lradar_lidar_tcc    = .true.
     578        9288 :        Llidar_only_freq_cloud = .true.
     579        9288 :        Lcloudsat_tcc       = .true.
     580        9288 :        Lcloudsat_tcc2      = .true.
     581             :     endif
     582             : 
     583             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     584             :     ! 2b) Error Checking
     585             :     !     Enforce bounds on input fields. If input field is out-of-bounds, report error
     586             :     !     and turn off simulator
     587             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     588             :     call cosp_errorCheck(cospgridIN, cospIN, Lisccp_subcolumn, Lisccp_column,            &
     589             :          Lmisr_subcolumn, Lmisr_column, Lmodis_subcolumn, Lmodis_column,                 &
     590             :          Lcloudsat_subcolumn, Lcloudsat_column, Lcalipso_subcolumn, Lcalipso_column,     &
     591             :          Latlid_subcolumn, Latlid_column, LgrLidar532_subcolumn, LgrLidar532_column,     &
     592             :          Lrttov_subcolumn, Lrttov_column, Lparasol_subcolumn, Lparasol_column,           &
     593             :          Lradar_lidar_tcc, Llidar_only_freq_cloud, Lcloudsat_tcc,Lcloudsat_tcc2, cospOUT,&
     594        9288 :          cosp_simulator, nError)
     595             : 
     596             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     597             :     ! 3) Populate instrument simulator inputs
     598             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     599        9288 :     if (Lisccp_subcolumn .or. Lmodis_subcolumn) then
     600        9288 :        isccpIN%Npoints  => Npoints
     601        9288 :        isccpIN%Ncolumns => cospIN%Ncolumns
     602        9288 :        isccpIN%Nlevels  => cospIN%Nlevels
     603        9288 :        isccpIN%emsfc_lw => cospIN%emsfc_lw
     604        9288 :        isccpIN%skt      => cospgridIN%skt
     605        9288 :        isccpIN%qv       => cospgridIN%qv
     606        9288 :        isccpIN%at       => cospgridIN%at
     607        9288 :        isccpIN%frac_out => cospIN%frac_out
     608        9288 :        isccpIN%dtau     => cospIN%tau_067
     609        9288 :        isccpIN%dem      => cospIN%emiss_11
     610        9288 :        isccpIN%phalf    => cospgridIN%phalf
     611        9288 :        isccpIN%sunlit   => cospgridIN%sunlit
     612        9288 :        isccpIN%pfull    => cospgridIN%pfull
     613             :     endif
     614             : 
     615        9288 :     if (Lmisr_subcolumn) then
     616        9288 :        misrIN%Npoints  => Npoints
     617        9288 :        misrIN%Ncolumns => cospIN%Ncolumns
     618        9288 :        misrIN%Nlevels  => cospIN%Nlevels
     619        9288 :        misrIN%dtau     => cospIN%tau_067
     620        9288 :        misrIN%sunlit   => cospgridIN%sunlit
     621        9288 :        misrIN%zfull    => cospgridIN%hgt_matrix
     622        9288 :        misrIN%at       => cospgridIN%at
     623             :     endif
     624             : 
     625        9288 :     if (Lcalipso_subcolumn) then
     626        9288 :        calipsoIN%Npoints     => Npoints
     627        9288 :        calipsoIN%Ncolumns    => cospIN%Ncolumns
     628        9288 :        calipsoIN%Nlevels     => cospIN%Nlevels
     629        9288 :        calipsoIN%beta_mol    => cospIN%beta_mol_calipso
     630        9288 :        calipsoIN%betatot     => cospIN%betatot_calipso
     631        9288 :        calipsoIN%betatot_liq => cospIN%betatot_liq_calipso
     632        9288 :        calipsoIN%betatot_ice => cospIN%betatot_ice_calipso
     633        9288 :        calipsoIN%tau_mol     => cospIN%tau_mol_calipso
     634        9288 :        calipsoIN%tautot      => cospIN%tautot_calipso
     635        9288 :        calipsoIN%tautot_liq  => cospIN%tautot_liq_calipso
     636        9288 :        calipsoIN%tautot_ice  => cospIN%tautot_ice_calipso
     637             :     endif
     638             : 
     639        9288 :     if (LgrLidar532_subcolumn) then 
     640           0 :        grLidar532IN%Npoints  => Npoints
     641           0 :        grLidar532IN%Ncolumns => cospIN%Ncolumns 
     642           0 :        grLidar532IN%Nlevels  => cospIN%Nlevels
     643           0 :        grLidar532IN%beta_mol => cospIN%beta_mol_grLidar532 
     644           0 :        grLidar532IN%betatot  => cospIN%betatot_grLidar532 
     645           0 :        grLidar532IN%tau_mol  => cospIN%tau_mol_grLidar532 
     646           0 :        grLidar532IN%tautot   => cospIN%tautot_grLidar532  
     647             :     endif
     648             :     
     649        9288 :     if (Latlid_subcolumn) then 
     650           0 :        atlidIN%Npoints        => Npoints 
     651           0 :        atlidIN%Ncolumns       => cospIN%Ncolumns 
     652           0 :        atlidIN%Nlevels        => cospIN%Nlevels 
     653           0 :        atlidIN%beta_mol_atlid => cospIN%beta_mol_atlid
     654           0 :        atlidIN%betatot_atlid  => cospIN%betatot_atlid 
     655           0 :        atlidIN%tau_mol_atlid  => cospIN%tau_mol_atlid 
     656           0 :        atlidIN%tautot_atlid   => cospIN%tautot_atlid 
     657             :     endif 
     658             :     
     659        9288 :     if (Lparasol_subcolumn) then
     660        9288 :        parasolIN%Npoints      => Npoints
     661        9288 :        parasolIN%Nlevels      => cospIN%Nlevels
     662        9288 :        parasolIN%Ncolumns     => cospIN%Ncolumns
     663        9288 :        parasolIN%Nrefl        => cospIN%Nrefl
     664        9288 :        parasolIN%tautot_S_liq => cospIN%tautot_S_liq
     665        9288 :        parasolIN%tautot_S_ice => cospIN%tautot_S_ice
     666             :     endif
     667             : 
     668        9288 :     if (Lcloudsat_subcolumn) then
     669        9288 :        cloudsatIN%Npoints    => Npoints
     670        9288 :        cloudsatIN%Nlevels    => cospIN%Nlevels
     671        9288 :        cloudsatIN%Ncolumns   => cospIN%Ncolumns
     672        9288 :        cloudsatIN%z_vol      => cospIN%z_vol_cloudsat
     673        9288 :        cloudsatIN%kr_vol     => cospIN%kr_vol_cloudsat
     674        9288 :        cloudsatIN%g_vol      => cospIN%g_vol_cloudsat
     675        9288 :        cloudsatIN%rcfg       => cospIN%rcfg_cloudsat
     676        9288 :        cloudsatIN%hgt_matrix => cospgridIN%hgt_matrix
     677             :     endif
     678             : 
     679        9288 :     if (Lmodis_subcolumn) then
     680        9288 :        modisIN%Ncolumns  => cospIN%Ncolumns
     681        9288 :        modisIN%Nlevels   => cospIN%Nlevels
     682        9288 :        modisIN%Npoints   => Npoints
     683        9288 :        modisIN%liqFrac   => cospIN%fracLiq
     684        9288 :        modisIN%tau       => cospIN%tau_067
     685        9288 :        modisIN%g         => cospIN%asym
     686        9288 :        modisIN%w0        => cospIN%ss_alb
     687      155088 :        modisIN%Nsunlit   = count(cospgridIN%sunlit > 0)
     688        9288 :        if (modisIN%Nsunlit .gt. 0) then
     689       29166 :           allocate(modisIN%sunlit(modisIN%Nsunlit),modisIN%pres(modisIN%Nsunlit,cospIN%Nlevels+1))
     690      384929 :           modisIN%sunlit    = pack((/ (i, i = 1, Npoints ) /),mask = cospgridIN%sunlit > 0)
     691     6692307 :           modisIN%pres      = cospgridIN%phalf(int(modisIN%sunlit(:)),:)
     692             :        endif
     693      155088 :        if (count(cospgridIN%sunlit <= 0) .gt. 0) then
     694       90925 :           allocate(modisIN%notSunlit(count(cospgridIN%sunlit <= 0)))
     695      384485 :           modisIN%notSunlit = pack((/ (i, i = 1, Npoints ) /),mask = .not. cospgridIN%sunlit > 0)
     696             :        endif
     697             :     endif
     698             : 
     699        9288 :     if (Lrttov_column) then
     700           0 :        rttovIN%nPoints    => Npoints
     701           0 :        rttovIN%nLevels    => cospIN%nLevels
     702           0 :        rttovIN%nSubCols   => cospIN%nColumns
     703           0 :        rttovIN%zenang     => cospgridIN%zenang
     704           0 :        rttovIN%co2        => cospgridIN%co2
     705           0 :        rttovIN%ch4        => cospgridIN%ch4
     706           0 :        rttovIN%n2o        => cospgridIN%n2o
     707           0 :        rttovIN%co         => cospgridIN%co
     708           0 :        rttovIN%surfem     => cospgridIN%emis_sfc
     709           0 :        rttovIN%h_surf     => cospgridIN%hgt_matrix_half(:,cospIN%Nlevels+1)
     710           0 :        rttovIN%u_surf     => cospgridIN%u_sfc
     711           0 :        rttovIN%v_surf     => cospgridIN%v_sfc
     712           0 :        rttovIN%t_skin     => cospgridIN%skt
     713           0 :        rttovIN%p_surf     => cospgridIN%phalf(:,cospIN%Nlevels+1)
     714           0 :        rttovIN%q2m        => cospgridIN%qv(:,cospIN%Nlevels)
     715           0 :        rttovIN%t2m        => cospgridIN%at(:,cospIN%Nlevels)
     716           0 :        rttovIN%lsmask     => cospgridIN%land
     717           0 :        rttovIN%latitude   => cospgridIN%lat
     718           0 :        rttovIN%longitude  => cospgridIN%lon
     719           0 :        rttovIN%seaice     => cospgridIN%seaice
     720           0 :        rttovIN%p          => cospgridIN%pfull
     721           0 :        rttovIN%ph         => cospgridIN%phalf
     722           0 :        rttovIN%t          => cospgridIN%at
     723           0 :        rttovIN%q          => cospgridIN%qv
     724           0 :        rttovIN%o3         => cospgridIN%o3
     725             :        ! Below only needed for all-sky RTTOV calculation
     726           0 :        rttovIN%month      => cospgridIN%month
     727           0 :        rttovIN%tca        => cospgridIN%tca
     728           0 :        rttovIN%cldIce     => cospgridIN%cloudIce
     729           0 :        rttovIN%cldLiq     => cospgridIN%cloudLiq
     730           0 :        rttovIN%fl_rain    => cospgridIN%fl_rain
     731           0 :        rttovIN%fl_snow    => cospgridIN%fl_snow
     732             :     endif
     733             : 
     734             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     735             :     ! 4) Call subcolumn simulators
     736             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     737             : 
     738             :     ! ISCCP (icarus) subcolumn simulator
     739        9288 :     if (Lisccp_subcolumn .or. Lmodis_subcolumn) then
     740             :        ! Allocate space for local variables
     741             :        allocate(isccpLEVMATCH(Npoints,isccpIN%Ncolumns),                                 &
     742             :                 isccp_boxttop(Npoints,isccpIN%Ncolumns),                                 &
     743             :                 isccp_boxptop(Npoints,isccpIN%Ncolumns),                                 &
     744      120744 :                 isccp_boxtau(Npoints,isccpIN%Ncolumns), isccp_meantbclr(Npoints))
     745             :        ! Call simulator
     746             :        call icarus_subcolumn(isccpIN%npoints,isccpIN%ncolumns,isccpIN%nlevels,           &
     747             :                              isccpIN%sunlit,isccpIN%dtau,isccpIN%dem,isccpIN%skt,        &
     748             :                              isccpIN%emsfc_lw,isccpIN%qv,isccpIN%at,isccpIN%pfull,       &
     749             :                              isccpIN%phalf,isccpIN%frac_out,isccpLEVMATCH,               &
     750             :                              isccp_boxtau(:,:),isccp_boxptop(:,:),                       &
     751        9288 :                              isccp_boxttop(:,:),isccp_meantbclr(:))
     752             :        ! Store output (if requested)
     753        9288 :        if (associated(cospOUT%isccp_boxtau)) then
     754     1560168 :           cospOUT%isccp_boxtau(ij:ik,:)  = isccp_boxtau
     755             :        endif
     756        9288 :        if (associated(cospOUT%isccp_boxptop)) then
     757     1560168 :           cospOUT%isccp_boxptop(ij:ik,:) = isccp_boxptop
     758             :        endif
     759        9288 :        if (associated(cospOUT%isccp_meantbclr)) then
     760      155088 :           cospOUT%isccp_meantbclr(ij:ik) = isccp_meantbclr
     761             :        endif
     762             :    endif
     763             : 
     764             :    ! MISR subcolumn simulator
     765        9288 :     if (Lmisr_subcolumn) then
     766             :        ! Allocate space for local variables
     767             :        allocate(misr_boxztop(Npoints,misrIN%Ncolumns),                                   &
     768             :                 misr_boxtau(Npoints,misrIN%Ncolumns),                                    &
     769       74304 :                 misr_dist_model_layertops(Npoints,numMISRHgtBins))
     770             :        ! Call simulator
     771             :        call misr_subcolumn(misrIN%Npoints,misrIN%Ncolumns,misrIN%Nlevels,misrIN%dtau,    &
     772             :                            misrIN%zfull,misrIN%at,misrIN%sunlit,misr_boxtau,             &
     773        9288 :                            misr_dist_model_layertops,misr_boxztop)
     774             :        ! Store output (if requested)
     775        9288 :        if (associated(cospOUT%misr_dist_model_layertops)) then
     776     2490696 :           cospOUT%misr_dist_model_layertops(ij:ik,:) = misr_dist_model_layertops
     777             :        endif
     778             :     endif
     779             : 
     780             :     ! Calipso subcolumn simulator
     781        9288 :     if (Lcalipso_subcolumn) then
     782             :        ! Allocate space for local variables
     783           0 :        allocate(calipso_beta_mol(calipsoIN%Npoints,calipsoIN%Nlevels),                   &
     784           0 :                 calipso_beta_tot(calipsoIN%Npoints,calipsoIN%Ncolumns,calipsoIN%Nlevels),&
     785      102168 :                 calipso_betaperp_tot(calipsoIN%Npoints,calipsoIN%Ncolumns,calipsoIN%Nlevels))
     786             :        ! Call simulator
     787             :        call lidar_subcolumn(calipsoIN%npoints, calipsoIN%ncolumns, calipsoIN%nlevels, .false., &
     788             :             calipsoIN%beta_mol, calipsoIN%tau_mol, calipsoIN%betatot, calipsoIN%tautot,  &
     789             :             calipso_beta_mol(:,:), calipso_beta_tot(:,:,:), calipsoIN%betatot_ice,       &
     790             :             calipsoIN%tautot_ice, calipsoIN%betatot_liq, calipsoIN%tautot_liq,           &
     791        9288 :             calipso_betaperp_tot(:,:,:))
     792             :        ! Store output (if requested)
     793        9288 :        if (associated(cospOUT%calipso_beta_mol))                                         &
     794    13036680 :             cospOUT%calipso_beta_mol(ij:ik,calipsoIN%Nlevels:1:-1) = calipso_beta_mol
     795        9288 :        if (associated(cospOUT%calipso_beta_tot))                                         &
     796   131063400 :             cospOUT%calipso_beta_tot(ij:ik,:,calipsoIN%Nlevels:1:-1) = calipso_beta_tot
     797        9288 :        if (associated(cospOUT%calipso_betaperp_tot))                                     &
     798   131063400 :             cospOUT%calipso_betaperp_tot(ij:ik,:,:) = calipso_betaperp_tot
     799             :     endif
     800             : 
     801             :     ! GROUND LIDAR subcolumn simulator 
     802        9288 :     if (LgrLidar532_subcolumn) then  
     803             :        ! Allocate space for local variables  
     804           0 :        allocate(grLidar532_beta_mol(grLidar532IN%Npoints,grLidar532IN%Nlevels),       &  
     805           0 :                 grLidar532_beta_tot(grLidar532IN%Npoints,grLidar532IN%Ncolumns,grLidar532IN%Nlevels))
     806             :        ! Call simulator  
     807             :        call lidar_subcolumn(grLidar532IN%npoints, grLidar532IN%ncolumns, grLidar532IN%nlevels,&
     808             :             .true., grLidar532IN%beta_mol, grLidar532IN%tau_mol, grLidar532IN%betatot,&
     809           0 :             grLidar532IN%tautot, grLidar532_beta_mol(:,:), grLidar532_beta_tot(:,:,:))
     810             :        ! Store output (if requested) 
     811           0 :        if (associated(cospOUT%grLidar532_beta_mol))                                      & 
     812           0 :             cospOUT%grLidar532_beta_mol(ij:ik,grLidar532IN%Nlevels:1:-1) = grLidar532_beta_mol 
     813           0 :        if (associated(cospOUT%grLidar532_beta_tot))                                         & 
     814           0 :             cospOUT%grLidar532_beta_tot(ij:ik,:,grLidar532IN%Nlevels:1:-1) = grLidar532_beta_tot 
     815             :     endif 
     816             : 
     817             :     ! ATLID subcolumn simulator
     818        9288 :     if (Latlid_subcolumn) then
     819             :        ! Allocate space for local variables
     820           0 :        allocate(atlid_beta_mol(atlidIN%Npoints,atlidIN%Nlevels),                      & 
     821           0 :                 atlid_beta_tot(atlidIN%Npoints,atlidIN%Ncolumns,atlidIN%Nlevels)) 
     822             :        ! Call simulator 
     823             :        call lidar_subcolumn(atlidIN%npoints, atlidIN%ncolumns, atlidIN%nlevels,&
     824             :             .false., atlidIN%beta_mol_atlid, atlidIN%tau_mol_atlid, atlidIN%betatot_atlid,&
     825           0 :             atlidIN%tautot_atlid, atlid_beta_mol(:,:), atlid_beta_tot(:,:,:))
     826             :        ! Store output (if requested)
     827           0 :        if (associated(cospOUT%atlid_beta_mol))                                        & 
     828           0 :             cospOUT%atlid_beta_mol(ij:ik,atlidIN%Nlevels:1:-1) = atlid_beta_mol 
     829           0 :        if (associated(cospOUT%atlid_beta_tot))                                        &
     830           0 :             cospOUT%atlid_beta_tot(ij:ik,:,atlidIN%Nlevels:1:-1) = atlid_beta_tot   
     831             :     endif
     832             : 
     833             :     ! PARASOL subcolumn simulator
     834        9288 :     if (Lparasol_subcolumn) then
     835             :        ! Allocate space for local variables
     836       46440 :        allocate(parasolPix_refl(parasolIN%Npoints,parasolIN%Ncolumns,PARASOL_NREFL))
     837             :        ! Call simulator
     838      102168 :        do icol=1,parasolIN%Ncolumns
     839             :           call parasol_subcolumn(parasolIN%npoints, PARASOL_NREFL,                       &
     840       92880 :                                  parasolIN%tautot_S_liq(1:parasolIN%Npoints,icol),       &
     841       92880 :                                  parasolIN%tautot_S_ice(1:parasolIN%Npoints,icol),       &
     842    15787440 :                                  parasolPix_refl(:,icol,1:PARASOL_NREFL))
     843             :           ! Store output (if requested)
     844      102168 :           if (associated(cospOUT%parasolPix_refl)) then
     845       92880 :              cospOUT%parasolPix_refl(ij:ik,icol,1:PARASOL_NREFL) =                          &
     846     7940160 :                   parasolPix_refl(:,icol,1:PARASOL_NREFL)
     847             :           endif
     848             :        enddo
     849             :     endif
     850             : 
     851             :     ! Cloudsat (quickbeam) subcolumn simulator
     852        9288 :     if (Lcloudsat_subcolumn) then
     853             :        ! Allocate space for local variables
     854           0 :        allocate(cloudsatDBZe(cloudsatIN%Npoints,cloudsatIN%Ncolumns,cloudsatIN%Nlevels), &
     855       74304 :                 cloudsatZe_non(cloudsatIN%Npoints,cloudsatIN%Ncolumns,cloudsatIN%Nlevels))
     856      102168 :        do icol=1,cloudsatIN%ncolumns
     857             :           call quickbeam_subcolumn(cloudsatIN%rcfg,cloudsatIN%Npoints,cloudsatIN%Nlevels,&
     858             :                                    cloudsatIN%hgt_matrix/1000._wp,                       &
     859           0 :                                    cloudsatIN%z_vol(:,icol,:),                           &
     860           0 :                                    cloudsatIN%kr_vol(:,icol,:),                          &
     861   781745688 :                                    cloudsatIN%g_vol(:,1,:),cloudsatDBze(:,icol,:),cloudsatZe_non(:,icol,:))
     862             :        enddo
     863             :        ! Store output (if requested)
     864        9288 :        if (associated(cospOUT%cloudsat_Ze_tot)) then
     865   131063400 :           cospOUT%cloudsat_Ze_tot(ij:ik,:,:) = cloudsatDBZe(:,:,1:cloudsatIN%Nlevels)
     866             :        endif
     867             :     endif
     868             : 
     869        9288 :     if (Lmodis_subcolumn) then
     870        9288 :        if(modisiN%nSunlit > 0) then
     871             :           ! Allocate space for local variables
     872           0 :           allocate(modisRetrievedTau(modisIN%nSunlit,modisIN%nColumns),                  &
     873           0 :                    modisRetrievedSize(modisIN%nSunlit,modisIN%nColumns),                 &
     874           0 :                    modisRetrievedPhase(modisIN%nSunlit,modisIN%nColumns),                &
     875       53471 :                    modisRetrievedCloudTopPressure(modisIN%nSunlit,modisIN%nColumns))
     876             :           ! Call simulator
     877       77761 :           do i = 1, modisIN%nSunlit
     878           0 :              call modis_subcolumn(modisIN%Ncolumns,modisIN%Nlevels,modisIN%pres(i,:),    &
     879           0 :                                   modisIN%tau(int(modisIN%sunlit(i)),:,:),               &
     880           0 :                                   modisIN%liqFrac(int(modisIN%sunlit(i)),:,:),           &
     881           0 :                                   modisIN%g(int(modisIN%sunlit(i)),:,:),                 &
     882           0 :                                   modisIN%w0(int(modisIN%sunlit(i)),:,:),                &
     883           0 :                                   isccp_boxptop(int(modisIN%sunlit(i)),:),               &
     884      145714 :                                   modisRetrievedPhase(i,:),                              &
     885      145714 :                                   modisRetrievedCloudTopPressure(i,:),                   &
     886   282557994 :                                   modisRetrievedTau(i,:),modisRetrievedSize(i,:))
     887             :           end do
     888             :        endif
     889             :     endif
     890             : 
     891             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     892             :     ! 5) Call column simulators
     893             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     894             : 
     895             :     ! ISCCP
     896        9288 :     if (Lisccp_column) then
     897             :        ! Check to see which outputs are requested. If not requested, use a local dummy array
     898        9288 :        if(.not. associated(cospOUT%isccp_meanalbedocld)) then
     899           0 :           allocate(out1D_1(Npoints))
     900           0 :           cospOUT%isccp_meanalbedocld(ij:ik) => out1D_1
     901             :        endif
     902        9288 :        if(.not. associated(cospOUT%isccp_meanptop)) then
     903           0 :           allocate(out1D_2(Npoints))
     904           0 :           cospOUT%isccp_meanptop(ij:ik) => out1D_2
     905             :        endif
     906        9288 :        if(.not. associated(cospOUT%isccp_meantaucld)) then
     907           0 :           allocate(out1D_3(Npoints))
     908           0 :           cospOUT%isccp_meantaucld(ij:ik) => out1D_3
     909             :        endif
     910        9288 :        if(.not. associated(cospOUT%isccp_totalcldarea)) then
     911           0 :           allocate(out1D_4(Npoints))
     912           0 :           cospOUT%isccp_totalcldarea(ij:ik) => out1D_4
     913             :        endif
     914        9288 :        if(.not. associated(cospOUT%isccp_meantb)) then
     915           0 :           allocate(out1D_5(Npoints))
     916           0 :           cospOUT%isccp_meantb(ij:ik) => out1D_5
     917             :        endif
     918        9288 :        if(.not. associated(cospOUT%isccp_fq)) then
     919           0 :           allocate(out1D_6(Npoints*numISCCPTauBins*numISCCPPresBins))
     920           0 :           cospOUT%isccp_fq(ij:ik,1:numISCCPTauBins,1:numISCCPPresBins) => out1D_6
     921             :        endif
     922             : 
     923             :        ! Call simulator
     924             :        call icarus_column(isccpIN%npoints, isccpIN%ncolumns,isccp_boxtau(:,:),           &
     925             :                           isccp_boxptop(:,:)/100._wp, isccpIN%sunlit,isccp_boxttop,      &
     926           0 :                           cospOUT%isccp_fq(ij:ik,:,:),                                   &
     927           0 :                           cospOUT%isccp_meanalbedocld(ij:ik),                            &
     928           0 :                           cospOUT%isccp_meanptop(ij:ik),cospOUT%isccp_meantaucld(ij:ik), &
     929     1560168 :                           cospOUT%isccp_totalcldarea(ij:ik),cospOUT%isccp_meantb(ij:ik))
     930    15347232 :        cospOUT%isccp_fq(ij:ik,:,:) = cospOUT%isccp_fq(ij:ik,:,7:1:-1)
     931             : 
     932             :        ! Check if there is any value slightly greater than 1
     933             :        where ((cospOUT%isccp_totalcldarea > 1.0-1.e-5) .and.                             &
     934      155088 :               (cospOUT%isccp_totalcldarea < 1.0+1.e-5))
     935             :               cospOUT%isccp_totalcldarea = 1.0
     936             :        endwhere
     937             : 
     938             :        ! Clear up memory (if necessary)
     939        9288 :        if (allocated(isccp_boxttop))   deallocate(isccp_boxttop)
     940        9288 :        if (allocated(isccp_boxptop))   deallocate(isccp_boxptop)
     941        9288 :        if (allocated(isccp_boxtau))    deallocate(isccp_boxtau)
     942        9288 :        if (allocated(isccp_meantbclr)) deallocate(isccp_meantbclr)
     943        9288 :        if (allocated(isccpLEVMATCH))   deallocate(isccpLEVMATCH)
     944        9288 :        if (allocated(out1D_1)) then
     945           0 :           deallocate(out1D_1)
     946           0 :           nullify(cospOUT%isccp_meanalbedocld)
     947             :        endif
     948        9288 :        if (allocated(out1D_2)) then
     949           0 :           deallocate(out1D_2)
     950           0 :           nullify(cospOUT%isccp_meanptop)
     951             :        endif
     952        9288 :        if (allocated(out1D_3)) then
     953           0 :           deallocate(out1D_3)
     954           0 :           nullify(cospOUT%isccp_meantaucld)
     955             :        endif
     956        9288 :        if (allocated(out1D_4)) then
     957           0 :           deallocate(out1D_4)
     958           0 :           nullify(cospOUT%isccp_totalcldarea)
     959             :        endif
     960        9288 :        if (allocated(out1D_5)) then
     961           0 :           deallocate(out1D_5)
     962           0 :           nullify(cospOUT%isccp_meantb)
     963             :        endif
     964        9288 :        if (allocated(out1D_6)) then
     965           0 :           deallocate(out1D_6)
     966           0 :           nullify(cospOUT%isccp_fq)
     967             :        endif
     968             :     endif
     969             : 
     970             :     ! MISR
     971        9288 :     if (Lmisr_column) then
     972             :        ! Check to see which outputs are requested. If not requested, use a local dummy array
     973        9288 :        if (.not. associated(cospOUT%misr_cldarea)) then
     974           0 :           allocate(out1D_1(Npoints))
     975           0 :           cospOUT%misr_cldarea(ij:ik) => out1D_1
     976             :        endif
     977        9288 :        if (.not. associated(cospOUT%misr_meanztop)) then
     978           0 :           allocate(out1D_2(Npoints))
     979           0 :           cospOUT%misr_meanztop(ij:ik) => out1D_2
     980             :        endif
     981        9288 :        if (.not. associated(cospOUT%misr_fq)) then
     982           0 :           allocate(out1D_3(Npoints*numMISRTauBins*numMISRHgtBins))
     983           0 :           cospOUT%misr_fq(ij:ik,1:numMISRTauBins,1:numMISRHgtBins) => out1D_3
     984             :         endif
     985             : 
     986             :        ! Call simulator
     987             :         call misr_column(misrIN%Npoints,misrIN%Ncolumns,misr_boxztop,misrIN%sunlit,&
     988           0 :                          misr_boxtau,cospOUT%misr_cldarea(ij:ik),                  &
     989        9288 :                          cospOUT%misr_meanztop(ij:ik),cospOUT%misr_fq(ij:ik,:,:))
     990             : 
     991             :        ! Clear up memory
     992        9288 :        if (allocated(misr_boxtau))               deallocate(misr_boxtau)
     993        9288 :        if (allocated(misr_boxztop))              deallocate(misr_boxztop)
     994        9288 :        if (allocated(misr_dist_model_layertops)) deallocate(misr_dist_model_layertops)
     995        9288 :        if (allocated(out1D_1)) then
     996           0 :           deallocate(out1D_1)
     997           0 :           nullify(cospOUT%misr_cldarea)
     998             :        endif
     999        9288 :        if (allocated(out1D_2)) then
    1000           0 :           deallocate(out1D_2)
    1001           0 :           nullify(cospOUT%misr_meanztop)
    1002             :        endif
    1003        9288 :        if (allocated(out1D_3)) then
    1004           0 :           deallocate(out1D_3)
    1005           0 :           nullify(cospOUT%misr_fq)
    1006             :        endif
    1007             :     endif
    1008             : 
    1009             :     ! CALIPSO LIDAR Simulator
    1010        9288 :     if (Lcalipso_column) then
    1011             :        ! Check to see which outputs are requested. If not requested, use a local dummy array
    1012        9288 :        if (.not. associated(cospOUT%calipso_cfad_sr)) then
    1013           0 :           allocate(out1D_1(Npoints*SR_BINS*Nlvgrid))
    1014           0 :           cospOUT%calipso_cfad_sr(ij:ik,1:SR_BINS,1:Nlvgrid) => out1D_1
    1015             :        endif
    1016        9288 :        if (.not. associated(cospOUT%calipso_lidarcld)) then
    1017           0 :           allocate(out1D_2(Npoints*Nlvgrid))
    1018           0 :           cospOUT%calipso_lidarcld(ij:ik,1:Nlvgrid) => out1D_2
    1019             :        endif
    1020        9288 :        if (.not. associated(cospOUT%calipso_lidarcldphase)) then
    1021           0 :           allocate(out1D_3(Npoints*Nlvgrid*6))
    1022           0 :           cospOUT%calipso_lidarcldphase(ij:ik,1:Nlvgrid,1:6) => out1D_3
    1023             :        endif
    1024        9288 :        if (.not. associated(cospOUT%calipso_cldlayer)) then
    1025           0 :           allocate(out1D_4(Npoints*LIDAR_NCAT))
    1026           0 :           cospOUT%calipso_cldlayer(ij:ik,1:LIDAR_NCAT) => out1D_4
    1027             :        endif
    1028        9288 :        if (.not. associated(cospOUT%calipso_cldlayerphase)) then
    1029           0 :           allocate(out1D_5(Npoints*LIDAR_NCAT*6))
    1030           0 :           cospOUT%calipso_cldlayerphase(ij:ik,1:LIDAR_NCAT,1:6) => out1D_5
    1031             :        endif
    1032        9288 :        if (.not. associated(cospOUT%calipso_lidarcldtmp)) then
    1033           0 :           allocate(out1D_6(Npoints*40*5))
    1034           0 :           cospOUT%calipso_lidarcldtmp(ij:ik,1:40,1:5) => out1D_6
    1035             :        endif   
    1036        9288 :        if (.not. associated(cospOUT%calipso_lidarcldtype)) then
    1037       27864 :           allocate(out1D_7(Npoints*Nlvgrid*4))
    1038        9288 :           cospOUT%calipso_lidarcldtype(ij:ik,1:Nlvgrid,1:4) => out1D_7
    1039             :        endif
    1040        9288 :        if (.not. associated(cospOUT%calipso_cldtype)) then 
    1041       27864 :           allocate(out1D_8(Npoints*LIDAR_NTYPE)) 
    1042        9288 :           cospOUT%calipso_cldtype(ij:ik,1:LIDAR_NTYPE) => out1D_8  
    1043             :        endif 
    1044        9288 :        if (.not. associated(cospOUT%calipso_cldtypetemp)) then 
    1045       27864 :           allocate(out1D_9(Npoints*LIDAR_NTYPE))  
    1046        9288 :           cospOUT%calipso_cldtypetemp(ij:ik,1:LIDAR_NTYPE) => out1D_9 
    1047             :        endif 
    1048        9288 :        if (.not. associated(cospOUT%calipso_cldtypemeanz)) then 
    1049       27864 :           allocate(out1D_10(Npoints*2))
    1050        9288 :           cospOUT%calipso_cldtypemeanz(ij:ik,1:2) => out1D_10 
    1051             :        endif 
    1052        9288 :        if (.not. associated(cospOUT%calipso_cldtypemeanzse)) then
    1053       27864 :           allocate(out1D_12(Npoints*3)) 
    1054        9288 :           cospOUT%calipso_cldtypemeanzse(ij:ik,1:3) => out1D_12
    1055             :        endif
    1056        9288 :        if (.not. associated(cospOUT%calipso_cldthinemis)) then
    1057       27864 :           allocate(out1D_11(Npoints)) 
    1058        9288 :           cospOUT%calipso_cldthinemis(ij:ik) => out1D_11 
    1059             :        endif
    1060             :        
    1061             :        ! Call simulator
    1062        9288 :        ok_lidar_cfad=.true.
    1063             :        call lidar_column(calipsoIN%Npoints, calipsoIN%Ncolumns, calipsoIN%Nlevels,       &
    1064             :             Nlvgrid, SR_BINS, LIDAR_NTYPE, 'calipso',calipso_beta_tot(:,:,:), calipso_beta_mol(:,:),&
    1065        9288 :             cospgridIN%phalf(:,2:calipsoIN%Nlevels+1),cospgridIN%hgt_matrix,               &
    1066             :             cospgridIN%hgt_matrix_half, vgrid_z(:), ok_lidar_cfad, LIDAR_NCAT,           &
    1067           0 :             cospOUT%calipso_cfad_sr(ij:ik,:,:), cospOUT%calipso_lidarcld(ij:ik,:),       &
    1068           0 :             cospOUT%calipso_cldlayer(ij:ik,:),                                           &
    1069             :             cospgridIN%at(:,:), calipso_betaperp_tot(:,:,:), cospgridIN%surfelev,        & 
    1070           0 :             cospOUT%calipso_lidarcldphase(ij:ik,:,:),                       &
    1071           0 :             cospOUT%calipso_lidarcldtype(ij:ik,:,:),  cospOUT%calipso_cldtype(ij:ik,:),  &
    1072           0 :             cospOUT%calipso_cldtypetemp(ij:ik,:), cospOUT%calipso_cldtypemeanz(ij:ik,:), & 
    1073           0 :             cospOUT%calipso_cldtypemeanzse(ij:ik,:), cospOUT%calipso_cldthinemis(ij:ik), &
    1074       18576 :             cospOUT%calipso_cldlayerphase(ij:ik,:,:), cospOUT%calipso_lidarcldtmp(ij:ik,:,:))
    1075             : 
    1076      157896 :          if (associated(cospOUT%calipso_srbval)) cospOUT%calipso_srbval = calipso_histBsct
    1077             : 
    1078             :        ! Free up memory (if necessary)
    1079        9288 :        if (allocated(out1D_1)) then
    1080           0 :           deallocate(out1D_1)
    1081           0 :           nullify(cospOUT%calipso_cfad_sr)
    1082             :        endif
    1083        9288 :        if (allocated(out1D_2)) then
    1084           0 :           deallocate(out1D_2)
    1085           0 :           nullify(cospOUT%calipso_lidarcld)
    1086             :        endif
    1087        9288 :        if (allocated(out1D_3)) then
    1088           0 :           deallocate(out1D_3)
    1089           0 :           nullify(cospOUT%calipso_lidarcldphase)
    1090             :        endif
    1091        9288 :        if (allocated(out1D_4)) then
    1092           0 :           deallocate(out1D_4)
    1093           0 :           nullify(cospOUT%calipso_cldlayer)
    1094             :        endif
    1095        9288 :        if (allocated(out1D_5)) then
    1096           0 :           deallocate(out1D_5)
    1097           0 :           nullify(cospOUT%calipso_cldlayerphase)
    1098             :        endif
    1099        9288 :        if (allocated(out1D_6)) then
    1100           0 :           deallocate(out1D_6)
    1101           0 :           nullify(cospOUT%calipso_lidarcldtmp)
    1102             :        endif
    1103        9288 :        if (allocated(out1D_7)) then
    1104        9288 :           deallocate(out1D_7)  
    1105        9288 :           nullify(cospOUT%calipso_lidarcldtype)
    1106             :        endif  
    1107        9288 :        if (allocated(out1D_8)) then
    1108        9288 :           deallocate(out1D_8)
    1109        9288 :           nullify(cospOUT%calipso_cldtype)
    1110             :        endif 
    1111        9288 :        if (allocated(out1D_9)) then 
    1112        9288 :           deallocate(out1D_9) 
    1113        9288 :           nullify(cospOUT%calipso_cldtypetemp)
    1114             :        endif 
    1115        9288 :        if (allocated(out1D_10)) then 
    1116        9288 :           deallocate(out1D_10)
    1117        9288 :           nullify(cospOUT%calipso_cldtypemeanz)
    1118             :        endif 
    1119        9288 :        if (allocated(out1D_12)) then 
    1120        9288 :           deallocate(out1D_12) 
    1121        9288 :           nullify(cospOUT%calipso_cldtypemeanzse)
    1122             :        endif 
    1123        9288 :        if (allocated(out1D_11)) then 
    1124        9288 :           deallocate(out1D_11) 
    1125        9288 :           nullify(cospOUT%calipso_cldthinemis)
    1126             :        endif
    1127             : 
    1128             :     endif
    1129             : 
    1130             :     ! GROUND LIDAR Simulator
    1131        9288 :     if (LgrLidar532_column) then
    1132             :        ! Check to see which outputs are requested. If not requested, use a local dummy array
    1133           0 :        if (.not. associated(cospOUT%grLidar532_cfad_sr)) then
    1134           0 :           allocate(out1D_1(Npoints*SR_BINS*Nlvgrid)) 
    1135           0 :           cospOUT%grLidar532_cfad_sr(ij:ik,1:SR_BINS,1:Nlvgrid) => out1D_1
    1136             :        endif 
    1137           0 :        if (.not. associated(cospOUT%grLidar532_lidarcld)) then
    1138           0 :           allocate(out1D_2(Npoints*Nlvgrid)) 
    1139           0 :           cospOUT%grLidar532_lidarcld(ij:ik,1:Nlvgrid) => out1D_2
    1140             :        endif
    1141           0 :        if (.not. associated(cospOUT%grLidar532_cldlayer)) then
    1142           0 :           allocate(out1D_3(Npoints*LIDAR_NCAT))
    1143           0 :           cospOUT%grLidar532_cldlayer(ij:ik,1:LIDAR_NCAT) => out1D_3
    1144             :        endif
    1145             :        
    1146             :        ! Call simulator 
    1147           0 :        ok_lidar_cfad_grLidar532=.true.
    1148             :        call lidar_column(grLidar532IN%Npoints, grLidar532IN%Ncolumns, grLidar532IN%Nlevels,       &
    1149             :             Nlvgrid, SR_BINS, LIDAR_NTYPE, 'grlidar532',grLidar532_beta_tot(:,:,:), grLidar532_beta_mol(:,:),&
    1150           0 :             cospgridIN%phalf(:,2:grLidar532IN%Nlevels+1),cospgridIN%hgt_matrix,               &
    1151             :             cospgridIN%hgt_matrix_half, vgrid_z(:), ok_lidar_cfad_grLidar532, LIDAR_NCAT,      &
    1152           0 :             cospOUT%grLidar532_cfad_sr(ij:ik,:,:), cospOUT%grLidar532_lidarcld(ij:ik,:),       &
    1153           0 :             cospOUT%grLidar532_cldlayer(ij:ik,:))
    1154             : 
    1155           0 :        if (associated(cospOUT%grLidar532_srbval)) cospOUT%grLidar532_srbval = grLidar532_histBsct
    1156             : 
    1157             :        ! Free up memory (if necessary) 
    1158           0 :        if (allocated(out1D_1)) then
    1159           0 :           deallocate(out1D_1)
    1160           0 :           nullify(cospOUT%grLidar532_cfad_sr)
    1161             :        endif 
    1162           0 :        if (allocated(out1D_2)) then
    1163           0 :           deallocate(out1D_2)
    1164           0 :           nullify(cospOUT%grLidar532_lidarcld)
    1165             :        endif 
    1166           0 :        if (allocated(out1D_3)) then
    1167           0 :           deallocate(out1D_3)
    1168           0 :           nullify(cospOUT%grLidar532_cldlayer)
    1169             :        endif
    1170             : 
    1171             :     endif
    1172             : 
    1173             :     ! ATLID Simulator
    1174        9288 :     if (Latlid_column) then
    1175             :        ! Check to see which outputs are requested. If not requested, use a local dummy array
    1176           0 :        if (.not. associated(cospOUT%atlid_cfad_sr)) then
    1177           0 :           allocate(out1D_1(Npoints*SR_BINS*Nlvgrid))
    1178           0 :           cospOUT%atlid_cfad_sr(ij:ik,1:SR_BINS,1:Nlvgrid) => out1D_1
    1179             :        endif                                    
    1180           0 :        if (.not. associated(cospOUT%atlid_lidarcld)) then 
    1181           0 :           allocate(out1D_2(Npoints*Nlvgrid))                 
    1182           0 :           cospOUT%atlid_lidarcld(ij:ik,1:Nlvgrid) => out1D_2 
    1183             :        endif                                                   
    1184           0 :        if (.not. associated(cospOUT%atlid_cldlayer)) then   
    1185           0 :           allocate(out1D_3(Npoints*LIDAR_NCAT))                 
    1186           0 :           cospOUT%atlid_cldlayer(ij:ik,1:LIDAR_NCAT) => out1D_3 
    1187             :        endif                                                      
    1188             :        
    1189             :        ! Call simulator                                                             
    1190           0 :        ok_lidar_cfad_atlid=.true.
    1191             :        call lidar_column(atlidIN%Npoints, atlidIN%Ncolumns, atlidIN%Nlevels,       &
    1192             :             Nlvgrid, SR_BINS, LIDAR_NTYPE, 'atlid',atlid_beta_tot(:,:,:),     &
    1193           0 :             atlid_beta_mol(:,:), cospgridIN%phalf(:,2:atlidIN%Nlevels+1),            &
    1194             :             cospgridIN%hgt_matrix, cospgridIN%hgt_matrix_half, vgrid_z(:),         &
    1195           0 :             ok_lidar_cfad_atlid, LIDAR_NCAT, cospOUT%atlid_cfad_sr(ij:ik,:,:),     &
    1196           0 :             cospOUT%atlid_lidarcld(ij:ik,:), cospOUT%atlid_cldlayer(ij:ik,:))
    1197             :        
    1198           0 :        if (associated(cospOUT%atlid_srbval)) cospOUT%atlid_srbval = atlid_histBsct 
    1199             : 
    1200             :        ! Free up memory (if necessary)        
    1201           0 :        if (allocated(out1D_1)) then           
    1202           0 :           deallocate(out1D_1)                 
    1203           0 :           nullify(cospOUT%atlid_cfad_sr)
    1204             :        endif                                  
    1205           0 :        if (allocated(out1D_2)) then          
    1206           0 :           deallocate(out1D_2)                
    1207           0 :           nullify(cospOUT%atlid_lidarcld)
    1208             :        endif                                  
    1209           0 :        if (allocated(out1D_3)) then          
    1210           0 :           deallocate(out1D_3)
    1211           0 :           nullify(cospOUT%atlid_cldlayer)
    1212             :        endif          
    1213             : 
    1214             :     endif
    1215             : 
    1216             :     ! PARASOL
    1217        9288 :     if (Lparasol_column) then
    1218             :        call parasol_column(parasolIN%Npoints,PARASOL_NREFL,parasolIN%Ncolumns,           &
    1219             :                             cospgridIN%land(:),parasolPix_refl(:,:,:),                   &
    1220        9288 :                             cospOUT%parasolGrid_refl(ij:ik,:))
    1221        9288 :        if (allocated(parasolPix_refl)) deallocate(parasolPix_refl)
    1222             :     endif
    1223             : 
    1224             :     ! CLOUDSAT
    1225        9288 :     if (Lcloudsat_column) then
    1226             :        ! Check to see which outputs are requested. If not requested, use a local dummy array
    1227        9288 :        if (.not. associated(cospOUT%cloudsat_cfad_ze)) then
    1228           0 :           allocate(out1D_1(Npoints*cloudsat_DBZE_BINS*Nlvgrid))
    1229           0 :           cospOUT%cloudsat_cfad_ze(ij:ik,1:cloudsat_DBZE_BINS,1:Nlvgrid) => out1D_1
    1230             :        endif
    1231             : 
    1232        9288 :        if (.not. associated(cospOUT%cloudsat_pia)) then
    1233           0 :           allocate(out1D_2(Npoints))
    1234           0 :           cospOUT%cloudsat_pia(ij:ik) => out1D_2
    1235             :        endif
    1236        9288 :        if (.not. associated(cospOUT%cloudsat_precip_cover)) then
    1237           0 :           allocate(out1D_3(Npoints*nCloudsatPrecipClass))
    1238           0 :           cospOUT%cloudsat_precip_cover(ij:ik,1:nCloudsatPrecipClass) => out1D_3
    1239             :        endif
    1240             :           
    1241             :        ! Call simulator
    1242             :        call quickbeam_column(cloudsatIN%Npoints, cloudsatIN%Ncolumns, cloudsatIN%Nlevels,&
    1243             :             Nlvgrid, cloudsat_DBZE_BINS, 'cloudsat', cloudsatDBZe, cloudsatZe_non,       &
    1244             :             cospgridIN%land(:), cospgridIN%surfelev(:), cospgridIN%at(:,cospIN%Nlevels), &
    1245             :             cospIN%fracPrecipIce, cospgridIN%hgt_matrix, cospgridIN%hgt_matrix_half,     &
    1246           0 :             cospOUT%cloudsat_cfad_ze(ij:ik,:,:), cospOUT%cloudsat_precip_cover,          &
    1247        9288 :             cospOUT%cloudsat_pia)
    1248             :        ! Free up memory  (if necessary)
    1249        9288 :        if (allocated(out1D_1)) then
    1250           0 :           deallocate(out1D_1)
    1251           0 :           nullify(cospOUT%cloudsat_cfad_ze)
    1252             :        endif
    1253        9288 :        if (allocated(out1D_2)) then
    1254           0 :           deallocate(out1D_2)
    1255           0 :           nullify(cospOUT%cloudsat_pia)
    1256             :        endif
    1257        9288 :        if (allocated(out1D_3)) then
    1258           0 :           deallocate(out1D_3)
    1259           0 :           nullify(cospOUT%cloudsat_precip_cover)
    1260             :        endif
    1261             :     endif
    1262             : 
    1263             :     ! MODIS
    1264        9288 :     if (Lmodis_column) then
    1265        9288 :        if(modisiN%nSunlit > 0) then
    1266             :           ! Allocate space for local variables
    1267           0 :           allocate(modisCftotal(modisIN%nSunlit), modisCfLiquid(modisIN%nSunlit),        &
    1268           0 :                    modisCfIce(modisIN%nSunlit),modisCfHigh(modisIN%nSunlit),             &
    1269           0 :                    modisCfMid(modisIN%nSunlit),modisCfLow(modisIN%nSunlit),              &
    1270           0 :                    modisMeanTauTotal(modisIN%nSunlit),                                   &
    1271           0 :                    modisMeanTauLiquid(modisIN%nSunlit),modisMeanTauIce(modisIN%nSunlit), &
    1272           0 :                    modisMeanLogTauTotal(modisIN%nSunlit),                                &
    1273           0 :                    modisMeanLogTauLiquid(modisIN%nSunlit),                               &
    1274           0 :                    modisMeanLogTauIce(modisIN%nSunlit),                                  &
    1275           0 :                    modisMeanSizeLiquid(modisIN%nSunlit),                                 &
    1276           0 :                    modisMeanSizeIce(modisIN%nSunlit),                                    &
    1277           0 :                    modisMeanCloudTopPressure(modisIN%nSunlit),                           &
    1278           0 :                    modisMeanLiquidWaterPath(modisIN%nSunlit),                            &
    1279           0 :                    modisMeanIceWaterPath(modisIN%nSunlit),                               &
    1280           0 :                    modisJointHistogram(modisIN%nSunlit,numMODISTauBins,numMODISPresBins),&
    1281           0 :                    modisJointHistogramIce(modisIN%nSunlit,numModisTauBins,numMODISReffIceBins),&
    1282      140969 :                    modisJointHistogramLiq(modisIN%nSunlit,numModisTauBins,numMODISReffLiqBins))
    1283             :           ! Call simulator
    1284             :           call modis_column(modisIN%nSunlit, modisIN%Ncolumns,modisRetrievedPhase,       &
    1285             :                              modisRetrievedCloudTopPressure,modisRetrievedTau,           &
    1286             :                              modisRetrievedSize, modisCfTotal, modisCfLiquid, modisCfIce,&
    1287             :                              modisCfHigh, modisCfMid, modisCfLow, modisMeanTauTotal,     &
    1288             :                              modisMeanTauLiquid, modisMeanTauIce, modisMeanLogTauTotal,  &
    1289             :                              modisMeanLogTauLiquid, modisMeanLogTauIce,                  &
    1290             :                              modisMeanSizeLiquid, modisMeanSizeIce,                      &
    1291             :                              modisMeanCloudTopPressure, modisMeanLiquidWaterPath,        &
    1292             :                              modisMeanIceWaterPath, modisJointHistogram,                 &
    1293        4861 :                              modisJointHistogramIce,modisJointHistogramLiq)
    1294             :           ! Store data (if requested)
    1295        4861 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean)) then
    1296           0 :              cospOUT%modis_Cloud_Fraction_Total_Mean(ij+int(modisIN%sunlit(:))-1)   =    &
    1297      150661 :                   modisCfTotal
    1298             :           endif
    1299        4861 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean)) then
    1300           0 :              cospOUT%modis_Cloud_Fraction_Water_Mean(ij+int(modisIN%sunlit(:))-1)   =    &
    1301      150661 :                   modisCfLiquid
    1302             :           endif
    1303        4861 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean)) then
    1304           0 :              cospOUT%modis_Cloud_Fraction_Ice_Mean(ij+int(modisIN%sunlit(:))-1)     =    &
    1305      150661 :                   modisCfIce
    1306             :           endif
    1307        4861 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean)) then
    1308           0 :              cospOUT%modis_Cloud_Fraction_High_Mean(ij+int(modisIN%sunlit(:))-1)    =    &
    1309      150661 :                   modisCfHigh
    1310             :           endif
    1311        4861 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean)) then
    1312           0 :              cospOUT%modis_Cloud_Fraction_Mid_Mean(ij+int(modisIN%sunlit(:))-1)     =    &
    1313      150661 :                   modisCfMid
    1314             :           endif
    1315        4861 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean)) then
    1316           0 :              cospOUT%modis_Cloud_Fraction_Low_Mean(ij+int(modisIN%sunlit(:))-1)     =    &
    1317      150661 :                   modisCfLow
    1318             :           endif
    1319        4861 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean)) then
    1320           0 :              cospOUT%modis_Optical_Thickness_Total_Mean(ij+int(modisIN%sunlit(:))-1) =   &
    1321      150661 :                   modisMeanTauTotal
    1322             :           endif
    1323        4861 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean)) then
    1324           0 :              cospOUT%modis_Optical_Thickness_Water_Mean(ij+int(modisIN%sunlit(:))-1) =   &
    1325      150661 :                   modisMeanTauLiquid
    1326             :           endif
    1327        4861 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean)) then
    1328           0 :              cospOUT%modis_Optical_Thickness_Ice_Mean(ij+int(modisIN%sunlit(:))-1)  =    &
    1329      150661 :                   modisMeanTauIce
    1330             :           endif
    1331        4861 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean)) then
    1332           0 :              cospOUT%modis_Optical_Thickness_Total_LogMean(ij+int(modisIN%sunlit(:))-1)= &
    1333      150661 :                   modisMeanLogTauTotal
    1334             :           endif
    1335        4861 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean)) then
    1336           0 :              cospOUT%modis_Optical_Thickness_Water_LogMean(ij+int(modisIN%sunlit(:))-1) = &
    1337      150661 :                   modisMeanLogTauLiquid
    1338             :           endif
    1339        4861 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean)) then
    1340           0 :              cospOUT%modis_Optical_Thickness_Ice_LogMean(ij+int(modisIN%sunlit(:))-1) =  &
    1341      150661 :                   modisMeanLogTauIce
    1342             :           endif
    1343        4861 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean)) then
    1344           0 :              cospOUT%modis_Cloud_Particle_Size_Water_Mean(ij+int(modisIN%sunlit(:))-1) = &
    1345      150661 :                   modisMeanSizeLiquid
    1346             :           endif
    1347        4861 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean)) then
    1348           0 :              cospOUT%modis_Cloud_Particle_Size_Ice_Mean(ij+int(modisIN%sunlit(:))-1) =   &
    1349      150661 :                   modisMeanSizeIce
    1350             :           endif
    1351        4861 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean)) then
    1352           0 :              cospOUT%modis_Cloud_Top_Pressure_Total_Mean(ij+int(modisIN%sunlit(:))-1) =  &
    1353      150661 :                   modisMeanCloudTopPressure
    1354             :           endif
    1355        4861 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean)) then
    1356           0 :              cospOUT%modis_Liquid_Water_Path_Mean(ij+int(modisIN%sunlit(:))-1)      =    &
    1357      150661 :                   modisMeanLiquidWaterPath
    1358             :           endif
    1359        4861 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean)) then
    1360           0 :               cospOUT%modis_Ice_Water_Path_Mean(ij+int(modisIN%sunlit(:))-1)         =   &
    1361      150661 :                   modisMeanIceWaterPath
    1362             :           endif
    1363        4861 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure)) then
    1364        4861 :              cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(ij+            &
    1365     3926938 :                   int(modisIN%sunlit(:))-1, 1:numModisTauBins, :) = modisJointHistogram(:, :, :)
    1366             :              ! Reorder pressure bins in joint histogram to go from surface to TOA
    1367        4861 :              cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(ij:ik,:,:) = &
    1368     8048116 :                   cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(ij:ik,:,numMODISPresBins:1:-1)
    1369             :           endif
    1370        4861 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffIce)) then
    1371        4861 :              cospOUT%modis_Optical_Thickness_vs_ReffIce(ij+int(modisIN%sunlit(:))-1, 1:numMODISTauBins,:) = &
    1372     3377750 :                 modisJointHistogramIce(:,:,:)
    1373             :           endif
    1374        4861 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLiq)) then
    1375        4861 :              cospOUT%modis_Optical_Thickness_vs_ReffLiq(ij+int(modisIN%sunlit(:))-1, 1:numMODISTauBins,:) = &
    1376     3377750 :                 modisJointHistogramLiq(:,:,:)
    1377             :           endif
    1378             : 
    1379        4861 :           if(modisIN%nSunlit < modisIN%Npoints) then
    1380             :              ! Where it's night and we haven't done the retrievals the values are undefined
    1381         443 :              if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                    &
    1382        7581 :                 cospOUT%modis_Cloud_Fraction_Total_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1383         443 :              if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                    &
    1384        7581 :                 cospOUT%modis_Cloud_Fraction_Water_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1385         443 :              if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                      &
    1386        7581 :                 cospOUT%modis_Cloud_Fraction_Ice_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1387         443 :              if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                     &
    1388        7581 :                 cospOUT%modis_Cloud_Fraction_High_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1389         443 :              if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                      &
    1390        7581 :                 cospOUT%modis_Cloud_Fraction_Mid_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1391         443 :              if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                      &
    1392        7581 :                 cospOUT%modis_Cloud_Fraction_Low_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1393         443 :              if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                 &
    1394        7581 :                 cospOUT%modis_Optical_Thickness_Total_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1395         443 :              if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                 &
    1396        7581 :                 cospOUT%modis_Optical_Thickness_Water_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1397         443 :              if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                   &
    1398        7581 :                 cospOUT%modis_Optical_Thickness_Ice_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1399         443 :              if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))              &
    1400        7581 :                 cospOUT%modis_Optical_Thickness_Total_LogMean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1401         443 :              if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))              &
    1402        7581 :                 cospOUT%modis_Optical_Thickness_Water_LogMean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1403         443 :              if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                &
    1404        7581 :                 cospOUT%modis_Optical_Thickness_Ice_LogMean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1405         443 :              if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))               &
    1406        7581 :                 cospOUT%modis_Cloud_Particle_Size_Water_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1407         443 :              if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                 &
    1408        7581 :                 cospOUT%modis_Cloud_Particle_Size_Ice_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1409         443 :              if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                &
    1410        7581 :                 cospOUT%modis_Cloud_Top_Pressure_Total_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1411         443 :              if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                       &
    1412        7581 :                 cospOUT%modis_Liquid_Water_Path_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1413         443 :              if (associated(cospOUT%modis_Ice_Water_Path_Mean))                          &
    1414        7581 :                 cospOUT%modis_Ice_Water_Path_Mean(ij+int(modisIN%notSunlit(:))-1) = R_UNDEF
    1415         443 :              if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))      &
    1416      203701 :                 cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(ij+int(modisIN%notSunlit(:))-1, :, :) = R_UNDEF
    1417             :           end if
    1418             :        else
    1419             :           ! It's nightime everywhere - everything is undefined
    1420        4427 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                       &
    1421       73758 :              cospOUT%modis_Cloud_Fraction_Total_Mean(ij:ik) = R_UNDEF
    1422        4427 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                       &
    1423       73758 :              cospOUT%modis_Cloud_Fraction_Water_Mean(ij:ik) = R_UNDEF
    1424        4427 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                         &
    1425       73758 :              cospOUT%modis_Cloud_Fraction_Ice_Mean(ij:ik) = R_UNDEF
    1426        4427 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                        &
    1427       73758 :              cospOUT%modis_Cloud_Fraction_High_Mean(ij:ik) = R_UNDEF
    1428        4427 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                         &
    1429       73758 :              cospOUT%modis_Cloud_Fraction_Mid_Mean(ij:ik) = R_UNDEF
    1430        4427 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                         &
    1431       73758 :              cospOUT%modis_Cloud_Fraction_Low_Mean(ij:ik) = R_UNDEF
    1432        4427 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                    &
    1433       73758 :              cospOUT%modis_Optical_Thickness_Total_Mean(ij:ik) = R_UNDEF
    1434        4427 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                    &
    1435       73758 :              cospOUT%modis_Optical_Thickness_Water_Mean(ij:ik) = R_UNDEF
    1436        4427 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                      &
    1437       73758 :              cospOUT%modis_Optical_Thickness_Ice_Mean(ij:ik) = R_UNDEF
    1438        4427 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                 &
    1439       73758 :              cospOUT%modis_Optical_Thickness_Total_LogMean(ij:ik) = R_UNDEF
    1440        4427 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                 &
    1441       73758 :              cospOUT%modis_Optical_Thickness_Water_LogMean(ij:ik) = R_UNDEF
    1442        4427 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                   &
    1443       73758 :              cospOUT%modis_Optical_Thickness_Ice_LogMean(ij:ik) = R_UNDEF
    1444        4427 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                  &
    1445       73758 :              cospOUT%modis_Cloud_Particle_Size_Water_Mean(ij:ik) = R_UNDEF
    1446        4427 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                    &
    1447       73758 :               cospOUT%modis_Cloud_Particle_Size_Ice_Mean(ij:ik) = R_UNDEF
    1448        4427 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                   &
    1449       73758 :              cospOUT%modis_Cloud_Top_Pressure_Total_Mean(ij:ik) = R_UNDEF
    1450        4427 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                          &
    1451       73758 :              cospOUT%modis_Liquid_Water_Path_Mean(ij:ik) = R_UNDEF
    1452        4427 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                             &
    1453       73758 :              cospOUT%modis_Ice_Water_Path_Mean(ij:ik) = R_UNDEF
    1454        4427 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))         &
    1455     3649558 :              cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(ij:ik, :, :) = R_UNDEF
    1456             :        endif
    1457             :        ! Free up memory (if necessary)
    1458        9288 :        if (allocated(modisRetrievedTau))               deallocate(modisRetrievedTau)
    1459        9288 :        if (allocated(modisRetrievedSize))              deallocate(modisRetrievedSize)
    1460        9288 :        if (allocated(modisRetrievedPhase))             deallocate(modisRetrievedPhase)
    1461        9288 :        if (allocated(modisRetrievedCloudTopPressure))  deallocate(modisRetrievedCloudTopPressure)
    1462        9288 :        if (allocated(modisCftotal))                    deallocate(modisCftotal)
    1463        9288 :        if (allocated(modisCfLiquid))                   deallocate(modisCfLiquid)
    1464        9288 :        if (allocated(modisCfIce))                      deallocate(modisCfIce)
    1465        9288 :        if (allocated(modisCfHigh))                     deallocate(modisCfHigh)
    1466        9288 :        if (allocated(modisCfMid))                      deallocate(modisCfMid)
    1467        9288 :        if (allocated(modisCfLow))                      deallocate(modisCfLow)
    1468        9288 :        if (allocated(modisMeanTauTotal))               deallocate(modisMeanTauTotal)
    1469        9288 :        if (allocated(modisMeanTauLiquid))              deallocate(modisMeanTauLiquid)
    1470        9288 :        if (allocated(modisMeanTauIce))                 deallocate(modisMeanTauIce)
    1471        9288 :        if (allocated(modisMeanLogTauTotal))            deallocate(modisMeanLogTauTotal)
    1472        9288 :        if (allocated(modisMeanLogTauLiquid))           deallocate(modisMeanLogTauLiquid)
    1473        9288 :        if (allocated(modisMeanLogTauIce))              deallocate(modisMeanLogTauIce)
    1474        9288 :        if (allocated(modisMeanSizeLiquid))             deallocate(modisMeanSizeLiquid)
    1475        9288 :        if (allocated(modisMeanSizeIce))                deallocate(modisMeanSizeIce)
    1476        9288 :        if (allocated(modisMeanCloudTopPressure))       deallocate(modisMeanCloudTopPressure)
    1477        9288 :        if (allocated(modisMeanLiquidWaterPath))        deallocate(modisMeanLiquidWaterPath)
    1478        9288 :        if (allocated(modisMeanIceWaterPath))           deallocate(modisMeanIceWaterPath)
    1479        9288 :        if (allocated(modisJointHistogram))             deallocate(modisJointHistogram)
    1480        9288 :        if (allocated(modisJointHistogramIce))          deallocate(modisJointHistogramIce)
    1481        9288 :        if (allocated(modisJointHistogramLiq))          deallocate(modisJointHistogramLiq)
    1482        9288 :        if (allocated(isccp_boxttop))                   deallocate(isccp_boxttop)
    1483        9288 :        if (allocated(isccp_boxptop))                   deallocate(isccp_boxptop)
    1484        9288 :        if (allocated(isccp_boxtau))                    deallocate(isccp_boxtau)
    1485        9288 :        if (allocated(isccp_meantbclr))                 deallocate(isccp_meantbclr)
    1486        9288 :        if (allocated(isccpLEVMATCH))                   deallocate(isccpLEVMATCH)
    1487             :     endif
    1488             : 
    1489             :     ! RTTOV
    1490        9288 :     if (lrttov_column) then
    1491             :        call rttov_column(rttovIN%nPoints,rttovIN%nLevels,rttovIN%nSubCols,rttovIN%q,    &
    1492             :                          rttovIN%p,rttovIN%t,rttovIN%o3,rttovIN%ph,rttovIN%h_surf,      &
    1493             :                          rttovIN%u_surf,rttovIN%v_surf,rttovIN%p_surf,rttovIN%t_skin,   &
    1494             :                          rttovIN%t2m,rttovIN%q2m,rttovIN%lsmask,rttovIN%longitude,      &
    1495             :                          rttovIN%latitude,rttovIN%seaice,rttovIN%co2,rttovIN%ch4,       &
    1496             :                          rttovIN%n2o,rttovIN%co,rttovIN%zenang,lrttov_cleanUp,          &
    1497           0 :                          cospOUT%rttov_tbs(ij:ik,:),cosp_simulator(nError+1),           &
    1498             :                          ! Optional arguments for surface emissivity calculation
    1499           0 :                          month=rttovIN%month)
    1500             :                          ! Optional arguments to rttov for all-sky calculation
    1501             :                          ! rttovIN%month, rttovIN%tca,rttovIN%cldIce,rttovIN%cldLiq,     &
    1502             :                          ! rttovIN%fl_rain,rttovIN%fl_snow)
    1503             :     endif
    1504             : 
    1505             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1506             :     ! 6) Compute multi-instrument products
    1507             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1508             : 
    1509             :     ! CLOUDSAT/CALIPSO products
    1510        9288 :     if (Lradar_lidar_tcc .or. Llidar_only_freq_cloud .or. Lcloudsat_tcc .or. Lcloudsat_tcc2) then
    1511             : 
    1512        9288 :        if (use_vgrid) then
    1513           0 :           allocate(lidar_only_freq_cloud(cloudsatIN%Npoints,Nlvgrid),                    &
    1514           0 :                radar_lidar_tcc(cloudsatIN%Npoints), cloudsat_tcc(cloudsatIN%Npoints),    &
    1515       74304 :                cloudsat_tcc2(cloudsatIN%Npoints))
    1516           0 :           allocate(betamol_in(cloudsatIN%Npoints,1,cloudsatIN%Nlevels),                  &
    1517           0 :                    betamoli(cloudsatIN%Npoints,1,Nlvgrid),                               &
    1518           0 :                    pnormI(cloudsatIN%Npoints,cloudsatIN%Ncolumns,Nlvgrid),               &
    1519      120744 :                    Ze_totI(cloudsatIN%Npoints,cloudsatIN%Ncolumns,Nlvgrid))
    1520             : 
    1521             :           ! Regrid in the vertical (*NOTE* This routine requires SFC-2-TOA ordering, so flip
    1522             :           ! inputs and outputs to maintain TOA-2-SFC ordering convention in COSP2.)
    1523    13036680 :           betamol_in(:,1,:) = calipso_beta_mol(:,cloudsatIN%Nlevels:1:-1)
    1524             :           call cosp_change_vertical_grid(cloudsatIN%Npoints,1,cloudsatIN%Nlevels,        &
    1525           0 :                cospgridIN%hgt_matrix(:,cloudsatIN%Nlevels:1:-1),                         &
    1526           0 :                cospgridIN%hgt_matrix_half(:,cloudsatIN%Nlevels:1:-1),betamol_in,         &
    1527           0 :                Nlvgrid,vgrid_zl(Nlvgrid:1:-1),vgrid_zu(Nlvgrid:1:-1),                    &
    1528    33010632 :                betamolI(:,1,Nlvgrid:1:-1))
    1529             : 
    1530             :           call cosp_change_vertical_grid(cloudsatIN%Npoints,cloudsatIN%Ncolumns,         &
    1531           0 :                cloudsatIN%Nlevels,cospgridIN%hgt_matrix(:,cloudsatIN%Nlevels:1:-1),      &
    1532           0 :                cospgridIN%hgt_matrix_half(:,cloudsatIN%Nlevels:1:-1),                    &
    1533           0 :                calipso_beta_tot(:,:,cloudsatIN%Nlevels:1:-1),Nlvgrid,                    &
    1534   220267944 :                vgrid_zl(Nlvgrid:1:-1),vgrid_zu(Nlvgrid:1:-1),pnormI(:,:,Nlvgrid:1:-1))
    1535             : 
    1536             :           call cosp_change_vertical_grid(cloudsatIN%Npoints,cloudsatIN%Ncolumns,         &
    1537           0 :                cloudsatIN%Nlevels,cospgridIN%hgt_matrix(:,cloudsatIN%Nlevels:1:-1),      &
    1538           0 :                cospgridIN%hgt_matrix_half(:,cloudsatIN%Nlevels:1:-1),                    &
    1539           0 :                cloudsatDBZe(:,:,cloudsatIN%Nlevels:1:-1),Nlvgrid,vgrid_zl(Nlvgrid:1:-1), &
    1540   220267944 :                vgrid_zu(Nlvgrid:1:-1),Ze_totI(:,:,Nlvgrid:1:-1),log_units=.true.)
    1541             : 
    1542             :           call cosp_lidar_only_cloud(cloudsatIN%Npoints, cloudsatIN%Ncolumns, Nlvgrid,   &
    1543             :              pnormI, betamolI, Ze_totI, lidar_only_freq_cloud, radar_lidar_tcc,          &
    1544        9288 :              cloudsat_tcc, cloudsat_tcc2)
    1545             : 
    1546        9288 :           deallocate(betamol_in,betamolI,pnormI,ze_totI)
    1547             :        else
    1548           0 :           allocate(lidar_only_freq_cloud(cloudsatIN%Npoints,cloudsatIN%Nlevels),         &
    1549           0 :                radar_lidar_tcc(cloudsatIN%Npoints), cloudsat_tcc(cloudsatIN%Npoints),    &
    1550           0 :                cloudsat_tcc2(cloudsatIN%Npoints))
    1551             :           call cosp_lidar_only_cloud(cloudsatIN%Npoints,cloudsatIN%Ncolumns,             &
    1552           0 :                cospIN%Nlevels,calipso_beta_tot(:,:,cloudsatIN%Nlevels:1:-1),             &
    1553           0 :                calipso_beta_mol(:,cloudsatIN%Nlevels:1:-1),                              &
    1554           0 :                cloudsatDBZe(:,:,cloudsatIN%Nlevels:1:-1),lidar_only_freq_cloud,          &
    1555           0 :                radar_lidar_tcc, cloudsat_tcc, cloudsat_tcc2)
    1556             :        endif
    1557             : 
    1558             :        ! Store, when necessary
    1559        9288 :        if (associated(cospOUT%lidar_only_freq_cloud)) then
    1560     6212808 :           cospOUT%lidar_only_freq_cloud(ij:ik,:) = lidar_only_freq_cloud
    1561             :        endif
    1562        9288 :        if (associated(cospOUT%radar_lidar_tcc)) then
    1563      155088 :           cospOUT%radar_lidar_tcc(ij:ik) = radar_lidar_tcc
    1564             :        endif
    1565        9288 :        if (associated(cospOUT%cloudsat_tcc)) then
    1566           0 :           cospOUT%cloudsat_tcc(ij:ik) = cloudsat_tcc
    1567             :        endif
    1568        9288 :        if (associated(cospOUT%cloudsat_tcc2)) then
    1569           0 :           cospOUT%cloudsat_tcc2(ij:ik) = cloudsat_tcc2
    1570             :        endif
    1571             :     endif
    1572             : 
    1573             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1574             :     ! 7) Cleanup
    1575             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1576        9288 :     if (Lisccp_subcolumn .or. Lmodis_subcolumn) then
    1577        9288 :        nullify(isccpIN%Npoints,isccpIN%Ncolumns,isccpIN%Nlevels,isccpIN%emsfc_lw,        &
    1578        9288 :                isccpIN%skt,isccpIN%qv,isccpIN%at,isccpIN%frac_out,isccpIN%dtau,          &
    1579        9288 :                isccpIN%dem,isccpIN%phalf,isccpIN%sunlit,isccpIN%pfull)
    1580             :     endif
    1581             : 
    1582        9288 :     if (Lmisr_subcolumn) then
    1583        9288 :        nullify(misrIN%Npoints,misrIN%Ncolumns,misrIN%Nlevels,misrIN%dtau,misrIN%sunlit,  &
    1584        9288 :                misrIN%zfull,misrIN%at)
    1585             :     endif
    1586             : 
    1587        9288 :     if (Lcalipso_subcolumn) then
    1588        9288 :        nullify(calipsoIN%Npoints,calipsoIN%Ncolumns,calipsoIN%Nlevels,calipsoIN%beta_mol,&
    1589        9288 :                calipsoIN%betatot,calipsoIN%betatot_liq,calipsoIN%betatot_ice,            &
    1590        9288 :                calipsoIN%tau_mol,calipsoIN%tautot,calipsoIN%tautot_liq,calipsoIN%tautot_ice)
    1591             :     endif
    1592             : 
    1593        9288 :     if (LgrLidar532_subcolumn) then 
    1594           0 :        nullify(grLidar532IN%Npoints,grLidar532IN%Ncolumns,grLidar532IN%Nlevels,grLidar532IN%beta_mol, &
    1595           0 :                grLidar532IN%betatot,grLidar532IN%tau_mol,grLidar532IN%tautot) 
    1596             :     endif 
    1597             : 
    1598        9288 :     if (Latlid_subcolumn) then
    1599           0 :        nullify(atlidIN%Npoints,atlidIN%Ncolumns,atlidIN%Nlevels,atlidIN%beta_mol_atlid, &
    1600           0 :                atlidIN%betatot_atlid,atlidIN%tau_mol_atlid,atlidIN%tautot_atlid)
    1601             :     endif 
    1602             : 
    1603        9288 :     if (Lparasol_subcolumn) then
    1604        9288 :        nullify(parasolIN%Npoints,parasolIN%Nlevels,parasolIN%Ncolumns,parasolIN%Nrefl,   &
    1605        9288 :             parasolIN%tautot_S_liq,parasolIN%tautot_S_ice)
    1606             :     endif
    1607             : 
    1608             : 
    1609        9288 :     if (Lcloudsat_subcolumn) then
    1610        9288 :        nullify(cloudsatIN%Npoints,cloudsatIN%Nlevels,cloudsatIN%Ncolumns,cloudsatIN%rcfg,&
    1611        9288 :                cloudsatIN%kr_vol,cloudsatIN%g_vol,cloudsatIN%z_vol,cloudsatIN%hgt_matrix)
    1612             :     endif
    1613             : 
    1614        9288 :     if (Lmodis_subcolumn) then
    1615        9288 :        nullify(modisIN%Npoints,modisIN%Ncolumns,modisIN%Nlevels,modisIN%tau,modisIN%g,   &
    1616        9288 :                modisIN%liqFrac,modisIN%w0)
    1617        9288 :        if (allocated(modisIN%sunlit))    deallocate(modisIN%sunlit)
    1618        9288 :        if (allocated(modisIN%notSunlit)) deallocate(modisIN%notSunlit)
    1619        9288 :        if (allocated(modisIN%pres))      deallocate(modisIN%pres)
    1620             :     endif
    1621             : 
    1622        9288 :     if (allocated(calipso_beta_tot))      deallocate(calipso_beta_tot)
    1623        9288 :     if (allocated(grLidar532_beta_tot))  deallocate(grLidar532_beta_tot)
    1624        9288 :     if (allocated(atlid_beta_tot))        deallocate(atlid_beta_tot) 
    1625        9288 :     if (allocated(calipso_beta_mol))      deallocate(calipso_beta_mol)
    1626        9288 :     if (allocated(grLidar532_beta_mol))  deallocate(grLidar532_beta_mol)
    1627        9288 :     if (allocated(atlid_beta_mol))        deallocate(atlid_beta_mol)
    1628        9288 :     if (allocated(calipso_betaperp_tot))  deallocate(calipso_betaperp_tot)
    1629        9288 :     if (allocated(cloudsatDBZe))          deallocate(cloudsatDBZe)
    1630        9288 :     if (allocated(lidar_only_freq_cloud)) deallocate(lidar_only_freq_cloud)
    1631        9288 :     if (allocated(radar_lidar_tcc))       deallocate(radar_lidar_tcc)
    1632        9288 :     if (allocated(cloudsat_tcc))          deallocate(cloudsat_tcc)
    1633        9288 :     if (allocated(cloudsat_tcc2))         deallocate(cloudsat_tcc2)
    1634             : 
    1635             :   end function COSP_SIMULATOR
    1636             :   ! ######################################################################################
    1637             :   ! SUBROUTINE cosp_init
    1638             :   ! ######################################################################################
    1639        1536 :   SUBROUTINE COSP_INIT(Lisccp, Lmodis, Lmisr, Lcloudsat, Lcalipso, LgrLidar532, Latlid, Lparasol, Lrttov,     &
    1640             :        cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs, cloudsat_do_ray,          &
    1641             :        isccp_top_height, isccp_top_height_direction, surface_radar, rcfg, lusevgrid,     &
    1642        1536 :        luseCSATvgrid, Nvgrid, Nlevels, cloudsat_micro_scheme)
    1643             : 
    1644             :     ! INPUTS
    1645             :     logical,intent(in) :: Lisccp,Lmodis,Lmisr,Lcloudsat,Lcalipso,LgrLidar532,Latlid,Lparasol,Lrttov
    1646             :     integer,intent(in)  :: &
    1647             :          cloudsat_use_gas_abs,       & !
    1648             :          cloudsat_do_ray,            & !
    1649             :          isccp_top_height,           & !
    1650             :          isccp_top_height_direction, & !
    1651             :          Nlevels,                    & !
    1652             :          Nvgrid,                     & ! Number of levels for new L3 grid
    1653             :          surface_radar                 !
    1654             :     real(wp),intent(in) :: &
    1655             :          cloudsat_radar_freq,        & !
    1656             :          cloudsat_k2                   !
    1657             :     logical,intent(in) :: &
    1658             :          lusevgrid,                  & ! Switch to use different vertical grid
    1659             :          luseCSATvgrid                 ! Switch to use CLOUDSAT grid spacing for new
    1660             :                                        ! vertical grid
    1661             :     character(len=64),intent(in) :: &
    1662             :        cloudsat_micro_scheme           ! Microphysical scheme used by CLOUDSAT
    1663             : 
    1664             :     ! OUTPUTS
    1665             :     type(radar_cfg) :: rcfg
    1666             : 
    1667             :     ! Local variables
    1668             :     integer  :: i
    1669             :     real(wp) :: zstep
    1670             : 
    1671             :     ! Initialize MODIS optical-depth bin boundaries for joint-histogram. (defined in cosp_config.F90)
    1672        1536 :     if (.not. allocated(modis_histTau)) then
    1673        1536 :        allocate(modis_histTau(ntau+1),modis_histTauEdges(2,ntau),modis_histTauCenters(ntau))
    1674        1536 :        numMODISTauBins      = ntau
    1675       15360 :        modis_histTau        = tau_binBounds
    1676       35328 :        modis_histTauEdges   = tau_binEdges
    1677       13824 :        modis_histTauCenters = tau_binCenters
    1678             :     endif
    1679             : 
    1680             :     ! Set up vertical grid used by CALIPSO and CLOUDSAT L3
    1681        1536 :     use_vgrid = lusevgrid
    1682             : 
    1683        1536 :     if (use_vgrid) then
    1684        1536 :       Nlvgrid  = Nvgrid
    1685        7680 :        allocate(vgrid_zl(Nlvgrid),vgrid_zu(Nlvgrid),vgrid_z(Nlvgrid))
    1686             :        ! CloudSat grid requested
    1687        1536 :        if (luseCSATvgrid)       zstep = 480._wp
    1688             :        ! Other grid requested. Constant vertical spacing with top at 20 km
    1689        1536 :        if (.not. luseCSATvgrid) zstep = 20000._wp/Nvgrid
    1690       62976 :        do i=1,Nvgrid
    1691       61440 :           vgrid_zl(Nlvgrid-i+1) = (i-1)*zstep
    1692       62976 :           vgrid_zu(Nlvgrid-i+1) = i*zstep
    1693             :        enddo
    1694       64512 :        vgrid_z = (vgrid_zl+vgrid_zu)/2._wp
    1695             :     else
    1696           0 :        Nlvgrid = Nlevels
    1697           0 :        allocate(vgrid_zl(Nlvgrid),vgrid_zu(Nlvgrid),vgrid_z(Nlvgrid))
    1698             :     endif
    1699             : 
    1700             :     ! Initialize simulators
    1701        1536 :     if (Lisccp) call cosp_isccp_init(isccp_top_height,isccp_top_height_direction)
    1702        1536 :     if (Lmodis) call cosp_modis_init()
    1703        1536 :     if (Lmisr)  call cosp_misr_init()
    1704        1536 :     if (Lrttov) call cosp_rttov_init()
    1705        1536 :     if (Lcloudsat) call cosp_cloudsat_init(cloudsat_radar_freq,cloudsat_k2,              &
    1706             :          cloudsat_use_gas_abs,cloudsat_do_ray,R_UNDEF,N_HYDRO, surface_radar,            &
    1707        1536 :          rcfg,cloudsat_micro_scheme)
    1708        1536 :     if (Lcalipso) call cosp_calipso_init()
    1709        1536 :     if (LgrLidar532) call cosp_grLidar532_init()
    1710        1536 :     if (Latlid) call cosp_atlid_init()
    1711        1536 :     if (Lparasol) call cosp_parasol_init()
    1712             : 
    1713        1536 :     linitialization = .FALSE.
    1714        1536 :   END SUBROUTINE COSP_INIT
    1715             : 
    1716             :   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1717             :   ! SUBROUTINE cosp_cleanUp
    1718             :   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1719           0 :   subroutine cosp_cleanUp()
    1720           0 :     deallocate(vgrid_zl,vgrid_zu,vgrid_z)
    1721           0 :   end subroutine cosp_cleanUp
    1722             : 
    1723             :   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1724             :   ! SUBROUTINE cosp_errorCheck
    1725             :   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1726        9288 :   subroutine cosp_errorCheck(cospgridIN, cospIN, Lisccp_subcolumn, Lisccp_column,           &
    1727             :        Lmisr_subcolumn, Lmisr_column, Lmodis_subcolumn, Lmodis_column, Lcloudsat_subcolumn, &
    1728             :        Lcloudsat_column, Lcalipso_subcolumn, Lcalipso_column, Latlid_subcolumn,             &
    1729             :        Latlid_column, LgrLidar532_subcolumn, LgrLidar532_column, Lrttov_subcolumn,        &
    1730             :        Lrttov_column, Lparasol_subcolumn, Lparasol_column, Lradar_lidar_tcc,                &
    1731             :        Llidar_only_freq_cloud, Lcloudsat_tcc, Lcloudsat_tcc2, cospOUT, errorMessage, nError)
    1732             :     
    1733             :     ! Inputs
    1734             :     type(cosp_column_inputs),intent(in) :: &
    1735             :          cospgridIN       ! Model grid inputs to COSP
    1736             :     type(cosp_optical_inputs),intent(in) :: &
    1737             :          cospIN           ! Derived (optical) input to COSP
    1738             :     
    1739             :     ! Outputs
    1740             :     logical,intent(inout) :: &
    1741             :          Lisccp_subcolumn,    & ! ISCCP subcolumn simulator on/off switch
    1742             :          Lisccp_column,       & ! ISCCP column simulator on/off switch
    1743             :          Lmisr_subcolumn,     & ! MISR subcolumn simulator on/off switch
    1744             :          Lmisr_column,        & ! MISR column simulator on/off switch
    1745             :          Lmodis_subcolumn,    & ! MODIS subcolumn simulator on/off switch
    1746             :          Lmodis_column,       & ! MODIS column simulator on/off switch
    1747             :          Lcloudsat_subcolumn, & ! CLOUDSAT subcolumn simulator on/off switch
    1748             :          Lcloudsat_column,    & ! CLOUDSAT column simulator on/off switch
    1749             :          Lcalipso_subcolumn,  & ! CALIPSO subcolumn simulator on/off switch
    1750             :          Lcalipso_column,     & ! CALIPSO column simulator on/off switch
    1751             :          Latlid_subcolumn,    & ! EarthCare subcolumn simulator on/off switch
    1752             :          Latlid_column,       & ! EarthCare column simulator on/off switch
    1753             :          LgrLidar532_subcolumn, & ! Ground Lidar subcolumn simulator on/off switch
    1754             :          LgrLidar532_column, & ! Ground Lidar column simulator on/off switch
    1755             :          Lparasol_subcolumn,  & ! PARASOL subcolumn simulator on/off switch
    1756             :          Lparasol_column,     & ! PARASOL column simulator on/off switch
    1757             :          Lrttov_subcolumn,    & ! RTTOV subcolumn simulator on/off switch
    1758             :          Lrttov_column,       & ! RTTOV column simulator on/off switch
    1759             :          Lcloudsat_tcc,       & !
    1760             :          Lcloudsat_tcc2,      & !
    1761             :          Lradar_lidar_tcc,    & ! On/Off switch for joint Calipso/Cloudsat product
    1762             :          Llidar_only_freq_cloud ! On/Off switch for joint Calipso/Cloudsat product
    1763             :     type(cosp_outputs),intent(inout) :: &
    1764             :          cospOUT                ! COSP Outputs
    1765             :     character(len=256),dimension(100) :: errorMessage
    1766             :     integer,intent(out) :: nError
    1767             :     
    1768             :     ! Local variables
    1769             :     character(len=100) :: parasolErrorMessage
    1770             :     logical :: alloc_status
    1771             :     
    1772        9288 :     nError = 0
    1773             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1774             :     ! PART 0: Ensure that the inputs needed by the requested simulators are allocated.
    1775             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1776             :     ! ISCCP simulator
    1777        9288 :     if (Lisccp_subcolumn .or. Lisccp_column) then
    1778        9288 :        alloc_status = .true.
    1779        9288 :        if (.not. allocated(cospgridIN%skt)) then
    1780           0 :           nError=nError+1
    1781           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospgridIN%skt has not been allocated'
    1782           0 :           alloc_status = .false.
    1783             :        endif
    1784        9288 :        if (.not. allocated(cospgridIN%qv)) then
    1785           0 :           nError=nError+1
    1786           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospgridIN%qv has not been allocated'
    1787           0 :           alloc_status = .false.
    1788             :        endif
    1789        9288 :        if (.not. allocated(cospgridIN%at)) then
    1790           0 :           nError=nError+1
    1791           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospgridIN%at has not been allocated'
    1792           0 :           alloc_status = .false.
    1793             :        endif
    1794        9288 :        if (.not. allocated(cospIN%frac_out)) then
    1795           0 :           nError=nError+1
    1796           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospIN%frac_out has not been allocated'
    1797           0 :           alloc_status = .false.
    1798             :        endif
    1799        9288 :        if (.not. allocated(cospIN%tau_067)) then
    1800           0 :           nError=nError+1
    1801           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospIN%tau_067 has not been allocated'
    1802           0 :           alloc_status = .false.
    1803             :        endif
    1804        9288 :        if (.not. allocated(cospIN%emiss_11)) then
    1805           0 :           nError=nError+1
    1806           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospIN%emiss_11 has not been allocated'
    1807           0 :           alloc_status = .false.
    1808             :        endif
    1809        9288 :        if (.not. allocated(cospgridIN%phalf)) then
    1810           0 :           nError=nError+1
    1811           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospgridIN%phalf has not been allocated'
    1812           0 :           alloc_status = .false.
    1813             :        endif
    1814        9288 :        if (.not. allocated(cospgridIN%sunlit)) then
    1815           0 :           nError=nError+1
    1816           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospgridIN%sunlit has not been allocated'
    1817           0 :           alloc_status = .false.
    1818             :        endif
    1819        9288 :        if (.not. allocated(cospgridIN%pfull)) then
    1820           0 :           nError=nError+1
    1821           0 :           errorMessage(nError) = 'ERROR: COSP input variable (ISSCP simulator): cospgridIN%pfull has not been allocated'
    1822             :           alloc_status = .false.
    1823             :        endif
    1824        9288 :        if (.not. alloc_status) then
    1825           0 :           Lisccp_subcolumn = .false.
    1826           0 :           Lisccp_column    = .false.
    1827           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    1828           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    1829           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    1830           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    1831           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    1832           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    1833           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    1834           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    1835           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    1836             :        endif
    1837             :     endif
    1838             :     
    1839             :     ! MISR simulator
    1840        9288 :     if (Lmisr_subcolumn .or. Lmisr_column) then
    1841        9288 :        alloc_status = .true.
    1842        9288 :        if (.not. allocated(cospIN%tau_067)) then
    1843           0 :           nError=nError+1
    1844           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MISR simulator): cospIN%tau_067 has not been allocated'
    1845           0 :           alloc_status = .false.
    1846             :        endif
    1847        9288 :        if (.not. allocated(cospgridIN%sunlit)) then
    1848           0 :           nError=nError+1
    1849           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MISR simulator): cospgridIN%sunlit has not been allocated'
    1850           0 :           alloc_status = .false.
    1851             :        endif
    1852        9288 :        if (.not. allocated(cospgridIN%hgt_matrix)) then
    1853           0 :           nError=nError+1
    1854           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MISR simulator): cospgridIN%hgt_matrix has not been allocated'
    1855           0 :           alloc_status = .false.
    1856             :        endif
    1857        9288 :        if (.not. allocated(cospgridIN%at)) then
    1858           0 :           nError=nError+1
    1859           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MISR simulator): cospgridIN%at has not been allocated'
    1860             :           alloc_status = .false.
    1861             :        endif
    1862        9288 :        if (.not. alloc_status) then
    1863           0 :           Lmisr_subcolumn = .false.
    1864           0 :           Lmisr_column    = .false.
    1865           0 :           if (associated(cospOUT%misr_fq))                   cospOUT%misr_fq(:,:,:)                 = R_UNDEF
    1866           0 :           if (associated(cospOUT%misr_dist_model_layertops)) cospOUT%misr_dist_model_layertops(:,:) = R_UNDEF
    1867           0 :           if (associated(cospOUT%misr_meanztop))             cospOUT%misr_meanztop(:)               = R_UNDEF
    1868           0 :           if (associated(cospOUT%misr_cldarea))              cospOUT%misr_cldarea(:)                = R_UNDEF          
    1869             :        endif
    1870             :     endif
    1871             : 
    1872             :     ! EarthCare Lidar simulator.
    1873        9288 :     if (Latlid_subcolumn .or. Latlid_column) then
    1874           0 :        alloc_status = .true.
    1875           0 :        if (.not. allocated(cospIN%beta_mol_atlid)) then
    1876           0 :           nError=nError+1
    1877           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospIN%beta_mol_atlid has not been allocated'
    1878           0 :           alloc_status = .false.
    1879             :        endif
    1880           0 :        if (.not. allocated(cospIN%betatot_atlid)) then
    1881           0 :           nError=nError+1
    1882           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospIN%betatot_atlid has not been allocated'
    1883           0 :           alloc_status = .false.
    1884             :        endif
    1885           0 :        if (.not. allocated(cospIN%tau_mol_atlid)) then
    1886           0 :           nError=nError+1
    1887           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospIN%tau_mol_atlid has not been allocated'
    1888           0 :           alloc_status = .false.
    1889             :        endif
    1890           0 :        if (.not. allocated(cospIN%tautot_atlid)) then
    1891           0 :           nError=nError+1
    1892           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospIN%tautot_atlid has not been allocated'
    1893             :           alloc_status = .false.
    1894             :        endif
    1895           0 :        if (.not. alloc_status) then
    1896           0 :           Latlid_subcolumn = .false.
    1897           0 :           Latlid_column    = .false.
    1898           0 :           if (associated(cospOUT%atlid_cfad_sr))  cospOUT%atlid_cfad_sr(:,:,:)  = R_UNDEF
    1899           0 :           if (associated(cospOUT%atlid_lidarcld)) cospOUT%atlid_lidarcld(:,:)   = R_UNDEF
    1900           0 :           if (associated(cospOUT%atlid_cldlayer)) cospOUT%atlid_cldlayer(:,:)   = R_UNDEF
    1901           0 :           if (associated(cospOUT%atlid_beta_mol)) cospOUT%atlid_beta_mol(:,:)   = R_UNDEF
    1902           0 :           if (associated(cospOUT%atlid_beta_tot)) cospOUT%atlid_beta_tot(:,:,:) = R_UNDEF
    1903             :        endif
    1904             :        
    1905             :        ! EarthCare column simulator requires additional inputs not required by the subcolumn simulator.
    1906           0 :        alloc_status = .true.
    1907           0 :        if (.not. allocated(cospgridIN%hgt_matrix)) then
    1908           0 :           nError=nError+1
    1909           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospgridIN%hgt_matrix has not been allocated'
    1910           0 :           alloc_status = .false.
    1911             :        endif
    1912           0 :        if (.not. allocated(cospgridIN%hgt_matrix_half)) then
    1913           0 :           nError=nError+1
    1914           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospgridIN%hgt_matrix_half has not been allocated'
    1915           0 :           alloc_status = .false.
    1916             :        endif
    1917           0 :        if (.not. allocated(cospgridIN%phalf)) then
    1918           0 :           nError=nError+1
    1919           0 :           errorMessage(nError) = 'ERROR: COSP input variable (EarthCare Lidar simulator): cospgridIN%phalf has not been allocated'
    1920             :           alloc_status = .false.
    1921             :        endif
    1922           0 :        if (.not. alloc_status) then
    1923           0 :           Latlid_column  = .false.
    1924           0 :           if (associated(cospOUT%atlid_cfad_sr)) cospOUT%atlid_cfad_sr(:,:,:) = R_UNDEF
    1925             :        endif
    1926             :     endif
    1927             : 
    1928             :     ! Ground Lidar simulator.
    1929        9288 :     if (LgrLidar532_subcolumn .or. LgrLidar532_column) then
    1930           0 :        alloc_status = .true.
    1931           0 :        if (.not. allocated(cospIN%beta_mol_grLidar532)) then
    1932           0 :           nError=nError+1
    1933           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospIN%beta_mol_grLidar532 has not been allocated'
    1934           0 :           alloc_status = .false.
    1935             :        endif
    1936           0 :        if (.not. allocated(cospIN%betatot_grLidar532)) then
    1937           0 :           nError=nError+1
    1938           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospIN%betatot_grLidar532 has not been allocated'
    1939           0 :           alloc_status = .false.
    1940             :        endif
    1941           0 :        if (.not. allocated(cospIN%tau_mol_grLidar532)) then
    1942           0 :           nError=nError+1
    1943           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospIN%tau_mol_grLidar532 has not been allocated'
    1944           0 :           alloc_status = .false.
    1945             :        endif
    1946           0 :        if (.not. allocated(cospIN%tautot_grLidar532)) then
    1947           0 :           nError=nError+1
    1948           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospIN%tautot_grLidar532 has not been allocated'
    1949             :           alloc_status = .false.
    1950             :        endif
    1951           0 :        if (.not. alloc_status) then
    1952           0 :           LgrLidar532_subcolumn = .false.
    1953           0 :           LgrLidar532_column    = .false.
    1954           0 :           if (associated(cospOUT%grLidar532_cfad_sr))  cospOUT%grLidar532_cfad_sr(:,:,:)  = R_UNDEF
    1955           0 :           if (associated(cospOUT%grLidar532_lidarcld)) cospOUT%grLidar532_lidarcld(:,:)   = R_UNDEF
    1956           0 :           if (associated(cospOUT%grLidar532_cldlayer)) cospOUT%grLidar532_cldlayer(:,:)   = R_UNDEF
    1957           0 :           if (associated(cospOUT%grLidar532_beta_mol)) cospOUT%grLidar532_beta_mol(:,:)   = R_UNDEF
    1958           0 :           if (associated(cospOUT%grLidar532_beta_tot)) cospOUT%grLidar532_beta_tot(:,:,:) = R_UNDEF
    1959             :        endif
    1960             :        
    1961             :        ! Ground Lidar column simulator requires additional inputs not required by the subcolumn simulator.
    1962           0 :        alloc_status = .true.
    1963           0 :        if (.not. allocated(cospgridIN%hgt_matrix)) then
    1964           0 :           nError=nError+1
    1965           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospgridIN%hgt_matrix has not been allocated'
    1966           0 :           alloc_status = .false.
    1967             :        endif
    1968           0 :        if (.not. allocated(cospgridIN%hgt_matrix_half)) then
    1969           0 :           nError=nError+1
    1970           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospgridIN%hgt_matrix_half has not been allocated'
    1971           0 :           alloc_status = .false.
    1972             :        endif
    1973           0 :        if (.not. allocated(cospgridIN%phalf)) then
    1974           0 :           nError=nError+1
    1975           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Ground Lidar simulator): cospgridIN%phalf has not been allocated'
    1976             :           alloc_status = .false.
    1977             :        endif
    1978           0 :        if (.not. alloc_status) then
    1979           0 :           LgrLidar532_column  = .false.
    1980           0 :           if (associated(cospOUT%grLidar532_cfad_sr)) cospOUT%grLidar532_cfad_sr(:,:,:) = R_UNDEF
    1981             :        endif
    1982             :     endif
    1983             :     
    1984             :     ! Calipso Lidar simulator
    1985        9288 :     if (Lcalipso_subcolumn .or. Lcalipso_column) then
    1986        9288 :        alloc_status = .true.
    1987        9288 :        if (.not. allocated(cospIN%beta_mol_calipso)) then
    1988           0 :           nError=nError+1
    1989           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator): cospIN%beta_mol_calipso has not been allocated'
    1990           0 :           alloc_status = .false.
    1991             :        endif
    1992        9288 :        if (.not. allocated(cospIN%betatot_calipso)) then
    1993           0 :           nError=nError+1
    1994           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator): cospIN%betatot_calipso has not been allocated'
    1995           0 :           alloc_status = .false.
    1996             :        endif
    1997        9288 :        if (.not. allocated(cospIN%betatot_liq_calipso)) then
    1998           0 :           nError=nError+1
    1999           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator):'//&
    2000           0 :                ' cospIN%betatot_liq_calipso has not been allocated'
    2001           0 :           alloc_status = .false.
    2002             :        endif
    2003        9288 :        if (.not. allocated(cospIN%betatot_ice_calipso)) then
    2004           0 :           nError=nError+1
    2005           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator):'//&
    2006           0 :                ' cospIN%betatot_ice_calipso has not been allocated'
    2007           0 :           alloc_status = .false.
    2008             :        endif
    2009        9288 :        if (.not. allocated(cospIN%tau_mol_calipso)) then
    2010           0 :           nError=nError+1
    2011           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator): cospIN%tau_mol_calipso has not been allocated'
    2012           0 :           alloc_status = .false.
    2013             :        endif
    2014        9288 :        if (.not. allocated(cospIN%tautot_calipso)) then
    2015           0 :           nError=nError+1
    2016           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator): cospIN%tautot_calipso has not been allocated'
    2017           0 :           alloc_status = .false.
    2018             :        endif
    2019        9288 :        if (.not. allocated(cospIN%tautot_liq_calipso)) then
    2020           0 :           nError=nError+1
    2021           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator):'//&
    2022           0 :                ' cospIN%tautot_liq has not been allocated'
    2023           0 :           alloc_status = .false.
    2024             :        endif
    2025        9288 :        if (.not. allocated(cospIN%tautot_ice_calipso)) then
    2026           0 :           nError=nError+1
    2027           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator):'//&
    2028           0 :                ' cospIN%tautot_ice has not been allocated'
    2029             :           alloc_status = .false.
    2030             :        endif
    2031        9288 :        if (.not. alloc_status) then
    2032           0 :           Lcalipso_subcolumn = .false.
    2033           0 :           Lcalipso_column    = .false.
    2034           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    2035           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    2036           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    2037           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    2038           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    2039           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    2040           0 :           if (associated(cospOUT%calipso_beta_mol))      cospOUT%calipso_beta_mol(:,:)        = R_UNDEF
    2041           0 :           if (associated(cospOUT%calipso_beta_tot))      cospOUT%calipso_beta_tot(:,:,:)      = R_UNDEF
    2042           0 :           if (associated(cospOUT%calipso_betaperp_tot))  cospOUT%calipso_betaperp_tot(:,:,:)  = R_UNDEF
    2043             :           ! Also, turn-off joint-products 
    2044           0 :           if (Lradar_lidar_tcc) then
    2045           0 :              Lradar_lidar_tcc = .false.
    2046           0 :              if (associated(cospOUT%radar_lidar_tcc)) cospOUT%radar_lidar_tcc(:) = R_UNDEF
    2047             :           endif
    2048           0 :           if (Lcloudsat_tcc) then
    2049           0 :              Lcloudsat_tcc = .false.
    2050           0 :              if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    2051             :           endif
    2052           0 :           if (Lcloudsat_tcc2) then
    2053           0 :              Lcloudsat_tcc2 = .false.
    2054           0 :              if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    2055             :           endif
    2056           0 :           if (Llidar_only_freq_cloud) then
    2057           0 :              Llidar_only_freq_cloud = .false.
    2058           0 :              if (associated(cospOUT%lidar_only_freq_cloud)) cospOUT%lidar_only_freq_cloud(:,:) = R_UNDEF
    2059             :           endif
    2060             :        endif
    2061             :        
    2062             :        ! Calipso column simulator requires additional inputs not required by the subcolumn simulator.
    2063        9288 :        alloc_status = .true.
    2064        9288 :        if (.not. allocated(cospgridIN%hgt_matrix)) then
    2065           0 :           nError=nError+1
    2066           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator):'//&
    2067           0 :                ' cospgridIN%hgt_matrix has not been allocated'
    2068           0 :           alloc_status = .false.
    2069             :        endif
    2070        9288 :        if (.not. allocated(cospgridIN%hgt_matrix_half)) then
    2071           0 :           nError=nError+1
    2072           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator):'//&
    2073           0 :                ' cospgridIN%hgt_matrix_half has not been allocated'
    2074           0 :           alloc_status = .false.
    2075             :        endif
    2076        9288 :        if (.not. allocated(cospgridIN%at)) then
    2077           0 :           nError=nError+1
    2078           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator): cospgridIN%at has not been allocated'
    2079           0 :           alloc_status = .false.
    2080             :        endif
    2081        9288 :        if (.not. allocated(cospgridIN%phalf)) then
    2082           0 :           nError=nError+1
    2083           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Calipso Lidar simulator): cospgridIN%phalf has not been allocated'
    2084             :           alloc_status = .false.
    2085             :        endif
    2086        9288 :        if (.not. alloc_status) then
    2087           0 :           Lcalipso_column  = .false.
    2088           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    2089           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    2090           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    2091           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    2092           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    2093           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    2094           0 :           if (Lcloudsat_tcc) then
    2095           0 :              Lcloudsat_tcc = .false.
    2096           0 :              if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    2097             :           endif
    2098           0 :           if (Lcloudsat_tcc2) then
    2099           0 :              Lcloudsat_tcc2 = .false.
    2100           0 :              if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    2101             :           endif
    2102             :           ! Also, turn-off joint-products 
    2103           0 :           if (Lradar_lidar_tcc) then
    2104           0 :              Lradar_lidar_tcc = .false.
    2105           0 :              if (associated(cospOUT%radar_lidar_tcc)) cospOUT%radar_lidar_tcc(:) = R_UNDEF
    2106             :           endif
    2107           0 :           if (Llidar_only_freq_cloud) then
    2108           0 :              Llidar_only_freq_cloud = .false.
    2109           0 :              if (associated(cospOUT%lidar_only_freq_cloud)) cospOUT%lidar_only_freq_cloud(:,:) = R_UNDEF
    2110             :           endif
    2111             :        endif
    2112             :     endif
    2113             :     
    2114             :     ! PARASOL simulator
    2115        9288 :     if (Lparasol_subcolumn .or. Lparasol_column) then
    2116        9288 :        alloc_status = .true.
    2117        9288 :        if (.not. allocated(cospIN%tautot_S_liq)) then
    2118           0 :           nError=nError+1
    2119           0 :           errorMessage(nError) = 'ERROR: COSP input variable (PARASOL simulator): cospIN%tautot_S_liq has not been allocated'
    2120           0 :           alloc_status = .false.
    2121             :        endif
    2122        9288 :        if (.not. allocated(cospIN%tautot_S_ice)) then
    2123           0 :           nError=nError+1
    2124           0 :           errorMessage(nError) = 'ERROR: COSP input variable (PARASOL simulator): cospIN%tautot_S_ice has not been allocated'
    2125             :           alloc_status = .false.
    2126             :        endif
    2127        9288 :        if (.not. alloc_status) then
    2128           0 :           Lparasol_subcolumn  = .false.
    2129           0 :           Lparasol_column     = .false.
    2130           0 :           if (associated(cospOUT%parasolPix_refl))  cospOUT%parasolPix_refl(:,:,:) = R_UNDEF
    2131           0 :           if (associated(cospOUT%parasolGrid_refl)) cospOUT%parasolGrid_refl(:,:)  = R_UNDEF
    2132             :        endif
    2133             :        
    2134             :        ! PARASOL column simulator requires additional inputs not required by the subcolumn simulator.
    2135        9288 :        alloc_status = .true.
    2136        9288 :        if (.not. allocated(cospgridIN%land)) then
    2137           0 :           nError=nError+1
    2138           0 :           errorMessage(nError) = 'ERROR: COSP input variable (PARASOL simulator): cospgridIN%land has not been allocated'
    2139             :           alloc_status = .false.
    2140             :        endif
    2141             :        if (.not. alloc_status) then
    2142           0 :           Lparasol_column  = .false.
    2143           0 :           if (associated(cospOUT%parasolGrid_refl)) cospOUT%parasolGrid_refl(:,:)  = R_UNDEF
    2144             :        endif
    2145             :     endif
    2146             :     
    2147             :     ! Cloudsat radar simulator
    2148        9288 :     if (Lcloudsat_subcolumn .or. Lcloudsat_column) then
    2149        9288 :        alloc_status = .true.
    2150        9288 :        if (.not. allocated(cospIN%z_vol_cloudsat)) then
    2151           0 :           nError=nError+1
    2152           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Cloudsat radar simulator):'//&
    2153           0 :                ' cospIN%z_vol_cloudsat has not been allocated'
    2154           0 :           alloc_status = .false.
    2155             :        endif
    2156        9288 :        if (.not. allocated(cospIN%kr_vol_cloudsat)) then
    2157           0 :           nError=nError+1
    2158           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Cloudsat radar simulator):'//&
    2159           0 :                ' cospIN%kr_vol_cloudsat has not been allocated'
    2160           0 :           alloc_status = .false.
    2161             :        endif
    2162        9288 :        if (.not. allocated(cospIN%g_vol_cloudsat)) then
    2163           0 :           nError=nError+1
    2164           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Cloudsat radar simulator):'//&
    2165           0 :                ' cospIN%g_vol_cloudsat has not been allocated'
    2166           0 :           alloc_status = .false.
    2167             :        endif
    2168        9288 :        if (.not. allocated(cospgridIN%hgt_matrix)) then
    2169           0 :           nError=nError+1
    2170           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Cloudsat radar simulator):'//&
    2171           0 :                ' cospgridIN%hgt_matrix has not been allocated'
    2172             :           alloc_status = .false.
    2173             :        endif
    2174        9288 :        if (.not. alloc_status) then
    2175           0 :           Lcloudsat_subcolumn  = .false.
    2176           0 :           Lcloudsat_column     = .false.
    2177           0 :           if (associated(cospOUT%cloudsat_cfad_ze)) cospOUT%cloudsat_cfad_ze(:,:,:) = R_UNDEF
    2178           0 :           if (associated(cospOUT%cloudsat_Ze_tot))  cospOUT%cloudsat_Ze_tot(:,:,:)  = R_UNDEF
    2179           0 :           if (Lcloudsat_tcc) then
    2180           0 :              Lcloudsat_tcc = .false.
    2181           0 :              if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    2182             :           endif
    2183           0 :           if (Lcloudsat_tcc2) then
    2184           0 :              Lcloudsat_tcc2 = .false.
    2185           0 :              if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    2186             :           endif
    2187             :           ! Also, turn-off joint-products 
    2188           0 :           if (Lradar_lidar_tcc) then
    2189           0 :              Lradar_lidar_tcc = .false.
    2190           0 :              if (associated(cospOUT%radar_lidar_tcc)) cospOUT%radar_lidar_tcc(:) = R_UNDEF
    2191             :           endif
    2192           0 :           if (Llidar_only_freq_cloud) then
    2193           0 :              Llidar_only_freq_cloud = .false.
    2194           0 :              if (associated(cospOUT%lidar_only_freq_cloud)) cospOUT%lidar_only_freq_cloud(:,:) = R_UNDEF
    2195             :           endif
    2196             :        endif
    2197             :        
    2198             :        ! Cloudsat column simulator requires additional inputs not required by the subcolumn simulator.
    2199        9288 :        alloc_status = .true.
    2200        9288 :        if (.not. allocated(cospgridIN%hgt_matrix_half)) then
    2201           0 :           nError=nError+1
    2202           0 :           errorMessage(nError) = 'ERROR: COSP input variable (Cloudsat radar simulator):'//&
    2203           0 :                ' cospgridIN%hgt_matrix_half has not been allocated'
    2204             :           alloc_status = .false.
    2205             :        endif
    2206             :        if (.not. alloc_status) then
    2207           0 :           Lcloudsat_column  = .false.
    2208           0 :           if (associated(cospOUT%cloudsat_cfad_ze))      cospOUT%cloudsat_cfad_ze(:,:,:)    = R_UNDEF
    2209           0 :           if (Lcloudsat_tcc) then
    2210           0 :              Lcloudsat_tcc = .false.
    2211           0 :              if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    2212             :           endif
    2213           0 :           if (Lcloudsat_tcc2) then
    2214           0 :              Lcloudsat_tcc2 = .false.
    2215           0 :              if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    2216             :           endif
    2217             :           ! Also, turn-off joint-products 
    2218           0 :           if (Lradar_lidar_tcc) then
    2219           0 :              Lradar_lidar_tcc = .false.
    2220           0 :              if (associated(cospOUT%radar_lidar_tcc)) cospOUT%radar_lidar_tcc(:) = R_UNDEF
    2221             :           endif
    2222           0 :           if (Llidar_only_freq_cloud) then
    2223           0 :              Llidar_only_freq_cloud = .false.
    2224           0 :              if (associated(cospOUT%lidar_only_freq_cloud)) cospOUT%lidar_only_freq_cloud(:,:) = R_UNDEF
    2225             :           endif
    2226             :        endif
    2227             :     endif
    2228             :     
    2229             :     ! MODIS simulator
    2230        9288 :     if (Lmodis_subcolumn .or. Lmodis_column) then
    2231        9288 :        alloc_status = .true.
    2232        9288 :        if (.not. allocated(cospIN%fracLiq)) then
    2233           0 :           nError=nError+1
    2234           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MODIS simulator): cospIN%fracLiq has not been allocated'
    2235           0 :           alloc_status = .false.
    2236             :        endif
    2237        9288 :        if (.not. allocated(cospIN%tau_067)) then
    2238           0 :           nError=nError+1
    2239           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MODIS simulator): cospIN%tau_067 has not been allocated'
    2240           0 :           alloc_status = .false.
    2241             :        endif
    2242        9288 :        if (.not. allocated(cospIN%asym)) then
    2243           0 :           nError=nError+1
    2244           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MODIS simulator): cospIN%asym has not been allocated'
    2245           0 :           alloc_status = .false.
    2246             :        endif
    2247        9288 :        if (.not. allocated(cospIN%ss_alb)) then
    2248           0 :           nError=nError+1
    2249           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MODIS simulator): cospIN%ss_alb has not been allocated'
    2250           0 :           alloc_status = .false.
    2251             :        endif
    2252        9288 :        if (.not. allocated(cospgridIN%sunlit)) then
    2253           0 :           nError=nError+1
    2254           0 :           errorMessage(nError) = 'ERROR: COSP input variable (MODIS simulator): cospgridIN%sunlit has not been allocated'
    2255             :           alloc_status = .false.
    2256             :        endif
    2257        9288 :        if (.not. alloc_status) then
    2258           0 :           Lmodis_subcolumn  = .false.
    2259           0 :           Lmodis_column     = .false.
    2260           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                          &
    2261           0 :                cospOUT%modis_Cloud_Fraction_Total_Mean(:)                   = R_UNDEF
    2262           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                          &
    2263           0 :                cospOUT%modis_Cloud_Fraction_Water_Mean(:)                   = R_UNDEF
    2264           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                            &
    2265           0 :                cospOUT%modis_Cloud_Fraction_Ice_Mean(:)                     = R_UNDEF
    2266           0 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                           &
    2267           0 :                cospOUT%modis_Cloud_Fraction_High_Mean(:)                    = R_UNDEF
    2268           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                            &
    2269           0 :                cospOUT%modis_Cloud_Fraction_Mid_Mean(:)                     = R_UNDEF
    2270           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                            &
    2271           0 :                cospOUT%modis_Cloud_Fraction_Low_Mean(:)                     = R_UNDEF
    2272           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                       &
    2273           0 :                cospOUT%modis_Optical_Thickness_Total_Mean(:)                = R_UNDEF
    2274           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                       &
    2275           0 :                cospOUT%modis_Optical_Thickness_Water_Mean(:)                = R_UNDEF
    2276           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                         &
    2277           0 :                cospOUT%modis_Optical_Thickness_Ice_Mean(:)                  = R_UNDEF
    2278           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                    &
    2279           0 :                cospOUT%modis_Optical_Thickness_Total_LogMean(:)             = R_UNDEF
    2280           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                    &
    2281           0 :                cospOUT%modis_Optical_Thickness_Water_LogMean(:)             = R_UNDEF
    2282           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                      &
    2283           0 :                cospOUT%modis_Optical_Thickness_Ice_LogMean(:)               = R_UNDEF
    2284           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                     &
    2285           0 :                cospOUT%modis_Cloud_Particle_Size_Water_Mean(:)              = R_UNDEF
    2286           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                       &
    2287           0 :                cospOUT%modis_Cloud_Particle_Size_Ice_Mean(:)                = R_UNDEF
    2288           0 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                      &
    2289           0 :                cospOUT%modis_Cloud_Top_Pressure_Total_Mean(:)               = R_UNDEF
    2290           0 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                             &
    2291           0 :                cospOUT%modis_Liquid_Water_Path_Mean(:)                      = R_UNDEF
    2292           0 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                                &
    2293           0 :                cospOUT%modis_Ice_Water_Path_Mean(:)                         = R_UNDEF
    2294           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))            &
    2295           0 :                cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,:,:) = R_UNDEF
    2296           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffICE))                       &
    2297           0 :                cospOUT%modis_Optical_Thickness_vs_ReffICE(:,:,:)            = R_UNDEF
    2298           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLIQ))                       &
    2299           0 :                cospOUT%modis_Optical_Thickness_vs_ReffLIQ(:,:,:)            = R_UNDEF          
    2300             :        endif
    2301             :     endif
    2302             :     
    2303             :     ! RTTOV
    2304        9288 :     if (Lrttov_column) then
    2305           0 :        alloc_status = .true.
    2306           0 :        if (.not. allocated(cospgridIN%emis_sfc)) then
    2307           0 :           nError=nError+1
    2308           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%emis_sfc has not been allocated'
    2309           0 :           alloc_status = .false.
    2310             :        endif
    2311           0 :        if (.not. allocated(cospgridIN%hgt_matrix_half)) then
    2312           0 :           nError=nError+1
    2313           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%emis_sfc has not been allocated'
    2314           0 :           alloc_status = .false.
    2315             :        endif
    2316           0 :        if (.not. allocated(cospgridIN%u_sfc)) then
    2317           0 :           nError=nError+1
    2318           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%u_sfc has not been allocated'
    2319           0 :           alloc_status = .false.
    2320             :        endif
    2321           0 :        if (.not. allocated(cospgridIN%v_sfc)) then
    2322           0 :           nError=nError+1
    2323           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%v_sfc has not been allocated'
    2324           0 :           alloc_status = .false.
    2325             :        endif
    2326           0 :        if (.not. allocated(cospgridIN%skt)) then
    2327           0 :           nError=nError+1
    2328           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%skt has not been allocated'
    2329           0 :           alloc_status = .false.
    2330             :        endif
    2331           0 :        if (.not. allocated(cospgridIN%phalf)) then
    2332           0 :           nError=nError+1
    2333           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%phalf has not been allocated'
    2334           0 :           alloc_status = .false.
    2335             :        endif
    2336           0 :        if (.not. allocated(cospgridIN%qv)) then
    2337           0 :           nError=nError+1
    2338           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%qv has not been allocated'
    2339           0 :           alloc_status = .false.
    2340             :        endif
    2341           0 :        if (.not. allocated(cospgridIN%at)) then
    2342           0 :           nError=nError+1
    2343           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%at has not been allocated'
    2344           0 :           alloc_status = .false.
    2345             :        endif
    2346           0 :        if (.not. allocated(cospgridIN%land)) then
    2347           0 :           nError=nError+1
    2348           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%land has not been allocated'
    2349           0 :           alloc_status = .false.
    2350             :        endif
    2351           0 :        if (.not. allocated(cospgridIN%lat)) then
    2352           0 :           nError=nError+1
    2353           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%lat has not been allocated'
    2354           0 :           alloc_status = .false.
    2355             :        endif
    2356           0 :        if (.not. allocated(cospgridIN%lon)) then
    2357           0 :           nError=nError+1
    2358           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%lon has not been allocated'
    2359           0 :           alloc_status = .false.
    2360             :        endif
    2361           0 :        if (.not. allocated(cospgridIN%seaice)) then
    2362           0 :           nError=nError+1
    2363           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%seaice has not been allocated'
    2364           0 :           alloc_status = .false.
    2365             :        endif
    2366           0 :        if (.not. allocated(cospgridIN%pfull)) then
    2367           0 :           nError=nError+1
    2368           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%pfull has not been allocated'
    2369           0 :           alloc_status = .false.
    2370             :        endif
    2371           0 :        if (.not. allocated(cospgridIN%phalf)) then
    2372           0 :           nError=nError+1
    2373           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%phalf has not been allocated'
    2374           0 :           alloc_status = .false.
    2375             :        endif
    2376           0 :        if (.not. allocated(cospgridIN%at)) then
    2377           0 :           nError=nError+1
    2378           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%at has not been allocated'
    2379           0 :           alloc_status = .false.
    2380             :        endif
    2381           0 :        if (.not. allocated(cospgridIN%qv)) then
    2382           0 :           nError=nError+1
    2383           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%qv has not been allocated'
    2384           0 :           alloc_status = .false.
    2385             :        endif
    2386           0 :        if (.not. allocated(cospgridIN%o3)) then
    2387           0 :           nError=nError+1
    2388           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%o3 has not been allocated'
    2389           0 :           alloc_status = .false.
    2390             :        endif
    2391           0 :        if (.not. allocated(cospgridIN%tca)) then
    2392           0 :           nError=nError+1
    2393           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%tca has not been allocated'
    2394           0 :           alloc_status = .false.
    2395             :        endif
    2396           0 :        if (.not. allocated(cospgridIN%cloudIce)) then
    2397           0 :           nError=nError+1
    2398           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%cloudIce has not been allocated'
    2399           0 :           alloc_status = .false.
    2400             :        endif
    2401           0 :        if (.not. allocated(cospgridIN%cloudLiq)) then
    2402           0 :           nError=nError+1
    2403           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%cloudLiq has not been allocated'
    2404           0 :           alloc_status = .false.
    2405             :        endif
    2406           0 :        if (.not. allocated(cospgridIN%fl_rain)) then
    2407           0 :           nError=nError+1
    2408           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%fl_rain has not been allocated'
    2409           0 :           alloc_status = .false.
    2410             :        endif
    2411           0 :        if (.not. allocated(cospgridIN%fl_snow)) then
    2412           0 :           nError=nError+1
    2413           0 :           errorMessage(nError) = 'ERROR: COSP input variable (RTTOV): cospgridIN%fl_snow has not been allocated'
    2414             :           alloc_status = .false.
    2415             :        endif
    2416           0 :        if (.not. alloc_status) then
    2417           0 :           Lrttov_column     = .false.
    2418           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:)         = R_UNDEF          
    2419             :        endif
    2420             :     endif
    2421             :     
    2422             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2423             :     ! PART 1: Check input array values for out-of-bounds values. When an out-of-bound value
    2424             :     !         is encountered, COSP outputs that are dependent on that input are filled with
    2425             :     !         an undefined value (set in cosp_config.f90) and if necessary, that simulator
    2426             :     !         is turned off.
    2427             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2428        9288 :     if (any([Lisccp_subcolumn, Lisccp_column, Lmisr_subcolumn, Lmisr_column, Lmodis_subcolumn, Lmodis_column])) then
    2429      155088 :        if (any(cospgridIN%sunlit .lt. 0)) then
    2430           0 :           nError=nError+1
    2431           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%sunlit contains values out of range (0 or 1)'
    2432           0 :           Lisccp_subcolumn = .false.
    2433           0 :           Lisccp_column    = .false.
    2434           0 :           Lmisr_subcolumn  = .false.
    2435           0 :           Lmisr_column     = .false.
    2436           0 :           Lmodis_subcolumn = .false.
    2437           0 :           Lmodis_column    = .false.
    2438           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2439           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2440           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2441           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2442           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2443           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2444           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2445           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2446           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2447           0 :           if (associated(cospOUT%misr_fq))                   cospOUT%misr_fq(:,:,:)                 = R_UNDEF
    2448           0 :           if (associated(cospOUT%misr_dist_model_layertops)) cospOUT%misr_dist_model_layertops(:,:) = R_UNDEF
    2449           0 :           if (associated(cospOUT%misr_meanztop))             cospOUT%misr_meanztop(:)               = R_UNDEF
    2450           0 :           if (associated(cospOUT%misr_cldarea))              cospOUT%misr_cldarea(:)                = R_UNDEF
    2451           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                          &
    2452           0 :                cospOUT%modis_Cloud_Fraction_Total_Mean(:)                   = R_UNDEF
    2453           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                          &
    2454           0 :                cospOUT%modis_Cloud_Fraction_Water_Mean(:)                   = R_UNDEF
    2455           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                            &
    2456           0 :                cospOUT%modis_Cloud_Fraction_Ice_Mean(:)                     = R_UNDEF
    2457           0 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                           &
    2458           0 :                cospOUT%modis_Cloud_Fraction_High_Mean(:)                    = R_UNDEF
    2459           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                            &
    2460           0 :                cospOUT%modis_Cloud_Fraction_Mid_Mean(:)                     = R_UNDEF
    2461           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                            &
    2462           0 :                cospOUT%modis_Cloud_Fraction_Low_Mean(:)                     = R_UNDEF
    2463           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                       &
    2464           0 :                cospOUT%modis_Optical_Thickness_Total_Mean(:)                = R_UNDEF
    2465           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                       &
    2466           0 :                cospOUT%modis_Optical_Thickness_Water_Mean(:)                = R_UNDEF
    2467           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                         &
    2468           0 :                cospOUT%modis_Optical_Thickness_Ice_Mean(:)                  = R_UNDEF
    2469           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                    &
    2470           0 :                cospOUT%modis_Optical_Thickness_Total_LogMean(:)             = R_UNDEF
    2471           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                    &
    2472           0 :                cospOUT%modis_Optical_Thickness_Water_LogMean(:)             = R_UNDEF
    2473           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                      &
    2474           0 :                cospOUT%modis_Optical_Thickness_Ice_LogMean(:)               = R_UNDEF
    2475           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                     &
    2476           0 :                cospOUT%modis_Cloud_Particle_Size_Water_Mean(:)              = R_UNDEF
    2477           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                       &
    2478           0 :                cospOUT%modis_Cloud_Particle_Size_Ice_Mean(:)                = R_UNDEF
    2479           0 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                      &
    2480           0 :                cospOUT%modis_Cloud_Top_Pressure_Total_Mean(:)               = R_UNDEF
    2481           0 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                             &
    2482           0 :                cospOUT%modis_Liquid_Water_Path_Mean(:)                      = R_UNDEF
    2483           0 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                                &
    2484           0 :                cospOUT%modis_Ice_Water_Path_Mean(:)                         = R_UNDEF
    2485           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))            &
    2486           0 :                cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,:,:) = R_UNDEF
    2487           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffICE))                       &
    2488           0 :                cospOUT%modis_Optical_Thickness_vs_ReffICE(:,:,:)            = R_UNDEF
    2489           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLIQ))                       &
    2490           0 :                cospOUT%modis_Optical_Thickness_vs_ReffLIQ(:,:,:)            = R_UNDEF
    2491             :        endif
    2492             :     endif
    2493             : 
    2494        9288 :     if (any([Lisccp_subcolumn, Lisccp_column, Lmisr_subcolumn, Lmisr_column, Lrttov_column,&
    2495             :          Lcalipso_column, Lcloudsat_column, Lradar_lidar_tcc,Llidar_only_freq_cloud, &
    2496             :          Lcloudsat_tcc, Lcloudsat_tcc2])) then
    2497    13036680 :        if (any(cospgridIN%at .lt. 0)) then
    2498           0 :           nError=nError+1
    2499           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%at contains values out of range (at<0), expected units (K)'
    2500           0 :           Lisccp_subcolumn = .false.
    2501           0 :           Lisccp_column    = .false.
    2502           0 :           Lmisr_subcolumn  = .false.
    2503           0 :           Lmisr_column     = .false.
    2504           0 :           Lrttov_column    = .false.
    2505           0 :           Lcalipso_column  = .false.
    2506           0 :           Lcloudsat_column = .false.
    2507           0 :           Lradar_lidar_tcc = .false.
    2508           0 :           Llidar_only_freq_cloud = .false.
    2509           0 :           Lcloudsat_tcc    = .false.
    2510           0 :           Lcloudsat_tcc2   = .false.
    2511           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:)         = R_UNDEF
    2512           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2513           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2514           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2515           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2516           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2517           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2518           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2519           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2520           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2521           0 :           if (associated(cospOUT%misr_fq))                   cospOUT%misr_fq(:,:,:)                 = R_UNDEF
    2522           0 :           if (associated(cospOUT%misr_dist_model_layertops)) cospOUT%misr_dist_model_layertops(:,:) = R_UNDEF
    2523           0 :           if (associated(cospOUT%misr_meanztop))             cospOUT%misr_meanztop(:)               = R_UNDEF
    2524           0 :           if (associated(cospOUT%misr_cldarea))              cospOUT%misr_cldarea(:)                = R_UNDEF
    2525           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    2526           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    2527           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    2528           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    2529           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    2530           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    2531           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    2532           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    2533           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    2534           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF 
    2535           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF 
    2536           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    2537           0 :           if (associated(cospOUT%cloudsat_cfad_ze))      cospOUT%cloudsat_cfad_ze(:,:,:)      = R_UNDEF
    2538           0 :           if (associated(cospOUT%lidar_only_freq_cloud)) cospOUT%lidar_only_freq_cloud(:,:)   = R_UNDEF
    2539           0 :           if (associated(cospOUT%radar_lidar_tcc))       cospOUT%radar_lidar_tcc(:)           = R_UNDEF
    2540           0 :           if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    2541           0 :           if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    2542             :        endif
    2543             :     endif
    2544        9288 :     if (any([Lisccp_subcolumn, Lisccp_column, Lrttov_column])) then
    2545    13036680 :        if (any(cospgridIN%pfull .lt. 0)) then
    2546           0 :           nError=nError+1
    2547           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%pfull contains values out of range'
    2548           0 :           Lisccp_subcolumn = .false.
    2549           0 :           Lisccp_column    = .false.
    2550           0 :           Lrttov_column    = .false.
    2551           0 :           if (associated(cospOUT%rttov_tbs))           cospOUT%rttov_tbs(:,:)         = R_UNDEF
    2552           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2553           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2554           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2555           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2556           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2557           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2558           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2559           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2560           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2561             :        endif
    2562             :     endif
    2563        9288 :     if (any([Lisccp_subcolumn,Lisccp_column,Lmodis_subcolumn,Lmodis_column,Lcalipso_column,Lrttov_column,&
    2564             :              LgrLidar532_column,Latlid_column])) then
    2565    13191768 :        if (any(cospgridIN%phalf .lt. 0)) then
    2566           0 :           nError=nError+1
    2567           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%phalf contains values out of range'
    2568           0 :           Lisccp_subcolumn = .false.
    2569           0 :           Lisccp_column    = .false.
    2570           0 :           Lmodis_subcolumn = .false.
    2571           0 :           Lmodis_column    = .false.
    2572           0 :           Lcalipso_column  = .false.
    2573           0 :           Lrttov_column    = .false.
    2574           0 :           Latlid_column    = .false.
    2575           0 :           LgrLidar532_column = .false.
    2576           0 :           if (associated(cospOUT%rttov_tbs))           cospOUT%rttov_tbs(:,:)         = R_UNDEF
    2577           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2578           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2579           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2580           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2581           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2582           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2583           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2584           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2585           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2586           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                          &
    2587           0 :                cospOUT%modis_Cloud_Fraction_Total_Mean(:)                   = R_UNDEF
    2588           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                          &
    2589           0 :                cospOUT%modis_Cloud_Fraction_Water_Mean(:)                   = R_UNDEF
    2590           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                            &
    2591           0 :                cospOUT%modis_Cloud_Fraction_Ice_Mean(:)                     = R_UNDEF
    2592           0 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                           &
    2593           0 :                cospOUT%modis_Cloud_Fraction_High_Mean(:)                    = R_UNDEF
    2594           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                            &
    2595           0 :                cospOUT%modis_Cloud_Fraction_Mid_Mean(:)                     = R_UNDEF
    2596           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                            &
    2597           0 :                cospOUT%modis_Cloud_Fraction_Low_Mean(:)                     = R_UNDEF
    2598           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                       &
    2599           0 :                cospOUT%modis_Optical_Thickness_Total_Mean(:)                = R_UNDEF
    2600           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                       &
    2601           0 :                cospOUT%modis_Optical_Thickness_Water_Mean(:)                = R_UNDEF
    2602           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                         &
    2603           0 :                cospOUT%modis_Optical_Thickness_Ice_Mean(:)                  = R_UNDEF
    2604           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                    &
    2605           0 :                cospOUT%modis_Optical_Thickness_Total_LogMean(:)             = R_UNDEF
    2606           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                    &
    2607           0 :                cospOUT%modis_Optical_Thickness_Water_LogMean(:)             = R_UNDEF
    2608           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                      &
    2609           0 :                cospOUT%modis_Optical_Thickness_Ice_LogMean(:)               = R_UNDEF
    2610           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                     &
    2611           0 :                cospOUT%modis_Cloud_Particle_Size_Water_Mean(:)              = R_UNDEF
    2612           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                       &
    2613           0 :                cospOUT%modis_Cloud_Particle_Size_Ice_Mean(:)                = R_UNDEF
    2614           0 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                      &
    2615           0 :                cospOUT%modis_Cloud_Top_Pressure_Total_Mean(:)               = R_UNDEF
    2616           0 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                             &
    2617           0 :                cospOUT%modis_Liquid_Water_Path_Mean(:)                      = R_UNDEF
    2618           0 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                                &
    2619           0 :                cospOUT%modis_Ice_Water_Path_Mean(:)                         = R_UNDEF
    2620           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))            &
    2621           0 :                cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,:,:) = R_UNDEF
    2622           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffICE))                       &
    2623           0 :                cospOUT%modis_Optical_Thickness_vs_ReffICE(:,:,:)            = R_UNDEF
    2624           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLIQ))                       &
    2625           0 :                cospOUT%modis_Optical_Thickness_vs_ReffLIQ(:,:,:)            = R_UNDEF
    2626           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    2627           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    2628           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    2629           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    2630           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    2631           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    2632           0 :           if (associated(cospOUT%atlid_cfad_sr))         cospOUT%atlid_cfad_sr(:,:,:)         = R_UNDEF
    2633           0 :           if (associated(cospOUT%atlid_lidarcld))        cospOUT%atlid_lidarcld(:,:)          = R_UNDEF
    2634           0 :           if (associated(cospOUT%atlid_cldlayer))        cospOUT%atlid_cldlayer(:,:)          = R_UNDEF
    2635           0 :           if (associated(cospOUT%grLidar532_cfad_sr))   cospOUT%grLidar532_cfad_sr(:,:,:)   = R_UNDEF
    2636           0 :           if (associated(cospOUT%grLidar532_lidarcld))  cospOUT%grLidar532_lidarcld(:,:)    = R_UNDEF
    2637           0 :           if (associated(cospOUT%grLidar532_cldlayer))  cospOUT%grLidar532_cldlayer(:,:)    = R_UNDEF
    2638           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF 
    2639           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    2640           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF
    2641           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF
    2642           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    2643           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    2644             :        endif
    2645             :     endif
    2646        9288 :     if (any([Lisccp_subcolumn,Lisccp_column,Lrttov_column])) then
    2647    13036680 :        if (any(cospgridIN%qv .lt. 0)) then
    2648           0 :           nError=nError+1
    2649           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%qv contains values out of range'
    2650           0 :           Lisccp_subcolumn = .false.
    2651           0 :           Lisccp_column    = .false.
    2652           0 :           Lrttov_column    = .false.
    2653           0 :           if (associated(cospOUT%rttov_tbs))           cospOUT%rttov_tbs(:,:)         = R_UNDEF
    2654           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2655           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2656           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2657           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2658           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2659           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2660           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2661           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2662           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2663             :        endif
    2664             :     endif
    2665        9288 :     if (any([Lmisr_subcolumn,Lmisr_column,Lcloudsat_subcolumn,Lcloudsat_column,Lcalipso_column,Lradar_lidar_tcc,&
    2666             :          Llidar_only_freq_cloud,LgrLidar532_column,Latlid_column,Lcloudsat_tcc, Lcloudsat_tcc2])) then
    2667    13036680 :        if (any(cospgridIN%hgt_matrix .lt. -300)) then
    2668           0 :           nError=nError+1
    2669           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%hgt_matrix contains values out of range'
    2670           0 :           Lmisr_subcolumn     = .false.
    2671           0 :           Lmisr_column        = .false.
    2672           0 :           Lcloudsat_subcolumn = .false.
    2673           0 :           Lcloudsat_column    = .false.
    2674           0 :           Lcalipso_column     = .false.
    2675           0 :           Lradar_lidar_tcc    = .false.
    2676           0 :           Llidar_only_freq_cloud = .false.
    2677           0 :           Lcloudsat_tcc       = .false.
    2678           0 :           Lcloudsat_tcc2      = .false.
    2679           0 :           Latlid_column       = .false.
    2680           0 :           LgrLidar532_column  = .false.
    2681           0 :           if (associated(cospOUT%misr_fq))                   cospOUT%misr_fq(:,:,:)                 = R_UNDEF
    2682           0 :           if (associated(cospOUT%misr_dist_model_layertops)) cospOUT%misr_dist_model_layertops(:,:) = R_UNDEF
    2683           0 :           if (associated(cospOUT%misr_meanztop))             cospOUT%misr_meanztop(:)               = R_UNDEF
    2684           0 :           if (associated(cospOUT%misr_cldarea))              cospOUT%misr_cldarea(:)                = R_UNDEF
    2685           0 :           if (associated(cospOUT%calipso_cfad_sr))           cospOUT%calipso_cfad_sr(:,:,:)         = R_UNDEF
    2686           0 :           if (associated(cospOUT%calipso_lidarcld))          cospOUT%calipso_lidarcld(:,:)          = R_UNDEF
    2687           0 :           if (associated(cospOUT%calipso_lidarcldphase))     cospOUT%calipso_lidarcldphase(:,:,:)   = R_UNDEF
    2688           0 :           if (associated(cospOUT%calipso_cldlayer))          cospOUT%calipso_cldlayer(:,:)          = R_UNDEF
    2689           0 :           if (associated(cospOUT%calipso_cldlayerphase))     cospOUT%calipso_cldlayerphase(:,:,:)   = R_UNDEF
    2690           0 :           if (associated(cospOUT%calipso_lidarcldtmp))       cospOUT%calipso_lidarcldtmp(:,:,:)     = R_UNDEF
    2691           0 :           if (associated(cospOUT%cloudsat_cfad_ze))          cospOUT%cloudsat_cfad_ze(:,:,:)        = R_UNDEF
    2692           0 :           if (associated(cospOUT%cloudsat_Ze_tot))           cospOUT%cloudsat_Ze_tot(:,:,:)         = R_UNDEF
    2693           0 :           if (associated(cospOUT%lidar_only_freq_cloud))     cospOUT%lidar_only_freq_cloud(:,:)     = R_UNDEF
    2694           0 :           if (associated(cospOUT%radar_lidar_tcc))           cospOUT%radar_lidar_tcc(:)             = R_UNDEF
    2695           0 :           if (associated(cospOUT%cloudsat_tcc))              cospOUT%cloudsat_tcc(:)                = R_UNDEF
    2696           0 :           if (associated(cospOUT%cloudsat_tcc2))             cospOUT%cloudsat_tcc2(:)               = R_UNDEF
    2697           0 :           if (associated(cospOUT%atlid_cfad_sr))             cospOUT%atlid_cfad_sr(:,:,:)           = R_UNDEF
    2698           0 :           if (associated(cospOUT%atlid_lidarcld))            cospOUT%atlid_lidarcld(:,:)            = R_UNDEF
    2699           0 :           if (associated(cospOUT%atlid_cldlayer))            cospOUT%atlid_cldlayer(:,:)            = R_UNDEF
    2700           0 :           if (associated(cospOUT%grLidar532_cfad_sr))        cospOUT%grLidar532_cfad_sr(:,:,:)      = R_UNDEF
    2701           0 :           if (associated(cospOUT%grLidar532_lidarcld))       cospOUT%grLidar532_lidarcld(:,:)       = R_UNDEF
    2702           0 :           if (associated(cospOUT%grLidar532_cldlayer))       cospOUT%grLidar532_cldlayer(:,:)       = R_UNDEF
    2703           0 :           if (associated(cospOUT%calipso_lidarcldtype))      cospOUT%calipso_lidarcldtype(:,:,:)    = R_UNDEF
    2704           0 :           if (associated(cospOUT%calipso_cldtype))           cospOUT%calipso_cldtype(:,:)           = R_UNDEF 
    2705           0 :           if (associated(cospOUT%calipso_cldtypetemp))       cospOUT%calipso_cldtypetemp(:,:)       = R_UNDEF 
    2706           0 :           if (associated(cospOUT%calipso_cldtypemeanz))      cospOUT%calipso_cldtypemeanz(:,:)      = R_UNDEF 
    2707           0 :           if (associated(cospOUT%calipso_cldtypemeanzse))    cospOUT%calipso_cldtypemeanzse(:,:)    = R_UNDEF
    2708           0 :           if (associated(cospOUT%calipso_cldthinemis))       cospOUT%calipso_cldthinemis(:)         = R_UNDEF
    2709             :        endif
    2710             :     endif
    2711       18576 :     if (any([Lrttov_column,Lcloudsat_column,Lcalipso_column,Lradar_lidar_tcc,Llidar_only_freq_cloud, &
    2712             :              LgrLidar532_column, Latlid_column, Lcloudsat_tcc, Lcloudsat_tcc2])) then
    2713    13191768 :        if (any(cospgridIN%hgt_matrix_half .lt. -300)) then
    2714           0 :           nError=nError+1
    2715           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%hgt_matrix_half contains values out of range'
    2716           0 :           Lrttov_column    = .false.
    2717           0 :           Lcloudsat_column = .false.
    2718           0 :           Lcalipso_column  = .false.
    2719           0 :           Lradar_lidar_tcc = .false.
    2720           0 :           Llidar_only_freq_cloud = .false.
    2721           0 :           Lcloudsat_tcc    = .false.
    2722           0 :           Lcloudsat_tcc2   = .false.
    2723           0 :           Latlid_column       = .false.
    2724           0 :           LgrLidar532_column = .false.
    2725           0 :           if (associated(cospOUT%rttov_tbs))              cospOUT%rttov_tbs(:,:)               = R_UNDEF
    2726           0 :           if (associated(cospOUT%calipso_cfad_sr))        cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    2727           0 :           if (associated(cospOUT%calipso_lidarcld))       cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    2728           0 :           if (associated(cospOUT%calipso_lidarcldphase))  cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    2729           0 :           if (associated(cospOUT%calipso_cldlayer))       cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    2730           0 :           if (associated(cospOUT%calipso_cldlayerphase))  cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    2731           0 :           if (associated(cospOUT%calipso_lidarcldtmp))    cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    2732           0 :           if (associated(cospOUT%cloudsat_cfad_ze))       cospOUT%cloudsat_cfad_ze(:,:,:)      = R_UNDEF
    2733           0 :           if (associated(cospOUT%lidar_only_freq_cloud))  cospOUT%lidar_only_freq_cloud(:,:)   = R_UNDEF
    2734           0 :           if (associated(cospOUT%radar_lidar_tcc))        cospOUT%radar_lidar_tcc(:)           = R_UNDEF
    2735           0 :           if (associated(cospOUT%cloudsat_tcc))           cospOUT%cloudsat_tcc(:)              = R_UNDEF
    2736           0 :           if (associated(cospOUT%cloudsat_tcc2))          cospOUT%cloudsat_tcc2(:)             = R_UNDEF          
    2737           0 :           if (associated(cospOUT%atlid_cfad_sr))          cospOUT%atlid_cfad_sr(:,:,:)         = R_UNDEF
    2738           0 :           if (associated(cospOUT%atlid_lidarcld))         cospOUT%atlid_lidarcld(:,:)          = R_UNDEF
    2739           0 :           if (associated(cospOUT%atlid_cldlayer))         cospOUT%atlid_cldlayer(:,:)          = R_UNDEF
    2740           0 :           if (associated(cospOUT%grLidar532_cfad_sr))     cospOUT%grLidar532_cfad_sr(:,:,:)    = R_UNDEF
    2741           0 :           if (associated(cospOUT%grLidar532_lidarcld))    cospOUT%grLidar532_lidarcld(:,:)     = R_UNDEF
    2742           0 :           if (associated(cospOUT%grLidar532_cldlayer))    cospOUT%grLidar532_cldlayer(:,:)     = R_UNDEF
    2743           0 :           if (associated(cospOUT%calipso_lidarcldtype))   cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    2744           0 :           if (associated(cospOUT%calipso_cldtype))        cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    2745           0 :           if (associated(cospOUT%calipso_cldtypetemp))    cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    2746           0 :           if (associated(cospOUT%calipso_cldtypemeanz))   cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF 
    2747           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:)  = R_UNDEF 
    2748           0 :           if (associated(cospOUT%calipso_cldthinemis))    cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    2749             :        endif
    2750             :     endif
    2751       18576 :     if (any([Lrttov_column,Lcalipso_column,Lparasol_column])) then
    2752      155088 :        if (any(cospgridIN%land .lt. 0)) then
    2753           0 :           nError=nError+1
    2754           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%land contains values out of range'
    2755           0 :           Lrttov_column    = .false.
    2756           0 :           Lcalipso_column  = .false.
    2757           0 :           Lparasol_column  = .false.
    2758           0 :           if (associated(cospOUT%rttov_tbs))             cospOUT%rttov_tbs(:,:)               = R_UNDEF
    2759           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    2760           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    2761           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    2762           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    2763           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    2764           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    2765           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    2766           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    2767           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    2768           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF
    2769           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    2770           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    2771           0 :           if (associated(cospOUT%parasolGrid_refl))      cospOUT%parasolGrid_refl(:,:)        = R_UNDEF
    2772             :        endif
    2773             :     endif
    2774        9288 :     if (any([Lisccp_subcolumn,Lisccp_column,Lrttov_column])) then
    2775      155088 :        if (any(cospgridIN%skt .lt. 0)) then
    2776           0 :           nError=nError+1
    2777           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%skt contains values out of range'
    2778           0 :           Lisccp_subcolumn = .false.
    2779           0 :           Lisccp_column    = .false.
    2780           0 :           Lrttov_column    = .false.
    2781           0 :           if (associated(cospOUT%rttov_tbs))           cospOUT%rttov_tbs(:,:)         = R_UNDEF
    2782           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2783           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2784           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2785           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2786           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2787           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2788           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2789           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2790           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2791             :        endif
    2792             :     endif
    2793             :     
    2794             :     ! RTTOV Inputs
    2795        9288 :     if (Lrttov_column) then
    2796           0 :        if (cospgridIN%zenang .lt. -90. .OR. cospgridIN%zenang .gt. 90) then
    2797           0 :           nError=nError+1
    2798           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%zenang contains values out of range'
    2799           0 :           Lrttov_column = .false.
    2800           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2801             :        endif
    2802           0 :        if (cospgridIN%co2 .lt. 0) then
    2803           0 :           nError=nError+1
    2804           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%co2 contains values out of range'
    2805           0 :           Lrttov_column = .false.
    2806           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2807             :        endif
    2808           0 :        if (cospgridIN%ch4 .lt. 0) then
    2809           0 :           nError=nError+1
    2810           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%ch4 contains values out of range'
    2811           0 :           Lrttov_column = .false.
    2812           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2813             :        endif
    2814           0 :        if (cospgridIN%n2o .lt. 0) then
    2815           0 :           nError=nError+1
    2816           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%n2o contains values out of range'
    2817           0 :           Lrttov_column = .false.
    2818           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2819             :        endif
    2820           0 :        if (cospgridIN%co.lt. 0) then
    2821           0 :           nError=nError+1
    2822           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%co contains values out of range'
    2823           0 :           Lrttov_column = .false.
    2824           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2825             :        endif
    2826           0 :        if (any(cospgridIN%o3 .lt. 0)) then
    2827           0 :           nError=nError+1
    2828           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%o3 contains values out of range'
    2829           0 :           Lrttov_column = .false.
    2830           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2831             :        endif
    2832           0 :        if (any(cospgridIN%emis_sfc .lt. 0. .OR. cospgridIN%emis_sfc .gt. 1)) then
    2833           0 :           nError=nError+1
    2834           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospgridIN%emis_sfc contains values out of range'
    2835           0 :           Lrttov_column = .false.
    2836           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2837             :        endif
    2838           0 :        if (any(cospgridIN%u_sfc .lt. -100. .OR. cospgridIN%u_sfc .gt. 100.)) then
    2839           0 :           nError=nError+1
    2840           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%u_sfc contains values out of range'
    2841           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2842           0 :           Lrttov_column = .false.
    2843             :        endif
    2844           0 :        if (any(cospgridIN%v_sfc .lt. -100. .OR. cospgridIN%v_sfc .gt. 100.)) then
    2845           0 :           nError=nError+1
    2846           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%v_sfc contains values out of range'
    2847           0 :           Lrttov_column = .false.
    2848           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2849             :        endif
    2850           0 :        if (any(cospgridIN%lat .lt. -90 .OR. cospgridIN%lat .gt. 90)) then
    2851           0 :           nError=nError+1
    2852           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%lat contains values out of range'
    2853           0 :           Lrttov_column = .false.
    2854           0 :           if (associated(cospOUT%rttov_tbs)) cospOUT%rttov_tbs(:,:) = R_UNDEF
    2855             :        endif
    2856             :     endif
    2857             :     
    2858             :     ! COSP_INPUTS
    2859        9288 :     if (any([Lisccp_subcolumn,Lisccp_column])) then
    2860        9288 :        if (cospIN%emsfc_lw .lt. 0. .OR. cospIN%emsfc_lw .gt. 1.) then
    2861           0 :           nError=nError+1
    2862           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%emsfc_lw contains values out of range'
    2863           0 :           Lisccp_subcolumn = .false.
    2864           0 :           Lisccp_column    = .false.
    2865           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2866           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2867           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2868           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2869           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2870           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2871           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2872           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2873           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2874             :        endif
    2875             :     endif
    2876        9288 :     if (any([Lisccp_subcolumn,Lisccp_column,Lmisr_subcolumn,Lmisr_column,Lmodis_subcolumn,Lmodis_column])) then
    2877   131063400 :        if (any(cospIN%tau_067 .lt. 0)) then
    2878           0 :           nError=nError+1
    2879           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tau_067 contains values out of range'
    2880           0 :           Lisccp_subcolumn = .false.
    2881           0 :           Lisccp_column    = .false.
    2882           0 :           Lmisr_subcolumn  = .false.
    2883           0 :           Lmisr_column     = .false.
    2884           0 :           Lmodis_subcolumn = .false.
    2885           0 :           Lmodis_column    = .false.
    2886           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2887           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2888           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2889           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2890           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2891           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2892           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2893           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2894           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2895           0 :           if (associated(cospOUT%misr_fq))                   cospOUT%misr_fq(:,:,:)                 = R_UNDEF
    2896           0 :           if (associated(cospOUT%misr_dist_model_layertops)) cospOUT%misr_dist_model_layertops(:,:) = R_UNDEF
    2897           0 :           if (associated(cospOUT%misr_meanztop))             cospOUT%misr_meanztop(:)               = R_UNDEF
    2898           0 :           if (associated(cospOUT%misr_cldarea))              cospOUT%misr_cldarea(:)                = R_UNDEF
    2899           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                          &
    2900           0 :                cospOUT%modis_Cloud_Fraction_Total_Mean(:)                   = R_UNDEF
    2901           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                          &
    2902           0 :                cospOUT%modis_Cloud_Fraction_Water_Mean(:)                   = R_UNDEF
    2903           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                            &
    2904           0 :                cospOUT%modis_Cloud_Fraction_Ice_Mean(:)                     = R_UNDEF
    2905           0 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                           &
    2906           0 :                cospOUT%modis_Cloud_Fraction_High_Mean(:)                    = R_UNDEF
    2907           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                            &
    2908           0 :                cospOUT%modis_Cloud_Fraction_Mid_Mean(:)                     = R_UNDEF
    2909           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                            &
    2910           0 :                cospOUT%modis_Cloud_Fraction_Low_Mean(:)                     = R_UNDEF
    2911           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                       &
    2912           0 :                cospOUT%modis_Optical_Thickness_Total_Mean(:)                = R_UNDEF
    2913           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                       &
    2914           0 :                cospOUT%modis_Optical_Thickness_Water_Mean(:)                = R_UNDEF
    2915           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                         &
    2916           0 :                cospOUT%modis_Optical_Thickness_Ice_Mean(:)                  = R_UNDEF
    2917           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                    &
    2918           0 :                cospOUT%modis_Optical_Thickness_Total_LogMean(:)             = R_UNDEF
    2919           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                    &
    2920           0 :                cospOUT%modis_Optical_Thickness_Water_LogMean(:)             = R_UNDEF
    2921           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                      &
    2922           0 :                cospOUT%modis_Optical_Thickness_Ice_LogMean(:)               = R_UNDEF
    2923           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                     &
    2924           0 :                cospOUT%modis_Cloud_Particle_Size_Water_Mean(:)              = R_UNDEF
    2925           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                       &
    2926           0 :                cospOUT%modis_Cloud_Particle_Size_Ice_Mean(:)                = R_UNDEF
    2927           0 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                      &
    2928           0 :                cospOUT%modis_Cloud_Top_Pressure_Total_Mean(:)               = R_UNDEF
    2929           0 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                             &
    2930           0 :                cospOUT%modis_Liquid_Water_Path_Mean(:)                      = R_UNDEF
    2931           0 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                                &
    2932           0 :                cospOUT%modis_Ice_Water_Path_Mean(:)                         = R_UNDEF
    2933           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))            &
    2934           0 :                cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,:,:) = R_UNDEF
    2935           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffICE))                       &
    2936           0 :                cospOUT%modis_Optical_Thickness_vs_ReffICE(:,:,:)            = R_UNDEF
    2937           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLIQ))                       &
    2938           0 :                cospOUT%modis_Optical_Thickness_vs_ReffLIQ(:,:,:)            = R_UNDEF
    2939             :        endif
    2940             :     endif
    2941        9288 :     if (any([Lisccp_subcolumn,Lisccp_column])) then
    2942   131063400 :        if (any(cospIN%emiss_11 .lt. 0. .OR. cospIN%emiss_11 .gt. 1)) then
    2943           0 :           nError=nError+1
    2944           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%emiss_11 contains values out of range'
    2945           0 :           Lisccp_subcolumn = .false.
    2946           0 :           Lisccp_column    = .false.
    2947           0 :           if (associated(cospOUT%isccp_totalcldarea))  cospOUT%isccp_totalcldarea(:)  = R_UNDEF
    2948           0 :           if (associated(cospOUT%isccp_meantb))        cospOUT%isccp_meantb(:)        = R_UNDEF
    2949           0 :           if (associated(cospOUT%isccp_meantbclr))     cospOUT%isccp_meantbclr(:)     = R_UNDEF
    2950           0 :           if (associated(cospOUT%isccp_meanptop))      cospOUT%isccp_meanptop(:)      = R_UNDEF
    2951           0 :           if (associated(cospOUT%isccp_meantaucld))    cospOUT%isccp_meantaucld(:)    = R_UNDEF
    2952           0 :           if (associated(cospOUT%isccp_meanalbedocld)) cospOUT%isccp_meanalbedocld(:) = R_UNDEF
    2953           0 :           if (associated(cospOUT%isccp_boxtau))        cospOUT%isccp_boxtau(:,:)      = R_UNDEF
    2954           0 :           if (associated(cospOUT%isccp_boxptop))       cospOUT%isccp_boxptop(:,:)     = R_UNDEF
    2955           0 :           if (associated(cospOUT%isccp_fq))            cospOUT%isccp_fq(:,:,:)        = R_UNDEF
    2956             :        endif
    2957             :     endif
    2958        9288 :     if (any([Lmodis_subcolumn,Lmodis_column])) then
    2959   131063400 :        if (any(cospIN%asym .lt. -1. .OR. cospIN%asym .gt. 1)) then
    2960           0 :           nError=nError+1
    2961           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%asym contains values out of range'
    2962           0 :           Lmodis_subcolumn = .false.
    2963           0 :           Lmodis_column    = .false.
    2964           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                          &
    2965           0 :                cospOUT%modis_Cloud_Fraction_Total_Mean(:)                   = R_UNDEF
    2966           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                          &
    2967           0 :                cospOUT%modis_Cloud_Fraction_Water_Mean(:)                   = R_UNDEF
    2968           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                            &
    2969           0 :                cospOUT%modis_Cloud_Fraction_Ice_Mean(:)                     = R_UNDEF
    2970           0 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                           &
    2971           0 :                cospOUT%modis_Cloud_Fraction_High_Mean(:)                    = R_UNDEF
    2972           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                            &
    2973           0 :                cospOUT%modis_Cloud_Fraction_Mid_Mean(:)                     = R_UNDEF
    2974           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                            &
    2975           0 :                cospOUT%modis_Cloud_Fraction_Low_Mean(:)                     = R_UNDEF
    2976           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                       &
    2977           0 :                cospOUT%modis_Optical_Thickness_Total_Mean(:)                = R_UNDEF
    2978           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                       &
    2979           0 :                cospOUT%modis_Optical_Thickness_Water_Mean(:)                = R_UNDEF
    2980           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                         &
    2981           0 :                cospOUT%modis_Optical_Thickness_Ice_Mean(:)                  = R_UNDEF
    2982           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                    &
    2983           0 :                cospOUT%modis_Optical_Thickness_Total_LogMean(:)             = R_UNDEF
    2984           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                    &
    2985           0 :                cospOUT%modis_Optical_Thickness_Water_LogMean(:)             = R_UNDEF
    2986           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                      &
    2987           0 :                cospOUT%modis_Optical_Thickness_Ice_LogMean(:)               = R_UNDEF
    2988           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                     &
    2989           0 :                cospOUT%modis_Cloud_Particle_Size_Water_Mean(:)              = R_UNDEF
    2990           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                       &
    2991           0 :                cospOUT%modis_Cloud_Particle_Size_Ice_Mean(:)                = R_UNDEF
    2992           0 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                      &
    2993           0 :                cospOUT%modis_Cloud_Top_Pressure_Total_Mean(:)               = R_UNDEF
    2994           0 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                             &
    2995           0 :                cospOUT%modis_Liquid_Water_Path_Mean(:)                      = R_UNDEF
    2996           0 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                                &
    2997           0 :                cospOUT%modis_Ice_Water_Path_Mean(:)                         = R_UNDEF
    2998           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))            &
    2999           0 :                cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,:,:) = R_UNDEF
    3000           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffICE))                       &
    3001           0 :                cospOUT%modis_Optical_Thickness_vs_ReffICE(:,:,:)            = R_UNDEF
    3002           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLIQ))                       &
    3003           0 :                cospOUT%modis_Optical_Thickness_vs_ReffLIQ(:,:,:)            = R_UNDEF
    3004             :        endif
    3005   131063400 :        if (any(cospIN%ss_alb .lt. 0 .OR. cospIN%ss_alb .gt. 1)) then
    3006           0 :           nError=nError+1
    3007           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%ss_alb contains values out of range'
    3008           0 :           Lmodis_subcolumn = .false.
    3009           0 :           Lmodis_column    = .false.
    3010           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Total_Mean))                          &
    3011           0 :                cospOUT%modis_Cloud_Fraction_Total_Mean(:)                   = R_UNDEF
    3012           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Water_Mean))                          &
    3013           0 :                cospOUT%modis_Cloud_Fraction_Water_Mean(:)                   = R_UNDEF
    3014           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Ice_Mean))                            &
    3015           0 :                cospOUT%modis_Cloud_Fraction_Ice_Mean(:)                     = R_UNDEF
    3016           0 :           if (associated(cospOUT%modis_Cloud_Fraction_High_Mean))                           &
    3017           0 :                cospOUT%modis_Cloud_Fraction_High_Mean(:)                    = R_UNDEF
    3018           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Mid_Mean))                            &
    3019           0 :                cospOUT%modis_Cloud_Fraction_Mid_Mean(:)                     = R_UNDEF
    3020           0 :           if (associated(cospOUT%modis_Cloud_Fraction_Low_Mean))                            &
    3021           0 :                cospOUT%modis_Cloud_Fraction_Low_Mean(:)                     = R_UNDEF
    3022           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_Mean))                       &
    3023           0 :                cospOUT%modis_Optical_Thickness_Total_Mean(:)                = R_UNDEF
    3024           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_Mean))                       &
    3025           0 :                cospOUT%modis_Optical_Thickness_Water_Mean(:)                = R_UNDEF
    3026           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_Mean))                         &
    3027           0 :                cospOUT%modis_Optical_Thickness_Ice_Mean(:)                  = R_UNDEF
    3028           0 :           if (associated(cospOUT%modis_Optical_Thickness_Total_LogMean))                    &
    3029           0 :                cospOUT%modis_Optical_Thickness_Total_LogMean(:)             = R_UNDEF
    3030           0 :           if (associated(cospOUT%modis_Optical_Thickness_Water_LogMean))                    &
    3031           0 :                cospOUT%modis_Optical_Thickness_Water_LogMean(:)             = R_UNDEF
    3032           0 :           if (associated(cospOUT%modis_Optical_Thickness_Ice_LogMean))                      &
    3033           0 :                cospOUT%modis_Optical_Thickness_Ice_LogMean(:)               = R_UNDEF
    3034           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Water_Mean))                     &
    3035           0 :                cospOUT%modis_Cloud_Particle_Size_Water_Mean(:)              = R_UNDEF
    3036           0 :           if (associated(cospOUT%modis_Cloud_Particle_Size_Ice_Mean))                       &
    3037           0 :                cospOUT%modis_Cloud_Particle_Size_Ice_Mean(:)                = R_UNDEF
    3038           0 :           if (associated(cospOUT%modis_Cloud_Top_Pressure_Total_Mean))                      &
    3039           0 :                cospOUT%modis_Cloud_Top_Pressure_Total_Mean(:)               = R_UNDEF
    3040           0 :           if (associated(cospOUT%modis_Liquid_Water_Path_Mean))                             &
    3041           0 :                cospOUT%modis_Liquid_Water_Path_Mean(:)                      = R_UNDEF
    3042           0 :           if (associated(cospOUT%modis_Ice_Water_Path_Mean))                                &
    3043           0 :                cospOUT%modis_Ice_Water_Path_Mean(:)                         = R_UNDEF
    3044           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure))            &
    3045           0 :                cospOUT%modis_Optical_Thickness_vs_Cloud_Top_Pressure(:,:,:) = R_UNDEF
    3046           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffICE))                       &
    3047           0 :                cospOUT%modis_Optical_Thickness_vs_ReffICE(:,:,:)            = R_UNDEF
    3048           0 :           if (associated(cospOUT%modis_Optical_Thickness_vs_ReffLIQ))                       &
    3049           0 :                cospOUT%modis_Optical_Thickness_vs_ReffLIQ(:,:,:)            = R_UNDEF
    3050             :        endif
    3051             :     endif
    3052       27864 :     if (any([Latlid_subcolumn,Latlid_column])) then
    3053           0 :        if (any(cospIN%betatot_atlid .lt. 0)) then
    3054           0 :           nError=nError+1
    3055           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%betatot_atlid contains values out of range'
    3056           0 :           Latlid_subcolumn = .false.
    3057           0 :           Latlid_column    = .false.
    3058           0 :           if (associated(cospOUT%atlid_cfad_sr))       cospOUT%atlid_cfad_sr(:,:,:)  = R_UNDEF
    3059           0 :           if (associated(cospOUT%atlid_lidarcld))      cospOUT%atlid_lidarcld(:,:)   = R_UNDEF
    3060           0 :           if (associated(cospOUT%atlid_cldlayer))      cospOUT%atlid_cldlayer(:,:)   = R_UNDEF
    3061           0 :           if (associated(cospOUT%atlid_beta_tot))      cospOUT%atlid_beta_tot(:,:,:) = R_UNDEF
    3062           0 :           if (associated(cospOUT%atlid_beta_mol))      cospOUT%atlid_beta_mol(:,:)   = R_UNDEF
    3063             :        endif
    3064           0 :        if (any(cospIN%beta_mol_atlid .lt. 0)) then
    3065           0 :           nError=nError+1
    3066           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%beta_mol_atlid contains values out of range'
    3067           0 :           Latlid_subcolumn = .false.
    3068           0 :           Latlid_column    = .false.
    3069           0 :           if (associated(cospOUT%atlid_cfad_sr))       cospOUT%atlid_cfad_sr(:,:,:)  = R_UNDEF
    3070           0 :           if (associated(cospOUT%atlid_lidarcld))      cospOUT%atlid_lidarcld(:,:)   = R_UNDEF
    3071           0 :           if (associated(cospOUT%atlid_cldlayer))      cospOUT%atlid_cldlayer(:,:)   = R_UNDEF
    3072           0 :           if (associated(cospOUT%atlid_beta_tot))      cospOUT%atlid_beta_tot(:,:,:) = R_UNDEF
    3073           0 :           if (associated(cospOUT%atlid_beta_mol))      cospOUT%atlid_beta_mol(:,:)   = R_UNDEF
    3074             :        endif
    3075           0 :        if (any(cospIN%tautot_atlid .lt. 0)) then
    3076           0 :           nError=nError+1
    3077           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tautot_atlid contains values out of range'
    3078           0 :           Latlid_subcolumn = .false.
    3079           0 :           Latlid_column    = .false.
    3080           0 :           if (associated(cospOUT%atlid_cfad_sr))       cospOUT%atlid_cfad_sr(:,:,:)  = R_UNDEF
    3081           0 :           if (associated(cospOUT%atlid_lidarcld))      cospOUT%atlid_lidarcld(:,:)   = R_UNDEF
    3082           0 :           if (associated(cospOUT%atlid_cldlayer))      cospOUT%atlid_cldlayer(:,:)   = R_UNDEF
    3083           0 :           if (associated(cospOUT%atlid_beta_tot))      cospOUT%atlid_beta_tot(:,:,:) = R_UNDEF
    3084           0 :           if (associated(cospOUT%atlid_beta_mol))      cospOUT%atlid_beta_mol(:,:)   = R_UNDEF
    3085             :        endif
    3086           0 :        if (any(cospIN%tau_mol_atlid .lt. 0)) then
    3087           0 :           nError=nError+1
    3088           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tau_mol_atlid contains values out of range'
    3089           0 :           Latlid_subcolumn = .false.
    3090           0 :           Latlid_column    = .false.
    3091           0 :           if (associated(cospOUT%atlid_cfad_sr))       cospOUT%atlid_cfad_sr(:,:,:)  = R_UNDEF
    3092           0 :           if (associated(cospOUT%atlid_lidarcld))      cospOUT%atlid_lidarcld(:,:)   = R_UNDEF
    3093           0 :           if (associated(cospOUT%atlid_cldlayer))      cospOUT%atlid_cldlayer(:,:)   = R_UNDEF
    3094           0 :           if (associated(cospOUT%atlid_beta_tot))      cospOUT%atlid_beta_tot(:,:,:) = R_UNDEF
    3095           0 :           if (associated(cospOUT%atlid_beta_mol))      cospOUT%atlid_beta_mol(:,:)   = R_UNDEF
    3096             :        endif
    3097             :     endif
    3098             :     
    3099       27864 :     if (any([LgrLidar532_subcolumn,LgrLidar532_column])) then
    3100           0 :        if (any(cospIN%betatot_grLidar532 .lt. 0)) then
    3101           0 :           nError=nError+1
    3102           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%betatot_grLidar532 contains values out of range'
    3103           0 :           LgrLidar532_subcolumn = .false.
    3104           0 :           LgrLidar532_column    = .false.
    3105           0 :           if (associated(cospOUT%grLidar532_cfad_sr))       cospOUT%grLidar532_cfad_sr(:,:,:)  = R_UNDEF
    3106           0 :           if (associated(cospOUT%grLidar532_lidarcld))      cospOUT%grLidar532_lidarcld(:,:)   = R_UNDEF
    3107           0 :           if (associated(cospOUT%grLidar532_cldlayer))      cospOUT%grLidar532_cldlayer(:,:)   = R_UNDEF
    3108           0 :           if (associated(cospOUT%grLidar532_beta_tot))      cospOUT%grLidar532_beta_tot(:,:,:) = R_UNDEF
    3109           0 :           if (associated(cospOUT%grLidar532_beta_mol))      cospOUT%grLidar532_beta_mol(:,:)   = R_UNDEF
    3110             :        endif
    3111           0 :        if (any(cospIN%beta_mol_grLidar532 .lt. 0)) then
    3112           0 :           nError=nError+1
    3113           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%beta_mol_grLidar532 contains values out of range'
    3114           0 :           LgrLidar532_subcolumn = .false.
    3115           0 :           LgrLidar532_column    = .false.
    3116           0 :           if (associated(cospOUT%grLidar532_cfad_sr))       cospOUT%grLidar532_cfad_sr(:,:,:)  = R_UNDEF
    3117           0 :           if (associated(cospOUT%grLidar532_lidarcld))      cospOUT%grLidar532_lidarcld(:,:)   = R_UNDEF
    3118           0 :           if (associated(cospOUT%grLidar532_cldlayer))      cospOUT%grLidar532_cldlayer(:,:)   = R_UNDEF
    3119           0 :           if (associated(cospOUT%grLidar532_beta_tot))      cospOUT%grLidar532_beta_tot(:,:,:) = R_UNDEF
    3120           0 :           if (associated(cospOUT%grLidar532_beta_mol))      cospOUT%grLidar532_beta_mol(:,:)   = R_UNDEF
    3121             :        endif
    3122           0 :        if (any(cospIN%tautot_grLidar532 .lt. 0)) then
    3123           0 :           nError=nError+1
    3124           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tautot_grLidar532 contains values out of range'
    3125           0 :           LgrLidar532_subcolumn = .false.
    3126           0 :           LgrLidar532_column    = .false.
    3127           0 :           if (associated(cospOUT%grLidar532_cfad_sr))       cospOUT%grLidar532_cfad_sr(:,:,:)  = R_UNDEF
    3128           0 :           if (associated(cospOUT%grLidar532_lidarcld))      cospOUT%grLidar532_lidarcld(:,:)   = R_UNDEF
    3129           0 :           if (associated(cospOUT%grLidar532_cldlayer))      cospOUT%grLidar532_cldlayer(:,:)   = R_UNDEF
    3130           0 :           if (associated(cospOUT%grLidar532_beta_tot))      cospOUT%grLidar532_beta_tot(:,:,:) = R_UNDEF
    3131           0 :           if (associated(cospOUT%grLidar532_beta_mol))      cospOUT%grLidar532_beta_mol(:,:)   = R_UNDEF
    3132             :        endif
    3133           0 :        if (any(cospIN%tau_mol_grLidar532 .lt. 0)) then
    3134           0 :           nError=nError+1
    3135           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tau_mol_grLidar532 contains values out of range'
    3136           0 :           LgrLidar532_subcolumn = .false.
    3137           0 :           LgrLidar532_column    = .false.
    3138           0 :           if (associated(cospOUT%grLidar532_cfad_sr))       cospOUT%grLidar532_cfad_sr(:,:,:)  = R_UNDEF
    3139           0 :           if (associated(cospOUT%grLidar532_lidarcld))      cospOUT%grLidar532_lidarcld(:,:)   = R_UNDEF
    3140           0 :           if (associated(cospOUT%grLidar532_cldlayer))      cospOUT%grLidar532_cldlayer(:,:)   = R_UNDEF
    3141           0 :           if (associated(cospOUT%grLidar532_beta_tot))      cospOUT%grLidar532_beta_tot(:,:,:) = R_UNDEF
    3142           0 :           if (associated(cospOUT%grLidar532_beta_mol))      cospOUT%grLidar532_beta_mol(:,:)   = R_UNDEF
    3143             :        endif
    3144             :     endif
    3145             : 
    3146        9288 :     if (any([Lcalipso_subcolumn,Lcalipso_column])) then
    3147   131063400 :        if (any(cospIN%betatot_calipso .lt. 0)) then
    3148           0 :           nError=nError+1
    3149           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%betatot_calipso contains values out of range'
    3150           0 :           Lcalipso_subcolumn = .false.
    3151           0 :           Lcalipso_column    = .false.
    3152           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3153           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3154           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3155           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3156           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3157           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3158           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3159           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF 
    3160           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    3161           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    3162           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF 
    3163           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF 
    3164           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3165             :        endif
    3166   131063400 :        if (any(cospIN%betatot_liq_calipso .lt. 0)) then
    3167           0 :           nError=nError+1
    3168           0 :           errorMessage(nError) = ('ERROR: COSP input variable: cospIN%betatot_liq_calipso contains values out of range')
    3169           0 :           Lcalipso_subcolumn = .false.
    3170           0 :           Lcalipso_column    = .false.
    3171           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3172           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3173           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3174           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3175           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3176           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3177           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3178           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    3179           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF
    3180           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    3181           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF 
    3182           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    3183           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3184             :        endif
    3185   131063400 :        if (any(cospIN%betatot_ice_calipso .lt. 0)) then
    3186           0 :           nError=nError+1
    3187           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%betatot_ice_calipso contains values out of range'
    3188           0 :           Lcalipso_subcolumn = .false.
    3189           0 :           Lcalipso_column    = .false.
    3190           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3191           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3192           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3193           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3194           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3195           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3196           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3197           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    3198           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    3199           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    3200           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF 
    3201           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    3202           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3203             :        endif
    3204   131063400 :        if (any(cospIN%tautot_calipso .lt. 0)) then
    3205           0 :           nError=nError+1
    3206           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tautot_calipso contains values out of range'
    3207           0 :           Lcalipso_subcolumn = .false.
    3208           0 :           Lcalipso_column    = .false.
    3209           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3210           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3211           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3212           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3213           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3214           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3215           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3216           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    3217           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    3218           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF 
    3219           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF 
    3220           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    3221           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3222             :        endif
    3223   131063400 :        if (any(cospIN%tautot_liq_calipso .lt. 0)) then
    3224           0 :           nError=nError+1
    3225           0 :           errorMessage(nError) = ('ERROR: COSP input variable: cospIN%tautot_liq_calipso contains values out of range')
    3226           0 :           Lcalipso_subcolumn = .false.
    3227           0 :           Lcalipso_column    = .false.
    3228           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3229           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3230           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3231           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3232           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3233           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3234           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3235           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    3236           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF
    3237           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF
    3238           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF
    3239           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    3240           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3241             :        endif
    3242   131063400 :        if (any(cospIN%tautot_ice_calipso .lt. 0)) then
    3243           0 :           nError=nError+1
    3244           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tautot_ice_calipso contains values out of range'
    3245           0 :           Lcalipso_subcolumn = .false.
    3246           0 :           Lcalipso_column    = .false.
    3247           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3248           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3249           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3250           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3251           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3252           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3253           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3254           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    3255           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF
    3256           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF
    3257           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF
    3258           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    3259           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3260             :        endif
    3261    13036680 :        if (any(cospIN%tau_mol_calipso .lt. 0)) then
    3262           0 :           nError=nError+1
    3263           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tau_mol_calipso contains values out of range'
    3264           0 :           Lcalipso_subcolumn = .false.
    3265           0 :           Lcalipso_column    = .false.
    3266           0 :           if (associated(cospOUT%calipso_cfad_sr))       cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3267           0 :           if (associated(cospOUT%calipso_lidarcld))      cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3268           0 :           if (associated(cospOUT%calipso_lidarcldphase)) cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3269           0 :           if (associated(cospOUT%calipso_cldlayer))      cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3270           0 :           if (associated(cospOUT%calipso_cldlayerphase)) cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3271           0 :           if (associated(cospOUT%calipso_lidarcldtmp))   cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3272           0 :           if (associated(cospOUT%calipso_srbval))        cospOUT%calipso_srbval(:)            = R_UNDEF
    3273           0 :           if (associated(cospOUT%calipso_lidarcldtype))  cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF 
    3274           0 :           if (associated(cospOUT%calipso_cldtype))       cospOUT%calipso_cldtype(:,:)         = R_UNDEF 
    3275           0 :           if (associated(cospOUT%calipso_cldtypetemp))   cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF
    3276           0 :           if (associated(cospOUT%calipso_cldtypemeanz))  cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF
    3277           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:) = R_UNDEF
    3278           0 :           if (associated(cospOUT%calipso_cldthinemis))   cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3279             :        endif
    3280             :     endif
    3281        9288 :     if (any([Lcalipso_subcolumn,Lcalipso_column,Lcloudsat_column,Lradar_lidar_tcc,       &
    3282             :         Llidar_only_freq_cloud, Lcloudsat_tcc, Lcloudsat_tcc2])) then
    3283    13036680 :        if (any(cospIN%beta_mol_calipso .lt. 0)) then
    3284           0 :           nError=nError+1
    3285           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%beta_mol_calipso contains values out of range'
    3286           0 :           Lcalipso_subcolumn = .false.
    3287           0 :           Lcalipso_column    = .false.
    3288           0 :           Lcloudsat_column   = .false.
    3289           0 :           Lradar_lidar_tcc   = .false.
    3290           0 :           Llidar_only_freq_cloud = .false.
    3291           0 :           Lcloudsat_tcc      = .false.
    3292           0 :           Lcloudsat_tcc2     = .false.
    3293           0 :           if (associated(cospOUT%calipso_cfad_sr))        cospOUT%calipso_cfad_sr(:,:,:)       = R_UNDEF
    3294           0 :           if (associated(cospOUT%calipso_lidarcld))       cospOUT%calipso_lidarcld(:,:)        = R_UNDEF
    3295           0 :           if (associated(cospOUT%calipso_lidarcldphase))  cospOUT%calipso_lidarcldphase(:,:,:) = R_UNDEF
    3296           0 :           if (associated(cospOUT%calipso_cldlayer))       cospOUT%calipso_cldlayer(:,:)        = R_UNDEF
    3297           0 :           if (associated(cospOUT%calipso_cldlayerphase))  cospOUT%calipso_cldlayerphase(:,:,:) = R_UNDEF
    3298           0 :           if (associated(cospOUT%calipso_lidarcldtmp))    cospOUT%calipso_lidarcldtmp(:,:,:)   = R_UNDEF
    3299           0 :           if (associated(cospOUT%calipso_srbval))         cospOUT%calipso_srbval(:)            = R_UNDEF
    3300           0 :           if (associated(cospOUT%cloudsat_cfad_ze))       cospOUT%cloudsat_cfad_ze(:,:,:)      = R_UNDEF
    3301           0 :           if (associated(cospOUT%lidar_only_freq_cloud))  cospOUT%lidar_only_freq_cloud(:,:)   = R_UNDEF
    3302           0 :           if (associated(cospOUT%radar_lidar_tcc))        cospOUT%radar_lidar_tcc(:)           = R_UNDEF
    3303           0 :           if (associated(cospOUT%cloudsat_tcc))           cospOUT%cloudsat_tcc(:)              = R_UNDEF
    3304           0 :           if (associated(cospOUT%cloudsat_tcc2))          cospOUT%cloudsat_tcc2(:)             = R_UNDEF
    3305           0 :           if (associated(cospOUT%calipso_lidarcldtype))   cospOUT%calipso_lidarcldtype(:,:,:)  = R_UNDEF
    3306           0 :           if (associated(cospOUT%calipso_cldtype))        cospOUT%calipso_cldtype(:,:)         = R_UNDEF
    3307           0 :           if (associated(cospOUT%calipso_cldtypetemp))    cospOUT%calipso_cldtypetemp(:,:)     = R_UNDEF
    3308           0 :           if (associated(cospOUT%calipso_cldtypemeanz))   cospOUT%calipso_cldtypemeanz(:,:)    = R_UNDEF
    3309           0 :           if (associated(cospOUT%calipso_cldtypemeanzse)) cospOUT%calipso_cldtypemeanzse(:,:)  = R_UNDEF
    3310           0 :           if (associated(cospOUT%calipso_cldthinemis))    cospOUT%calipso_cldthinemis(:)       = R_UNDEF
    3311             :        endif
    3312             :     endif
    3313        9288 :     if (any([Lparasol_subcolumn,Lparasol_column])) then
    3314     1560168 :        if (any(cospIN%tautot_S_liq .lt. 0)) then
    3315           0 :           nError=nError+1
    3316           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tautot_S_liq contains values out of range'
    3317           0 :           Lparasol_subcolumn = .false.
    3318           0 :           Lparasol_column    = .false.
    3319           0 :           if (associated(cospOUT%parasolPix_refl))  cospOUT%parasolPix_refl(:,:,:) = R_UNDEF
    3320           0 :           if (associated(cospOUT%parasolGrid_refl)) cospOUT%parasolGrid_refl(:,:)  = R_UNDEF
    3321             :        endif
    3322     1560168 :        if (any(cospIN%tautot_S_ice .lt. 0)) then
    3323           0 :           nError=nError+1
    3324           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%tautot_S_ice contains values out of range'
    3325           0 :           Lparasol_subcolumn = .false.
    3326           0 :           Lparasol_column    = .false.
    3327           0 :           if (associated(cospOUT%parasolPix_refl))  cospOUT%parasolPix_refl(:,:,:) = R_UNDEF
    3328           0 :           if (associated(cospOUT%parasolGrid_refl)) cospOUT%parasolGrid_refl(:,:)  = R_UNDEF
    3329             :        endif
    3330             :     endif
    3331        9288 :     if (any([Lcloudsat_subcolumn,Lcloudsat_column,Lradar_lidar_tcc,Llidar_only_freq_cloud, &
    3332             :         Lcloudsat_tcc, Lcloudsat_tcc2])) then
    3333   131063400 :        if (any(cospIN%z_vol_cloudsat .lt. 0)) then
    3334           0 :           nError=nError+1
    3335           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%z_vol_cloudsat contains values out of range'
    3336           0 :           Lcloudsat_subcolumn = .false.
    3337           0 :           Lcloudsat_column    = .false.
    3338           0 :           Lradar_lidar_tcc    = .false.
    3339           0 :           Llidar_only_freq_cloud = .false.
    3340           0 :           Lcloudsat_tcc       = .false.
    3341           0 :           Lcloudsat_tcc2      = .false.
    3342           0 :           if (associated(cospOUT%cloudsat_cfad_ze))          cospOUT%cloudsat_cfad_ze(:,:,:)        = R_UNDEF
    3343           0 :           if (associated(cospOUT%cloudsat_Ze_tot))           cospOUT%cloudsat_Ze_tot(:,:,:)         = R_UNDEF
    3344           0 :           if (associated(cospOUT%lidar_only_freq_cloud))     cospOUT%lidar_only_freq_cloud(:,:)     = R_UNDEF
    3345           0 :           if (associated(cospOUT%radar_lidar_tcc))           cospOUT%radar_lidar_tcc(:)             = R_UNDEF
    3346           0 :           if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    3347           0 :           if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    3348             :        endif
    3349   131063400 :        if (any(cospIN%kr_vol_cloudsat .lt. 0)) then
    3350           0 :           nError=nError+1
    3351           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%kr_vol_cloudsat contains values out of range'
    3352           0 :           Lcloudsat_subcolumn = .false.
    3353           0 :           Lcloudsat_column    = .false.
    3354           0 :           Lradar_lidar_tcc    = .false.
    3355           0 :           Llidar_only_freq_cloud = .false.
    3356           0 :           Lcloudsat_tcc       = .false.
    3357           0 :           Lcloudsat_tcc2      = .false.
    3358           0 :           if (associated(cospOUT%cloudsat_cfad_ze))          cospOUT%cloudsat_cfad_ze(:,:,:)        = R_UNDEF
    3359           0 :           if (associated(cospOUT%cloudsat_Ze_tot))           cospOUT%cloudsat_Ze_tot(:,:,:)         = R_UNDEF
    3360           0 :           if (associated(cospOUT%lidar_only_freq_cloud))     cospOUT%lidar_only_freq_cloud(:,:)     = R_UNDEF
    3361           0 :           if (associated(cospOUT%radar_lidar_tcc))           cospOUT%radar_lidar_tcc(:)             = R_UNDEF
    3362           0 :           if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    3363           0 :           if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF
    3364             :        endif
    3365   131063400 :        if (any(cospIN%g_vol_cloudsat .lt. 0)) then
    3366           0 :           nError=nError+1
    3367           0 :           errorMessage(nError) = 'ERROR: COSP input variable: cospIN%g_vol_cloudsat contains values out of range'
    3368           0 :           Lcloudsat_subcolumn = .false.
    3369           0 :           Lcloudsat_column    = .false.
    3370           0 :           Lradar_lidar_tcc    = .false.
    3371           0 :           Llidar_only_freq_cloud = .false.
    3372           0 :           Lcloudsat_tcc       = .false.
    3373           0 :           Lcloudsat_tcc2      = .false.          
    3374           0 :           if (associated(cospOUT%cloudsat_cfad_ze))          cospOUT%cloudsat_cfad_ze(:,:,:)        = R_UNDEF
    3375           0 :           if (associated(cospOUT%cloudsat_Ze_tot))           cospOUT%cloudsat_Ze_tot(:,:,:)         = R_UNDEF
    3376           0 :           if (associated(cospOUT%lidar_only_freq_cloud))     cospOUT%lidar_only_freq_cloud(:,:)     = R_UNDEF
    3377           0 :           if (associated(cospOUT%radar_lidar_tcc))           cospOUT%radar_lidar_tcc(:)             = R_UNDEF
    3378           0 :           if (associated(cospOUT%cloudsat_tcc)) cospOUT%cloudsat_tcc(:) = R_UNDEF
    3379           0 :           if (associated(cospOUT%cloudsat_tcc2)) cospOUT%cloudsat_tcc2(:) = R_UNDEF          
    3380             :        endif
    3381             :     endif
    3382             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3383             :     ! Part 2: Check input fields array size for consistency. This needs to be done for each
    3384             :     !         simulator
    3385             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3386             :     ! ISCCP
    3387        9288 :     if (Lisccp_subcolumn .or. Lisccp_column) then
    3388             :        if (size(cospIN%frac_out,1)  .ne. cospIN%Npoints .OR. &
    3389             :            size(cospIN%tau_067,1)   .ne. cospIN%Npoints .OR. &
    3390             :            size(cospIN%emiss_11,1)  .ne. cospIN%Npoints .OR. &
    3391             :            size(cospgridIN%skt)     .ne. cospIN%Npoints .OR. &
    3392             :            size(cospgridIN%qv,1)    .ne. cospIN%Npoints .OR. &
    3393             :            size(cospgridIN%at,1)    .ne. cospIN%Npoints .OR. &
    3394             :            size(cospgridIN%phalf,1) .ne. cospIN%Npoints .OR. &
    3395        9288 :            size(cospgridIN%sunlit)  .ne. cospIN%Npoints .OR. &
    3396             :            size(cospgridIN%pfull,1) .ne. cospIN%Npoints) then
    3397           0 :           Lisccp_subcolumn = .false.
    3398           0 :           Lisccp_column    = .false.
    3399           0 :           nError=nError+1
    3400           0 :           errorMessage(nError) = 'ERROR(isccp_simulator): The number of points in the input fields are inconsistent'
    3401             :        endif
    3402             :        if (size(cospIN%frac_out,2) .ne. cospIN%Ncolumns .OR. &
    3403        9288 :            size(cospIN%tau_067,2)  .ne. cospIN%Ncolumns .OR. &
    3404             :            size(cospIN%emiss_11,2) .ne. cospIN%Ncolumns) then
    3405           0 :           Lisccp_subcolumn = .false.
    3406           0 :           Lisccp_column    = .false.
    3407           0 :           nError=nError+1
    3408           0 :           errorMessage(nError) = 'ERROR(isccp_simulator): The number of sub-columns in the input fields are inconsistent'
    3409             :        endif
    3410             :        if (size(cospIN%frac_out,3)  .ne. cospIN%Nlevels .OR. &
    3411             :            size(cospIN%tau_067,3)   .ne. cospIN%Nlevels .OR. &
    3412             :            size(cospIN%emiss_11,3)  .ne. cospIN%Nlevels .OR. &
    3413             :            size(cospgridIN%qv,2)    .ne. cospIN%Nlevels .OR. &
    3414             :            size(cospgridIN%at,2)    .ne. cospIN%Nlevels .OR. &
    3415        9288 :            size(cospgridIN%pfull,2) .ne. cospIN%Nlevels .OR. &
    3416             :            size(cospgridIN%phalf,2) .ne. cospIN%Nlevels+1) then
    3417           0 :           Lisccp_subcolumn = .false.
    3418           0 :           Lisccp_column    = .false.
    3419           0 :           nError=nError+1
    3420           0 :           errorMessage(nError) = 'ERROR(isccp_simulator): The number of levels in the input fields are inconsistent'
    3421             :        endif
    3422             :     endif
    3423             :     
    3424             :     ! MISR
    3425        9288 :     if (Lmisr_subcolumn .or. Lmisr_column) then
    3426             :        if (size(cospIN%tau_067,1)        .ne. cospIN%Npoints .OR. &
    3427             :            size(cospgridIN%sunlit)       .ne. cospIN%Npoints .OR. &
    3428        9288 :            size(cospgridIN%hgt_matrix,1) .ne. cospIN%Npoints .OR. &
    3429             :            size(cospgridIN%at,1)         .ne. cospIN%Npoints) then
    3430           0 :           Lmisr_subcolumn = .false.
    3431           0 :           Lmisr_column    = .false.
    3432           0 :           nError=nError+1
    3433           0 :           errorMessage(nError) = 'ERROR(misr_simulator): The number of points in the input fields are inconsistent'
    3434             :        endif
    3435        9288 :        if (size(cospIN%tau_067,2) .ne. cospIN%Ncolumns) then
    3436           0 :           Lmisr_subcolumn = .false.
    3437           0 :           Lmisr_column    = .false.
    3438           0 :           nError=nError+1
    3439           0 :           errorMessage(nError) = 'ERROR(misr_simulator): The number of sub-columns in the input fields are inconsistent'
    3440             :        endif
    3441             :        if (size(cospIN%tau_067,3)        .ne. cospIN%Nlevels .OR. &
    3442        9288 :            size(cospgridIN%hgt_matrix,2) .ne. cospIN%Nlevels .OR. &
    3443             :            size(cospgridIN%at,2)         .ne. cospIN%Nlevels) then
    3444           0 :           Lmisr_subcolumn = .false.
    3445           0 :           Lmisr_column    = .false.
    3446           0 :           nError=nError+1
    3447           0 :           errorMessage(nError) = 'ERROR(misr_simulator): The number of levels in the input fields are inconsistent'
    3448             :        endif
    3449             :     endif
    3450             :     
    3451             :     ! MODIS
    3452        9288 :     if (Lmodis_subcolumn .or. Lmodis_column) then
    3453             :        if (size(cospIN%fracLiq,1) .ne. cospIN%Npoints .OR. &
    3454             :            size(cospIN%tau_067,1) .ne. cospIN%Npoints .OR. &
    3455        9288 :            size(cospIN%asym,1)    .ne. cospIN%Npoints .OR. &
    3456             :            size(cospIN%ss_alb,1)  .ne. cospIN%Npoints) then
    3457           0 :           Lmodis_subcolumn = .false.
    3458           0 :           Lmodis_column    = .false.
    3459           0 :           nError=nError+1
    3460           0 :           errorMessage(nError) = 'ERROR(modis_simulator): The number of points in the input fields are inconsistent'
    3461             :        endif
    3462             :        if (size(cospIN%fracLiq,2) .ne. cospIN%Ncolumns .OR. &
    3463             :            size(cospIN%tau_067,2) .ne. cospIN%Ncolumns .OR. &
    3464        9288 :            size(cospIN%asym,2)    .ne. cospIN%Ncolumns .OR. &
    3465             :            size(cospIN%ss_alb,2)  .ne. cospIN%Ncolumns) then
    3466           0 :           Lmodis_subcolumn = .false.
    3467           0 :           Lmodis_column    = .false.
    3468           0 :           nError=nError+1
    3469           0 :           errorMessage(nError) = 'ERROR(modis_simulator): The number of sub-columns in the input fields are inconsistent'
    3470             :        endif
    3471             :        if (size(cospIN%fracLiq,3) .ne. cospIN%Nlevels .OR. &
    3472             :            size(cospIN%tau_067,3) .ne. cospIN%Nlevels .OR. &
    3473        9288 :            size(cospIN%asym,3)    .ne. cospIN%Nlevels .OR. &
    3474             :            size(cospIN%ss_alb,3)  .ne. cospIN%Nlevels) then
    3475           0 :           Lmodis_subcolumn = .false.
    3476           0 :           Lmodis_column    = .false.
    3477           0 :           nError=nError+1
    3478           0 :           errorMessage(nError) = 'ERROR(modis_simulator): The number of levels in the input fields are inconsistent'
    3479             :        endif
    3480             :     endif
    3481             :     
    3482             :     ! CLOUDSAT
    3483        9288 :     if (Lcloudsat_subcolumn .or. Lcloudsat_column) then
    3484             :        if (size(cospIN%z_vol_cloudsat,1)   .ne. cospIN%Npoints .OR. &
    3485             :            size(cospIN%kr_vol_cloudsat,1)  .ne. cospIN%Npoints .OR. &
    3486        9288 :            size(cospIN%g_vol_cloudsat,1)   .ne. cospIN%Npoints .OR. &
    3487             :            size(cospgridIN%hgt_matrix,1)   .ne. cospIN%Npoints) then
    3488           0 :           Lcloudsat_subcolumn = .false.
    3489           0 :           Lcloudsat_column    = .false.
    3490           0 :           nError=nError+1
    3491           0 :           errorMessage(nError) = 'ERROR(cloudsat_simulator): The number of points in the input fields are inconsistent'
    3492             :        endif
    3493             :        if (size(cospIN%z_vol_cloudsat,2)  .ne. cospIN%Ncolumns .OR. &
    3494        9288 :            size(cospIN%kr_vol_cloudsat,2) .ne. cospIN%Ncolumns .OR. &
    3495             :            size(cospIN%g_vol_cloudsat,2)  .ne. cospIN%Ncolumns) then
    3496           0 :           Lcloudsat_subcolumn = .false.
    3497           0 :           Lcloudsat_column    = .false.
    3498           0 :           nError=nError+1
    3499           0 :           errorMessage(nError) = 'ERROR(cloudsat_simulator): The number of sub-columns in the input fields are inconsistent'
    3500             :        endif
    3501             :        if (size(cospIN%z_vol_cloudsat,3)  .ne. cospIN%Nlevels .OR. &
    3502             :            size(cospIN%kr_vol_cloudsat,3) .ne. cospIN%Nlevels .OR. &
    3503        9288 :            size(cospIN%g_vol_cloudsat,3)  .ne. cospIN%Nlevels .OR. &
    3504             :            size(cospgridIN%hgt_matrix,2)  .ne. cospIN%Nlevels) then
    3505           0 :           Lcloudsat_subcolumn = .false.
    3506           0 :           Lcloudsat_column    = .false.
    3507           0 :           nError=nError+1
    3508           0 :           errorMessage(nError) = 'ERROR(cloudsat_simulator): The number of levels in the input fields are inconsistent'
    3509             :        endif
    3510             :     endif
    3511             : 
    3512             :     ! GROUND LIDAR @ 532nm
    3513        9288 :     if (LgrLidar532_subcolumn .or. LgrLidar532_column) then
    3514             :        if (size(cospIN%beta_mol_grLidar532,1)    .ne. cospIN%Npoints .OR. & 
    3515             :            size(cospIN%betatot_grLidar532,1)     .ne. cospIN%Npoints .OR. &
    3516           0 :            size(cospIN%tau_mol_grLidar532,1)     .ne. cospIN%Npoints .OR. &
    3517             :            size(cospIN%tautot_grLidar532,1)      .ne. cospIN%Npoints) then
    3518           0 :           LgrLidar532_subcolumn = .false.
    3519           0 :           LgrLidar532_column    = .false.
    3520           0 :           nError=nError+1
    3521           0 :           errorMessage(nError) = 'ERROR(grLidar532_simulator): The number of points in the input fields are inconsistent'
    3522             :        endif
    3523           0 :        if (size(cospIN%betatot_grLidar532,2)    .ne. cospIN%Ncolumns .OR. & 
    3524             :            size(cospIN%tautot_grLidar532,2)     .ne. cospIN%Ncolumns) then 
    3525           0 :           LgrLidar532_subcolumn = .false. 
    3526           0 :           LgrLidar532_column    = .false. 
    3527           0 :           nError=nError+1
    3528           0 :           errorMessage(nError) = 'ERROR(grLidar532_simulator): The number of sub-columns in the input fields are inconsistent'
    3529             :        endif
    3530             :        if (size(cospIN%beta_mol_grLidar532,2)    .ne. cospIN%Nlevels .OR. &
    3531             :            size(cospIN%betatot_grLidar532,3)     .ne. cospIN%Nlevels .OR. &
    3532           0 :            size(cospIN%tau_mol_grLidar532,2)     .ne. cospIN%Nlevels .OR. &
    3533             :            size(cospIN%tautot_grLidar532,3)      .ne. cospIN%Nlevels) then
    3534           0 :           LgrLidar532_subcolumn = .false. 
    3535           0 :           LgrLidar532_column    = .false. 
    3536           0 :           nError=nError+1
    3537           0 :           errorMessage(nError) = 'ERROR(grLidar532_simulator): The number of levels in the input fields are inconsistent' 
    3538             :        endif
    3539             :     endif
    3540             :     
    3541             :     ! ATLID
    3542        9288 :     if (Latlid_subcolumn .or. Latlid_column) then
    3543             :        if (size(cospIN%beta_mol_atlid,1)    .ne. cospIN%Npoints .OR. &
    3544             :            size(cospIN%betatot_atlid,1)     .ne. cospIN%Npoints .OR. &
    3545           0 :            size(cospIN%tau_mol_atlid,1)     .ne. cospIN%Npoints .OR. & 
    3546             :            size(cospIN%tautot_atlid,1)      .ne. cospIN%Npoints) then 
    3547           0 :           Latlid_subcolumn = .false. 
    3548           0 :           Latlid_column    = .false. 
    3549           0 :           nError=nError+1             
    3550           0 :           errorMessage(nError) = 'ERROR(atlid_simulator): The number of points in the input fields are inconsistent'
    3551             :        endif
    3552           0 :        if (size(cospIN%betatot_atlid,2)    .ne. cospIN%Ncolumns .OR. &
    3553             :            size(cospIN%tautot_atlid,2)     .ne. cospIN%Ncolumns) then 
    3554           0 :           Latlid_subcolumn = .false.
    3555           0 :           Latlid_column    = .false.
    3556           0 :           nError=nError+1              
    3557           0 :           errorMessage(nError) = 'ERROR(atlid_simulator): The number of sub-columns in the input fields are inconsistent'
    3558             :        endif
    3559             :        if (size(cospIN%beta_mol_atlid,2)    .ne. cospIN%Nlevels .OR. &
    3560             :            size(cospIN%betatot_atlid,3)     .ne. cospIN%Nlevels .OR. & 
    3561           0 :            size(cospIN%tau_mol_atlid,2)     .ne. cospIN%Nlevels .OR. &
    3562             :            size(cospIN%tautot_atlid,3)      .ne. cospIN%Nlevels) then 
    3563           0 :           Latlid_subcolumn = .false.
    3564           0 :           Latlid_column    = .false. 
    3565           0 :           nError=nError+1 
    3566           0 :           errorMessage(nError) = 'ERROR(atlid_simulator): The number of levels in the input fields are inconsistent'
    3567             :        endif
    3568             :     endif
    3569             : 
    3570             :     ! CALIPSO
    3571        9288 :     if (Lcalipso_subcolumn .or. Lcalipso_column) then
    3572             :        if (size(cospIN%beta_mol_calipso,1)    .ne. cospIN%Npoints .OR. &
    3573             :            size(cospIN%betatot_calipso,1)     .ne. cospIN%Npoints .OR. &
    3574             :            size(cospIN%betatot_liq_calipso,1) .ne. cospIN%Npoints .OR. &
    3575             :            size(cospIN%betatot_ice_calipso,1) .ne. cospIN%Npoints .OR. &
    3576             :            size(cospIN%tau_mol_calipso,1)     .ne. cospIN%Npoints .OR. &
    3577             :            size(cospIN%tautot_calipso,1)      .ne. cospIN%Npoints .OR. &
    3578        9288 :            size(cospIN%tautot_liq_calipso,1)  .ne. cospIN%Npoints .OR. &
    3579             :            size(cospIN%tautot_ice_calipso,1)  .ne. cospIN%Npoints) then
    3580           0 :           Lcalipso_subcolumn = .false.
    3581           0 :           Lcalipso_column    = .false.
    3582           0 :           nError=nError+1
    3583           0 :           errorMessage(nError) = 'ERROR(calipso_simulator): The number of points in the input fields are inconsistent'
    3584             :        endif
    3585             :        if (size(cospIN%betatot_calipso,2)     .ne. cospIN%Ncolumns .OR. &
    3586             :            size(cospIN%betatot_liq_calipso,2) .ne. cospIN%Ncolumns .OR. &
    3587             :            size(cospIN%betatot_ice_calipso,2) .ne. cospIN%Ncolumns .OR. &
    3588             :            size(cospIN%tautot_calipso,2)      .ne. cospIN%Ncolumns .OR. &
    3589        9288 :            size(cospIN%tautot_liq_calipso,2)  .ne. cospIN%Ncolumns .OR. &
    3590             :            size(cospIN%tautot_ice_calipso,2)  .ne. cospIN%Ncolumns) then
    3591           0 :           Lcalipso_subcolumn = .false.
    3592           0 :           Lcalipso_column    = .false.
    3593           0 :           nError=nError+1
    3594           0 :           errorMessage(nError) = 'ERROR(calipso_simulator): The number of sub-columns in the input fields are inconsistent'
    3595             :        endif
    3596             :        if (size(cospIN%beta_mol_calipso,2)    .ne. cospIN%Nlevels .OR. &
    3597             :            size(cospIN%betatot_calipso,3)     .ne. cospIN%Nlevels .OR. &
    3598             :            size(cospIN%betatot_liq_calipso,3) .ne. cospIN%Nlevels .OR. &
    3599             :            size(cospIN%betatot_ice_calipso,3) .ne. cospIN%Nlevels .OR. &
    3600             :            size(cospIN%tau_mol_calipso,2)     .ne. cospIN%Nlevels .OR. &
    3601             :            size(cospIN%tautot_calipso,3)      .ne. cospIN%Nlevels .OR. &
    3602        9288 :            size(cospIN%tautot_liq_calipso,3)  .ne. cospIN%Nlevels .OR. &
    3603             :            size(cospIN%tautot_ice_calipso,3)  .ne. cospIN%Nlevels) then
    3604           0 :           Lcalipso_subcolumn = .false.
    3605           0 :           Lcalipso_column    = .false.
    3606           0 :           nError=nError+1
    3607           0 :           errorMessage(nError) = 'ERROR(calipso_simulator): The number of levels in the input fields are inconsistent'
    3608             :        endif
    3609             :     endif
    3610             :     
    3611             :     ! PARASOL
    3612        9288 :     if (Lparasol_subcolumn .or. Lparasol_column) then
    3613        9288 :        if (size(cospIN%tautot_S_liq,1) .ne. cospIN%Npoints .OR. &
    3614             :            size(cospIN%tautot_S_ice,1) .ne. cospIN%Npoints) then
    3615           0 :           Lparasol_subcolumn = .false.
    3616           0 :           Lparasol_column    = .false.
    3617           0 :           nError=nError+1
    3618           0 :           errorMessage(nError) = 'ERROR(parasol_simulator): The number of points in the input fields are inconsistent'
    3619             :        endif
    3620        9288 :        if (size(cospIN%tautot_S_liq,2) .ne. cospIN%Ncolumns .OR. &
    3621             :            size(cospIN%tautot_S_ice,2) .ne. cospIN%Ncolumns) then
    3622           0 :           Lparasol_subcolumn = .false.
    3623           0 :           Lparasol_column    = .false.
    3624           0 :           nError=nError+1
    3625           0 :           errorMessage(nError) = 'ERROR(parasol_simulator): The number of levels in the input fields are inconsistent'
    3626             :        endif
    3627             :     endif
    3628             : 
    3629             :     ! RTTOV
    3630        9288 :     if (Lrttov_column) then
    3631             :        if (size(cospgridIN%pfull,1)           .ne. cospIN%Npoints .OR. &
    3632             :            size(cospgridIN%at,1)              .ne. cospIN%Npoints .OR. &
    3633             :            size(cospgridIN%qv,1)              .ne. cospIN%Npoints .OR. &
    3634             :            size(cospgridIN%hgt_matrix_half,1) .ne. cospIN%Npoints .OR. &
    3635             :            size(cospgridIN%u_sfc)             .ne. cospIN%Npoints .OR. &
    3636             :            size(cospgridIN%v_sfc)             .ne. cospIN%Npoints .OR. &
    3637             :            size(cospgridIN%skt)               .ne. cospIN%Npoints .OR. &
    3638             :            size(cospgridIN%phalf,1)           .ne. cospIN%Npoints .OR. &
    3639             :            size(cospgridIN%qv,1)              .ne. cospIN%Npoints .OR. &
    3640           0 :            size(cospgridIN%land)              .ne. cospIN%Npoints .OR. &
    3641             :            size(cospgridIN%lat)               .ne. cospIN%Npoints) then
    3642           0 :           Lrttov_column    = .false.
    3643           0 :           nError=nError+1
    3644           0 :           errorMessage(nError) = 'ERROR(rttov_simulator): The number of points in the input fields are inconsistent'
    3645             :        endif
    3646             :        if (size(cospgridIN%pfull,2)           .ne. cospIN%Nlevels   .OR. &
    3647             :            size(cospgridIN%at,2)              .ne. cospIN%Nlevels   .OR. &
    3648             :            size(cospgridIN%qv,2)              .ne. cospIN%Nlevels   .OR. &
    3649             :            size(cospgridIN%hgt_matrix_half,2) .ne. cospIN%Nlevels+1 .OR. &
    3650           0 :            size(cospgridIN%phalf,2)           .ne. cospIN%Nlevels+1 .OR. &
    3651             :            size(cospgridIN%qv,2)              .ne. cospIN%Nlevels) then
    3652           0 :           Lrttov_column    = .false.
    3653           0 :           nError=nError+1
    3654           0 :           errorMessage(nError) = 'ERROR(rttov_simulator): The number of levels in the input fields are inconsistent'
    3655             :        endif
    3656             :     endif
    3657        9288 :   end subroutine cosp_errorCheck
    3658             : 
    3659             :   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3660             :   ! END MODULE
    3661             :   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3662           0 : END MODULE MOD_COSP

Generated by: LCOV version 1.14