forked from wrf-model/WRF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_em.F
More file actions
2679 lines (2411 loc) · 127 KB
/
Copy pathstart_em.F
File metadata and controls
2679 lines (2411 loc) · 127 KB
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
!-------------------------------------------------------------------
SUBROUTINE start_domain_em ( grid, allowed_to_read &
! Actual arguments generated from Registry
# include "dummy_new_args.inc"
!
)
USE module_domain, ONLY : domain, wrfu_timeinterval, get_ijk_from_grid, &
domain_setgmtetc, get_ijk_from_subgrid
USE module_state_description
USE module_driver_constants
USE module_wrf_error
USE module_model_constants
USE module_bc, ONLY : boundary_condition_check, set_physical_bc2d, set_physical_bc3d, bdyzone
USE module_bc_em, ONLY: lbc_fcx_gcx, set_w_surface
USE module_configure, ONLY : model_to_grid_config_rec, model_config_rec, grid_config_rec_type
USE module_tiles, ONLY : set_tiles
#ifdef DM_PARALLEL
USE module_dm, ONLY : wrf_dm_min_real, wrf_dm_max_real, wrf_dm_maxval, &
ntasks_x, ntasks_y, &
local_communicator_periodic, local_communicator, mytask, ntasks
#else
USE module_dm, ONLY : wrf_dm_min_real, wrf_dm_max_real
#endif
USE module_comm_dm
USE module_llxy, ONLY : proj_cassini
USE module_physics_init
USE NoahmpGroundwaterInitMod, ONLY: NoahmpGroundwaterInitMain
USE module_lightning_driver, ONLY : lightning_init
USE module_fr_fire_driver_wrf, ONLY : fire_driver_em_init
USE module_firebrand_spotting, ONLY : firebrand_spotting_em_init
USE module_stoch, ONLY : setup_rand_perturb, rand_seed, update_stoch, initialize_stoch
USE module_trajectory, ONLY : trajectory_init
#if (WRF_CHEM == 1)
USE module_aerosols_sorgam, ONLY: sum_pm_sorgam
USE module_gocart_aerosols, ONLY: sum_pm_gocart
USE module_mosaic_driver, ONLY: sum_pm_mosaic
USE module_input_tracer, ONLY: initialize_tracer
USE module_aerosols_soa_vbs, only: sum_pm_soa_vbs
#if (WRF_USE_CLM == 1)
USE shr_megan_mod, only : wrf_spc_chk
#endif
#endif
USE module_diag_pld, ONLY : pld
USE module_diag_zld, ONLY : zld
USE module_trad_fields, ONLY : trad_fields
#ifdef WRF_CFBM
! CFBM
use initialize_mod, only : Init_fire_state_within_wrf
#endif
USE NoahmpIOVarType, only : NoahmpIOdom
!!debug
!USE module_compute_geop
USE module_model_constants
USE module_avgflx_em, ONLY : zero_avgflx
IMPLICIT NONE
! Input data.
TYPE (domain) :: grid
LOGICAL , INTENT(IN) :: allowed_to_read
! Definitions of dummy arguments to this routine (generated from Registry).
# include "dummy_new_decl.inc"
! Structure that contains run-time configuration (namelist) data for domain
TYPE (grid_config_rec_type) :: config_flags
! Local data
INTEGER :: &
ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
ips, ipe, jps, jpe, kps, kpe, &
its, ite, jts, jte, kts, kte, &
ij,i,j,k,ii,jj,kk,loop,error,l
INTEGER :: imsx, imex, jmsx, jmex, kmsx, kmex, &
ipsx, ipex, jpsx, jpex, kpsx, kpex, &
imsy, imey, jmsy, jmey, kmsy, kmey, &
ipsy, ipey, jpsy, jpey, kpsy, kpey
INTEGER :: i_m
REAL :: p_top_test, p00, t00, a, tiso, p_surf, pd_surf, temp, tiso_tmp
REAL :: p_strat, a_strat
#if (WRF_CHEM == 1)
REAL RGASUNIV ! universal gas constant [ J/mol-K ]
PARAMETER ( RGASUNIV = 8.314510 )
REAL,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33) :: &
z_at_w,convfac
REAL :: tempfac
INTEGER :: numgas
#endif
REAL :: qvf1, qvf2, qvf
REAL :: pfu, pfd, phm
REAL :: MPDT
REAL :: spongeweight
LOGICAL :: first_trip_for_this_domain, start_of_simulation, fill_w_flag
LOGICAL, EXTERNAL :: wrf_dm_on_monitor
#if (WRF_CHEM != 1)
REAL,ALLOCATABLE,DIMENSION(:,:,:) :: cldfra_old
#endif
REAL :: lat1 , lat2 , lat3 , lat4
REAL :: lon1 , lon2 , lon3 , lon4
INTEGER :: num_points_lat_lon , iloc , jloc
CHARACTER (LEN=256) :: message, a_message
TYPE(WRFU_TimeInterval) :: stepTime
REAL, DIMENSION(:,:), ALLOCATABLE :: clat_glob
logical :: f_flux ! flag for computing averaged fluxes in cu_gd
INTEGER :: idex, jdex
INTEGER :: im1,ip1,jm1,jp1
REAL :: hx,hy,pi
REAL :: w_max, w_min
LOGICAL :: w_needs_to_be_set
!
! Define variables local (topo_wind local vars)
REAL :: alpha, vfac
INTEGER :: j_save
! For a global domain
INTEGER :: alloc_status
CHARACTER (LEN=256) :: alloc_err_message
!..Need to fill special height var for setting up initial condition. G. Thompson
REAL, ALLOCATABLE, DIMENSION(:,:,:) :: z_at_q
REAL, ALLOCATABLE, DIMENSION(:,:,:) :: dz8w !mchen
! CCN for MP=18 initializatio
REAL :: ccn_max_val
REAL :: dt_s, dx_km
REAL :: max_mf, max_rot_angle
#ifdef WRF_CFBM
integer :: ifds, ifde, jfds, jfde, kfds, kfde, &
ifms, ifme, jfms, jfme, kfms, kfme, &
ifps, ifpe, jfps, jfpe, kfps, kfpe
real :: cen_lat, cen_lon, truelat1, truelat2, stand_lon
logical :: is_cfbm_initialized = .false.
#endif
CALL get_ijk_from_grid ( grid , &
ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
ips, ipe, jps, jpe, kps, kpe, &
imsx, imex, jmsx, jmex, kmsx, kmex, &
ipsx, ipex, jpsx, jpex, kpsx, kpex, &
imsy, imey, jmsy, jmey, kmsy, kmey, &
ipsy, ipey, jpsy, jpey, kpsy, kpey )
kts = kps ; kte = kpe ! note that tile is entire patch
its = ips ; ite = ipe ! note that tile is entire patch
jts = jps ; jte = jpe ! note that tile is entire patch
#if (WRF_CHEM != 1)
ALLOCATE(CLDFRA_OLD(IMS:IME,KMS:KME,JMS:JME),STAT=I) ; CLDFRA_OLD = 0.
#endif
ALLOCATE(dz8w(IMS:IME,KMS:KME,JMS:JME),STAT=I) ; dz8w = 0.
ALLOCATE(z_at_q(IMS:IME,KMS:KME,JMS:JME),STAT=I) ; z_at_q = 0.
CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
IF ( ( MOD (ide-ids,config_flags%parent_grid_ratio) .NE. 0 ) .OR. &
( MOD (jde-jds,config_flags%parent_grid_ratio) .NE. 0 ) ) THEN
WRITE(message, FMT='(A,I2,": Both MOD(",I4,"-",I1,",",I2,") and MOD(",I4,"-",I1,",",I2,") must = 0" )') &
"Nested dimensions are illegal for domain ",grid%id,ide,ids,config_flags%parent_grid_ratio,&
jde,jds,config_flags%parent_grid_ratio
CALL wrf_error_fatal ( message )
END IF
IF ( config_flags%polar ) THEN
!write(0,*)"<stdin>",__LINE__,' clat ',ips,ipe,jps,jpe
!do j = jps,jpe
!write(0,*)"<stdin>",__LINE__,' clat ',ids,j,grid%clat(ips,j)
!enddo
#ifdef DM_PARALLEL
! WARNING: this might present scaling issues on very large numbers of processors
alloc_err_message = ' '
alloc_err_message(1:12) = 'NO PROBLEMOS'
#if 0
ALLOCATE( clat_glob(ids:ide,jds:jde), STAT=alloc_status, ERRMSG=alloc_err_message )
#else
ALLOCATE( clat_glob(ids:ide,jds:jde), STAT=alloc_status)
alloc_err_message = 'Allocation of space for a global field failed.'
#endif
IF ( alloc_status .NE. 0 ) THEN
CALL wrf_message ( TRIM(alloc_err_message) )
CALL wrf_error_fatal ( 'Error allocating entire domain size of 2d array CLAT for global domain' )
END IF
CALL wrf_patch_to_global_real ( grid%clat, clat_glob, grid%domdesc, 'xy', 'xy', &
ids, ide, jds, jde, 1, 1, &
ims, ime, jms, jme, 1, 1, &
its, ite, jts, jte, 1, 1 )
CALL wrf_dm_bcast_real ( clat_glob , (ide-ids+1)*(jde-jds+1) )
grid%clat_xxx(ipsx:ipex,jpsx:jpex) = clat_glob(ipsx:ipex,jpsx:jpex)
find_j_index_of_fft_filter : DO j = jds , jde-1
IF ( ABS(clat_glob(ids,j)) .LE. config_flags%fft_filter_lat ) THEN
j_save = j
EXIT find_j_index_of_fft_filter
END IF
END DO find_j_index_of_fft_filter
CALL wrf_patch_to_global_real ( grid%msft, clat_glob, grid%domdesc, 'xy', 'xy', &
ids, ide, jds, jde, 1, 1, &
ims, ime, jms, jme, 1, 1, &
its, ite, jts, jte, 1, 1 )
CALL wrf_dm_bcast_real ( clat_glob , (ide-ids+1)*(jde-jds+1) )
grid%mf_fft = clat_glob(ids,j_save)
grid%mf_xxx(ipsx:ipex,jpsx:jpex) = clat_glob(ipsx:ipex,jpsx:jpex)
DEALLOCATE( clat_glob )
#endif
ENDIF
! here we check to see if the boundary conditions are set properly
CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
! make sure that topo_wind option has var_sso data available
IF ((config_flags%topo_wind .EQ. 1) .AND. (.NOT. grid%got_var_sso)) THEN
CALL wrf_error_fatal ("topo_wind requires VAR_SSO data")
ENDIF
!kludge - need to stop CG from resetting precip and phys tendencies to zero
! when we are in here due to a nest being spawned, we want to still
! recompute the base state, but that is about it
! This is temporary and will need to be changed when grid%itimestep is removed.
IF ( grid%itimestep .EQ. 0 ) THEN
first_trip_for_this_domain = .TRUE.
ELSE
first_trip_for_this_domain = .FALSE.
END IF
IF ( .not. ( config_flags%restart .or. grid%moved ) ) THEN
grid%itimestep=0
ENDIF
IF ( config_flags%restart .or. grid%moved .or. config_flags%cycling) THEN
first_trip_for_this_domain = .TRUE.
ENDIF
! Print out the maximum map scale factor on the coarse domain
IF ( ( first_trip_for_this_domain ) .AND. ( grid%id .EQ. 1 ) .AND. &
( .NOT. config_flags%polar ) ) THEN
max_mf = grid%msft(its,jts)
DO j=jts,MIN(jde-1,jte)
DO i=its,MIN(ide-1,ite)
max_mf = MAX ( max_mf , grid%msft(i,j) )
END DO
END DO
#if ( defined(DM_PARALLEL) && ! defined(STUBMPI) )
max_mf = wrf_dm_max_real ( max_mf )
#endif
WRITE ( a_message , FMT='(A,F5.2,A)' ) 'Max map factor in domain 1 = ',max_mf, &
'. Scale the dt in the model accordingly.'
CALL wrf_message ( a_message )
END IF
!-----------------------------------------------------------------------
! Do a gross check on the time step for the most coarse grid (not for
! adaptive time steps. If the value is significantly larger than reasonable,
! then stop immediately. Likely the user made a mistake.
! If the rule of thumb is 6 DX = DT, then anything > 10 is flagged.
! Only look at domain 1, only do this for the firt time into this routine,
! only look at real-data cases (where the map projection is not Cartesian),
! and only look at user-specified time steps (not the adaptive dt option).
!-----------------------------------------------------------------------
IF ( ( grid%id .EQ. 1 ) .AND. &
( first_trip_for_this_domain ) .AND. &
( config_flags%map_proj .NE. 0 ) .AND. &
( .NOT. config_flags%use_adaptive_time_step ) ) THEN
dt_s = REAL(config_flags%time_step) + &
REAL(config_flags%time_step_fract_num) / &
REAL(config_flags%time_step_fract_den)
dx_km = MIN ( config_flags%dx , config_flags%dy ) / 1000.
WRITE (message,*) 'D01: Time step = ',dt_s ,' (s)'
CALL wrf_message ( TRIM(message) )
WRITE (message,*) 'D01: Grid Distance = ',dx_km ,' (km)'
CALL wrf_message ( TRIM(message) )
WRITE (message,*) 'D01: Grid Distance Ratio dt/dx = ', dt_s / dx_km, ' (s/km)'
CALL wrf_message ( TRIM(message) )
WRITE (message,*) 'D01: Ratio Including Maximum Map Factor = ', dt_s / (dx_km / max_mf) , ' (s/km)'
CALL wrf_message ( TRIM(message) )
WRITE (message,*) 'D01: NML defined reasonable_time_step_ratio = ', config_flags%reasonable_time_step_ratio
CALL wrf_message ( TRIM(message) )
IF ( dt_s / dx_km > config_flags%reasonable_time_step_ratio ) THEN
CALL wrf_message ( 'The time step is probably too large for this grid distance, reduce it.' )
WRITE (message, * ) 'If you are sure of your settings, set reasonable_time_step_ratio in namelist.input > ' &
,dt_s / (dx_km / max_mf)
CALL wrf_message ( TRIM(message) )
CALL wrf_error_fatal ( '--- ERROR: Time step too large')
END IF
END IF
if(config_flags%cycling) then
! Clear the buckets for diagnostics at initial time
DO j = jts,min(jte,jde-1)
DO i = its, min(ite,ide-1)
grid%prec_acc_nc(i,j) = 0.
grid%snow_acc_nc(i,j) = 0.
grid%sfcrunoff (i,j) = 0.
grid%udrunoff (i,j) = 0.
! acsnow, and acrunoff are run-total
grid%acrunoff (i,j) = 0.
grid%acsnow (i,j) = 0.
ENDDO
ENDDO
endif
! --- SETUP AND INITIALIZE STOCHASTIC PERTURBATION SCHEMES ---
IF ( grid%itimestep .EQ. 0 ) THEN
first_trip_for_this_domain = .TRUE.
ELSE
first_trip_for_this_domain = .FALSE.
END IF
IF ( .not. ( config_flags%restart .or. grid%moved .or. config_flags%hrrr_cycling) ) THEN
grid%itimestep=0
ENDIF
IF ( config_flags%restart .or. grid%moved .or. config_flags%hrrr_cycling) THEN
first_trip_for_this_domain = .TRUE.
ENDIF
CALL INITIALIZE_STOCH (grid, config_flags, &
first_trip_for_this_domain, &
ips, ipe, jps, jpe, kps, kpe, &
ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
its, ite, jts, jte, kts, kte, &
imsx, imex, jmsx, jmex, kmsx, kmex, &
ipsx, ipex, jpsx, jpex, kpsx, kpex, &
imsy, imey, jmsy, jmey, kmsy, kmey, &
ipsy, ipey, jpsy, jpey, kpsy, kpey )
! --- END SETUP STOCHASTIC PERTURBATION SCHEMES ----------
! wig: Add a combined exponential+linear weight on the mother boundaries
! following code changes by Ruby Leung. For the nested grid, there
! appears to be some problems when a sponge is used. The points where
! processors meet have problematic values.
CALL lbc_fcx_gcx ( grid%fcx , grid%gcx , grid%spec_bdy_width , &
grid%spec_zone , grid%relax_zone , grid%dt , config_flags%spec_exp , &
config_flags%specified , config_flags%nested )
IF ( config_flags%nested ) THEN
grid%dtbc = 0.
ENDIF
IF ( ( grid%id .NE. 1 ) .AND. ( .NOT. config_flags%input_from_file ) ) THEN
! Every time a domain starts or every time a domain moves, this routine is called. We want
! the center (middle) lat/lon of the grid for the metacode. The lat/lon values are
! defined at mass points. Depending on the even/odd points in the SN and WE directions,
! we end up with the middle point as either 1 point or an average of either 2 or 4 points.
! Add to this, the need to make sure that we are on the correct patch to retrieve the
! value of the lat/lon, AND that the lat/lons (for an average) may not all be on the same
! patch. Once we find the correct value for lat lon, we need to keep it around on all patches,
! which is where the wrf_dm_min_real calls come in.
! If this is the most coarse domain, we do not go in here. Also, if there is an input file
! (which has the right values for the middle lat/lon) we do not go in this IF test.
IF ( ( MOD(ide,2) .EQ. 0 ) .AND. ( MOD(jde,2) .EQ. 0 ) ) THEN
num_points_lat_lon = 1
iloc = ide/2
jloc = jde/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat1 = grid%xlat (iloc,jloc)
lon1 = grid%xlong(iloc,jloc)
ELSE
lat1 = 99999.
lon1 = 99999.
END IF
lat1 = wrf_dm_min_real ( lat1 )
lon1 = wrf_dm_min_real ( lon1 )
CALL nl_set_cen_lat ( grid%id , lat1 )
CALL nl_set_cen_lon ( grid%id , lon1 )
ELSE IF ( ( MOD(ide,2) .NE. 0 ) .AND. ( MOD(jde,2) .EQ. 0 ) ) THEN
num_points_lat_lon = 2
iloc = (ide-1)/2
jloc = jde /2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat1 = grid%xlat (iloc,jloc)
lon1 = grid%xlong(iloc,jloc)
ELSE
lat1 = 99999.
lon1 = 99999.
END IF
lat1 = wrf_dm_min_real ( lat1 )
lon1 = wrf_dm_min_real ( lon1 )
iloc = (ide+1)/2
jloc = jde /2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat2 = grid%xlat (iloc,jloc)
lon2 = grid%xlong(iloc,jloc)
ELSE
lat2 = 99999.
lon2 = 99999.
END IF
lat2 = wrf_dm_min_real ( lat2 )
lon2 = wrf_dm_min_real ( lon2 )
CALL nl_set_cen_lat ( grid%id , ( lat1 + lat2 ) * 0.50 )
CALL nl_set_cen_lon ( grid%id , ( lon1 + lon2 ) * 0.50 )
ELSE IF ( ( MOD(ide,2) .EQ. 0 ) .AND. ( MOD(jde,2) .NE. 0 ) ) THEN
num_points_lat_lon = 2
iloc = ide /2
jloc = (jde-1)/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat1 = grid%xlat (iloc,jloc)
lon1 = grid%xlong(iloc,jloc)
ELSE
lat1 = 99999.
lon1 = 99999.
END IF
lat1 = wrf_dm_min_real ( lat1 )
lon1 = wrf_dm_min_real ( lon1 )
iloc = ide /2
jloc = (jde+1)/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat2 = grid%xlat (iloc,jloc)
lon2 = grid%xlong(iloc,jloc)
ELSE
lat2 = 99999.
lon2 = 99999.
END IF
lat2 = wrf_dm_min_real ( lat2 )
lon2 = wrf_dm_min_real ( lon2 )
CALL nl_set_cen_lat ( grid%id , ( lat1 + lat2 ) * 0.50 )
CALL nl_set_cen_lon ( grid%id , ( lon1 + lon2 ) * 0.50 )
ELSE IF ( ( MOD(ide,2) .NE. 0 ) .AND. ( MOD(jde,2) .NE. 0 ) ) THEN
num_points_lat_lon = 4
iloc = (ide-1)/2
jloc = (jde-1)/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat1 = grid%xlat (iloc,jloc)
lon1 = grid%xlong(iloc,jloc)
ELSE
lat1 = 99999.
lon1 = 99999.
END IF
lat1 = wrf_dm_min_real ( lat1 )
lon1 = wrf_dm_min_real ( lon1 )
iloc = (ide+1)/2
jloc = (jde-1)/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat2 = grid%xlat (iloc,jloc)
lon2 = grid%xlong(iloc,jloc)
ELSE
lat2 = 99999.
lon2 = 99999.
END IF
lat2 = wrf_dm_min_real ( lat2 )
lon2 = wrf_dm_min_real ( lon2 )
iloc = (ide-1)/2
jloc = (jde+1)/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat3 = grid%xlat (iloc,jloc)
lon3 = grid%xlong(iloc,jloc)
ELSE
lat3 = 99999.
lon3 = 99999.
END IF
lat3 = wrf_dm_min_real ( lat3 )
lon3 = wrf_dm_min_real ( lon3 )
iloc = (ide+1)/2
jloc = (jde+1)/2
IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
lat4 = grid%xlat (iloc,jloc)
lon4 = grid%xlong(iloc,jloc)
ELSE
lat4 = 99999.
lon4 = 99999.
END IF
lat4 = wrf_dm_min_real ( lat4 )
lon4 = wrf_dm_min_real ( lon4 )
CALL nl_set_cen_lat ( grid%id , ( lat1 + lat2 + lat3 + lat4 ) * 0.25 )
CALL nl_set_cen_lon ( grid%id , ( lon1 + lon2 + lon3 + lon4 ) * 0.25 )
END IF
END IF
! Make sure that the base-state vales have not changed between what is in the input file
! and the namelist file.
IF ( .NOT. grid%this_is_an_ideal_run ) THEN
CALL nl_get_p_top_requested ( 1 , p_top_test )
IF ( grid%p_top .NE. p_top_test ) THEN
CALL wrf_error_fatal ( 'start_em: p_top from the namelist does not match p_top from the input file.' )
END IF
END IF
IF ( config_flags%use_baseparam_fr_nml ) then
CALL nl_get_base_pres ( 1 , p00 )
CALL nl_get_base_temp ( 1 , t00 )
CALL nl_get_base_lapse ( 1 , a )
CALL nl_get_iso_temp ( 1 , tiso )
CALL nl_get_base_lapse_strat ( 1 , a_strat )
CALL nl_get_base_pres_strat ( 1 , p_strat )
IF ( ( t00 .LT. 100. .or. p00 .LT. 10000.) .AND. ( .NOT. grid%this_is_an_ideal_run ) ) THEN
WRITE(wrf_err_message,*) 'start_em: BAD BASE STATE for T00 or P00 in namelist.input file'
CALL wrf_error_fatal(TRIM(wrf_err_message))
END IF
ELSE
! get these constants from model data
t00 = grid%t00
p00 = grid%p00
a = grid%tlp
tiso = grid%tiso
a_strat = grid%tlp_strat
p_strat = grid%p_strat
IF ( ( t00 .LT. 100. .or. p00 .LT. 10000.) .AND. ( .NOT. grid%this_is_an_ideal_run ) ) THEN
WRITE(wrf_err_message,*)&
'start_em: did not find base state parameters in wrfinput. Add use_baseparam_fr_nml = .t. in &dynamics and rerun'
CALL wrf_error_fatal(TRIM(wrf_err_message))
ENDIF
ENDIF
! check if tiso in the input file agrees with namelist value
CALL nl_get_iso_temp ( 1 , tiso_tmp )
IF ( ( tiso_tmp .NE. tiso ) .AND. ( .NOT. grid%this_is_an_ideal_run ) ) THEN
WRITE(wrf_err_message,*)&
'start_em: namelist iso_temp is not equal to iso_temp in wrfinput. Reset nml value and rerun'
CALL wrf_error_fatal(TRIM(wrf_err_message))
ENDIF
IF ( .NOT. config_flags%restart .AND. &
(( config_flags%input_from_hires ) .OR. ( config_flags%input_from_file ))) THEN
IF ( config_flags%map_proj .EQ. 0 ) THEN
CALL wrf_error_fatal ( 'start_domain: Idealized case cannot have a separate nested input file' )
END IF
! Base state potential temperature and inverse density (alpha = 1/rho) from
! the half eta levels and the base-profile surface pressure. Compute 1/rho
! from equation of state. The potential temperature is a perturbation from t0.
IF ( grid%c1f(1) .NE. 1. ) THEN
CALL wrf_debug ( 0 , '---- WARNING : Maybe old non-HVC input, setting default 1d array values for TF' )
IF ( grid%hybrid_opt .NE. 0 ) THEN
CALL wrf_error_fatal ( '---- Error : Cannot use old input and try to use hybrid vertical coordinate option' )
END IF
DO k = 1, kte
grid%c1f(k) = 1.
grid%c2f(k) = 0.
grid%c3f(k) = grid%znw(k)
grid%c4f(k) = 0.
grid%c1h(k) = 1.
grid%c2h(k) = 0.
grid%c3h(k) = grid%znu(k)
grid%c4h(k) = 0.
END DO
END IF
! With newer versions of WRF, the grid%t_2 field might come in as "zero"
! from an older data set. Yikes, but it can be corrected unless the user
! has requested moist theta.
IF ( grid%t_2(its,kte-1,jts) .EQ. 0. ) THEN
CALL wrf_debug ( 0 , '---- WARNING : Older v3 input data detected' )
IF ( grid%use_theta_m .NE. 0 ) THEN
CALL wrf_error_fatal ( '---- Error : Cannot use moist theta option with old data' )
END IF
DO j = jts, MIN(jte,jde-1)
DO k = 1, kte-1
DO i = its, MIN(ite,ide-1)
grid%t_2(i,k,j) = grid%th_phy_m_t0(i,k,j)
END DO
END DO
END DO
END IF
DO j = jts, MIN(jte,jde-1)
DO i = its, MIN(ite,ide-1)
! Base state pressure is a function of eta level and terrain, only, plus
! the hand full of constants: p00 (sea level pressure, Pa), t00 (sea level
! temperature, K), A (temperature difference, from 1000 mb to 300 mb, K),
! tiso (isothermal temperature at tropopause/lower stratosphere),
! p_strat (pressure at top of isothermal layer), A_strat (lapse rate in
! stratosphere above isothermal layer)
p_surf = p00 * EXP ( -t00/a + ( (t00/a)**2 - 2.*g*grid%ht(i,j)/a/r_d ) **0.5 )
DO k = 1, kte-1
grid%pb(i,k,j) = grid%c3h(k)*(p_surf - grid%p_top) + grid%c4h(k) + grid%p_top
temp = MAX ( tiso, t00 + A*LOG(grid%pb(i,k,j)/p00) )
IF ( grid%pb(i,k,j) .LT. p_strat ) THEN
temp = tiso + A_strat * LOG ( grid%pb(i,k,j)/p_strat )
ENDIF
grid%t_init(i,k,j) = temp*(p00/grid%pb(i,k,j))**(r_d/cp) - t0
grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
END DO
! Base state mu is defined as base state surface pressure minus grid%p_top
grid%MUB(i,j) = p_surf - grid%p_top
! Integrate base geopotential, starting at terrain elevation. This assures that
! the base state is in exact hydrostatic balance with respect to the model equations.
! This field is on full levels.
grid%phb(i,1,j) = grid%ht(i,j) * g
IF ( config_flags%hypsometric_opt .EQ. 1 ) THEN
DO kk = 2,kte
k = kk - 1
grid%phb(i,kk,j) = grid%phb(i,kk-1,j) - grid%dnw(kk-1)*(grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))*grid%alb(i,kk-1,j)
END DO
ELSE IF ( config_flags%hypsometric_opt .EQ. 2 ) THEN
DO k = 2,kte
pfu = grid%c3f(k )*grid%MUB(i,j) + grid%c4f(k ) + grid%p_top
pfd = grid%c3f(k-1)*grid%MUB(i,j) + grid%c4f(k-1) + grid%p_top
phm = grid%c3h(k-1)*grid%MUB(i,j) + grid%c4h(k-1) + grid%p_top
grid%phb(i,k,j) = grid%phb(i,k-1,j) + grid%alb(i,k-1,j)*phm*LOG(pfd/pfu)
END DO
END IF
END DO
END DO
ENDIF
IF(.not.config_flags%restart)THEN
! if this is for a nested domain, the defined/interpolated fields are the _2
IF ( first_trip_for_this_domain ) THEN
! data that is expected to be zero must be explicitly initialized as such
! grid%h_diabatic = 0.
DO j = jts,min(jte,jde-1)
DO k = kts,kte-1
DO i = its, min(ite,ide-1)
IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
grid%t_1(i,k,j)=grid%t_2(i,k,j)
ENDIF
ENDDO
ENDDO
ENDDO
DO j = jts,min(jte,jde-1)
DO k = kts,kte
DO i = its, min(ite,ide-1)
grid%ph_1(i,k,j)=grid%ph_2(i,k,j)
ENDDO
ENDDO
ENDDO
DO j = jts,min(jte,jde-1)
DO i = its, min(ite,ide-1)
IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
grid%MU_1(i,j)=grid%MU_2(i,j)
ENDIF
ENDDO
ENDDO
END IF
! reconstitute base-state fields
IF(config_flags%max_dom .EQ. 1)THEN
! with single domain, grid%t_init from wrfinput is OK to use
DO j = jts,min(jte,jde-1)
DO k = kts,kte-1
DO i = its, min(ite,ide-1)
IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
grid%pb(i,k,j) = grid%c3h(k )*grid%MUB(i,j) + grid%c4h(k ) + grid%p_top
grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
ENDIF
ENDDO
ENDDO
ENDDO
ELSE ! there is more than 1 domain
IF ( .NOT. grid%this_is_an_ideal_run ) THEN ! this is a real run
DO j = jts,min(jte,jde-1)
DO k = kts,kte-1
DO i = its, min(ite,ide-1)
IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
grid%pb(i,k,j) = grid%c3h(k )*grid%MUB(i,j) + grid%c4h(k ) + grid%p_top
temp = MAX ( tiso, t00 + A*LOG(grid%pb(i,k,j)/p00) )
IF ( grid%pb(i,k,j) .LT. p_strat ) THEN
temp = tiso + A_strat * LOG ( grid%pb(i,k,j)/p_strat )
ENDIF
grid%t_init(i,k,j) = temp*(p00/grid%pb(i,k,j))**(r_d/cp) - t0
grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
ENDIF
ENDDO
ENDDO
ENDDO
!Note that rebalance must be set to 1 for vertical nesting
IF ( config_flags%rebalance .EQ. 1 ) THEN
! Integrate base geopotential, starting at terrain elevation. This assures that
! the base state is in exact hydrostatic balance with respect to the model equations.
! This field is on full levels.
DO j = jts,min(jte,jde-1)
DO i = its, min(ite,ide-1)
grid%phb(i,1,j) = grid%ht(i,j) * g
IF ( config_flags%hypsometric_opt .EQ. 1 ) THEN
DO kk = 2,kte
k = kk - 1
grid%phb(i,kk,j) = grid%phb(i,kk-1,j) - grid%dnw(kk-1)*(grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))*grid%alb(i,kk-1,j)
END DO
ELSE IF ( config_flags%hypsometric_opt .EQ. 2 ) THEN
DO k = 2,kte
pfu = grid%c3f(k )*grid%MUB(i,j) + grid%c4f(k ) + grid%p_top
pfd = grid%c3f(k-1)*grid%MUB(i,j) + grid%c4f(k-1) + grid%p_top
phm = grid%c3h(k-1)*grid%MUB(i,j) + grid%c4h(k-1) + grid%p_top
grid%phb(i,k,j) = grid%phb(i,k-1,j) + grid%alb(i,k-1,j)*phm*LOG(pfd/pfu)
END DO
ENDIF
ENDDO
ENDDO
END IF
ELSE
IF ( config_flags%ideal_init_method .EQ. 1 ) THEN
DO j = jts,min(jte,jde-1)
DO k = kts,kte-1
DO i = its, min(ite,ide-1)
IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
grid%pb(i,k,j) = grid%c3h(k )*grid%MUB(i,j) + grid%c4h(k ) + grid%p_top
grid%alb(i,k,j) = -grid%rdnw(k)*(grid%phb(i,k+1,j)-grid%phb(i,k,j))/(grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))
grid%t_init(i,k,j) = grid%alb(i,k,j)*(p1000mb/r_d)/((grid%pb(i,k,j)/p1000mb)**cvpm) - t0
ENDIF
ENDDO
ENDDO
ENDDO
ELSE IF ( config_flags%ideal_init_method .EQ. 2 ) THEN
DO j = jts,min(jte,jde-1)
DO k = kts,kte-1
DO i = its, min(ite,ide-1)
IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
grid%pb(i,k,j) = grid%c3h(k )*grid%MUB(i,j) + grid%c4h(k ) + grid%p_top
grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
ENDIF
ENDDO
ENDDO
ENDDO
! Integrate base geopotential, starting at terrain elevation. This assures that
! the base state is in exact hydrostatic balance with respect to the model equations.
! This field is on full levels.
DO j = jts,min(jte,jde-1)
DO i = its, min(ite,ide-1)
grid%phb(i,1,j) = grid%ht(i,j) * g
DO kk = 2,kte
k = kk - 1
grid%phb(i,kk,j) = grid%phb(i,kk-1,j) - grid%dnw(kk-1)*(grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))*grid%alb(i,kk-1,j)
END DO
ENDDO
ENDDO
END IF ! end if initialization for ideal, use method 1 or 2
END IF ! end if this is a real or ideal run
END IF ! end if there is more than 1 domain
!------base state is finished, perturbation values are recalculated below-----
! For the HRRR application, we want to go through this rebalancing. They
! have a clunky way of testig on this, but it is operational, so no need to
! cause them troubles.
IF ( ( grid%dfi_opt .EQ. DFI_NODFI ) .and. ( config_flags%cycling ) ) THEN
call rebalance_driver_cycl (grid )
DO j = jts,min(jte,jde-1)
DO k = kts,kte
DO i = its, min(ite,ide-1)
grid%ph_1(i,k,j)=grid%ph_2(i,k,j)
ENDDO
ENDDO
ENDDO
! Everyone else runs thorugh here. NOTE that we might also want to call the
! rebalancing ourselves for different set ups. It does not impact HRRR, so
! it is an easy decision.
ELSE
! We request rebalancing for vertical grid nesting, or when the user asks for rebalancing.
! (Note that rebalance now must be set to 1 for vertical nesting)
! Rebalance recomputes 1/rho, p, ph_2, ph0, p_hyd
IF ( config_flags%rebalance .EQ. 1 ) THEN
call rebalance_driver_cycl (grid )
DO j = jts,min(jte,jde-1)
DO k = kts,kte
DO i = its, min(ite,ide-1)
grid%ph_1(i,k,j)=grid%ph_2(i,k,j)
ENDDO
ENDDO
ENDDO
END IF
! Use equations from calc_p_rho_phi to derive p and al from ph: linear in log p
IF ( config_flags%hypsometric_opt .EQ. 1 ) THEN
DO j=jts,min(jte,jde-1)
DO k=kts,kte-1
DO i=its,min(ite,ide-1)
grid%al(i,k,j)=-1./((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mu_1(i,j)))*(grid%alb(i,k,j)*(grid%c1h(k)*grid%mu_1(i,j)) &
+grid%rdnw(k)*(grid%ph_1(i,k+1,j)-grid%ph_1(i,k,j)))
ENDDO
ENDDO
ENDDO
ELSE IF ( config_flags%hypsometric_opt .EQ. 2 ) THEN
DO j=jts,min(jte,jde-1)
DO k=kts,kte-1
DO i=its,min(ite,ide-1)
pfu = grid%c3f(k+1)*(grid%MUB(i,j)+grid%MU_1(i,j)) + grid%c4f(k+1) + grid%p_top
pfd = grid%c3f(k )*(grid%MUB(i,j)+grid%MU_1(i,j)) + grid%c4f(k ) + grid%p_top
phm = grid%c3h(k )*(grid%MUB(i,j)+grid%MU_1(i,j)) + grid%c4h(k ) + grid%p_top
grid%al(i,k,j) = (grid%ph_1(i,k+1,j)-grid%ph_1(i,k,j)+grid%phb(i,k+1,j)-grid%phb(i,k,j)) &
/phm/LOG(pfd/pfu)-grid%alb(i,k,j)
ENDDO
ENDDO
ENDDO
END IF ! which hypsometric option
DO j=jts,min(jte,jde-1)
DO k=kts,kte-1
DO i=its,min(ite,ide-1)
#if ( WRFPLUS == 1 )
IF ( .NOT. config_flags%var4d_run ) THEN
IF ( config_flags%use_theta_m == 0 ) THEN
qvf = 1.+rvovrd*moist(i,k,j,P_QV)
ELSE
qvf = 1
END IF
grid%p(i,k,j)=p1000mb*( (r_d*(t0+grid%t_1(i,k,j))*qvf)/ &
(p1000mb*(grid%al(i,k,j)+grid%alb(i,k,j))) )**cpovcv &
-grid%pb(i,k,j)
END IF
#else
IF ( config_flags%use_theta_m == 0 ) THEN
qvf = 1.+rvovrd*moist(i,k,j,P_QV)
ELSE
qvf = 1
END IF
grid%p(i,k,j)=p1000mb*( (r_d*(t0+grid%t_1(i,k,j))*qvf)/ &
(p1000mb*(grid%al(i,k,j)+grid%alb(i,k,j))) )**cpovcv &
-grid%pb(i,k,j)
#endif
grid%p_hyd(i,k,j) = grid%p(i,k,j) + grid%pb(i,k,j)
grid%alt(i,k,j) = grid%al(i,k,j) + grid%alb(i,k,j)
ENDDO
ENDDO
ENDDO
ENDIF ! Various rebalancing options
IF ( .NOT. grid%this_is_an_ideal_run ) THEN
DO j=jts,min(jte,jde-1)
DO i=its,min(ite,ide-1)
p_surf = p00 * EXP ( -t00/a + ( (t00/a)**2 - 2.*g*grid%ht(i,j)/a/r_d ) **0.5 )
grid%p_hyd_w(i,1,j) = grid%p(i,1,j) + grid%c3f(1)*(p_surf - grid%p_top) + grid%c4f(1) + grid%p_top
DO k=kts+1,kte
grid%p_hyd_w(i,k,j) = ( 2.*(grid%p(i,k-1,j)+grid%pb(i,k-1,j)) - grid%p_hyd_w(i,k-1,j) )
ENDDO
ENDDO
ENDDO
ELSE
DO j=jts,min(jte,jde-1)
DO i=its,min(ite,ide-1)
p_surf = grid%MUB(i,j)+grid%p_top
grid%p_hyd_w(i,1,j) = grid%p(i,1,j) + grid%c3f(1)*(p_surf - grid%p_top) + grid%c4f(1) + grid%p_top
DO k=kts+1,kte
grid%p_hyd_w(i,k,j) = ( 2.*(grid%p(i,k-1,j)+grid%pb(i,k-1,j)) - grid%p_hyd_w(i,k-1,j) )
ENDDO
ENDDO
ENDDO
END IF
ENDIF ! first trip for this domain
DO j=jts,min(jte,jde-1)
DO k = kts,kte
DO i = its, min(ite,ide-1)
z_at_q(i,k,j)=(grid%ph_2(i,k,j)+grid%phb(i,k,j))/g
ENDDO
ENDDO
ENDDO
IF ( grid%press_adj .and. ( grid%id .NE. 1 ) .AND. .NOT. ( config_flags%restart ) .AND. &
( ( config_flags%input_from_hires ) .OR. ( config_flags%input_from_file ) ) ) THEN
DO j = jts, MIN(jte,jde-1)
DO i = its, MIN(ite,ide-1)
grid%MU_2(i,j) = grid%MU_2(i,j) + grid%al(i,1,j) / ( grid%alt(i,1,j) * grid%alb(i,1,j) ) * &
g * ( grid%ht(i,j) - grid%ht_fine(i,j) )
END DO
END DO
DO j = jts,min(jte,jde-1)
DO i = its, min(ite,ide-1)
grid%MU_1(i,j)=grid%MU_2(i,j)
ENDDO
ENDDO
END IF
! set GMT outside of phy_init because phy_init may not be called on this
! process if, for example, it is a moving nest and if this part of the domain is not
! being initialized (not the leading edge).
CALL domain_setgmtetc( grid, start_of_simulation )
IF ( first_trip_for_this_domain ) THEN
CALL wrf_debug ( 100 , 'start_domain_em: Before call to phy_init' )
! namelist MPDT does not exist yet, so set it here
! MPDT is the call frequency for microphysics in minutes (0 means every step)
MPDT = 0.
IF(config_flags%cycling) THEN
start_of_simulation = .true.
! print *,'cycling, start_of_simulation -->',config_flags%cycling, start_of_simulation
grid%xtime=0.
! print *,'xtime=',grid%xtime
ENDIF
!-----------------------------------------------------------------------------
! Adaptive time step: Added by T. Hutchinson, WSI 11/6/07
!
!
IF ( ( grid%use_adaptive_time_step ) .AND. &
( ( grid%dfi_opt .EQ. DFI_NODFI ) .OR. ( grid%dfi_stage .EQ. DFI_FST ) ) ) THEN
! Calculate any variables that were not set
!BPR BEGIN
! This subroutine is called more than once at the first time step for a
! given domain. The following if statement is to prevent the code in
! the if statement from executing more than once per domain at the
! beginning of the model run (since last_step_update=-1 the first time
! this is reached and should be =0 after this).
! Without this if statement, when this code was executed for the second
! time it can result in grid%dt being set incorrectly.
! -This is because grid%dt will be set equal to grid%starting_time_step
! which ignores a possible denominator in the starting time step.
! -The first time this code is reached is also does this, but then the
! call to adapt_timestep correct this
! -Subsequent times this code is reached adapt_timestep will not correct
! this because it will recognize that it has already been executed for
! this timestep and exit out before doing the calculation.
if (grid%last_step_updated .NE. grid%itimestep) then
if (grid%starting_time_step == -1) then
grid%starting_time_step = NINT(4 * MIN(grid%dx,grid%dy) / 1000)
endif
grid%time_step = grid%starting_time_step
config_flags%time_step = grid%starting_time_step
model_config_rec%time_step = grid%starting_time_step
if (grid%max_time_step == -1) then
grid%max_time_step = NINT(8 * MIN(grid%dx,grid%dy) / 1000)
endif
if (grid%min_time_step == -1) then
grid%min_time_step = NINT(3 * MIN(grid%dx,grid%dy) / 1000)
endif
! Set a starting timestep.
grid%dt = grid%starting_time_step
! Initialize max cfl values
grid%last_max_vert_cfl = 0
grid%last_max_horiz_cfl = 0
! Check to assure that time_step_sound is to be dynamically set.
CALL nl_set_time_step_sound ( 1 , 0 )
grid%time_step_sound = 0
grid%max_msftx=MAXVAL(grid%msftx)
grid%max_msfty=MAXVAL(grid%msfty)
#ifdef DM_PARALLEL
CALL wrf_dm_maxval(grid%max_msftx, idex, jdex)
CALL wrf_dm_maxval(grid%max_msfty, idex, jdex)
#endif
end if
!BPR END
! This first call just initializes variables.
! If a restart, get initialized variables from restart file
IF ( .NOT. ( config_flags%restart ) ) then
CALL adapt_timestep(grid, config_flags)
END IF