-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathintjcmod.f90
1169 lines (1048 loc) · 35.8 KB
/
intjcmod.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
module intjcmod
!$$$ module documentation block
! . . . .
! module: intjcmod module for weak constraint int routines
! pgrmmr: kleist
!
! abstract: module for Jc int routines
!
! program history log:
! 2012-01-21 kleist - consolidation of Jc int routines into single module
! 2013-10-25 todling - nullify work pointers
! 2014-03-19 pondeca - add weak constraint subroutine for wspd10m
! 2014-05-07 pondeca - add weak constraint subroutine for howv
! 2014-06-17 carley/zhu - add intliml for lcbas + some cleanup
! 2015-07-10 pondeca - add weak constraint subroutine for cldch
! 2019-03-05 martin - update intlimq to weight factqmin/max by latitude
! 2019-03-14 eliu - add intlimqc to constraint negative hydrometeors
! 2019-03-14 eliu - add precipitation components in various constraints
!
! subroutines included:
!
! attributes:
! language: f90
! machine:
!
!$$$ end documentation block
use kinds, only: r_kind,i_kind,r_quad
use constants, only: zero,two,one,half,zero_quad,one_quad,two_quad
use gsi_bundlemod, only: gsi_bundle,gsi_bundlegetpointer
implicit none
PRIVATE
PUBLIC intlimqc,intlimq,intlimg,intlimp,intlimv,intlimw10m,intlimhowv,intliml,intlimcldch,intjcdfi,intjcpdry,intjcpdry1,intjcpdry2
contains
subroutine intlimq(rval,sval,itbin)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimq
! prgmmr: derber org: np23 date: 1996-11-19
!
! abstract: limit negative q as a weak constraint
!
! program history log:
! 1996-11-19 derber
! 1998-07-10 weiyu yang
! 1999-08-24 derber, j., treadon, r., yang, w., first frozen mpp version
! 2004-03-15 kleist, d., derber, j., treadon, r., use negative q only
! 2004-06-02 kleist, add penalty for excess moisture
! 2004-08-02 treadon - add only to module use, add intent in/out
! 2007-02-13 derber - modify to use rh rather than q
! 2008-06-02 safford - rm unused vars
! 2010-05-13 todling - update to use gsi_bundle
! 2011-12-27 kleist - add multiple time level capability (for 4densvar option)
! 2019-03-05 martin - update to weight factqmin/max by latitude
!
! input argument list:
! sq - increment in grid space
! itbin - observation bin (time level)
!
! output argument list:
! rq - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use gridmod, only: nsig,lat1,lon1,istart,wgtfactlats
use jfunc, only: factqmin,factqmax,superfact
use gsi_metguess_mod, only: gsi_metguess_bundle
use guess_grids, only: ges_qsat
use mpimod, only: mype
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
integer, intent(in) :: itbin
! Declare local variables
integer(i_kind) i,j,k,ier,istatus,ii,mm1
real(r_kind) q
real(r_kind),pointer,dimension(:,:,:) :: sq=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: rq=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: ges_q_it=>NULL()
if (factqmin==zero .and. factqmax==zero) return
mm1=mype+1
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'q',sq,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'q',rq,istatus);ier=istatus+ier
if(ier/=0)return
call gsi_bundlegetpointer(gsi_metguess_bundle(itbin),'q',ges_q_it,ier)
if(ier/=0)return
!$omp parallel do schedule(dynamic,1) private(k,j,i,q)
do k = 1,nsig
do j = 2,lon1+1
do i = 2,lat1+1
ii=istart(mm1)+i-2
q = ges_q_it(i,j,k) + sq(i,j,k)
! Lower constraint limit
if (q < zero) then
rq(i,j,k) = rq(i,j,k) + (factqmin*wgtfactlats(ii))*q &
/(ges_qsat(i,j,k,itbin)*ges_qsat(i,j,k,itbin))
! Upper constraint limit
else if (q > superfact*ges_qsat(i,j,k,itbin)) then
rq(i,j,k) = rq(i,j,k) + (factqmax*wgtfactlats(ii))*(q-superfact*ges_qsat(i,j,k,itbin))/ &
(ges_qsat(i,j,k,itbin)*ges_qsat(i,j,k,itbin))
end if
end do
end do
end do
return
end subroutine intlimq
subroutine intlimqc(rval,sval,itbin,cldtype)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimqc
! prgmmr: eliu org: np23 date: 2018-05-19
!
! abstract: limit negative hydrometeors as a weak constraint
!
! program history log:
! 2018-05-19 eliu
!
! input argument list:
! sqc - increment in grid space
! itbin - observation bin (time level)
!
! output argument list:
! rqc - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use mpimod, only: mype
use gridmod, only: nsig,lat1,lon1
use jfunc, only: factql,factqi,factqr,factqs,factqg
use gsi_metguess_mod, only: gsi_metguess_bundle
use guess_grids, only: ges_qsat
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
integer(i_kind), intent(in) :: itbin
character(2), intent(in) :: cldtype
! Declare local variables
integer(i_kind) i,j,k,ier,ier1,istatus
real(r_kind) qc
real(r_kind) factqc
real(r_kind),pointer,dimension(:,:,:) :: sqc=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: rqc=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: ges_qc_it=>NULL()
ier=0
ier1=0
if (trim(cldtype) == 'ql') then
factqc = factql
call gsi_bundlegetpointer(sval,'ql',sqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'ql',rqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(gsi_metguess_bundle(itbin),'ql',ges_qc_it,ier1)
else if (trim(cldtype) == 'qi') then
factqc = factqi
call gsi_bundlegetpointer(sval,'qi',sqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'qi',rqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(gsi_metguess_bundle(itbin),'qi',ges_qc_it,ier1)
else if (trim(cldtype) == 'qr') then
factqc = factqr
call gsi_bundlegetpointer(sval,'qr',sqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'qr',rqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(gsi_metguess_bundle(itbin),'qr',ges_qc_it,ier1)
else if (trim(cldtype) == 'qs') then
factqc = factqs
call gsi_bundlegetpointer(sval,'qs',sqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'qs',rqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(gsi_metguess_bundle(itbin),'qs',ges_qc_it,ier1)
else if (trim(cldtype) == 'qg') then
factqc = factqg
call gsi_bundlegetpointer(sval,'qg',sqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'qg',rqc,istatus);ier=istatus+ier
call gsi_bundlegetpointer(gsi_metguess_bundle(itbin),'qg',ges_qc_it,ier1)
endif
if (factqc == zero) return
if (mype==0) write(6,*) 'intlimqc: factqc = ', factqc, trim(cldtype)
if (mype==0) write(6,*) 'intlimqc: ier ier1= ', ier, ier1
if (ier/=0 .or. ier1/=0) return
!$omp parallel do schedule(dynamic,1) private(k,j,i,qc)
do k = 1,nsig
do j = 2,lon1+1
do i = 2,lat1+1
qc = ges_qc_it(i,j,k) + sqc(i,j,k)
! Lower constraint limit
if (qc < zero) then
rqc(i,j,k) = rqc(i,j,k) + factqc*qc/(ges_qsat(i,j,k,itbin)*ges_qsat(i,j,k,itbin))
end if
end do
end do
end do
return
end subroutine intlimqc
subroutine intlimg(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimg
! prgmmr: zhu org: np23 date: 2011-02-20
!
! abstract: limit negative gust as a weak constraint
!
! program history log:
! 2011-02-20 zhu
!
! input argument list:
! sg - increment in grid space
!
! output argument list:
! rg - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use gridmod, only: lat1,lon1
use jfunc, only: factg
use derivsmod, only: ggues
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) gust
real(r_kind),pointer,dimension(:,:) :: sg=>NULL()
real(r_kind),pointer,dimension(:,:) :: rg=>NULL()
if (factg==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'gust',sg,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'gust',rg,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
gust = ggues(i,j) + sg(i,j)
! Lower constraint limit
if (gust < zero) then
rg(i,j) = rg(i,j) + factg*gust/(ggues(i,j)*ggues(i,j))
end if
end do
end do
return
end subroutine intlimg
subroutine intlimp(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimp
! prgmmr: zhu org: np23 date: 2011-02-20
!
! abstract: limit negative pblh as a weak constraint
!
! program history log:
! 2011-02-20 zhu
!
! input argument list:
! sp - increment in grid space
!
! output argument list:
! rp - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use gridmod, only: lat1,lon1
use jfunc, only: factp
use derivsmod, only: pgues
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) pblh
real(r_kind),pointer,dimension(:,:) :: sp=>NULL()
real(r_kind),pointer,dimension(:,:) :: rp=>NULL()
if (factp==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'pblh',sp,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'pblh',rp,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
pblh = pgues(i,j) + sp(i,j)
! Lower constraint limit
if (pblh < zero) then
rp(i,j) = rp(i,j) + factp*pblh/(pgues(i,j)*pgues(i,j))
end if
end do
end do
return
end subroutine intlimp
subroutine intlimv(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimv
! prgmmr: zhu org: np23 date: 2011-02-20
!
! abstract: limit negative vis as a weak constraint
!
! program history log:
! 2011-02-20 zhu
!
! input argument list:
! sv - increment in grid space
!
! output argument list:
! rv - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use gridmod, only: lat1,lon1
use jfunc, only: factv
use derivsmod, only: vgues
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) vis
real(r_kind),pointer,dimension(:,:) :: sv=>NULL()
real(r_kind),pointer,dimension(:,:) :: rv=>NULL()
if (factv==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'vis',sv,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'vis',rv,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
vis = vgues(i,j) + sv(i,j)
! Lower constraint limit
if (vis < zero) then
rv(i,j) = rv(i,j) + factv*vis/(vgues(i,j)*vgues(i,j))
end if
end do
end do
return
end subroutine intlimv
subroutine intlimw10m(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimw10m
! prgmmr: pondeca org: np23 date: 2014-03-19
!
! abstract: limit negative 10-m wind speed as a weak constraint
!
! program history log:
! 2014-03-19 pondeca
!
! input argument list:
! sg - increment in grid space
!
! output argument list:
! rg - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use kinds, only: r_kind,i_kind
use constants, only: zero
use gridmod, only: lat1,lon1
use jfunc, only: factw10m
use derivsmod, only: w10mgues
use gsi_bundlemod, only: gsi_bundle
use gsi_bundlemod, only: gsi_bundlegetpointer
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) wspd10m
real(r_kind),pointer,dimension(:,:) :: sg=>NULL()
real(r_kind),pointer,dimension(:,:) :: rg=>NULL()
if (factw10m==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'wspd10m',sg,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'wspd10m',rg,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
wspd10m = w10mgues(i,j) + sg(i,j)
! Lower constraint limit
if (wspd10m < zero) then
rg(i,j) = rg(i,j) + factw10m*wspd10m/(w10mgues(i,j)*w10mgues(i,j))
end if
end do
end do
return
end subroutine intlimw10m
subroutine intlimhowv(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimhowv
! prgmmr: pondeca org: np23 date: 2014-05-07
!
! abstract: limit negative significant wave height as a weak constraint
!
! program history log:
! 2014-03-19 pondeca
!
! input argument list:
! sg - increment in grid space
!
! output argument list:
! rg - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use kinds, only: r_kind,i_kind
use constants, only: zero
use gridmod, only: lat1,lon1
use jfunc, only: facthowv
use derivsmod, only: howvgues
use gsi_bundlemod, only: gsi_bundle
use gsi_bundlemod, only: gsi_bundlegetpointer
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) howv
real(r_kind),pointer,dimension(:,:) :: sg=>NULL()
real(r_kind),pointer,dimension(:,:) :: rg=>NULL()
if (facthowv==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'howv',sg,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'howv',rg,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
howv = howvgues(i,j) + sg(i,j)
! Lower constraint limit
if (howv < zero) then
rg(i,j) = rg(i,j) + facthowv*howv/(howvgues(i,j)*howvgues(i,j))
end if
end do
end do
return
end subroutine intlimhowv
subroutine intliml(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intliml
! prgmmr: zhu org: np23 date: 2012-04-20
!
! abstract: limit negative lcbas as a weak constraint
!
! program history log:
! 2012-04-20 zhu
!
! input argument list:
! sv - increment in grid space
!
! output argument list:
! rv - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use gridmod, only: lat1,lon1
use jfunc, only: factl
use derivsmod, only: lgues
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) lcbas
real(r_kind),pointer,dimension(:,:) :: sv=>NULL()
real(r_kind),pointer,dimension(:,:) :: rv=>NULL()
if (factl==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'lcbas',sv,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'lcbas',rv,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
lcbas = lgues(i,j) + sv(i,j)
! Lower constraint limit
if (lcbas < zero) then
rv(i,j) = rv(i,j) + factl*lcbas/(lgues(i,j)*lgues(i,j))
end if
end do
end do
return
end subroutine intliml
subroutine intlimcldch(rval,sval)
!$$$ subprogram documentation block
! . . . .
! subprogram: intlimcldch
! prgmmr: pondeca org: np23 date: 2014-05-07
!
! abstract: limit negative cloud ceiling height as a weak constraint
!
! program history log:
! 2015-07-10 pondeca
!
! input argument list:
! sg - increment in grid space
!
! output argument list:
! rg - results from limiting operator
!
! remarks: see modules used
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use kinds, only: r_kind,i_kind
use constants, only: zero
use gridmod, only: lat1,lon1
use jfunc, only: factcldch
use derivsmod, only: cldchgues
use gsi_bundlemod, only: gsi_bundle
use gsi_bundlemod, only: gsi_bundlegetpointer
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ) :: sval
type(gsi_bundle),intent(inout) :: rval
! Declare local variables
integer(i_kind) i,j,ier,istatus
real(r_kind) cldch
real(r_kind),pointer,dimension(:,:) :: sg=>NULL()
real(r_kind),pointer,dimension(:,:) :: rg=>NULL()
if (factcldch==zero) return
! Retrieve pointers
! Simply return if any pointer not found
ier=0
call gsi_bundlegetpointer(sval,'cldch',sg,istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval,'cldch',rg,istatus);ier=istatus+ier
if(ier/=0)return
do j = 2,lon1+1
do i = 2,lat1+1
cldch = cldchgues(i,j) + sg(i,j)
! Lower constraint limit
if (cldch < zero) then
rg(i,j) = rg(i,j) + factcldch*cldch/(cldchgues(i,j)*cldchgues(i,j))
end if
end do
end do
return
end subroutine intlimcldch
subroutine intjcpdry(rval,sval,nbins,pjc)
!$$$ subprogram documentation block
! . . . .
! subprogram: intjcpdry mean dry ps conservation contribution to gradient
! prgmmr: kleist org: np23 date: 2009-07-07
!
! abstract: calculate contribution to gradient from mass conservation: combined
!
! program history log:
! 2009-07-07 kleist
! 2010-05-13 todling - update to use gsi_bundle
! 2010-05-25 derber - modify to minimize number of communications
! 2010-08-18 hu - added qpvals= to mpl_allreduce call
! 2010-11-03 treadon - correct i,j loop limits for rq,rc update
! 2011-11-01 eliu - add handling for ql & qi increments and search directions
! 2013-05-05 todling - separate dry mass from the rest (zero-diff change)
! collapse two verions of this routine into one (add opt arg)
! 2014-12-02 derber - fix comments
!
! input argument list:
! sval - current increments
! nbins - number of observation bins
! rval - input gradient
!
! output argument list:
! rval - input value plus contribution to gradient
! pjc - optional -- penalty from mass term
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use mpimod, only: mype
use gridmod, only: lat2,lon2,nsig,wgtlats,nlon,istart
use guess_grids, only: ges_prsi,ntguessig
use mpl_allreducemod, only: mpl_allreduce
use jcmod, only: bamp_jcpdry
use gsi_metguess_mod, only: gsi_metguess_get
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ),dimension(nbins) :: sval
type(gsi_bundle),intent(inout),dimension(nbins) :: rval
integer(i_kind),intent(in) :: nbins
real(r_quad) ,intent( out),optional :: pjc
! Declare local variables
real(r_quad),dimension(2*nbins) :: mass ! 1=dry;2=wv
real(r_quad),dimension(nsig) :: mass2
real(r_quad) rcon,con,dmass
integer(i_kind) i,j,k,it,ii,mm1,ier,icw,iql,iqi,istatus
real(r_kind),pointer,dimension(:,:,:) :: sq =>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sc =>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sql=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sqi=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: rq =>NULL()
real(r_kind),pointer,dimension(:,:,:) :: rc =>NULL()
real(r_kind),pointer,dimension(:,:,:) :: rql=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: rqi=>NULL()
real(r_kind),pointer,dimension(:,:) :: sp =>NULL()
real(r_kind),pointer,dimension(:,:) :: rp =>NULL()
integer(i_kind) :: n
it=ntguessig
mass=zero_quad
rcon=(one_quad/(two_quad*real(nlon,r_quad)))**2
mm1=mype+1
do n=1,nbins
! Retrieve pointers
! Simply return if any pointer not found
ier=0; icw=0; iql=0; iqi=0
call gsi_bundlegetpointer(sval(n),'q' ,sq, istatus);ier=istatus+ier
call gsi_bundlegetpointer(sval(n),'cw',sc, istatus);icw=istatus+icw
call gsi_bundlegetpointer(sval(n),'ql',sql,istatus);iql=istatus+iql
call gsi_bundlegetpointer(sval(n),'qi',sqi,istatus);iqi=istatus+iqi
call gsi_bundlegetpointer(sval(n),'ps',sp, istatus);ier=istatus+ier
if(ier+icw*(iql+iqi)/=0)then
if (mype==0) write(6,*)'intjcpdry: checking ier+icw*(iql+iqi)=', ier+icw*(iql+iqi)
return
end if
! Calculate mean surface pressure contribution in subdomain
do j=2,lon2-1
do i=2,lat2-1
ii=istart(mm1)+i-2
mass(n)=mass(n)+sp(i,j)*wgtlats(ii)
end do
end do
mass2(:)=zero_quad
! Calculate water-vapor contribution to total mass
!$omp parallel do schedule(dynamic,1) private(k,j,i,ii,con)
do k=1,nsig
do j=2,lon2-1
do i=2,lat2-1
ii=istart(mm1)+i-2
con = (ges_prsi(i,j,k,it)-ges_prsi(i,j,k+1,it))*wgtlats(ii)
mass2(k)=mass2(k)+sq(i,j,k)*con
if (icw==0) then
mass2(k)=mass2(k)+sc(i,j,k)*con
else
mass2(k)=mass2(k)+(sql(i,j,k)+sqi(i,j,k))*con
endif
end do
end do
end do
do k=1,nsig
mass(nbins+n)=mass(nbins+n)+mass2(k)
end do
end do
! First, use MPI to get global mean increment
call mpl_allreduce(2*nbins,qpvals=mass)
do n=1,nbins
ier=0; icw=0; iql=0; iqi=0
call gsi_bundlegetpointer(rval(n),'q' ,rq, istatus);ier=istatus+ier
call gsi_bundlegetpointer(rval(n),'cw',rc, istatus);icw=istatus+icw
call gsi_bundlegetpointer(rval(n),'ql',rql,istatus);iql=istatus+iql
call gsi_bundlegetpointer(rval(n),'qi',rqi,istatus);iqi=istatus+iqi
call gsi_bundlegetpointer(rval(n),'ps',rp, istatus);ier=istatus+ier
if(ier+icw*(iql+iqi)/=0)then
if (mype==0) write(6,*)'intjcpdry: checking ier+icw*(iql+iqi)=', ier+icw*(iql+iqi)
return
end if
! Remove water-vapor contribution to get incremental dry ps
! if (mype==0) write(6,*)'intjcpdry: total mass =', mass(n)
! if (mype==0) write(6,*)'intjcpdry: wv mass =', mass(nbins+n)
dmass=bamp_jcpdry*(mass(n)-mass(nbins+n))*rcon
if(present(pjc)) then
pjc = dmass*dmass
endif
! Calculate mean surface pressure contribution in subdomain
do j=2,lon2-1
do i=2,lat2-1
ii=istart(mm1)+i-2
rp(i,j)=rp(i,j)+dmass*wgtlats(ii)
end do
end do
! Remove water to get incremental dry ps
!$omp parallel do schedule(dynamic,1) private(k,j,i,ii,con)
do k=1,nsig
do j=2,lon2-1
do i=2,lat2-1
ii=istart(mm1)+i-2
con = dmass*(ges_prsi(i,j,k,it)-ges_prsi(i,j,k+1,it))*wgtlats(ii)
rq(i,j,k)=rq(i,j,k)-con
if (icw==0)then
rc(i,j,k)=rc(i,j,k)-con
else
rql(i,j,k)=rql(i,j,k)-con
rqi(i,j,k)=rqi(i,j,k)-con
endif
end do
end do
end do
end do
return
end subroutine intjcpdry
subroutine intjcpdry1(sval,nbins,mass)
!$$$ subprogram documentation block
! . . . .
! subprogram: intjcpdry1 mean dry ps conservation: part 1
! prgmmr: kleist org: np23 date: 2009-07-07
!
! abstract: calculate contribution to gradient from mass conservation: part 1
!
! program history log:
! 2009-07-07 kleist
! 2010-05-13 todling - update to use gsi_bundle
! 2010-05-25 derber - modify to minimize number of communications
! 2010-11-03 treadon - correct i,j loop limits for rq,rc update
! 2011-11-01 eliu - add handling for ql & qi increments and search directions
! 2013-05-05 todling - separate dry mass from the rest (zero-diff change)
! collapse two verions of this routine into one (add opt arg)
! 2014-12-02 derber - fix comments - break up into 2 parts to minimize
! 2018-04-16 eliu - add controbution from precipitating hydrometeors
! communications
!
! input argument list:
! sval - current increments
! nbins - number of observation bins
!
! output argument list:
! mass - output mass vector
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use mpimod, only: mype
use gridmod, only: lat2,lon2,nsig,wgtlats,istart
use guess_grids, only: ges_prsi,ntguessig
use gsi_metguess_mod, only: gsi_metguess_get
implicit none
! Declare passed variables
type(gsi_bundle),intent(in ),dimension(nbins) :: sval
integer(i_kind),intent(in) :: nbins
real(r_quad),dimension(2*nbins),intent(out) :: mass ! 1=dry;2=wv
! Declare local variables
real(r_quad),dimension(nsig) :: mass2
real(r_quad) con
integer(i_kind) i,j,k,it,ii,mm1,icw,iql,iqi
integer(i_kind) iq,iqr,iqs,iqg,iqh,ips
real(r_kind),pointer,dimension(:,:,:) :: sq =>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sc =>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sql=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sqi=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sqr=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sqs=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sqg=>NULL()
real(r_kind),pointer,dimension(:,:,:) :: sqh=>NULL()
real(r_kind),pointer,dimension(:,:) :: sp =>NULL()
integer(i_kind) :: n
it=ntguessig
mass=zero_quad
mm1=mype+1
do n=1,nbins
! Retrieve pointers
! Simply return if any pointer not found
call gsi_bundlegetpointer(sval(n),'q' ,sq, iq )
call gsi_bundlegetpointer(sval(n),'cw',sc, icw )
call gsi_bundlegetpointer(sval(n),'ql',sql, iql )
call gsi_bundlegetpointer(sval(n),'qi',sqi, iqi )
call gsi_bundlegetpointer(sval(n),'qr',sqr, iqr )
call gsi_bundlegetpointer(sval(n),'qs',sqs, iqs )
call gsi_bundlegetpointer(sval(n),'qg',sqg, iqg )
call gsi_bundlegetpointer(sval(n),'qh',sqh, iqh )
call gsi_bundlegetpointer(sval(n),'ps',sp, ips )
if ( iq*ips/=0 .or. icw*(iql+iqi)/=0 ) then
if (mype==0) write(6,*)'intjcpdry1: warning - missing some required variables'
if (mype==0) write(6,*)'intjcpdry1: constraint for dry mass constraint not performed'
return
end if
! Calculate mean surface pressure contribution in subdomain
do j=2,lon2-1
do i=2,lat2-1
ii=istart(mm1)+i-2
mass(n)=mass(n)+sp(i,j)*wgtlats(ii)
end do
end do
mass2(:)=zero_quad
! Calculate water-vapor contribution to total mass
!$omp parallel do schedule(dynamic,1) private(k,j,i,ii,con)
do k=1,nsig
do j=2,lon2-1
do i=2,lat2-1
ii=istart(mm1)+i-2
con = (ges_prsi(i,j,k,it)-ges_prsi(i,j,k+1,it))*wgtlats(ii)
mass2(k)=mass2(k)+sq(i,j,k)*con
if (icw==0) then
mass2(k)=mass2(k)+sc(i,j,k)*con
else
mass2(k)=mass2(k)+(sql(i,j,k)+sqi(i,j,k))*con
if (iqr==0) mass2(k)=mass2(k)+sqr(i,j,k)*con
if (iqs==0) mass2(k)=mass2(k)+sqs(i,j,k)*con
if (iqg==0) mass2(k)=mass2(k)+sqg(i,j,k)*con
if (iqh==0) mass2(k)=mass2(k)+sqh(i,j,k)*con
endif
end do
end do
end do
do k=1,nsig
mass(nbins+n)=mass(nbins+n)+mass2(k)
end do
end do
return
end subroutine intjcpdry1
subroutine intjcpdry2(rval,nbins,mass,pjc)
!$$$ subprogram documentation block
! . . . .
! subprogram: intjcpdry2 dry ps conservation: part 2
! prgmmr: kleist org: np23 date: 2009-07-07
!
! abstract: calculate contribution to gradient from mass conservation: part 2
!
! program history log:
! 2009-07-07 kleist
! 2010-05-13 todling - update to use gsi_bundle
! 2010-05-25 derber - modify to minimize number of communications
! 2010-11-03 treadon - correct i,j loop limits for rq,rc update
! 2011-11-01 eliu - add handling for ql & qi increments and search directions
! 2013-05-05 todling - separate dry mass from the rest (zero-diff change)
! collapse two verions of this routine into one (add opt arg)
! 2014-12-02 derber - fix comments - break up into 2 parts to minimize
! 2018-04-16 eliu - add controbution from precipitating hydrometeors
! communications
!
! input argument list:
! nbins - number of observation bins
! rval - input gradient
! mass - input mass vector
!
! output argument list:
! rval - input value plus contribution to gradient
! pjc - optional -- penalty from mass term
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$
use mpimod, only: mype
use gridmod, only: lat2,lon2,nsig,wgtlats,nlon,istart
use guess_grids, only: ges_prsi,ntguessig
use jcmod, only: bamp_jcpdry
use gsi_metguess_mod, only: gsi_metguess_get
implicit none
! Declare passed variables
type(gsi_bundle),intent(inout),dimension(nbins) :: rval
integer(i_kind),intent(in) :: nbins
real(r_quad),dimension(2*nbins),intent(in) :: mass ! 1=dry;2=wv
real(r_quad) ,intent( out),optional :: pjc