SUBROUTINE sum_up_3d_data !------------------------------------------------------------------------------! ! Actual revisions: ! ----------------- ! +shf*, qsws* ! ! Former revisions: ! ----------------- ! $Id: sum_up_3d_data.f90 367 2009-08-25 08:35:52Z raasch $ ! ! 96 2007-06-04 08:07:41Z raasch ! +sum-up of density and salinity ! ! 72 2007-03-19 08:20:46Z raasch ! +sum-up of precipitation rate and roughness length (prr*, z0*) ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.1 2006/02/23 12:55:23 raasch ! Initial revision ! ! ! Description: ! ------------ ! Sum-up the values of 3d-arrays. The real averaging is later done in routine ! average_3d_data. !------------------------------------------------------------------------------! USE arrays_3d USE averaging USE cloud_parameters USE control_parameters USE cpulog USE indices USE interfaces USE particle_attributes IMPLICIT NONE INTEGER :: i, ii, j, k, n, psi REAL :: mean_r, s_r3, s_r4 CALL cpu_log (log_point(34),'sum_up_3d_data','start') ! !-- Allocate and initialize the summation arrays if called for the very first !-- time or the first time after average_3d_data has been called !-- (some or all of the arrays may have been already allocated !-- in read_3d_binary) IF ( average_count_3d == 0 ) THEN DO ii = 1, doav_n SELECT CASE ( TRIM( doav(ii) ) ) CASE ( 'e' ) IF ( .NOT. ALLOCATED( e_av ) ) THEN ALLOCATE( e_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF e_av = 0.0 CASE ( 'lwp*' ) IF ( .NOT. ALLOCATED( lwp_av ) ) THEN ALLOCATE( lwp_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF lwp_av = 0.0 CASE ( 'p' ) IF ( .NOT. ALLOCATED( p_av ) ) THEN ALLOCATE( p_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF p_av = 0.0 CASE ( 'pc' ) IF ( .NOT. ALLOCATED( pc_av ) ) THEN ALLOCATE( pc_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF pc_av = 0.0 CASE ( 'pr' ) IF ( .NOT. ALLOCATED( pr_av ) ) THEN ALLOCATE( pr_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF pr_av = 0.0 CASE ( 'prr*' ) IF ( .NOT. ALLOCATED( precipitation_rate_av ) ) THEN ALLOCATE( precipitation_rate_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF precipitation_rate_av = 0.0 CASE ( 'pt' ) IF ( .NOT. ALLOCATED( pt_av ) ) THEN ALLOCATE( pt_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF pt_av = 0.0 CASE ( 'q' ) IF ( .NOT. ALLOCATED( q_av ) ) THEN ALLOCATE( q_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF q_av = 0.0 CASE ( 'ql' ) IF ( .NOT. ALLOCATED( ql_av ) ) THEN ALLOCATE( ql_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ql_av = 0.0 CASE ( 'ql_c' ) IF ( .NOT. ALLOCATED( ql_c_av ) ) THEN ALLOCATE( ql_c_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ql_c_av = 0.0 CASE ( 'ql_v' ) IF ( .NOT. ALLOCATED( ql_v_av ) ) THEN ALLOCATE( ql_v_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ql_v_av = 0.0 CASE ( 'ql_vp' ) IF ( .NOT. ALLOCATED( ql_vp_av ) ) THEN ALLOCATE( ql_vp_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ql_vp_av = 0.0 CASE ( 'qsws*' ) IF ( .NOT. ALLOCATED( qsws_av ) ) THEN ALLOCATE( qsws_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF qsws_av = 0.0 CASE ( 'qv' ) IF ( .NOT. ALLOCATED( qv_av ) ) THEN ALLOCATE( qv_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF qv_av = 0.0 CASE ( 'rho' ) IF ( .NOT. ALLOCATED( rho_av ) ) THEN ALLOCATE( rho_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF rho_av = 0.0 CASE ( 's' ) IF ( .NOT. ALLOCATED( s_av ) ) THEN ALLOCATE( s_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF s_av = 0.0 CASE ( 'sa' ) IF ( .NOT. ALLOCATED( sa_av ) ) THEN ALLOCATE( sa_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF sa_av = 0.0 CASE ( 'shf*' ) IF ( .NOT. ALLOCATED( shf_av ) ) THEN ALLOCATE( shf_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF shf_av = 0.0 CASE ( 't*' ) IF ( .NOT. ALLOCATED( ts_av ) ) THEN ALLOCATE( ts_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ts_av = 0.0 CASE ( 'u' ) IF ( .NOT. ALLOCATED( u_av ) ) THEN ALLOCATE( u_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF u_av = 0.0 CASE ( 'u*' ) IF ( .NOT. ALLOCATED( us_av ) ) THEN ALLOCATE( us_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF us_av = 0.0 CASE ( 'v' ) IF ( .NOT. ALLOCATED( v_av ) ) THEN ALLOCATE( v_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF v_av = 0.0 CASE ( 'vpt' ) IF ( .NOT. ALLOCATED( vpt_av ) ) THEN ALLOCATE( vpt_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF vpt_av = 0.0 CASE ( 'w' ) IF ( .NOT. ALLOCATED( w_av ) ) THEN ALLOCATE( w_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF w_av = 0.0 CASE ( 'z0*' ) IF ( .NOT. ALLOCATED( z0_av ) ) THEN ALLOCATE( z0_av(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF z0_av = 0.0 CASE DEFAULT ! !-- User-defined quantity CALL user_3d_data_averaging( 'allocate', doav(ii) ) END SELECT ENDDO ENDIF ! !-- Loop of all variables to be averaged. DO ii = 1, doav_n ! !-- Store the array chosen on the temporary array. SELECT CASE ( TRIM( doav(ii) ) ) CASE ( 'e' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 e_av(k,j,i) = e_av(k,j,i) + e(k,j,i) ENDDO ENDDO ENDDO CASE ( 'lwp*' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 lwp_av(j,i) = lwp_av(j,i) + SUM( ql(nzb:nzt,j,i) * & dzw(1:nzt+1) ) ENDDO ENDDO CASE ( 'p' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 p_av(k,j,i) = p_av(k,j,i) + p(k,j,i) ENDDO ENDDO ENDDO CASE ( 'pc' ) DO i = nxl, nxr DO j = nys, nyn DO k = nzb, nzt+1 pc_av(k,j,i) = pc_av(k,j,i) + prt_count(k,j,i) ENDDO ENDDO ENDDO CASE ( 'pr' ) DO i = nxl, nxr DO j = nys, nyn DO k = nzb, nzt+1 psi = prt_start_index(k,j,i) s_r3 = 0.0 s_r4 = 0.0 DO n = psi, psi+prt_count(k,j,i)-1 s_r3 = s_r3 + particles(n)%radius**3 s_r4 = s_r4 + particles(n)%radius**4 ENDDO IF ( s_r3 /= 0.0 ) THEN mean_r = s_r4 / s_r3 ELSE mean_r = 0.0 ENDIF pr_av(k,j,i) = pr_av(k,j,i) + mean_r ENDDO ENDDO ENDDO CASE ( 'pr*' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 precipitation_rate_av(j,i) = precipitation_rate_av(j,i) + & precipitation_rate(j,i) ENDDO ENDDO CASE ( 'pt' ) IF ( .NOT. cloud_physics ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i) ENDDO ENDDO ENDDO ELSE DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i) + l_d_cp * & pt_d_t(k) * ql(k,j,i) ENDDO ENDDO ENDDO ENDIF CASE ( 'q' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 q_av(k,j,i) = q_av(k,j,i) + q(k,j,i) ENDDO ENDDO ENDDO CASE ( 'ql' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 ql_av(k,j,i) = ql_av(k,j,i) + ql(k,j,i) ENDDO ENDDO ENDDO CASE ( 'ql_c' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 ql_c_av(k,j,i) = ql_c_av(k,j,i) + ql_c(k,j,i) ENDDO ENDDO ENDDO CASE ( 'ql_v' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 ql_v_av(k,j,i) = ql_v_av(k,j,i) + ql_v(k,j,i) ENDDO ENDDO ENDDO CASE ( 'ql_vp' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 ql_vp_av(k,j,i) = ql_vp_av(k,j,i) + ql_vp(k,j,i) ENDDO ENDDO ENDDO CASE ( 'qv' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 qv_av(k,j,i) = qv_av(k,j,i) + q(k,j,i) - ql(k,j,i) ENDDO ENDDO ENDDO CASE ( 'rho' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 rho_av(k,j,i) = rho_av(k,j,i) + rho(k,j,i) ENDDO ENDDO ENDDO CASE ( 's' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 s_av(k,j,i) = s_av(k,j,i) + q(k,j,i) ENDDO ENDDO ENDDO CASE ( 'sa' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 sa_av(k,j,i) = sa_av(k,j,i) + sa(k,j,i) ENDDO ENDDO ENDDO CASE ( 't*' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 ts_av(j,i) = ts_av(j,i) + ts(j,i) ENDDO ENDDO CASE ( 'u' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 u_av(k,j,i) = u_av(k,j,i) + u(k,j,i) ENDDO ENDDO ENDDO CASE ( 'u*' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 us_av(j,i) = us_av(j,i) + us(j,i) ENDDO ENDDO CASE ( 'v' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 v_av(k,j,i) = v_av(k,j,i) + v(k,j,i) ENDDO ENDDO ENDDO CASE ( 'vpt' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 vpt_av(k,j,i) = vpt_av(k,j,i) + vpt(k,j,i) ENDDO ENDDO ENDDO CASE ( 'w' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = nzb, nzt+1 w_av(k,j,i) = w_av(k,j,i) + w(k,j,i) ENDDO ENDDO ENDDO CASE ( 'z0*' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 z0_av(j,i) = z0_av(j,i) + z0(j,i) ENDDO ENDDO CASE DEFAULT ! !-- User-defined quantity CALL user_3d_data_averaging( 'sum', doav(ii) ) END SELECT ENDDO CALL cpu_log (log_point(34),'sum_up_3d_data','stop','nobarrier') END SUBROUTINE sum_up_3d_data