ocnice_prep 1.14.0
Loading...
Searching...
No Matches
arrays_mod.F90
Go to the documentation of this file.
1
7module arrays_mod
8
9 use init_mod , only : nxt, nyt, nlevs, nxr, nyr
10 use init_mod , only : debug, logunit
11 use init_mod , only : vardefs
12
13 implicit none
14
15 real(kind=8), parameter :: maskspval = 9.9692099683868690d+36
16 real(kind=8), parameter :: hmin = 1.0d-3
17
18 integer :: nbilin2d
19 integer :: nbilin3d
20 integer :: nconsd2d
21
22 ! source arrays
23 real(kind=8), allocatable, dimension(:,:) :: bilin2d
24 real(kind=8), allocatable, dimension(:,:) :: consd2d
25 real(kind=8), allocatable, dimension(:,:,:) :: bilin3d
26
27 ! types
28 type(vardefs), allocatable, dimension(:) :: b2d
29 type(vardefs), allocatable, dimension(:) :: c2d
30 type(vardefs), allocatable, dimension(:) :: b3d
31
32 ! destination arrays
33 real(kind=8), allocatable, dimension(:,:) :: rgb2d
34 real(kind=8), allocatable, dimension(:,:) :: rgc2d
35 real(kind=8), allocatable, dimension(:,:,:) :: rgb3d
36
37 ! source masking arrays
38 real(kind=8), allocatable, dimension(:,:) :: mask3d
40 ! calculated eta on source grid
41 real(kind=8), allocatable, dimension(:,:) :: eta
42
43 public setup_packing
44
45contains
52 subroutine setup_packing(nvalid, vars)
53
54 type(vardefs), intent(inout) :: vars(:)
55 integer , intent(in) :: nvalid
56
57 ! local variables
58 integer :: n,i,j,k
59 character(len=20) :: subname = 'setup packing'
60 !----------------------------------------------------------------------------
61
62 if (debug)write(logunit,'(a)')'enter '//trim(subname)
63
64 nbilin2d = 0; nbilin3d = 0; nconsd2d = 0
65 do n = 1,nvalid
66 if (trim(vars(n)%var_remapmethod) == 'bilinear') then
67 if (vars(n)%var_dimen == 2) nbilin2d = nbilin2d + 1
68 if (vars(n)%var_dimen == 3) nbilin3d = nbilin3d + 1
69 end if
70 !no 3d variables w/ conservative mapping
71 if (trim(vars(n)%var_remapmethod) == 'conserve')nconsd2d = nconsd2d + 1
72 end do
73 if (debug) write(logunit,'(3(a,i4))')'bilin 2d ',nbilin2d,' bilin 3d ',nbilin3d,' conserv 2d ',nconsd2d
74
75 ! initialization required when compiled with sinit_arrays=nan
76 if (nbilin2d > 0) then
77 allocate(bilin2d(nbilin2d,nxt*nyt)); bilin2d = 0.0
78 allocate(b2d(1:nbilin2d))
79 if (debug) write(logunit,'(a)')'allocate bilin2d fields and types '
80 end if
81 if (nconsd2d > 0) then
82 allocate(consd2d(nconsd2d,nxt*nyt)); consd2d = 0.0
83 allocate(c2d(1:nconsd2d))
84 if (debug) write(logunit,'(a)')'allocate consd2d fields and types '
85 end if
86 if (nbilin3d > 0) then
87 allocate(bilin3d(nbilin3d,nlevs,nxt*nyt)); bilin3d = 0.0
88 allocate(b3d(1:nbilin3d))
89 if (debug) write(logunit,'(a)')'allocate bilin3d fields and types '
90 end if
91
92 ! create types for each packed array and fill values
93 i = 0; j = 0; k = 0
94 do n = 1,nvalid
95 if (trim(vars(n)%var_remapmethod) == 'bilinear') then
96 if (vars(n)%var_dimen == 2 .and. allocated(b2d)) then
97 i = i+1; b2d(i) = vars(n)
98 end if
99 if (vars(n)%var_dimen == 3 .and. allocated(b3d)) then
100 j = j+1; b3d(j) = vars(n)
101 end if
102 end if
103 if (trim(vars(n)%var_remapmethod) == 'conserve' .and. allocated(c2d)) then
104 k = k+1; c2d(k) = vars(n)
105 end if
106 end do
107
108 ! create arrays for remapped packed fields
109 if (nbilin2d > 0) then
110 allocate(rgb2d(nbilin2d,nxr*nyr)); rgb2d = 0.0
111 end if
112 if (nconsd2d > 0) then
113 allocate(rgc2d(nconsd2d,nxr*nyr)); rgc2d = 0.0
114 end if
115 if (nbilin3d > 0) then
116 allocate(rgb3d(nbilin3d,nlevs,nxr*nyr)); rgb3d = 0.0
117 end if
118 if (debug)write(logunit,'(a)')'exit '//trim(subname)
119
120 end subroutine setup_packing
121end module arrays_mod