@@ -1427,7 +1427,7 @@ subroutine clubb_ini_cam(pbuf2d)
1427
1427
logical , parameter :: l_input_fields = .false. ! Always false for CAM-CLUBB.
1428
1428
logical , parameter :: l_update_pressure = .false. ! Always false for CAM-CLUBB.
1429
1429
1430
- integer :: nlev
1430
+ integer :: nlev, ierr = 0
1431
1431
1432
1432
real (r8 ) :: &
1433
1433
C1, C1b, C1c, C2rt, C2thl, C2rtthl, &
@@ -1465,7 +1465,8 @@ subroutine clubb_ini_cam(pbuf2d)
1465
1465
allocate ( &
1466
1466
pdf_params_chnk(begchunk:endchunk), &
1467
1467
pdf_params_zm_chnk(begchunk:endchunk), &
1468
- pdf_implicit_coefs_terms_chnk(begchunk:endchunk) )
1468
+ pdf_implicit_coefs_terms_chnk(begchunk:endchunk), stat= ierr )
1469
+ if ( ierr /= 0 ) call endrun(' clubb_ini_cam: failed to allocate pdf_params' )
1469
1470
1470
1471
! ----------------------------------------------------------------- !
1471
1472
! Determine how many constituents CLUBB will transport. Note that
@@ -1831,13 +1832,18 @@ subroutine clubb_ini_cam(pbuf2d)
1831
1832
stats_zt(:), stats_zm(:), stats_sfc(:), &
1832
1833
stats_rad_zt(:), stats_rad_zm(:))
1833
1834
1834
- allocate (out_zt(pcols,pverp,stats_zt(1 )% num_output_fields))
1835
- allocate (out_zm(pcols,pverp,stats_zm(1 )% num_output_fields))
1836
- allocate (out_sfc(pcols,1 ,stats_sfc(1 )% num_output_fields))
1835
+ allocate (out_zt(pcols,pverp,stats_zt(1 )% num_output_fields), stat= ierr)
1836
+ if ( ierr /= 0 ) call endrun( ' clubb_ini_cam: Unable to allocate out_zt' )
1837
+ allocate (out_zm(pcols,pverp,stats_zm(1 )% num_output_fields), stat= ierr)
1838
+ if ( ierr /= 0 ) call endrun( ' clubb_ini_cam: Unable to allocate out_zm' )
1839
+ allocate (out_sfc(pcols,1 ,stats_sfc(1 )% num_output_fields), stat= ierr)
1840
+ if ( ierr /= 0 ) call endrun( ' clubb_ini_cam: Unable to allocate out_sfc' )
1837
1841
1838
1842
if ( stats_metadata% l_output_rad_files ) then
1839
- allocate (out_radzt(pcols,pverp,stats_rad_zt(1 )% num_output_fields))
1840
- allocate (out_radzm(pcols,pverp,stats_rad_zm(1 )% num_output_fields))
1843
+ allocate (out_radzt(pcols,pverp,stats_rad_zt(1 )% num_output_fields), stat= ierr)
1844
+ if ( ierr /= 0 ) call endrun( ' clubb_ini_cam: Unable to allocate out_radzt' )
1845
+ allocate (out_radzm(pcols,pverp,stats_rad_zm(1 )% num_output_fields), stat= ierr)
1846
+ if ( ierr /= 0 ) call endrun( ' clubb_ini_cam: Unable to allocate out_radzm' )
1841
1847
end if
1842
1848
1843
1849
endif
@@ -3796,12 +3802,14 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
3796
3802
ptend_loc% q(i,k,ixcldliq) = (rcm(i,k) - state1% q(i,k,ixcldliq)) / hdtime ! Tendency of liquid water
3797
3803
ptend_loc% s(i,k) = (clubb_s(i,k) - state1% s(i,k)) / hdtime ! Tendency of static energy
3798
3804
3799
- rtm_integral_ltend(i) = rtm_integral_ltend(i) + ptend_loc% q(i,k,ixcldliq)* state1% pdel(i,k)/ gravit
3800
- rtm_integral_vtend(i) = rtm_integral_vtend(i) + ptend_loc% q(i,k,ixq)* state1% pdel(i,k)/ gravit
3805
+ rtm_integral_ltend(i) = rtm_integral_ltend(i) + ptend_loc% q(i,k,ixcldliq)* state1% pdel(i,k)
3806
+ rtm_integral_vtend(i) = rtm_integral_vtend(i) + ptend_loc% q(i,k,ixq)* state1% pdel(i,k)
3801
3807
3802
3808
end do
3803
3809
end do
3804
-
3810
+
3811
+ rtm_integral_ltend(i) = rtm_integral_ltend(i)/ gravit
3812
+ rtm_integral_vtend(i) = rtm_integral_vtend(i)/ gravit
3805
3813
3806
3814
if (clubb_do_adv) then
3807
3815
if (macmic_it == cld_macmic_num_steps) then
@@ -4761,10 +4769,10 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4761
4769
if ( abs ( stats_metadata% stats_tsamp/ delt - floor (stats_metadata% stats_tsamp/ delt) ) > 1.e-8_r8 ) then
4762
4770
l_error = .true. ! This will cause the run to stop.
4763
4771
write (fstderr,* ) ' Error: stats_tsamp should be an even multiple of ' , &
4764
- ' delt (which is dtmain). Check the appropriate ' , &
4765
- ' model.in file.'
4772
+ ' the clubb time step (delt below)'
4766
4773
write (fstderr,* ) ' stats_tsamp = ' , stats_metadata% stats_tsamp
4767
4774
write (fstderr,* ) ' delt = ' , delt
4775
+ call endrun (" stats_init_clubb: CLUBB stats_tsamp must be an even multiple of the timestep" )
4768
4776
endif
4769
4777
4770
4778
! Initialize zt (mass points)
@@ -4777,6 +4785,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4777
4785
enddo
4778
4786
ntot = i - 1
4779
4787
if ( ntot == nvarmax_zt ) then
4788
+ l_error = .true.
4780
4789
write (fstderr,* ) " There are more statistical variables listed in " , &
4781
4790
" clubb_vars_zt than allowed for by nvarmax_zt."
4782
4791
write (fstderr,* ) " Check the number of variables listed for clubb_vars_zt " , &
@@ -4788,16 +4797,22 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4788
4797
stats_zt(j)% num_output_fields = ntot
4789
4798
stats_zt(j)% kk = nnzp
4790
4799
4791
- allocate ( stats_zt(j)% z( stats_zt(j)% kk ) )
4800
+ allocate ( stats_zt(j)% z( stats_zt(j)% kk ), stat= ierr )
4801
+ if ( ierr /= 0 ) call endrun(" stats_init_clubb: Failed to allocate stats_zt%z" )
4792
4802
4793
- allocate ( stats_zt(j)% accum_field_values( 1 , 1 , stats_zt(j)% kk, stats_zt(j)% num_output_fields ) )
4794
- allocate ( stats_zt(j)% accum_num_samples( 1 , 1 , stats_zt(j)% kk, stats_zt(j)% num_output_fields ) )
4795
- allocate ( stats_zt(j)% l_in_update( 1 , 1 , stats_zt(j)% kk, stats_zt(j)% num_output_fields ) )
4803
+ allocate ( stats_zt(j)% accum_field_values( 1 , 1 , stats_zt(j)% kk, stats_zt(j)% num_output_fields ), stat= ierr )
4804
+ if ( ierr /= 0 ) call endrun(" stats_init_clubb: Failed to allocate stats_zt%accum_field_values" )
4805
+ allocate ( stats_zt(j)% accum_num_samples( 1 , 1 , stats_zt(j)% kk, stats_zt(j)% num_output_fields ), stat= ierr )
4806
+ if ( ierr /= 0 ) call endrun(" stats_init_clubb: Failed to allocate stats_zt%accum_num_samples" )
4807
+ allocate ( stats_zt(j)% l_in_update( 1 , 1 , stats_zt(j)% kk, stats_zt(j)% num_output_fields ), stat= ierr )
4808
+ if ( ierr /= 0 ) call endrun(" stats_init_clubb: Failed to allocate stats_zt%l_in_update" )
4796
4809
call stats_zero( stats_zt(j)% kk, stats_zt(j)% num_output_fields, stats_zt(j)% accum_field_values, &
4797
4810
stats_zt(j)% accum_num_samples, stats_zt(j)% l_in_update )
4798
4811
4799
- allocate ( stats_zt(j)% file% grid_avg_var( stats_zt(j)% num_output_fields ) )
4800
- allocate ( stats_zt(j)% file% z( stats_zt(j)% kk ) )
4812
+ allocate ( stats_zt(j)% file% grid_avg_var( stats_zt(j)% num_output_fields ), stat= ierr )
4813
+ if ( ierr /= 0 ) call endrun(" stats_init_clubb: Failed to allocate stats_zt%file%grid_avg_var" )
4814
+ allocate ( stats_zt(j)% file% z( stats_zt(j)% kk ), stat= ierr )
4815
+ if ( ierr /= 0 ) call endrun(" stats_init_clubb: Failed to allocate stats_zt%file%z" )
4801
4816
4802
4817
! Default initialization for array indices for zt
4803
4818
call stats_init_zt_api( clubb_vars_zt, &
@@ -4814,6 +4829,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4814
4829
end do
4815
4830
ntot = i - 1
4816
4831
if ( ntot == nvarmax_zm ) then
4832
+ l_error = .true. ! This will cause the run to stop.
4817
4833
write (fstderr,* ) " There are more statistical variables listed in " , &
4818
4834
" clubb_vars_zm than allowed for by nvarmax_zm."
4819
4835
write (fstderr,* ) " Check the number of variables listed for clubb_vars_zm " , &
@@ -4889,6 +4905,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4889
4905
end do
4890
4906
ntot = i - 1
4891
4907
if ( ntot == nvarmax_rad_zm ) then
4908
+ l_error = .true. ! This will cause the run to stop.
4892
4909
write (fstderr,* ) " There are more statistical variables listed in " , &
4893
4910
" clubb_vars_rad_zm than allowed for by nvarmax_rad_zm."
4894
4911
write (fstderr,* ) " Check the number of variables listed for clubb_vars_rad_zm " , &
@@ -4928,6 +4945,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4928
4945
end do
4929
4946
ntot = i - 1
4930
4947
if ( ntot == nvarmax_sfc ) then
4948
+ l_error = .true. ! This will cause the run to stop.
4931
4949
write (fstderr,* ) " There are more statistical variables listed in " , &
4932
4950
" clubb_vars_sfc than allowed for by nvarmax_sfc."
4933
4951
write (fstderr,* ) " Check the number of variables listed for clubb_vars_sfc " , &
@@ -4990,20 +5008,29 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
4990
5008
if (stats_metadata% l_output_rad_files) then
4991
5009
4992
5010
do i = 1 , stats_rad_zt(1 )% num_output_fields
4993
- call addfld( trim (stats_rad_zt(1 )% file% grid_avg_var(i)% name), (/ ' ilev' / ), ' A' , &
5011
+ temp1 = trim (stats_rad_zt(1 )% file% grid_avg_var(i)% name)
5012
+ sub = temp1
5013
+ if (len (temp1) > max_fieldname_len) sub = temp1(1 :max_fieldname_len)
5014
+ call addfld( trim (sub), (/ ' ilev' / ), ' A' , &
4994
5015
trim (stats_rad_zt(1 )% file% grid_avg_var(i)% units), &
4995
5016
trim (stats_rad_zt(1 )% file% grid_avg_var(i)% description) )
4996
5017
enddo
4997
5018
4998
5019
do i = 1 , stats_rad_zm(1 )% num_output_fields
4999
- call addfld( trim (stats_rad_zm(1 )% file% grid_avg_var(i)% name), (/ ' ilev' / ), ' A' , &
5020
+ temp1 = trim (stats_rad_zm(1 )% file% grid_avg_var(i)% name)
5021
+ sub = temp1
5022
+ if (len (temp1) > max_fieldname_len) sub = temp1(1 :max_fieldname_len)
5023
+ call addfld( trim (sub), (/ ' ilev' / ), ' A' , &
5000
5024
trim (stats_rad_zm(1 )% file% grid_avg_var(i)% units), &
5001
5025
trim (stats_rad_zm(1 )% file% grid_avg_var(i)% description) )
5002
5026
enddo
5003
5027
endif
5004
5028
5005
5029
do i = 1 , stats_sfc(1 )% num_output_fields
5006
- call addfld( trim (stats_sfc(1 )% file% grid_avg_var(i)% name), horiz_only, ' A' , &
5030
+ temp1 = trim (stats_sfc(1 )% file% grid_avg_var(i)% name)
5031
+ sub = temp1
5032
+ if (len (temp1) > max_fieldname_len) sub = temp1(1 :max_fieldname_len)
5033
+ call addfld( trim (sub), horiz_only, ' A' , &
5007
5034
trim (stats_sfc(1 )% file% grid_avg_var(i)% units), &
5008
5035
trim (stats_sfc(1 )% file% grid_avg_var(i)% description) )
5009
5036
enddo
0 commit comments