-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver_code.f90
1162 lines (961 loc) · 45 KB
/
driver_code.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
!>@author
!>Paul Connolly, The University of Manchester
!>@brief
!>drivers for the dynamical cloud model
module drivers
use numerics_type
!use variables
private
public :: model_driver
contains
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>calls IO and runs one time-step of model
!>@param[in] ntim: number of time-levels
!>@param[in] dt: grids
!>@param[in] ip, jp, kp: dims for full domain
!>@param[in] ipp, jpp, kpp: dims for this block of data
!>@param[in] l_h,r_h, ipstart,jpstart,kpstart: halo and dims
!>@param[in] x,y,z, xn,ym,zn,dx, dy, dz, dxn, dyn, dzn: grids
!>@param[in] dampfacn,dampfac
!>@param[in] pref,prefn
!>@param[inout] ubar,vbar,wbar,thbar,qbar
!>@param[in] u_force, v_force, forcing_tau, w_subs
!>@param[inout] ut,vt,wt: prognostics
!>@param[inout] zut,zvt,zwt: prognostics - previous time-step
!>@param[inout] tut,tvt,twt: prognostics - temp storage
!>@param[inout] th,sth,p: prognostic variables
!>@param[inout] su,sv,sw,psrc, div: more prognostic variables
!>@param[inout] strain,vism,vist - viscosity subgrid
!>@param[in] z0,z0th - roughness lengths
!>@param[in] ptol - tolerance for pressure solver
!>@param[in] c_s, c_e: start and end indices for a category
!>@param[in] cat_am,cat_c, cat_r,cat_i: category index for cloud and rain and ice
!>@param[in] n_mode,inc,iqc,inr,iqr,ini, iqi, iai
!>@param[in] q_name: name of q-variables
!>@param[inout] q,sq,viss - for clouds and subgrid
!>@param[inout] precip - array for precipitation
!>@param[in] theta, thetan: reference variables
!>@param[in] tref, trefn: reference variables
!>@param[in] rhoa, rhoan: reference variables
!>@param[in] lamsq, lamsqn: reference variables
!>@param[inout] thbase, thtop: bottom and base th
!>@param[inout] micro_init: initialise microphysics
!>@param[inout] new_file: flag for if this is a new file
!>@param[in] outputfile: netcdf output
!>@param[in] output_interval: interval for output (s)
!>@param[in] viscous: logical for applying viscous dissipation
!>@param[in] advection_scheme, kord, monotone: flags for advection schemes
!>@param[in] moisture: flag for moisture
!>@param[in] microphysics_flag: flag for microphysics
!>@param[in] ice_flag: flag for ice microphysics
!>@param[in] hm_flag: flag for hallett-mossop (not always used)
!>@param[in] wr_flag: flag for warm rain
!>@param[in] theta_flag: flag for adjusting theta
!>@param[in] damping_layer: flag for damping layer
!>@param[in] forcing: flag for large-scale forcing of horizontal winds
!>@param[in] divergence: flag for large-scale divergence
!>@param[in] radiation: radiation scheme
!>@param[in] j_stochastic, ice_nuc_flag, mode1_ice_flag, mode2_ice_flag, coll_breakup_flag1,
!>@param[in] heyms_west, lawson, recycle
!>@param[in] nq,nprec,ncat: number of q-variables
!>@param[in] psurf
!>@param[in] tdstart, tdend: start and end array indices - parallel ts
!>@param[inout] a, b, c, r, usol: tridag
!>@param[in] nbands, ns, nl: number of bands
!>@param[inout] flux_u, flux_d, rad_power
!>@param[in] lambda, lambda_low, lambda_high, delta_lambda, nrwbin,niwbin
!>@param[in] sflux_l, b_s_g
!>@param[in] start_year, start_mon,start_day,start_hour,start_min,start_sec
!>@param[in] lat, lon, albedo, emiss,quad_flag, asymmetry_water
!>@param[in] nrad
!>@param[inout] ngs,lamgs,mugs
!>@param[in] coords: for Cartesian topology
!>@param[in] dims,id, world_process, ring_comm, sub_horiz_comm: mpi variables
!>@param[in] sub_vert_comm: mpi variables
subroutine model_driver(ntim,dt,l_h,r_h, &
ip,jp,kp, &
ipp,jpp,kpp, &
ipstart, jpstart, kpstart, &
x,y,z, xn,yn,zn, &
dx,dy,dz, &
dxn,dyn,dzn, &
ubar,vbar,wbar,thbar,qbar,dampfacn,dampfac, &
u_force,v_force,forcing_tau, &
w_subs, &
ut,vt,wt,&
zut,zvt,zwt,&
tut,tvt,twt,&
th,sth,p, &
su,sv,sw,psrc, &
div, &
strain, vism, vist, z0,z0th, ptol, &
c_s, c_e, cat_am,cat_c,cat_r, cat_i,&
n_mode,inc,iqc, inr,iqr, ini, iqi, iai, &
q_name, q,sq,viss, &
precip, &
theta,thetan, &
tref,trefn, &
rhoa,rhoan, &
pref,prefn, &
lamsq,lamsqn, &
thbase,thtop, &
micro_init, &
new_file,outputfile, output_interval, &
viscous, &
advection_scheme, kord, monotone, &
moisture, microphysics_flag, ice_flag, hm_flag, wr_flag, theta_flag, &
damping_layer,forcing, divergence, radiation, land_surface, &
j_stochastic, ice_nuc_flag, mode1_ice_flag, &
mode2_ice_flag, coll_breakup_flag1, &
heyms_west, lawson, recycle, &
nq, nprec, ncat, &
psurf, &
skp,sz,szn,dsz,dszn, &
tdend_lsm,t_lsm,wg_lsm,tsurf_lsm, a_lsm,b_lsm,c_lsm,r_lsm,u_lsm, pscs_lsm, &
b1_lsm,wgs_lsm,wfc_lsm, phi_ps_lsm,kgs_lsm, &
tdstart,tdend, &
a,b,c,r,usol, &
nbands, ns,nl, flux_u, flux_d, rad_power, &
lambda,lambda_low,lambda_high, delta_lambda,&
nrwbin,niwbin, &
sflux_l, b_s_g, &
start_year,start_mon, start_day,start_hour,start_min,start_sec, &
lat, lon, albedo, emiss,quad_flag, &
gas_absorption, &
nmolecule, nweights, npress, ntemp, nh2o, &
itemp,ipress,bli_read, probs_read, h2o_read, &
molecularWeights, &
moleculeID, moleculePPM, &
asymmetry_water, &
nrad,ngs,lamgs,mugs, &
nprocv,mvrecv, &
coords, &
dims,id, world_process, rank, ring_comm,sub_horiz_comm,sub_vert_comm)
use numerics_type
use mpi_module, only : exchange_full, exchange_along_dim, exchange_along_dim_wo
use advection_s_3d, only : first_order_upstream_3d, &
mpdata_3d, mpdata_vec_3d, adv_ref_state, mpdata_3d_add, &
mpdata_vert_3d, mpdata_vec_vert_3d
use d_solver, only : bicgstab, sources, advance_momentum, radiative_transfer
use subgrid_3d, only : advance_scalar_fields_3d
use diagnostics
use p_micro_module
use lsm, only : soil_solver, calculate_h_and_le, lv
implicit none
logical, intent(inout) :: new_file
logical, intent(in) :: viscous, monotone, moisture, &
damping_layer, forcing, theta_flag, ice_flag, hm_flag, &
wr_flag, divergence, radiation, land_surface, &
heyms_west, lawson, recycle, &
gas_absorption
integer(i4b), intent(in) :: ice_nuc_flag, nrad, mode1_ice_flag, mode2_ice_flag, &
coll_breakup_flag1
logical, intent(inout) :: micro_init
integer(i4b), intent(in) :: ntim,ip,jp,kp, ipp,jpp,kpp, &
l_h,r_h, ipstart, jpstart, kpstart, &
advection_scheme, kord, nq,nprec,ncat, microphysics_flag, &
nmolecule, nweights, npress, ntemp, nh2o
integer(i4b), intent(in), dimension(1-r_h:kp+r_h) :: itemp, ipress
real(wp), intent(in), dimension(1:nbands,1:nmolecule,1:nweights, &
1:ntemp,1:npress, 1:nh2o) :: bli_read
real(wp), intent(in), dimension(1:nweights) :: probs_read
real(wp), intent(in), dimension(1:nh2o) :: h2o_read
integer(i4b), intent(in), dimension(1:nmolecule) :: moleculeID
real(wp), intent(in), dimension(1:nmolecule) :: moleculePPM, molecularWeights
integer(i4b), intent(in) :: id, world_process, ring_comm, sub_horiz_comm, &
sub_vert_comm,rank
integer(i4b), dimension(3), intent(in) :: coords, dims
character (len=*), intent(in) :: outputfile
real(wp), intent(in) :: output_interval, dt, z0,z0th, ptol, forcing_tau, &
j_stochastic
integer(i4b), dimension(ncat), intent(in) :: c_s, c_e
integer(i4b), intent(in) :: cat_am,cat_c, cat_r, cat_i,n_mode,inc,iqc,inr,iqr, &
ini, iqi, iai
real(wp), intent(inout) :: thbase, thtop
real(wp), dimension(1-l_h:ipp+r_h), intent(in) :: x,xn,dx, dxn
real(wp), dimension(1-l_h:jpp+r_h), intent(in) :: y,yn,dy,dyn
real(wp), dimension(1-l_h:kpp+r_h), intent(in) :: z,zn,dz,dzn, theta, thetan, &
tref,trefn, &
rhoa, rhoan,lamsq, lamsqn, &
u_force, v_force, w_subs
real(wp), dimension(1-l_h:kpp+r_h), intent(inout) :: ubar,vbar,wbar,thbar,qbar
real(wp), dimension(1-l_h:kpp+r_h), intent(in) :: dampfacn,dampfac
real(wp), dimension(1-l_h:kpp+r_h), intent(in) :: pref,prefn
real(wp), &
dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h), &
intent(inout) :: th,p,su,sv,sw,psrc,div
real(wp), &
dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-l_h:ipp+r_h), target, &
intent(inout) :: ut,zut,tut
real(wp), &
dimension(1-r_h:kpp+r_h,1-l_h:jpp+r_h,1-r_h:ipp+r_h), target, &
intent(inout) :: vt,zvt,tvt
real(wp), &
dimension(1-l_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h), target, &
intent(inout) :: wt,zwt,twt
real(wp), &
dimension(1-l_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h), &
intent(inout) ::sth,strain,vism,vist
real(wp), &
dimension(1-l_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h,1:nq), &
intent(inout) :: q,sq,viss
real(wp), &
dimension(1:kpp,1-l_h:jpp+r_h,1-l_h:ipp+r_h,1:nprec), &
intent(inout) :: precip
real(wp), &
dimension(1-l_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h,1:nrad), &
intent(inout) :: ngs,lamgs,mugs
character(len=20), intent(in), dimension(nq) :: q_name
! radiation variables
real(wp), dimension(nbands), intent(in) :: lambda, b_s_g, lambda_low,&
lambda_high, delta_lambda, nrwbin,niwbin, sflux_l
real(wp), intent(in), dimension(nprocv) :: mvrecv
integer(i4b), intent(in) :: nbands, ns, nl, tdstart,tdend
integer(i4b), intent(in) :: nprocv
real(wp), intent(inout), dimension(1:tdend) :: a,b,c,r,usol
real(wp), dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h,1:nbands) :: &
flux_d,flux_u
real(wp), dimension(1-r_h:jpp+r_h,1-r_h:ipp+r_h) :: fng
real(wp), dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h) :: &
rad_power
real(wp), intent(in) :: lat, lon, albedo, emiss, asymmetry_water
integer(i4b), intent(in) :: quad_flag, start_year, start_mon, start_day, &
start_hour, start_min, start_sec
! land surface model variables
real(wp), intent(in) :: psurf
integer(i4b), intent(in) :: tdend_lsm, skp
real(wp), dimension(1-l_h:skp+r_h), intent(in) :: sz,szn, dsz, dszn, pscs_lsm, &
b1_lsm,wgs_lsm,wfc_lsm, &
phi_ps_lsm,kgs_lsm
real(wp), dimension(1-l_h:skp+r_h,1-l_h:jpp+r_h,1-l_h:ipp+r_h), &
intent(inout) :: t_lsm,wg_lsm
real(wp), dimension(1-l_h:jpp+r_h,1-l_h:ipp+r_h), &
intent(inout) :: tsurf_lsm
real(wp), dimension(tdend_lsm), intent(inout) :: b_lsm,r_lsm,u_lsm
real(wp), dimension(tdend_lsm-1), intent(inout) :: a_lsm,c_lsm
real(wp), dimension(1-r_h:jpp+r_h,1-r_h:ipp+r_h) :: flux2d_1, flux2d_2, &
hf_lsm, lef_lsm
!-
! locals:
integer(i4b) :: n,n2, cur=1, i,j,k,nqc, error, rank2, jj,kk
real(wp) :: time, time_last_output, output_time, t1=0._wp,t2=0._wp, rad
real(wp), dimension(nq) :: q1,q2
real(wp), dimension(:,:,:), pointer :: u,zu,tu
real(wp), dimension(:,:,:), pointer :: v,zv,tv
real(wp), dimension(:,:,:), pointer :: w,zw,tw
real(wp), dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h) :: utmp, vtmp, wtmp
! real(wp), &
! dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h) :: th2
time_last_output=-output_interval
output_time=output_interval
rank2=dims(1)*dims(2)*dims(3)
if(id>=rank2) return
q1=0._wp
q2=0._wp
fng=0._wp
! associate pointers - for efficiency, when swapping arrays in leap-frog scheme
u => ut; v => vt; w => wt ! current time-step
zu => zut; zv => zvt; zw => zwt ! previous time-step
tu => tut; tv => tvt; tw => twt ! next-time-step
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(coords(3)==0) then
zw(0,:,:)=-zw(1,:,:); zu(1,:,:)=0._wp; zv(1,:,:)=0._wp
endif
if(coords(3)==(dims(3)-1)) then
zw(kpp,:,:)=-zw(kpp-1,:,:); zw(kpp+1,:,:)=0._wp
zu(kpp,:,:)=0._wp
zv(kpp,:,:)=0._wp
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! time-loop !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
do n=1,ntim
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! write netcdf variables !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
time=real(n-1,wp)*dt
if (time-time_last_output >= output_interval) then
if (id==world_process) &
print *,'output no ',cur,' at time (s) ', &
time,n,' steps of ',ntim
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Output to NetCDF !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call output(new_file,outputfile,cur, &
ip,ipp,ipstart,jp,jpp,jpstart,kp,kpp,kpstart, &
l_h,r_h, &
time, x,y,z,rhoa, thetan, trefn, &
u,v,w,th,p,div, &
q_name,q,nq, precip, nprec,moisture, &
id, world_process, rank2, ring_comm)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
time_last_output=time
cur=cur+1
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! microphysics !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sth = 0._wp
if(moisture) then
sq = 0._wp
select case (microphysics_flag)
case (0) ! null microphysics
case (1) ! not coded yet
case (2) ! not coded yet
case (3) ! pamm microphysics - an exchange full is done on fields
call p_microphysics_3d(nq,ncat,n_mode,c_s,c_e, inc, iqc,&
inr,iqr,ini,iqi,&
iai, &
cat_am,cat_c, cat_r, cat_i,&
nprec, &
ipp,jpp,kpp,l_h,r_h,dt,dz,&
dzn,q(:,:,:,:),precip(:,:,:,:),&
nrad,ngs(:,:,:,:),lamgs(:,:,:,:),mugs(:,:,:,:), &
th(:,:,:),prefn, &
zn(:),thetan,rhoa,rhoan,w(:,:,:), &
micro_init,hm_flag,wr_flag, 1.e-14_wp, &
ice_flag, theta_flag, &
j_stochastic, ice_nuc_flag, mode1_ice_flag, &
mode2_ice_flag, &
coll_breakup_flag1, &
heyms_west, lawson, recycle, &
radiation, &
ring_comm,sub_vert_comm,id,dims,coords)
case default
print *,'not coded'
stop
end select
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! try doing radiation here !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(radiation) then
! updates th
call radiative_transfer(ring_comm,id,rank2, dims, coords, &
dt,dz,dzn,ipp,jpp,kpp,l_h,r_h,&
th,sth,&
tref,trefn, rhoa,rhoan,&
sub_vert_comm, time,tdstart,tdend, &
a,b,c,r,usol, &
nbands, ns,nl, flux_u, flux_d, &
lambda,lambda_low,lambda_high, delta_lambda,nrwbin, niwbin, &
sflux_l, b_s_g, &
nq, q, &
start_year,start_mon, start_day,start_hour,start_min,start_sec, &
lat, lon, albedo, emiss,quad_flag, &
gas_absorption, &
nmolecule, nweights, npress, ntemp, nh2o, &
itemp,ipress,bli_read, probs_read, h2o_read, &
moleculeID, moleculePPM, molecularWeights, &
asymmetry_water, &
nrad,ngs,lamgs,mugs, &
nprocv,mvrecv)
if(land_surface) then
! the net flux at the ground can now be calculated
fng=sum(flux_d(0,:,:,:),dim=3)-sum(flux_u(0,:,:,:),dim=3)
endif
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! call land-surface model !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(land_surface) then
! call the land-surface model
call calculate_h_and_le(ipp,jpp,kpp,l_h, r_h, nq, dt,z0, &
z0th, wfc_lsm(1), rhoan, thetan, z,zn,dz,u,v, psurf, tsurf_lsm,&
th,wg_lsm(1,:,:),q(:,:,:,1), sth, sq, hf_lsm, lef_lsm )
flux2d_1=fng-hf_lsm-lef_lsm
flux2d_2=-(precip(1,:,:,1)/3.6e6_wp-lef_lsm/lv/1000._wp)
call soil_solver(ipp,jpp,skp,l_h,r_h, &
tdend_lsm,a_lsm,b_lsm,c_lsm,r_lsm,u_lsm, pscs_lsm, &
b1_lsm,wgs_lsm,phi_ps_lsm,kgs_lsm, &
dt,t_lsm,wg_lsm,tsurf_lsm, &
sz,szn,dsz,dszn, flux2d_1, flux2d_2, &
coords,dims, id, ring_comm)
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! calculate horizontal averages !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call horizontal_means(sub_horiz_comm,id,dims,coords, moisture, &
ip,jp,ipp,jpp,kpp,l_h,r_h, nq,&
ubar,vbar,wbar,thbar,qbar,u,v,w,th,q)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! calculate divergence - test !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call divergence_calc(ring_comm,id,dims,coords, &
ipp,jpp,kpp,dx,dxn,dy,dyn,dz,dzn,rhoa,rhoan,l_h,r_h,u,v,w,div)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! calculate sources of momentum, theta, q, pressure !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call sources(ring_comm, id, rank2, dims,coords, &
dt,xn,yn ,z,zn,dx,dy,dz,dxn,dyn,dzn,ipp,jpp,kpp,l_h,r_h,&
nq, &
ubar,vbar,wbar,thbar,qbar, dampfacn,dampfac, &
u_force,v_force,forcing_tau, &
w_subs, &
zu,zv,zw, &
u,v,w,su,sv,sw, &
q,sq,viss, &
psrc, &
th,sth, strain,vism,vist, &
theta,thetan,tref, trefn, rhoa,rhoan,lamsq,lamsqn, &
z0,z0th, &
viscous, moisture,damping_layer, forcing, divergence, radiation, &
sub_vert_comm, time,tdstart,tdend, &
a,b,c,r,usol, &
nbands, ns,nl, flux_u, flux_d, rad_power, &
lambda,lambda_low,lambda_high, delta_lambda,&
nrwbin,niwbin, &
sflux_l, b_s_g, &
start_year,start_mon, start_day,start_hour,start_min,start_sec, &
lat, lon, albedo, emiss,quad_flag, &
asymmetry_water, &
nrad,ngs,lamgs,mugs, &
nprocv,mvrecv)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set halos !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call exchange_along_dim_wo(ring_comm, id, kpp, jpp, ipp, &
r_h,r_h,r_h,r_h,r_h,r_h, psrc, &
dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! find pressure perturbation !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call bicgstab(ring_comm, id, rank2,dims,coords, &
dt,x,y,z,dx,dy,dz,dxn,dyn,dzn, &
rhoa,rhoan, &
ipp,jpp,kpp,l_h,r_h,su,sv,sw,zu,zv,zw,p,psrc,ptol, &
.false.)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set halos !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call exchange_along_dim_wo(ring_comm, id, kpp, jpp, ipp, &
r_h,r_h,r_h,r_h,r_h,r_h, p, dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if((advection_scheme == 0) .or. (advection_scheme == 1)) then
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advect the reference state !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call adv_ref_state(dt,dx,dy,dz,dxn,dyn,dzn,rhoa,rhoan,ipp,jpp,kpp,l_h,r_h, &
u,v,w,th,thetan,ring_comm,id,dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set halos !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call exchange_full(ring_comm, id, kpp, jpp, ipp, &
r_h,r_h,r_h,r_h,r_h,r_h,th,0._wp,0._wp,dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advect scalar fields using mid-point !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
select case (advection_scheme)
case (0)
call first_order_upstream_3d(dt,dxn,dyn,dzn,rhoa,rhoan, &
ipp,jpp,kpp,l_h,r_h,u,v,w,th,0,dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set halos !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call exchange_full(ring_comm, id, kpp, jpp, ipp, &
r_h,r_h,r_h,r_h,r_h,r_h,th,t1,t2,dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
case (1)
call mpdata_3d(dt,dx,dy,dz,dxn,dyn,dzn,rhoa,rhoan, &
ipp,jpp,kpp,l_h,r_h,u,v,w,th,t1,t2, &
kord,monotone,0,ring_comm,id, &
dims,coords)
case(2)
call mpdata_3d_add(dt,dx,dy,dz,dxn,dyn,dzn,rhoa,rhoan, &
ipp,jpp,kpp,l_h,r_h,u,v,w,th,thetan,thbase,thtop, &
kord,monotone,0,ring_comm,id, &
dims,coords)
case default
print *,'not coded'
stop
end select
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advect q-fields !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(moisture) then
select case (advection_scheme)
case (0:2)
do nqc=1,ncat
!if((nqc<2).or.(nqc>(n_mode+1))) then
call mpdata_vec_3d(dt,dx,dy,dz,dxn,dyn,dzn,rhoa,rhoan, &
ipp,jpp,kpp,c_e(nqc)-c_s(nqc)+1, &
l_h,r_h,u,v,w,q(:,:,:,c_s(nqc):c_e(nqc)), &
q1(c_s(nqc):c_e(nqc)),q2(c_s(nqc):c_e(nqc)), &
kord,monotone,0,ring_comm,id, &
dims,coords)
!endif
enddo
case default
print *,'not coded'
stop
end select
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advance momentum 1 time-step !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call advance_momentum(ring_comm, id, rank2,&
2._wp*dt,dx,dy,dz,dxn,dyn,dzn,rhoa,rhoan,ipp,jpp,kpp,l_h,r_h,&
tu,tv,tw,zu,zv,zw,su,sv,sw,p,dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advance scalars 1 time-step !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advance fields
call advance_scalar_fields_3d(dt,&
q,sq,&
th,sth,rhoa,rhoan,ipp,jpp,kpp,nq,l_h,r_h,moisture)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! time-smoothing !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
utmp=0.99_wp*u+0.01_wp*zu
vtmp=0.99_wp*v+0.01_wp*zv
wtmp=0.99_wp*w+0.01_wp*zw
zu=0.01_wp*u+0.99_wp*zu
zv=0.01_wp*v+0.99_wp*zv
zw=0.01_wp*w+0.99_wp*zw
u=utmp
v=vtmp
w=wtmp
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! swap pointers (for efficiency) !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(modulo(n,3).eq.1) then
u => tut; v => tvt; w => twt
zu => ut; zv => vt; zw => wt
tu => zut; tv => zvt; tw => zwt
else if(modulo(n,3).eq.2) then
u => zut; v => zvt; w => zwt
zu => tut; zv => tvt; zw => twt
tu => ut; tv => vt; tw => wt
else if(modulo(n,3).eq.0) then
u => ut; v => vt; w => wt
zu => zut; zv => zvt; zw => zwt
tu => tut; tv => tvt; tw => twt
endif
! u,v,w are now the values on the current time-step in the next iteration
! zu,zv,zw are now the values on the previous time-step in the next iteration
! tu,tv,tw are now the values on the future time-step in the next iteration
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! set halos !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call exchange_full(ring_comm, id, kpp, jpp, ipp, r_h,r_h,r_h,r_h,l_h,r_h,u,&
0._wp,0._wp,dims,coords)
call exchange_full(ring_comm, id, kpp, jpp, ipp, r_h,r_h,l_h,r_h,r_h,r_h,v,&
0._wp,0._wp,dims,coords)
call exchange_full(ring_comm, id, kpp, jpp, ipp, l_h,r_h,r_h,r_h,r_h,r_h,w,&
0._wp,0._wp,dims,coords)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(coords(3)==0) then
w(0,:,:)=0._wp ! the vertical velocity at the surface is zero
u(0,:,:)=-u(1,:,:) ! average results in zero horizontal velocity at ground
v(0,:,:)=-v(1,:,:)
endif
if(coords(3)==(dims(3)-1)) then
!w(kpp,:,:)=-w(kpp-1,:,:)
w(kpp+1,:,:)=0._wp
u(kpp+1,:,:)=u(kpp,:,:)
v(kpp+1,:,:)=v(kpp,:,:)
endif
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end subroutine model_driver
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>outputs variables to NetCDF file using MPI
!>@param[inout] new_file: flag if this is a new file
!>@param[in] outputfile: outputfilename
!>@param[in] n: time-level
!>@param[in] ip: number of x global grid
!>@param[in] ipp: number of x levels on this PE
!>@param[in] ipstart: start of i index on global grid
!>@param[in] jp: ditto for y
!>@param[in] jpp: ditto for y
!>@param[in] jpstart: start of j index on global grid
!>@param[in] kp: ditto for z
!>@param[in] kpp: ditto for z
!>@param[in] kpstart: start of j index on global grid
!>@param[in] nq: number of q-variables
!>@param[in] l_h,r_h: halo
!>@param[in] time: time (s)
!>@param[in] x,y,z, rhoa, thetan, trefn: grids
!>@param[in] u,v,w,th,p,div: prognostic variables
!>@param[in] q_name: name of q-variables
!>@param[in] q
!>@param[in] precip, nprec
!>@param[in] moisture: flag for moisture
!>@param[in] id: id
!>@param[in] world_process: world_process
!>@param[in] rank: rank
!>@param[in] ring_comm: ring_comm
subroutine output(new_file,outputfile,n,ip,ipp,ipstart,jp,jpp,jpstart, &
kp,kpp,kpstart,l_h,r_h, &
time, &
x,y,z,rhoa, thetan, trefn, &
u,v,w,th,p,div, &
q_name,q,nq, precip, nprec,&
moisture, &
id, world_process, rank, ring_comm)
use netcdf
use mpi
use mpi_module, only : mpi_integer9
!use variables, only : MPI_INTEGER9
implicit none
logical, intent(inout) :: new_file
character (len=*), intent(in) :: outputfile
integer(i4b), intent(in) :: n, ip, ipp, ipstart, jp, jpp, jpstart, &
kp, kpp, kpstart, l_h,r_h, nq,nprec
real(wp), intent(in) :: time
real(wp), dimension(1-l_h:ipp+r_h), intent(in) :: x
real(wp), dimension(1-l_h:jpp+r_h), intent(in) :: y
real(wp), dimension(1-l_h:kpp+r_h), intent(in) :: z,rhoa, thetan, trefn
real(wp), &
dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h), &
intent(inout) :: th,p,div
real(wp), &
dimension(1-r_h:kpp+r_h,1-r_h:jpp+r_h,1-l_h:ipp+r_h), &
intent(inout) :: u
real(wp), &
dimension(1-r_h:kpp+r_h,1-l_h:jpp+r_h,1-r_h:ipp+r_h), &
intent(inout) :: v
real(wp), &
dimension(1-l_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h), &
intent(inout) :: w
character(len=20), intent(in), dimension(nq) :: q_name
real(wp), dimension(1-l_h:kpp+r_h,1-r_h:jpp+r_h,1-r_h:ipp+r_h,nq), intent(in) :: q
real(wp), dimension(1:kpp,1-r_h:jpp+r_h,1-r_h:ipp+r_h,1:nprec), &
intent(in) :: precip
logical, intent(in) :: moisture
integer(i4b), intent(in) :: id ,world_process, rank, ring_comm
integer(i4b) :: ncid, x_dimid, nx_dimid, ny_dimid, nz_dimid, &
error, varid,a_dimid, id_go, lq_dimid,nq_dimid,nprec_dimid
integer(i4b) :: i, tag1
logical :: var
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! perform a blocking recv to wait for message from main process, !
! before carrying on !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(id .ne. world_process) then
tag1=id
call MPI_Recv(var,1, MPI_LOGICAL, world_process, &
tag1, MPI_COMM_WORLD, MPI_STATUS_IGNORE,error)
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if((id==world_process) .and. new_file) then
! open the file
call check( nf90_create(outputfile, NF90_CLOBBER, ncid) )
! define dimensions (netcdf hands back a handle)
call check( nf90_def_dim(ncid, "times", NF90_UNLIMITED, x_dimid) )
call check( nf90_def_dim(ncid, "ip", ip, nx_dimid) )
call check( nf90_def_dim(ncid, "jp", jp, ny_dimid) )
call check( nf90_def_dim(ncid, "kp", kp, nz_dimid) )
if(moisture) then
call check( nf90_def_dim(ncid, "nq", nq, nq_dimid) )
call check( nf90_def_dim(ncid, "nprec", nprec, nprec_dimid) )
call check( nf90_def_dim(ncid, "l_q_names", 20, lq_dimid) )
endif
! close the file, freeing up any internal netCDF resources
! associated with the file, and flush any buffers
call check( nf90_close(ncid) )
! now define some variables, units, etc
call check( nf90_open(outputfile, NF90_WRITE, ncid) )
! define mode
call check( nf90_redef(ncid) )
! define variable: time
call check( nf90_def_var(ncid, "time", nf90_float, &
(/x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "time", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "seconds") )
! define variable: x
call check( nf90_def_var(ncid, "x", nf90_float, &
(/nx_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "x", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m") )
! define variable: y
call check( nf90_def_var(ncid, "y", nf90_float, &
(/ny_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "y", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m") )
! define variable: z
call check( nf90_def_var(ncid, "z", nf90_float, &
(/nz_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "z", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m") )
! define variable: rhoa
call check( nf90_def_var(ncid, "rhoa", nf90_float, &
(/nz_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "rhoa", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "kg/m3") )
! define variable: theta
call check( nf90_def_var(ncid, "thetan", nf90_float, &
(/nz_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "thetan", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "K") )
! define variable: trefn
call check( nf90_def_var(ncid, "trefn", nf90_float, &
(/nz_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "trefn", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "K") )
! define variable: th
call check( nf90_def_var(ncid, "th", nf90_float, &
(/nz_dimid,ny_dimid,nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "th", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "K") )
! define variable: u
call check( nf90_def_var(ncid, "u", nf90_float, &
(/nz_dimid,ny_dimid,nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "u", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m/s") )
! define variable: v
call check( nf90_def_var(ncid, "v", nf90_float, &
(/nz_dimid,ny_dimid,nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "v", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m/s") )
! define variable: w
call check( nf90_def_var(ncid, "w", nf90_float, &
(/nz_dimid,ny_dimid,nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "w", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m/s") )
! define variable: p
call check( nf90_def_var(ncid, "p", nf90_float, &
(/nz_dimid,ny_dimid,nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "p", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "pa") )
! define variable: div
call check( nf90_def_var(ncid, "div", nf90_float, &
(/nz_dimid,ny_dimid,nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "div", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "m/s**2") )
if(moisture) then
! define variable: q_names
call check( nf90_def_var(ncid, "q_names", NF90_CHAR, &
(/lq_dimid,nq_dimid/), varid) )
! define variable: q
call check( nf90_def_var(ncid, "q", nf90_float, &
(/nq_dimid, nz_dimid, ny_dimid, nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "q", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "kg or number per kg") )
! define variable: precip
call check( nf90_def_var(ncid, "precip", nf90_float, &
(/nprec_dimid, nz_dimid, ny_dimid, nx_dimid,x_dimid/), varid) )
! get id to a_dimid
call check( nf90_inq_varid(ncid, "precip", a_dimid) )
! units
call check( nf90_put_att(ncid, a_dimid, &
"units", "mm hr-1 or number per m-2 s-1") )
endif
! exit define mode
call check( nf90_enddef(ncid) )
call check( nf90_close(ncid) )
new_file=.false.
call check( nf90_open(outputfile, NF90_WRITE, ncid) )
if(moisture) then
call check( nf90_inq_varid(ncid, "q_names", varid ) )
call check( nf90_put_var(ncid, varid, q_name, start = (/1,1/)))
endif
call check( nf90_close(ncid) )
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! now send messages from the main process to all other processes !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(id == world_process) then
do i=1,rank-1
tag1=i
call MPI_Send(var, 1, MPI_LOGICAL, i, &
tag1, MPI_COMM_WORLD, error)
enddo
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! perform a blocking recv to wait for message from main process, !
! before carrying on !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(id .ne. world_process) then
tag1=id
call MPI_Recv(id_go,1, MPI_INTEGER9, id-1, &