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