|
| 1 | +!----------------------------------------------------------------------------- |
| 2 | +! (C) Crown copyright 2025 Met Office. All rights reserved. |
| 3 | +! The file LICENCE, distributed with this code, contains details of the terms |
| 4 | +! under which the code may be used. |
| 5 | +!----------------------------------------------------------------------------- |
| 6 | +! |
| 7 | +! The main entry point for calculating section 20 aviation diagnostics. |
| 8 | +! |
| 9 | +! Code Owner: Please refer to the UM file CodeOwners.txt |
| 10 | +! This file currently belongs in section: physics_schemes_interface |
| 11 | +! whilst discussions are ongoing about its final location. |
| 12 | +! |
| 13 | +MODULE aviation_diags_alg_mod |
| 14 | + |
| 15 | + USE constants_mod, ONLY: r_def, i_def, l_def, str_long |
| 16 | + USE field_mod, ONLY: field_type |
| 17 | + USE io_config_mod, ONLY: USE_xios_io |
| 18 | + USE initialise_diagnostics_mod, ONLY: init_diag => init_diagnostic_field |
| 19 | + |
| 20 | + USE lfric_xios_diag_mod, ONLY: get_axis_dimension, get_axis_values |
| 21 | + USE log_mod, ONLY: log_event, log_scratch_space, & |
| 22 | + LOG_LEVEL_ALWAYS, LOG_LEVEL_ERROR, & |
| 23 | + LOG_LEVEL_INFO, LOG_LEVEL_DEBUG |
| 24 | + |
| 25 | + USE aviation_diags_kernel_mod, ONLY: aviation_diags_kernel_type |
| 26 | + |
| 27 | + IMPLICIT NONE |
| 28 | + |
| 29 | +PRIVATE |
| 30 | +PUBLIC :: aviation_diags_alg |
| 31 | + |
| 32 | +CONTAINS |
| 33 | + |
| 34 | + ! Algorithm to calculate the section 20 aviation diagnostics. |
| 35 | + SUBROUTINE aviation_diags_alg(plev_geopot) |
| 36 | + |
| 37 | + IMPLICIT NONE |
| 38 | + |
| 39 | + ! Arguments |
| 40 | + |
| 41 | + ! We calculate the result from this input field. |
| 42 | + TYPE(field_type), INTENT(IN) :: plev_geopot |
| 43 | + |
| 44 | + |
| 45 | + ! Local variables |
| 46 | + |
| 47 | + ! These flags tell us which results are requested at this time step. |
| 48 | + LOGICAL(l_def) :: aviation_thick_850_flag, aviation_thick_500_flag |
| 49 | + |
| 50 | + ! The array of pressure levels. |
| 51 | + INTEGER(I_DEF) :: nplev |
| 52 | + REAL(R_DEF), ALLOCATABLE :: plevs(:) |
| 53 | + INTEGER(I_DEF) :: plevs_alloc_stat |
| 54 | + |
| 55 | + ! Level indices for the three pressure levels we want to read. |
| 56 | + INTEGER(I_DEF) :: i1000, i850, i500 |
| 57 | + |
| 58 | + ! Approximate equality tolerance - is there a common variable somewhere? |
| 59 | + REAL(R_DEF), PARAMETER :: plev_tol = 0.1_r_def |
| 60 | + |
| 61 | + ! The two output fields we produce. |
| 62 | + TYPE( field_type ) :: aviation_thick_850, aviation_thick_500 |
| 63 | + |
| 64 | + INTEGER(I_DEF) :: i |
| 65 | + |
| 66 | + character(len=str_long) :: message |
| 67 | + |
| 68 | + |
| 69 | + ! Check the request flags. |
| 70 | + aviation_thick_850_flag = & |
| 71 | + init_diag(aviation_thick_850, 'aviation__geopot_thickness_850') |
| 72 | + aviation_thick_500_flag = & |
| 73 | + init_diag(aviation_thick_500, 'aviation__geopot_thickness_500') |
| 74 | + |
| 75 | + ! Anything to do? |
| 76 | + IF ( .NOT. (aviation_thick_850_flag .OR. aviation_thick_500_flag) ) THEN |
| 77 | + ! Nothing requested at this time step. |
| 78 | + RETURN |
| 79 | + END IF |
| 80 | + |
| 81 | + IF ( .NOT. use_xios_io ) THEN |
| 82 | + RETURN |
| 83 | + ENDIF |
| 84 | + |
| 85 | + ! Initialise required fields to 1. Todo: Why 1 and not 0? |
| 86 | + IF ( aviation_thick_850_flag ) THEN |
| 87 | + message = 'Section 20: geopot thick 850 requested' |
| 88 | + CALL log_event( message, LOG_LEVEL_DEBUG ) |
| 89 | + CALL invoke( setval_c(aviation_thick_850, 1.0_r_def)) |
| 90 | + END IF |
| 91 | + |
| 92 | + IF ( aviation_thick_500_flag ) THEN |
| 93 | + message = 'Section 20: geopot thick 500 requested' |
| 94 | + CALL log_event( message, LOG_LEVEL_DEBUG ) |
| 95 | + CALL invoke( setval_c(aviation_thick_500, 1.0_r_def)) |
| 96 | + END IF |
| 97 | + |
| 98 | + |
| 99 | + ! Get the array of pressure levels. |
| 100 | + nplev = get_axis_dimension('pressure_levels') |
| 101 | + IF (nplev <= 0) THEN |
| 102 | + message = 'Section 20: No pressure levels' |
| 103 | + CALL log_event( message, LOG_LEVEL_DEBUG ) |
| 104 | + RETURN |
| 105 | + END IF |
| 106 | + |
| 107 | + ALLOCATE(plevs(nplev), stat=plevs_alloc_stat) |
| 108 | + IF (plevs_alloc_stat /= 0) THEN |
| 109 | + message = 'Section 20: allocate(plevs) failed' |
| 110 | + CALL log_event( message, LOG_LEVEL_DEBUG ) |
| 111 | + |
| 112 | + RETURN |
| 113 | + END IF |
| 114 | + plevs = get_axis_values('pressure_levels',nplev) |
| 115 | + |
| 116 | + ! Find the level indices for our three pressures of interest. |
| 117 | + ! Assumes hPa. |
| 118 | + i1000 = -1 |
| 119 | + i850 = -1 |
| 120 | + i500 = -1 |
| 121 | + DO i = 1, nplev |
| 122 | + |
| 123 | + ! 1000? |
| 124 | + IF ( abs(plevs(i) - 100000.0_r_def) < plev_tol ) THEN |
| 125 | + i1000 = i |
| 126 | + |
| 127 | + ! 850? |
| 128 | + ELSE IF ( abs(plevs(i) - 85000.0_r_def) < plev_tol ) THEN |
| 129 | + i850 = i |
| 130 | + |
| 131 | + ! 500? |
| 132 | + ELSE IF ( abs(plevs(i) - 50000.0_r_def) < plev_tol ) THEN |
| 133 | + i500 = i |
| 134 | + |
| 135 | + END IF |
| 136 | + END DO |
| 137 | + |
| 138 | + ! Check we found the required levels. |
| 139 | + IF (i1000 == -1) THEN |
| 140 | + message = 'Section 20: could not find 1000hPa' |
| 141 | + CALL log_event( message, LOG_LEVEL_INFO ) |
| 142 | + RETURN |
| 143 | + END IF |
| 144 | + |
| 145 | + IF (aviation_thick_850_flag .AND. i850 == -1) THEN |
| 146 | + message = 'Section 20: could not find 850hPa' |
| 147 | + CALL log_event( message, LOG_LEVEL_INFO ) |
| 148 | + RETURN |
| 149 | + END IF |
| 150 | + |
| 151 | + IF (aviation_thick_500_flag .AND. i500 == -1) THEN |
| 152 | + message = 'Section 20: could not find 500hPa' |
| 153 | + CALL log_event( message, LOG_LEVEL_INFO ) |
| 154 | + RETURN |
| 155 | + END IF |
| 156 | + |
| 157 | + ! Call the kernel to subtract the levels. |
| 158 | + ! Todo: Comment why we initialise to 1.0 and not 0.0. I can't remember. |
| 159 | + CALL invoke( aviation_diags_kernel_type( & |
| 160 | + aviation_thick_850, aviation_thick_500, & |
| 161 | + plev_geopot, & |
| 162 | + aviation_thick_850_flag, aviation_thick_500_flag, & |
| 163 | + i1000, i850, i500)) |
| 164 | + |
| 165 | + ! Write the fields |
| 166 | + IF (aviation_thick_850_flag) CALL aviation_thick_850%write_field() |
| 167 | + IF (aviation_thick_500_flag) CALL aviation_thick_500%write_field() |
| 168 | + |
| 169 | + ! Clean up. |
| 170 | + IF (allocated(plevs)) THEN |
| 171 | + DEALLOCATE(plevs) |
| 172 | + END IF |
| 173 | + |
| 174 | + END SUBROUTINE aviation_diags_alg |
| 175 | + |
| 176 | +END MODULE aviation_diags_alg_mod |
0 commit comments