SCALE-RM
scale_fileio.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
15  !-----------------------------------------------------------------------------
16  !
17  !++ used modules
18  !
19  use scale_precision
20  use scale_stdio
21  use scale_prof
25  !-----------------------------------------------------------------------------
26  implicit none
27  private
28  !-----------------------------------------------------------------------------
29  !
30  !++ Public procedure
31  !
32  public :: fileio_setup
33  public :: fileio_cleanup
34  public :: fileio_set_coordinates
35  public :: fileio_check_coordinates
36  public :: fileio_read
37  public :: fileio_write
38  public :: fileio_flush
39 
40  public :: fileio_create
41  public :: fileio_open
42  public :: fileio_def_var
43  public :: fileio_enddef
44  public :: fileio_write_var
45  public :: fileio_close
46 
47  interface fileio_check_coordinates
48  module procedure fileio_check_coordinates_name
49  module procedure fileio_check_coordinates_id
50  end interface fileio_check_coordinates
51 
52  interface fileio_read
53  module procedure fileio_read_1d
54  module procedure fileio_read_2d
55  module procedure fileio_read_3d
56  module procedure fileio_read_4d
57 
58  module procedure fileio_read_var_1d
59  module procedure fileio_read_var_2d
60  module procedure fileio_read_var_3d
61  module procedure fileio_read_var_4d
62  end interface fileio_read
63 
64  interface fileio_write
65  module procedure fileio_write_1d
66  module procedure fileio_write_2d
67  module procedure fileio_write_3d
68  module procedure fileio_write_3d_t
69  module procedure fileio_write_4d
70  end interface fileio_write
71 
72  interface fileio_write_var
73  module procedure fileio_write_var_1d
74  module procedure fileio_write_var_2d
75  module procedure fileio_write_var_3d
76  module procedure fileio_write_var_3d_t
77  module procedure fileio_write_var_4d
78  end interface fileio_write_var
79 
80  !-----------------------------------------------------------------------------
81  !-----------------------------------------------------------------------------
82  !
83  !++ Public parameters & variables
84  !
85  !-----------------------------------------------------------------------------
86  !
87  !++ Private procedure
88  !
89  private :: closeall
90  private :: getcftunits
91  private :: check_1d
92  private :: check_2d
93  private :: check_3d
94  !-----------------------------------------------------------------------------
95  !
96  !++ Private parameters & variables
97  !
98  real(RP), private :: FILEIO_datacheck_criteria
99 
100  real(RP), private, allocatable :: AXIS_LON (:,:) ! [deg]
101  real(RP), private, allocatable :: AXIS_LONX (:,:) ! [deg]
102  real(RP), private, allocatable :: AXIS_LONY (:,:) ! [deg]
103  real(RP), private, allocatable :: AXIS_LONXY(:,:) ! [deg]
104  real(RP), private, allocatable :: AXIS_LAT (:,:) ! [deg]
105  real(RP), private, allocatable :: AXIS_LATX (:,:) ! [deg]
106  real(RP), private, allocatable :: AXIS_LATY (:,:) ! [deg]
107  real(RP), private, allocatable :: AXIS_LATXY(:,:) ! [deg]
108  real(RP), private, allocatable :: AXIS_HZXY (:,:,:)
109  real(RP), private, allocatable :: AXIS_HWXY (:,:,:)
110 
111  integer, private, parameter :: File_nfile_max = 512 ! number limit of file
112  ! Keep consistency with "FILE_MAX" in gtool_netcdf.c
113  logical, private :: File_axes_written(0:File_nfile_max-1) ! whether axes have been written
114  ! ! fid starts from zero so index should start from zero
115  logical, private :: File_closed(0:File_nfile_max-1) ! whether file has been closed
116  logical, private :: File_nozcoord(0:File_nfile_max-1) ! whether nozcoord is true or false
117  integer, private :: write_buf_amount = 0 ! sum of write buffer amounts
118 
119  ! local start and end
120  integer, private :: XSB, XEB, YSB, YEB
121  ! global star and count
122  integer, private :: startXY (3), countXY (3)
123  integer, private :: startZX (2), countZX (2)
124  integer, private :: startZXY (4), countZXY (4)
125  integer, private :: startLAND (3), countLAND (3)
126  integer, private :: startURBAN(3), countURBAN(3)
127 
128  ! MPI element datatype for restart variables
129  integer, private :: etype
130 
131  ! MPI derived datatypes
132  integer, private :: centerTypeXY
133  integer, private :: centerTypeZX
134  integer, private :: centerTypeZXY
135  integer, private :: centerTypeLAND
136  integer, private :: centerTypeURBAN
137 
138  logical, private :: set_coordinates = .false.
139 
140  !-----------------------------------------------------------------------------
141 contains
142  !-----------------------------------------------------------------------------
144  subroutine fileio_setup
145  use scale_process, only: &
146  prc_myrank, &
148  use scale_rm_process, only: &
149  prc_2drank, &
150  prc_num_x, &
151  prc_num_y
152  use scale_const, only: &
153  eps => const_eps
154  implicit none
155 
156  namelist / param_fileio / &
157  fileio_datacheck_criteria
158 
159  integer :: ierr
160  !---------------------------------------------------------------------------
161 
162  if( io_l ) write(io_fid_log,*)
163  if( io_l ) write(io_fid_log,*) '++++++ Module[FIELIO] / Categ[ATMOS-RM IO] / Origin[SCALElib]'
164 
165  fileio_datacheck_criteria = eps * 10.0_rp
166 
167  !--- read namelist
168  rewind(io_fid_conf)
169  read(io_fid_conf,nml=param_fileio,iostat=ierr)
170  if( ierr < 0 ) then !--- missing
171  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
172  elseif( ierr > 0 ) then !--- fatal error
173  write(*,*) 'xxx Not appropriate names in namelist PARAM_FILEIO. Check!'
174  call prc_mpistop
175  endif
176  if( io_nml ) write(io_fid_nml,nml=param_fileio)
177 
178  if( io_l ) write(io_fid_log,*)
179  if( io_l ) write(io_fid_log,*) '*** NetCDF header information ***'
180  if( io_l ) write(io_fid_log,*) '*** Data source : ', trim(h_source)
181  if( io_l ) write(io_fid_log,*) '*** Institute : ', trim(h_institute)
182  if( io_l ) write(io_fid_log,*)
183  if( io_l ) write(io_fid_log,*) '*** Data consistency criteria : ', &
184  '(file-internal)/internal = ', fileio_datacheck_criteria
185 
186  if ( io_aggregate ) then
187  ! construct indices independent from PRC_PERIODIC_X/Y
188  xsb = 1 + ihalo
189  if( prc_2drank(prc_myrank,1) == 0 ) xsb = 1
190  xeb = imax + ihalo
191  if( prc_2drank(prc_myrank,1) == prc_num_x-1 ) xeb = ia
192 
193  ysb = 1 + jhalo
194  if( prc_2drank(prc_myrank,2) == 0 ) ysb = 1
195  yeb = jmax + jhalo
196  if( prc_2drank(prc_myrank,2) == prc_num_y-1 ) yeb = ja
197  else
198  xsb = isb
199  xeb = ieb
200  ysb = jsb
201  yeb = jeb
202  end if
203 
204  allocate( axis_lon( ia, ja) )
205  allocate( axis_lonx(0:ia, ja) )
206  allocate( axis_lony( ia,0:ja) )
207  allocate( axis_lonxy(0:ia,0:ja) )
208  allocate( axis_lat( ia, ja) )
209  allocate( axis_latx(0:ia, ja) )
210  allocate( axis_laty( ia,0:ja) )
211  allocate( axis_latxy(0:ia,0:ja) )
212 
213  allocate( axis_hzxy( ka,ia,ja) )
214  allocate( axis_hwxy(0:ka,ia,ja) )
215 
217 
218  file_closed(:) = .true.
219 
220  return
221  end subroutine fileio_setup
222 
223  !-----------------------------------------------------------------------------
225  subroutine fileio_cleanup
226  implicit none
227  !---------------------------------------------------------------------------
228 
229  deallocate( axis_lon )
230  deallocate( axis_lonx )
231  deallocate( axis_lony )
232  deallocate( axis_lonxy )
233  deallocate( axis_lat )
234  deallocate( axis_latx )
235  deallocate( axis_laty )
236  deallocate( axis_latxy )
237  deallocate( axis_hzxy )
238  deallocate( axis_hwxy )
239 
241 
242  call closeall
243 
244  return
245  end subroutine fileio_cleanup
246 
247  !-----------------------------------------------------------------------------
249  subroutine fileio_set_coordinates( &
250  LON, &
251  LONX, &
252  LONY, &
253  LONXY, &
254  LAT, &
255  LATX, &
256  LATY, &
257  LATXY, &
258  CZ, &
259  FZ )
260  use scale_const, only: &
261  d2r => const_d2r
262  implicit none
263 
264  real(RP), intent(in) :: lon ( ia, ja)
265  real(RP), intent(in) :: lonx (0:ia, ja)
266  real(RP), intent(in) :: lony ( ia,0:ja)
267  real(RP), intent(in) :: lonxy(0:ia,0:ja)
268  real(RP), intent(in) :: lat ( ia, ja)
269  real(RP), intent(in) :: latx (0:ia, ja)
270  real(RP), intent(in) :: laty ( ia,0:ja)
271  real(RP), intent(in) :: latxy(0:ia,0:ja)
272  real(RP), intent(in) :: cz ( ka,ia,ja)
273  real(RP), intent(in) :: fz (0:ka,ia,ja)
274  !---------------------------------------------------------------------------
275 
276  axis_lon(:,:) = lon(:,:) / d2r
277  axis_lonx(:,:) = lonx(:,:) / d2r
278  axis_lony(:,:) = lony(:,:) / d2r
279  axis_lonxy(:,:) = lonxy(:,:) / d2r
280  axis_lat(:,:) = lat(:,:) / d2r
281  axis_latx(:,:) = latx(:,:) / d2r
282  axis_laty(:,:) = laty(:,:) / d2r
283  axis_latxy(:,:) = latxy(:,:) / d2r
284 
285  axis_hzxy(:,:,:) = cz(:,:,:)
286  axis_hwxy(:,:,:) = fz(:,:,:)
287 
288  set_coordinates = .true.
289 
290  return
291  end subroutine fileio_set_coordinates
292 
293  !-----------------------------------------------------------------------------
295  subroutine fileio_check_coordinates_name( &
296  basename, &
297  atmos, &
298  land, &
299  urban, &
300  transpose )
301  implicit none
302 
303  character(len=*), intent(in) :: basename
304  logical, intent(in), optional :: atmos
305  logical, intent(in), optional :: land
306  logical, intent(in), optional :: urban
307  logical, intent(in), optional :: transpose
308 
309  logical :: atmos_
310  logical :: land_
311  logical :: urban_
312  logical :: transpose_
313 
314  integer :: fid
315  !---------------------------------------------------------------------------
316 
317  atmos_ = .false.
318  land_ = .false.
319  urban_ = .false.
320  transpose_ = .false.
321 
322  if( present(atmos) ) atmos_ = atmos
323  if( present(land ) ) land_ = land
324  if( present(urban) ) urban_ = urban
325  if( present(transpose) ) transpose_ = transpose
326 
327  call fileio_open( fid, & ! [OUT]
328  basename ) ! [IN]
329 
330  call fileio_check_coordinates_id( fid, & ! [IN]
331  atmos_, land_, urban_, & ! [IN]
332  transpose_ )
333 
334  return
335  end subroutine fileio_check_coordinates_name
336 
337  !-----------------------------------------------------------------------------
339  subroutine fileio_check_coordinates_id( &
340  fid, &
341  atmos, &
342  land, &
343  urban, &
344  transpose )
345  use scale_grid, only: &
346  grid_cz, &
347  grid_cx, &
348  grid_cy
349  use scale_land_grid, only: &
350  grid_lcz
351  use scale_urban_grid, only: &
352  grid_ucz
353  implicit none
354 
355  integer, intent(in) :: fid
356  logical, intent(in), optional :: atmos
357  logical, intent(in), optional :: land
358  logical, intent(in), optional :: urban
359  logical, intent(in), optional :: transpose
360 
361  logical :: atmos_
362  logical :: land_
363  logical :: urban_
364  logical :: transpose_
365 
366  real(RP) :: buffer_z (KA)
367  real(RP) :: buffer_x (IA)
368  real(RP) :: buffer_y (JA)
369  real(RP) :: buffer_xy (IA,JA)
370  real(RP) :: buffer_zxy(KA,IA,JA)
371  real(RP) :: buffer_l (LKMAX)
372  real(RP) :: buffer_u (UKMAX)
373  !---------------------------------------------------------------------------
374 
375  if( io_l ) write(io_fid_log,*)
376  if( io_l ) write(io_fid_log,*) '*** Check consistency of axis ***'
377 
378  atmos_ = .false.
379  land_ = .false.
380  urban_ = .false.
381  transpose_ = .false.
382 
383  if( present(atmos) ) atmos_ = atmos
384  if( present(land ) ) land_ = land
385  if( present(urban) ) urban_ = urban
386  if( present(transpose) ) transpose_ = transpose
387 
388  call fileio_read_var_1d( buffer_x, fid, 'x', 'X', 1 )
389  call fileio_read_var_1d( buffer_y, fid, 'y', 'Y', 1 )
390  call fileio_flush( fid )
391  call check_1d( grid_cx(isb:ieb), buffer_x(isb:ieb), 'x' )
392  call check_1d( grid_cy(jsb:jeb), buffer_y(jsb:jeb), 'y' )
393 
394  if ( set_coordinates ) then
395  call fileio_read_var_2d( buffer_xy, fid, 'lon', 'XY', 1 )
396  call fileio_flush( fid )
397  call check_2d( axis_lon(xsb:xeb,ysb:yeb), buffer_xy(xsb:xeb,ysb:yeb), 'lon' )
398 
399  call fileio_read_var_2d( buffer_xy, fid, 'lat', 'XY', 1 )
400  call fileio_flush( fid )
401  call check_2d( axis_lat(xsb:xeb,ysb:yeb), buffer_xy(xsb:xeb,ysb:yeb), 'lat' )
402  end if
403 
404  if ( atmos_ ) then
405  call fileio_read_var_1d( buffer_z, fid, 'z', 'Z', 1 )
406  if ( .not. transpose_ ) then
407  call fileio_read_var_3d( buffer_zxy, fid, 'height', 'ZXY', 1 )
408  end if
409  call fileio_flush( fid )
410  call check_1d( grid_cz(ks:ke), buffer_z(ks:ke), 'z' )
411  if ( .not. transpose_ ) then
412  call check_3d( axis_hzxy(ks:ke,xsb:xeb,ysb:yeb), buffer_zxy(ks:ke,xsb:xeb,ysb:yeb), 'height', transpose_ )
413  end if
414  end if
415 
416  if ( land_ ) then
417  call fileio_read_var_1d( buffer_l, fid, 'lz', 'LZ', 1 )
418  call fileio_flush( fid )
419  call check_1d( grid_lcz(lks:lke), buffer_l(lks:lke), 'lz' )
420  end if
421 
422  if ( urban_ ) then
423  call fileio_read_var_1d( buffer_u, fid, 'uz', 'UZ', 1 )
424  call fileio_flush( fid )
425  call check_1d( grid_ucz(uks:uke), buffer_u(uks:uke), 'uz' )
426  end if
427 
428  return
429  end subroutine fileio_check_coordinates_id
430 
431  !-----------------------------------------------------------------------------
433  subroutine construct_derived_datatype
434  use mpi
435  use scale_process, only: &
437  use scale_rm_process, only: &
438  prc_num_x, &
439  prc_num_y
440  implicit none
441 
442  integer :: err, order
443  integer :: sizes(3), subsizes(3), sub_off(3)
444  !---------------------------------------------------------------------------
445 
446  order = mpi_order_fortran
447 
448  centertypexy = mpi_datatype_null
449  centertypezx = mpi_datatype_null
450  centertypezxy = mpi_datatype_null
451  centertypeland = mpi_datatype_null
452  centertypeurban = mpi_datatype_null
453 
454  etype = mpi_float
455 
456  if( rp == 8 ) etype = mpi_double_precision
457 
458  ! for axistype == 'XY'
459  startxy(1) = is_ing - ihalo
460  startxy(2) = js_ing - jhalo
461  countxy(1) = ia
462  countxy(2) = ja
463  ! for axistype == 'ZXY'
464  startzxy(1) = 1
465  startzxy(2:3) = startxy(1:2)
466  countzxy(1) = kmax
467  countzxy(2:3) = countxy(1:2)
468  ! construct MPI subarray data type
469  sizes(1) = ka
470  sizes(2) = ia
471  sizes(3) = ja
472  subsizes(1) = kmax
473  subsizes(2) = ia
474  subsizes(3) = ja
475  sub_off(1) = ks - 1 ! MPI start index starts with 0
476  sub_off(2) = 0
477  sub_off(3) = 0
478 
479  call mpi_type_create_subarray(3, sizes, subsizes, sub_off, order, etype, centertypezxy, err)
480  call mpi_type_commit(centertypezxy, err)
481 
482  ! for axistype == 'Land'
483  startland(1) = 1
484  startland(2:3) = startxy(1:2)
485  countland(1) = lkmax
486  countland(2:3) = countxy(1:2)
487  ! construct MPI subarray data type
488  sizes(1) = lkmax
489  subsizes(1) = lkmax
490  sub_off(1) = lks - 1 ! MPI start index starts with 0
491 
492  call mpi_type_create_subarray(3, sizes, subsizes, sub_off, order, etype, centertypeland, err)
493  call mpi_type_commit(centertypeland, err)
494 
495  ! for axistype == 'URBAN'
496  starturban(1) = 1
497  starturban(2:3) = startxy(1:2)
498  counturban(1) = ukmax
499  counturban(2:3) = countxy(1:2)
500  ! construct MPI subarray data type
501  sizes(1) = ukmax
502  subsizes(1) = ukmax
503  sub_off(1) = uks - 1 ! MPI start index starts with 0
504 
505  call mpi_type_create_subarray(3, sizes, subsizes, sub_off, order, etype, centertypeurban, err)
506  call mpi_type_commit(centertypeurban, err)
507 
508  ! for axistype == 'ZX'
509  startzx(1) = khalo+1
510  startzx(2) = is_ing - ihalo
511  countzx(1) = khalo
512  countzx(2) = ia
513  ! construct MPI subarray data type
514  sizes(1) = ka
515  sizes(2) = ia
516  subsizes(1) = kmax
517  subsizes(2) = imaxb
518  sub_off(1) = khalo ! MPI start index starts with 0
519  sub_off(2) = isb - 1 ! MPI start index starts with 0
520 
521  call mpi_type_create_subarray(2, sizes, subsizes, sub_off, order, etype, centertypezx, err)
522  call mpi_type_commit(centertypezx, err)
523 
524  return
525  end subroutine construct_derived_datatype
526 
527  !-----------------------------------------------------------------------------
529  subroutine free_derived_datatype
530  use mpi
531  implicit none
532 
533  integer :: err
534  !---------------------------------------------------------------------------
535 
536  if( .NOT. io_aggregate ) return
537 
538  if( centertypexy /= mpi_datatype_null ) call mpi_type_free(centertypexy, err)
539  if( centertypezx /= mpi_datatype_null ) call mpi_type_free(centertypezx, err)
540  if( centertypezxy /= mpi_datatype_null ) call mpi_type_free(centertypezxy, err)
541  if( centertypeland /= mpi_datatype_null ) call mpi_type_free(centertypeland, err)
542  if( centertypeurban /= mpi_datatype_null ) call mpi_type_free(centertypeurban, err)
543 
544  return
545  end subroutine free_derived_datatype
546 
547  !-----------------------------------------------------------------------------
549  subroutine fileio_read_1d( &
550  var, &
551  basename, &
552  varname, &
553  axistype, &
554  step )
555  use gtool_file, only: &
556  fileread
557  use scale_process, only: &
559  implicit none
560 
561  real(RP), intent(out) :: var(:)
562  character(len=*), intent(in) :: basename
563  character(len=*), intent(in) :: varname
564  character(len=*), intent(in) :: axistype
565  integer, intent(in) :: step
566 
567  integer :: fid
568  !---------------------------------------------------------------------------
569 
570  call fileio_open( fid, & ! [OUT]
571  basename ) ! [IN]
572 
573  call fileio_read_var_1d( var(:), & ! [OUT]
574  fid, varname, axistype, step ) ! [IN]
575 
576  call fileio_close( fid )
577 
578  return
579  end subroutine fileio_read_1d
580 
581  !-----------------------------------------------------------------------------
583  subroutine fileio_read_2d( &
584  var, &
585  basename, &
586  varname, &
587  axistype, &
588  step )
589  use gtool_file, only: &
590  fileread
591  use scale_process, only: &
593  implicit none
594 
595  real(RP), intent(out) :: var(:,:)
596  character(len=*), intent(in) :: basename
597  character(len=*), intent(in) :: varname
598  character(len=*), intent(in) :: axistype
599  integer, intent(in) :: step
600 
601  integer :: fid
602  !---------------------------------------------------------------------------
603 
604  call fileio_open( fid, & ! [OUT]
605  basename ) ! [IN]
606 
607  call fileio_read_var_2d( var(:,:), & ! [OUT]
608  fid, varname, axistype, step ) ! [IN]
609 
610  call fileio_close( fid )
611 
612  return
613  end subroutine fileio_read_2d
614 
615  !-----------------------------------------------------------------------------
617  subroutine fileio_read_3d( &
618  var, &
619  basename, &
620  varname, &
621  axistype, &
622  step )
623  use gtool_file, only: &
624  fileread
625  use scale_process, only: &
627  implicit none
628 
629  real(RP), intent(out) :: var(:,:,:)
630  character(len=*), intent(in) :: basename
631  character(len=*), intent(in) :: varname
632  character(len=*), intent(in) :: axistype
633  integer, intent(in) :: step
634 
635  integer :: fid
636  !---------------------------------------------------------------------------
637 
638  call fileio_open( fid, & ! [OUT]
639  basename ) ! [IN]
640 
641  call fileio_read_var_3d( var(:,:,:), & ! [OUT]
642  fid, varname, axistype, step ) ! [IN]
643 
644  call fileio_close( fid )
645 
646  return
647  end subroutine fileio_read_3d
648 
649  !-----------------------------------------------------------------------------
651  subroutine fileio_read_4d( &
652  var, &
653  basename, &
654  varname, &
655  axistype, &
656  step )
657  use gtool_file, only: &
658  fileread
659  use scale_process, only: &
661  implicit none
662 
663  real(RP), intent(out) :: var(:,:,:,:)
664  character(len=*), intent(in) :: basename
665  character(len=*), intent(in) :: varname
666  character(len=*), intent(in) :: axistype
667  integer, intent(in) :: step
668 
669  integer :: fid
670  !---------------------------------------------------------------------------
671 
672  call fileio_open( fid, & ! [OUT]
673  basename ) ! [IN]
674 
675  call fileio_read_var_4d( var(:,:,:,:), & ! [OUT]
676  fid, varname, axistype, step ) ! [IN]
677 
678  call fileio_close( fid )
679 
680  return
681  end subroutine fileio_read_4d
682 
683  !-----------------------------------------------------------------------------
685  subroutine fileio_read_var_1d( &
686  var, &
687  fid, &
688  varname, &
689  axistype, &
690  step )
691  use gtool_file, only: &
692  fileread
693  use scale_process, only: &
695  use scale_rm_process, only: &
696  prc_num_x, &
697  prc_num_y
698  use mpi
699  implicit none
700 
701  real(RP), intent(out) :: var(:)
702  integer, intent(in) :: fid
703  character(len=*), intent(in) :: varname
704  character(len=*), intent(in) :: axistype
705  integer, intent(in) :: step
706 
707  integer :: dim1_S, dim1_E
708  integer :: start(1) ! start offset of globale variable
709  integer :: count(1) ! request length to the global variable
710  !---------------------------------------------------------------------------
711 
712  call prof_rapstart('FILE_I_NetCDF', 2)
713 
714  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Read from file (1D), name : ', trim(varname)
715 
716  if ( io_aggregate ) then
717  ! read data and halos into the local buffer
718  if ( axistype == 'Z' ) then
719  start(1) = 1
720  count(1) = kmax
721  call fileread( var(ks:ke), fid, varname, step, &
722  ntypes=kmax, dtype=etype, start=start, count=count )
723  elseif( axistype == 'LZ' ) then
724  start(1) = 1
725  count(1) = lkmax
726  call fileread( var, fid, varname, step, &
727  ntypes=lkmax, dtype=etype, start=start, count=count )
728  elseif( axistype == 'UZ' ) then
729  start(1) = 1
730  count(1) = ukmax
731  call fileread( var, fid, varname, step, &
732  ntypes=ukmax, dtype=etype, start=start, count=count )
733  elseif( axistype == 'X' .OR. axistype == 'CX' ) then
734  start(1) = is_ing - ihalo
735  count(1) = ia
736  call fileread( var, fid, varname, step, &
737  ntypes=ia, dtype=etype, start=start, count=count )
738  elseif( axistype == 'Y' .OR. axistype == 'CY' ) then
739  start(1) = js_ing - jhalo
740  count(1) = ja
741  call fileread( var, fid, varname, step, &
742  ntypes=ja, dtype=etype, start=start, count=count )
743  else
744  write(*,*) 'xxx [FILEIO_read_var_1D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
745  call prc_mpistop
746  endif
747  else
748  if ( axistype == 'Z' ) then
749  dim1_s = ks
750  dim1_e = ke
751  elseif( axistype == 'LZ' ) then
752  dim1_s = 1
753  dim1_e = lkmax
754  elseif( axistype == 'UZ' ) then
755  dim1_s = 1
756  dim1_e = ukmax
757  elseif( axistype == 'X' ) then
758  dim1_s = isb
759  dim1_e = ieb
760  elseif( axistype == 'CX' ) then
761  dim1_s = 1
762  dim1_e = ia
763  elseif( axistype == 'Y' ) then
764  dim1_s = jsb
765  dim1_e = jeb
766  elseif( axistype == 'CY' ) then
767  dim1_s = 1
768  dim1_e = ja
769  else
770  write(*,*) 'xxx [FILEIO_read_var_1D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
771  call prc_mpistop
772  endif
773 
774  call fileread( var(dim1_s:dim1_e), fid, varname, step )
775  end if
776 
777  call prof_rapend ('FILE_I_NetCDF', 2)
778 
779  return
780  end subroutine fileio_read_var_1d
781 
782  !-----------------------------------------------------------------------------
784  subroutine fileio_read_var_2d( &
785  var, &
786  fid, &
787  varname, &
788  axistype, &
789  step )
790  use gtool_file, only: &
791  fileread
792  use scale_process, only: &
794  use scale_rm_process, only: &
795  prc_num_x, &
796  prc_num_y
797  use mpi
798  implicit none
799 
800  real(RP), intent(out) :: var(:,:)
801  integer, intent(in) :: fid
802  character(len=*), intent(in) :: varname
803  character(len=*), intent(in) :: axistype
804  integer, intent(in) :: step
805 
806  integer :: dim1_S, dim1_E
807  integer :: dim2_S, dim2_E
808  !---------------------------------------------------------------------------
809 
810  call prof_rapstart('FILE_I_NetCDF', 2)
811 
812  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Read from file (2D), name : ', trim(varname)
813 
814  if ( io_aggregate ) then
815  ! read data and halos into the local buffer
816  if ( axistype == 'XY' ) then
817  call fileread( var, fid, varname, step, &
818  ntypes=ia*ja, dtype=etype, start=startxy, count=countxy )
819  elseif( axistype == 'ZX' ) then
820  ! Because KHALO is not saved in files, we use centerTypeZX, an MPI
821  ! derived datatype to describe the layout of local read buffer
822  call fileread( var, fid, varname, step, &
823  ntypes=1, dtype=centertypezx, start=startzx, count=countzx )
824  else
825  write(*,*) 'xxx [FILEIO_read_var_2D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
826  call prc_mpistop
827  endif
828  else
829  if ( axistype == 'XY' ) then
830  dim1_s = isb
831  dim1_e = ieb
832  dim2_s = jsb
833  dim2_e = jeb
834  elseif( axistype == 'ZX' ) then
835  dim1_s = ks
836  dim1_e = ke
837  dim2_s = isb
838  dim2_e = ieb
839  else
840  write(*,*) 'xxx [FILEIO_read_var_2D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
841  call prc_mpistop
842  endif
843 
844  call fileread( var(dim1_s:dim1_e,dim2_s:dim2_e), fid, varname, step )
845  end if
846 
847  call prof_rapend ('FILE_I_NetCDF', 2)
848 
849  return
850  end subroutine fileio_read_var_2d
851 
852  !-----------------------------------------------------------------------------
854  subroutine fileio_read_var_3d( &
855  var, &
856  fid, &
857  varname, &
858  axistype, &
859  step )
860  use gtool_file, only: &
861  fileread
862  use scale_process, only: &
864  use scale_rm_process, only: &
865  prc_num_x, &
866  prc_num_y
867  implicit none
868 
869  real(RP), intent(out) :: var(:,:,:)
870  integer, intent(in) :: fid
871  character(len=*), intent(in) :: varname
872  character(len=*), intent(in) :: axistype
873  integer, intent(in) :: step
874 
875  integer :: dim1_S, dim1_E
876  integer :: dim2_S, dim2_E
877  integer :: dim3_S, dim3_E
878  !---------------------------------------------------------------------------
879 
880  call prof_rapstart('FILE_I_NetCDF', 2)
881 
882  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Read from file (3D), name : ', trim(varname)
883 
884  if ( io_aggregate ) then
885  ! read data and halos into the local buffer
886  ! Because KHALO is not saved in files, we use mpi derived datatypes to
887  ! describe the layout of local read buffer
888  if ( axistype == 'ZXY' ) then
889  call fileread( var, fid, varname, step, &
890  ntypes=1, dtype=centertypezxy, start=startzxy, count=countzxy )
891  elseif( axistype == 'XYT' ) then
892  startxy(3) = 1
893  countxy(3) = step
894  call fileread( var, fid, varname, step, &
895  ntypes=step*ia*ja, dtype=etype, start=startxy, count=countxy )
896  elseif( axistype == 'Land' ) then
897  call fileread( var, fid, varname, step, &
898  ntypes=1, dtype=centertypeland, start=startland, count=countland )
899  elseif( axistype == 'Urban' ) then
900  call fileread( var, fid, varname, step, &
901  ntypes=1, dtype=centertypeurban, start=starturban, count=counturban )
902  else
903  write(*,*) 'xxx [FILEIO_read_var_3D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
904  call prc_mpistop
905  endif
906  else
907  if ( axistype == 'ZXY' ) then
908  dim1_s = ks
909  dim1_e = ke
910  dim2_s = isb
911  dim2_e = ieb
912  dim3_s = jsb
913  dim3_e = jeb
914  elseif( axistype == 'XYT' ) then
915  dim1_s = isb
916  dim1_e = ieb
917  dim2_s = jsb
918  dim2_e = jeb
919  dim3_s = 1
920  dim3_e = step
921  elseif( axistype == 'Land' ) then
922  dim1_s = lks
923  dim1_e = lke
924  dim2_s = isb
925  dim2_e = ieb
926  dim3_s = jsb
927  dim3_e = jeb
928  elseif( axistype == 'Urban' ) then
929  dim1_s = uks
930  dim1_e = uke
931  dim2_s = isb
932  dim2_e = ieb
933  dim3_s = jsb
934  dim3_e = jeb
935  else
936  write(*,*) 'xxx [FILEIO_read_var_3D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
937  call prc_mpistop
938  endif
939 
940  call fileread( var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
941  fid, varname, step )
942  end if
943 
944  call prof_rapend ('FILE_I_NetCDF', 2)
945 
946  return
947  end subroutine fileio_read_var_3d
948 
949  !-----------------------------------------------------------------------------
951  subroutine fileio_read_var_4d( &
952  var, &
953  fid, &
954  varname, &
955  axistype, &
956  step )
957  use gtool_file, only: &
958  fileread
959  use scale_process, only: &
961  use scale_rm_process, only: &
962  prc_num_x, &
963  prc_num_y
964  implicit none
965 
966  real(RP), intent(out) :: var(:,:,:,:)
967  integer, intent(in) :: fid
968  character(len=*), intent(in) :: varname
969  character(len=*), intent(in) :: axistype
970  integer, intent(in) :: step
971 
972  integer :: dim1_S, dim1_E
973  integer :: dim2_S, dim2_E
974  integer :: dim3_S, dim3_E
975  integer :: dim4_S, dim4_E
976  !---------------------------------------------------------------------------
977 
978  call prof_rapstart('FILE_I_NetCDF', 2)
979 
980  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Read from file (4D), name : ', trim(varname)
981 
982  if ( io_aggregate ) then
983  ! read data and halos into the local buffer
984  if ( axistype == 'ZXYT' ) then
985  startzxy(4) = 1
986  countzxy(4) = step
987  call fileread( var, fid, varname, step, &
988  ntypes=step, dtype=centertypezxy, start=startzxy, count=countzxy )
989  else
990  write(*,*) 'xxx [FILEIO_read_var_4D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
991  call prc_mpistop
992  endif
993  else
994  if ( axistype == 'ZXYT' ) then
995  dim1_s = ks
996  dim1_e = ke
997  dim2_s = isb
998  dim2_e = ieb
999  dim3_s = jsb
1000  dim3_e = jeb
1001  dim4_s = 1
1002  dim4_e = step
1003  else
1004  write(*,*) 'xxx [FILEIO_read_var_4D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
1005  call prc_mpistop
1006  endif
1007 
1008  call fileread( var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e,dim4_s:dim4_e), &
1009  fid, varname, step )
1010  end if
1011 
1012  call prof_rapend ('FILE_I_NetCDF', 2)
1013 
1014  return
1015  end subroutine fileio_read_var_4d
1016 
1017  !-----------------------------------------------------------------------------
1019  subroutine fileio_write_1d( &
1020  var, &
1021  basename, &
1022  title, &
1023  varname, &
1024  desc, &
1025  unit, &
1026  axistype, &
1027  datatype, &
1028  date, &
1029  subsec, &
1030  append )
1031  use gtool_file, only: &
1032  filecreate, &
1033  fileaddvariable, &
1034  filesetglobalattribute, &
1035  filewrite
1036  use scale_process, only: &
1037  prc_mpistop
1038  implicit none
1039 
1040  real(RP), intent(in) :: var(:)
1041  character(len=*), intent(in) :: basename
1042  character(len=*), intent(in) :: title
1043  character(len=*), intent(in) :: varname
1044  character(len=*), intent(in) :: desc
1045  character(len=*), intent(in) :: unit
1046  character(len=*), intent(in) :: axistype
1047  character(len=*), intent(in) :: datatype
1048 
1049  integer, intent(in), optional :: date(6)
1050  real(DP), intent(in), optional :: subsec
1051  logical, intent(in), optional :: append
1052 
1053  integer :: fid, vid
1054  !---------------------------------------------------------------------------
1055 
1056  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Write to file (1D), name : ', trim(varname)
1057 
1058  call fileio_create( fid, & ! [OUT]
1059  basename, title, datatype, date, subsec, append )
1060 
1061  call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype )
1062 
1063  call fileio_enddef( fid )
1064 
1065  call fileio_write_var_1d( fid, vid, var, varname, axistype )
1066 
1067  return
1068  end subroutine fileio_write_1d
1069 
1070  !-----------------------------------------------------------------------------
1072  subroutine fileio_write_2d( &
1073  var, &
1074  basename, &
1075  title, &
1076  varname, &
1077  desc, &
1078  unit, &
1079  axistype, &
1080  datatype, &
1081  date, &
1082  subsec, &
1083  append, &
1084  nohalo, &
1085  nozcoord )
1086  use gtool_file, only: &
1087  filecreate, &
1088  fileaddvariable, &
1089  filesetglobalattribute, &
1090  filewrite
1091  use scale_process, only: &
1092  prc_mpistop
1093  implicit none
1094 
1095  real(RP), intent(in) :: var(:,:)
1096  character(len=*), intent(in) :: basename
1097  character(len=*), intent(in) :: title
1098  character(len=*), intent(in) :: varname
1099  character(len=*), intent(in) :: desc
1100  character(len=*), intent(in) :: unit
1101  character(len=*), intent(in) :: axistype
1102  character(len=*), intent(in) :: datatype
1103 
1104  integer, intent(in), optional :: date(6)
1105  real(DP), intent(in), optional :: subsec
1106  logical, intent(in), optional :: append
1107  logical, intent(in), optional :: nohalo
1108  logical, intent(in), optional :: nozcoord
1109 
1110  integer :: fid, vid
1111  !---------------------------------------------------------------------------
1112 
1113  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Write to file (2D), name : ', trim(varname)
1114 
1115  call fileio_create( fid, & ! [OUT]
1116  basename, title, datatype, date, subsec, append, nozcoord )
1117 
1118  call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype )
1119 
1120  call fileio_enddef( fid )
1121 
1122  call fileio_write_var_2d( fid, vid, var, varname, axistype, nohalo )
1123 
1124  return
1125  end subroutine fileio_write_2d
1126 
1127  !-----------------------------------------------------------------------------
1129  subroutine fileio_write_3d( &
1130  var, &
1131  basename, &
1132  title, &
1133  varname, &
1134  desc, &
1135  unit, &
1136  axistype, &
1137  datatype, &
1138  date, &
1139  subsec, &
1140  append, &
1141  nohalo )
1142  use gtool_file, only: &
1143  rmiss
1144  use gtool_file, only: &
1145  filecreate, &
1146  fileaddvariable, &
1147  filesetglobalattribute, &
1148  filewrite
1149  use scale_process, only: &
1150  prc_masterrank, &
1151  prc_mpistop
1152  implicit none
1153 
1154  real(RP), intent(in) :: var(:,:,:)
1155  character(len=*), intent(in) :: basename
1156  character(len=*), intent(in) :: title
1157  character(len=*), intent(in) :: varname
1158  character(len=*), intent(in) :: desc
1159  character(len=*), intent(in) :: unit
1160  character(len=*), intent(in) :: axistype
1161  character(len=*), intent(in) :: datatype
1162 
1163  integer, intent(in), optional :: date(6)
1164  real(DP), intent(in), optional :: subsec
1165  logical, intent(in), optional :: append
1166  logical, intent(in), optional :: nohalo
1167 
1168  integer :: fid, vid
1169  !---------------------------------------------------------------------------
1170 
1171  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Write to file (3D), name : ', trim(varname)
1172 
1173  call fileio_create( fid, & ! [OUT]
1174  basename, title, datatype, date, subsec, append )
1175 
1176  call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype )
1177 
1178  call fileio_enddef( fid )
1179 
1180  call fileio_write_var_3d( fid, vid, var, varname, axistype, nohalo )
1181 
1182  return
1183  end subroutine fileio_write_3d
1184 
1185  !-----------------------------------------------------------------------------
1187  subroutine fileio_write_3d_t( &
1188  var, &
1189  basename, &
1190  title, &
1191  varname, &
1192  desc, &
1193  unit, &
1194  axistype, &
1195  datatype, &
1196  timeintv, &
1197  tsince, &
1198  append, &
1199  timetarg, &
1200  nohalo )
1201  use gtool_file_h, only: &
1202  file_real8, &
1203  file_real4
1204  use gtool_file, only: &
1205  filecreate, &
1206  fileputaxis, &
1207  fileaddvariable, &
1208  filewrite
1209  use scale_process, only: &
1210  prc_masterrank, &
1211  prc_mpistop
1212  implicit none
1213 
1214  real(RP), intent(in) :: var(:,:,:)
1215  character(len=*), intent(in) :: basename
1216  character(len=*), intent(in) :: title
1217  character(len=*), intent(in) :: varname
1218  character(len=*), intent(in) :: desc
1219  character(len=*), intent(in) :: unit
1220  character(len=*), intent(in) :: axistype
1221  character(len=*), intent(in) :: datatype
1222  real(RP), intent(in) :: timeintv
1223  integer , intent(in) :: tsince(6)
1224 
1225  logical, intent(in), optional :: append
1226  integer, intent(in), optional :: timetarg
1227  logical, intent(in), optional :: nohalo
1228 
1229  integer :: fid, vid
1230  integer :: nsteps
1231 
1232  intrinsic :: size
1233  !---------------------------------------------------------------------------
1234 
1235  if( io_l ) write(io_fid_log,'(1x,3A)') '*** Write to file (3D), name : ', trim(varname), 'with time dimension'
1236 
1237  call fileio_create( fid, & ! [OUT]
1238  basename, title, datatype, tsince, append=append )
1239 
1240  if ( present(timetarg) ) then
1241  nsteps = 1
1242  else
1243  nsteps = size(var,3)
1244  end if
1245  call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps )
1246 
1247  call fileio_enddef( fid )
1248 
1249  call fileio_write_var_3d_t( fid, vid, var, varname, axistype, timeintv, timetarg, nohalo )
1250 
1251  return
1252  end subroutine fileio_write_3d_t
1253 
1254  !-----------------------------------------------------------------------------
1256  subroutine fileio_write_4d( &
1257  var, &
1258  basename, &
1259  title, &
1260  varname, &
1261  desc, &
1262  unit, &
1263  axistype, &
1264  datatype, &
1265  timeintv, &
1266  tsince, &
1267  append, &
1268  timetarg, &
1269  nohalo )
1270  use gtool_file, only: &
1271  rmiss
1272  use gtool_file, only: &
1273  filecreate, &
1274  fileputaxis, &
1275  fileaddvariable, &
1276  filewrite
1277  use scale_process, only: &
1278  prc_mpistop
1279  implicit none
1280 
1281  real(RP), intent(in) :: var(:,:,:,:)
1282  character(len=*), intent(in) :: basename
1283  character(len=*), intent(in) :: title
1284  character(len=*), intent(in) :: varname
1285  character(len=*), intent(in) :: desc
1286  character(len=*), intent(in) :: unit
1287  character(len=*), intent(in) :: axistype
1288  character(len=*), intent(in) :: datatype
1289  real(RP), intent(in) :: timeintv
1290  integer, intent(in) :: tsince(6)
1291 
1292  logical, intent(in), optional :: append
1293  integer, intent(in), optional :: timetarg
1294  logical, intent(in), optional :: nohalo
1295 
1296  integer :: fid, vid
1297  integer :: nsteps
1298 
1299  intrinsic :: size
1300  !---------------------------------------------------------------------------
1301 
1302  if( io_l ) write(io_fid_log,'(1x,2A)') '*** Write to file (4D), name : ', trim(varname)
1303 
1304  call fileio_create( fid, & ! [OUT]
1305  basename, title, datatype, tsince, append=append )
1306 
1307  if ( present(timetarg) ) then
1308  nsteps = 1
1309  else
1310  nsteps = size(var,3)
1311  end if
1312  call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps )
1313 
1314  call fileio_enddef( fid )
1315 
1316  call fileio_write_var_4d( fid, vid, var, varname, axistype, timeintv, timetarg, nohalo )
1317 
1318  return
1319  end subroutine fileio_write_4d
1320 
1321  !-----------------------------------------------------------------------------
1323  subroutine fileio_open( &
1324  fid, &
1325  basename )
1326  use gtool_file_h, only: &
1327  file_fread
1328  use gtool_file, only: &
1329  fileopen
1330  use scale_process, only: &
1331  prc_myrank, &
1333  use mpi, only : mpi_comm_null
1334  implicit none
1335 
1336  integer, intent(out) :: fid
1337  character(len=*), intent(in) :: basename
1338 
1339  integer :: comm
1340  !---------------------------------------------------------------------------
1341 
1342  call prof_rapstart('FILE_O_NetCDF', 2)
1343 
1344  if ( io_aggregate ) then ! user input parameter indicates to do PnetCDF I/O
1345  comm = prc_local_comm_world
1346  else
1347  comm = mpi_comm_null
1348  end if
1349 
1350  call fileopen( fid, & ! [OUT]
1351  basename, & ! [IN]
1352  file_fread, & ! [IN]
1353  comm = comm, & ! [IN]
1354  myrank = prc_myrank ) ! [IN]
1355 
1356  file_closed(fid) = .false.
1357 
1358  call prof_rapend ('FILE_O_NetCDF', 2)
1359 
1360  return
1361  end subroutine fileio_open
1362 
1363  !-----------------------------------------------------------------------------
1365  subroutine fileio_create( &
1366  fid, &
1367  basename, &
1368  title, &
1369  datatype, &
1370  date, &
1371  subsec, &
1372  append, &
1373  nozcoord )
1374  use mpi, only: &
1375  mpi_comm_null
1376  use gtool_file_h, only: &
1377  file_real8, &
1378  file_real4
1379  use gtool_file, only: &
1380  filecreate, &
1381  filesetglobalattribute
1382  use scale_process, only: &
1383  prc_masterrank, &
1384  prc_myrank, &
1385  prc_mpistop, &
1387  use scale_rm_process, only: &
1388  prc_2drank, &
1389  prc_periodic_x, &
1391  use scale_time, only: &
1392  nowdate => time_nowdate, &
1393  nowms => time_nowms
1394  implicit none
1395 
1396  integer, intent(out) :: fid
1397  character(len=*), intent(in) :: basename
1398  character(len=*), intent(in) :: title
1399  character(len=*), intent(in) :: datatype
1400 
1401  integer, intent(in), optional :: date(6)
1402  real(DP), intent(in), optional :: subsec
1403  logical, intent(in), optional :: append
1404  logical, intent(in), optional :: nozcoord
1405 
1406  integer :: rankidx(2)
1407  integer :: dtype
1408  logical :: append_sw
1409  character(len=34) :: tunits
1410  integer :: comm
1411  logical :: fileexisted
1412  character(len=H_SHORT) :: logical_str
1413  !---------------------------------------------------------------------------
1414 
1415  call prof_rapstart('FILE_O_NetCDF', 2)
1416 
1417  rankidx(1) = prc_2drank(prc_myrank,1)
1418  rankidx(2) = prc_2drank(prc_myrank,2)
1419 
1420  ! dtype is used to define the data type of axis variables in file
1421  if ( datatype == 'REAL8' ) then
1422  dtype = file_real8
1423  elseif( datatype == 'REAL4' ) then
1424  dtype = file_real4
1425  else
1426  if ( rp == 8 ) then
1427  dtype = file_real8
1428  elseif( rp == 4 ) then
1429  dtype = file_real4
1430  else
1431  write(*,*) 'xxx unsupported data type. Check!', trim(datatype)
1432  call prc_mpistop
1433  endif
1434  endif
1435 
1436  append_sw = .false.
1437  if ( present(append) ) then
1438  append_sw = append
1439  endif
1440 
1441  ! create a netCDF file if not already existed. Otherwise, open it.
1442  if ( present(date) ) then
1443  call getcftunits( tunits, date )
1444  else
1445  tunits = 'seconds'
1446  end if
1447 
1448  if ( io_aggregate ) then ! user input parameter indicates to do PnetCDF I/O
1449  comm = prc_local_comm_world
1450  else
1451  comm = mpi_comm_null
1452  end if
1453 
1454  call filecreate( fid, & ! [OUT]
1455  fileexisted, & ! [OUT]
1456  basename, & ! [IN]
1457  title, & ! [IN]
1458  h_source, & ! [IN]
1459  h_institute, & ! [IN]
1460  prc_masterrank, & ! [IN]
1461  prc_myrank, & ! [IN]
1462  rankidx, & ! [IN]
1463  time_units = tunits, & ! [IN]
1464  append = append_sw, & ! [IN]
1465  comm = comm ) ! [IN]
1466 
1467  if ( .NOT. fileexisted ) then ! do below only once when file is created
1468  call fileio_def_axes( fid, dtype, xy = nozcoord ) ! [IN]
1469  file_axes_written(fid) = .false. ! indicating axes have not been written yet
1470  if ( present( nozcoord ) ) then
1471  file_nozcoord(fid) = nozcoord
1472  else
1473  file_nozcoord(fid) = .false.
1474  endif
1475 
1476  if ( present( subsec ) ) then
1477  call filesetglobalattribute( fid, "time", (/subsec/) )
1478  else
1479  call filesetglobalattribute( fid, "time", (/nowms/) )
1480  end if
1481  if ( present( date ) ) then
1482  call getcftunits(tunits, date)
1483  else
1484  call getcftunits(tunits, nowdate)
1485  end if
1486  call filesetglobalattribute( fid, "time_units", tunits )
1487  call filesetglobalattribute( fid, "IHALO", (/ihalo/) )
1488  call filesetglobalattribute( fid, "JHALO", (/jhalo/) )
1489  logical_str = "false"
1490  if(prc_periodic_x .AND. .NOT. io_aggregate) logical_str = "true"
1491  call filesetglobalattribute( fid, "PRC_PERIODIC_X", trim(logical_str) )
1492  logical_str = "false"
1493  if(prc_periodic_y .AND. .NOT. io_aggregate) logical_str = "true"
1494  call filesetglobalattribute( fid, "PRC_PERIODIC_Y", trim(logical_str) )
1495 
1496  file_closed(fid) = .false.
1497  endif
1498 
1499  call prof_rapend ('FILE_O_NetCDF', 2)
1500 
1501  return
1502  end subroutine fileio_create
1503 
1504  !-----------------------------------------------------------------------------
1506  subroutine fileio_enddef( &
1507  fid )
1508  use gtool_file, only: &
1509  fileenddef, &
1510  fileflush, &
1512  implicit none
1513 
1514  integer, intent(in) :: fid
1515  !---------------------------------------------------------------------------
1516 
1517  call prof_rapstart('FILE_O_NetCDF', 2)
1518 
1519  call fileenddef( fid ) ! [IN]
1520 
1521  ! If this enddef is called the first time, write axis variables
1522  if ( .NOT. file_axes_written(fid) ) then
1523  call fileio_write_axes( fid, file_nozcoord(fid) )
1524  if ( io_aggregate ) then
1525  call fileflush( fid )
1526  ! Tell PnetCDF library to use a buffer of size write_buf_amount to
1527  ! aggregate write requests to be post in FILEIO_write_var
1528  call fileattachbuffer( fid, write_buf_amount )
1529  end if
1530  file_axes_written(fid) = .true.
1531  end if
1532 
1533  call prof_rapend ('FILE_O_NetCDF', 2)
1534 
1535  return
1536  end subroutine fileio_enddef
1537 
1538  !-----------------------------------------------------------------------------
1540  subroutine fileio_flush( &
1541  fid )
1542  use gtool_file, only: &
1543  fileflush
1544  implicit none
1545 
1546  integer, intent(in) :: fid
1547  !---------------------------------------------------------------------------
1548 
1549  call prof_rapstart('FILE_O_NetCDF', 2)
1550 
1551  if ( io_aggregate ) then
1552  call fileflush( fid ) ! flush all pending read/write requests
1553  end if
1554 
1555  call prof_rapend ('FILE_O_NetCDF', 2)
1556 
1557  return
1558  end subroutine fileio_flush
1559 
1560  !-----------------------------------------------------------------------------
1562  subroutine fileio_close( &
1563  fid )
1564  use gtool_file, only: &
1565  fileclose, &
1566  fileflush, &
1568  implicit none
1569 
1570  integer, intent(in) :: fid
1571 
1572  !---------------------------------------------------------------------------
1573 
1574  call prof_rapstart('FILE_O_NetCDF', 2)
1575 
1576  if ( .NOT. file_closed(fid) ) then
1577 
1578  if ( io_aggregate ) then
1579  call fileflush( fid ) ! flush all pending read/write requests
1580  if ( write_buf_amount > 0 ) then
1581  call filedetachbuffer( fid ) ! detach PnetCDF aggregation buffer
1582  write_buf_amount = 0 ! reset write request amount
1583  end if
1584  end if
1585 
1586  call fileclose( fid ) ! [IN]
1587 
1588  file_closed(fid) = .true.
1589 
1590  end if
1591 
1592  call prof_rapend ('FILE_O_NetCDF', 2)
1593 
1594  return
1595  end subroutine fileio_close
1596 
1597  !-----------------------------------------------------------------------------
1599  subroutine fileio_def_axes( &
1600  fid, &
1601  dtype, &
1602  xy )
1603  use gtool_file, only: &
1604  filedefaxis, &
1605  filesettattr, &
1607  use scale_rm_process, only: &
1608  prc_num_x, &
1609  prc_num_y
1610  implicit none
1611 
1612  integer, intent(in) :: fid
1613  integer, intent(in) :: dtype
1614  logical, intent(in), optional :: xy
1615 
1616  character(len=2) :: AXIS_name(3)
1617  logical :: xy_
1618  !---------------------------------------------------------------------------
1619 
1620  if ( present(xy) ) then
1621  xy_ = xy
1622  else
1623  xy_ = .false.
1624  end if
1625 
1626  if ( .NOT. xy_ ) then
1627  call filedefaxis( fid, 'z', 'Z', 'm', 'z', dtype, kmax )
1628  end if
1629  if ( .NOT. io_aggregate ) then
1630  call filedefaxis( fid, 'x', 'X', 'm', 'x', dtype, imaxb )
1631  call filedefaxis( fid, 'y', 'Y', 'm', 'y', dtype, jmaxb )
1632  else
1633  call filedefaxis( fid, 'x', 'X', 'm', 'x', dtype, iag )
1634  call filedefaxis( fid, 'y', 'Y', 'm', 'y', dtype, jag )
1635  end if
1636 
1637  if ( .NOT. xy_ ) then
1638  call filedefaxis( fid, 'zh', 'Z (half level)', 'm', 'zh', dtype, kmax )
1639  end if
1640  if ( .NOT. io_aggregate ) then
1641  call filedefaxis( fid, 'xh', 'X (half level)', 'm', 'xh', dtype, imaxb )
1642  call filedefaxis( fid, 'yh', 'Y (half level)', 'm', 'yh', dtype, jmaxb )
1643  else
1644  call filedefaxis( fid, 'xh', 'X (half level)', 'm', 'xh', dtype, iag )
1645  call filedefaxis( fid, 'yh', 'Y (half level)', 'm', 'yh', dtype, jag )
1646  end if
1647 
1648  if ( .NOT. xy_ ) then
1649  call filedefaxis( fid, 'lz', 'LZ', 'm', 'lz', dtype, lkmax )
1650  call filedefaxis( fid, 'lzh', 'LZ (half level)', 'm', 'lzh', dtype, lkmax )
1651  call filedefaxis( fid, 'uz', 'UZ', 'm', 'uz', dtype, ukmax )
1652  call filedefaxis( fid, 'uzh', 'UZ (half level)', 'm', 'uzh', dtype, ukmax )
1653  end if
1654 
1655  if ( .NOT. xy_ ) then
1656  call filedefaxis( fid, 'CZ', 'Atmos Grid Center Position Z', 'm', 'CZ', dtype, ka )
1657  end if
1658  if ( .NOT. io_aggregate ) then
1659  call filedefaxis( fid, 'CX', 'Atmos Grid Center Position X', 'm', 'CX', dtype, ia )
1660  call filedefaxis( fid, 'CY', 'Atmos Grid Center Position Y', 'm', 'CY', dtype, ja )
1661  else
1662  call filedefaxis( fid, 'CX', 'Atmos Grid Center Position X', 'm', 'CX', dtype, iag )
1663  call filedefaxis( fid, 'CY', 'Atmos Grid Center Position Y', 'm', 'CY', dtype, jag )
1664  end if
1665 
1666  if ( .NOT. xy_ ) then
1667  call filedefaxis( fid, 'FZ', 'Atmos Grid Face Position Z', 'm', 'FZ', dtype, ka+1 )
1668  end if
1669  if ( .NOT. io_aggregate ) then
1670  call filedefaxis( fid, 'FX', 'Atmos Grid Face Position X', 'm', 'FX', dtype, ia+1 )
1671  call filedefaxis( fid, 'FY', 'Atmos Grid Face Position Y', 'm', 'FY', dtype, ja+1 )
1672  else
1673  call filedefaxis( fid, 'FX', 'Atmos Grid Face Position X', 'm', 'FX', dtype, iag+1 )
1674  call filedefaxis( fid, 'FY', 'Atmos Grid Face Position Y', 'm', 'FY', dtype, jag+1 )
1675  end if
1676 
1677  if ( .NOT. xy_ ) then
1678  call filedefaxis( fid, 'CDZ', 'Grid Cell length Z', 'm', 'CZ', dtype, ka )
1679  end if
1680  if ( .NOT. io_aggregate ) then
1681  call filedefaxis( fid, 'CDX', 'Grid Cell length X', 'm', 'CX', dtype, ia )
1682  call filedefaxis( fid, 'CDY', 'Grid Cell length Y', 'm', 'CY', dtype, ja )
1683  else
1684  call filedefaxis( fid, 'CDX', 'Grid Cell length X', 'm', 'CX', dtype, iag )
1685  call filedefaxis( fid, 'CDY', 'Grid Cell length Y', 'm', 'CY', dtype, jag )
1686  end if
1687 
1688  if ( .NOT. xy_ ) then
1689  call filedefaxis( fid, 'FDZ', 'Grid distance Z', 'm', 'FDZ', dtype, ka-1 )
1690  end if
1691  if ( .NOT. io_aggregate ) then
1692  call filedefaxis( fid, 'FDX', 'Grid distance X', 'm', 'FDX', dtype, ia-1 )
1693  call filedefaxis( fid, 'FDY', 'Grid distance Y', 'm', 'FDY', dtype, ja-1 )
1694  else
1695  call filedefaxis( fid, 'FDX', 'Grid distance X', 'm', 'FDX', dtype, iag-1 )
1696  call filedefaxis( fid, 'FDY', 'Grid distance Y', 'm', 'FDY', dtype, jag-1 )
1697  end if
1698 
1699  if ( .NOT. xy_ ) then
1700  call filedefaxis( fid, 'LCZ', 'Land Grid Center Position Z', 'm', 'LCZ', dtype, lkmax )
1701  call filedefaxis( fid, 'LFZ', 'Land Grid Face Position Z', 'm', 'LFZ', dtype, lkmax+1 )
1702  call filedefaxis( fid, 'LCDZ', 'Land Grid Cell length Z', 'm', 'LCZ', dtype, lkmax )
1703 
1704  call filedefaxis( fid, 'UCZ', 'Urban Grid Center Position Z', 'm', 'UCZ', dtype, ukmax )
1705  call filedefaxis( fid, 'UFZ', 'Urban Grid Face Position Z', 'm', 'UFZ', dtype, ukmax+1 )
1706  call filedefaxis( fid, 'UCDZ', 'Urban Grid Cell length Z', 'm', 'UCZ', dtype, ukmax )
1707  end if
1708 
1709  if ( .NOT. xy_ ) then
1710  call filedefaxis( fid, 'CBFZ', 'Boundary factor Center Z', '1', 'CZ', dtype, ka )
1711  end if
1712  if ( .NOT. io_aggregate ) then
1713  call filedefaxis( fid, 'CBFX', 'Boundary factor Center X', '1', 'CX', dtype, ia )
1714  call filedefaxis( fid, 'CBFY', 'Boundary factor Center Y', '1', 'CY', dtype, ja )
1715  else
1716  call filedefaxis( fid, 'CBFX', 'Boundary factor Center X', '1', 'CX', dtype, iag )
1717  call filedefaxis( fid, 'CBFY', 'Boundary factor Center Y', '1', 'CY', dtype, jag )
1718  end if
1719 
1720  if ( .NOT. xy_ ) then
1721  call filedefaxis( fid, 'FBFZ', 'Boundary factor Face Z', '1', 'CZ', dtype, ka )
1722  end if
1723  if ( .NOT. io_aggregate ) then
1724  call filedefaxis( fid, 'FBFX', 'Boundary factor Face X', '1', 'CX', dtype, ia )
1725  call filedefaxis( fid, 'FBFY', 'Boundary factor Face Y', '1', 'CY', dtype, ja )
1726  else
1727  call filedefaxis( fid, 'FBFX', 'Boundary factor Face X', '1', 'CX', dtype, iag )
1728  call filedefaxis( fid, 'FBFY', 'Boundary factor Face Y', '1', 'CY', dtype, jag )
1729  end if
1730 
1731  ! TODO: skip 8 axes below when IO_AGGREGATE is true, as all axes are now global
1732  call filedefaxis( fid, 'CXG', 'Grid Center Position X (global)', 'm', 'CXG', dtype, iag )
1733  call filedefaxis( fid, 'CYG', 'Grid Center Position Y (global)', 'm', 'CYG', dtype, jag )
1734  call filedefaxis( fid, 'FXG', 'Grid Face Position X (global)', 'm', 'FXG', dtype, iag+1 )
1735  call filedefaxis( fid, 'FYG', 'Grid Face Position Y (global)', 'm', 'FYG', dtype, jag+1 )
1736 
1737  call filedefaxis( fid, 'CBFXG', 'Boundary factor Center X (global)', '1', 'CXG', dtype, iag )
1738  call filedefaxis( fid, 'CBFYG', 'Boundary factor Center Y (global)', '1', 'CYG', dtype, jag )
1739  call filedefaxis( fid, 'FBFXG', 'Boundary factor Face X (global)', '1', 'CXG', dtype, iag )
1740  call filedefaxis( fid, 'FBFYG', 'Boundary factor Face Y (global)', '1', 'CYG', dtype, jag )
1741 
1742  ! associate coordinates
1743  axis_name(1:2) = (/'x ','y '/)
1744  call filedefassociatedcoordinates( fid, 'lon' , 'longitude', &
1745  'degrees_east' , axis_name(1:2), dtype )
1746  axis_name(1:2) = (/'xh','y '/)
1747  call filedefassociatedcoordinates( fid, 'lon_uy', 'longitude (half level uy)', &
1748  'degrees_east' , axis_name(1:2), dtype )
1749  axis_name(1:2) = (/'x ','yh'/)
1750  call filedefassociatedcoordinates( fid, 'lon_xv', 'longitude (half level xv)', &
1751  'degrees_east' , axis_name(1:2), dtype )
1752  axis_name(1:2) = (/'xh','yh'/)
1753  call filedefassociatedcoordinates( fid, 'lon_uv', 'longitude (half level uv)', &
1754  'degrees_east' , axis_name(1:2), dtype )
1755  axis_name(1:2) = (/'x ','y '/)
1756  call filedefassociatedcoordinates( fid, 'lat' , 'latitude', &
1757  'degrees_north', axis_name(1:2), dtype )
1758  axis_name(1:2) = (/'xh','y '/)
1759  call filedefassociatedcoordinates( fid, 'lat_uy', 'latitude (half level uy)', &
1760  'degrees_north', axis_name(1:2), dtype )
1761  axis_name(1:2) = (/'x ','yh'/)
1762  call filedefassociatedcoordinates( fid, 'lat_xv', 'latitude (half level xv)', &
1763  'degrees_north', axis_name(1:2), dtype )
1764  axis_name(1:2) = (/'xh','yh'/)
1765  call filedefassociatedcoordinates( fid, 'lat_uv', 'latitude (half level uv)', &
1766  'degrees_north', axis_name(1:2), dtype )
1767 
1768  if ( .NOT. xy_ ) then
1769  axis_name = (/'z', 'x', 'y'/)
1770  call filedefassociatedcoordinates( fid, 'height', 'height above ground level', &
1771  'm', axis_name(1:3), dtype )
1772  axis_name = (/'zh', 'x ', 'y '/)
1773  call filedefassociatedcoordinates( fid, 'height_wxy', 'height above ground level (half level wxy)', &
1774  'm', axis_name(1:3), dtype )
1775  end if
1776 
1777  ! attributes
1778  if ( .NOT. xy_ ) then
1779  call filesettattr( fid, 'lz', 'positive', 'down' )
1780  call filesettattr( fid, 'lzh', 'positive', 'down' )
1781  call filesettattr( fid, 'uz', 'positive', 'down' )
1782  call filesettattr( fid, 'uzh', 'positive', 'down' )
1783  call filesettattr( fid, 'LCZ', 'positive', 'down' )
1784  call filesettattr( fid, 'LFZ', 'positive', 'down' )
1785  call filesettattr( fid, 'UCZ', 'positive', 'down' )
1786  call filesettattr( fid, 'UFZ', 'positive', 'down' )
1787  end if
1788 
1789  return
1790  end subroutine fileio_def_axes
1791 
1792  !-----------------------------------------------------------------------------
1794  subroutine fileio_write_axes( &
1795  fid, &
1796  xy )
1797  use gtool_file, only: &
1798  filewriteaxis, &
1799  filewriteassociatedcoordinates
1800  use scale_process, only: &
1801  prc_myrank
1802  use scale_rm_process, only: &
1803  prc_2drank, &
1804  prc_num_x, &
1805  prc_num_y
1806  use scale_grid, only: &
1807  grid_cz, &
1808  grid_cx, &
1809  grid_cy, &
1810  grid_fz, &
1811  grid_fx, &
1812  grid_fy, &
1813  grid_cdz, &
1814  grid_cdx, &
1815  grid_cdy, &
1816  grid_fdz, &
1817  grid_fdx, &
1818  grid_fdy, &
1819  grid_cbfz, &
1820  grid_cbfx, &
1821  grid_cbfy, &
1822  grid_fbfz, &
1823  grid_fbfx, &
1824  grid_fbfy, &
1825  grid_cxg, &
1826  grid_cyg, &
1827  grid_fxg, &
1828  grid_fyg, &
1829  grid_cdxg, &
1830  grid_cdyg, &
1831  grid_fdxg, &
1832  grid_fdyg, &
1833  grid_cbfxg, &
1834  grid_cbfyg, &
1835  grid_fbfxg, &
1836  grid_fbfyg
1837  use scale_land_grid, only: &
1838  grid_lcz, &
1839  grid_lfz, &
1840  grid_lcdz
1841  use scale_urban_grid, only: &
1842  grid_ucz, &
1843  grid_ufz, &
1844  grid_ucdz
1845  implicit none
1846 
1847  integer, intent(in) :: fid
1848  logical, intent(in), optional :: xy
1849 
1850  logical :: xy_
1851  logical :: put_x
1852  logical :: put_y
1853  logical :: put_z
1854 
1855  integer :: rankidx(2)
1856  integer :: start(3)
1857  !---------------------------------------------------------------------------
1858 
1859  if ( present(xy) ) then
1860  xy_ = xy
1861  else
1862  xy_ = .false.
1863  end if
1864 
1865  if ( io_aggregate ) then
1866  rankidx(1) = prc_2drank(prc_myrank,1)
1867  rankidx(2) = prc_2drank(prc_myrank,2)
1868 
1869  ! For parallel I/O, not all variables are written by all processes.
1870  ! 1. Let PRC_myrank 0 writes all z axes
1871  ! 2. Let processes (rankidx(2) == 0) write x axes (south-most processes)
1872  ! rankidx(1) == 0 writes west HALO
1873  ! rankidx(1) == PRC_NUM_X-1 writes east HALO
1874  ! others writes without HALO
1875  ! 3. Let processes (rankidx(1) == 0) write y axes (west-most processes)
1876  ! rankidx(1) == 0 writes south HALO
1877  ! rankidx(1) == PRC_NUM_Y-1 writes north HALO
1878  ! others writes without HALO
1879 
1880  put_z = ( .NOT. xy_ ) .AND. ( prc_myrank == 0 ) ! only master process output the vertical coordinates
1881  put_x = ( rankidx(2) == 0 ) ! only south most row processes write x coordinates
1882  put_y = ( rankidx(1) == 0 ) ! only west most column processes write y coordinates
1883  else
1884  put_z = ( .NOT. xy_ )
1885  put_x = .true.
1886  put_y = .true.
1887 
1888  start(:) = 1
1889  end if
1890 
1891  if ( put_z ) then
1892  if( io_aggregate ) start(1) = 1
1893  call filewriteaxis( fid, 'z', grid_cz(ks:ke), start )
1894  call filewriteaxis( fid, 'zh', grid_fz(ks:ke), start )
1895  call filewriteaxis( fid, 'lz', grid_lcz(lks:lke), start )
1896  call filewriteaxis( fid, 'lzh', grid_lfz(lks:lke), start )
1897  call filewriteaxis( fid, 'uz', grid_ucz(uks:uke), start )
1898  call filewriteaxis( fid, 'uzh', grid_ufz(uks:uke), start )
1899  end if
1900  if ( put_x ) then
1901  if( io_aggregate ) start(1) = isga
1902  call filewriteaxis( fid, 'x', grid_cx(xsb:xeb), start )
1903  call filewriteaxis( fid, 'xh', grid_fx(xsb:xeb), start )
1904  end if
1905  if ( put_y ) then
1906  if( io_aggregate ) start(1) = jsga
1907  call filewriteaxis( fid, 'y', grid_cy(ysb:yeb), start )
1908  call filewriteaxis( fid, 'yh', grid_fy(ysb:yeb), start )
1909  end if
1910 
1911  if ( put_z ) then
1912  if( io_aggregate ) start(1) = 1
1913  call filewriteaxis( fid, 'CZ', grid_cz, start )
1914  call filewriteaxis( fid, 'FZ', grid_fz, start )
1915  call filewriteaxis( fid, 'CDZ', grid_cdz, start )
1916  call filewriteaxis( fid, 'FDZ', grid_fdz, start )
1917 
1918  call filewriteaxis( fid, 'LCZ', grid_lcz, start )
1919  call filewriteaxis( fid, 'LFZ', grid_lfz, start )
1920  call filewriteaxis( fid, 'LCDZ', grid_lcdz, start )
1921 
1922  call filewriteaxis( fid, 'UCZ', grid_ucz, start )
1923  call filewriteaxis( fid, 'UFZ', grid_ufz, start )
1924  call filewriteaxis( fid, 'UCDZ', grid_ucdz, start )
1925 
1926  call filewriteaxis( fid, 'CBFZ', grid_cbfz, start )
1927  call filewriteaxis( fid, 'FBFZ', grid_fbfz, start )
1928  end if
1929 
1930  if ( io_aggregate ) then
1931  if ( prc_myrank == 0 ) then
1932  start(1) = 1
1933  call filewriteaxis( fid, 'CX', grid_cxg, start )
1934  call filewriteaxis( fid, 'CY', grid_cyg, start )
1935  call filewriteaxis( fid, 'FX', grid_fxg, start )
1936  call filewriteaxis( fid, 'FY', grid_fyg, start )
1937 
1938  call filewriteaxis( fid, 'CDX', grid_cdxg, start )
1939  call filewriteaxis( fid, 'CDY', grid_cdyg, start )
1940  call filewriteaxis( fid, 'FDX', grid_fdxg, start )
1941  call filewriteaxis( fid, 'FDY', grid_fdyg, start )
1942 
1943  call filewriteaxis( fid, 'CBFX', grid_cbfxg, start )
1944  call filewriteaxis( fid, 'CBFY', grid_cbfyg, start )
1945  call filewriteaxis( fid, 'FBFX', grid_fbfxg, start )
1946  call filewriteaxis( fid, 'FBFY', grid_fbfyg, start )
1947 
1948  call filewriteaxis( fid, 'CXG', grid_cxg, start )
1949  call filewriteaxis( fid, 'CYG', grid_cyg, start )
1950  call filewriteaxis( fid, 'FXG', grid_fxg, start )
1951  call filewriteaxis( fid, 'FYG', grid_fyg, start )
1952 
1953  call filewriteaxis( fid, 'CBFXG', grid_cbfxg, start )
1954  call filewriteaxis( fid, 'CBFYG', grid_cbfyg, start )
1955  call filewriteaxis( fid, 'FBFXG', grid_fbfxg, start )
1956  call filewriteaxis( fid, 'FBFYG', grid_fbfyg, start )
1957  end if
1958  else
1959  call filewriteaxis( fid, 'CX', grid_cx )
1960  call filewriteaxis( fid, 'CY', grid_cy )
1961  call filewriteaxis( fid, 'FX', grid_fx )
1962  call filewriteaxis( fid, 'FY', grid_fy )
1963 
1964  call filewriteaxis( fid, 'CDX', grid_cdx )
1965  call filewriteaxis( fid, 'CDY', grid_cdy )
1966  call filewriteaxis( fid, 'FDX', grid_fdx )
1967  call filewriteaxis( fid, 'FDY', grid_fdy )
1968 
1969  call filewriteaxis( fid, 'CBFX', grid_cbfx )
1970  call filewriteaxis( fid, 'CBFY', grid_cbfy )
1971  call filewriteaxis( fid, 'FBFX', grid_fbfx )
1972  call filewriteaxis( fid, 'FBFY', grid_fbfy )
1973 
1974  call filewriteaxis( fid, 'CXG', grid_cxg )
1975  call filewriteaxis( fid, 'CYG', grid_cyg )
1976  call filewriteaxis( fid, 'FXG', grid_fxg )
1977  call filewriteaxis( fid, 'FYG', grid_fyg )
1978 
1979  call filewriteaxis( fid, 'CBFXG', grid_cbfxg )
1980  call filewriteaxis( fid, 'CBFYG', grid_cbfyg )
1981  call filewriteaxis( fid, 'FBFXG', grid_fbfxg )
1982  call filewriteaxis( fid, 'FBFYG', grid_fbfyg )
1983  end if
1984 
1985  ! associate coordinates
1986 
1987  if ( io_aggregate ) then
1988  start(1) = isga
1989  start(2) = jsga
1990  end if
1991  call filewriteassociatedcoordinates( fid, 'lon' , axis_lon(xsb:xeb,ysb:yeb), start )
1992  call filewriteassociatedcoordinates( fid, 'lon_uy', axis_lonx(xsb:xeb,ysb:yeb), start )
1993  call filewriteassociatedcoordinates( fid, 'lon_xv', axis_lony(xsb:xeb,ysb:yeb), start )
1994  call filewriteassociatedcoordinates( fid, 'lon_uv', axis_lonxy(xsb:xeb,ysb:yeb), start )
1995  call filewriteassociatedcoordinates( fid, 'lat' , axis_lat(xsb:xeb,ysb:yeb), start )
1996  call filewriteassociatedcoordinates( fid, 'lat_uy', axis_latx(xsb:xeb,ysb:yeb), start )
1997  call filewriteassociatedcoordinates( fid, 'lat_xv', axis_laty(xsb:xeb,ysb:yeb), start )
1998  call filewriteassociatedcoordinates( fid, 'lat_uv', axis_latxy(xsb:xeb,ysb:yeb), start )
1999 
2000  if ( .NOT. xy_ ) then
2001  if ( io_aggregate ) then
2002  start(1) = 1
2003  start(2) = isga
2004  start(3) = jsga
2005  end if
2006  call filewriteassociatedcoordinates( fid, 'height', axis_hzxy(ks:ke,xsb:xeb,ysb:yeb), start )
2007  call filewriteassociatedcoordinates( fid, 'height_wxy', axis_hwxy(ks:ke,xsb:xeb,ysb:yeb), start )
2008  end if
2009 
2010  return
2011  end subroutine fileio_write_axes
2012 
2013  !-----------------------------------------------------------------------------
2015  subroutine fileio_def_var( &
2016  fid, &
2017  vid, &
2018  varname, &
2019  desc, &
2020  unit, &
2021  axistype, &
2022  datatype, &
2023  timeintv, &
2024  nsteps )
2025  use gtool_file_h, only: &
2026  file_real8, &
2027  file_real4
2028  use gtool_file, only: &
2030  use scale_process, only: &
2031  prc_mpistop
2032  implicit none
2033 
2034  integer, intent(in) :: fid
2035  integer, intent(out) :: vid
2036  character(len=*), intent(in) :: varname
2037  character(len=*), intent(in) :: desc
2038  character(len=*), intent(in) :: unit
2039  character(len=*), intent(in) :: axistype
2040  character(len=*), intent(in) :: datatype
2041 
2042  real(RP), intent(in), optional :: timeintv
2043  integer, intent(in), optional :: nsteps
2044 
2045  integer :: dtype, ndims, elm_size
2046  character(len=2) :: dims(3)
2047  real(DP) :: time_interval
2048  !---------------------------------------------------------------------------
2049 
2050  call prof_rapstart('FILE_O_NetCDF', 2)
2051 
2052  if ( datatype == 'REAL8' ) then
2053  dtype = file_real8
2054  elm_size = 4
2055  elseif( datatype == 'REAL4' ) then
2056  dtype = file_real4
2057  elm_size = 8
2058  else
2059  if ( rp == 8 ) then
2060  dtype = file_real8
2061  elm_size = 8
2062  elseif( rp == 4 ) then
2063  dtype = file_real4
2064  elm_size = 4
2065  else
2066  write(*,*) 'xxx unsupported data type. Check!', trim(datatype), ' item:',trim(varname)
2067  call prc_mpistop
2068  endif
2069  endif
2070 
2071  if ( axistype == 'Z' ) then ! 1D variable
2072  ndims = 1
2073  dims(1) = 'z'
2074  write_buf_amount = write_buf_amount + ka * elm_size
2075  elseif( axistype == 'X' ) then
2076  ndims = 1
2077  dims(1) = 'x'
2078  write_buf_amount = write_buf_amount + ia * elm_size
2079  elseif( axistype == 'Y' ) then
2080  ndims = 1
2081  dims(1) = 'y'
2082  write_buf_amount = write_buf_amount + ja * elm_size
2083  elseif( axistype == 'XY' ) then ! 2D variable
2084  ndims = 2
2085  dims(1) = 'x'
2086  dims(2) = 'y'
2087  write_buf_amount = write_buf_amount + ia * ja * elm_size
2088  elseif( axistype == 'UY' ) then
2089  ndims = 2
2090  dims(1) = 'xh'
2091  dims(2) = 'y'
2092  write_buf_amount = write_buf_amount + ia * ja * elm_size
2093  elseif( axistype == 'XV' ) then
2094  ndims = 2
2095  dims(1) = 'x'
2096  dims(2) = 'yh'
2097  write_buf_amount = write_buf_amount + ia * ja * elm_size
2098  elseif( axistype == 'UV' ) then
2099  ndims = 2
2100  dims(1) = 'xh'
2101  dims(2) = 'yh'
2102  write_buf_amount = write_buf_amount + ia * ja * elm_size
2103  elseif( axistype == 'ZX' ) then
2104  ndims = 2
2105  dims(1) = 'z'
2106  dims(2) = 'x'
2107  write_buf_amount = write_buf_amount + ka * ia * elm_size
2108  elseif( axistype == 'ZXY' ) then ! 3D variable
2109  ndims = 3
2110  dims = (/'z','x','y'/)
2111  write_buf_amount = write_buf_amount + ka * ia * ja * elm_size
2112  elseif( axistype == 'ZHXY' ) then
2113  ndims = 3
2114  dims = (/'zh','x ','y '/)
2115  write_buf_amount = write_buf_amount + ka * ia * ja * elm_size
2116  elseif( axistype == 'ZXHY' ) then
2117  ndims = 3
2118  dims = (/'z ','xh','y '/)
2119  write_buf_amount = write_buf_amount + ka * ia * ja * elm_size
2120  elseif( axistype == 'ZXYH' ) then
2121  ndims = 3
2122  dims = (/'z ','x ','yh'/)
2123  write_buf_amount = write_buf_amount + ka * ia * ja * elm_size
2124  elseif( axistype == 'Land' ) then
2125  ndims = 3
2126  dims = (/'lz','x ','y '/)
2127  write_buf_amount = write_buf_amount + lkmax * ia * ja * elm_size
2128  elseif( axistype == 'Urban' ) then
2129  ndims = 3
2130  dims = (/'uz','x ','y '/)
2131  write_buf_amount = write_buf_amount + ukmax * ia * ja * elm_size
2132  elseif( axistype == 'XYT' ) then ! 3D variable with time dimension
2133  ndims = 2
2134  dims(1) = 'x'
2135  dims(2) = 'y'
2136  if ( present(nsteps) ) then
2137  write_buf_amount = write_buf_amount + ia * ja * elm_size * nsteps
2138  else
2139  write_buf_amount = write_buf_amount + ia * ja * elm_size
2140  end if
2141  elseif( axistype == 'ZXYT' ) then ! 4D variable
2142  ndims = 3
2143  dims = (/'z','x','y'/)
2144  if ( present(nsteps) ) then
2145  write_buf_amount = write_buf_amount + ka * ia * ja * elm_size * nsteps
2146  else
2147  write_buf_amount = write_buf_amount + ka * ia * ja * elm_size
2148  end if
2149  else
2150  write(*,*) 'xxx [FILEIO_def_var] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
2151  call prc_mpistop
2152  endif
2153 
2154  if ( present(timeintv) ) then ! 3D/4D variable with time dimension
2155  time_interval = timeintv
2156  call filedefinevariable( fid, vid, varname, desc, unit, ndims, dims, dtype, & ! [IN]
2157  tint=time_interval ) ! [IN]
2158  else
2159  call filedefinevariable( fid, vid, varname, desc, unit, ndims, dims, dtype ) ! [IN]
2160  endif
2161 
2162  call prof_rapend ('FILE_O_NetCDF', 2)
2163 
2164  return
2165  end subroutine fileio_def_var
2166 
2167  !-----------------------------------------------------------------------------
2169  subroutine fileio_write_var_1d( &
2170  fid, &
2171  vid, &
2172  var, &
2173  varname, &
2174  axistype )
2175  use gtool_file, only: &
2176  filewrite
2177  use scale_process, only: &
2178  prc_myrank, &
2179  prc_mpistop
2180  use scale_rm_process, only: &
2181  prc_2drank
2182  use scale_time, only: &
2183  nowsec => time_nowdaysec
2184  implicit none
2185 
2186  integer, intent(in) :: fid
2187  integer, intent(in) :: vid
2188  real(RP), intent(in) :: var(:)
2189  character(len=*), intent(in) :: varname
2190  character(len=*), intent(in) :: axistype
2191 
2192  integer :: dim1_S, dim1_E
2193  integer :: rankidx(2)
2194  integer :: start(1) ! used only when IO_AGGREGATE is .true.
2195  logical :: exec = .true.
2196  !---------------------------------------------------------------------------
2197 
2198  call prof_rapstart('FILE_O_NetCDF', 2)
2199 
2200  rankidx(1) = prc_2drank(prc_myrank,1)
2201  rankidx(2) = prc_2drank(prc_myrank,2)
2202 
2203  if ( axistype == 'Z' ) then
2204  dim1_s = ks
2205  dim1_e = ke
2206  start(1) = 1
2207  if( io_aggregate .AND. prc_myrank > 0 ) exec = .false. ! only rank 0 writes
2208  elseif( axistype == 'X' ) then
2209  dim1_s = isb
2210  dim1_e = ieb
2211  start(1) = isga
2212  if( io_aggregate .AND. rankidx(2) > 0 ) exec = .false. ! only south most row processes write
2213  elseif( axistype == 'Y' ) then
2214  dim1_s = jsb
2215  dim1_e = jeb
2216  start(1) = jsga
2217  if( io_aggregate .AND. rankidx(1) > 0 ) exec = .false. ! only west most column processes write
2218  else
2219  write(*,*) 'xxx [FILEIO_write_var_1D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
2220  call prc_mpistop
2221  endif
2222 
2223  if( exec ) call filewrite( fid, vid, var(dim1_s:dim1_e), &
2224  nowsec, nowsec, start ) ! [IN]
2225 
2226  call prof_rapend ('FILE_O_NetCDF', 2)
2227 
2228  return
2229  end subroutine fileio_write_var_1d
2230 
2231  !-----------------------------------------------------------------------------
2233  subroutine fileio_write_var_2d( &
2234  fid, &
2235  vid, &
2236  var, &
2237  varname, &
2238  axistype, &
2239  nohalo )
2240  use gtool_file, only: &
2241  rmiss
2242  use gtool_file, only: &
2243  filewrite
2244  use scale_process, only: &
2245  prc_myrank, &
2246  prc_mpistop
2247  use scale_rm_process, only: &
2248  prc_2drank, &
2249  prc_num_x, &
2250  prc_num_y
2251  use scale_time, only: &
2252  nowsec => time_nowdaysec
2253  implicit none
2254 
2255  integer, intent(in) :: fid
2256  integer, intent(in) :: vid
2257  real(RP), intent(in) :: var(:,:)
2258  character(len=*), intent(in) :: varname
2259  character(len=*), intent(in) :: axistype
2260  logical, intent(in), optional :: nohalo
2261 
2262  real(RP) :: varhalo( size(var(:,1)), size(var(1,:)) )
2263 
2264  integer :: dim1_S, dim1_E
2265  integer :: dim2_S, dim2_E
2266 
2267  integer :: i, j
2268  logical :: nohalo_
2269  integer :: rankidx(2)
2270  integer :: start(2) ! used only when IO_AGGREGATE is .true.
2271  logical :: exec = .true.
2272  !---------------------------------------------------------------------------
2273 
2274  call prof_rapstart('FILE_O_NetCDF', 2)
2275 
2276  rankidx(1) = prc_2drank(prc_myrank,1)
2277  rankidx(2) = prc_2drank(prc_myrank,2)
2278 
2279  start(1) = isga
2280  start(2) = jsga
2281 
2282  nohalo_ = .false.
2283  if( present(nohalo) ) nohalo_ = nohalo
2284 
2285  if ( axistype == 'XY' &
2286  .OR. axistype == 'UY' &
2287  .OR. axistype == 'XV' &
2288  .OR. axistype == 'UV' ) then
2289  dim1_s = isb
2290  dim1_e = ieb
2291  dim2_s = jsb
2292  dim2_e = jeb
2293  if ( io_aggregate ) then
2294  if( rankidx(1) == 0 ) dim1_s = 1
2295  if( rankidx(1) == prc_num_x - 1 ) dim1_e = ia
2296  if( rankidx(2) == 0 ) dim2_s = 1
2297  if( rankidx(2) == prc_num_y - 1 ) dim2_e = ja
2298  end if
2299  elseif( axistype == 'ZX' ) then
2300  dim1_s = ks
2301  dim1_e = ke
2302  dim2_s = isb
2303  dim2_e = ieb
2304  start(2) = start(1)
2305  start(1) = 1
2306  if ( io_aggregate .AND. rankidx(2) > 0 ) then
2307  exec = .false. ! only south most row processes write
2308  if( rankidx(1) == 0 ) dim2_s = 1
2309  if( rankidx(1) == prc_num_x - 1 ) dim2_e = ia
2310  end if
2311  else
2312  write(*,*) 'xxx [FILEIO_write_var_2D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
2313  call prc_mpistop
2314  endif
2315 
2316  if ( exec ) then
2317  if ( nohalo_ ) then ! fill halo cells with RMISS
2318  varhalo(:,:) = var(:,:)
2319 
2320  ! W halo
2321  do j = 1, ja
2322  do i = 1, is-1
2323  varhalo(i,j) = rmiss
2324  end do
2325  end do
2326  ! E halo
2327  do j = 1, ja
2328  do i = ie+1, ia
2329  varhalo(i,j) = rmiss
2330  end do
2331  end do
2332  ! S halo
2333  do j = 1, js-1
2334  do i = 1, ia
2335  varhalo(i,j) = rmiss
2336  end do
2337  end do
2338  ! N halo
2339  do j = je+1, ja
2340  do i = 1, ia
2341  varhalo(i,j) = rmiss
2342  end do
2343  end do
2344 
2345  call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e), &
2346  nowsec, nowsec, start ) ! [IN]
2347  else
2348  call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e), &
2349  nowsec, nowsec, start ) ! [IN]
2350  end if
2351 
2352  end if
2353 
2354  call prof_rapend ('FILE_O_NetCDF', 2)
2355 
2356  return
2357  end subroutine fileio_write_var_2d
2358 
2359  !-----------------------------------------------------------------------------
2361  subroutine fileio_write_var_3d( &
2362  fid, &
2363  vid, &
2364  var, &
2365  varname, &
2366  axistype, &
2367  nohalo )
2368  use gtool_file, only: &
2369  rmiss
2370  use gtool_file, only: &
2371  filewrite
2372  use scale_process, only: &
2373  prc_myrank, &
2374  prc_mpistop
2375  use scale_rm_process, only: &
2376  prc_2drank, &
2377  prc_num_x, &
2378  prc_num_y
2379  use scale_time, only: &
2380  nowsec => time_nowdaysec
2381  implicit none
2382 
2383  integer, intent(in) :: fid
2384  integer, intent(in) :: vid
2385  real(RP), intent(in) :: var(:,:,:)
2386  character(len=*), intent(in) :: varname
2387  character(len=*), intent(in) :: axistype
2388 
2389  logical, intent(in), optional :: nohalo
2390 
2391  real(RP) :: varhalo( size(var(:,1,1)), size(var(1,:,1)), size(var(1,1,:)) )
2392 
2393  integer :: dim1_S, dim1_E, dim1_max
2394  integer :: dim2_S, dim2_E
2395  integer :: dim3_S, dim3_E
2396 
2397  integer :: i, j, k
2398  logical :: nohalo_
2399  integer :: rankidx(2)
2400  integer :: start(3) ! used only when IO_AGGREGATE is .true.
2401  !---------------------------------------------------------------------------
2402 
2403  call prof_rapstart('FILE_O_NetCDF', 2)
2404 
2405  nohalo_ = .false.
2406  if( present(nohalo) ) nohalo_ = nohalo
2407 
2408  rankidx(1) = prc_2drank(prc_myrank,1)
2409  rankidx(2) = prc_2drank(prc_myrank,2)
2410 
2411  start(1) = 1
2412  start(2) = isga
2413  start(3) = jsga
2414 
2415  dim2_s = isb
2416  dim2_e = ieb
2417  dim3_s = jsb
2418  dim3_e = jeb
2419  if ( io_aggregate ) then
2420  if( rankidx(1) == 0 ) dim2_s = 1
2421  if( rankidx(1) == prc_num_x - 1 ) dim2_e = ia
2422  if( rankidx(2) == 0 ) dim3_s = 1
2423  if( rankidx(2) == prc_num_y - 1 ) dim3_e = ja
2424  end if
2425 
2426  if ( axistype == 'ZXY' &
2427  .OR. axistype == 'ZHXY' &
2428  .OR. axistype == 'ZXHY' &
2429  .OR. axistype == 'ZXYH' ) then
2430  dim1_max = kmax
2431  dim1_s = ks
2432  dim1_e = ke
2433  elseif( axistype == 'Land' ) then
2434  dim1_max = lkmax
2435  dim1_s = lks
2436  dim1_e = lke
2437  elseif( axistype == 'Urban' ) then
2438  dim1_max = ukmax
2439  dim1_s = uks
2440  dim1_e = uke
2441  else
2442  write(*,*) 'xxx [FILEIO_write_var_3D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
2443  call prc_mpistop
2444  endif
2445 
2446  if ( nohalo_ ) then
2447  varhalo(:,:,:) = var(:,:,:)
2448 
2449  ! W halo
2450  do k = 1, dim1_max
2451  do j = 1, ja
2452  do i = 1, is-1
2453  varhalo(k,i,j) = rmiss
2454  end do
2455  end do
2456  end do
2457  ! E halo
2458  do k = 1, dim1_max
2459  do j = 1, ja
2460  do i = ie+1, ia
2461  varhalo(k,i,j) = rmiss
2462  end do
2463  end do
2464  end do
2465  ! S halo
2466  do k = 1, dim1_max
2467  do j = 1, js-1
2468  do i = 1, ia
2469  varhalo(k,i,j) = rmiss
2470  end do
2471  end do
2472  end do
2473  ! N halo
2474  do k = 1, dim1_max
2475  do j = je+1, ja
2476  do i = 1, ia
2477  varhalo(k,i,j) = rmiss
2478  end do
2479  end do
2480  end do
2481 
2482  call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2483  nowsec, nowsec, start ) ! [IN]
2484  else
2485  call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2486  nowsec, nowsec, start ) ! [IN]
2487  end if
2488 
2489  call prof_rapend ('FILE_O_NetCDF', 2)
2490 
2491  return
2492  end subroutine fileio_write_var_3d
2493 
2494  !-----------------------------------------------------------------------------
2496  subroutine fileio_write_var_3d_t( &
2497  fid, &
2498  vid, &
2499  var, &
2500  varname, &
2501  axistype, &
2502  timeintv, &
2503  timetarg, &
2504  nohalo )
2505  use gtool_file, only: &
2506  rmiss
2507  use gtool_file, only: &
2508  filewrite
2509  use scale_process, only: &
2510  prc_myrank, &
2511  prc_mpistop
2512  use scale_rm_process, only: &
2513  prc_2drank, &
2514  prc_num_x, &
2515  prc_num_y
2516  implicit none
2517 
2518  integer, intent(in) :: fid
2519  integer, intent(in) :: vid
2520  real(RP), intent(in) :: var(:,:,:)
2521  character(len=*), intent(in) :: varname
2522  character(len=*), intent(in) :: axistype
2523  real(RP), intent(in) :: timeintv
2524 
2525  integer, intent(in), optional :: timetarg
2526  logical, intent(in), optional :: nohalo
2527 
2528  real(RP) :: varhalo( size(var(:,1,1)), size(var(1,:,1)) )
2529 
2530  integer :: dim1_S, dim1_E
2531  integer :: dim2_S, dim2_E
2532 
2533  real(DP) :: time_interval, nowtime
2534 
2535  integer :: step
2536  integer :: i, j, n
2537  logical :: nohalo_
2538  integer :: rankidx(2)
2539  integer :: start(3) ! used only when IO_AGGREGATE is .true.
2540  !---------------------------------------------------------------------------
2541 
2542  call prof_rapstart('FILE_O_NetCDF', 2)
2543 
2544  nohalo_ = .false.
2545  if( present(nohalo) ) nohalo_ = nohalo
2546 
2547  time_interval = timeintv
2548  step = size(var(isb,jsb,:))
2549 
2550  rankidx(1) = prc_2drank(prc_myrank,1)
2551  rankidx(2) = prc_2drank(prc_myrank,2)
2552 
2553  if ( axistype == 'XYT' ) then
2554  dim1_s = isb
2555  dim1_e = ieb
2556  dim2_s = jsb
2557  dim2_e = jeb
2558  if ( io_aggregate ) then
2559  if( rankidx(1) == 0 ) dim1_s = 1
2560  if( rankidx(1) == prc_num_x - 1 ) dim1_e = ia
2561  if( rankidx(2) == 0 ) dim2_s = 1
2562  if( rankidx(2) == prc_num_y - 1 ) dim2_e = ja
2563  end if
2564  else
2565  write(*,*) 'xxx [FILEIO_write_var_3D_t] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
2566  call prc_mpistop
2567  endif
2568 
2569  start(1) = isga
2570  start(2) = jsga
2571  ! start(3) time dimension will be set in file_write_data()
2572 
2573  if ( present(timetarg) ) then
2574  nowtime = (timetarg-1) * time_interval
2575 
2576  if ( nohalo_ ) then
2577  varhalo(:,:) = var(:,:,timetarg)
2578 
2579  ! W halo
2580  do j = 1, ja
2581  do i = 1, is-1
2582  varhalo(i,j) = rmiss
2583  end do
2584  end do
2585  ! E halo
2586  do j = 1, ja
2587  do i = ie+1, ia
2588  varhalo(i,j) = rmiss
2589  end do
2590  end do
2591  ! S halo
2592  do j = 1, js-1
2593  do i = 1, ia
2594  varhalo(i,j) = rmiss
2595  end do
2596  end do
2597  ! N halo
2598  do j = je+1, ja
2599  do i = 1, ia
2600  varhalo(i,j) = rmiss
2601  end do
2602  end do
2603 
2604  call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e), &
2605  nowtime, nowtime, start ) ! [IN]
2606  else
2607  call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,timetarg), &
2608  nowtime, nowtime, start ) ! [IN]
2609  end if
2610  else
2611  nowtime = 0.0_dp
2612  do n = 1, step
2613  if ( nohalo_ ) then
2614  varhalo(:,:) = var(:,:,n)
2615 
2616  ! W halo
2617  do j = 1, ja
2618  do i = 1, is-1
2619  varhalo(i,j) = rmiss
2620  end do
2621  end do
2622  ! E halo
2623  do j = 1, ja
2624  do i = ie+1, ia
2625  varhalo(i,j) = rmiss
2626  end do
2627  end do
2628  ! S halo
2629  do j = 1, js-1
2630  do i = 1, ia
2631  varhalo(i,j) = rmiss
2632  end do
2633  end do
2634  ! N halo
2635  do j = je+1, ja
2636  do i = 1, ia
2637  varhalo(i,j) = rmiss
2638  end do
2639  end do
2640 
2641  call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e), &
2642  nowtime, nowtime, start ) ! [IN]
2643  else
2644  call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,n), &
2645  nowtime, nowtime, start ) ! [IN]
2646  end if
2647  nowtime = nowtime + time_interval
2648  enddo
2649  endif
2650 
2651  call prof_rapend ('FILE_O_NetCDF', 2)
2652 
2653  return
2654  end subroutine fileio_write_var_3d_t
2655 
2656  !-----------------------------------------------------------------------------
2658  subroutine fileio_write_var_4d( &
2659  fid, &
2660  vid, &
2661  var, &
2662  varname, &
2663  axistype, &
2664  timeintv, &
2665  timetarg, &
2666  nohalo )
2667  use gtool_file, only: &
2668  rmiss
2669  use gtool_file, only: &
2670  filewrite
2671  use scale_process, only: &
2672  prc_myrank, &
2673  prc_mpistop
2674  use scale_rm_process, only: &
2675  prc_2drank, &
2676  prc_num_x, &
2677  prc_num_y
2678  implicit none
2679 
2680  integer, intent(in) :: fid
2681  integer, intent(in) :: vid
2682  real(RP), intent(in) :: var(:,:,:,:)
2683  character(len=*), intent(in) :: varname
2684  character(len=*), intent(in) :: axistype
2685  real(RP), intent(in) :: timeintv
2686 
2687  integer, intent(in), optional :: timetarg
2688  logical, intent(in), optional :: nohalo
2689 
2690  real(RP) :: varhalo( size(var(:,1,1,1)), size(var(1,:,1,1)), size(var(1,1,:,1)) )
2691 
2692  integer :: dim1_S, dim1_E, dim1_max
2693  integer :: dim2_S, dim2_E
2694  integer :: dim3_S, dim3_E
2695 
2696  real(DP) :: time_interval, nowtime
2697 
2698  integer :: step
2699  integer :: i, j, k, n
2700  logical :: nohalo_
2701  integer :: rankidx(2)
2702  integer :: start(4) ! used only when IO_AGGREGATE is .true.
2703  !---------------------------------------------------------------------------
2704 
2705  call prof_rapstart('FILE_O_NetCDF', 2)
2706 
2707  nohalo_ = .false.
2708  if( present(nohalo) ) nohalo_ = nohalo
2709 
2710  rankidx(1) = prc_2drank(prc_myrank,1)
2711  rankidx(2) = prc_2drank(prc_myrank,2)
2712 
2713  start(1) = 1
2714  start(2) = isga
2715  start(3) = jsga
2716  ! start(4) time dimension will be set in file_write_data()
2717 
2718  time_interval = timeintv
2719  step = size(var,4)
2720 
2721  if ( axistype == 'ZXYT' ) then
2722  dim1_max = kmax
2723  dim1_s = ks
2724  dim1_e = ke
2725  dim2_s = isb
2726  dim2_e = ieb
2727  dim3_s = jsb
2728  dim3_e = jeb
2729  if ( io_aggregate ) then
2730  if( rankidx(1) == 0 ) dim2_s = 1
2731  if( rankidx(1) == prc_num_x - 1 ) dim2_e = ia
2732  if( rankidx(2) == 0 ) dim3_s = 1
2733  if( rankidx(2) == prc_num_y - 1 ) dim3_e = ja
2734  end if
2735  else
2736  write(*,*) 'xxx [FILEIO_write_var_4D] unsupported axis type. Check! axistype:', trim(axistype), ', item:',trim(varname)
2737  call prc_mpistop
2738  endif
2739 
2740  if ( present(timetarg) ) then
2741  nowtime = (timetarg-1) * time_interval
2742 
2743  if ( nohalo_ ) then
2744  varhalo(:,:,:) = var(:,:,:,timetarg)
2745 
2746  ! W halo
2747  do k = 1, dim1_max
2748  do j = 1, ja
2749  do i = 1, is-1
2750  varhalo(k,i,j) = rmiss
2751  end do
2752  end do
2753  end do
2754  ! E halo
2755  do k = 1, dim1_max
2756  do j = 1, ja
2757  do i = ie+1, ia
2758  varhalo(k,i,j) = rmiss
2759  end do
2760  end do
2761  end do
2762  ! S halo
2763  do k = 1, dim1_max
2764  do j = 1, js-1
2765  do i = 1, ia
2766  varhalo(k,i,j) = rmiss
2767  end do
2768  end do
2769  end do
2770  ! N halo
2771  do k = 1, dim1_max
2772  do j = je+1, ja
2773  do i = 1, ia
2774  varhalo(k,i,j) = rmiss
2775  end do
2776  end do
2777  end do
2778 
2779  call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2780  nowtime, nowtime, start ) ! [IN]
2781  else
2782  call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e,timetarg), &
2783  nowtime, nowtime, start ) ! [IN]
2784  end if
2785  else
2786  nowtime = 0.0_dp
2787  do n = 1, step
2788  if ( nohalo_ ) then
2789  varhalo(:,:,:) = var(:,:,:,n)
2790 
2791  ! W halo
2792  do k = 1, dim1_max
2793  do j = 1, ja
2794  do i = 1, is-1
2795  varhalo(k,i,j) = rmiss
2796  end do
2797  end do
2798  end do
2799  ! E halo
2800  do k = 1, dim1_max
2801  do j = 1, ja
2802  do i = ie+1, ia
2803  varhalo(k,i,j) = rmiss
2804  end do
2805  end do
2806  end do
2807  ! S halo
2808  do k = 1, dim1_max
2809  do j = 1, js-1
2810  do i = 1, ia
2811  varhalo(k,i,j) = rmiss
2812  end do
2813  end do
2814  end do
2815  ! N halo
2816  do k = 1, dim1_max
2817  do j = je+1, ja
2818  do i = 1, ia
2819  varhalo(k,i,j) = rmiss
2820  end do
2821  end do
2822  end do
2823 
2824  call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2825  nowtime, nowtime, start ) ! [IN]
2826  else
2827  call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e,n), &
2828  nowtime, nowtime, start ) ! [IN]
2829  end if
2830  nowtime = nowtime + time_interval
2831  enddo
2832  endif
2833 
2834  call prof_rapend ('FILE_O_NetCDF', 2)
2835 
2836  return
2837  end subroutine fileio_write_var_4d
2838 
2839  !-----------------------------------------------------------------------------
2840  subroutine closeall
2841  implicit none
2842 
2843  integer :: fid
2844  !---------------------------------------------------------------------------
2845 
2846  do fid = 0, file_nfile_max-1
2847  call fileio_close( fid )
2848  end do
2849 
2850  return
2851  end subroutine closeall
2852 
2853  !-----------------------------------------------------------------------------
2854  subroutine getcftunits(tunits, date)
2855  implicit none
2856 
2857  character(len=34), intent(out) :: tunits
2858  integer, intent(in) :: date(6)
2859  !---------------------------------------------------------------------------
2860 
2861  write(tunits,'(a,i4.4,"-",i2.2,"-",i2.2," ",i2.2,":",i2.2,":",i2.2)') 'seconds since ', date
2862 
2863  return
2864  end subroutine getcftunits
2865 
2866  !-----------------------------------------------------------------------------
2867  subroutine check_1d( &
2868  expected, buffer, &
2869  name )
2870  use scale_process, only: &
2871  prc_mpistop
2872  use scale_const, only: &
2873  eps => const_eps
2874  implicit none
2875 
2876  real(RP), intent(in) :: expected(:)
2877  real(RP), intent(in) :: buffer(:)
2878  character(len=*), intent(in) :: name
2879 
2880  real(RP) :: check
2881  integer :: nmax, n
2882 
2883  intrinsic :: size
2884  !---------------------------------------------------------------------------
2885 
2886  nmax = size(expected)
2887  if ( size(buffer) /= nmax ) then
2888  write(*,*) 'xxx size of coordinate ('//trim(name)//') is different:', nmax, size(buffer)
2889  call prc_mpistop
2890  end if
2891 
2892  do n=1, nmax
2893  if ( abs(expected(n)) > eps ) then
2894  check = abs(buffer(n)-expected(n)) / abs(buffer(n)+expected(n)) * 2.0_rp
2895  else
2896  check = abs(buffer(n)-expected(n))
2897  end if
2898 
2899  if ( check > fileio_datacheck_criteria ) then
2900  write(*,*) 'xxx value of coordinate ('//trim(name)//') at ', n, ' is different:', &
2901  expected(n), buffer(n), check
2902  call prc_mpistop
2903  end if
2904  end do
2905 
2906  return
2907  end subroutine check_1d
2908 
2909  !-----------------------------------------------------------------------------
2910  subroutine check_2d( &
2911  expected, buffer, &
2912  name )
2913  use scale_process, only: &
2914  prc_mpistop
2915  use scale_const, only: &
2916  eps => const_eps
2917  implicit none
2918 
2919  real(RP), intent(in) :: expected(:,:)
2920  real(RP), intent(in) :: buffer(:,:)
2921  character(len=*), intent(in) :: name
2922 
2923  real(RP) :: check
2924  integer :: imax, jmax
2925  integer :: i, j
2926 
2927  intrinsic :: size
2928  !---------------------------------------------------------------------------
2929 
2930  imax = size(expected,1)
2931  jmax = size(expected,2)
2932  if ( size(buffer,1) /= imax ) then
2933  write(*,*) 'xxx the first size of coordinate ('//trim(name)//') is different:', imax, size(buffer,1)
2934  call prc_mpistop
2935  end if
2936  if ( size(buffer,2) /= jmax ) then
2937  write(*,*) 'xxx the second size of coordinate ('//trim(name)//') is different:', jmax, size(buffer,2)
2938  call prc_mpistop
2939  end if
2940 
2941  do j=1, jmax
2942  do i=1, imax
2943  if ( abs(expected(i,j)) > eps ) then
2944  check = abs(buffer(i,j)-expected(i,j)) / abs(buffer(i,j)+expected(i,j)) * 2.0_rp
2945  else
2946  check = abs(buffer(i,j)-expected(i,j))
2947  end if
2948 
2949  if ( check > fileio_datacheck_criteria ) then
2950  write(*,*) 'xxx value of coordinate ('//trim(name)//') at (', i, ',', j, ') is different:', &
2951  expected(i,j), buffer(i,j), check
2952  call prc_mpistop
2953  end if
2954  end do
2955  end do
2956 
2957  return
2958  end subroutine check_2d
2959 
2960  !-----------------------------------------------------------------------------
2961  subroutine check_3d( &
2962  expected, buffer, &
2963  name, &
2964  transpose )
2965  use scale_process, only: &
2966  prc_mpistop
2967  use scale_const, only: &
2968  eps => const_eps
2969  implicit none
2970 
2971  real(RP), intent(in) :: expected(:,:,:)
2972  real(RP), intent(in) :: buffer(:,:,:)
2973  character(len=*), intent(in) :: name
2974  logical, intent(in) :: transpose
2975 
2976  real(RP) :: check
2977  integer :: imax, jmax, kmax
2978  integer :: i, j, k
2979 
2980  intrinsic :: size
2981  !---------------------------------------------------------------------------
2982 
2983  if ( transpose ) then
2984  kmax = size(expected,3)
2985  imax = size(expected,1)
2986  jmax = size(expected,2)
2987  else
2988  kmax = size(expected,1)
2989  imax = size(expected,2)
2990  jmax = size(expected,3)
2991  end if
2992  if ( size(buffer,1) /= kmax ) then
2993  write(*,*) 'xxx the first size of coordinate ('//trim(name)//') is different:', kmax, size(buffer,1)
2994  call prc_mpistop
2995  end if
2996  if ( size(buffer,2) /= imax ) then
2997  write(*,*) 'xxx the second size of coordinate ('//trim(name)//') is different:', imax, size(buffer,2)
2998  call prc_mpistop
2999  end if
3000  if ( size(buffer,3) /= jmax ) then
3001  write(*,*) 'xxx the third size of coordinate ('//trim(name)//') is different:', jmax, size(buffer,3)
3002  call prc_mpistop
3003  end if
3004 
3005  if ( transpose ) then
3006  ! buffer(i,j,k), expected(k,i,j)
3007  do k=1, kmax
3008  do j=1, jmax
3009  do i=1, imax
3010  if ( abs(expected(k,i,j)) > eps ) then
3011  check = abs(buffer(i,j,k)-expected(k,i,j)) / abs(buffer(i,j,k)+expected(k,i,j)) * 2.0_rp
3012  else
3013  check = abs(buffer(i,j,k)-expected(k,i,j))
3014  end if
3015 
3016  if ( check > fileio_datacheck_criteria ) then
3017  write(*,*) 'xxx value of coordinate ('//trim(name)//') at ', i, ',', j, ',', k, ' is different:', &
3018  expected(k,i,j), buffer(i,j,k), check
3019  call prc_mpistop
3020  end if
3021  end do
3022  end do
3023  end do
3024  else
3025  do j=1, jmax
3026  do i=1, imax
3027  do k=1, kmax
3028  if ( abs(expected(k,i,j)) > eps ) then
3029  check = abs(buffer(k,i,j)-expected(k,i,j)) / abs(buffer(k,i,j)+expected(k,i,j)) * 2.0_rp
3030  else
3031  check = abs(buffer(k,i,j)-expected(k,i,j))
3032  end if
3033 
3034  if ( check > fileio_datacheck_criteria ) then
3035  write(*,*) 'xxx value of coordinate ('//trim(name)//') at ', k, ',', i, ',', j, ' is different:', &
3036  expected(k,i,j), buffer(k,i,j), check
3037  call prc_mpistop
3038  end if
3039  end do
3040  end do
3041  end do
3042  end if
3043 
3044  return
3045  end subroutine check_3d
3046 
3047 end module scale_fileio
integer, public imax
of computational cells: x, local
integer, public prc_num_x
x length of 2D processor topology
integer, public is
start point of inner domain: x, local
module GTOOL_FILE
Definition: gtool_file.f90:17
integer, public je
end point of inner domain: y, local
subroutine fileio_read_1d(var, basename, varname, axistype, step)
Read 1D data from file.
real(rp), dimension(:), allocatable, public grid_cyg
center coordinate [m]: y, global
integer, public prc_local_comm_world
local communicator
subroutine, public prc_mpistop
Abort MPI.
real(rp), dimension(:), allocatable, public grid_cbfyg
center buffer factor (0-1): y, global
integer, public jeb
logical, public prc_periodic_y
periodic condition or not (Y)?
real(dp), public time_nowms
subsecond part of current time [millisec]
Definition: scale_time.F90:66
real(dp), parameter, public rmiss
Definition: gtool_file.f90:150
real(rp), dimension(:), allocatable, public grid_cxg
center coordinate [m]: x, global
real(rp), dimension(:), allocatable, public grid_fdy
y-length of grid(j+1) to grid(j) [m]
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:61
real(rp), dimension(:), allocatable, public grid_cdyg
center coordinate [m]: y, global
subroutine fileio_def_axes(fid, dtype, xy)
define axis variables in the file
real(rp), dimension(:), allocatable, public grid_cz
center coordinate [m]: z, local=global
real(rp), dimension(:), allocatable, public grid_fxg
face coordinate [m]: x, global
subroutine, public fileio_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
subroutine fileio_write_var_3d(fid, vid, var, varname, axistype, nohalo)
Write 3D data to file.
real(rp), dimension(:), allocatable, public grid_fbfy
face buffer factor (0-1): y
subroutine, public fileio_setup
Setup.
subroutine, public filedefinevariable(fid, vid, varname, desc, units, ndims, dims, dtype, tint, tavg)
real(dp), public time_nowdaysec
second of current time [sec]
Definition: scale_time.F90:69
module STDIO
Definition: scale_stdio.F90:12
subroutine, public fileenddef(fid)
integer, public ke
end point of inner domain: z, local
subroutine fileio_write_3d_t(var, basename, title, varname, desc, unit, axistype, datatype, timeintv, tsince, append, timetarg, nohalo)
Write 3D data with time dimension to file.
integer, public imaxb
real(rp), public const_d2r
degree to radian
Definition: scale_const.F90:35
subroutine fileio_write_4d(var, basename, title, varname, desc, unit, axistype, datatype, timeintv, tsince, append, timetarg, nohalo)
Write 4D data to file.
subroutine construct_derived_datatype
construct MPI derived datatypes for read buffers
subroutine, public fileattachbuffer(fid, buf_amount)
module GRID (cartesian) for land
logical, public prc_periodic_x
periodic condition or not (X)?
real(rp), dimension(:), allocatable, public grid_cdxg
center coordinate [m]: x, global
subroutine fileio_write_axes(fid, xy)
write axis to the file
subroutine fileio_write_var_4d(fid, vid, var, varname, axistype, timeintv, timetarg, nohalo)
Write 4D data to file.
subroutine fileio_read_4d(var, basename, varname, axistype, step)
Read 4D data from file.
integer, public jmaxb
module FILE I/O (netcdf)
real(rp), dimension(:), allocatable, public grid_fx
face coordinate [m]: x, local
subroutine fileio_read_var_1d(var, fid, varname, axistype, step)
Read 1D data from file.
subroutine fileio_write_var_1d(fid, vid, var, varname, axistype)
Write 1D data to file.
real(rp), dimension(:), allocatable, public grid_lfz
face coordinate [m]: z, local=global
integer, public ieb
integer, public prc_num_y
y length of 2D processor topology
subroutine fileio_read_var_4d(var, fid, varname, axistype, step)
Read 4D data from file.
module grid index
real(rp), dimension(:), allocatable, public grid_ucdz
z-length of control volume [m]
logical, public io_nml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:62
integer, public jsga
start point of the full domain: cy, global
integer, public ia
of whole cells: x, local, with HALO
character(len=h_mid), public h_source
for file header
Definition: scale_stdio.F90:50
integer, public jag
of computational grids
module GRID (cartesian) for urban
real(rp), dimension(:), allocatable, public grid_fbfx
face buffer factor (0-1): x
real(rp), dimension(:), allocatable, public grid_fdz
z-length of grid(k+1) to grid(k) [m]
subroutine, public fileclose(fid)
real(rp), dimension(:), allocatable, public grid_ufz
face coordinate [m]: z, local=global
integer, public ka
of whole cells: z, local, with HALO
real(rp), dimension(:), allocatable, public grid_fbfxg
face buffer factor (0-1): x, global
subroutine, public filedefassociatedcoordinates(fid, name, desc, units, dim_names, dtype)
Definition: gtool_file.f90:903
subroutine, public filesettattr(fid, vname, key, val)
real(rp), dimension(:), allocatable, public grid_fdyg
center coordinate [m]: y, global
subroutine fileio_write_2d(var, basename, title, varname, desc, unit, axistype, datatype, date, subsec, append, nohalo, nozcoord)
Write 2D data to file.
integer, public kmax
of computational cells: z, local
real(rp), dimension(:), allocatable, public grid_fz
face coordinate [m]: z, local=global
real(rp), dimension(:), allocatable, public grid_fbfz
face buffer factor (0-1): z
subroutine fileio_write_3d(var, basename, title, varname, desc, unit, axistype, datatype, date, subsec, append, nohalo)
Write 3D data to file.
subroutine fileio_write_var_3d_t(fid, vid, var, varname, axistype, timeintv, timetarg, nohalo)
Write 3D data with time dimension to file.
subroutine, public fileio_create(fid, basename, title, datatype, date, subsec, append, nozcoord)
Create/open a netCDF file.
integer, public jhalo
of halo cells: y
subroutine fileio_read_var_3d(var, fid, varname, axistype, step)
Read 3D data from file.
integer, public js
start point of inner domain: y, local
integer, public iag
of computational grids
real(rp), dimension(:), allocatable, public grid_cbfx
center buffer factor (0-1): x
module TIME
Definition: scale_time.F90:15
module PROCESS
real(rp), dimension(:), allocatable, public grid_fbfyg
face buffer factor (0-1): y, global
real(rp), dimension(:), allocatable, public grid_ucz
center coordinate [m]: z, local=global
integer, parameter, public file_fread
subroutine fileio_read_var_2d(var, fid, varname, axistype, step)
Read 2D data from file.
module CONSTANT
Definition: scale_const.F90:14
integer, parameter, public prc_masterrank
master process in each communicator
integer, public is_ing
start point of the inner domain: cx, global
integer, public ks
start point of inner domain: z, local
real(rp), dimension(:), allocatable, public grid_cbfz
center buffer factor (0-1): z
integer, parameter, public khalo
of halo cells: z
integer, public prc_myrank
process num in local communicator
real(rp), dimension(:), allocatable, public grid_cx
center coordinate [m]: x, local
module GRID (cartesian)
subroutine, public fileio_enddef(fid)
Exit netCDF file define mode.
subroutine, public prof_rapstart(rapname_base, level)
Start raptime.
Definition: scale_prof.F90:156
subroutine, public fileio_cleanup
deallocate buffers
module RM PROCESS
integer, public isga
start point of the full domain: cx, global
module profiler
Definition: scale_prof.F90:10
integer, public ie
end point of inner domain: x, local
real(rp), public const_eps
small number
Definition: scale_const.F90:36
real(rp), dimension(:), allocatable, public grid_lcdz
z-length of control volume [m]
character(len=h_mid), public h_institute
for file header
Definition: scale_stdio.F90:51
subroutine, public filedetachbuffer(fid)
logical, public io_aggregate
do parallel I/O through PnetCDF
Definition: scale_stdio.F90:66
real(rp), dimension(:), allocatable, public grid_fdxg
center coordinate [m]: x, global
subroutine fileio_check_coordinates_name(basename, atmos, land, urban, transpose)
check coordinates in the file
subroutine, public fileio_open(fid, basename)
open a netCDF file for read
module PRECISION
integer, dimension(:,:), allocatable, public prc_2drank
node index in 2D topology
real(rp), dimension(:), allocatable, public grid_cdz
z-length of control volume [m]
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps)
Define a variable to file.
real(rp), dimension(:), allocatable, public grid_fdx
x-length of grid(i+1) to grid(i) [m]
real(rp), dimension(:), allocatable, public grid_lcz
center coordinate [m]: z, local=global
integer, parameter, public file_real4
real(rp), dimension(:), allocatable, public grid_cdy
y-length of control volume [m]
integer, public js_ing
start point of the inner domain: cy, global
real(rp), dimension(:), allocatable, public grid_cbfy
center buffer factor (0-1): y
integer, public isb
subroutine, public fileflush(fid)
integer, dimension(6), public time_nowdate
current time [YYYY MM DD HH MM SS]
Definition: scale_time.F90:65
subroutine, public fileio_close(fid)
Close a netCDF file.
module land grid index
subroutine, public filecreate(fid, existed, basename, title, source, institution, master, myrank, rankidx, single, time_units, append, comm)
Definition: gtool_file.f90:191
subroutine, public fileio_set_coordinates(LON, LONX, LONY, LONXY, LAT, LATX, LATY, LATXY, CZ, FZ)
set latlon and z
module FILE I/O HEADER
integer, public io_fid_conf
Config file ID.
Definition: scale_stdio.F90:55
subroutine, public fileopen(fid, basename, mode, single, comm, myrank)
Definition: gtool_file.f90:495
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56
subroutine free_derived_datatype
free MPI derived datatypes
integer, public jsb
subroutine, public prof_rapend(rapname_base, level)
Save raptime.
Definition: scale_prof.F90:204
integer, parameter, public rp
real(rp), dimension(:), allocatable, public grid_cdx
x-length of control volume [m]
integer, public jmax
of computational cells: y, local
subroutine fileio_write_var_2d(fid, vid, var, varname, axistype, nohalo)
Write 2D data to file.
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57
real(rp), dimension(:), allocatable, public grid_fyg
face coordinate [m]: y, global
real(rp), dimension(:), allocatable, public grid_cy
center coordinate [m]: y, local
integer, parameter, public file_real8
subroutine fileio_read_2d(var, basename, varname, axistype, step)
Read 2D data from file.
real(rp), dimension(:), allocatable, public grid_cbfxg
center buffer factor (0-1): x, global
subroutine fileio_read_3d(var, basename, varname, axistype, step)
Read 3D data from file.
integer, public ihalo
of halo cells: x
subroutine fileio_write_1d(var, basename, title, varname, desc, unit, axistype, datatype, date, subsec, append)
Write 1D data to file.
subroutine, public filedefaxis(fid, name, desc, units, dim_name, dtype, dim_size)
Definition: gtool_file.f90:584
module urban grid index
integer, public ja
of whole cells: y, local, with HALO
real(rp), dimension(:), allocatable, public grid_fy
face coordinate [m]: y, local