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_finalize
 finalize More...
 
subroutine, public file_create (basename, title, source, institution, fid, existed, rankid, single, aggregate, time_units, calendar, allnodes, 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, allnodes, 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...
 
logical function, public file_allnodes (fid)
 check if the file is allnodes 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_stats, 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_get_cftunits (date, tunits)
 get unit of time More...
 
logical function, public file_get_aggregate (fid)
 

Variables

logical, public file_aggregate
 
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 > 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 236 of file scale_file.F90.

236  use scale_prc, only: &
238  implicit none
239 
240  integer, intent(in) :: myrank
241 
242  namelist / param_file / &
243  file_aggregate
244 
245  integer :: fid
246  integer :: ierr
247 
248  file_aggregate = .false.
249 
250  !--- read namelist
251  rewind(io_fid_conf)
252  read(io_fid_conf,nml=param_file,iostat=ierr)
253  if( ierr < 0 ) then !--- missing
254  log_info("FILE_setup",*) 'Not found namelist. Default used.'
255  elseif( ierr > 0 ) then !--- fatal error
256  log_error("FILE_setup",*) 'Not appropriate names in namelist PARAM_FILE. Check!'
257  call prc_abort
258  endif
259  log_nml(param_file)
260 
261  mpi_myrank = myrank
262 
263  call prc_set_file_closer( file_close_all )
264 
265  do fid = 1, file_file_max
266  file_files(fid)%fid = -1
267  file_files(fid)%name = ""
268  end do
269 
270  return

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_finalize()

subroutine, public scale_file::file_finalize

finalize

Definition at line 277 of file scale_file.F90.

277 
278  file_nfiles = 0
279  file_nvars = 0
280 
281  return

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

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  allnodes,
logical, intent(in), optional  append 
)

create file fid is >= 1

Definition at line 295 of file scale_file.F90.

