LCOV - code coverage report
Current view: | top level - chemistry/utils - solar_wind_data.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 11 | 35 | 31.4 %
Date: | 2025-01-13 21:54:50 |  | Functions: | 2 | 2 | 100.0 %

              Line data    Source code
           1             : !-------------------------------------------------------------------------------
           2             : ! solar wind data -- IMF components, wind velocity and density
           3             : !-------------------------------------------------------------------------------
           4             : module solar_wind_data
           5             :
           6             :   use shr_kind_mod,     only : r8 => shr_kind_r8, shr_kind_cl
           7             :   use input_data_utils, only : time_coordinate
           8             :   use infnan,           only : nan, assignment(=)
           9             :
          10             :   implicit none
          11             :
          12             :   private
          13             :   save
          14             :
          15             :  ! public interface
          16             :
          17             :   public :: solar_wind_init
          18             :   public :: solar_wind_advance
          19             :
          20             :   logical, public :: solar_wind_on = .false.
          21             :
          22             :  ! time-interpolated quantities
          23             :
          24             :   real(r8), public, protected :: solar_wind_byimf
          25             :   real(r8), public, protected :: solar_wind_bzimf
          26             :   real(r8), public, protected :: solar_wind_swvel
          27             :   real(r8), public, protected :: solar_wind_swden
          28             :
          29             :  ! private data
          30             :
          31             :   real(r8), allocatable :: byimf_in(:)
          32             :   real(r8), allocatable :: bzimf_in(:)
          33             :   real(r8), allocatable :: swvel_in(:)
          34             :   real(r8), allocatable :: swden_in(:)
          35             :
          36             :   type(time_coordinate) :: time_coord
          37             :
          38             : contains
          39             :
          40        1536 :   subroutine solar_wind_init(filepath, fixed, fixed_ymd, fixed_tod)
          41             :     !---------------------------------------------------------------
          42             :     !   ... initialize solar parmaters
          43             :     !---------------------------------------------------------------
          44             :
          45             :     use ioFileMod
          46             :     use error_messages, only: alloc_err
          47             :     use cam_pio_utils,  only: cam_pio_openfile
          48             :     use pio,            only: file_desc_t, var_desc_t, pio_get_var, &
          49             :                               pio_inq_varid, pio_closefile, pio_nowrite
          50             :
          51             :     !---------------------------------------------------------------
          52             :     ! arguments
          53             :     !---------------------------------------------------------------
          54             :     character(len=*), intent(in) :: filepath
          55             :     logical, intent(in) :: fixed
          56             :     integer, intent(in) :: fixed_ymd
          57             :     integer, intent(in) :: fixed_tod
          58             :
          59             :     !---------------------------------------------------------------
          60             :     !   ... local variables
          61             :     !---------------------------------------------------------------
          62             :     type(file_desc_t)  :: ncid
          63             :     type(var_desc_t)  :: varid
          64             :     integer  :: astat
          65             :     character(len=shr_kind_cl) :: locfn
          66             :     integer :: ierr
          67             :
          68        1536 :     solar_wind_byimf = nan
          69        1536 :     solar_wind_bzimf = nan
          70        1536 :     solar_wind_swvel = nan
          71        1536 :     solar_wind_swden = nan
          72             :
          73        1536 :     solar_wind_on = (trim(filepath).ne.'NONE' .and. len_trim(filepath)>0)
          74             :
          75        1536 :     if (.not.solar_wind_on) return
          76             :
          77             :     !-----------------------------------------------------------------------
          78             :     !   ... readin the solar parms dataset
          79             :     !-----------------------------------------------------------------------
          80             :
          81           0 :     call getfil(filepath,  locfn, 0)
          82           0 :     call cam_pio_openfile ( ncid, locfn, PIO_NOWRITE)
          83             :
          84             :     call time_coord%initialize( filepath, fixed=fixed, fixed_ymd=fixed_ymd, &
          85           0 :                                 fixed_tod=fixed_tod, force_time_interp=.true. )
          86             :
          87             :     !---------------------------------------------------------------
          88             :     !   ... allocate and read solar parms
          89             :     !---------------------------------------------------------------
          90             :     allocate( byimf_in(time_coord%ntimes), bzimf_in(time_coord%ntimes), &
          91             :               swvel_in(time_coord%ntimes), swden_in(time_coord%ntimes), &
          92           0 :               stat=astat )
          93           0 :     if( astat /= 0 ) then
          94             :        call alloc_err( astat, 'solar_wind_init', 'byimf_in ... swden_in ', &
          95           0 :                        time_coord%ntimes )
          96             :     end if
          97             :
          98           0 :     ierr = pio_inq_varid( ncid, 'by', varid )
          99           0 :     ierr = pio_get_var( ncid, varid, byimf_in )
         100           0 :     ierr = pio_inq_varid( ncid, 'bz', varid )
         101           0 :     ierr = pio_get_var( ncid, varid, bzimf_in )
         102           0 :     ierr = pio_inq_varid( ncid, 'swvel', varid )
         103           0 :     ierr = pio_get_var( ncid, varid, swvel_in )
         104           0 :     ierr = pio_inq_varid( ncid, 'swden', varid )
         105           0 :     ierr = pio_get_var( ncid, varid, swden_in )
         106             :
         107           0 :     call pio_closefile( ncid )
         108             :
         109        3072 : end subroutine solar_wind_init
         110             :
         111      370944 : subroutine solar_wind_advance
         112             :   !---------------------------------------------------------------
         113             :   ! time interpolate space wx indices
         114             :   !---------------------------------------------------------------
         115             :
         116      370944 :   if (solar_wind_on) then
         117           0 :      call time_coord%advance()
         118             :     !  time interpolate
         119           0 :      solar_wind_byimf = time_coord%wghts(1)*byimf_in(time_coord%indxs(1)) &
         120           0 :                       + time_coord%wghts(2)*byimf_in(time_coord%indxs(2))
         121           0 :      solar_wind_bzimf = time_coord%wghts(1)*bzimf_in(time_coord%indxs(1)) &
         122           0 :                       + time_coord%wghts(2)*bzimf_in(time_coord%indxs(2))
         123           0 :      solar_wind_swvel = time_coord%wghts(1)*swvel_in(time_coord%indxs(1)) &
         124           0 :                       + time_coord%wghts(2)*swvel_in(time_coord%indxs(2))
         125           0 :      solar_wind_swden = time_coord%wghts(1)*swden_in(time_coord%indxs(1)) &
         126           0 :                       + time_coord%wghts(2)*swden_in(time_coord%indxs(2))
         127             :   endif
         128             :
         129        1536 : end subroutine solar_wind_advance
         130             :
         131             : end module solar_wind_data

Generated by: LCOV version 1.14