diff --git a/source/ecosys_driver.F90 b/source/ecosys_driver.F90 index a334da98..399ea474 100644 --- a/source/ecosys_driver.F90 +++ b/source/ecosys_driver.F90 @@ -29,6 +29,7 @@ module ecosys_driver use shr_infnan_mod , only : shr_infnan_isnan use marbl_interface , only : marbl_interface_class + use marbl_logging , only : marbl_log_type use namelist_from_str_mod , only : namelist_split_by_line use namelist_from_str_mod , only : namelist_split_by_nl @@ -67,6 +68,7 @@ module ecosys_driver ! !PUBLIC MEMBER FUNCTIONS: public :: ecosys_driver_init + public :: ecosys_driver_set_compute_now public :: ecosys_driver_set_interior_forcing public :: ecosys_driver_set_interior public :: ecosys_driver_set_global_scalars @@ -105,6 +107,7 @@ module ecosys_driver !----------------------------------------------------------------------- type(marbl_interface_class) :: marbl_instances(max_blocks_clinic) + type(marbl_log_type) :: driver_status_log integer (int_kind) :: totChl_surf_nf_ind = 0 ! total chlorophyll in surface layer integer (int_kind) :: sflux_co2_nf_ind = 0 ! air-sea co2 gas flux @@ -232,6 +235,7 @@ subroutine ecosys_driver_init( & ecosys_qsw_distrb_const, marbl_settings_file errorCode = POP_Success + call driver_status_log%construct() lmarginal_seas = .true. ecosys_tadvect_ctype = 'base_model' @@ -571,7 +575,13 @@ subroutine ecosys_driver_init( & ! Initialize tavg ids (need only do this using first block) !-------------------------------------------------------------------- - call ecosys_tavg_init(marbl_instances(1)) + call ecosys_tavg_init(marbl_instances(1), driver_status_log) + if (driver_status_log%labort_marbl) then + call driver_status_log%log_error_trace("ecosys_tavg_init", subname) + call print_marbl_log(marbl_instances(1)%StatusLog, 1) + call print_marbl_log(driver_status_log, 1) + end if + call driver_status_log%erase() !-------------------------------------------------------------------- ! Register and set Chl field for short-wave absorption @@ -759,7 +769,7 @@ subroutine ecosys_driver_set_interior( & call marbl_instances(bid)%interior_tendency_compute() if (marbl_instances(bid)%StatusLog%labort_marbl) then write(log_message,"(A,I0,A)") "marbl_instances(", bid, & - ")%set_interior_forcing()" + ")%interior_tendency_compute()" call marbl_instances(bid)%StatusLog%log_error_trace(log_message, subname) end if call print_marbl_log(marbl_instances(bid)%StatusLog, bid, i, c) @@ -1105,6 +1115,27 @@ end subroutine ecosys_driver_post_set_sflux !*********************************************************************** + subroutine ecosys_driver_set_compute_now() + + use ecosys_tavg, only : ecosys_tavg_set_compute_now + integer :: iblock + logical :: first_call = .true. + + ! Return if function has already been called + if (.not. first_call) return + + ! Loop through instances and set compute_now flag for all diagnostics + do iblock=1,nblocks_clinic + call ecosys_tavg_set_compute_now(marbl_instances(iblock)%surface_flux_diags, 'surface_flux', driver_status_log) + call ecosys_tavg_set_compute_now(marbl_instances(iblock)%interior_tendency_diags, 'interior_tendency', driver_status_log) + call print_marbl_log(driver_status_log, iblock) + call driver_status_log%erase() + end do + first_call = .false. + end subroutine ecosys_driver_set_compute_now + + !*********************************************************************** + subroutine ecosys_driver_comp_global_averages(field_source) ! DESCRIPTION: @@ -1520,7 +1551,6 @@ end subroutine gen_marbl_to_pop_index_mapping subroutine print_marbl_log(log_to_print, iblock, i, j) use marbl_logging, only : marbl_status_log_entry_type - use marbl_logging, only : marbl_log_type use grid, only : TLATD, TLOND use blocks, only : get_block use domain, only : blocks_clinic diff --git a/source/ecosys_tavg.F90 b/source/ecosys_tavg.F90 index 43ac825d..bffca32f 100644 --- a/source/ecosys_tavg.F90 +++ b/source/ecosys_tavg.F90 @@ -26,6 +26,7 @@ module ecosys_tavg use tavg , only : accumulate_tavg_field use shr_sys_mod , only : shr_sys_abort use marbl_interface , only : marbl_interface_class + use marbl_logging , only : marbl_log_type use marbl_interface_public_types , only : marbl_diagnostics_type use ecosys_diagnostics_operators_mod, only : max_marbl_diags_stream_cnt @@ -39,6 +40,7 @@ module ecosys_tavg public :: ecosys_tavg_accumulate_interior public :: ecosys_tavg_accumulate_surface public :: ecosys_tavg_accumulate_scalar_rmeans + public :: ecosys_tavg_set_compute_now !----------------------------------------------------------------------- ! define tavg id for interior tendency diagnostics, diagnostics related @@ -59,7 +61,7 @@ module ecosys_tavg !*********************************************************************** - subroutine ecosys_tavg_init(marbl_instance) + subroutine ecosys_tavg_init(marbl_instance, status_log) ! !DESCRIPTION: ! call define_tavg_field for all tavg fields @@ -68,9 +70,8 @@ subroutine ecosys_tavg_init(marbl_instance) use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_surface use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_interior - implicit none - - type(marbl_interface_class) , intent(in) :: marbl_instance + type(marbl_interface_class), intent(in) :: marbl_instance + type(marbl_log_type), intent(inout) :: status_log !----------------------------------------------------------------------- ! local variables @@ -100,11 +101,13 @@ subroutine ecosys_tavg_init(marbl_instance) call ecosys_tavg_define_from_diag(marbl_diags=interior_tendency, & stream_cnt=marbl_diags_stream_cnt_interior, & - tavg_ids=tavg_ids_interior_tendency) + tavg_ids=tavg_ids_interior_tendency, & + status_log=status_log) call ecosys_tavg_define_from_diag(marbl_diags=surface_flux, & stream_cnt=marbl_diags_stream_cnt_surface, & - tavg_ids=tavg_ids_surface_flux) + tavg_ids=tavg_ids_surface_flux, & + status_log=status_log) end associate @@ -137,8 +140,6 @@ subroutine ecosys_tavg_accumulate_surface(marbl_col_to_pop_i, marbl_col_to_pop_j use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_surface use ecosys_tracers_and_saved_state_mod, only : o2_ind - implicit none - integer, intent(in) :: marbl_col_to_pop_i(:) integer, intent(in) :: marbl_col_to_pop_j(:) real (r8) , intent(in) :: STF(:,:,:) @@ -165,8 +166,6 @@ subroutine ecosys_tavg_accumulate_interior(i, c, marbl_instance, bid) use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_interior - implicit none - integer, intent(in) :: i, c ! column indices type(marbl_interface_class), intent(in) :: marbl_instance integer, intent(in) :: bid ! block index @@ -188,8 +187,6 @@ subroutine ecosys_tavg_accumulate_from_diag(i, c, bid, marbl_diags, marbl_diags_ ! Accumulate diagnostics - implicit none - integer, dimension(:) , intent(in) :: i, c ! column indices integer , intent(in) :: bid ! block index type(marbl_diagnostics_type) , intent(in) :: marbl_diags @@ -227,8 +224,6 @@ subroutine ecosys_tavg_accumulate_scalar_rmeans(marbl_instance, field_source) ! Accumulate diagnostics for scalar running means - implicit none - type(marbl_interface_class), intent(in) :: marbl_instance character (*), intent(in) :: field_source ! 'interior_tendency' or 'surface_flux' @@ -254,23 +249,22 @@ end subroutine ecosys_tavg_accumulate_scalar_rmeans !*********************************************************************** - subroutine ecosys_tavg_define_from_diag(marbl_diags, stream_cnt, tavg_ids) + subroutine ecosys_tavg_define_from_diag(marbl_diags, stream_cnt, tavg_ids, status_log) use tavg, only : tavg_method_avg use pop_constants, only : cmperm use domain_size, only : km use grid, only : zw - implicit none - type(marbl_diagnostics_type), intent(in) :: marbl_diags integer(int_kind), dimension(:), intent(in) :: stream_cnt integer(int_kind), dimension(:,:), intent(inout) :: tavg_ids + type(marbl_log_type), intent(inout) :: status_log !----------------------------------------------------------------------- ! local variables !----------------------------------------------------------------------- - character(char_len) :: err_msg, gloc, coords, short_name + character(char_len) :: err_msg, gloc, coords, short_name, vert_grid integer :: m, n, ndims real (r8) :: ref_depth_cm @@ -278,76 +272,119 @@ subroutine ecosys_tavg_define_from_diag(marbl_diags, stream_cnt, tavg_ids) !----------------------------------------------------------------------- - associate(diags => marbl_diags%diags(:)) - - do n=1,size(diags) - if (trim(diags(n)%vertical_grid).eq.'none') then - ndims = 2 - gloc = '2110' - coords = 'TLONG TLAT time' - ! find layer containing ref_depth, i.e., zw(k-1) .le. ref_depth .lt. zw(k) - ref_depth_cm = cmperm * diags(n)%ref_depth - if (ref_depth_cm .lt. zw(km)) then - do ref_k = 1, km - if (ref_depth_cm .lt. zw(ref_k)) exit - end do + do n=1,size(marbl_diags%diags) + vert_grid = marbl_diags%get_str(n, 'vertical_grid', status_log) + if (trim(vert_grid).eq.'none') then + ndims = 2 + gloc = '2110' + coords = 'TLONG TLAT time' + ! find layer containing ref_depth, i.e., zw(k-1) .le. ref_depth .lt. zw(k) + ref_depth_cm = cmperm * marbl_diags%diags(n)%ref_depth + if (ref_depth_cm .lt. zw(km)) then + do ref_k = 1, km + if (ref_depth_cm .lt. zw(ref_k)) exit + end do + else + ref_k = km + end if + else + ndims = 3 + if (trim(vert_grid) .eq. 'layer_avg') then + if (marbl_diags%diags(n)%ltruncated_vertical_extent) then + gloc = '3114' + coords = 'TLONG TLAT z_t_150m time' else - ref_k = km + gloc = '3111' + coords = 'TLONG TLAT z_t time' end if - else - ndims = 3 - if (trim(diags(n)%vertical_grid).eq.'layer_avg') then - if (diags(n)%ltruncated_vertical_extent) then - gloc = '3114' - coords = 'TLONG TLAT z_t_150m time' - else - gloc = '3111' - coords = 'TLONG TLAT z_t time' - end if - elseif (trim(diags(n)%vertical_grid).eq.'layer_iface') then - gloc = '3112' - coords = 'TLONG TLAT z_w_top time' - else - write(err_msg,*) "'", trim(diags(n)%vertical_grid), & - "' is not a valid vertical grid" - call shr_sys_abort(err_msg) - end if - end if - - do m=1,stream_cnt(n) - if (m .eq. 1) then - write(short_name, "(A)") trim(diags(n)%short_name) - else - write(short_name, "(A,'_',I0)") trim(diags(n)%short_name), m - end if - if (ndims .eq. 2) then - call define_tavg_field(tavg_ids(n,m), & - short_name, & - ndims, & - tavg_method = tavg_method_avg, & - long_name=trim(diags(n)%long_name), & - units=trim(diags(n)%units), & - grid_loc=gloc, & - mask_k=ref_k, & - coordinates=coords, & - transpose_field=(ndims .eq. 3)) - else - call define_tavg_field(tavg_ids(n,m), & - short_name, & - ndims, & - tavg_method = tavg_method_avg, & - long_name=trim(diags(n)%long_name), & - units=trim(diags(n)%units), & - grid_loc=gloc, & - coordinates=coords, & - transpose_field=(ndims .eq. 3)) - end if - end do + elseif (trim(vert_grid).eq.'layer_iface') then + gloc = '3112' + coords = 'TLONG TLAT z_w_top time' + else + write(err_msg,*) "'", trim(vert_grid), & + "' is not a valid vertical grid" + call shr_sys_abort(err_msg) + end if + end if + + do m=1,stream_cnt(n) + if (m .eq. 1) then + write(short_name, "(A)") trim(marbl_diags%get_str(n, 'short_name', status_log)) + else + write(short_name, "(A,'_',I0)") trim(marbl_diags%get_str(n, 'short_name', status_log)), m + end if + if (ndims .eq. 2) then + call define_tavg_field(tavg_ids(n,m), & + short_name, & + ndims, & + tavg_method = tavg_method_avg, & + long_name=marbl_diags%get_str(n, 'long_name', status_log), & + units=marbl_diags%get_str(n, 'units', status_log), & + grid_loc=gloc, & + mask_k=ref_k, & + coordinates=coords, & + transpose_field=(ndims .eq. 3)) + else + call define_tavg_field(tavg_ids(n,m), & + short_name, & + ndims, & + tavg_method = tavg_method_avg, & + long_name=marbl_diags%get_str(n, 'long_name', status_log), & + units=marbl_diags%get_str(n, 'units', status_log), & + grid_loc=gloc, & + coordinates=coords, & + transpose_field=(ndims .eq. 3)) + end if end do - end associate + end do end subroutine ecosys_tavg_define_from_diag + !*********************************************************************** + + subroutine ecosys_tavg_set_compute_now(marbl_diags, field_source, status_log) + + use tavg, only : set_in_tavg_contents + use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_surface + use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_interior + + type(marbl_diagnostics_type), intent(inout) :: marbl_diags + character(len=*), intent(in) :: field_source + type(marbl_log_type), intent(inout) :: status_log + + character(len=char_len) :: err_msg + logical :: in_tavg_contents + integer :: n, m + + select case (trim(field_source)) + case ('surface_flux') + do n=1,size(marbl_diags%diags) + in_tavg_contents = .false. + do m=1,marbl_diags_stream_cnt_surface(n) + in_tavg_contents = in_tavg_contents .or. set_in_tavg_contents(tavg_ids_surface_flux(n,m)) + end do + call marbl_diags%set(n, 'compute_now', in_tavg_contents, status_log) + end do + case ('interior_tendency') + do n=1,size(marbl_diags%diags) + in_tavg_contents = .false. + do m=1,marbl_diags_stream_cnt_interior(n) + in_tavg_contents = in_tavg_contents .or. set_in_tavg_contents(tavg_ids_interior_tendency(n,m)) + end do + call marbl_diags%set(n, 'compute_now', in_tavg_contents, status_log) + end do + case DEFAULT + write(err_msg, "(3A)") "'", trim(field_source), "' is not a valid field source" + call shr_sys_abort(err_msg) + end select + + do n=1,size(marbl_diags%diags) + write(err_msg, *) "compute_now for '", trim(marbl_diags%get_str(n, 'short_name', status_log)), "': ", marbl_diags%diags(n)%compute_now + call status_log%log_noerror(err_msg, 'tmp_subname') + end do + + end subroutine ecosys_tavg_set_compute_now + end module ecosys_tavg !||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| diff --git a/source/passive_tracers.F90 b/source/passive_tracers.F90 index e78b3807..587bab03 100644 --- a/source/passive_tracers.F90 +++ b/source/passive_tracers.F90 @@ -47,6 +47,7 @@ module passive_tracers use ecosys_driver, only: & ecosys_tracer_cnt, & ecosys_driver_init, & + ecosys_driver_set_compute_now, & ecosys_driver_set_sflux_forcing, & ecosys_driver_set_sflux, & ecosys_driver_post_set_sflux, & @@ -1057,6 +1058,9 @@ subroutine set_sflux_passive_tracers(U10_SQR,ICE_FRAC,PRESS,ATM_FINE_DUST_FLUX,A !----------------------------------------------------------------------- if (ecosys_on) then + ! Make sure MARBL is only computed selected diagnostics + call ecosys_driver_set_compute_now() + call ecosys_driver_set_sflux_forcing( & U10_SQR, ICE_FRAC, PRESS, ATM_FINE_DUST_FLUX, ATM_COARSE_DUST_FLUX, SEAICE_DUST_FLUX, & ATM_BLACK_CARBON_FLUX, SEAICE_BLACK_CARBON_FLUX, &