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