Skip to content

Instantly share code, notes, and snippets.

@nbren12
Created January 9, 2021 00:31
Show Gist options
  • Save nbren12/d8617ff52d69792b624310167a972104 to your computer and use it in GitHub Desktop.
Save nbren12/d8617ff52d69792b624310167a972104 to your computer and use it in GitHub Desktop.
module python
use machine , only : kind_phys
use callpy_mod
implicit none
character(len=*), parameter :: python_module = "plugin"
contains
subroutine python_init ()
call call_function(python_module, "init")
end subroutine python_init
subroutine python_finalize()
call call_function(python_module, "finalize")
end subroutine python_finalize
!> \section arg_table_python_run Argument Table
!! \htmlinclude python_run.html
!!
subroutine python_run (errmsg, errflg&
,specific_humidity&
,air_temperature&
,cosine_zenith_angle&
,land_sea_mask&
,geopotential&
,air_pressure_at_interface&
,rain &
,time_step&
)
implicit none
!--- arguments
! add your arguments here
character(len=*), intent(out) :: errmsg
integer, intent(out) :: errflg
real(kind=kind_phys), intent(inout) :: specific_humidity(:, :)
real(kind=kind_phys), intent(inout) :: air_temperature(:, :)
real(kind=kind_phys), intent(in) :: cosine_zenith_angle(:)
integer, intent(in) :: land_sea_mask(:)
real(kind=kind_phys), intent(in) :: geopotential(:, :)
real(kind=kind_phys), intent(in) :: air_pressure_at_interface(:, :)
real(kind=kind_phys), intent(out) :: rain(:)
real(kind=kind_phys), intent(in) :: time_step
!--- local variables
! add your local variables here
! # TODO call_python needs methods for scalars
real(kind=kind_phys) time_step_tmp(1)
time_step_tmp(1) = time_step
!--- initialize CCPP error handling variables
errmsg = ''
errflg = 0
!--- initialize intent(out) variables
! initialize all intent(out) variables here
!--- actual code
! add your code here
call set_state("specific_humidity", specific_humidity)
call set_state("air_temperature", air_temperature)
call set_state("cos_zenith_angle", cosine_zenith_angle)
call set_state("land_sea_mask", land_sea_mask)
call set_state("geopotential", geopotential)
call set_state("air_pressure_at_interface", air_pressure_at_interface)
call set_state("time_step", time_step_tmp)
call call_function(python_module, "run")
call get_state("specific_humidity", specific_humidity)
call get_state("air_temperature", air_temperature)
call get_state("rain", rain)
! in case of errors, set errflg to a value != 0,
! assign a meaningful message to errmsg and return
return
end subroutine python_run
end module python
[ccpp-table-properties]
name = python
type = scheme
dependencies = machine.F
[ccpp-arg-table]
name = python_run
type = scheme
[errmsg]
standard_name = ccpp_error_message
long_name = error message for error handling in CCPP
units = none
dimensions = ()
type = character
kind = len=*
intent = out
optional = F
[errflg]
standard_name = ccpp_error_flag
long_name = error flag for error handling in CCPP
units = flag
dimensions = ()
type = integer
intent = out
optional = F
[specific_humidity]
standard_name = water_vapor_specific_humidity_updated_by_physics
long_name = water vapor
units = kg kg-1
dimensions=(horizontal_loop_extent,vertical_dimension)
type = real
kind = kind_phys
intent = in
optional = F
[air_temperature]
standard_name = air_temperature_updated_by_physics
long_name = updated temperature
units = K
dimensions = (horizontal_loop_extent,vertical_dimension)
type = real
kind = kind_phys
intent = inout
optional = F
[cosine_zenith_angle]
standard_name = instantaneous_cosine_of_zenith_angle
long_name = instant cos of zenith angle over rad call period
units = none
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
intent = inout
optional = F
[land_sea_mask]
standard_name = sea_land_ice_mask
long_name = landmask: sea/land/ice=0/1/2
units = flag
dimensions = (horizontal_loop_extent)
type = integer
intent = in
optional = F
[geopotential]
standard_name = geopotential_at_interface
long_name = geopotential at model layer interfaces
units = m2 s-2
dimensions = (horizontal_loop_extent,vertical_dimension_plus_one)
type = real
kind = kind_phys
[air_pressure_at_interface]
standard_name = air_pressure_at_interface
long_name = air pressure at model layer interfaces
units = Pa
dimensions = (horizontal_loop_extent,vertical_dimension_plus_one)
type = real
kind = kind_phys
[rain]
standard_name = lwe_thickness_of_deep_convective_precipitation_amount
long_name = deep convective rainfall amount on physics timestep
units = m
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
intent = out
optional = F
[time_step]
standard_name = time_step_for_physics
long_name = physics time step
units = s
dimensions = ()
type = real
kind = kind_phys
intent = in
optional = F
[ccpp-arg-table]
name = python_init
type = scheme
[ccpp-arg-table]
name = python_finalize
type = scheme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment