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  !-----------------------------------------------------------------------------
27  implicit none
28  private
29  !-----------------------------------------------------------------------------
30  !
31  !++ Public procedures
32  !
33  public :: file_setup
34  public :: file_open
35  public :: file_opened
36  public :: file_single
37  public :: file_create
38  public :: file_get_dimlength
39  public :: file_set_option
40  public :: file_def_axis
41  public :: file_put_axis
42  public :: file_write_axis
44  public :: file_put_associatedcoordinate
45  public :: file_write_associatedcoordinate
46  public :: file_add_variable
47  public :: file_def_variable
48  public :: file_get_shape
49  public :: file_get_stepsize
50  public :: file_get_commoninfo
51  public :: file_get_datainfo
52  public :: file_get_all_datainfo
53  public :: file_read
54  public :: file_write
55  public :: file_get_attribute
56  public :: file_set_attribute
58  public :: file_enddef
59  public :: file_redef
60  public :: file_flush
61  public :: file_close
62  public :: file_close_all
63  public :: file_make_fname
64  public :: file_attach_buffer
65  public :: file_detach_buffer
66  public :: file_get_cftunits
67  public :: file_get_aggregate
68 
69  interface file_get_commoninfo
70  module procedure file_get_commoninfo_fid
71  module procedure file_get_commoninfo_fname
72  end interface file_get_commoninfo
73 
74  interface file_get_shape
75  module procedure file_get_shape_fid
76  module procedure file_get_shape_fname
77  end interface file_get_shape
78 
79  interface file_get_datainfo
80  module procedure file_get_datainfo_fid
81  module procedure file_get_datainfo_fname
82  end interface file_get_datainfo
83 
84  interface file_get_all_datainfo
85  module procedure file_get_all_datainfo_fid
86  module procedure file_get_all_datainfo_fname
87  end interface file_get_all_datainfo
88 
89  interface file_put_axis
90  module procedure file_put_axis_realsp
91  module procedure file_put_axis_realdp
92  end interface file_put_axis
93  interface file_write_axis
94  module procedure file_write_axis_realsp
95  module procedure file_write_axis_realdp
96  end interface file_write_axis
97  interface file_put_associatedcoordinate
98  module procedure file_put_associatedcoordinate_realsp_1d
99  module procedure file_put_associatedcoordinate_realdp_1d
100  module procedure file_put_associatedcoordinate_realsp_2d
101  module procedure file_put_associatedcoordinate_realdp_2d
102  module procedure file_put_associatedcoordinate_realsp_3d
103  module procedure file_put_associatedcoordinate_realdp_3d
104  module procedure file_put_associatedcoordinate_realsp_4d
105  module procedure file_put_associatedcoordinate_realdp_4d
106  end interface file_put_associatedcoordinate
107  interface file_write_associatedcoordinate
108  module procedure file_write_associatedcoordinate_realsp_1d
109  module procedure file_write_associatedcoordinate_realdp_1d
110  module procedure file_write_associatedcoordinate_realsp_2d
111  module procedure file_write_associatedcoordinate_realdp_2d
112  module procedure file_write_associatedcoordinate_realsp_3d
113  module procedure file_write_associatedcoordinate_realdp_3d
114  module procedure file_write_associatedcoordinate_realsp_4d
115  module procedure file_write_associatedcoordinate_realdp_4d
116  end interface file_write_associatedcoordinate
117  interface file_add_variable
118  module procedure file_add_variable_no_time
119  module procedure file_add_variable_with_time
120  end interface file_add_variable
121  interface file_read
122  module procedure file_read_realsp_1d
123  module procedure file_read_realdp_1d
124  module procedure file_read_realsp_2d
125  module procedure file_read_realdp_2d
126  module procedure file_read_realsp_3d
127  module procedure file_read_realdp_3d
128  module procedure file_read_realsp_4d
129  module procedure file_read_realdp_4d
130  module procedure file_read_var_realsp_1d
131  module procedure file_read_var_realdp_1d
132  module procedure file_read_var_realsp_2d
133  module procedure file_read_var_realdp_2d
134  module procedure file_read_var_realsp_3d
135  module procedure file_read_var_realdp_3d
136  module procedure file_read_var_realsp_4d
137  module procedure file_read_var_realdp_4d
138  end interface file_read
139  interface file_write
140  module procedure file_write_realsp_1d
141  module procedure file_write_realdp_1d
142  module procedure file_write_realsp_2d
143  module procedure file_write_realdp_2d
144  module procedure file_write_realsp_3d
145  module procedure file_write_realdp_3d
146  module procedure file_write_realsp_4d
147  module procedure file_write_realdp_4d
148  end interface file_write
149  interface file_get_attribute
150  module procedure file_get_attribute_text_fname
151  module procedure file_get_attribute_logical_fname
152  module procedure file_get_attribute_int_fname_ary
153  module procedure file_get_attribute_int_fname
154  module procedure file_get_attribute_float_fname_ary
155  module procedure file_get_attribute_float_fname
156  module procedure file_get_attribute_double_fname_ary
157  module procedure file_get_attribute_double_fname
158  module procedure file_get_attribute_text_fid
159  module procedure file_get_attribute_logical_fid
160  module procedure file_get_attribute_int_fid_ary
161  module procedure file_get_attribute_int_fid
162  module procedure file_get_attribute_float_fid_ary
163  module procedure file_get_attribute_float_fid
164  module procedure file_get_attribute_double_fid_ary
165  module procedure file_get_attribute_double_fid
166  end interface file_get_attribute
167  interface file_set_attribute
168  module procedure file_set_attribute_text
169  module procedure file_set_attribute_logical
170  module procedure file_set_attribute_int_ary
171  module procedure file_set_attribute_int
172  module procedure file_set_attribute_float_ary
173  module procedure file_set_attribute_float
174  module procedure file_set_attribute_double_ary
175  module procedure file_set_attribute_double
176  end interface file_set_attribute
177 
178  !-----------------------------------------------------------------------------
179  !
180  !++ Public parameters & variables
181  !
182  logical, public :: file_aggregate = .false.
183 
184  !-----------------------------------------------------------------------------
185  !
186  !++ Private procedures
187  !
188  private :: file_get_fid
189 
190  !-----------------------------------------------------------------------------
191  !
192  !++ Private parameters & variables
193  !
194  type file
195  character(len=FILE_HLONG) :: name
196  integer :: fid
197  logical :: aggregate
198  logical :: single
199  integer :: buffer_size
200  end type file
201  type(file) :: file_files(file_file_max)
202  integer :: file_nfiles = 0
203 
204  type var
205  character(len=FILE_HLONG) :: name
206  integer :: fid
207  integer :: vid
208  end type var
209  type(var) :: file_vars(file_var_max)
210  integer :: file_nvars = 0
211 
212  integer :: mpi_myrank
213 
214  !-----------------------------------------------------------------------------
215 contains
216  !-----------------------------------------------------------------------------
218  !-----------------------------------------------------------------------------
219  subroutine file_setup( &
220  myrank )
221  use scale_prc, only: &
223  implicit none
224 
225  integer, intent(in) :: myrank
226 
227  namelist / param_file / &
229 
230  integer :: fid
231  integer :: ierr
232 
233  !--- read namelist
234  rewind(io_fid_conf)
235  read(io_fid_conf,nml=param_file,iostat=ierr)
236  if( ierr < 0 ) then !--- missing
237  log_info("FILE_setup",*) 'Not found namelist. Default used.'
238  elseif( ierr > 0 ) then !--- fatal error
239  log_error("FILE_setup",*) 'Not appropriate names in namelist PARAM_FILE. Check!'
240  call prc_abort
241  endif
242  log_nml(param_file)
243 
244  mpi_myrank = myrank
245 
247 
248  do fid = 1, file_file_max
249  file_files(fid)%fid = -1
250  file_files(fid)%name = ""
251  end do
252 
253  return
254  end subroutine file_setup
255 
256  !-----------------------------------------------------------------------------
260  subroutine file_create( &
261  basename, &
262  title, source, institution, &
263  fid, existed, &
264  rankid, single, aggregate, &
265  time_units, calendar, &
266  append )
267  implicit none
268 
269  character(len=*), intent(in) :: basename
270  character(len=*), intent(in) :: title
271  character(len=*), intent(in) :: source
272  character(len=*), intent(in) :: institution
273 
274  integer, intent(out) :: fid
275  logical, intent(out) :: existed
276 
277  integer, intent(in), optional :: rankid
278  logical, intent(in), optional :: single
279  logical, intent(in), optional :: aggregate
280  character(len=*), intent(in), optional :: time_units
281  character(len=*), intent(in), optional :: calendar
282  logical, intent(in), optional :: append
283 
284  character(len=FILE_HMID) :: time_units_
285  character(len=FILE_HSHORT) :: calendar_
286  integer :: rankid_
287  logical :: single_
288  integer :: mode
289 
290  integer :: error
291  !---------------------------------------------------------------------------
292 
293 
294  if ( present(rankid) ) then
295  rankid_ = rankid
296  else
297  rankid_ = mpi_myrank
298  end if
299 
300  single_ = .false.
301  if ( present(single) ) then
302  single_ = single
303  endif
304 
305  if ( present(time_units) ) then
306  time_units_ = time_units
307  else
308  time_units_ = 'seconds'
309  endif
310 
311  if ( present(calendar) ) then
312  calendar_ = calendar
313  else
314  calendar_ = ""
315  end if
316 
317  mode = file_fwrite
318  if ( present(append) ) then
319  if( append ) mode = file_fappend
320  endif
321 
322  if ( single_ .and. rankid_ /= 0 ) then
323  fid = -1
324  existed = .false.
325  return
326  end if
327 
328  call file_get_fid( basename, mode, & ! [IN]
329  rankid_, single_, & ! [IN]
330  fid, existed, & ! [OUT]
331  aggregate=aggregate ) ! [IN]
332 
333  if( existed ) return
334 
335  !--- append package header to the file
336  call file_set_attribute( fid, "global", "title" , title ) ! [IN]
337  call file_set_attribute( fid, "global", "source" , source ) ! [IN]
338  call file_set_attribute( fid, "global", "institution", institution ) ! [IN]
339 
340  if ( ( .not. present(aggregate) ) .or. .not. aggregate ) then
341  ! for shared-file parallel I/O, skip attributes related to MPI processes
342  call file_set_attribute( fid, "global", "rankid" , (/rankid/) ) ! [IN]
343  endif
344 
345  call file_set_tunits_c( file_files(fid)%fid, & ! [IN]
346  time_units_, calendar_, & ! [IN]
347  error ) ! [OUT]
348 
349  if ( error /= file_success_code ) then
350  log_error("FILE_create",*) 'failed to set time units'
351  call prc_abort
352  endif
353 
354  return
355  end subroutine file_create
356 
357  !-----------------------------------------------------------------------------
358  subroutine file_get_var_num( &
359  fid, nvars_limit, &
360  nvars )
361  implicit none
362 
363  integer, intent(in) :: fid
364  integer, intent(in) :: nvars_limit
365  integer, intent(out) :: nvars
366 
367  integer :: error
368  !---------------------------------------------------------------------------
369 
370  if ( .not. file_opened(fid) ) then
371  log_error("FILE_get_var_num",*) 'File is not opened. fid = ', fid
372  call prc_abort
373  end if
374 
375  call file_get_nvars_c( file_files(fid)%fid, & ! (in)
376  nvars, error ) ! (out)
377 
378  if ( error /= file_success_code ) then
379  log_error("FILE_get_var_num",*) 'failed to get varnum. fid = ', fid
380  call prc_abort
381  end if
382 
383  if ( nvars > nvars_limit ) then
384  log_error("FILE_get_var_num",*) 'number of variables exceeds the requested size.', nvars, nvars_limit
385  call prc_abort
386  endif
387 
388  return
389  end subroutine file_get_var_num
390 
391  !-----------------------------------------------------------------------------
392  subroutine file_get_var_name( &
393  fid, cvid, &
394  varname )
395  implicit none
396 
397  integer, intent(in) :: fid
398  integer, intent(in) :: cvid
399  character(len=*), intent(out) :: varname
400 
401  integer :: error
402  !---------------------------------------------------------------------------
403 
404  if ( .not. file_opened(fid) ) then
405  log_error("FILE_get_var_name",*) 'File is not opened. fid = ', fid
406  call prc_abort
407  end if
408 
409  call file_get_varname_c( file_files(fid)%fid, cvid, & ! (in)
410  varname, error ) ! (out)
411 
412  if ( error /= file_success_code ) then
413  log_error("FILE_get_var_name",*) 'failed to get varname. cvid = ', cvid
414  call prc_abort
415  end if
416 
417  return
418  end subroutine file_get_var_name
419 
420  !-----------------------------------------------------------------------------
421  subroutine file_add_associatedvariable( fid, vname, existed )
422  integer, intent(in) :: fid
423  character(len=*), intent(in) :: vname
424  logical, optional, intent(out) :: existed
425 
426  integer :: error
427 
428  if ( .not. file_opened(fid) ) then
429  log_error("FILE_add_associatedVariable",*) 'File is not opened. fid = ', fid
430  call prc_abort
431  end if
432 
433  call file_add_associatedvariable_c( file_files(fid)%fid, vname , & ! (in)
434  error ) ! (out)
435 
436  if ( present(existed) ) then
437  if ( error == file_already_existed_code ) then
438  existed = .true.
439  return
440  end if
441  existed = .false.
442  end if
443 
444  if ( error /= file_success_code ) then
445  log_error("FILE_add_associatedvariable",*) 'failed to add associated variable: '//trim(vname)
446  call prc_abort
447  end if
448 
449  return
450  end subroutine file_add_associatedvariable
451 
452  !-----------------------------------------------------------------------------
453  subroutine file_set_option( &
454  fid, &
455  filetype, key, val )
456  integer, intent(in) :: fid
457  character(len=*), intent(in) :: filetype
458  character(len=*), intent(in) :: key
459  character(len=*), intent(in) :: val
460 
461  integer :: error
462 
463  if ( .not. file_opened(fid) ) then
464  log_error("FILE_set_option",*) 'File is not opened. fid = ', fid
465  call prc_abort
466  end if
467 
468  call file_set_option_c( file_files(fid)%fid, filetype, key, val, & ! (in)
469  error ) ! (out)
470  if ( error /= file_success_code ) then
471  log_error("FILE_set_option",*) 'failed to set option'
472  call prc_abort
473  end if
474 
475  return
476  end subroutine file_set_option
477 
478  !-----------------------------------------------------------------------------
479  subroutine file_open( &
480  basename, &
481  fid, &
482  mode, &
483  single, &
484  aggregate, &
485  rankid, &
486  postfix )
487  implicit none
488 
489  character(len=*), intent( in) :: basename
490  integer, intent(out) :: fid
491  integer, intent( in), optional :: mode
492  logical, intent( in), optional :: single
493  logical, intent( in), optional :: aggregate
494  integer, intent( in), optional :: rankid
495  character(len=*), intent( in), optional :: postfix
496 
497  integer :: mode_
498  integer :: rankid_
499  logical :: existed
500  logical :: single_
501 
502  single_ = .false.
503 
504  if ( present(mode) ) then
505  mode_ = mode
506  else
507  mode_ = file_fread
508  end if
509 
510  if ( present(single) ) single_ = single
511  if ( present(rankid) ) then
512  rankid_ = rankid
513  else
514  rankid_ = mpi_myrank
515  end if
516 
517  call file_get_fid( basename, mode_, rankid_, single_, & ! (in)
518  fid, existed, & ! (out)
519  aggregate=aggregate, postfix=postfix ) ! (in)
520 
521  return
522  end subroutine file_open
523 
524  !-----------------------------------------------------------------------------
526  function file_opened( fid )
527  implicit none
528 
529  integer, intent( in) :: fid
530  logical :: file_opened
531 
532  if ( fid < 1 ) then
533  file_opened = .false.
534  else
535  file_opened = file_files(fid)%fid >= 0
536  end if
537 
538  return
539  end function file_opened
540 
541  !-----------------------------------------------------------------------------
543  function file_single( fid )
544  implicit none
545 
546  integer, intent( in) :: fid
547  logical :: file_single
548 
549  if ( fid < 1 ) then
550  file_single = .false.
551  else
552  file_single = file_files(fid)%single
553  end if
554 
555  return
556  end function file_single
557 
558  !-----------------------------------------------------------------------------
560  !-----------------------------------------------------------------------------
561  subroutine file_get_dimlength( &
562  fid, dimname, &
563  len, &
564  error )
565  integer, intent(in) :: fid
566  character(len=*), intent(in) :: dimname
567 
568  integer, intent(out) :: len
569 
570  logical, intent(out), optional :: error
571 
572  integer :: ierror
573 
574 
575  if ( .not. file_opened(fid) ) then
576  log_error("FILE_get_dimLength",*) 'File is not opened. fid = ', fid
577  call prc_abort
578  end if
579 
580  call file_get_dim_length_c( file_files(fid)%fid, dimname, & ! (in)
581  len, ierror ) ! (out)
582  if ( ierror /= file_success_code .and. ierror /= file_already_existed_code ) then
583  if ( present(error) ) then
584  error = .true.
585  else
586  log_error("FILE_get_dimLength",*) 'failed to get dimension length'
587  call prc_abort
588  end if
589  else
590  if ( present(error) ) error = .false.
591  end if
592 
593  return
594  end subroutine file_get_dimlength
595 
596  !-----------------------------------------------------------------------------
597  ! interface FILE_PutAxis
598  !-----------------------------------------------------------------------------
599  subroutine file_put_axis_realsp( &
600  fid, &
601  name, desc, units, &
602  dim_name, dtype, &
603  val )
604  integer, intent(in) :: fid
605  character(len=*), intent(in) :: name
606  character(len=*), intent(in) :: desc
607  character(len=*), intent(in) :: units
608  character(len=*), intent(in) :: dim_name
609  integer, intent(in) :: dtype
610  real(sp), intent(in) :: val(:)
611 
612  integer :: error
613  intrinsic size
614 
615  if ( .not. file_opened(fid) ) then
616  log_error("FILE_put_axis_real",*) 'File is not opened. fid = ', fid
617  call prc_abort
618  end if
619 
620  call file_put_axis_c( file_files(fid)%fid, & ! (in)
621  name, desc, units, dim_name, dtype, val, size(val), sp, & ! (in)
622  error ) ! (out)
623  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
624  log_error("FILE_put_axis_realSP",*) 'failed to put axis'
625  call prc_abort
626  end if
627 
628  return
629  end subroutine file_put_axis_realsp
630  subroutine file_put_axis_realdp( &
631  fid, &
632  name, desc, units, &
633  dim_name, dtype, &
634  val )
635  integer, intent(in) :: fid
636  character(len=*), intent(in) :: name
637  character(len=*), intent(in) :: desc
638  character(len=*), intent(in) :: units
639  character(len=*), intent(in) :: dim_name
640  integer, intent(in) :: dtype
641  real(dp), intent(in) :: val(:)
642 
643  integer :: error
644  intrinsic size
645 
646  if ( .not. file_opened(fid) ) then
647  log_error("FILE_put_axis_real",*) 'File is not opened. fid = ', fid
648  call prc_abort
649  end if
650 
651  call file_put_axis_c( file_files(fid)%fid, & ! (in)
652  name, desc, units, dim_name, dtype, val, size(val), dp, & ! (in)
653  error ) ! (out)
654  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
655  log_error("FILE_put_axis_realDP",*) 'failed to put axis'
656  call prc_abort
657  end if
658 
659  return
660  end subroutine file_put_axis_realdp
661 
662  subroutine file_def_axis( &
663  fid, &
664  name, desc, units, &
665  dim_name, dtype, dim_size, &
666  bounds )
667  integer, intent(in) :: fid
668  character(len=*), intent(in) :: name
669  character(len=*), intent(in) :: desc
670  character(len=*), intent(in) :: units
671  character(len=*), intent(in) :: dim_name
672  integer, intent(in) :: dtype
673  integer, intent(in) :: dim_size
674 
675  logical, intent(in), optional :: bounds
676 
677  integer :: error
678  integer :: bounds_
679 
680  bounds_ = 0 ! .false.
681  if ( present(bounds) ) then
682  if ( bounds ) bounds_ = 1 ! .true.
683  end if
684 
685  if ( .not. file_opened(fid) ) then
686  log_error("FILE_def_axis",*) 'File is not opened. fid = ', fid
687  call prc_abort
688  end if
689 
690  call file_def_axis_c( file_files(fid)%fid, &
691  name, desc, units, dim_name, dtype, dim_size, bounds_, & ! (in)
692  error ) ! (out)
693  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
694  log_error("FILE_def_axis",*) 'failed to define axis'
695  call prc_abort
696  end if
697 
698  return
699  end subroutine file_def_axis
700 
701  !-----------------------------------------------------------------------------
702  ! interface FILE_WriteAxis
703  !-----------------------------------------------------------------------------
704  subroutine file_write_axis_realsp( &
705  fid, &
706  name, &
707  val, &
708  start )
709  integer, intent(in) :: fid
710  character(len=*), intent(in) :: name
711  real(sp), intent(in) :: val(:)
712  integer, intent(in), optional :: start(:)
713 
714  integer :: error
715  intrinsic shape
716 
717  if ( .not. file_opened(fid) ) then
718  log_error("FILE_write_axis_realSP",*) 'File is not opened. fid = ', fid
719  call prc_abort
720  end if
721 
722  if ( present(start) ) then
723  call file_write_axis_c( file_files(fid)%fid, & ! (in)
724  name, val, sp, start, shape(val), & ! (in)
725  error ) ! (out)
726  else
727  call file_write_axis_c( file_files(fid)%fid, & ! (in)
728  name, val, sp, (/1/), shape(val), & ! (in)
729  error ) ! (out)
730  end if
731  if ( error /= file_success_code ) then
732  log_error("FILE_write_axis_realSP",*) 'failed to write axis: '//trim(name)
733  call prc_abort
734  end if
735 
736  return
737  end subroutine file_write_axis_realsp
738  subroutine file_write_axis_realdp( &
739  fid, &
740  name, &
741  val, &
742  start )
743  integer, intent(in) :: fid
744  character(len=*), intent(in) :: name
745  real(dp), intent(in) :: val(:)
746  integer, intent(in), optional :: start(:)
747 
748  integer :: error
749  intrinsic shape
750 
751  if ( .not. file_opened(fid) ) then
752  log_error("FILE_write_axis_realDP",*) 'File is not opened. fid = ', fid
753  call prc_abort
754  end if
755 
756  if ( present(start) ) then
757  call file_write_axis_c( file_files(fid)%fid, & ! (in)
758  name, val, dp, start, shape(val), & ! (in)
759  error ) ! (out)
760  else
761  call file_write_axis_c( file_files(fid)%fid, & ! (in)
762  name, val, dp, (/1/), shape(val), & ! (in)
763  error ) ! (out)
764  end if
765  if ( error /= file_success_code ) then
766  log_error("FILE_write_axis_realDP",*) 'failed to write axis: '//trim(name)
767  call prc_abort
768  end if
769 
770  return
771  end subroutine file_write_axis_realdp
772 
773  !-----------------------------------------------------------------------------
774  ! interface FILE_put_associatedCoordinate
775  !-----------------------------------------------------------------------------
776  subroutine file_put_associatedcoordinate_realsp_1d( &
777  fid, &
778  name, desc, units, &
779  dim_names, dtype, &
780  val )
781  integer, intent(in) :: fid
782  character(len=*), intent(in) :: name
783  character(len=*), intent(in) :: desc
784  character(len=*), intent(in) :: units
785  character(len=*), intent(in) :: dim_names(:)
786  integer, intent(in) :: dtype
787  real(sp), intent(in) :: val(:)
788 
789  integer :: error
790  intrinsic size
791 
792  if ( .not. file_opened(fid) ) then
793  log_error("FILE_put_associatedCoordinate_realSP_1D",*) 'File is not opened. fid = ', fid
794  call prc_abort
795  end if
796 
797  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
798  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
799  val, sp, & ! (in)
800  error ) ! (out)
801  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
802  log_error("FILE_put_associatedCoordinate_realSP_1D",*) 'failed to put associated coordinate: '//trim(name)
803  call prc_abort
804  end if
805 
806  return
807  end subroutine file_put_associatedcoordinate_realsp_1d
808  subroutine file_put_associatedcoordinate_realdp_1d( &
809  fid, &
810  name, desc, units, &
811  dim_names, dtype, &
812  val )
813  integer, intent(in) :: fid
814  character(len=*), intent(in) :: name
815  character(len=*), intent(in) :: desc
816  character(len=*), intent(in) :: units
817  character(len=*), intent(in) :: dim_names(:)
818  integer, intent(in) :: dtype
819  real(dp), intent(in) :: val(:)
820 
821  integer :: error
822  intrinsic size
823 
824  if ( .not. file_opened(fid) ) then
825  log_error("FILE_put_associatedCoordinate_realDP_1D",*) 'File is not opened. fid = ', fid
826  call prc_abort
827  end if
828 
829  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
830  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
831  val, dp, & ! (in)
832  error ) ! (out)
833  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
834  log_error("FILE_put_associatedCoordinate_realDP_1D",*) 'failed to put associated coordinate: '//trim(name)
835  call prc_abort
836  end if
837 
838  return
839  end subroutine file_put_associatedcoordinate_realdp_1d
840  subroutine file_put_associatedcoordinate_realsp_2d( &
841  fid, &
842  name, desc, units, &
843  dim_names, dtype, &
844  val )
845  integer, intent(in) :: fid
846  character(len=*), intent(in) :: name
847  character(len=*), intent(in) :: desc
848  character(len=*), intent(in) :: units
849  character(len=*), intent(in) :: dim_names(:)
850  integer, intent(in) :: dtype
851  real(sp), intent(in) :: val(:,:)
852 
853  integer :: error
854  intrinsic size
855 
856  if ( .not. file_opened(fid) ) then
857  log_error("FILE_put_associatedCoordinate_realSP_2D",*) 'File is not opened. fid = ', fid
858  call prc_abort
859  end if
860 
861  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
862  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
863  val, sp, & ! (in)
864  error ) ! (out)
865  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
866  log_error("FILE_put_associatedCoordinate_realSP_2D",*) 'failed to put associated coordinate: '//trim(name)
867  call prc_abort
868  end if
869 
870  return
871  end subroutine file_put_associatedcoordinate_realsp_2d
872  subroutine file_put_associatedcoordinate_realdp_2d( &
873  fid, &
874  name, desc, units, &
875  dim_names, dtype, &
876  val )
877  integer, intent(in) :: fid
878  character(len=*), intent(in) :: name
879  character(len=*), intent(in) :: desc
880  character(len=*), intent(in) :: units
881  character(len=*), intent(in) :: dim_names(:)
882  integer, intent(in) :: dtype
883  real(dp), intent(in) :: val(:,:)
884 
885  integer :: error
886  intrinsic size
887 
888  if ( .not. file_opened(fid) ) then
889  log_error("FILE_put_associatedCoordinate_realDP_2D",*) 'File is not opened. fid = ', fid
890  call prc_abort
891  end if
892 
893  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
894  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
895  val, dp, & ! (in)
896  error ) ! (out)
897  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
898  log_error("FILE_put_associatedCoordinate_realDP_2D",*) 'failed to put associated coordinate: '//trim(name)
899  call prc_abort
900  end if
901 
902  return
903  end subroutine file_put_associatedcoordinate_realdp_2d
904  subroutine file_put_associatedcoordinate_realsp_3d( &
905  fid, &
906  name, desc, units, &
907  dim_names, dtype, &
908  val )
909  integer, intent(in) :: fid
910  character(len=*), intent(in) :: name
911  character(len=*), intent(in) :: desc
912  character(len=*), intent(in) :: units
913  character(len=*), intent(in) :: dim_names(:)
914  integer, intent(in) :: dtype
915  real(sp), intent(in) :: val(:,:,:)
916 
917  integer :: error
918  intrinsic size
919 
920  if ( .not. file_opened(fid) ) then
921  log_error("FILE_put_associatedCoordinate_realSP_3D",*) 'File is not opened. fid = ', fid
922  call prc_abort
923  end if
924 
925  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
926  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
927  val, sp, & ! (in)
928  error ) ! (out)
929  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
930  log_error("FILE_put_associatedCoordinate_realSP_3D",*) 'failed to put associated coordinate: '//trim(name)
931  call prc_abort
932  end if
933 
934  return
935  end subroutine file_put_associatedcoordinate_realsp_3d
936  subroutine file_put_associatedcoordinate_realdp_3d( &
937  fid, &
938  name, desc, units, &
939  dim_names, dtype, &
940  val )
941  integer, intent(in) :: fid
942  character(len=*), intent(in) :: name
943  character(len=*), intent(in) :: desc
944  character(len=*), intent(in) :: units
945  character(len=*), intent(in) :: dim_names(:)
946  integer, intent(in) :: dtype
947  real(dp), intent(in) :: val(:,:,:)
948 
949  integer :: error
950  intrinsic size
951 
952  if ( .not. file_opened(fid) ) then
953  log_error("FILE_put_associatedCoordinate_realDP_3D",*) 'File is not opened. fid = ', fid
954  call prc_abort
955  end if
956 
957  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
958  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
959  val, dp, & ! (in)
960  error ) ! (out)
961  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
962  log_error("FILE_put_associatedCoordinate_realDP_3D",*) 'failed to put associated coordinate: '//trim(name)
963  call prc_abort
964  end if
965 
966  return
967  end subroutine file_put_associatedcoordinate_realdp_3d
968  subroutine file_put_associatedcoordinate_realsp_4d( &
969  fid, &
970  name, desc, units, &
971  dim_names, dtype, &
972  val )
973  integer, intent(in) :: fid
974  character(len=*), intent(in) :: name
975  character(len=*), intent(in) :: desc
976  character(len=*), intent(in) :: units
977  character(len=*), intent(in) :: dim_names(:)
978  integer, intent(in) :: dtype
979  real(sp), intent(in) :: val(:,:,:,:)
980 
981  integer :: error
982  intrinsic size
983 
984  if ( .not. file_opened(fid) ) then
985  log_error("FILE_put_associatedCoordinate_realSP_4D",*) 'File is not opened. fid = ', fid
986  call prc_abort
987  end if
988 
989  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
990  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
991  val, sp, & ! (in)
992  error ) ! (out)
993  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
994  log_error("FILE_put_associatedCoordinate_realSP_4D",*) 'failed to put associated coordinate: '//trim(name)
995  call prc_abort
996  end if
997 
998  return
999  end subroutine file_put_associatedcoordinate_realsp_4d
1000  subroutine file_put_associatedcoordinate_realdp_4d( &
1001  fid, &
1002  name, desc, units, &
1003  dim_names, dtype, &
1004  val )
1005  integer, intent(in) :: fid
1006  character(len=*), intent(in) :: name
1007  character(len=*), intent(in) :: desc
1008  character(len=*), intent(in) :: units
1009  character(len=*), intent(in) :: dim_names(:)
1010  integer, intent(in) :: dtype
1011  real(dp), intent(in) :: val(:,:,:,:)
1012 
1013  integer :: error
1014  intrinsic size
1015 
1016  if ( .not. file_opened(fid) ) then
1017  log_error("FILE_put_associatedCoordinate_realDP_4D",*) 'File is not opened. fid = ', fid
1018  call prc_abort
1019  end if
1020 
1021  call file_put_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1022  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
1023  val, dp, & ! (in)
1024  error ) ! (out)
1025  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1026  log_error("FILE_put_associatedCoordinate_realDP_4D",*) 'failed to put associated coordinate: '//trim(name)
1027  call prc_abort
1028  end if
1029 
1030  return
1031  end subroutine file_put_associatedcoordinate_realdp_4d
1032 
1033  subroutine file_def_associatedcoordinate( &
1034  fid, &
1035  name, desc, units, &
1036  dim_names, dtype )
1037  integer, intent(in) :: fid
1038  character(len=*), intent(in) :: name
1039  character(len=*), intent(in) :: desc
1040  character(len=*), intent(in) :: units
1041  character(len=*), intent(in) :: dim_names(:)
1042  integer, intent(in) :: dtype
1043 
1044  integer :: error
1045  intrinsic size
1046 
1047  if ( .not. file_opened(fid) ) then
1048  log_error("FILE_def_associatedCoordinate",*) 'File is not opened. fid = ', fid
1049  call prc_abort
1050  end if
1051 
1052  call file_def_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1053  name, desc, units, dim_names, size(dim_names), dtype, & ! (in)
1054  error ) ! (out)
1055  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1056  log_error("FILE_def_associatedCoordinate",*) 'failed to put associated coordinate: '//trim(name)
1057  call prc_abort
1058  end if
1059 
1060  return
1061  end subroutine file_def_associatedcoordinate
1062 
1063  !-----------------------------------------------------------------------------
1064  ! interface FILE_write_associatedCoordinate
1065  !-----------------------------------------------------------------------------
1066  subroutine file_write_associatedcoordinate_realsp_1d( &
1067  fid, &
1068  name, &
1069  val, &
1070  start, count, &
1071  ndims )
1072  integer, intent(in) :: fid
1073  character(len=*), intent(in) :: name
1074  real(sp), intent(in) :: val(:)
1075  integer, intent(in), optional :: start(:)
1076  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1077  integer, intent(in), optional :: ndims ! in case val has been reshaped
1078 
1079  integer :: error
1080  intrinsic shape
1081 
1082  if ( .not. file_opened(fid) ) then
1083  log_error("FILE_write_associatedCoordinate_realSP_1D",*) 'File is not opened. fid = ', fid
1084  call prc_abort
1085  end if
1086 
1087  if ( present(ndims) ) then
1088  ! Note this is called for history coordinates which have been reshaped
1089  ! from 2D/3D into 1D array. In this case, start and count must be also present
1090  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1091  name, val, sp, & ! (in)
1092  ndims, start, count, & ! (in)
1093  error ) ! (out)
1094  else if ( present(start) ) then
1095  ! Note this is called for restart coordinates
1096  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1097  name, val, sp, & ! (in)
1098  1, start, shape(val), & ! (in)
1099  error ) ! (out)
1100  else
1101  ! Note this is for the one-file-per-process I/O method
1102  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1103  name, val, sp, & ! (in)
1104  1, (/1/), shape(val), & ! (in)
1105  error ) ! (out)
1106  end if
1107  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1108  log_error("FILE_write_associatedCoordinate_realSP_1D",*) 'failed to put associated coordinate: '//trim(name)
1109  call prc_abort
1110  end if
1111 
1112  return
1113  end subroutine file_write_associatedcoordinate_realsp_1d
1114  subroutine file_write_associatedcoordinate_realdp_1d( &
1115  fid, &
1116  name, &
1117  val, &
1118  start, count, &
1119  ndims )
1120  integer, intent(in) :: fid
1121  character(len=*), intent(in) :: name
1122  real(dp), intent(in) :: val(:)
1123  integer, intent(in), optional :: start(:)
1124  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1125  integer, intent(in), optional :: ndims ! in case val has been reshaped
1126 
1127  integer :: error
1128  intrinsic shape
1129 
1130  if ( .not. file_opened(fid) ) then
1131  log_error("FILE_write_associatedCoordinate_realDP_1D",*) 'File is not opened. fid = ', fid
1132  call prc_abort
1133  end if
1134 
1135  if ( present(ndims) ) then
1136  ! Note this is called for history coordinates which have been reshaped
1137  ! from 2D/3D into 1D array. In this case, start and count must be also present
1138  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1139  name, val, dp, & ! (in)
1140  ndims, start, count, & ! (in)
1141  error ) ! (out)
1142  else if ( present(start) ) then
1143  ! Note this is called for restart coordinates
1144  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1145  name, val, dp, & ! (in)
1146  1, start, shape(val), & ! (in)
1147  error ) ! (out)
1148  else
1149  ! Note this is for the one-file-per-process I/O method
1150  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1151  name, val, dp, & ! (in)
1152  1, (/1/), shape(val), & ! (in)
1153  error ) ! (out)
1154  end if
1155  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1156  log_error("FILE_write_associatedCoordinate_realDP_1D",*) 'failed to put associated coordinate: '//trim(name)
1157  call prc_abort
1158  end if
1159 
1160  return
1161  end subroutine file_write_associatedcoordinate_realdp_1d
1162  subroutine file_write_associatedcoordinate_realsp_2d( &
1163  fid, &
1164  name, &
1165  val, &
1166  start, count, &
1167  ndims )
1168  integer, intent(in) :: fid
1169  character(len=*), intent(in) :: name
1170  real(sp), intent(in) :: val(:,:)
1171  integer, intent(in), optional :: start(:)
1172  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1173  integer, intent(in), optional :: ndims ! in case val has been reshaped
1174 
1175  integer :: error
1176  intrinsic shape
1177 
1178  if ( .not. file_opened(fid) ) then
1179  log_error("FILE_write_associatedCoordinate_realSP_2D",*) 'File is not opened. fid = ', fid
1180  call prc_abort
1181  end if
1182 
1183  if ( present(ndims) ) then
1184  ! Note this is called for history coordinates which have been reshaped
1185  ! from 2D/3D into 1D array. In this case, start and count must be also present
1186  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1187  name, val, sp, & ! (in)
1188  ndims, start, count, & ! (in)
1189  error ) ! (out)
1190  else if ( present(start) ) then
1191  ! Note this is called for restart coordinates
1192  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1193  name, val, sp, & ! (in)
1194  2, start, shape(val), & ! (in)
1195  error ) ! (out)
1196  else
1197  ! Note this is for the one-file-per-process I/O method
1198  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1199  name, val, sp, & ! (in)
1200  2, (/1,1/), shape(val), & ! (in)
1201  error ) ! (out)
1202  end if
1203  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1204  log_error("FILE_write_associatedCoordinate_realSP_2D",*) 'failed to put associated coordinate: '//trim(name)
1205  call prc_abort
1206  end if
1207 
1208  return
1209  end subroutine file_write_associatedcoordinate_realsp_2d
1210  subroutine file_write_associatedcoordinate_realdp_2d( &
1211  fid, &
1212  name, &
1213  val, &
1214  start, count, &
1215  ndims )
1216  integer, intent(in) :: fid
1217  character(len=*), intent(in) :: name
1218  real(dp), intent(in) :: val(:,:)
1219  integer, intent(in), optional :: start(:)
1220  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1221  integer, intent(in), optional :: ndims ! in case val has been reshaped
1222 
1223  integer :: error
1224  intrinsic shape
1225 
1226  if ( .not. file_opened(fid) ) then
1227  log_error("FILE_write_associatedCoordinate_realDP_2D",*) 'File is not opened. fid = ', fid
1228  call prc_abort
1229  end if
1230 
1231  if ( present(ndims) ) then
1232  ! Note this is called for history coordinates which have been reshaped
1233  ! from 2D/3D into 1D array. In this case, start and count must be also present
1234  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1235  name, val, dp, & ! (in)
1236  ndims, start, count, & ! (in)
1237  error ) ! (out)
1238  else if ( present(start) ) then
1239  ! Note this is called for restart coordinates
1240  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1241  name, val, dp, & ! (in)
1242  2, start, shape(val), & ! (in)
1243  error ) ! (out)
1244  else
1245  ! Note this is for the one-file-per-process I/O method
1246  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1247  name, val, dp, & ! (in)
1248  2, (/1,1/), shape(val), & ! (in)
1249  error ) ! (out)
1250  end if
1251  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1252  log_error("FILE_write_associatedCoordinate_realDP_2D",*) 'failed to put associated coordinate: '//trim(name)
1253  call prc_abort
1254  end if
1255 
1256  return
1257  end subroutine file_write_associatedcoordinate_realdp_2d
1258  subroutine file_write_associatedcoordinate_realsp_3d( &
1259  fid, &
1260  name, &
1261  val, &
1262  start, count, &
1263  ndims )
1264  integer, intent(in) :: fid
1265  character(len=*), intent(in) :: name
1266  real(sp), intent(in) :: val(:,:,:)
1267  integer, intent(in), optional :: start(:)
1268  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1269  integer, intent(in), optional :: ndims ! in case val has been reshaped
1270 
1271  integer :: error
1272  intrinsic shape
1273 
1274  if ( .not. file_opened(fid) ) then
1275  log_error("FILE_write_associatedCoordinate_realSP_3D",*) 'File is not opened. fid = ', fid
1276  call prc_abort
1277  end if
1278 
1279  if ( present(ndims) ) then
1280  ! Note this is called for history coordinates which have been reshaped
1281  ! from 2D/3D into 1D array. In this case, start and count must be also present
1282  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1283  name, val, sp, & ! (in)
1284  ndims, start, count, & ! (in)
1285  error ) ! (out)
1286  else if ( present(start) ) then
1287  ! Note this is called for restart coordinates
1288  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1289  name, val, sp, & ! (in)
1290  3, start, shape(val), & ! (in)
1291  error ) ! (out)
1292  else
1293  ! Note this is for the one-file-per-process I/O method
1294  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1295  name, val, sp, & ! (in)
1296  3, (/1,1,1/), shape(val), & ! (in)
1297  error ) ! (out)
1298  end if
1299  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1300  log_error("FILE_write_associatedCoordinate_realSP_3D",*) 'failed to put associated coordinate: '//trim(name)
1301  call prc_abort
1302  end if
1303 
1304  return
1305  end subroutine file_write_associatedcoordinate_realsp_3d
1306  subroutine file_write_associatedcoordinate_realdp_3d( &
1307  fid, &
1308  name, &
1309  val, &
1310  start, count, &
1311  ndims )
1312  integer, intent(in) :: fid
1313  character(len=*), intent(in) :: name
1314  real(dp), intent(in) :: val(:,:,:)
1315  integer, intent(in), optional :: start(:)
1316  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1317  integer, intent(in), optional :: ndims ! in case val has been reshaped
1318 
1319  integer :: error
1320  intrinsic shape
1321 
1322  if ( .not. file_opened(fid) ) then
1323  log_error("FILE_write_associatedCoordinate_realDP_3D",*) 'File is not opened. fid = ', fid
1324  call prc_abort
1325  end if
1326 
1327  if ( present(ndims) ) then
1328  ! Note this is called for history coordinates which have been reshaped
1329  ! from 2D/3D into 1D array. In this case, start and count must be also present
1330  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1331  name, val, dp, & ! (in)
1332  ndims, start, count, & ! (in)
1333  error ) ! (out)
1334  else if ( present(start) ) then
1335  ! Note this is called for restart coordinates
1336  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1337  name, val, dp, & ! (in)
1338  3, start, shape(val), & ! (in)
1339  error ) ! (out)
1340  else
1341  ! Note this is for the one-file-per-process I/O method
1342  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1343  name, val, dp, & ! (in)
1344  3, (/1,1,1/), shape(val), & ! (in)
1345  error ) ! (out)
1346  end if
1347  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1348  log_error("FILE_write_associatedCoordinate_realDP_3D",*) 'failed to put associated coordinate: '//trim(name)
1349  call prc_abort
1350  end if
1351 
1352  return
1353  end subroutine file_write_associatedcoordinate_realdp_3d
1354  subroutine file_write_associatedcoordinate_realsp_4d( &
1355  fid, &
1356  name, &
1357  val, &
1358  start, count, &
1359  ndims )
1360  integer, intent(in) :: fid
1361  character(len=*), intent(in) :: name
1362  real(sp), intent(in) :: val(:,:,:,:)
1363  integer, intent(in), optional :: start(:)
1364  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1365  integer, intent(in), optional :: ndims ! in case val has been reshaped
1366 
1367  integer :: error
1368  intrinsic shape
1369 
1370  if ( .not. file_opened(fid) ) then
1371  log_error("FILE_write_associatedCoordinate_realSP_4D",*) 'File is not opened. fid = ', fid
1372  call prc_abort
1373  end if
1374 
1375  if ( present(ndims) ) then
1376  ! Note this is called for history coordinates which have been reshaped
1377  ! from 2D/3D into 1D array. In this case, start and count must be also present
1378  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1379  name, val, sp, & ! (in)
1380  ndims, start, count, & ! (in)
1381  error ) ! (out)
1382  else if ( present(start) ) then
1383  ! Note this is called for restart coordinates
1384  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1385  name, val, sp, & ! (in)
1386  4, start, shape(val), & ! (in)
1387  error ) ! (out)
1388  else
1389  ! Note this is for the one-file-per-process I/O method
1390  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1391  name, val, sp, & ! (in)
1392  4, (/1,1,1,1/), shape(val), & ! (in)
1393  error ) ! (out)
1394  end if
1395  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1396  log_error("FILE_write_associatedCoordinate_realSP_4D",*) 'failed to put associated coordinate: '//trim(name)
1397  call prc_abort
1398  end if
1399 
1400  return
1401  end subroutine file_write_associatedcoordinate_realsp_4d
1402  subroutine file_write_associatedcoordinate_realdp_4d( &
1403  fid, &
1404  name, &
1405  val, &
1406  start, count, &
1407  ndims )
1408  integer, intent(in) :: fid
1409  character(len=*), intent(in) :: name
1410  real(dp), intent(in) :: val(:,:,:,:)
1411  integer, intent(in), optional :: start(:)
1412  integer, intent(in), optional :: count(:) ! in case val has been reshaped
1413  integer, intent(in), optional :: ndims ! in case val has been reshaped
1414 
1415  integer :: error
1416  intrinsic shape
1417 
1418  if ( .not. file_opened(fid) ) then
1419  log_error("FILE_write_associatedCoordinate_realDP_4D",*) 'File is not opened. fid = ', fid
1420  call prc_abort
1421  end if
1422 
1423  if ( present(ndims) ) then
1424  ! Note this is called for history coordinates which have been reshaped
1425  ! from 2D/3D into 1D array. In this case, start and count must be also present
1426  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1427  name, val, dp, & ! (in)
1428  ndims, start, count, & ! (in)
1429  error ) ! (out)
1430  else if ( present(start) ) then
1431  ! Note this is called for restart coordinates
1432  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1433  name, val, dp, & ! (in)
1434  4, start, shape(val), & ! (in)
1435  error ) ! (out)
1436  else
1437  ! Note this is for the one-file-per-process I/O method
1438  call file_write_associatedcoordinate_c( file_files(fid)%fid, & ! (in)
1439  name, val, dp, & ! (in)
1440  4, (/1,1,1,1/), shape(val), & ! (in)
1441  error ) ! (out)
1442  end if
1443  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1444  log_error("FILE_write_associatedCoordinate_realDP_4D",*) 'failed to put associated coordinate: '//trim(name)
1445  call prc_abort
1446  end if
1447 
1448  return
1449  end subroutine file_write_associatedcoordinate_realdp_4d
1450 
1451  !-----------------------------------------------------------------------------
1452  ! interface FILE_add_variable
1453  !-----------------------------------------------------------------------------
1454  subroutine file_add_variable_no_time( &
1455  fid, &
1456  varname, desc, units, &
1457  standard_name, &
1458  dims, dtype, &
1459  vid, &
1460  time_avg )
1461  integer, intent( in) :: fid
1462  character(len=*), intent( in) :: varname
1463  character(len=*), intent( in) :: desc
1464  character(len=*), intent( in) :: units
1465  character(len=*), intent( in) :: standard_name
1466  character(len=*), intent( in) :: dims(:)
1467  integer, intent( in) :: dtype
1468  integer, intent(out) :: vid
1469  logical, intent( in), optional :: time_avg
1470 
1471  if ( .not. file_opened(fid) ) then
1472  log_error("FILE_add_variable_no_time",*) 'File is not opened. fid = ', fid
1473  call prc_abort
1474  end if
1475 
1476  call file_add_variable_with_time( fid, & ! (in)
1477  varname, desc, units, standard_name, & ! (in)
1478  dims, dtype, -1.0_dp, & ! (in)
1479  vid, & ! (out)
1480  time_avg = time_avg ) ! (in)
1481 
1482  return
1483  end subroutine file_add_variable_no_time
1484 
1485  !-----------------------------------------------------------------------------
1486  subroutine file_add_variable_with_time( &
1487  fid, &
1488  varname, desc, units, &
1489  standard_name, &
1490  dims, dtype, &
1491  time_int, &
1492  vid, &
1493  time_avg )
1494  implicit none
1495  integer, intent(in) :: fid
1496  character(len=*), intent(in) :: varname
1497  character(len=*), intent(in) :: desc
1498  character(len=*), intent(in) :: units
1499  character(len=*), intent(in) :: standard_name
1500  character(len=*), intent(in) :: dims(:)
1501  integer, intent(in) :: dtype
1502  real(dp), intent(in) :: time_int
1503 
1504  integer, intent(out) :: vid
1505 
1506  logical, intent(in), optional :: time_avg
1507 
1508  integer :: cvid
1509  integer :: ndims
1510  integer :: itavg
1511  integer :: error
1512  integer :: n
1513 
1514  intrinsic size
1515  !---------------------------------------------------------------------------
1516 
1517  if ( .not. file_opened(fid) ) then
1518  log_error("FILE_add_variable_with_time",*) 'File is not opened. fid = ', fid
1519  call prc_abort
1520  end if
1521 
1522  vid = -1
1523  do n = 1, file_nvars
1524  if ( file_vars(n)%fid == fid .and. file_vars(n)%name == varname ) then
1525  vid = file_vars(n)%vid
1526  exit
1527  endif
1528  enddo
1529 
1530  if ( vid < 0 ) then ! variable registration
1531 
1532  ndims = size(dims)
1533  itavg = 0
1534 
1535  if ( present(time_avg) ) then
1536  if( time_avg ) itavg = 1
1537  endif
1538 
1539  call file_add_variable_c( file_files(fid)%fid, & ! [IN]
1540  varname, desc, units, standard_name, & ! [IN]
1541  dims, ndims, dtype, time_int, itavg, & ! [IN]
1542  cvid, error ) ! [OUT]
1543 
1544  if ( error /= file_success_code ) then
1545  log_error("FILE_add_variable_with_time",*) 'failed to add variable: '//trim(varname)
1546  call prc_abort
1547  endif
1548 
1549  file_nvars = file_nvars + 1
1550  vid = file_nvars
1551  file_vars(vid)%name = varname
1552  file_vars(vid)%vid = cvid
1553  file_vars(vid)%fid = fid
1554 
1555  log_info("FILE_add_variable_with_time",'(1x,A,I3.3,A,I4.4,2A)') &
1556  'Variable registration : NO.', fid, ', vid = ', vid, ', name = ', trim(varname)
1557  endif
1558 
1559  return
1560  end subroutine file_add_variable_with_time
1561 
1562  subroutine file_def_variable( &
1563  fid, &
1564  varname, desc, units, &
1565  standard_name, &
1566  ndims, dims, &
1567  dtype, &
1568  vid, &
1569  time_int, time_avg, &
1570  existed )
1571  integer, intent( in) :: fid
1572  character(len=*), intent( in) :: varname
1573  character(len=*), intent( in) :: desc
1574  character(len=*), intent( in) :: units
1575  character(len=*), intent( in) :: standard_name
1576  integer, intent( in) :: ndims
1577  character(len=*), intent( in) :: dims(:)
1578  integer, intent( in) :: dtype
1579  integer, intent(out) :: vid
1580  real(dp), intent( in), optional :: time_int
1581  logical, intent( in), optional :: time_avg
1582  logical, intent(out), optional :: existed
1583 
1584  real(dp) :: tint_
1585  integer :: itavg
1586  integer :: cvid
1587  integer :: error
1588  integer :: n
1589 
1590  !---------------------------------------------------------------------------
1591 
1592  if ( .not. file_opened(fid) ) then
1593  log_error("FILE_def_variable",*) 'File is not opened. fid = ', fid
1594  call prc_abort
1595  end if
1596 
1597  vid = -1
1598  do n = 1, file_nvars
1599  if ( file_vars(n)%fid == fid .and. file_vars(n)%name == varname ) then
1600  vid = n
1601  end if
1602  enddo
1603 
1604  if ( vid < 0 ) then ! variable registration
1605 
1606  if ( present(time_int) ) then
1607  tint_ = time_int
1608  else
1609  tint_ = -1.0_dp
1610  endif
1611 
1612  if ( present(time_avg) ) then
1613  if ( time_avg ) then
1614  itavg = 1
1615  else
1616  itavg = 0
1617  end if
1618  else
1619  itavg = 0
1620  end if
1621 
1622  call file_add_variable_c( file_files(fid)%fid, & ! (in)
1623  varname, desc, units, standard_name, & ! (in)
1624  dims, ndims, dtype, & ! (in)
1625  tint_, itavg, & ! (in)
1626  cvid, error ) ! (out)
1627  if ( error /= file_success_code ) then
1628  log_error("FILE_def_variable",*) 'failed to add variable: '//trim(varname)
1629  call prc_abort
1630  end if
1631 
1632  file_nvars = file_nvars + 1
1633  vid = file_nvars
1634  file_vars(vid)%name = varname
1635  file_vars(vid)%vid = cvid
1636  file_vars(vid)%fid = fid
1637 
1638  log_info("FILE_def_variable",'(1x,A,I3.3,A,I4.4,2A)') &
1639  'Variable registration : NO.', fid, ', vid = ', vid, ', name = ', trim(varname)
1640 
1641  if ( present(existed) ) existed = .false.
1642  else
1643  if ( present(existed) ) existed = .true.
1644  endif
1645 
1646  return
1647  end subroutine file_def_variable
1648 
1649  !-----------------------------------------------------------------------------
1650  ! FILE_Get_Attribute
1651  !-----------------------------------------------------------------------------
1652  subroutine file_get_attribute_text_fid( &
1653  fid, &
1654  vname, key, &
1655  val, &
1656  existed )
1657  integer, intent(in ) :: fid
1658  character(len=*), intent(in ) :: vname
1659  character(len=*), intent(in ) :: key
1660  character(len=*), intent(out) :: val
1661 
1662  logical, intent(out), optional :: existed
1663 
1664  integer :: suppress
1665  integer :: error
1666 
1667  if ( .not. file_opened(fid) ) then
1668  log_error("FILE_get_attribute_text_fid",*) 'File is not opened. fid = ', fid
1669  call prc_abort
1670  end if
1671 
1672  if ( present(existed) ) then
1673  suppress = 1
1674  else
1675  suppress = 0
1676  end if
1678  file_files(fid)%fid, vname, & ! (in)
1679  key, suppress, & ! (in)
1680  val, error ) ! (out)
1681  if ( error /= file_success_code ) then
1682  if ( present(existed) ) then
1683  existed = .false.
1684  else
1685  log_error("FILE_get_attribute_text_fid",*) 'failed to get text attribute for '//trim(vname)//': '//trim(key)
1686  call prc_abort
1687  end if
1688  else
1689  if ( present(existed) ) existed = .true.
1690  end if
1691 
1692  return
1693  end subroutine file_get_attribute_text_fid
1694  subroutine file_get_attribute_text_fname( &
1695  basename, vname, key, &
1696  val, &
1697  single, aggregate, rankid, &
1698  existed )
1699  implicit none
1700 
1701  character(len=*), intent(in) :: basename
1702  character(len=*), intent(in) :: vname
1703  character(len=*), intent(in) :: key
1704 
1705  character(len=*), intent(out) :: val
1706 
1707  logical, intent(in), optional :: single
1708  logical, intent(in), optional :: aggregate
1709  integer, intent(in), optional :: rankid
1710 
1711  logical, intent(out), optional :: existed
1712  integer :: fid
1713 
1714  call file_open( basename, & ! (in)
1715  fid, & ! (out)
1716  single=single, & ! (in)
1717  aggregate=aggregate, & ! (in)
1718  rankid=rankid ) ! (in)
1719 
1720  call file_get_attribute_text_fid( &
1721  fid, vname, key, & ! (in)
1722  val, & ! (out)
1723  existed ) ! (out)
1724 
1725  return
1726  end subroutine file_get_attribute_text_fname
1727 
1728  !-----------------------------------------------------------------------------
1729  subroutine file_get_attribute_logical_fid( &
1730  fid, &
1731  vname, key, &
1732  val, &
1733  existed )
1734  integer, intent(in ) :: fid
1735  character(len=*), intent(in ) :: vname
1736  character(len=*), intent(in ) :: key
1737  logical, intent(out) :: val
1738 
1739  logical, intent(out), optional :: existed
1740 
1741  character(len=5) :: buf
1742 
1743  if ( .not. file_opened(fid) ) then
1744  log_error("FILE_get_attribute_logical_fid",*) 'File is not opened. fid = ', fid
1745  call prc_abort
1746  end if
1747 
1748  call file_get_attribute_text_fid( fid, vname, key, & ! (in)
1749  buf, existed ) ! (out)
1750 
1751  if ( present(existed) ) then
1752  if ( .not. existed ) return
1753  end if
1754 
1755  if ( buf == "true" ) then
1756  val = .true.
1757  else if ( buf == "false" ) then
1758  val = .false.
1759  else
1760  log_error("FILE_get_attribute_logical_fid",*) 'value is not eigher true or false'
1761  call prc_abort
1762  end if
1763 
1764  return
1765  end subroutine file_get_attribute_logical_fid
1766  subroutine file_get_attribute_logical_fname( &
1767  basename, vname, key, &
1768  val, &
1769  single, aggregate, rankid, &
1770  existed )
1771  implicit none
1772 
1773  character(len=*), intent(in) :: basename
1774  character(len=*), intent(in) :: vname
1775  character(len=*), intent(in) :: key
1776 
1777  logical, intent(out) :: val
1778 
1779  logical, intent(in), optional :: single
1780  logical, intent(in), optional :: aggregate
1781  integer, intent(in), optional :: rankid
1782 
1783  logical, intent(out), optional :: existed
1784  integer :: fid
1785 
1786  call file_open( basename, & ! (in)
1787  fid, & ! (out)
1788  single=single, & ! (in)
1789  aggregate=aggregate, & ! (in)
1790  rankid=rankid ) ! (in)
1791 
1792  call file_get_attribute_logical_fid( &
1793  fid, vname, key, & ! (in)
1794  val, & ! (out)
1795  existed ) ! (out)
1796 
1797  return
1798  end subroutine file_get_attribute_logical_fname
1799 
1800  !-----------------------------------------------------------------------------
1801  subroutine file_get_attribute_int_fid_ary( &
1802  fid, vname, key, &
1803  val, &
1804  existed )
1805  integer, intent(in ) :: fid
1806  character(len=*), intent(in ) :: vname
1807  character(len=*), intent(in ) :: key
1808  integer, intent(out) :: val(:)
1809 
1810  logical, intent(out), optional :: existed
1811 
1812  integer :: suppress
1813  integer :: error
1814 
1815  intrinsic size
1816 
1817  if ( .not. file_opened(fid) ) then
1818  log_error("FILE_get_attribute_int_fid",*) 'File is not opened. fid = ', fid
1819  call prc_abort
1820  end if
1821 
1822  if ( present(existed) ) then
1823  suppress = 1
1824  else
1825  suppress = 0
1826  end if
1827  call file_get_attribute_int_c( &
1828  file_files(fid)%fid, vname, & ! (in)
1829  key, size(val), suppress, & ! (in)
1830  val, error ) ! (out)
1831  if ( error /= file_success_code ) then
1832  if ( present(existed) ) then
1833  existed = .false.
1834  else
1835  log_error("FILE_get_attribute_int_fid",*) 'failed to get integer attribute for '//trim(vname)//': '//trim(key)
1836  call prc_abort
1837  end if
1838  else
1839  if ( present(existed) ) existed = .true.
1840  end if
1841 
1842  return
1843  end subroutine file_get_attribute_int_fid_ary
1844  subroutine file_get_attribute_int_fid( &
1845  fid, vname, key, &
1846  val, &
1847  existed )
1848  integer, intent(in ) :: fid
1849  character(len=*), intent(in ) :: vname
1850  character(len=*), intent(in ) :: key
1851  integer, intent(out) :: val
1852  logical, intent(out), optional :: existed
1853  integer :: ary(1)
1854 
1855  call file_get_attribute_int_fid_ary( &
1856  fid, vname, key, &
1857  ary(:), &
1858  existed )
1859  if ( present(existed) ) then
1860  if ( .not. existed ) return
1861  end if
1862  val = ary(1)
1863 
1864  return
1865  end subroutine file_get_attribute_int_fid
1866  subroutine file_get_attribute_int_fname_ary( &
1867  basename, vname, key, &
1868  val, &
1869  single, aggregate, rankid, &
1870  existed )
1871  implicit none
1872 
1873  character(len=*), intent(in) :: basename
1874  character(len=*), intent(in) :: vname
1875  character(len=*), intent(in) :: key
1876 
1877  integer, intent(out) :: val(:)
1878 
1879  logical, intent(in), optional :: single
1880  logical, intent(in), optional :: aggregate
1881  integer, intent(in), optional :: rankid
1882 
1883  logical, intent(out), optional :: existed
1884 
1885  integer :: fid
1886 
1887  call file_open( basename, & ! (in)
1888  fid, & ! (out)
1889  single=single, & ! (in)
1890  aggregate=aggregate, &
1891  rankid=rankid ) ! (in)
1892 
1893  call file_get_attribute_int_fid_ary( &
1894  fid, vname, key, & ! (in)
1895  val, & ! (out)
1896  existed ) ! (out)
1897 
1898  return
1899  end subroutine file_get_attribute_int_fname_ary
1900  subroutine file_get_attribute_int_fname( &
1901  basename, vname, key, &
1902  val, &
1903  single, aggregate, rankid, &
1904  existed )
1905  implicit none
1906  character(len=*), intent(in) :: basename
1907  character(len=*), intent(in) :: vname
1908  character(len=*), intent(in) :: key
1909  integer, intent(out) :: val
1910  logical, intent(in), optional :: single
1911  logical, intent(in), optional :: aggregate
1912  integer, intent(in), optional :: rankid
1913  logical, intent(out), optional :: existed
1914  integer :: ary(1)
1915 
1916  call file_get_attribute_int_fname_ary( &
1917  basename, vname, key, &
1918  ary(:), &
1919  single, aggregate, rankid, &
1920  existed )
1921  val = ary(1)
1922 
1923  return
1924  end subroutine file_get_attribute_int_fname
1925  !-----------------------------------------------------------------------------
1926 
1927  subroutine file_get_attribute_float_fid_ary( &
1928  fid, vname, key, &
1929  val, &
1930  existed )
1931  integer, intent(in ) :: fid
1932  character(len=*), intent(in ) :: vname
1933  character(len=*), intent(in ) :: key
1934  real(sp), intent(out) :: val(:)
1935 
1936  logical, intent(out), optional :: existed
1937 
1938  integer :: suppress
1939  integer :: error
1940 
1941  intrinsic size
1942 
1943  if ( .not. file_opened(fid) ) then
1944  log_error("FILE_get_attribute_float_fid",*) 'File is not opened. fid = ', fid
1945  call prc_abort
1946  end if
1947 
1948  if ( present(existed) ) then
1949  suppress = 1
1950  else
1951  suppress = 0
1952  end if
1954  file_files(fid)%fid, vname, & ! (in)
1955  key, size(val), suppress, & ! (in)
1956  val, error ) ! (out)
1957  if ( error /= file_success_code ) then
1958  if ( present(existed) ) then
1959  existed = .false.
1960  else
1961  log_error("FILE_get_attribute_float_fid",*) 'failed to get float attribute for '//trim(vname)//': '//trim(key)
1962  call prc_abort
1963  end if
1964  else
1965  if ( present(existed) ) existed = .true.
1966  end if
1967 
1968  return
1969  end subroutine file_get_attribute_float_fid_ary
1970  subroutine file_get_attribute_float_fid( &
1971  fid, vname, key, &
1972  val, &
1973  existed )
1974  integer, intent(in ) :: fid
1975  character(len=*), intent(in ) :: vname
1976  character(len=*), intent(in ) :: key
1977  real(sp), intent(out) :: val
1978  logical, intent(out), optional :: existed
1979  real(sp) :: ary(1)
1980 
1981  call file_get_attribute_float_fid_ary( &
1982  fid, vname, key, &
1983  ary(:), &
1984  existed )
1985  if ( present(existed) ) then
1986  if ( .not. existed ) return
1987  end if
1988  val = ary(1)
1989 
1990  return
1991  end subroutine file_get_attribute_float_fid
1992  subroutine file_get_attribute_float_fname_ary( &
1993  basename, vname, key, &
1994  val, &
1995  single, aggregate, rankid, &
1996  existed )
1997  implicit none
1998 
1999  character(len=*), intent(in) :: basename
2000  character(len=*), intent(in) :: vname
2001  character(len=*), intent(in) :: key
2002 
2003  real(sp), intent(out) :: val(:)
2004 
2005  logical, intent(in), optional :: single
2006  logical, intent(in), optional :: aggregate
2007  integer, intent(in), optional :: rankid
2008 
2009  logical, intent(out), optional :: existed
2010 
2011  integer :: fid
2012 
2013  call file_open( basename, & ! (in)
2014  fid, & ! (out)
2015  single=single, & ! (in)
2016  aggregate=aggregate, & ! (in)
2017  rankid=rankid ) ! (in)
2018 
2019  call file_get_attribute_float_fid_ary( &
2020  fid, vname, key, & ! (in)
2021  val, & ! (out)
2022  existed ) ! (out)
2023 
2024  return
2025  end subroutine file_get_attribute_float_fname_ary
2026  subroutine file_get_attribute_float_fname( &
2027  basename, vname, key, &
2028  val, &
2029  single, aggregate, rankid, &
2030  existed )
2031  implicit none
2032  character(len=*), intent(in) :: basename
2033  character(len=*), intent(in) :: vname
2034  character(len=*), intent(in) :: key
2035  real(sp), intent(out) :: val
2036  logical, intent(in), optional :: single
2037  logical, intent(in), optional :: aggregate
2038  integer, intent(in), optional :: rankid
2039  logical, intent(out), optional :: existed
2040  real(sp) :: ary(1)
2041 
2042  call file_get_attribute_float_fname_ary( &
2043  basename, vname, key, &
2044  ary(:), &
2045  single, aggregate, rankid, &
2046  existed )
2047  val = ary(1)
2048 
2049  return
2050  end subroutine file_get_attribute_float_fname
2051  subroutine file_get_attribute_double_fid_ary( &
2052  fid, vname, key, &
2053  val, &
2054  existed )
2055  integer, intent(in ) :: fid
2056  character(len=*), intent(in ) :: vname
2057  character(len=*), intent(in ) :: key
2058  real(dp), intent(out) :: val(:)
2059 
2060  logical, intent(out), optional :: existed
2061 
2062  integer :: suppress
2063  integer :: error
2064 
2065  intrinsic size
2066 
2067  if ( .not. file_opened(fid) ) then
2068  log_error("FILE_get_attribute_double_fid",*) 'File is not opened. fid = ', fid
2069  call prc_abort
2070  end if
2071 
2072  if ( present(existed) ) then
2073  suppress = 1
2074  else
2075  suppress = 0
2076  end if
2078  file_files(fid)%fid, vname, & ! (in)
2079  key, size(val), suppress, & ! (in)
2080  val, error ) ! (out)
2081  if ( error /= file_success_code ) then
2082  if ( present(existed) ) then
2083  existed = .false.
2084  else
2085  log_error("FILE_get_attribute_double_fid",*) 'failed to get double attribute for '//trim(vname)//': '//trim(key)
2086  call prc_abort
2087  end if
2088  else
2089  if ( present(existed) ) existed = .true.
2090  end if
2091 
2092  return
2093  end subroutine file_get_attribute_double_fid_ary
2094  subroutine file_get_attribute_double_fid( &
2095  fid, vname, key, &
2096  val, &
2097  existed )
2098  integer, intent(in ) :: fid
2099  character(len=*), intent(in ) :: vname
2100  character(len=*), intent(in ) :: key
2101  real(dp), intent(out) :: val
2102  logical, intent(out), optional :: existed
2103  real(dp) :: ary(1)
2104 
2105  call file_get_attribute_double_fid_ary( &
2106  fid, vname, key, &
2107  ary(:), &
2108  existed )
2109  if ( present(existed) ) then
2110  if ( .not. existed ) return
2111  end if
2112  val = ary(1)
2113 
2114  return
2115  end subroutine file_get_attribute_double_fid
2116  subroutine file_get_attribute_double_fname_ary( &
2117  basename, vname, key, &
2118  val, &
2119  single, aggregate, rankid, &
2120  existed )
2121  implicit none
2122 
2123  character(len=*), intent(in) :: basename
2124  character(len=*), intent(in) :: vname
2125  character(len=*), intent(in) :: key
2126 
2127  real(dp), intent(out) :: val(:)
2128 
2129  logical, intent(in), optional :: single
2130  logical, intent(in), optional :: aggregate
2131  integer, intent(in), optional :: rankid
2132 
2133  logical, intent(out), optional :: existed
2134 
2135  integer :: fid
2136 
2137  call file_open( basename, & ! (in)
2138  fid, & ! (out)
2139  single=single, & ! (in)
2140  aggregate=aggregate, & ! (in)
2141  rankid=rankid ) ! (in)
2142 
2143  call file_get_attribute_double_fid_ary( &
2144  fid, vname, key, & ! (in)
2145  val, & ! (out)
2146  existed ) ! (out)
2147 
2148  return
2149  end subroutine file_get_attribute_double_fname_ary
2150  subroutine file_get_attribute_double_fname( &
2151  basename, vname, key, &
2152  val, &
2153  single, aggregate, rankid, &
2154  existed )
2155  implicit none
2156  character(len=*), intent(in) :: basename
2157  character(len=*), intent(in) :: vname
2158  character(len=*), intent(in) :: key
2159  real(dp), intent(out) :: val
2160  logical, intent(in), optional :: single
2161  logical, intent(in), optional :: aggregate
2162  integer, intent(in), optional :: rankid
2163  logical, intent(out), optional :: existed
2164  real(dp) :: ary(1)
2165 
2166  call file_get_attribute_double_fname_ary( &
2167  basename, vname, key, &
2168  ary(:), &
2169  single, aggregate, rankid, &
2170  existed )
2171  val = ary(1)
2172 
2173  return
2174  end subroutine file_get_attribute_double_fname
2175 
2176  !-----------------------------------------------------------------------------
2177  ! FILE_set_attribute
2178  !-----------------------------------------------------------------------------
2179  subroutine file_set_attribute_text( &
2180  fid, vname, &
2181  key, val )
2182  integer, intent(in) :: fid
2183  character(len=*), intent(in) :: vname
2184  character(len=*), intent(in) :: key
2185  character(len=*), intent(in) :: val
2186 
2187  integer :: error
2188 
2189  if ( .not. file_opened(fid) ) then
2190  log_error("FILE_set_attribute_text",*) 'File is not opened. fid = ', fid
2191  call prc_abort
2192  end if
2193 
2195  file_files(fid)%fid, vname, & ! (in)
2196  key, val, & ! (in)
2197  error ) ! (out)
2198  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2199  log_error("FILE_set_attribute_text",*) 'failed to set text attribute for '//trim(vname)//': '//trim(key)
2200  call prc_abort
2201  end if
2202 
2203  return
2204  end subroutine file_set_attribute_text
2205 
2206  subroutine file_set_attribute_logical( &
2207  fid, vname, &
2208  key, val )
2209  integer, intent(in) :: fid
2210  character(len=*), intent(in) :: vname
2211  character(len=*), intent(in) :: key
2212  logical, intent(in) :: val
2213 
2214  character(len=5) :: buf
2215 
2216  if ( .not. file_opened(fid) ) then
2217  log_error("FILE_set_attribute_logical",*) 'File is not opened. fid = ', fid
2218  call prc_abort
2219  end if
2220 
2221  if ( val ) then
2222  buf = "true"
2223  else
2224  buf = "false"
2225  end if
2226 
2227  call file_set_attribute_text( fid, vname, key, buf )
2228 
2229  return
2230  end subroutine file_set_attribute_logical
2231 
2232  !-----------------------------------------------------------------------------
2233  subroutine file_set_attribute_int_ary( &
2234  fid, vname, &
2235  key, val )
2236  integer, intent(in) :: fid
2237  character(len=*), intent(in) :: vname
2238  character(len=*), intent(in) :: key
2239  integer, intent(in) :: val(:)
2240 
2241  integer :: error
2242 
2243  intrinsic size
2244 
2245  if ( .not. file_opened(fid) ) then
2246  log_error("FILE_set_attribute_int",*) 'File is not opened. fid = ', fid
2247  call prc_abort
2248  end if
2249 
2250  call file_set_attribute_int_c( &
2251  file_files(fid)%fid, vname, & ! (in)
2252  key, val(:), size(val(:)), & ! (in)
2253  error ) ! (out)
2254  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2255  log_error("FILE_set_attribute_int",*) 'failed to set integer attribute for '//trim(vname)//': '//trim(key)
2256  call prc_abort
2257  end if
2258 
2259  return
2260  end subroutine file_set_attribute_int_ary
2261 
2262  subroutine file_set_attribute_int( &
2263  fid, vname, &
2264  key, val )
2265  integer, intent(in) :: fid
2266  character(len=*), intent(in) :: vname
2267  character(len=*), intent(in) :: key
2268  integer, intent(in) :: val
2269 
2270  integer :: ary(1)
2271 
2272  ary(1) = val
2273  call file_set_attribute_int_ary( fid, vname, &
2274  key, ary(:) )
2275 
2276  return
2277  end subroutine file_set_attribute_int
2278 
2279  !-----------------------------------------------------------------------------
2280  subroutine file_set_attribute_float_ary( &
2281  fid, vname, &
2282  key, val )
2283  integer, intent(in) :: fid
2284  character(len=*), intent(in) :: vname
2285  character(len=*), intent(in) :: key
2286  real(sp), intent(in) :: val(:)
2287 
2288  integer :: error
2289 
2290  intrinsic size
2291 
2292  if ( .not. file_opened(fid) ) then
2293  log_error("FILE_set_attributefloat",*) 'File is not opened. fid = ', fid
2294  call prc_abort
2295  end if
2296 
2298  file_files(fid)%fid, vname, & ! (in)
2299  key, val(:), size(val(:)), & ! (in)
2300  error ) ! (out)
2301  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2302  log_error("FILE_set_attribute_float",*) 'failed to set float attribute for '//trim(vname)//': '//trim(key)
2303  call prc_abort
2304  end if
2305 
2306  return
2307  end subroutine file_set_attribute_float_ary
2308 
2309  subroutine file_set_attribute_float( &
2310  fid, vname, &
2311  key, val )
2312  integer, intent(in) :: fid
2313  character(len=*), intent(in) :: vname
2314  character(len=*), intent(in) :: key
2315  real(sp), intent(in) :: val
2316 
2317  real(sp) :: ary(1)
2318 
2319  ary(1) = val
2320  call file_set_attribute_float_ary( fid, vname, &
2321  key, ary(:) )
2322 
2323  return
2324  end subroutine file_set_attribute_float
2325  !-----------------------------------------------------------------------------
2326  subroutine file_set_attribute_double_ary( &
2327  fid, vname, &
2328  key, val )
2329  integer, intent(in) :: fid
2330  character(len=*), intent(in) :: vname
2331  character(len=*), intent(in) :: key
2332  real(dp), intent(in) :: val(:)
2333 
2334  integer :: error
2335 
2336  intrinsic size
2337 
2338  if ( .not. file_opened(fid) ) then
2339  log_error("FILE_set_attributedouble",*) 'File is not opened. fid = ', fid
2340  call prc_abort
2341  end if
2342 
2344  file_files(fid)%fid, vname, & ! (in)
2345  key, val(:), size(val(:)), & ! (in)
2346  error ) ! (out)
2347  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
2348  log_error("FILE_set_attribute_double",*) 'failed to set double attribute for '//trim(vname)//': '//trim(key)
2349  call prc_abort
2350  end if
2351 
2352  return
2353  end subroutine file_set_attribute_double_ary
2354 
2355  subroutine file_set_attribute_double( &
2356  fid, vname, &
2357  key, val )
2358  integer, intent(in) :: fid
2359  character(len=*), intent(in) :: vname
2360  character(len=*), intent(in) :: key
2361  real(dp), intent(in) :: val
2362 
2363  real(dp) :: ary(1)
2364 
2365  ary(1) = val
2366  call file_set_attribute_double_ary( fid, vname, &
2367  key, ary(:) )
2368 
2369  return
2370  end subroutine file_set_attribute_double
2371  !-----------------------------------------------------------------------------
2372  ! FILE_get_shape
2373  !-----------------------------------------------------------------------------
2374  subroutine file_get_shape_fname( &
2375  basename, varname, &
2376  dims, &
2377  rankid, single, &
2378  error )
2379  implicit none
2380 
2381  character(len=*), intent( in) :: basename
2382  character(len=*), intent( in) :: varname
2383  integer, intent(out) :: dims(:)
2384  integer, intent( in), optional :: rankid
2385  logical, intent( in), optional :: single
2386  logical, intent(out), optional :: error
2387 
2388  integer :: fid
2389  !---------------------------------------------------------------------------
2390 
2391  !--- search/register file
2392  call file_open( basename, & ! (in)
2393  fid, & ! (out)
2394  rankid=rankid, single=single ) ! (in)
2395 
2396  call file_get_shape_fid( fid, varname, & ! (in)
2397  dims(:), & ! (out)
2398  error = error ) ! (out)
2399 
2400  return
2401  end subroutine file_get_shape_fname
2402 
2403  subroutine file_get_shape_fid( &
2404  fid, varname, &
2405  dims, &
2406  error )
2407  implicit none
2408  integer, intent( in) :: fid
2409  character(len=*), intent( in) :: varname
2410 
2411  integer, intent(out) :: dims(:)
2412 
2413  logical, intent(out), optional :: error
2414 
2415  type(datainfo) :: dinfo
2416  integer :: ierror
2417  integer :: n
2418 
2419  logical :: suppress
2420 
2421  intrinsic size
2422  !---------------------------------------------------------------------------
2423 
2424  if ( .not. file_opened(fid) ) then
2425  log_error("FILE_get_shape_id",*) 'File is not opened. fid = ', fid
2426  call prc_abort
2427  end if
2428 
2429  if ( present(error) ) then
2430  suppress = .true.
2431  else
2432  suppress = .false.
2433  end if
2434 
2435  !--- get data information
2436  call file_get_datainfo_c( dinfo, & ! (out)
2437  file_files(fid)%fid, varname, & ! (in)
2438  1, suppress, & ! (in)
2439  ierror ) ! (out)
2440 
2441  !--- verify
2442  if ( ierror /= file_success_code ) then
2443  if ( present(error) ) then
2444  error = .true.
2445  return
2446  else
2447  log_error("FILE_get_shape_fid",*) 'failed to get data information : ', trim(varname)
2448  call prc_abort
2449  end if
2450  end if
2451 
2452  if ( dinfo%rank /= size(dims) ) then
2453  log_error("FILE_get_shape_fid",*) 'rank is different, ', trim(varname), size(dims), dinfo%rank
2454  call prc_abort
2455  end if
2456  do n = 1, size(dims)
2457  dims(n) = dinfo%dim_size(n)
2458  end do
2459 
2460  if ( present(error) ) error = .false.
2461 
2462  return
2463  end subroutine file_get_shape_fid
2464 
2465  !-----------------------------------------------------------------------------
2467  !-----------------------------------------------------------------------------
2468  subroutine file_get_stepsize( &
2469  fid, varname, &
2470  len, &
2471  error )
2472  integer, intent(in) :: fid
2473  character(len=*), intent(in) :: varname
2474 
2475  integer, intent(out) :: len
2476 
2477  logical, intent(out), optional :: error
2478 
2479  integer :: ierror
2480 
2481  if ( .not. file_opened(fid) ) then
2482  log_error("FILE_get_stepSize",*) 'File is not opened. fid = ', fid
2483  call prc_abort
2484  end if
2485 
2486  call file_get_step_size_c( file_files(fid)%fid, varname, & ! (in)
2487  len, ierror ) ! (out)
2488  if ( ierror /= file_success_code .and. ierror /= file_already_existed_code ) then
2489  if ( present(error) ) then
2490  error = .true.
2491  else
2492  log_error("FILE_get_stepSize",*) 'failed to get number of steps'
2493  call prc_abort
2494  end if
2495  else
2496  if ( present(error) ) error = .false.
2497  end if
2498 
2499  return
2500  end subroutine file_get_stepsize
2501 
2502  !-----------------------------------------------------------------------------
2503  ! FILE_get_commonInfo
2504  !-----------------------------------------------------------------------------
2505  subroutine file_get_commoninfo_fname( &
2506  basename, &
2507  rankid, &
2508  nvars_limit, &
2509  title, &
2510  source, &
2511  institution, &
2512  nvars, &
2513  varname )
2514  implicit none
2515 
2516  character(len=*), intent(in) :: basename
2517  integer, intent(in) :: rankid
2518  integer, intent(in) :: nvars_limit
2519  character(len=FILE_HMID), intent(out) :: title ! title of the file
2520  character(len=FILE_HMID), intent(out) :: source ! for file header
2521  character(len=FILE_HMID), intent(out) :: institution ! for file header
2522  integer, intent(out) :: nvars ! number of variables
2523  character(len=FILE_HSHORT), intent(out) :: varname(nvars_limit) ! name of variables
2524 
2525  integer :: fid
2526  !---------------------------------------------------------------------------
2527 
2528  call file_open( basename, & ! [IN]
2529  fid, & ! [OUT]
2530  rankid=rankid ) ! [IN]
2531 
2532  call file_get_commoninfo_fid( fid, & ! [IN]
2533  nvars_limit, & ! [IN]
2534  title, & ! [OUT]
2535  source, & ! [OUT]
2536  institution, & ! [OUT]
2537  nvars, & ! [OUT]
2538  varname(:) ) ! [OUT]
2539 
2540  return
2541  end subroutine file_get_commoninfo_fname
2542 
2543  subroutine file_get_commoninfo_fid( &
2544  fid, &
2545  nvars_limit, &
2546  title, &
2547  source, &
2548  institution, &
2549  nvars, &
2550  varname )
2551  implicit none
2552 
2553  integer, intent(in) :: fid
2554  integer, intent(in) :: nvars_limit
2555  character(len=FILE_HMID), intent(out) :: title ! title of the file
2556  character(len=FILE_HMID), intent(out) :: source ! for file header
2557  character(len=FILE_HMID), intent(out) :: institution ! for file header
2558  integer, intent(out) :: nvars ! number of variables
2559  character(len=FILE_HSHORT), intent(out) :: varname(nvars_limit) ! name of variables
2560 
2561  integer :: v
2562  !---------------------------------------------------------------------------
2563 
2564  if ( .not. file_opened(fid) ) then
2565  log_error("FILE_get_commonInfo_fid",*) 'File is not opened. fid = ', fid
2566  call prc_abort
2567  end if
2568 
2569  call file_get_attribute( fid, 'global', 'title', title )
2570  call file_get_attribute( fid, 'global', 'source', source )
2571  call file_get_attribute( fid, 'global', 'institution', institution )
2572 
2573  call file_get_var_num( fid, nvars_limit, nvars )
2574 
2575  do v = 1, nvars
2576  call file_get_var_name( fid, v, varname(v) )
2577  enddo
2578 
2579  return
2580  end subroutine file_get_commoninfo_fid
2581 
2582  !-----------------------------------------------------------------------------
2583  ! FILE_get_dataInfo
2584  !-----------------------------------------------------------------------------
2585  subroutine file_get_datainfo_fname( &
2586  basename, varname, &
2587  rankid, istep, single, &
2588  existed, &
2589  description, units, standard_name, &
2590  datatype, &
2591  dim_rank, dim_name, dim_size, &
2592  natts, att_name, att_type, att_len, &
2593  time_start, time_end, &
2594  time_units, calendar )
2595  implicit none
2596 
2597  character(len=*), intent(in) :: basename
2598  character(len=*), intent(in) :: varname
2599 
2600  integer, intent(in), optional :: rankid
2601  integer, intent(in), optional :: istep
2602  logical, intent(in), optional :: single
2603  logical, intent(out), optional :: existed
2604  character(len=FILE_HMID), intent(out), optional :: description
2605  character(len=FILE_HSHORT), intent(out), optional :: units
2606  character(len=FILE_HMID), intent(out), optional :: standard_name
2607  integer, intent(out), optional :: datatype
2608  integer, intent(out), optional :: dim_rank
2609  character(len=FILE_HSHORT), intent(out), optional :: dim_name(:)
2610  integer, intent(out), optional :: dim_size(:)
2611  integer, intent(out), optional :: natts
2612  character(len=FILE_HSHORT), intent(out), optional :: att_name(:)
2613  integer, intent(out), optional :: att_type(:)
2614  integer, intent(out), optional :: att_len (:)
2615  real(dp), intent(out), optional :: time_start
2616  real(dp), intent(out), optional :: time_end
2617  character(len=FILE_HMID), intent(out), optional :: time_units
2618  character(len=FILE_HSHORT), intent(out), optional :: calendar
2619 
2620  logical :: single_
2621  integer :: fid
2622  !---------------------------------------------------------------------------
2623 
2624  if ( present(single) ) then
2625  single_ = single
2626  else
2627  single_ = .false.
2628  endif
2629 
2630  !--- search/register file
2631  call file_open( basename, & ! [IN]
2632  fid, & ! [OUT]
2633  rankid=rankid, single=single_ ) ! [IN]
2634 
2635  call file_get_datainfo_fid( fid, varname, & ! [IN]
2636  istep, & ! [IN] , optional
2637  existed, & ! [OUT], optional
2638  description, units, standard_name, & ! [OUT], optional
2639  datatype, & ! [OUT], optional
2640  dim_rank, dim_name, dim_size, & ! [OUT], optional
2641  natts, att_name, att_type, att_len, & ! [OUT], optional
2642  time_start, time_end, time_units, calendar ) ! [OUT], optional
2643 
2644  return
2645  end subroutine file_get_datainfo_fname
2646 
2647  subroutine file_get_datainfo_fid( &
2648  fid, varname, &
2649  istep, &
2650  existed, &
2651  description, units, standard_name, &
2652  datatype, &
2653  dim_rank, dim_name, dim_size, &
2654  natts, att_name, att_type, att_len, &
2655  time_start, time_end, &
2656  time_units, calendar )
2657  implicit none
2658 
2659  integer, intent(in) :: fid
2660  character(len=*), intent(in) :: varname
2661 
2662  integer, intent(in), optional :: istep
2663  logical, intent(out), optional :: existed
2664  character(len=FILE_HMID), intent(out), optional :: description
2665  character(len=FILE_HSHORT), intent(out), optional :: units
2666  character(len=FILE_HMID), intent(out), optional :: standard_name
2667  integer, intent(out), optional :: datatype
2668  integer, intent(out), optional :: dim_rank
2669  character(len=FILE_HSHORT), intent(out), optional :: dim_name(:)
2670  integer, intent(out), optional :: dim_size(:)
2671  integer, intent(out), optional :: natts
2672  character(len=FILE_HSHORT), intent(out), optional :: att_name(:)
2673  integer, intent(out), optional :: att_type(:)
2674  integer, intent(out), optional :: att_len (:)
2675  real(dp), intent(out), optional :: time_start
2676  real(dp), intent(out), optional :: time_end
2677  character(len=FILE_HMID), intent(out), optional :: time_units
2678  character(len=FILE_HSHORT), intent(out), optional :: calendar
2679 
2680  type(datainfo) :: dinfo
2681 
2682  integer :: istep_
2683  real(dp) :: time(1)
2684  integer :: i
2685  integer :: error
2686 
2687  logical :: suppress
2688  logical :: existed2
2689 
2690  intrinsic size
2691  !---------------------------------------------------------------------------
2692 
2693  if ( present(istep) ) then
2694  istep_ = istep
2695  else
2696  istep_ = 1
2697  end if
2698 
2699  if ( present(existed) ) then
2700  suppress = .true.
2701  else
2702  suppress = .false.
2703  end if
2704 
2705  if ( .not. file_opened(fid) ) then
2706  log_error("FILE_get_dataInfo_fid",*) 'File is not opened. fid = ', fid
2707  call prc_abort
2708  end if
2709 
2710  !--- get data information
2711  call file_get_datainfo_c( dinfo, & ! [OUT]
2712  file_files(fid)%fid, & ! [IN]
2713  varname, & ! [IN]
2714  istep_, & ! [IN]
2715  suppress, & ! [IN]
2716  error ) ! [OUT]
2717 
2718  !--- verify and exit
2719  if ( error /= file_success_code ) then
2720  if ( present( existed ) ) then
2721  existed = .false.
2722  return
2723  else
2724  log_error("FILE_get_dataInfo_fid",*) 'data info not found'
2725  call prc_abort
2726  end if
2727  endif
2728 
2729  if ( present(existed) ) existed = .true.
2730 
2731  if ( present(description) ) description = dinfo%description
2732  if ( present(units) ) units = dinfo%units
2733  if ( present(standard_name) ) standard_name = dinfo%standard_name
2734  if ( present(datatype) ) datatype = dinfo%datatype
2735  if ( present(dim_rank) ) dim_rank = dinfo%rank
2736 
2737  if ( present(dim_name) ) then
2738  do i = 1, min( dinfo%rank, size(dim_name) ) ! limit dimension rank
2739  dim_name(i) = dinfo%dim_name(i)
2740  enddo
2741  endif
2742 
2743  if ( present(dim_size) ) then
2744  do i = 1, min( dinfo%rank, size(dim_size) ) ! limit dimension rank
2745  dim_size(i) = dinfo%dim_size(i)
2746  enddo
2747  endif
2748 
2749  if ( present(natts) ) natts = dinfo%natts
2750  if ( present(att_name) ) then
2751  do i = 1, min( dinfo%natts, size(att_name) )
2752  att_name(i) = dinfo%att_name(i)
2753  end do
2754  end if
2755  if ( present(att_type) ) then
2756  do i = 1, min( dinfo%natts, size(att_type) )
2757  att_type(i) = dinfo%att_type(i)
2758  end do
2759  end if
2760  if ( present(att_len) ) then
2761  do i = 1, min( dinfo%natts, size(att_len) )
2762  att_len(i) = dinfo%att_len(i)
2763  end do
2764  end if
2765 
2766  if ( present(time_units) ) then
2767  if ( dinfo%time_units == "" ) then
2768  call file_get_attribute( fid, "global", "time_units", time_units )
2769  else
2770  time_units = dinfo%time_units
2771  endif
2772  endif
2773 
2774  if ( present(calendar) ) then
2775  if ( dinfo%time_units == "" ) then
2776  call file_get_attribute( fid, "global", "calendar", calendar, existed2 )
2777  if ( .not. existed2 ) calendar = ""
2778  else
2779  calendar = dinfo%calendar
2780  end if
2781  end if
2782 
2783  if ( present(time_start) ) then
2784  if ( dinfo%time_units == "" ) then
2785  call file_get_attribute( fid, "global", "time_start", time )
2786  time_start = time(1)
2787  else
2788  time_start = dinfo%time_start
2789  endif
2790  endif
2791 
2792  if ( present(time_end) ) then
2793  if ( dinfo%time_units == "" ) then
2794  call file_get_attribute( fid, "global", "time_start", time )
2795  time_end = time(1)
2796  else
2797  time_end = dinfo%time_end
2798  end if
2799  endif
2800 
2801  return
2802  end subroutine file_get_datainfo_fid
2803 
2804  !-----------------------------------------------------------------------------
2805  ! FILE_get_data_all_dataInfo
2806  !-----------------------------------------------------------------------------
2807  subroutine file_get_all_datainfo_fname( &
2808  basename, varname, &
2809  step_nmax, &
2810  description, units, standard_name, &
2811  datatype, &
2812  dim_rank, dim_name, dim_size, &
2813  natts, att_name, att_type, att_len, &
2814  time_start, time_end, &
2815  time_units, calendar, &
2816  rankid, single )
2817  implicit none
2818  character(len=*), intent(in) :: basename
2819  character(len=*), intent(in) :: varname
2820  integer, intent(out) :: step_nmax
2821  character(len=FILE_HMID), intent(out) :: description
2822  character(len=FILE_HSHORT), intent(out) :: units
2823  character(len=FILE_HMID), intent(out) :: standard_name
2824  integer, intent(out) :: datatype
2825  integer, intent(out) :: dim_rank
2826  character(len=FILE_HSHORT), intent(out) :: dim_name (:)
2827  integer, intent(out) :: dim_size (:)
2828  integer, intent(out) :: natts
2829  character(len=FILE_HSHORT), intent(out) :: att_name (:)
2830  integer, intent(out) :: att_type (:)
2831  integer, intent(out) :: att_len (:)
2832  real(dp), intent(out) :: time_start(:)
2833  real(dp), intent(out) :: time_end (:)
2834  character(len=FILE_HMID), intent(out) :: time_units
2835  character(len=FILE_HSHORT), intent(out) :: calendar
2836 
2837  integer, intent(in), optional :: rankid
2838  logical, intent(in), optional :: single
2839 
2840  integer :: fid
2841  logical :: single_
2842  !---------------------------------------------------------------------------
2843 
2844  if ( present(single) ) then
2845  single_ = single
2846  else
2847  single_ = .false.
2848  endif
2849 
2850  !--- search/register file
2851  call file_open( basename, & ! [IN]
2852  fid, & ! [OUT]
2853  rankid=rankid, single=single_ ) ! [IN]
2854 
2855  call file_get_all_datainfo_fid( fid, varname, & ! [IN]
2856  step_nmax, & ! [OUT]
2857  description, units, standard_name, & ! [OUT]
2858  datatype, & ! [OUT]
2859  dim_rank, dim_name(:), dim_size(:), & ! [OUT]
2860  natts, att_name(:), att_type(:), att_len(:), & ! [OUT]
2861  time_start(:), time_end(:), & ! [OUT]
2862  time_units, calendar ) ! [OUT]
2863 
2864  return
2865  end subroutine file_get_all_datainfo_fname
2866 
2867  subroutine file_get_all_datainfo_fid( &
2868  fid, varname, &
2869  step_nmax, &
2870  description, units, standard_name, &
2871  datatype, &
2872  dim_rank, dim_name, dim_size, &
2873  natts, att_name, att_type, att_len, &
2874  time_start, time_end, &
2875  time_units, calendar )
2876  implicit none
2877 
2878  integer, intent(in) :: fid
2879  character(len=*), intent(in) :: varname
2880  integer, intent(out) :: step_nmax
2881  character(len=FILE_HMID), intent(out) :: description
2882  character(len=FILE_HSHORT), intent(out) :: units
2883  character(len=FILE_HMID), intent(out) :: standard_name
2884  integer, intent(out) :: datatype
2885  integer, intent(out) :: dim_rank
2886  character(len=FILE_HSHORT), intent(out) :: dim_name (:)
2887  integer, intent(out) :: dim_size (:)
2888  integer, intent(out) :: natts
2889  character(len=FILE_HSHORT), intent(out) :: att_name (:)
2890  integer, intent(out) :: att_type (:)
2891  integer, intent(out) :: att_len (:)
2892  real(dp), intent(out) :: time_start(:)
2893  real(dp), intent(out) :: time_end (:)
2894  character(len=FILE_HMID), intent(out) :: time_units
2895  character(len=FILE_HSHORT), intent(out) :: calendar
2896 
2897  type(datainfo) :: dinfo
2898 
2899  real(dp) :: time(1)
2900  integer :: i
2901  integer :: error
2902  logical :: existed
2903 
2904  integer :: istep
2905 
2906  intrinsic size
2907  !---------------------------------------------------------------------------
2908 
2909  if ( .not. file_opened(fid) ) then
2910  log_error("FILE_get_all_dataInfo_fid",*) 'File is not opened. fid = ', fid
2911  call prc_abort
2912  end if
2913 
2914  ! initialize
2915  description = ""
2916  units = ""
2917  standard_name = ""
2918  datatype = -1
2919  dim_rank = -1
2920  dim_name(:) = ""
2921  dim_size(:) = -1
2922  time_start(:) = file_rmiss
2923  time_end(:) = file_rmiss
2924 
2925  do istep = 1, min( size(time_start), size(time_end) )
2926  !--- get data information
2927  call file_get_datainfo_c( dinfo, & ! [OUT]
2928  file_files(fid)%fid, & ! [IN]
2929  varname, & ! [IN]
2930  istep, & ! [IN]
2931  .true., & ! [IN]
2932  error ) ! [OUT]
2933 
2934  !--- verify and exit
2935  if ( error /= file_success_code ) then
2936  step_nmax = istep - 1
2937  exit
2938  endif
2939 
2940  if ( istep == 1 ) then
2941  description = dinfo%description
2942  units = dinfo%units
2943  standard_name = dinfo%standard_name
2944  datatype = dinfo%datatype
2945  dim_rank = dinfo%rank
2946  natts = dinfo%natts
2947 
2948  do i = 1, min( dinfo%rank, size(dim_name) ) ! limit dimension rank
2949  dim_name(i) = dinfo%dim_name(i)
2950  dim_size(i) = dinfo%dim_size(i)
2951  enddo
2952 
2953  do i = 1, min( dinfo%natts, size(att_name) )
2954  att_name(i) = dinfo%att_name(i)
2955  att_type(i) = dinfo%att_type(i)
2956  att_len(i) = dinfo%att_len (i)
2957  end do
2958 
2959  if ( dinfo%time_units == "" ) then
2960  call file_get_attribute( fid, "global", "time_units", time_units )
2961  call file_get_attribute( fid, "global", "calendar", calendar, existed )
2962  if ( .not. existed ) calendar = ""
2963  call file_get_attribute( fid, "global", "time_start", time )
2964  time_start(1) = time(1)
2965  time_end(1) = time(1)
2966  step_nmax = 1
2967  exit
2968  else
2969  time_units = dinfo%time_units
2970  calendar = dinfo%calendar
2971  time_start(1) = dinfo%time_start
2972  time_end(1) = dinfo%time_end
2973  endif
2974  else
2975  time_start(istep) = dinfo%time_start
2976  time_end(istep) = dinfo%time_end
2977  endif
2978  enddo
2979 
2980  return
2981  end subroutine file_get_all_datainfo_fid
2982 
2983  !-----------------------------------------------------------------------------
2984  ! interface FILE_read
2985  !-----------------------------------------------------------------------------
2986  subroutine file_read_realsp_1d( &
2987  basename, varname, &
2988  var, &
2989  step, rankid, single, postfix, &
2990  allow_missing, missing_value )
2991  implicit none
2992 
2993  character(len=*), intent( in) :: basename
2994  character(len=*), intent( in) :: varname
2995  real(sp), intent(out) :: var(:)
2996  integer, intent( in), optional :: step
2997  integer, intent( in), optional :: rankid
2998  logical, intent( in), optional :: single
2999  character(len=*), intent( in), optional :: postfix
3000  logical, intent( in), optional :: allow_missing
3001  real(sp), intent( in), optional :: missing_value
3002 
3003  integer :: fid
3004 
3005  intrinsic shape
3006  !---------------------------------------------------------------------------
3007 
3008  !--- search/register file
3009  call file_open( basename, & ! (in)
3010  fid, & ! (out)
3011  rankid=rankid, single=single, & ! (in)
3012  postfix=postfix ) ! (in)
3013 
3014  call file_read_var_realsp_1d( &
3015  fid, varname, & ! (in)
3016  var(:), & ! (out)
3017  step=step, & ! (in)
3018  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3019 
3020  return
3021  end subroutine file_read_realsp_1d
3022  subroutine file_read_realdp_1d( &
3023  basename, varname, &
3024  var, &
3025  step, rankid, single, postfix, &
3026  allow_missing, missing_value )
3027  implicit none
3028 
3029  character(len=*), intent( in) :: basename
3030  character(len=*), intent( in) :: varname
3031  real(dp), intent(out) :: var(:)
3032  integer, intent( in), optional :: step
3033  integer, intent( in), optional :: rankid
3034  logical, intent( in), optional :: single
3035  character(len=*), intent( in), optional :: postfix
3036  logical, intent( in), optional :: allow_missing
3037  real(dp), intent( in), optional :: missing_value
3038 
3039  integer :: fid
3040 
3041  intrinsic shape
3042  !---------------------------------------------------------------------------
3043 
3044  !--- search/register file
3045  call file_open( basename, & ! (in)
3046  fid, & ! (out)
3047  rankid=rankid, single=single, & ! (in)
3048  postfix=postfix ) ! (in)
3049 
3050  call file_read_var_realdp_1d( &
3051  fid, varname, & ! (in)
3052  var(:), & ! (out)
3053  step=step, & ! (in)
3054  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3055 
3056  return
3057  end subroutine file_read_realdp_1d
3058  subroutine file_read_realsp_2d( &
3059  basename, varname, &
3060  var, &
3061  step, rankid, single, postfix, &
3062  allow_missing, missing_value )
3063  implicit none
3064 
3065  character(len=*), intent( in) :: basename
3066  character(len=*), intent( in) :: varname
3067  real(sp), intent(out) :: var(:,:)
3068  integer, intent( in), optional :: step
3069  integer, intent( in), optional :: rankid
3070  logical, intent( in), optional :: single
3071  character(len=*), intent( in), optional :: postfix
3072  logical, intent( in), optional :: allow_missing
3073  real(sp), intent( in), optional :: missing_value
3074 
3075  integer :: fid
3076 
3077  intrinsic shape
3078  !---------------------------------------------------------------------------
3079 
3080  !--- search/register file
3081  call file_open( basename, & ! (in)
3082  fid, & ! (out)
3083  rankid=rankid, single=single, & ! (in)
3084  postfix=postfix ) ! (in)
3085 
3086  call file_read_var_realsp_2d( &
3087  fid, varname, & ! (in)
3088  var(:,:), & ! (out)
3089  step=step, & ! (in)
3090  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3091 
3092  return
3093  end subroutine file_read_realsp_2d
3094  subroutine file_read_realdp_2d( &
3095  basename, varname, &
3096  var, &
3097  step, rankid, single, postfix, &
3098  allow_missing, missing_value )
3099  implicit none
3100 
3101  character(len=*), intent( in) :: basename
3102  character(len=*), intent( in) :: varname
3103  real(dp), intent(out) :: var(:,:)
3104  integer, intent( in), optional :: step
3105  integer, intent( in), optional :: rankid
3106  logical, intent( in), optional :: single
3107  character(len=*), intent( in), optional :: postfix
3108  logical, intent( in), optional :: allow_missing
3109  real(dp), intent( in), optional :: missing_value
3110 
3111  integer :: fid
3112 
3113  intrinsic shape
3114  !---------------------------------------------------------------------------
3115 
3116  !--- search/register file
3117  call file_open( basename, & ! (in)
3118  fid, & ! (out)
3119  rankid=rankid, single=single, & ! (in)
3120  postfix=postfix ) ! (in)
3121 
3122  call file_read_var_realdp_2d( &
3123  fid, varname, & ! (in)
3124  var(:,:), & ! (out)
3125  step=step, & ! (in)
3126  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3127 
3128  return
3129  end subroutine file_read_realdp_2d
3130  subroutine file_read_realsp_3d( &
3131  basename, varname, &
3132  var, &
3133  step, rankid, single, postfix, &
3134  allow_missing, missing_value )
3135  implicit none
3136 
3137  character(len=*), intent( in) :: basename
3138  character(len=*), intent( in) :: varname
3139  real(sp), intent(out) :: var(:,:,:)
3140  integer, intent( in), optional :: step
3141  integer, intent( in), optional :: rankid
3142  logical, intent( in), optional :: single
3143  character(len=*), intent( in), optional :: postfix
3144  logical, intent( in), optional :: allow_missing
3145  real(sp), intent( in), optional :: missing_value
3146 
3147  integer :: fid
3148 
3149  intrinsic shape
3150  !---------------------------------------------------------------------------
3151 
3152  !--- search/register file
3153  call file_open( basename, & ! (in)
3154  fid, & ! (out)
3155  rankid=rankid, single=single, & ! (in)
3156  postfix=postfix ) ! (in)
3157 
3158  call file_read_var_realsp_3d( &
3159  fid, varname, & ! (in)
3160  var(:,:,:), & ! (out)
3161  step=step, & ! (in)
3162  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3163 
3164  return
3165  end subroutine file_read_realsp_3d
3166  subroutine file_read_realdp_3d( &
3167  basename, varname, &
3168  var, &
3169  step, rankid, single, postfix, &
3170  allow_missing, missing_value )
3171  implicit none
3172 
3173  character(len=*), intent( in) :: basename
3174  character(len=*), intent( in) :: varname
3175  real(dp), intent(out) :: var(:,:,:)
3176  integer, intent( in), optional :: step
3177  integer, intent( in), optional :: rankid
3178  logical, intent( in), optional :: single
3179  character(len=*), intent( in), optional :: postfix
3180  logical, intent( in), optional :: allow_missing
3181  real(dp), intent( in), optional :: missing_value
3182 
3183  integer :: fid
3184 
3185  intrinsic shape
3186  !---------------------------------------------------------------------------
3187 
3188  !--- search/register file
3189  call file_open( basename, & ! (in)
3190  fid, & ! (out)
3191  rankid=rankid, single=single, & ! (in)
3192  postfix=postfix ) ! (in)
3193 
3194  call file_read_var_realdp_3d( &
3195  fid, varname, & ! (in)
3196  var(:,:,:), & ! (out)
3197  step=step, & ! (in)
3198  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3199 
3200  return
3201  end subroutine file_read_realdp_3d
3202  subroutine file_read_realsp_4d( &
3203  basename, varname, &
3204  var, &
3205  step, rankid, single, postfix, &
3206  allow_missing, missing_value )
3207  implicit none
3208 
3209  character(len=*), intent( in) :: basename
3210  character(len=*), intent( in) :: varname
3211  real(sp), intent(out) :: var(:,:,:,:)
3212  integer, intent( in), optional :: step
3213  integer, intent( in), optional :: rankid
3214  logical, intent( in), optional :: single
3215  character(len=*), intent( in), optional :: postfix
3216  logical, intent( in), optional :: allow_missing
3217  real(sp), intent( in), optional :: missing_value
3218 
3219  integer :: fid
3220 
3221  intrinsic shape
3222  !---------------------------------------------------------------------------
3223 
3224  !--- search/register file
3225  call file_open( basename, & ! (in)
3226  fid, & ! (out)
3227  rankid=rankid, single=single, & ! (in)
3228  postfix=postfix ) ! (in)
3229 
3230  call file_read_var_realsp_4d( &
3231  fid, varname, & ! (in)
3232  var(:,:,:,:), & ! (out)
3233  step=step, & ! (in)
3234  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3235 
3236  return
3237  end subroutine file_read_realsp_4d
3238  subroutine file_read_realdp_4d( &
3239  basename, varname, &
3240  var, &
3241  step, rankid, single, postfix, &
3242  allow_missing, missing_value )
3243  implicit none
3244 
3245  character(len=*), intent( in) :: basename
3246  character(len=*), intent( in) :: varname
3247  real(dp), intent(out) :: var(:,:,:,:)
3248  integer, intent( in), optional :: step
3249  integer, intent( in), optional :: rankid
3250  logical, intent( in), optional :: single
3251  character(len=*), intent( in), optional :: postfix
3252  logical, intent( in), optional :: allow_missing
3253  real(dp), intent( in), optional :: missing_value
3254 
3255  integer :: fid
3256 
3257  intrinsic shape
3258  !---------------------------------------------------------------------------
3259 
3260  !--- search/register file
3261  call file_open( basename, & ! (in)
3262  fid, & ! (out)
3263  rankid=rankid, single=single, & ! (in)
3264  postfix=postfix ) ! (in)
3265 
3266  call file_read_var_realdp_4d( &
3267  fid, varname, & ! (in)
3268  var(:,:,:,:), & ! (out)
3269  step=step, & ! (in)
3270  allow_missing=allow_missing, missing_value=missing_value ) ! (in)
3271 
3272  return
3273  end subroutine file_read_realdp_4d
3274 
3275  subroutine file_read_var_realsp_1d( &
3276  fid, varname, &
3277  var, &
3278  step, &
3279  allow_missing, &
3280  missing_value, &
3281  ntypes, dtype, &
3282  start, count )
3283  implicit none
3284 
3285  integer, intent( in) :: fid
3286  character(len=*), intent( in) :: varname
3287  real(sp), intent(out) :: var(:)
3288  integer, intent( in), optional :: step
3289  logical, intent( in), optional :: allow_missing
3290  real(sp), intent( in), optional :: missing_value
3291  integer, intent( in), optional :: ntypes
3292  integer, intent( in), optional :: dtype
3293  integer, intent( in), optional :: start(:)
3294  integer, intent( in), optional :: count(:)
3295 
3296  integer :: step_
3297  logical :: allow_missing_
3298  real(sp) :: missing_value_
3299 
3300  type(datainfo) :: dinfo
3301  integer :: dim_size(1)
3302  integer :: error
3303  integer :: n
3304 
3305  intrinsic size, shape
3306  !---------------------------------------------------------------------------
3307 
3308  if ( .not. file_opened(fid) ) then
3309  log_error("FILE_",*) 'File is not opened. fid = ', fid
3310  call prc_abort
3311  end if
3312 
3313  if ( present(step) ) then
3314  step_ = step
3315  else
3316  step_ = 1
3317  end if
3318 
3319  if ( present(allow_missing) ) then
3320  allow_missing_ = allow_missing
3321  else
3322  allow_missing_ = .false.
3323  end if
3324 
3325  if ( present(missing_value) ) then
3326  missing_value_ = missing_value
3327  else
3328  missing_value_ = 0.0_sp
3329  end if
3330 
3331  !--- get data information
3332  call file_get_datainfo_c( dinfo, & ! (out)
3333  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3334  error ) ! (out)
3335 
3336  !--- verify
3337  if ( error /= file_success_code ) then
3338  if ( allow_missing_ ) then
3339  log_info("FILE_read_var_realSP_1D",*) '[INPUT]/[FILE] data not found! : ', &
3340  'varname= ',trim(varname),', step=',step_
3341  log_info("FILE_read_var_realSP_1D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3342  var(:) = missing_value_
3343  return
3344  else
3345  log_error("FILE_read_var_realSP_1D",*) 'failed to get data information :'//trim(varname)
3346  call prc_abort
3347  end if
3348  end if
3349 
3350  if ( dinfo%rank /= 1 ) then
3351  if ( (.not. present(start)) .and. (.not. present(count)) ) then
3352  log_error("FILE_read_var_realSP_1D",*) 'rank of '//trim(varname)//' is not 1', dinfo%rank
3353  call prc_abort
3354  end if
3355  end if
3356 
3357  if ( present(ntypes) ) then
3358  call file_read_data_c( var(:), & ! (out)
3359  dinfo, sp, ntypes, dtype, start(:), count(:), & ! (in)
3360  error ) ! (out)
3361  else if ( present(start) .and. present(count) ) then
3362  call file_read_data_c( var(:), & ! (out)
3363  dinfo, sp, 0, 0, start(:), count(:), & ! (in)
3364  error ) ! (out)
3365  else
3366  dim_size(:) = shape(var)
3367  do n = 1, 1
3368  if ( dinfo%dim_size(n) /= dim_size(n) ) then
3369  log_error("FILE_read_var_realSP_1D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
3370  call prc_abort
3371  end if
3372  end do
3373  call file_read_data_c( var(:), & ! (out)
3374  dinfo, sp, 0, 0, -1, -1, & ! (in)
3375  error ) ! (out)
3376  end if
3377  if ( error /= file_success_code ) then
3378  log_error("FILE_read_var_realSP_1D",*) 'failed to get data value: ', trim(varname)
3379  call prc_abort
3380  end if
3381 
3382  return
3383  end subroutine file_read_var_realsp_1d
3384  subroutine file_read_var_realdp_1d( &
3385  fid, varname, &
3386  var, &
3387  step, &
3388  allow_missing, &
3389  missing_value, &
3390  ntypes, dtype, &
3391  start, count )
3392  implicit none
3393 
3394  integer, intent( in) :: fid
3395  character(len=*), intent( in) :: varname
3396  real(dp), intent(out) :: var(:)
3397  integer, intent( in), optional :: step
3398  logical, intent( in), optional :: allow_missing
3399  real(dp), intent( in), optional :: missing_value
3400  integer, intent( in), optional :: ntypes
3401  integer, intent( in), optional :: dtype
3402  integer, intent( in), optional :: start(:)
3403  integer, intent( in), optional :: count(:)
3404 
3405  integer :: step_
3406  logical :: allow_missing_
3407  real(dp) :: missing_value_
3408 
3409  type(datainfo) :: dinfo
3410  integer :: dim_size(1)
3411  integer :: error
3412  integer :: n
3413 
3414  intrinsic size, shape
3415  !---------------------------------------------------------------------------
3416 
3417  if ( .not. file_opened(fid) ) then
3418  log_error("FILE_",*) 'File is not opened. fid = ', fid
3419  call prc_abort
3420  end if
3421 
3422  if ( present(step) ) then
3423  step_ = step
3424  else
3425  step_ = 1
3426  end if
3427 
3428  if ( present(allow_missing) ) then
3429  allow_missing_ = allow_missing
3430  else
3431  allow_missing_ = .false.
3432  end if
3433 
3434  if ( present(missing_value) ) then
3435  missing_value_ = missing_value
3436  else
3437  missing_value_ = 0.0_dp
3438  end if
3439 
3440  !--- get data information
3441  call file_get_datainfo_c( dinfo, & ! (out)
3442  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3443  error ) ! (out)
3444 
3445  !--- verify
3446  if ( error /= file_success_code ) then
3447  if ( allow_missing_ ) then
3448  log_info("FILE_read_var_realDP_1D",*) '[INPUT]/[FILE] data not found! : ', &
3449  'varname= ',trim(varname),', step=',step_
3450  log_info("FILE_read_var_realDP_1D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3451  var(:) = missing_value_
3452  return
3453  else
3454  log_error("FILE_read_var_realDP_1D",*) 'failed to get data information :'//trim(varname)
3455  call prc_abort
3456  end if
3457  end if
3458 
3459  if ( dinfo%rank /= 1 ) then
3460  if ( (.not. present(start)) .and. (.not. present(count)) ) then
3461  log_error("FILE_read_var_realDP_1D",*) 'rank of '//trim(varname)//' is not 1', dinfo%rank
3462  call prc_abort
3463  end if
3464  end if
3465 
3466  if ( present(ntypes) ) then
3467  call file_read_data_c( var(:), & ! (out)
3468  dinfo, dp, ntypes, dtype, start(:), count(:), & ! (in)
3469  error ) ! (out)
3470  else if ( present(start) .and. present(count) ) then
3471  call file_read_data_c( var(:), & ! (out)
3472  dinfo, dp, 0, 0, start(:), count(:), & ! (in)
3473  error ) ! (out)
3474  else
3475  dim_size(:) = shape(var)
3476  do n = 1, 1
3477  if ( dinfo%dim_size(n) /= dim_size(n) ) then
3478  log_error("FILE_read_var_realDP_1D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
3479  call prc_abort
3480  end if
3481  end do
3482  call file_read_data_c( var(:), & ! (out)
3483  dinfo, dp, 0, 0, -1, -1, & ! (in)
3484  error ) ! (out)
3485  end if
3486  if ( error /= file_success_code ) then
3487  log_error("FILE_read_var_realDP_1D",*) 'failed to get data value: ', trim(varname)
3488  call prc_abort
3489  end if
3490 
3491  return
3492  end subroutine file_read_var_realdp_1d
3493  subroutine file_read_var_realsp_2d( &
3494  fid, varname, &
3495  var, &
3496  step, &
3497  allow_missing, &
3498  missing_value, &
3499  ntypes, dtype, &
3500  start, count )
3501  implicit none
3502 
3503  integer, intent( in) :: fid
3504  character(len=*), intent( in) :: varname
3505  real(sp), intent(out) :: var(:,:)
3506  integer, intent( in), optional :: step
3507  logical, intent( in), optional :: allow_missing
3508  real(sp), intent( in), optional :: missing_value
3509  integer, intent( in), optional :: ntypes
3510  integer, intent( in), optional :: dtype
3511  integer, intent( in), optional :: start(:)
3512  integer, intent( in), optional :: count(:)
3513 
3514  integer :: step_
3515  logical :: allow_missing_
3516  real(sp) :: missing_value_
3517 
3518  type(datainfo) :: dinfo
3519  integer :: dim_size(2)
3520  integer :: error
3521  integer :: n
3522 
3523  intrinsic size, shape
3524  !---------------------------------------------------------------------------
3525 
3526  if ( .not. file_opened(fid) ) then
3527  log_error("FILE_",*) 'File is not opened. fid = ', fid
3528  call prc_abort
3529  end if
3530 
3531  if ( present(step) ) then
3532  step_ = step
3533  else
3534  step_ = 1
3535  end if
3536 
3537  if ( present(allow_missing) ) then
3538  allow_missing_ = allow_missing
3539  else
3540  allow_missing_ = .false.
3541  end if
3542 
3543  if ( present(missing_value) ) then
3544  missing_value_ = missing_value
3545  else
3546  missing_value_ = 0.0_sp
3547  end if
3548 
3549  !--- get data information
3550  call file_get_datainfo_c( dinfo, & ! (out)
3551  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3552  error ) ! (out)
3553 
3554  !--- verify
3555  if ( error /= file_success_code ) then
3556  if ( allow_missing_ ) then
3557  log_info("FILE_read_var_realSP_2D",*) '[INPUT]/[FILE] data not found! : ', &
3558  'varname= ',trim(varname),', step=',step_
3559  log_info("FILE_read_var_realSP_2D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3560  var(:,:) = missing_value_
3561  return
3562  else
3563  log_error("FILE_read_var_realSP_2D",*) 'failed to get data information :'//trim(varname)
3564  call prc_abort
3565  end if
3566  end if
3567 
3568  if ( dinfo%rank /= 2 ) then
3569  if ( (.not. present(start)) .and. (.not. present(count)) ) then
3570  log_error("FILE_read_var_realSP_2D",*) 'rank of '//trim(varname)//' is not 2', dinfo%rank
3571  call prc_abort
3572  end if
3573  end if
3574 
3575  if ( present(ntypes) ) then
3576  call file_read_data_c( var(:,:), & ! (out)
3577  dinfo, sp, ntypes, dtype, start(:), count(:), & ! (in)
3578  error ) ! (out)
3579  else if ( present(start) .and. present(count) ) then
3580  call file_read_data_c( var(:,:), & ! (out)
3581  dinfo, sp, 0, 0, start(:), count(:), & ! (in)
3582  error ) ! (out)
3583  else
3584  dim_size(:) = shape(var)
3585  do n = 1, 2
3586  if ( dinfo%dim_size(n) /= dim_size(n) ) then
3587  log_error("FILE_read_var_realSP_2D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
3588  call prc_abort
3589  end if
3590  end do
3591  call file_read_data_c( var(:,:), & ! (out)
3592  dinfo, sp, 0, 0, -1, -1, & ! (in)
3593  error ) ! (out)
3594  end if
3595  if ( error /= file_success_code ) then
3596  log_error("FILE_read_var_realSP_2D",*) 'failed to get data value: ', trim(varname)
3597  call prc_abort
3598  end if
3599 
3600  return
3601  end subroutine file_read_var_realsp_2d
3602  subroutine file_read_var_realdp_2d( &
3603  fid, varname, &
3604  var, &
3605  step, &
3606  allow_missing, &
3607  missing_value, &
3608  ntypes, dtype, &
3609  start, count )
3610  implicit none
3611 
3612  integer, intent( in) :: fid
3613  character(len=*), intent( in) :: varname
3614  real(dp), intent(out) :: var(:,:)
3615  integer, intent( in), optional :: step
3616  logical, intent( in), optional :: allow_missing
3617  real(dp), intent( in), optional :: missing_value
3618  integer, intent( in), optional :: ntypes
3619  integer, intent( in), optional :: dtype
3620  integer, intent( in), optional :: start(:)
3621  integer, intent( in), optional :: count(:)
3622 
3623  integer :: step_
3624  logical :: allow_missing_
3625  real(dp) :: missing_value_
3626 
3627  type(datainfo) :: dinfo
3628  integer :: dim_size(2)
3629  integer :: error
3630  integer :: n
3631 
3632  intrinsic size, shape
3633  !---------------------------------------------------------------------------
3634 
3635  if ( .not. file_opened(fid) ) then
3636  log_error("FILE_",*) 'File is not opened. fid = ', fid
3637  call prc_abort
3638  end if
3639 
3640  if ( present(step) ) then
3641  step_ = step
3642  else
3643  step_ = 1
3644  end if
3645 
3646  if ( present(allow_missing) ) then
3647  allow_missing_ = allow_missing
3648  else
3649  allow_missing_ = .false.
3650  end if
3651 
3652  if ( present(missing_value) ) then
3653  missing_value_ = missing_value
3654  else
3655  missing_value_ = 0.0_dp
3656  end if
3657 
3658  !--- get data information
3659  call file_get_datainfo_c( dinfo, & ! (out)
3660  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3661  error ) ! (out)
3662 
3663  !--- verify
3664  if ( error /= file_success_code ) then
3665  if ( allow_missing_ ) then
3666  log_info("FILE_read_var_realDP_2D",*) '[INPUT]/[FILE] data not found! : ', &
3667  'varname= ',trim(varname),', step=',step_
3668  log_info("FILE_read_var_realDP_2D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3669  var(:,:) = missing_value_
3670  return
3671  else
3672  log_error("FILE_read_var_realDP_2D",*) 'failed to get data information :'//trim(varname)
3673  call prc_abort
3674  end if
3675  end if
3676 
3677  if ( dinfo%rank /= 2 ) then
3678  if ( (.not. present(start)) .and. (.not. present(count)) ) then
3679  log_error("FILE_read_var_realDP_2D",*) 'rank of '//trim(varname)//' is not 2', dinfo%rank
3680  call prc_abort
3681  end if
3682  end if
3683 
3684  if ( present(ntypes) ) then
3685  call file_read_data_c( var(:,:), & ! (out)
3686  dinfo, dp, ntypes, dtype, start(:), count(:), & ! (in)
3687  error ) ! (out)
3688  else if ( present(start) .and. present(count) ) then
3689  call file_read_data_c( var(:,:), & ! (out)
3690  dinfo, dp, 0, 0, start(:), count(:), & ! (in)
3691  error ) ! (out)
3692  else
3693  dim_size(:) = shape(var)
3694  do n = 1, 2
3695  if ( dinfo%dim_size(n) /= dim_size(n) ) then
3696  log_error("FILE_read_var_realDP_2D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
3697  call prc_abort
3698  end if
3699  end do
3700  call file_read_data_c( var(:,:), & ! (out)
3701  dinfo, dp, 0, 0, -1, -1, & ! (in)
3702  error ) ! (out)
3703  end if
3704  if ( error /= file_success_code ) then
3705  log_error("FILE_read_var_realDP_2D",*) 'failed to get data value: ', trim(varname)
3706  call prc_abort
3707  end if
3708 
3709  return
3710  end subroutine file_read_var_realdp_2d
3711  subroutine file_read_var_realsp_3d( &
3712  fid, varname, &
3713  var, &
3714  step, &
3715  allow_missing, &
3716  missing_value, &
3717  ntypes, dtype, &
3718  start, count )
3719  implicit none
3720 
3721  integer, intent( in) :: fid
3722  character(len=*), intent( in) :: varname
3723  real(sp), intent(out) :: var(:,:,:)
3724  integer, intent( in), optional :: step
3725  logical, intent( in), optional :: allow_missing
3726  real(sp), intent( in), optional :: missing_value
3727  integer, intent( in), optional :: ntypes
3728  integer, intent( in), optional :: dtype
3729  integer, intent( in), optional :: start(:)
3730  integer, intent( in), optional :: count(:)
3731 
3732  integer :: step_
3733  logical :: allow_missing_
3734  real(sp) :: missing_value_
3735 
3736  type(datainfo) :: dinfo
3737  integer :: dim_size(3)
3738  integer :: error
3739  integer :: n
3740 
3741  intrinsic size, shape
3742  !---------------------------------------------------------------------------
3743 
3744  if ( .not. file_opened(fid) ) then
3745  log_error("FILE_",*) 'File is not opened. fid = ', fid
3746  call prc_abort
3747  end if
3748 
3749  if ( present(step) ) then
3750  step_ = step
3751  else
3752  step_ = 1
3753  end if
3754 
3755  if ( present(allow_missing) ) then
3756  allow_missing_ = allow_missing
3757  else
3758  allow_missing_ = .false.
3759  end if
3760 
3761  if ( present(missing_value) ) then
3762  missing_value_ = missing_value
3763  else
3764  missing_value_ = 0.0_sp
3765  end if
3766 
3767  !--- get data information
3768  call file_get_datainfo_c( dinfo, & ! (out)
3769  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3770  error ) ! (out)
3771 
3772  !--- verify
3773  if ( error /= file_success_code ) then
3774  if ( allow_missing_ ) then
3775  log_info("FILE_read_var_realSP_3D",*) '[INPUT]/[FILE] data not found! : ', &
3776  'varname= ',trim(varname),', step=',step_
3777  log_info("FILE_read_var_realSP_3D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3778  var(:,:,:) = missing_value_
3779  return
3780  else
3781  log_error("FILE_read_var_realSP_3D",*) 'failed to get data information :'//trim(varname)
3782  call prc_abort
3783  end if
3784  end if
3785 
3786  if ( dinfo%rank /= 3 ) then
3787  if ( (.not. present(start)) .and. (.not. present(count)) ) then
3788  log_error("FILE_read_var_realSP_3D",*) 'rank of '//trim(varname)//' is not 3', dinfo%rank
3789  call prc_abort
3790  end if
3791  end if
3792 
3793  if ( present(ntypes) ) then
3794  call file_read_data_c( var(:,:,:), & ! (out)
3795  dinfo, sp, ntypes, dtype, start(:), count(:), & ! (in)
3796  error ) ! (out)
3797  else if ( present(start) .and. present(count) ) then
3798  call file_read_data_c( var(:,:,:), & ! (out)
3799  dinfo, sp, 0, 0, start(:), count(:), & ! (in)
3800  error ) ! (out)
3801  else
3802  dim_size(:) = shape(var)
3803  do n = 1, 3
3804  if ( dinfo%dim_size(n) /= dim_size(n) ) then
3805  log_error("FILE_read_var_realSP_3D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
3806  call prc_abort
3807  end if
3808  end do
3809  call file_read_data_c( var(:,:,:), & ! (out)
3810  dinfo, sp, 0, 0, -1, -1, & ! (in)
3811  error ) ! (out)
3812  end if
3813  if ( error /= file_success_code ) then
3814  log_error("FILE_read_var_realSP_3D",*) 'failed to get data value: ', trim(varname)
3815  call prc_abort
3816  end if
3817 
3818  return
3819  end subroutine file_read_var_realsp_3d
3820  subroutine file_read_var_realdp_3d( &
3821  fid, varname, &
3822  var, &
3823  step, &
3824  allow_missing, &
3825  missing_value, &
3826  ntypes, dtype, &
3827  start, count )
3828  implicit none
3829 
3830  integer, intent( in) :: fid
3831  character(len=*), intent( in) :: varname
3832  real(dp), intent(out) :: var(:,:,:)
3833  integer, intent( in), optional :: step
3834  logical, intent( in), optional :: allow_missing
3835  real(dp), intent( in), optional :: missing_value
3836  integer, intent( in), optional :: ntypes
3837  integer, intent( in), optional :: dtype
3838  integer, intent( in), optional :: start(:)
3839  integer, intent( in), optional :: count(:)
3840 
3841  integer :: step_
3842  logical :: allow_missing_
3843  real(dp) :: missing_value_
3844 
3845  type(datainfo) :: dinfo
3846  integer :: dim_size(3)
3847  integer :: error
3848  integer :: n
3849 
3850  intrinsic size, shape
3851  !---------------------------------------------------------------------------
3852 
3853  if ( .not. file_opened(fid) ) then
3854  log_error("FILE_",*) 'File is not opened. fid = ', fid
3855  call prc_abort
3856  end if
3857 
3858  if ( present(step) ) then
3859  step_ = step
3860  else
3861  step_ = 1
3862  end if
3863 
3864  if ( present(allow_missing) ) then
3865  allow_missing_ = allow_missing
3866  else
3867  allow_missing_ = .false.
3868  end if
3869 
3870  if ( present(missing_value) ) then
3871  missing_value_ = missing_value
3872  else
3873  missing_value_ = 0.0_dp
3874  end if
3875 
3876  !--- get data information
3877  call file_get_datainfo_c( dinfo, & ! (out)
3878  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3879  error ) ! (out)
3880 
3881  !--- verify
3882  if ( error /= file_success_code ) then
3883  if ( allow_missing_ ) then
3884  log_info("FILE_read_var_realDP_3D",*) '[INPUT]/[FILE] data not found! : ', &
3885  'varname= ',trim(varname),', step=',step_
3886  log_info("FILE_read_var_realDP_3D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3887  var(:,:,:) = missing_value_
3888  return
3889  else
3890  log_error("FILE_read_var_realDP_3D",*) 'failed to get data information :'//trim(varname)
3891  call prc_abort
3892  end if
3893  end if
3894 
3895  if ( dinfo%rank /= 3 ) then
3896  if ( (.not. present(start)) .and. (.not. present(count)) ) then
3897  log_error("FILE_read_var_realDP_3D",*) 'rank of '//trim(varname)//' is not 3', dinfo%rank
3898  call prc_abort
3899  end if
3900  end if
3901 
3902  if ( present(ntypes) ) then
3903  call file_read_data_c( var(:,:,:), & ! (out)
3904  dinfo, dp, ntypes, dtype, start(:), count(:), & ! (in)
3905  error ) ! (out)
3906  else if ( present(start) .and. present(count) ) then
3907  call file_read_data_c( var(:,:,:), & ! (out)
3908  dinfo, dp, 0, 0, start(:), count(:), & ! (in)
3909  error ) ! (out)
3910  else
3911  dim_size(:) = shape(var)
3912  do n = 1, 3
3913  if ( dinfo%dim_size(n) /= dim_size(n) ) then
3914  log_error("FILE_read_var_realDP_3D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
3915  call prc_abort
3916  end if
3917  end do
3918  call file_read_data_c( var(:,:,:), & ! (out)
3919  dinfo, dp, 0, 0, -1, -1, & ! (in)
3920  error ) ! (out)
3921  end if
3922  if ( error /= file_success_code ) then
3923  log_error("FILE_read_var_realDP_3D",*) 'failed to get data value: ', trim(varname)
3924  call prc_abort
3925  end if
3926 
3927  return
3928  end subroutine file_read_var_realdp_3d
3929  subroutine file_read_var_realsp_4d( &
3930  fid, varname, &
3931  var, &
3932  step, &
3933  allow_missing, &
3934  missing_value, &
3935  ntypes, dtype, &
3936  start, count )
3937  implicit none
3938 
3939  integer, intent( in) :: fid
3940  character(len=*), intent( in) :: varname
3941  real(sp), intent(out) :: var(:,:,:,:)
3942  integer, intent( in), optional :: step
3943  logical, intent( in), optional :: allow_missing
3944  real(sp), intent( in), optional :: missing_value
3945  integer, intent( in), optional :: ntypes
3946  integer, intent( in), optional :: dtype
3947  integer, intent( in), optional :: start(:)
3948  integer, intent( in), optional :: count(:)
3949 
3950  integer :: step_
3951  logical :: allow_missing_
3952  real(sp) :: missing_value_
3953 
3954  type(datainfo) :: dinfo
3955  integer :: dim_size(4)
3956  integer :: error
3957  integer :: n
3958 
3959  intrinsic size, shape
3960  !---------------------------------------------------------------------------
3961 
3962  if ( .not. file_opened(fid) ) then
3963  log_error("FILE_",*) 'File is not opened. fid = ', fid
3964  call prc_abort
3965  end if
3966 
3967  if ( present(step) ) then
3968  step_ = step
3969  else
3970  step_ = 1
3971  end if
3972 
3973  if ( present(allow_missing) ) then
3974  allow_missing_ = allow_missing
3975  else
3976  allow_missing_ = .false.
3977  end if
3978 
3979  if ( present(missing_value) ) then
3980  missing_value_ = missing_value
3981  else
3982  missing_value_ = 0.0_sp
3983  end if
3984 
3985  !--- get data information
3986  call file_get_datainfo_c( dinfo, & ! (out)
3987  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
3988  error ) ! (out)
3989 
3990  !--- verify
3991  if ( error /= file_success_code ) then
3992  if ( allow_missing_ ) then
3993  log_info("FILE_read_var_realSP_4D",*) '[INPUT]/[FILE] data not found! : ', &
3994  'varname= ',trim(varname),', step=',step_
3995  log_info("FILE_read_var_realSP_4D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
3996  var(:,:,:,:) = missing_value_
3997  return
3998  else
3999  log_error("FILE_read_var_realSP_4D",*) 'failed to get data information :'//trim(varname)
4000  call prc_abort
4001  end if
4002  end if
4003 
4004  if ( dinfo%rank /= 4 ) then
4005  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4006  log_error("FILE_read_var_realSP_4D",*) 'rank of '//trim(varname)//' is not 4', dinfo%rank
4007  call prc_abort
4008  end if
4009  end if
4010 
4011  if ( present(ntypes) ) then
4012  call file_read_data_c( var(:,:,:,:), & ! (out)
4013  dinfo, sp, ntypes, dtype, start(:), count(:), & ! (in)
4014  error ) ! (out)
4015  else if ( present(start) .and. present(count) ) then
4016  call file_read_data_c( var(:,:,:,:), & ! (out)
4017  dinfo, sp, 0, 0, start(:), count(:), & ! (in)
4018  error ) ! (out)
4019  else
4020  dim_size(:) = shape(var)
4021  do n = 1, 4
4022  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4023  log_error("FILE_read_var_realSP_4D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4024  call prc_abort
4025  end if
4026  end do
4027  call file_read_data_c( var(:,:,:,:), & ! (out)
4028  dinfo, sp, 0, 0, -1, -1, & ! (in)
4029  error ) ! (out)
4030  end if
4031  if ( error /= file_success_code ) then
4032  log_error("FILE_read_var_realSP_4D",*) 'failed to get data value: ', trim(varname)
4033  call prc_abort
4034  end if
4035 
4036  return
4037  end subroutine file_read_var_realsp_4d
4038  subroutine file_read_var_realdp_4d( &
4039  fid, varname, &
4040  var, &
4041  step, &
4042  allow_missing, &
4043  missing_value, &
4044  ntypes, dtype, &
4045  start, count )
4046  implicit none
4047 
4048  integer, intent( in) :: fid
4049  character(len=*), intent( in) :: varname
4050  real(dp), intent(out) :: var(:,:,:,:)
4051  integer, intent( in), optional :: step
4052  logical, intent( in), optional :: allow_missing
4053  real(dp), intent( in), optional :: missing_value
4054  integer, intent( in), optional :: ntypes
4055  integer, intent( in), optional :: dtype
4056  integer, intent( in), optional :: start(:)
4057  integer, intent( in), optional :: count(:)
4058 
4059  integer :: step_
4060  logical :: allow_missing_
4061  real(dp) :: missing_value_
4062 
4063  type(datainfo) :: dinfo
4064  integer :: dim_size(4)
4065  integer :: error
4066  integer :: n
4067 
4068  intrinsic size, shape
4069  !---------------------------------------------------------------------------
4070 
4071  if ( .not. file_opened(fid) ) then
4072  log_error("FILE_",*) 'File is not opened. fid = ', fid
4073  call prc_abort
4074  end if
4075 
4076  if ( present(step) ) then
4077  step_ = step
4078  else
4079  step_ = 1
4080  end if
4081 
4082  if ( present(allow_missing) ) then
4083  allow_missing_ = allow_missing
4084  else
4085  allow_missing_ = .false.
4086  end if
4087 
4088  if ( present(missing_value) ) then
4089  missing_value_ = missing_value
4090  else
4091  missing_value_ = 0.0_dp
4092  end if
4093 
4094  !--- get data information
4095  call file_get_datainfo_c( dinfo, & ! (out)
4096  file_files(fid)%fid, varname, step_, allow_missing_, & ! (in)
4097  error ) ! (out)
4098 
4099  !--- verify
4100  if ( error /= file_success_code ) then
4101  if ( allow_missing_ ) then
4102  log_info("FILE_read_var_realDP_4D",*) '[INPUT]/[FILE] data not found! : ', &
4103  'varname= ',trim(varname),', step=',step_
4104  log_info("FILE_read_var_realDP_4D",*) '[INPUT]/[FILE] Value is set to ', missing_value_
4105  var(:,:,:,:) = missing_value_
4106  return
4107  else
4108  log_error("FILE_read_var_realDP_4D",*) 'failed to get data information :'//trim(varname)
4109  call prc_abort
4110  end if
4111  end if
4112 
4113  if ( dinfo%rank /= 4 ) then
4114  if ( (.not. present(start)) .and. (.not. present(count)) ) then
4115  log_error("FILE_read_var_realDP_4D",*) 'rank of '//trim(varname)//' is not 4', dinfo%rank
4116  call prc_abort
4117  end if
4118  end if
4119 
4120  if ( present(ntypes) ) then
4121  call file_read_data_c( var(:,:,:,:), & ! (out)
4122  dinfo, dp, ntypes, dtype, start(:), count(:), & ! (in)
4123  error ) ! (out)
4124  else if ( present(start) .and. present(count) ) then
4125  call file_read_data_c( var(:,:,:,:), & ! (out)
4126  dinfo, dp, 0, 0, start(:), count(:), & ! (in)
4127  error ) ! (out)
4128  else
4129  dim_size(:) = shape(var)
4130  do n = 1, 4
4131  if ( dinfo%dim_size(n) /= dim_size(n) ) then
4132  log_error("FILE_read_var_realDP_4D",*) 'shape is different: ', trim(varname), n, dinfo%dim_size(n), dim_size(n)
4133  call prc_abort
4134  end if
4135  end do
4136  call file_read_data_c( var(:,:,:,:), & ! (out)
4137  dinfo, dp, 0, 0, -1, -1, & ! (in)
4138  error ) ! (out)
4139  end if
4140  if ( error /= file_success_code ) then
4141  log_error("FILE_read_var_realDP_4D",*) 'failed to get data value: ', trim(varname)
4142  call prc_abort
4143  end if
4144 
4145  return
4146  end subroutine file_read_var_realdp_4d
4147 
4148  !-----------------------------------------------------------------------------
4149  ! interface FILE_write
4150  !-----------------------------------------------------------------------------
4151  subroutine file_write_realsp_1d( &
4152  vid, var, &
4153  t_start, t_end, &
4154  ndims, &
4155  count, &
4156  start )
4157  implicit none
4158 
4159  integer, intent(in) :: vid
4160  real(sp), intent(in) :: var(:)
4161  real(dp), intent(in) :: t_start
4162  real(dp), intent(in) :: t_end
4163  integer, intent(in), optional :: ndims ! when var has been reshaped to 1D
4164  integer, intent(in), optional :: count(:)
4165  integer, intent(in), optional :: start(:)
4166  real(dp) :: ts, te
4167 
4168  integer :: start_(1)
4169 
4170  integer :: fid
4171  integer :: error
4172 
4173  intrinsic shape
4174  !---------------------------------------------------------------------------
4175 
4176  ts = t_start
4177  te = t_end
4178 
4179  fid = file_vars(vid)%fid
4180 
4181  if ( .not. file_opened(fid) ) then
4182  log_error("FILE_write_realSP_1D",*) 'File is not opened. fid = ', fid
4183  call prc_abort
4184  end if
4185 
4186  if ( present(ndims) ) then
4187  ! history variable has been reshaped to 1D
4188  ! In this case, start and count must be present
4189 
4190  if ( .not. present(start) ) then
4191  log_error("FILE_write_realSP_1D",*) 'start argument is neccessary when ndims is specified'
4192  call prc_abort
4193  end if
4194  if ( .not. present(count) ) then
4195  log_error("FILE_write_realSP_1D",*) 'count argument is neccessary when ndims is specified'
4196  call prc_abort
4197  end if
4198 
4199  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4200  var(:), ts, te, sp, & ! (in)
4201  ndims, start, count, & ! (in)
4202  error ) ! (out)
4203  else
4204  ! this is for restart variable which keeps its original shape
4205  if ( present(start) ) then
4206  start_(:) = start(:)
4207  else
4208  start_(:) = 1
4209  end if
4210  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4211  var(:), ts, te, sp, & ! (in)
4212  1, start_, shape(var), & ! (in)
4213  error ) ! (out)
4214  end if
4215  if ( error /= file_success_code ) then
4216  log_error("FILE_write_realSP_1D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4217  call prc_abort
4218  end if
4219 
4220  return
4221  end subroutine file_write_realsp_1d
4222  subroutine file_write_realdp_1d( &
4223  vid, var, &
4224  t_start, t_end, &
4225  ndims, &
4226  count, &
4227  start )
4228  implicit none
4229 
4230  integer, intent(in) :: vid
4231  real(dp), intent(in) :: var(:)
4232  real(dp), intent(in) :: t_start
4233  real(dp), intent(in) :: t_end
4234  integer, intent(in), optional :: ndims ! when var has been reshaped to 1D
4235  integer, intent(in), optional :: count(:)
4236  integer, intent(in), optional :: start(:)
4237  real(dp) :: ts, te
4238 
4239  integer :: start_(1)
4240 
4241  integer :: fid
4242  integer :: error
4243 
4244  intrinsic shape
4245  !---------------------------------------------------------------------------
4246 
4247  ts = t_start
4248  te = t_end
4249 
4250  fid = file_vars(vid)%fid
4251 
4252  if ( .not. file_opened(fid) ) then
4253  log_error("FILE_write_realDP_1D",*) 'File is not opened. fid = ', fid
4254  call prc_abort
4255  end if
4256 
4257  if ( present(ndims) ) then
4258  ! history variable has been reshaped to 1D
4259  ! In this case, start and count must be present
4260 
4261  if ( .not. present(start) ) then
4262  log_error("FILE_write_realDP_1D",*) 'start argument is neccessary when ndims is specified'
4263  call prc_abort
4264  end if
4265  if ( .not. present(count) ) then
4266  log_error("FILE_write_realDP_1D",*) 'count argument is neccessary when ndims is specified'
4267  call prc_abort
4268  end if
4269 
4270  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4271  var(:), ts, te, dp, & ! (in)
4272  ndims, start, count, & ! (in)
4273  error ) ! (out)
4274  else
4275  ! this is for restart variable which keeps its original shape
4276  if ( present(start) ) then
4277  start_(:) = start(:)
4278  else
4279  start_(:) = 1
4280  end if
4281  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4282  var(:), ts, te, dp, & ! (in)
4283  1, start_, shape(var), & ! (in)
4284  error ) ! (out)
4285  end if
4286  if ( error /= file_success_code ) then
4287  log_error("FILE_write_realDP_1D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4288  call prc_abort
4289  end if
4290 
4291  return
4292  end subroutine file_write_realdp_1d
4293  subroutine file_write_realsp_2d( &
4294  vid, var, &
4295  t_start, t_end, &
4296  start )
4297  implicit none
4298 
4299  integer, intent(in) :: vid
4300  real(sp), intent(in) :: var(:,:)
4301  real(dp), intent(in) :: t_start
4302  real(dp), intent(in) :: t_end
4303  integer, intent(in), optional :: start(:)
4304  real(dp) :: ts, te
4305 
4306  integer :: start_(2)
4307 
4308  integer :: fid
4309  integer :: error
4310 
4311  intrinsic shape
4312  !---------------------------------------------------------------------------
4313 
4314  ts = t_start
4315  te = t_end
4316 
4317  fid = file_vars(vid)%fid
4318 
4319  if ( .not. file_opened(fid) ) then
4320  log_error("FILE_write_realSP_2D",*) 'File is not opened. fid = ', fid
4321  call prc_abort
4322  end if
4323 
4324  ! this is for restart variable which keeps its original shape
4325  if ( present(start) ) then
4326  start_(:) = start(:)
4327  else
4328  start_(:) = 1
4329  end if
4330  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4331  var(:,:), ts, te, sp, & ! (in)
4332  2, start_, shape(var), & ! (in)
4333  error ) ! (out)
4334  if ( error /= file_success_code ) then
4335  log_error("FILE_write_realSP_2D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4336  call prc_abort
4337  end if
4338 
4339  return
4340  end subroutine file_write_realsp_2d
4341  subroutine file_write_realdp_2d( &
4342  vid, var, &
4343  t_start, t_end, &
4344  start )
4345  implicit none
4346 
4347  integer, intent(in) :: vid
4348  real(dp), intent(in) :: var(:,:)
4349  real(dp), intent(in) :: t_start
4350  real(dp), intent(in) :: t_end
4351  integer, intent(in), optional :: start(:)
4352  real(dp) :: ts, te
4353 
4354  integer :: start_(2)
4355 
4356  integer :: fid
4357  integer :: error
4358 
4359  intrinsic shape
4360  !---------------------------------------------------------------------------
4361 
4362  ts = t_start
4363  te = t_end
4364 
4365  fid = file_vars(vid)%fid
4366 
4367  if ( .not. file_opened(fid) ) then
4368  log_error("FILE_write_realDP_2D",*) 'File is not opened. fid = ', fid
4369  call prc_abort
4370  end if
4371 
4372  ! this is for restart variable which keeps its original shape
4373  if ( present(start) ) then
4374  start_(:) = start(:)
4375  else
4376  start_(:) = 1
4377  end if
4378  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4379  var(:,:), ts, te, dp, & ! (in)
4380  2, start_, shape(var), & ! (in)
4381  error ) ! (out)
4382  if ( error /= file_success_code ) then
4383  log_error("FILE_write_realDP_2D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4384  call prc_abort
4385  end if
4386 
4387  return
4388  end subroutine file_write_realdp_2d
4389  subroutine file_write_realsp_3d( &
4390  vid, var, &
4391  t_start, t_end, &
4392  start )
4393  implicit none
4394 
4395  integer, intent(in) :: vid
4396  real(sp), intent(in) :: var(:,:,:)
4397  real(dp), intent(in) :: t_start
4398  real(dp), intent(in) :: t_end
4399  integer, intent(in), optional :: start(:)
4400  real(dp) :: ts, te
4401 
4402  integer :: start_(3)
4403 
4404  integer :: fid
4405  integer :: error
4406 
4407  intrinsic shape
4408  !---------------------------------------------------------------------------
4409 
4410  ts = t_start
4411  te = t_end
4412 
4413  fid = file_vars(vid)%fid
4414 
4415  if ( .not. file_opened(fid) ) then
4416  log_error("FILE_write_realSP_3D",*) 'File is not opened. fid = ', fid
4417  call prc_abort
4418  end if
4419 
4420  ! this is for restart variable which keeps its original shape
4421  if ( present(start) ) then
4422  start_(:) = start(:)
4423  else
4424  start_(:) = 1
4425  end if
4426  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4427  var(:,:,:), ts, te, sp, & ! (in)
4428  3, start_, shape(var), & ! (in)
4429  error ) ! (out)
4430  if ( error /= file_success_code ) then
4431  log_error("FILE_write_realSP_3D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4432  call prc_abort
4433  end if
4434 
4435  return
4436  end subroutine file_write_realsp_3d
4437  subroutine file_write_realdp_3d( &
4438  vid, var, &
4439  t_start, t_end, &
4440  start )
4441  implicit none
4442 
4443  integer, intent(in) :: vid
4444  real(dp), intent(in) :: var(:,:,:)
4445  real(dp), intent(in) :: t_start
4446  real(dp), intent(in) :: t_end
4447  integer, intent(in), optional :: start(:)
4448  real(dp) :: ts, te
4449 
4450  integer :: start_(3)
4451 
4452  integer :: fid
4453  integer :: error
4454 
4455  intrinsic shape
4456  !---------------------------------------------------------------------------
4457 
4458  ts = t_start
4459  te = t_end
4460 
4461  fid = file_vars(vid)%fid
4462 
4463  if ( .not. file_opened(fid) ) then
4464  log_error("FILE_write_realDP_3D",*) 'File is not opened. fid = ', fid
4465  call prc_abort
4466  end if
4467 
4468  ! this is for restart variable which keeps its original shape
4469  if ( present(start) ) then
4470  start_(:) = start(:)
4471  else
4472  start_(:) = 1
4473  end if
4474  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4475  var(:,:,:), ts, te, dp, & ! (in)
4476  3, start_, shape(var), & ! (in)
4477  error ) ! (out)
4478  if ( error /= file_success_code ) then
4479  log_error("FILE_write_realDP_3D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4480  call prc_abort
4481  end if
4482 
4483  return
4484  end subroutine file_write_realdp_3d
4485  subroutine file_write_realsp_4d( &
4486  vid, var, &
4487  t_start, t_end, &
4488  start )
4489  implicit none
4490 
4491  integer, intent(in) :: vid
4492  real(sp), intent(in) :: var(:,:,:,:)
4493  real(dp), intent(in) :: t_start
4494  real(dp), intent(in) :: t_end
4495  integer, intent(in), optional :: start(:)
4496  real(dp) :: ts, te
4497 
4498  integer :: start_(4)
4499 
4500  integer :: fid
4501  integer :: error
4502 
4503  intrinsic shape
4504  !---------------------------------------------------------------------------
4505 
4506  ts = t_start
4507  te = t_end
4508 
4509  fid = file_vars(vid)%fid
4510 
4511  if ( .not. file_opened(fid) ) then
4512  log_error("FILE_write_realSP_4D",*) 'File is not opened. fid = ', fid
4513  call prc_abort
4514  end if
4515 
4516  ! this is for restart variable which keeps its original shape
4517  if ( present(start) ) then
4518  start_(:) = start(:)
4519  else
4520  start_(:) = 1
4521  end if
4522  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4523  var(:,:,:,:), ts, te, sp, & ! (in)
4524  4, start_, shape(var), & ! (in)
4525  error ) ! (out)
4526  if ( error /= file_success_code ) then
4527  log_error("FILE_write_realSP_4D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4528  call prc_abort
4529  end if
4530 
4531  return
4532  end subroutine file_write_realsp_4d
4533  subroutine file_write_realdp_4d( &
4534  vid, var, &
4535  t_start, t_end, &
4536  start )
4537  implicit none
4538 
4539  integer, intent(in) :: vid
4540  real(dp), intent(in) :: var(:,:,:,:)
4541  real(dp), intent(in) :: t_start
4542  real(dp), intent(in) :: t_end
4543  integer, intent(in), optional :: start(:)
4544  real(dp) :: ts, te
4545 
4546  integer :: start_(4)
4547 
4548  integer :: fid
4549  integer :: error
4550 
4551  intrinsic shape
4552  !---------------------------------------------------------------------------
4553 
4554  ts = t_start
4555  te = t_end
4556 
4557  fid = file_vars(vid)%fid
4558 
4559  if ( .not. file_opened(fid) ) then
4560  log_error("FILE_write_realDP_4D",*) 'File is not opened. fid = ', fid
4561  call prc_abort
4562  end if
4563 
4564  ! this is for restart variable which keeps its original shape
4565  if ( present(start) ) then
4566  start_(:) = start(:)
4567  else
4568  start_(:) = 1
4569  end if
4570  call file_write_data_c( file_files(fid)%fid, file_vars(vid)%vid, & ! (in)
4571  var(:,:,:,:), ts, te, dp, & ! (in)
4572  4, start_, shape(var), & ! (in)
4573  error ) ! (out)
4574  if ( error /= file_success_code ) then
4575  log_error("FILE_write_realDP_4D",*) 'failed to write data: ', trim(file_vars(vid)%name)
4576  call prc_abort
4577  end if
4578 
4579  return
4580  end subroutine file_write_realdp_4d
4581 
4582  !-----------------------------------------------------------------------------
4583  ! exit netCDF define mode and enter data mode
4584  subroutine file_enddef( fid )
4585  implicit none
4586 
4587  integer, intent(in) :: fid
4588 
4589  integer :: error
4590  !---------------------------------------------------------------------------
4591 
4592  if ( .not. file_opened(fid) ) return
4593 
4594  call file_enddef_c( file_files(fid)%fid, error )
4595 
4596  if ( error == file_success_code ) then
4597 
4598  log_newline
4599  log_info("FILE_enddef",'(1x,A,I3.3,2A)') &
4600  'End define mode : No.', fid, ', name = ', trim(file_files(fid)%name)
4601 
4602  else
4603  log_error("FILE_enddef",*) 'failed to exit define mode'
4604  call prc_abort
4605  end if
4606 
4607  return
4608  end subroutine file_enddef
4609 
4610  !-----------------------------------------------------------------------------
4611  ! enter netCDF define mode and enter data mode
4612  subroutine file_redef( fid )
4613  implicit none
4614 
4615  integer, intent(in) :: fid
4616 
4617  integer :: error
4618  !---------------------------------------------------------------------------
4619 
4620  if ( .not. file_opened(fid) ) return
4621 
4622  call file_redef_c( file_files(fid)%fid, error )
4623 
4624  if ( error == file_success_code ) then
4625 
4626  log_newline
4627  log_info("FILE_redef",'(1x,A,I3.3,2A)') &
4628  'Enter to define mode : No.', fid, ', name = ', trim(file_files(fid)%name)
4629 
4630  else
4631  log_error("FILE_redef",*) 'failed to enter to define mode'
4632  call prc_abort
4633  end if
4634 
4635  return
4636  end subroutine file_redef
4637 
4638  !-----------------------------------------------------------------------------
4639  ! This subroutine is used when PnetCDF I/O method is enabled
4640  subroutine file_attach_buffer( &
4641  fid, &
4642  buf_amount )
4643  implicit none
4644 
4645  integer, intent(in) :: fid
4646  integer(8), intent(in) :: buf_amount
4647 
4648  integer :: error
4649  !---------------------------------------------------------------------------
4650 
4651  if ( .not. file_opened(fid) ) return
4652 
4653  if ( file_files(fid)%buffer_size > 0 ) then
4654  call file_detach_buffer(fid)
4655  end if
4656 
4657  call file_attach_buffer_c( file_files(fid)%fid, buf_amount, error )
4658 
4659  if ( error /= file_success_code ) then
4660  log_error("FILE_attach_buffer",*) 'failed to attach buffer in PnetCDF'
4661  call prc_abort
4662  end if
4663 
4664  log_newline
4665  log_info("FILE_attach_buffer",'(1x,A,I3.3,3A,I10)') &
4666  'Attach buffer : No.', fid, ', name = ', trim(file_files(fid)%name), &
4667  ', size = ', buf_amount
4668 
4669  file_files(fid)%buffer_size = buf_amount
4670 
4671  return
4672  end subroutine file_attach_buffer
4673 
4674  !-----------------------------------------------------------------------------
4675  ! This subroutine is used when PnetCDF I/O method is enabled
4676  subroutine file_detach_buffer( fid )
4677  implicit none
4678 
4679  integer, intent(in) :: fid
4680 
4681  integer :: error
4682  !---------------------------------------------------------------------------
4683 
4684  if ( .not. file_opened(fid) ) return
4685 
4686  if ( file_files(fid)%fid < 0 ) return ! already closed
4687 
4688  if ( file_files(fid)%buffer_size < 0 ) return ! not attached
4689 
4690  call file_detach_buffer_c( file_files(fid)%fid, error )
4691 
4692  if ( error /= file_success_code ) then
4693  log_error("FILE_detach_buffer",*) 'failed to detach buffer in PnetCDF'
4694  call prc_abort
4695  end if
4696 
4697  log_newline
4698  log_info("FILE_detach_buffer",'(1x,A,I3.3,2A)') &
4699  'Detach buffer : No.', fid, ', name = ', trim(file_files(fid)%name)
4700 
4701  file_files(fid)%buffer_size = -1
4702 
4703  return
4704  end subroutine file_detach_buffer
4705 
4706  !-----------------------------------------------------------------------------
4707  ! This subroutine is used when PnetCDF I/O method is enabled
4708  subroutine file_flush( fid )
4709  implicit none
4710 
4711  integer, intent(in) :: fid
4712 
4713  integer :: error
4714  !---------------------------------------------------------------------------
4715 
4716  if ( .not. file_opened(fid) ) return
4717 
4718  if ( file_files(fid)%fid < 0 ) return ! already closed
4719 
4720  call file_flush_c( file_files(fid)%fid, error )
4721 
4722  if ( error == file_success_code ) then
4723 
4724 !!$ LOG_NEWLINE
4725 !!$ LOG_INFO("FILE_flush",'(1xA,I3.3,2A)') &
4726 !!$ 'Flush : No.', fid, ', name = ', trim(FILE_files(fid)%name)
4727 
4728  else
4729  log_error("FILE_flush",*) 'failed to flush PnetCDF pending requests'
4730  call prc_abort
4731  end if
4732 
4733  return
4734  end subroutine file_flush
4735 
4736  !-----------------------------------------------------------------------------
4737  subroutine file_close( fid, abort )
4738  implicit none
4739  integer, intent(in) :: fid
4740  logical, intent(in), optional :: abort
4741 
4742  logical :: abort_
4743  integer :: error
4744  integer :: n
4745  !---------------------------------------------------------------------------
4746 
4747  if ( .not. file_opened(fid) ) return
4748 
4749  if ( file_files(fid)%fid < 0 ) return ! already closed
4750 
4751  if ( present(abort) ) then
4752  abort_ = abort
4753  else
4754  abort_ = .false.
4755  end if
4756 
4757  call file_close_c( file_files(fid)%fid, abort_, error )
4758 
4759  if ( error == file_success_code ) then
4760 
4761  log_newline
4762  log_info("FILE_close",'(1x,A,I3.3,2A)') &
4763  'Close : No.', fid, ', name = ', trim(file_files(fid)%name)
4764 
4765  elseif( error /= file_already_closed_code ) then
4766  log_error("FILE_close",*) 'failed to close file'
4767  if ( .not. abort_ ) call prc_abort
4768  end if
4769 
4770  file_files(fid)%fid = -1
4771  file_files(fid)%name = ''
4772  file_files(fid)%aggregate = .false.
4773  file_files(fid)%buffer_size = -1
4774 
4775  do n = 1, file_nvars
4776  if ( file_vars(n)%fid == fid ) then
4777  file_vars(n)%vid = -1
4778  file_vars(n)%name = ''
4779  end if
4780  end do
4781 
4782  return
4783  end subroutine file_close
4784  !-----------------------------------------------------------------------------
4785  subroutine file_close_all( &
4786  skip_abort )
4787  implicit none
4788  logical, intent(in), optional :: skip_abort
4789 
4790  integer :: fid
4791  !---------------------------------------------------------------------------
4792 
4793  do fid = 1, file_nfiles
4794  call file_close( fid, skip_abort )
4795  enddo
4796 
4797  return
4798  end subroutine file_close_all
4799 
4800  subroutine file_make_fname( &
4801  basename, &
4802  prefix, &
4803  rankid, &
4804  len, &
4805  fname )
4806  character(len=*), intent( in) :: basename
4807  character(len=*), intent( in) :: prefix
4808  integer, intent( in) :: rankid
4809  integer, intent( in) :: len
4810  character(len=*), intent(out) :: fname
4811 
4812  ! 12345678901234567
4813  character(len=17) :: fmt = "(A, '.', A, I*.*)"
4814  !---------------------------------------------------------------------------
4815 
4816  if ( len < 1 .or. len > 9 ) then
4817  log_error("FILE_make_fname",*) 'len is invalid'
4818  call prc_abort
4819  end if
4820 
4821  write(fmt(14:14),'(I1)') len
4822  write(fmt(16:16),'(I1)') len
4823  write(fname, fmt) trim(basename), trim(prefix), rankid
4824 
4825  return
4826  end subroutine file_make_fname
4827 
4828  !-----------------------------------------------------------------------------
4830  !-----------------------------------------------------------------------------
4831  subroutine file_get_cftunits(date, tunits)
4832  implicit none
4833 
4834  integer, intent(in) :: date(6)
4835  character(len=*), intent(out) :: tunits
4836  !---------------------------------------------------------------------------
4837 
4838  write(tunits,'(a,i4.4,"-",i2.2,"-",i2.2," ",i2.2,":",i2.2,":",i2.2)') 'seconds since ', date
4839 
4840  return
4841  end subroutine file_get_cftunits
4842 
4843  function file_get_aggregate( fid )
4844  integer, intent(in) :: fid
4845  logical :: file_get_aggregate
4846 
4847  if ( .not. file_opened(fid) ) then
4848  file_get_aggregate = .false.
4849  else
4850  file_get_aggregate = file_files(fid)%aggregate
4851  end if
4852 
4853  return
4854  end function file_get_aggregate
4855 
4856  !-----------------------------------------------------------------------------
4857  ! private
4858  !-----------------------------------------------------------------------------
4859 
4860  !-----------------------------------------------------------------------------
4861  subroutine file_get_fid( &
4862  basename, &
4863  mode, &
4864  rankid, &
4865  single, &
4866  fid, &
4867  existed, &
4868  aggregate, &
4869  postfix )
4870  use scale_prc, only: &
4873  implicit none
4874 
4875  character(len=*), intent( in) :: basename
4876  integer, intent( in) :: mode
4877  integer, intent( in) :: rankid
4878  logical, intent( in) :: single
4879 
4880  integer, intent(out) :: fid
4881  logical, intent(out) :: existed
4882 
4883  logical, intent( in), optional :: aggregate
4884  character(len=*), intent( in), optional :: postfix
4885 
4886  character(len=FILE_HSHORT) :: rwname(0:2)
4887  data rwname / 'READ','WRITE','APPEND' /
4888 
4889  character(len=FILE_HLONG) :: fname
4890  integer :: n
4891 
4892  logical :: aggregate_
4893  integer :: cfid
4894  integer :: error
4895  integer :: mpi_comm
4896  !---------------------------------------------------------------------------
4897 
4898  !--- check aggregate (parallel I/O on a single shared netCDF file)
4899 
4900  ! check to do PnetCDF I/O
4901  if ( present(aggregate) ) then
4902  aggregate_ = aggregate
4903  else
4904  aggregate_ = file_aggregate
4905  end if
4906 
4907  if ( aggregate_ ) then
4908  mpi_comm = prc_local_comm_world
4909  else
4910  mpi_comm = prc_comm_null
4911  end if
4912 
4913  if ( present(postfix) ) then
4914  fname = trim(basename)//trim(postfix)
4915  elseif ( aggregate_ ) then
4916  fname = basename
4917  elseif ( single ) then
4918  fname = trim(basename)//'.peall'
4919  else
4920  call file_make_fname( basename, 'pe', rankid, 6, fname )
4921  endif
4922 
4923  !--- search existing file
4924  fid = -1
4925  do n = 1, file_nfiles
4926  if ( fname == file_files(n)%name ) then
4927  fid = n
4928  exit
4929  end if
4930  enddo
4931 
4932  if ( file_opened(fid) ) then
4933  existed = .true.
4934  return
4935  end if
4936 
4937  call file_open_c( cfid, & ! (out)
4938  fname, mode, mpi_comm, & ! (in)
4939  error ) ! (out)
4940 
4941  if ( error /= file_success_code ) then
4942  log_error("FILE_get_fid",*) 'failed to open file :'//trim(fname)//'.nc'
4943  call prc_abort
4944  end if
4945 
4946  file_nfiles = file_nfiles + 1
4947  fid = file_nfiles
4948 
4949  file_files(fid)%name = fname
4950  file_files(fid)%fid = cfid
4951  file_files(fid)%aggregate = aggregate_
4952  file_files(fid)%single = single
4953  file_files(fid)%buffer_size = -1
4954 
4955  log_newline
4956  log_info("FILE_get_fid",'(1x,A,A6,A,I3.3,2A)') &
4957  'Registration (', trim(rwname(mode)), ') : No.', fid, ', name = ', trim(fname)
4958 
4959  existed = .false.
4960 
4961  return
4962  end subroutine file_get_fid
4963 
4964 
4965 end module scale_file
4966 !-------------------------------------------------------------------------------
4967 
4968 
4969 !--
4970 ! vi:set readonly sw=4 ts=8
4971 !
4972 !Local Variables:
4973 !mode: f90
4974 !buffer-read-only: t
4975 !End:
4976 !
4977 !++
file_put_associatedcoordinate_c
int32_t file_put_associatedcoordinate_c(const int32_t fid, const char *name, const char *desc, const char *units, const char **dim_names, const int32_t ndims, const int32_t dtype, const void *val, const int32_t precision)
Definition: scale_file_netcdf.c:1381
scale_precision::sp
integer, parameter, public sp
Definition: scale_precision.F90:31
file_get_nvars_c
int32_t file_get_nvars_c(const int32_t fid, int32_t *nvars)
Definition: scale_file_netcdf.c:296
scale_file::file_get_stepsize
subroutine, public file_get_stepsize(fid, varname, len, error)
get number of steps
Definition: scale_file.F90:2472
file_set_attribute_text_c
int32_t file_set_attribute_text_c(const int32_t fid, const char *vname, const char *key, const char *value)
Definition: scale_file_netcdf.c:1028
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:342
file_write_axis_c
int32_t file_write_axis_c(const int32_t fid, const char *name, const void *val, const int32_t precision, const MPI_Offset *start, const MPI_Offset *count)
Definition: scale_file_netcdf.c:1339
file_set_option_c
int32_t file_set_option_c(const int32_t fid, const char *filetype, const char *key, const char *val)
Definition: scale_file_netcdf.c:280
file_flush_c
int32_t file_flush_c(const int32_t fid)
Definition: scale_file_netcdf.c:1843
scale_file::file_close_all
subroutine, public file_close_all(skip_abort)
Definition: scale_file.F90:4787
scale_file::file_enddef
subroutine, public file_enddef(fid)
Definition: scale_file.F90:4585
scale_file_h::file_already_closed_code
integer, parameter, public file_already_closed_code
Definition: scale_file_h.F90:39
scale_prc::prc_set_file_closer
subroutine, public prc_set_file_closer(routine)
Definition: scale_prc.F90:1005
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_prc::prc_local_comm_world
integer, public prc_local_comm_world
local communicator
Definition: scale_prc.F90:88
scale_file::file_attach_buffer
subroutine, public file_attach_buffer(fid, buf_amount)
Definition: scale_file.F90:4643
file_get_dim_length_c
int32_t file_get_dim_length_c(const int32_t fid, const char *dimname, int32_t *len)
Definition: scale_file_netcdf.c:256
scale_file::file_flush
subroutine, public file_flush(fid)
Definition: scale_file.F90:4709
file_add_associatedvariable_c
int32_t file_add_associatedvariable_c(const int32_t fid, const char *vname)
Definition: scale_file_netcdf.c:1192
file_def_axis_c
int32_t file_def_axis_c(const int32_t fid, const char *name, const char *desc, const char *units, const char *dim_name, const int32_t dtype, const int32_t dim_size, const int32_t bounds)
Definition: scale_file_netcdf.c:1274
file_add_variable_c
int32_t file_add_variable_c(const int32_t fid, const char *varname, const char *desc, const char *units, const char *stdname, const char **dims, const int32_t ndims, const int32_t dtype, const real64_t tint, const int32_t tavg, int32_t *vid)
Definition: scale_file_netcdf.c:1526
scale_file_h::file_rmiss
real(dp), parameter, public file_rmiss
Definition: scale_file_h.F90:49
file_close_c
int32_t file_close_c(const int32_t fid, const int32_t abort)
Definition: scale_file_netcdf.c:1982
scale_file::file_make_fname
subroutine, public file_make_fname(basename, prefix, rankid, len, fname)
Definition: scale_file.F90:4806
scale_file::file_get_dimlength
subroutine, public file_get_dimlength(fid, dimname, len, error)
get length of dimension
Definition: scale_file.F90:565
scale_file::file_opened
logical function, public file_opened(fid)
check if the file is opened?
Definition: scale_file.F90:527
file_attach_buffer_c
int32_t file_attach_buffer_c(const int32_t fid, const int64_t buf_amount)
Definition: scale_file_netcdf.c:1816
scale_file
module file
Definition: scale_file.F90:15
scale_file::file_def_axis
subroutine, public file_def_axis(fid, name, desc, units, dim_name, dtype, dim_size, bounds)
Definition: scale_file.F90:667
scale_prc
module PROCESS
Definition: scale_prc.F90:11
scale_io
module STDIO
Definition: scale_io.F90:10
scale_prc::prc_comm_null
integer, parameter, public prc_comm_null
Definition: scale_prc.F90:68
file_get_step_size_c
int32_t file_get_step_size_c(const int32_t fid, const char *varname, int32_t *len)
Definition: scale_file_netcdf.c:633
scale_file::file_close
subroutine, public file_close(fid, abort)
Definition: scale_file.F90:4738
scale_file::file_def_associatedcoordinate
subroutine, public file_def_associatedcoordinate(fid, name, desc, units, dim_names, dtype)
Definition: scale_file.F90:1037
file_set_attribute_double_c
int32_t file_set_attribute_double_c(const int32_t fid, const char *vname, const char *key, const double *value, const size_t len)
Definition: scale_file_netcdf.c:1154
scale_file::i
logical, public i
Definition: scale_file.F90:182
scale_file::file_open
subroutine, public file_open(basename, fid, mode, single, aggregate, rankid, postfix)
Definition: scale_file.F90:487
scale_file_h::file_already_existed_code
integer, parameter, public file_already_existed_code
Definition: scale_file_h.F90:40
file_redef_c
int32_t file_redef_c(const int32_t fid)
Definition: scale_file_netcdf.c:1805
file_get_varname_c
int32_t file_get_varname_c(const int32_t fid, const int32_t vid, char *name, const int32_t len)
Definition: scale_file_netcdf.c:313
scale_prof
module profiler
Definition: scale_prof.F90:11
file_write_associatedcoordinate_c
int32_t file_write_associatedcoordinate_c(const int32_t fid, const char *name, const void *val, const int32_t precision, const MPI_Offset *start, const MPI_Offset *count)
Definition: scale_file_netcdf.c:1484
file_set_attribute_int_c
int32_t file_set_attribute_int_c(const int32_t fid, const char *vname, const char *key, const int32_t *value, const size_t len)
Definition: scale_file_netcdf.c:1069
file_open_c
int32_t file_open_c(int32_t *fid, const char *fname, const int32_t mode, const MPI_Comm comm)
Definition: scale_file_netcdf.c:170
scale_precision::dp
integer, parameter, public dp
Definition: scale_precision.F90:32
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:34
file_set_attribute_float_c
int32_t file_set_attribute_float_c(const int32_t fid, const char *vname, const char *key, const float *value, const size_t len)
Definition: scale_file_netcdf.c:1112
file_get_attribute_int_c
int32_t file_get_attribute_int_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, int32_t *value, const size_t len)
scale_file::file_add_associatedvariable
subroutine, public file_add_associatedvariable(fid, vname, existed)
Definition: scale_file.F90:422
file_get_attribute_double_c
int32_t file_get_attribute_double_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, double *value, const size_t len)
Definition: scale_file_netcdf.c:985
scale_file::file_single
logical function, public file_single(fid)
check if the file is single
Definition: scale_file.F90:544
scale_file::file_get_cftunits
subroutine, public file_get_cftunits(date, tunits)
get unit of time
Definition: scale_file.F90:4832
file_get_datainfo_c
int32_t file_get_datainfo_c(datainfo_t *dinfo, const int32_t fid, const char *varname, const int32_t step, const int32_t suppress)
Definition: scale_file_netcdf.c:338
scale_file::file_aggregate
logical, public file_aggregate
Definition: scale_file.F90:182
file_read_data_c
int32_t file_read_data_c(void *var, const datainfo_t *dinfo, const int32_t precision, const MPI_Offset ntypes, const MPI_Datatype dtype, const int32_t *start, const int32_t *count)
Definition: scale_file_netcdf.c:687
scale_file_h::file_fread
integer, parameter, public file_fread
Definition: scale_file_h.F90:32
scale_file_h::file_success_code
integer, parameter, public file_success_code
Definition: scale_file_h.F90:38
scale_file::file_redef
subroutine, public file_redef(fid)
Definition: scale_file.F90:4613
scale_file::file_def_variable
subroutine, public file_def_variable(fid, varname, desc, units, standard_name, ndims, dims, dtype, vid, time_int, time_avg, existed)
Definition: scale_file.F90:1571
scale_file_h::file_var_max
integer, parameter, public file_var_max
Definition: scale_file_h.F90:44
scale_file::file_get_aggregate
logical function, public file_get_aggregate(fid)
Definition: scale_file.F90:4844
file_put_axis_c
int32_t file_put_axis_c(const int32_t fid, const char *name, const char *desc, const char *units, const char *dim_name, const int32_t dtype, const void *val, const int32_t size, const int32_t precision)
Definition: scale_file_netcdf.c:1225
scale_file_h::datainfo
Definition: scale_file_h.F90:52
scale_file::file_detach_buffer
subroutine, public file_detach_buffer(fid)
Definition: scale_file.F90:4677
scale_file::file_setup
subroutine, public file_setup(myrank)
setup
Definition: scale_file.F90:221
file_get_attribute_text_c
int32_t file_get_attribute_text_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, char *value, const int32_t len)
Definition: scale_file_netcdf.c:852
file_get_attribute_float_c
int32_t file_get_attribute_float_c(const int32_t fid, const char *vname, const char *key, const int32_t suppress, float *value, const size_t len)
Definition: scale_file_netcdf.c:942
file_set_tunits_c
int32_t file_set_tunits_c(const int32_t fid, const char *time_units, const char *calendar)
Definition: scale_file_netcdf.c:1215
scale_file_h::file_file_max
integer, parameter, public file_file_max
Definition: scale_file_h.F90:43
scale_io::io_fid_conf
integer, public io_fid_conf
Config file ID.
Definition: scale_io.F90:56
file_def_associatedcoordinate_c
int32_t file_def_associatedcoordinate_c(const int32_t fid, const char *name, const char *desc, const char *units, const char **dim_names, const int32_t ndims, const int32_t dtype)
Definition: scale_file_netcdf.c:1434
scale_file::file_create
subroutine, public file_create(basename, title, source, institution, fid, existed, rankid, single, aggregate, time_units, calendar, append)
create file fid is >= 1
Definition: scale_file.F90:267
scale_file::file_set_option
subroutine, public file_set_option(fid, filetype, key, val)
Definition: scale_file.F90:456
file_detach_buffer_c
int32_t file_detach_buffer_c(const int32_t fid)
Definition: scale_file_netcdf.c:1830
file_write_data_c
int32_t file_write_data_c(const int32_t fid, const int32_t vid, const void *var, const real64_t t_start, const real64_t t_end, const int32_t precision, const int32_t ndims, const int32_t *start, const int32_t *count)
Definition: scale_file_netcdf.c:1858
file_enddef_c
int32_t file_enddef_c(const int32_t fid)
Definition: scale_file_netcdf.c:1794
scale_file_h::file_fwrite
integer, parameter, public file_fwrite
Definition: scale_file_h.F90:33