295  implicit none
296 
297  character(len=*), intent(in) :: basename
298  character(len=*), intent(in) :: title
299  character(len=*), intent(in) :: source
300  character(len=*), intent(in) :: institution
301 
302  integer, intent(out) :: fid
303  logical, intent(out) :: existed
304 
305  integer, intent(in), optional :: rankid
306  logical, intent(in), optional :: single
307  logical, intent(in), optional :: aggregate
308  character(len=*), intent(in), optional :: time_units
309  character(len=*), intent(in), optional :: calendar
310  logical, intent(in), optional :: allnodes
311  logical, intent(in), optional :: append
312 
313  character(len=FILE_HMID) :: time_units_
314  character(len=FILE_HSHORT) :: calendar_
315  integer :: rankid_
316  logical :: single_
317  integer :: mode
318 
319  integer :: error
320  !---------------------------------------------------------------------------
321 
322 
323  if ( present(rankid) ) then
324  rankid_ = rankid
325  else
326  rankid_ = mpi_myrank
327  end if
328 
329  single_ = .false.
330  if ( present(single) ) then
331  single_ = single
332  endif
333 
334  if ( present(time_units) ) then
335  time_units_ = time_units
336  else
337  time_units_ = 'seconds'
338  endif
339 
340  if ( present(calendar) ) then
341  calendar_ = calendar
342  else
343  calendar_ = ""
344  end if
345 
346  mode = file_fwrite
347  if ( present(append) ) then
348  if( append ) mode = file_fappend
349  endif
350 
351  if ( single_ .and. rankid_ /= 0 ) then
352  fid = -1
353  existed = .false.
354  return
355  end if
356 
357  call file_get_fid( basename, mode, & ! [IN]
358  rankid_, single_, & ! [IN]
359  fid, existed, & ! [OUT]
360  allnodes=allnodes, & ! [IN]
361  aggregate=aggregate ) ! [IN]
362 
363  if( existed ) return
364 
365  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
366 
367  !--- append package header to the file
368  call file_set_attribute( fid, "global", "title" , title ) ! [IN]
369  call file_set_attribute( fid, "global", "source" , source ) ! [IN]
370  call file_set_attribute( fid, "global", "institution", institution ) ! [IN]
371 
372  if ( ( .not. present(aggregate) ) .or. .not. aggregate ) then
373  ! for shared-file parallel I/O, skip attributes related to MPI processes
374  call file_set_attribute( fid, "global", "rankid" , (/rankid_/) ) ! [IN]
375  endif
376 
377  error = file_set_tunits_c( file_files(fid)%fid, & ! [IN]
378  cstr(time_units_), &
379  cstr(calendar_ ) ) ! [IN]
380 
381  if ( error /= file_success_code ) then
382  log_error("FILE_create",*) 'failed to set time units'
383  call prc_abort
384  endif
385 
386  call prof_rapend('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
387 
388  return

References scale_file_h::cstr(), 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, scale_prc::prc_abort(), scale_prof::prof_rapend(), and scale_prof::prof_rapstart().

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 463 of file scale_file.F90.

463  integer, intent(in) :: fid
464  character(len=*), intent(in) :: vname
465  logical, optional, intent(out) :: existed
466 
467  integer :: error
468 
469  if ( .not. file_opened(fid) ) then
470  log_error("FILE_add_associatedVariable",*) 'File is not opened. fid = ', fid
471  call prc_abort
472  end if
473 
474  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
475 
476  error = file_add_associatedvariable_c( file_files(fid)%fid, cstr(vname) ) ! (in)
477 
478  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
479 
480  if ( present(existed) ) then
481  if ( error == file_already_existed_code ) then
482  existed = .true.
483  return
484  end if
485  existed = .false.
486  end if
487 
488  if ( error /= file_success_code ) then
489  log_error("FILE_add_associatedvariable",*) 'failed to add associated variable: '//trim(vname)
490  call prc_abort
491  end if
492 
493  return

References scale_file_h::cstr(), file_add_associatedvariable_c(), scale_file_h::file_already_existed_code, file_opened(), scale_file_h::file_success_code, scale_prc::prc_abort(), scale_prof::prof_rapend(), and scale_prof::prof_rapstart().

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 500 of file scale_file.F90.

500  integer, intent(in) :: fid
501  character(len=*), intent(in) :: filetype
502  character(len=*), intent(in) :: key
503  character(len=*), intent(in) :: val
504 
505  integer :: error
506 
507  if ( .not. file_opened(fid) ) then
508  log_error("FILE_set_option",*) 'File is not opened. fid = ', fid
509  call prc_abort
510  end if
511 
512  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
513 
514  error = file_set_option_c( file_files(fid)%fid, cstr(filetype), cstr(key), cstr(val) ) ! (in)
515  if ( error /= file_success_code ) then
516  log_error("FILE_set_option",*) 'failed to set option'
517  call prc_abort
518  end if
519 
520  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
521 
522  return

References scale_file_h::cstr(), file_opened(), file_set_option_c(), scale_file_h::file_success_code, scale_prc::prc_abort(), scale_prof::prof_rapend(), and scale_prof::prof_rapstart().

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  allnodes,
logical, intent(in), optional  aggregate,
integer, intent(in), optional  rankid,
character(len=*), intent(in), optional  postfix 
)

Definition at line 535 of file scale_file.F90.

535  implicit none
536 
537  character(len=*), intent( in) :: basename
538  integer, intent(out) :: fid
539  integer, intent( in), optional :: mode
540  logical, intent( in), optional :: single
541  logical, intent( in), optional :: allnodes
542  logical, intent( in), optional :: aggregate
543  integer, intent( in), optional :: rankid
544  character(len=*), intent( in), optional :: postfix
545 
546  integer :: mode_
547  integer :: rankid_
548  logical :: existed
549  logical :: single_
550 
551  single_ = .false.
552 
553  if ( present(mode) ) then
554  mode_ = mode
555  else
556  mode_ = file_fread
557  end if
558 
559  if ( present(single) ) single_ = single
560  if ( present(rankid) ) then
561  rankid_ = rankid
562  else
563  rankid_ = mpi_myrank
564  end if
565 
566  call file_get_fid( basename, mode_, rankid_, single_, & ! (in)
567  fid, existed, & ! (out)
568  allnodes=allnodes, & ! (in)
569  aggregate=aggregate, postfix=postfix ) ! (in)
570 
571  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_finalize(), mod_realinput_netcdf::check_filetype(), scale_comm_cartesc_nest::comm_cartesc_nest_domain_regist_file(), 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_finalize(), scale_file_cartesc::file_cartesc_open(), file_def_variable(), scale_file_external_input::file_external_input_query(), scale_file_external_input::file_external_input_regist_file(), file_get_stepsize(), scale_land_grid_cartesc::land_grid_cartesc_finalize(), scale_land_grid_icoa::land_grid_icoa_finalize(), scale_ocean_grid_cartesc::ocean_grid_cartesc_finalize(), scale_ocean_grid_icoa::ocean_grid_icoa_setup(), mod_realinput_netcdf::parentatmosopennetcdf(), mod_realinput_nicam::parentatmosopennicam(), mod_realinput_netcdf::parentlandopennetcdf(), mod_realinput_netcdf::parentoceanopennetcdf(), scale_urban_grid_cartesc::urban_grid_cartesc_finalize(), and scale_urban_grid_icoa::urban_grid_icoa_finalize().

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 577 of file scale_file.F90.

