LCOV - code coverage report
Current view: top level - chemistry/aerosol - soil_erod_mod.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 45 0.0 %
Date: 2024-12-17 22:39:59 Functions: 0 1 0.0 %

          Line data    Source code
       1             : !===============================================================================
       2             : !===============================================================================
       3             : module soil_erod_mod
       4             :   use shr_kind_mod,     only: r8 => shr_kind_r8, cl => shr_kind_cl
       5             :   use cam_logfile,      only: iulog
       6             :   use spmd_utils,       only: masterproc
       7             :   use cam_abortutils,   only: endrun
       8             : 
       9             :   implicit none
      10             :   private
      11             : 
      12             :   public :: soil_erod_init
      13             :   public :: soil_erodibility
      14             :   public :: soil_erod_fact
      15             : 
      16             :   real(r8), allocatable ::  soil_erodibility(:,:)  ! soil erodibility factor
      17             :   real(r8) :: soil_erod_fact                       ! tuning parameter for dust emissions
      18             : 
      19             : contains
      20             : 
      21             :   !=============================================================================
      22             :   !=============================================================================
      23           0 :   subroutine soil_erod_init( dust_emis_fact, soil_erod_file )
      24             :     use interpolate_data, only: lininterp_init, lininterp, lininterp_finish, interp_type
      25             :     use ppgrid,           only: begchunk, endchunk, pcols
      26             :     use mo_constants,     only: pi, d2r
      27             :     use pio,              only: file_desc_t,pio_inq_dimid,pio_inq_dimlen,pio_get_var,pio_inq_varid, PIO_NOWRITE
      28             :     use phys_grid,        only: get_ncols_p, get_rlat_all_p, get_rlon_all_p
      29             :     use cam_pio_utils,    only: cam_pio_openfile
      30             :     use ioFileMod,        only: getfil
      31             : 
      32             :     real(r8),         intent(in) :: dust_emis_fact
      33             :     character(len=*), intent(in) :: soil_erod_file
      34             : 
      35           0 :     real(r8), allocatable ::  soil_erodibility_in(:,:)  ! temporary input array
      36           0 :     real(r8), allocatable :: dst_lons(:)
      37           0 :     real(r8), allocatable :: dst_lats(:)
      38             :     character(len=cl)     :: infile
      39             :     integer :: did, vid, nlat, nlon
      40             :     type(file_desc_t) :: ncid
      41             : 
      42             :     type(interp_type) :: lon_wgts, lat_wgts
      43             :     real(r8) :: to_lats(pcols), to_lons(pcols)
      44             :     integer :: c, ncols, ierr
      45             :     real(r8), parameter :: zero=0._r8, twopi=2._r8*pi
      46             : 
      47           0 :     soil_erod_fact = dust_emis_fact
      48             : 
      49             :     ! Summary to log file
      50           0 :     if (masterproc) then
      51           0 :        write(iulog,*) 'soil_erod_mod: soil erodibility dataset: ', trim(soil_erod_file)
      52           0 :        write(iulog,*) 'soil_erod_mod: soil_erod_fact = ', soil_erod_fact
      53             :     end if
      54             : 
      55             :     ! for soil erodibility in mobilization, apply inside CAM instead of lsm.
      56             :     ! read in soil erodibility factors, similar to Zender's boundary conditions
      57             : 
      58             :     ! Get file name.  
      59           0 :     call getfil(soil_erod_file, infile, 0)
      60           0 :     call cam_pio_openfile (ncid, trim(infile), PIO_NOWRITE)
      61             : 
      62             :     ! Get input data resolution.
      63           0 :     ierr = pio_inq_dimid( ncid, 'lon', did )
      64           0 :     ierr = pio_inq_dimlen( ncid, did, nlon )
      65             : 
      66           0 :     ierr = pio_inq_dimid( ncid, 'lat', did )
      67           0 :     ierr = pio_inq_dimlen( ncid, did, nlat )
      68             : 
      69           0 :     allocate(dst_lons(nlon))
      70           0 :     allocate(dst_lats(nlat))
      71           0 :     allocate(soil_erodibility_in(nlon,nlat))
      72             : 
      73           0 :     ierr = pio_inq_varid( ncid, 'lon', vid )
      74           0 :     ierr = pio_get_var( ncid, vid, dst_lons  )
      75             : 
      76           0 :     ierr = pio_inq_varid( ncid, 'lat', vid )
      77           0 :     ierr = pio_get_var( ncid, vid, dst_lats  )
      78             : 
      79           0 :     ierr = pio_inq_varid( ncid, 'mbl_bsn_fct_geo', vid )
      80           0 :     ierr = pio_get_var( ncid, vid, soil_erodibility_in )
      81             : 
      82             :     !-----------------------------------------------------------------------
      83             :     !           ... convert to radians and setup regridding
      84             :     !-----------------------------------------------------------------------
      85           0 :     dst_lats(:) = d2r * dst_lats(:)
      86           0 :     dst_lons(:) = d2r * dst_lons(:)
      87             : 
      88           0 :     allocate( soil_erodibility(pcols,begchunk:endchunk), stat=ierr )
      89           0 :     if( ierr /= 0 ) then
      90           0 :        write(iulog,*) 'soil_erod_init: failed to allocate soil_erodibility_in, ierr = ',ierr
      91           0 :        call endrun('soil_erod_init: failed to allocate soil_erodibility_in')
      92             :     end if
      93             : 
      94             :     !-----------------------------------------------------------------------
      95             :     !           ... regrid ..
      96             :     !-----------------------------------------------------------------------
      97           0 :     do c=begchunk,endchunk
      98           0 :        ncols = get_ncols_p(c)
      99           0 :        call get_rlat_all_p(c, pcols, to_lats)
     100           0 :        call get_rlon_all_p(c, pcols, to_lons)
     101             : 
     102           0 :        call lininterp_init(dst_lons, nlon, to_lons, ncols, 2, lon_wgts, zero, twopi)
     103           0 :        call lininterp_init(dst_lats, nlat, to_lats, ncols, 1, lat_wgts)
     104             : 
     105           0 :        call lininterp(soil_erodibility_in(:,:), nlon,nlat , soil_erodibility(:,c), ncols, lon_wgts,lat_wgts)
     106             : 
     107           0 :        call lininterp_finish(lat_wgts)
     108           0 :        call lininterp_finish(lon_wgts)
     109             :     end do
     110           0 :     deallocate( soil_erodibility_in, stat=ierr )
     111           0 :     if( ierr /= 0 ) then
     112           0 :        write(iulog,*) 'soil_erod_init: failed to deallocate soil_erodibility_in, ierr = ',ierr
     113           0 :        call endrun('soil_erod_init: failed to deallocate soil_erodibility_in')
     114             :     end if
     115             : 
     116           0 :     deallocate( dst_lats )
     117           0 :     deallocate( dst_lons )
     118             : 
     119           0 :   end  subroutine soil_erod_init
     120             : 
     121             : end module soil_erod_mod

Generated by: LCOV version 1.14