EMC Training | Day 2 Adding a New Scheme to the CCPP > Calculate the Index and Add it to the Output

Add diagnostic variables for output

In order to add RFTIM to the output files, we need to add a new diagnostic variable to NEMSfv3gfs that stores the RFTIM. Because the NEMSfv3gfs diagnostic output doesn't work with integers, we need to declare rftim as a real array constituent of GFS_diag_type:

Variable rftim:
   standard_name : modified_red_flag_threat_index
   units         : index
   rank          : 1
   type          : real
   kind          : kind_phys

Let's register this variable in the GFS diagnostics module. Open FV3/gfsphysics/GFS_layer/GFS_diagnostics.F90 and add the following blob to the end of routine GFS_externaldiag_populate (be sure to enter this after the last #endif preprocessor directive):

   idx = idx + 1
   ExtDiag(idx)%axes = 2
   ExtDiag(idx)%name = 'rftim'
   ExtDiag(idx)%desc = 'modified red flag threat index'
   ExtDiag(idx)%unit = 'n/a'
   ExtDiag(idx)%mod_name = 'gfs_sfc'
   ExtDiag(idx)%intpl_method = 'bilinear'
   allocate (ExtDiag(idx)%data(nblks))
   do nb = 1,nblks
     ExtDiag(idx)%data(nb)%var2 => IntDiag(nb)%rftim(:)
   enddo

Calculate the index

Now we can begin the task of calculating the RFTIM (variable name rftim in the following). A skeleton CCPP scheme called rtfim, as well as a module containing the simplified climatology to map rh2m and ws6m to red flag threat indices, are provided for you to copy into your development codebase.  Both files need to be copied into ccpp/physics/physics:

      /scratch4/BMC/gmtb/emc_training_march_2019/handson_day2/templates/module_rftim_clima.F90
      /scratch4/BMC/gmtb/emc_training_march_2019/handson_day2/templates/rftim.F90

Please take a look at module_rftim_clima.F90, but note that you do not need to make any modification in this file. You will see two functions in this file. The functions rfti_rh_clima and rfti_ws_clima can be called for arrays or scalars, and return integers. The interfaces are for relative humidity and wind speed are:

   elemental function rfti_rh_clima(lat, lon, rh)  result(rfti_rh)
      real(kind_phys), intent(in) :: lat
      real(kind_phys), intent(in) :: lon
      real(kind_phys), intent(in) :: rh      
      integer :: rfti_rh
   end function rfti_rh_clima

   elemental function rfti_ws_clima(lat, lon, ws) result(rfti_ws)
      real(kind_phys), intent(in) :: lat
      real(kind_phys), intent(in) :: lon
      real(kind_phys), intent(in) :: ws
      integer :: rfti_ws
   end function rfti_ws_clima

Next you need to edit rftim.F90 to compute RFTIM.

Note that in file rftim.F90 there are 3 subroutines wrapped in a module: rftim_init, rftim_finalize, and rftim_run. This is typical of CCPP schemes.  No changes are needed in rftim_init and rftim_finalize, but you need to edit rftim_run and do the following:

  • Update the metadata table in the module

  • Declare local variable i

  • Calculate RFTIM

The argument list for subroutine rftim_run is:

  subroutine rftim_run(im, lat, lon, islmsk, rh2, ws6, rftim, errmsg, errflg)

The metadata table needs to be populated with the same variables and in the same order as the subroutine call. The local variable names, standard names, intent, and optional columns are already pre-populated. Your job is to add the remaining metadata. Note that units are critical because they are used during the build system to compare the variables requested by the physics against those supplied by the host model. Therefore, the units needs to be exactly what the host model provides.

Variable im:
   standard_name : horizontal_loop_extent
   units         : count
   rank          : 0
   type          : integer
   kind          : 

Variable lat:
   standard_name : latitude
   units         : radians
   rank          : 1
   type          : real
   kind          : kind_phys

Variable lon:
   standard_name : longitude
   units         : radians
   rank          : 1
   type          : real
   kind          : kind_phys

Variable islmsk:
   standard_name : sea_land_ice_mask
   units         : flag
   rank          : 1
   type          : integer
   kind          : 

Variable rh2m:
   standard_name : relative_humidity_at_2m
   units         : percent
   rank          : 1
   type          : real
   kind          : kind_phys

Variable ws6m:
   standard_name : wind_speed_at_6m_in_miles_per_hour
   units         : mi h-1
   rank          : 1
   type          : real
   kind          : kind_phys

Variable rftim:
   standard_name : modified_red_flag_threat_index
   units         : index
   rank          : 1
   type          : real
   kind          : kind_phys

Variable errmsg:
   standard_name : ccpp_error_message
   units         : none
   rank          : 0
   type          : character
   kind          : len=*

Variable errflg:
   standard_name : ccpp_error_flag
   units         : flag
   rank          : 0
   type          : integer
   kind          : 

Hint: For unit “mi h-1” make sure you have the white space in the middle. If not, there will be a mismatch between the variable provided by the host model and what scheme rtfim requests.

Now that you are done with the metadata table, add to the subroutine

integer :: i

do i=1,im

        rftim(i) = real(rfti_rh_clima(lat(i), lon(i), rh2(i)) + rfti_ws_clima(lat(i), lon(i), ws6(i)), kind_phys)

enddo