chgres_cube  1.8.0
All Data Structures Namespaces Files Functions Variables Pages
write_data.F90
Go to the documentation of this file.
1  module write_data
2 
3  private
4 
5  public :: write_fv3_atm_header_netcdf
6  public :: write_fv3_atm_bndy_data_netcdf
7  public :: write_fv3_atm_data_netcdf
8  public :: write_fv3_sfc_data_netcdf
9 
10  contains
11 
21 
26  subroutine write_fv3_atm_header_netcdf(localpet)
27 
28  use esmf
29 
30  use netcdf
31 
33  vcoord_target, &
35 
37 
38  implicit none
39 
40  integer, intent(in) :: localpet
41 
42  character(len=13) :: outfile
43 
44  integer :: fsize=65536, initial = 0
45  integer :: header_buffer_val = 16384
46  integer :: error, ncid, dim_nvcoord
47  integer :: dim_levp1, id_ntrac, id_vcoord
48  integer :: num_tracers_output
49 
50  real(kind=esmf_kind_r8), allocatable :: tmp(:,:)
51 
52  if (localpet /= 0) return
53 
54  outfile="./gfs_ctrl.nc"
55 
56  print*,"- WRITE ATMOSPHERIC HEADER FILE: ", trim(outfile)
57 
58  error = nf90_create(outfile, ior(nf90_netcdf4,nf90_classic_model), &
59  ncid, initialsize=initial, chunksize=fsize)
60  call netcdf_err(error, 'CREATING FILE='//trim(outfile) )
61 
62  error = nf90_def_dim(ncid, 'nvcoord', nvcoord_target, dim_nvcoord)
63  call netcdf_err(error, 'define dimension nvcoord for file='//trim(outfile) )
64 
65  error = nf90_def_dim(ncid, 'levsp', levp1_target, dim_levp1)
66  call netcdf_err(error, 'define dimension levsp for file='//trim(outfile) )
67 
68  error = nf90_def_var(ncid, 'ntrac', nf90_int, id_ntrac)
69  call netcdf_err(error, 'define var ntrac for file='//trim(outfile) )
70 
71  error = nf90_def_var(ncid, 'vcoord', nf90_double, (/dim_levp1, dim_nvcoord/), id_vcoord)
72  call netcdf_err(error, 'define var vcoord for file='//trim(outfile) )
73 
74  error = nf90_enddef(ncid, header_buffer_val,4,0,4)
75  call netcdf_err(error, 'end meta define for file='//trim(outfile) )
76 
77  num_tracers_output = num_tracers
78  if (use_thomp_mp_climo) num_tracers_output = num_tracers + 2
79  error = nf90_put_var( ncid, id_ntrac, num_tracers_output)
80  call netcdf_err(error, 'write var ntrac for file='//trim(outfile) )
81 
82  allocate(tmp(levp1_target, nvcoord_target))
83  tmp(1:levp1_target,:) = vcoord_target(levp1_target:1:-1,:)
84 
85  error = nf90_put_var( ncid, id_vcoord, tmp)
86  call netcdf_err(error, 'write var vcoord for file='//trim(outfile) )
87 
88  deallocate(tmp)
89 
90  error = nf90_close(ncid)
91 
92  end subroutine write_fv3_atm_header_netcdf
93 
99  subroutine write_fv3_atm_bndy_data_netcdf(localpet)
101 !---------------------------------------------------------------------------
102 !
103 ! Output data along the four halo boundaries. The naming convention
104 ! assumes point (1,1) is the lower left corner of the grid:
105 !
106 ! --------------- TOP ---------------
107 ! | |
108 ! | |
109 ! LEFT | | RIGHT
110 ! | |
111 ! |PT(1,1) |
112 ! ------------- BOTTOM --------------
113 !
114 !---------------------------------------------------------------------------
115 
116  use esmf
117  use netcdf
118 
125 
127 
128  use program_setup, only : halo_bndy, halo_blend, &
131 
132  implicit none
133 
134  integer, intent(in) :: localpet
135 
136  character(len=50) :: name
137 
138  integer :: fsize=65536, initial = 0
139  integer :: header_buffer_val = 16384
140  integer :: ncid, error, tile, i, n
141  integer :: dim_lon, dim_lat
142  integer :: dim_lonp, dim_halo
143  integer :: dim_halop, dim_latm
144  integer :: dim_lev, dim_levp1
145  integer :: j_target2, halo, halo_p1
146  integer :: id_i_bottom, id_j_bottom
147  integer :: id_i_top, id_j_top
148  integer :: id_i_right, id_j_right
149  integer :: id_i_left, id_j_left
150  integer :: id_qnifa_bottom, id_qnifa_top
151  integer :: id_qnifa_right, id_qnifa_left
152  integer :: id_qnwfa_bottom, id_qnwfa_top
153  integer :: id_qnwfa_right, id_qnwfa_left
154  integer :: id_ps_bottom, id_ps_top
155  integer :: id_ps_right, id_ps_left
156  integer :: id_t_bottom, id_t_top
157  integer :: id_t_right, id_t_left
158  integer :: id_w_bottom, id_w_top
159  integer :: id_w_right, id_w_left
160  integer :: id_zh_bottom, id_zh_top
161  integer :: id_zh_right, id_zh_left
162  integer, allocatable :: id_tracer_bottom(:), id_tracer_top(:)
163  integer, allocatable :: id_tracer_right(:), id_tracer_left(:)
164  integer :: id_i_w_bottom, id_j_w_bottom
165  integer :: id_i_w_top, id_j_w_top
166  integer :: id_j_w_right, id_i_w_left
167  integer :: id_j_w_left, id_i_w_right
168  integer :: id_u_w_bottom, id_u_w_top
169  integer :: id_u_w_right, id_u_w_left
170  integer :: id_v_w_bottom, id_v_w_top
171  integer :: id_v_w_right, id_v_w_left
172  integer :: id_i_s_bottom, id_j_s_bottom
173  integer :: id_i_s_top, id_j_s_top
174  integer :: id_i_s_right, id_j_s_right
175  integer :: id_i_s_left, id_j_s_left
176  integer :: id_u_s_bottom, id_u_s_top
177  integer :: id_u_s_right, id_u_s_left
178  integer :: id_v_s_bottom, id_v_s_top
179  integer :: id_v_s_right, id_v_s_left
180  integer :: i_start_top, i_end_top
181  integer :: j_start_top, j_end_top
182  integer :: i_start_bottom, i_end_bottom
183  integer :: j_start_bottom, j_end_bottom
184  integer :: i_start_left, i_end_left
185  integer :: j_start_left, j_end_left
186  integer :: i_start_right, i_end_right
187  integer :: j_start_right, j_end_right
188  integer(kind=4), allocatable :: idum(:)
189 
190  real(kind=4), allocatable :: dum2d_top(:,:), dum2d_bottom(:,:)
191  real(kind=4), allocatable :: dum2d_left(:,:), dum2d_right(:,:)
192  real(kind=4), allocatable :: dum3d_top(:,:,:), dum3d_bottom(:,:,:)
193  real(kind=4), allocatable :: dum3d_left(:,:,:), dum3d_right(:,:,:)
194  real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
195  real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
196 
197  print*,"- OUTPUT LATERAL BOUNDARY DATA."
198 
199  halo = halo_bndy + halo_blend
200  halo_p1 = halo + 1
201 
202  allocate(id_tracer_bottom(num_tracers))
203  allocate(id_tracer_top(num_tracers))
204  allocate(id_tracer_left(num_tracers))
205  allocate(id_tracer_right(num_tracers))
206 
207  if (localpet == 0) then
208 
209 !--- open the file
210  error = nf90_create("./gfs.bndy.nc", ior(nf90_netcdf4,nf90_classic_model), &
211  ncid, initialsize=initial, chunksize=fsize)
212  call netcdf_err(error, 'CREATING BNDY FILE' )
213 
214  error = nf90_def_dim(ncid, 'lon', i_target, dim_lon)
215  call netcdf_err(error, 'defining lon dimension')
216 
217  j_target2 = j_target - (2*halo_bndy)
218  error = nf90_def_dim(ncid, 'lat', j_target2, dim_lat)
219  call netcdf_err(error, 'DEFINING LAT DIMENSION')
220 
221  error = nf90_def_dim(ncid, 'lonp', ip1_target, dim_lonp)
222  call netcdf_err(error, 'DEFINING LONP DIMENSION')
223 
224  j_target2 = j_target - (2*halo_bndy) - 1
225  error = nf90_def_dim(ncid, 'latm', j_target2, dim_latm)
226  call netcdf_err(error, 'DEFINING LATM DIMENSION')
227 
228  error = nf90_def_dim(ncid, 'halo', halo, dim_halo)
229  call netcdf_err(error, 'DEFINING HALO DIMENSION')
230 
231  error = nf90_def_dim(ncid, 'halop', halo_p1, dim_halop)
232  call netcdf_err(error, 'DEFINING HALOP DIMENSION')
233 
234  error = nf90_def_dim(ncid, 'lev', lev_target, dim_lev)
235  call netcdf_err(error, 'DEFINING LEV DIMENSION')
236 
237  error = nf90_def_dim(ncid, 'levp', levp1_target, dim_levp1)
238  call netcdf_err(error, 'DEFINING LEVP DIMENSION')
239 
240  error = nf90_def_var(ncid, 'i_bottom', nf90_int, &
241  (/dim_lon/), id_i_bottom)
242  call netcdf_err(error, 'DEFINING I_BOTTOM')
243 
244  error = nf90_def_var(ncid, 'j_bottom', nf90_int, &
245  (/dim_halo/), id_j_bottom)
246  call netcdf_err(error, 'DEFINING J_BOTTOM')
247 
248  error = nf90_def_var(ncid, 'i_top', nf90_int, &
249  (/dim_lon/), id_i_top)
250  call netcdf_err(error, 'DEFINING I_TOP')
251 
252  error = nf90_def_var(ncid, 'j_top', nf90_int, &
253  (/dim_halo/), id_j_top)
254  call netcdf_err(error, 'DEFINING J_TOP')
255 
256  error = nf90_def_var(ncid, 'i_right', nf90_int, &
257  (/dim_halo/), id_i_right)
258  call netcdf_err(error, 'DEFINING I_RIGHT')
259 
260  error = nf90_def_var(ncid, 'j_right', nf90_int, &
261  (/dim_lat/), id_j_right)
262  call netcdf_err(error, 'DEFINING J_RIGHT')
263 
264  error = nf90_def_var(ncid, 'i_left', nf90_int, &
265  (/dim_halo/), id_i_left)
266  call netcdf_err(error, 'DEFINING I_LEFT')
267 
268  error = nf90_def_var(ncid, 'j_left', nf90_int, &
269  (/dim_lat/), id_j_left)
270  call netcdf_err(error, 'DEFINING J_LEFT')
271 
272  error = nf90_def_var(ncid, 'ps_bottom', nf90_float, &
273  (/dim_lon, dim_halo/), id_ps_bottom)
274  call netcdf_err(error, 'DEFINING PS_BOTTOM')
275 
276  error = nf90_def_var(ncid, 'ps_top', nf90_float, &
277  (/dim_lon, dim_halo/), id_ps_top)
278  call netcdf_err(error, 'DEFINING PS_TOP')
279 
280  error = nf90_def_var(ncid, 'ps_right', nf90_float, &
281  (/dim_halo, dim_lat/), id_ps_right)
282  call netcdf_err(error, 'DEFINING PS_RIGHT')
283 
284  error = nf90_def_var(ncid, 'ps_left', nf90_float, &
285  (/dim_halo, dim_lat/), id_ps_left)
286  call netcdf_err(error, 'DEFINING PS_LEFT')
287 
288  error = nf90_def_var(ncid, 't_bottom', nf90_float, &
289  (/dim_lon, dim_halo, dim_lev/), id_t_bottom)
290  call netcdf_err(error, 'DEFINING T_BOTTOM')
291 
292  error = nf90_def_var(ncid, 't_top', nf90_float, &
293  (/dim_lon, dim_halo, dim_lev/), id_t_top)
294  call netcdf_err(error, 'DEFINING T_TOP')
295 
296  error = nf90_def_var(ncid, 't_right', nf90_float, &
297  (/dim_halo, dim_lat, dim_lev/), id_t_right)
298  call netcdf_err(error, 'DEFINING T_RIGHT')
299 
300  error = nf90_def_var(ncid, 't_left', nf90_float, &
301  (/dim_halo, dim_lat, dim_lev/), id_t_left)
302  call netcdf_err(error, 'DEFINING T_LEFT')
303 
304  error = nf90_def_var(ncid, 'w_bottom', nf90_float, &
305  (/dim_lon, dim_halo, dim_lev/), id_w_bottom)
306  call netcdf_err(error, 'DEFINING W_BOTTOM')
307 
308  error = nf90_def_var(ncid, 'w_top', nf90_float, &
309  (/dim_lon, dim_halo, dim_lev/), id_w_top)
310  call netcdf_err(error, 'DEFINING W_TOP')
311 
312  error = nf90_def_var(ncid, 'w_right', nf90_float, &
313  (/dim_halo, dim_lat, dim_lev/), id_w_right)
314  call netcdf_err(error, 'DEFINING W_RIGHT')
315 
316  error = nf90_def_var(ncid, 'w_left', nf90_float, &
317  (/dim_halo, dim_lat, dim_lev/), id_w_left)
318  call netcdf_err(error, 'DEFINING W_LEFT')
319 
320  error = nf90_def_var(ncid, 'zh_bottom', nf90_float, &
321  (/dim_lon, dim_halo, dim_levp1/), id_zh_bottom)
322  call netcdf_err(error, 'DEFINING ZH_BOTTOM')
323 
324  error = nf90_def_var(ncid, 'zh_top', nf90_float, &
325  (/dim_lon, dim_halo, dim_levp1/), id_zh_top)
326  call netcdf_err(error, 'DEFINING ZH_TOP')
327 
328  error = nf90_def_var(ncid, 'zh_right', nf90_float, &
329  (/dim_halo, dim_lat, dim_levp1/), id_zh_right)
330  call netcdf_err(error, 'DEFINING ZH_RIGHT')
331 
332  error = nf90_def_var(ncid, 'zh_left', nf90_float, &
333  (/dim_halo, dim_lat, dim_levp1/), id_zh_left)
334  call netcdf_err(error, 'DEFINING ZH_LEFT')
335 
336  do n = 1, num_tracers
337 
338  name = trim(tracers(n)) // "_bottom"
339  error = nf90_def_var(ncid, name, nf90_float, &
340  (/dim_lon, dim_halo, dim_lev/), id_tracer_bottom(n))
341  call netcdf_err(error, 'DEFINING TRACER_BOTTOM')
342 
343  name = trim(tracers(n)) // "_top"
344  error = nf90_def_var(ncid, name, nf90_float, &
345  (/dim_lon, dim_halo, dim_lev/), id_tracer_top(n))
346  call netcdf_err(error, 'DEFINING TRACER_TOP')
347 
348  name = trim(tracers(n)) // "_right"
349  error = nf90_def_var(ncid, name, nf90_float, &
350  (/dim_halo, dim_lat, dim_lev/), id_tracer_right(n))
351  call netcdf_err(error, 'DEFINING TRACER_RIGHT')
352 
353  name = trim(tracers(n)) // "_left"
354  error = nf90_def_var(ncid, name, nf90_float, &
355  (/dim_halo, dim_lat, dim_lev/), id_tracer_left(n))
356  call netcdf_err(error, 'DEFINING TRACER_LEFT')
357 
358  enddo
359 
360  if (use_thomp_mp_climo) then
361 
362  name = "ice_aero_bottom"
363  error = nf90_def_var(ncid, name, nf90_float, &
364  (/dim_lon, dim_halo, dim_lev/), id_qnifa_bottom)
365  call netcdf_err(error, 'DEFINING QNIFA_BOTTOM')
366 
367  name = "ice_aero_top"
368  error = nf90_def_var(ncid, name, nf90_float, &
369  (/dim_lon, dim_halo, dim_lev/), id_qnifa_top)
370  call netcdf_err(error, 'DEFINING QNIFA_TOP')
371 
372  name = "ice_aero_right"
373  error = nf90_def_var(ncid, name, nf90_float, &
374  (/dim_halo, dim_lat, dim_lev/), id_qnifa_right)
375  call netcdf_err(error, 'DEFINING QNIFA_RIGHT')
376 
377  name = "ice_aero_left"
378  error = nf90_def_var(ncid, name, nf90_float, &
379  (/dim_halo, dim_lat, dim_lev/), id_qnifa_left)
380  call netcdf_err(error, 'DEFINING QNIFA_LEFT')
381 
382  name = "liq_aero_bottom"
383  error = nf90_def_var(ncid, name, nf90_float, &
384  (/dim_lon, dim_halo, dim_lev/), id_qnwfa_bottom)
385  call netcdf_err(error, 'DEFINING QNWFA_BOTTOM')
386 
387  name = "liq_aero_top"
388  error = nf90_def_var(ncid, name, nf90_float, &
389  (/dim_lon, dim_halo, dim_lev/), id_qnwfa_top)
390  call netcdf_err(error, 'DEFINING QNWFA_TOP')
391 
392  name = "liq_aero_right"
393  error = nf90_def_var(ncid, name, nf90_float, &
394  (/dim_halo, dim_lat, dim_lev/), id_qnwfa_right)
395  call netcdf_err(error, 'DEFINING QNWFA_RIGHT')
396 
397  name = "liq_aero_left"
398  error = nf90_def_var(ncid, name, nf90_float, &
399  (/dim_halo, dim_lat, dim_lev/), id_qnwfa_left)
400  call netcdf_err(error, 'DEFINING QNWFA_LEFT')
401 
402  endif
403 
404  error = nf90_def_var(ncid, 'i_w_bottom', nf90_int, &
405  (/dim_lonp/), id_i_w_bottom)
406  call netcdf_err(error, 'DEFINING I_W_BOTTOM')
407 
408  error = nf90_def_var(ncid, 'j_w_bottom', nf90_int, &
409  (/dim_halo/), id_j_w_bottom)
410  call netcdf_err(error, 'DEFINING J_W_BOTTOM')
411 
412  error = nf90_def_var(ncid, 'i_w_top', nf90_int, &
413  (/dim_lonp/), id_i_w_top)
414  call netcdf_err(error, 'DEFINING I_W_TOP')
415 
416  error = nf90_def_var(ncid, 'j_w_top', nf90_int, &
417  (/dim_halo/), id_j_w_top)
418  call netcdf_err(error, 'DEFINING J_W_TOP')
419 
420  error = nf90_def_var(ncid, 'i_w_right', nf90_int, &
421  (/dim_halop/), id_i_w_right)
422  call netcdf_err(error, 'DEFINING I_W_RIGHT')
423 
424  error = nf90_def_var(ncid, 'j_w_right', nf90_int, &
425  (/dim_lat/), id_j_w_right)
426  call netcdf_err(error, 'DEFINING J_W_RIGHT')
427 
428  error = nf90_def_var(ncid, 'i_w_left', nf90_int, &
429  (/dim_halop/), id_i_w_left)
430  call netcdf_err(error, 'DEFINING I_W_LEFT')
431 
432  error = nf90_def_var(ncid, 'j_w_left', nf90_int, &
433  (/dim_lat/), id_j_w_left)
434  call netcdf_err(error, 'DEFINING J_W_LEFT')
435 
436  error = nf90_def_var(ncid, 'u_w_bottom', nf90_float, &
437  (/dim_lonp, dim_halo, dim_lev/), id_u_w_bottom)
438  call netcdf_err(error, 'DEFINING U_W_BOTTOM')
439 
440  error = nf90_def_var(ncid, 'u_w_top', nf90_float, &
441  (/dim_lonp, dim_halo, dim_lev/), id_u_w_top)
442  call netcdf_err(error, 'DEFINING U_W_TOP')
443 
444  error = nf90_def_var(ncid, 'u_w_right', nf90_float, &
445  (/dim_halop, dim_lat, dim_lev/), id_u_w_right)
446  call netcdf_err(error, 'DEFINING U_W_RIGHT')
447 
448  error = nf90_def_var(ncid, 'u_w_left', nf90_float, &
449  (/dim_halop, dim_lat, dim_lev/), id_u_w_left)
450  call netcdf_err(error, 'DEFINING U_W_LEFT')
451 
452  error = nf90_def_var(ncid, 'v_w_bottom', nf90_float, &
453  (/dim_lonp, dim_halo, dim_lev/), id_v_w_bottom)
454  call netcdf_err(error, 'DEFINING V_W_BOTTOM')
455 
456  error = nf90_def_var(ncid, 'v_w_top', nf90_float, &
457  (/dim_lonp, dim_halo, dim_lev/), id_v_w_top)
458  call netcdf_err(error, 'DEFINING V_W_TOP')
459 
460  error = nf90_def_var(ncid, 'v_w_right', nf90_float, &
461  (/dim_halop, dim_lat, dim_lev/), id_v_w_right)
462  call netcdf_err(error, 'DEFINING V_W_RIGHT')
463 
464  error = nf90_def_var(ncid, 'v_w_left', nf90_float, &
465  (/dim_halop, dim_lat, dim_lev/), id_v_w_left)
466  call netcdf_err(error, 'DEFINING V_W_LEFT')
467 
468  error = nf90_def_var(ncid, 'i_s_bottom', nf90_int, &
469  (/dim_lon/), id_i_s_bottom)
470  call netcdf_err(error, 'DEFINING I_S_BOTTOM')
471 
472  error = nf90_def_var(ncid, 'j_s_bottom', nf90_int, &
473  (/dim_halop/), id_j_s_bottom)
474  call netcdf_err(error, 'DEFINING J_S_BOTTOM')
475 
476  error = nf90_def_var(ncid, 'i_s_top', nf90_int, &
477  (/dim_lon/), id_i_s_top)
478  call netcdf_err(error, 'DEFINING I_S_TOP')
479 
480  error = nf90_def_var(ncid, 'j_s_top', nf90_int, &
481  (/dim_halop/), id_j_s_top)
482  call netcdf_err(error, 'DEFINING J_S_TOP')
483 
484  error = nf90_def_var(ncid, 'i_s_right', nf90_int, &
485  (/dim_halo/), id_i_s_right)
486  call netcdf_err(error, 'DEFINING I_S_RIGHT')
487 
488  error = nf90_def_var(ncid, 'j_s_right', nf90_int, &
489  (/dim_latm/), id_j_s_right)
490  call netcdf_err(error, 'DEFINING J_S_RIGHT')
491 
492  error = nf90_def_var(ncid, 'i_s_left', nf90_int, &
493  (/dim_halo/), id_i_s_left)
494  call netcdf_err(error, 'DEFINING I_S_LEFT')
495 
496  error = nf90_def_var(ncid, 'j_s_left', nf90_int, &
497  (/dim_latm/), id_j_s_left)
498  call netcdf_err(error, 'DEFINING J_S_LEFT')
499 
500  error = nf90_def_var(ncid, 'u_s_bottom', nf90_float, &
501  (/dim_lon, dim_halop, dim_lev/), id_u_s_bottom)
502  call netcdf_err(error, 'DEFINING U_S_BOTTOM')
503 
504  error = nf90_def_var(ncid, 'u_s_top', nf90_float, &
505  (/dim_lon, dim_halop, dim_lev/), id_u_s_top)
506  call netcdf_err(error, 'DEFINING U_S_TOP')
507 
508  error = nf90_def_var(ncid, 'u_s_right', nf90_float, &
509  (/dim_halo, dim_latm, dim_lev/), id_u_s_right)
510  call netcdf_err(error, 'DEFINING U_S_RIGHT')
511 
512  error = nf90_def_var(ncid, 'u_s_left', nf90_float, &
513  (/dim_halo, dim_latm, dim_lev/), id_u_s_left)
514  call netcdf_err(error, 'DEFINING U_S_LEFT')
515 
516  error = nf90_def_var(ncid, 'v_s_bottom', nf90_float, &
517  (/dim_lon, dim_halop, dim_lev/), id_v_s_bottom)
518  call netcdf_err(error, 'DEFINING V_S_BOTTOM')
519 
520  error = nf90_def_var(ncid, 'v_s_top', nf90_float, &
521  (/dim_lon, dim_halop, dim_lev/), id_v_s_top)
522  call netcdf_err(error, 'DEFINING V_S_TOP')
523 
524  error = nf90_def_var(ncid, 'v_s_right', nf90_float, &
525  (/dim_halo, dim_latm, dim_lev/), id_v_s_right)
526  call netcdf_err(error, 'DEFINING V_S_RIGHT')
527 
528  error = nf90_def_var(ncid, 'v_s_left', nf90_float, &
529  (/dim_halo, dim_latm, dim_lev/), id_v_s_left)
530  call netcdf_err(error, 'DEFINING V_S_LEFT')
531 
532 !--- define global attributes
533  if (trim(input_type) == "gaussian_nemsio") then
534  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS GAUSSIAN NEMSIO FILE')
535  elseif (trim(input_type) == "gfs_gaussian_nemsio") then
536  error = nf90_put_att(ncid, nf90_global, 'source', 'SPECTRAL GFS GAUSSIAN NEMSIO FILE')
537  elseif (trim(input_type) == "gfs_sigio") then
538  error = nf90_put_att(ncid, nf90_global, 'source', 'SPECTRAL GFS SIGIO FILE')
539  elseif (trim(input_type) == "history") then
540  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS TILED HISTORY FILE')
541  elseif (trim(input_type) == "restart") then
542  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS TILED RESTART FILE')
543  elseif (trim(input_type) == "gaussian_netcdf") then
544  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS GAUSSIAN NETCDF FILE')
545  elseif (trim(input_type) == "grib2") then
546  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS GRIB2 FILE')
547  endif
548 
549  error = nf90_enddef(ncid, header_buffer_val,4,0,4)
550  call netcdf_err(error, 'DEFINING END OF HEADER')
551 
552  endif
553 
554 !---------------------------------------------------------------------------
555 ! Set up bounds for mass points. Indices are with respect to the whole
556 ! grid - including total halo (boundary plus blending halo).
557 !---------------------------------------------------------------------------
558 
559  i_start_top = 1
560  i_end_top = i_target
561  j_start_top = j_target - halo + 1
562  j_end_top = j_target
563 
564  i_start_bottom = 1
565  i_end_bottom = i_target
566  j_start_bottom = 1
567  j_end_bottom = halo
568 
569  i_start_left = 1
570  i_end_left = halo
571  j_start_left = halo_bndy + 1
572  j_end_left = j_target - halo_bndy
573 
574  i_start_right = i_target - halo + 1
575  i_end_right = i_target
576  j_start_right = halo_bndy + 1
577  j_end_right = j_target - halo_bndy
578 
579  if (localpet == 0) then
580 
581 ! Indices here are with respect to the computational grid -
582 ! without lateral boundary halo but including blending halo.
583 
584  allocate(idum(i_start_top:i_end_top))
585  do i = i_start_top, i_end_top
586  idum(i) = i - halo_bndy
587  enddo
588  error = nf90_put_var(ncid, id_i_top, idum)
589  call netcdf_err(error, "WRITING I_TOP")
590  deallocate(idum)
591  allocate(idum(i_start_bottom:i_end_bottom))
592  do i = i_start_bottom, i_end_bottom
593  idum(i) = i - halo_bndy
594  enddo
595  error = nf90_put_var(ncid, id_i_bottom, idum)
596  call netcdf_err(error, "WRITING I_BOTTOM")
597  deallocate(idum)
598  allocate(idum(i_start_left:i_end_left))
599  do i = i_start_left, i_end_left
600  idum(i) = i - halo_bndy
601  enddo
602  error = nf90_put_var(ncid, id_i_left, idum)
603  call netcdf_err(error, "WRITING I_LEFT")
604  deallocate(idum)
605  allocate(idum(i_start_right:i_end_right))
606  do i = i_start_right, i_end_right
607  idum(i) = i - halo_bndy
608  enddo
609  error = nf90_put_var(ncid, id_i_right, idum)
610  call netcdf_err(error, "WRITING I_RIGHT")
611  deallocate(idum)
612  allocate(idum(j_start_top:j_end_top))
613  do i = j_start_top, j_end_top
614  idum(i) = i - halo_bndy
615  enddo
616  error = nf90_put_var(ncid, id_j_top, idum)
617  call netcdf_err(error, "WRITING J_TOP")
618  deallocate(idum)
619  allocate(idum(j_start_bottom:j_end_bottom))
620  do i = j_start_bottom, j_end_bottom
621  idum(i) = i - halo_bndy
622  enddo
623  error = nf90_put_var(ncid, id_j_bottom, idum)
624  call netcdf_err(error, "WRITING J_BOTTOM")
625  deallocate(idum)
626  allocate(idum(j_start_left:j_end_left))
627  do i = j_start_left, j_end_left
628  idum(i) = i - halo_bndy
629  enddo
630  error = nf90_put_var(ncid, id_j_left, idum)
631  call netcdf_err(error, "WRITING J_LEFT")
632  deallocate(idum)
633  allocate(idum(j_start_right:j_end_right))
634  do i = j_start_right, j_end_right
635  idum(i) = i - halo_bndy
636  enddo
637  error = nf90_put_var(ncid, id_j_right, idum)
638  call netcdf_err(error, "WRITING J_RIGHT")
639  deallocate(idum)
640  endif
641 
642 ! surface pressure
643 
644  if (localpet == 0) then
645  allocate(data_one_tile(i_target,j_target))
646  allocate(dum2d_top(i_start_top:i_end_top, j_start_top:j_end_top))
647  allocate(dum2d_bottom(i_start_bottom:i_end_bottom, j_start_bottom:j_end_bottom))
648  allocate(dum2d_left(i_start_left:i_end_left, j_start_left:j_end_left))
649  allocate(dum2d_right(i_start_right:i_end_right, j_start_right:j_end_right))
650  else
651  allocate(data_one_tile(0,0))
652  allocate(dum2d_top(0,0))
653  allocate(dum2d_bottom(0,0))
654  allocate(dum2d_left(0,0))
655  allocate(dum2d_right(0,0))
656  endif
657 
658  tile = 1
659 
660  print*,"- CALL FieldGather FOR TARGET GRID SURFACE PRESSURE"
661  call esmf_fieldgather(ps_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
662  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
663  call error_handler("IN FieldGather", error)
664 
665  if (localpet == 0) then
666  dum2d_top(:,:) = data_one_tile(i_start_top:i_end_top, j_start_top:j_end_top)
667  error = nf90_put_var( ncid, id_ps_top, dum2d_top)
668  call netcdf_err(error, 'WRITING PS TOP' )
669  dum2d_bottom(:,:) = data_one_tile(i_start_bottom:i_end_bottom, j_start_bottom:j_end_bottom)
670  error = nf90_put_var( ncid, id_ps_bottom, dum2d_bottom)
671  call netcdf_err(error, 'WRITING PS BOTTOM' )
672  dum2d_left(:,:) = data_one_tile(i_start_left:i_end_left, j_start_left:j_end_left)
673  error = nf90_put_var( ncid, id_ps_left, dum2d_left)
674  call netcdf_err(error, 'WRITING PS LEFT' )
675  dum2d_right(:,:) = data_one_tile(i_start_right:i_end_right, j_start_right:j_end_right)
676  error = nf90_put_var( ncid, id_ps_right, dum2d_right)
677  call netcdf_err(error, 'WRITING PS RIGHT' )
678  endif
679 
680  deallocate(dum2d_top, dum2d_bottom, dum2d_left, dum2d_right, data_one_tile)
681 
682 ! height
683 
684  if (localpet == 0) then
685  allocate(data_one_tile_3d(i_target,j_target,levp1_target))
686  allocate(dum3d_top(i_start_top:i_end_top, j_start_top:j_end_top, levp1_target))
687  allocate(dum3d_bottom(i_start_bottom:i_end_bottom, j_start_bottom:j_end_bottom, levp1_target))
688  allocate(dum3d_left(i_start_left:i_end_left, j_start_left:j_end_left, levp1_target))
689  allocate(dum3d_right(i_start_right:i_end_right, j_start_right:j_end_right, levp1_target))
690  else
691  allocate(data_one_tile_3d(0,0,0))
692  allocate(dum3d_top(0,0,0))
693  allocate(dum3d_bottom(0,0,0))
694  allocate(dum3d_left(0,0,0))
695  allocate(dum3d_right(0,0,0))
696  endif
697 
698  print*,"- CALL FieldGather FOR TARGET GRID HEIGHT FOR TILE: ", tile
699  call esmf_fieldgather(zh_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
700  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
701  call error_handler("IN FieldGather", error)
702 
703  if (localpet == 0) then
704  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
705  dum3d_top(:,:,1:levp1_target) = dum3d_top(:,:,levp1_target:1:-1)
706  error = nf90_put_var( ncid, id_zh_top, dum3d_top)
707  call netcdf_err(error, 'WRITING ZH TOP' )
708  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
709  dum3d_bottom(:,:,1:levp1_target) = dum3d_bottom(:,:,levp1_target:1:-1)
710  error = nf90_put_var( ncid, id_zh_bottom, dum3d_bottom)
711  call netcdf_err(error, 'WRITING ZH BOTTOM' )
712  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
713  dum3d_left(:,:,1:levp1_target) = dum3d_left(:,:,levp1_target:1:-1)
714  error = nf90_put_var( ncid, id_zh_left, dum3d_left)
715  call netcdf_err(error, 'WRITING ZH LEFT' )
716  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
717  dum3d_right(:,:,1:levp1_target) = dum3d_right(:,:,levp1_target:1:-1)
718  error = nf90_put_var( ncid, id_zh_right, dum3d_right)
719  call netcdf_err(error, 'WRITING ZH RIGHT' )
720  endif
721 
722  deallocate(dum3d_top, dum3d_bottom, dum3d_left, dum3d_right, data_one_tile_3d)
723 
724 ! Tracers
725 
726  if (localpet == 0) then
727  allocate(data_one_tile_3d(i_target,j_target,lev_target))
728  allocate(dum3d_top(i_start_top:i_end_top, j_start_top:j_end_top, lev_target))
729  allocate(dum3d_bottom(i_start_bottom:i_end_bottom, j_start_bottom:j_end_bottom, lev_target))
730  allocate(dum3d_left(i_start_left:i_end_left, j_start_left:j_end_left, lev_target))
731  allocate(dum3d_right(i_start_right:i_end_right, j_start_right:j_end_right, lev_target))
732  else
733  allocate(data_one_tile_3d(0,0,0))
734  allocate(dum3d_top(0,0,0))
735  allocate(dum3d_bottom(0,0,0))
736  allocate(dum3d_left(0,0,0))
737  allocate(dum3d_right(0,0,0))
738  endif
739 
740  do n = 1, num_tracers
741 
742  print*,"- CALL FieldGather FOR TARGET GRID TRACER FOR TILE: ", trim(tracers(n)), tile
743  call esmf_fieldgather(tracers_target_grid(n), data_one_tile_3d, rootpet=0, tile=tile, rc=error)
744  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
745  call error_handler("IN FieldGather", error)
746 
747  if (localpet == 0) then
748  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
749  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
750  error = nf90_put_var( ncid, id_tracer_top(n), dum3d_top)
751  call netcdf_err(error, 'WRITING TRACER TOP' )
752  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
753  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
754  error = nf90_put_var( ncid, id_tracer_bottom(n), dum3d_bottom)
755  call netcdf_err(error, 'WRITING TRACER BOTTOM' )
756  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
757  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
758  error = nf90_put_var( ncid, id_tracer_left(n), dum3d_left)
759  call netcdf_err(error, 'WRITING TRACER LEFT' )
760  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
761  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
762  error = nf90_put_var( ncid, id_tracer_right(n), dum3d_right)
763  call netcdf_err(error, 'WRITING TRACER RIGHT' )
764  endif
765 
766  enddo
767 
768 ! Vertical velocity
769 
770  print*,"- CALL FieldGather FOR TARGET GRID W FOR TILE: ", tile
771  call esmf_fieldgather(dzdt_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
772  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
773  call error_handler("IN FieldGather", error)
774 
775  if (localpet == 0) then
776  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
777  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
778  error = nf90_put_var( ncid, id_w_top, dum3d_top)
779  call netcdf_err(error, 'WRITING W TOP' )
780  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
781  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
782  error = nf90_put_var( ncid, id_w_bottom, dum3d_bottom)
783  call netcdf_err(error, 'WRITING W BOTTOM' )
784  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
785  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
786  error = nf90_put_var( ncid, id_w_left, dum3d_left)
787  call netcdf_err(error, 'WRITING W LEFT' )
788  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
789  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
790  error = nf90_put_var( ncid, id_w_right, dum3d_right)
791  call netcdf_err(error, 'WRITING W RIGHT' )
792  endif
793 
794 ! Temperature
795 
796  print*,"- CALL FieldGather FOR TARGET GRID TEMPERATURE FOR TILE: ", tile
797  call esmf_fieldgather(temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
798  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
799  call error_handler("IN FieldGather", error)
800 
801  if (localpet == 0) then
802  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
803  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
804  error = nf90_put_var( ncid, id_t_top, dum3d_top)
805  call netcdf_err(error, 'WRITING T TOP' )
806  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
807  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
808  error = nf90_put_var( ncid, id_t_bottom, dum3d_bottom)
809  call netcdf_err(error, 'WRITING T BOTTOM' )
810  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
811  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
812  error = nf90_put_var( ncid, id_t_left, dum3d_left)
813  call netcdf_err(error, 'WRITING T LEFT' )
814  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
815  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
816  error = nf90_put_var( ncid, id_t_right, dum3d_right)
817  call netcdf_err(error, 'WRITING T RIGHT' )
818  endif
819 
820  if (use_thomp_mp_climo) then
821 
822  print*,"- CALL FieldGather FOR TARGET GRID CLIMO QNIFA FOR TILE: ", tile
823  call esmf_fieldgather(qnifa_climo_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
824  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
825  call error_handler("IN FieldGather", error)
826 
827  if (localpet == 0) then
828  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
829  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
830  error = nf90_put_var( ncid, id_qnifa_top, dum3d_top)
831  call netcdf_err(error, 'WRITING QNIFA CLIMO TOP' )
832  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
833  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
834  error = nf90_put_var( ncid, id_qnifa_bottom, dum3d_bottom)
835  call netcdf_err(error, 'WRITING QNIFA CLIMO BOTTOM' )
836  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
837  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
838  error = nf90_put_var( ncid, id_qnifa_left, dum3d_left)
839  call netcdf_err(error, 'WRITING QNIFA CLIMO LEFT' )
840  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
841  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
842  error = nf90_put_var( ncid, id_qnifa_right, dum3d_right)
843  call netcdf_err(error, 'WRITING QNIFA CLIMO RIGHT' )
844  endif
845 
846  print*,"- CALL FieldGather FOR TARGET GRID CLIMO QNWFA FOR TILE: ", tile
847  call esmf_fieldgather(qnwfa_climo_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
848  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
849  call error_handler("IN FieldGather", error)
850 
851  if (localpet == 0) then
852  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
853  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
854  error = nf90_put_var( ncid, id_qnwfa_top, dum3d_top)
855  call netcdf_err(error, 'WRITING QNWFA CLIMO TOP' )
856  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
857  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
858  error = nf90_put_var( ncid, id_qnwfa_bottom, dum3d_bottom)
859  call netcdf_err(error, 'WRITING QNWFA CLIMO BOTTOM' )
860  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
861  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
862  error = nf90_put_var( ncid, id_qnwfa_left, dum3d_left)
863  call netcdf_err(error, 'WRITING QNWFA CLIMO LEFT' )
864  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
865  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
866  error = nf90_put_var( ncid, id_qnwfa_right, dum3d_right)
867  call netcdf_err(error, 'WRITING QNWFA CLIMO RIGHT' )
868  endif
869 
870  endif
871 
872  deallocate(dum3d_top, dum3d_bottom, dum3d_left, dum3d_right, data_one_tile_3d)
873 
874 !---------------------------------------------------------------------------
875 ! Set up bounds for 's' winds. Indices are with respect to the whole
876 ! grid - including total halo (boundary plus blending halo).
877 !---------------------------------------------------------------------------
878 
879  i_start_top = 1
880  i_end_top = i_target
881  j_start_top = jp1_target - halo_p1 + 1
882  j_end_top = jp1_target
883 
884  i_start_bottom = 1
885  i_end_bottom = i_target
886  j_start_bottom = 1
887  j_end_bottom = halo_p1
888 
889  i_start_left = 1
890  i_end_left = halo
891  j_start_left = halo_bndy + 2
892  j_end_left = j_target - halo_bndy
893 
894  i_start_right = i_target - halo + 1
895  i_end_right = i_target
896  j_start_right = halo_bndy + 2
897  j_end_right = j_target - halo_bndy
898 
899  if (localpet == 0) then
900 
901 ! Indices here are with respect to the computational grid -
902 ! without lateral boundary halo but including blending halo.
903 
904  allocate(idum(i_start_top:i_end_top))
905  do i = i_start_top, i_end_top
906  idum(i) = i - halo_bndy
907  enddo
908  error = nf90_put_var(ncid, id_i_s_top, idum)
909  call netcdf_err(error, "WRITING I_S_TOP")
910  deallocate(idum)
911  allocate(idum(i_start_bottom:i_end_bottom))
912  do i = i_start_bottom, i_end_bottom
913  idum(i) = i - halo_bndy
914  enddo
915  error = nf90_put_var(ncid, id_i_s_bottom, idum)
916  call netcdf_err(error, "WRITING I_S_BOTTOM")
917  deallocate(idum)
918  allocate(idum(i_start_left:i_end_left))
919  do i = i_start_left, i_end_left
920  idum(i) = i - halo_bndy
921  enddo
922  error = nf90_put_var(ncid, id_i_s_left, idum)
923  call netcdf_err(error, "WRITING I_S_LEFT")
924  deallocate(idum)
925  allocate(idum(i_start_right:i_end_right))
926  do i = i_start_right, i_end_right
927  idum(i) = i - halo_bndy
928  enddo
929  error = nf90_put_var(ncid, id_i_s_right, idum)
930  call netcdf_err(error, "WRITING I_S_RIGHT")
931  deallocate(idum)
932  allocate(idum(j_start_top:j_end_top))
933  do i = j_start_top, j_end_top
934  idum(i) = i - halo_bndy
935  enddo
936  error = nf90_put_var(ncid, id_j_s_top, idum)
937  call netcdf_err(error, "WRITING J_S_TOP")
938  deallocate(idum)
939  allocate(idum(j_start_bottom:j_end_bottom))
940  do i = j_start_bottom, j_end_bottom
941  idum(i) = i - halo_bndy
942  enddo
943  error = nf90_put_var(ncid, id_j_s_bottom, idum)
944  call netcdf_err(error, "WRITING J_S_BOTTOM")
945  deallocate(idum)
946  allocate(idum(j_start_left:j_end_left))
947  do i = j_start_left, j_end_left
948  idum(i) = i - halo_bndy
949  enddo
950  error = nf90_put_var(ncid, id_j_s_left, idum)
951  call netcdf_err(error, "WRITING J_S_LEFT")
952  deallocate(idum)
953  allocate(idum(j_start_right:j_end_right))
954  do i = j_start_right, j_end_right
955  idum(i) = i - halo_bndy
956  enddo
957  error = nf90_put_var(ncid, id_j_s_right, idum)
958  call netcdf_err(error, "WRITING J_S_RIGHT")
959  deallocate(idum)
960  endif
961 
962 ! U-WINDS 'S'
963 
964  if (localpet == 0) then
965  allocate(data_one_tile_3d(i_target,jp1_target,lev_target))
966  allocate(dum3d_top(i_start_top:i_end_top, j_start_top:j_end_top, lev_target))
967  allocate(dum3d_bottom(i_start_bottom:i_end_bottom, j_start_bottom:j_end_bottom, lev_target))
968  allocate(dum3d_left(i_start_left:i_end_left, j_start_left:j_end_left, lev_target))
969  allocate(dum3d_right(i_start_right:i_end_right, j_start_right:j_end_right, lev_target))
970  else
971  allocate(data_one_tile_3d(0,0,0))
972  allocate(dum3d_top(0,0,0))
973  allocate(dum3d_bottom(0,0,0))
974  allocate(dum3d_left(0,0,0))
975  allocate(dum3d_right(0,0,0))
976  endif
977 
978  print*,"- CALL FieldGather FOR TARGET GRID U_S FOR TILE: ", tile
979  call esmf_fieldgather(u_s_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
980  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
981  call error_handler("IN FieldGather", error)
982 
983  if (localpet == 0) then
984  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
985  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
986  error = nf90_put_var( ncid, id_u_s_top, dum3d_top)
987  call netcdf_err(error, 'WRITING U_S TOP' )
988  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
989  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
990  error = nf90_put_var( ncid, id_u_s_bottom, dum3d_bottom)
991  call netcdf_err(error, 'WRITING U_S BOTTOM' )
992  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
993  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
994  error = nf90_put_var( ncid, id_u_s_left, dum3d_left)
995  call netcdf_err(error, 'WRITING U_S LEFT' )
996  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
997  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
998  error = nf90_put_var( ncid, id_u_s_right, dum3d_right)
999  call netcdf_err(error, 'WRITING U_S RIGHT' )
1000  endif
1001 
1002 ! V-WINDS 'S'
1003 
1004  print*,"- CALL FieldGather FOR TARGET GRID V_S FOR TILE: ", tile
1005  call esmf_fieldgather(v_s_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
1006  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1007  call error_handler("IN FieldGather", error)
1008 
1009  if (localpet == 0) then
1010  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
1011  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
1012  error = nf90_put_var( ncid, id_v_s_top, dum3d_top)
1013  call netcdf_err(error, 'WRITING V_S TOP' )
1014  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
1015  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
1016  error = nf90_put_var( ncid, id_v_s_bottom, dum3d_bottom)
1017  call netcdf_err(error, 'WRITING V_S BOTTOM' )
1018  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
1019  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
1020  error = nf90_put_var( ncid, id_v_s_left, dum3d_left)
1021  call netcdf_err(error, 'WRITING V_S LEFT' )
1022  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
1023  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
1024  error = nf90_put_var( ncid, id_v_s_right, dum3d_right)
1025  call netcdf_err(error, 'WRITING V_S RIGHT' )
1026  endif
1027 
1028  deallocate(dum3d_top, dum3d_bottom, dum3d_left, dum3d_right, data_one_tile_3d)
1029 
1030 !---------------------------------------------------------------------------
1031 ! Set up bounds for 'w' winds. Indices are with respect to the whole
1032 ! grid - including total halo (boundary plus blending halo).
1033 !---------------------------------------------------------------------------
1034 
1035  i_start_top = 1
1036  i_end_top = ip1_target
1037  j_start_top = j_target - halo + 1
1038  j_end_top = j_target
1039 
1040  i_start_bottom = 1
1041  i_end_bottom = ip1_target
1042  j_start_bottom = 1
1043  j_end_bottom = halo
1044 
1045  i_start_left = 1
1046  i_end_left = halo_p1
1047  j_start_left = halo_bndy + 1
1048  j_end_left = j_target - halo_bndy
1049 
1050  i_start_right = ip1_target - halo_p1 + 1
1051  i_end_right = ip1_target
1052  j_start_right = halo_bndy + 1
1053  j_end_right = j_target - halo_bndy
1054 
1055  if (localpet == 0) then
1056 
1057 ! Indices here are with respect to the computational grid -
1058 ! without lateral boundary halo but including blending halo.
1059 
1060  allocate(idum(i_start_top:i_end_top))
1061  do i = i_start_top, i_end_top
1062  idum(i) = i - halo_bndy
1063  enddo
1064  error = nf90_put_var(ncid, id_i_w_top, idum)
1065  call netcdf_err(error, "WRITING I_W_TOP")
1066  deallocate(idum)
1067  allocate(idum(i_start_bottom:i_end_bottom))
1068  do i = i_start_bottom, i_end_bottom
1069  idum(i) = i - halo_bndy
1070  enddo
1071  error = nf90_put_var(ncid, id_i_w_bottom, idum)
1072  call netcdf_err(error, "WRITING I_W_BOTTOM")
1073  deallocate(idum)
1074  allocate(idum(i_start_left:i_end_left))
1075  do i = i_start_left, i_end_left
1076  idum(i) = i - halo_bndy
1077  enddo
1078  error = nf90_put_var(ncid, id_i_w_left, idum)
1079  call netcdf_err(error, "WRITING I_W_LEFT")
1080  deallocate(idum)
1081  allocate(idum(i_start_right:i_end_right))
1082  do i = i_start_right, i_end_right
1083  idum(i) = i - halo_bndy
1084  enddo
1085  error = nf90_put_var(ncid, id_i_w_right, idum)
1086  call netcdf_err(error, "WRITING I_W_RIGHT")
1087  deallocate(idum)
1088  allocate(idum(j_start_top:j_end_top))
1089  do i = j_start_top, j_end_top
1090  idum(i) = i - halo_bndy
1091  enddo
1092  error = nf90_put_var(ncid, id_j_w_top, idum)
1093  call netcdf_err(error, "WRITING J_W_TOP")
1094  deallocate(idum)
1095  allocate(idum(j_start_bottom:j_end_bottom))
1096  do i = j_start_bottom, j_end_bottom
1097  idum(i) = i - halo_bndy
1098  enddo
1099  error = nf90_put_var(ncid, id_j_w_bottom, idum)
1100  call netcdf_err(error, "WRITING J_W_BOTTOM")
1101  deallocate(idum)
1102  allocate(idum(j_start_left:j_end_left))
1103  do i = j_start_left, j_end_left
1104  idum(i) = i - halo_bndy
1105  enddo
1106  error = nf90_put_var(ncid, id_j_w_left, idum)
1107  call netcdf_err(error, "WRITING J_W_LEFT")
1108  deallocate(idum)
1109  allocate(idum(j_start_right:j_end_right))
1110  do i = j_start_right, j_end_right
1111  idum(i) = i - halo_bndy
1112  enddo
1113  error = nf90_put_var(ncid, id_j_w_right, idum)
1114  call netcdf_err(error, "WRITING J_W_RIGHT")
1115  deallocate(idum)
1116  endif
1117 
1118 ! U-WINDS 'W'
1119 
1120  if (localpet == 0) then
1121  allocate(data_one_tile_3d(ip1_target,j_target,lev_target))
1122  allocate(dum3d_top(i_start_top:i_end_top, j_start_top:j_end_top, lev_target))
1123  allocate(dum3d_bottom(i_start_bottom:i_end_bottom, j_start_bottom:j_end_bottom, lev_target))
1124  allocate(dum3d_left(i_start_left:i_end_left, j_start_left:j_end_left, lev_target))
1125  allocate(dum3d_right(i_start_right:i_end_right, j_start_right:j_end_right, lev_target))
1126  else
1127  allocate(data_one_tile_3d(0,0,0))
1128  allocate(dum3d_top(0,0,0))
1129  allocate(dum3d_bottom(0,0,0))
1130  allocate(dum3d_left(0,0,0))
1131  allocate(dum3d_right(0,0,0))
1132  endif
1133 
1134  print*,"- CALL FieldGather FOR TARGET GRID U_W FOR TILE: ", tile
1135  call esmf_fieldgather(u_w_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
1136  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1137  call error_handler("IN FieldGather", error)
1138 
1139  if (localpet == 0) then
1140  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
1141  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
1142  error = nf90_put_var( ncid, id_u_w_top, dum3d_top)
1143  call netcdf_err(error, 'WRITING U_W TOP' )
1144  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
1145  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
1146  error = nf90_put_var( ncid, id_u_w_bottom, dum3d_bottom)
1147  call netcdf_err(error, 'WRITING U_W BOTTOM' )
1148  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
1149  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
1150  error = nf90_put_var( ncid, id_u_w_left, dum3d_left)
1151  call netcdf_err(error, 'WRITING U_W LEFT' )
1152  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
1153  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
1154  error = nf90_put_var( ncid, id_u_w_right, dum3d_right)
1155  call netcdf_err(error, 'WRITING U_W RIGHT' )
1156  endif
1157 
1158 ! V-WINDS 'W'
1159 
1160  print*,"- CALL FieldGather FOR TARGET GRID V_W FOR TILE: ", tile
1161  call esmf_fieldgather(v_w_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
1162  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1163  call error_handler("IN FieldGather", error)
1164 
1165  if (localpet == 0) then
1166  dum3d_top(:,:,:) = data_one_tile_3d(i_start_top:i_end_top,j_start_top:j_end_top,:)
1167  dum3d_top(:,:,1:lev_target) = dum3d_top(:,:,lev_target:1:-1)
1168  error = nf90_put_var( ncid, id_v_w_top, dum3d_top)
1169  call netcdf_err(error, 'WRITING V_W TOP' )
1170  dum3d_bottom(:,:,:) = data_one_tile_3d(i_start_bottom:i_end_bottom,j_start_bottom:j_end_bottom,:)
1171  dum3d_bottom(:,:,1:lev_target) = dum3d_bottom(:,:,lev_target:1:-1)
1172  error = nf90_put_var( ncid, id_v_w_bottom, dum3d_bottom)
1173  call netcdf_err(error, 'WRITING V_W BOTTOM' )
1174  dum3d_left(:,:,:) = data_one_tile_3d(i_start_left:i_end_left,j_start_left:j_end_left,:)
1175  dum3d_left(:,:,1:lev_target) = dum3d_left(:,:,lev_target:1:-1)
1176  error = nf90_put_var( ncid, id_v_w_left, dum3d_left)
1177  call netcdf_err(error, 'WRITING V_W LEFT' )
1178  dum3d_right(:,:,:) = data_one_tile_3d(i_start_right:i_end_right,j_start_right:j_end_right,:)
1179  dum3d_right(:,:,1:lev_target) = dum3d_right(:,:,lev_target:1:-1)
1180  error = nf90_put_var( ncid, id_v_w_right, dum3d_right)
1181  call netcdf_err(error, 'WRITING V_W RIGHT' )
1182  endif
1183 
1184  deallocate(dum3d_top, dum3d_bottom, dum3d_left, dum3d_right, data_one_tile_3d)
1185  deallocate(id_tracer_bottom, id_tracer_top, id_tracer_left, id_tracer_right)
1186 
1187  if (localpet == 0) error = nf90_close(ncid)
1188 
1189  end subroutine write_fv3_atm_bndy_data_netcdf
1190 
1199  subroutine write_fv3_atm_data_netcdf(localpet)
1201  use esmf
1202  use netcdf
1203 
1204  use program_setup, only : halo=>halo_bndy, &
1207  regional
1208 
1216 
1217  use model_grid, only : num_tiles_target_grid, &
1218  i_target, j_target, &
1226 
1227  implicit none
1228 
1229  integer, intent(in) :: localpet
1230 
1231  character(len=128) :: outfile
1232 
1233  integer :: error, ncid, tile, n
1234  integer :: fsize=65536, initial = 0
1235  integer :: header_buffer_val = 16384
1236  integer :: dim_lon, dim_lat
1237  integer :: dim_lonp, dim_latp
1238  integer :: dim_lev, dim_levp1, dim_ntracer
1239  integer, allocatable :: id_tracers(:)
1240  integer :: id_lon, id_lat, id_ps
1241  integer :: id_lat_s, id_lon_s
1242  integer :: id_lat_w, id_lon_w
1243  integer :: id_w, id_zh, id_u_w
1244  integer :: id_v_w, id_u_s, id_v_s
1245  integer :: id_t, id_delp, id_qnifa, id_qnwfa
1246  integer :: i_start, i_end, j_start, j_end
1247  integer :: i_target_out, j_target_out
1248  integer :: ip1_target_out, jp1_target_out
1249  integer :: ip1_end, jp1_end, num_tracers_output
1250 
1251  real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
1252  real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
1253  real(kind=4), allocatable :: dum2d(:,:)
1254  real(kind=4), allocatable :: dum3d(:,:,:)
1255 
1256 ! Remove any halo region.
1257 
1258  i_target_out = i_target-(2*halo)
1259  j_target_out = j_target-(2*halo)
1260 
1261  i_start = halo + 1
1262  j_start = halo + 1
1263  i_end = i_target - halo
1264  j_end = j_target - halo
1265 
1266  ip1_target_out = i_target_out + 1
1267  jp1_target_out = j_target_out + 1
1268 
1269  ip1_end = i_end + 1
1270  jp1_end = j_end + 1
1271 
1272  if (localpet < num_tiles_target_grid) then
1273  allocate(data_one_tile(i_target,j_target))
1274  allocate(dum2d(i_target_out,j_target_out))
1275  else
1276  allocate(data_one_tile(0,0))
1277  allocate(dum2d(0,0))
1278  endif
1279 
1280  allocate(id_tracers(num_tracers))
1281 
1282  header : if (localpet < num_tiles_target_grid) then
1283 
1284  tile = localpet + 1
1285  if (regional > 0) then
1286  outfile = "out.atm.tile7.nc"
1287  else
1288  WRITE(outfile, '(A, I1, A)') 'out.atm.tile', tile, '.nc'
1289  endif
1290 
1291 !--- open the file
1292  error = nf90_create(outfile, ior(nf90_netcdf4,nf90_classic_model), &
1293  ncid, initialsize=initial, chunksize=fsize)
1294  call netcdf_err(error, 'CREATING FILE='//trim(outfile) )
1295 
1296 !--- define dimension
1297  error = nf90_def_dim(ncid, 'lon', i_target_out, dim_lon)
1298  call netcdf_err(error, 'DEFINING LON DIMENSION' )
1299  error = nf90_def_dim(ncid, 'lat', j_target_out, dim_lat)
1300  call netcdf_err(error, 'DEFINING LAT DIMENSION' )
1301  error = nf90_def_dim(ncid, 'lonp', ip1_target_out, dim_lonp)
1302  call netcdf_err(error, 'DEFINING LONP DIMENSION' )
1303  error = nf90_def_dim(ncid, 'latp', jp1_target_out, dim_latp)
1304  call netcdf_err(error, 'DEFINING LATP DIMENSION' )
1305  error = nf90_def_dim(ncid, 'lev', lev_target, dim_lev)
1306  call netcdf_err(error, 'DEFINING LEV DIMENSION' )
1307  error = nf90_def_dim(ncid, 'levp', levp1_target, dim_levp1)
1308  call netcdf_err(error, 'DEFINING LEVP DIMENSION' )
1309  num_tracers_output = num_tracers
1310  if (use_thomp_mp_climo) num_tracers_output = num_tracers + 2
1311  error = nf90_def_dim(ncid, 'ntracer', num_tracers_output, dim_ntracer)
1312  call netcdf_err(error, 'DEFINING NTRACER DIMENSION' )
1313 
1314 !--- define global attributes
1315  if (trim(input_type) == "gaussian_nemsio") then
1316  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS GAUSSIAN NEMSIO FILE')
1317  elseif (trim(input_type) == "gaussian_netcdf") then
1318  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS GAUSSIAN NETCDF FILE')
1319  elseif (trim(input_type) == "gfs_gaussian_nemsio") then
1320  error = nf90_put_att(ncid, nf90_global, 'source', 'SPECTRAL GFS GAUSSIAN NEMSIO FILE')
1321  elseif (trim(input_type) == "gfs_sigio") then
1322  error = nf90_put_att(ncid, nf90_global, 'source', 'SPECTRAL GFS SIGIO FILE')
1323  elseif (trim(input_type) == "history") then
1324  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS TILED HISTORY FILE')
1325  elseif (trim(input_type) == "restart") then
1326  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS TILED RESTART FILE')
1327  elseif (trim(input_type) == "grib2") then
1328  error = nf90_put_att(ncid, nf90_global, 'source', 'FV3GFS GRIB2 FILE')
1329  endif
1330 
1331 !--- define field
1332  error = nf90_def_var(ncid, 'geolon', nf90_float, (/dim_lon,dim_lat/), id_lon)
1333  call netcdf_err(error, 'DEFINING GEOLON FIELD' )
1334  error = nf90_put_att(ncid, id_lon, "long_name", "Longitude")
1335  call netcdf_err(error, 'DEFINING GEOLON NAME' )
1336  error = nf90_put_att(ncid, id_lon, "units", "degrees_east")
1337  call netcdf_err(error, 'DEFINING GEOLON UNITS' )
1338 
1339  error = nf90_def_var(ncid, 'geolat', nf90_float, (/dim_lon,dim_lat/), id_lat)
1340  call netcdf_err(error, 'DEFINING GEOLAT FIELD' )
1341  error = nf90_put_att(ncid, id_lat, "long_name", "Latitude")
1342  call netcdf_err(error, 'DEFINING GEOLAT NAME' )
1343  error = nf90_put_att(ncid, id_lat, "units", "degrees_north")
1344  call netcdf_err(error, 'DEFINING GEOLAT UNITS' )
1345 
1346  error = nf90_def_var(ncid, 'geolon_s', nf90_float, (/dim_lon,dim_latp/), id_lon_s)
1347  call netcdf_err(error, 'DEFINING GEOLON_S FIELD' )
1348  error = nf90_put_att(ncid, id_lon_s, "long_name", "Longitude_s")
1349  call netcdf_err(error, 'DEFINING GEOLON_S NAME' )
1350  error = nf90_put_att(ncid, id_lon_s, "units", "degrees_east")
1351  call netcdf_err(error, 'DEFINING GEOLON_S UNITS' )
1352 
1353  error = nf90_def_var(ncid, 'geolat_s', nf90_float, (/dim_lon,dim_latp/), id_lat_s)
1354  call netcdf_err(error, 'DEFINING GEOLAT_S FIELD' )
1355  error = nf90_put_att(ncid, id_lat_s, "long_name", "Latitude_s")
1356  call netcdf_err(error, 'DEFINING GEOLAT_S NAME' )
1357  error = nf90_put_att(ncid, id_lat_s, "units", "degrees_north")
1358  call netcdf_err(error, 'DEFINING GEOLAT_S UNITS' )
1359 
1360  error = nf90_def_var(ncid, 'geolon_w', nf90_float, (/dim_lonp,dim_lat/), id_lon_w)
1361  call netcdf_err(error, 'DEFINING GEOLON_W FIELD' )
1362  error = nf90_put_att(ncid, id_lon_w, "long_name", "Longitude_w")
1363  call netcdf_err(error, 'DEFINING GEOLON_W NAME' )
1364  error = nf90_put_att(ncid, id_lon_w, "units", "degrees_east")
1365  call netcdf_err(error, 'DEFINING GEOLON_W UNITS' )
1366 
1367  error = nf90_def_var(ncid, 'geolat_w', nf90_float, (/dim_lonp,dim_lat/), id_lat_w)
1368  call netcdf_err(error, 'DEFINING GEOLAT_W FIELD' )
1369  error = nf90_put_att(ncid, id_lat_w, "long_name", "Latitude_w")
1370  call netcdf_err(error, 'DEFINING GEOLAT_W NAME' )
1371  error = nf90_put_att(ncid, id_lat_w, "units", "degrees_north")
1372  call netcdf_err(error, 'DEFINING GEOLAT_W UNITS' )
1373 
1374  error = nf90_def_var(ncid, 'ps', nf90_float, (/dim_lon,dim_lat/), id_ps)
1375  call netcdf_err(error, 'DEFINING PS' )
1376  error = nf90_put_att(ncid, id_ps, "coordinates", "geolon geolat")
1377  call netcdf_err(error, 'DEFINING PS COORD' )
1378 
1379  error = nf90_def_var(ncid, 'w', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_w)
1380  call netcdf_err(error, 'DEFINING W' )
1381  error = nf90_put_att(ncid, id_w, "coordinates", "geolon geolat")
1382  call netcdf_err(error, 'DEFINING W COORD' )
1383 
1384  error = nf90_def_var(ncid, 'zh', nf90_float, (/dim_lon,dim_lat,dim_levp1/), id_zh)
1385  call netcdf_err(error, 'DEFINING ZH' )
1386  error = nf90_put_att(ncid, id_zh, "coordinates", "geolon geolat")
1387  call netcdf_err(error, 'DEFINING ZH COORD' )
1388 
1389  error = nf90_def_var(ncid, 't', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_t)
1390  call netcdf_err(error, 'DEFINING T' )
1391  error = nf90_put_att(ncid, id_t, "coordinates", "geolon geolat")
1392  call netcdf_err(error, 'DEFINING T COORD' )
1393 
1394  error = nf90_def_var(ncid, 'delp', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_delp)
1395  call netcdf_err(error, 'DEFINING DELP' )
1396  error = nf90_put_att(ncid, id_delp, "coordinates", "geolon geolat")
1397  call netcdf_err(error, 'DEFINING DELP COORD' )
1398 
1399  do n = 1, num_tracers
1400  if (localpet==0) print*, "write to file tracer ", trim(tracers(n))
1401  error = nf90_def_var(ncid, tracers(n), nf90_float, (/dim_lon,dim_lat,dim_lev/), id_tracers(n))
1402  call netcdf_err(error, 'DEFINING TRACERS' )
1403  error = nf90_put_att(ncid, id_tracers(n), "coordinates", "geolon geolat")
1404  call netcdf_err(error, 'DEFINING TRACERS COORD' )
1405  enddo
1406 
1407  if (use_thomp_mp_climo) then
1408  error = nf90_def_var(ncid, 'ice_aero', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_qnifa)
1409  call netcdf_err(error, 'DEFINING QNIFA' )
1410  error = nf90_put_att(ncid, id_qnifa, "coordinates", "geolon geolat")
1411  call netcdf_err(error, 'DEFINING QNIFA COORD' )
1412 
1413  error = nf90_def_var(ncid, 'liq_aero', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_qnwfa)
1414  call netcdf_err(error, 'DEFINING QNWFA' )
1415  error = nf90_put_att(ncid, id_qnwfa, "coordinates", "geolon geolat")
1416  call netcdf_err(error, 'DEFINING QNWFA COORD' )
1417  endif
1418 
1419  error = nf90_def_var(ncid, 'u_w', nf90_float, (/dim_lonp,dim_lat,dim_lev/), id_u_w)
1420  call netcdf_err(error, 'DEFINING U_W' )
1421  error = nf90_put_att(ncid, id_u_w, "coordinates", "geolon_w geolat_w")
1422  call netcdf_err(error, 'DEFINING U_W COORD' )
1423 
1424  error = nf90_def_var(ncid, 'v_w', nf90_float, (/dim_lonp,dim_lat,dim_lev/), id_v_w)
1425  call netcdf_err(error, 'DEFINING V_W' )
1426  error = nf90_put_att(ncid, id_v_w, "coordinates", "geolon_w geolat_w")
1427  call netcdf_err(error, 'DEFINING V_W COORD' )
1428 
1429  error = nf90_def_var(ncid, 'u_s', nf90_float, (/dim_lon,dim_latp,dim_lev/), id_u_s)
1430  call netcdf_err(error, 'DEFINING U_S' )
1431  error = nf90_put_att(ncid, id_u_s, "coordinates", "geolon_s geolat_s")
1432  call netcdf_err(error, 'DEFINING U_S COORD' )
1433 
1434  error = nf90_def_var(ncid, 'v_s', nf90_float, (/dim_lon,dim_latp,dim_lev/), id_v_s)
1435  call netcdf_err(error, 'DEFINING V_S' )
1436  error = nf90_put_att(ncid, id_v_s, "coordinates", "geolon_s geolat_s")
1437  call netcdf_err(error, 'DEFINING V_S COORD' )
1438 
1439  error = nf90_enddef(ncid, header_buffer_val,4,0,4)
1440  call netcdf_err(error, 'DEFINING HEADER' )
1441 
1442  endif header
1443 
1444 ! longitude
1445 
1446  do tile = 1, num_tiles_target_grid
1447  print*,"- CALL FieldGather FOR TARGET GRID LONGITUDE FOR TILE: ", tile
1448  call esmf_fieldgather(longitude_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1449  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1450  call error_handler("IN FieldGather", error)
1451  enddo
1452 
1453  if (localpet < num_tiles_target_grid) then
1454  dum2d(:,:) = data_one_tile(i_start:i_end, j_start:j_end)
1455  error = nf90_put_var( ncid, id_lon, dum2d)
1456  call netcdf_err(error, 'WRITING LONGITUDE RECORD' )
1457  endif
1458 
1459 ! latitude
1460 
1461  do tile = 1, num_tiles_target_grid
1462  print*,"- CALL FieldGather FOR TARGET GRID LATITUDE FOR TILE: ", tile
1463  call esmf_fieldgather(latitude_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1464  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1465  call error_handler("IN FieldGather", error)
1466  enddo
1467 
1468  if (localpet < num_tiles_target_grid) then
1469  dum2d(:,:) = data_one_tile(i_start:i_end, j_start:j_end)
1470  error = nf90_put_var( ncid, id_lat, dum2d)
1471  call netcdf_err(error, 'WRITING LATITUDE RECORD' )
1472  endif
1473 
1474 ! surface pressure
1475 
1476  do tile = 1, num_tiles_target_grid
1477  print*,"- CALL FieldGather FOR TARGET GRID SURFACE PRESSURE FOR TILE: ", tile
1478  call esmf_fieldgather(ps_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1479  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1480  call error_handler("IN FieldGather", error)
1481  enddo
1482 
1483  if (localpet < num_tiles_target_grid) then
1484  dum2d(:,:) = data_one_tile(i_start:i_end, j_start:j_end)
1485  error = nf90_put_var( ncid, id_ps, dum2d)
1486  call netcdf_err(error, 'WRITING SURFACE PRESSURE RECORD' )
1487  endif
1488 
1489  deallocate(dum2d, data_one_tile)
1490 
1491 ! height
1492 
1493  if (localpet < num_tiles_target_grid) then
1494  allocate(dum3d(i_target_out,j_target_out,levp1_target))
1495  allocate(data_one_tile_3d(i_target,j_target,levp1_target))
1496  else
1497  allocate(dum3d(0,0,0))
1498  allocate(data_one_tile_3d(0,0,0))
1499  endif
1500 
1501  do tile = 1, num_tiles_target_grid
1502  print*,"- CALL FieldGather FOR TARGET GRID HEIGHT FOR TILE: ", tile
1503  call esmf_fieldgather(zh_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1504  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1505  call error_handler("IN FieldGather", error)
1506  enddo
1507 
1508  if (localpet < num_tiles_target_grid) then
1509  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1510  dum3d(:,:,1:levp1_target) = dum3d(:,:,levp1_target:1:-1)
1511  error = nf90_put_var( ncid, id_zh, dum3d)
1512  call netcdf_err(error, 'WRITING HEIGHT RECORD' )
1513  endif
1514 
1515  deallocate(dum3d, data_one_tile_3d)
1516 
1517 ! vertical velocity
1518 
1519  if (localpet < num_tiles_target_grid) then
1520  allocate(dum3d(i_target_out,j_target_out,lev_target))
1521  allocate(data_one_tile_3d(i_target,j_target,lev_target))
1522  else
1523  allocate(dum3d(0,0,0))
1524  allocate(data_one_tile_3d(0,0,0))
1525  endif
1526 
1527  do tile = 1, num_tiles_target_grid
1528  print*,"- CALL FieldGather FOR TARGET GRID VERTICAL VELOCITY FOR TILE: ", tile
1529  call esmf_fieldgather(dzdt_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1530  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1531  call error_handler("IN FieldGather", error)
1532  enddo
1533 
1534  if (localpet < num_tiles_target_grid) then
1535  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1536  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1537  print*,"MIN MAX W AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1538  error = nf90_put_var( ncid, id_w, dum3d)
1539  call netcdf_err(error, 'WRITING VERTICAL VELOCITY RECORD' )
1540  endif
1541 
1542 ! delp
1543 
1544  do tile = 1, num_tiles_target_grid
1545  print*,"- CALL FieldGather FOR TARGET GRID DELP FOR TILE: ", tile
1546  call esmf_fieldgather(delp_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1547  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1548  call error_handler("IN FieldGather", error)
1549  enddo
1550 
1551  if (localpet < num_tiles_target_grid) then
1552  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1553  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1554  error = nf90_put_var( ncid, id_delp, dum3d)
1555  call netcdf_err(error, 'WRITING DELP RECORD' )
1556  endif
1557 
1558 ! temperature
1559 
1560  do tile = 1, num_tiles_target_grid
1561  print*,"- CALL FieldGather FOR TARGET GRID TEMPERATURE FOR TILE: ", tile
1562  call esmf_fieldgather(temp_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1563  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1564  call error_handler("IN FieldGather", error)
1565  enddo
1566 
1567  if (localpet < num_tiles_target_grid) then
1568  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1569  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1570  error = nf90_put_var( ncid, id_t, dum3d)
1571  call netcdf_err(error, 'WRITING TEMPERTAURE RECORD' )
1572  endif
1573 
1574 ! tracers
1575 
1576  do n = 1, num_tracers
1577 
1578  do tile = 1, num_tiles_target_grid
1579  print*,"- CALL FieldGather FOR TARGET GRID TRACER ", trim(tracers(n)), " TILE: ", tile
1580  call esmf_fieldgather(tracers_target_grid(n), data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1581  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1582  call error_handler("IN FieldGather", error)
1583  enddo
1584 
1585  if (localpet < num_tiles_target_grid) then
1586  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1587  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1588  error = nf90_put_var( ncid, id_tracers(n), dum3d)
1589  call netcdf_err(error, 'WRITING TRACER RECORD' )
1590  endif
1591 
1592  enddo
1593 
1594 ! qnifa
1595 
1596  if (use_thomp_mp_climo) then
1597  do tile = 1, num_tiles_target_grid
1598  print*,"- CALL FieldGather FOR TARGET GRID QNIFA FOR TILE: ", tile
1599  call esmf_fieldgather(qnifa_climo_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1600  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1601  call error_handler("IN FieldGather", error)
1602  enddo
1603 
1604  if (localpet < num_tiles_target_grid) then
1605  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1606  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1607  error = nf90_put_var( ncid, id_qnifa, dum3d)
1608  call netcdf_err(error, 'WRITING QNIFA RECORD' )
1609  endif
1610 
1611 ! qnwfa
1612 
1613  do tile = 1, num_tiles_target_grid
1614  print*,"- CALL FieldGather FOR TARGET GRID QNWFA FOR TILE: ", tile
1615  call esmf_fieldgather(qnwfa_climo_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1616  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1617  call error_handler("IN FieldGather", error)
1618  enddo
1619 
1620  if (localpet < num_tiles_target_grid) then
1621  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1622  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1623  error = nf90_put_var( ncid, id_qnwfa, dum3d)
1624  call netcdf_err(error, 'WRITING QNWFA RECORD' )
1625  endif
1626  endif
1627 
1628  deallocate(dum3d, data_one_tile_3d)
1629 
1630 ! lat/lon_s
1631 
1632  if (localpet < num_tiles_target_grid) then
1633  allocate(dum2d(i_target_out,jp1_target_out))
1634  allocate(data_one_tile(i_target,jp1_target))
1635  else
1636  allocate(dum2d(0,0))
1637  allocate(data_one_tile(0,0))
1638  endif
1639 
1640  do tile = 1, num_tiles_target_grid
1641  print*,"- CALL FieldGather FOR TARGET GRID LON_S FOR TILE: ", tile
1642  call esmf_fieldgather(longitude_s_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1643  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1644  call error_handler("IN FieldGather", error)
1645  enddo
1646 
1647  if (localpet < num_tiles_target_grid) then
1648  dum2d(:,:) = data_one_tile(i_start:i_end,j_start:jp1_end)
1649  error = nf90_put_var( ncid, id_lon_s, dum2d)
1650  call netcdf_err(error, 'WRITING LON_S RECORD' )
1651  endif
1652 
1653  do tile = 1, num_tiles_target_grid
1654  print*,"- CALL FieldGather FOR TARGET GRID LAT_S FOR TILE: ", tile
1655  call esmf_fieldgather(latitude_s_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1656  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1657  call error_handler("IN FieldGather", error)
1658  enddo
1659 
1660  if (localpet < num_tiles_target_grid) then
1661  dum2d(:,:) = data_one_tile(i_start:i_end,j_start:jp1_end)
1662  error = nf90_put_var( ncid, id_lat_s, dum2d)
1663  call netcdf_err(error, 'WRITING LAT_S RECORD' )
1664  endif
1665 
1666  deallocate(dum2d, data_one_tile)
1667 
1668 ! uwinds s
1669 
1670  if (localpet < num_tiles_target_grid) then
1671  allocate(dum3d(i_target_out,jp1_target_out,lev_target))
1672  allocate(data_one_tile_3d(i_target,jp1_target,lev_target))
1673  else
1674  allocate(dum3d(0,0,0))
1675  allocate(data_one_tile_3d(0,0,0))
1676  endif
1677 
1678  do tile = 1, num_tiles_target_grid
1679  print*,"- CALL FieldGather FOR TARGET GRID U_S FOR TILE: ", tile
1680  call esmf_fieldgather(u_s_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1681  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1682  call error_handler("IN FieldGather", error)
1683  enddo
1684 
1685  if (localpet < num_tiles_target_grid) then
1686  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:jp1_end,:)
1687  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1688  print*,"MIN MAX US AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1689  error = nf90_put_var( ncid, id_u_s, dum3d)
1690  call netcdf_err(error, 'WRITING U_S RECORD' )
1691  endif
1692 
1693 ! vwinds s
1694 
1695  do tile = 1, num_tiles_target_grid
1696  print*,"- CALL FieldGather FOR TARGET GRID V_S FOR TILE: ", tile
1697  call esmf_fieldgather(v_s_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1698  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1699  call error_handler("IN FieldGather", error)
1700  enddo
1701 
1702  if (localpet < num_tiles_target_grid) then
1703  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:jp1_end,:)
1704  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1705  print*,"MIN MAX VS AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1706  error = nf90_put_var( ncid, id_v_s, dum3d)
1707  call netcdf_err(error, 'WRITING V_S RECORD' )
1708  endif
1709 
1710  deallocate(dum3d, data_one_tile_3d)
1711 
1712 ! lat/lon_w
1713 
1714  if (localpet < num_tiles_target_grid) then
1715  allocate(dum2d(ip1_target_out,j_target_out))
1716  allocate(data_one_tile(ip1_target,j_target))
1717  else
1718  allocate(dum2d(0,0))
1719  allocate(data_one_tile(0,0))
1720  endif
1721 
1722  do tile = 1, num_tiles_target_grid
1723  print*,"- CALL FieldGather FOR TARGET GRID LON_W FOR TILE: ", tile
1724  call esmf_fieldgather(longitude_w_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1725  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1726  call error_handler("IN FieldGather", error)
1727  enddo
1728 
1729  if (localpet < num_tiles_target_grid) then
1730  dum2d(:,:) = data_one_tile(i_start:ip1_end,j_start:j_end)
1731  error = nf90_put_var( ncid, id_lon_w, dum2d)
1732  call netcdf_err(error, 'WRITING LON_W RECORD' )
1733  endif
1734 
1735  do tile = 1, num_tiles_target_grid
1736  print*,"- CALL FieldGather FOR TARGET GRID LAT_W FOR TILE: ", tile
1737  call esmf_fieldgather(latitude_w_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1738  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1739  call error_handler("IN FieldGather", error)
1740  enddo
1741 
1742  if (localpet < num_tiles_target_grid) then
1743  dum2d(:,:) = data_one_tile(i_start:ip1_end,j_start:j_end)
1744  error = nf90_put_var( ncid, id_lat_w, dum2d)
1745  call netcdf_err(error, 'WRITING LAT_W RECORD' )
1746  endif
1747 
1748  deallocate(dum2d, data_one_tile)
1749 
1750 ! uwinds w
1751 
1752  if (localpet < num_tiles_target_grid) then
1753  allocate(dum3d(ip1_target_out,j_target_out,lev_target))
1754  allocate(data_one_tile_3d(ip1_target,j_target,lev_target))
1755  else
1756  allocate(dum3d(0,0,0))
1757  allocate(data_one_tile_3d(0,0,0))
1758  endif
1759 
1760  do tile = 1, num_tiles_target_grid
1761  print*,"- CALL FieldGather FOR TARGET GRID U_W FOR TILE: ", tile
1762  call esmf_fieldgather(u_w_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1763  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1764  call error_handler("IN FieldGather", error)
1765  enddo
1766 
1767  if (localpet < num_tiles_target_grid) then
1768  dum3d(:,:,:) = data_one_tile_3d(i_start:ip1_end,j_start:j_end,:)
1769  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1770  print*,"MIN MAX UW AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1771  error = nf90_put_var( ncid, id_u_w, dum3d)
1772  call netcdf_err(error, 'WRITING U_W RECORD' )
1773  endif
1774 
1775 ! vwinds w
1776 
1777  do tile = 1, num_tiles_target_grid
1778  print*,"- CALL FieldGather FOR TARGET GRID V_W FOR TILE: ", tile
1779  call esmf_fieldgather(v_w_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1780  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1781  call error_handler("IN FieldGather", error)
1782  enddo
1783 
1784  if (localpet < num_tiles_target_grid) then
1785  dum3d(:,:,:) = data_one_tile_3d(i_start:ip1_end,j_start:j_end,:)
1786  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1787  print*,"MIN MAX VW AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1788  error = nf90_put_var( ncid, id_v_w, dum3d)
1789  call netcdf_err(error, 'WRITING V_W RECORD' )
1790  endif
1791 
1792  deallocate(dum3d, data_one_tile_3d, id_tracers)
1793 
1794 !-------------------------------------------------------------------------------
1795 ! close file
1796 !-------------------------------------------------------------------------------
1797 
1798  if (localpet < num_tiles_target_grid) error = nf90_close(ncid)
1799 
1800  end subroutine write_fv3_atm_data_netcdf
1801 
1806  subroutine write_fv3_sfc_data_netcdf(localpet)
1808  use esmf
1809  use netcdf
1810 
1811  use model_grid, only : num_tiles_target_grid, &
1816 
1817  use program_setup, only : convert_nst, halo=>halo_bndy, &
1819 
1821  f10m_target_grid, &
1822  ffmm_target_grid, &
1823  q2m_target_grid, &
1834  t2m_target_grid, &
1837  z0_target_grid, &
1838  lai_target_grid, &
1839  c_d_target_grid, &
1840  c_0_target_grid, &
1843  ifd_target_grid, &
1845  tref_target_grid, &
1846  w_d_target_grid, &
1847  w_0_target_grid, &
1848  xs_target_grid, &
1849  xt_target_grid, &
1850  xu_target_grid, &
1851  xv_target_grid, &
1852  xz_target_grid, &
1853  xtts_target_grid, &
1854  xzts_target_grid, &
1855  z_c_target_grid, &
1857 
1858  use static_data, only : alvsf_target_grid, &
1872 
1873  implicit none
1874 
1875  integer, intent(in) :: localpet
1876  character(len=128) :: outfile
1877 
1878  integer :: fsize=65536, initial = 0
1879  integer :: header_buffer_val = 16384
1880  integer :: dim_x, dim_y, dim_lsoil, dim_time
1881  integer :: error, i, ncid, tile
1882  integer :: id_x, id_y, id_lsoil
1883  integer :: id_slmsk, id_time
1884  integer :: id_lat, id_lon
1885  integer :: id_tsea, id_sheleg, id_tg3
1886  integer :: id_zorl, id_alvsf, id_alvwf
1887  integer :: id_alnsf, id_alnwf, id_vfrac
1888  integer :: id_canopy, id_f10m, id_t2m
1889  integer :: id_q2m, id_vtype, id_stype
1890  integer :: id_facsf, id_facwf, id_uustar
1891  integer :: id_ffmm, id_ffhh, id_hice
1892  integer :: id_fice, id_tisfc, id_tprcp
1893  integer :: id_srflag, id_snwdph, id_shdmin
1894  integer :: id_shdmax, id_slope, id_snoalb
1895  integer :: id_lai
1896  integer :: id_stc, id_smc, id_slc
1897  integer :: id_tref, id_z_c, id_c_0
1898  integer :: id_c_d, id_w_0, id_w_d
1899  integer :: id_xt, id_xs, id_xu, id_xv
1900  integer :: id_xz, id_zm, id_xtts, id_xzts
1901  integer :: id_d_conv, id_ifd, id_dt_cool
1902  integer :: id_qrain
1903  integer :: i_target_out, j_target_out
1904  integer :: istart, iend, jstart, jend
1905 
1906  integer(esmf_kind_i8), allocatable :: idata_one_tile(:,:)
1907 
1908  real(kind=4), allocatable :: lsoil_data(:), x_data(:), y_data(:)
1909  real(kind=8), allocatable :: dum2d(:,:), dum3d(:,:,:)
1910  real(kind=4) :: times
1911  real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
1912  real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
1913 
1914 ! Remove any halo region.
1915 
1916  i_target_out = i_target-(2*halo)
1917  j_target_out = j_target-(2*halo)
1918 
1919  istart = halo + 1
1920  jstart = halo + 1
1921  iend = i_target - halo
1922  jend = j_target - halo
1923 
1924  allocate(lsoil_data(lsoil_target))
1925  do i = 1, lsoil_target
1926  lsoil_data(i) = float(i)
1927  enddo
1928 
1929  allocate(x_data(i_target_out))
1930  do i = 1, i_target_out
1931  x_data(i) = float(i)
1932  enddo
1933 
1934  allocate(y_data(j_target_out))
1935  do i = 1, j_target_out
1936  y_data(i) = float(i)
1937  enddo
1938 
1939  if (convert_nst) then
1940  print*,'- WRITE FV3 SURFACE AND NST DATA TO NETCDF FILE'
1941  else
1942  print*,'- WRITE FV3 SURFACE DATA TO NETCDF FILE'
1943  endif
1944 
1945  if (localpet == 0) then
1946  allocate(data_one_tile(i_target,j_target))
1947  allocate(data_one_tile_3d(i_target,j_target,lsoil_target))
1948  allocate(idata_one_tile(i_target,j_target))
1949  allocate(dum2d(i_target_out,j_target_out))
1950  allocate(dum3d(i_target_out,j_target_out,lsoil_target))
1951  else
1952  allocate(data_one_tile(0,0))
1953  allocate(data_one_tile_3d(0,0,0))
1954  allocate(idata_one_tile(0,0))
1955  allocate(dum2d(0,0))
1956  allocate(dum3d(0,0,0))
1957  endif
1958 
1959  tile_loop : do tile = 1, num_tiles_target_grid
1960 
1961  local_pet : if (localpet == 0) then
1962 
1963  if (regional > 0) then
1964  outfile = "out.sfc.tile7.nc"
1965  else
1966  WRITE(outfile, '(A, I1, A)') 'out.sfc.tile', tile, '.nc'
1967  endif
1968 
1969 !--- open the file
1970  error = nf90_create(outfile, ior(nf90_netcdf4,nf90_classic_model), &
1971  ncid, initialsize=initial, chunksize=fsize)
1972  call netcdf_err(error, 'CREATING FILE='//trim(outfile) )
1973 
1974 !--- define dimensions
1975  error = nf90_def_dim(ncid, 'xaxis_1', i_target_out, dim_x)
1976  call netcdf_err(error, 'DEFINING XAXIS DIMENSION' )
1977  error = nf90_def_dim(ncid, 'yaxis_1', j_target_out, dim_y)
1978  call netcdf_err(error, 'DEFINING YAXIS DIMENSION' )
1979  error = nf90_def_dim(ncid, 'zaxis_1', lsoil_target, dim_lsoil)
1980  call netcdf_err(error, 'DEFINING ZAXIS DIMENSION' )
1981  error = nf90_def_dim(ncid, 'Time', 1, dim_time)
1982  call netcdf_err(error, 'DEFINING TIME DIMENSION' )
1983 
1984  !--- define fields
1985  error = nf90_def_var(ncid, 'xaxis_1', nf90_float, (/dim_x/), id_x)
1986  call netcdf_err(error, 'DEFINING XAXIS_1 FIELD' )
1987  error = nf90_put_att(ncid, id_x, "long_name", "xaxis_1")
1988  call netcdf_err(error, 'DEFINING XAXIS_1 LONG NAME' )
1989  error = nf90_put_att(ncid, id_x, "units", "none")
1990  call netcdf_err(error, 'DEFINING XAXIS_1 UNITS' )
1991  error = nf90_put_att(ncid, id_x, "cartesian_axis", "X")
1992  call netcdf_err(error, 'WRITING XAXIS_1 FIELD' )
1993 
1994  error = nf90_def_var(ncid, 'yaxis_1', nf90_float, (/dim_y/), id_y)
1995  call netcdf_err(error, 'DEFINING YAXIS_1 FIELD' )
1996  error = nf90_put_att(ncid, id_y, "long_name", "yaxis_1")
1997  call netcdf_err(error, 'DEFINING YAXIS_1 LONG NAME' )
1998  error = nf90_put_att(ncid, id_y, "units", "none")
1999  call netcdf_err(error, 'DEFINING YAXIS_1 UNITS' )
2000  error = nf90_put_att(ncid, id_y, "cartesian_axis", "Y")
2001  call netcdf_err(error, 'WRITING YAXIS_1 FIELD' )
2002 
2003  error = nf90_def_var(ncid, 'zaxis_1', nf90_float, (/dim_lsoil/), id_lsoil)
2004  call netcdf_err(error, 'DEFINING ZAXIS_1 FIELD' )
2005  error = nf90_put_att(ncid, id_lsoil, "long_name", "zaxis_1")
2006  call netcdf_err(error, 'DEFINING ZAXIS_1 LONG NAME' )
2007  error = nf90_put_att(ncid, id_lsoil, "units", "none")
2008  call netcdf_err(error, 'DEFINING ZAXIS_1 UNITS' )
2009  error = nf90_put_att(ncid, id_lsoil, "cartesian_axis", "Z")
2010  call netcdf_err(error, 'WRITING ZAXIS_1 FIELD' )
2011 
2012  error = nf90_def_var(ncid, 'Time', nf90_float, dim_time, id_time)
2013  call netcdf_err(error, 'DEFINING TIME FIELD' )
2014  error = nf90_put_att(ncid, id_time, "long_name", "Time")
2015  call netcdf_err(error, 'DEFINING TIME LONG NAME' )
2016  error = nf90_put_att(ncid, id_time, "units", "time level")
2017  call netcdf_err(error, 'DEFINING TIME UNITS' )
2018  error = nf90_put_att(ncid, id_time, "cartesian_axis", "T")
2019  call netcdf_err(error, 'WRITING TIME FIELD' )
2020 
2021  error = nf90_def_var(ncid, 'geolon', nf90_double, (/dim_x,dim_y/), id_lon)
2022  call netcdf_err(error, 'DEFINING GEOLON' )
2023  error = nf90_put_att(ncid, id_lon, "long_name", "Longitude")
2024  call netcdf_err(error, 'DEFINING GEOLON LONG NAME' )
2025  error = nf90_put_att(ncid, id_lon, "units", "degrees_east")
2026  call netcdf_err(error, 'DEFINING GEOLON UNITS' )
2027 
2028  error = nf90_def_var(ncid, 'geolat', nf90_double, (/dim_x,dim_y/), id_lat)
2029  call netcdf_err(error, 'DEFINING GEOLAT' )
2030  error = nf90_put_att(ncid, id_lat, "long_name", "Latitude")
2031  call netcdf_err(error, 'DEFINING GEOLAT LONG NAME' )
2032  error = nf90_put_att(ncid, id_lat, "units", "degrees_north")
2033  call netcdf_err(error, 'DEFINING GEOLAT UNITS' )
2034 
2035  error = nf90_def_var(ncid, 'slmsk', nf90_double, (/dim_x,dim_y,dim_time/), id_slmsk)
2036  call netcdf_err(error, 'DEFINING SLMSK' )
2037  error = nf90_put_att(ncid, id_slmsk, "long_name", "slmsk")
2038  call netcdf_err(error, 'DEFINING SLMSK LONG NAME' )
2039  error = nf90_put_att(ncid, id_slmsk, "units", "none")
2040  call netcdf_err(error, 'DEFINING SLMSK UNITS' )
2041  error = nf90_put_att(ncid, id_slmsk, "coordinates", "geolon geolat")
2042  call netcdf_err(error, 'DEFINING SLMSK COORD' )
2043 
2044  error = nf90_def_var(ncid, 'tsea', nf90_double, (/dim_x,dim_y,dim_time/), id_tsea)
2045  call netcdf_err(error, 'DEFINING TSEA' )
2046  error = nf90_put_att(ncid, id_tsea, "long_name", "tsea")
2047  call netcdf_err(error, 'DEFINING TSEA LONG NAME' )
2048  error = nf90_put_att(ncid, id_tsea, "units", "none")
2049  call netcdf_err(error, 'DEFINING TSEA UNITS' )
2050  error = nf90_put_att(ncid, id_tsea, "coordinates", "geolon geolat")
2051  call netcdf_err(error, 'DEFINING TSEA COORD' )
2052 
2053  error = nf90_def_var(ncid, 'sheleg', nf90_double, (/dim_x,dim_y,dim_time/), id_sheleg)
2054  call netcdf_err(error, 'DEFINING SHELEG' )
2055  error = nf90_put_att(ncid, id_sheleg, "long_name", "sheleg")
2056  call netcdf_err(error, 'DEFINING SHELEG LONG NAME' )
2057  error = nf90_put_att(ncid, id_sheleg, "units", "none")
2058  call netcdf_err(error, 'DEFINING SHELEG UNITS' )
2059  error = nf90_put_att(ncid, id_sheleg, "coordinates", "geolon geolat")
2060  call netcdf_err(error, 'DEFINING SHELEG COORD' )
2061 
2062  error = nf90_def_var(ncid, 'tg3', nf90_double, (/dim_x,dim_y,dim_time/), id_tg3)
2063  call netcdf_err(error, 'DEFINING TG3' )
2064  error = nf90_put_att(ncid, id_tg3, "long_name", "tg3")
2065  call netcdf_err(error, 'DEFINING TG3 LONG NAME' )
2066  error = nf90_put_att(ncid, id_tg3, "units", "none")
2067  call netcdf_err(error, 'DEFINING TG3 UNITS' )
2068  error = nf90_put_att(ncid, id_tg3, "coordinates", "geolon geolat")
2069  call netcdf_err(error, 'DEFINING TG3 COORD' )
2070 
2071  error = nf90_def_var(ncid, 'zorl', nf90_double, (/dim_x,dim_y,dim_time/), id_zorl)
2072  call netcdf_err(error, 'DEFINING ZORL' )
2073  error = nf90_put_att(ncid, id_zorl, "long_name", "zorl")
2074  call netcdf_err(error, 'DEFINING ZORL LONG NAME' )
2075  error = nf90_put_att(ncid, id_zorl, "units", "none")
2076  call netcdf_err(error, 'DEFINING ZORL UNITS' )
2077  error = nf90_put_att(ncid, id_zorl, "coordinates", "geolon geolat")
2078  call netcdf_err(error, 'DEFINING ZORL COORD' )
2079 
2080  error = nf90_def_var(ncid, 'alvsf', nf90_double, (/dim_x,dim_y,dim_time/), id_alvsf)
2081  call netcdf_err(error, 'DEFINING ALVSF' )
2082  error = nf90_put_att(ncid, id_alvsf, "long_name", "alvsf")
2083  call netcdf_err(error, 'DEFINING ALVSF LONG NAME' )
2084  error = nf90_put_att(ncid, id_alvsf, "units", "none")
2085  call netcdf_err(error, 'DEFINING ALVSF UNITS' )
2086  error = nf90_put_att(ncid, id_alvsf, "coordinates", "geolon geolat")
2087  call netcdf_err(error, 'DEFINING ALVSF COORD' )
2088 
2089  error = nf90_def_var(ncid, 'alvwf', nf90_double, (/dim_x,dim_y,dim_time/), id_alvwf)
2090  call netcdf_err(error, 'DEFINING ALVWF' )
2091  error = nf90_put_att(ncid, id_alvwf, "long_name", "alvwf")
2092  call netcdf_err(error, 'DEFINING ALVWF LONG NAME' )
2093  error = nf90_put_att(ncid, id_alvwf, "units", "none")
2094  call netcdf_err(error, 'DEFINING ALVWF UNITS' )
2095  error = nf90_put_att(ncid, id_alvwf, "coordinates", "geolon geolat")
2096  call netcdf_err(error, 'DEFINING ALVWF COORD' )
2097 
2098  error = nf90_def_var(ncid, 'alnsf', nf90_double, (/dim_x,dim_y,dim_time/), id_alnsf)
2099  call netcdf_err(error, 'DEFINING ALNSF' )
2100  error = nf90_put_att(ncid, id_alnsf, "long_name", "alnsf")
2101  call netcdf_err(error, 'DEFINING ALNSF LONG NAME' )
2102  error = nf90_put_att(ncid, id_alnsf, "units", "none")
2103  call netcdf_err(error, 'DEFINING ALNSF UNITS' )
2104  error = nf90_put_att(ncid, id_alnsf, "coordinates", "geolon geolat")
2105  call netcdf_err(error, 'DEFINING ALNSF COORD' )
2106 
2107  error = nf90_def_var(ncid, 'alnwf', nf90_double, (/dim_x,dim_y,dim_time/), id_alnwf)
2108  call netcdf_err(error, 'DEFINING ALNWF' )
2109  error = nf90_put_att(ncid, id_alnwf, "long_name", "alnwf")
2110  call netcdf_err(error, 'DEFINING ALNWF LONG NAME' )
2111  error = nf90_put_att(ncid, id_alnwf, "units", "none")
2112  call netcdf_err(error, 'DEFINING ALNWF UNITS' )
2113  error = nf90_put_att(ncid, id_alnwf, "coordinates", "geolon geolat")
2114  call netcdf_err(error, 'DEFINING ALNWF COORD' )
2115 
2116  error = nf90_def_var(ncid, 'facsf', nf90_double, (/dim_x,dim_y,dim_time/), id_facsf)
2117  call netcdf_err(error, 'DEFINING FACSF' )
2118  error = nf90_put_att(ncid, id_facsf, "long_name", "facsf")
2119  call netcdf_err(error, 'DEFINING FACSF LONG NAME' )
2120  error = nf90_put_att(ncid, id_facsf, "units", "none")
2121  call netcdf_err(error, 'DEFINING FACSF UNITS' )
2122  error = nf90_put_att(ncid, id_facsf, "coordinates", "geolon geolat")
2123  call netcdf_err(error, 'DEFINING FACSF COORD' )
2124 
2125  error = nf90_def_var(ncid, 'facwf', nf90_double, (/dim_x,dim_y,dim_time/), id_facwf)
2126  call netcdf_err(error, 'DEFINING FACWF' )
2127  error = nf90_put_att(ncid, id_facwf, "long_name", "facwf")
2128  call netcdf_err(error, 'DEFINING FACWF LONG NAME' )
2129  error = nf90_put_att(ncid, id_facwf, "units", "none")
2130  call netcdf_err(error, 'DEFINING FACWF UNITS' )
2131  error = nf90_put_att(ncid, id_facwf, "coordinates", "geolon geolat")
2132  call netcdf_err(error, 'DEFINING FACWF COORD' )
2133 
2134  error = nf90_def_var(ncid, 'vfrac', nf90_double, (/dim_x,dim_y,dim_time/), id_vfrac)
2135  call netcdf_err(error, 'DEFINING VFRAC' )
2136  error = nf90_put_att(ncid, id_vfrac, "long_name", "vfrac")
2137  call netcdf_err(error, 'DEFINING VFRAC LONG NAME' )
2138  error = nf90_put_att(ncid, id_vfrac, "units", "none")
2139  call netcdf_err(error, 'DEFINING VFRAC UNITS' )
2140  error = nf90_put_att(ncid, id_vfrac, "coordinates", "geolon geolat")
2141  call netcdf_err(error, 'DEFINING VFRAC COORD' )
2142 
2143  error = nf90_def_var(ncid, 'canopy', nf90_double, (/dim_x,dim_y,dim_time/), id_canopy)
2144  call netcdf_err(error, 'DEFINING CANOPY' )
2145  error = nf90_put_att(ncid, id_canopy, "long_name", "canopy")
2146  call netcdf_err(error, 'DEFINING CANOPY LONG NAME' )
2147  error = nf90_put_att(ncid, id_canopy, "units", "none")
2148  call netcdf_err(error, 'DEFINING CANOPY UNITS' )
2149  error = nf90_put_att(ncid, id_canopy, "coordinates", "geolon geolat")
2150  call netcdf_err(error, 'DEFINING CANOPY COORD' )
2151 
2152  error = nf90_def_var(ncid, 'f10m', nf90_double, (/dim_x,dim_y,dim_time/), id_f10m)
2153  call netcdf_err(error, 'DEFINING F10M' )
2154  error = nf90_put_att(ncid, id_f10m, "long_name", "f10m")
2155  call netcdf_err(error, 'DEFINING F10M LONG NAME' )
2156  error = nf90_put_att(ncid, id_f10m, "units", "none")
2157  call netcdf_err(error, 'DEFINING F10M UNITS' )
2158  error = nf90_put_att(ncid, id_f10m, "coordinates", "geolon geolat")
2159  call netcdf_err(error, 'DEFINING F10M COORD' )
2160 
2161  error = nf90_def_var(ncid, 't2m', nf90_double, (/dim_x,dim_y,dim_time/), id_t2m)
2162  call netcdf_err(error, 'DEFINING T2M' )
2163  error = nf90_put_att(ncid, id_t2m, "long_name", "t2m")
2164  call netcdf_err(error, 'DEFINING T2M LONG NAME' )
2165  error = nf90_put_att(ncid, id_t2m, "units", "none")
2166  call netcdf_err(error, 'DEFINING T2M UNITS' )
2167  error = nf90_put_att(ncid, id_t2m, "coordinates", "geolon geolat")
2168  call netcdf_err(error, 'DEFINING T2M COORD' )
2169 
2170  error = nf90_def_var(ncid, 'q2m', nf90_double, (/dim_x,dim_y,dim_time/), id_q2m)
2171  call netcdf_err(error, 'DEFINING Q2M' )
2172  error = nf90_put_att(ncid, id_q2m, "long_name", "q2m")
2173  call netcdf_err(error, 'DEFINING Q2M LONG NAME' )
2174  error = nf90_put_att(ncid, id_q2m, "units", "none")
2175  call netcdf_err(error, 'DEFINING Q2M UNITS' )
2176  error = nf90_put_att(ncid, id_q2m, "coordinates", "geolon geolat")
2177  call netcdf_err(error, 'DEFINING Q2M COORD' )
2178 
2179  error = nf90_def_var(ncid, 'vtype', nf90_double, (/dim_x,dim_y,dim_time/), id_vtype)
2180  call netcdf_err(error, 'DEFINING VTYPE' )
2181  error = nf90_put_att(ncid, id_vtype, "long_name", "vtype")
2182  call netcdf_err(error, 'DEFINING VTYPE LONG NAME' )
2183  error = nf90_put_att(ncid, id_vtype, "units", "none")
2184  call netcdf_err(error, 'DEFINING VTYPE UNITS' )
2185  error = nf90_put_att(ncid, id_vtype, "coordinates", "geolon geolat")
2186  call netcdf_err(error, 'DEFINING VTYPE COORD' )
2187 
2188  error = nf90_def_var(ncid, 'stype', nf90_double, (/dim_x,dim_y,dim_time/), id_stype)
2189  call netcdf_err(error, 'DEFINING STYPE' )
2190  error = nf90_put_att(ncid, id_stype, "long_name", "stype")
2191  call netcdf_err(error, 'DEFINING STYPE LONG NAME' )
2192  error = nf90_put_att(ncid, id_stype, "units", "none")
2193  call netcdf_err(error, 'DEFINING STYPE UNITS' )
2194  error = nf90_put_att(ncid, id_stype, "coordinates", "geolon geolat")
2195  call netcdf_err(error, 'DEFINING STYPE COORD' )
2196 
2197  error = nf90_def_var(ncid, 'uustar', nf90_double, (/dim_x,dim_y,dim_time/), id_uustar)
2198  call netcdf_err(error, 'DEFINING UUSTAR' )
2199  error = nf90_put_att(ncid, id_uustar, "long_name", "uustar")
2200  call netcdf_err(error, 'DEFINING UUSTAR LONG NAME' )
2201  error = nf90_put_att(ncid, id_uustar, "units", "none")
2202  call netcdf_err(error, 'DEFINING UUSTAR UNITS' )
2203  error = nf90_put_att(ncid, id_uustar, "coordinates", "geolon geolat")
2204  call netcdf_err(error, 'DEFINING UUSTAR COORD' )
2205 
2206  error = nf90_def_var(ncid, 'ffmm', nf90_double, (/dim_x,dim_y,dim_time/), id_ffmm)
2207  call netcdf_err(error, 'DEFINING FFMM' )
2208  error = nf90_put_att(ncid, id_ffmm, "long_name", "ffmm")
2209  call netcdf_err(error, 'DEFINING FFMM LONG NAME' )
2210  error = nf90_put_att(ncid, id_ffmm, "units", "none")
2211  call netcdf_err(error, 'DEFINING FFMM UNITS' )
2212  error = nf90_put_att(ncid, id_ffmm, "coordinates", "geolon geolat")
2213  call netcdf_err(error, 'DEFINING FFMM COORD' )
2214 
2215  error = nf90_def_var(ncid, 'ffhh', nf90_double, (/dim_x,dim_y,dim_time/), id_ffhh)
2216  call netcdf_err(error, 'DEFINING FFHH' )
2217  error = nf90_put_att(ncid, id_ffhh, "long_name", "ffhh")
2218  call netcdf_err(error, 'DEFINING FFHH LONG NAME' )
2219  error = nf90_put_att(ncid, id_ffhh, "units", "none")
2220  call netcdf_err(error, 'DEFINING FFHH UNITS' )
2221  error = nf90_put_att(ncid, id_ffhh, "coordinates", "geolon geolat")
2222  call netcdf_err(error, 'DEFINING FFHH COORD' )
2223 
2224  error = nf90_def_var(ncid, 'hice', nf90_double, (/dim_x,dim_y,dim_time/), id_hice)
2225  call netcdf_err(error, 'DEFINING HICE' )
2226  error = nf90_put_att(ncid, id_hice, "long_name", "hice")
2227  call netcdf_err(error, 'DEFINING HICE LONG NAME' )
2228  error = nf90_put_att(ncid, id_hice, "units", "none")
2229  call netcdf_err(error, 'DEFINING HICE UNITS' )
2230  error = nf90_put_att(ncid, id_hice, "coordinates", "geolon geolat")
2231  call netcdf_err(error, 'DEFINING HICE COORD' )
2232 
2233  error = nf90_def_var(ncid, 'fice', nf90_double, (/dim_x,dim_y,dim_time/), id_fice)
2234  call netcdf_err(error, 'DEFINING FICE' )
2235  error = nf90_put_att(ncid, id_fice, "long_name", "fice")
2236  call netcdf_err(error, 'DEFINING FICE LONG NAME' )
2237  error = nf90_put_att(ncid, id_fice, "units", "none")
2238  call netcdf_err(error, 'DEFINING FICE UNITS' )
2239  error = nf90_put_att(ncid, id_fice, "coordinates", "geolon geolat")
2240  call netcdf_err(error, 'DEFINING FICE COORD' )
2241 
2242  error = nf90_def_var(ncid, 'tisfc', nf90_double, (/dim_x,dim_y,dim_time/), id_tisfc)
2243  call netcdf_err(error, 'DEFINING TISFC' )
2244  error = nf90_put_att(ncid, id_tisfc, "long_name", "tisfc")
2245  call netcdf_err(error, 'DEFINING TISFC LONG NAME' )
2246  error = nf90_put_att(ncid, id_tisfc, "units", "none")
2247  call netcdf_err(error, 'DEFINING TISFC UNITS' )
2248  error = nf90_put_att(ncid, id_tisfc, "coordinates", "geolon geolat")
2249  call netcdf_err(error, 'DEFINING TISFC COORD' )
2250 
2251  error = nf90_def_var(ncid, 'tprcp', nf90_double, (/dim_x,dim_y,dim_time/), id_tprcp)
2252  call netcdf_err(error, 'DEFINING TPRCP' )
2253  error = nf90_put_att(ncid, id_tprcp, "long_name", "tprcp")
2254  call netcdf_err(error, 'DEFINING TPRCP LONG NAME' )
2255  error = nf90_put_att(ncid, id_tprcp, "units", "none")
2256  call netcdf_err(error, 'DEFINING TPRCP UNITS' )
2257  error = nf90_put_att(ncid, id_tprcp, "coordinates", "geolon geolat")
2258  call netcdf_err(error, 'DEFINING TPRCP COORD' )
2259 
2260  error = nf90_def_var(ncid, 'srflag', nf90_double, (/dim_x,dim_y,dim_time/), id_srflag)
2261  call netcdf_err(error, 'DEFINING SRFLAG' )
2262  error = nf90_put_att(ncid, id_srflag, "long_name", "srflag")
2263  call netcdf_err(error, 'DEFINING SRFLAG LONG NAME' )
2264  error = nf90_put_att(ncid, id_srflag, "units", "none")
2265  call netcdf_err(error, 'DEFINING SRFLAG UNITS' )
2266  error = nf90_put_att(ncid, id_srflag, "coordinates", "geolon geolat")
2267  call netcdf_err(error, 'DEFINING SRFLAG COORD' )
2268 
2269  error = nf90_def_var(ncid, 'snwdph', nf90_double, (/dim_x,dim_y,dim_time/), id_snwdph)
2270  call netcdf_err(error, 'DEFINING SNWDPH' )
2271  error = nf90_put_att(ncid, id_snwdph, "long_name", "snwdph")
2272  call netcdf_err(error, 'DEFINING SNWDPH LONG NAME' )
2273  error = nf90_put_att(ncid, id_snwdph, "units", "none")
2274  call netcdf_err(error, 'DEFINING SNWDPH UNITS' )
2275  error = nf90_put_att(ncid, id_snwdph, "coordinates", "geolon geolat")
2276  call netcdf_err(error, 'DEFINING SNWDPH COORD' )
2277 
2278  error = nf90_def_var(ncid, 'shdmin', nf90_double, (/dim_x,dim_y,dim_time/), id_shdmin)
2279  call netcdf_err(error, 'DEFINING SHDMIN' )
2280  error = nf90_put_att(ncid, id_shdmin, "long_name", "shdmin")
2281  call netcdf_err(error, 'DEFINING SHDMIN LONG NAME' )
2282  error = nf90_put_att(ncid, id_shdmin, "units", "none")
2283  call netcdf_err(error, 'DEFINING SHDMIN UNITS' )
2284  error = nf90_put_att(ncid, id_shdmin, "coordinates", "geolon geolat")
2285  call netcdf_err(error, 'DEFINING SHDMIN COORD' )
2286 
2287  error = nf90_def_var(ncid, 'shdmax', nf90_double, (/dim_x,dim_y,dim_time/), id_shdmax)
2288  call netcdf_err(error, 'DEFINING SHDMAX' )
2289  error = nf90_put_att(ncid, id_shdmax, "long_name", "shdmax")
2290  call netcdf_err(error, 'DEFINING SHDMAX LONG NAME' )
2291  error = nf90_put_att(ncid, id_shdmax, "units", "none")
2292  call netcdf_err(error, 'DEFINING SHDMAX UNITS' )
2293  error = nf90_put_att(ncid, id_shdmax, "coordinates", "geolon geolat")
2294  call netcdf_err(error, 'DEFINING SHDMAX COORD' )
2295 
2296  error = nf90_def_var(ncid, 'slope', nf90_double, (/dim_x,dim_y,dim_time/), id_slope)
2297  call netcdf_err(error, 'DEFINING SLOPE' )
2298  error = nf90_put_att(ncid, id_slope, "long_name", "slope")
2299  call netcdf_err(error, 'DEFINING SLOPE LONG NAME' )
2300  error = nf90_put_att(ncid, id_slope, "units", "none")
2301  call netcdf_err(error, 'DEFINING SLOPE UNITS' )
2302  error = nf90_put_att(ncid, id_slope, "coordinates", "geolon geolat")
2303  call netcdf_err(error, 'DEFINING SLOPE COORD' )
2304 
2305  error = nf90_def_var(ncid, 'snoalb', nf90_double, (/dim_x,dim_y,dim_time/), id_snoalb)
2306  call netcdf_err(error, 'DEFINING SNOALB' )
2307  error = nf90_put_att(ncid, id_snoalb, "long_name", "snoalb")
2308  call netcdf_err(error, 'DEFINING SNOALB LONG NAME' )
2309  error = nf90_put_att(ncid, id_snoalb, "units", "none")
2310  call netcdf_err(error, 'DEFINING SNOALB UNITS' )
2311  error = nf90_put_att(ncid, id_snoalb, "coordinates", "geolon geolat")
2312  call netcdf_err(error, 'DEFINING SNOALB COORD' )
2313 
2314  if (.not. lai_from_climo) then
2315  error = nf90_def_var(ncid, 'lai', nf90_double, (/dim_x,dim_y,dim_time/), id_lai)
2316  call netcdf_err(error, 'DEFINING LAI' )
2317  error = nf90_put_att(ncid, id_lai, "long_name", "lai")
2318  call netcdf_err(error, 'DEFINING LAI LONG NAME' )
2319  error = nf90_put_att(ncid, id_lai, "units", "none")
2320  call netcdf_err(error, 'DEFINING LAI UNITS' )
2321  error = nf90_put_att(ncid, id_lai, "coordinates", "geolon geolat")
2322  call netcdf_err(error, 'DEFINING LAI COORD' )
2323  endif
2324 
2325  error = nf90_def_var(ncid, 'stc', nf90_double, (/dim_x,dim_y,dim_lsoil,dim_time/), id_stc)
2326  call netcdf_err(error, 'DEFINING STC' )
2327  error = nf90_put_att(ncid, id_stc, "long_name", "stc")
2328  call netcdf_err(error, 'DEFINING STC LONG NAME' )
2329  error = nf90_put_att(ncid, id_stc, "units", "none")
2330  call netcdf_err(error, 'DEFINING STC UNITS' )
2331  error = nf90_put_att(ncid, id_stc, "coordinates", "geolon geolat")
2332  call netcdf_err(error, 'DEFINING STC COORD' )
2333 
2334  error = nf90_def_var(ncid, 'smc', nf90_double, (/dim_x,dim_y,dim_lsoil,dim_time/), id_smc)
2335  call netcdf_err(error, 'DEFINING SMC' )
2336  error = nf90_put_att(ncid, id_smc, "long_name", "smc")
2337  call netcdf_err(error, 'DEFINING SMC LONG NAME' )
2338  error = nf90_put_att(ncid, id_smc, "units", "none")
2339  call netcdf_err(error, 'DEFINING SMC UNITS' )
2340  error = nf90_put_att(ncid, id_smc, "coordinates", "geolon geolat")
2341  call netcdf_err(error, 'DEFINING SMC COORD' )
2342 
2343  error = nf90_def_var(ncid, 'slc', nf90_double, (/dim_x,dim_y,dim_lsoil,dim_time/), id_slc)
2344  call netcdf_err(error, 'DEFINING SLC' )
2345  error = nf90_put_att(ncid, id_slc, "long_name", "slc")
2346  call netcdf_err(error, 'DEFINING SLC LONG NAME' )
2347  error = nf90_put_att(ncid, id_slc, "units", "none")
2348  call netcdf_err(error, 'DEFINING SLC UNITS' )
2349  error = nf90_put_att(ncid, id_slc, "coordinates", "geolon geolat")
2350  call netcdf_err(error, 'DEFINING SLC COORD' )
2351 
2352  if (convert_nst) then
2353 
2354  error = nf90_def_var(ncid, 'tref', nf90_double, (/dim_x,dim_y,dim_time/), id_tref)
2355  call netcdf_err(error, 'DEFINING TREF' )
2356  error = nf90_put_att(ncid, id_tref, "long_name", "tref")
2357  call netcdf_err(error, 'DEFINING TREF LONG NAME' )
2358  error = nf90_put_att(ncid, id_tref, "units", "none")
2359  call netcdf_err(error, 'DEFINING TREF UNITS' )
2360  error = nf90_put_att(ncid, id_tref, "coordinates", "geolon geolat")
2361  call netcdf_err(error, 'DEFINING TREF COORD' )
2362 
2363  error = nf90_def_var(ncid, 'z_c', nf90_double, (/dim_x,dim_y,dim_time/), id_z_c)
2364  call netcdf_err(error, 'DEFINING Z_C' )
2365  error = nf90_put_att(ncid, id_z_c, "long_name", "z_c")
2366  call netcdf_err(error, 'DEFINING Z_C LONG NAME' )
2367  error = nf90_put_att(ncid, id_z_c, "units", "none")
2368  call netcdf_err(error, 'DEFINING Z_C UNITS' )
2369  error = nf90_put_att(ncid, id_z_c, "coordinates", "geolon geolat")
2370  call netcdf_err(error, 'DEFINING Z_C COORD' )
2371 
2372  error = nf90_def_var(ncid, 'c_0', nf90_double, (/dim_x,dim_y,dim_time/), id_c_0)
2373  call netcdf_err(error, 'DEFINING C_0' )
2374  error = nf90_put_att(ncid, id_c_0, "long_name", "c_0")
2375  call netcdf_err(error, 'DEFINING C_0 LONG NAME' )
2376  error = nf90_put_att(ncid, id_c_0, "units", "none")
2377  call netcdf_err(error, 'DEFINING C_0 UNITS' )
2378  error = nf90_put_att(ncid, id_c_0, "coordinates", "geolon geolat")
2379  call netcdf_err(error, 'DEFINING C_0 COORD' )
2380 
2381  error = nf90_def_var(ncid, 'c_d', nf90_double, (/dim_x,dim_y,dim_time/), id_c_d)
2382  call netcdf_err(error, 'DEFINING C_D' )
2383  error = nf90_put_att(ncid, id_c_d, "long_name", "c_d")
2384  call netcdf_err(error, 'DEFINING C_D LONG NAME' )
2385  error = nf90_put_att(ncid, id_c_d, "units", "none")
2386  call netcdf_err(error, 'DEFINING C_D UNITS' )
2387  error = nf90_put_att(ncid, id_c_d, "coordinates", "geolon geolat")
2388  call netcdf_err(error, 'DEFINING C_D COORD' )
2389 
2390  error = nf90_def_var(ncid, 'w_0', nf90_double, (/dim_x,dim_y,dim_time/), id_w_0)
2391  call netcdf_err(error, 'DEFINING W_0' )
2392  error = nf90_put_att(ncid, id_w_0, "long_name", "w_0")
2393  call netcdf_err(error, 'DEFINING W_0 LONG NAME' )
2394  error = nf90_put_att(ncid, id_w_0, "units", "none")
2395  call netcdf_err(error, 'DEFINING W_0 UNITS' )
2396  error = nf90_put_att(ncid, id_w_0, "coordinates", "geolon geolat")
2397  call netcdf_err(error, 'DEFINING W_0 COORD' )
2398 
2399  error = nf90_def_var(ncid, 'w_d', nf90_double, (/dim_x,dim_y,dim_time/), id_w_d)
2400  call netcdf_err(error, 'DEFINING W_D' )
2401  error = nf90_put_att(ncid, id_w_d, "long_name", "w_d")
2402  call netcdf_err(error, 'DEFINING W_D LONG NAME' )
2403  error = nf90_put_att(ncid, id_w_d, "units", "none")
2404  call netcdf_err(error, 'DEFINING W_D UNITS' )
2405  error = nf90_put_att(ncid, id_w_d, "coordinates", "geolon geolat")
2406  call netcdf_err(error, 'DEFINING W_D COORD' )
2407 
2408  error = nf90_def_var(ncid, 'xt', nf90_double, (/dim_x,dim_y,dim_time/), id_xt)
2409  call netcdf_err(error, 'DEFINING XT' )
2410  error = nf90_put_att(ncid, id_xt, "long_name", "xt")
2411  call netcdf_err(error, 'DEFINING XT LONG NAME' )
2412  error = nf90_put_att(ncid, id_xt, "units", "none")
2413  call netcdf_err(error, 'DEFINING XT UNITS' )
2414  error = nf90_put_att(ncid, id_xt, "coordinates", "geolon geolat")
2415  call netcdf_err(error, 'DEFINING XT COORD' )
2416 
2417  error = nf90_def_var(ncid, 'xs', nf90_double, (/dim_x,dim_y,dim_time/), id_xs)
2418  call netcdf_err(error, 'DEFINING XS' )
2419  error = nf90_put_att(ncid, id_xs, "long_name", "xs")
2420  call netcdf_err(error, 'DEFINING XS LONG NAME' )
2421  error = nf90_put_att(ncid, id_xs, "units", "none")
2422  call netcdf_err(error, 'DEFINING XS UNITS' )
2423  error = nf90_put_att(ncid, id_xs, "coordinates", "geolon geolat")
2424  call netcdf_err(error, 'DEFINING XS COORD' )
2425 
2426  error = nf90_def_var(ncid, 'xu', nf90_double, (/dim_x,dim_y,dim_time/), id_xu)
2427  call netcdf_err(error, 'DEFINING XU' )
2428  error = nf90_put_att(ncid, id_xu, "long_name", "xu")
2429  call netcdf_err(error, 'DEFINING XU LONG NAME' )
2430  error = nf90_put_att(ncid, id_xu, "units", "none")
2431  call netcdf_err(error, 'DEFINING XU UNITS' )
2432  error = nf90_put_att(ncid, id_xu, "coordinates", "geolon geolat")
2433  call netcdf_err(error, 'DEFINING XU COORD' )
2434 
2435  error = nf90_def_var(ncid, 'xv', nf90_double, (/dim_x,dim_y,dim_time/), id_xv)
2436  call netcdf_err(error, 'DEFINING XV' )
2437  error = nf90_put_att(ncid, id_xv, "long_name", "xv")
2438  call netcdf_err(error, 'DEFINING XV LONG NAME' )
2439  error = nf90_put_att(ncid, id_xv, "units", "none")
2440  call netcdf_err(error, 'DEFINING XV UNITS' )
2441  error = nf90_put_att(ncid, id_xv, "coordinates", "geolon geolat")
2442  call netcdf_err(error, 'DEFINING XV COORD' )
2443 
2444  error = nf90_def_var(ncid, 'xz', nf90_double, (/dim_x,dim_y,dim_time/), id_xz)
2445  call netcdf_err(error, 'DEFINING XZ' )
2446  error = nf90_put_att(ncid, id_xz, "long_name", "xz")
2447  call netcdf_err(error, 'DEFINING XZ LONG NAME' )
2448  error = nf90_put_att(ncid, id_xz, "units", "none")
2449  call netcdf_err(error, 'DEFINING XZ UNITS' )
2450  error = nf90_put_att(ncid, id_xz, "coordinates", "geolon geolat")
2451  call netcdf_err(error, 'DEFINING XZ COORD' )
2452 
2453  error = nf90_def_var(ncid, 'zm', nf90_double, (/dim_x,dim_y,dim_time/), id_zm)
2454  call netcdf_err(error, 'DEFINING ZM' )
2455  error = nf90_put_att(ncid, id_zm, "long_name", "zm")
2456  call netcdf_err(error, 'DEFINING ZM LONG NAME' )
2457  error = nf90_put_att(ncid, id_zm, "units", "none")
2458  call netcdf_err(error, 'DEFINING ZM UNITS' )
2459  error = nf90_put_att(ncid, id_zm, "coordinates", "geolon geolat")
2460  call netcdf_err(error, 'DEFINING ZM COORD' )
2461 
2462  error = nf90_def_var(ncid, 'xtts', nf90_double, (/dim_x,dim_y,dim_time/), id_xtts)
2463  call netcdf_err(error, 'DEFINING XTTS' )
2464  error = nf90_put_att(ncid, id_xtts, "long_name", "xtts")
2465  call netcdf_err(error, 'DEFINING XTTS LONG NAME' )
2466  error = nf90_put_att(ncid, id_xtts, "units", "none")
2467  call netcdf_err(error, 'DEFINING XTTS UNITS' )
2468  error = nf90_put_att(ncid, id_xtts, "coordinates", "geolon geolat")
2469  call netcdf_err(error, 'DEFINING XTTS COORD' )
2470 
2471  error = nf90_def_var(ncid, 'xzts', nf90_double, (/dim_x,dim_y,dim_time/), id_xzts)
2472  call netcdf_err(error, 'DEFINING XZTS' )
2473  error = nf90_put_att(ncid, id_xzts, "long_name", "xzts")
2474  call netcdf_err(error, 'DEFINING XZTS LONG NAME' )
2475  error = nf90_put_att(ncid, id_xzts, "units", "none")
2476  call netcdf_err(error, 'DEFINING XZTS UNITS' )
2477  error = nf90_put_att(ncid, id_xzts, "coordinates", "geolon geolat")
2478  call netcdf_err(error, 'DEFINING XZTS COORD' )
2479 
2480  error = nf90_def_var(ncid, 'd_conv', nf90_double, (/dim_x,dim_y,dim_time/), id_d_conv)
2481  call netcdf_err(error, 'DEFINING D_CONV' )
2482  error = nf90_put_att(ncid, id_d_conv, "long_name", "d_conv")
2483  call netcdf_err(error, 'DEFINING D_CONV LONG NAME' )
2484  error = nf90_put_att(ncid, id_d_conv, "units", "none")
2485  call netcdf_err(error, 'DEFINING D_CONV UNITS' )
2486  error = nf90_put_att(ncid, id_d_conv, "coordinates", "geolon geolat")
2487  call netcdf_err(error, 'DEFINING D_CONV COORD' )
2488 
2489  error = nf90_def_var(ncid, 'ifd', nf90_double, (/dim_x,dim_y,dim_time/), id_ifd)
2490  call netcdf_err(error, 'DEFINING IFD' )
2491  error = nf90_put_att(ncid, id_ifd, "long_name", "ifd")
2492  call netcdf_err(error, 'DEFINING IFD LONG NAME' )
2493  error = nf90_put_att(ncid, id_ifd, "units", "none")
2494  call netcdf_err(error, 'DEFINING IFD UNITS' )
2495  error = nf90_put_att(ncid, id_ifd, "coordinates", "geolon geolat")
2496  call netcdf_err(error, 'DEFINING IFD COORD' )
2497 
2498  error = nf90_def_var(ncid, 'dt_cool', nf90_double, (/dim_x,dim_y,dim_time/), id_dt_cool)
2499  call netcdf_err(error, 'DEFINING DT_COOL' )
2500  error = nf90_put_att(ncid, id_dt_cool, "long_name", "dt_cool")
2501  call netcdf_err(error, 'DEFINING DT_COOL LONG NAME' )
2502  error = nf90_put_att(ncid, id_dt_cool, "units", "none")
2503  call netcdf_err(error, 'DEFINING DT_COOL UNITS' )
2504  error = nf90_put_att(ncid, id_dt_cool, "coordinates", "geolon geolat")
2505  call netcdf_err(error, 'DEFINING DT_COOL COORD' )
2506 
2507  error = nf90_def_var(ncid, 'qrain', nf90_double, (/dim_x,dim_y,dim_time/), id_qrain)
2508  call netcdf_err(error, 'DEFINING QRAIN' )
2509  error = nf90_put_att(ncid, id_qrain, "long_name", "qrain")
2510  call netcdf_err(error, 'DEFINING QRAIN LONG NAME' )
2511  error = nf90_put_att(ncid, id_qrain, "units", "none")
2512  call netcdf_err(error, 'DEFINING QRAIN UNITS' )
2513  error = nf90_put_att(ncid, id_qrain, "coordinates", "geolon geolat")
2514  call netcdf_err(error, 'DEFINING QRAIN COORD' )
2515 
2516  endif ! nsst records
2517 
2518  error = nf90_enddef(ncid, header_buffer_val,4,0,4)
2519  call netcdf_err(error, 'DEFINING HEADER' )
2520 
2521  endif local_pet ! is localpet 0?
2522 
2523  if (localpet == 0) then
2524  error = nf90_put_var( ncid, id_lsoil, lsoil_data)
2525  call netcdf_err(error, 'WRITING ZAXIS RECORD' )
2526  error = nf90_put_var( ncid, id_x, x_data)
2527  call netcdf_err(error, 'WRITING XAXIS RECORD' )
2528  error = nf90_put_var( ncid, id_y, y_data)
2529  call netcdf_err(error, 'WRITING YAXIS RECORD' )
2530  times = 1.0
2531  error = nf90_put_var( ncid, id_time, times)
2532  call netcdf_err(error, 'WRITING TIME RECORD' )
2533  endif
2534 
2535  print*,"- CALL FieldGather FOR TARGET GRID LATITUDE FOR TILE: ", tile
2536  call esmf_fieldgather(latitude_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2537  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2538  call error_handler("IN FieldGather", error)
2539 
2540  if (localpet == 0) then
2541  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2542  error = nf90_put_var( ncid, id_lat, dum2d)
2543  call netcdf_err(error, 'WRITING LATITUDE RECORD' )
2544  endif
2545 
2546  print*,"- CALL FieldGather FOR TARGET GRID LONGITUDE FOR TILE: ", tile
2547  call esmf_fieldgather(longitude_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2548  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2549  call error_handler("IN FieldGather", error)
2550 
2551  if (localpet == 0) then
2552  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2553  error = nf90_put_var( ncid, id_lon, dum2d)
2554  call netcdf_err(error, 'WRITING LONGITUDE RECORD' )
2555  endif
2556 
2557  print*,"- CALL FieldGather FOR TARGET GRID SNOW LIQ EQUIV FOR TILE: ", tile
2558  call esmf_fieldgather(snow_liq_equiv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2559  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2560  call error_handler("IN FieldGather", error)
2561 
2562  if (localpet == 0) then
2563  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2564  error = nf90_put_var( ncid, id_sheleg, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2565  call netcdf_err(error, 'WRITING SNOW LIQ EQUIV RECORD' )
2566  endif
2567 
2568  print*,"- CALL FieldGather FOR TARGET GRID SNOW DEPTH FOR TILE: ", tile
2569  call esmf_fieldgather(snow_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2570  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2571  call error_handler("IN FieldGather", error)
2572 
2573  if (localpet == 0) then
2574  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2575  error = nf90_put_var( ncid, id_snwdph, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2576  call netcdf_err(error, 'WRITING SNWDPH RECORD' )
2577  endif
2578 
2579  print*,"- CALL FieldGather FOR TARGET GRID SLOPE TYPE FOR TILE: ", tile
2580  call esmf_fieldgather(slope_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2581  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2582  call error_handler("IN FieldGather", error)
2583 
2584  if (localpet == 0) then
2585  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2586  error = nf90_put_var( ncid, id_slope, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2587  call netcdf_err(error, 'WRITING SLOPE RECORD' )
2588  endif
2589 
2590  print*,"- CALL FieldGather FOR TARGET GRID Z0 FOR TILE: ", tile
2591  call esmf_fieldgather(z0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2592  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2593  call error_handler("IN FieldGather", error)
2594 
2595  if (localpet == 0) then
2596  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2597  error = nf90_put_var( ncid, id_zorl, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2598  call netcdf_err(error, 'WRITING Z0 RECORD' )
2599  endif
2600 
2601  print*,"- CALL FieldGather FOR TARGET GRID MAX SNOW ALBEDO FOR TILE: ", tile
2602  call esmf_fieldgather(mxsno_albedo_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2603  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2604  call error_handler("IN FieldGather", error)
2605 
2606  if (localpet == 0) then
2607  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2608  error = nf90_put_var( ncid, id_snoalb, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2609  call netcdf_err(error, 'WRITING MAX SNOW ALBEDO RECORD' )
2610  endif
2611 
2612  if (.not. lai_from_climo) then
2613  print*,"- CALL FieldGather FOR TARGET GRID LEAF AREA INDEX FOR TILE: ", tile
2614  call esmf_fieldgather(lai_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2615  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2616  call error_handler("IN FieldGather", error)
2617 
2618  if (localpet == 0) then
2619  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2620  error = nf90_put_var( ncid, id_lai, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2621  call netcdf_err(error, 'WRITING LEAF AREA INDEX RECORD' )
2622  endif
2623  endif
2624 
2625  print*,"- CALL FieldGather FOR TARGET GRID SOIL TYPE FOR TILE: ", tile
2626  call esmf_fieldgather(soil_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2627  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2628  call error_handler("IN FieldGather", error)
2629 
2630  if (localpet == 0) then
2631  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2632  error = nf90_put_var( ncid, id_stype, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2633  call netcdf_err(error, 'WRITING SOIL TYPE RECORD' )
2634  endif
2635 
2636  print*,"- CALL FieldGather FOR TARGET GRID VEGETATION TYPE FOR TILE: ", tile
2637  call esmf_fieldgather(veg_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2638  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2639  call error_handler("IN FieldGather", error)
2640 
2641  if (localpet == 0) then
2642  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2643  error = nf90_put_var( ncid, id_vtype, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2644  call netcdf_err(error, 'WRITING VEGETATION TYPE RECORD' )
2645  endif
2646 
2647  print*,"- CALL FieldGather FOR TARGET GRID VEGETATION GREENNESS FOR TILE: ", tile
2648  call esmf_fieldgather(veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2649  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2650  call error_handler("IN FieldGather", error)
2651 
2652  if (localpet == 0) then
2653  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2654  error = nf90_put_var( ncid, id_vfrac, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2655  call netcdf_err(error, 'WRITING VEGETATION GREENNESS RECORD' )
2656  endif
2657 
2658  print*,"- CALL FieldGather FOR TARGET GRID SUBSTRATE TEMPERATURE FOR TILE: ", tile
2659  call esmf_fieldgather(substrate_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2660  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2661  call error_handler("IN FieldGather", error)
2662 
2663  if (localpet == 0) then
2664  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2665  error = nf90_put_var( ncid, id_tg3, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2666  call netcdf_err(error, 'WRITING SUBSTRATE TEMPERATURE RECORD' )
2667  endif
2668 
2669  print*,"- CALL FieldGather FOR TARGET GRID FACSF FOR TILE: ", tile
2670  call esmf_fieldgather(facsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2671  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2672  call error_handler("IN FieldGather", error)
2673 
2674  if (localpet == 0) then
2675  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2676  error = nf90_put_var( ncid, id_facsf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2677  call netcdf_err(error, 'WRITING FACSF RECORD' )
2678  endif
2679 
2680  print*,"- CALL FieldGather FOR TARGET GRID FACWF FOR TILE: ", tile
2681  call esmf_fieldgather(facwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2682  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2683  call error_handler("IN FieldGather", error)
2684 
2685  if (localpet == 0) then
2686  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2687  error = nf90_put_var( ncid, id_facwf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2688  call netcdf_err(error, 'WRITING FACWF RECORD' )
2689  endif
2690 
2691  print*,"- CALL FieldGather FOR TARGET GRID ALNSF FOR TILE: ", tile
2692  call esmf_fieldgather(alnsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2693  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2694  call error_handler("IN FieldGather", error)
2695 
2696  if (localpet == 0) then
2697  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2698  error = nf90_put_var( ncid, id_alnsf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2699  call netcdf_err(error, 'WRITING ALNSF RECORD' )
2700  endif
2701 
2702  print*,"- CALL FieldGather FOR TARGET GRID ALNWF FOR TILE: ", tile
2703  call esmf_fieldgather(alnwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2704  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2705  call error_handler("IN FieldGather", error)
2706 
2707  if (localpet == 0) then
2708  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2709  error = nf90_put_var( ncid, id_alnwf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2710  call netcdf_err(error, 'WRITING ALNWF RECORD' )
2711  endif
2712 
2713  print*,"- CALL FieldGather FOR TARGET GRID ALVSF FOR TILE: ", tile
2714  call esmf_fieldgather(alvsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2715  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2716  call error_handler("IN FieldGather", error)
2717 
2718  if (localpet == 0) then
2719  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2720  error = nf90_put_var( ncid, id_alvsf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2721  call netcdf_err(error, 'WRITING ALVSF RECORD' )
2722  endif
2723 
2724  print*,"- CALL FieldGather FOR TARGET GRID ALVWF FOR TILE: ", tile
2725  call esmf_fieldgather(alvwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2726  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2727  call error_handler("IN FieldGather", error)
2728 
2729  if (localpet == 0) then
2730  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2731  error = nf90_put_var( ncid, id_alvwf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2732  call netcdf_err(error, 'WRITING ALVWF RECORD' )
2733  endif
2734 
2735  print*,"- CALL FieldGather FOR TARGET GRID MAX VEGETATION GREENNESS FOR TILE: ", tile
2736  call esmf_fieldgather(max_veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2737  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2738  call error_handler("IN FieldGather", error)
2739 
2740  if (localpet == 0) then
2741  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2742  error = nf90_put_var( ncid, id_shdmax, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2743  call netcdf_err(error, 'WRITING MAX VEGETATION GREENNESS RECORD' )
2744  endif
2745 
2746  print*,"- CALL FieldGather FOR TARGET GRID MIN VEGETATION GREENNESS FOR TILE: ", tile
2747  call esmf_fieldgather(min_veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2748  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2749  call error_handler("IN FieldGather", error)
2750 
2751  if (localpet == 0) then
2752  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2753  error = nf90_put_var( ncid, id_shdmin, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2754  call netcdf_err(error, 'WRITING MIN VEGETATION GREENNESS RECORD' )
2755  endif
2756 
2757  print*,"- CALL FieldGather FOR TARGET GRID T2M FOR TILE: ", tile
2758  call esmf_fieldgather(t2m_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2759  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2760  call error_handler("IN FieldGather", error)
2761 
2762  if (localpet == 0) then
2763  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2764  error = nf90_put_var( ncid, id_t2m, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2765  call netcdf_err(error, 'WRITING T2M RECORD' )
2766  endif
2767 
2768  print*,"- CALL FieldGather FOR TARGET GRID Q2M FOR TILE: ", tile
2769  call esmf_fieldgather(q2m_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2770  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2771  call error_handler("IN FieldGather", error)
2772 
2773  if (localpet == 0) then
2774  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2775  error = nf90_put_var( ncid, id_q2m, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2776  call netcdf_err(error, 'WRITING Q2M RECORD' )
2777  endif
2778 
2779  print*,"- CALL FieldGather FOR TARGET GRID TPRCP FOR TILE: ", tile
2780  call esmf_fieldgather(tprcp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2781  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2782  call error_handler("IN FieldGather", error)
2783 
2784  if (localpet == 0) then
2785  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2786  error = nf90_put_var( ncid, id_tprcp, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2787  call netcdf_err(error, 'WRITING TPRCP RECORD' )
2788  endif
2789 
2790  print*,"- CALL FieldGather FOR TARGET GRID F10M FOR TILE: ", tile
2791  call esmf_fieldgather(f10m_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2792  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2793  call error_handler("IN FieldGather", error)
2794 
2795  if (localpet == 0) then
2796  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2797  error = nf90_put_var( ncid, id_f10m, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2798  call netcdf_err(error, 'WRITING F10M RECORD' )
2799  endif
2800 
2801  print*,"- CALL FieldGather FOR TARGET GRID FFMM FOR TILE: ", tile
2802  call esmf_fieldgather(ffmm_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2803  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2804  call error_handler("IN FieldGather", error)
2805 
2806  if (localpet == 0) then
2807  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2808  error = nf90_put_var( ncid, id_ffmm, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2809  call netcdf_err(error, 'WRITING FFMM RECORD' )
2810  dum2d = 0.0
2811  error = nf90_put_var( ncid, id_ffhh, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2812  call netcdf_err(error, 'WRITING FFHH RECORD' )
2813  endif
2814 
2815  print*,"- CALL FieldGather FOR TARGET GRID USTAR FOR TILE: ", tile
2816  call esmf_fieldgather(ustar_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2817  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2818  call error_handler("IN FieldGather", error)
2819 
2820  if (localpet == 0) then
2821  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2822  error = nf90_put_var( ncid, id_uustar, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2823  call netcdf_err(error, 'WRITING USTAR RECORD' )
2824  endif
2825 
2826  print*,"- CALL FieldGather FOR TARGET GRID SRFLAG FOR TILE: ", tile
2827  call esmf_fieldgather(srflag_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2828  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2829  call error_handler("IN FieldGather", error)
2830 
2831  if (localpet == 0) then
2832  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2833  error = nf90_put_var( ncid, id_srflag, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2834  call netcdf_err(error, 'WRITING SRFLAG RECORD' )
2835  endif
2836 
2837  print*,"- CALL FieldGather FOR TARGET GRID SEA ICE FRACTION FOR TILE: ", tile
2838  call esmf_fieldgather(seaice_fract_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2839  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2840  call error_handler("IN FieldGather", error)
2841 
2842  if (localpet == 0) then
2843  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2844  error = nf90_put_var( ncid, id_fice, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2845  call netcdf_err(error, 'WRITING FICE RECORD' )
2846  endif
2847 
2848  print*,"- CALL FieldGather FOR TARGET GRID SEA ICE DEPTH FOR TILE: ", tile
2849  call esmf_fieldgather(seaice_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2850  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2851  call error_handler("IN FieldGather", error)
2852 
2853  if (localpet == 0) then
2854  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2855  error = nf90_put_var( ncid, id_hice, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2856  call netcdf_err(error, 'WRITING HICE RECORD' )
2857  endif
2858 
2859  print*,"- CALL FieldGather FOR TARGET GRID SEA ICE SKIN TEMP FOR TILE: ", tile
2860  call esmf_fieldgather(seaice_skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2861  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2862  call error_handler("IN FieldGather", error)
2863 
2864  if (localpet == 0) then
2865  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2866  error = nf90_put_var( ncid, id_tisfc, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2867  call netcdf_err(error, 'WRITING TISFC RECORD' )
2868  endif
2869 
2870  print*,"- CALL FieldGather FOR TARGET GRID SKIN TEMP FOR TILE: ", tile
2871  call esmf_fieldgather(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2872  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2873  call error_handler("IN FieldGather", error)
2874 
2875  if (localpet == 0) then
2876  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2877  error = nf90_put_var( ncid, id_tsea, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2878  call netcdf_err(error, 'WRITING TSEA RECORD' )
2879  endif
2880 
2881  print*,"- CALL FieldGather FOR TARGET GRID LANDMASK FOR TILE: ", tile
2882  call esmf_fieldgather(landmask_target_grid, idata_one_tile, rootpet=0, tile=tile, rc=error)
2883  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2884  call error_handler("IN FieldGather", error)
2885 
2886  if (localpet == 0) then
2887  dum2d(:,:) = float(idata_one_tile(istart:iend, jstart:jend))
2888  error = nf90_put_var( ncid, id_slmsk, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2889  call netcdf_err(error, 'WRITING LANDMASK RECORD' )
2890  endif
2891 
2892  print*,"- CALL FieldGather FOR TARGET GRID CANOPY MOISTURE CONTENT FOR TILE: ", tile
2893  call esmf_fieldgather(canopy_mc_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2894  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2895  call error_handler("IN FieldGather", error)
2896 
2897  if (localpet == 0) then
2898  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2899  error = nf90_put_var( ncid, id_canopy, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2900  call netcdf_err(error, 'WRITING CANOPY MC RECORD' )
2901  endif
2902 
2903 ! soil temperature
2904 
2905  print*,"- CALL FieldGather FOR TARGET GRID SOIL TEMPERATURE FOR TILE: ", tile
2906  call esmf_fieldgather(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
2907  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2908  call error_handler("IN FieldGather", error)
2909 
2910  if (localpet == 0) then
2911  dum3d(:,:,:) = data_one_tile_3d(istart:iend, jstart:jend,:)
2912  error = nf90_put_var( ncid, id_stc, dum3d, start=(/1,1,1,1/), count=(/i_target_out,j_target_out,lsoil_target,1/))
2913  call netcdf_err(error, 'WRITING SOIL TEMP RECORD' )
2914  endif
2915 
2916 ! soil moisture (total)
2917 
2918  print*,"- CALL FieldGather FOR TARGET GRID TOTAL SOIL MOISTURE FOR TILE: ", tile
2919  call esmf_fieldgather(soilm_tot_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
2920  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2921  call error_handler("IN FieldGather", error)
2922 
2923  if (localpet == 0) then
2924  dum3d(:,:,:) = data_one_tile_3d(istart:iend, jstart:jend,:)
2925  error = nf90_put_var( ncid, id_smc, dum3d, start=(/1,1,1,1/), count=(/i_target_out,j_target_out,lsoil_target,1/))
2926  call netcdf_err(error, 'WRITING TOTAL SOIL MOISTURE RECORD' )
2927  endif
2928 
2929 ! soil moisture (liquid)
2930 
2931  print*,"- CALL FieldGather FOR TARGET GRID LIQUID SOIL MOISTURE FOR TILE: ", tile
2932  call esmf_fieldgather(soilm_liq_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
2933  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2934  call error_handler("IN FieldGather", error)
2935 
2936  if (localpet == 0) then
2937  dum3d(:,:,:) = data_one_tile_3d(istart:iend, jstart:jend,:)
2938  error = nf90_put_var( ncid, id_slc, dum3d, start=(/1,1,1,1/), count=(/i_target_out,j_target_out,lsoil_target,1/))
2939  call netcdf_err(error, 'WRITING LIQUID SOIL MOISTURE RECORD' )
2940  endif
2941 
2942  if (convert_nst) then
2943 
2944  print*,"- CALL FieldGather FOR TARGET C_D FOR TILE: ", tile
2945  call esmf_fieldgather(c_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2946  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2947  call error_handler("IN FieldGather", error)
2948 
2949  if (localpet == 0) then
2950  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2951  error = nf90_put_var( ncid, id_c_d, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2952  call netcdf_err(error, 'WRITING C_D RECORD' )
2953  endif
2954 
2955  print*,"- CALL FieldGather FOR TARGET C_0 FOR TILE: ", tile
2956  call esmf_fieldgather(c_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2957  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2958  call error_handler("IN FieldGather", error)
2959 
2960  if (localpet == 0) then
2961  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2962  error = nf90_put_var( ncid, id_c_0, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2963  call netcdf_err(error, 'WRITING C_0 RECORD' )
2964  endif
2965 
2966  print*,"- CALL FieldGather FOR TARGET D_CONV FOR TILE: ", tile
2967  call esmf_fieldgather(d_conv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2968  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2969  call error_handler("IN FieldGather", error)
2970 
2971  if (localpet == 0) then
2972  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2973  error = nf90_put_var( ncid, id_d_conv, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2974  call netcdf_err(error, 'WRITING D_CONV RECORD' )
2975  endif
2976 
2977  print*,"- CALL FieldGather FOR TARGET DT_COOL FOR TILE: ", tile
2978  call esmf_fieldgather(dt_cool_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2979  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2980  call error_handler("IN FieldGather", error)
2981 
2982  if (localpet == 0) then
2983  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2984  error = nf90_put_var( ncid, id_dt_cool, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2985  call netcdf_err(error, 'WRITING DT_COOL RECORD' )
2986  endif
2987 
2988  print*,"- CALL FieldGather FOR TARGET IFD FOR TILE: ", tile
2989  call esmf_fieldgather(ifd_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2990  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2991  call error_handler("IN FieldGather", error)
2992 
2993  if (localpet == 0) then
2994  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2995  error = nf90_put_var( ncid, id_ifd, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2996  call netcdf_err(error, 'WRITING IFD RECORD' )
2997  endif
2998 
2999  print*,"- CALL FieldGather FOR TARGET QRAIN FOR TILE: ", tile
3000  call esmf_fieldgather(qrain_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3001  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3002  call error_handler("IN FieldGather", error)
3003 
3004  if (localpet == 0) then
3005  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3006  error = nf90_put_var( ncid, id_qrain, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3007  call netcdf_err(error, 'WRITING QRAIN RECORD' )
3008  endif
3009 
3010  print*,"- CALL FieldGather FOR TARGET TREF FOR TILE: ", tile
3011  call esmf_fieldgather(tref_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3012  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3013  call error_handler("IN FieldGather", error)
3014 
3015  if (localpet == 0) then
3016  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3017  error = nf90_put_var( ncid, id_tref, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3018  call netcdf_err(error, 'WRITING TREF RECORD' )
3019  endif
3020 
3021  print*,"- CALL FieldGather FOR TARGET W_D FOR TILE: ", tile
3022  call esmf_fieldgather(w_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3023  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3024  call error_handler("IN FieldGather", error)
3025 
3026  if (localpet == 0) then
3027  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3028  error = nf90_put_var( ncid, id_w_d, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3029  call netcdf_err(error, 'WRITING W_D RECORD' )
3030  endif
3031 
3032  print*,"- CALL FieldGather FOR TARGET W_0 FOR TILE: ", tile
3033  call esmf_fieldgather(w_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3034  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3035  call error_handler("IN FieldGather", error)
3036 
3037  if (localpet == 0) then
3038  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3039  error = nf90_put_var( ncid, id_w_0, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3040  call netcdf_err(error, 'WRITING W_0 RECORD' )
3041  endif
3042 
3043  print*,"- CALL FieldGather FOR TARGET XS FOR TILE: ", tile
3044  call esmf_fieldgather(xs_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3045  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3046  call error_handler("IN FieldGather", error)
3047 
3048  if (localpet == 0) then
3049  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3050  error = nf90_put_var( ncid, id_xs, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3051  call netcdf_err(error, 'WRITING XS RECORD' )
3052  endif
3053 
3054  print*,"- CALL FieldGather FOR TARGET XT FOR TILE: ", tile
3055  call esmf_fieldgather(xt_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3056  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3057  call error_handler("IN FieldGather", error)
3058 
3059  if (localpet == 0) then
3060  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3061  error = nf90_put_var( ncid, id_xt, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3062  call netcdf_err(error, 'WRITING XT RECORD' )
3063  endif
3064 
3065  print*,"- CALL FieldGather FOR TARGET XU FOR TILE: ", tile
3066  call esmf_fieldgather(xu_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3067  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3068  call error_handler("IN FieldGather", error)
3069 
3070  if (localpet == 0) then
3071  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3072  error = nf90_put_var( ncid, id_xu, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3073  call netcdf_err(error, 'WRITING XU RECORD' )
3074  endif
3075 
3076  print*,"- CALL FieldGather FOR TARGET XV FOR TILE: ", tile
3077  call esmf_fieldgather(xv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3078  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3079  call error_handler("IN FieldGather", error)
3080 
3081  if (localpet == 0) then
3082  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3083  error = nf90_put_var( ncid, id_xv, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3084  call netcdf_err(error, 'WRITING XV RECORD' )
3085  endif
3086 
3087  print*,"- CALL FieldGather FOR TARGET XZ FOR TILE: ", tile
3088  call esmf_fieldgather(xz_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3089  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3090  call error_handler("IN FieldGather", error)
3091 
3092  if (localpet == 0) then
3093  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3094  error = nf90_put_var( ncid, id_xz, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3095  call netcdf_err(error, 'WRITING XZ RECORD' )
3096  endif
3097 
3098  print*,"- CALL FieldGather FOR TARGET XTTS FOR TILE: ", tile
3099  call esmf_fieldgather(xtts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3100  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3101  call error_handler("IN FieldGather", error)
3102 
3103  if (localpet == 0) then
3104  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3105  error = nf90_put_var( ncid, id_xtts, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3106  call netcdf_err(error, 'WRITING XTTS RECORD' )
3107  endif
3108 
3109  print*,"- CALL FieldGather FOR TARGET XZTS FOR TILE: ", tile
3110  call esmf_fieldgather(xzts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3111  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3112  call error_handler("IN FieldGather", error)
3113 
3114  if (localpet == 0) then
3115  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3116  error = nf90_put_var( ncid, id_xzts, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3117  call netcdf_err(error, 'WRITING XZTS RECORD' )
3118  endif
3119 
3120  print*,"- CALL FieldGather FOR TARGET Z_C FOR TILE: ", tile
3121  call esmf_fieldgather(z_c_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3122  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3123  call error_handler("IN FieldGather", error)
3124 
3125  if (localpet == 0) then
3126  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3127  error = nf90_put_var( ncid, id_z_c, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3128  call netcdf_err(error, 'WRITING Z_C RECORD' )
3129  endif
3130 
3131  print*,"- CALL FieldGather FOR TARGET ZM FOR TILE: ", tile
3132  call esmf_fieldgather(zm_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3133  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3134  call error_handler("IN FieldGather", error)
3135 
3136  if (localpet == 0) then
3137  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3138  error = nf90_put_var( ncid, id_zm, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3139  call netcdf_err(error, 'WRITING ZM RECORD' )
3140  endif
3141 
3142  endif ! convert nst
3143 
3144 !-------------------------------------------------------------------------------
3145 ! close file
3146 !-------------------------------------------------------------------------------
3147 
3148  error = nf90_close(ncid)
3149 
3150  enddo tile_loop
3151 
3152  deallocate(lsoil_data, x_data, y_data)
3153  deallocate(data_one_tile, data_one_tile_3d, idata_one_tile, dum2d, dum3d)
3154 
3155  return
3156 
3157  end subroutine write_fv3_sfc_data_netcdf
3158 
3159  end module write_data
type(esmf_field), public d_conv_target_grid
Thickness of free convection layer.
integer, public j_target
j dimension of each global tile, or of a nest, target grid.
Definition: model_grid.F90:39
type(esmf_field), public zm_target_grid
Oceanic mixed layer depth.
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
integer, public num_tiles_target_grid
Number of tiles, target grid.
Definition: model_grid.F90:48
integer, public lsoil_target
Number of soil layers, target grid.
Definition: model_grid.F90:24
type(esmf_field), public canopy_mc_target_grid
Canopy moisture content.
type(esmf_field), public v_w_target_grid
V-wind, &#39;west&#39; edge of grid cell.
type(esmf_field), public longitude_w_target_grid
longitude of &#39;west&#39; edge of grid box, target grid
Definition: model_grid.F90:89
type(esmf_field), public f10m_target_grid
log((z0+10)*1/z0) See sfc_diff.f for details.
type(esmf_field), public c_d_target_grid
Coefficient 2 to calculate d(tz)/d(ts).
type(esmf_field), public ifd_target_grid
Model mode index.
type(esmf_field), public w_d_target_grid
Coefficient 4 to calculate d(tz)/d(ts).
type(esmf_field), public xtts_target_grid
d(xt)/d(ts).
logical, public lai_from_climo
If false, interpolate leaf area index from the input data to the target grid instead of using data fr...
integer, public regional
For regional target grids.
type(esmf_field), public srflag_target_grid
Snow/rain flag.
type(esmf_field), public xu_target_grid
u-current content in diurnal thermocline layer.
character(len=20), dimension(max_tracers), public tracers
Name of each atmos tracer to be processed.
real(esmf_kind_r8), dimension(:,:), allocatable, public vcoord_target
Vertical coordinate.
Module to hold ESMF fields associated with the target grid surface data.
type(esmf_field), public min_veg_greenness_target_grid
minimum annual greenness fraction
Definition: static_data.F90:28
type(esmf_field), public tprcp_target_grid
Precipitation.
type(esmf_field), public max_veg_greenness_target_grid
maximum annual greenness fraction
Definition: static_data.F90:27
type(esmf_field), public mxsno_albedo_target_grid
maximum snow albedo
Definition: static_data.F90:29
type(esmf_field), public longitude_s_target_grid
longitude of &#39;south&#39; edge of grid box, target grid
Definition: model_grid.F90:86
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
Definition: model_grid.F90:9
type(esmf_field), public alvwf_target_grid
visible white sky albedo
Definition: static_data.F90:22
type(esmf_field), public qnifa_climo_target_grid
Number concentration of ice friendly aerosols.
type(esmf_field), public latitude_target_grid
latitude of grid center, target grid
Definition: model_grid.F90:76
integer, public i_target
i dimension of each global tile, or of a nest, target grid.
Definition: model_grid.F90:36
integer, public halo_bndy
Number of row/cols of lateral halo, where pure lateral bndy conditions are applied (regional target g...
type(esmf_field), public xzts_target_grid
d(xz)/d(ts).
type(esmf_field), public latitude_s_target_grid
latitude of &#39;south&#39; edge of grid box, target grid
Definition: model_grid.F90:78
type(esmf_field), public c_0_target_grid
Coefficient 1 to calculate d(tz)/d(ts).
type(esmf_field), public soilm_liq_target_grid
3-d liquid soil moisture.
type(esmf_field), public zh_target_grid
3-d height.
type(esmf_field), public alnsf_target_grid
near ir black sky albedo
Definition: static_data.F90:23
type(esmf_field), public xz_target_grid
Diurnal thermocline layer thickness.
type(esmf_field), public latitude_w_target_grid
latitude of &#39;west&#39; edge of grid box, target grid
Definition: model_grid.F90:81
type(esmf_field), public delp_target_grid
Pressure thickness.
type(esmf_field), public z_c_target_grid
Sub-layer cooling thickness.
integer, public lev_target
Number of vertical levels.
type(esmf_field), public lai_target_grid
Leaf area index.
type(esmf_field), public landmask_target_grid
land mask target grid - &#39;1&#39; land; &#39;0&#39; non-land
Definition: model_grid.F90:73
type(esmf_field), public seaice_fract_target_grid
Sea ice fraction.
logical, public convert_nst
Convert nst data when true.
type(esmf_field), public snow_liq_equiv_target_grid
Liquid equivalent snow depth.
type(esmf_field), public qrain_target_grid
Sensible heat flux due to rainfall.
type(esmf_field), public soilm_tot_target_grid
3-d total soil moisture.
Module to hold variables and ESMF fields associated with the target grid atmospheric data...
subroutine netcdf_err(err, string)
Error handler for netcdf.
Definition: utils.F90:32
type(esmf_field), public seaice_depth_target_grid
Sea ice depth.
type(esmf_field), public ffmm_target_grid
log((z0+z1)*1/z0) See sfc_diff.f for details.
type(esmf_field), public seaice_skin_temp_target_grid
Sea ice skin temperature.
type(esmf_field), public longitude_target_grid
longitude of grid center, target grid
Definition: model_grid.F90:84
type(esmf_field), public alvsf_target_grid
visible black sky albedo
Definition: static_data.F90:21
type(esmf_field), public slope_type_target_grid
slope type
Definition: static_data.F90:30
Reads static surface climatological data for the target FV3 grid (such as soil type and vegetation ty...
Definition: static_data.F90:13
type(esmf_field), public qnwfa_climo_target_grid
Number concentration of water friendly aerosols.
type(esmf_field), public v_s_target_grid
V-wind, &#39;south&#39; edge of grid cell.
type(esmf_field), public xs_target_grid
Salinity content in diurnal thermocline layer.
integer, public nvcoord_target
Number of vertical coordinate variables.
type(esmf_field), public ustar_target_grid
Friction velocity.
subroutine error_handler(string, rc)
General error handler.
Definition: utils.F90:10
type(esmf_field), public u_s_target_grid
U-wind, &#39;south&#39; edge of grid cell.
type(esmf_field), public tref_target_grid
Reference temperature.
type(esmf_field), public q2m_target_grid
2-m specific humidity.
type(esmf_field), public ps_target_grid
Surface pressure.
type(esmf_field), public u_w_target_grid
U-wind, &#39;west&#39; edge of grid cell.
integer, public ip1_target
ip1_target plus 1
Definition: model_grid.F90:42
character(len=25), public input_type
Input data type:
integer, public num_tracers
Number of atmospheric tracers to be processed.
type(esmf_field), public substrate_temp_target_grid
soil subtrate temperature
Definition: static_data.F90:32
type(esmf_field), public veg_greenness_target_grid
vegetation greenness fraction
Definition: static_data.F90:33
type(esmf_field), public skin_temp_target_grid
Skin temperature/sst.
type(esmf_field), public temp_target_grid
Temperautre.
integer, public levp1_target
Number of vertical levels plus 1.
type(esmf_field), public xv_target_grid
v-current content in diurnal thermocline layer.
type(esmf_field), public xt_target_grid
Heat content in diurnal thermocline layer.
logical, public use_thomp_mp_climo
When true, read and process Thompson MP climatological tracers.
type(esmf_field), public veg_type_target_grid
vegetation type
Definition: static_data.F90:34
type(esmf_field), dimension(:), allocatable, public tracers_target_grid
Tracers.
type(esmf_field), public z0_target_grid
Roughness length.
type(esmf_field), public facwf_target_grid
fractional coverage for weak zenith angle dependent albedo
Definition: static_data.F90:26
integer, public halo_blend
Number of row/cols of blending halo, where model tendencies and lateral boundary tendencies are appli...
type(esmf_field), public dzdt_target_grid
Vertical velocity.
type(esmf_field), public t2m_target_grid
2-m temperatrure.
type(esmf_field), public soil_temp_target_grid
3-d soil temperature.
type(esmf_field), public alnwf_target_grid
near ir white sky albedo
Definition: static_data.F90:24
type(esmf_field), public dt_cool_target_grid
Sub-layer cooling amount.
type(esmf_field), public w_0_target_grid
Coefficient 3 to calculate d(tz)/d(ts).
type(esmf_field), public facsf_target_grid
fractional coverage for strong zenith angle dependent albedo
Definition: static_data.F90:25
integer, public jp1_target
jp1_target plus 1
Definition: model_grid.F90:44
type(esmf_field), public snow_depth_target_grid
Physical snow depth.
type(esmf_field), public soil_type_target_grid
soil type
Definition: static_data.F90:31