SCALE-RM
Data Types | Functions/Subroutines | Variables
scale_file Module Reference

module file More...

Functions/Subroutines

subroutine, public file_setup (myrank)
 setup More...
 
subroutine, public file_create (basename, title, source, institution, fid, existed, rankid, single, aggregate, time_units, calendar, append)
 create file fid is >= 1 More...
 
subroutine, public file_add_associatedvariable (fid, vname, existed)
 
subroutine, public file_set_option (fid, filetype, key, val)
 
subroutine, public file_open (basename, fid, mode, single, aggregate, rankid, postfix)
 
logical function, public file_opened (fid)
 check if the file is opened? More...
 
logical function, public file_single (fid)
 check if the file is single More...
 
subroutine, public file_get_dimlength (fid, dimname, len, error)
 get length of dimension More...
 
subroutine, public file_def_axis (fid, name, desc, units, dim_name, dtype, dim_size, bounds)
 
subroutine, public file_def_associatedcoordinate (fid, name, desc, units, dim_names, dtype)
 
subroutine, public file_def_variable (fid, varname, desc, units, standard_name, ndims, dims, dtype, vid, time_int, time_avg, existed)
 
subroutine, public file_get_stepsize (fid, varname, len, error)
 get number of steps More...
 
subroutine, public file_enddef (fid)
 
subroutine, public file_redef (fid)
 
subroutine, public file_attach_buffer (fid, buf_amount)
 
subroutine, public file_detach_buffer (fid)
 
subroutine, public file_flush (fid)
 
subroutine, public file_close (fid, abort)
 
subroutine, public file_close_all (skip_abort)
 
subroutine, public file_make_fname (basename, prefix, rankid, len, fname)
 
subroutine, public file_get_cftunits (date, tunits)
 get unit of time More...
 
logical function, public file_get_aggregate (fid)
 

Variables

logical, public file_aggregate = .false.
 
logical, public do
 
logical, public parallel
 
logical, public i
 
logical, public o
 
logical, public through
 
logical, dimension(default setting), public pnetcdf
 

Detailed Description

module file

Description
file I/O hundring
Author
Team SCALE
NAMELIST
  • PARAM_FILE
    nametypedefault valuecomment
    FILE_AGGREGATE logical .false. > do parallel I/O through PnetCDF (default setting)

History Output
No history output

Function/Subroutine Documentation

◆ file_setup()

subroutine, public scale_file::file_setup ( integer, intent(in)  myrank)

setup

Definition at line 221 of file scale_file.F90.

221  use scale_prc, only: &
223  implicit none
224 
225  integer, intent(in) :: myrank
226 
227  namelist / param_file / &
228  file_aggregate
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 
246  call prc_set_file_closer( file_close_all )
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

References file_aggregate, file_close_all(), scale_file_h::file_file_max, scale_io::io_fid_conf, and scale_prc::prc_set_file_closer().

Referenced by scale_file_cartesc::file_cartesc_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_create()

subroutine, public scale_file::file_create ( character(len=*), intent(in)  basename,
character(len=*), intent(in)  title,
character(len=*), intent(in)  source,
character(len=*), intent(in)  institution,
integer, intent(out)  fid,
logical, intent(out)  existed,
integer, intent(in), optional  rankid,
logical, intent(in), optional  single,
logical, intent(in), optional  aggregate,
character(len=*), intent(in), optional  time_units,
character(len=*), intent(in), optional  calendar,
logical, intent(in), optional  append 
)

create file fid is >= 1

Definition at line 267 of file scale_file.F90.

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

