TABLE OF CONTENTS


etsf_io_data_init

[ Top ] [ etsf_io_data_group ] [ Methods ]

NAME

etsf_io_data_init

FUNCTION

High-level routine to create an ETSF file.

INPUTS

OUTPUT

SIDE EFFECTS

NOTES

This file has been automatically generated by the autogen_subroutines.py script. Any change you would bring to it will systematically be overwritten.

SOURCE

subroutine etsf_io_data_init(filename, groups, dims, title, history, lstat, &
  & error_data, k_dependent, overwrite, split_definition)

  !Arguments ------------------------------------
  character(len=*), intent(in) :: filename
  type(etsf_groups_flags), intent(in) :: groups
  type(etsf_dims), intent(inout) :: dims
  character(len=*), intent(in) :: title
  character(len=*), intent(in) :: history
  logical, intent(out) :: lstat
  type(etsf_io_low_error), intent(out) :: error_data
  logical, optional, intent(in) :: k_dependent
  logical, optional, intent(in) :: overwrite
  type(etsf_split), optional, intent(in) :: split_definition
  !Local variables-------------------------------
  character(len=*),parameter :: my_name = 'etsf_io_data_init'
  integer :: ncid, i
  logical :: my_k_dependent
  logical :: my_overwrite
  type(etsf_split) :: my_split_definition


  ! *************************************************************************

!DEBUG
!write (*,*) 'etsf_io_data_init : enter'
!ENDDEBUG

  ! Get values for optional arguments, set default.
  if (present(k_dependent)) then
    my_k_dependent = k_dependent
  else
    my_k_dependent = .true.
  end if
  if (present(overwrite)) then
    my_overwrite = overwrite
  else
    my_overwrite = .false.
  end if
  if (present(split_definition)) then
    my_split_definition = split_definition
  end if
  
  ! Create the NetCDF file
  call etsf_io_low_open_create(ncid, filename, etsf_file_format_version, lstat, &
                             & title = trim(title), history = trim(history), &
                             & error_data = error_data, overwrite = my_overwrite)
  if (.not. lstat) then
    call etsf_io_low_error_update(error_data, my_name)
    return
  end if
  
  ! Define dimensions
  dims%character_string_length        = etsf_charlen
  dims%number_of_cartesian_directions = etsf_3dimlen
  dims%number_of_reduced_dimensions   = etsf_3dimlen
  dims%number_of_vectors              = etsf_3dimlen
  dims%symbol_length                  = etsf_chemlen
  
  ! We set the size of split arrays, if required.
  if (present(split_definition)) then
    call etsf_io_split_init(dims, split_definition)
  end if
  
  ! We write the dimensions to the file.
  call etsf_io_dims_def(ncid, dims, lstat, error_data)
  if (.not. lstat) then
    call etsf_io_low_error_update(error_data, my_name)
    return
  end if
  
  ! Define split arrays.
  if (present(split_definition)) then
    call etsf_io_split_def(ncid, dims, lstat, error_data)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  ! Define groups.
  if (groups%geometry /= etsf_geometry_none) then
    call etsf_io_geometry_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%geometry, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  if (groups%electrons /= etsf_electrons_none) then
    call etsf_io_electrons_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%electrons, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  if (groups%kpoints /= etsf_kpoints_none) then
    call etsf_io_kpoints_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%kpoints, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  if (groups%basisdata /= etsf_basisdata_none) then
    call etsf_io_basisdata_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%basisdata, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  if (groups%gwdata /= etsf_gwdata_none) then
    call etsf_io_gwdata_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%gwdata, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  if (groups%dielectric /= etsf_dielectric_none) then
    call etsf_io_dielectric_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%dielectric, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  if (groups%main /= etsf_main_none) then
    call etsf_io_main_def(ncid, lstat, error_data, &
                      & k_dependent = my_k_dependent, &
                      & flags = groups%main, &
                      & split = my_split_definition)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  
  ! Write the split arrays.
  if (present(split_definition)) then
    ! Begin by putting the file in write mode.
    call etsf_io_low_set_write_mode(ncid, lstat, error_data = error_data)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
    ! Write the arrays.
    call etsf_io_split_put(ncid, split_definition, lstat, error_data)
    if (.not. lstat) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  
  ! End definitions and close file
  call etsf_io_low_close(ncid, lstat, error_data = error_data)
  if (.not. lstat) then
    call etsf_io_low_error_update(error_data, my_name)
    return
  end if

!DEBUG
!write (*,*) 'etsf_io_data_init : exit'
!ENDDEBUG

end subroutine etsf_io_data_init