Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ run_util = \
runInfoType.f90 \
modelVarType.f90 \
ioModule.f90 \
byte_utilities.f90 \
messagepack_value.f90 \
messagepack_user.f90 \
messagepack.f90 \
runSnow17.f90

model_run = $(patsubst %, $(share_dir)/%, $(run_util))
Expand Down
85 changes: 74 additions & 11 deletions src/bmi/bmi_snow17.f90
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ function snow17_var_type(this, name, type) result (bmi_status)
character (len=*), intent(in) :: name
character (len=*), intent(out) :: type
integer :: bmi_status
character(len=BMI_MAX_TYPE_NAME) :: ser_create = "uint64" !pads spaces upto 2048.
character(len=BMI_MAX_TYPE_NAME) :: ser_size = "uint64" !pads spaces upto 2048
character(len=BMI_MAX_TYPE_NAME) :: ser_state = "character" !pads spaces upto 2048
character(len=BMI_MAX_TYPE_NAME) :: ser_free = "int" !pads spaces upto 2048

select case(name)
case('tair', 'precip', & ! input/output vars
Expand All @@ -600,6 +604,18 @@ function snow17_var_type(this, name, type) result (bmi_status)
case('hru_id')
type = "character"
bmi_status = BMI_SUCCESS
case ('serialization_create')
type = ser_create
bmi_status = BMI_SUCCESS
case ('serialization_size')
type = ser_size
bmi_status = BMI_SUCCESS
case ('serialization_state')
type = ser_state
bmi_status = BMI_SUCCESS
case ('serialization_free')
type = ser_free
bmi_status = BMI_SUCCESS
case default
type = "-"
bmi_status = BMI_FAILURE
Expand Down Expand Up @@ -778,17 +794,35 @@ function snow17_var_nbytes(this, name, nbytes) result (bmi_status)
integer, intent(out) :: nbytes
integer :: bmi_status
integer :: s1, s2, s3, grid, grid_size, item_size
s1 = this%get_var_grid(name, grid)
s2 = this%get_grid_size(grid, grid_size)
s3 = this%get_var_itemsize(name, item_size)

if ((s1 == BMI_SUCCESS).and.(s2 == BMI_SUCCESS).and.(s3 == BMI_SUCCESS)) then
nbytes = item_size * grid_size
bmi_status = BMI_SUCCESS

if (name == "serialization_create" .or. name == "serialization_size") then
nbytes = storage_size(0_int64)/8 !returns size in bits. So, divide by 8 for bytes.
bmi_status = BMI_SUCCESS
else if (name == "serialization_state") then
if(.not.allocated(this%model%serialization_buffer) .or. size(this%model%serialization_buffer) == 0) then
nbytes = -1
call write_log("Serialization not set yet!", LOG_LEVEL_WARNING)
bmi_status = BMI_FAILURE
else
nbytes = size(this%model%serialization_buffer,KIND=int64)
bmi_status = BMI_SUCCESS
end if
else if (name == "serialization_free") then
nbytes = storage_size(0_int32)/8 !returns size in bits. So, divide by 8 for bytes.
bmi_status = BMI_SUCCESS
else
nbytes = -1
bmi_status = BMI_FAILURE
call write_log("snow17_var_nbytes - " // name // " not found.", LOG_LEVEL_SEVERE)
s1 = this%get_var_grid(name, grid)
s2 = this%get_grid_size(grid, grid_size)
s3 = this%get_var_itemsize(name, item_size)

if ((s1 == BMI_SUCCESS).and.(s2 == BMI_SUCCESS).and.(s3 == BMI_SUCCESS)) then
nbytes = item_size * grid_size
bmi_status = BMI_SUCCESS
else
nbytes = -1
bmi_status = BMI_FAILURE
call write_log("snow17_var_nbytes - " // name // " not found.", LOG_LEVEL_SEVERE)
end if
end if
end function snow17_var_nbytes

Expand Down Expand Up @@ -818,6 +852,14 @@ function snow17_get_int(this, name, dest) result (bmi_status)
! case("model__identification_number")
! dest = [this%model%id]
! bmi_status = BMI_SUCCESS
case("serialization_size")
if(.not.allocated(this%model%serialization_buffer) .or. size(this%model%serialization_buffer) == 0) then
call write_log("Serialization not set yet!", LOG_LEVEL_WARNING)
bmi_status = BMI_FAILURE
else
dest = size(this%model%serialization_buffer,KIND=int64)
bmi_status = BMI_SUCCESS
end if
case default
dest(:) = -1
bmi_status = BMI_FAILURE
Expand Down Expand Up @@ -991,6 +1033,9 @@ function snow17_get_ptr_int(this, name, dest_ptr) result (bmi_status)
!==================== UPDATE IMPLEMENTATION IF NECESSARY FOR INTEGER VARS =================

select case(name)
case("serialization_state")
dest_ptr = this%model%serialization_buffer
bmi_status = BMI_SUCCESS
case default
bmi_status = BMI_FAILURE
call write_log("snow17_get_ptr_int - " // name // " not found.", LOG_LEVEL_SEVERE)
Expand Down Expand Up @@ -1094,14 +1139,32 @@ function snow17_set_int(this, name, src) result (bmi_status)
character (len=*), intent(in) :: name
integer, intent(in) :: src(:)
integer :: bmi_status
integer(kind=int64) :: exec_status

!==================== UPDATE IMPLEMENTATION IF NECESSARY FOR INTEGER VARS =================

select case(name)
! case("model__identification_number")
! this%model%id = src(1)
! bmi_status = BMI_SUCCESS
case default
case("serialization_create")
call new_serialization_request(this%model, exec_status)
if (exec_status == 0) then
bmi_status = BMI_SUCCESS
call write_log("Serialization for state saving complete", LOG_LEVEL_INFO)
else
bmi_status = BMI_FAILURE
call write_log(" Failed to create serialized data for state saving", LOG_LEVEL_FATAL)
end if
case("serialization_state")
call deserialize_mp_buffer(this%model,src)
bmi_status = BMI_SUCCESS
case("serialization_free")
if(allocated(this%model%serialization_buffer)) then
deallocate(this%model%serialization_buffer)
end if
bmi_status = BMI_SUCCESS
case default
bmi_status = BMI_FAILURE
call write_log("snow17_set_int - " // name // " not found.", LOG_LEVEL_SEVERE)
end select
Expand Down
Loading