chgres_cube  1.3.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  error = nf90_def_var(ncid, tracers(n), nf90_float, (/dim_lon,dim_lat,dim_lev/), id_tracers(n))
1403  call netcdf_err(error, 'DEFINING TRACERS' )
1404  error = nf90_put_att(ncid, id_tracers(n), "coordinates", "geolon geolat")
1405  call netcdf_err(error, 'DEFINING TRACERS COORD' )
1406  enddo
1407 
1408  if (use_thomp_mp_climo) then
1409  error = nf90_def_var(ncid, 'ice_aero', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_qnifa)
1410  call netcdf_err(error, 'DEFINING QNIFA' )
1411  error = nf90_put_att(ncid, id_qnifa, "coordinates", "geolon geolat")
1412  call netcdf_err(error, 'DEFINING QNIFA COORD' )
1413 
1414  error = nf90_def_var(ncid, 'liq_aero', nf90_float, (/dim_lon,dim_lat,dim_lev/), id_qnwfa)
1415  call netcdf_err(error, 'DEFINING QNWFA' )
1416  error = nf90_put_att(ncid, id_qnwfa, "coordinates", "geolon geolat")
1417  call netcdf_err(error, 'DEFINING QNWFA COORD' )
1418  endif
1419 
1420  error = nf90_def_var(ncid, 'u_w', nf90_float, (/dim_lonp,dim_lat,dim_lev/), id_u_w)
1421  call netcdf_err(error, 'DEFINING U_W' )
1422  error = nf90_put_att(ncid, id_u_w, "coordinates", "geolon_w geolat_w")
1423  call netcdf_err(error, 'DEFINING U_W COORD' )
1424 
1425  error = nf90_def_var(ncid, 'v_w', nf90_float, (/dim_lonp,dim_lat,dim_lev/), id_v_w)
1426  call netcdf_err(error, 'DEFINING V_W' )
1427  error = nf90_put_att(ncid, id_v_w, "coordinates", "geolon_w geolat_w")
1428  call netcdf_err(error, 'DEFINING V_W COORD' )
1429 
1430  error = nf90_def_var(ncid, 'u_s', nf90_float, (/dim_lon,dim_latp,dim_lev/), id_u_s)
1431  call netcdf_err(error, 'DEFINING U_S' )
1432  error = nf90_put_att(ncid, id_u_s, "coordinates", "geolon_s geolat_s")
1433  call netcdf_err(error, 'DEFINING U_S COORD' )
1434 
1435  error = nf90_def_var(ncid, 'v_s', nf90_float, (/dim_lon,dim_latp,dim_lev/), id_v_s)
1436  call netcdf_err(error, 'DEFINING V_S' )
1437  error = nf90_put_att(ncid, id_v_s, "coordinates", "geolon_s geolat_s")
1438  call netcdf_err(error, 'DEFINING V_S COORD' )
1439 
1440  error = nf90_enddef(ncid, header_buffer_val,4,0,4)
1441  call netcdf_err(error, 'DEFINING HEADER' )
1442 
1443  endif header
1444 
1445 ! longitude
1446 
1447  do tile = 1, num_tiles_target_grid
1448  print*,"- CALL FieldGather FOR TARGET GRID LONGITUDE FOR TILE: ", tile
1449  call esmf_fieldgather(longitude_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1450  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1451  call error_handler("IN FieldGather", error)
1452  enddo
1453 
1454  if (localpet < num_tiles_target_grid) then
1455  dum2d(:,:) = data_one_tile(i_start:i_end, j_start:j_end)
1456  error = nf90_put_var( ncid, id_lon, dum2d)
1457  call netcdf_err(error, 'WRITING LONGITUDE RECORD' )
1458  endif
1459 
1460 ! latitude
1461 
1462  do tile = 1, num_tiles_target_grid
1463  print*,"- CALL FieldGather FOR TARGET GRID LATITUDE FOR TILE: ", tile
1464  call esmf_fieldgather(latitude_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1465  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1466  call error_handler("IN FieldGather", error)
1467  enddo
1468 
1469  if (localpet < num_tiles_target_grid) then
1470  dum2d(:,:) = data_one_tile(i_start:i_end, j_start:j_end)
1471  error = nf90_put_var( ncid, id_lat, dum2d)
1472  call netcdf_err(error, 'WRITING LATITUDE RECORD' )
1473  endif
1474 
1475 ! surface pressure
1476 
1477  do tile = 1, num_tiles_target_grid
1478  print*,"- CALL FieldGather FOR TARGET GRID SURFACE PRESSURE FOR TILE: ", tile
1479  call esmf_fieldgather(ps_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1480  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1481  call error_handler("IN FieldGather", error)
1482  enddo
1483 
1484  if (localpet < num_tiles_target_grid) then
1485  dum2d(:,:) = data_one_tile(i_start:i_end, j_start:j_end)
1486  error = nf90_put_var( ncid, id_ps, dum2d)
1487  call netcdf_err(error, 'WRITING SURFACE PRESSURE RECORD' )
1488  endif
1489 
1490  deallocate(dum2d, data_one_tile)
1491 
1492 ! height
1493 
1494  if (localpet < num_tiles_target_grid) then
1495  allocate(dum3d(i_target_out,j_target_out,levp1_target))
1496  allocate(data_one_tile_3d(i_target,j_target,levp1_target))
1497  else
1498  allocate(dum3d(0,0,0))
1499  allocate(data_one_tile_3d(0,0,0))
1500  endif
1501 
1502  do tile = 1, num_tiles_target_grid
1503  print*,"- CALL FieldGather FOR TARGET GRID HEIGHT FOR TILE: ", tile
1504  call esmf_fieldgather(zh_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1505  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1506  call error_handler("IN FieldGather", error)
1507  enddo
1508 
1509  if (localpet < num_tiles_target_grid) then
1510  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1511  dum3d(:,:,1:levp1_target) = dum3d(:,:,levp1_target:1:-1)
1512  error = nf90_put_var( ncid, id_zh, dum3d)
1513  call netcdf_err(error, 'WRITING HEIGHT RECORD' )
1514  endif
1515 
1516  deallocate(dum3d, data_one_tile_3d)
1517 
1518 ! vertical velocity
1519 
1520  if (localpet < num_tiles_target_grid) then
1521  allocate(dum3d(i_target_out,j_target_out,lev_target))
1522  allocate(data_one_tile_3d(i_target,j_target,lev_target))
1523  else
1524  allocate(dum3d(0,0,0))
1525  allocate(data_one_tile_3d(0,0,0))
1526  endif
1527 
1528  do tile = 1, num_tiles_target_grid
1529  print*,"- CALL FieldGather FOR TARGET GRID VERTICAL VELOCITY FOR TILE: ", tile
1530  call esmf_fieldgather(dzdt_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1531  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1532  call error_handler("IN FieldGather", error)
1533  enddo
1534 
1535  if (localpet < num_tiles_target_grid) then
1536  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1537  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1538  print*,"MIN MAX W AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1539  error = nf90_put_var( ncid, id_w, dum3d)
1540  call netcdf_err(error, 'WRITING VERTICAL VELOCITY RECORD' )
1541  endif
1542 
1543 ! delp
1544 
1545  do tile = 1, num_tiles_target_grid
1546  print*,"- CALL FieldGather FOR TARGET GRID DELP FOR TILE: ", tile
1547  call esmf_fieldgather(delp_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1548  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1549  call error_handler("IN FieldGather", error)
1550  enddo
1551 
1552  if (localpet < num_tiles_target_grid) then
1553  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1554  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1555  error = nf90_put_var( ncid, id_delp, dum3d)
1556  call netcdf_err(error, 'WRITING DELP RECORD' )
1557  endif
1558 
1559 ! temperature
1560 
1561  do tile = 1, num_tiles_target_grid
1562  print*,"- CALL FieldGather FOR TARGET GRID TEMPERATURE FOR TILE: ", tile
1563  call esmf_fieldgather(temp_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1564  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1565  call error_handler("IN FieldGather", error)
1566  enddo
1567 
1568  if (localpet < num_tiles_target_grid) then
1569  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1570  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1571  error = nf90_put_var( ncid, id_t, dum3d)
1572  call netcdf_err(error, 'WRITING TEMPERTAURE RECORD' )
1573  endif
1574 
1575 ! tracers
1576 
1577  do n = 1, num_tracers
1578 
1579  do tile = 1, num_tiles_target_grid
1580  print*,"- CALL FieldGather FOR TARGET GRID TRACER ", trim(tracers(n)), " TILE: ", tile
1581  call esmf_fieldgather(tracers_target_grid(n), data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1582  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1583  call error_handler("IN FieldGather", error)
1584  enddo
1585 
1586  if (localpet < num_tiles_target_grid) then
1587  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1588  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1589  error = nf90_put_var( ncid, id_tracers(n), dum3d)
1590  call netcdf_err(error, 'WRITING TRACER RECORD' )
1591  endif
1592 
1593  enddo
1594 
1595 ! qnifa
1596 
1597  if (use_thomp_mp_climo) then
1598  do tile = 1, num_tiles_target_grid
1599  print*,"- CALL FieldGather FOR TARGET GRID QNIFA FOR TILE: ", tile
1600  call esmf_fieldgather(qnifa_climo_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1601  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1602  call error_handler("IN FieldGather", error)
1603  enddo
1604 
1605  if (localpet < num_tiles_target_grid) then
1606  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1607  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1608  error = nf90_put_var( ncid, id_qnifa, dum3d)
1609  call netcdf_err(error, 'WRITING QNIFA RECORD' )
1610  endif
1611 
1612 ! qnwfa
1613 
1614  do tile = 1, num_tiles_target_grid
1615  print*,"- CALL FieldGather FOR TARGET GRID QNWFA FOR TILE: ", tile
1616  call esmf_fieldgather(qnwfa_climo_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1617  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1618  call error_handler("IN FieldGather", error)
1619  enddo
1620 
1621  if (localpet < num_tiles_target_grid) then
1622  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:j_end,:)
1623  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1624  error = nf90_put_var( ncid, id_qnwfa, dum3d)
1625  call netcdf_err(error, 'WRITING QNWFA RECORD' )
1626  endif
1627  endif
1628 
1629  deallocate(dum3d, data_one_tile_3d)
1630 
1631 ! lat/lon_s
1632 
1633  if (localpet < num_tiles_target_grid) then
1634  allocate(dum2d(i_target_out,jp1_target_out))
1635  allocate(data_one_tile(i_target,jp1_target))
1636  else
1637  allocate(dum2d(0,0))
1638  allocate(data_one_tile(0,0))
1639  endif
1640 
1641  do tile = 1, num_tiles_target_grid
1642  print*,"- CALL FieldGather FOR TARGET GRID LON_S FOR TILE: ", tile
1643  call esmf_fieldgather(longitude_s_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1644  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1645  call error_handler("IN FieldGather", error)
1646  enddo
1647 
1648  if (localpet < num_tiles_target_grid) then
1649  dum2d(:,:) = data_one_tile(i_start:i_end,j_start:jp1_end)
1650  error = nf90_put_var( ncid, id_lon_s, dum2d)
1651  call netcdf_err(error, 'WRITING LON_S RECORD' )
1652  endif
1653 
1654  do tile = 1, num_tiles_target_grid
1655  print*,"- CALL FieldGather FOR TARGET GRID LAT_S FOR TILE: ", tile
1656  call esmf_fieldgather(latitude_s_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1657  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1658  call error_handler("IN FieldGather", error)
1659  enddo
1660 
1661  if (localpet < num_tiles_target_grid) then
1662  dum2d(:,:) = data_one_tile(i_start:i_end,j_start:jp1_end)
1663  error = nf90_put_var( ncid, id_lat_s, dum2d)
1664  call netcdf_err(error, 'WRITING LAT_S RECORD' )
1665  endif
1666 
1667  deallocate(dum2d, data_one_tile)
1668 
1669 ! uwinds s
1670 
1671  if (localpet < num_tiles_target_grid) then
1672  allocate(dum3d(i_target_out,jp1_target_out,lev_target))
1673  allocate(data_one_tile_3d(i_target,jp1_target,lev_target))
1674  else
1675  allocate(dum3d(0,0,0))
1676  allocate(data_one_tile_3d(0,0,0))
1677  endif
1678 
1679  do tile = 1, num_tiles_target_grid
1680  print*,"- CALL FieldGather FOR TARGET GRID U_S FOR TILE: ", tile
1681  call esmf_fieldgather(u_s_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1682  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1683  call error_handler("IN FieldGather", error)
1684  enddo
1685 
1686  if (localpet < num_tiles_target_grid) then
1687  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:jp1_end,:)
1688  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1689  print*,"MIN MAX US AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1690  error = nf90_put_var( ncid, id_u_s, dum3d)
1691  call netcdf_err(error, 'WRITING U_S RECORD' )
1692  endif
1693 
1694 ! vwinds s
1695 
1696  do tile = 1, num_tiles_target_grid
1697  print*,"- CALL FieldGather FOR TARGET GRID V_S FOR TILE: ", tile
1698  call esmf_fieldgather(v_s_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1699  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1700  call error_handler("IN FieldGather", error)
1701  enddo
1702 
1703  if (localpet < num_tiles_target_grid) then
1704  dum3d(:,:,:) = data_one_tile_3d(i_start:i_end,j_start:jp1_end,:)
1705  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1706  print*,"MIN MAX VS AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1707  error = nf90_put_var( ncid, id_v_s, dum3d)
1708  call netcdf_err(error, 'WRITING V_S RECORD' )
1709  endif
1710 
1711  deallocate(dum3d, data_one_tile_3d)
1712 
1713 ! lat/lon_w
1714 
1715  if (localpet < num_tiles_target_grid) then
1716  allocate(dum2d(ip1_target_out,j_target_out))
1717  allocate(data_one_tile(ip1_target,j_target))
1718  else
1719  allocate(dum2d(0,0))
1720  allocate(data_one_tile(0,0))
1721  endif
1722 
1723  do tile = 1, num_tiles_target_grid
1724  print*,"- CALL FieldGather FOR TARGET GRID LON_W FOR TILE: ", tile
1725  call esmf_fieldgather(longitude_w_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1726  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1727  call error_handler("IN FieldGather", error)
1728  enddo
1729 
1730  if (localpet < num_tiles_target_grid) then
1731  dum2d(:,:) = data_one_tile(i_start:ip1_end,j_start:j_end)
1732  error = nf90_put_var( ncid, id_lon_w, dum2d)
1733  call netcdf_err(error, 'WRITING LON_W RECORD' )
1734  endif
1735 
1736  do tile = 1, num_tiles_target_grid
1737  print*,"- CALL FieldGather FOR TARGET GRID LAT_W FOR TILE: ", tile
1738  call esmf_fieldgather(latitude_w_target_grid, data_one_tile, rootpet=tile-1, tile=tile, rc=error)
1739  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1740  call error_handler("IN FieldGather", error)
1741  enddo
1742 
1743  if (localpet < num_tiles_target_grid) then
1744  dum2d(:,:) = data_one_tile(i_start:ip1_end,j_start:j_end)
1745  error = nf90_put_var( ncid, id_lat_w, dum2d)
1746  call netcdf_err(error, 'WRITING LAT_W RECORD' )
1747  endif
1748 
1749  deallocate(dum2d, data_one_tile)
1750 
1751 ! uwinds w
1752 
1753  if (localpet < num_tiles_target_grid) then
1754  allocate(dum3d(ip1_target_out,j_target_out,lev_target))
1755  allocate(data_one_tile_3d(ip1_target,j_target,lev_target))
1756  else
1757  allocate(dum3d(0,0,0))
1758  allocate(data_one_tile_3d(0,0,0))
1759  endif
1760 
1761  do tile = 1, num_tiles_target_grid
1762  print*,"- CALL FieldGather FOR TARGET GRID U_W FOR TILE: ", tile
1763  call esmf_fieldgather(u_w_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1764  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1765  call error_handler("IN FieldGather", error)
1766  enddo
1767 
1768  if (localpet < num_tiles_target_grid) then
1769  dum3d(:,:,:) = data_one_tile_3d(i_start:ip1_end,j_start:j_end,:)
1770  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1771  print*,"MIN MAX UW AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1772  error = nf90_put_var( ncid, id_u_w, dum3d)
1773  call netcdf_err(error, 'WRITING U_W RECORD' )
1774  endif
1775 
1776 ! vwinds w
1777 
1778  do tile = 1, num_tiles_target_grid
1779  print*,"- CALL FieldGather FOR TARGET GRID V_W FOR TILE: ", tile
1780  call esmf_fieldgather(v_w_target_grid, data_one_tile_3d, rootpet=tile-1, tile=tile, rc=error)
1781  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1782  call error_handler("IN FieldGather", error)
1783  enddo
1784 
1785  if (localpet < num_tiles_target_grid) then
1786  dum3d(:,:,:) = data_one_tile_3d(i_start:ip1_end,j_start:j_end,:)
1787  dum3d(:,:,1:lev_target) = dum3d(:,:,lev_target:1:-1)
1788  print*,"MIN MAX VW AT WRITE = ", minval(dum3d(:,:,:)), maxval(dum3d(:,:,:))
1789  error = nf90_put_var( ncid, id_v_w, dum3d)
1790  call netcdf_err(error, 'WRITING V_W RECORD' )
1791  endif
1792 
1793  deallocate(dum3d, data_one_tile_3d, id_tracers)
1794 
1795 !-------------------------------------------------------------------------------
1796 ! close file
1797 !-------------------------------------------------------------------------------
1798 
1799  if (localpet < num_tiles_target_grid) error = nf90_close(ncid)
1800 
1801  end subroutine write_fv3_atm_data_netcdf
1802 
1807  subroutine write_fv3_sfc_data_netcdf(localpet)
1808 
1809  use esmf
1810  use netcdf
1811 
1812  use model_grid, only : num_tiles_target_grid, &
1813  landmask_target_grid, &
1814  latitude_target_grid, &
1815  longitude_target_grid, &
1816  i_target, j_target, lsoil_target
1817 
1818  use program_setup, only : convert_nst, halo=>halo_bndy, &
1819  regional, lai_from_climo
1820 
1821  use surface, only : canopy_mc_target_grid, &
1822  f10m_target_grid, &
1823  ffmm_target_grid, &
1824  q2m_target_grid, &
1825  seaice_depth_target_grid, &
1826  seaice_fract_target_grid, &
1827  seaice_skin_temp_target_grid, &
1828  skin_temp_target_grid, &
1829  soil_temp_target_grid, &
1830  soilm_liq_target_grid, &
1831  soilm_tot_target_grid, &
1832  srflag_target_grid, &
1833  snow_liq_equiv_target_grid, &
1834  snow_depth_target_grid, &
1835  t2m_target_grid, &
1836  tprcp_target_grid, &
1837  ustar_target_grid, &
1838  z0_target_grid, &
1839  lai_target_grid, &
1840  c_d_target_grid, &
1841  c_0_target_grid, &
1842  d_conv_target_grid, &
1843  dt_cool_target_grid, &
1844  ifd_target_grid, &
1845  qrain_target_grid, &
1846  tref_target_grid, &
1847  w_d_target_grid, &
1848  w_0_target_grid, &
1849  xs_target_grid, &
1850  xt_target_grid, &
1851  xu_target_grid, &
1852  xv_target_grid, &
1853  xz_target_grid, &
1854  xtts_target_grid, &
1855  xzts_target_grid, &
1856  z_c_target_grid, &
1857  zm_target_grid
1858 
1859  use static_data, only : alvsf_target_grid, &
1860  alnsf_target_grid, &
1861  alvwf_target_grid, &
1862  alnwf_target_grid, &
1863  facsf_target_grid, &
1864  facwf_target_grid, &
1865  max_veg_greenness_target_grid, &
1866  min_veg_greenness_target_grid, &
1867  mxsno_albedo_target_grid, &
1868  slope_type_target_grid, &
1869  soil_type_target_grid, &
1870  substrate_temp_target_grid, &
1871  veg_greenness_target_grid, &
1872  veg_type_target_grid
1873 
1874  implicit none
1875 
1876  integer, intent(in) :: localpet
1877  character(len=128) :: outfile
1878 
1879  integer :: fsize=65536, initial = 0
1880  integer :: header_buffer_val = 16384
1881  integer :: dim_x, dim_y, dim_lsoil, dim_time
1882  integer :: error, i, ncid, tile
1883  integer :: id_x, id_y, id_lsoil
1884  integer :: id_slmsk, id_time
1885  integer :: id_lat, id_lon
1886  integer :: id_tsea, id_sheleg, id_tg3
1887  integer :: id_zorl, id_alvsf, id_alvwf
1888  integer :: id_alnsf, id_alnwf, id_vfrac
1889  integer :: id_canopy, id_f10m, id_t2m
1890  integer :: id_q2m, id_vtype, id_stype
1891  integer :: id_facsf, id_facwf, id_uustar
1892  integer :: id_ffmm, id_ffhh, id_hice
1893  integer :: id_fice, id_tisfc, id_tprcp
1894  integer :: id_srflag, id_snwdph, id_shdmin
1895  integer :: id_shdmax, id_slope, id_snoalb
1896  integer :: id_lai
1897  integer :: id_stc, id_smc, id_slc
1898  integer :: id_tref, id_z_c, id_c_0
1899  integer :: id_c_d, id_w_0, id_w_d
1900  integer :: id_xt, id_xs, id_xu, id_xv
1901  integer :: id_xz, id_zm, id_xtts, id_xzts
1902  integer :: id_d_conv, id_ifd, id_dt_cool
1903  integer :: id_qrain
1904  integer :: i_target_out, j_target_out
1905  integer :: istart, iend, jstart, jend
1906 
1907  integer(esmf_kind_i8), allocatable :: idata_one_tile(:,:)
1908 
1909  real(kind=4), allocatable :: lsoil_data(:), x_data(:), y_data(:)
1910  real(kind=8), allocatable :: dum2d(:,:), dum3d(:,:,:)
1911  real(kind=4) :: times
1912  real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
1913  real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
1914 
1915 ! Remove any halo region.
1916 
1917  i_target_out = i_target-(2*halo)
1918  j_target_out = j_target-(2*halo)
1919 
1920  istart = halo + 1
1921  jstart = halo + 1
1922  iend = i_target - halo
1923  jend = j_target - halo
1924 
1925  allocate(lsoil_data(lsoil_target))
1926  do i = 1, lsoil_target
1927  lsoil_data(i) = float(i)
1928  enddo
1929 
1930  allocate(x_data(i_target_out))
1931  do i = 1, i_target_out
1932  x_data(i) = float(i)
1933  enddo
1934 
1935  allocate(y_data(j_target_out))
1936  do i = 1, j_target_out
1937  y_data(i) = float(i)
1938  enddo
1939 
1940  if (convert_nst) then
1941  print*,'- WRITE FV3 SURFACE AND NST DATA TO NETCDF FILE'
1942  else
1943  print*,'- WRITE FV3 SURFACE DATA TO NETCDF FILE'
1944  endif
1945 
1946  if (localpet == 0) then
1947  allocate(data_one_tile(i_target,j_target))
1948  allocate(data_one_tile_3d(i_target,j_target,lsoil_target))
1949  allocate(idata_one_tile(i_target,j_target))
1950  allocate(dum2d(i_target_out,j_target_out))
1951  allocate(dum3d(i_target_out,j_target_out,lsoil_target))
1952  else
1953  allocate(data_one_tile(0,0))
1954  allocate(data_one_tile_3d(0,0,0))
1955  allocate(idata_one_tile(0,0))
1956  allocate(dum2d(0,0))
1957  allocate(dum3d(0,0,0))
1958  endif
1959 
1960  tile_loop : do tile = 1, num_tiles_target_grid
1961 
1962  local_pet : if (localpet == 0) then
1963 
1964  if (regional > 0) then
1965  outfile = "out.sfc.tile7.nc"
1966  else
1967  WRITE(outfile, '(A, I1, A)') 'out.sfc.tile', tile, '.nc'
1968  endif
1969 
1970 !--- open the file
1971  error = nf90_create(outfile, ior(nf90_netcdf4,nf90_classic_model), &
1972  ncid, initialsize=initial, chunksize=fsize)
1973  call netcdf_err(error, 'CREATING FILE='//trim(outfile) )
1974 
1975 !--- define dimensions
1976  error = nf90_def_dim(ncid, 'xaxis_1', i_target_out, dim_x)
1977  call netcdf_err(error, 'DEFINING XAXIS DIMENSION' )
1978  error = nf90_def_dim(ncid, 'yaxis_1', j_target_out, dim_y)
1979  call netcdf_err(error, 'DEFINING YAXIS DIMENSION' )
1980  error = nf90_def_dim(ncid, 'zaxis_1', lsoil_target, dim_lsoil)
1981  call netcdf_err(error, 'DEFINING ZAXIS DIMENSION' )
1982  error = nf90_def_dim(ncid, 'Time', 1, dim_time)
1983  call netcdf_err(error, 'DEFINING TIME DIMENSION' )
1984 
1985  !--- define fields
1986  error = nf90_def_var(ncid, 'xaxis_1', nf90_float, (/dim_x/), id_x)
1987  call netcdf_err(error, 'DEFINING XAXIS_1 FIELD' )
1988  error = nf90_put_att(ncid, id_x, "long_name", "xaxis_1")
1989  call netcdf_err(error, 'DEFINING XAXIS_1 LONG NAME' )
1990  error = nf90_put_att(ncid, id_x, "units", "none")
1991  call netcdf_err(error, 'DEFINING XAXIS_1 UNITS' )
1992  error = nf90_put_att(ncid, id_x, "cartesian_axis", "X")
1993  call netcdf_err(error, 'WRITING XAXIS_1 FIELD' )
1994 
1995  error = nf90_def_var(ncid, 'yaxis_1', nf90_float, (/dim_y/), id_y)
1996  call netcdf_err(error, 'DEFINING YAXIS_1 FIELD' )
1997  error = nf90_put_att(ncid, id_y, "long_name", "yaxis_1")
1998  call netcdf_err(error, 'DEFINING YAXIS_1 LONG NAME' )
1999  error = nf90_put_att(ncid, id_y, "units", "none")
2000  call netcdf_err(error, 'DEFINING YAXIS_1 UNITS' )
2001  error = nf90_put_att(ncid, id_y, "cartesian_axis", "Y")
2002  call netcdf_err(error, 'WRITING YAXIS_1 FIELD' )
2003 
2004  error = nf90_def_var(ncid, 'zaxis_1', nf90_float, (/dim_lsoil/), id_lsoil)
2005  call netcdf_err(error, 'DEFINING ZAXIS_1 FIELD' )
2006  error = nf90_put_att(ncid, id_lsoil, "long_name", "zaxis_1")
2007  call netcdf_err(error, 'DEFINING ZAXIS_1 LONG NAME' )
2008  error = nf90_put_att(ncid, id_lsoil, "units", "none")
2009  call netcdf_err(error, 'DEFINING ZAXIS_1 UNITS' )
2010  error = nf90_put_att(ncid, id_lsoil, "cartesian_axis", "Z")
2011  call netcdf_err(error, 'WRITING ZAXIS_1 FIELD' )
2012 
2013  error = nf90_def_var(ncid, 'Time', nf90_float, dim_time, id_time)
2014  call netcdf_err(error, 'DEFINING TIME FIELD' )
2015  error = nf90_put_att(ncid, id_time, "long_name", "Time")
2016  call netcdf_err(error, 'DEFINING TIME LONG NAME' )
2017  error = nf90_put_att(ncid, id_time, "units", "time level")
2018  call netcdf_err(error, 'DEFINING TIME UNITS' )
2019  error = nf90_put_att(ncid, id_time, "cartesian_axis", "T")
2020  call netcdf_err(error, 'WRITING TIME FIELD' )
2021 
2022  error = nf90_def_var(ncid, 'geolon', nf90_double, (/dim_x,dim_y/), id_lon)
2023  call netcdf_err(error, 'DEFINING GEOLON' )
2024  error = nf90_put_att(ncid, id_lon, "long_name", "Longitude")
2025  call netcdf_err(error, 'DEFINING GEOLON LONG NAME' )
2026  error = nf90_put_att(ncid, id_lon, "units", "degrees_east")
2027  call netcdf_err(error, 'DEFINING GEOLON UNITS' )
2028 
2029  error = nf90_def_var(ncid, 'geolat', nf90_double, (/dim_x,dim_y/), id_lat)
2030  call netcdf_err(error, 'DEFINING GEOLAT' )
2031  error = nf90_put_att(ncid, id_lat, "long_name", "Latitude")
2032  call netcdf_err(error, 'DEFINING GEOLAT LONG NAME' )
2033  error = nf90_put_att(ncid, id_lat, "units", "degrees_north")
2034  call netcdf_err(error, 'DEFINING GEOLAT UNITS' )
2035 
2036  error = nf90_def_var(ncid, 'slmsk', nf90_double, (/dim_x,dim_y,dim_time/), id_slmsk)
2037  call netcdf_err(error, 'DEFINING SLMSK' )
2038  error = nf90_put_att(ncid, id_slmsk, "long_name", "slmsk")
2039  call netcdf_err(error, 'DEFINING SLMSK LONG NAME' )
2040  error = nf90_put_att(ncid, id_slmsk, "units", "none")
2041  call netcdf_err(error, 'DEFINING SLMSK UNITS' )
2042  error = nf90_put_att(ncid, id_slmsk, "coordinates", "geolon geolat")
2043  call netcdf_err(error, 'DEFINING SLMSK COORD' )
2044 
2045  error = nf90_def_var(ncid, 'tsea', nf90_double, (/dim_x,dim_y,dim_time/), id_tsea)
2046  call netcdf_err(error, 'DEFINING TSEA' )
2047  error = nf90_put_att(ncid, id_tsea, "long_name", "tsea")
2048  call netcdf_err(error, 'DEFINING TSEA LONG NAME' )
2049  error = nf90_put_att(ncid, id_tsea, "units", "none")
2050  call netcdf_err(error, 'DEFINING TSEA UNITS' )
2051  error = nf90_put_att(ncid, id_tsea, "coordinates", "geolon geolat")
2052  call netcdf_err(error, 'DEFINING TSEA COORD' )
2053 
2054  error = nf90_def_var(ncid, 'sheleg', nf90_double, (/dim_x,dim_y,dim_time/), id_sheleg)
2055  call netcdf_err(error, 'DEFINING SHELEG' )
2056  error = nf90_put_att(ncid, id_sheleg, "long_name", "sheleg")
2057  call netcdf_err(error, 'DEFINING SHELEG LONG NAME' )
2058  error = nf90_put_att(ncid, id_sheleg, "units", "none")
2059  call netcdf_err(error, 'DEFINING SHELEG UNITS' )
2060  error = nf90_put_att(ncid, id_sheleg, "coordinates", "geolon geolat")
2061  call netcdf_err(error, 'DEFINING SHELEG COORD' )
2062 
2063  error = nf90_def_var(ncid, 'tg3', nf90_double, (/dim_x,dim_y,dim_time/), id_tg3)
2064  call netcdf_err(error, 'DEFINING TG3' )
2065  error = nf90_put_att(ncid, id_tg3, "long_name", "tg3")
2066  call netcdf_err(error, 'DEFINING TG3 LONG NAME' )
2067  error = nf90_put_att(ncid, id_tg3, "units", "none")
2068  call netcdf_err(error, 'DEFINING TG3 UNITS' )
2069  error = nf90_put_att(ncid, id_tg3, "coordinates", "geolon geolat")
2070  call netcdf_err(error, 'DEFINING TG3 COORD' )
2071 
2072  error = nf90_def_var(ncid, 'zorl', nf90_double, (/dim_x,dim_y,dim_time/), id_zorl)
2073  call netcdf_err(error, 'DEFINING ZORL' )
2074  error = nf90_put_att(ncid, id_zorl, "long_name", "zorl")
2075  call netcdf_err(error, 'DEFINING ZORL LONG NAME' )
2076  error = nf90_put_att(ncid, id_zorl, "units", "none")
2077  call netcdf_err(error, 'DEFINING ZORL UNITS' )
2078  error = nf90_put_att(ncid, id_zorl, "coordinates", "geolon geolat")
2079  call netcdf_err(error, 'DEFINING ZORL COORD' )
2080 
2081  error = nf90_def_var(ncid, 'alvsf', nf90_double, (/dim_x,dim_y,dim_time/), id_alvsf)
2082  call netcdf_err(error, 'DEFINING ALVSF' )
2083  error = nf90_put_att(ncid, id_alvsf, "long_name", "alvsf")
2084  call netcdf_err(error, 'DEFINING ALVSF LONG NAME' )
2085  error = nf90_put_att(ncid, id_alvsf, "units", "none")
2086  call netcdf_err(error, 'DEFINING ALVSF UNITS' )
2087  error = nf90_put_att(ncid, id_alvsf, "coordinates", "geolon geolat")
2088  call netcdf_err(error, 'DEFINING ALVSF COORD' )
2089 
2090  error = nf90_def_var(ncid, 'alvwf', nf90_double, (/dim_x,dim_y,dim_time/), id_alvwf)
2091  call netcdf_err(error, 'DEFINING ALVWF' )
2092  error = nf90_put_att(ncid, id_alvwf, "long_name", "alvwf")
2093  call netcdf_err(error, 'DEFINING ALVWF LONG NAME' )
2094  error = nf90_put_att(ncid, id_alvwf, "units", "none")
2095  call netcdf_err(error, 'DEFINING ALVWF UNITS' )
2096  error = nf90_put_att(ncid, id_alvwf, "coordinates", "geolon geolat")
2097  call netcdf_err(error, 'DEFINING ALVWF COORD' )
2098 
2099  error = nf90_def_var(ncid, 'alnsf', nf90_double, (/dim_x,dim_y,dim_time/), id_alnsf)
2100  call netcdf_err(error, 'DEFINING ALNSF' )
2101  error = nf90_put_att(ncid, id_alnsf, "long_name", "alnsf")
2102  call netcdf_err(error, 'DEFINING ALNSF LONG NAME' )
2103  error = nf90_put_att(ncid, id_alnsf, "units", "none")
2104  call netcdf_err(error, 'DEFINING ALNSF UNITS' )
2105  error = nf90_put_att(ncid, id_alnsf, "coordinates", "geolon geolat")
2106  call netcdf_err(error, 'DEFINING ALNSF COORD' )
2107 
2108  error = nf90_def_var(ncid, 'alnwf', nf90_double, (/dim_x,dim_y,dim_time/), id_alnwf)
2109  call netcdf_err(error, 'DEFINING ALNWF' )
2110  error = nf90_put_att(ncid, id_alnwf, "long_name", "alnwf")
2111  call netcdf_err(error, 'DEFINING ALNWF LONG NAME' )
2112  error = nf90_put_att(ncid, id_alnwf, "units", "none")
2113  call netcdf_err(error, 'DEFINING ALNWF UNITS' )
2114  error = nf90_put_att(ncid, id_alnwf, "coordinates", "geolon geolat")
2115  call netcdf_err(error, 'DEFINING ALNWF COORD' )
2116 
2117  error = nf90_def_var(ncid, 'facsf', nf90_double, (/dim_x,dim_y,dim_time/), id_facsf)
2118  call netcdf_err(error, 'DEFINING FACSF' )
2119  error = nf90_put_att(ncid, id_facsf, "long_name", "facsf")
2120  call netcdf_err(error, 'DEFINING FACSF LONG NAME' )
2121  error = nf90_put_att(ncid, id_facsf, "units", "none")
2122  call netcdf_err(error, 'DEFINING FACSF UNITS' )
2123  error = nf90_put_att(ncid, id_facsf, "coordinates", "geolon geolat")
2124  call netcdf_err(error, 'DEFINING FACSF COORD' )
2125 
2126  error = nf90_def_var(ncid, 'facwf', nf90_double, (/dim_x,dim_y,dim_time/), id_facwf)
2127  call netcdf_err(error, 'DEFINING FACWF' )
2128  error = nf90_put_att(ncid, id_facwf, "long_name", "facwf")
2129  call netcdf_err(error, 'DEFINING FACWF LONG NAME' )
2130  error = nf90_put_att(ncid, id_facwf, "units", "none")
2131  call netcdf_err(error, 'DEFINING FACWF UNITS' )
2132  error = nf90_put_att(ncid, id_facwf, "coordinates", "geolon geolat")
2133  call netcdf_err(error, 'DEFINING FACWF COORD' )
2134 
2135  error = nf90_def_var(ncid, 'vfrac', nf90_double, (/dim_x,dim_y,dim_time/), id_vfrac)
2136  call netcdf_err(error, 'DEFINING VFRAC' )
2137  error = nf90_put_att(ncid, id_vfrac, "long_name", "vfrac")
2138  call netcdf_err(error, 'DEFINING VFRAC LONG NAME' )
2139  error = nf90_put_att(ncid, id_vfrac, "units", "none")
2140  call netcdf_err(error, 'DEFINING VFRAC UNITS' )
2141  error = nf90_put_att(ncid, id_vfrac, "coordinates", "geolon geolat")
2142  call netcdf_err(error, 'DEFINING VFRAC COORD' )
2143 
2144  error = nf90_def_var(ncid, 'canopy', nf90_double, (/dim_x,dim_y,dim_time/), id_canopy)
2145  call netcdf_err(error, 'DEFINING CANOPY' )
2146  error = nf90_put_att(ncid, id_canopy, "long_name", "canopy")
2147  call netcdf_err(error, 'DEFINING CANOPY LONG NAME' )
2148  error = nf90_put_att(ncid, id_canopy, "units", "none")
2149  call netcdf_err(error, 'DEFINING CANOPY UNITS' )
2150  error = nf90_put_att(ncid, id_canopy, "coordinates", "geolon geolat")
2151  call netcdf_err(error, 'DEFINING CANOPY COORD' )
2152 
2153  error = nf90_def_var(ncid, 'f10m', nf90_double, (/dim_x,dim_y,dim_time/), id_f10m)
2154  call netcdf_err(error, 'DEFINING F10M' )
2155  error = nf90_put_att(ncid, id_f10m, "long_name", "f10m")
2156  call netcdf_err(error, 'DEFINING F10M LONG NAME' )
2157  error = nf90_put_att(ncid, id_f10m, "units", "none")
2158  call netcdf_err(error, 'DEFINING F10M UNITS' )
2159  error = nf90_put_att(ncid, id_f10m, "coordinates", "geolon geolat")
2160  call netcdf_err(error, 'DEFINING F10M COORD' )
2161 
2162  error = nf90_def_var(ncid, 't2m', nf90_double, (/dim_x,dim_y,dim_time/), id_t2m)
2163  call netcdf_err(error, 'DEFINING T2M' )
2164  error = nf90_put_att(ncid, id_t2m, "long_name", "t2m")
2165  call netcdf_err(error, 'DEFINING T2M LONG NAME' )
2166  error = nf90_put_att(ncid, id_t2m, "units", "none")
2167  call netcdf_err(error, 'DEFINING T2M UNITS' )
2168  error = nf90_put_att(ncid, id_t2m, "coordinates", "geolon geolat")
2169  call netcdf_err(error, 'DEFINING T2M COORD' )
2170 
2171  error = nf90_def_var(ncid, 'q2m', nf90_double, (/dim_x,dim_y,dim_time/), id_q2m)
2172  call netcdf_err(error, 'DEFINING Q2M' )
2173  error = nf90_put_att(ncid, id_q2m, "long_name", "q2m")
2174  call netcdf_err(error, 'DEFINING Q2M LONG NAME' )
2175  error = nf90_put_att(ncid, id_q2m, "units", "none")
2176  call netcdf_err(error, 'DEFINING Q2M UNITS' )
2177  error = nf90_put_att(ncid, id_q2m, "coordinates", "geolon geolat")
2178  call netcdf_err(error, 'DEFINING Q2M COORD' )
2179 
2180  error = nf90_def_var(ncid, 'vtype', nf90_double, (/dim_x,dim_y,dim_time/), id_vtype)
2181  call netcdf_err(error, 'DEFINING VTYPE' )
2182  error = nf90_put_att(ncid, id_vtype, "long_name", "vtype")
2183  call netcdf_err(error, 'DEFINING VTYPE LONG NAME' )
2184  error = nf90_put_att(ncid, id_vtype, "units", "none")
2185  call netcdf_err(error, 'DEFINING VTYPE UNITS' )
2186  error = nf90_put_att(ncid, id_vtype, "coordinates", "geolon geolat")
2187  call netcdf_err(error, 'DEFINING VTYPE COORD' )
2188 
2189  error = nf90_def_var(ncid, 'stype', nf90_double, (/dim_x,dim_y,dim_time/), id_stype)
2190  call netcdf_err(error, 'DEFINING STYPE' )
2191  error = nf90_put_att(ncid, id_stype, "long_name", "stype")
2192  call netcdf_err(error, 'DEFINING STYPE LONG NAME' )
2193  error = nf90_put_att(ncid, id_stype, "units", "none")
2194  call netcdf_err(error, 'DEFINING STYPE UNITS' )
2195  error = nf90_put_att(ncid, id_stype, "coordinates", "geolon geolat")
2196  call netcdf_err(error, 'DEFINING STYPE COORD' )
2197 
2198  error = nf90_def_var(ncid, 'uustar', nf90_double, (/dim_x,dim_y,dim_time/), id_uustar)
2199  call netcdf_err(error, 'DEFINING UUSTAR' )
2200  error = nf90_put_att(ncid, id_uustar, "long_name", "uustar")
2201  call netcdf_err(error, 'DEFINING UUSTAR LONG NAME' )
2202  error = nf90_put_att(ncid, id_uustar, "units", "none")
2203  call netcdf_err(error, 'DEFINING UUSTAR UNITS' )
2204  error = nf90_put_att(ncid, id_uustar, "coordinates", "geolon geolat")
2205  call netcdf_err(error, 'DEFINING UUSTAR COORD' )
2206 
2207  error = nf90_def_var(ncid, 'ffmm', nf90_double, (/dim_x,dim_y,dim_time/), id_ffmm)
2208  call netcdf_err(error, 'DEFINING FFMM' )
2209  error = nf90_put_att(ncid, id_ffmm, "long_name", "ffmm")
2210  call netcdf_err(error, 'DEFINING FFMM LONG NAME' )
2211  error = nf90_put_att(ncid, id_ffmm, "units", "none")
2212  call netcdf_err(error, 'DEFINING FFMM UNITS' )
2213  error = nf90_put_att(ncid, id_ffmm, "coordinates", "geolon geolat")
2214  call netcdf_err(error, 'DEFINING FFMM COORD' )
2215 
2216  error = nf90_def_var(ncid, 'ffhh', nf90_double, (/dim_x,dim_y,dim_time/), id_ffhh)
2217  call netcdf_err(error, 'DEFINING FFHH' )
2218  error = nf90_put_att(ncid, id_ffhh, "long_name", "ffhh")
2219  call netcdf_err(error, 'DEFINING FFHH LONG NAME' )
2220  error = nf90_put_att(ncid, id_ffhh, "units", "none")
2221  call netcdf_err(error, 'DEFINING FFHH UNITS' )
2222  error = nf90_put_att(ncid, id_ffhh, "coordinates", "geolon geolat")
2223  call netcdf_err(error, 'DEFINING FFHH COORD' )
2224 
2225  error = nf90_def_var(ncid, 'hice', nf90_double, (/dim_x,dim_y,dim_time/), id_hice)
2226  call netcdf_err(error, 'DEFINING HICE' )
2227  error = nf90_put_att(ncid, id_hice, "long_name", "hice")
2228  call netcdf_err(error, 'DEFINING HICE LONG NAME' )
2229  error = nf90_put_att(ncid, id_hice, "units", "none")
2230  call netcdf_err(error, 'DEFINING HICE UNITS' )
2231  error = nf90_put_att(ncid, id_hice, "coordinates", "geolon geolat")
2232  call netcdf_err(error, 'DEFINING HICE COORD' )
2233 
2234  error = nf90_def_var(ncid, 'fice', nf90_double, (/dim_x,dim_y,dim_time/), id_fice)
2235  call netcdf_err(error, 'DEFINING FICE' )
2236  error = nf90_put_att(ncid, id_fice, "long_name", "fice")
2237  call netcdf_err(error, 'DEFINING FICE LONG NAME' )
2238  error = nf90_put_att(ncid, id_fice, "units", "none")
2239  call netcdf_err(error, 'DEFINING FICE UNITS' )
2240  error = nf90_put_att(ncid, id_fice, "coordinates", "geolon geolat")
2241  call netcdf_err(error, 'DEFINING FICE COORD' )
2242 
2243  error = nf90_def_var(ncid, 'tisfc', nf90_double, (/dim_x,dim_y,dim_time/), id_tisfc)
2244  call netcdf_err(error, 'DEFINING TISFC' )
2245  error = nf90_put_att(ncid, id_tisfc, "long_name", "tisfc")
2246  call netcdf_err(error, 'DEFINING TISFC LONG NAME' )
2247  error = nf90_put_att(ncid, id_tisfc, "units", "none")
2248  call netcdf_err(error, 'DEFINING TISFC UNITS' )
2249  error = nf90_put_att(ncid, id_tisfc, "coordinates", "geolon geolat")
2250  call netcdf_err(error, 'DEFINING TISFC COORD' )
2251 
2252  error = nf90_def_var(ncid, 'tprcp', nf90_double, (/dim_x,dim_y,dim_time/), id_tprcp)
2253  call netcdf_err(error, 'DEFINING TPRCP' )
2254  error = nf90_put_att(ncid, id_tprcp, "long_name", "tprcp")
2255  call netcdf_err(error, 'DEFINING TPRCP LONG NAME' )
2256  error = nf90_put_att(ncid, id_tprcp, "units", "none")
2257  call netcdf_err(error, 'DEFINING TPRCP UNITS' )
2258  error = nf90_put_att(ncid, id_tprcp, "coordinates", "geolon geolat")
2259  call netcdf_err(error, 'DEFINING TPRCP COORD' )
2260 
2261  error = nf90_def_var(ncid, 'srflag', nf90_double, (/dim_x,dim_y,dim_time/), id_srflag)
2262  call netcdf_err(error, 'DEFINING SRFLAG' )
2263  error = nf90_put_att(ncid, id_srflag, "long_name", "srflag")
2264  call netcdf_err(error, 'DEFINING SRFLAG LONG NAME' )
2265  error = nf90_put_att(ncid, id_srflag, "units", "none")
2266  call netcdf_err(error, 'DEFINING SRFLAG UNITS' )
2267  error = nf90_put_att(ncid, id_srflag, "coordinates", "geolon geolat")
2268  call netcdf_err(error, 'DEFINING SRFLAG COORD' )
2269 
2270  error = nf90_def_var(ncid, 'snwdph', nf90_double, (/dim_x,dim_y,dim_time/), id_snwdph)
2271  call netcdf_err(error, 'DEFINING SNWDPH' )
2272  error = nf90_put_att(ncid, id_snwdph, "long_name", "snwdph")
2273  call netcdf_err(error, 'DEFINING SNWDPH LONG NAME' )
2274  error = nf90_put_att(ncid, id_snwdph, "units", "none")
2275  call netcdf_err(error, 'DEFINING SNWDPH UNITS' )
2276  error = nf90_put_att(ncid, id_snwdph, "coordinates", "geolon geolat")
2277  call netcdf_err(error, 'DEFINING SNWDPH COORD' )
2278 
2279  error = nf90_def_var(ncid, 'shdmin', nf90_double, (/dim_x,dim_y,dim_time/), id_shdmin)
2280  call netcdf_err(error, 'DEFINING SHDMIN' )
2281  error = nf90_put_att(ncid, id_shdmin, "long_name", "shdmin")
2282  call netcdf_err(error, 'DEFINING SHDMIN LONG NAME' )
2283  error = nf90_put_att(ncid, id_shdmin, "units", "none")
2284  call netcdf_err(error, 'DEFINING SHDMIN UNITS' )
2285  error = nf90_put_att(ncid, id_shdmin, "coordinates", "geolon geolat")
2286  call netcdf_err(error, 'DEFINING SHDMIN COORD' )
2287 
2288  error = nf90_def_var(ncid, 'shdmax', nf90_double, (/dim_x,dim_y,dim_time/), id_shdmax)
2289  call netcdf_err(error, 'DEFINING SHDMAX' )
2290  error = nf90_put_att(ncid, id_shdmax, "long_name", "shdmax")
2291  call netcdf_err(error, 'DEFINING SHDMAX LONG NAME' )
2292  error = nf90_put_att(ncid, id_shdmax, "units", "none")
2293  call netcdf_err(error, 'DEFINING SHDMAX UNITS' )
2294  error = nf90_put_att(ncid, id_shdmax, "coordinates", "geolon geolat")
2295  call netcdf_err(error, 'DEFINING SHDMAX COORD' )
2296 
2297  error = nf90_def_var(ncid, 'slope', nf90_double, (/dim_x,dim_y,dim_time/), id_slope)
2298  call netcdf_err(error, 'DEFINING SLOPE' )
2299  error = nf90_put_att(ncid, id_slope, "long_name", "slope")
2300  call netcdf_err(error, 'DEFINING SLOPE LONG NAME' )
2301  error = nf90_put_att(ncid, id_slope, "units", "none")
2302  call netcdf_err(error, 'DEFINING SLOPE UNITS' )
2303  error = nf90_put_att(ncid, id_slope, "coordinates", "geolon geolat")
2304  call netcdf_err(error, 'DEFINING SLOPE COORD' )
2305 
2306  error = nf90_def_var(ncid, 'snoalb', nf90_double, (/dim_x,dim_y,dim_time/), id_snoalb)
2307  call netcdf_err(error, 'DEFINING SNOALB' )
2308  error = nf90_put_att(ncid, id_snoalb, "long_name", "snoalb")
2309  call netcdf_err(error, 'DEFINING SNOALB LONG NAME' )
2310  error = nf90_put_att(ncid, id_snoalb, "units", "none")
2311  call netcdf_err(error, 'DEFINING SNOALB UNITS' )
2312  error = nf90_put_att(ncid, id_snoalb, "coordinates", "geolon geolat")
2313  call netcdf_err(error, 'DEFINING SNOALB COORD' )
2314 
2315  if (.not. lai_from_climo) then
2316  error = nf90_def_var(ncid, 'lai', nf90_double, (/dim_x,dim_y,dim_time/), id_lai)
2317  call netcdf_err(error, 'DEFINING LAI' )
2318  error = nf90_put_att(ncid, id_lai, "long_name", "lai")
2319  call netcdf_err(error, 'DEFINING LAI LONG NAME' )
2320  error = nf90_put_att(ncid, id_lai, "units", "none")
2321  call netcdf_err(error, 'DEFINING LAI UNITS' )
2322  error = nf90_put_att(ncid, id_lai, "coordinates", "geolon geolat")
2323  call netcdf_err(error, 'DEFINING LAI COORD' )
2324  endif
2325 
2326  error = nf90_def_var(ncid, 'stc', nf90_double, (/dim_x,dim_y,dim_lsoil,dim_time/), id_stc)
2327  call netcdf_err(error, 'DEFINING STC' )
2328  error = nf90_put_att(ncid, id_stc, "long_name", "stc")
2329  call netcdf_err(error, 'DEFINING STC LONG NAME' )
2330  error = nf90_put_att(ncid, id_stc, "units", "none")
2331  call netcdf_err(error, 'DEFINING STC UNITS' )
2332  error = nf90_put_att(ncid, id_stc, "coordinates", "geolon geolat")
2333  call netcdf_err(error, 'DEFINING STC COORD' )
2334 
2335  error = nf90_def_var(ncid, 'smc', nf90_double, (/dim_x,dim_y,dim_lsoil,dim_time/), id_smc)
2336  call netcdf_err(error, 'DEFINING SMC' )
2337  error = nf90_put_att(ncid, id_smc, "long_name", "smc")
2338  call netcdf_err(error, 'DEFINING SMC LONG NAME' )
2339  error = nf90_put_att(ncid, id_smc, "units", "none")
2340  call netcdf_err(error, 'DEFINING SMC UNITS' )
2341  error = nf90_put_att(ncid, id_smc, "coordinates", "geolon geolat")
2342  call netcdf_err(error, 'DEFINING SMC COORD' )
2343 
2344  error = nf90_def_var(ncid, 'slc', nf90_double, (/dim_x,dim_y,dim_lsoil,dim_time/), id_slc)
2345  call netcdf_err(error, 'DEFINING SLC' )
2346  error = nf90_put_att(ncid, id_slc, "long_name", "slc")
2347  call netcdf_err(error, 'DEFINING SLC LONG NAME' )
2348  error = nf90_put_att(ncid, id_slc, "units", "none")
2349  call netcdf_err(error, 'DEFINING SLC UNITS' )
2350  error = nf90_put_att(ncid, id_slc, "coordinates", "geolon geolat")
2351  call netcdf_err(error, 'DEFINING SLC COORD' )
2352 
2353  if (convert_nst) then
2354 
2355  error = nf90_def_var(ncid, 'tref', nf90_double, (/dim_x,dim_y,dim_time/), id_tref)
2356  call netcdf_err(error, 'DEFINING TREF' )
2357  error = nf90_put_att(ncid, id_tref, "long_name", "tref")
2358  call netcdf_err(error, 'DEFINING TREF LONG NAME' )
2359  error = nf90_put_att(ncid, id_tref, "units", "none")
2360  call netcdf_err(error, 'DEFINING TREF UNITS' )
2361  error = nf90_put_att(ncid, id_tref, "coordinates", "geolon geolat")
2362  call netcdf_err(error, 'DEFINING TREF COORD' )
2363 
2364  error = nf90_def_var(ncid, 'z_c', nf90_double, (/dim_x,dim_y,dim_time/), id_z_c)
2365  call netcdf_err(error, 'DEFINING Z_C' )
2366  error = nf90_put_att(ncid, id_z_c, "long_name", "z_c")
2367  call netcdf_err(error, 'DEFINING Z_C LONG NAME' )
2368  error = nf90_put_att(ncid, id_z_c, "units", "none")
2369  call netcdf_err(error, 'DEFINING Z_C UNITS' )
2370  error = nf90_put_att(ncid, id_z_c, "coordinates", "geolon geolat")
2371  call netcdf_err(error, 'DEFINING Z_C COORD' )
2372 
2373  error = nf90_def_var(ncid, 'c_0', nf90_double, (/dim_x,dim_y,dim_time/), id_c_0)
2374  call netcdf_err(error, 'DEFINING C_0' )
2375  error = nf90_put_att(ncid, id_c_0, "long_name", "c_0")
2376  call netcdf_err(error, 'DEFINING C_0 LONG NAME' )
2377  error = nf90_put_att(ncid, id_c_0, "units", "none")
2378  call netcdf_err(error, 'DEFINING C_0 UNITS' )
2379  error = nf90_put_att(ncid, id_c_0, "coordinates", "geolon geolat")
2380  call netcdf_err(error, 'DEFINING C_0 COORD' )
2381 
2382  error = nf90_def_var(ncid, 'c_d', nf90_double, (/dim_x,dim_y,dim_time/), id_c_d)
2383  call netcdf_err(error, 'DEFINING C_D' )
2384  error = nf90_put_att(ncid, id_c_d, "long_name", "c_d")
2385  call netcdf_err(error, 'DEFINING C_D LONG NAME' )
2386  error = nf90_put_att(ncid, id_c_d, "units", "none")
2387  call netcdf_err(error, 'DEFINING C_D UNITS' )
2388  error = nf90_put_att(ncid, id_c_d, "coordinates", "geolon geolat")
2389  call netcdf_err(error, 'DEFINING C_D COORD' )
2390 
2391  error = nf90_def_var(ncid, 'w_0', nf90_double, (/dim_x,dim_y,dim_time/), id_w_0)
2392  call netcdf_err(error, 'DEFINING W_0' )
2393  error = nf90_put_att(ncid, id_w_0, "long_name", "w_0")
2394  call netcdf_err(error, 'DEFINING W_0 LONG NAME' )
2395  error = nf90_put_att(ncid, id_w_0, "units", "none")
2396  call netcdf_err(error, 'DEFINING W_0 UNITS' )
2397  error = nf90_put_att(ncid, id_w_0, "coordinates", "geolon geolat")
2398  call netcdf_err(error, 'DEFINING W_0 COORD' )
2399 
2400  error = nf90_def_var(ncid, 'w_d', nf90_double, (/dim_x,dim_y,dim_time/), id_w_d)
2401  call netcdf_err(error, 'DEFINING W_D' )
2402  error = nf90_put_att(ncid, id_w_d, "long_name", "w_d")
2403  call netcdf_err(error, 'DEFINING W_D LONG NAME' )
2404  error = nf90_put_att(ncid, id_w_d, "units", "none")
2405  call netcdf_err(error, 'DEFINING W_D UNITS' )
2406  error = nf90_put_att(ncid, id_w_d, "coordinates", "geolon geolat")
2407  call netcdf_err(error, 'DEFINING W_D COORD' )
2408 
2409  error = nf90_def_var(ncid, 'xt', nf90_double, (/dim_x,dim_y,dim_time/), id_xt)
2410  call netcdf_err(error, 'DEFINING XT' )
2411  error = nf90_put_att(ncid, id_xt, "long_name", "xt")
2412  call netcdf_err(error, 'DEFINING XT LONG NAME' )
2413  error = nf90_put_att(ncid, id_xt, "units", "none")
2414  call netcdf_err(error, 'DEFINING XT UNITS' )
2415  error = nf90_put_att(ncid, id_xt, "coordinates", "geolon geolat")
2416  call netcdf_err(error, 'DEFINING XT COORD' )
2417 
2418  error = nf90_def_var(ncid, 'xs', nf90_double, (/dim_x,dim_y,dim_time/), id_xs)
2419  call netcdf_err(error, 'DEFINING XS' )
2420  error = nf90_put_att(ncid, id_xs, "long_name", "xs")
2421  call netcdf_err(error, 'DEFINING XS LONG NAME' )
2422  error = nf90_put_att(ncid, id_xs, "units", "none")
2423  call netcdf_err(error, 'DEFINING XS UNITS' )
2424  error = nf90_put_att(ncid, id_xs, "coordinates", "geolon geolat")
2425  call netcdf_err(error, 'DEFINING XS COORD' )
2426 
2427  error = nf90_def_var(ncid, 'xu', nf90_double, (/dim_x,dim_y,dim_time/), id_xu)
2428  call netcdf_err(error, 'DEFINING XU' )
2429  error = nf90_put_att(ncid, id_xu, "long_name", "xu")
2430  call netcdf_err(error, 'DEFINING XU LONG NAME' )
2431  error = nf90_put_att(ncid, id_xu, "units", "none")
2432  call netcdf_err(error, 'DEFINING XU UNITS' )
2433  error = nf90_put_att(ncid, id_xu, "coordinates", "geolon geolat")
2434  call netcdf_err(error, 'DEFINING XU COORD' )
2435 
2436  error = nf90_def_var(ncid, 'xv', nf90_double, (/dim_x,dim_y,dim_time/), id_xv)
2437  call netcdf_err(error, 'DEFINING XV' )
2438  error = nf90_put_att(ncid, id_xv, "long_name", "xv")
2439  call netcdf_err(error, 'DEFINING XV LONG NAME' )
2440  error = nf90_put_att(ncid, id_xv, "units", "none")
2441  call netcdf_err(error, 'DEFINING XV UNITS' )
2442  error = nf90_put_att(ncid, id_xv, "coordinates", "geolon geolat")
2443  call netcdf_err(error, 'DEFINING XV COORD' )
2444 
2445  error = nf90_def_var(ncid, 'xz', nf90_double, (/dim_x,dim_y,dim_time/), id_xz)
2446  call netcdf_err(error, 'DEFINING XZ' )
2447  error = nf90_put_att(ncid, id_xz, "long_name", "xz")
2448  call netcdf_err(error, 'DEFINING XZ LONG NAME' )
2449  error = nf90_put_att(ncid, id_xz, "units", "none")
2450  call netcdf_err(error, 'DEFINING XZ UNITS' )
2451  error = nf90_put_att(ncid, id_xz, "coordinates", "geolon geolat")
2452  call netcdf_err(error, 'DEFINING XZ COORD' )
2453 
2454  error = nf90_def_var(ncid, 'zm', nf90_double, (/dim_x,dim_y,dim_time/), id_zm)
2455  call netcdf_err(error, 'DEFINING ZM' )
2456  error = nf90_put_att(ncid, id_zm, "long_name", "zm")
2457  call netcdf_err(error, 'DEFINING ZM LONG NAME' )
2458  error = nf90_put_att(ncid, id_zm, "units", "none")
2459  call netcdf_err(error, 'DEFINING ZM UNITS' )
2460  error = nf90_put_att(ncid, id_zm, "coordinates", "geolon geolat")
2461  call netcdf_err(error, 'DEFINING ZM COORD' )
2462 
2463  error = nf90_def_var(ncid, 'xtts', nf90_double, (/dim_x,dim_y,dim_time/), id_xtts)
2464  call netcdf_err(error, 'DEFINING XTTS' )
2465  error = nf90_put_att(ncid, id_xtts, "long_name", "xtts")
2466  call netcdf_err(error, 'DEFINING XTTS LONG NAME' )
2467  error = nf90_put_att(ncid, id_xtts, "units", "none")
2468  call netcdf_err(error, 'DEFINING XTTS UNITS' )
2469  error = nf90_put_att(ncid, id_xtts, "coordinates", "geolon geolat")
2470  call netcdf_err(error, 'DEFINING XTTS COORD' )
2471 
2472  error = nf90_def_var(ncid, 'xzts', nf90_double, (/dim_x,dim_y,dim_time/), id_xzts)
2473  call netcdf_err(error, 'DEFINING XZTS' )
2474  error = nf90_put_att(ncid, id_xzts, "long_name", "xzts")
2475  call netcdf_err(error, 'DEFINING XZTS LONG NAME' )
2476  error = nf90_put_att(ncid, id_xzts, "units", "none")
2477  call netcdf_err(error, 'DEFINING XZTS UNITS' )
2478  error = nf90_put_att(ncid, id_xzts, "coordinates", "geolon geolat")
2479  call netcdf_err(error, 'DEFINING XZTS COORD' )
2480 
2481  error = nf90_def_var(ncid, 'd_conv', nf90_double, (/dim_x,dim_y,dim_time/), id_d_conv)
2482  call netcdf_err(error, 'DEFINING D_CONV' )
2483  error = nf90_put_att(ncid, id_d_conv, "long_name", "d_conv")
2484  call netcdf_err(error, 'DEFINING D_CONV LONG NAME' )
2485  error = nf90_put_att(ncid, id_d_conv, "units", "none")
2486  call netcdf_err(error, 'DEFINING D_CONV UNITS' )
2487  error = nf90_put_att(ncid, id_d_conv, "coordinates", "geolon geolat")
2488  call netcdf_err(error, 'DEFINING D_CONV COORD' )
2489 
2490  error = nf90_def_var(ncid, 'ifd', nf90_double, (/dim_x,dim_y,dim_time/), id_ifd)
2491  call netcdf_err(error, 'DEFINING IFD' )
2492  error = nf90_put_att(ncid, id_ifd, "long_name", "ifd")
2493  call netcdf_err(error, 'DEFINING IFD LONG NAME' )
2494  error = nf90_put_att(ncid, id_ifd, "units", "none")
2495  call netcdf_err(error, 'DEFINING IFD UNITS' )
2496  error = nf90_put_att(ncid, id_ifd, "coordinates", "geolon geolat")
2497  call netcdf_err(error, 'DEFINING IFD COORD' )
2498 
2499  error = nf90_def_var(ncid, 'dt_cool', nf90_double, (/dim_x,dim_y,dim_time/), id_dt_cool)
2500  call netcdf_err(error, 'DEFINING DT_COOL' )
2501  error = nf90_put_att(ncid, id_dt_cool, "long_name", "dt_cool")
2502  call netcdf_err(error, 'DEFINING DT_COOL LONG NAME' )
2503  error = nf90_put_att(ncid, id_dt_cool, "units", "none")
2504  call netcdf_err(error, 'DEFINING DT_COOL UNITS' )
2505  error = nf90_put_att(ncid, id_dt_cool, "coordinates", "geolon geolat")
2506  call netcdf_err(error, 'DEFINING DT_COOL COORD' )
2507 
2508  error = nf90_def_var(ncid, 'qrain', nf90_double, (/dim_x,dim_y,dim_time/), id_qrain)
2509  call netcdf_err(error, 'DEFINING QRAIN' )
2510  error = nf90_put_att(ncid, id_qrain, "long_name", "qrain")
2511  call netcdf_err(error, 'DEFINING QRAIN LONG NAME' )
2512  error = nf90_put_att(ncid, id_qrain, "units", "none")
2513  call netcdf_err(error, 'DEFINING QRAIN UNITS' )
2514  error = nf90_put_att(ncid, id_qrain, "coordinates", "geolon geolat")
2515  call netcdf_err(error, 'DEFINING QRAIN COORD' )
2516 
2517  endif ! nsst records
2518 
2519  error = nf90_enddef(ncid, header_buffer_val,4,0,4)
2520  call netcdf_err(error, 'DEFINING HEADER' )
2521 
2522  endif local_pet ! is localpet 0?
2523 
2524  if (localpet == 0) then
2525  error = nf90_put_var( ncid, id_lsoil, lsoil_data)
2526  call netcdf_err(error, 'WRITING ZAXIS RECORD' )
2527  error = nf90_put_var( ncid, id_x, x_data)
2528  call netcdf_err(error, 'WRITING XAXIS RECORD' )
2529  error = nf90_put_var( ncid, id_y, y_data)
2530  call netcdf_err(error, 'WRITING YAXIS RECORD' )
2531  times = 1.0
2532  error = nf90_put_var( ncid, id_time, times)
2533  call netcdf_err(error, 'WRITING TIME RECORD' )
2534  endif
2535 
2536  print*,"- CALL FieldGather FOR TARGET GRID LATITUDE FOR TILE: ", tile
2537  call esmf_fieldgather(latitude_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2538  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2539  call error_handler("IN FieldGather", error)
2540 
2541  if (localpet == 0) then
2542  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2543  error = nf90_put_var( ncid, id_lat, dum2d)
2544  call netcdf_err(error, 'WRITING LATITUDE RECORD' )
2545  endif
2546 
2547  print*,"- CALL FieldGather FOR TARGET GRID LONGITUDE FOR TILE: ", tile
2548  call esmf_fieldgather(longitude_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2549  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2550  call error_handler("IN FieldGather", error)
2551 
2552  if (localpet == 0) then
2553  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2554  error = nf90_put_var( ncid, id_lon, dum2d)
2555  call netcdf_err(error, 'WRITING LONGITUDE RECORD' )
2556  endif
2557 
2558  print*,"- CALL FieldGather FOR TARGET GRID SNOW LIQ EQUIV FOR TILE: ", tile
2559  call esmf_fieldgather(snow_liq_equiv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2560  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2561  call error_handler("IN FieldGather", error)
2562 
2563  if (localpet == 0) then
2564  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2565  error = nf90_put_var( ncid, id_sheleg, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2566  call netcdf_err(error, 'WRITING SNOW LIQ EQUIV RECORD' )
2567  endif
2568 
2569  print*,"- CALL FieldGather FOR TARGET GRID SNOW DEPTH FOR TILE: ", tile
2570  call esmf_fieldgather(snow_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2571  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2572  call error_handler("IN FieldGather", error)
2573 
2574  if (localpet == 0) then
2575  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2576  error = nf90_put_var( ncid, id_snwdph, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2577  call netcdf_err(error, 'WRITING SNWDPH RECORD' )
2578  endif
2579 
2580  print*,"- CALL FieldGather FOR TARGET GRID SLOPE TYPE FOR TILE: ", tile
2581  call esmf_fieldgather(slope_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2582  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2583  call error_handler("IN FieldGather", error)
2584 
2585  if (localpet == 0) then
2586  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2587  error = nf90_put_var( ncid, id_slope, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2588  call netcdf_err(error, 'WRITING SLOPE RECORD' )
2589  endif
2590 
2591  print*,"- CALL FieldGather FOR TARGET GRID Z0 FOR TILE: ", tile
2592  call esmf_fieldgather(z0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2593  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2594  call error_handler("IN FieldGather", error)
2595 
2596  if (localpet == 0) then
2597  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2598  error = nf90_put_var( ncid, id_zorl, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2599  call netcdf_err(error, 'WRITING Z0 RECORD' )
2600  endif
2601 
2602  print*,"- CALL FieldGather FOR TARGET GRID MAX SNOW ALBEDO FOR TILE: ", tile
2603  call esmf_fieldgather(mxsno_albedo_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2604  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2605  call error_handler("IN FieldGather", error)
2606 
2607  if (localpet == 0) then
2608  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2609  error = nf90_put_var( ncid, id_snoalb, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2610  call netcdf_err(error, 'WRITING MAX SNOW ALBEDO RECORD' )
2611  endif
2612 
2613  if (.not. lai_from_climo) then
2614  print*,"- CALL FieldGather FOR TARGET GRID LEAF AREA INDEX FOR TILE: ", tile
2615  call esmf_fieldgather(lai_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2616  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2617  call error_handler("IN FieldGather", error)
2618 
2619  if (localpet == 0) then
2620  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2621  error = nf90_put_var( ncid, id_lai, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2622  call netcdf_err(error, 'WRITING LEAF AREA INDEX RECORD' )
2623  endif
2624  endif
2625 
2626  print*,"- CALL FieldGather FOR TARGET GRID SOIL TYPE FOR TILE: ", tile
2627  call esmf_fieldgather(soil_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2628  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2629  call error_handler("IN FieldGather", error)
2630 
2631  if (localpet == 0) then
2632  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2633  error = nf90_put_var( ncid, id_stype, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2634  call netcdf_err(error, 'WRITING SOIL TYPE RECORD' )
2635  endif
2636 
2637  print*,"- CALL FieldGather FOR TARGET GRID VEGETATION TYPE FOR TILE: ", tile
2638  call esmf_fieldgather(veg_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2639  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2640  call error_handler("IN FieldGather", error)
2641 
2642  if (localpet == 0) then
2643  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2644  error = nf90_put_var( ncid, id_vtype, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2645  call netcdf_err(error, 'WRITING VEGETATION TYPE RECORD' )
2646  endif
2647 
2648  print*,"- CALL FieldGather FOR TARGET GRID VEGETATION GREENNESS FOR TILE: ", tile
2649  call esmf_fieldgather(veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2650  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2651  call error_handler("IN FieldGather", error)
2652 
2653  if (localpet == 0) then
2654  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2655  error = nf90_put_var( ncid, id_vfrac, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2656  call netcdf_err(error, 'WRITING VEGETATION GREENNESS RECORD' )
2657  endif
2658 
2659  print*,"- CALL FieldGather FOR TARGET GRID SUBSTRATE TEMPERATURE FOR TILE: ", tile
2660  call esmf_fieldgather(substrate_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2661  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2662  call error_handler("IN FieldGather", error)
2663 
2664  if (localpet == 0) then
2665  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2666  error = nf90_put_var( ncid, id_tg3, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2667  call netcdf_err(error, 'WRITING SUBSTRATE TEMPERATURE RECORD' )
2668  endif
2669 
2670  print*,"- CALL FieldGather FOR TARGET GRID FACSF FOR TILE: ", tile
2671  call esmf_fieldgather(facsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2672  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2673  call error_handler("IN FieldGather", error)
2674 
2675  if (localpet == 0) then
2676  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2677  error = nf90_put_var( ncid, id_facsf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2678  call netcdf_err(error, 'WRITING FACSF RECORD' )
2679  endif
2680 
2681  print*,"- CALL FieldGather FOR TARGET GRID FACWF FOR TILE: ", tile
2682  call esmf_fieldgather(facwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2683  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2684  call error_handler("IN FieldGather", error)
2685 
2686  if (localpet == 0) then
2687  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2688  error = nf90_put_var( ncid, id_facwf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2689  call netcdf_err(error, 'WRITING FACWF RECORD' )
2690  endif
2691 
2692  print*,"- CALL FieldGather FOR TARGET GRID ALNSF FOR TILE: ", tile
2693  call esmf_fieldgather(alnsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2694  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2695  call error_handler("IN FieldGather", error)
2696 
2697  if (localpet == 0) then
2698  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2699  error = nf90_put_var( ncid, id_alnsf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2700  call netcdf_err(error, 'WRITING ALNSF RECORD' )
2701  endif
2702 
2703  print*,"- CALL FieldGather FOR TARGET GRID ALNWF FOR TILE: ", tile
2704  call esmf_fieldgather(alnwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2705  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2706  call error_handler("IN FieldGather", error)
2707 
2708  if (localpet == 0) then
2709  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2710  error = nf90_put_var( ncid, id_alnwf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2711  call netcdf_err(error, 'WRITING ALNWF RECORD' )
2712  endif
2713 
2714  print*,"- CALL FieldGather FOR TARGET GRID ALVSF FOR TILE: ", tile
2715  call esmf_fieldgather(alvsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2716  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2717  call error_handler("IN FieldGather", error)
2718 
2719  if (localpet == 0) then
2720  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2721  error = nf90_put_var( ncid, id_alvsf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2722  call netcdf_err(error, 'WRITING ALVSF RECORD' )
2723  endif
2724 
2725  print*,"- CALL FieldGather FOR TARGET GRID ALVWF FOR TILE: ", tile
2726  call esmf_fieldgather(alvwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2727  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2728  call error_handler("IN FieldGather", error)
2729 
2730  if (localpet == 0) then
2731  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2732  error = nf90_put_var( ncid, id_alvwf, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2733  call netcdf_err(error, 'WRITING ALVWF RECORD' )
2734  endif
2735 
2736  print*,"- CALL FieldGather FOR TARGET GRID MAX VEGETATION GREENNESS FOR TILE: ", tile
2737  call esmf_fieldgather(max_veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2738  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2739  call error_handler("IN FieldGather", error)
2740 
2741  if (localpet == 0) then
2742  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2743  error = nf90_put_var( ncid, id_shdmax, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2744  call netcdf_err(error, 'WRITING MAX VEGETATION GREENNESS RECORD' )
2745  endif
2746 
2747  print*,"- CALL FieldGather FOR TARGET GRID MIN VEGETATION GREENNESS FOR TILE: ", tile
2748  call esmf_fieldgather(min_veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2749  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2750  call error_handler("IN FieldGather", error)
2751 
2752  if (localpet == 0) then
2753  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2754  error = nf90_put_var( ncid, id_shdmin, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2755  call netcdf_err(error, 'WRITING MIN VEGETATION GREENNESS RECORD' )
2756  endif
2757 
2758  print*,"- CALL FieldGather FOR TARGET GRID T2M FOR TILE: ", tile
2759  call esmf_fieldgather(t2m_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2760  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2761  call error_handler("IN FieldGather", error)
2762 
2763  if (localpet == 0) then
2764  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2765  error = nf90_put_var( ncid, id_t2m, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2766  call netcdf_err(error, 'WRITING T2M RECORD' )
2767  endif
2768 
2769  print*,"- CALL FieldGather FOR TARGET GRID Q2M FOR TILE: ", tile
2770  call esmf_fieldgather(q2m_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2771  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2772  call error_handler("IN FieldGather", error)
2773 
2774  if (localpet == 0) then
2775  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2776  error = nf90_put_var( ncid, id_q2m, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2777  call netcdf_err(error, 'WRITING Q2M RECORD' )
2778  endif
2779 
2780  print*,"- CALL FieldGather FOR TARGET GRID TPRCP FOR TILE: ", tile
2781  call esmf_fieldgather(tprcp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2782  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2783  call error_handler("IN FieldGather", error)
2784 
2785  if (localpet == 0) then
2786  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2787  error = nf90_put_var( ncid, id_tprcp, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2788  call netcdf_err(error, 'WRITING TPRCP RECORD' )
2789  endif
2790 
2791  print*,"- CALL FieldGather FOR TARGET GRID F10M FOR TILE: ", tile
2792  call esmf_fieldgather(f10m_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2793  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2794  call error_handler("IN FieldGather", error)
2795 
2796  if (localpet == 0) then
2797  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2798  error = nf90_put_var( ncid, id_f10m, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2799  call netcdf_err(error, 'WRITING F10M RECORD' )
2800  endif
2801 
2802  print*,"- CALL FieldGather FOR TARGET GRID FFMM FOR TILE: ", tile
2803  call esmf_fieldgather(ffmm_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2804  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2805  call error_handler("IN FieldGather", error)
2806 
2807  if (localpet == 0) then
2808  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2809  error = nf90_put_var( ncid, id_ffmm, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2810  call netcdf_err(error, 'WRITING FFMM RECORD' )
2811  dum2d = 0.0
2812  error = nf90_put_var( ncid, id_ffhh, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2813  call netcdf_err(error, 'WRITING FFHH RECORD' )
2814  endif
2815 
2816  print*,"- CALL FieldGather FOR TARGET GRID USTAR FOR TILE: ", tile
2817  call esmf_fieldgather(ustar_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2818  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2819  call error_handler("IN FieldGather", error)
2820 
2821  if (localpet == 0) then
2822  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2823  error = nf90_put_var( ncid, id_uustar, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2824  call netcdf_err(error, 'WRITING USTAR RECORD' )
2825  endif
2826 
2827  print*,"- CALL FieldGather FOR TARGET GRID SRFLAG FOR TILE: ", tile
2828  call esmf_fieldgather(srflag_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2829  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2830  call error_handler("IN FieldGather", error)
2831 
2832  if (localpet == 0) then
2833  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2834  error = nf90_put_var( ncid, id_srflag, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2835  call netcdf_err(error, 'WRITING SRFLAG RECORD' )
2836  endif
2837 
2838  print*,"- CALL FieldGather FOR TARGET GRID SEA ICE FRACTION FOR TILE: ", tile
2839  call esmf_fieldgather(seaice_fract_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2840  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2841  call error_handler("IN FieldGather", error)
2842 
2843  if (localpet == 0) then
2844  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2845  error = nf90_put_var( ncid, id_fice, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2846  call netcdf_err(error, 'WRITING FICE RECORD' )
2847  endif
2848 
2849  print*,"- CALL FieldGather FOR TARGET GRID SEA ICE DEPTH FOR TILE: ", tile
2850  call esmf_fieldgather(seaice_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2851  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2852  call error_handler("IN FieldGather", error)
2853 
2854  if (localpet == 0) then
2855  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2856  error = nf90_put_var( ncid, id_hice, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2857  call netcdf_err(error, 'WRITING HICE RECORD' )
2858  endif
2859 
2860  print*,"- CALL FieldGather FOR TARGET GRID SEA ICE SKIN TEMP FOR TILE: ", tile
2861  call esmf_fieldgather(seaice_skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2862  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2863  call error_handler("IN FieldGather", error)
2864 
2865  if (localpet == 0) then
2866  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2867  error = nf90_put_var( ncid, id_tisfc, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2868  call netcdf_err(error, 'WRITING TISFC RECORD' )
2869  endif
2870 
2871  print*,"- CALL FieldGather FOR TARGET GRID SKIN TEMP FOR TILE: ", tile
2872  call esmf_fieldgather(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2873  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2874  call error_handler("IN FieldGather", error)
2875 
2876  if (localpet == 0) then
2877  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2878  error = nf90_put_var( ncid, id_tsea, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2879  call netcdf_err(error, 'WRITING TSEA RECORD' )
2880  endif
2881 
2882  print*,"- CALL FieldGather FOR TARGET GRID LANDMASK FOR TILE: ", tile
2883  call esmf_fieldgather(landmask_target_grid, idata_one_tile, rootpet=0, tile=tile, rc=error)
2884  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2885  call error_handler("IN FieldGather", error)
2886 
2887  if (localpet == 0) then
2888  dum2d(:,:) = float(idata_one_tile(istart:iend, jstart:jend))
2889  error = nf90_put_var( ncid, id_slmsk, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2890  call netcdf_err(error, 'WRITING LANDMASK RECORD' )
2891  endif
2892 
2893  print*,"- CALL FieldGather FOR TARGET GRID CANOPY MOISTURE CONTENT FOR TILE: ", tile
2894  call esmf_fieldgather(canopy_mc_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2895  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2896  call error_handler("IN FieldGather", error)
2897 
2898  if (localpet == 0) then
2899  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2900  error = nf90_put_var( ncid, id_canopy, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2901  call netcdf_err(error, 'WRITING CANOPY MC RECORD' )
2902  endif
2903 
2904 ! soil temperature
2905 
2906  print*,"- CALL FieldGather FOR TARGET GRID SOIL TEMPERATURE FOR TILE: ", tile
2907  call esmf_fieldgather(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
2908  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2909  call error_handler("IN FieldGather", error)
2910 
2911  if (localpet == 0) then
2912  dum3d(:,:,:) = data_one_tile_3d(istart:iend, jstart:jend,:)
2913  error = nf90_put_var( ncid, id_stc, dum3d, start=(/1,1,1,1/), count=(/i_target_out,j_target_out,lsoil_target,1/))
2914  call netcdf_err(error, 'WRITING SOIL TEMP RECORD' )
2915  endif
2916 
2917 ! soil moisture (total)
2918 
2919  print*,"- CALL FieldGather FOR TARGET GRID TOTAL SOIL MOISTURE FOR TILE: ", tile
2920  call esmf_fieldgather(soilm_tot_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
2921  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2922  call error_handler("IN FieldGather", error)
2923 
2924  if (localpet == 0) then
2925  dum3d(:,:,:) = data_one_tile_3d(istart:iend, jstart:jend,:)
2926  error = nf90_put_var( ncid, id_smc, dum3d, start=(/1,1,1,1/), count=(/i_target_out,j_target_out,lsoil_target,1/))
2927  call netcdf_err(error, 'WRITING TOTAL SOIL MOISTURE RECORD' )
2928  endif
2929 
2930 ! soil moisture (liquid)
2931 
2932  print*,"- CALL FieldGather FOR TARGET GRID LIQUID SOIL MOISTURE FOR TILE: ", tile
2933  call esmf_fieldgather(soilm_liq_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=error)
2934  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2935  call error_handler("IN FieldGather", error)
2936 
2937  if (localpet == 0) then
2938  dum3d(:,:,:) = data_one_tile_3d(istart:iend, jstart:jend,:)
2939  error = nf90_put_var( ncid, id_slc, dum3d, start=(/1,1,1,1/), count=(/i_target_out,j_target_out,lsoil_target,1/))
2940  call netcdf_err(error, 'WRITING LIQUID SOIL MOISTURE RECORD' )
2941  endif
2942 
2943  if (convert_nst) then
2944 
2945  print*,"- CALL FieldGather FOR TARGET C_D FOR TILE: ", tile
2946  call esmf_fieldgather(c_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2947  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2948  call error_handler("IN FieldGather", error)
2949 
2950  if (localpet == 0) then
2951  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2952  error = nf90_put_var( ncid, id_c_d, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2953  call netcdf_err(error, 'WRITING C_D RECORD' )
2954  endif
2955 
2956  print*,"- CALL FieldGather FOR TARGET C_0 FOR TILE: ", tile
2957  call esmf_fieldgather(c_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2958  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2959  call error_handler("IN FieldGather", error)
2960 
2961  if (localpet == 0) then
2962  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2963  error = nf90_put_var( ncid, id_c_0, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2964  call netcdf_err(error, 'WRITING C_0 RECORD' )
2965  endif
2966 
2967  print*,"- CALL FieldGather FOR TARGET D_CONV FOR TILE: ", tile
2968  call esmf_fieldgather(d_conv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2969  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2970  call error_handler("IN FieldGather", error)
2971 
2972  if (localpet == 0) then
2973  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2974  error = nf90_put_var( ncid, id_d_conv, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2975  call netcdf_err(error, 'WRITING D_CONV RECORD' )
2976  endif
2977 
2978  print*,"- CALL FieldGather FOR TARGET DT_COOL FOR TILE: ", tile
2979  call esmf_fieldgather(dt_cool_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2980  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2981  call error_handler("IN FieldGather", error)
2982 
2983  if (localpet == 0) then
2984  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2985  error = nf90_put_var( ncid, id_dt_cool, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2986  call netcdf_err(error, 'WRITING DT_COOL RECORD' )
2987  endif
2988 
2989  print*,"- CALL FieldGather FOR TARGET IFD FOR TILE: ", tile
2990  call esmf_fieldgather(ifd_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
2991  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2992  call error_handler("IN FieldGather", error)
2993 
2994  if (localpet == 0) then
2995  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
2996  error = nf90_put_var( ncid, id_ifd, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
2997  call netcdf_err(error, 'WRITING IFD RECORD' )
2998  endif
2999 
3000  print*,"- CALL FieldGather FOR TARGET QRAIN FOR TILE: ", tile
3001  call esmf_fieldgather(qrain_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3002  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3003  call error_handler("IN FieldGather", error)
3004 
3005  if (localpet == 0) then
3006  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3007  error = nf90_put_var( ncid, id_qrain, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3008  call netcdf_err(error, 'WRITING QRAIN RECORD' )
3009  endif
3010 
3011  print*,"- CALL FieldGather FOR TARGET TREF FOR TILE: ", tile
3012  call esmf_fieldgather(tref_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3013  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3014  call error_handler("IN FieldGather", error)
3015 
3016  if (localpet == 0) then
3017  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3018  error = nf90_put_var( ncid, id_tref, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3019  call netcdf_err(error, 'WRITING TREF RECORD' )
3020  endif
3021 
3022  print*,"- CALL FieldGather FOR TARGET W_D FOR TILE: ", tile
3023  call esmf_fieldgather(w_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3024  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3025  call error_handler("IN FieldGather", error)
3026 
3027  if (localpet == 0) then
3028  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3029  error = nf90_put_var( ncid, id_w_d, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3030  call netcdf_err(error, 'WRITING W_D RECORD' )
3031  endif
3032 
3033  print*,"- CALL FieldGather FOR TARGET W_0 FOR TILE: ", tile
3034  call esmf_fieldgather(w_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3035  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3036  call error_handler("IN FieldGather", error)
3037 
3038  if (localpet == 0) then
3039  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3040  error = nf90_put_var( ncid, id_w_0, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3041  call netcdf_err(error, 'WRITING W_0 RECORD' )
3042  endif
3043 
3044  print*,"- CALL FieldGather FOR TARGET XS FOR TILE: ", tile
3045  call esmf_fieldgather(xs_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3046  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3047  call error_handler("IN FieldGather", error)
3048 
3049  if (localpet == 0) then
3050  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3051  error = nf90_put_var( ncid, id_xs, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3052  call netcdf_err(error, 'WRITING XS RECORD' )
3053  endif
3054 
3055  print*,"- CALL FieldGather FOR TARGET XT FOR TILE: ", tile
3056  call esmf_fieldgather(xt_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3057  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3058  call error_handler("IN FieldGather", error)
3059 
3060  if (localpet == 0) then
3061  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3062  error = nf90_put_var( ncid, id_xt, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3063  call netcdf_err(error, 'WRITING XT RECORD' )
3064  endif
3065 
3066  print*,"- CALL FieldGather FOR TARGET XU FOR TILE: ", tile
3067  call esmf_fieldgather(xu_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3068  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3069  call error_handler("IN FieldGather", error)
3070 
3071  if (localpet == 0) then
3072  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3073  error = nf90_put_var( ncid, id_xu, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3074  call netcdf_err(error, 'WRITING XU RECORD' )
3075  endif
3076 
3077  print*,"- CALL FieldGather FOR TARGET XV FOR TILE: ", tile
3078  call esmf_fieldgather(xv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3079  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3080  call error_handler("IN FieldGather", error)
3081 
3082  if (localpet == 0) then
3083  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3084  error = nf90_put_var( ncid, id_xv, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3085  call netcdf_err(error, 'WRITING XV RECORD' )
3086  endif
3087 
3088  print*,"- CALL FieldGather FOR TARGET XZ FOR TILE: ", tile
3089  call esmf_fieldgather(xz_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3090  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3091  call error_handler("IN FieldGather", error)
3092 
3093  if (localpet == 0) then
3094  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3095  error = nf90_put_var( ncid, id_xz, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3096  call netcdf_err(error, 'WRITING XZ RECORD' )
3097  endif
3098 
3099  print*,"- CALL FieldGather FOR TARGET XTTS FOR TILE: ", tile
3100  call esmf_fieldgather(xtts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3101  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3102  call error_handler("IN FieldGather", error)
3103 
3104  if (localpet == 0) then
3105  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3106  error = nf90_put_var( ncid, id_xtts, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3107  call netcdf_err(error, 'WRITING XTTS RECORD' )
3108  endif
3109 
3110  print*,"- CALL FieldGather FOR TARGET XZTS FOR TILE: ", tile
3111  call esmf_fieldgather(xzts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3112  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3113  call error_handler("IN FieldGather", error)
3114 
3115  if (localpet == 0) then
3116  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3117  error = nf90_put_var( ncid, id_xzts, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3118  call netcdf_err(error, 'WRITING XZTS RECORD' )
3119  endif
3120 
3121  print*,"- CALL FieldGather FOR TARGET Z_C FOR TILE: ", tile
3122  call esmf_fieldgather(z_c_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3123  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3124  call error_handler("IN FieldGather", error)
3125 
3126  if (localpet == 0) then
3127  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3128  error = nf90_put_var( ncid, id_z_c, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3129  call netcdf_err(error, 'WRITING Z_C RECORD' )
3130  endif
3131 
3132  print*,"- CALL FieldGather FOR TARGET ZM FOR TILE: ", tile
3133  call esmf_fieldgather(zm_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
3134  if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3135  call error_handler("IN FieldGather", error)
3136 
3137  if (localpet == 0) then
3138  dum2d(:,:) = data_one_tile(istart:iend, jstart:jend)
3139  error = nf90_put_var( ncid, id_zm, dum2d, start=(/1,1,1/), count=(/i_target_out,j_target_out,1/))
3140  call netcdf_err(error, 'WRITING ZM RECORD' )
3141  endif
3142 
3143  endif ! convert nst
3144 
3145 !-------------------------------------------------------------------------------
3146 ! close file
3147 !-------------------------------------------------------------------------------
3148 
3149  error = nf90_close(ncid)
3150 
3151  enddo tile_loop
3152 
3153  deallocate(lsoil_data, x_data, y_data)
3154  deallocate(data_one_tile, data_one_tile_3d, idata_one_tile, dum2d, dum3d)
3155 
3156  return
3157 
3158  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