@@ -719,28 +719,43 @@ subroutine update_clm(tstartcycle, mype) bind(C,name="update_clm")
719719 ! Case 1: Snow depth
720720 ! Write updated snow depth back to CLM and then repartition snow and adjust related variables
721721 if (clmupdate_snow.eq. 1 ) then
722- cc = 1
723- do j= clm_begg,clm_endg
722+ do j= clm_begc,clm_endc
724723 ! iterate through the columns and copy from the same gridcell
725724 ! i.e. statevec position (cc) for each column
726- do jj= clm_begc,clm_endc
727- ! Catch negative or 0 values from DA
728- if (clm_statevec(cc+ offset).lt. 0.0 ) then
729- print * , " WARNING: snow depth at g,c is negative: " , j, jj, clm_statevec(cc+ offset)
730- else
731- rsnow(jj) = snow_depth(jj) - clm_statevec(cc+ offset)
732- if ( ABS (SUM (rsnow(:))) .gt. 0.000001 ) then
733- snow_depth(jj) = clm_statevec(cc+ offset)
734- endif
735- endif
736- end do
737- cc = cc + 1
738- end do
739- if ( clmupdate_snow_repartitioning.ne. 0 ) then
725+
726+ ! Set cc (the state vector index) from the
727+ ! CLM5-grid-index and the `CLM5-layer-index times
728+ ! num_gridcells`
729+ if (clmstatevec_allcol.eq. 0 ) then
730+ cc = (col% gridcell(j) - clm_begg + 1 )
731+ else
732+ cc = (j - clm_begc + 1 )
733+ end if
734+ ! Catch negative or 0 values from DA
735+ if (clm_statevec(cc+ offset).lt. 0.0 ) then
736+ print * , " WARNING: snow depth at g,c is negative: " , cc, j, clm_statevec(cc+ offset)
737+ else
738+ rsnow(j) = snow_depth(j)
739+ if ( ABS (SUM (rsnow(:) - clm_statevec(cc+ offset))) .gt. 0.000001 ) then
740+ snow_depth(j) = clm_statevec(cc+ offset)
741+ ! JK: clmupdate_snow_repartitioning.eq.3 is experimental
742+ ! JK: clmupdate_snow_repartitioning.eq.3 from NASA-Code (based on older CLM3.5 version)
743+ ! https://github.com/NASA-LIS/LISF/blob/master/lis/surfacemodels/land/clm2/da_snow/clm2_setsnowvars.F90
744+ if ( clmupdate_snow_repartitioning.eq. 3 ) then
745+ incr_h2osno = snow_depth(j) / rsnow(j) ! INC = New SD / OLD SD
746+ do i= snlsno(j)+ 1 ,0
747+ h2osoi_ice(j,i) = h2osoi_ice(j,i) * incr_h2osno
748+ end do
749+ endif
750+ endif
751+ endif
752+ end do
753+
754+ if ( clmupdate_snow_repartitioning.ne. 0 .and. clmupdate_snow_repartitioning.ne. 3 ) then
740755 if ( ABS (SUM (rsnow(:))).gt. 0.000001 ) then
741756 call clm_repartition_snow()
742757 end if
743- end if
758+ end if
744759 endif
745760 ! Case 2: Snow water equivalent
746761 ! Write updated snow depth back to CLM and then repartition snow and adjust related variables
0 commit comments