@@ -30,10 +30,12 @@ program update_mpas_states
30
30
get_time, get_date, operator (/= )
31
31
use model_mod, only : static_init_model, &
32
32
get_model_size, &
33
- get_analysis_time, update_u_from_reconstruct
33
+ get_analysis_time, update_u_from_reconstruct, &
34
+ use_increments_for_u_update, uv_cell_to_edges
34
35
35
36
use state_structure_mod, only : get_num_variables, get_variable_name, &
36
- get_variable_size, get_varid_from_varname
37
+ get_variable_size, get_varid_from_varname, &
38
+ get_dim_lengths
37
39
38
40
use netcdf_utilities_mod, only : nc_open_file_readonly, &
39
41
nc_open_file_readwrite, &
@@ -62,6 +64,10 @@ program update_mpas_states
62
64
real (r8 ), allocatable :: variable(:)
63
65
type (time_type) :: model_time
64
66
type (time_type) :: state_time
67
+ integer :: dims(2 ) ! (nVertLevels, nEdges | nCells)
68
+ real (r8 ), allocatable :: u(:,:), ucell(:,:), vcell(:,:)
69
+ real (r8 ), allocatable :: ucell_dart(:,:), vcell_dart(:,:), increments(:,:)
70
+ integer :: dom_id = 1 ! HK @todo
65
71
!- ---------------------------------------------------------------------
66
72
67
73
call initialize_utilities(progname= source)
@@ -85,8 +91,8 @@ program update_mpas_states
85
91
next_outfile = get_next_filename(update_output_file_list, filenum)
86
92
if (next_infile == ' ' .or. next_outfile == ' ' ) exit fileloop
87
93
88
- ncAnlID = nc_open_file_readonly(next_infile, ' update_mpas_states - open readonly' )
89
- ncBckID = nc_open_file_readwrite(next_outfile, ' update_mpas_states - open readwrite' )
94
+ ncAnlID = nc_open_file_readonly(next_infile, ' update_mpas_states - open readonly' ) ! analysis from DART
95
+ ncBckID = nc_open_file_readwrite(next_outfile, ' update_mpas_states - open readwrite' ) ! background, original mpas file
90
96
91
97
model_time = get_analysis_time(ncBckID, next_outfile)
92
98
state_time = get_analysis_time(ncAnlID, next_infile)
@@ -105,24 +111,81 @@ program update_mpas_states
105
111
106
112
allocate (variable(get_variable_size(1 , i)))
107
113
108
- if (get_variable_name(1 ,i) == ' uReconstructZonal' .or. &
109
- get_variable_name(1 ,i) == ' uReconstructMeridional' .or. &
110
- get_variable_name(1 ,i) == ' u' ) cycle varloop
114
+ if (get_variable_name(dom_id ,i) == ' uReconstructZonal' .or. &
115
+ get_variable_name(dom_id ,i) == ' uReconstructMeridional' .or. &
116
+ get_variable_name(dom_id ,i) == ' u' ) cycle varloop
111
117
112
- call nc_get_variable(ncAnlID, get_variable_name(1 ,i), variable)
113
- call nc_put_variable(ncBckID, get_variable_name(1 ,i), variable)
118
+ call nc_get_variable(ncAnlID, get_variable_name(dom_id ,i), variable)
119
+ call nc_put_variable(ncBckID, get_variable_name(dom_id ,i), variable)
114
120
115
121
deallocate (variable)
116
122
117
123
enddo varloop
118
124
119
125
! deal with wind
120
126
if (update_u_from_reconstruct) then
121
- ! reconstruct u
122
- call error_handler(E_ERR,' update_mpas_states' ,' update_u_from_reconstruct is not implemented' ,source)
127
+
128
+ if (use_increments_for_u_update) then
129
+ ! Read in the previous reconstructed winds from the original mpas netcdf file
130
+ ! and compute what increments (changes in values) were added by the assimilation.
131
+ ! Read in the original edge normal wind 'u' field from that same mpas netcdf
132
+ ! file and add the interpolated increments to compute the updated 'u' values.
133
+
134
+ ! read in u, uReconstrtuctZonal, uReconstructMeridional from background
135
+ ! read in uReconstrtuctZonal, uReconstructMeridional from analysis
136
+
137
+ dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, ' u' ))
138
+ allocate (u(dims(1 ), dims(2 )), increments(dims(1 ), dims(2 )))
139
+ call nc_get_variable(ncBckID, ' u' , u)
140
+
141
+ dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, ' uReconstructZonal' ))
142
+ allocate (ucell(dims(1 ), dims(2 )), ucell_dart(dims(1 ), dims(2 )))
143
+ call nc_get_variable(ncBckID, ' uReconstructZonal' , ucell)
144
+ call nc_get_variable(ncAnlID, ' uReconstructZonal' , ucell_dart)
145
+ ucell = ucell_dart - ucell ! u increments
146
+
147
+ dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, ' uReconstructMeridional' ))
148
+ allocate (vcell(dims(1 ), dims(2 )), vcell_dart(dims(1 ), dims(2 )))
149
+ call nc_get_variable(ncBckID, ' uReconstructMeridional' , vcell)
150
+ call nc_get_variable(ncAnlID, ' uReconstructMeridional' , vcell_dart)
151
+ vcell = vcell_dart - vcell ! v increments
152
+
153
+ call uv_cell_to_edges(ucell, vcell, increments) !
154
+
155
+ u = u + increments
156
+
157
+ call nc_put_variable(ncBckID, ' u' , u)
158
+ call nc_put_variable(ncBckID, ' uReconstructZonal' , ucell_dart)
159
+ call nc_put_variable(ncBckID, ' uReconstructMeridional' , vcell_dart)
160
+
161
+ deallocate (u, increments, ucell, vcell, ucell_dart, vcell_dart)
162
+
163
+ else
164
+ ! The state vector has updated zonal and meridional wind components.
165
+ ! put them directly into the arrays. These are the full values, not
166
+ ! just increments.
167
+ dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, ' u' ))
168
+ allocate (u(dims(1 ), dims(2 )))
169
+ dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, ' uReconstructZonal' ))
170
+ allocate (ucell_dart(dims(1 ), dims(2 )))
171
+ call nc_get_variable(ncAnlID, ' uReconstructZonal' , ucell_dart)
172
+ dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, ' uReconstructMeridional' ))
173
+ allocate (vcell_dart(dims(1 ), dims(2 )))
174
+ call nc_get_variable(ncAnlID, ' uReconstructMeridional' , vcell_dart)
175
+
176
+ call uv_cell_to_edges(ucell_dart, vcell_dart, u, .true. )
177
+
178
+ call nc_put_variable(ncBckID, ' u' , variable)
179
+ call nc_put_variable(ncBckID, ' uReconstructZonal' , variable)
180
+ call nc_put_variable(ncBckID, ' uReconstructMeridional' , variable)
181
+
182
+ deallocate (u, ucell_dart, vcell_dart)
183
+
184
+ endif
185
+
123
186
else
124
187
! copy u from analysis to background
125
- allocate (variable(get_variable_size(1 , get_varid_from_varname(1 , ' u' ))))
188
+ allocate (variable(get_variable_size(1 , get_varid_from_varname(dom_id , ' u' ))))
126
189
127
190
call nc_get_variable(ncAnlID, ' u' , variable)
128
191
call nc_put_variable(ncBckID, ' u' , variable)
0 commit comments