diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dcd08ebfdcf..b2938757f332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated +## [2.44.1] - 2024-03-19 + +### Fixed + +- Fix bug where bit-shaved, instantaneous binary output in History was modifying the original export state passed + ## [2.44.0] - 2024-02-08 ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e2df2da13e6..b88a43b45e27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ endif () project ( MAPL - VERSION 2.44.0 + VERSION 2.44.1 LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF # Set the possible values of build type for cmake-gui diff --git a/gridcomps/History/MAPL_HistoryGridComp.F90 b/gridcomps/History/MAPL_HistoryGridComp.F90 index 9f5329b99ec5..3f78d05004bd 100644 --- a/gridcomps/History/MAPL_HistoryGridComp.F90 +++ b/gridcomps/History/MAPL_HistoryGridComp.F90 @@ -3253,7 +3253,8 @@ subroutine Run ( gc, import, export, clock, rc ) integer :: n,m logical, allocatable :: NewSeg(:) logical, allocatable :: Writing(:) - type(ESMF_State) :: state_out + type(ESMF_State) :: state_out, final_state + type(ESMF_Field) :: temp_field, state_field integer :: nymd, nhms character(len=ESMF_MAXSTR) :: DateStamp type(ESMF_Time) :: current_time @@ -3626,13 +3627,36 @@ subroutine Run ( gc, import, export, clock, rc ) INTSTATE%LCTL(n) = .false. endif - call shavebits(state_out, list(n), _RC) + if (list(n)%nbits_to_keep < MAPL_NBITS_UPPER_LIMIT) then + final_state = ESMF_StateCreate(_RC) + do m=1,list(n)%field_set%nfields + call ESMF_StateGet(state_out,trim(list(n)%field_set%fields(3,m)),state_field,_RC) + temp_field = MAPL_FieldCreate(state_field,list(n)%field_set%fields(3,m),DoCopy=.true.,_RC) + call ESMF_StateAdd(final_state,[temp_field],_RC) + enddo + call ESMF_AttributeCopy(state_out,final_state,_RC) + call shavebits(final_state,list(n),_RC) + end if do m=1,list(n)%field_set%nfields - call MAPL_VarWrite ( list(n)%unit, STATE=state_out, & - NAME=trim(list(n)%field_set%fields(3,m)), & - forceWriteNoRestart=.true., _RC ) + if (list(n)%nbits_to_keep >=MAPL_NBITS_UPPER_LIMIT) then + call MAPL_VarWrite ( list(n)%unit, STATE=state_out, & + NAME=trim(list(n)%field_set%fields(3,m)), & + forceWriteNoRestart=.true., _RC ) + else + call MAPL_VarWrite ( list(n)%unit, STATE=final_state, & + NAME=trim(list(n)%field_set%fields(3,m)), & + forceWriteNoRestart=.true., _RC ) + endif enddo + + if (list(n)%nbits_to_keep < MAPL_NBITS_UPPER_LIMIT) then + do m=1,list(n)%field_set%nfields + call ESMF_StateGet(final_state,trim(list(n)%field_set%fields(3,m)),temp_field,_RC) + call ESMF_FieldDestroy(temp_field,noGarbage=.true.,_RC) + enddo + call ESMF_StateDestroy(final_state,noGarbage=.true.,_RC) + end if call WRITE_PARALLEL("Wrote GrADS Output for File: "//trim(filename(n))) end if IOTYPE @@ -5154,7 +5178,7 @@ subroutine checkIfStateHasField(state, fieldName, hasField, rc) _RETURN(ESMF_SUCCESS) end subroutine checkIfStateHasField - subroutine shavebits( state, list, rc) + subroutine shavebits( state, list, rc) type(ESMF_state), intent(inout) :: state type (HistoryCollection), intent(in) :: list integer, optional, intent(out):: rc @@ -5165,10 +5189,6 @@ subroutine shavebits( state, list, rc) type(ESMF_VM) :: vm integer :: comm - if (list%nbits_to_keep >=MAPL_NBITS_UPPER_LIMIT) then - _RETURN(ESMF_SUCCESS) - endif - call ESMF_VMGetCurrent(vm,_RC) call ESMF_VMGet(vm,mpiCommunicator=comm,_RC)