-
Notifications
You must be signed in to change notification settings - Fork 1
/
iotest.for
149 lines (121 loc) · 4.41 KB
/
iotest.for
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
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c Test routines for I/O for the ABL.for model
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
PROGRAM test_io
USE io
IMPLICIT NONE
CHARACTER(LEN=256) :: fname, lon_name, lat_name, mask_name
INTEGER :: mgr, ngr, i, j, k
REAL, ALLOCATABLE, DIMENSION(:,:) :: rlat, rlon, output2D
REAL, ALLOCATABLE, DIMENSION(:,:,:) :: output3D
INTEGER, ALLOCATABLE, DIMENSION(:,:) :: mask
TYPE(datetime) :: time
TYPE(input_var) :: mslp
type(output_file) :: output_test, interp_out
! Test reading of grid
fname = "grid.nc"
lon_name = "plon"
lat_name = "plat"
mask_name = "mask"
CALL read_grid(fname, lon_name, lat_name, mask_name, mgr, ngr,
1 rlon, rlat,mask)
print *, "Read ", trim(fname)
print *, "mgr = ", mgr
print *, "ngr = ", ngr
print *, "maxval(rlon) = ", maxval(rlon),
1 "minval(rlon) = ", minval(rlon)
print *, "maxval(rlat) = ", maxval(rlat),
1 "minval(rlat) = ", minval(rlat)
do i = 1, mgr, mgr/100
do j = 1, ngr, ngr/100
if ( mask(i,j) .eq. 0) then
write(6, "(A)", advance="no") "X"
else
write(6, "(A)", advance="no") " "
end if
end do
write(6, *)
end do
! Test the output routines
! Create file and initialise variables
! Need initial time :/
time = datetime(2015,12,15,12,15,12,15)
print *, time%isoformat()
fname = "out_test.nc"
call output_test%init(fname, mgr, ngr, mask, rlon, rlat, nz=10)
call output_test%add_var("test2D",
1 long_name="test_for_a_2D_case",
1 standard_name="test for a 2D case",
1 units = "-")
call output_test%add_var("test3D", zdim="nz",
1 long_name="test_for_a_3D_case",
1 standard_name="test for a 3D case",
1 units = "-")
allocate(output2D(size(rlon,1),size(rlon,2)))
allocate(output3D(size(rlon,1),size(rlon,2),10))
! First step and output
output2D = 0.0
output3D = 0.0
do i = 2, 10
output3D(:,:,i) = output3D(:,:,i-1) + 0.1
enddo
call output_test%append_time(time)
call output_test%append_var("test2D", output2D)
call output_test%append_var("test3D", output3D)
! Second step and output - using the absolute time for
! append_netCDF_time
output2D = 1.0
output3D = 1.0
do i = 2, 10
output3D(:,:,i) = output3D(:,:,i-1) + 0.1
enddo
time = time + timedelta(days=1)
call output_test%append_time(time)
call output_test%append_var("test2D", output2D)
call output_test%append_var("test3D", output3D)
! Third step and output
output2D = 2.0
output3D = 2.0
do i = 2, 10
output3D(:,:,i) = output3D(:,:,i-1) + 0.1
enddo
time = time + timedelta(days=1)
call output_test%append_time(time)
call output_test%append_var("test2D", output2D)
call output_test%append_var("test3D", output3D)
! Test the loading of data and interpolation
time = datetime(2007,08,21)
call mslp%init("msl", "data", rlon, rlat, time, "ERA")
call mslp%read_input(time, "ERA")
! Write the intrapolation results to file
fname = "msl_interp.nc"
print *, trim(fname)
call interp_out%init(fname, mgr, ngr, mask, rlon, rlat)
call interp_out%add_var("msl",
1 long_name="interpolated_msl",
2 standard_name="interpolated msl",
3 units="Pa",
4 missing_value = 0.)
call interp_out%append_time(time)
! Apply the mask
do i = 1, mgr
do j = 1, ngr
output2D(i,j) = mask(i,j) * mslp%get_point(i,j)
enddo
enddo
call interp_out%append_var("msl", output2D)
! One more time ...
do k=1, 125
time = time + timedelta(hours=1)
call mslp%read_input(time, "ERA")
call interp_out%append_time(time)
do i = 1, mgr
do j = 1, ngr
output2D(i,j) = mask(i,j) * mslp%get_point(i,j)
enddo
enddo
call interp_out%append_var("msl", output2D)
enddo
END PROGRAM test_io