577  implicit none
578 
579  integer, intent( in) :: fid
580  logical :: FILE_opened
581 
582  if ( fid < 1 ) then
583  file_opened = .false.
584  else
585  file_opened = file_files(fid)%fid >= 0
586  end if
587 
588  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)

check if the file is single

Definition at line 594 of file scale_file.F90.

594  implicit none
595 
596  integer, intent( in) :: fid
597  logical :: FILE_single
598 
599  if ( fid < 1 ) then
600  file_single = .false.
601  else
602  file_single = file_files(fid)%single
603  end if
604 
605  return

◆ file_allnodes()

logical function, public scale_file::file_allnodes ( 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 632 of file scale_file.F90.

632  integer, intent(in) :: fid
633  character(len=*), intent(in) :: dimname
634 
635  integer, intent(out) :: len
636 
637  logical, intent(out), optional :: error
638 
639  logical(c_bool) :: suppress
640  integer :: ierror
641 
642 
643  if ( .not. file_opened(fid) ) then
644  log_error("FILE_get_dimLength",*) 'File is not opened. fid = ', fid
645  call prc_abort
646  end if
647 
648  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
649 
650  if ( present(error) ) then
651  suppress = .true.
652  else
653  suppress = .false.
654  end if
655 
656  ierror = file_get_dim_length_c( len, & ! (out)
657  file_files(fid)%fid, & ! (in)
658  cstr(dimname), & ! (in)
659  suppress ) ! (in)
660  if ( ierror /= file_success_code .and. ierror /= file_already_existed_code ) then
661  if ( present(error) ) then
662  error = .true.
663  else
664  log_error("FILE_get_dimLength",*) 'failed to get dimension length'
665  call prc_abort
666  end if
667  else
668  if ( present(error) ) error = .false.
669  end if
670 
671  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
672 
673  return

References scale_file_h::cstr(), 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(), scale_prof::prof_rapend(), scale_prof::prof_rapstart(), and scale_precision::sp.

Referenced by mod_copytopo::copytopo_get_size_wrfarw(), mod_realinput_netcdf::parentatmossetupnetcdf(), mod_realinput_netcdf::parentlandsetupnetcdf(), and mod_realinput_netcdf::parentoceansetupnetcdf().

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 769 of file scale_file.F90.

769  integer, intent(in) :: fid
770  character(len=*), intent(in) :: name
771  character(len=*), intent(in) :: desc
772  character(len=*), intent(in) :: units
773  character(len=*), intent(in) :: dim_name
774  integer, intent(in) :: dtype
775  integer, intent(in) :: dim_size
776 
777  logical, intent(in), optional :: bounds
778 
779  integer :: error
780  integer :: bounds_
781 
782  bounds_ = 0 ! .false.
783  if ( present(bounds) ) then
784  if ( bounds ) bounds_ = 1 ! .true.
785  end if
786 
787  if ( .not. file_opened(fid) ) then
788  log_error("FILE_def_axis",*) 'File is not opened. fid = ', fid
789  call prc_abort
790  end if
791 
792  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
793 
794  error = file_def_axis_c( file_files(fid)%fid, & ! (in)
795  cstr(name), cstr(desc), cstr(units), & ! (in)
796  cstr(dim_name), dtype, dim_size, bounds_ ) ! (in)
797  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
798  log_error("FILE_def_axis",*) 'failed to define axis'
799  call prc_abort
800  end if
801 
802  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
803 
804  return

References scale_file_h::cstr(), 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(), i, scale_prc::prc_abort(), scale_prof::prof_rapend(), scale_prof::prof_rapstart(), 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 1471 of file scale_file.F90.

1471  integer, intent(in) :: fid
1472  character(len=*), intent(in) :: name
1473  character(len=*), intent(in) :: desc
1474  character(len=*), intent(in) :: units
1475  character(len=*), intent(in) :: dim_names(:)
1476  integer, intent(in) :: dtype
1477 
1478  type(c_ptr) :: dim_names_(size(dim_names))
1479 ! character(:,c_char), allocatable, target :: cptr(:)
1480  character(len=H_SHORT+1), allocatable, target :: cptr(:)
1481 
1482  integer :: error
1483  integer :: i
1484  intrinsic size, len
1485 
1486  if ( .not. file_opened(fid) ) then
1487  log_error("FILE_def_associatedCoordinate",*) 'File is not opened. fid = ', fid
1488  call prc_abort
1489  end if
1490 
1491  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1492 
1493  !allocate( character(len=len(dim_names)+1) :: cptr(size(dim_names)) )
1494  allocate( cptr(size(dim_names)) )
1495  do i = 1, size(dim_names)
1496  cptr(i) = cstr(dim_names(i))
1497  dim_names_(i) = c_loc(cptr(i))
1498  end do
1499 
1501  file_files(fid)%fid, & ! (in)
1502  cstr(name), cstr(desc), cstr(units), & ! (in)
1503  dim_names_, size(dim_names), dtype ) ! (in)
1504  if ( error /= file_success_code .and. error /= file_already_existed_code ) then
1505  log_error("FILE_def_associatedCoordinate",*) 'failed to define associated coordinate: '//trim(name)
1506  call prc_abort
1507  end if
1508 
1509  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
1510 
1511  return

