-
Notifications
You must be signed in to change notification settings - Fork 12
/
stats_clubb_utilities.F90
3300 lines (2775 loc) · 115 KB
/
stats_clubb_utilities.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!-----------------------------------------------------------------------
! $Id$
!===============================================================================
module stats_clubb_utilities
implicit none
private ! Set Default Scope
public :: stats_init, stats_begin_timestep, stats_end_timestep, &
stats_accumulate, stats_finalize, stats_accumulate_hydromet, &
stats_accumulate_lh_tend
private :: stats_zero, stats_avg, stats_check_num_samples
contains
!-----------------------------------------------------------------------
subroutine stats_init( iunit, fname_prefix, fdir, l_stats_in, &
stats_fmt_in, stats_tsamp_in, stats_tout_in, fnamelist, &
nzmax, nlon, nlat, gzt, gzm, nnrad_zt, &
grad_zt, nnrad_zm, grad_zm, day, month, year, &
rlon, rlat, time_current, delt, l_silhs_out_in )
!
! Description:
! Initializes the statistics saving functionality of the CLUBB model.
!
! References:
! None
!-----------------------------------------------------------------------
use stats_variables, only: &
stats_zt, & ! Variables
ztscr01, &
ztscr02, &
ztscr03, &
ztscr04, &
ztscr05, &
ztscr06, &
ztscr07, &
ztscr08, &
ztscr09, &
ztscr10, &
ztscr11, &
ztscr12, &
ztscr13, &
ztscr14, &
ztscr15, &
ztscr16, &
ztscr17, &
ztscr18, &
ztscr19, &
ztscr20, &
ztscr21
use stats_variables, only: &
l_silhs_out, & ! Variable(s)
stats_lh_zt, &
stats_lh_sfc
use stats_variables, only: &
stats_zm, & ! Variables
zmscr01, &
zmscr02, &
zmscr03, &
zmscr04, &
zmscr05, &
zmscr06, &
zmscr07, &
zmscr08, &
zmscr09, &
zmscr10, &
zmscr11, &
zmscr12, &
zmscr13, &
zmscr14, &
zmscr15, &
zmscr16, &
zmscr17, &
stats_rad_zt
use stats_variables, only: &
stats_rad_zm, &
stats_sfc, &
l_stats, &
l_output_rad_files, &
stats_tsamp, &
stats_tout, &
l_stats_samp, &
l_stats_last, &
fname_zt, &
fname_lh_zt, &
fname_lh_sfc, &
fname_zm, &
fname_rad_zt, &
fname_rad_zm, &
fname_sfc, &
l_netcdf, &
l_grads
use clubb_precision, only: &
time_precision, & ! Constant(s)
core_rknd
use output_grads, only: &
open_grads ! Procedure
#ifdef NETCDF
use output_netcdf, only: &
open_netcdf_for_writing ! Procedure
#endif
use stats_zm_module, only: &
nvarmax_zm, & ! Constant(s)
stats_init_zm ! Procedure(s)
use stats_zt_module, only: &
nvarmax_zt, & ! Constant(s)
stats_init_zt ! Procedure(s)
use stats_lh_zt_module, only: &
nvarmax_lh_zt, & ! Constant(s)
stats_init_lh_zt ! Procedure(s)
use stats_lh_sfc_module, only: &
nvarmax_lh_sfc, & ! Constant(s)
stats_init_lh_sfc ! Procedure(s)
use stats_rad_zt_module, only: &
nvarmax_rad_zt, & ! Constant(s)
stats_init_rad_zt ! Procedure(s)
use stats_rad_zm_module, only: &
nvarmax_rad_zm, & ! Constant(s)
stats_init_rad_zm ! Procedure(s)
use stats_sfc_module, only: &
nvarmax_sfc, & ! Constant(s)
stats_init_sfc ! Procedure(s)
use constants_clubb, only: &
fstdout, fstderr, var_length ! Constants
use parameters_model, only: &
hydromet_dim, & ! Variable(s)
sclr_dim, &
edsclr_dim
use error_code, only: &
clubb_at_least_debug_level, & ! Procedure
err_code, & ! Error Indicator
clubb_fatal_error ! Constant
implicit none
! Local Constants
integer, parameter :: &
silhs_num_importance_categories = 8
! Input Variables
integer, intent(in) :: iunit ! File unit for fnamelist
character(len=*), intent(in) :: &
fname_prefix, & ! Start of the stats filenames
fdir ! Directory to output to
logical, intent(in) :: &
l_stats_in ! Stats on? T/F
character(len=*), intent(in) :: &
stats_fmt_in ! Format of the stats file output
real( kind = core_rknd ), intent(in) :: &
stats_tsamp_in, & ! Sampling interval [s]
stats_tout_in ! Output interval [s]
character(len=*), intent(in) :: &
fnamelist ! Filename holding the &statsnl
integer, intent(in) :: &
nlon, & ! Number of points in the X direction [-]
nlat, & ! Number of points in the Y direction [-]
nzmax ! Grid points in the vertical [-]
real( kind = core_rknd ), intent(in), dimension(nzmax) :: &
gzt, gzm ! Thermodynamic and momentum levels [m]
integer, intent(in) :: nnrad_zt ! Grid points in the radiation grid [count]
real( kind = core_rknd ), intent(in), dimension(nnrad_zt) :: grad_zt ! Radiation levels [m]
integer, intent(in) :: nnrad_zm ! Grid points in the radiation grid [count]
real( kind = core_rknd ), intent(in), dimension(nnrad_zm) :: grad_zm ! Radiation levels [m]
integer, intent(in) :: day, month, year ! Time of year
real( kind = core_rknd ), dimension(nlon), intent(in) :: &
rlon ! Longitude(s) [Degrees E]
real( kind = core_rknd ), dimension(nlat), intent(in) :: &
rlat ! Latitude(s) [Degrees N]
real( kind = time_precision ), intent(in) :: &
time_current ! Model time [s]
real( kind = core_rknd ), intent(in) :: &
delt ! Timestep (dt_main in CLUBB) [s]
logical, intent(in) :: &
l_silhs_out_in ! Whether to output SILHS files (stats_lh_zt, stats_lh_sfc) [boolean]
! Local Variables
logical :: l_error
character(len=200) :: fname
integer :: ivar, ntot, read_status
! Namelist Variables
character(len=10) :: stats_fmt ! File storage convention
character(len=var_length), dimension(nvarmax_zt) :: &
vars_zt ! Variables on the thermodynamic levels
character(len=var_length), dimension(nvarmax_lh_zt) :: &
vars_lh_zt ! Latin Hypercube variables on the thermodynamic levels
character(len=var_length), dimension(nvarmax_lh_sfc) :: &
vars_lh_sfc ! Latin Hypercube variables at the surface
character(len=var_length), dimension(nvarmax_zm) :: &
vars_zm ! Variables on the momentum levels
character(len=var_length), dimension(nvarmax_rad_zt) :: &
vars_rad_zt ! Variables on the radiation levels
character(len=var_length), dimension(nvarmax_rad_zm) :: &
vars_rad_zm ! Variables on the radiation levels
character(len=var_length), dimension(nvarmax_sfc) :: &
vars_sfc ! Variables at the model surface
namelist /statsnl/ &
vars_zt, &
vars_zm, &
vars_lh_zt, &
vars_lh_sfc, &
vars_rad_zt, &
vars_rad_zm, &
vars_sfc
! ---- Begin Code ----
! Initialize
l_error = .false.
! Set stats_variables variables with inputs from calling subroutine
l_stats = l_stats_in
stats_tsamp = stats_tsamp_in
stats_tsamp = stats_tsamp_in
stats_tout = stats_tout_in
stats_fmt = trim( stats_fmt_in )
l_silhs_out = l_silhs_out_in
if ( .not. l_stats ) then
l_stats_samp = .false.
l_stats_last = .false.
return
end if
! Initialize namelist variables
vars_zt = ''
vars_zm = ''
vars_lh_zt = ''
vars_lh_sfc = ''
vars_rad_zt = ''
vars_rad_zm = ''
vars_sfc = ''
! Reads list of variables that should be output to GrADS/NetCDF (namelist &statsnl)
open(unit=iunit, file=fnamelist)
read(unit=iunit, nml=statsnl, iostat=read_status, end=100)
if ( read_status /= 0 ) then
if ( read_status > 0 ) then
write(fstderr,*) "Error reading stats namelist in file ", &
trim( fnamelist )
else ! Read status < 0
write(fstderr,*) "End of file marker reached while reading stats namelist in file ", &
trim( fnamelist )
end if
write(fstderr,*) "One cause is having more statistical variables ", &
"listed in the namelist for var_zt, var_zm, or ", &
"var_sfc than allowed by nvarmax_zt, nvarmax_zm, ", &
"or nvarmax_sfc, respectively."
write(fstderr,*) "Maximum variables allowed for var_zt = ", nvarmax_zt
write(fstderr,*) "Maximum variables allowed for var_zm = ", nvarmax_zm
write(fstderr,*) "Maximum variables allowed for var_rad_zt = ", nvarmax_rad_zt
write(fstderr,*) "Maximum variables allowed for var_rad_zm = ", nvarmax_rad_zm
write(fstderr,*) "Maximum variables allowed for var_sfc = ", nvarmax_sfc
write(fstderr,*) "stats_init: Error reading stats namelist."
err_code = clubb_fatal_error
close(unit=iunit)
return
end if ! read_status /= 0
close(unit=iunit)
if ( clubb_at_least_debug_level( 1 ) ) then
write(fstdout,*) "--------------------------------------------------"
write(fstdout,*) "Statistics"
write(fstdout,*) "--------------------------------------------------"
write(fstdout,*) "vars_zt = "
ivar = 1
do while ( vars_zt(ivar) /= '' )
write(fstdout,*) vars_zt(ivar)
ivar = ivar + 1
end do
write(fstdout,*) "vars_zm = "
ivar = 1
do while ( vars_zm(ivar) /= '' )
write(fstdout,*) vars_zm(ivar)
ivar = ivar + 1
end do
if ( l_silhs_out ) then
write(fstdout,*) "vars_lh_zt = "
ivar = 1
do while ( vars_lh_zt(ivar) /= '' )
write(fstdout,*) vars_lh_zt(ivar)
ivar = ivar + 1
end do
write(fstdout,*) "vars_lh_sfc = "
ivar = 1
do while ( vars_lh_sfc(ivar) /= '' )
write(fstdout,*) vars_lh_sfc(ivar)
ivar = ivar + 1
end do
end if ! l_silhs_out
if ( l_output_rad_files ) then
write(fstdout,*) "vars_rad_zt = "
ivar = 1
do while ( vars_rad_zt(ivar) /= '' )
write(fstdout,*) vars_rad_zt(ivar)
ivar = ivar + 1
end do
write(fstdout,*) "vars_rad_zm = "
ivar = 1
do while ( vars_rad_zm(ivar) /= '' )
write(fstdout,*) vars_rad_zm(ivar)
ivar = ivar + 1
end do
end if ! l_output_rad_files
write(fstdout,*) "vars_sfc = "
ivar = 1
do while ( vars_sfc(ivar) /= '' )
write(fstdout,*) vars_sfc(ivar)
ivar = ivar + 1
end do
write(fstdout,*) "--------------------------------------------------"
end if ! clubb_at_least_debug_level 1
! Determine file names for GrADS or NetCDF files
fname_zt = trim( fname_prefix )//"_zt"
fname_zm = trim( fname_prefix )//"_zm"
fname_lh_zt = trim( fname_prefix )//"_lh_zt"
fname_lh_sfc = trim( fname_prefix )//"_lh_sfc"
fname_rad_zt = trim( fname_prefix )//"_rad_zt"
fname_rad_zm = trim( fname_prefix )//"_rad_zm"
fname_sfc = trim( fname_prefix )//"_sfc"
! Parse the file type for stats output. Currently only GrADS and
! netCDF > version 3.5 are supported by this code.
select case ( trim( stats_fmt ) )
case ( "GrADS", "grads", "gr" )
l_netcdf = .false.
l_grads = .true.
case ( "NetCDF", "netcdf", "nc" )
l_netcdf = .true.
l_grads = .false.
case default
write(fstderr,*) "In module stats_clubb_utilities subroutine stats_init: "
write(fstderr,*) "Invalid stats output format "//trim( stats_fmt )
err_code = clubb_fatal_error
return
end select
! Check sampling and output frequencies
! The model time step length, delt (which is dt_main), should multiply
! evenly into the statistical sampling time step length, stats_tsamp.
if ( abs( stats_tsamp/delt - real( floor( stats_tsamp/delt ), kind=core_rknd ) ) &
> 1.e-8_core_rknd) then
l_error = .true. ! This will cause the run to stop.
write(fstderr,*) 'Error: stats_tsamp should be an even multiple of ', &
'delt (which is dt_main). Check the appropriate ', &
'model.in file.'
write(fstderr,*) 'stats_tsamp = ', stats_tsamp
write(fstderr,*) 'delt = ', delt
end if
! The statistical sampling time step length, stats_tsamp, should multiply
! evenly into the statistical output time step length, stats_tout.
if ( abs( stats_tout/stats_tsamp &
- real( floor( stats_tout/stats_tsamp ), kind=core_rknd) ) &
> 1.e-8_core_rknd) then
l_error = .true. ! This will cause the run to stop.
write(fstderr,*) 'Error: stats_tout should be an even multiple of ', &
'stats_tsamp. Check the appropriate model.in file.'
write(fstderr,*) 'stats_tout = ', stats_tout
write(fstderr,*) 'stats_tsamp = ', stats_tsamp
end if
! Initialize zt (mass points)
ivar = 1
do while ( ichar(vars_zt(ivar)(1:1)) /= 0 &
.and. len_trim(vars_zt(ivar)) /= 0 &
.and. ivar <= nvarmax_zt )
ivar = ivar + 1
end do
ntot = ivar - 1
if ( any( vars_zt == "hm_i" ) ) then
! Correct for number of variables found under "hm_i".
! Subtract "hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "mu_hm_i" ) ) then
! Correct for number of variables found under "mu_hm_i".
! Subtract "mu_hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "mu_Ncn_i" ) ) then
! Correct for number of variables found under "mu_Ncn_i".
! Subtract "mu_Ncn_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "mu_hm_i_n" ) ) then
! Correct for number of variables found under "mu_hm_i_n".
! Subtract "mu_hm_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "mu_Ncn_i_n" ) ) then
! Correct for number of variables found under "mu_Ncn_i_n".
! Subtract "mu_Ncn_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "sigma_hm_i" ) ) then
! Correct for number of variables found under "sigma_hm_i".
! Subtract "sigma_hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "sigma_Ncn_i" ) ) then
! Correct for number of variables found under "sigma_Ncn_i".
! Subtract "sigma_Ncn_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "sigma_hm_i_n" ) ) then
! Correct for number of variables found under "sigma_hm_i_n".
! Subtract "sigma_hm_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "sigma_Ncn_i_n" ) ) then
! Correct for number of variables found under "sigma_Ncn_i_n".
! Subtract "sigma_Ncn_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_w_hm_i" ) ) then
! Correct for number of variables found under "corr_w_hm_i".
! Subtract "corr_w_hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_w_Ncn_i" ) ) then
! Correct for number of variables found under "corr_w_Ncn_i".
! Subtract "corr_w_Ncn_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_chi_hm_i" ) ) then
! Correct for number of variables found under "corr_chi_hm_i".
! Subtract "corr_chi_hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_chi_Ncn_i" ) ) then
! Correct for number of variables found under "corr_chi_Ncn_i".
! Subtract "corr_chi_Ncn_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_eta_hm_i" ) ) then
! Correct for number of variables found under "corr_eta_hm_i".
! Subtract "corr_eta_hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_eta_Ncn_i" ) ) then
! Correct for number of variables found under "corr_eta_Ncn_i".
! Subtract "corr_eta_Ncn_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_Ncn_hm_i" ) ) then
! Correct for number of variables found under "corr_Ncn_hm_i".
! Subtract "corr_Ncn_hm_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_hmx_hmy_i" ) ) then
! Correct for number of variables found under "corr_hmx_hmy_i".
! Subtract "corr_hmx_hmy_i" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) multipled by the
! number of correlations of two hydrometeors, which is found by:
! (1/2) * hydromet_dim * ( hydromet_dim - 1 );
! to the number of zt statistical variables.
ntot = ntot + hydromet_dim * ( hydromet_dim - 1 )
endif
if ( any( vars_zt == "corr_w_hm_i_n" ) ) then
! Correct for number of variables found under "corr_w_hm_i_n".
! Subtract "corr_w_hm_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_w_Ncn_i_n" ) ) then
! Correct for number of variables found under "corr_w_Ncn_i_n".
! Subtract "corr_w_Ncn_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_chi_hm_i_n" ) ) then
! Correct for number of variables found under "corr_chi_hm_i_n".
! Subtract "corr_chi_hm_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_chi_Ncn_i_n" ) ) then
! Correct for number of variables found under "corr_chi_Ncn_i_n".
! Subtract "corr_chi_Ncn_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_eta_hm_i_n" ) ) then
! Correct for number of variables found under "corr_eta_hm_i_n".
! Subtract "corr_eta_hm_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_eta_Ncn_i_n" ) ) then
! Correct for number of variables found under "corr_eta_Ncn_i_n".
! Subtract "corr_eta_Ncn_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) to the number of zt
! statistical variables.
ntot = ntot + 2
endif
if ( any( vars_zt == "corr_Ncn_hm_i_n" ) ) then
! Correct for number of variables found under "corr_Ncn_hm_i_n".
! Subtract "corr_Ncn_hm_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) for each hydrometeor
! to the number of zt statistical variables.
ntot = ntot + 2 * hydromet_dim
endif
if ( any( vars_zt == "corr_hmx_hmy_i_n" ) ) then
! Correct for number of variables found under "corr_hmx_hmy_i_n".
! Subtract "corr_hmx_hmy_i_n" from the number of zt statistical variables.
ntot = ntot - 1
! Add 2 (1st PDF component and 2nd PDF component) multipled by the
! number of normal space correlations of two hydrometeors, which is
! found by: (1/2) * hydromet_dim * ( hydromet_dim - 1 );
! to the number of zt statistical variables.
ntot = ntot + hydromet_dim * ( hydromet_dim - 1 )
endif
if ( any( vars_zt == "hmp2_zt" ) ) then
! Correct for number of variables found under "hmp2_zt".
! Subtract "hmp2_zt" from the number of zt statistical variables.
ntot = ntot - 1
! Add 1 for each hydrometeor to the number of zt statistical variables.
ntot = ntot + hydromet_dim
endif
if ( any( vars_zt == "wp2hmp" ) ) then
! Correct for number of variables found under "wp2hmp".
! Subtract "wp2hmp" from the number of zt statistical variables.
ntot = ntot - 1
! Add 1 for each hydrometeor to the number of zt statistical variables.
ntot = ntot + hydromet_dim
endif
if ( any( vars_zt == "sclrm" ) ) then
! Correct for number of variables found under "sclrm".
! Subtract "sclrm" from the number of zt statistical variables.
ntot = ntot - 1
! Add 1 for each scalar to the number of zt statistical variables.
ntot = ntot + sclr_dim
endif
if ( any( vars_zt == "sclrm_f" ) ) then
! Correct for number of variables found under "sclrm_f".
! Subtract "sclrm_f" from the number of zt statistical variables.
ntot = ntot - 1
! Add 1 for each scalar to the number of zt statistical variables.
ntot = ntot + sclr_dim
endif
if ( any( vars_zt == "edsclrm" ) ) then
! Correct for number of variables found under "edsclrm".
! Subtract "edsclrm" from the number of zt statistical variables.
ntot = ntot - 1
! Add 1 for each scalar to the number of zt statistical variables.
ntot = ntot + edsclr_dim
endif
if ( any( vars_zt == "edsclrm_f" ) ) then
! Correct for number of variables found under "edsclrm_f".
! Subtract "edsclrm_f" from the number of zt statistical variables.
ntot = ntot - 1
! Add 1 for each scalar to the number of zt statistical variables.
ntot = ntot + edsclr_dim
endif
if ( ntot >= nvarmax_zt ) then
write(fstderr,*) "There are more statistical variables listed in ", &
"vars_zt than allowed for by nvarmax_zt."
write(fstderr,*) "Check the number of variables listed for vars_zt ", &
"in the stats namelist, or change nvarmax_zt."
write(fstderr,*) "nvarmax_zt = ", nvarmax_zt
write(fstderr,*) "number of variables in vars_zt = ", ntot
write(fstderr,*) "stats_init: number of zt statistical variables exceeds limit"
err_code = clubb_fatal_error
return
end if
stats_zt%num_output_fields = ntot
stats_zt%kk = nzmax
stats_zt%ii = nlon
stats_zt%jj = nlat
allocate( stats_zt%z( stats_zt%kk ) )
stats_zt%z = gzt
allocate( stats_zt%accum_field_values( stats_zt%ii, stats_zt%jj, &
stats_zt%kk, stats_zt%num_output_fields ) )
allocate( stats_zt%accum_num_samples( stats_zt%ii, stats_zt%jj, &
stats_zt%kk, stats_zt%num_output_fields ) )
allocate( stats_zt%l_in_update( stats_zt%ii, stats_zt%jj, stats_zt%kk, &
stats_zt%num_output_fields ) )
call stats_zero( stats_zt%ii, stats_zt%jj, stats_zt%kk, stats_zt%num_output_fields, &
stats_zt%accum_field_values, stats_zt%accum_num_samples, stats_zt%l_in_update )
allocate( stats_zt%file%var( stats_zt%num_output_fields ) )
allocate( stats_zt%file%z( stats_zt%kk ) )
! Allocate scratch space
allocate( ztscr01(stats_zt%kk) )
allocate( ztscr02(stats_zt%kk) )
allocate( ztscr03(stats_zt%kk) )
allocate( ztscr04(stats_zt%kk) )
allocate( ztscr05(stats_zt%kk) )
allocate( ztscr06(stats_zt%kk) )
allocate( ztscr07(stats_zt%kk) )
allocate( ztscr08(stats_zt%kk) )
allocate( ztscr09(stats_zt%kk) )
allocate( ztscr10(stats_zt%kk) )
allocate( ztscr11(stats_zt%kk) )
allocate( ztscr12(stats_zt%kk) )
allocate( ztscr13(stats_zt%kk) )
allocate( ztscr14(stats_zt%kk) )
allocate( ztscr15(stats_zt%kk) )
allocate( ztscr16(stats_zt%kk) )
allocate( ztscr17(stats_zt%kk) )
allocate( ztscr18(stats_zt%kk) )
allocate( ztscr19(stats_zt%kk) )
allocate( ztscr20(stats_zt%kk) )
allocate( ztscr21(stats_zt%kk) )
ztscr01 = 0.0_core_rknd
ztscr02 = 0.0_core_rknd
ztscr03 = 0.0_core_rknd
ztscr04 = 0.0_core_rknd
ztscr05 = 0.0_core_rknd
ztscr06 = 0.0_core_rknd
ztscr07 = 0.0_core_rknd
ztscr08 = 0.0_core_rknd
ztscr09 = 0.0_core_rknd
ztscr10 = 0.0_core_rknd
ztscr11 = 0.0_core_rknd
ztscr12 = 0.0_core_rknd
ztscr13 = 0.0_core_rknd
ztscr14 = 0.0_core_rknd
ztscr15 = 0.0_core_rknd
ztscr16 = 0.0_core_rknd
ztscr17 = 0.0_core_rknd
ztscr18 = 0.0_core_rknd
ztscr19 = 0.0_core_rknd
ztscr20 = 0.0_core_rknd
ztscr21 = 0.0_core_rknd
fname = trim( fname_zt )
if ( l_grads ) then
! Open GrADS file
call open_grads( iunit, fdir, fname, &
1, stats_zt%kk, nlat, nlon, stats_zt%z, &
day, month, year, rlat, rlon, &
time_current+real(stats_tout,kind=time_precision), stats_tout, &
stats_zt%num_output_fields, stats_zt%file )
else ! Open NetCDF file
#ifdef NETCDF
call open_netcdf_for_writing( nlat, nlon, fdir, fname, 1, stats_zt%kk, stats_zt%z, & ! In
day, month, year, rlat, rlon, & ! In
time_current, stats_tout, stats_zt%num_output_fields, & ! In
stats_zt%file ) ! InOut
if ( err_code == clubb_fatal_error ) return
#else
stop "This CLUBB program was not compiled with netCDF support."
#endif
end if
! Default initialization for array indices for zt
call stats_init_zt( vars_zt, l_error )
! Setup output file for stats_lh_zt (Latin Hypercube stats)
if ( l_silhs_out ) then
ivar = 1
do while ( ichar(vars_lh_zt(ivar)(1:1)) /= 0 &
.and. len_trim(vars_lh_zt(ivar)) /= 0 &
.and. ivar <= nvarmax_lh_zt )
ivar = ivar + 1
end do
ntot = ivar - 1
if ( any( vars_lh_zt == "silhs_variance_category" ) ) then
! Correct for number of variables found under "silhs_variance_category".
! Subtract "silhs_variance_category" from the number of lh_zt statistical
! variables.
ntot = ntot - 1
! Add 1 for each SILHS category to the number of lh_zt statistical variables
ntot = ntot + silhs_num_importance_categories
end if
if ( any( vars_lh_zt == "lh_samp_frac_category" ) ) then
! Correct for number of variables found under "lh_samp_frac_category".
! Subtract "lh_samp_frac_category" from the number of lh_zt statistical
! variables.
ntot = ntot - 1
! Add 1 for each SILHS category to the number of lh_zt statistical variables
ntot = ntot + silhs_num_importance_categories
end if
if ( ntot == nvarmax_lh_zt ) then
write(fstderr,*) "There are more statistical variables listed in ", &
"vars_lh_zt than allowed for by nvarmax_lh_zt."
write(fstderr,*) "Check the number of variables listed for vars_lh_zt ", &
"in the stats namelist, or change nvarmax_lh_zt."
write(fstderr,*) "nvarmax_lh_zt = ", nvarmax_lh_zt
write(fstderr,*) "number of variables in vars_lh_zt = ", ntot
write(fstderr,*) "stats_init: number of lh_zt statistical variables exceeds limit"
err_code = clubb_fatal_error
return
end if
stats_lh_zt%num_output_fields = ntot
stats_lh_zt%kk = nzmax
stats_lh_zt%ii = nlon
stats_lh_zt%jj = nlat
allocate( stats_lh_zt%z( stats_lh_zt%kk ) )
stats_lh_zt%z = gzt
allocate( stats_lh_zt%accum_field_values( stats_lh_zt%ii, stats_lh_zt%jj, &
stats_lh_zt%kk, stats_lh_zt%num_output_fields ) )
allocate( stats_lh_zt%accum_num_samples( stats_lh_zt%ii, stats_lh_zt%jj, &
stats_lh_zt%kk, stats_lh_zt%num_output_fields ) )
allocate( stats_lh_zt%l_in_update( stats_lh_zt%ii, stats_lh_zt%jj, stats_lh_zt%kk, &
stats_lh_zt%num_output_fields ) )
call stats_zero( stats_lh_zt%ii, stats_lh_zt%jj, stats_lh_zt%kk, &
stats_lh_zt%num_output_fields, &
stats_lh_zt%accum_field_values, stats_lh_zt%accum_num_samples, stats_lh_zt%l_in_update )
allocate( stats_lh_zt%file%var( stats_lh_zt%num_output_fields ) )
allocate( stats_lh_zt%file%z( stats_lh_zt%kk ) )
fname = trim( fname_lh_zt )
if ( l_grads ) then
! Open GrADS file
call open_grads( iunit, fdir, fname, &
1, stats_lh_zt%kk, nlat, nlon, stats_lh_zt%z, &
day, month, year, rlat, rlon, &
time_current+real(stats_tout,kind=time_precision), stats_tout, &
stats_lh_zt%num_output_fields, stats_lh_zt%file )
else ! Open NetCDF file
#ifdef NETCDF
call open_netcdf_for_writing( nlat, nlon, fdir, fname, 1, stats_lh_zt%kk, & ! In
stats_lh_zt%z, day, month, year, rlat, rlon, & ! In
time_current, stats_tout, stats_lh_zt%num_output_fields, & ! In
stats_lh_zt%file ) ! InOut
if ( err_code == clubb_fatal_error ) return
#else
stop "This CLUBB program was not compiled with netCDF support."
#endif
end if
call stats_init_lh_zt( vars_lh_zt, l_error )
ivar = 1
do while ( ichar(vars_lh_sfc(ivar)(1:1)) /= 0 &
.and. len_trim(vars_lh_sfc(ivar)) /= 0 &
.and. ivar <= nvarmax_lh_sfc )
ivar = ivar + 1
end do
ntot = ivar - 1
if ( ntot == nvarmax_lh_sfc ) then
write(fstderr,*) "There are more statistical variables listed in ", &
"vars_lh_sfc than allowed for by nvarmax_lh_sfc."
write(fstderr,*) "Check the number of variables listed for vars_lh_sfc ", &
"in the stats namelist, or change nvarmax_lh_sfc."
write(fstderr,*) "nvarmax_lh_sfc = ", nvarmax_lh_sfc
write(fstderr,*) "number of variables in vars_lh_sfc = ", ntot
write(fstderr,*) "stats_init: number of lh_sfc statistical variables exceeds limit"
err_code = clubb_fatal_error
return
end if
stats_lh_sfc%num_output_fields = ntot
stats_lh_sfc%kk = 1
stats_lh_sfc%ii = nlon
stats_lh_sfc%jj = nlat
allocate( stats_lh_sfc%z( stats_lh_sfc%kk ) )
stats_lh_sfc%z = gzm(1)
allocate( stats_lh_sfc%accum_field_values( stats_lh_sfc%ii, stats_lh_sfc%jj, &
stats_lh_sfc%kk, stats_lh_sfc%num_output_fields ) )
allocate( stats_lh_sfc%accum_num_samples( stats_lh_sfc%ii, stats_lh_sfc%jj, &
stats_lh_sfc%kk, stats_lh_sfc%num_output_fields ) )
allocate( stats_lh_sfc%l_in_update( stats_lh_sfc%ii, stats_lh_sfc%jj, &
stats_lh_sfc%kk, stats_lh_sfc%num_output_fields ) )
call stats_zero( stats_lh_sfc%ii, stats_lh_sfc%jj, stats_lh_sfc%kk, &
stats_lh_sfc%num_output_fields, stats_lh_sfc%accum_field_values, &
stats_lh_sfc%accum_num_samples, stats_lh_sfc%l_in_update )
allocate( stats_lh_sfc%file%var( stats_lh_sfc%num_output_fields ) )
allocate( stats_lh_sfc%file%z( stats_lh_sfc%kk ) )
fname = trim( fname_lh_sfc )
if ( l_grads ) then
! Open GrADS file
call open_grads( iunit, fdir, fname, &
1, stats_lh_sfc%kk, nlat, nlon, stats_lh_sfc%z, &
day, month, year, rlat, rlon, &
time_current+real(stats_tout,kind=time_precision), stats_tout, &
stats_lh_sfc%num_output_fields, stats_lh_sfc%file )
else ! Open NetCDF file
#ifdef NETCDF
call open_netcdf_for_writing( nlat, nlon, fdir, fname, 1, stats_lh_sfc%kk, & ! In
stats_lh_sfc%z, day, month, year, rlat, rlon, & ! In
time_current, stats_tout, stats_lh_sfc%num_output_fields, & ! In
stats_lh_sfc%file ) ! InOut
if ( err_code == clubb_fatal_error ) return
#else
stop "This CLUBB program was not compiled with netCDF support."
#endif
end if
call stats_init_lh_sfc( vars_lh_sfc, l_error )
end if ! l_silhs_out
! Initialize stats_zm (momentum points)
ivar = 1
do while ( ichar(vars_zm(ivar)(1:1)) /= 0 &
.and. len_trim(vars_zm(ivar)) /= 0 &
.and. ivar <= nvarmax_zm )
ivar = ivar + 1
end do
ntot = ivar - 1
if ( any( vars_zm == "hydrometp2" ) ) then
! Correct for number of variables found under "hydrometp2".
! Subtract "hydrometp2" from the number of zm statistical variables.
ntot = ntot - 1
! Add 1 for each hydrometeor to the number of zm statistical variables.
ntot = ntot + hydromet_dim
endif
if ( any( vars_zm == "wphydrometp" ) ) then
! Correct for number of variables found under "wphydrometp".
! Subtract "wphydrometp" from the number of zm statistical variables.
ntot = ntot - 1
! Add 1 for each hydrometeor to the number of zm statistical variables.
ntot = ntot + hydromet_dim
endif
if ( any( vars_zm == "rtphmp" ) ) then
! Correct for number of variables found under "rtphmp".
! Subtract "rtphmp" from the number of zm statistical variables.
ntot = ntot - 1
! Add 1 for each hydrometeor to the number of zm statistical variables.
ntot = ntot + hydromet_dim
endif
if ( any( vars_zm == "thlphmp" ) ) then
! Correct for number of variables found under "thlphmp".
! Subtract "thlphmp" from the number of zm statistical variables.
ntot = ntot - 1
! Add 1 for each hydrometeor to the number of zm statistical variables.