-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_initialize_quarter_ss.F
More file actions
1788 lines (1443 loc) · 54.8 KB
/
module_initialize_quarter_ss.F
File metadata and controls
1788 lines (1443 loc) · 54.8 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
! for GSD version of WRF 3.8
!IDEAL:MODEL_LAYER:INITIALIZATION
#if ( HYBRID_COORD==1 )
# define gridmu_1(...) (grid%c1h(k)*XXPC1HXX(__VA_ARGS__))
# define XXPC1HXX(...) grid%mu_1(__VA_ARGS__)
# define gridMu_1(...) (grid%c1f(k)*XXPC1FXX(__VA_ARGS__))
# define XXPC1FXX(...) grid%Mu_1(__VA_ARGS__)
# define gridmub(...) (grid%c1h(k)*XXPCBHXX(__VA_ARGS__)+grid%c2h(k))
# define XXPCBHXX(...) grid%mub(__VA_ARGS__)
# define gridMub(...) (grid%c1f(k)*XXPCBFXX(__VA_ARGS__)+grid%c2f(k))
# define XXPCBFXX(...) grid%Mub(__VA_ARGS__)
#endif
!
! This MODULE holds the routines which are used to perform various initializations
! for the individual domains.
! This MODULE CONTAINS the following routines:
! initialize_field_test - 1. Set different fields to different constant
! values. This is only a test. If the correct
! domain is not found (based upon the "id")
! then a fatal error is issued.
!-----------------------------------------------------------------------
MODULE module_initialize_ideal
USE module_domain
USE module_io_domain
USE module_state_description
USE module_model_constants
USE module_bc
USE module_timing
USE module_configure
USE module_init_utilities
USE module_soil_pre
#ifdef DM_PARALLEL
USE module_dm
#endif
private rndnum
real, private :: ugrid = 0.0 ! east-west grid motion (subtracted from U wind component)
real, private :: vgrid = 0.0 ! north-south grid motion (subtracted from V wind component)
logical :: use_snd_plevels = .false. ! whether to read in pressure from the sounding file and use the same levels
logical :: use_snd_zlevels = .false. ! whether to use Z levels the sounding file and create pressure
integer :: config_stretch_z = 0 ! 0 for 'equal spacing', 1 for geometric stretch
real :: p_surface = 100000.
real :: qv_surface = 14.
real :: th_surface = 300.
CONTAINS
!-------------------------------------------------------------------
! this is a wrapper for the solver-specific init_domain routines.
! Also dereferences the grid variables and passes them down as arguments.
! This is crucial, since the lower level routines may do message passing
! and this will get fouled up on machines that insist on passing down
! copies of assumed-shape arrays (by passing down as arguments, the
! data are treated as assumed-size -- ie. f77 -- arrays and the copying
! business is avoided). Fie on the F90 designers. Fie and a pox.
SUBROUTINE init_domain ( grid )
IMPLICIT NONE
! Input data.
TYPE (domain), POINTER :: grid
! Local data.
INTEGER :: idum1, idum2
write(0,*) 'Begin init_domain'
CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
CALL init_domain_rk( grid &
!
#include "actual_new_args.inc"
!
)
write(0,*) 'End init_domain'
END SUBROUTINE init_domain
!-------------------------------------------------------------------
SUBROUTINE init_domain_rk ( grid &
!
# include "dummy_new_args.inc"
!
)
USE module_optional_input
IMPLICIT NONE
! Input data.
TYPE (domain), POINTER :: grid
# include "dummy_new_decl.inc"
TYPE (grid_config_rec_type) :: config_flags
! Local data
INTEGER :: &
ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
its, ite, jts, jte, kts, kte, &
i, j, k, n
! Local data
INTEGER, PARAMETER :: nl_max = 1000
REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in, etal, etaltmp,p_z
REAL, DIMENSION(nl_max) :: alttde
REAL :: tmp_v_1, tmp_v_2, tmp_1, tmp_2
INTEGER :: nl_in , icount
INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid
INTEGER :: nxc=-1, nyc=-1
REAL :: delt = 3.
real :: pres, qvs, rh, qvs1
real :: zradbub = 1500.
real :: xradbub = 10000.
real :: yradbub = 10000.
logical :: use_eta_levels = .false.
integer, parameter :: maxbub = 10
integer :: numbub = 1
integer :: nxb(maxbub) = -1 , nyb(maxbub) = -1
logical :: setccn = .false.
integer :: istat
REAL :: u_mean,v_mean, f0, p_surf, p_level, qvf, z_at_v, z_at_u
REAL :: z_scale, xrad, yrad, zrad, rad, cof1, cof2
! REAL, EXTERNAL :: interp_0
REAL :: hm
REAL :: pi, rnd
! stuff from original initialization that has been dropped from the Registry
REAL :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
REAL :: qvf1, qvf2, pd_surf, theta_surf
INTEGER :: it
real :: thtmp, ptmp, tem, temp(3)
LOGICAL :: moisture_init
LOGICAL :: stretch_grid, dry_sounding
logical :: moisten = .false.
REAL :: B1, B2, B3, B4, B5, sin_arg
! soil input
INTEGER :: ns_input
REAL :: tmn_input, tsk_input
REAL :: zs_input(100),tslb_input(100),smois_input(100)
REAL :: zrwa(200), zwa(200)
INTEGER :: xs , xe , ys , ye
REAL :: mtn_ht = 500.
integer :: ido_terrain = 0 ! 1 = mountain, 2 = EW Ridge, 3 = NS Ridge
INTEGER :: ks, ke, id
LOGICAL, EXTERNAL :: wrf_dm_on_monitor
real :: lat = 35.0
real :: lon = -95.0
integer :: lu_index = 2
real :: vegfra = 0.5, canwat = 0.0
integer :: isltyp = 4
character (len=256) :: mminlu2
LOGICAL :: real_soil = .false.
logical :: fcoriolis = .false.
integer :: ibbleseed = -1
integer :: bubbletype = 1 ! =2 to add random perts
real, allocatable :: ranarray(:,:),ranarraysmth(:,:)
! real :: rndnum
integer :: iranseed, i1, j1
double precision :: dthtot, dthrantot, dthrantotv, dthran
double precision :: dthrantotn, dthrantotp
double precision :: dthrantotvn, dthrantotvp
real :: dz_bot = 200., dz_top = 500., ztop = 20000. ! dz_bot =grid spacing at z=0
! dz_top = max stretch,
! ztop = config_flags%ztop
integer :: nbndlyr = 0 ! number of layers with dz_bot before stretching starts
! hard-wired values for second upper-level stretch (default off)
real :: rtop = 1.0 ! upper level stretch factor
real :: ztopstr = 100000. ! height to start upper level stretching; set < ztop to turn on
real :: dzmaxtop = 700. ! max upper level dz
integer :: nz1
double precision, dimension(0:nl_max) :: gzc, gze
real :: tmp1,tmp2,dz
NAMELIST /init_ideal/ nxc,nyc,delt,use_eta_levels, &
ugrid,vgrid,setccn,use_snd_plevels,use_snd_zlevels,numbub,nxb,nyb, &
xradbub,yradbub,zradbub,moisten,mtn_ht,ido_terrain,lat,lon, &
lu_index, vegfra, canwat, isltyp, real_soil, fcoriolis, bubbletype, ibbleseed, &
dz_bot, dz_top, nbndlyr, config_stretch_z
SELECT CASE ( model_data_order )
CASE ( DATA_ORDER_ZXY )
kds = grid%sd31 ; kde = grid%ed31 ;
ids = grid%sd32 ; ide = grid%ed32 ;
jds = grid%sd33 ; jde = grid%ed33 ;
kms = grid%sm31 ; kme = grid%em31 ;
ims = grid%sm32 ; ime = grid%em32 ;
jms = grid%sm33 ; jme = grid%em33 ;
kts = grid%sp31 ; kte = grid%ep31 ; ! note that tile is entire patch
its = grid%sp32 ; ite = grid%ep32 ; ! note that tile is entire patch
jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
CASE ( DATA_ORDER_XYZ )
ids = grid%sd31 ; ide = grid%ed31 ;
jds = grid%sd32 ; jde = grid%ed32 ;
kds = grid%sd33 ; kde = grid%ed33 ;
ims = grid%sm31 ; ime = grid%em31 ;
jms = grid%sm32 ; jme = grid%em32 ;
kms = grid%sm33 ; kme = grid%em33 ;
its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
jts = grid%sp32 ; jte = grid%ep32 ; ! note that tile is entire patch
kts = grid%sp33 ; kte = grid%ep33 ; ! note that tile is entire patch
CASE ( DATA_ORDER_XZY )
ids = grid%sd31 ; ide = grid%ed31 ;
kds = grid%sd32 ; kde = grid%ed32 ;
jds = grid%sd33 ; jde = grid%ed33 ;
ims = grid%sm31 ; ime = grid%em31 ;
kms = grid%sm32 ; kme = grid%em32 ;
jms = grid%sm33 ; jme = grid%em33 ;
its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
kts = grid%sp32 ; kte = grid%ep32 ; ! note that tile is entire patch
jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
END SELECT
open(15,file="namelist.input",status='old',form='formatted')
rewind(15)
read(15,NML=init_ideal,iostat=istat) ! returning iostat prevents bombing if the namelist does not exist
close(15)
open(15,file="namelist.output",status='old',form='formatted',position='append')
write(15,NML=init_ideal)
write(0,NML=init_ideal)
close(15)
n = 0
IF ( use_eta_levels ) n = n + 1
IF ( use_snd_plevels ) n = n + 1
IF ( use_snd_zlevels ) n = n + 1
IF ( n > 1 ) THEN
write(0,*) 'ERROR: Can only have one of these as .true. :'
write(0,*) ' use_eta_levels = ',use_eta_levels
write(0,*) ' use_snd_plevels = ',use_snd_plevels
write(0,*) ' use_snd_xlevels = ',use_snd_zlevels
WRITE( wrf_err_message , * ) 'Can only have one use_xxx_levels as true! '
CALL wrf_error_fatal ( wrf_err_message )
ENDIF
stretch_grid = .not. ( use_eta_levels .or. use_snd_plevels .or. use_snd_zlevels ) ! .true.
! delt = 5.
! z_scale = .50
z_scale = .40
pi = 2.*asin(1.0)
write(6,*) ' pi is ',pi
IF ( nxc <= 0 .and. nxb(1) <= 0) THEN
nxc = (ide-ids)/3 + 1
nxb(1) = nxc
ELSEIF ( nxc > 0 .and. nxb(1) <= 0) THEN
nxb(1) = nxc
ENDIF
IF ( nyc <= 0 .and. nyb(1) <= 0 ) THEN
nyc = (jde-jds)/2 + 1
nyb(1) = nyc
ELSEIF ( nyc > 0 .and. nyb(1) <= 0 ) THEN
nyb(1) = nyc
ENDIF
CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
!-----------------------------------------------------------------------------
! TEMPERATURE perturbations
dthtot = 0.0d0
dthrantot = 0.0d0
dthrantotv = 0.0d0
dthrantotn = 0.0d0
dthrantotp = 0.0d0
dthrantotvn = 0.0d0
dthrantotvp = 0.0d0
IF ( bubbletype > 1 ) THEN
! write(0,*) 'allocate ranarray: ids:ide,jds:jde = ',ids,ide,jds,jde
allocate ( ranarray(ids:ide,jds:jde) )
allocate ( ranarraysmth(ids:ide,jds:jde) )
iranseed = -Abs(ibbleseed)
! dfac = 0.0
ranarray(:,:) = 0.0
ranarraysmth(:,:) = 0.0
DO j = jds,jde
DO i = ids,ide
ranarray(i,j) = 2.0*(rndnum(iranseed) - 0.5) ! values of -1 to 1
ENDDO
ENDDO
DO j = jds,jde-4,4
DO i = ids,ide-4,4
DO j1 = 0,4
DO i1 = 0,4
ranarraysmth(i+i1,j+j1) = ranarray(i,j)
ENDDO
ENDDO
ENDDO
ENDDO
ENDIF
! here we check to see if the boundary conditions are set properly
CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
moisture_init = .true.
grid%itimestep=0
#ifdef DM_PARALLEL
CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
#endif
IF ( grid%sf_sfclay_physics /= 0 ) THEN
mminlu2 = 'USGS'
CALL nl_set_mminlu(1, mminlu2)
CALL nl_set_iswater(1,16)
! CALL nl_set_isice(1,3)
CALL nl_get_isice ( grid%id , grid%isice )
write(0,*) 'isice = ',grid%isice
ELSE
CALL nl_set_mminlu(1, ' ')
CALL nl_set_iswater(1,0)
ENDIF
CALL nl_set_cen_lat(1,lat)
CALL nl_set_cen_lon(1,lon)
CALL nl_set_truelat1(1,0.)
CALL nl_set_truelat2(1,0.)
CALL nl_set_moad_cen_lat (1,0.)
CALL nl_set_stand_lon (1,0.)
CALL nl_set_pole_lon (1,0.)
CALL nl_set_pole_lat (1,90.)
CALL nl_set_map_proj(1,0)
CALL nl_get_iswater(1,grid%iswater)
! here we initialize data we currently is not initialized
! in the input data
DO j = jts, jte
DO i = its, ite
grid%msft(i,j) = 1.
grid%msfu(i,j) = 1.
grid%msfv(i,j) = 1.
grid%msftx(i,j) = 1.
grid%msfty(i,j) = 1.
grid%msfux(i,j) = 1.
grid%msfuy(i,j) = 1.
grid%msfvx(i,j) = 1.
grid%msfvx_inv(i,j)= 1.
grid%msfvy(i,j) = 1.
grid%sina(i,j) = 0.
grid%cosa(i,j) = 1.
grid%e(i,j) = 0.
grid%f(i,j) = 0.
IF ( fcoriolis ) THEN
grid%e(i,j) = 2.0*EOMEG*cos(lat*DEGRAD)
grid%f(i,j) = 2.0*EOMEG*sin(lat*DEGRAD)
ENDIF
grid%xlat(i,j) = lat
grid%xlong(i,j) = lon
grid%xland(i,j) = 1.
grid%landmask(i,j) = 1.
grid%lu_index(i,j) = lu_index
END DO
END DO
DO j = jts , MIN(jde-1,jte)
DO i = its , MIN(ide-1,ite)
grid%vegfra(i,j) = vegfra
grid%canwat(i,j) = canwat
grid%isltyp(i,j) = isltyp
grid%ivgtyp(i,j) = lu_index
grid%xice(i,j) = 0.
grid%snow(i,j) = 0.
END DO
END DO
DO j = jts, jte
DO k = kts, kte
DO i = its, ite
grid%ww(i,k,j) = 0.
END DO
END DO
END DO
grid%step_number = 0
hold_ups = .true. ! need this set to true to initialize the soil on the interior of the domain
IF ( config_flags%sf_surface_physics /= 0 ) THEN
IF ( real_soil ) THEN ! from input file
IF (config_flags%sf_surface_physics .NE. 2) WRITE (6, *) &
'If using LSM option other than Noah, must edit input_soil file (from test/em_scm_xy)'
CALL read_soil(100,ns_input,tmn_input,tsk_input,zs_input,tslb_input,smois_input)
CALL init_module_optional_input(grid,config_flags)
num_st_levels_input = ns_input
num_sm_levels_input = ns_input
num_sw_levels_input = ns_input
DO k = 1,ns_input
st_levels_input(k) = zs_input(k)*100.0 ! to cm
sm_levels_input(k) = zs_input(k)*100.0 ! to cm
sw_levels_input(k) = zs_input(k)*100.0 ! to cm
st_input(:,k+1,:) = tslb_input(k)
sm_input(:,k+1,:) = smois_input(k)
sw_input(:,k+1,:) = smois_input(k)
! grid%tslb(:,k,:) = tslb_input(k)
write(6,*) 'tslb_input,smois_input,z: ',k,tslb_input(k),smois_input(k),zs_input(k)
ENDDO
grid%tsk = tsk_input
grid%sst = tsk_input
grid%tmn = tmn_input
flag_soil_layers = 0 ! go ahead and put skin temp in
flag_soil_levels = 0 ! go ahead and put skin moisture in
flag_sst = 0 ! don't modify for ocean
flag_tavgsfc = 0
flag_soilhgt = 0
CALL process_soil_real ( grid%tsk , grid%tmn , grid%tavgsfc, &
grid%landmask , grid%sst , grid%ht, grid%toposoil, &
st_input , sm_input , sw_input , &
st_levels_input , sm_levels_input , sw_levels_input , &
grid%zs , grid%dzs , grid%tslb , grid%smois , grid%sh2o , &
flag_sst , flag_tavgsfc, flag_soilhgt, flag_soil_layers, flag_soil_levels, &
ids , ide , jds , jde , kds , kde , &
ims , ime , jms , jme , kms , kme , &
its , ite , jts , jte , kts , kte , &
model_config_rec%sf_surface_physics(grid%id) , &
model_config_rec%num_soil_layers , &
model_config_rec%real_data_init_type , &
num_st_levels_input , num_sm_levels_input , num_sw_levels_input , &
num_st_levels_alloc , num_sm_levels_alloc , num_sw_levels_alloc )
write(6,*) 'size of tslb',size(grid%tslb,1),size(grid%tslb,2),size(grid%tslb,3)
DO k=1,ns_input
write(6,*) 'tslb in center:',k,grid%tslb(ite/2,k,jte/2)
IF ( grid%tslb(ite/2,k,jte/2) < 200. ) THEN
grid%tslb(:,k,:) = 298.0
ENDIF
ENDDO
ELSE ! ideal soil
! Process the soil; note that there are some things hard-wired into share/module_soil_pre.F
CALL process_soil_ideal(grid%xland,grid%xice,grid%vegfra,grid%snow,grid%canwat, &
grid%ivgtyp,grid%isltyp,grid%tslb,grid%smois, &
grid%tsk,grid%tmn,grid%zs,grid%dzs,model_config_rec%num_soil_layers, &
model_config_rec%sf_surface_physics(grid%id), &
ids,ide, jds,jde, kds,kde,&
ims,ime, jms,jme, kms,kme,&
its,ite, jts,jte, kts,kte )
ENDIF
ENDIF
! set up the grid
IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
IF ( config_stretch_z == 0 ) THEN
DO k=1, kde
grid%znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
(1.-exp(-1./z_scale))
ENDDO
ELSE ! geometric stretch
nz1 = kde
ztop = config_flags%ztop
dz = ztop/float(nz1-1)
write(6,*) 'nz1,dz,ztop = ',nz1,dz,ztop,kde
CALL ZGRID_sub(dz, dz_bot, nz1, nbndlyr, gzc, gze, 1, dz_top,ztopstr,rtop,dzmaxtop)
DO k = 1,nz1
!write(6,*) 'k,gzc,gze = ',k,gzc(k),gze(k)
tmp1 = gzc(k)
tmp2 = gze(k)
write(6,*) ' k, gzc, gze = ', k, tmp1,tmp2
ENDDO
gze(0) = -gze(2)
ke = nz1
gze(ke+1) = gze(ke) + (gze(ke) - gze(ke-1))
CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, etal, dry_sounding, nl_max, nl_in, theta_surf)
grid%znw(1) = 1.0
write(6,*) 'eta levels:'
write(6,*) 'k, eta'
write(6,*) 1,grid%znw(1)
DO k=2, kde-1
tmp1 = gze(k)
etaltmp(k) = interp_0( etal, zk, tmp1, nl_in )
p_z(k) = interp_0( p_in, zk, tmp1, nl_in )
write(6,*) 'k,z,etaltmp,zk,p: ',k,tmp1,etaltmp(k),zk(k),tmp2
ENDDO
p_z(kde) = interp_0( p_in, zk, config_flags%ztop, nl_in )
etaltmp(1) = 1.
do k=2,kde
etaltmp(k) = (p_z(k) - p_z(kde))/(p_surface - p_z(kde))
write(6,*) 'k,z,new-etaltmp,p: ',k,gze(k),etaltmp(k),p_z(k)
enddo
DO k=2, kde
grid%znw(k) = etaltmp(k)
write(6,*) k,grid%znw(k)
ENDDO
!k = kde
!grid%znw(k) = etal(k+1) ! use the added top w-point for model top
! write(6,*) k,grid%znw(k)
ENDIF
ELSE
IF ( use_snd_plevels .or. use_snd_zlevels ) THEN
dry_sounding = .false.
CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, etal, dry_sounding, nl_max, nl_in, theta_surf )
grid%znw(1) = 1.0
write(6,*) 'eta levels:'
write(6,*) 'k, eta, delta-eta'
write(6,*) 1,grid%znw(1)
DO k=2, kde-1
grid%znw(k) = 0.5*( etal(k) + etal(k+1) )
write(6,*) k,grid%znw(k)
ENDDO
k = kde
grid%znw(k) = etal(k+1) ! use the added top w-point for model top
write(6,*) k,grid%znw(k)
write(6,"( 5(f10.7,',',1x))") (grid%znw(k), k=1,kde)
ELSEIF ( use_eta_levels ) THEN
DO k=1, kde
! grid%znw(k) = 1. - float(k-1)/float(kde-1)
! grid%znw(k) = eta_levels(k)
grid%znw(k) = model_config_rec%eta_levels(k)
! write(6,*) 'k,eta = ',k,grid%znw(k)
ENDDO
ENDIF
ENDIF
DO k=1, kde-1
grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
grid%rdnw(k) = 1./grid%dnw(k)
grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
ENDDO
IF ( config_flags%hybrid_opt .NE. 0 ) THEN
! call wrf_error_fatal ( '--- ERROR: Hybrid Vertical Coordinate option not supported with this idealized case' )
END IF
grid%hybrid_opt = 0
DO k=1, kde
grid%c3f(k) = grid%znw(k)
grid%c4f(k) = 0.
grid%c3h(k) = grid%znu(k)
grid%c4h(k) = 0.
grid%c1f(k) = 1.
grid%c2f(k) = 0.
grid%c1h(k) = 1.
grid%c2h(k) = 0.
ENDDO
DO k=2, kde-1
grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
grid%rdn(k) = 1./grid%dn(k)
grid%fnp(k) = .5* grid%dnw(k )/grid%dn(k)
grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
ENDDO
cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
cof2 = grid%dn(2) /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
grid%cf1 = grid%fnp(2) + cof1
grid%cf2 = grid%fnm(2) - cof1 - cof2
grid%cf3 = cof2
grid%cfn = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
grid%rdx = 1./config_flags%dx
grid%rdy = 1./config_flags%dy
! get the sounding from the ascii sounding file, first get dry sounding and
! calculate base state
dry_sounding = .true.
IF ( wrf_dm_on_monitor() ) THEN
write(6,*) ' getting dry sounding for base state '
CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, etal, dry_sounding, nl_max, nl_in, theta_surf )
ENDIF
CALL wrf_dm_bcast_real( zk , nl_max )
CALL wrf_dm_bcast_real( p_in , nl_max )
CALL wrf_dm_bcast_real( pd_in , nl_max )
CALL wrf_dm_bcast_real( theta , nl_max )
CALL wrf_dm_bcast_real( rho , nl_max )
CALL wrf_dm_bcast_real( u , nl_max )
CALL wrf_dm_bcast_real( v , nl_max )
CALL wrf_dm_bcast_real( qv , nl_max )
CALL wrf_dm_bcast_integer ( nl_in , 1 )
write(6,*) ' returned from reading sounding, nl_in is ',nl_in
! find ptop for the desired ztop (ztop is input from the namelist),
! and find surface pressure
grid%p_top = interp_0( p_in, zk, config_flags%ztop, nl_in )
IF ( use_eta_levels ) THEN
grid%p_top = Max( grid%p_top_requested, p_in(nl_in) )
write(6,*) 'ptop,p_top_requested,p_in(nl_in) = ',grid%p_top,grid%p_top_requested,p_in(nl_in)
ENDIF
! Fill in the hybrid coordinate coefficients
DO k=1, kde
IF ( config_flags%hybrid_opt .EQ. 0 ) THEN
grid%c3f(k) = grid%znw(k)
ELSE IF ( config_flags%hybrid_opt .EQ. 1 ) THEN
grid%c3f(k) = grid%znw(k)
ELSE IF ( config_flags%hybrid_opt .EQ. 2 ) THEN
B1 = 2. * grid%etac**2 * ( 1. - grid%etac )
B2 = -grid%etac * ( 4. - 3. * grid%etac - grid%etac**3 )
B3 = 2. * ( 1. - grid%etac**3 )
B4 = - ( 1. - grid%etac**2 )
B5 = (1.-grid%etac)**4
grid%c3f(k) = ( B1 + B2*grid%znw(k) + B3*grid%znw(k)**2 + B4*grid%znw(k)**3 ) / B5
IF ( grid%znw(k) .LT. grid%etac ) THEN
grid%c3f(k) = 0.
END IF
IF ( k .EQ. kds ) THEN
grid%c3f(k) = 1.
ELSE IF ( k .EQ. kde ) THEN
grid%c3f(k) = 0.
END IF
ELSE IF ( config_flags%hybrid_opt .EQ. 3 ) THEN
IF ( grid%znw(k) .GE. grid%etac ) THEN
sin_arg = (1./(1.-grid%etac))*(grid%znw(k)-1.)+1
grid%c3f(k) = (sin(sin_arg*3.14159265358/2.))**2
ELSE
grid%c3f(k) = 0.
END IF
IF ( k .EQ. kds ) THEN
grid%c3f(k) = 1.
ELSE IF ( k .EQ. kds ) THEN
grid%c3f(kde) = 0.
END IF
ELSE
CALL wrf_error_fatal ( 'ERROR: --- hybrid_opt=0 ===> Standard WRF Coordinate; hybrid_opt>=1 ===> Hybrid Vertical Coordinate' )
END IF
END DO
DO k=1, kde
grid%c4f(k) = ( grid%znw(k) - grid%c3f(k) ) * ( p1000mb - grid%p_top )
ENDDO
! Now on half levels, just add up and divide by 2 (for c3h). Use (eta-c3)*(p00-pt) for c4 on half levels.
DO k=1, kde-1
grid%c3h(k) = ( grid%c3f(k+1) + grid%c3f(k) ) * 0.5
grid%c4h(k) = ( grid%znu(k) - grid%c3h(k) ) * ( p1000mb - grid%p_top )
ENDDO
! c1 = d(B)/d(eta). We define c1f as c1 on FULL levels. For a vertical difference,
! we need to use B and eta on half levels. The k-loop ends up referring to the
! full levels, neglecting the top and bottom.
DO k=kds+1, kde-1
grid%c1f(k) = ( grid%c3h(k) - grid%c3h(k-1) ) / ( grid%znu(k) - grid%znu(k-1) )
ENDDO
! The boundary conditions to get the coefficients:
! 1) At k=kts: define d(B)/d(eta) = 1. This gives us the same value of B and d(B)/d(eta)
! when doing the sigma-only B=eta.
! 2) At k=kte: with the new vertical coordinate, define d(B)/d(eta) = 0. The curve B SMOOTHLY
! goes to zero, and at the very top, B continues to SMOOTHLY go to zero. Note that for
! almost all cases of non B=eta, B is ALREADY=ZERO at the top, so this is a reasonable BC to
! assume.
! 3) At k=kte: when trying to mimic the original vertical coordinate, since B = eta, then
! d(B)/d(eta) = 1.
grid%c1f(kds) = 1.
IF ( ( config_flags%hybrid_opt .EQ. 0 ) .OR. ( config_flags%hybrid_opt .EQ. 1 ) ) THEN
grid%c1f(kde) = 1.
ELSE
grid%c1f(kde) = 0.
END IF
! c2 = ( 1. - c1(k) ) * (p00 - pt). There is no vertical differencing, so we can do the
! full kds to kde looping.
DO k=kds, kde
grid%c2f(k) = ( 1. - grid%c1f(k) ) * ( p1000mb - grid%p_top )
END DO
! Now on half levels for c1 and c2. The c1h will result from the full level c3 and full
! level eta differences. The c2 value use the half level c1(k).
DO k=1, kde-1
grid%c1h(k) = ( grid%c3f(k+1) - grid%c3f(k) ) / ( grid%znw(k+1) - grid%znw(k) )
grid%c2h(k) = ( 1. - grid%c1h(k) ) * ( p1000mb - grid%p_top )
END DO
IF ( use_snd_plevels .or. use_snd_zlevels ) grid%p_top = p_in(nl_in)
DO j=jts,jte
DO i=its,ite
grid%ht(i,j) = 0.
ENDDO
ENDDO
xs=ide/2 -3
xs=ids -3
xe=xs + 6
ys=jde/2 -3
ye=ys + 6
! mtn_ht = 500
IF ( ido_terrain == 1 ) THEN ! MTN
DO j=max(ys,jds),min(ye,jde-1)
DO i=max(xs,ids),min(xe,ide-1)
grid%ht(i,j) = mtn_ht * 0.25 * &
( 1. + COS ( 2*pi/(xe-xs) * ( i-xs ) + pi ) ) * &
( 1. + COS ( 2*pi/(ye-ys) * ( j-ys ) + pi ) )
ENDDO
ENDDO
endif
IF ( ido_terrain == 2 ) THEN ! EW_RIDGE
DO j=max(ys,jds),min(ye,jde-1)
DO i=ids,ide
grid%ht(i,j) = mtn_ht * 0.50 * &
( 1. + COS ( 2*pi/(ye-ys) * ( j-ys ) + pi ) )
ENDDO
ENDDO
endif
IF ( ido_terrain ==3 ) THEN ! NS_RIDGE
DO j=jds,jde
DO i=max(xs,ids),min(xe,ide-1)
grid%ht(i,j) = mtn_ht * 0.50 * &
( 1. + COS ( 2*pi/(xe-xs) * ( i-xs ) + pi ) )
ENDDO
ENDDO
endif
DO j=jts,jte
DO i=its,ite
grid%phb(i,1,j) = g * grid%ht(i,j)
grid%ph0(i,1,j) = g * grid%ht(i,j)
ENDDO
ENDDO
DO J = jts, jte
DO I = its, ite
p_surf = interp_0( p_in, zk, grid%phb(i,1,j)/g, nl_in )
grid%mub(i,j) = p_surf-grid%p_top
! this is dry hydrostatic sounding (base state), so given grid%p (coordinate),
! interp theta (from interp) and compute 1/rho from eqn. of state
DO K = 1, kte-1
! p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
#if !( HYBRID_COORD==1 )
p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
#elif ( HYBRID_COORD==1 )
p_level = grid%c3h(k)*(p_surf - grid%p_top) + grid%c4h(k) + grid%p_top
#endif
grid%pb(i,k,j) = p_level
grid%t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
ENDDO
! calc hydrostatic balance (alternatively we could interp the geopotential from the
! sounding, but this assures that the base state is in exact hydrostatic balance with
! respect to the model eqns.
DO k = 2,kte
grid%phb(i,k,j) = grid%phb(i,k-1,j) - grid%dnw(k-1)*grid%mub(i,j)*grid%alb(i,k-1,j)
ENDDO
ENDDO
ENDDO
IF ( wrf_dm_on_monitor() ) THEN
write(6,*) ' ptop is ',grid%p_top
! write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
#if !( HYBRID_COORD==1 )
write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
#elif ( HYBRID_COORD==1 )
write(6,*) ' base state grid%MUB(1,1), p_surf is ',grid%MUB(1,1),grid%c3f(kts)*grid%MUB(1,1)+grid%c4f(kts)+grid%p_top
#endif
ENDIF
! calculate full state for each column - this includes moisture.
write(6,*) ' getting moist sounding for full state '
dry_sounding = .false.
CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, etal, dry_sounding, nl_max, nl_in, theta_surf )
DO J = jts, min(jde-1,jte)
DO I = its, min(ide-1,ite)
! At this point grid%p_top is already set. find the DRY mass in the column
! by interpolating the DRY pressure.
pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
! compute the perturbation mass and the full mass
grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
grid%mu_2(i,j) = grid%mu_1(i,j)
grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
! given the dry pressure and coordinate system, interp the potential
! temperature and qv
do k=1,kde-1
! p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
#if !( HYBRID_COORD==1 )
p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
#elif ( HYBRID_COORD==1 )
p_level = grid%c3h(k)*(pd_surf - grid%p_top) + grid%c4h(k) + grid%p_top
#endif
moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
grid%t_1(i,k,j) = interp_0( theta, pd_in, p_level, nl_in ) - t0
grid%t_2(i,k,j) = grid%t_1(i,k,j)
IF ( f_qnn .and. setccn ) THEN
IF ( config_flags%mp_physics == wdm5scheme .or. config_flags%mp_physics == wdm6scheme ) THEN
scalar(i,k,j,P_QNN) = grid%ccn_conc
ELSEIF ( config_flags%mp_physics == nssl_2momccn ) THEN
! ELSEIF ( config_flags%mp_physics == nssl_2momccn .or. config_flags%mp_physics == nssl_3mom ) THEN
scalar(:,:,:,P_QNN) = grid%nssl_cccn/1.225
ELSE
scalar(:,:,:,P_QNN) = grid%ccn_conc
ENDIF
ENDIF
enddo
! integrate the hydrostatic equation (from the RHS of the bigstep
! vertical momentum equation) down from the top to get grid%p.
! first from the top of the model to the top pressure
k = kte-1 ! top level
qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
qvf2 = 1./(1.+qvf1)
qvf1 = qvf1*qvf2
! grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
qvf = 1. + rvovrd*moist(i,k,j,P_QV)
grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
(((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
! down the column
do k=kte-2,1,-1
qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
qvf2 = 1./(1.+qvf1)
qvf1 = qvf1*qvf2
grid%p(i,k,j) = grid%p(i,k+1,j) - (grid%mu_1(i,j) + qvf1*grid%mub(i,j))/qvf2/grid%rdn(k+1)
qvf = 1. + rvovrd*moist(i,k,j,P_QV)
grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
(((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
enddo
! this is the hydrostatic equation used in the model after the
! small timesteps. In the model, grid%al (inverse density)
! is computed from the geopotential.
grid%ph_1(i,1,j) = 0.
DO k = 2,kte
grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (grid%dnw(k-1))*( &
(grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
grid%mu_1(i,j)*grid%alb(i,k-1,j) )
grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
ENDDO
IF ( wrf_dm_on_monitor() ) THEN
if((i==2) .and. (j==2)) then
write(6,*) ' grid%ph_1 calc ',grid%ph_1(2,1,2),grid%ph_1(2,2,2),&
grid%mu_1(2,2)+grid%mub(2,2),grid%mu_1(2,2), &
grid%alb(2,1,2),grid%al(1,2,1),grid%rdnw(1)
endif
ENDIF
ENDDO
ENDDO
!#if 0
! thermal perturbation to kick off convection
DO n = 1,numbub
write(6,*) ' nxc, nyc for perturbation ',nxb(n),nyb(n)
ENDDO
write(6,*) ' delt for perturbation ',delt
DO J = jts, min(jde-1,jte)
yrad = config_flags%dy*float(j-nyc)/yradbub
! yrad = 0.
DO I = its, min(ide-1,ite)
xrad = config_flags%dx*float(i-nxc)/xradbub
! xrad = 0.
DO K = 1, kte-1
! put in preturbation theta (bubble) and recalc density. note,
! the mass in the column is not changing, so when theta changes,
! we recompute density and geopotential
dthran = 0.0d0
IF( bubbletype .eq. 2 ) dthran = dthran + 0.1*ranarray(i,j)
DO n = 1,numbub
yrad = config_flags%dy*float(j-nyb(n))/yradbub
xrad = config_flags%dx*float(i-nxb(n))/xradbub
zrad = 0.5*(grid%ph_1(i,k,j)+grid%ph_1(i,k+1,j) &
+grid%phb(i,k,j)+grid%phb(i,k+1,j))/g
zrad = (zrad-zradbub)/zradbub
RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
IF(RAD <= 1.) THEN
thtmp = grid%t_1(i,k,j) + t0
grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*COS(.5*PI*RAD)**2 + dthran
grid%t_2(i,k,j)=grid%t_1(i,k,j)
qvf = 1. + rvovrd*moist(i,k,j,P_QV)
grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
(((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
IF ( moisten ) THEN
pres = grid%pb(i,k,j) ! psfc*pz(k)**(cp/rd)
! thtmp = grid%t_1(i,k,j) - delt*COS(.5*PI*RAD)**2
ptmp = grid%p(i,k,j)+grid%pb(i,k,j)
tem = thtmp * (ptmp/p1000mb)**rcp
qvs = 380.*exp(17.27*(tem-273.16) / (tem - 36.)) / ptmp
! qvs = 380.*exp(17.27*(pz(k)*tz(k)-273.16) / (pz(k)*tz(k)- 36.)) / pres
rh = moist(i,k,j,P_QV) / qvs