Subroutine vom_adapt_foliage

2124 : 
2125 : !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2126 : !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2127 : !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2128 : !*------ADJUSTMENT OF JMAX25, PC, LAI-------------------------------------
2129 : 
2130 :       subroutine vom_adapt_foliage ()
2131 :       use vom_vegwat_mod
2132 :       implicit none
2133 : 
2134 :       INTEGER :: ii                     ! Counter
2135 :       REAL*8  :: jmax25g_tmp            ! Temporary jmax25g for comparison
2136 :       REAL*8  :: lai_g_tmp              ! Temporary leaf area index for comparison
2137 :       REAL*8  :: max_netcg              ! Maximum daily grass net carbon profit grasses
2138 :       REAL*8  :: max_netcg_tmp          ! Temporary max net carbon profit
2139 :       REAL*8  :: netcg_d(3,3)           ! Daily grass net carbon profit
2140 :       REAL*8  :: netct_d(3,3)           ! Daily grass net carbon profit
2141 :       REAL*8  :: pcg_d_tmp              ! Temporary grass cover
2142 :       INTEGER :: posma(1)               ! Pointer to variable values that achieved maximum assimilation
2143 :       INTEGER :: posbest(2)              ! Pointer to variable values that achieved maximum net assimilation
2144 :       !trees
2145 : 
2146 :       !loop over foliage costs due to different LAI
2147 :       !3 values of ncp due to different jmax25t values and LAI
2148 :       netct_d(1,:) = asst_d(1,:) - 3600.d0 * 24.d0 * (q_cpcct_d + rrt_d + q_tct_d(:))
2149 :       netct_d(2,:) = asst_d(2,:) - 3600.d0 * 24.d0 * (q_cpcct_d + rrt_d + q_tct_d(:))
2150 :       netct_d(3,:) = asst_d(3,:) - 3600.d0 * 24.d0 * (q_cpcct_d + rrt_d + q_tct_d(:))
2151 :       posbest(:)    = MAXLOC(netct_d(:,:))
2152 : 
2153 : 
2154 :       lai_lt(2) = lai_lt(posbest(2))                    !lai trees 
2155 :       jmax25t_d(2) = jmax25t_d(posbest(1))              !jmax25 trees in 
2156 :   
2157 :       !set daily value back to zero
2158 :       asst_d(:,:)    = 0.d0
2159 : 
2160 : 
2161 :       !grasses
2162 : 
2163 :       !set initial max value at zero
2164 :       max_netcg    = -9999.d0
2165 : 
2166 :       !loop over foliage costs due to different LAI
2167 :       do ii = 1,3
2168 : 
2169 :          !3 values of ncp due to different cover (rows in assg_d) and jmax25g (columns in assg_d)
2170 :          netcg_d(1,:) = assg_d(1,:,ii) - 3600.d0 * 24.d0 * (cpccg_d(1) + rrg_d + tcg_d(ii, 1))
2171 :          netcg_d(2,:) = assg_d(2,:,ii) - 3600.d0 * 24.d0 * (cpccg_d(2) + rrg_d + tcg_d(ii, 2))
2172 :          netcg_d(3,:) = assg_d(3,:,ii) - 3600.d0 * 24.d0 * (cpccg_d(3) + rrg_d + tcg_d(ii, 3))
2173 :          posbest(:)    = MAXLOC(netcg_d(:,:))
2174 :          max_netcg_tmp= netcg_d( posbest(1), posbest(2) )
2175 : 
2176 :          !check if carbon profit is higher for different LAI
2177 :          if( max_netcg_tmp .gt. max_netcg) then
2178 :             
2179 :             pcg_d_tmp = MIN(1.d0 - o_cai, pcg_d(posbest(1))) !cover grasses to temporary variable
2180 :             lai_g_tmp = lai_lg(ii)                          !lai grasses in temporary variable
2181 :             jmax25g_tmp = jmax25g_d(posbest(2))              !jmax25 grasses in temporary variable
2182 :             max_netcg = max_netcg_tmp                       !new NCP is higher as previous
2183 :             posmna = (/ posbest , ii /)
2184 :          end if
2185 :       end do
2186 : 
2187 :       !save all temporary variables to the global vectors
2188 :       pcg_d(2)     = pcg_d_tmp
2189 :       jmax25g_d(2) = jmax25g_tmp
2190 :       lai_lg(2)    = lai_g_tmp
2191 : 
2192 :       !set daily value back to zero
2193 :       assg_d(:,:,:)  = 0.d0
2194 : 
2195 :       return
2196 :       end subroutine vom_adapt_foliage