References file_add_variable_c(), file_def_associatedcoordinate_c(), file_opened(), file_write_associatedcoordinate_c(), and i.

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,
character(len=*), intent(in), optional  time_stats,
logical, intent(out), optional  existed 
)

Definition at line 2380 of file scale_file.F90.

2380  integer, intent( in) :: fid
2381  character(len=*), intent( in) :: varname
2382  character(len=*), intent( in) :: desc
2383  character(len=*), intent( in) :: units
2384  character(len=*), intent( in) :: standard_name
2385  integer, intent( in) :: ndims
2386  character(len=*), intent( in) :: dims(:)
2387  integer, intent( in) :: dtype
2388  integer, intent(out) :: vid
2389  real(DP), intent( in), optional :: time_int
2390  character(len=*), intent( in), optional :: time_stats
2391  logical, intent(out), optional :: existed
2392 
2393  type(c_ptr) :: dims_(size(dims))
2394  !character(:,c_char), allocatable, target :: cptr(:)
2395  character(len=H_SHORT), allocatable, target :: cptr(:)
2396 
2397  character(len=4) :: ctstats
2398 
2399  real(DP) :: tint_
2400  integer :: cvid
2401  integer :: error
2402  integer :: n
2403 
2404  !---------------------------------------------------------------------------
2405 
2406  if ( .not. file_opened(fid) ) then
2407  log_error("FILE_def_variable",*) 'File is not opened. fid = ', fid
2408  call prc_abort
2409  end if
2410 
2411  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2412 
2413  vid = -1
2414  do n = 1, file_nvars
2415  if ( file_vars(n)%fid == fid .and. file_vars(n)%name == varname ) then
2416  vid = n
2417  end if
2418  enddo
2419 
2420  if ( vid < 0 ) then ! variable registration
2421 
2422  if ( present(time_int) ) then
2423  tint_ = time_int
2424  else
2425  tint_ = -1.0_dp
2426  endif
2427 
2428  ctstats = "none"
2429  if ( present(time_stats) ) then
2430  ctstats = time_stats
2431  end if
2432 
2433  !allocate( character(len=len(dims)+1) :: cptr(ndims) )
2434  allocate( cptr(ndims) )
2435  do n = 1, ndims
2436  cptr(n) = cstr(dims(n))
2437  dims_(n) = c_loc(cptr(n))
2438  end do
2439 
2440  error = file_add_variable_c( cvid, & ! [OUT]
2441  file_files(fid)%fid, & ! [IN]
2442  cstr(varname), cstr(desc), & ! [IN]
2443  cstr(units), cstr(standard_name), & ! [IN]
2444  dims_, ndims, dtype, tint_, cstr(ctstats) ) ! [IN]
2445 
2446  if ( error /= file_success_code ) then
2447  log_error("FILE_def_variable",*) 'failed to add variable: '//trim(varname)
2448  call prc_abort
2449  end if
2450 
2451  file_nvars = file_nvars + 1
2452  vid = file_nvars
2453  file_vars(vid)%name = varname
2454  file_vars(vid)%vid = cvid
2455  file_vars(vid)%fid = fid
2456 
2457  log_info("FILE_def_variable",'(1x,A,I3.3,A,I4.4,2A)') &
2458  'Variable registration : NO.', fid, ', vid = ', vid, ', name = ', trim(varname)
2459 
2460  if ( present(existed) ) existed = .false.
2461  else
2462  if ( present(existed) ) existed = .true.
2463  endif
2464 
2465  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
2466 
2467  return