References scale_file_h::file_fappend, scale_file_h::file_fwrite, file_get_nvars_c(), file_get_varname_c(), file_opened(), file_set_tunits_c(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_cartesc::file_cartesc_create(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_add_associatedvariable()

subroutine, public scale_file::file_add_associatedvariable ( integer, intent(in)  fid,
character(len=*), intent(in)  vname,
logical, intent(out), optional  existed 
)

Definition at line 422 of file scale_file.F90.

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

References file_add_associatedvariable_c(), scale_file_h::file_already_existed_code, file_opened(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_cartesc::file_cartesc_def_axes(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_set_option()

subroutine, public scale_file::file_set_option ( integer, intent(in)  fid,
character(len=*), intent(in)  filetype,
character(len=*), intent(in)  key,
character(len=*), intent(in)  val 
)

Definition at line 456 of file scale_file.F90.

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

References file_opened(), file_set_option_c(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_open()

subroutine, public scale_file::file_open ( character(len=*), intent(in)  basename,
integer, intent(out)  fid,
integer, intent(in), optional  mode,
logical, intent(in), optional  single,
logical, intent(in), optional  aggregate,
integer, intent(in), optional  rankid,
character(len=*), intent(in), optional  postfix 
)

Definition at line 487 of file scale_file.F90.

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

References scale_file_h::file_fread.

Referenced by scale_atmos_grid_cartesc::atmos_grid_cartesc_allocate(), scale_atmos_phy_rd_profile::atmos_phy_rd_profile_setup(), scale_comm_cartesc_nest::comm_cartesc_nest_setup(), mod_copytopo::copytopo_get_data_scale(), mod_copytopo::copytopo_get_data_wrfarw(), mod_copytopo::copytopo_get_size_wrfarw(), scale_file_cartesc::file_cartesc_cleanup(), scale_file_cartesc::file_cartesc_open(), file_def_variable(), scale_file_external_input::file_external_input_regist(), scale_file_external_input::file_external_input_update_3d(), file_get_stepsize(), scale_land_grid_cartesc::land_grid_cartesc_setup(), scale_land_grid_icoa::land_grid_icoa_setup(), scale_ocean_grid_cartesc::ocean_grid_cartesc_setup(), scale_ocean_grid_icoa::ocean_grid_icoa_setup(), mod_realinput_scale::parentatmosinputscale(), mod_realinput_wrfarw::parentatmosinputwrfarw(), mod_realinput_nicam::parentatmosopennicam(), mod_realinput_scale::parentatmosopenscale(), mod_realinput_wrfarw::parentatmossetupwrfarw(), mod_realinput_scale::parentlandinputscale(), mod_realinput_wrfarw::parentlandinputwrfarw(), mod_realinput_wrfarw::parentlandsetupwrfarw(), mod_realinput_scale::parentoceaninputscale(), mod_realinput_wrfarw::parentoceaninputwrfarw(), mod_realinput_scale::parentoceanopenscale(), mod_realinput_wrfarw::parentoceansetupwrfarw(), scale_urban_grid_cartesc::urban_grid_cartesc_setup(), scale_urban_grid_icoa::urban_grid_icoa_setup(), and mod_realinput_wrfarw::wrf_arwpost_calc_uvmet().

Here is the caller graph for this function:

◆ file_opened()

logical function, public scale_file::file_opened ( integer, intent(in)  fid)

check if the file is opened?

Definition at line 527 of file scale_file.F90.

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

Referenced by file_add_associatedvariable(), file_attach_buffer(), scale_file_cartesc::file_cartesc_close(), scale_file_cartesc::file_cartesc_def_axes(), scale_file_cartesc::file_cartesc_def_var(), scale_file_cartesc::file_cartesc_enddef(), scale_file_cartesc::file_cartesc_flush(), scale_file_cartesc::file_cartesc_put_globalattributes(), scale_file_cartesc::file_cartesc_read_1d(), scale_file_cartesc::file_cartesc_read_auto_2d(), scale_file_cartesc::file_cartesc_read_auto_3d(), scale_file_cartesc::file_cartesc_read_var_2d(), scale_file_cartesc::file_cartesc_read_var_3d(), scale_file_cartesc::file_cartesc_read_var_4d(), scale_file_cartesc::file_cartesc_write_axes(), scale_file_cartesc::file_cartesc_write_var_1d(), scale_file_cartesc::file_cartesc_write_var_2d(), scale_file_cartesc::file_cartesc_write_var_3d(), scale_file_cartesc::file_cartesc_write_var_3d_t(), scale_file_cartesc::file_cartesc_write_var_4d(), file_close(), file_create(), file_def_associatedcoordinate(), file_def_axis(), file_def_variable(), file_detach_buffer(), file_enddef(), file_flush(), file_get_aggregate(), file_get_dimlength(), file_get_stepsize(), file_redef(), and file_set_option().

Here is the caller graph for this function:

◆ file_single()

logical function, public scale_file::file_single ( integer, intent(in)  fid)

◆ file_get_dimlength()

subroutine, public scale_file::file_get_dimlength ( integer, intent(in)  fid,
character(len=*), intent(in)  dimname,
integer, intent(out)  len,
logical, intent(out), optional  error 
)

get length of dimension

Definition at line 565 of file scale_file.F90.

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

References scale_precision::dp, scale_file_h::file_already_existed_code, file_get_dim_length_c(), file_opened(), file_put_axis_c(), scale_file_h::file_success_code, scale_prc::prc_abort(), and scale_precision::sp.

Referenced by mod_copytopo::copytopo_get_size_wrfarw(), mod_realinput_wrfarw::parentatmossetupwrfarw(), mod_realinput_wrfarw::parentlandsetupwrfarw(), and mod_realinput_wrfarw::parentoceansetupwrfarw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_def_axis()

subroutine, public scale_file::file_def_axis ( integer, intent(in)  fid,
character(len=*), intent(in)  name,
character(len=*), intent(in)  desc,
character(len=*), intent(in)  units,
character(len=*), intent(in)  dim_name,
integer, intent(in)  dtype,
integer, intent(in)  dim_size,
logical, intent(in), optional  bounds 
)

Definition at line 667 of file scale_file.F90.

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

References scale_precision::dp, scale_file_h::file_already_existed_code, file_def_axis_c(), file_opened(), file_put_associatedcoordinate_c(), scale_file_h::file_success_code, file_write_axis_c(), scale_prc::prc_abort(), and scale_precision::sp.

Referenced by scale_file_cartesc::file_cartesc_def_axes(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_def_associatedcoordinate()

subroutine, public scale_file::file_def_associatedcoordinate ( integer, intent(in)  fid,
character(len=*), intent(in)  name,
character(len=*), intent(in)  desc,
character(len=*), intent(in)  units,
character(len=*), dimension(:), intent(in)  dim_names,
integer, intent(in)  dtype 
)

Definition at line 1037 of file scale_file.F90.

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

References scale_precision::dp, file_add_variable_c(), scale_file_h::file_already_existed_code, file_def_associatedcoordinate_c(), file_opened(), scale_file_h::file_success_code, file_write_associatedcoordinate_c(), scale_prc::prc_abort(), and scale_precision::sp.

Referenced by scale_file_cartesc::file_cartesc_def_axes(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_def_variable()

subroutine, public scale_file::file_def_variable ( integer, intent(in)  fid,
character(len=*), intent(in)  varname,
character(len=*), intent(in)  desc,
character(len=*), intent(in)  units,
character(len=*), intent(in)  standard_name,
integer, intent(in)  ndims,
character(len=*), dimension(:), intent(in)  dims,
integer, intent(in)  dtype,
integer, intent(out)  vid,
real(dp), intent(in), optional  time_int,
logical, intent(in), optional  time_avg,
logical, intent(out), optional  existed 
)

Definition at line 1571 of file scale_file.F90.

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

References file_add_variable_c(), scale_file_h::file_already_existed_code, file_get_attribute_double_c(), file_get_attribute_float_c(), file_get_attribute_int_c(), file_get_attribute_text_c(), file_get_datainfo_c(), file_open(), file_opened(), file_set_attribute_double_c(), file_set_attribute_float_c(), file_set_attribute_int_c(), file_set_attribute_text_c(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_cartesc::file_cartesc_def_var().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_get_stepsize()

subroutine, public scale_file::file_get_stepsize ( integer, intent(in)  fid,
character(len=*), intent(in)  varname,
integer, intent(out)  len,
logical, intent(out), optional  error 
)

get number of steps

Definition at line 2472 of file scale_file.F90.

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

References scale_precision::dp, scale_file_h::file_already_existed_code, file_get_datainfo_c(), file_get_step_size_c(), file_open(), file_opened(), file_read_data_c(), scale_file_h::file_rmiss, scale_file_h::file_success_code, file_write_data_c(), i, scale_prc::prc_abort(), and scale_precision::sp.

Here is the call graph for this function:

◆ file_enddef()

subroutine, public scale_file::file_enddef ( integer, intent(in)  fid)

Definition at line 4585 of file scale_file.F90.

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

References file_enddef_c(), file_opened(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_cartesc::file_cartesc_enddef(), scale_file_history::file_history_set_attribute_double(), and scale_file_history::file_history_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_redef()

subroutine, public scale_file::file_redef ( integer, intent(in)  fid)

Definition at line 4613 of file scale_file.F90.

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

References file_opened(), file_redef_c(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_attach_buffer()

subroutine, public scale_file::file_attach_buffer ( integer, intent(in)  fid,
integer(8), intent(in)  buf_amount 
)

Definition at line 4643 of file scale_file.F90.

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

References file_attach_buffer_c(), file_detach_buffer(), file_opened(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_cartesc::file_cartesc_enddef(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_detach_buffer()

subroutine, public scale_file::file_detach_buffer ( integer, intent(in)  fid)

Definition at line 4677 of file scale_file.F90.

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

References file_detach_buffer_c(), file_opened(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by file_attach_buffer(), scale_file_cartesc::file_cartesc_close(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_flush()

subroutine, public scale_file::file_flush ( integer, intent(in)  fid)

Definition at line 4709 of file scale_file.F90.

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

References file_flush_c(), file_opened(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_file_cartesc::file_cartesc_close(), scale_file_cartesc::file_cartesc_enddef(), scale_file_cartesc::file_cartesc_flush(), scale_file_cartesc::file_cartesc_write_var_4d(), scale_file_history::file_history_finalize(), scale_file_history::file_history_set_attribute_double(), and scale_file_history::file_history_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_close()

subroutine, public scale_file::file_close ( integer, intent(in)  fid,
logical, intent(in), optional  abort 
)

Definition at line 4738 of file scale_file.F90.

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

References scale_file_h::file_already_closed_code, file_close_c(), file_opened(), scale_file_h::file_success_code, and scale_prc::prc_abort().

Referenced by scale_atmos_phy_rd_profile::atmos_phy_rd_profile_setup(), mod_copytopo::copytopo_get_data_scale(), mod_copytopo::copytopo_get_data_wrfarw(), scale_file_cartesc::file_cartesc_close(), file_close_all(), and scale_file_history::file_history_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_close_all()

subroutine, public scale_file::file_close_all ( logical, intent(in), optional  skip_abort)

Definition at line 4787 of file scale_file.F90.

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

References file_close().

Referenced by file_setup(), mod_rm_driver::rm_driver(), mod_rm_prep::rm_prep(), and scale::scale_finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_make_fname()

subroutine, public scale_file::file_make_fname ( character(len=*), intent(in)  basename,
character(len=*), intent(in)  prefix,
integer, intent(in)  rankid,
integer, intent(in)  len,
character(len=*), intent(out)  fname 
)

Definition at line 4806 of file scale_file.F90.

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

References scale_prc::prc_abort().

Referenced by file_get_aggregate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_get_cftunits()

subroutine, public scale_file::file_get_cftunits ( integer, dimension(6), intent(in)  date,
character(len=*), intent(out)  tunits 
)

get unit of time

Definition at line 4832 of file scale_file.F90.

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

Referenced by scale_file_cartesc::file_cartesc_create(), and scale_file_history_cartesc::file_history_cartesc_truncate_3d().

Here is the caller graph for this function:

◆ file_get_aggregate()

logical function, public scale_file::file_get_aggregate ( integer, intent(in)  fid)

Definition at line 4844 of file scale_file.F90.

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

References file_aggregate, file_make_fname(), file_open_c(), file_opened(), scale_file_h::file_success_code, scale_prc::prc_comm_null, and scale_prc::prc_local_comm_world.

Referenced by mod_atmos_dyn_vars::atmos_dyn_vars_restart_read(), mod_atmos_phy_ae_vars::atmos_phy_ae_vars_restart_read(), mod_atmos_phy_bl_vars::atmos_phy_bl_vars_restart_read(), mod_atmos_phy_ch_vars::atmos_phy_ch_vars_restart_read(), mod_atmos_phy_cp_vars::atmos_phy_cp_vars_restart_read(), mod_atmos_phy_lt_vars::atmos_phy_lt_vars_restart_read(), mod_atmos_phy_mp_vars::atmos_phy_mp_vars_restart_read(), mod_atmos_phy_rd_vars::atmos_phy_rd_vars_restart_read(), mod_atmos_phy_sf_vars::atmos_phy_sf_vars_restart_read(), mod_atmos_vars::atmos_vars_restart_check(), mod_atmos_vars::atmos_vars_restart_read(), scale_file_cartesc::file_cartesc_close(), scale_file_cartesc::file_cartesc_def_axes(), scale_file_cartesc::file_cartesc_enddef(), scale_file_cartesc::file_cartesc_flush(), scale_file_cartesc::file_cartesc_read_1d(), scale_file_cartesc::file_cartesc_read_var_2d(), scale_file_cartesc::file_cartesc_read_var_3d(), scale_file_cartesc::file_cartesc_read_var_4d(), scale_file_cartesc::file_cartesc_write_axes(), scale_file_cartesc::file_cartesc_write_var_1d(), scale_file_cartesc::file_cartesc_write_var_2d(), scale_file_cartesc::file_cartesc_write_var_3d(), scale_file_cartesc::file_cartesc_write_var_3d_t(), scale_file_cartesc::file_cartesc_write_var_4d(), mod_land_vars::land_vars_restart_read(), mod_ocean_vars::ocean_vars_restart_read(), and mod_urban_vars::urban_vars_restart_read().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ file_aggregate

logical, public scale_file::file_aggregate = .false.

◆ do

logical, public scale_file::do

Definition at line 182 of file scale_file.F90.

◆ parallel

logical, public scale_file::parallel

Definition at line 182 of file scale_file.F90.

◆ i

logical, public scale_file::i

◆ o

logical, public scale_file::o

Definition at line 182 of file scale_file.F90.

◆ through

logical, public scale_file::through

Definition at line 182 of file scale_file.F90.

◆ pnetcdf

logical, dimension (default setting), public scale_file::pnetcdf

Definition at line 182 of file scale_file.F90.

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_prc::prc_set_file_closer
subroutine, public prc_set_file_closer(routine)
Definition: scale_prc.F90:1005
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
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
file_close_c
int32_t file_close_c(const int32_t fid, const int32_t abort)
Definition: scale_file_netcdf.c:1982
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_prc
module PROCESS
Definition: scale_prc.F90:11
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
file_redef_c
int32_t file_redef_c(const int32_t fid)
Definition: scale_file_netcdf.c:1805
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
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
file_detach_buffer_c
int32_t file_detach_buffer_c(const int32_t fid)
Definition: scale_file_netcdf.c:1830
file_enddef_c
int32_t file_enddef_c(const int32_t fid)
Definition: scale_file_netcdf.c:1794