forked from NOAA-OWP/noah-owp-modular
-
Notifications
You must be signed in to change notification settings - Fork 0
Serialization and get/set value functions for NOAH-OWP-MODULAR #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cc1579e
added implementation for get/set value in BMI for serialization
sivasankkar 03336ef
Added messagepack modules and a draft serialization module for this m…
sivasankkar c15aeb8
Serialization routine complete with all potential variables.
sivasankkar 211bbca
de-serialization first draft
sivasankkar 0801761
Serialization and Deserialization complete. Updated makefiles and bui…
sivasankkar 17b51ec
Updated serialization and deserialization protocols in BMI and also r…
sivasankkar 0a6e883
Updated log levels in a couple of functions and also tried TRANSFER.
sivasankkar 5001099
Changed log level in some functions in BMI
sivasankkar 8d89214
Reverse spurious whitespace change
PhilMiller 883615e
Added serialization_size in the BMI and also allocated space before a…
sivasankkar 20f7c91
Added the deallocate step for the TARGET serialized data conversion.
sivasankkar 6c6bc9b
Adopted the transfer_values_from_mp functions for deserialization pro…
sivasankkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| module StateSerialization | ||
|
|
||
| use LevelsType | ||
| use DomainType | ||
| use ParametersType | ||
| use WaterType | ||
| use EnergyType | ||
| use ForcingType | ||
| use SnowWaterRenew | ||
| use SnowLayerChange | ||
| use messagepack | ||
| use iso_fortran_env | ||
|
|
||
| implicit none | ||
| byte, dimension(:), allocatable :: serialization_buffer | ||
|
|
||
| contains | ||
|
|
||
| SUBROUTINE forcing_serialization (forcing) | ||
PhilMiller marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type(ForcingType), intent(in) :: forcing | ||
| class(mp_arr_type), allocatable, intent(out) :: mp_arr | ||
| mp_arr = mp_arr_type(22) | ||
| mp_arr%values(1)%obj = mp_float_type(forcing%UU) !UU | ||
| mp_arr%values(2)%obj = mp_float_type(forcing%VV) !VV | ||
| mp_arr%values(3)%obj = mp_float_type(forcing%SFCTMP) !SFCTMP | ||
| mp_arr%values(4)%obj = mp_float_type(forcing%Q2) !Q2 | ||
| mp_arr%values(5)%obj = mp_float_type(forcing%SFCPRS) !SFCPRS | ||
| mp_arr%values(6)%obj = mp_float_type(forcing%SOLDN) !SOLDN | ||
| mp_arr%values(7)%obj = mp_float_type(forcing%LWDN) !LWDN | ||
| mp_arr%values(8)%obj = mp_int_type(forcing%YEARLEN) !YEARLEN, out | ||
| mp_arr%values(9)%obj = mp_float_type(forcing%JULIAN) !JULIAN, out | ||
| mp_arr%values(10)%obj = mp_float_type(forcing%THAIR) !THAIR, out | ||
| mp_arr%values(11)%obj = mp_float_type(mforcing%QAIR) !QAIR, out | ||
| mp_arr%values(12)%obj = mp_float_type(forcing%EAIR) !EAIR, out | ||
| mp_arr%values(13)%obj = mp_float_type(forcing%RHOAIR) !RHOAIR, out | ||
| mp_arr%values(14)%obj = mp_float_type(forcing%O2PP) !O2PP | ||
| mp_arr%values(15)%obj = mp_float_type(forcing%CO2PP) !CO2PP | ||
| mp_arr%values(16)%obj = mp_float_type(forcing%SWDOWN) !SWDOWN, out | ||
| mp_arr%values(17)%obj = mp_float_type(forcing%SOLAD) !SOLAD | ||
| mp_arr%values(18)%obj = mp_float_type(forcing%SOLAI) !SOLAI | ||
| mp_arr%values(19)%obj = mp_float_type(forcing%PRCP) !PRCP | ||
| mp_arr%values(20)%obj = mp_float_type(forcing%PRCPNONC) !PRCPNONC | ||
| mp_arr%values(21)%obj = mp_float_type(mforcing%FPICE) !FPICE, out | ||
| mp_arr%values(22)%obj = mp_float_type(forcing%UR) !UR, out | ||
|
|
||
| END SUBROUTINE forcing_serialization | ||
|
|
||
| SUBROUTINE domain_serialization (domain) | ||
| type(ForcingType), intent(in) :: domain | ||
| class(mp_arr_type), allocatable, intent(out) :: mp_arr | ||
|
|
||
| mp_arr = mp_arr_type(6) | ||
| mp_arr%values(1)%obj = mp_float_type(domain%curr_datetime) !curr_datetime | ||
| mp_arr%values(2)%obj = mp_float_type(domain%ITIME) !ITIME | ||
| mp_arr%values(3)%obj = mp_float_type(domain%time_dbl) !time_dbl | ||
| mp_arr%values(4)%obj = mp_float_type(domain%nowdate) !nowdate | ||
|
|
||
| mp_arr%values(5)%obj = mp_arr_type(domain%DZSNSO) !DZSNSO have to fix indices using levels%soil | ||
| mp_arr%values(6)%obj = mp_arr_type(domain%ZSNSO) !ZSNSO have to fix indices using levels%soil | ||
|
|
||
| END SUBROUTINE domain_serialization (domain) | ||
|
|
||
| SUBROUTINE domain_serialization (domain) | ||
| type(ForcingType), intent(in) :: domain | ||
| class(mp_arr_type), allocatable, intent(out) :: mp_arr | ||
|
|
||
| mp_arr = mp_arr_type(6) | ||
| mp_arr%values(1)%obj = mp_float_type(domain%curr_datetime) !curr_datetime | ||
| mp_arr%values(2)%obj = mp_float_type(domain%ITIME) !ITIME | ||
| mp_arr%values(3)%obj = mp_float_type(domain%time_dbl) !time_dbl | ||
| mp_arr%values(4)%obj = mp_float_type(domain%nowdate) !nowdate | ||
|
|
||
| mp_arr%values(5)%obj = mp_arr_type(domain%DZSNSO) !DZSNSO have to fix indices using levels%soil | ||
| mp_arr%values(6)%obj = mp_arr_type(domain%ZSNSO) !ZSNSO have to fix indices using levels%soil | ||
|
|
||
| END SUBROUTINE domain_serialization (domain) | ||
PhilMiller marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| END Module | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| module messagepack | ||
|
|
||
| ! implement buffer or c++ vector | ||
| ! implement static buffer? | ||
| ! implement packing | ||
| ! implement unpacking | ||
| ! implement file io | ||
| use iso_fortran_env | ||
| use messagepack_value | ||
| use messagepack_user | ||
| use byte_utilities | ||
|
|
||
| implicit none | ||
| contains | ||
|
|
||
| subroutine print_bytes_as_hex(bytes, addhexmark) | ||
| ! prints a buffer of bytes as the unsigned hex version | ||
| ! @param[in] bytes - byte buffer to print | ||
| ! @param[in] addhexmark - If true, print with 0x prepended | ||
| ! @returns none | ||
| byte, dimension(:), allocatable, intent(in) :: bytes | ||
| logical, intent(in) :: addhexmark | ||
|
|
||
| integer :: i | ||
| integer :: val | ||
| write(*, "(A2)", advance="no") "[ " | ||
| if (addhexmark) then | ||
| do i = 1,size(bytes) | ||
| val = int8_as_unsigned(bytes(i)) | ||
| write(*, '("0x", Z2.2, " ")', advance="no") val | ||
| end do | ||
| else | ||
| do i = 1,size(bytes) | ||
| val = int8_as_unsigned(bytes(i)) | ||
| write(*, '(Z2.2, " ")', advance="no") val | ||
| end do | ||
| end if | ||
| write(*,*) "]" | ||
| end subroutine | ||
|
|
||
| subroutine unpack_array_int_1d(obj, om, errored) | ||
| ! Attempts to unpack a 1d messagepack array of integers | ||
| ! Note: does not check `is_unsigned`. | ||
| ! @param[in] obj - messagepack object | ||
| ! @param[out] om - dynamically allocated matrix | ||
| ! @param[out] errored - .true. if an error occurred | ||
| class(mp_value_type), allocatable, intent(in) :: obj | ||
| integer(kind=int64), dimension(:), allocatable, intent(out) :: om | ||
| logical, intent(out) :: errored | ||
|
|
||
| ! variables | ||
| logical :: stat | ||
| integer(kind=int64) :: i, val, l | ||
| class(mp_arr_type), allocatable :: arr | ||
|
|
||
| errored = .true. | ||
| call get_arr_ref(obj, arr, stat) | ||
| if (.not.(stat)) then | ||
| return | ||
| end if | ||
| ! initialize output | ||
| l = arr%numelements() | ||
| allocate(om(l)) | ||
| do i = 1,l | ||
| call get_int(arr%values(i)%obj, val, stat) | ||
| if (.not.(stat)) then | ||
| return | ||
| end if | ||
| om(i) = val | ||
| end do | ||
| errored = .false. | ||
| end subroutine | ||
|
|
||
| subroutine unpack_array_real_1d(obj, om, errored) | ||
| ! Attempts to unpack a 1d messagepack array of reals | ||
| ! @param[in] obj - messagepack object | ||
| ! @param[out] om - dynamically allocated matrix | ||
| ! @param[out] errored - .true. if an error occurred | ||
| class(mp_value_type), allocatable, intent(in) :: obj | ||
| real(kind=real64), dimension(:), allocatable, intent(out) :: om | ||
| logical, intent(out) :: errored | ||
|
|
||
| ! variables | ||
| logical :: stat | ||
| integer(kind=int64) :: i, l | ||
| real(kind=real64) :: val | ||
| class(mp_arr_type), allocatable :: arr | ||
|
|
||
| errored = .true. | ||
| call get_arr_ref(obj, arr, stat) | ||
| if (.not.(stat)) then | ||
| return | ||
| end if | ||
| ! initialize output | ||
| l = arr%numelements() | ||
| allocate(om(l)) | ||
| do i = 1,l | ||
| call get_real(arr%values(i)%obj, val, stat) | ||
| if (.not.(stat)) then | ||
| return | ||
| end if | ||
| om(i) = val | ||
| end do | ||
| errored = .false. | ||
| end subroutine | ||
|
|
||
| end module |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.