SCALE-RM
scale_file.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
10 !-------------------------------------------------------------------------------
11 ! Warning: This file was generated from file/scale_file.F90.erb.
12 ! Do not edit this file.
13 !-------------------------------------------------------------------------------
14 #include "scalelib.h"
15 module scale_file
16  !-----------------------------------------------------------------------------
17  !
18  !++ Used modules
19  !
20  use scale_precision
21  use scale_io
22  use scale_prof
23  use scale_file_h
24  use scale_prc, only: &
25  prc_abort
26  use iso_c_binding
27 #ifdef _OPENACC
28  use openacc
29 #endif
30  !-----------------------------------------------------------------------------
31  implicit none
32  private
33 
34  include 'scale_file_c.inc'
35  !-----------------------------------------------------------------------------
36  !
37  !++ Public procedures
38  !
39  public :: file_setup
40  public :: file_finalize
41  public :: file_open
42  public :: file_opened
43  public :: file_single
44  public :: file_allnodes
45  public :: file_create
46  public :: file_get_dimlength
47  public :: file_set_option
48  public :: file_def_axis
49  public :: file_put_axis
50  public :: file_write_axis
52  public :: file_put_associatedcoordinate
53  public :: file_write_associatedcoordinate
54  public :: file_add_variable
55  public :: file_def_variable
56  public :: file_get_shape
57  public :: file_get_stepsize
58  public :: file_get_commoninfo
59  public :: file_get_datainfo
60  public :: file_get_all_datainfo
61  public :: file_read
62  public :: file_write
63  public :: file_get_attribute
64  public :: file_set_attribute
66  public :: file_enddef
67  public :: file_redef
68  public :: file_flush
69  public :: file_close
70  public :: file_close_all
71  public :: file_attach_buffer
72  public :: file_detach_buffer
73  public :: file_get_cftunits
74  public :: file_get_aggregate
75 
76  interface file_get_commoninfo
77  module procedure file_get_commoninfo_fid
78  module procedure file_get_commoninfo_fname
79  end interface file_get_commoninfo
80 
81  interface file_get_shape
82  module procedure file_get_shape_fid
83  module procedure file_get_shape_fname
84  end interface file_get_shape
85 
86  interface file_get_datainfo
87  module procedure file_get_datainfo_fid
88  module procedure file_get_datainfo_fname
89  end interface file_get_datainfo
90 
91  interface file_get_all_datainfo
92  module procedure file_get_all_datainfo_fid
93  module procedure file_get_all_datainfo_fname
94  end interface file_get_all_datainfo
95 
96  interface file_put_axis
97  module procedure file_put_axis_realsp
98  module procedure file_put_axis_realdp
99  end interface file_put_axis
100  interface file_write_axis
101  module procedure file_write_axis_realsp
102  module procedure file_write_axis_realdp
103  end interface file_write_axis
104  interface file_put_associatedcoordinate
105  module procedure file_put_associatedcoordinate_realsp_1d
106  module procedure file_put_associatedcoordinate_realdp_1d
107  module procedure file_put_associatedcoordinate_realsp_2d
108  module procedure file_put_associatedcoordinate_realdp_2d
109  module procedure file_put_associatedcoordinate_realsp_3d
110  module procedure file_put_associatedcoordinate_realdp_3d
111  module procedure file_put_associatedcoordinate_realsp_4d
112  module procedure file_put_associatedcoordinate_realdp_4d
113  end interface file_put_associatedcoordinate
114  interface file_write_associatedcoordinate
115  module procedure file_write_associatedcoordinate_realsp_1d
116  module procedure file_write_associatedcoordinate_realdp_1d
117  module procedure file_write_associatedcoordinate_realsp_2d
118  module procedure file_write_associatedcoordinate_realdp_2d
119  module procedure file_write_associatedcoordinate_realsp_3d
120  module procedure file_write_associatedcoordinate_realdp_3d
121  module procedure file_write_associatedcoordinate_realsp_4d
122  module procedure file_write_associatedcoordinate_realdp_4d
123  end interface file_write_associatedcoordinate
124  interface file_add_variable
125  module procedure file_add_variable_no_time
126  module procedure file_add_variable_with_time
127  end interface file_add_variable
128  interface file_read
129  module procedure file_read_realsp_1d
130  module procedure file_read_realdp_1d
131  module procedure file_read_realsp_2d
132  module procedure file_read_realdp_2d
133  module procedure file_read_realsp_3d
134  module procedure file_read_realdp_3d
135  module procedure file_read_realsp_4d
136  module procedure file_read_realdp_4d
137  module procedure file_read_var_realsp_1d
138  module procedure file_read_var_realdp_1d
139  module procedure file_read_var_realsp_2d
140  module procedure file_read_var_realdp_2d
141  module procedure file_read_var_realsp_3d
142  module procedure file_read_var_realdp_3d
143  module procedure file_read_var_realsp_4d
144  module procedure file_read_var_realdp_4d
145  end interface file_read
146  interface file_write
147  module procedure file_write_realsp_1d
148  module procedure file_write_realdp_1d
149  module procedure file_write_realsp_2d
150  module procedure file_write_realdp_2d
151  module procedure file_write_realsp_3d
152  module procedure file_write_realdp_3d
153  module procedure file_write_realsp_4d
154  module procedure file_write_realdp_4d
155  end interface file_write
156  interface file_get_attribute
157  module procedure file_get_attribute_text_fname
158  module procedure file_get_attribute_logical_fname
159  module procedure file_get_attribute_int_fname_ary
160  module procedure file_get_attribute_int_fname
161  module procedure file_get_attribute_float_fname_ary
162  module procedure file_get_attribute_float_fname
163  module procedure file_get_attribute_double_fname_ary
164  module procedure file_get_attribute_double_fname
165  module procedure file_get_attribute_text_fid
166  module procedure file_get_attribute_logical_fid
167  module procedure file_get_attribute_int_fid_ary
168  module procedure file_get_attribute_int_fid
169  module procedure file_get_attribute_float_fid_ary
170  module procedure file_get_attribute_float_fid
171  module procedure file_get_attribute_double_fid_ary
172  module procedure file_get_attribute_double_fid
173  end interface file_get_attribute
174  interface file_set_attribute
175  module procedure file_set_attribute_text
176  module procedure file_set_attribute_logical
177  module procedure file_set_attribute_int_ary
178  module procedure file_set_attribute_int
179  module procedure file_set_attribute_float_ary
180  module procedure file_set_attribute_float
181  module procedure file_set_attribute_double_ary
182  module procedure file_set_attribute_double
183  end interface file_set_attribute
184 
185 #if defined(__GFORTRAN__) && __GNUC__ < 7
186  interface cloc
187  module procedure cloc_sp
188  module procedure cloc_dp
189  end interface cloc
190 #endif
191 
192  !-----------------------------------------------------------------------------
193  !
194  !++ Public parameters & variables
195  !
196  logical, public :: file_aggregate
197 
198  !-----------------------------------------------------------------------------
199  !
200  !++ Private procedures
201  !
202  private :: file_get_fid
203 
204  !-----------------------------------------------------------------------------
205  !
206  !++ Private parameters & variables
207  !
208  type file
209  character(len=FILE_HLONG) :: name
210  integer :: fid
211  logical :: aggregate
212  logical :: single
213  logical :: allnodes
214  integer(8) :: buffer_size
215  end type file
216  type(file) :: file_files(file_file_max)
217  integer :: file_nfiles = 0
218 
219  type var
220  character(len=FILE_HLONG) :: name
221  integer :: fid
222  integer :: vid
223  end type var
224  type(var) :: file_vars(file_var_max)
225  integer :: file_nvars = 0
226 
227  integer :: mpi_myrank
228 
229  !-----------------------------------------------------------------------------
230 contains
231  !-----------------------------------------------------------------------------
233  !-----------------------------------------------------------------------------
234  subroutine file_setup( &
235  myrank )
236  use scale_prc, only: &
238  implicit none
239 
240  integer, intent(in) :: myrank
241 
242  namelist / param_file / &
244 
245  integer :: fid
246  integer :: ierr
247 
248  file_aggregate = .false.
249 
250  !--- read namelist
251  rewind(io_fid_conf)
252  read(io_fid_conf,nml=param_file,iostat=ierr)
253  if( ierr < 0 ) then !--- missing
254  log_info("FILE_setup",*) 'Not found namelist. Default used.'
255  elseif( ierr > 0 ) then !--- fatal error
256  log_error("FILE_setup",*) 'Not appropriate names in namelist PARAM_FILE. Check!'
257  call prc_abort
258  endif
259  log_nml(param_file)
260 
261  mpi_myrank = myrank
262 
264 
265  do fid = 1, file_file_max
266  file_files(fid)%fid = -1
267  file_files(fid)%name = ""
268  end do
269 
270  return
271  end subroutine file_setup
272 
273  !-----------------------------------------------------------------------------
275  !-----------------------------------------------------------------------------
276  subroutine file_finalize
277 
278  file_nfiles = 0
279  file_nvars = 0
280 
281  return
282  end subroutine file_finalize
283 
284  !-----------------------------------------------------------------------------
288  subroutine file_create( &
289  basename, &
290  title, source, institution, &
291  fid, existed, &
292  rankid, single, aggregate, &
293  time_units, calendar, &
294  allnodes, append )
295  implicit none
296 
297  character(len=*), intent(in) :: basename
298  character(len=*), intent(in) :: title
299  character(len=*), intent(in) :: source
300  character(len=*), intent(in) :: institution
301 
302  integer, intent(out) :: fid
303  logical, intent(out) :: existed
304 
305  integer, intent(in), optional :: rankid
306  logical, intent(in), optional :: single
307  logical, intent(in), optional :: aggregate
308  character(len=*), intent(in), optional :: time_units
309  character(len=*), intent(in), optional :: calendar
310  logical, intent(in), optional :: allnodes
311  logical, intent(in), optional :: append
312 
313  character(len=FILE_HMID) :: time_units_
314  character(len=FILE_HSHORT) :: calendar_
315  integer :: rankid_
316  logical :: single_
317  integer :: mode
318 
319  integer :: error
320  !---------------------------------------------------------------------------
321 
322 
323  if ( present(rankid) ) then
324  rankid_ = rankid
325  else
326  rankid_ = mpi_myrank
327  end if
328 
329  single_ = .false.
330  if ( present(single) ) then
331  single_ = single
332  endif
333 
334  if ( present(time_units) ) then
335  time_units_ = time_units
336  else
337  time_units_ = 'seconds'
338  endif
339 
340  if ( present(calendar) ) then
341  calendar_ = calendar
342  else
343  calendar_ = ""
344  end if
345 
346  mode = file_fwrite
347  if ( present(append) ) then
348  if( append ) mode = file_fappend
349  endif
350 
351  if ( single_ .and. rankid_ /= 0 ) then
352  fid = -1
353  existed = .false.
354  return
355  end if
356 
357  call file_get_fid( basename, mode, & ! [IN]
358  rankid_, single_, & ! [IN]
359  fid, existed, & ! [OUT]
360  allnodes=allnodes, & ! [IN]
361  aggregate=aggregate ) ! [IN]
362 
363  if( existed ) return
364 
365  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
366 
367  !--- append package header to the file
368  call file_set_attribute( fid, "global", "title" , title ) ! [IN]
369  call file_set_attribute( fid, "global", "source" , source ) ! [IN]
370  call file_set_attribute( fid, "global", "institution", institution ) ! [IN]
371 
372  if ( ( .not. present(aggregate) ) .or. .not. aggregate ) then
373  ! for shared-file parallel I/O, skip attributes related to MPI processes
374  call file_set_attribute( fid, "global", "rankid" , (/rankid_/) ) ! [IN]
375  endif
376 
377  error = file_set_tunits_c( file_files(fid)%fid, & ! [IN]
378  cstr(time_units_), &
379  cstr(calendar_ ) ) ! [IN]
380 
381  if ( error /= file_success_code ) then
382  log_error("FILE_create",*) 'failed to set time units'
383  call prc_abort
384  endif
385 
386  call prof_rapend('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
387 
388  return
389  end subroutine file_create
390 
391  !-----------------------------------------------------------------------------
392  subroutine file_get_var_num( &
393  fid, nvars_limit, &
394  nvars )
395  implicit none
396 
397  integer, intent(in) :: fid
398  integer, intent(in) :: nvars_limit
399  integer, intent(out) :: nvars
400 
401  integer :: error
402  !---------------------------------------------------------------------------
403 
404  if ( .not. file_opened(fid) ) then
405  log_error("FILE_get_var_num",*) 'File is not opened. fid = ', fid
406  call prc_abort
407  end if
408 
409  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
410 
411  error = file_get_nvars_c( nvars, & ! (out)
412  file_files(fid)%fid ) ! (in)
413  if ( error /= file_success_code ) then
414  log_error("FILE_get_var_num",*) 'failed to get varnum. fid = ', fid
415  call prc_abort
416  end if
417 
418  if ( nvars > nvars_limit ) then
419  log_error("FILE_get_var_num",*) 'number of variables exceeds the requested size.', nvars, nvars_limit
420  call prc_abort
421  endif
422 
423  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
424 
425  return
426  end subroutine file_get_var_num
427 
428  !-----------------------------------------------------------------------------
429  subroutine file_get_var_name( &
430  fid, cvid, &
431  varname )
432  implicit none
433 
434  integer, intent(in) :: fid
435  integer, intent(in) :: cvid
436  character(len=*), intent(out) :: varname
437 
438  integer :: error
439  !---------------------------------------------------------------------------
440 
441  if ( .not. file_opened(fid) ) then
442  log_error("FILE_get_var_name",*) 'File is not opened. fid = ', fid
443  call prc_abort
444  end if
445 
446  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
447 
448  error = file_get_varname_c( varname, &
449  file_files(fid)%fid, cvid, len(varname) ) ! (in)
450  if ( error == file_success_code ) then
451  call fstr(varname)
452  else
453  log_error("FILE_get_var_name",*) 'failed to get varname. cvid = ', cvid
454  call prc_abort
455  end if
456 
457  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
458 
459  return
460  end subroutine file_get_var_name
461 
462  !-----------------------------------------------------------------------------
463  subroutine file_add_associatedvariable( fid, vname, existed )
464  integer, intent(in) :: fid
465  character(len=*), intent(in) :: vname
466  logical, optional, intent(out) :: existed
467 
468  integer :: error
469 
470  if ( .not. file_opened(fid) ) then
471  log_error("FILE_add_associatedVariable",*) 'File is not opened. fid = ', fid
472  call prc_abort
473  end if
474 
475  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
476 
477  error = file_add_associatedvariable_c( file_files(fid)%fid, cstr(vname) ) ! (in)
478 
479  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
480 
481  if ( present(existed) ) then
482  if ( error == file_already_existed_code ) then
483  existed = .true.
484  return
485  end if
486  existed = .false.
487  end if
488 
489  if ( error /= file_success_code ) then
490  log_error("FILE_add_associatedvariable",*) 'failed to add associated variable: '//trim(vname)
491  call prc_abort
492  end if
493 
494  return
495  end subroutine file_add_associatedvariable
496 
497  !-----------------------------------------------------------------------------
498  subroutine file_set_option( &
499  fid, &
500  filetype, key, val )
501  integer, intent(in) :: fid
502  character(len=*), intent(in) :: filetype
503  character(len=*), intent(in) :: key
504  character(len=*), intent(in) :: val
505 
506  integer :: error
507 
508  if ( .not. file_opened(fid) ) then
509  log_error("FILE_set_option",*) 'File is not opened. fid = ', fid
510  call prc_abort
511  end if
512 
513  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
514 
515  error = file_set_option_c( file_files(fid)%fid, cstr(filetype), cstr(key), cstr(val) ) ! (in)
516  if ( error /= file_success_code ) then
517  log_error("FILE_set_option",*) 'failed to set option'
518  call prc_abort
519  end if
520 
521  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
522 
523  return
524  end subroutine file_set_option
525 
526  !-----------------------------------------------------------------------------
527  subroutine file_open( &
528  basename, &
529  fid, &
530  mode, &
531  single, &
532  allnodes, &
533  aggregate, &
534  rankid, &
535  postfix )
536  implicit none
537 
538  character(len=*), intent( in) :: basename
539  integer, intent(out) :: fid
540  integer, intent( in), optional :: mode
541  logical, intent( in), optional :: single
542  logical, intent( in), optional :: allnodes
543  logical, intent( in), optional :: aggregate
544  integer, intent( in), optional :: rankid
545  character(len=*), intent( in), optional :: postfix
546 
547  integer :: mode_
548  integer :: rankid_
549  logical :: existed
550  logical :: single_
551 
552  single_ = .false.
553 
554  if ( present(mode) ) then
555  mode_ = mode
556  else
557  mode_ = file_fread
558  end if
559 
560  if ( present(single) ) single_ = single
561  if ( present(rankid) ) then
562  rankid_ = rankid
563  else
564  rankid_ = mpi_myrank
565  end if
566 
567  call file_get_fid( basename, mode_, rankid_, single_, & ! (in)
568  fid, existed, & ! (out)
569  allnodes=allnodes, & ! (in)
570  aggregate=aggregate, postfix=postfix ) ! (in)
571 
572  return
573  end subroutine file_open
574 
575  !-----------------------------------------------------------------------------
577  function file_opened( fid )
578  implicit none
579 
580  integer, intent( in) :: fid
581  logical :: file_opened
582 
583  if ( fid < 1 ) then
584  file_opened = .false.
585  else
586  file_opened = file_files(fid)%fid >= 0
587  end if
588 
589  return
590  end function file_opened
591 
592  !-----------------------------------------------------------------------------
594  function file_single( fid )
595  implicit none
596 
597  integer, intent( in) :: fid
598  logical :: file_single
599 
600  if ( fid < 1 ) then
601  file_single = .false.
602  else
603  file_single = file_files(fid)%single
604  end if
605 
606  return
607  end function file_single
608 
609  !-----------------------------------------------------------------------------
611  function file_allnodes( fid )
612  implicit none
613 
614  integer, intent( in) :: fid
615  logical :: file_allnodes
616 
617  if ( fid < 1 ) then
618  file_allnodes = .false.
619  else
620  file_allnodes = file_files(fid)%allnodes
621  end if
622 
623  return
624  end function file_allnodes
625 
626  !-----------------------------------------------------------------------------
628  !-----------------------------------------------------------------------------
629  subroutine file_get_dimlength( &
630  fid, dimname, &
631  len, &
632  error )
633  integer, intent(in) :: fid
634  character(len=*), intent(in) :: dimname
635 
636  integer, intent(out) :: len
637 
638  logical, intent(out), optional :: error
639 
640  logical(c_bool) :: suppress
641  integer :: ierror
642 
643 
644  if ( .not. file_opened(fid) ) then
645  log_error("FILE_get_dimLength",*) 'File is not opened. fid = ', fid
646  call prc_abort
647  end if
648 
649  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
650 
651  if ( present(error) ) then
652  suppress = .true.
653  else
654  suppress = .false.
655  end if
656 
657  ierror = file_get_dim_length_c( len, & ! (out)
658  file_files(fid)%fid, & ! (in)
659  cstr(dimname), & ! (in)
660  suppress ) ! (in)
661  if ( ierror /= file_success_code .and. ierror /= file_already_existed_code ) then
662  if ( present(error) ) then
663  error = .true.
664  else
665  log_error("FILE_get_dimLength",*) 'failed to get dimension length'
666  call prc_abort
667  end if
668  else
669  if ( present(error) ) error = .false.
670  end if
671 
672  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
673 
674  return
675  end subroutine file_get_dimlength
676 
677  !-----------------------------------------------------------------------------
678  ! interface FILE_PutAxis
679  !-----------------------------------------------------------------------------
680  subroutine file_put_axis_realsp( &
681  fid, &
682  name, desc, units, &
683  dim_name, dtype, &
684  val )
685  integer, intent(in) :: fid
686  character(len=*), intent(in) :: name
687  character(len=*), intent(in) :: desc
688  character(len=*), intent(in) :: units
689  character(len=*), intent(in) :: dim_name
690  integer, intent(in) :: dtype
691  real(sp), intent(in), target, contiguous :: val(:)
692 
693  integer :: error
694  intrinsic size
695 
696  if ( .not. file_opened(fid) ) then
697  log_error("FILE_put_axis_real",*) 'File is not opened. fid = ', fid
698  call prc_abort
699  end if
700 
701  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
702 
703  !$acc update host(val) if(acc_is_present(val))
704 
705  error = file_put_axis_c( file_files(fid)%fid, & ! (in)
706  cstr(name), cstr(desc), cstr(units), & ! (in)
707  cstr(dim_name), dtype, & ! (in)
708 #if defined(__GFORTRAN__) && __GNUC__ < 7
709  cloc(val(1)), size(val), sp ) ! (in)
710 #else
711  c_loc(val), size(val), sp ) ! (in)
712 #endif
713  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
714  log_error("FILE_put_axis_realSP",*) 'failed to put axis'
715  call prc_abort
716  end if
717 
718  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
719 
720  return
721  end subroutine file_put_axis_realsp
722  subroutine file_put_axis_realdp( &
723  fid, &
724  name, desc, units, &
725  dim_name, dtype, &
726  val )
727  integer, intent(in) :: fid
728  character(len=*), intent(in) :: name
729  character(len=*), intent(in) :: desc
730  character(len=*), intent(in) :: units
731  character(len=*), intent(in) :: dim_name
732  integer, intent(in) :: dtype
733  real(dp), intent(in), target, contiguous :: val(:)
734 
735  integer :: error
736  intrinsic size
737 
738  if ( .not. file_opened(fid) ) then
739  log_error("FILE_put_axis_real",*) 'File is not opened. fid = ', fid
740  call prc_abort
741  end if
742 
743  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
744 
745  !$acc update host(val) if(acc_is_present(val))
746 
747  error = file_put_axis_c( file_files(fid)%fid, & ! (in)
748  cstr(name), cstr(desc), cstr(units), & ! (in)
749  cstr(dim_name), dtype, & ! (in)
750 #if defined(__GFORTRAN__) && __GNUC__ < 7
751  cloc(val(1)), size(val), dp ) ! (in)
752 #else
753  c_loc(val), size(val), dp ) ! (in)
754 #endif
755  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
756  log_error("FILE_put_axis_realDP",*) 'failed to put axis'
757  call prc_abort
758  end if
759 
760  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
761 
762  return
763  end subroutine file_put_axis_realdp
764 
765  subroutine file_def_axis( &
766  fid, &
767  name, desc, units, &
768  dim_name, dtype, dim_size, &
769  bounds )
770  integer, intent(in) :: fid
771  character(len=*), intent(in) :: name
772  character(len=*), intent(in) :: desc
773  character(len=*), intent(in) :: units
774  character(len=*), intent(in) :: dim_name
775  integer, intent(in) :: dtype
776  integer, intent(in) :: dim_size
777 
778  logical, intent(in), optional :: bounds
779 
780  integer :: error
781  integer :: bounds_
782 
783  bounds_ = 0 ! .false.
784  if ( present(bounds) ) then
785  if ( bounds ) bounds_ = 1 ! .true.
786  end if
787 
788  if ( .not. file_opened(fid) ) then
789  log_error("FILE_def_axis",*) 'File is not opened. fid = ', fid
790  call prc_abort
791  end if
792 
793  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
794 
795  error = file_def_axis_c( file_files(fid)%fid, & ! (in)
796  cstr(name), cstr(desc), cstr(units), & ! (in)
797  cstr(dim_name), dtype, dim_size, bounds_ ) ! (in)
798  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
799  log_error("FILE_def_axis",*) 'failed to define axis'
800  call prc_abort
801  end if
802 
803  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
804 
805  return
806  end subroutine file_def_axis
807 
808  !-----------------------------------------------------------------------------
809  ! interface FILE_WriteAxis
810  !-----------------------------------------------------------------------------
811  subroutine file_write_axis_realsp( &
812  fid, &
813  name, &
814  val, &
815  start )
816  integer, intent(in) :: fid
817  character(len=*), intent(in) :: name
818  real(sp), intent(in), target, contiguous :: val(:)
819  integer, intent(in), optional :: start(:)
820 
821  integer :: error
822  intrinsic shape
823 
824  if ( .not. file_opened(fid) ) then
825  log_error("FILE_write_axis_realSP",*) 'File is not opened. fid = ', fid
826  call prc_abort
827  end if
828 
829  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
830 
831  !$acc update host(val) if(acc_is_present(val))
832 
833  if ( present(start) ) then
834  error = file_write_axis_c( file_files(fid)%fid, cstr(name), & ! (in)
835 #if defined(__GFORTRAN__) && __GNUC__ < 7
836  cloc(val(1)), sp, start-1, shape(val) ) ! (in)
837 #else
838  c_loc(val), sp, start-1, shape(val) ) ! (in)
839 #endif
840  else
841  error = file_write_axis_c( file_files(fid)%fid, cstr(name), & ! (in)
842 #if defined(__GFORTRAN__) && __GNUC__ < 7
843  cloc(val(1)), sp, (/0/), shape(val) ) ! (in)
844 #else
845  c_loc(val), sp, (/0/), shape(val) ) ! (in)
846 #endif
847  end if
848  if ( error /= file_success_code ) then
849  log_error("FILE_write_axis_realSP",*) 'failed to write axis: '//trim(name)
850  call prc_abort
851  end if
852 
853  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
854 
855  return
856  end subroutine file_write_axis_realsp
857  subroutine file_write_axis_realdp( &
858  fid, &
859  name, &
860  val, &
861  start )
862  integer, intent(in) :: fid
863  character(len=*), intent(in) :: name
864  real(dp), intent(in), target, contiguous :: val(:)
865  integer, intent(in), optional :: start(:)
866 
867  integer :: error
868  intrinsic shape
869 
870  if ( .not. file_opened(fid) ) then
871  log_error("FILE_write_axis_realDP",*) 'File is not opened. fid = ', fid
872  call prc_abort
873  end if
874 
875  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
876 
877  !$acc update host(val) if(acc_is_present(val))
878 
879  if ( present(start) ) then
880  error = file_write_axis_c( file_files(fid)%fid, cstr(name), & ! (in)
881 #if defined(__GFORTRAN__) && __GNUC__ < 7
882  cloc(val(1)), dp, start-1, shape(val) ) ! (in)
883 #else
884  c_loc(val), dp, start-1, shape(val) ) ! (in)
885 #endif
886  else
887  error = file_write_axis_c( file_files(fid)%fid, cstr(name), & ! (in)
888 #if defined(__GFORTRAN__) && __GNUC__ < 7
889  cloc(val(1)), dp, (/0/), shape(val) ) ! (in)
890 #else
891  c_loc(val), dp, (/0/), shape(val) ) ! (in)
892 #endif
893  end if
894  if ( error /= file_success_code ) then
895  log_error("FILE_write_axis_realDP",*) 'failed to write axis: '//trim(name)
896  call prc_abort
897  end if
898 
899  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
900 
901  return
902  end subroutine file_write_axis_realdp
903 
904  !-----------------------------------------------------------------------------
905  ! interface FILE_put_associatedCoordinate
906  !-----------------------------------------------------------------------------
907  subroutine file_put_associatedcoordinate_realsp_1d( &
908  fid, &
909  name, desc, units, &
910  dim_names, dtype, &
911  val )
912  integer, intent(in) :: fid
913  character(len=*), intent(in) :: name
914  character(len=*), intent(in) :: desc
915  character(len=*), intent(in) :: units
916  character(len=*), intent(in) :: dim_names(:)
917  integer, intent(in) :: dtype
918 #ifdef NVIDIA
919  real(sp), intent(in) :: val(:)
920 #else
921  real(sp), intent(in), target, contiguous :: val(:)
922 #endif
923 
924  type(c_ptr) :: dim_names_(size(dim_names))
925  !character(:,c_char), allocatable, target :: cptr(:)
926  character(len=H_SHORT), allocatable, target :: cptr(:)
927 
928  integer :: i
929  integer :: error
930  intrinsic size, len
931 
932  if ( .not. file_opened(fid) ) then
933  log_error("FILE_put_associatedCoordinate_realSP_1D",*) 'File is not opened. fid = ', fid
934  call prc_abort
935  end if
936 
937  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
938 
939  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
940  allocate( cptr(size(dim_names)) )
941  do i = 1, size(dim_names)
942  cptr(i) = cstr(dim_names(i))
943  dim_names_(i) = c_loc(cptr(i))
944  end do
945 
946  !$acc update host(val) if(acc_is_present(val))
947 
948 #ifdef NVIDIA
949  block
950  real(sp), allocatable, target :: work(:)
951  allocate(work, source=val)
952 #endif
954  file_files(fid)%fid, & ! (in)
955  cstr(name), cstr(desc), cstr(units), & ! (in)
956  dim_names_, size(dim_names), dtype, & ! (in)
957 #if defined(__GFORTRAN__) && __GNUC__ < 7
958  cloc(val(1)), sp ) ! (in)
959 #elif defined(NVIDIA)
960  c_loc(work), sp ) ! (in)
961 #else
962  c_loc(val), sp ) ! (in)
963 #endif
964  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
965  log_error("FILE_put_associatedCoordinate_realSP_1D",*) 'failed to put associated coordinate: '//trim(name)
966  call prc_abort
967  end if
968 
969 #ifdef NVIDIA
970  end block
971 #endif
972 
973  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
974 
975  return
976  end subroutine file_put_associatedcoordinate_realsp_1d
977  subroutine file_put_associatedcoordinate_realdp_1d( &
978  fid, &
979  name, desc, units, &
980  dim_names, dtype, &
981  val )
982  integer, intent(in) :: fid
983  character(len=*), intent(in) :: name
984  character(len=*), intent(in) :: desc
985  character(len=*), intent(in) :: units
986  character(len=*), intent(in) :: dim_names(:)
987  integer, intent(in) :: dtype
988 #ifdef NVIDIA
989  real(dp), intent(in) :: val(:)
990 #else
991  real(dp), intent(in), target, contiguous :: val(:)
992 #endif
993 
994  type(c_ptr) :: dim_names_(size(dim_names))
995  !character(:,c_char), allocatable, target :: cptr(:)
996  character(len=H_SHORT), allocatable, target :: cptr(:)
997 
998  integer :: i
999  integer :: error
1000  intrinsic size, len
1001 
1002  if ( .not. file_opened(fid) ) then
1003  log_error("FILE_put_associatedCoordinate_realDP_1D",*) 'File is not opened. fid = ', fid
1004  call prc_abort
1005  end if
1006 
1007  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1008 
1009  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1010  allocate( cptr(size(dim_names)) )
1011  do i = 1, size(dim_names)
1012  cptr(i) = cstr(dim_names(i))
1013  dim_names_(i) = c_loc(cptr(i))
1014  end do
1015 
1016  !$acc update host(val) if(acc_is_present(val))
1017 
1018 #ifdef NVIDIA
1019  block
1020  real(dp), allocatable, target :: work(:)
1021  allocate(work, source=val)
1022 #endif
1024  file_files(fid)%fid, & ! (in)
1025  cstr(name), cstr(desc), cstr(units), & ! (in)
1026  dim_names_, size(dim_names), dtype, & ! (in)
1027 #if defined(__GFORTRAN__) && __GNUC__ < 7
1028  cloc(val(1)), dp ) ! (in)
1029 #elif defined(NVIDIA)
1030  c_loc(work), dp ) ! (in)
1031 #else
1032  c_loc(val), dp ) ! (in)
1033 #endif
1034  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1035  log_error("FILE_put_associatedCoordinate_realDP_1D",*) 'failed to put associated coordinate: '//trim(name)
1036  call prc_abort
1037  end if
1038 
1039 #ifdef NVIDIA
1040  end block
1041 #endif
1042 
1043  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1044 
1045  return
1046  end subroutine file_put_associatedcoordinate_realdp_1d
1047  subroutine file_put_associatedcoordinate_realsp_2d( &
1048  fid, &
1049  name, desc, units, &
1050  dim_names, dtype, &
1051  val )
1052  integer, intent(in) :: fid
1053  character(len=*), intent(in) :: name
1054  character(len=*), intent(in) :: desc
1055  character(len=*), intent(in) :: units
1056  character(len=*), intent(in) :: dim_names(:)
1057  integer, intent(in) :: dtype
1058 #ifdef NVIDIA
1059  real(sp), intent(in) :: val(:,:)
1060 #else
1061  real(sp), intent(in), target, contiguous :: val(:,:)
1062 #endif
1063 
1064  type(c_ptr) :: dim_names_(size(dim_names))
1065  !character(:,c_char), allocatable, target :: cptr(:)
1066  character(len=H_SHORT), allocatable, target :: cptr(:)
1067 
1068  integer :: i
1069  integer :: error
1070  intrinsic size, len
1071 
1072  if ( .not. file_opened(fid) ) then
1073  log_error("FILE_put_associatedCoordinate_realSP_2D",*) 'File is not opened. fid = ', fid
1074  call prc_abort
1075  end if
1076 
1077  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1078 
1079  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1080  allocate( cptr(size(dim_names)) )
1081  do i = 1, size(dim_names)
1082  cptr(i) = cstr(dim_names(i))
1083  dim_names_(i) = c_loc(cptr(i))
1084  end do
1085 
1086  !$acc update host(val) if(acc_is_present(val))
1087 
1088 #ifdef NVIDIA
1089  block
1090  real(sp), allocatable, target :: work(:,:)
1091  allocate(work, source=val)
1092 #endif
1094  file_files(fid)%fid, & ! (in)
1095  cstr(name), cstr(desc), cstr(units), & ! (in)
1096  dim_names_, size(dim_names), dtype, & ! (in)
1097 #if defined(__GFORTRAN__) && __GNUC__ < 7
1098  cloc(val(1,1)), sp ) ! (in)
1099 #elif defined(NVIDIA)
1100  c_loc(work), sp ) ! (in)
1101 #else
1102  c_loc(val), sp ) ! (in)
1103 #endif
1104  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1105  log_error("FILE_put_associatedCoordinate_realSP_2D",*) 'failed to put associated coordinate: '//trim(name)
1106  call prc_abort
1107  end if
1108 
1109 #ifdef NVIDIA
1110  end block
1111 #endif
1112 
1113  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1114 
1115  return
1116  end subroutine file_put_associatedcoordinate_realsp_2d
1117  subroutine file_put_associatedcoordinate_realdp_2d( &
1118  fid, &
1119  name, desc, units, &
1120  dim_names, dtype, &
1121  val )
1122  integer, intent(in) :: fid
1123  character(len=*), intent(in) :: name
1124  character(len=*), intent(in) :: desc
1125  character(len=*), intent(in) :: units
1126  character(len=*), intent(in) :: dim_names(:)
1127  integer, intent(in) :: dtype
1128 #ifdef NVIDIA
1129  real(dp), intent(in) :: val(:,:)
1130 #else
1131  real(dp), intent(in), target, contiguous :: val(:,:)
1132 #endif
1133 
1134  type(c_ptr) :: dim_names_(size(dim_names))
1135  !character(:,c_char), allocatable, target :: cptr(:)
1136  character(len=H_SHORT), allocatable, target :: cptr(:)
1137 
1138  integer :: i
1139  integer :: error
1140  intrinsic size, len
1141 
1142  if ( .not. file_opened(fid) ) then
1143  log_error("FILE_put_associatedCoordinate_realDP_2D",*) 'File is not opened. fid = ', fid
1144  call prc_abort
1145  end if
1146 
1147  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1148 
1149  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1150  allocate( cptr(size(dim_names)) )
1151  do i = 1, size(dim_names)
1152  cptr(i) = cstr(dim_names(i))
1153  dim_names_(i) = c_loc(cptr(i))
1154  end do
1155 
1156  !$acc update host(val) if(acc_is_present(val))
1157 
1158 #ifdef NVIDIA
1159  block
1160  real(dp), allocatable, target :: work(:,:)
1161  allocate(work, source=val)
1162 #endif
1164  file_files(fid)%fid, & ! (in)
1165  cstr(name), cstr(desc), cstr(units), & ! (in)
1166  dim_names_, size(dim_names), dtype, & ! (in)
1167 #if defined(__GFORTRAN__) && __GNUC__ < 7
1168  cloc(val(1,1)), dp ) ! (in)
1169 #elif defined(NVIDIA)
1170  c_loc(work), dp ) ! (in)
1171 #else
1172  c_loc(val), dp ) ! (in)
1173 #endif
1174  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1175  log_error("FILE_put_associatedCoordinate_realDP_2D",*) 'failed to put associated coordinate: '//trim(name)
1176  call prc_abort
1177  end if
1178 
1179 #ifdef NVIDIA
1180  end block
1181 #endif
1182 
1183  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1184 
1185  return
1186  end subroutine file_put_associatedcoordinate_realdp_2d
1187  subroutine file_put_associatedcoordinate_realsp_3d( &
1188  fid, &
1189  name, desc, units, &
1190  dim_names, dtype, &
1191  val )
1192  integer, intent(in) :: fid
1193  character(len=*), intent(in) :: name
1194  character(len=*), intent(in) :: desc
1195  character(len=*), intent(in) :: units
1196  character(len=*), intent(in) :: dim_names(:)
1197  integer, intent(in) :: dtype
1198 #ifdef NVIDIA
1199  real(sp), intent(in) :: val(:,:,:)
1200 #else
1201  real(sp), intent(in), target, contiguous :: val(:,:,:)
1202 #endif
1203 
1204  type(c_ptr) :: dim_names_(size(dim_names))
1205  !character(:,c_char), allocatable, target :: cptr(:)
1206  character(len=H_SHORT), allocatable, target :: cptr(:)
1207 
1208  integer :: i
1209  integer :: error
1210  intrinsic size, len
1211 
1212  if ( .not. file_opened(fid) ) then
1213  log_error("FILE_put_associatedCoordinate_realSP_3D",*) 'File is not opened. fid = ', fid
1214  call prc_abort
1215  end if
1216 
1217  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1218 
1219  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1220  allocate( cptr(size(dim_names)) )
1221  do i = 1, size(dim_names)
1222  cptr(i) = cstr(dim_names(i))
1223  dim_names_(i) = c_loc(cptr(i))
1224  end do
1225 
1226  !$acc update host(val) if(acc_is_present(val))
1227 
1228 #ifdef NVIDIA
1229  block
1230  real(sp), allocatable, target :: work(:,:,:)
1231  allocate(work, source=val)
1232 #endif
1234  file_files(fid)%fid, & ! (in)
1235  cstr(name), cstr(desc), cstr(units), & ! (in)
1236  dim_names_, size(dim_names), dtype, & ! (in)
1237 #if defined(__GFORTRAN__) && __GNUC__ < 7
1238  cloc(val(1,1,1)), sp ) ! (in)
1239 #elif defined(NVIDIA)
1240  c_loc(work), sp ) ! (in)
1241 #else
1242  c_loc(val), sp ) ! (in)
1243 #endif
1244  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1245  log_error("FILE_put_associatedCoordinate_realSP_3D",*) 'failed to put associated coordinate: '//trim(name)
1246  call prc_abort
1247  end if
1248 
1249 #ifdef NVIDIA
1250  end block
1251 #endif
1252 
1253  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1254 
1255  return
1256  end subroutine file_put_associatedcoordinate_realsp_3d
1257  subroutine file_put_associatedcoordinate_realdp_3d( &
1258  fid, &
1259  name, desc, units, &
1260  dim_names, dtype, &
1261  val )
1262  integer, intent(in) :: fid
1263  character(len=*), intent(in) :: name
1264  character(len=*), intent(in) :: desc
1265  character(len=*), intent(in) :: units
1266  character(len=*), intent(in) :: dim_names(:)
1267  integer, intent(in) :: dtype
1268 #ifdef NVIDIA
1269  real(dp), intent(in) :: val(:,:,:)
1270 #else
1271  real(dp), intent(in), target, contiguous :: val(:,:,:)
1272 #endif
1273 
1274  type(c_ptr) :: dim_names_(size(dim_names))
1275  !character(:,c_char), allocatable, target :: cptr(:)
1276  character(len=H_SHORT), allocatable, target :: cptr(:)
1277 
1278  integer :: i
1279  integer :: error
1280  intrinsic size, len
1281 
1282  if ( .not. file_opened(fid) ) then
1283  log_error("FILE_put_associatedCoordinate_realDP_3D",*) 'File is not opened. fid = ', fid
1284  call prc_abort
1285  end if
1286 
1287  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1288 
1289  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1290  allocate( cptr(size(dim_names)) )
1291  do i = 1, size(dim_names)
1292  cptr(i) = cstr(dim_names(i))
1293  dim_names_(i) = c_loc(cptr(i))
1294  end do
1295 
1296  !$acc update host(val) if(acc_is_present(val))
1297 
1298 #ifdef NVIDIA
1299  block
1300  real(dp), allocatable, target :: work(:,:,:)
1301  allocate(work, source=val)
1302 #endif
1304  file_files(fid)%fid, & ! (in)
1305  cstr(name), cstr(desc), cstr(units), & ! (in)
1306  dim_names_, size(dim_names), dtype, & ! (in)
1307 #if defined(__GFORTRAN__) && __GNUC__ < 7
1308  cloc(val(1,1,1)), dp ) ! (in)
1309 #elif defined(NVIDIA)
1310  c_loc(work), dp ) ! (in)
1311 #else
1312  c_loc(val), dp ) ! (in)
1313 #endif
1314  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1315  log_error("FILE_put_associatedCoordinate_realDP_3D",*) 'failed to put associated coordinate: '//trim(name)
1316  call prc_abort
1317  end if
1318 
1319 #ifdef NVIDIA
1320  end block
1321 #endif
1322 
1323  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1324 
1325  return
1326  end subroutine file_put_associatedcoordinate_realdp_3d
1327  subroutine file_put_associatedcoordinate_realsp_4d( &
1328  fid, &
1329  name, desc, units, &
1330  dim_names, dtype, &
1331  val )
1332  integer, intent(in) :: fid
1333  character(len=*), intent(in) :: name
1334  character(len=*), intent(in) :: desc
1335  character(len=*), intent(in) :: units
1336  character(len=*), intent(in) :: dim_names(:)
1337  integer, intent(in) :: dtype
1338 #ifdef NVIDIA
1339  real(sp), intent(in) :: val(:,:,:,:)
1340 #else
1341  real(sp), intent(in), target, contiguous :: val(:,:,:,:)
1342 #endif
1343 
1344  type(c_ptr) :: dim_names_(size(dim_names))
1345  !character(:,c_char), allocatable, target :: cptr(:)
1346  character(len=H_SHORT), allocatable, target :: cptr(:)
1347 
1348  integer :: i
1349  integer :: error
1350  intrinsic size, len
1351 
1352  if ( .not. file_opened(fid) ) then
1353  log_error("FILE_put_associatedCoordinate_realSP_4D",*) 'File is not opened. fid = ', fid
1354  call prc_abort
1355  end if
1356 
1357  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1358 
1359  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1360  allocate( cptr(size(dim_names)) )
1361  do i = 1, size(dim_names)
1362  cptr(i) = cstr(dim_names(i))
1363  dim_names_(i) = c_loc(cptr(i))
1364  end do
1365 
1366  !$acc update host(val) if(acc_is_present(val))
1367 
1368 #ifdef NVIDIA
1369  block
1370  real(sp), allocatable, target :: work(:,:,:,:)
1371  allocate(work, source=val)
1372 #endif
1374  file_files(fid)%fid, & ! (in)
1375  cstr(name), cstr(desc), cstr(units), & ! (in)
1376  dim_names_, size(dim_names), dtype, & ! (in)
1377 #if defined(__GFORTRAN__) && __GNUC__ < 7
1378  cloc(val(1,1,1,1)), sp ) ! (in)
1379 #elif defined(NVIDIA)
1380  c_loc(work), sp ) ! (in)
1381 #else
1382  c_loc(val), sp ) ! (in)
1383 #endif
1384  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1385  log_error("FILE_put_associatedCoordinate_realSP_4D",*) 'failed to put associated coordinate: '//trim(name)
1386  call prc_abort
1387  end if
1388 
1389 #ifdef NVIDIA
1390  end block
1391 #endif
1392 
1393  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1394 
1395  return
1396  end subroutine file_put_associatedcoordinate_realsp_4d
1397  subroutine file_put_associatedcoordinate_realdp_4d( &
1398  fid, &
1399  name, desc, units, &
1400  dim_names, dtype, &
1401  val )
1402  integer, intent(in) :: fid
1403  character(len=*), intent(in) :: name
1404  character(len=*), intent(in) :: desc
1405  character(len=*), intent(in) :: units
1406  character(len=*), intent(in) :: dim_names(:)
1407  integer, intent(in) :: dtype
1408 #ifdef NVIDIA
1409  real(dp), intent(in) :: val(:,:,:,:)
1410 #else
1411  real(dp), intent(in), target, contiguous :: val(:,:,:,:)
1412 #endif
1413 
1414  type(c_ptr) :: dim_names_(size(dim_names))
1415  !character(:,c_char), allocatable, target :: cptr(:)
1416  character(len=H_SHORT), allocatable, target :: cptr(:)
1417 
1418  integer :: i
1419  integer :: error
1420  intrinsic size, len
1421 
1422  if ( .not. file_opened(fid) ) then
1423  log_error("FILE_put_associatedCoordinate_realDP_4D",*) 'File is not opened. fid = ', fid
1424  call prc_abort
1425  end if
1426 
1427  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1428 
1429  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1430  allocate( cptr(size(dim_names)) )
1431  do i = 1, size(dim_names)
1432  cptr(i) = cstr(dim_names(i))
1433  dim_names_(i) = c_loc(cptr(i))
1434  end do
1435 
1436  !$acc update host(val) if(acc_is_present(val))
1437 
1438 #ifdef NVIDIA
1439  block
1440  real(dp), allocatable, target :: work(:,:,:,:)
1441  allocate(work, source=val)
1442 #endif
1444  file_files(fid)%fid, & ! (in)
1445  cstr(name), cstr(desc), cstr(units), & ! (in)
1446  dim_names_, size(dim_names), dtype, & ! (in)
1447 #if defined(__GFORTRAN__) && __GNUC__ < 7
1448  cloc(val(1,1,1,1)), dp ) ! (in)
1449 #elif defined(NVIDIA)
1450  c_loc(work), dp ) ! (in)
1451 #else
1452  c_loc(val), dp ) ! (in)
1453 #endif
1454  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1455  log_error("FILE_put_associatedCoordinate_realDP_4D",*) 'failed to put associated coordinate: '//trim(name)
1456  call prc_abort
1457  end if
1458 
1459 #ifdef NVIDIA
1460  end block
1461 #endif
1462 
1463  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1464 
1465  return
1466  end subroutine file_put_associatedcoordinate_realdp_4d
1467 
1468  subroutine file_def_associatedcoordinate( &
1469  fid, &
1470  name, desc, units, &
1471  dim_names, dtype )
1472  integer, intent(in) :: fid
1473  character(len=*), intent(in) :: name
1474  character(len=*), intent(in) :: desc
1475  character(len=*), intent(in) :: units
1476  character(len=*), intent(in) :: dim_names(:)
1477  integer, intent(in) :: dtype
1478 
1479  type(c_ptr) :: dim_names_(size(dim_names))
1480 ! character(:,c_char), allocatable, target :: cptr(:)
1481  character(len=H_SHORT+1), allocatable, target :: cptr(:)
1482 
1483  integer :: error
1484  integer :: i
1485  intrinsic size, len
1486 
1487  if ( .not. file_opened(fid) ) then
1488  log_error("FILE_def_associatedCoordinate",*) 'File is not opened. fid = ', fid
1489  call prc_abort
1490  end if
1491 
1492  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1493 
1494  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1495  allocate( cptr(size(dim_names)) )
1496  do i = 1, size(dim_names)
1497  cptr(i) = cstr(dim_names(i))
1498  dim_names_(i) = c_loc(cptr(i))
1499  end do
1500 
1502  file_files(fid)%fid, & ! (in)
1503  cstr(name), cstr(desc), cstr(units), & ! (in)
1504  dim_names_, size(dim_names), dtype ) ! (in)
1505  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1506  log_error("FILE_def_associatedCoordinate",*) 'failed to define associated coordinate: '//trim(name)
1507  call prc_abort
1508  end if
1509 
1510  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1511 
1512  return
1513  end subroutine file_def_associatedcoordinate
1514 
1515  !-----------------------------------------------------------------------------
1516  ! interface FILE_write_associatedCoordinate
1517  !-----------------------------------------------------------------------------
1518  subroutine file_write_associatedcoordinate_realsp_1d( &
1519  fid, &
1520  name, &
1521  val, &
1522  start, count, &
1523  ndims )
1524  integer, intent(in) :: fid
1525  character(len=*), intent(in) :: name
1526 #ifdef NVIDIA
1527  real(sp), intent(in) :: val(:)
1528 #else
1529  real(sp), intent(in), target, contiguous :: val(:)
1530 #endif
1531  integer, intent(in), optional :: start(:)
1532  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1533  integer, intent(in), optional :: ndims ! in case val has been reshaped
1534 
1535  integer :: ndims_
1536  integer, allocatable :: start_(:), count_(:)
1537  integer :: error
1538  integer :: i
1539  intrinsic shape, size
1540 
1541  if ( .not. file_opened(fid) ) then
1542  log_error("FILE_write_associatedCoordinate_realSP_1D",*) 'File is not opened. fid = ', fid
1543  call prc_abort
1544  end if
1545 
1546  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1547 
1548  if ( present(ndims) ) then
1549  ndims_ = ndims
1550  else
1551  ndims_ = 1
1552  end if
1553  allocate( start_(ndims_), count_(ndims_) )
1554 
1555  if ( present(ndims) ) then
1556  ! Note this is called for history coordinates which have been reshaped
1557  ! from 2D/3D into 1D array. In this case, start and count must be also present
1558  do i = 1, ndims_
1559  start_(i) = start(ndims_-i+1) - 1
1560  count_(i) = count(ndims_-i+1)
1561  end do
1562  else if ( present(start) ) then
1563  ! Note this is called for restart coordinates
1564  do i = 1, ndims_
1565  start_(i) = start(1-i+1) - 1
1566  count_(i) = size(val, 1-i+1)
1567  end do
1568  else
1569  ! Note this is for the one-file-per-process I/O method
1570  do i = 1, 1
1571  start_(i) = 0
1572  count_(i) = size(val, 1-i+1)
1573  end do
1574  end if
1575 
1576  !$acc update host(val) if(acc_is_present(val))
1577 
1578 #ifdef NVIDIA
1579  block
1580  real(sp), allocatable, target :: work(:)
1581  allocate(work, source=val)
1582 #endif
1584  file_files(fid)%fid, cstr(name), & ! (in)
1585 #if defined(__GFORTRAN__) && __GNUC__ < 7
1586  cloc(val(1)), & ! (in)
1587 #elif defined(NVIDIA)
1588  c_loc(work), & ! (in)
1589 #else
1590  c_loc(val), & ! (in)
1591 #endif
1592  ndims_, sp, & ! (in)
1593  start_, count_ ) ! (in)
1594 
1595  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1596  log_error("FILE_write_associatedCoordinate_realSP_1D",*) 'failed to write associated coordinate: '//trim(name)
1597  call prc_abort
1598  end if
1599 
1600 #ifdef NVIDIA
1601  end block
1602 #endif
1603 
1604  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1605 
1606  return
1607  end subroutine file_write_associatedcoordinate_realsp_1d
1608  subroutine file_write_associatedcoordinate_realdp_1d( &
1609  fid, &
1610  name, &
1611  val, &
1612  start, count, &
1613  ndims )
1614  integer, intent(in) :: fid
1615  character(len=*), intent(in) :: name
1616 #ifdef NVIDIA
1617  real(dp), intent(in) :: val(:)
1618 #else
1619  real(dp), intent(in), target, contiguous :: val(:)
1620 #endif
1621  integer, intent(in), optional :: start(:)
1622  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1623  integer, intent(in), optional :: ndims ! in case val has been reshaped
1624 
1625  integer :: ndims_
1626  integer, allocatable :: start_(:), count_(:)
1627  integer :: error
1628  integer :: i
1629  intrinsic shape, size
1630 
1631  if ( .not. file_opened(fid) ) then
1632  log_error("FILE_write_associatedCoordinate_realDP_1D",*) 'File is not opened. fid = ', fid
1633  call prc_abort
1634  end if
1635 
1636  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1637 
1638  if ( present(ndims) ) then
1639  ndims_ = ndims
1640  else
1641  ndims_ = 1
1642  end if
1643  allocate( start_(ndims_), count_(ndims_) )
1644 
1645  if ( present(ndims) ) then
1646  ! Note this is called for history coordinates which have been reshaped
1647  ! from 2D/3D into 1D array. In this case, start and count must be also present
1648  do i = 1, ndims_
1649  start_(i) = start(ndims_-i+1) - 1
1650  count_(i) = count(ndims_-i+1)
1651  end do
1652  else if ( present(start) ) then
1653  ! Note this is called for restart coordinates
1654  do i = 1, ndims_
1655  start_(i) = start(1-i+1) - 1
1656  count_(i) = size(val, 1-i+1)
1657  end do
1658  else
1659  ! Note this is for the one-file-per-process I/O method
1660  do i = 1, 1
1661  start_(i) = 0
1662  count_(i) = size(val, 1-i+1)
1663  end do
1664  end if
1665 
1666  !$acc update host(val) if(acc_is_present(val))
1667 
1668 #ifdef NVIDIA
1669  block
1670  real(dp), allocatable, target :: work(:)
1671  allocate(work, source=val)
1672 #endif
1674  file_files(fid)%fid, cstr(name), & ! (in)
1675 #if defined(__GFORTRAN__) && __GNUC__ < 7
1676  cloc(val(1)), & ! (in)
1677 #elif defined(NVIDIA)
1678  c_loc(work), & ! (in)
1679 #else
1680  c_loc(val), & ! (in)
1681 #endif
1682  ndims_, dp, & ! (in)
1683  start_, count_ ) ! (in)
1684 
1685  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1686  log_error("FILE_write_associatedCoordinate_realDP_1D",*) 'failed to write associated coordinate: '//trim(name)
1687  call prc_abort
1688  end if
1689 
1690 #ifdef NVIDIA
1691  end block
1692 #endif
1693 
1694  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1695 
1696  return
1697  end subroutine file_write_associatedcoordinate_realdp_1d
1698  subroutine file_write_associatedcoordinate_realsp_2d( &
1699  fid, &
1700  name, &
1701  val, &
1702  start, count, &
1703  ndims )
1704  integer, intent(in) :: fid
1705  character(len=*), intent(in) :: name
1706 #ifdef NVIDIA
1707  real(sp), intent(in) :: val(:,:)
1708 #else
1709  real(sp), intent(in), target, contiguous :: val(:,:)
1710 #endif
1711  integer, intent(in), optional :: start(:)
1712  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1713  integer, intent(in), optional :: ndims ! in case val has been reshaped
1714 
1715  integer :: ndims_
1716  integer, allocatable :: start_(:), count_(:)
1717  integer :: error
1718  integer :: i
1719  intrinsic shape, size
1720 
1721  if ( .not. file_opened(fid) ) then
1722  log_error("FILE_write_associatedCoordinate_realSP_2D",*) 'File is not opened. fid = ', fid
1723  call prc_abort
1724  end if
1725 
1726  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1727 
1728  if ( present(ndims) ) then
1729  ndims_ = ndims
1730  else
1731  ndims_ = 2
1732  end if
1733  allocate( start_(ndims_), count_(ndims_) )
1734 
1735  if ( present(ndims) ) then
1736  ! Note this is called for history coordinates which have been reshaped
1737  ! from 2D/3D into 1D array. In this case, start and count must be also present
1738  do i = 1, ndims_
1739  start_(i) = start(ndims_-i+1) - 1
1740  count_(i) = count(ndims_-i+1)
1741  end do
1742  else if ( present(start) ) then
1743  ! Note this is called for restart coordinates
1744  do i = 1, ndims_
1745  start_(i) = start(2-i+1) - 1
1746  count_(i) = size(val, 2-i+1)
1747  end do
1748  else
1749  ! Note this is for the one-file-per-process I/O method
1750  do i = 1, 2
1751  start_(i) = 0
1752  count_(i) = size(val, 2-i+1)
1753  end do
1754  end if
1755 
1756  !$acc update host(val) if(acc_is_present(val))
1757 
1758 #ifdef NVIDIA
1759  block
1760  real(sp), allocatable, target :: work(:,:)
1761  allocate(work, source=val)
1762 #endif
1764  file_files(fid)%fid, cstr(name), & ! (in)
1765 #if defined(__GFORTRAN__) && __GNUC__ < 7
1766  cloc(val(1,1)), & ! (in)
1767 #elif defined(NVIDIA)
1768  c_loc(work), & ! (in)
1769 #else
1770  c_loc(val), & ! (in)
1771 #endif
1772  ndims_, sp, & ! (in)
1773  start_, count_ ) ! (in)
1774 
1775  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1776  log_error("FILE_write_associatedCoordinate_realSP_2D",*) 'failed to write associated coordinate: '//trim(name)
1777  call prc_abort
1778  end if
1779 
1780 #ifdef NVIDIA
1781  end block
1782 #endif
1783 
1784  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1785 
1786  return
1787  end subroutine file_write_associatedcoordinate_realsp_2d
1788  subroutine file_write_associatedcoordinate_realdp_2d( &
1789  fid, &
1790  name, &
1791  val, &
1792  start, count, &
1793  ndims )
1794  integer, intent(in) :: fid
1795  character(len=*), intent(in) :: name
1796 #ifdef NVIDIA
1797  real(dp), intent(in) :: val(:,:)
1798 #else
1799  real(dp), intent(in), target, contiguous :: val(:,:)
1800 #endif
1801  integer, intent(in), optional :: start(:)
1802  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1803  integer, intent(in), optional :: ndims ! in case val has been reshaped
1804 
1805  integer :: ndims_
1806  integer, allocatable :: start_(:), count_(:)
1807  integer :: error
1808  integer :: i
1809  intrinsic shape, size
1810 
1811  if ( .not. file_opened(fid) ) then
1812  log_error("FILE_write_associatedCoordinate_realDP_2D",*) 'File is not opened. fid = ', fid
1813  call prc_abort
1814  end if
1815 
1816  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1817 
1818  if ( present(ndims) ) then
1819  ndims_ = ndims
1820  else
1821  ndims_ = 2
1822  end if
1823  allocate( start_(ndims_), count_(ndims_) )
1824 
1825  if ( present(ndims) ) then
1826  ! Note this is called for history coordinates which have been reshaped
1827  ! from 2D/3D into 1D array. In this case, start and count must be also present
1828  do i = 1, ndims_
1829  start_(i) = start(ndims_-i+1) - 1
1830  count_(i) = count(ndims_-i+1)
1831  end do
1832  else if ( present(start) ) then
1833  ! Note this is called for restart coordinates
1834  do i = 1, ndims_
1835  start_(i) = start(2-i+1) - 1
1836  count_(i) = size(val, 2-i+1)
1837  end do
1838  else
1839  ! Note this is for the one-file-per-process I/O method
1840  do i = 1, 2
1841  start_(i) = 0
1842  count_(i) = size(val, 2-i+1)
1843  end do
1844  end if
1845 
1846  !$acc update host(val) if(acc_is_present(val))
1847 
1848 #ifdef NVIDIA
1849  block
1850  real(dp), allocatable, target :: work(:,:)
1851  allocate(work, source=val)
1852 #endif
1854  file_files(fid)%fid, cstr(name), & ! (in)
1855 #if defined(__GFORTRAN__) && __GNUC__ < 7
1856  cloc(val(1,1)), & ! (in)
1857 #elif defined(NVIDIA)
1858  c_loc(work), & ! (in)
1859 #else
1860  c_loc(val), & ! (in)
1861 #endif
1862  ndims_, dp, & ! (in)
1863  start_, count_ ) ! (in)
1864 
1865  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1866  log_error("FILE_write_associatedCoordinate_realDP_2D",*) 'failed to write associated coordinate: '//trim(name)
1867  call prc_abort
1868  end if
1869 
1870 #ifdef NVIDIA
1871  end block
1872 #endif
1873 
1874  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1875 
1876  return
1877  end subroutine file_write_associatedcoordinate_realdp_2d
1878  subroutine file_write_associatedcoordinate_realsp_3d( &
1879  fid, &
1880  name, &
1881  val, &
1882  start, count, &
1883  ndims )
1884  integer, intent(in) :: fid
1885  character(len=*), intent(in) :: name
1886 #ifdef NVIDIA
1887  real(sp), intent(in) :: val(:,:,:)
1888 #else
1889  real(sp), intent(in), target, contiguous :: val(:,:,:)
1890 #endif
1891  integer, intent(in), optional :: start(:)
1892  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1893  integer, intent(in), optional :: ndims ! in case val has been reshaped
1894 
1895  integer :: ndims_
1896  integer, allocatable :: start_(:), count_(:)
1897  integer :: error
1898  integer :: i
1899  intrinsic shape, size
1900 
1901  if ( .not. file_opened(fid) ) then
1902  log_error("FILE_write_associatedCoordinate_realSP_3D",*) 'File is not opened. fid = ', fid
1903  call prc_abort
1904  end if
1905 
1906  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1907 
1908  if ( present(ndims) ) then
1909  ndims_ = ndims
1910  else
1911  ndims_ = 3
1912  end if
1913  allocate( start_(ndims_), count_(ndims_) )
1914 
1915  if ( present(ndims) ) then
1916  ! Note this is called for history coordinates which have been reshaped
1917  ! from 2D/3D into 1D array. In this case, start and count must be also present
1918  do i = 1, ndims_
1919  start_(i) = start(ndims_-i+1) - 1
1920  count_(i) = count(ndims_-i+1)
1921  end do
1922  else if ( present(start) ) then
1923  ! Note this is called for restart coordinates
1924  do i = 1, ndims_
1925  start_(i) = start(3-i+1) - 1
1926  count_(i) = size(val, 3-i+1)
1927  end do
1928  else
1929  ! Note this is for the one-file-per-process I/O method
1930  do i = 1, 3
1931  start_(i) = 0
1932  count_(i) = size(val, 3-i+1)
1933  end do
1934  end if
1935 
1936  !$acc update host(val) if(acc_is_present(val))
1937 
1938 #ifdef NVIDIA
1939  block
1940  real(sp), allocatable, target :: work(:,:,:)
1941  allocate(work, source=val)
1942 #endif
1944  file_files(fid)%fid, cstr(name), & ! (in)
1945 #if defined(__GFORTRAN__) && __GNUC__ < 7
1946  cloc(val(1,1,1)), & ! (in)
1947 #elif defined(NVIDIA)
1948  c_loc(work), & ! (in)
1949 #else
1950  c_loc(val), & ! (in)
1951 #endif
1952  ndims_, sp, & ! (in)
1953  start_, count_ ) ! (in)
1954 
1955  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1956  log_error("FILE_write_associatedCoordinate_realSP_3D",*) 'failed to write associated coordinate: '//trim(name)
1957  call prc_abort
1958  end if
1959 
1960 #ifdef NVIDIA
1961  end block
1962 #endif
1963 
1964  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1965 
1966  return
1967  end subroutine file_write_associatedcoordinate_realsp_3d
1968  subroutine file_write_associatedcoordinate_realdp_3d( &
1969  fid, &
1970  name, &
1971  val, &
1972  start, count, &
1973  ndims )
1974  integer, intent(in) :: fid
1975  character(len=*), intent(in) :: name
1976 #ifdef NVIDIA
1977  real(dp), intent(in) :: val(:,:,:)
1978 #else
1979  real(dp), intent(in), target, contiguous :: val(:,:,:)
1980 #endif
1981  integer, intent(in), optional :: start(:)
1982  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1983  integer, intent(in), optional :: ndims ! in case val has been reshaped
1984 
1985  integer :: ndims_
1986  integer, allocatable :: start_(:), count_(:)
1987  integer :: error
1988  integer :: i
1989  intrinsic shape, size
1990 
1991  if ( .not. file_opened(fid) ) then
1992  log_error("FILE_write_associatedCoordinate_realDP_3D",*) 'File is not opened. fid = ', fid
1993  call prc_abort
1994  end if
1995 
1996  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1997 
1998  if ( present(ndims) ) then
1999  ndims_ = ndims
2000  else
2001  ndims_ = 3
2002  end if
2003  allocate( start_(ndims_), count_(ndims_) )
2004 
2005  if ( present(ndims) ) then
2006  ! Note this is called for history coordinates which have been reshaped
2007  ! from 2D/3D into 1D array. In this case, start and count must be also present
2008  do i = 1, ndims_
2009  start_(i) = start(ndims_-i+1) - 1
2010  count_(i) = count(ndims_-i+1)
2011  end do
2012  else if ( present(start) ) then
2013  ! Note this is called for restart coordinates
2014  do i = 1, ndims_
2015  start_(i) = start(3-i+1) - 1
2016  count_(i) = size(val, 3-i+1)
2017  end do
2018  else
2019  ! Note this is for the one-file-per-process I/O method
2020  do i = 1, 3
2021  start_(i) = 0
2022  count_(i) = size(val, 3-i+1)
2023  end do
2024  end if
2025 
2026  !$acc update host(val) if(acc_is_present(val))
2027 
2028 #ifdef NVIDIA
2029  block
2030  real(dp), allocatable, target :: work(:,:,:)
2031  allocate(work, source=val)
2032 #endif
2034  file_files(fid)%fid, cstr(name), & ! (in)
2035 #if defined(__GFORTRAN__) && __GNUC__ < 7
2036  cloc(val(1,1,1)), & ! (in)
2037 #elif defined(NVIDIA)
2038  c_loc(work), & ! (in)
2039 #else
2040  c_loc(val), & ! (in)
2041 #endif
2042  ndims_, dp, & ! (in)
2043  start_, count_ ) ! (in)
2044 
2045  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2046  log_error("FILE_write_associatedCoordinate_realDP_3D",*) 'failed to write associated coordinate: '//trim(name)
2047  call prc_abort
2048  end if
2049 
2050 #ifdef NVIDIA
2051  end block
2052 #endif
2053 
2054  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2055 
2056  return
2057  end subroutine file_write_associatedcoordinate_realdp_3d
2058  subroutine file_write_associatedcoordinate_realsp_4d( &
2059  fid, &
2060  name, &
2061  val, &
2062  start, count, &
2063  ndims )
2064  integer, intent(in) :: fid
2065  character(len=*), intent(in) :: name
2066 #ifdef NVIDIA
2067  real(sp), intent(in) :: val(:,:,:,:)
2068 #else
2069  real(sp), intent(in), target, contiguous :: val(:,:,:,:)
2070 #endif
2071  integer, intent(in), optional :: start(:)
2072  integer, intent(in), optional :: count(:) ! in case val has been reshaped
2073  integer, intent(in), optional :: ndims ! in case val has been reshaped
2074 
2075  integer :: ndims_
2076  integer, allocatable :: start_(:), count_(:)
2077  integer :: error
2078  integer :: i
2079  intrinsic shape, size
2080 
2081  if ( .not. file_opened(fid) ) then
2082  log_error("FILE_write_associatedCoordinate_realSP_4D",*) 'File is not opened. fid = ', fid
2083  call prc_abort
2084  end if
2085 
2086  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2087 
2088  if ( present(ndims) ) then
2089  ndims_ = ndims
2090  else
2091  ndims_ = 4
2092  end if
2093  allocate( start_(ndims_), count_(ndims_) )
2094 
2095  if ( present(ndims) ) then
2096  ! Note this is called for history coordinates which have been reshaped
2097  ! from 2D/3D into 1D array. In this case, start and count must be also present
2098  do i = 1, ndims_
2099  start_(i) = start(ndims_-i+1) - 1
2100  count_(i) = count(ndims_-i+1)
2101  end do
2102  else if ( present(start) ) then
2103  ! Note this is called for restart coordinates
2104  do i = 1, ndims_
2105  start_(i) = start(4-i+1) - 1
2106  count_(i) = size(val, 4-i+1)
2107  end do
2108  else
2109  ! Note this is for the one-file-per-process I/O method
2110  do i = 1, 4
2111  start_(i) = 0
2112  count_(i) = size(val, 4-i+1)
2113  end do
2114  end if
2115 
2116  !$acc update host(val) if(acc_is_present(val))
2117 
2118 #ifdef NVIDIA
2119  block
2120  real(sp), allocatable, target :: work(:,:,:,:)
2121  allocate(work, source=val)
2122 #endif
2124  file_files(fid)%fid, cstr(name), & ! (in)
2125 #if defined(__GFORTRAN__) && __GNUC__ < 7
2126  cloc(val(1,1,1,1)), & ! (in)
2127 #elif defined(NVIDIA)
2128  c_loc(work), & ! (in)
2129 #else
2130  c_loc(val), & ! (in)
2131 #endif
2132  ndims_, sp, & ! (in)
2133  start_, count_ ) ! (in)
2134 
2135  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2136  log_error("FILE_write_associatedCoordinate_realSP_4D",*) 'failed to write associated coordinate: '//trim(name)
2137  call prc_abort
2138  end if
2139 
2140 #ifdef NVIDIA
2141  end block
2142 #endif
2143 
2144  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2145 
2146  return
2147  end subroutine file_write_associatedcoordinate_realsp_4d
2148  subroutine file_write_associatedcoordinate_realdp_4d( &
2149  fid, &
2150  name, &
2151  val, &
2152  start, count, &
2153  ndims )
2154  integer, intent(in) :: fid
2155  character(len=*), intent(in) :: name
2156 #ifdef NVIDIA
2157  real(dp), intent(in) :: val(:,:,:,:)
2158 #else
2159  real(dp), intent(in), target, contiguous :: val(:,:,:,:)
2160 #endif
2161  integer, intent(in), optional :: start(:)
2162  integer, intent(in), optional :: count(:) ! in case val has been reshaped
2163  integer, intent(in), optional :: ndims ! in case val has been reshaped
2164 
2165  integer :: ndims_
2166  integer, allocatable :: start_(:), count_(:)
2167  integer :: error
2168  integer :: i
2169  intrinsic shape, size
2170 
2171  if ( .not. file_opened(fid) ) then
2172  log_error("FILE_write_associatedCoordinate_realDP_4D",*) 'File is not opened. fid = ', fid
2173  call prc_abort
2174  end if
2175 
2176  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2177 
2178  if ( present(ndims) ) then
2179  ndims_ = ndims
2180  else
2181  ndims_ = 4
2182  end if
2183  allocate( start_(ndims_), count_(ndims_) )
2184 
2185  if ( present(ndims) ) then
2186  ! Note this is called for history coordinates which have been reshaped
2187  ! from 2D/3D into 1D array. In this case, start and count must be also present
2188  do i = 1, ndims_
2189  start_(i) = start(ndims_-i+1) - 1
2190  count_(i) = count(ndims_-i+1)
2191  end do
2192  else if ( present(start) ) then
2193  ! Note this is called for restart coordinates
2194  do i = 1, ndims_
2195  start_(i) = start(4-i+1) - 1
2196  count_(i) = size(val, 4-i+1)
2197  end do
2198  else
2199  ! Note this is for the one-file-per-process I/O method
2200  do i = 1, 4
2201  start_(i) = 0
2202  count_(i) = size(val, 4-i+1)
2203  end do
2204  end if
2205 
2206  !$acc update host(val) if(acc_is_present(val))
2207 
2208 #ifdef NVIDIA
2209  block
2210  real(dp), allocatable, target :: work(:,:,:,:)
2211  allocate(work, source=val)
2212 #endif
2214  file_files(fid)%fid, cstr(name), & ! (in)
2215 #if defined(__GFORTRAN__) && __GNUC__ < 7
2216  cloc(val(1,1,1,1)), & ! (in)
2217 #elif defined(NVIDIA)
2218  c_loc(work), & ! (in)
2219 #else
2220  c_loc(val), & ! (in)
2221 #endif
2222  ndims_, dp, & ! (in)
2223  start_, count_ ) ! (in)
2224 
2225  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2226  log_error("FILE_write_associatedCoordinate_realDP_4D",*) 'failed to write associated coordinate: '//trim(name)
2227  call prc_abort
2228  end if
2229 
2230 #ifdef NVIDIA
2231  end block
2232 #endif
2233 
2234  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2235 
2236  return
2237  end subroutine file_write_associatedcoordinate_realdp_4d
2238 
2239  !-----------------------------------------------------------------------------
2240  ! interface FILE_add_variable
2241  !-----------------------------------------------------------------------------
2242  subroutine file_add_variable_no_time( &
2243  fid, &
2244  varname, desc, units, &
2245  standard_name, &
2246  dims, dtype, &
2247  vid, &
2248  time_stats )
2249  integer, intent( in) :: fid
2250  character(len=*), intent( in) :: varname
2251  character(len=*), intent( in) :: desc
2252  character(len=*), intent( in) :: units
2253  character(len=*), intent( in) :: standard_name
2254  character(len=*), intent( in) :: dims(:)
2255  integer, intent( in) :: dtype
2256  integer, intent(out) :: vid
2257  character(len=*), intent( in), optional :: time_stats
2258 
2259  if ( .not. file_opened(fid) ) then
2260  log_error("FILE_add_variable_no_time",*) 'File is not opened. fid = ', fid
2261  call prc_abort
2262  end if
2263 
2264  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2265 
2266  call file_add_variable_with_time( fid, & ! (in)
2267  varname, desc, units, standard_name, & ! (in)
2268  dims, dtype, -1.0_dp, & ! (in)
2269  vid, & ! (out)
2270  time_stats = time_stats ) ! (in)
2271 
2272  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2273 
2274  return
2275  end subroutine file_add_variable_no_time
2276 
2277  !-----------------------------------------------------------------------------
2278  subroutine file_add_variable_with_time( &
2279  fid, &
2280  varname, desc, units, &
2281  standard_name, &
2282  dims, dtype, &
2283  time_int, &
2284  vid, &
2285  time_stats )
2286  implicit none
2287  integer, intent(in) :: fid
2288  character(len=*), intent(in) :: varname
2289  character(len=*), intent(in) :: desc
2290  character(len=*), intent(in) :: units
2291  character(len=*), intent(in) :: standard_name
2292  character(len=*), intent(in) :: dims(:)
2293  integer, intent(in) :: dtype
2294  real(dp), intent(in) :: time_int
2295 
2296  integer, intent(out) :: vid
2297 
2298  character(len=*), intent(in), optional :: time_stats
2299 
2300  type(c_ptr) :: dims_(size(dims))
2301  !character(:,c_char), allocatable, target :: cptr(:)
2302  character(len=H_SHORT), allocatable, target :: cptr(:)
2303 
2304  character(len=4) :: ctstats
2305 
2306  integer :: cvid
2307  integer :: ndims
2308  integer :: error
2309  integer :: n
2310 
2311  intrinsic size
2312  !---------------------------------------------------------------------------
2313 
2314  if ( .not. file_opened(fid) ) then
2315  log_error("FILE_add_variable_with_time",*) 'File is not opened. fid = ', fid
2316  call prc_abort
2317  end if
2318 
2319  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2320 
2321  vid = -1
2322  do n = 1, file_nvars
2323  if ( file_vars(n)%fid == fid .and. file_vars(n)%name == varname ) then
2324  vid = file_vars(n)%vid
2325  exit
2326  endif
2327  enddo
2328 
2329  if ( vid < 0 ) then ! variable registration
2330 
2331  ndims = size(dims)
2332 
2333  ctstats = "none"
2334  if ( present(time_stats) ) then
2335  ctstats = time_stats
2336  endif
2337 
2338  !allocate( character(len=len(dims)+1) :: cptr(ndims) )
2339  allocate( cptr(ndims) )
2340  do n = 1, ndims
2341  cptr(n) = cstr(dims(n))
2342  dims_(n) = c_loc(cptr(n))
2343  end do
2344 
2345  error = file_add_variable_c( cvid, & ! [OUT]
2346  file_files(fid)%fid, & ! [IN]
2347  cstr(varname), cstr(desc), & ! [IN]
2348  cstr(units), cstr(standard_name), & ! [IN]
2349  dims_, ndims, dtype, & ! [IN]
2350  time_int, cstr(ctstats) ) ! [IN]
2351 
2352  if ( error /= file_success_code ) then
2353  log_error("FILE_add_variable_with_time",*) 'failed to add variable: '//trim(varname)
2354  call prc_abort
2355  endif
2356 
2357  file_nvars = file_nvars + 1
2358  vid = file_nvars
2359  file_vars(vid)%name = varname
2360  file_vars(vid)%vid = cvid
2361  file_vars(vid)%fid = fid
2362 
2363  log_info("FILE_add_variable_with_time",'(1x,A,I3.3,A,I4.4,2A)') &
2364  'Variable registration : NO.', fid, ', vid = ', vid, ', name = ', trim(varname)
2365  endif
2366 
2367  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2368 
2369  return
2370  end subroutine file_add_variable_with_time
2371 
2372  subroutine file_def_variable( &
2373  fid, &
2374  varname, desc, units, &
2375  standard_name, &
2376  ndims, dims, &
2377  dtype, &
2378  vid, &
2379  time_int, time_stats, &
2380  existed )
2381  integer, intent( in) :: fid
2382  character(len=*), intent( in) :: varname
2383  character(len=*), intent( in) :: desc
2384  character(len=*), intent( in) :: units
2385  character(len=*), intent( in) :: standard_name
2386  integer, intent( in) :: ndims
2387  character(len=*), intent( in) :: dims(:)
2388  integer, intent( in) :: dtype
2389  integer, intent(out) :: vid
2390  real(dp), intent( in), optional :: time_int
2391  character(len=*), intent( in), optional :: time_stats
2392  logical, intent(out), optional :: existed
2393 
2394  type(c_ptr) :: dims_(size(dims))
2395  !character(:,c_char), allocatable, target :: cptr(:)
2396  character(len=H_SHORT), allocatable, target :: cptr(:)
2397 
2398  character(len=4) :: ctstats
2399 
2400  real(dp) :: tint_
2401  integer :: cvid
2402  integer :: error
2403  integer :: n
2404 
2405  !---------------------------------------------------------------------------
2406 
2407  if ( .not. file_opened(fid) ) then
2408  log_error("FILE_def_variable",*) 'File is not opened. fid = ', fid
2409  call prc_abort
2410  end if
2411 
2412  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2413 
2414  vid = -1
2415  do n = 1, file_nvars
2416  if ( file_vars(n)%fid == fid .and. file_vars(n)%name == varname ) then
2417  vid = n
2418  end if
2419  enddo
2420 
2421  if ( vid < 0 ) then ! variable registration
2422 
2423  if ( present(time_int) ) then
2424  tint_ = time_int
2425  else
2426  tint_ = -1.0_dp
2427  endif
2428 
2429  ctstats = "none"
2430  if ( present(time_stats) ) then
2431  ctstats = time_stats
2432  end if
2433 
2434  !allocate( character(len=len(dims)+1) :: cptr(ndims) )
2435  allocate( cptr(ndims) )
2436  do n = 1, ndims
2437  cptr(n) = cstr(dims(n))
2438  dims_(n) = c_loc(cptr(n))
2439  end do
2440 
2441  error = file_add_variable_c( cvid, & ! [OUT]
2442  file_files(fid)%fid, & ! [IN]
2443  cstr(varname), cstr(desc), & ! [IN]
2444  cstr(units), cstr(standard_name), & ! [IN]
2445  dims_, ndims, dtype, tint_, cstr(ctstats) ) ! [IN]
2446 
2447  if ( error /= file_success_code ) then
2448  log_error("FILE_def_variable",*) 'failed to add variable: '//trim(varname)
2449  call prc_abort
2450  end if
2451 
2452  file_nvars = file_nvars + 1
2453  vid = file_nvars
2454  file_vars(vid)%name = varname
2455  file_vars(vid)%vid = cvid
2456  file_vars(vid)%fid = fid
2457 
2458  log_info("FILE_def_variable",'(1x,A,I3.3,A,I4.4,2A)') &
2459  'Variable registration : NO.', fid, ', vid = ', vid, ', name = ', trim(varname)
2460 
2461  if ( present(existed) ) existed = .false.
2462  else
2463  if ( present(existed) ) existed = .true.
2464  endif
2465 
2466  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2467 
2468  return
2469  end subroutine file_def_variable
2470 
2471  !-----------------------------------------------------------------------------
2472  ! FILE_Get_Attribute
2473  !-----------------------------------------------------------------------------
2474  subroutine file_get_attribute_text_fid( &
2475  fid, &
2476  vname, key, &
2477  val, &
2478  existed )
2479  integer, intent(in ) :: fid
2480  character(len=*), intent(in ) :: vname
2481  character(len=*), intent(in ) :: key
2482  character(len=*), intent(out) :: val
2483 
2484  logical, intent(out), optional :: existed
2485 
2486  logical(c_bool) :: suppress
2487  integer :: error
2488 
2489  if ( .not. file_opened(fid) ) then
2490  log_error("FILE_get_attribute_text_fid",*) 'File is not opened. fid = ', fid
2491  call prc_abort
2492  end if
2493 
2494  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2495 
2496  if ( present(existed) ) then
2497  suppress = .true.
2498  else
2499  suppress = .false.
2500  end if
2501  error = file_get_attribute_text_c( val, & ! (out)
2502  file_files(fid)%fid, & ! (in)
2503  cstr(vname), cstr(key), & ! (in)
2504  suppress, len(val) ) ! (in)
2505  if ( error == file_success_code ) then
2506  if ( present(existed) ) existed = .true.
2507  call fstr(val)
2508  else
2509  if ( present(existed) ) then
2510  existed = .false.
2511  else
2512  log_error("FILE_get_attribute_text_fid",*) 'failed to get text attribute for '//trim(vname)//': '//trim(key)
2513  call prc_abort
2514  end if
2515  end if
2516 
2517  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2518 
2519  return
2520  end subroutine file_get_attribute_text_fid
2521  subroutine file_get_attribute_text_fname( &
2522  basename, vname, key, &
2523  val, &
2524  single, aggregate, rankid, &
2525  existed )
2526  implicit none
2527 
2528  character(len=*), intent(in) :: basename
2529  character(len=*), intent(in) :: vname
2530  character(len=*), intent(in) :: key
2531 
2532  character(len=*), intent(out) :: val
2533 
2534  logical, intent(in), optional :: single
2535  logical, intent(in), optional :: aggregate
2536  integer, intent(in), optional :: rankid
2537 
2538  logical, intent(out), optional :: existed
2539  integer :: fid
2540 
2541  call file_open( basename, & ! (in)
2542  fid, & ! (out)
2543  single=single, & ! (in)
2544  aggregate=aggregate, & ! (in)
2545  rankid=rankid ) ! (in)
2546 
2547  call file_get_attribute_text_fid( &
2548  fid, vname, key, & ! (in)
2549  val, & ! (out)
2550  existed ) ! (out)
2551 
2552  return
2553  end subroutine file_get_attribute_text_fname
2554 
2555  !-----------------------------------------------------------------------------
2556  subroutine file_get_attribute_logical_fid( &
2557  fid, &
2558  vname, key, &
2559  val, &
2560  existed )
2561  integer, intent(in ) :: fid
2562  character(len=*), intent(in ) :: vname
2563  character(len=*), intent(in ) :: key
2564  logical, intent(out) :: val
2565 
2566  logical, intent(out), optional :: existed
2567 
2568  character(len=6) :: buf ! max length is for "false\0"
2569 
2570  if ( .not. file_opened(fid) ) then
2571  log_error("FILE_get_attribute_logical_fid",*) 'File is not opened. fid = ', fid
2572  call prc_abort
2573  end if
2574 
2575  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2576 
2577  call file_get_attribute_text_fid( fid, vname, key, & ! (in)
2578  buf, existed ) ! (out)
2579 
2580  if ( present(existed) ) then
2581  if ( .not. existed ) return
2582  end if
2583 
2584  if ( buf == "true" ) then
2585  val = .true.
2586  else if ( buf == "false" ) then
2587  val = .false.
2588  else
2589  log_error("FILE_get_attribute_logical_fid",*) 'value is not eigher true or false'
2590  call prc_abort
2591  end if
2592 
2593  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2594 
2595  return
2596  end subroutine file_get_attribute_logical_fid
2597  subroutine file_get_attribute_logical_fname( &
2598  basename, vname, key, &
2599  val, &
2600  single, aggregate, rankid, &
2601  existed )
2602  implicit none
2603 
2604  character(len=*), intent(in) :: basename
2605  character(len=*), intent(in) :: vname
2606  character(len=*), intent(in) :: key
2607 
2608  logical, intent(out) :: val
2609 
2610  logical, intent(in), optional :: single
2611  logical, intent(in), optional :: aggregate
2612  integer, intent(in), optional :: rankid
2613 
2614  logical, intent(out), optional :: existed
2615  integer :: fid
2616 
2617  call file_open( basename, & ! (in)
2618  fid, & ! (out)
2619  single=single, & ! (in)
2620  aggregate=aggregate, & ! (in)
2621  rankid=rankid ) ! (in)
2622 
2623  call file_get_attribute_logical_fid( &
2624  fid, vname, key, & ! (in)
2625  val, & ! (out)
2626  existed ) ! (out)
2627 
2628  return
2629  end subroutine file_get_attribute_logical_fname
2630 
2631  !-----------------------------------------------------------------------------
2632  subroutine file_get_attribute_int_fid_ary( &
2633  fid, vname, key, &
2634  val, &
2635  existed )
2636  integer, intent(in ) :: fid
2637  character(len=*), intent(in ) :: vname
2638  character(len=*), intent(in ) :: key
2639  integer, intent(out) :: val(:)
2640 
2641  logical, intent(out), optional :: existed
2642 
2643  logical(c_bool) :: suppress
2644  integer :: error
2645 
2646  intrinsic size
2647 
2648  if ( .not. file_opened(fid) ) then
2649  log_error("FILE_get_attribute_int_fid",*) 'File is not opened. fid = ', fid
2650  call prc_abort
2651  end if
2652 
2653  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2654 
2655  if ( present(existed) ) then
2656  suppress = .true.
2657  else
2658  suppress = .false.
2659  end if
2660  error = file_get_attribute_int_c( val(:), & ! (out)
2661  file_files(fid)%fid, & ! (in)
2662  cstr(vname), cstr(key), & ! (in)
2663  suppress, size(val) ) ! (in)
2664  if ( error /= file_success_code ) then
2665  if ( present(existed) ) then
2666  existed = .false.
2667  else
2668  log_error("FILE_get_attribute_int_fid",*) 'failed to get integer attribute for '//trim(vname)//': '//trim(key)
2669  call prc_abort
2670  end if
2671  else
2672  if ( present(existed) ) existed = .true.
2673  end if
2674 
2675  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2676 
2677  return
2678  end subroutine file_get_attribute_int_fid_ary
2679  subroutine file_get_attribute_int_fid( &
2680  fid, vname, key, &
2681  val, &
2682  existed )
2683  integer, intent(in ) :: fid
2684  character(len=*), intent(in ) :: vname
2685  character(len=*), intent(in ) :: key
2686  integer, intent(out) :: val
2687  logical, intent(out), optional :: existed
2688  integer :: ary(1)
2689 
2690  call file_get_attribute_int_fid_ary( &
2691  fid, vname, key, &
2692  ary(:), &
2693  existed )
2694  if ( present(existed) ) then
2695  if ( .not. existed ) return
2696  end if
2697  val = ary(1)
2698 
2699  return
2700  end subroutine file_get_attribute_int_fid
2701  subroutine file_get_attribute_int_fname_ary( &
2702  basename, vname, key, &
2703  val, &
2704  single, aggregate, rankid, &
2705  existed )
2706  implicit none
2707 
2708  character(len=*), intent(in) :: basename
2709  character(len=*), intent(in) :: vname
2710  character(len=*), intent(in) :: key
2711 
2712  integer, intent(out) :: val(:)
2713 
2714  logical, intent(in), optional :: single
2715  logical, intent(in), optional :: aggregate
2716  integer, intent(in), optional :: rankid
2717 
2718  logical, intent(out), optional :: existed
2719 
2720  integer :: fid
2721 
2722  call file_open( basename, & ! (in)
2723  fid, & ! (out)
2724  single=single, & ! (in)
2725  aggregate=aggregate, &
2726  rankid=rankid ) ! (in)
2727 
2728  call file_get_attribute_int_fid_ary( &
2729  fid, vname, key, & ! (in)
2730  val, & ! (out)
2731  existed ) ! (out)
2732 
2733  return
2734  end subroutine file_get_attribute_int_fname_ary
2735  subroutine file_get_attribute_int_fname( &
2736  basename, vname, key, &
2737  val, &
2738  single, aggregate, rankid, &
2739  existed )
2740  implicit none
2741  character(len=*), intent(in) :: basename
2742  character(len=*), intent(in) :: vname
2743  character(len=*), intent(in) :: key
2744  integer, intent(out) :: val
2745  logical, intent(in), optional :: single
2746  logical, intent(in), optional :: aggregate
2747  integer, intent(in), optional :: rankid
2748  logical, intent(out), optional :: existed
2749  integer :: ary(1)
2750 
2751  call file_get_attribute_int_fname_ary( &
2752  basename, vname, key, &
2753  ary(:), &
2754  single, aggregate, rankid, &
2755  existed )
2756  val = ary(1)
2757 
2758  return
2759  end subroutine file_get_attribute_int_fname
2760  !-----------------------------------------------------------------------------
2761 
2762  subroutine file_get_attribute_float_fid_ary( &
2763  fid, vname, key, &
2764  val, &
2765  existed )
2766  integer, intent(in ) :: fid
2767  character(len=*), intent(in ) :: vname
2768  character(len=*), intent(in ) :: key
2769  real(sp), intent(out) :: val(:)
2770 
2771  logical, intent(out), optional :: existed
2772 
2773  logical(c_bool) :: suppress
2774  integer :: error
2775 
2776  intrinsic size
2777 
2778  if ( .not. file_opened(fid) ) then
2779  log_error("FILE_get_attribute_float_fid",*) 'File is not opened. fid = ', fid
2780  call prc_abort
2781  end if
2782 
2783  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2784 
2785  if ( present(existed) ) then
2786  suppress = .true.
2787  else
2788  suppress = .false.
2789  end if
2790  error = file_get_attribute_float_c( val, & ! (out)
2791  file_files(fid)%fid, & ! (in)
2792  cstr(vname), cstr(key), & ! (in)
2793  suppress, size(val) ) ! (in)
2794  if ( error /= file_success_code ) then
2795  if ( present(existed) ) then
2796  existed = .false.
2797  else
2798  log_error("FILE_get_attribute_float_fid",*) 'failed to get float attribute for '//trim(vname)//': '//trim(key)
2799  call prc_abort
2800  end if
2801  else
2802  if ( present(existed) ) existed = .true.
2803  end if
2804 
2805  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2806 
2807  return
2808  end subroutine file_get_attribute_float_fid_ary
2809  subroutine file_get_attribute_float_fid( &
2810  fid, vname, key, &
2811  val, &
2812  existed )
2813  integer, intent(in ) :: fid
2814  character(len=*), intent(in ) :: vname
2815  character(len=*), intent(in ) :: key
2816  real(sp), intent(out) :: val
2817  logical, intent(out), optional :: existed
2818  real(sp) :: ary(1)
2819 
2820  call file_get_attribute_float_fid_ary( &
2821  fid, vname, key, &
2822  ary(:), &
2823  existed )
2824  if ( present(existed) ) then
2825  if ( .not. existed ) return
2826  end if
2827  val = ary(1)
2828 
2829  return
2830  end subroutine file_get_attribute_float_fid
2831  subroutine file_get_attribute_float_fname_ary( &
2832  basename, vname, key, &
2833  val, &
2834  single, aggregate, rankid, &
2835  existed )
2836  implicit none
2837 
2838  character(len=*), intent(in) :: basename
2839  character(len=*), intent(in) :: vname
2840  character(len=*), intent(in) :: key
2841 
2842  real(sp), intent(out) :: val(:)
2843 
2844  logical, intent(in), optional :: single
2845  logical, intent(in), optional :: aggregate
2846  integer, intent(in), optional :: rankid
2847 
2848  logical, intent(out), optional :: existed
2849 
2850  integer :: fid
2851 
2852  call file_open( basename, & ! (in)
2853  fid, & ! (out)
2854  single=single, & ! (in)
2855  aggregate=aggregate, & ! (in)
2856  rankid=rankid ) ! (in)
2857 
2858  call file_get_attribute_float_fid_ary( &
2859  fid, vname, key, & ! (in)
2860  val, & ! (out)
2861  existed ) ! (out)
2862 
2863  return
2864  end subroutine file_get_attribute_float_fname_ary
2865  subroutine file_get_attribute_float_fname( &
2866  basename, vname, key, &
2867  val, &
2868  single, aggregate, rankid, &
2869  existed )
2870  implicit none
2871  character(len=*), intent(in) :: basename
2872  character(len=*), intent(in) :: vname
2873  character(len=*), intent(in) :: key
2874  real(sp), intent(out) :: val
2875  logical, intent(in), optional :: single
2876  logical, intent(in), optional :: aggregate
2877  integer, intent(in), optional :: rankid
2878  logical, intent(out), optional :: existed
2879  real(sp) :: ary(1)
2880 
2881  call file_get_attribute_float_fname_ary( &
2882  basename, vname, key, &
2883  ary(:), &
2884  single, aggregate, rankid, &
2885  existed )
2886  val = ary(1)
2887 
2888  return
2889  end subroutine file_get_attribute_float_fname
2890  subroutine file_get_attribute_double_fid_ary( &
2891  fid, vname, key, &
2892  val, &
2893  existed )
2894  integer, intent(in ) :: fid
2895  character(len=*), intent(in ) :: vname
2896  character(len=*), intent(in ) :: key
2897  real(dp), intent(out) :: val(:)
2898 
2899  logical, intent(out), optional :: existed
2900 
2901  logical(c_bool) :: suppress
2902  integer :: error
2903 
2904  intrinsic size
2905 
2906  if ( .not. file_opened(fid) ) then
2907  log_error("FILE_get_attribute_double_fid",*) 'File is not opened. fid = ', fid
2908  call prc_abort
2909  end if
2910 
2911  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2912 
2913  if ( present(existed) ) then
2914  suppress = .true.
2915  else
2916  suppress = .false.
2917  end if
2918  error = file_get_attribute_double_c( val, & ! (out)
2919  file_files(fid)%fid, & ! (in)
2920  cstr(vname), cstr(key), & ! (in)
2921  suppress, size(val) ) ! (in)
2922  if ( error /= file_success_code ) then
2923  if ( present(existed) ) then
2924  existed = .false.
2925  else
2926  log_error("FILE_get_attribute_double_fid",*) 'failed to get double attribute for '//trim(vname)//': '//trim(key)
2927  call prc_abort
2928  end if
2929  else
2930  if ( present(existed) ) existed = .true.
2931  end if
2932 
2933  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
2934 
2935  return
2936  end subroutine file_get_attribute_double_fid_ary
2937  subroutine file_get_attribute_double_fid( &
2938  fid, vname, key, &
2939  val, &
2940  existed )
2941  integer, intent(in ) :: fid
2942  character(len=*), intent(in ) :: vname
2943  character(len=*), intent(in ) :: key
2944  real(dp), intent(out) :: val
2945  logical, intent(out), optional :: existed
2946  real(dp) :: ary(1)
2947 
2948  call file_get_attribute_double_fid_ary( &
2949  fid, vname, key, &
2950  ary(:), &
2951  existed )
2952  if ( present(existed) ) then
2953  if ( .not. existed ) return
2954  end if
2955  val = ary(1)
2956 
2957  return
2958  end subroutine file_get_attribute_double_fid
2959  subroutine file_get_attribute_double_fname_ary( &
2960  basename, vname, key, &
2961  val, &
2962  single, aggregate, rankid, &
2963  existed )
2964  implicit none
2965 
2966  character(len=*), intent(in) :: basename
2967  character(len=*), intent(in) :: vname
2968  character(len=*), intent(in) :: key
2969 
2970  real(dp), intent(out) :: val(:)
2971 
2972  logical, intent(in), optional :: single
2973  logical, intent(in), optional :: aggregate
2974  integer, intent(in), optional :: rankid
2975 
2976  logical, intent(out), optional :: existed
2977 
2978  integer :: fid
2979 
2980  call file_open( basename, & ! (in)
2981  fid, & ! (out)
2982  single=single, & ! (in)
2983  aggregate=aggregate, & ! (in)
2984  rankid=rankid ) ! (in)
2985 
2986  call file_get_attribute_double_fid_ary( &
2987  fid, vname, key, & ! (in)
2988  val, & ! (out)
2989  existed ) ! (out)
2990 
2991  return
2992  end subroutine file_get_attribute_double_fname_ary
2993  subroutine file_get_attribute_double_fname( &
2994  basename, vname, key, &
2995  val, &
2996  single, aggregate, rankid, &
2997  existed )
2998  implicit none
2999  character(len=*), intent(in) :: basename
3000  character(len=*), intent(in) :: vname
3001  character(len=*), intent(in) :: key
3002  real(dp), intent(out) :: val
3003  logical, intent(in), optional :: single
3004  logical, intent(in), optional :: aggregate
3005  integer, intent(in), optional :: rankid
3006  logical, intent(out), optional :: existed
3007  real(dp) :: ary(1)
3008 
3009  call file_get_attribute_double_fname_ary( &
3010  basename, vname, key, &
3011  ary(:), &
3012  single, aggregate, rankid, &
3013  existed )
3014  val = ary(1)
3015 
3016  return
3017  end subroutine file_get_attribute_double_fname
3018 
3019  !-----------------------------------------------------------------------------
3020  ! FILE_set_attribute
3021  !-----------------------------------------------------------------------------
3022  subroutine file_set_attribute_text( &
3023  fid, vname, &
3024  key, val )
3025  integer, intent(in) :: fid
3026  character(len=*), intent(in) :: vname
3027  character(len=*), intent(in) :: key
3028  character(len=*), intent(in) :: val
3029 
3030  integer :: error
3031 
3032  if ( .not. file_opened(fid) ) then
3033  log_error("FILE_set_attribute_text",*) 'File is not opened. fid = ', fid
3034  call prc_abort
3035  end if
3036 
3037  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3038 
3039  error = file_set_attribute_text_c( file_files(fid)%fid, & ! (in)
3040  cstr(vname), cstr(key), & ! (in)
3041  cstr(val) ) ! (in)
3042  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
3043  log_error("FILE_set_attribute_text",*) 'failed to set text attribute for '//trim(vname)//': '//trim(key)
3044  call prc_abort
3045  end if
3046 
3047  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3048 
3049  return
3050  end subroutine file_set_attribute_text
3051 
3052  subroutine file_set_attribute_logical( &
3053  fid, vname, &
3054  key, val )
3055  integer, intent(in) :: fid
3056  character(len=*), intent(in) :: vname
3057  character(len=*), intent(in) :: key
3058  logical, intent(in) :: val
3059 
3060  character(len=5) :: buf
3061 
3062  if ( .not. file_opened(fid) ) then
3063  log_error("FILE_set_attribute_logical",*) 'File is not opened. fid = ', fid
3064  call prc_abort
3065  end if
3066 
3067  if ( val ) then
3068  buf = "true"
3069  else
3070  buf = "false"
3071  end if
3072 
3073  call file_set_attribute_text( fid, vname, key, buf )
3074 
3075  return
3076  end subroutine file_set_attribute_logical
3077 
3078  !-----------------------------------------------------------------------------
3079  subroutine file_set_attribute_int_ary( &
3080  fid, vname, &
3081  key, val )
3082  integer, intent(in) :: fid
3083  character(len=*), intent(in) :: vname
3084  character(len=*), intent(in) :: key
3085  integer, intent(in) :: val(:)
3086 
3087  integer :: error
3088 
3089  intrinsic size
3090 
3091  if ( .not. file_opened(fid) ) then
3092  log_error("FILE_set_attribute_int",*) 'File is not opened. fid = ', fid
3093  call prc_abort
3094  end if
3095 
3096  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3097 
3098  error = file_set_attribute_int_c( file_files(fid)%fid, & ! (in)
3099  cstr(vname), cstr(key), & ! (in)
3100  val(:), size(val(:)) ) ! (in)
3101  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
3102  log_error("FILE_set_attribute_int",*) 'failed to set integer attribute for '//trim(vname)//': '//trim(key)
3103  call prc_abort
3104  end if
3105 
3106  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3107 
3108  return
3109  end subroutine file_set_attribute_int_ary
3110 
3111  subroutine file_set_attribute_int( &
3112  fid, vname, &
3113  key, val )
3114  integer, intent(in) :: fid
3115  character(len=*), intent(in) :: vname
3116  character(len=*), intent(in) :: key
3117  integer, intent(in) :: val
3118 
3119  integer :: ary(1)
3120 
3121  ary(1) = val
3122  call file_set_attribute_int_ary( fid, vname, &
3123  key, ary(:) )
3124 
3125  return
3126  end subroutine file_set_attribute_int
3127 
3128  !-----------------------------------------------------------------------------
3129  subroutine file_set_attribute_float_ary( &
3130  fid, vname, &
3131  key, val )
3132  integer, intent(in) :: fid
3133  character(len=*), intent(in) :: vname
3134  character(len=*), intent(in) :: key
3135  real(sp), intent(in) :: val(:)
3136 
3137  integer :: error
3138 
3139  intrinsic size
3140 
3141  if ( .not. file_opened(fid) ) then
3142  log_error("FILE_set_attributefloat",*) 'File is not opened. fid = ', fid
3143  call prc_abort
3144  end if
3145 
3146  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3147 
3148  error = file_set_attribute_float_c( file_files(fid)%fid, & ! (in)
3149  cstr(vname), cstr(key), & ! (in)
3150  val(:), size(val(:)) ) ! (in)
3151  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
3152  log_error("FILE_set_attribute_float",*) 'failed to set float attribute for '//trim(vname)//': '//trim(key)
3153  call prc_abort
3154  end if
3155 
3156  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3157 
3158  return
3159  end subroutine file_set_attribute_float_ary
3160 
3161  subroutine file_set_attribute_float( &
3162  fid, vname, &
3163  key, val )
3164  integer, intent(in) :: fid
3165  character(len=*), intent(in) :: vname
3166  character(len=*), intent(in) :: key
3167  real(sp), intent(in) :: val
3168 
3169  real(sp) :: ary(1)
3170 
3171  ary(1) = val
3172  call file_set_attribute_float_ary( fid, vname, &
3173  key, ary(:) )
3174 
3175  return
3176  end subroutine file_set_attribute_float
3177  !-----------------------------------------------------------------------------
3178  subroutine file_set_attribute_double_ary( &
3179  fid, vname, &
3180  key, val )
3181  integer, intent(in) :: fid
3182  character(len=*), intent(in) :: vname
3183  character(len=*), intent(in) :: key
3184  real(dp), intent(in) :: val(:)
3185 
3186  integer :: error
3187 
3188  intrinsic size
3189 
3190  if ( .not. file_opened(fid) ) then
3191  log_error("FILE_set_attributedouble",*) 'File is not opened. fid = ', fid
3192  call prc_abort
3193  end if
3194 
3195  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3196 
3197  error = file_set_attribute_double_c( file_files(fid)%fid, & ! (in)
3198  cstr(vname), cstr(key), & ! (in)
3199  val(:), size(val(:)) ) ! (in)
3200  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
3201  log_error("FILE_set_attribute_double",*) 'failed to set double attribute for '//trim(vname)//': '//trim(key)
3202  call prc_abort
3203  end if
3204 
3205  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
3206 
3207  return
3208  end subroutine file_set_attribute_double_ary
3209 
3210  subroutine file_set_attribute_double( &
3211  fid, vname, &
3212  key, val )
3213  integer, intent(in) :: fid
3214  character(len=*), intent(in) :: vname
3215  character(len=*), intent(in) :: key
3216  real(dp), intent(in) :: val
3217 
3218  real(dp) :: ary(1)
3219 
3220  ary(1) = val
3221  call file_set_attribute_double_ary( fid, vname, &
3222  key, ary(:) )
3223 
3224  return
3225  end subroutine file_set_attribute_double
3226  !-----------------------------------------------------------------------------
3227  ! FILE_get_shape
3228  !-----------------------------------------------------------------------------
3229  subroutine file_get_shape_fname( &
3230  basename, varname, &
3231  dims, &
3232  rankid, single, &
3233  has_tdim, &
3234  error )
3235  implicit none
3236 
3237  character(len=*), intent( in) :: basename
3238  character(len=*), intent( in) :: varname
3239  integer, intent(out) :: dims(:)
3240  integer, intent( in), optional :: rankid
3241  logical, intent( in), optional :: single
3242  logical, intent(out), optional :: has_tdim
3243  logical, intent(out), optional :: error
3244 
3245  integer :: fid
3246  !---------------------------------------------------------------------------
3247 
3248  !--- search/register file
3249  call file_open( basename, & ! (in)
3250  fid, & ! (out)
3251  rankid=rankid, single=single ) ! (in)
3252 
3253  call file_get_shape_fid( fid, varname, & ! (in)
3254  dims(:), & ! (out)
3255  has_tdim = has_tdim, & ! (out)
3256  error = error ) ! (out)
3257 
3258  return
3259  end subroutine file_get_shape_fname
3260 
3261  subroutine file_get_shape_fid( &
3262  fid, varname, &
3263  dims, &
3264  has_tdim, &
3265  error )
3266  implicit none
3267  integer, intent( in) :: fid
3268  character(len=*), intent( in) :: varname
3269  integer, intent(out) :: dims(:)
3270  logical, intent(out), optional :: has_tdim
3271  logical, intent(out), optional :: error
3272 
3273  type(datainfo) :: dinfo
3274  integer :: ierror
3275  integer :: n
3276 
3277  logical(c_bool) :: suppress
3278 
3279  intrinsic size
3280  !---------------------------------------------------------------------------
3281 
3282  if ( .not. file_opened(fid) ) then
3283  log_error("FILE_get_shape_id",*) 'File is not opened. fid = ', fid
3284  call prc_abort
3285  end if
3286 
3287  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3288 
3289  if ( present(error) ) then
3290  suppress = .true.
3291  else
3292  suppress = .false.
3293  end if
3294 
3295  !--- get data information
3296  ierror = file_get_datainfo_c( dinfo, & ! (out)
3297  file_files(fid)%fid, & ! (in)
3298  cstr(varname), & ! (in)
3299  1, suppress ) ! (in)
3300 
3301  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3302 
3303  !--- verify
3304  if ( ierror /= file_success_code ) then
3305  if ( present(error) ) then
3306  error = .true.
3307  return
3308  else
3309  log_error("FILE_get_shape_fid",*) 'failed to get data information : ', trim(varname)
3310  call prc_abort
3311  end if
3312  end if
3313 
3314  if ( dinfo%rank /= size(dims) ) then
3315  log_error("FILE_get_shape_fid",*) 'rank is different, ', trim(varname), size(dims), dinfo%rank
3316  call prc_abort
3317  end if
3318  do n = 1, size(dims)
3319  dims(n) = dinfo%dim_size(n)
3320  end do
3321 
3322  if ( present(has_tdim) ) has_tdim = dinfo%has_tdim
3323  if ( present(error) ) error = .false.
3324 
3325  return
3326  end subroutine file_get_shape_fid
3327 
3328  !-----------------------------------------------------------------------------
3330  !-----------------------------------------------------------------------------
3331  subroutine file_get_stepsize( &
3332  fid, varname, &
3333  len, &
3334  error )
3335  integer, intent(in) :: fid
3336  character(len=*), intent(in) :: varname
3337 
3338  integer, intent(out) :: len
3339 
3340  logical, intent(out), optional :: error
3341 
3342  integer :: ierror
3343 
3344  if ( .not. file_opened(fid) ) then
3345  log_error("FILE_get_stepSize",*) 'File is not opened. fid = ', fid
3346  call prc_abort
3347  end if
3348 
3349  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3350 
3351  ierror = file_get_step_size_c( len, & ! (out)
3352  file_files(fid)%fid, cstr(varname) ) ! (in)
3353  if ( ierror /= file_success_code .and. ierror /= file_already_existed_code ) then
3354  if ( present(error) ) then
3355  error = .true.
3356  else
3357  log_error("FILE_get_stepSize",*) 'failed to get number of steps'
3358  call prc_abort
3359  end if
3360  else
3361  if ( present(error) ) error = .false.
3362  end if
3363 
3364  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3365 
3366  return
3367  end subroutine file_get_stepsize
3368 
3369  !-----------------------------------------------------------------------------
3370  ! FILE_get_commonInfo
3371  !-----------------------------------------------------------------------------
3372  subroutine file_get_commoninfo_fname( &
3373  basename, &
3374  rankid, &
3375  nvars_limit, &
3376  title, &
3377  source, &
3378  institution, &
3379  nvars, &
3380  varname )
3381  implicit none
3382 
3383  character(len=*), intent(in) :: basename
3384  integer, intent(in) :: rankid
3385  integer, intent(in) :: nvars_limit
3386  character(len=FILE_HMID), intent(out) :: title ! title of the file
3387  character(len=FILE_HMID), intent(out) :: source ! for file header
3388  character(len=FILE_HMID), intent(out) :: institution ! for file header
3389  integer, intent(out) :: nvars ! number of variables
3390  character(len=FILE_HSHORT), intent(out) :: varname(nvars_limit) ! name of variables
3391 
3392  integer :: fid
3393  !---------------------------------------------------------------------------
3394 
3395  call file_open( basename, & ! [IN]
3396  fid, & ! [OUT]
3397  rankid=rankid ) ! [IN]
3398 
3399  call file_get_commoninfo_fid( fid, & ! [IN]
3400  nvars_limit, & ! [IN]
3401  title, & ! [OUT]
3402  source, & ! [OUT]
3403  institution, & ! [OUT]
3404  nvars, & ! [OUT]
3405  varname(:) ) ! [OUT]
3406 
3407  return
3408  end subroutine file_get_commoninfo_fname
3409 
3410  subroutine file_get_commoninfo_fid( &
3411  fid, &
3412  nvars_limit, &
3413  title, &
3414  source, &
3415  institution, &
3416  nvars, &
3417  varname )
3418  implicit none
3419 
3420  integer, intent(in) :: fid
3421  integer, intent(in) :: nvars_limit
3422  character(len=FILE_HMID), intent(out) :: title ! title of the file
3423  character(len=FILE_HMID), intent(out) :: source ! for file header
3424  character(len=FILE_HMID), intent(out) :: institution ! for file header
3425  integer, intent(out) :: nvars ! number of variables
3426  character(len=FILE_HSHORT), intent(out) :: varname(nvars_limit) ! name of variables
3427 
3428  integer :: v
3429  !---------------------------------------------------------------------------
3430 
3431  if ( .not. file_opened(fid) ) then
3432  log_error("FILE_get_commonInfo_fid",*) 'File is not opened. fid = ', fid
3433  call prc_abort
3434  end if
3435 
3436  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3437 
3438  call file_get_attribute( fid, 'global', 'title', title )
3439  call file_get_attribute( fid, 'global', 'source', source )
3440  call file_get_attribute( fid, 'global', 'institution', institution )
3441 
3442  call file_get_var_num( fid, nvars_limit, nvars )
3443 
3444  do v = 1, nvars
3445  call file_get_var_name( fid, v, varname(v) )
3446  enddo
3447 
3448  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3449 
3450  return
3451  end subroutine file_get_commoninfo_fid
3452 
3453  !-----------------------------------------------------------------------------
3454  ! FILE_get_dataInfo
3455  !-----------------------------------------------------------------------------
3456  subroutine file_get_datainfo_fname( &
3457  basename, varname, &
3458  rankid, istep, single, &
3459  existed, &
3460  description, units, standard_name, &
3461  datatype, &
3462  dim_rank, dim_name, dim_size, &
3463  natts, att_name, att_type, att_len, &
3464  has_tdim, &
3465  time_start, time_end, time_units, &
3466  calendar )
3467  implicit none
3468 
3469  character(len=*), intent(in) :: basename
3470  character(len=*), intent(in) :: varname
3471 
3472  integer, intent(in), optional :: rankid
3473  integer, intent(in), optional :: istep
3474  logical, intent(in), optional :: single
3475  logical, intent(out), optional :: existed
3476  character(len=FILE_HMID), intent(out), optional :: description
3477  character(len=FILE_HSHORT), intent(out), optional :: units
3478  character(len=FILE_HMID), intent(out), optional :: standard_name
3479  integer, intent(out), optional :: datatype
3480  integer, intent(out), optional :: dim_rank
3481  character(len=FILE_HSHORT), intent(out), optional :: dim_name(:)
3482  integer, intent(out), optional :: dim_size(:)
3483  integer, intent(out), optional :: natts
3484  character(len=FILE_HSHORT), intent(out), optional :: att_name(:)
3485  integer, intent(out), optional :: att_type(:)
3486  integer, intent(out), optional :: att_len (:)
3487  logical, intent(out), optional :: has_tdim
3488  real(dp), intent(out), optional :: time_start
3489  real(dp), intent(out), optional :: time_end
3490  character(len=FILE_HMID), intent(out), optional :: time_units
3491  character(len=FILE_HSHORT), intent(out), optional :: calendar
3492 
3493  logical :: single_
3494  integer :: fid
3495  !---------------------------------------------------------------------------
3496 
3497  if ( present(single) ) then
3498  single_ = single
3499  else
3500  single_ = .false.
3501  endif
3502 
3503  !--- search/register file
3504  call file_open( basename, & ! [IN]
3505  fid, & ! [OUT]
3506  rankid=rankid, single=single_ ) ! [IN]
3507 
3508  call file_get_datainfo_fid( fid, varname, & ! [IN]
3509  istep, & ! [IN] , optional
3510  existed, & ! [OUT], optional
3511  description, units, standard_name, & ! [OUT], optional
3512  datatype, & ! [OUT], optional
3513  dim_rank, dim_name, dim_size, & ! [OUT], optional
3514  natts, att_name, att_type, att_len, & ! [OUT], optional
3515  has_tdim, & ! [OUT], optional
3516  time_start, time_end, time_units, & ! [OUT], optional
3517  calendar ) ! [OUT], optional
3518 
3519  return
3520  end subroutine file_get_datainfo_fname
3521 
3522  subroutine file_get_datainfo_fid( &
3523  fid, varname, &
3524  istep, &
3525  existed, &
3526  description, units, standard_name, &
3527  datatype, &
3528  dim_rank, dim_name, dim_size, &
3529  natts, att_name, att_type, att_len, &
3530  has_tdim, &
3531  time_start, time_end, time_units, &
3532  calendar )
3533  implicit none
3534 
3535  integer, intent(in) :: fid
3536  character(len=*), intent(in) :: varname
3537 
3538  integer, intent(in), optional :: istep
3539  logical, intent(out), optional :: existed
3540  character(len=*), intent(out), optional :: description
3541  character(len=*), intent(out), optional :: units
3542  character(len=*), intent(out), optional :: standard_name
3543  integer, intent(out), optional :: datatype
3544  integer, intent(out), optional :: dim_rank
3545  character(len=*), intent(out), optional :: dim_name(:)
3546  integer, intent(out), optional :: dim_size(:)
3547  integer, intent(out), optional :: natts
3548  character(len=*), intent(out), optional :: att_name(:)
3549  integer, intent(out), optional :: att_type(:)
3550  integer, intent(out), optional :: att_len (:)
3551  logical, intent(out), optional :: has_tdim
3552  real(dp), intent(out), optional :: time_start
3553  real(dp), intent(out), optional :: time_end
3554  character(len=*), intent(out), optional :: time_units
3555  character(len=*), intent(out), optional :: calendar
3556 
3557  type(datainfo) :: dinfo
3558 
3559  integer :: istep_
3560  real(dp) :: time(1)
3561  integer :: i
3562  integer :: error
3563 
3564  logical(c_bool) :: suppress
3565  logical :: existed2
3566 
3567  character(len=FILE_HMID) :: tu
3568 
3569  intrinsic size
3570  !---------------------------------------------------------------------------
3571 
3572  if ( present(istep) ) then
3573  istep_ = istep
3574  else
3575  istep_ = 1
3576  end if
3577 
3578  if ( present(existed) ) then
3579  suppress = .true.
3580  else
3581  suppress = .false.
3582  end if
3583 
3584  if ( .not. file_opened(fid) ) then
3585  log_error("FILE_get_dataInfo_fid",*) 'File is not opened. fid = ', fid
3586  call prc_abort
3587  end if
3588 
3589  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3590 
3591  !--- get data information
3592  error = file_get_datainfo_c( dinfo, & ! [OUT]
3593  file_files(fid)%fid, & ! [IN]
3594  cstr(varname), & ! [IN]
3595  istep_, & ! [IN]
3596  suppress ) ! [IN]
3597 
3598  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3599 
3600  !--- verify and exit
3601  if ( error /= file_success_code ) then
3602  if ( present( existed ) ) then
3603  existed = .false.
3604  return
3605  else
3606  log_error("FILE_get_dataInfo_fid",*) 'data info not found'
3607  call prc_abort
3608  end if
3609  endif
3610 
3611  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3612 
3613  if ( present(existed) ) existed = .true.
3614 
3615  if ( present(description) ) call fstr(description, dinfo%description)
3616  if ( present(units) ) call fstr(units, dinfo%units)
3617  if ( present(standard_name) ) call fstr(standard_name, dinfo%standard_name)
3618  if ( present(datatype) ) datatype = dinfo%datatype
3619  if ( present(dim_rank) ) dim_rank = dinfo%rank
3620 
3621  if ( present(dim_name) ) then
3622  do i = 1, min( dinfo%rank, size(dim_name) ) ! limit dimension rank
3623  call fstr(dim_name(i), dinfo%dim_name(:,i))
3624  enddo
3625  endif
3626 
3627  if ( present(dim_size) ) then
3628  do i = 1, min( dinfo%rank, size(dim_size) ) ! limit dimension rank
3629  dim_size(i) = dinfo%dim_size(i)
3630  enddo
3631  endif
3632 
3633  if ( present(natts) ) natts = dinfo%natts
3634  if ( present(att_name) ) then
3635  do i = 1, min( dinfo%natts, size(att_name) )
3636  call fstr(att_name(i), dinfo%att_name(:,i))
3637  end do
3638  end if
3639  if ( present(att_type) ) then
3640  do i = 1, min( dinfo%natts, size(att_type) )
3641  att_type(i) = dinfo%att_type(i)
3642  end do
3643  end if
3644  if ( present(att_len) ) then
3645  do i = 1, min( dinfo%natts, size(att_len) )
3646  att_len(i) = dinfo%att_len(i)
3647  end do
3648  end if
3649 
3650  call fstr(tu, dinfo%time_units)
3651 
3652  if ( present(time_units) ) then
3653  if ( tu == "" ) then
3654  call file_get_attribute( fid, "global", "time_units", time_units )
3655  else
3656  time_units = tu
3657  endif
3658  endif
3659 
3660  if ( present(calendar) ) then
3661  if ( tu == "" ) then
3662  call file_get_attribute( fid, "global", "calendar", calendar, existed2 )
3663  if ( .not. existed2 ) calendar = ""
3664  else
3665  call fstr(calendar, dinfo%calendar)
3666  end if
3667  end if
3668 
3669  if ( present(has_tdim) ) then
3670  has_tdim = dinfo%has_tdim
3671  end if
3672 
3673  if ( present(time_start) ) then
3674  if ( tu == "" ) then
3675  call file_get_attribute( fid, "global", "time_start", time )
3676  time_start = time(1)
3677  else
3678  time_start = dinfo%time_start
3679  endif
3680  endif
3681 
3682  if ( present(time_end) ) then
3683  if ( tu == "" ) then
3684  call file_get_attribute( fid, "global", "time_start", time )
3685  time_end = time(1)
3686  else
3687  time_end = dinfo%time_end
3688  end if
3689  endif
3690 
3691  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3692 
3693  return
3694  end subroutine file_get_datainfo_fid
3695 
3696  !-----------------------------------------------------------------------------
3697  ! FILE_get_data_all_dataInfo
3698  !-----------------------------------------------------------------------------
3699  subroutine file_get_all_datainfo_fname( &
3700  basename, varname, &
3701  step_nmax, &
3702  description, units, standard_name, &
3703  datatype, &
3704  dim_rank, dim_name, dim_size, &
3705  natts, att_name, att_type, att_len, &
3706  time_start, time_end, &
3707  time_units, calendar, &
3708  rankid, single )
3709  implicit none
3710  character(len=*), intent(in) :: basename
3711  character(len=*), intent(in) :: varname
3712  integer, intent(out) :: step_nmax
3713  character(len=FILE_HMID), intent(out) :: description
3714  character(len=FILE_HSHORT), intent(out) :: units
3715  character(len=FILE_HMID), intent(out) :: standard_name
3716  integer, intent(out) :: datatype
3717  integer, intent(out) :: dim_rank
3718  character(len=FILE_HSHORT), intent(out) :: dim_name (:)
3719  integer, intent(out) :: dim_size (:)
3720  integer, intent(out) :: natts
3721  character(len=FILE_HSHORT), intent(out) :: att_name (:)
3722  integer, intent(out) :: att_type (:)
3723  integer, intent(out) :: att_len (:)
3724  real(dp), intent(out) :: time_start(:)
3725  real(dp), intent(out) :: time_end (:)
3726  character(len=FILE_HMID), intent(out) :: time_units
3727  character(len=FILE_HSHORT), intent(out) :: calendar
3728 
3729  integer, intent(in), optional :: rankid
3730  logical, intent(in), optional :: single
3731 
3732  integer :: fid
3733  logical :: single_
3734  !---------------------------------------------------------------------------
3735 
3736  if ( present(single) ) then
3737  single_ = single
3738  else
3739  single_ = .false.
3740  endif
3741 
3742  !--- search/register file
3743  call file_open( basename, & ! [IN]
3744  fid, & ! [OUT]
3745  rankid=rankid, single=single_ ) ! [IN]
3746 
3747  call file_get_all_datainfo_fid( fid, varname, & ! [IN]
3748  step_nmax, & ! [OUT]
3749  description, units, standard_name, & ! [OUT]
3750  datatype, & ! [OUT]
3751  dim_rank, dim_name(:), dim_size(:), & ! [OUT]
3752  natts, att_name(:), att_type(:), att_len(:), & ! [OUT]
3753  time_start(:), time_end(:), & ! [OUT]
3754  time_units, calendar ) ! [OUT]
3755 
3756  return
3757  end subroutine file_get_all_datainfo_fname
3758 
3759  subroutine file_get_all_datainfo_fid( &
3760  fid, varname, &
3761  step_nmax, &
3762  description, units, standard_name, &
3763  datatype, &
3764  dim_rank, dim_name, dim_size, &
3765  natts, att_name, att_type, att_len, &
3766  time_start, time_end, &
3767  time_units, calendar )
3768  implicit none
3769 
3770  integer, intent(in) :: fid
3771  character(len=*), intent(in) :: varname
3772  integer, intent(out) :: step_nmax
3773  character(len=*), intent(out) :: description
3774  character(len=*), intent(out) :: units
3775  character(len=*), intent(out) :: standard_name
3776  integer, intent(out) :: datatype
3777  integer, intent(out) :: dim_rank
3778  character(len=*), intent(out) :: dim_name (:)
3779  integer, intent(out) :: dim_size (:)
3780  integer, intent(out) :: natts
3781  character(len=*), intent(out) :: att_name (:)
3782  integer, intent(out) :: att_type (:)
3783  integer, intent(out) :: att_len (:)
3784  real(dp), intent(out) :: time_start(:)
3785  real(dp), intent(out) :: time_end (:)
3786  character(len=*), intent(out) :: time_units
3787  character(len=*), intent(out) :: calendar
3788 
3789  type(datainfo) :: dinfo
3790 
3791  real(dp) :: time(1)
3792  integer :: i
3793  integer :: error
3794  logical :: existed
3795 
3796  integer :: istep
3797  integer :: istep_max
3798 
3799  logical(c_bool) :: suppress
3800  character(len=FILE_HMID) :: tu
3801 
3802  intrinsic size
3803  !---------------------------------------------------------------------------
3804 
3805  if ( .not. file_opened(fid) ) then
3806  log_error("FILE_get_all_dataInfo_fid",*) 'File is not opened. fid = ', fid
3807  call prc_abort
3808  end if
3809 
3810  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3811 
3812  ! initialize
3813  description = ""
3814  units = ""
3815  standard_name = ""
3816  datatype = -1
3817  dim_rank = -1
3818  dim_name(:) = ""
3819  dim_size(:) = -1
3820  time_start(:) = file_rmiss
3821  time_end(:) = file_rmiss
3822 
3823  suppress = .true.
3824  istep_max = min( size(time_start), size(time_end) )
3825  do istep = 1, istep_max
3826  !--- get data information
3827  error = file_get_datainfo_c( dinfo, & ! [OUT]
3828  file_files(fid)%fid, & ! [IN]
3829  cstr(varname), & ! [IN]
3830  istep, suppress ) ! [IN]
3831 
3832  !--- verify and exit
3833  if ( error /= file_success_code ) then
3834  step_nmax = istep - 1
3835  exit
3836  endif
3837 
3838  if ( istep == 1 ) then
3839  call fstr(description, dinfo%description)
3840  call fstr(units, dinfo%units)
3841  call fstr(standard_name, dinfo%standard_name)
3842  datatype = dinfo%datatype
3843  dim_rank = dinfo%rank
3844  natts = dinfo%natts
3845 
3846  do i = 1, min( dinfo%rank, size(dim_name) ) ! limit dimension rank
3847  call fstr(dim_name(i), dinfo%dim_name(:,i))
3848  dim_size(i) = dinfo%dim_size(i)
3849  enddo
3850 
3851  do i = 1, min( dinfo%natts, size(att_name) )
3852  call fstr(att_name(i), dinfo%att_name(:,i))
3853  att_type(i) = dinfo%att_type(i)
3854  att_len(i) = dinfo%att_len (i)
3855  end do
3856 
3857  call fstr(tu, dinfo%time_units)
3858  if ( tu == "" ) then
3859  call file_get_attribute( fid, "global", "time_units", time_units )
3860  call file_get_attribute( fid, "global", "calendar", calendar, existed )
3861  if ( .not. existed ) calendar = ""
3862  call file_get_attribute( fid, "global", "time_start", time )
3863  time_start(1) = time(1)
3864  time_end(1) = time(1)
3865  step_nmax = 1
3866  exit
3867  else
3868  time_units = tu
3869  time_start(1) = dinfo%time_start
3870  time_end(1) = dinfo%time_end
3871  call fstr(calendar, dinfo%calendar)
3872  endif
3873  else
3874  time_start(istep) = dinfo%time_start
3875  time_end(istep) = dinfo%time_end
3876  endif
3877  enddo
3878 
3879  if ( istep == istep_max + 1 ) then
3880  if ( error /= file_success_code ) then
3881  log_error("FILE_get_all_dataInfo_fid",*) 'size of time is not enough: ', istep_max
3882  call prc_abort
3883  else
3884  step_nmax = istep - 1
3885  end if
3886  end if
3887 
3888  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3889 
3890  return
3891  end subroutine file_get_all_datainfo_fid
3892 
3893  !-----------------------------------------------------------------------------
3894  ! interface FILE_read
3895  !-----------------------------------------------------------------------------
3896  subroutine file_read_realsp_1d( &
3897  basename, varname, &
3898  var, &
3899  step, rankid, single, postfix, &
3900  allow_missing, missing_value )
3901  implicit none
3902 
3903  character(len=*), intent( in) :: basename
3904  character(len=*), intent( in) :: varname
3905  real(sp), intent(out) :: var(:)
3906  integer, intent( in), optional :: step
3907  integer, intent( in), optional :: rankid
3908  logical, intent( in), optional :: single
3909  character(len=*), intent( in), optional :: postfix
3910  logical, intent( in), optional :: allow_missing
3911  real(sp), intent( in), optional :: missing_value
3912 
3913  integer :: fid
3914 
3915  intrinsic shape
3916  !---------------------------------------------------------------------------
3917 
3918  !--- search/register file
3919  call file_open( basename, & ! (in)
3920  fid, & ! (out)
3921  rankid=rankid, single=single, & ! (in)
3922  postfix=postfix ) ! (in)
3923 
3924  call file_read_var_realsp_1d( &
3925  fid, varname, & ! (in)
3926  var(:), & ! (out)
3927  step=step, & ! (in)
3928  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3929 
3930  return
3931  end subroutine file_read_realsp_1d
3932  subroutine file_read_realdp_1d( &
3933  basename, varname, &
3934  var, &
3935  step, rankid, single, postfix, &
3936  allow_missing, missing_value )
3937  implicit none
3938 
3939  character(len=*), intent( in) :: basename
3940  character(len=*), intent( in) :: varname
3941  real(dp), intent(out) :: var(:)
3942  integer, intent( in), optional :: step
3943  integer, intent( in), optional :: rankid
3944  logical, intent( in), optional :: single
3945  character(len=*), intent( in), optional :: postfix
3946  logical, intent( in), optional :: allow_missing
3947  real(dp), intent( in), optional :: missing_value
3948 
3949  integer :: fid
3950 
3951  intrinsic shape
3952  !---------------------------------------------------------------------------
3953 
3954  !--- search/register file
3955  call file_open( basename, & ! (in)
3956  fid, & ! (out)
3957  rankid=rankid, single=single, & ! (in)
3958  postfix=postfix ) ! (in)
3959 
3960  call file_read_var_realdp_1d( &
3961  fid, varname, & ! (in)
3962  var(:), & ! (out)
3963  step=step, & ! (in)
3964  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3965 
3966  return
3967  end subroutine file_read_realdp_1d
3968  subroutine file_read_realsp_2d( &
3969  basename, varname, &
3970  var, &
3971  step, rankid, single, postfix, &
3972  allow_missing, missing_value )
3973  implicit none
3974 
3975  character(len=*), intent( in) :: basename
3976  character(len=*), intent( in) :: varname
3977  real(sp), intent(out) :: var(:,:)
3978  integer, intent( in), optional :: step
3979  integer, intent( in), optional :: rankid
3980  logical, intent( in), optional :: single
3981  character(len=*), intent( in), optional :: postfix
3982  logical, intent( in), optional :: allow_missing
3983  real(sp), intent( in), optional :: missing_value
3984 
3985  integer :: fid
3986 
3987  intrinsic shape
3988  !---------------------------------------------------------------------------
3989 
3990  !--- search/register file
3991  call file_open( basename, & ! (in)
3992  fid, & ! (out)
3993  rankid=rankid, single=single, & ! (in)
3994  postfix=postfix ) ! (in)
3995 
3996  call file_read_var_realsp_2d( &
3997  fid, varname, & ! (in)
3998  var(:,:), & ! (out)
3999  step=step, & ! (in)
4000  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
4001 
4002  return
4003  end subroutine file_read_realsp_2d
4004  subroutine file_read_realdp_2d( &
4005  basename, varname, &
4006  var, &
4007  step, rankid, single, postfix, &
4008  allow_missing, missing_value )
4009  implicit none
4010 
4011  character(len=*), intent( in) :: basename
4012  character(len=*), intent( in) :: varname
4013  real(dp), intent(out) :: var(:,:)
4014  integer, intent( in), optional :: step
4015  integer, intent( in), optional :: rankid
4016  logical, intent( in), optional :: single
4017  character(len=*), intent( in), optional :: postfix
4018  logical, intent( in), optional :: allow_missing
4019  real(dp), intent( in), optional :: missing_value
4020 
4021  integer :: fid
4022 
4023  intrinsic shape
4024  !---------------------------------------------------------------------------
4025 
4026  !--- search/register file
4027  call file_open( basename, & ! (in)
4028  fid, & ! (out)
4029  rankid=rankid, single=single, & ! (in)
4030  postfix=postfix ) ! (in)
4031 
4032  call file_read_var_realdp_2d( &
4033  fid, varname, & ! (in)
4034  var(:,:), & ! (out)
4035  step=step, & ! (in)
4036  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
4037 
4038  return
4039  end subroutine file_read_realdp_2d
4040  subroutine file_read_realsp_3d( &
4041  basename, varname, &
4042  var, &
4043  step, rankid, single, postfix, &
4044  allow_missing, missing_value )
4045  implicit none
4046 
4047  character(len=*), intent( in) :: basename
4048  character(len=*), intent( in) :: varname
4049  real(sp), intent(out) :: var(:,:,:)
4050  integer, intent( in), optional :: step
4051  integer, intent( in), optional :: rankid
4052  logical, intent( in), optional :: single
4053  character(len=*), intent( in), optional :: postfix
4054  logical, intent( in), optional :: allow_missing
4055  real(sp), intent( in), optional :: missing_value
4056 
4057  integer :: fid
4058 
4059  intrinsic shape
4060  !---------------------------------------------------------------------------
4061 
4062  !--- search/register file
4063  call file_open( basename, & ! (in)
4064  fid, & ! (out)
4065  rankid=rankid, single=single, & ! (in)
4066  postfix=postfix ) ! (in)
4067 
4068  call file_read_var_realsp_3d( &
4069  fid, varname, & ! (in)
4070  var(:,:,:), & ! (out)
4071  step=step, & ! (in)
4072  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
4073 
4074  return
4075  end subroutine file_read_realsp_3d
4076  subroutine file_read_realdp_3d( &
4077  basename, varname, &
4078  var, &
4079  step, rankid, single, postfix, &
4080  allow_missing, missing_value )
4081  implicit none
4082 
4083  character(len=*), intent( in) :: basename
4084  character(len=*), intent( in) :: varname
4085  real(dp), intent(out) :: var(:,:,:)
4086  integer, intent( in), optional :: step
4087  integer, intent( in), optional :: rankid
4088  logical, intent( in), optional :: single
4089  character(len=*), intent( in), optional :: postfix
4090  logical, intent( in), optional :: allow_missing
4091  real(dp), intent( in), optional :: missing_value
4092 
4093  integer :: fid
4094 
4095  intrinsic shape
4096  !---------------------------------------------------------------------------
4097 
4098  !--- search/register file
4099  call file_open( basename, & ! (in)
4100  fid, & ! (out)
4101  rankid=rankid, single=single, & ! (in)
4102  postfix=postfix ) ! (in)
4103 
4104  call file_read_var_realdp_3d( &
4105  fid, varname, & ! (in)
4106  var(:,:,:), & ! (out)
4107  step=step, & ! (in)
4108  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
4109 
4110  return
4111  end subroutine file_read_realdp_3d
4112  subroutine file_read_realsp_4d( &
4113  basename, varname, &
4114  var, &
4115  step, rankid, single, postfix, &
4116  allow_missing, missing_value )
4117  implicit none
4118 
4119  character(len=*), intent( in) :: basename
4120  character(len=*), intent( in) :: varname
4121  real(sp), intent(out) :: var(:,:,:,:)
4122  integer, intent( in), optional :: step
4123  integer, intent( in), optional :: rankid
4124  logical, intent( in), optional :: single
4125  character(len=*), intent( in), optional :: postfix
4126  logical, intent( in), optional :: allow_missing
4127  real(sp), intent( in), optional :: missing_value
4128 
4129  integer :: fid
4130 
4131  intrinsic shape
4132  !---------------------------------------------------------------------------
4133 
4134  !--- search/register file
4135  call file_open( basename, & ! (in)
4136  fid, & ! (out)
4137  rankid=rankid, single=single, & ! (in)
4138  postfix=postfix ) ! (in)
4139 
4140  call file_read_var_realsp_4d( &
4141  fid, varname, & ! (in)
4142  var(:,:,:,:), & ! (out)
4143  step=step, & ! (in)
4144  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
4145 
4146  return
4147  end subroutine file_read_realsp_4d
4148  subroutine file_read_realdp_4d( &
4149  basename, varname, &
4150  var, &
4151  step, rankid, single, postfix, &
4152  allow_missing, missing_value )
4153  implicit none
4154 
4155  character(len=*), intent( in) :: basename
4156  character(len=*), intent( in) :: varname
4157  real(dp), intent(out) :: var(:,:,:,:)
4158  integer, intent( in), optional :: step
4159  integer, intent( in), optional :: rankid
4160  logical, intent( in), optional :: single
4161  character(len=*), intent( in), optional :: postfix
4162  logical, intent( in), optional :: allow_missing
4163  real(dp), intent( in), optional :: missing_value
4164 
4165  integer :: fid
4166 
4167  intrinsic shape
4168  !---------------------------------------------------------------------------
4169 
4170  !--- search/register file
4171  call file_open( basename, & ! (in)
4172  fid, & ! (out)
4173  rankid=rankid, single=single, & ! (in)
4174  postfix=postfix ) ! (in)
4175 
4176  call file_read_var_realdp_4d( &
4177  fid, varname, & ! (in)
4178  var(:,:,:,:), & ! (out)
4179  step=step, & ! (in)
4180  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
4181 
4182  return
4183  end subroutine file_read_realdp_4d
4184 
4185  subroutine file_read_var_realsp_1d( &
4186  fid, varname, &
4187  var, &
4188  step, &
4189  allow_missing, &
4190  missing_value, &
4191  ntypes, dtype, &
4192  start, count )
4193  implicit none
4194 
4195  integer, intent( in) :: fid
4196  character(len=*), intent( in) :: varname
4197 #ifdef NVIDIA
4198  real(sp), intent(out), target :: var(:)
4199 #else
4200  real(sp), intent(out), target, contiguous :: var(:)
4201 #endif
4202  integer, intent( in), optional :: step
4203  logical, intent( in), optional :: allow_missing
4204  real(sp), intent( in), optional :: missing_value
4205  integer, intent( in), optional :: ntypes
4206  integer, intent( in), optional :: dtype
4207  integer, intent( in), optional :: start(:)
4208  integer, intent( in), optional :: count(:)
4209 
4210  integer :: step_
4211  logical(c_bool) :: allow_missing_
4212  real(sp) :: missing_value_
4213 
4214  type(datainfo) :: dinfo
4215  integer :: dim_size(1)
4216 
4217  integer :: error
4218  integer :: n
4219 
4220  intrinsic size, shape
4221  !---------------------------------------------------------------------------
4222 
4223  if ( .not. file_opened(fid) ) then
4224  log_error("FILE_read_var_realSP_1D",*) 'File is not opened. fid = ', fid
4225  call prc_abort
4226  end if
4227 
4228  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4229 
4230  if ( present(step) ) then
4231  step_ = step
4232  else
4233  step_ = 1
4234  end if
4235 
4236  if ( present(allow_missing) ) then
4237  allow_missing_ = allow_missing
4238  else
4239  allow_missing_ = .false.
4240  end if
4241 
4242  if ( present(missing_value) ) then
4243  missing_value_ = missing_value
4244  else
4245  missing_value_ = 0.0_sp
4246  end if
4247 
4248  !--- get data information
4249  error = file_get_datainfo_c( dinfo, & ! (out)
4250  file_files(fid)%fid, & ! (in)
4251  cstr(varname), & ! (in)
4252  step_, allow_missing_ ) ! (in)
4253 
4254  !--- verify
4255  if ( error /= file_success_code ) then
4256  if ( allow_missing_ ) then
4257  log_info("FILE_read_var_realSP_1D",*) '[INPUT]/[FILE] data not found! : ', &
4258  'varname= ',trim(varname),', step=',step_
4259  log_info("FILE_read_var_realSP_1D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
4260  var(:) = missing_value_
4261  return
4262  else
4263  log_error("FILE_read_var_realSP_1D",*) 'failed to get data information :'//trim(varname)
4264  call prc_abort
4265  end if
4266  end if
4267 
4268  if ( dinfo%rank /= 1 ) then
4269  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4270  log_error("FILE_read_var_realSP_1D",*) 'rank of '//trim(varname)//' is not 1', dinfo%rank
4271  call prc_abort
4272  end if
4273  end if
4274 
4275  if ( present(ntypes) ) then
4276 #if defined(__GFORTRAN__) && __GNUC__ < 7
4277  error = file_read_data_c( cloc(var(1)), & ! (out)
4278 #else
4279  error = file_read_data_c( c_loc(var), & ! (out)
4280 #endif
4281  dinfo, sp, ntypes, dtype, start(:), count(:) ) ! (in)
4282  else if ( present(start) .and. present(count) ) then
4283 #ifdef NVIDIA
4284  block
4285  real(sp), allocatable, target :: work(:)
4286  allocate(work, mold=var)
4287 #endif
4288  error = file_read_data_c( &
4289 #if defined(__GFORTRAN__) && __GNUC__ < 7
4290  cloc(var(1)), & ! (out)
4291 #elif defined(NVIDIA)
4292  c_loc(work), & ! (out)
4293 #else
4294  c_loc(var), & ! (out)
4295 #endif
4296  dinfo, sp, 0, 0, start(:), count(:) ) ! (in)
4297 #ifdef NVIDIA
4298  var = work
4299  end block
4300 #endif
4301  else
4302  dim_size(:) = shape(var)
4303  do n = 1, 1
4304  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4305  log_error("FILE_read_var_realSP_1D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4306  call prc_abort
4307  end if
4308  end do
4309 #ifdef NVIDIA
4310  block
4311  real(sp), allocatable, target :: work(:)
4312  allocate(work, mold=var)
4313 #endif
4314  error = file_read_data_c( &
4315 #if defined(__GFORTRAN__) && __GNUC__ < 7
4316  cloc(var(1)), & ! (out)
4317 #elif defined(NVIDIA)
4318  c_loc(work), & ! (out)
4319 #else
4320  c_loc(var), & ! (out)
4321 #endif
4322  dinfo, sp, 0, 0, (/0/), (/0/) ) ! (in)
4323 #ifdef NVIDIA
4324  var = work
4325  end block
4326 #endif
4327  end if
4328  if ( error /= file_success_code ) then
4329  log_error("FILE_read_var_realSP_1D",*) 'failed to get data value: ', trim(varname)
4330  call prc_abort
4331  end if
4332 
4333  !$acc update device(var) if(acc_is_present(var))
4334 
4335  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4336 
4337  return
4338  end subroutine file_read_var_realsp_1d
4339  subroutine file_read_var_realdp_1d( &
4340  fid, varname, &
4341  var, &
4342  step, &
4343  allow_missing, &
4344  missing_value, &
4345  ntypes, dtype, &
4346  start, count )
4347  implicit none
4348 
4349  integer, intent( in) :: fid
4350  character(len=*), intent( in) :: varname
4351 #ifdef NVIDIA
4352  real(dp), intent(out), target :: var(:)
4353 #else
4354  real(dp), intent(out), target, contiguous :: var(:)
4355 #endif
4356  integer, intent( in), optional :: step
4357  logical, intent( in), optional :: allow_missing
4358  real(dp), intent( in), optional :: missing_value
4359  integer, intent( in), optional :: ntypes
4360  integer, intent( in), optional :: dtype
4361  integer, intent( in), optional :: start(:)
4362  integer, intent( in), optional :: count(:)
4363 
4364  integer :: step_
4365  logical(c_bool) :: allow_missing_
4366  real(dp) :: missing_value_
4367 
4368  type(datainfo) :: dinfo
4369  integer :: dim_size(1)
4370 
4371  integer :: error
4372  integer :: n
4373 
4374  intrinsic size, shape
4375  !---------------------------------------------------------------------------
4376 
4377  if ( .not. file_opened(fid) ) then
4378  log_error("FILE_read_var_realDP_1D",*) 'File is not opened. fid = ', fid
4379  call prc_abort
4380  end if
4381 
4382  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4383 
4384  if ( present(step) ) then
4385  step_ = step
4386  else
4387  step_ = 1
4388  end if
4389 
4390  if ( present(allow_missing) ) then
4391  allow_missing_ = allow_missing
4392  else
4393  allow_missing_ = .false.
4394  end if
4395 
4396  if ( present(missing_value) ) then
4397  missing_value_ = missing_value
4398  else
4399  missing_value_ = 0.0_dp
4400  end if
4401 
4402  !--- get data information
4403  error = file_get_datainfo_c( dinfo, & ! (out)
4404  file_files(fid)%fid, & ! (in)
4405  cstr(varname), & ! (in)
4406  step_, allow_missing_ ) ! (in)
4407 
4408  !--- verify
4409  if ( error /= file_success_code ) then
4410  if ( allow_missing_ ) then
4411  log_info("FILE_read_var_realDP_1D",*) '[INPUT]/[FILE] data not found! : ', &
4412  'varname= ',trim(varname),', step=',step_
4413  log_info("FILE_read_var_realDP_1D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
4414  var(:) = missing_value_
4415  return
4416  else
4417  log_error("FILE_read_var_realDP_1D",*) 'failed to get data information :'//trim(varname)
4418  call prc_abort
4419  end if
4420  end if
4421 
4422  if ( dinfo%rank /= 1 ) then
4423  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4424  log_error("FILE_read_var_realDP_1D",*) 'rank of '//trim(varname)//' is not 1', dinfo%rank
4425  call prc_abort
4426  end if
4427  end if
4428 
4429  if ( present(ntypes) ) then
4430 #if defined(__GFORTRAN__) && __GNUC__ < 7
4431  error = file_read_data_c( cloc(var(1)), & ! (out)
4432 #else
4433  error = file_read_data_c( c_loc(var), & ! (out)
4434 #endif
4435  dinfo, dp, ntypes, dtype, start(:), count(:) ) ! (in)
4436  else if ( present(start) .and. present(count) ) then
4437 #ifdef NVIDIA
4438  block
4439  real(dp), allocatable, target :: work(:)
4440  allocate(work, mold=var)
4441 #endif
4442  error = file_read_data_c( &
4443 #if defined(__GFORTRAN__) && __GNUC__ < 7
4444  cloc(var(1)), & ! (out)
4445 #elif defined(NVIDIA)
4446  c_loc(work), & ! (out)
4447 #else
4448  c_loc(var), & ! (out)
4449 #endif
4450  dinfo, dp, 0, 0, start(:), count(:) ) ! (in)
4451 #ifdef NVIDIA
4452  var = work
4453  end block
4454 #endif
4455  else
4456  dim_size(:) = shape(var)
4457  do n = 1, 1
4458  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4459  log_error("FILE_read_var_realDP_1D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4460  call prc_abort
4461  end if
4462  end do
4463 #ifdef NVIDIA
4464  block
4465  real(dp), allocatable, target :: work(:)
4466  allocate(work, mold=var)
4467 #endif
4468  error = file_read_data_c( &
4469 #if defined(__GFORTRAN__) && __GNUC__ < 7
4470  cloc(var(1)), & ! (out)
4471 #elif defined(NVIDIA)
4472  c_loc(work), & ! (out)
4473 #else
4474  c_loc(var), & ! (out)
4475 #endif
4476  dinfo, dp, 0, 0, (/0/), (/0/) ) ! (in)
4477 #ifdef NVIDIA
4478  var = work
4479  end block
4480 #endif
4481  end if
4482  if ( error /= file_success_code ) then
4483  log_error("FILE_read_var_realDP_1D",*) 'failed to get data value: ', trim(varname)
4484  call prc_abort
4485  end if
4486 
4487  !$acc update device(var) if(acc_is_present(var))
4488 
4489  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4490 
4491  return
4492  end subroutine file_read_var_realdp_1d
4493  subroutine file_read_var_realsp_2d( &
4494  fid, varname, &
4495  var, &
4496  step, &
4497  allow_missing, &
4498  missing_value, &
4499  ntypes, dtype, &
4500  start, count )
4501  implicit none
4502 
4503  integer, intent( in) :: fid
4504  character(len=*), intent( in) :: varname
4505 #ifdef NVIDIA
4506  real(sp), intent(out), target :: var(:,:)
4507 #else
4508  real(sp), intent(out), target, contiguous :: var(:,:)
4509 #endif
4510  integer, intent( in), optional :: step
4511  logical, intent( in), optional :: allow_missing
4512  real(sp), intent( in), optional :: missing_value
4513  integer, intent( in), optional :: ntypes
4514  integer, intent( in), optional :: dtype
4515  integer, intent( in), optional :: start(:)
4516  integer, intent( in), optional :: count(:)
4517 
4518  integer :: step_
4519  logical(c_bool) :: allow_missing_
4520  real(sp) :: missing_value_
4521 
4522  type(datainfo) :: dinfo
4523  integer :: dim_size(2)
4524 
4525  integer :: error
4526  integer :: n
4527 
4528  intrinsic size, shape
4529  !---------------------------------------------------------------------------
4530 
4531  if ( .not. file_opened(fid) ) then
4532  log_error("FILE_read_var_realSP_2D",*) 'File is not opened. fid = ', fid
4533  call prc_abort
4534  end if
4535 
4536  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4537 
4538  if ( present(step) ) then
4539  step_ = step
4540  else
4541  step_ = 1
4542  end if
4543 
4544  if ( present(allow_missing) ) then
4545  allow_missing_ = allow_missing
4546  else
4547  allow_missing_ = .false.
4548  end if
4549 
4550  if ( present(missing_value) ) then
4551  missing_value_ = missing_value
4552  else
4553  missing_value_ = 0.0_sp
4554  end if
4555 
4556  !--- get data information
4557  error = file_get_datainfo_c( dinfo, & ! (out)
4558  file_files(fid)%fid, & ! (in)
4559  cstr(varname), & ! (in)
4560  step_, allow_missing_ ) ! (in)
4561 
4562  !--- verify
4563  if ( error /= file_success_code ) then
4564  if ( allow_missing_ ) then
4565  log_info("FILE_read_var_realSP_2D",*) '[INPUT]/[FILE] data not found! : ', &
4566  'varname= ',trim(varname),', step=',step_
4567  log_info("FILE_read_var_realSP_2D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
4568  var(:,:) = missing_value_
4569  return
4570  else
4571  log_error("FILE_read_var_realSP_2D",*) 'failed to get data information :'//trim(varname)
4572  call prc_abort
4573  end if
4574  end if
4575 
4576  if ( dinfo%rank /= 2 ) then
4577  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4578  log_error("FILE_read_var_realSP_2D",*) 'rank of '//trim(varname)//' is not 2', dinfo%rank
4579  call prc_abort
4580  end if
4581  end if
4582 
4583  if ( present(ntypes) ) then
4584 #if defined(__GFORTRAN__) && __GNUC__ < 7
4585  error = file_read_data_c( cloc(var(1,1)), & ! (out)
4586 #else
4587  error = file_read_data_c( c_loc(var), & ! (out)
4588 #endif
4589  dinfo, sp, ntypes, dtype, start(:), count(:) ) ! (in)
4590  else if ( present(start) .and. present(count) ) then
4591 #ifdef NVIDIA
4592  block
4593  real(sp), allocatable, target :: work(:,:)
4594  allocate(work, mold=var)
4595 #endif
4596  error = file_read_data_c( &
4597 #if defined(__GFORTRAN__) && __GNUC__ < 7
4598  cloc(var(1,1)), & ! (out)
4599 #elif defined(NVIDIA)
4600  c_loc(work), & ! (out)
4601 #else
4602  c_loc(var), & ! (out)
4603 #endif
4604  dinfo, sp, 0, 0, start(:), count(:) ) ! (in)
4605 #ifdef NVIDIA
4606  var = work
4607  end block
4608 #endif
4609  else
4610  dim_size(:) = shape(var)
4611  do n = 1, 2
4612  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4613  log_error("FILE_read_var_realSP_2D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4614  call prc_abort
4615  end if
4616  end do
4617 #ifdef NVIDIA
4618  block
4619  real(sp), allocatable, target :: work(:,:)
4620  allocate(work, mold=var)
4621 #endif
4622  error = file_read_data_c( &
4623 #if defined(__GFORTRAN__) && __GNUC__ < 7
4624  cloc(var(1,1)), & ! (out)
4625 #elif defined(NVIDIA)
4626  c_loc(work), & ! (out)
4627 #else
4628  c_loc(var), & ! (out)
4629 #endif
4630  dinfo, sp, 0, 0, (/0/), (/0/) ) ! (in)
4631 #ifdef NVIDIA
4632  var = work
4633  end block
4634 #endif
4635  end if
4636  if ( error /= file_success_code ) then
4637  log_error("FILE_read_var_realSP_2D",*) 'failed to get data value: ', trim(varname)
4638  call prc_abort
4639  end if
4640 
4641  !$acc update device(var) if(acc_is_present(var))
4642 
4643  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4644 
4645  return
4646  end subroutine file_read_var_realsp_2d
4647  subroutine file_read_var_realdp_2d( &
4648  fid, varname, &
4649  var, &
4650  step, &
4651  allow_missing, &
4652  missing_value, &
4653  ntypes, dtype, &
4654  start, count )
4655  implicit none
4656 
4657  integer, intent( in) :: fid
4658  character(len=*), intent( in) :: varname
4659 #ifdef NVIDIA
4660  real(dp), intent(out), target :: var(:,:)
4661 #else
4662  real(dp), intent(out), target, contiguous :: var(:,:)
4663 #endif
4664  integer, intent( in), optional :: step
4665  logical, intent( in), optional :: allow_missing
4666  real(dp), intent( in), optional :: missing_value
4667  integer, intent( in), optional :: ntypes
4668  integer, intent( in), optional :: dtype
4669  integer, intent( in), optional :: start(:)
4670  integer, intent( in), optional :: count(:)
4671 
4672  integer :: step_
4673  logical(c_bool) :: allow_missing_
4674  real(dp) :: missing_value_
4675 
4676  type(datainfo) :: dinfo
4677  integer :: dim_size(2)
4678 
4679  integer :: error
4680  integer :: n
4681 
4682  intrinsic size, shape
4683  !---------------------------------------------------------------------------
4684 
4685  if ( .not. file_opened(fid) ) then
4686  log_error("FILE_read_var_realDP_2D",*) 'File is not opened. fid = ', fid
4687  call prc_abort
4688  end if
4689 
4690  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4691 
4692  if ( present(step) ) then
4693  step_ = step
4694  else
4695  step_ = 1
4696  end if
4697 
4698  if ( present(allow_missing) ) then
4699  allow_missing_ = allow_missing
4700  else
4701  allow_missing_ = .false.
4702  end if
4703 
4704  if ( present(missing_value) ) then
4705  missing_value_ = missing_value
4706  else
4707  missing_value_ = 0.0_dp
4708  end if
4709 
4710  !--- get data information
4711  error = file_get_datainfo_c( dinfo, & ! (out)
4712  file_files(fid)%fid, & ! (in)
4713  cstr(varname), & ! (in)
4714  step_, allow_missing_ ) ! (in)
4715 
4716  !--- verify
4717  if ( error /= file_success_code ) then
4718  if ( allow_missing_ ) then
4719  log_info("FILE_read_var_realDP_2D",*) '[INPUT]/[FILE] data not found! : ', &
4720  'varname= ',trim(varname),', step=',step_
4721  log_info("FILE_read_var_realDP_2D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
4722  var(:,:) = missing_value_
4723  return
4724  else
4725  log_error("FILE_read_var_realDP_2D",*) 'failed to get data information :'//trim(varname)
4726  call prc_abort
4727  end if
4728  end if
4729 
4730  if ( dinfo%rank /= 2 ) then
4731  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4732  log_error("FILE_read_var_realDP_2D",*) 'rank of '//trim(varname)//' is not 2', dinfo%rank
4733  call prc_abort
4734  end if
4735  end if
4736 
4737  if ( present(ntypes) ) then
4738 #if defined(__GFORTRAN__) && __GNUC__ < 7
4739  error = file_read_data_c( cloc(var(1,1)), & ! (out)
4740 #else
4741  error = file_read_data_c( c_loc(var), & ! (out)
4742 #endif
4743  dinfo, dp, ntypes, dtype, start(:), count(:) ) ! (in)
4744  else if ( present(start) .and. present(count) ) then
4745 #ifdef NVIDIA
4746  block
4747  real(dp), allocatable, target :: work(:,:)
4748  allocate(work, mold=var)
4749 #endif
4750  error = file_read_data_c( &
4751 #if defined(__GFORTRAN__) && __GNUC__ < 7
4752  cloc(var(1,1)), & ! (out)
4753 #elif defined(NVIDIA)
4754  c_loc(work), & ! (out)
4755 #else
4756  c_loc(var), & ! (out)
4757 #endif
4758  dinfo, dp, 0, 0, start(:), count(:) ) ! (in)
4759 #ifdef NVIDIA
4760  var = work
4761  end block
4762 #endif
4763  else
4764  dim_size(:) = shape(var)
4765  do n = 1, 2
4766  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4767  log_error("FILE_read_var_realDP_2D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4768  call prc_abort
4769  end if
4770  end do
4771 #ifdef NVIDIA
4772  block
4773  real(dp), allocatable, target :: work(:,:)
4774  allocate(work, mold=var)
4775 #endif
4776  error = file_read_data_c( &
4777 #if defined(__GFORTRAN__) && __GNUC__ < 7
4778  cloc(var(1,1)), & ! (out)
4779 #elif defined(NVIDIA)
4780  c_loc(work), & ! (out)
4781 #else
4782  c_loc(var), & ! (out)
4783 #endif
4784  dinfo, dp, 0, 0, (/0/), (/0/) ) ! (in)
4785 #ifdef NVIDIA
4786  var = work
4787  end block
4788 #endif
4789  end if
4790  if ( error /= file_success_code ) then
4791  log_error("FILE_read_var_realDP_2D",*) 'failed to get data value: ', trim(varname)
4792  call prc_abort
4793  end if
4794 
4795  !$acc update device(var) if(acc_is_present(var))
4796 
4797  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4798 
4799  return
4800  end subroutine file_read_var_realdp_2d
4801  subroutine file_read_var_realsp_3d( &
4802  fid, varname, &
4803  var, &
4804  step, &
4805  allow_missing, &
4806  missing_value, &
4807  ntypes, dtype, &
4808  start, count )
4809  implicit none
4810 
4811  integer, intent( in) :: fid
4812  character(len=*), intent( in) :: varname
4813 #ifdef NVIDIA
4814  real(sp), intent(out), target :: var(:,:,:)
4815 #else
4816  real(sp), intent(out), target, contiguous :: var(:,:,:)
4817 #endif
4818  integer, intent( in), optional :: step
4819  logical, intent( in), optional :: allow_missing
4820  real(sp), intent( in), optional :: missing_value
4821  integer, intent( in), optional :: ntypes
4822  integer, intent( in), optional :: dtype
4823  integer, intent( in), optional :: start(:)
4824  integer, intent( in), optional :: count(:)
4825 
4826  integer :: step_
4827  logical(c_bool) :: allow_missing_
4828  real(sp) :: missing_value_
4829 
4830  type(datainfo) :: dinfo
4831  integer :: dim_size(3)
4832 
4833  integer :: error
4834  integer :: n
4835 
4836  intrinsic size, shape
4837  !---------------------------------------------------------------------------
4838 
4839  if ( .not. file_opened(fid) ) then
4840  log_error("FILE_read_var_realSP_3D",*) 'File is not opened. fid = ', fid
4841  call prc_abort
4842  end if
4843 
4844  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4845 
4846  if ( present(step) ) then
4847  step_ = step
4848  else
4849  step_ = 1
4850  end if
4851 
4852  if ( present(allow_missing) ) then
4853  allow_missing_ = allow_missing
4854  else
4855  allow_missing_ = .false.
4856  end if
4857 
4858  if ( present(missing_value) ) then
4859  missing_value_ = missing_value
4860  else
4861  missing_value_ = 0.0_sp
4862  end if
4863 
4864  !--- get data information
4865  error = file_get_datainfo_c( dinfo, & ! (out)
4866  file_files(fid)%fid, & ! (in)
4867  cstr(varname), & ! (in)
4868  step_, allow_missing_ ) ! (in)
4869 
4870  !--- verify
4871  if ( error /= file_success_code ) then
4872  if ( allow_missing_ ) then
4873  log_info("FILE_read_var_realSP_3D",*) '[INPUT]/[FILE] data not found! : ', &
4874  'varname= ',trim(varname),', step=',step_
4875  log_info("FILE_read_var_realSP_3D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
4876  var(:,:,:) = missing_value_
4877  return
4878  else
4879  log_error("FILE_read_var_realSP_3D",*) 'failed to get data information :'//trim(varname)
4880  call prc_abort
4881  end if
4882  end if
4883 
4884  if ( dinfo%rank /= 3 ) then
4885  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4886  log_error("FILE_read_var_realSP_3D",*) 'rank of '//trim(varname)//' is not 3', dinfo%rank
4887  call prc_abort
4888  end if
4889  end if
4890 
4891  if ( present(ntypes) ) then
4892 #if defined(__GFORTRAN__) && __GNUC__ < 7
4893  error = file_read_data_c( cloc(var(1,1,1)), & ! (out)
4894 #else
4895  error = file_read_data_c( c_loc(var), & ! (out)
4896 #endif
4897  dinfo, sp, ntypes, dtype, start(:), count(:) ) ! (in)
4898  else if ( present(start) .and. present(count) ) then
4899 #ifdef NVIDIA
4900  block
4901  real(sp), allocatable, target :: work(:,:,:)
4902  allocate(work, mold=var)
4903 #endif
4904  error = file_read_data_c( &
4905 #if defined(__GFORTRAN__) && __GNUC__ < 7
4906  cloc(var(1,1,1)), & ! (out)
4907 #elif defined(NVIDIA)
4908  c_loc(work), & ! (out)
4909 #else
4910  c_loc(var), & ! (out)
4911 #endif
4912  dinfo, sp, 0, 0, start(:), count(:) ) ! (in)
4913 #ifdef NVIDIA
4914  var = work
4915  end block
4916 #endif
4917  else
4918  dim_size(:) = shape(var)
4919  do n = 1, 3
4920  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4921  log_error("FILE_read_var_realSP_3D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4922  call prc_abort
4923  end if
4924  end do
4925 #ifdef NVIDIA
4926  block
4927  real(sp), allocatable, target :: work(:,:,:)
4928  allocate(work, mold=var)
4929 #endif
4930  error = file_read_data_c( &
4931 #if defined(__GFORTRAN__) && __GNUC__ < 7
4932  cloc(var(1,1,1)), & ! (out)
4933 #elif defined(NVIDIA)
4934  c_loc(work), & ! (out)
4935 #else
4936  c_loc(var), & ! (out)
4937 #endif
4938  dinfo, sp, 0, 0, (/0/), (/0/) ) ! (in)
4939 #ifdef NVIDIA
4940  var = work
4941  end block
4942 #endif
4943  end if
4944  if ( error /= file_success_code ) then
4945  log_error("FILE_read_var_realSP_3D",*) 'failed to get data value: ', trim(varname)
4946  call prc_abort
4947  end if
4948 
4949  !$acc update device(var) if(acc_is_present(var))
4950 
4951  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4952 
4953  return
4954  end subroutine file_read_var_realsp_3d
4955  subroutine file_read_var_realdp_3d( &
4956  fid, varname, &
4957  var, &
4958  step, &
4959  allow_missing, &
4960  missing_value, &
4961  ntypes, dtype, &
4962  start, count )
4963  implicit none
4964 
4965  integer, intent( in) :: fid
4966  character(len=*), intent( in) :: varname
4967 #ifdef NVIDIA
4968  real(dp), intent(out), target :: var(:,:,:)
4969 #else
4970  real(dp), intent(out), target, contiguous :: var(:,:,:)
4971 #endif
4972  integer, intent( in), optional :: step
4973  logical, intent( in), optional :: allow_missing
4974  real(dp), intent( in), optional :: missing_value
4975  integer, intent( in), optional :: ntypes
4976  integer, intent( in), optional :: dtype
4977  integer, intent( in), optional :: start(:)
4978  integer, intent( in), optional :: count(:)
4979 
4980  integer :: step_
4981  logical(c_bool) :: allow_missing_
4982  real(dp) :: missing_value_
4983 
4984  type(datainfo) :: dinfo
4985  integer :: dim_size(3)
4986 
4987  integer :: error
4988  integer :: n
4989 
4990  intrinsic size, shape
4991  !---------------------------------------------------------------------------
4992 
4993  if ( .not. file_opened(fid) ) then
4994  log_error("FILE_read_var_realDP_3D",*) 'File is not opened. fid = ', fid
4995  call prc_abort
4996  end if
4997 
4998  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
4999 
5000  if ( present(step) ) then
5001  step_ = step
5002  else
5003  step_ = 1
5004  end if
5005 
5006  if ( present(allow_missing) ) then
5007  allow_missing_ = allow_missing
5008  else
5009  allow_missing_ = .false.
5010  end if
5011 
5012  if ( present(missing_value) ) then
5013  missing_value_ = missing_value
5014  else
5015  missing_value_ = 0.0_dp
5016  end if
5017 
5018  !--- get data information
5019  error = file_get_datainfo_c( dinfo, & ! (out)
5020  file_files(fid)%fid, & ! (in)
5021  cstr(varname), & ! (in)
5022  step_, allow_missing_ ) ! (in)
5023 
5024  !--- verify
5025  if ( error /= file_success_code ) then
5026  if ( allow_missing_ ) then
5027  log_info("FILE_read_var_realDP_3D",*) '[INPUT]/[FILE] data not found! : ', &
5028  'varname= ',trim(varname),', step=',step_
5029  log_info("FILE_read_var_realDP_3D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
5030  var(:,:,:) = missing_value_
5031  return
5032  else
5033  log_error("FILE_read_var_realDP_3D",*) 'failed to get data information :'//trim(varname)
5034  call prc_abort
5035  end if
5036  end if
5037 
5038  if ( dinfo%rank /= 3 ) then
5039  if ( (.not. present(start)) .and. (.not. present(count)) ) then
5040  log_error("FILE_read_var_realDP_3D",*) 'rank of '//trim(varname)//' is not 3', dinfo%rank
5041  call prc_abort
5042  end if
5043  end if
5044 
5045  if ( present(ntypes) ) then
5046 #if defined(__GFORTRAN__) && __GNUC__ < 7
5047  error = file_read_data_c( cloc(var(1,1,1)), & ! (out)
5048 #else
5049  error = file_read_data_c( c_loc(var), & ! (out)
5050 #endif
5051  dinfo, dp, ntypes, dtype, start(:), count(:) ) ! (in)
5052  else if ( present(start) .and. present(count) ) then
5053 #ifdef NVIDIA
5054  block
5055  real(dp), allocatable, target :: work(:,:,:)
5056  allocate(work, mold=var)
5057 #endif
5058  error = file_read_data_c( &
5059 #if defined(__GFORTRAN__) && __GNUC__ < 7
5060  cloc(var(1,1,1)), & ! (out)
5061 #elif defined(NVIDIA)
5062  c_loc(work), & ! (out)
5063 #else
5064  c_loc(var), & ! (out)
5065 #endif
5066  dinfo, dp, 0, 0, start(:), count(:) ) ! (in)
5067 #ifdef NVIDIA
5068  var = work
5069  end block
5070 #endif
5071  else
5072  dim_size(:) = shape(var)
5073  do n = 1, 3
5074  if ( dinfo%dim_size(n) /= dim_size(n) ) then
5075  log_error("FILE_read_var_realDP_3D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
5076  call prc_abort
5077  end if
5078  end do
5079 #ifdef NVIDIA
5080  block
5081  real(dp), allocatable, target :: work(:,:,:)
5082  allocate(work, mold=var)
5083 #endif
5084  error = file_read_data_c( &
5085 #if defined(__GFORTRAN__) && __GNUC__ < 7
5086  cloc(var(1,1,1)), & ! (out)
5087 #elif defined(NVIDIA)
5088  c_loc(work), & ! (out)
5089 #else
5090  c_loc(var), & ! (out)
5091 #endif
5092  dinfo, dp, 0, 0, (/0/), (/0/) ) ! (in)
5093 #ifdef NVIDIA
5094  var = work
5095  end block
5096 #endif
5097  end if
5098  if ( error /= file_success_code ) then
5099  log_error("FILE_read_var_realDP_3D",*) 'failed to get data value: ', trim(varname)
5100  call prc_abort
5101  end if
5102 
5103  !$acc update device(var) if(acc_is_present(var))
5104 
5105  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
5106 
5107  return
5108  end subroutine file_read_var_realdp_3d
5109  subroutine file_read_var_realsp_4d( &
5110  fid, varname, &
5111  var, &
5112  step, &
5113  allow_missing, &
5114  missing_value, &
5115  ntypes, dtype, &
5116  start, count )
5117  implicit none
5118 
5119  integer, intent( in) :: fid
5120  character(len=*), intent( in) :: varname
5121 #ifdef NVIDIA
5122  real(sp), intent(out), target :: var(:,:,:,:)
5123 #else
5124  real(sp), intent(out), target, contiguous :: var(:,:,:,:)
5125 #endif
5126  integer, intent( in), optional :: step
5127  logical, intent( in), optional :: allow_missing
5128  real(sp), intent( in), optional :: missing_value
5129  integer, intent( in), optional :: ntypes
5130  integer, intent( in), optional :: dtype
5131  integer, intent( in), optional :: start(:)
5132  integer, intent( in), optional :: count(:)
5133 
5134  integer :: step_
5135  logical(c_bool) :: allow_missing_
5136  real(sp) :: missing_value_
5137 
5138  type(datainfo) :: dinfo
5139  integer :: dim_size(4)
5140 
5141  integer :: error
5142  integer :: n
5143 
5144  intrinsic size, shape
5145  !---------------------------------------------------------------------------
5146 
5147  if ( .not. file_opened(fid) ) then
5148  log_error("FILE_read_var_realSP_4D",*) 'File is not opened. fid = ', fid
5149  call prc_abort
5150  end if
5151 
5152  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
5153 
5154  if ( present(step) ) then
5155  step_ = step
5156  else
5157  step_ = 1
5158  end if
5159 
5160  if ( present(allow_missing) ) then
5161  allow_missing_ = allow_missing
5162  else
5163  allow_missing_ = .false.
5164  end if
5165 
5166  if ( present(missing_value) ) then
5167  missing_value_ = missing_value
5168  else
5169  missing_value_ = 0.0_sp
5170  end if
5171 
5172  !--- get data information
5173  error = file_get_datainfo_c( dinfo, & ! (out)
5174  file_files(fid)%fid, & ! (in)
5175  cstr(varname), & ! (in)
5176  step_, allow_missing_ ) ! (in)
5177 
5178  !--- verify
5179  if ( error /= file_success_code ) then
5180  if ( allow_missing_ ) then
5181  log_info("FILE_read_var_realSP_4D",*) '[INPUT]/[FILE] data not found! : ', &
5182  'varname= ',trim(varname),', step=',step_
5183  log_info("FILE_read_var_realSP_4D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
5184  var(:,:,:,:) = missing_value_
5185  return
5186  else
5187  log_error("FILE_read_var_realSP_4D",*) 'failed to get data information :'//trim(varname)
5188  call prc_abort
5189  end if
5190  end if
5191 
5192  if ( dinfo%rank /= 4 ) then
5193  if ( (.not. present(start)) .and. (.not. present(count)) ) then
5194  log_error("FILE_read_var_realSP_4D",*) 'rank of '//trim(varname)//' is not 4', dinfo%rank
5195  call prc_abort
5196  end if
5197  end if
5198 
5199  if ( present(ntypes) ) then
5200 #if defined(__GFORTRAN__) && __GNUC__ < 7
5201  error = file_read_data_c( cloc(var(1,1,1,1)), & ! (out)
5202 #else
5203  error = file_read_data_c( c_loc(var), & ! (out)
5204 #endif
5205  dinfo, sp, ntypes, dtype, start(:), count(:) ) ! (in)
5206  else if ( present(start) .and. present(count) ) then
5207 #ifdef NVIDIA
5208  block
5209  real(sp), allocatable, target :: work(:,:,:,:)
5210  allocate(work, mold=var)
5211 #endif
5212  error = file_read_data_c( &
5213 #if defined(__GFORTRAN__) && __GNUC__ < 7
5214  cloc(var(1,1,1,1)), & ! (out)
5215 #elif defined(NVIDIA)
5216  c_loc(work), & ! (out)
5217 #else
5218  c_loc(var), & ! (out)
5219 #endif
5220  dinfo, sp, 0, 0, start(:), count(:) ) ! (in)
5221 #ifdef NVIDIA
5222  var = work
5223  end block
5224 #endif
5225  else
5226  dim_size(:) = shape(var)
5227  do n = 1, 4
5228  if ( dinfo%dim_size(n) /= dim_size(n) ) then
5229  log_error("FILE_read_var_realSP_4D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
5230  call prc_abort
5231  end if
5232  end do
5233 #ifdef NVIDIA
5234  block
5235  real(sp), allocatable, target :: work(:,:,:,:)
5236  allocate(work, mold=var)
5237 #endif
5238  error = file_read_data_c( &
5239 #if defined(__GFORTRAN__) && __GNUC__ < 7
5240  cloc(var(1,1,1,1)), & ! (out)
5241 #elif defined(NVIDIA)
5242  c_loc(work), & ! (out)
5243 #else
5244  c_loc(var), & ! (out)
5245 #endif
5246  dinfo, sp, 0, 0, (/0/), (/0/) ) ! (in)
5247 #ifdef NVIDIA
5248  var = work
5249  end block
5250 #endif
5251  end if
5252  if ( error /= file_success_code ) then
5253  log_error("FILE_read_var_realSP_4D",*) 'failed to get data value: ', trim(varname)
5254  call prc_abort
5255  end if
5256 
5257  !$acc update device(var) if(acc_is_present(var))
5258 
5259  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
5260 
5261  return
5262  end subroutine file_read_var_realsp_4d
5263  subroutine file_read_var_realdp_4d( &
5264  fid, varname, &
5265  var, &
5266  step, &
5267  allow_missing, &
5268  missing_value, &
5269  ntypes, dtype, &
5270  start, count )
5271  implicit none
5272 
5273  integer, intent( in) :: fid
5274  character(len=*), intent( in) :: varname
5275 #ifdef NVIDIA
5276  real(dp), intent(out), target :: var(:,:,:,:)
5277 #else
5278  real(dp), intent(out), target, contiguous :: var(:,:,:,:)
5279 #endif
5280  integer, intent( in), optional :: step
5281  logical, intent( in), optional :: allow_missing
5282  real(dp), intent( in), optional :: missing_value
5283  integer, intent( in), optional :: ntypes
5284  integer, intent( in), optional :: dtype
5285  integer, intent( in), optional :: start(:)
5286  integer, intent( in), optional :: count(:)
5287 
5288  integer :: step_
5289  logical(c_bool) :: allow_missing_
5290  real(dp) :: missing_value_
5291 
5292  type(datainfo) :: dinfo
5293  integer :: dim_size(4)
5294 
5295  integer :: error
5296  integer :: n
5297 
5298  intrinsic size, shape
5299  !---------------------------------------------------------------------------
5300 
5301  if ( .not. file_opened(fid) ) then
5302  log_error("FILE_read_var_realDP_4D",*) 'File is not opened. fid = ', fid
5303  call prc_abort
5304  end if
5305 
5306  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
5307 
5308  if ( present(step) ) then
5309  step_ = step
5310  else
5311  step_ = 1
5312  end if
5313 
5314  if ( present(allow_missing) ) then
5315  allow_missing_ = allow_missing
5316  else
5317  allow_missing_ = .false.
5318  end if
5319 
5320  if ( present(missing_value) ) then
5321  missing_value_ = missing_value
5322  else
5323  missing_value_ = 0.0_dp
5324  end if
5325 
5326  !--- get data information
5327  error = file_get_datainfo_c( dinfo, & ! (out)
5328  file_files(fid)%fid, & ! (in)
5329  cstr(varname), & ! (in)
5330  step_, allow_missing_ ) ! (in)
5331 
5332  !--- verify
5333  if ( error /= file_success_code ) then
5334  if ( allow_missing_ ) then
5335  log_info("FILE_read_var_realDP_4D",*) '[INPUT]/[FILE] data not found! : ', &
5336  'varname= ',trim(varname),', step=',step_
5337  log_info("FILE_read_var_realDP_4D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
5338  var(:,:,:,:) = missing_value_
5339  return
5340  else
5341  log_error("FILE_read_var_realDP_4D",*) 'failed to get data information :'//trim(varname)
5342  call prc_abort
5343  end if
5344  end if
5345 
5346  if ( dinfo%rank /= 4 ) then
5347  if ( (.not. present(start)) .and. (.not. present(count)) ) then
5348  log_error("FILE_read_var_realDP_4D",*) 'rank of '//trim(varname)//' is not 4', dinfo%rank
5349  call prc_abort
5350  end if
5351  end if
5352 
5353  if ( present(ntypes) ) then
5354 #if defined(__GFORTRAN__) && __GNUC__ < 7
5355  error = file_read_data_c( cloc(var(1,1,1,1)), & ! (out)
5356 #else
5357  error = file_read_data_c( c_loc(var), & ! (out)
5358 #endif
5359  dinfo, dp, ntypes, dtype, start(:), count(:) ) ! (in)
5360  else if ( present(start) .and. present(count) ) then
5361 #ifdef NVIDIA
5362  block
5363  real(dp), allocatable, target :: work(:,:,:,:)
5364  allocate(work, mold=var)
5365 #endif
5366  error = file_read_data_c( &
5367 #if defined(__GFORTRAN__) && __GNUC__ < 7
5368  cloc(var(1,1,1,1)), & ! (out)
5369 #elif defined(NVIDIA)
5370  c_loc(work), & ! (out)
5371 #else
5372  c_loc(var), & ! (out)
5373 #endif
5374  dinfo, dp, 0, 0, start(:), count(:) ) ! (in)
5375 #ifdef NVIDIA
5376  var = work
5377  end block
5378 #endif
5379  else
5380  dim_size(:) = shape(var)
5381  do n = 1, 4
5382  if ( dinfo%dim_size(n) /= dim_size(n) ) then
5383  log_error("FILE_read_var_realDP_4D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
5384  call prc_abort
5385  end if
5386  end do
5387 #ifdef NVIDIA
5388  block
5389  real(dp), allocatable, target :: work(:,:,:,:)
5390  allocate(work, mold=var)
5391 #endif
5392  error = file_read_data_c( &
5393 #if defined(__GFORTRAN__) && __GNUC__ < 7
5394  cloc(var(1,1,1,1)), & ! (out)
5395 #elif defined(NVIDIA)
5396  c_loc(work), & ! (out)
5397 #else
5398  c_loc(var), & ! (out)
5399 #endif
5400  dinfo, dp, 0, 0, (/0/), (/0/) ) ! (in)
5401 #ifdef NVIDIA
5402  var = work
5403  end block
5404 #endif
5405  end if
5406  if ( error /= file_success_code ) then
5407  log_error("FILE_read_var_realDP_4D",*) 'failed to get data value: ', trim(varname)
5408  call prc_abort
5409  end if
5410 
5411  !$acc update device(var) if(acc_is_present(var))
5412 
5413  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
5414 
5415  return
5416  end subroutine file_read_var_realdp_4d
5417 
5418  !-----------------------------------------------------------------------------
5419  ! interface FILE_write
5420  !-----------------------------------------------------------------------------
5421  subroutine file_write_realsp_1d( &
5422  vid, var, &
5423  t_start, t_end, &
5424  ndims, &
5425  count, &
5426  start )
5427  implicit none
5428 
5429  integer, intent(in) :: vid
5430 #ifdef NVIDIA
5431  real(sp), intent(in) :: var(:)
5432 #else
5433  real(sp), intent(in), target, contiguous :: var(:)
5434 #endif
5435  real(dp), intent(in) :: t_start
5436  real(dp), intent(in) :: t_end
5437  integer, intent(in), optional :: ndims ! when var has been reshaped to 1D
5438  integer, intent(in), optional :: count(:)
5439  integer, intent(in), optional :: start(:)
5440  real(dp) :: ts, te
5441 
5442  integer :: start_(1)
5443 
5444  integer :: fid
5445  integer :: error
5446 
5447  intrinsic shape
5448  !---------------------------------------------------------------------------
5449 
5450  ts = t_start
5451  te = t_end
5452 
5453  fid = file_vars(vid)%fid
5454 
5455  if ( .not. file_opened(fid) ) then
5456  log_error("FILE_write_realSP_1D",*) 'File is not opened. fid = ', fid
5457  call prc_abort
5458  end if
5459 
5460  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5461 
5462  if ( present(ndims) ) then
5463  ! history variable has been reshaped to 1D
5464  ! In this case, start and count must be present
5465 
5466  if ( .not. present(start) ) then
5467  log_error("FILE_write_realSP_1D",*) 'start argument is neccessary when ndims is specified'
5468  call prc_abort
5469  end if
5470  if ( .not. present(count) ) then
5471  log_error("FILE_write_realSP_1D",*) 'count argument is neccessary when ndims is specified'
5472  call prc_abort
5473  end if
5474 
5475  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5476 #if defined(__GFORTRAN__) && __GNUC__ < 7
5477  cloc(var(1)), ts, te, ndims, sp, & ! (in)
5478 #else
5479  c_loc(var), ts, te, ndims, sp, & ! (in)
5480 #endif
5481  start, count ) ! (in)
5482  else
5483  ! this is for restart variable which keeps its original shape
5484  if ( present(start) ) then
5485  start_(:) = start(:)
5486  else
5487  start_(:) = 1
5488  end if
5489 
5490  !$acc update host(var) if(acc_is_present(var))
5491 
5492 #ifdef NVIDIA
5493  block
5494  real(sp), allocatable, target :: work(:)
5495  allocate(work, source=var)
5496 #endif
5497  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5498 #if defined(__GFORTRAN__) && __GNUC__ < 7
5499  cloc(var(1)), & ! (in)
5500 #elif defined(NVIDIA)
5501  c_loc(work), & ! (in)
5502 #else
5503  c_loc(var), & ! (in)
5504 #endif
5505  ts, te, 1, sp, & ! (in)
5506  start_, shape(var) ) ! (in)
5507 #ifdef NVIDIA
5508  end block
5509 #endif
5510  end if
5511  if ( error /= file_success_code ) then
5512  log_error("FILE_write_realSP_1D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5513  call prc_abort
5514  end if
5515 
5516  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5517 
5518  return
5519  end subroutine file_write_realsp_1d
5520  subroutine file_write_realdp_1d( &
5521  vid, var, &
5522  t_start, t_end, &
5523  ndims, &
5524  count, &
5525  start )
5526  implicit none
5527 
5528  integer, intent(in) :: vid
5529 #ifdef NVIDIA
5530  real(dp), intent(in) :: var(:)
5531 #else
5532  real(dp), intent(in), target, contiguous :: var(:)
5533 #endif
5534  real(dp), intent(in) :: t_start
5535  real(dp), intent(in) :: t_end
5536  integer, intent(in), optional :: ndims ! when var has been reshaped to 1D
5537  integer, intent(in), optional :: count(:)
5538  integer, intent(in), optional :: start(:)
5539  real(dp) :: ts, te
5540 
5541  integer :: start_(1)
5542 
5543  integer :: fid
5544  integer :: error
5545 
5546  intrinsic shape
5547  !---------------------------------------------------------------------------
5548 
5549  ts = t_start
5550  te = t_end
5551 
5552  fid = file_vars(vid)%fid
5553 
5554  if ( .not. file_opened(fid) ) then
5555  log_error("FILE_write_realDP_1D",*) 'File is not opened. fid = ', fid
5556  call prc_abort
5557  end if
5558 
5559  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5560 
5561  if ( present(ndims) ) then
5562  ! history variable has been reshaped to 1D
5563  ! In this case, start and count must be present
5564 
5565  if ( .not. present(start) ) then
5566  log_error("FILE_write_realDP_1D",*) 'start argument is neccessary when ndims is specified'
5567  call prc_abort
5568  end if
5569  if ( .not. present(count) ) then
5570  log_error("FILE_write_realDP_1D",*) 'count argument is neccessary when ndims is specified'
5571  call prc_abort
5572  end if
5573 
5574  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5575 #if defined(__GFORTRAN__) && __GNUC__ < 7
5576  cloc(var(1)), ts, te, ndims, dp, & ! (in)
5577 #else
5578  c_loc(var), ts, te, ndims, dp, & ! (in)
5579 #endif
5580  start, count ) ! (in)
5581  else
5582  ! this is for restart variable which keeps its original shape
5583  if ( present(start) ) then
5584  start_(:) = start(:)
5585  else
5586  start_(:) = 1
5587  end if
5588 
5589  !$acc update host(var) if(acc_is_present(var))
5590 
5591 #ifdef NVIDIA
5592  block
5593  real(dp), allocatable, target :: work(:)
5594  allocate(work, source=var)
5595 #endif
5596  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5597 #if defined(__GFORTRAN__) && __GNUC__ < 7
5598  cloc(var(1)), & ! (in)
5599 #elif defined(NVIDIA)
5600  c_loc(work), & ! (in)
5601 #else
5602  c_loc(var), & ! (in)
5603 #endif
5604  ts, te, 1, dp, & ! (in)
5605  start_, shape(var) ) ! (in)
5606 #ifdef NVIDIA
5607  end block
5608 #endif
5609  end if
5610  if ( error /= file_success_code ) then
5611  log_error("FILE_write_realDP_1D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5612  call prc_abort
5613  end if
5614 
5615  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5616 
5617  return
5618  end subroutine file_write_realdp_1d
5619  subroutine file_write_realsp_2d( &
5620  vid, var, &
5621  t_start, t_end, &
5622  start )
5623  implicit none
5624 
5625  integer, intent(in) :: vid
5626 #ifdef NVIDIA
5627  real(sp), intent(in) :: var(:,:)
5628 #else
5629  real(sp), intent(in), target, contiguous :: var(:,:)
5630 #endif
5631  real(dp), intent(in) :: t_start
5632  real(dp), intent(in) :: t_end
5633  integer, intent(in), optional :: start(:)
5634  real(dp) :: ts, te
5635 
5636  integer :: start_(2)
5637 
5638  integer :: fid
5639  integer :: error
5640 
5641  intrinsic shape
5642  !---------------------------------------------------------------------------
5643 
5644  ts = t_start
5645  te = t_end
5646 
5647  fid = file_vars(vid)%fid
5648 
5649  if ( .not. file_opened(fid) ) then
5650  log_error("FILE_write_realSP_2D",*) 'File is not opened. fid = ', fid
5651  call prc_abort
5652  end if
5653 
5654  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5655 
5656  ! this is for restart variable which keeps its original shape
5657  if ( present(start) ) then
5658  start_(:) = start(:)
5659  else
5660  start_(:) = 1
5661  end if
5662 
5663  !$acc update host(var) if(acc_is_present(var))
5664 
5665 #ifdef NVIDIA
5666  block
5667  real(sp), allocatable, target :: work(:,:)
5668  allocate(work, source=var)
5669 #endif
5670  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5671 #if defined(__GFORTRAN__) && __GNUC__ < 7
5672  cloc(var(1,1)), & ! (in)
5673 #elif defined(NVIDIA)
5674  c_loc(work), & ! (in)
5675 #else
5676  c_loc(var), & ! (in)
5677 #endif
5678  ts, te, 2, sp, & ! (in)
5679  start_, shape(var) ) ! (in)
5680 #ifdef NVIDIA
5681  end block
5682 #endif
5683  if ( error /= file_success_code ) then
5684  log_error("FILE_write_realSP_2D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5685  call prc_abort
5686  end if
5687 
5688  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5689 
5690  return
5691  end subroutine file_write_realsp_2d
5692  subroutine file_write_realdp_2d( &
5693  vid, var, &
5694  t_start, t_end, &
5695  start )
5696  implicit none
5697 
5698  integer, intent(in) :: vid
5699 #ifdef NVIDIA
5700  real(dp), intent(in) :: var(:,:)
5701 #else
5702  real(dp), intent(in), target, contiguous :: var(:,:)
5703 #endif
5704  real(dp), intent(in) :: t_start
5705  real(dp), intent(in) :: t_end
5706  integer, intent(in), optional :: start(:)
5707  real(dp) :: ts, te
5708 
5709  integer :: start_(2)
5710 
5711  integer :: fid
5712  integer :: error
5713 
5714  intrinsic shape
5715  !---------------------------------------------------------------------------
5716 
5717  ts = t_start
5718  te = t_end
5719 
5720  fid = file_vars(vid)%fid
5721 
5722  if ( .not. file_opened(fid) ) then
5723  log_error("FILE_write_realDP_2D",*) 'File is not opened. fid = ', fid
5724  call prc_abort
5725  end if
5726 
5727  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5728 
5729  ! this is for restart variable which keeps its original shape
5730  if ( present(start) ) then
5731  start_(:) = start(:)
5732  else
5733  start_(:) = 1
5734  end if
5735 
5736  !$acc update host(var) if(acc_is_present(var))
5737 
5738 #ifdef NVIDIA
5739  block
5740  real(dp), allocatable, target :: work(:,:)
5741  allocate(work, source=var)
5742 #endif
5743  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5744 #if defined(__GFORTRAN__) && __GNUC__ < 7
5745  cloc(var(1,1)), & ! (in)
5746 #elif defined(NVIDIA)
5747  c_loc(work), & ! (in)
5748 #else
5749  c_loc(var), & ! (in)
5750 #endif
5751  ts, te, 2, dp, & ! (in)
5752  start_, shape(var) ) ! (in)
5753 #ifdef NVIDIA
5754  end block
5755 #endif
5756  if ( error /= file_success_code ) then
5757  log_error("FILE_write_realDP_2D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5758  call prc_abort
5759  end if
5760 
5761  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5762 
5763  return
5764  end subroutine file_write_realdp_2d
5765  subroutine file_write_realsp_3d( &
5766  vid, var, &
5767  t_start, t_end, &
5768  start )
5769  implicit none
5770 
5771  integer, intent(in) :: vid
5772 #ifdef NVIDIA
5773  real(sp), intent(in) :: var(:,:,:)
5774 #else
5775  real(sp), intent(in), target, contiguous :: var(:,:,:)
5776 #endif
5777  real(dp), intent(in) :: t_start
5778  real(dp), intent(in) :: t_end
5779  integer, intent(in), optional :: start(:)
5780  real(dp) :: ts, te
5781 
5782  integer :: start_(3)
5783 
5784  integer :: fid
5785  integer :: error
5786 
5787  intrinsic shape
5788  !---------------------------------------------------------------------------
5789 
5790  ts = t_start
5791  te = t_end
5792 
5793  fid = file_vars(vid)%fid
5794 
5795  if ( .not. file_opened(fid) ) then
5796  log_error("FILE_write_realSP_3D",*) 'File is not opened. fid = ', fid
5797  call prc_abort
5798  end if
5799 
5800  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5801 
5802  ! this is for restart variable which keeps its original shape
5803  if ( present(start) ) then
5804  start_(:) = start(:)
5805  else
5806  start_(:) = 1
5807  end if
5808 
5809  !$acc update host(var) if(acc_is_present(var))
5810 
5811 #ifdef NVIDIA
5812  block
5813  real(sp), allocatable, target :: work(:,:,:)
5814  allocate(work, source=var)
5815 #endif
5816  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5817 #if defined(__GFORTRAN__) && __GNUC__ < 7
5818  cloc(var(1,1,1)), & ! (in)
5819 #elif defined(NVIDIA)
5820  c_loc(work), & ! (in)
5821 #else
5822  c_loc(var), & ! (in)
5823 #endif
5824  ts, te, 3, sp, & ! (in)
5825  start_, shape(var) ) ! (in)
5826 #ifdef NVIDIA
5827  end block
5828 #endif
5829  if ( error /= file_success_code ) then
5830  log_error("FILE_write_realSP_3D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5831  call prc_abort
5832  end if
5833 
5834  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5835 
5836  return
5837  end subroutine file_write_realsp_3d
5838  subroutine file_write_realdp_3d( &
5839  vid, var, &
5840  t_start, t_end, &
5841  start )
5842  implicit none
5843 
5844  integer, intent(in) :: vid
5845 #ifdef NVIDIA
5846  real(dp), intent(in) :: var(:,:,:)
5847 #else
5848  real(dp), intent(in), target, contiguous :: var(:,:,:)
5849 #endif
5850  real(dp), intent(in) :: t_start
5851  real(dp), intent(in) :: t_end
5852  integer, intent(in), optional :: start(:)
5853  real(dp) :: ts, te
5854 
5855  integer :: start_(3)
5856 
5857  integer :: fid
5858  integer :: error
5859 
5860  intrinsic shape
5861  !---------------------------------------------------------------------------
5862 
5863  ts = t_start
5864  te = t_end
5865 
5866  fid = file_vars(vid)%fid
5867 
5868  if ( .not. file_opened(fid) ) then
5869  log_error("FILE_write_realDP_3D",*) 'File is not opened. fid = ', fid
5870  call prc_abort
5871  end if
5872 
5873  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5874 
5875  ! this is for restart variable which keeps its original shape
5876  if ( present(start) ) then
5877  start_(:) = start(:)
5878  else
5879  start_(:) = 1
5880  end if
5881 
5882  !$acc update host(var) if(acc_is_present(var))
5883 
5884 #ifdef NVIDIA
5885  block
5886  real(dp), allocatable, target :: work(:,:,:)
5887  allocate(work, source=var)
5888 #endif
5889  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5890 #if defined(__GFORTRAN__) && __GNUC__ < 7
5891  cloc(var(1,1,1)), & ! (in)
5892 #elif defined(NVIDIA)
5893  c_loc(work), & ! (in)
5894 #else
5895  c_loc(var), & ! (in)
5896 #endif
5897  ts, te, 3, dp, & ! (in)
5898  start_, shape(var) ) ! (in)
5899 #ifdef NVIDIA
5900  end block
5901 #endif
5902  if ( error /= file_success_code ) then
5903  log_error("FILE_write_realDP_3D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5904  call prc_abort
5905  end if
5906 
5907  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5908 
5909  return
5910  end subroutine file_write_realdp_3d
5911  subroutine file_write_realsp_4d( &
5912  vid, var, &
5913  t_start, t_end, &
5914  start )
5915  implicit none
5916 
5917  integer, intent(in) :: vid
5918 #ifdef NVIDIA
5919  real(sp), intent(in) :: var(:,:,:,:)
5920 #else
5921  real(sp), intent(in), target, contiguous :: var(:,:,:,:)
5922 #endif
5923  real(dp), intent(in) :: t_start
5924  real(dp), intent(in) :: t_end
5925  integer, intent(in), optional :: start(:)
5926  real(dp) :: ts, te
5927 
5928  integer :: start_(4)
5929 
5930  integer :: fid
5931  integer :: error
5932 
5933  intrinsic shape
5934  !---------------------------------------------------------------------------
5935 
5936  ts = t_start
5937  te = t_end
5938 
5939  fid = file_vars(vid)%fid
5940 
5941  if ( .not. file_opened(fid) ) then
5942  log_error("FILE_write_realSP_4D",*) 'File is not opened. fid = ', fid
5943  call prc_abort
5944  end if
5945 
5946  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5947 
5948  ! this is for restart variable which keeps its original shape
5949  if ( present(start) ) then
5950  start_(:) = start(:)
5951  else
5952  start_(:) = 1
5953  end if
5954 
5955  !$acc update host(var) if(acc_is_present(var))
5956 
5957 #ifdef NVIDIA
5958  block
5959  real(sp), allocatable, target :: work(:,:,:,:)
5960  allocate(work, source=var)
5961 #endif
5962  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
5963 #if defined(__GFORTRAN__) && __GNUC__ < 7
5964  cloc(var(1,1,1,1)), & ! (in)
5965 #elif defined(NVIDIA)
5966  c_loc(work), & ! (in)
5967 #else
5968  c_loc(var), & ! (in)
5969 #endif
5970  ts, te, 4, sp, & ! (in)
5971  start_, shape(var) ) ! (in)
5972 #ifdef NVIDIA
5973  end block
5974 #endif
5975  if ( error /= file_success_code ) then
5976  log_error("FILE_write_realSP_4D",*) 'failed to write data: ', trim(file_vars(vid)%name)
5977  call prc_abort
5978  end if
5979 
5980  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
5981 
5982  return
5983  end subroutine file_write_realsp_4d
5984  subroutine file_write_realdp_4d( &
5985  vid, var, &
5986  t_start, t_end, &
5987  start )
5988  implicit none
5989 
5990  integer, intent(in) :: vid
5991 #ifdef NVIDIA
5992  real(dp), intent(in) :: var(:,:,:,:)
5993 #else
5994  real(dp), intent(in), target, contiguous :: var(:,:,:,:)
5995 #endif
5996  real(dp), intent(in) :: t_start
5997  real(dp), intent(in) :: t_end
5998  integer, intent(in), optional :: start(:)
5999  real(dp) :: ts, te
6000 
6001  integer :: start_(4)
6002 
6003  integer :: fid
6004  integer :: error
6005 
6006  intrinsic shape
6007  !---------------------------------------------------------------------------
6008 
6009  ts = t_start
6010  te = t_end
6011 
6012  fid = file_vars(vid)%fid
6013 
6014  if ( .not. file_opened(fid) ) then
6015  log_error("FILE_write_realDP_4D",*) 'File is not opened. fid = ', fid
6016  call prc_abort
6017  end if
6018 
6019  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6020 
6021  ! this is for restart variable which keeps its original shape
6022  if ( present(start) ) then
6023  start_(:) = start(:)
6024  else
6025  start_(:) = 1
6026  end if
6027 
6028  !$acc update host(var) if(acc_is_present(var))
6029 
6030 #ifdef NVIDIA
6031  block
6032  real(dp), allocatable, target :: work(:,:,:,:)
6033  allocate(work, source=var)
6034 #endif
6035  error = file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
6036 #if defined(__GFORTRAN__) && __GNUC__ < 7
6037  cloc(var(1,1,1,1)), & ! (in)
6038 #elif defined(NVIDIA)
6039  c_loc(work), & ! (in)
6040 #else
6041  c_loc(var), & ! (in)
6042 #endif
6043  ts, te, 4, dp, & ! (in)
6044  start_, shape(var) ) ! (in)
6045 #ifdef NVIDIA
6046  end block
6047 #endif
6048  if ( error /= file_success_code ) then
6049  log_error("FILE_write_realDP_4D",*) 'failed to write data: ', trim(file_vars(vid)%name)
6050  call prc_abort
6051  end if
6052 
6053  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6054 
6055  return
6056  end subroutine file_write_realdp_4d
6057 
6058  !-----------------------------------------------------------------------------
6059  ! exit netCDF define mode and enter data mode
6060  subroutine file_enddef( fid )
6061  implicit none
6062 
6063  integer, intent(in) :: fid
6064 
6065  integer :: error
6066  !---------------------------------------------------------------------------
6067 
6068  if ( .not. file_opened(fid) ) return
6069 
6070  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6071 
6072  error = file_enddef_c( file_files(fid)%fid )
6073 
6074  if ( error == file_success_code ) then
6075 
6076  log_newline
6077  log_info("FILE_enddef",'(1x,A,I3.3,2A)') &
6078  'End define mode : No.', fid, ', name = ', trim(file_files(fid)%name)
6079 
6080  else
6081  log_error("FILE_enddef",*) 'failed to exit define mode'
6082  call prc_abort
6083  end if
6084 
6085  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6086 
6087  return
6088  end subroutine file_enddef
6089 
6090  !-----------------------------------------------------------------------------
6091  ! enter netCDF define mode and enter data mode
6092  subroutine file_redef( fid )
6093  implicit none
6094 
6095  integer, intent(in) :: fid
6096 
6097  integer :: error
6098  !---------------------------------------------------------------------------
6099 
6100  if ( .not. file_opened(fid) ) return
6101 
6102  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6103 
6104  error = file_redef_c( file_files(fid)%fid )
6105 
6106  if ( error == file_success_code ) then
6107 
6108  log_newline
6109  log_info("FILE_redef",'(1x,A,I3.3,2A)') &
6110  'Enter to define mode : No.', fid, ', name = ', trim(file_files(fid)%name)
6111 
6112  else
6113  log_error("FILE_redef",*) 'failed to enter to define mode'
6114  call prc_abort
6115  end if
6116 
6117  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6118 
6119  return
6120  end subroutine file_redef
6121 
6122  !-----------------------------------------------------------------------------
6123  ! This subroutine is used when PnetCDF I/O method is enabled
6124  subroutine file_attach_buffer( &
6125  fid, &
6126  buf_amount )
6127  implicit none
6128 
6129  integer, intent(in) :: fid
6130  integer(8), intent(in) :: buf_amount
6131 
6132  integer :: error
6133  !---------------------------------------------------------------------------
6134 
6135  if ( .not. file_opened(fid) ) return
6136 
6137  if ( file_files(fid)%buffer_size > 0 ) then
6138  call file_detach_buffer(fid)
6139  end if
6140 
6141  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6142 
6143  error = file_attach_buffer_c( file_files(fid)%fid, buf_amount )
6144 
6145  if ( error /= file_success_code ) then
6146  log_error("FILE_attach_buffer",*) 'failed to attach buffer in PnetCDF'
6147  call prc_abort
6148  end if
6149 
6150  log_newline
6151  log_info("FILE_attach_buffer",'(1x,A,I3.3,3A,I10)') &
6152  'Attach buffer : No.', fid, ', name = ', trim(file_files(fid)%name), &
6153  ', size = ', buf_amount
6154 
6155  file_files(fid)%buffer_size = buf_amount
6156 
6157  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6158 
6159  return
6160  end subroutine file_attach_buffer
6161 
6162  !-----------------------------------------------------------------------------
6163  ! This subroutine is used when PnetCDF I/O method is enabled
6164  subroutine file_detach_buffer( fid )
6165  implicit none
6166 
6167  integer, intent(in) :: fid
6168 
6169  integer :: error
6170  !---------------------------------------------------------------------------
6171 
6172  if ( .not. file_opened(fid) ) return
6173 
6174  if ( file_files(fid)%fid < 0 ) return ! already closed
6175 
6176  if ( file_files(fid)%buffer_size < 0 ) return ! not attached
6177 
6178  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6179 
6180  error = file_detach_buffer_c( file_files(fid)%fid )
6181 
6182  if ( error /= file_success_code ) then
6183  log_error("FILE_detach_buffer",*) 'failed to detach buffer in PnetCDF'
6184  call prc_abort
6185  end if
6186 
6187  log_newline
6188  log_info("FILE_detach_buffer",'(1x,A,I3.3,2A)') &
6189  'Detach buffer : No.', fid, ', name = ', trim(file_files(fid)%name)
6190 
6191  file_files(fid)%buffer_size = -1
6192 
6193  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6194 
6195  return
6196  end subroutine file_detach_buffer
6197 
6198  !-----------------------------------------------------------------------------
6199  ! flush data
6200  subroutine file_flush( fid )
6201  implicit none
6202 
6203  integer, intent(in) :: fid
6204 
6205  integer :: error
6206  !---------------------------------------------------------------------------
6207 
6208  if ( .not. file_opened(fid) ) return
6209 
6210  if ( file_files(fid)%fid < 0 ) return ! already closed
6211 
6212  call prof_rapstart('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6213 
6214  error = file_flush_c( file_files(fid)%fid )
6215 
6216  if ( error == file_success_code ) then
6217 
6218 !!$ LOG_NEWLINE
6219 !!$ LOG_INFO("FILE_flush",'(1xA,I3.3,2A)') &
6220 !!$ 'Flush : No.', fid, ', name = ', trim(FILE_files(fid)%name)
6221 
6222  else
6223  log_error("FILE_flush",*) 'failed to flush data to netcdf file'
6224  call prc_abort
6225  end if
6226 
6227  call prof_rapend ('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6228 
6229  return
6230  end subroutine file_flush
6231 
6232  !-----------------------------------------------------------------------------
6233  subroutine file_close( fid, abort )
6234  implicit none
6235  integer, intent(in) :: fid
6236  logical, intent(in), optional :: abort
6237 
6238  logical(c_bool) :: abort_
6239  integer :: error
6240  integer :: n
6241  !---------------------------------------------------------------------------
6242 
6243  if ( .not. file_opened(fid) ) return
6244 
6245  if ( file_files(fid)%fid < 0 ) return ! already closed
6246 
6247  call prof_rapstart('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6248 
6249  if ( present(abort) ) then
6250  abort_ = abort
6251  else
6252  abort_ = .false.
6253  end if
6254 
6255  error = file_close_c( file_files(fid)%fid, abort_ )
6256 
6257  if ( error == file_success_code ) then
6258 
6259  log_newline
6260  log_info("FILE_close",'(1x,A,I3.3,2A)') &
6261  'Close : No.', fid, ', name = ', trim(file_files(fid)%name)
6262 
6263  elseif( error /= file_already_closed_code ) then
6264  log_error("FILE_close",*) 'failed to close file: ', trim(file_files(fid)%name)
6265  if ( .not. abort_ ) call prc_abort
6266  end if
6267 
6268  file_files(fid)%fid = -1
6269  file_files(fid)%name = ''
6270  file_files(fid)%aggregate = .false.
6271  file_files(fid)%buffer_size = -1
6272 
6273  do n = 1, file_nvars
6274  if ( file_vars(n)%fid == fid ) then
6275  file_vars(n)%vid = -1
6276  file_vars(n)%name = ''
6277  end if
6278  end do
6279 
6280  call prof_rapend ('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6281 
6282  return
6283  end subroutine file_close
6284  !-----------------------------------------------------------------------------
6285  subroutine file_close_all( &
6286  skip_abort )
6287  implicit none
6288  logical, intent(in), optional :: skip_abort
6289 
6290  integer :: fid
6291  !---------------------------------------------------------------------------
6292 
6293  do fid = 1, file_nfiles
6294  call file_close( fid, skip_abort )
6295  enddo
6296 
6297  return
6298  end subroutine file_close_all
6299 
6300  !-----------------------------------------------------------------------------
6302  !-----------------------------------------------------------------------------
6303  subroutine file_get_cftunits(date, tunits)
6304  implicit none
6305 
6306  integer, intent(in) :: date(6)
6307  character(len=*), intent(out) :: tunits
6308  !---------------------------------------------------------------------------
6309 
6310  write(tunits,'(a,i4.4,"-",i2.2,"-",i2.2," ",i2.2,":",i2.2,":",i2.2)') 'seconds since ', date
6311 
6312  return
6313  end subroutine file_get_cftunits
6314 
6315  function file_get_aggregate( fid )
6316  integer, intent(in) :: fid
6317  logical :: file_get_aggregate
6318 
6319  if ( .not. file_opened(fid) ) then
6320  file_get_aggregate = .false.
6321  else
6322  file_get_aggregate = file_files(fid)%aggregate
6323  end if
6324 
6325  return
6326  end function file_get_aggregate
6327 
6328  !-----------------------------------------------------------------------------
6329  ! private
6330  !-----------------------------------------------------------------------------
6331 
6332  !-----------------------------------------------------------------------------
6333  subroutine file_get_fid( &
6334  basename, &
6335  mode, &
6336  rankid, &
6337  single, &
6338  fid, &
6339  existed, &
6340  allnodes, &
6341  aggregate, &
6342  postfix )
6343  use scale_prc, only: &
6346  implicit none
6347 
6348  character(len=*), intent( in) :: basename
6349  integer, intent( in) :: mode
6350  integer, intent( in) :: rankid
6351  logical, intent( in) :: single
6352 
6353  integer, intent(out) :: fid
6354  logical, intent(out) :: existed
6355 
6356  logical, intent( in), optional :: allnodes
6357  logical, intent( in), optional :: aggregate
6358  character(len=*), intent( in), optional :: postfix
6359 
6360  character(len=FILE_HSHORT) :: rwname(0:2)
6361  data rwname / 'READ','WRITE','APPEND' /
6362 
6363  character(len=FILE_HLONG) :: fname
6364  integer :: n
6365 
6366  logical :: allnodes_
6367  logical :: aggregate_
6368  integer :: cfid
6369  integer :: error
6370  integer :: mpi_comm
6371  !---------------------------------------------------------------------------
6372 
6373  !--- check aggregate (parallel I/O on a single shared netCDF file)
6374 
6375  if ( present(allnodes) ) then
6376  allnodes_ = allnodes
6377  else
6378  allnodes_ = .true.
6379  end if
6380 
6381  ! check to do PnetCDF I/O
6382  if ( present(aggregate) ) then
6383  aggregate_ = aggregate
6384  else
6385  aggregate_ = file_aggregate
6386  end if
6387 
6388  if ( aggregate_ ) then
6389  mpi_comm = prc_local_comm_world
6390  else
6391  mpi_comm = prc_comm_null
6392  end if
6393 
6394  if ( present(postfix) ) then
6395  call io_get_fname(fname, trim(basename)//trim(postfix))
6396  elseif ( aggregate_ ) then
6397  call io_get_fname(fname, basename)
6398  elseif ( single ) then
6399  call io_get_fname(fname, basename, rank=-1)
6400  else
6401  call io_get_fname(fname, basename, rank=rankid)
6402  endif
6403 
6404  !--- search existing file
6405  fid = -1
6406  do n = 1, file_nfiles
6407  if ( fname == file_files(n)%name ) then
6408  fid = n
6409  exit
6410  end if
6411  enddo
6412 
6413  if ( file_opened(fid) ) then
6414  existed = .true.
6415  return
6416  end if
6417 
6418  call prof_rapstart('FILE', 2, disable_barrier = ( .not. allnodes_ ) .or. single )
6419 
6420  error = file_open_c( cfid, & ! (out)
6421  cstr(fname), mode, mpi_comm ) ! (in)
6422 
6423  if ( error /= file_success_code ) then
6424  log_error("FILE_get_fid",*) 'failed to open file :'//trim(fname)//'.nc'
6425  call prc_abort
6426  end if
6427 
6428  file_nfiles = file_nfiles + 1
6429  fid = file_nfiles
6430 
6431  file_files(fid)%name = fname
6432  file_files(fid)%fid = cfid
6433  file_files(fid)%aggregate = aggregate_
6434  file_files(fid)%single = single
6435  file_files(fid)%allnodes = allnodes_ .and. (.not. single)
6436  file_files(fid)%buffer_size = -1
6437 
6438  log_newline
6439  log_info("FILE_get_fid",'(1x,A,A6,A,I3.3,2A)') &
6440  'Registration (', trim(rwname(mode)), ') : No.', fid, ', name = ', trim(fname)
6441 
6442  existed = .false.
6443 
6444  call prof_rapend ('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6445 
6446  return
6447  end subroutine file_get_fid
6448 
6449 #if defined(__GFORTRAN__) && __GNUC__ < 7
6450  function cloc_sp( x )
6451  use iso_c_binding
6452  implicit none
6453  real(sp), target, intent(in) :: x
6454  type(c_ptr) :: cloc_sp
6455  cloc_sp = c_loc(x)
6456  return
6457  end function cloc_sp
6458  function cloc_dp( x )
6459  use iso_c_binding
6460  implicit none
6461  real(dp), target, intent(in) :: x
6462  type(c_ptr) :: cloc_dp
6463  cloc_dp = c_loc(x)
6464  return
6465  end function cloc_dp
6466 #endif
6467 
6468 end module scale_file
6469 !-------------------------------------------------------------------------------
6470 
6471 
6472 !--
6473 ! vi:set readonly sw=4 ts=8
6474 !
6475 !Local Variables:
6476 !mode: f90
6477 !buffer-read-only: t
6478 !End:
6479 !
6480 !++
scale_precision::sp
integer, parameter, public sp
Definition: scale_precision.F90:31
scale_file::file_get_stepsize
subroutine, public file_get_stepsize(fid, varname, len, error)
get number of steps
Definition: scale_file.F90:3335
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:350
file_add_associatedvariable_c
int file_add_associatedvariable_c(const int fid, const char *vname)
Definition: scale_file_netcdf.c:1204
file_def_axis_c
int file_def_axis_c(const int fid, const char *name, const char *desc, const char *units, const char *dim_name, const int dtype, const int dim_size, const int bounds)
Definition: scale_file_netcdf.c:1286
scale_file::file_close_all
subroutine, public file_close_all(skip_abort)
Definition: scale_file.F90:6287
scale_file::file_open
subroutine, public file_open(basename, fid, mode, single, allnodes, aggregate, rankid, postfix)
Definition: scale_file.F90:536
file_read_data_c
int file_read_data_c(void *var, const datainfo_t *dinfo, const int precision, const int ntypes, const int dtype, const int *start, const int *count)
Definition: scale_file_netcdf.c:697
scale_file::file_enddef
subroutine, public file_enddef(fid)
Definition: scale_file.F90:6061
file_write_associatedcoordinate_c
int file_write_associatedcoordinate_c(const int fid, const char *name, const void *val, const int ndims, const int precision, const int *start, const int *count)
Definition: scale_file_netcdf.c:1500
file_detach_buffer_c
int file_detach_buffer_c(const int fid)
Definition: scale_file_netcdf.c:1854
scale_prc::prc_set_file_closer
subroutine, public prc_set_file_closer(routine)
Definition: scale_prc.F90:1048
scale_precision
module PRECISION
Definition: scale_precision.F90:14
file_set_attribute_float_c
int file_set_attribute_float_c(const int fid, const char *vname, const char *key, const float *value, const int len)
Definition: scale_file_netcdf.c:1124
scale_prc::prc_local_comm_world
integer, public prc_local_comm_world
local communicator
Definition: scale_prc.F90:89
scale_file::file_attach_buffer
subroutine, public file_attach_buffer(fid, buf_amount)
Definition: scale_file.F90:6127
file_get_dim_length_c
int file_get_dim_length_c(int *len, const int fid, const char *dimname, const bool suppress)
Definition: scale_file_netcdf.c:258
scale_file::file_flush
subroutine, public file_flush(fid)
Definition: scale_file.F90:6201
scale_prof::prof_rapstart
subroutine, public prof_rapstart(rapname_base, level, disable_barrier)
Start raptime.
Definition: scale_prof.F90:174
scale_file::file_allnodes
logical function, public file_allnodes(fid)
check if the file is allnodes
Definition: scale_file.F90:612
file_redef_c
int file_redef_c(const int fid)
Definition: scale_file_netcdf.c:1829
file_close_c
int file_close_c(const int fid, const bool abort)
Definition: scale_file_netcdf.c:2006
scale_file::file_get_dimlength
subroutine, public file_get_dimlength(fid, dimname, len, error)
get length of dimension
Definition: scale_file.F90:633
scale_file::file_opened
logical function, public file_opened(fid)
check if the file is opened?
Definition: scale_file.F90:578
scale_file
module file
Definition: scale_file.F90:15
file_get_attribute_double_c
int file_get_attribute_double_c(double *value, const int fid, const char *vname, const char *key, const bool suppress, const int len)
Definition: scale_file_netcdf.c:997
scale_file::file_def_axis
subroutine, public file_def_axis(fid, name, desc, units, dim_name, dtype, dim_size, bounds)
Definition: scale_file.F90:770
file_get_step_size_c
int file_get_step_size_c(int *len, const int fid, const char *varname)
Definition: scale_file_netcdf.c:643
file_get_varname_c
int file_get_varname_c(char *name, const int fid, const int vid, const int len)
Definition: scale_file_netcdf.c:320
scale_prc
module PROCESS
Definition: scale_prc.F90:11
file_get_attribute_int_c
int file_get_attribute_int_c(int *value, const int fid, const char *vname, const char *key, const bool suppress, const int len)
Definition: scale_file_netcdf.c:911
scale_io
module STDIO
Definition: scale_io.F90:10
scale_prc::prc_comm_null
integer, parameter, public prc_comm_null
Definition: scale_prc.F90:69
scale_file::file_close
subroutine, public file_close(fid, abort)
Definition: scale_file.F90:6234
scale_file::file_def_associatedcoordinate
subroutine, public file_def_associatedcoordinate(fid, name, desc, units, dim_names, dtype)
Definition: scale_file.F90:1472
scale_file::i
logical, public i
Definition: scale_file.F90:196
file_set_attribute_text_c
int file_set_attribute_text_c(const int fid, const char *vname, const char *key, const char *value)
Definition: scale_file_netcdf.c:1040
file_put_associatedcoordinate_c
int file_put_associatedcoordinate_c(const int fid, const char *name, const char *desc, const char *units, const char **dim_names, const int ndims, const int dtype, const void *val, const int precision)
Definition: scale_file_netcdf.c:1397
scale_file_h::file_already_existed_code
integer, parameter, public file_already_existed_code
Definition: scale_file_h.F90:42
scale_prof
module profiler
Definition: scale_prof.F90:11
file_get_datainfo_c
int file_get_datainfo_c(datainfo_t *dinfo, const int fid, const char *varname, const int step, const bool suppress)
Definition: scale_file_netcdf.c:345
scale_precision::dp
integer, parameter, public dp
Definition: scale_precision.F90:32
file_set_attribute_double_c
int file_set_attribute_double_c(const int fid, const char *vname, const char *key, const double *value, const int len)
Definition: scale_file_netcdf.c:1166
scale_file_h
module file_h
Definition: scale_file_h.F90:11
scale_file_h::file_fappend
integer, parameter, public file_fappend
Definition: scale_file_h.F90:36
scale_file::file_add_associatedvariable
subroutine, public file_add_associatedvariable(fid, vname, existed)
Definition: scale_file.F90:464
file_write_data_c
int file_write_data_c(const int fid, const int vid, const void *var, const double t_start, const double t_end, const int ndims, const int precision, const int *start, const int *count)
Definition: scale_file_netcdf.c:1882
file_open_c
int file_open_c(int *fid, const char *fname, const int mode, const int comm)
Definition: scale_file_netcdf.c:170
scale_file::file_single
logical function, public file_single(fid)
check if the file is single
Definition: scale_file.F90:595
scale_file::file_get_cftunits
subroutine, public file_get_cftunits(date, tunits)
get unit of time
Definition: scale_file.F90:6304
file_get_attribute_float_c
int file_get_attribute_float_c(float *value, const int fid, const char *vname, const char *key, const bool suppress, const int len)
Definition: scale_file_netcdf.c:954
scale_file::file_aggregate
logical, public file_aggregate
Definition: scale_file.F90:196
file_attach_buffer_c
int file_attach_buffer_c(const int fid, const int64_t buf_amount)
Definition: scale_file_netcdf.c:1840
file_write_axis_c
int file_write_axis_c(const int fid, const char *name, const void *val, const int precision, const int *start, const int *count)
Definition: scale_file_netcdf.c:1351
scale_file_h::file_fread
integer, parameter, public file_fread
Definition: scale_file_h.F90:34
scale_file_h::file_success_code
integer, parameter, public file_success_code
Definition: scale_file_h.F90:40
scale_file::file_def_variable
subroutine, public file_def_variable(fid, varname, desc, units, standard_name, ndims, dims, dtype, vid, time_int, time_stats, existed)
Definition: scale_file.F90:2381
file_get_attribute_text_c
int file_get_attribute_text_c(char *value, const int fid, const char *vname, const char *key, const bool suppress, const int len)
Definition: scale_file_netcdf.c:864
scale_file::file_redef
subroutine, public file_redef(fid)
Definition: scale_file.F90:6093
scale_file_h::file_var_max
integer, parameter, public file_var_max
Definition: scale_file_h.F90:46
scale_file::file_create
subroutine, public file_create(basename, title, source, institution, fid, existed, rankid, single, aggregate, time_units, calendar, allnodes, append)
create file fid is >= 1
Definition: scale_file.F90:295
file_def_associatedcoordinate_c
int file_def_associatedcoordinate_c(const int fid, const char *name, const char *desc, const char *units, const char **dim_names, const int ndims, const int dtype)
Definition: scale_file_netcdf.c:1450
scale_file_h::cstr
character(:, c_char) function, allocatable, target, public cstr(str)
Definition: scale_file_h.F90:94
scale_file::file_get_aggregate
logical function, public file_get_aggregate(fid)
Definition: scale_file.F90:6316
scale_file::file_finalize
subroutine, public file_finalize
finalize
Definition: scale_file.F90:277
file_add_variable_c
int file_add_variable_c(int *vid, const int fid, const char *varname, const char *desc, const char *units, const char *stdname, const char **dims, const int ndims, const int dtype, const double tint, const char *tstats)
Definition: scale_file_netcdf.c:1550
file_set_tunits_c
int file_set_tunits_c(const int fid, const char *time_units, const char *calendar)
Definition: scale_file_netcdf.c:1227
scale_prof::prof_rapend
subroutine, public prof_rapend(rapname_base, level, disable_barrier)
Save raptime.
Definition: scale_prof.F90:246
scale_file::file_detach_buffer
subroutine, public file_detach_buffer(fid)
Definition: scale_file.F90:6165
file_put_axis_c
int file_put_axis_c(const int fid, const char *name, const char *desc, const char *units, const char *dim_name, const int dtype, const void *val, const int size, const int precision)
Definition: scale_file_netcdf.c:1237
file_set_option_c
int file_set_option_c(const int fid, const char *filetype, const char *key, const char *val)
Definition: scale_file_netcdf.c:287
scale_file::file_setup
subroutine, public file_setup(myrank)
setup
Definition: scale_file.F90:236
file_get_nvars_c
int file_get_nvars_c(int *nvars, const int fid)
Definition: scale_file_netcdf.c:303
scale_file_h::file_file_max
integer, parameter, public file_file_max
Definition: scale_file_h.F90:45
file_set_attribute_int_c
int file_set_attribute_int_c(const int fid, const char *vname, const char *key, const int *value, const int len)
Definition: scale_file_netcdf.c:1081
scale_io::io_fid_conf
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:57
file_enddef_c
int file_enddef_c(const int fid)
Definition: scale_file_netcdf.c:1818
scale_file::file_set_option
subroutine, public file_set_option(fid, filetype, key, val)
Definition: scale_file.F90:501
scale_file_h::file_fwrite
integer, parameter, public file_fwrite
Definition: scale_file_h.F90:35
file_flush_c
int file_flush_c(const int fid)
Definition: scale_file_netcdf.c:1867