References file_add_variable_c(), 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(), and file_set_attribute_text_c().

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 3334 of file scale_file.F90.

3334  integer, intent(in) :: fid
3335  character(len=*), intent(in) :: varname
3336 
3337  integer, intent(out) :: len
3338 
3339  logical, intent(out), optional :: error
3340 
3341  integer :: ierror
3342 
3343  if ( .not. file_opened(fid) ) then
3344  log_error("FILE_get_stepSize",*) 'File is not opened. fid = ', fid
3345  call prc_abort
3346  end if
3347 
3348  call prof_rapstart('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3349 
3350  ierror = file_get_step_size_c( len, & ! (out)
3351  file_files(fid)%fid, cstr(varname) ) ! (in)
3352  if ( ierror /= file_success_code .and. ierror /= file_already_existed_code ) then
3353  if ( present(error) ) then
3354  error = .true.
3355  else
3356  log_error("FILE_get_stepSize",*) 'failed to get number of steps'
3357  call prc_abort
3358  end if
3359  else
3360  if ( present(error) ) error = .false.
3361  end if
3362 
3363  call prof_rapend ('FILE_Read', 2, disable_barrier = .not. file_files(fid)%allnodes )
3364 
3365  return

References file_get_datainfo_c(), file_get_step_size_c(), file_open(), file_opened(), file_read_data_c(), file_write_data_c(), and i.

Here is the call graph for this function:

◆ file_enddef()

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

Definition at line 6060 of file scale_file.F90.

6060  implicit none
6061 
6062  integer, intent(in) :: fid
6063 
6064  integer :: error
6065  !---------------------------------------------------------------------------
6066 
6067  if ( .not. file_opened(fid) ) return
6068 
6069  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6070 
6071  error = file_enddef_c( file_files(fid)%fid )
6072 
6073  if ( error == file_success_code ) then
6074 
6075  log_newline
6076  log_info("FILE_enddef",'(1x,A,I3.3,2A)') &
6077  'End define mode : No.', fid, ', name = ', trim(file_files(fid)%name)
6078 
6079  else
6080  log_error("FILE_enddef",*) 'failed to exit define mode'
6081  call prc_abort
6082  end if
6083 
6084  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6085 
6086  return

References file_enddef_c(), and file_opened().

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 6092 of file scale_file.F90.

6092  implicit none
6093 
6094  integer, intent(in) :: fid
6095 
6096  integer :: error
6097  !---------------------------------------------------------------------------
6098 
6099  if ( .not. file_opened(fid) ) return
6100 
6101  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6102 
6103  error = file_redef_c( file_files(fid)%fid )
6104 
6105  if ( error == file_success_code ) then
6106 
6107  log_newline
6108  log_info("FILE_redef",'(1x,A,I3.3,2A)') &
6109  'Enter to define mode : No.', fid, ', name = ', trim(file_files(fid)%name)
6110 
6111  else
6112  log_error("FILE_redef",*) 'failed to enter to define mode'
6113  call prc_abort
6114  end if
6115 
6116  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6117 
6118  return

References file_opened(), and file_redef_c().

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 6126 of file scale_file.F90.

6126  implicit none
6127 
6128  integer, intent(in) :: fid
6129  integer(8), intent(in) :: buf_amount
6130 
6131  integer :: error
6132  !---------------------------------------------------------------------------
6133 
6134  if ( .not. file_opened(fid) ) return
6135 
6136  if ( file_files(fid)%buffer_size > 0 ) then
6137  call file_detach_buffer(fid)
6138  end if
6139 
6140  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6141 
6142  error = file_attach_buffer_c( file_files(fid)%fid, buf_amount )
6143 
6144  if ( error /= file_success_code ) then
6145  log_error("FILE_attach_buffer",*) 'failed to attach buffer in PnetCDF'
6146  call prc_abort
6147  end if
6148 
6149  log_newline
6150  log_info("FILE_attach_buffer",'(1x,A,I3.3,3A,I10)') &
6151  'Attach buffer : No.', fid, ', name = ', trim(file_files(fid)%name), &
6152  ', size = ', buf_amount
6153 
6154  file_files(fid)%buffer_size = buf_amount
6155 
6156  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6157 
6158  return

References file_attach_buffer_c(), file_detach_buffer(), and file_opened().

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 6164 of file scale_file.F90.

6164  implicit none
6165 
6166  integer, intent(in) :: fid
6167 
6168  integer :: error
6169  !---------------------------------------------------------------------------
6170 
6171  if ( .not. file_opened(fid) ) return
6172 
6173  if ( file_files(fid)%fid < 0 ) return ! already closed
6174 
6175  if ( file_files(fid)%buffer_size < 0 ) return ! not attached
6176 
6177  call prof_rapstart('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6178 
6179  error = file_detach_buffer_c( file_files(fid)%fid )
6180 
6181  if ( error /= file_success_code ) then
6182  log_error("FILE_detach_buffer",*) 'failed to detach buffer in PnetCDF'
6183  call prc_abort
6184  end if
6185 
6186  log_newline
6187  log_info("FILE_detach_buffer",'(1x,A,I3.3,2A)') &
6188  'Detach buffer : No.', fid, ', name = ', trim(file_files(fid)%name)
6189 
6190  file_files(fid)%buffer_size = -1
6191 
6192  call prof_rapend ('FILE_Write', 2, disable_barrier = .not. file_files(fid)%allnodes )
6193 
6194  return

References file_detach_buffer_c(), and file_opened().

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 6200 of file scale_file.F90.

6200  implicit none
6201 
6202  integer, intent(in) :: fid
6203 
6204  integer :: error
6205  !---------------------------------------------------------------------------
6206 
6207  if ( .not. file_opened(fid) ) return
6208 
6209  if ( file_files(fid)%fid < 0 ) return ! already closed
6210 
6211  call prof_rapstart('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6212 
6213  error = file_flush_c( file_files(fid)%fid )
6214 
6215  if ( error == file_success_code ) then
6216 
6217 !!$ LOG_NEWLINE
6218 !!$ LOG_INFO("FILE_flush",'(1xA,I3.3,2A)') &
6219 !!$ 'Flush : No.', fid, ', name = ', trim(FILE_files(fid)%name)
6220 
6221  else
6222  log_error("FILE_flush",*) 'failed to flush data to netcdf file'
6223  call prc_abort
6224  end if
6225 
6226  call prof_rapend ('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6227 
6228  return

References file_flush_c(), and file_opened().

Referenced by scale_file_cartesc::file_cartesc_close(), scale_file_cartesc::file_cartesc_enddef(), scale_file_cartesc::file_cartesc_flush(), 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 6233 of file scale_file.F90.

6233  implicit none
6234  integer, intent(in) :: fid
6235  logical, intent(in), optional :: abort
6236 
6237  logical(c_bool) :: abort_
6238  integer :: error
6239  integer :: n
6240  !---------------------------------------------------------------------------
6241 
6242  if ( .not. file_opened(fid) ) return
6243 
6244  if ( file_files(fid)%fid < 0 ) return ! already closed
6245 
6246  call prof_rapstart('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6247 
6248  if ( present(abort) ) then
6249  abort_ = abort
6250  else
6251  abort_ = .false.
6252  end if
6253 
6254  error = file_close_c( file_files(fid)%fid, abort_ )
6255 
6256  if ( error == file_success_code ) then
6257 
6258  log_newline
6259  log_info("FILE_close",'(1x,A,I3.3,2A)') &
6260  'Close : No.', fid, ', name = ', trim(file_files(fid)%name)
6261 
6262  elseif( error /= file_already_closed_code ) then
6263  log_error("FILE_close",*) 'failed to close file: ', trim(file_files(fid)%name)
6264  if ( .not. abort_ ) call prc_abort
6265  end if
6266 
6267  file_files(fid)%fid = -1
6268  file_files(fid)%name = ''
6269  file_files(fid)%aggregate = .false.
6270  file_files(fid)%buffer_size = -1
6271 
6272  do n = 1, file_nvars
6273  if ( file_vars(n)%fid == fid ) then
6274  file_vars(n)%vid = -1
6275  file_vars(n)%name = ''
6276  end if
6277  end do
6278 
6279  call prof_rapend ('FILE', 2, disable_barrier = .not. file_files(fid)%allnodes )
6280 
6281  return

References file_close_c(), and file_opened().

Referenced by scale_atmos_phy_rd_profile::atmos_phy_rd_profile_finalize(), 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 6286 of file scale_file.F90.

6286  implicit none
6287  logical, intent(in), optional :: skip_abort
6288 
6289  integer :: fid
6290  !---------------------------------------------------------------------------
6291 
6292  do fid = 1, file_nfiles
6293  call file_close( fid, skip_abort )
6294  enddo
6295 
6296  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_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 6303 of file scale_file.F90.

6303  implicit none
6304 
6305  integer, intent(in) :: date(6)
6306  character(len=*), intent(out) :: tunits
6307  !---------------------------------------------------------------------------
6308 
6309  write(tunits,'(a,i4.4,"-",i2.2,"-",i2.2," ",i2.2,":",i2.2,":",i2.2)') 'seconds since ', date
6310 
6311  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 6315 of file scale_file.F90.

6315  integer, intent(in) :: fid
6316  logical :: FILE_get_aggregate
6317 
6318  if ( .not. file_opened(fid) ) then
6319  file_get_aggregate = .false.
6320  else
6321  file_get_aggregate = file_files(fid)%aggregate
6322  end if
6323 
6324  return

References file_aggregate, file_open_c(), file_opened(), 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

◆ do

logical, public scale_file::do

Definition at line 196 of file scale_file.F90.

◆ parallel

logical, public scale_file::parallel

Definition at line 196 of file scale_file.F90.

◆ i

logical, public scale_file::i

◆ o

logical, public scale_file::o

Definition at line 196 of file scale_file.F90.

◆ through

logical, public scale_file::through

Definition at line 196 of file scale_file.F90.

◆ pnetcdf

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

Definition at line 196 of file scale_file.F90.

file_add_associatedvariable_c
int file_add_associatedvariable_c(const int fid, const char *vname)
Definition: scale_file_netcdf.c:1204
file_def_axis_c
int file_def_axis_c(const int fid, const char *name, const char *desc, const char *units, const char *dim_name, const int dtype, const int dim_size, const int bounds)
Definition: scale_file_netcdf.c:1286
file_detach_buffer_c
int file_detach_buffer_c(const int fid)
Definition: scale_file_netcdf.c:1854
scale_prc::prc_set_file_closer
subroutine, public prc_set_file_closer(routine)
Definition: scale_prc.F90:1001
file_get_dim_length_c
int file_get_dim_length_c(int *len, const int fid, const char *dimname, const bool suppress)
Definition: scale_file_netcdf.c:258
file_redef_c
int file_redef_c(const int fid)
Definition: scale_file_netcdf.c:1829
file_close_c
int file_close_c(const int fid, const bool abort)
Definition: scale_file_netcdf.c:2006
file_get_step_size_c
int file_get_step_size_c(int *len, const int fid, const char *varname)
Definition: scale_file_netcdf.c:643
scale_prc
module PROCESS
Definition: scale_prc.F90:11
file_attach_buffer_c
int file_attach_buffer_c(const int fid, const int64_t buf_amount)
Definition: scale_file_netcdf.c:1840
file_def_associatedcoordinate_c
int file_def_associatedcoordinate_c(const int fid, const char *name, const char *desc, const char *units, const char **dim_names, const int ndims, const int dtype)
Definition: scale_file_netcdf.c:1450
file_add_variable_c
int file_add_variable_c(int *vid, const int fid, const char *varname, const char *desc, const char *units, const char *stdname, const char **dims, const int ndims, const int dtype, const double tint, const char *tstats)
Definition: scale_file_netcdf.c:1550
file_set_tunits_c
int file_set_tunits_c(const int fid, const char *time_units, const char *calendar)
Definition: scale_file_netcdf.c:1227
file_set_option_c
int file_set_option_c(const int fid, const char *filetype, const char *key, const char *val)
Definition: scale_file_netcdf.c:287
file_enddef_c
int file_enddef_c(const int fid)
Definition: scale_file_netcdf.c:1818
file_flush_c
int file_flush_c(const int fid)
Definition: scale_file_netcdf.c:1867