forked from jkbk2004/stochastic_physics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectral_transforms.F90
2381 lines (2186 loc) · 73.5 KB
/
spectral_transforms.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
!>@brief The module 'spectral_transforms' contains the subroutines spec_to_four and four_to_grid
module spectral_transforms
use kinddef
use mpi_wrapper, only : mp_alltoall,mype,npes
use stochy_internal_state_mod, only : stochy_internal_state
use stochy_namelist_def
private
public :: spec_to_four, four_to_grid,dozeuv_stochy,dezouv_stochy
public :: initialize_spectral,stochy_la2ga
integer, public :: ls_dim, &
ls_max_node, &
len_trie_ls, &
len_trio_ls, &
jcap,latg,latg2, &
skeblevs,levs,lnt, &
lonf,lonfx
!
integer, public, allocatable :: lat1s_a(:), lon_dims_a(:)
real(kind_dbl_prec), public, allocatable, dimension(:) :: colrad_a, wgt_a, rcs2_a, &
sinlat_a, coslat_a
contains
!>@brief The subrountine 'spec_to_four' converts the spherical harmonics to fourier coefficients
!>@details This code is taken from the legacy spectral GFS
subroutine spec_to_four(flnev,flnod,plnev,plnod, &
ls_node, &
workdim,four_gr, &
ls_nodes,max_ls_nodes, &
lats_nodes,global_lats, &
lats_node,ipt_lats_node, &
nvars )
!
implicit none
!
external esmf_dgemm
!
integer, intent(in) :: nvars
real(kind=kind_dbl_prec) flnev(len_trie_ls,2*nvars)
real(kind=kind_dbl_prec) flnod(len_trio_ls,2*nvars)
!
real(kind=kind_dbl_prec) plnev(len_trie_ls,latg2)
real(kind=kind_dbl_prec) plnod(len_trio_ls,latg2)
!
integer ls_node(ls_dim,3)
!
!cmr ls_node(1,1) ... ls_node(ls_max_node,1) : values of L
!cmr ls_node(1,2) ... ls_node(ls_max_node,2) : values of jbasev
!cmr ls_node(1,3) ... ls_node(ls_max_node,3) : values of jbasod
!
! local scalars
! -------------
!
integer j, l, lat, lat1, n, kn, n2,indev,indod
!
! local arrays
! ------------
!
real(kind=kind_dbl_prec), dimension(nvars*2,latg2) :: apev, apod
! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
!
integer workdim, lats_node, ipt_lats_node
!
real(kind=kind_dbl_prec) four_gr(lonf+2,nvars,workdim)
!
integer ls_nodes(ls_dim,npes)
integer, dimension(npes) :: max_ls_nodes, lats_nodes
integer, dimension(latg) :: global_lats
real(kind=4),target,dimension(2,nvars,ls_dim*workdim,npes):: workr,works
real(kind=4),pointer:: work1dr(:),work1ds(:)
integer, dimension(npes) :: kpts, kptr, sendcounts, recvcounts, sdispls
!
integer ilat,ipt_ls, lmax,lval,jj,nv
integer node,arrsz,my_pe,nvar
integer ilat_list(npes) ! for OMP buffer copy
!
! statement functions
! -------------------
!
integer indlsev, jbasev, indlsod, jbasod
!
include 'function_indlsev'
include 'function_indlsod'
!
real(kind=kind_dbl_prec), parameter :: cons0=0.0d0, cons1=1.0d0
!
! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
!
n2=2*nvars
arrsz=n2*ls_dim*workdim*npes
kpts = 0
!
do j = 1, ls_max_node ! start of do j loop #####################
!
l = ls_node(j,1)
jbasev = ls_node(j,2)
jbasod = ls_node(j,3)
indev = indlsev(l,l)
indod = indlsod(l+1,l)
!
lat1 = lat1s_a(l)
! compute the even and odd components of the fourier coefficients
!
! compute the sum of the even real terms for each level
! compute the sum of the even imaginary terms for each level
!
call esmf_dgemm('t', 'n', n2, latg2-lat1+1, (jcap+3-l)/2, &
cons1, flnev(indev,1), len_trie_ls, plnev(indev,lat1), &
len_trie_ls, cons0, apev(1,lat1), n2 )
!
! compute the sum of the odd real terms for each level
! compute the sum of the odd imaginary terms for each level
!
call esmf_dgemm('t', 'n', n2, latg2-lat1+1, (jcap+2-l)/2, &
cons1, flnod(indod,1), len_trio_ls, plnod(indod,lat1), &
len_trio_ls, cons0, apod(1,lat1), n2 )
!
!cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
!
! compute the fourier coefficients for each level
! -----------------------------------------------
!
ilat_list(1) = 0
do node = 1, npes - 1
ilat_list(node+1) = ilat_list(node) + lats_nodes(node)
end do
!$omp parallel do private(node,jj,ilat,lat,ipt_ls,nvar,kn,n2)
do node=1,npes
do jj=1,lats_nodes(node)
ilat = ilat_list(node) + jj
lat = global_lats(ilat)
ipt_ls = min(lat,latg-lat+1)
if ( ipt_ls >= lat1s_a(ls_nodes(j,mype+1)) ) then
kpts(node) = kpts(node) + 1
kn = kpts(node)
!
if ( lat <= latg2 ) then
! northern hemisphere
do nvar=1,nvars
n2 = nvar + nvar
works(1,nvar,kn,node) = apev(n2-1,ipt_ls) + apod(n2-1,ipt_ls)
works(2,nvar,kn,node) = apev(n2,ipt_ls) + apod(n2,ipt_ls)
enddo
else
! southern hemisphere
do nvar=1,nvars
n2 = nvar + nvar
works(1,nvar,kn,node) = apev(n2-1,ipt_ls) - apod(n2-1,ipt_ls)
works(2,nvar,kn,node) = apev(n2,ipt_ls) - apod(n2,ipt_ls)
enddo
endif
endif
enddo
enddo
!
enddo ! end of do j loop #######################################
!
kptr = 0
do node=1,npes
do l=1,max_ls_nodes(node)
lval = ls_nodes(l,node)+1
do j=1,lats_node
lat = global_lats(ipt_lats_node-1+j)
if ( min(lat,latg-lat+1) >= lat1s_a(lval-1) ) then
kptr(node) = kptr(node) + 1
endif
enddo
enddo
enddo
!
!
!$omp parallel do private(node)
do node=1,npes
sendcounts(node) = kpts(node) * n2
recvcounts(node) = kptr(node) * n2
sdispls(node) = (node-1) * n2 * ls_dim * workdim
end do
work1dr(1:arrsz)=>workr
work1ds(1:arrsz)=>works
call mp_alltoall(work1ds, sendcounts, sdispls, &
work1dr,recvcounts,sdispls)
nullify(work1dr)
nullify(work1ds)
!$omp parallel do private(j,lat,lmax,nvar,lval,nv)
do j=1,lats_node
lmax = min(jcap,lonf/2)
n2 = lmax + lmax + 3
if ( n2 <= lonf+2 ) then
do nv=1,nvars
do lval = n2, lonf+2
four_gr(lval,nv,j) = cons0
enddo
enddo
endif
enddo
!
kptr = 0
!!
!$omp parallel do private(node,l,lval,j,lat,nvar,kn,n2)
do node=1,npes
do l=1,max_ls_nodes(node)
lval = ls_nodes(l,node)+1
n2 = lval + lval
do j=1,lats_node
lat = global_lats(ipt_lats_node-1+j)
if ( min(lat,latg-lat+1) >= lat1s_a(lval-1) ) then
kptr(node) = kptr(node) + 1
kn = kptr(node)
do nv=1,nvars
four_gr(n2-1,nv,j) = workr(1,nv,kn,node)
four_gr(n2, nv,j) = workr(2,nv,kn,node)
enddo
endif
enddo
enddo
enddo
!
return
end subroutine spec_to_four
!>@brief The subroutine 'four_to_grid' calculate real values form fourrier coefficients
!>@details This code is taken from the legacy spectral GFS
subroutine four_to_grid(syn_gr_a_1,syn_gr_a_2, lon_dim_coef,nvars)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
!!
integer, intent(in) :: nvars
real(kind=kind_dbl_prec) syn_gr_a_1(lon_dim_coef,nvars)
real(kind=kind_dbl_prec) syn_gr_a_2(lonf,nvars)
integer lon_dim_coef
!________________________________________________________
real(kind=kind_dbl_prec) aux1crs(44002)
integer init
!________________________________________________________
init = 1
call dcrft_stochy(init, &
syn_gr_a_1(:,:) ,lon_dim_coef, &
syn_gr_a_2(:,:) ,lonf, &
lonf, nvars, &
aux1crs,22000, &
aux1crs(22001),20000)
init = 0
call dcrft_stochy(init, &
syn_gr_a_1(:,:) ,lon_dim_coef, &
syn_gr_a_2(:,:) ,lonf, &
lonf, nvars, &
aux1crs,22000, &
aux1crs(22001),20000)
return
end
SUBROUTINE dcrft_stochy(init,x,ldx,y,ldy,n,nvars, table,n1,wrk,n2)
implicit none
integer ,intent(in) :: ldx,ldy,n,nvars
integer init,n1,n2,i,j
real(kind_dbl_prec) x(ldx,nvars),y(ldy,nvars),table(44002),wrk
IF (init.ne.0) THEN
CALL rffti_stochy(n,table)
ELSE
DO j=1,nvars
y(1,j)=x(1,j)
DO i=2,n
y(i,j)=x(i+1,j)
ENDDO
CALL rfftb_stochy(n,y(:,j),table)
ENDDO
ENDIF
RETURN
END
! ******************************************************************
! ******************************************************************
! ****** ******
! ****** FFTPACK ******
! ****** ******
! ******************************************************************
! ******************************************************************
!
SUBROUTINE RFFTB_STOCHY (N,R,WSAVE)
implicit none
real(kind_dbl_prec), intent(inout) :: R(:)
real(kind_dbl_prec), intent(inout) :: WSAVE(44002)
integer :: N
IF (N .EQ. 1) RETURN
CALL RFFTB1_STOCHY (N,R,WSAVE,WSAVE(N+1:),WSAVE(2*N+1:))
RETURN
END
SUBROUTINE RFFTI_STOCHY (N,WSAVE)
implicit none
REAL(kind_dbl_prec), intent(inout) :: WSAVE(44002)
integer :: N
IF (N .EQ. 1) RETURN
CALL RFFTI1_STOCHY (N,WSAVE(N+1:),WSAVE(2*N+1:))
RETURN
END
SUBROUTINE RFFTB1_STOCHY (N,C,CH,WA,RFAC)
implicit none
integer, intent(in) :: N
real(kind_dbl_prec), intent(inout) :: CH(44002)
real(kind_dbl_prec), intent(inout) :: C(:)
real(kind_dbl_prec), intent(inout) :: WA(:)
real(kind_dbl_prec), intent(inout) :: RFAC(:)
integer :: NF,NA,L1,IW,IP,L2,IDO,IDL1,IX2,IX3,IX4
integer :: K1,I
NF = INT(RFAC(2))
NA = 0
L1 = 1
IW = 1
DO 116 K1=1,NF
IP = INT(RFAC(K1+2))
L2 = IP*L1
IDO = N/L2
IDL1 = IDO*L1
IF (IP .NE. 4) GO TO 103
IX2 = IW+IDO
IX3 = IX2+IDO
IF (NA .NE. 0) GO TO 101
CALL RADB4_STOCHY (IDO,L1,C(1:4*IDO*L1),CH(1:4*IDO*L1),WA(IW:),WA(IX2:),WA(IX3:))
GO TO 102
101 CALL RADB4_STOCHY (IDO,L1,CH(1:4*IDO*L1),C(1:4*IDO*L1),WA(IW:),WA(IX2:),WA(IX3:))
102 NA = 1-NA
GO TO 115
103 IF (IP .NE. 2) GO TO 106
IF (NA .NE. 0) GO TO 104
CALL RADB2_STOCHY (IDO,L1,C,CH,WA(IW:))
GO TO 105
104 CALL RADB2_STOCHY (IDO,L1,CH,C,WA(IW:))
105 NA = 1-NA
GO TO 115
106 IF (IP .NE. 3) GO TO 109
IX2 = IW+IDO
IF (NA .NE. 0) GO TO 107
CALL RADB3_STOCHY (IDO,L1,C,CH,WA(IW:),WA(IX2:))
GO TO 108
107 CALL RADB3_STOCHY (IDO,L1,CH,C,WA(IW:),WA(IX2:))
108 NA = 1-NA
GO TO 115
109 IF (IP .NE. 5) GO TO 112
IX2 = IW+IDO
IX3 = IX2+IDO
IX4 = IX3+IDO
IF (NA .NE. 0) GO TO 110
CALL RADB5_STOCHY (IDO,L1,C,CH,WA(IW:),WA(IX2:),WA(IX3:),WA(IX4:))
GO TO 111
110 CALL RADB5_STOCHY (IDO,L1,CH,C,WA(IW:),WA(IX2:),WA(IX3:),WA(IX4:))
111 NA = 1-NA
GO TO 115
112 IF (NA .NE. 0) GO TO 113
CALL RADBG_STOCHY (IDO,IP,L1,IDL1,C,C,C,CH,CH,WA(IW:))
GO TO 114
113 CALL RADBG_STOCHY (IDO,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW:))
114 IF (IDO .EQ. 1) NA = 1-NA
115 L1 = L2
IW = IW+(IP-1)*IDO
116 CONTINUE
IF (NA .EQ. 0) RETURN
DO 117 I=1,N
C(I) = CH(I)
117 CONTINUE
RETURN
END
SUBROUTINE RFFTI1_STOCHY (N,WA,RFAC)
implicit none
integer, intent(in) :: N
REAL(kind_dbl_prec), intent(inout) :: WA(:)
REAL(kind_dbl_prec), intent(inout) :: RFAC(:)
integer :: NTRYH(4)
integer :: NL,NF, I, J, NQ,NR,LD,FI,IS,ID,L1,L2,IP
integer :: NTRY, NFM1, K1,II, IB, IDO, IPM, IC
REAL(kind_dbl_prec), parameter :: TPI=6.28318530717959
real(kind_dbl_prec) :: ARG,ARGLD,ARGH, TI2,TI4
DATA NTRYH(:) /4,2,3,5/
NL = N
NF = 0
J = 0
101 J = J+1
IF ( (J-4) .LE. 0) THEN
GOTO 102
ELSE
GOTO 103
ENDIF
102 NTRY = NTRYH(J)
GO TO 104
103 NTRY = NTRY+2
104 NQ = NL/NTRY
NR = NL-NTRY*NQ
IF (NR.EQ.0) THEN
GO TO 105
ELSE
GO TO 101
ENDIF
105 NF = NF+1
RFAC(NF+2) = FLOAT(NTRY)
NL = NQ
IF (NTRY .NE. 2) GO TO 107
IF (NF .EQ. 1) GO TO 107
DO 106 I=2,NF
IB = NF-I+2
RFAC(IB+2) = RFAC(IB+1)
106 CONTINUE
RFAC(3) = 2.
107 IF (NL .NE. 1) GO TO 104
RFAC(1) = FLOAT(N)
RFAC(2) = FLOAT(NF)
ARGH = TPI/FLOAT(N)
IS = 0
NFM1 = NF-1
L1 = 1
IF (NFM1 .EQ. 0) RETURN
!OCL NOVREC
DO 110 K1=1,NFM1
IP = INT(RFAC(K1+2))
LD = 0
L2 = L1*IP
IDO = N/L2
IPM = IP-1
DO 109 J=1,IPM
LD = LD+L1
I = IS
ARGLD = FLOAT(LD)*ARGH
FI = 0
!OCL SCALAR
DO 108 II=3,IDO,2
I = I+2
FI = FI+1
ARG = FI*ARGLD
WA(I-1) = COS(ARG)
WA(I) = SIN(ARG)
108 CONTINUE
IS = IS+IDO
109 CONTINUE
L1 = L2
110 CONTINUE
RETURN
END
SUBROUTINE RADB2_STOCHY (IDO,L1,CC,CH,WA1)
implicit none
integer, intent(in) :: IDO
integer, intent(in) :: L1
real(kind_dbl_prec), intent(inout) :: CC(IDO,2,L1)
real(kind_dbl_prec), intent(inout) :: CH(IDO,L1,2)
real(kind_dbl_prec), intent(inout) :: WA1(:)
integer :: K,I,IC,IDP2
real(kind_dbl_prec) :: TR2,TI2
DO 101 K=1,L1
CH(1,K,1) = CC(1,1,K)+CC(IDO,2,K)
CH(1,K,2) = CC(1,1,K)-CC(IDO,2,K)
101 CONTINUE
IF ( (IDO-2) .LT. 0) THEN
GO TO 107
ELSE IF (( IDO-2).EQ. 0)THEN
GO TO 105
ELSE
GO TO 102
ENDIF
102 IDP2 = IDO+2
!OCL NOVREC
DO 104 K=1,L1
DO 103 I=3,IDO,2
IC = IDP2-I
CH(I-1,K,1) = CC(I-1,1,K)+CC(IC-1,2,K)
TR2 = CC(I-1,1,K)-CC(IC-1,2,K)
CH(I,K,1) = CC(I,1,K)-CC(IC,2,K)
TI2 = CC(I,1,K)+CC(IC,2,K)
CH(I-1,K,2) = WA1(I-2)*TR2-WA1(I-1)*TI2
CH(I,K,2) = WA1(I-2)*TI2+WA1(I-1)*TR2
103 CONTINUE
104 CONTINUE
IF (MOD(IDO,2) .EQ. 1) RETURN
105 DO 106 K=1,L1
CH(IDO,K,1) = CC(IDO,1,K)+CC(IDO,1,K)
CH(IDO,K,2) = -(CC(1,2,K)+CC(1,2,K))
106 CONTINUE
107 RETURN
END
SUBROUTINE RADB3_STOCHY (IDO,L1,CC,CH,WA1,WA2)
implicit none
integer, intent(in) :: IDO,L1
real(kind_dbl_prec), intent(inout) :: CC(IDO,3,L1)
real(kind_dbl_prec), intent(inout) :: CH(IDO,L1,3)
real(kind_dbl_prec), intent(inout) :: WA1(:)
real(kind_dbl_prec), intent(inout) :: WA2(:)
REAL(kind_dbl_prec), parameter :: TAUR= -.5
REAL(kind_dbl_prec), parameter :: TAUI=.866025403784439
integer :: I,K,IDP2,IC
real(kind_dbl_prec) :: TR2,CR2,TI1,CI2,CR3,CI3,DR2,DR3,DI2,DI3
real(kind_dbl_prec) :: TI2,TI4
DO 101 K=1,L1
TR2 = CC(IDO,2,K)+CC(IDO,2,K)
CR2 = CC(1,1,K)+TAUR*TR2
CH(1,K,1) = CC(1,1,K)+TR2
CI3 = TAUI*(CC(1,3,K)+CC(1,3,K))
CH(1,K,2) = CR2-CI3
CH(1,K,3) = CR2+CI3
101 CONTINUE
IF (IDO .EQ. 1) RETURN
IDP2 = IDO+2
!OCL NOVREC
DO 103 K=1,L1
DO 102 I=3,IDO,2
IC = IDP2-I
TR2 = CC(I-1,3,K)+CC(IC-1,2,K)
CR2 = CC(I-1,1,K)+TAUR*TR2
CH(I-1,K,1) = CC(I-1,1,K)+TR2
TI2 = CC(I,3,K)-CC(IC,2,K)
CI2 = CC(I,1,K)+TAUR*TI2
CH(I,K,1) = CC(I,1,K)+TI2
CR3 = TAUI*(CC(I-1,3,K)-CC(IC-1,2,K))
CI3 = TAUI*(CC(I,3,K)+CC(IC,2,K))
DR2 = CR2-CI3
DR3 = CR2+CI3
DI2 = CI2+CR3
DI3 = CI2-CR3
CH(I-1,K,2) = WA1(I-2)*DR2-WA1(I-1)*DI2
CH(I,K,2) = WA1(I-2)*DI2+WA1(I-1)*DR2
CH(I-1,K,3) = WA2(I-2)*DR3-WA2(I-1)*DI3
CH(I,K,3) = WA2(I-2)*DI3+WA2(I-1)*DR3
102 CONTINUE
103 CONTINUE
RETURN
END
SUBROUTINE RADB4_STOCHY (IDO,L1,CC,CH,WA1,WA2,WA3)
implicit none
integer, intent(in) :: IDO,L1
real(kind_dbl_prec), intent(inout) :: CC(IDO,4,L1)
real(kind_dbl_prec), intent(inout) :: CH(IDO,L1,4)
real(kind_dbl_prec), intent(inout) :: WA1(:)
real(kind_dbl_prec), intent(inout) :: WA2(:)
real(kind_dbl_prec), intent(inout) :: WA3(:)
REAL(kind_dbl_prec), parameter :: SQRT2=1.414213562373095
integer :: I,K,IDP2,IC
real(kind_dbl_prec) :: TR1,TR2,TR3,TR4,TI1,TI2,TI3,TI4
real(kind_dbl_prec) :: CI2,CI3,CI4,CR2,CR3,CR4
DO 101 K=1,L1
TR1 = CC(1,1,K)-CC(IDO,4,K)
TR2 = CC(1,1,K)+CC(IDO,4,K)
TR3 = CC(IDO,2,K)+CC(IDO,2,K)
TR4 = CC(1,3,K)+CC(1,3,K)
CH(1,K,1) = TR2+TR3
CH(1,K,2) = TR1-TR4
CH(1,K,3) = TR2-TR3
CH(1,K,4) = TR1+TR4
101 CONTINUE
IF ( (IDO-2) .LT.0 ) THEN
GO TO 107
ELSE IF ( (IDO-2) .EQ.0 ) THEN
GO TO 105
ELSE
GO TO 102
ENDIF
102 IDP2 = IDO+2
!OCL NOVREC
DO 104 K=1,L1
DO 103 I=3,IDO,2
IC = IDP2-I
TI1 = CC(I,1,K)+CC(IC,4,K)
TI2 = CC(I,1,K)-CC(IC,4,K)
TI3 = CC(I,3,K)-CC(IC,2,K)
TR4 = CC(I,3,K)+CC(IC,2,K)
TR1 = CC(I-1,1,K)-CC(IC-1,4,K)
TR2 = CC(I-1,1,K)+CC(IC-1,4,K)
TI4 = CC(I-1,3,K)-CC(IC-1,2,K)
TR3 = CC(I-1,3,K)+CC(IC-1,2,K)
CH(I-1,K,1) = TR2+TR3
CR3 = TR2-TR3
CH(I,K,1) = TI2+TI3
CI3 = TI2-TI3
CR2 = TR1-TR4
CR4 = TR1+TR4
CI2 = TI1+TI4
CI4 = TI1-TI4
CH(I-1,K,2) = WA1(I-2)*CR2-WA1(I-1)*CI2
CH(I,K,2) = WA1(I-2)*CI2+WA1(I-1)*CR2
CH(I-1,K,3) = WA2(I-2)*CR3-WA2(I-1)*CI3
CH(I,K,3) = WA2(I-2)*CI3+WA2(I-1)*CR3
CH(I-1,K,4) = WA3(I-2)*CR4-WA3(I-1)*CI4
CH(I,K,4) = WA3(I-2)*CI4+WA3(I-1)*CR4
103 CONTINUE
104 CONTINUE
IF (MOD(IDO,2) .EQ. 1) RETURN
105 CONTINUE
DO 106 K=1,L1
TI1 = CC(1,2,K)+CC(1,4,K)
TI2 = CC(1,4,K)-CC(1,2,K)
TR1 = CC(IDO,1,K)-CC(IDO,3,K)
TR2 = CC(IDO,1,K)+CC(IDO,3,K)
CH(IDO,K,1) = TR2+TR2
CH(IDO,K,2) = SQRT2*(TR1-TI1)
CH(IDO,K,3) = TI2+TI2
CH(IDO,K,4) = -SQRT2*(TR1+TI1)
106 CONTINUE
107 RETURN
END
SUBROUTINE RADB5_STOCHY (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)
implicit none
integer, intent(in) :: L1, IDO
REAL(kind_dbl_prec) :: CC(IDO,5,L1), CH(IDO,L1,5), WA1(*), WA2(*), WA3(*), WA4(*)
REAL(kind_dbl_prec), parameter :: TR11=0.309016994374947
REAL(kind_dbl_prec), parameter :: TI11= 0.951056516295154
REAL(kind_dbl_prec), parameter :: TR12=-0.809016994374947
REAL(kind_dbl_prec), parameter :: TI12=0.587785252292473
integer :: k,IDP2,I,IC
real(kind_dbl_prec) :: &
TI5,TI4,TR2,TR3,CR2,CR3,CI5,CI4, &
TI2,TI3,TR5,TR4, &
CI2,CI3,CR5,CR4, &
DR3,DR4,DI3,DI4,DR5,DR2,DI5,DI2
DO 101 K=1,L1
TI5 = CC(1,3,K)+CC(1,3,K)
TI4 = CC(1,5,K)+CC(1,5,K)
TR2 = CC(IDO,2,K)+CC(IDO,2,K)
TR3 = CC(IDO,4,K)+CC(IDO,4,K)
CH(1,K,1) = CC(1,1,K)+TR2+TR3
CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3
CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3
CI5 = TI11*TI5+TI12*TI4
CI4 = TI12*TI5-TI11*TI4
CH(1,K,2) = CR2-CI5
CH(1,K,3) = CR3-CI4
CH(1,K,4) = CR3+CI4
CH(1,K,5) = CR2+CI5
101 CONTINUE
IF (IDO .EQ. 1) RETURN
IDP2 = IDO+2
DO 103 K=1,L1
DO 102 I=3,IDO,2
IC = IDP2-I
TI5 = CC(I,3,K)+CC(IC,2,K)
TI2 = CC(I,3,K)-CC(IC,2,K)
TI4 = CC(I,5,K)+CC(IC,4,K)
TI3 = CC(I,5,K)-CC(IC,4,K)
TR5 = CC(I-1,3,K)-CC(IC-1,2,K)
TR2 = CC(I-1,3,K)+CC(IC-1,2,K)
TR4 = CC(I-1,5,K)-CC(IC-1,4,K)
TR3 = CC(I-1,5,K)+CC(IC-1,4,K)
CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3
CH(I,K,1) = CC(I,1,K)+TI2+TI3
CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3
CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3
CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3
CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3
CR5 = TI11*TR5+TI12*TR4
CI5 = TI11*TI5+TI12*TI4
CR4 = TI12*TR5-TI11*TR4
CI4 = TI12*TI5-TI11*TI4
DR3 = CR3-CI4
DR4 = CR3+CI4
DI3 = CI3+CR4
DI4 = CI3-CR4
DR5 = CR2+CI5
DR2 = CR2-CI5
DI5 = CI2-CR5
DI2 = CI2+CR5
CH(I-1,K,2) = WA1(I-2)*DR2-WA1(I-1)*DI2
CH(I,K,2) = WA1(I-2)*DI2+WA1(I-1)*DR2
CH(I-1,K,3) = WA2(I-2)*DR3-WA2(I-1)*DI3
CH(I,K,3) = WA2(I-2)*DI3+WA2(I-1)*DR3
CH(I-1,K,4) = WA3(I-2)*DR4-WA3(I-1)*DI4
CH(I,K,4) = WA3(I-2)*DI4+WA3(I-1)*DR4
CH(I-1,K,5) = WA4(I-2)*DR5-WA4(I-1)*DI5
CH(I,K,5) = WA4(I-2)*DI5+WA4(I-1)*DR5
102 CONTINUE
103 CONTINUE
RETURN
END
SUBROUTINE RADBG_STOCHY (IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)
implicit none
INTEGER :: IDO,IP,L1,IDL1
REAL(kind_dbl_prec) :: CH(IDO,L1,IP), CC(IDO,IP,L1), C1(IDO,L1,IP), C2(IDL1,IP), &
CH2(IDL1,IP) , WA(*)
REAL(kind_dbl_prec), parameter :: TPI=6.28318530717959
REAL(kind_dbl_prec) :: ARG, DCP, DSP, AI1, AI2, AR1, AR1H, DC2, DS2, AR2, AR2H
INTEGER :: I,J,K,IK, IDP2, IPP2, IPPH, JC, J2, IC, L, IS, IDIJ, NBD, LC
ARG = TPI/FLOAT(IP)
DCP = COS(ARG)
DSP = SIN(ARG)
IDP2 = IDO+2
NBD = (IDO-1)/2
IPP2 = IP+2
IPPH = (IP+1)/2
IF (IDO .LT. L1) GO TO 103
DO K=1,L1
DO I=1,IDO
CH(I,K,1) = CC(I,1,K)
ENDDO
ENDDO
GO TO 106
103 DO 105 I=1,IDO
DO 104 K=1,L1
CH(I,K,1) = CC(I,1,K)
104 CONTINUE
105 CONTINUE
!OCL NOVREC
106 DO 108 J=2,IPPH
JC = IPP2-J
J2 = J+J
DO 107 K=1,L1
CH(1,K,J) = CC(IDO,J2-2,K)+CC(IDO,J2-2,K)
CH(1,K,JC) = CC(1,J2-1,K)+CC(1,J2-1,K)
107 CONTINUE
108 CONTINUE
IF (IDO .EQ. 1) GO TO 116
IF (NBD .LT. L1) GO TO 112
!OCL NOVREC
DO 111 J=2,IPPH
JC = IPP2-J
DO 110 K=1,L1
DO 109 I=3,IDO,2
IC = IDP2-I
CH(I-1,K,J) = CC(I-1,2*J-1,K)+CC(IC-1,2*J-2,K)
CH(I-1,K,JC) = CC(I-1,2*J-1,K)-CC(IC-1,2*J-2,K)
CH(I,K,J) = CC(I,2*J-1,K)-CC(IC,2*J-2,K)
CH(I,K,JC) = CC(I,2*J-1,K)+CC(IC,2*J-2,K)
109 CONTINUE
110 CONTINUE
111 CONTINUE
GO TO 116
112 DO 115 J=2,IPPH
JC = IPP2-J
DO 114 I=3,IDO,2
IC = IDP2-I
DO 113 K=1,L1
CH(I-1,K,J) = CC(I-1,2*J-1,K)+CC(IC-1,2*J-2,K)
CH(I-1,K,JC) = CC(I-1,2*J-1,K)-CC(IC-1,2*J-2,K)
CH(I,K,J) = CC(I,2*J-1,K)-CC(IC,2*J-2,K)
CH(I,K,JC) = CC(I,2*J-1,K)+CC(IC,2*J-2,K)
113 CONTINUE
114 CONTINUE
115 CONTINUE
116 AR1 = 1.
AI1 = 0.
!OCL NOVREC
DO 120 L=2,IPPH
LC = IPP2-L
AR1H = DCP*AR1-DSP*AI1
AI1 = DCP*AI1+DSP*AR1
AR1 = AR1H
DO 117 IK=1,IDL1
C2(IK,L) = CH2(IK,1)+AR1*CH2(IK,2)
C2(IK,LC) = AI1*CH2(IK,IP)
117 CONTINUE
DC2 = AR1
DS2 = AI1
AR2 = AR1
AI2 = AI1
!OCL NOVREC
DO 119 J=3,IPPH
JC = IPP2-J
AR2H = DC2*AR2-DS2*AI2
AI2 = DC2*AI2+DS2*AR2
AR2 = AR2H
DO 118 IK=1,IDL1
C2(IK,L) = C2(IK,L)+AR2*CH2(IK,J)
C2(IK,LC) = C2(IK,LC)+AI2*CH2(IK,JC)
118 CONTINUE
119 CONTINUE
120 CONTINUE
!OCL NOVREC
DO 122 J=2,IPPH
DO 121 IK=1,IDL1
CH2(IK,1) = CH2(IK,1)+CH2(IK,J)
121 CONTINUE
122 CONTINUE
!OCL NOVREC
DO 124 J=2,IPPH
JC = IPP2-J
DO 123 K=1,L1
CH(1,K,J) = C1(1,K,J)-C1(1,K,JC)
CH(1,K,JC) = C1(1,K,J)+C1(1,K,JC)
123 CONTINUE
124 CONTINUE
IF (IDO .EQ. 1) GO TO 132
IF (NBD .LT. L1) GO TO 128
!OCL NOVREC
DO 127 J=2,IPPH
JC = IPP2-J
DO 126 K=1,L1
DO 125 I=3,IDO,2
CH(I-1,K,J) = C1(I-1,K,J)-C1(I,K,JC)
CH(I-1,K,JC) = C1(I-1,K,J)+C1(I,K,JC)
CH(I,K,J) = C1(I,K,J)+C1(I-1,K,JC)
CH(I,K,JC) = C1(I,K,J)-C1(I-1,K,JC)
125 CONTINUE
126 CONTINUE
127 CONTINUE
GO TO 132
128 DO 131 J=2,IPPH
JC = IPP2-J
DO 130 I=3,IDO,2
DO 129 K=1,L1
CH(I-1,K,J) = C1(I-1,K,J)-C1(I,K,JC)
CH(I-1,K,JC) = C1(I-1,K,J)+C1(I,K,JC)
CH(I,K,J) = C1(I,K,J)+C1(I-1,K,JC)
CH(I,K,JC) = C1(I,K,J)-C1(I-1,K,JC)
129 CONTINUE
130 CONTINUE
131 CONTINUE
132 CONTINUE
IF (IDO .EQ. 1) RETURN
DO 133 IK=1,IDL1
C2(IK,1) = CH2(IK,1)
133 CONTINUE
DO 135 J=2,IP
DO 134 K=1,L1
C1(1,K,J) = CH(1,K,J)
134 CONTINUE
135 CONTINUE
IF (NBD .GT. L1) GO TO 139
IS = -IDO
DO 138 J=2,IP
IS = IS+IDO
IDIJ = IS
DO 137 I=3,IDO,2
IDIJ = IDIJ+2
DO 136 K=1,L1
C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)
C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)
136 CONTINUE
137 CONTINUE
138 CONTINUE
GO TO 143
139 IS = -IDO
!OCL NOVREC
DO 142 J=2,IP
IS = IS+IDO
DO 141 K=1,L1
IDIJ = IS
DO 140 I=3,IDO,2
IDIJ = IDIJ+2
C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)
C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)
140 CONTINUE
141 CONTINUE
142 CONTINUE
143 RETURN
END
!>@brief The subroutine 'dozeuv_stochy' caculates odd u and even v winds harmonics from the odd harmonics
! of divergence and even harmonics of vorticty
!>@details This code is taken from the legacy spectral GFS
subroutine dozeuv_stochy(dod,zev,uod,vev,epsedn,epsodn, snnp1ev,snnp1od,ls_node)
implicit none
real(kind_dbl_prec), intent(in) :: dod(len_trio_ls,2)
real(kind_dbl_prec), intent(in) :: zev(len_trie_ls,2)
real(kind_dbl_prec), intent(out) :: uod(len_trio_ls,2)
real(kind_dbl_prec), intent(out) :: vev(len_trie_ls,2)
real(kind_dbl_prec), intent(in) :: epsedn(len_trie_ls)
real(kind_dbl_prec), intent(in) :: epsodn(len_trio_ls)
real(kind_dbl_prec), intent(in) :: snnp1ev(len_trie_ls)
real(kind_dbl_prec), intent(in) :: snnp1od(len_trio_ls)
integer, intent(in) :: ls_node(ls_dim,3)
!cmr ls_node(1,1) ... ls_node(ls_max_node,1) : values of L
!cmr ls_node(1,2) ... ls_node(ls_max_node,2) : values of jbasev
!cmr ls_node(1,3) ... ls_node(ls_max_node,3) : values of jbasod
! locaals
integer l,locl,n
integer indev,indev1,indev2
integer indod,indod1,indod2
integer inddif
real(kind_dbl_prec) rl
real(kind_dbl_prec) cons0 !constant
integer indlsev,jbasev
integer indlsod,jbasod
real(kind_dbl_prec) rerth
include 'function2'
!......................................................................
cons0 = 0.d0 !constant
rerth =6.3712e+6 ! radius of earth (m)
do locl=1,ls_max_node
l=ls_node(locl,1)
jbasev=ls_node(locl,2)
vev(indlsev(l,l),1) = cons0 !constant
vev(indlsev(l,l),2) = cons0 !constant
enddo
!......................................................................
do locl=1,ls_max_node
l=ls_node(locl,1)
jbasev=ls_node(locl,2)
jbasod=ls_node(locl,3)
indev1 = indlsev(L,L)
if (mod(L,2).eq.mod(jcap+1,2)) then
indev2 = indlsev(jcap-1,L)
else
indev2 = indlsev(jcap ,L)
endif
indod1 = indlsod(l+1,l)
inddif = indev1 - indod1
do indev = indev1 , indev2
uod(indev-inddif,1) = -epsodn(indev-inddif) * zev(indev,1)
uod(indev-inddif,2) = -epsodn(indev-inddif) * zev(indev,2)
enddo
enddo
!......................................................................
do locl=1,ls_max_node
l=ls_node(locl,1)
jbasev=ls_node(locl,2)
jbasod=ls_node(locl,3)
indev1 = indlsev(L,L) + 1
if (mod(L,2).eq.mod(jcap+1,2)) then
indev2 = indlsev(jcap+1,L)
else
indev2 = indlsev(jcap ,L)
endif
indod1 = indlsod(l+1,l)
inddif = indev1 - indod1
do indev = indev1 , indev2
vev(indev,1) = epsedn(indev) * dod(indev-inddif,1)
vev(indev,2) = epsedn(indev) * dod(indev-inddif,2)
enddo
enddo
!......................................................................
do locl=1,ls_max_node
l=ls_node(locl,1)
jbasod=ls_node(locl,3)
indod1 = indlsod(L+1,L)
if (mod(L,2).eq.mod(jcap+1,2)) then
indod2 = indlsod(jcap ,L)
else
indod2 = indlsod(jcap+1,L) - 1
endif
if ( l .ge. 1 ) then
rl = l
do indod = indod1 , indod2
! u(l,n)=-i*l*d(l,n)/(n*(n+1))
uod(indod,1) = uod(indod,1) + rl * dod(indod,2) / snnp1od(indod)
uod(indod,2) = uod(indod,2) - rl * dod(indod,1) / snnp1od(indod)
enddo
endif
enddo
!......................................................................
do locl=1,ls_max_node
l=ls_node(locl,1)
jbasev=ls_node(locl,2)