TABLE OF CONTENTS


etsf_io_main_def

[ Top ] [ etsf_main ] [ Methods ]

NAME

etsf_io_main_def

FUNCTION

The given ETSF file must be opened and in define state (see etsf_io_low_set_define_mode() to change it). Then, all variable of the group are defined. All required dimensions must have already defined (see etsf_io_dims_def(). If some dimensions are missing, then the variable is not defined and no error are generated.

One can specify which variable may be splitted using the optional argument @split. For each associated array in this structure, variable with appropriated dimensions will use my_<something> instead of <something>.

INPUTS

OUTPUT

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_main_def(ncid, lstat, error_data, k_dependent, flags, split)

  !Arguments ------------------------------------
  integer, intent(in) :: ncid
  logical, intent(out) :: lstat
  type(etsf_io_low_error), intent(out) :: error_data
  logical, optional, intent(in) :: k_dependent
  integer, optional, intent(in) :: flags
  type(etsf_split), optional, intent(in) :: split

  !Local variables-------------------------------
  character(len = *), parameter :: my_name = 'etsf_io_main_def'
  logical :: my_k_dependent
  integer :: my_flags
  type(etsf_split) :: my_split
  integer :: ivar
  type(split_dim_names) :: split_dims


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

!DEBUG
!write (*,*) 'etsf_io_main_def : 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(flags)) then
    my_flags = flags
  else
    my_flags = etsf_main_all
  end if
  ! Consistency checks.
  if (my_flags < etsf_main_none .or. my_flags > etsf_main_all) then
    call etsf_io_low_error_set(error_data, ERROR_MODE_DEF, ERROR_TYPE_ARG, my_name, &
                             & tgtname = "flags", errmess = "value out of bounds")
    lstat = .false.
    return
  end if
  
  ! Set the name for dimensions that could be splitted.
  if (present(split)) then
    if (associated(split%my_kpoints)) then
      write(split_dims%number_of_kpoints, "(A)") &
        & "my_number_of_kpoints"
    end if
    if (associated(split%my_grid_points_vector3)) then
      write(split_dims%number_of_grid_points_vector3, "(A)") &
        & "my_number_of_grid_points_vector3"
    end if
    if (associated(split%my_spins)) then
      write(split_dims%number_of_spins, "(A)") &
        & "my_number_of_spins"
    end if
    if (associated(split%my_grid_points_vector1)) then
      write(split_dims%number_of_grid_points_vector1, "(A)") &
        & "my_number_of_grid_points_vector1"
    end if
    if (associated(split%my_grid_points_vector2)) then
      write(split_dims%number_of_grid_points_vector2, "(A)") &
        & "my_number_of_grid_points_vector2"
    end if
    if (associated(split%my_coefficients)) then
      write(split_dims%max_number_of_coefficients, "(A)") &
        & "my_max_number_of_coefficients"
    end if
    if (associated(split%my_components)) then
      write(split_dims%number_of_components, "(A)") &
        & "my_number_of_components"
    end if
    if (associated(split%my_states)) then
      write(split_dims%max_number_of_states, "(A)") &
        & "my_max_number_of_states"
    end if
  end if
  
  if (iand(my_flags, etsf_main_density) /= 0) then
    call etsf_io_low_def_var(ncid, "density", &
      & etsf_io_low_double, &
      & (/ pad("real_or_complex_density"), &
      &    split_dims%number_of_grid_points_vector1, &
      &    split_dims%number_of_grid_points_vector2, &
      &    split_dims%number_of_grid_points_vector3, &
      &    split_dims%number_of_components /), &
      & lstat, ncvarid = ivar, error_data = error_data)
    ! We raise don't raise an error if a dimension is missing.
    if (.not. lstat .and. (error_data%access_mode_id /= ERROR_MODE_INQ .or. &
      & error_data%target_type_id /= ERROR_TYPE_DID)) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
    if (ivar >= 0) then
      ! Handle the units attribute.
      call etsf_io_low_write_att(ncid, ivar, &
                              & "units", &
                              & "atomic units", &
                              & lstat, error_data = error_data)
      if (.not. lstat) return
      call etsf_io_low_write_att(ncid, ivar, &
                              & "scale_to_atomic_units", &
                              & 1.0d0, &
                              & lstat, error_data = error_data)
      if (.not. lstat) then
        call etsf_io_low_error_update(error_data, my_name)
        return
      end if
    end if
  end if
  
  if (iand(my_flags, etsf_main_pot_x_only) /= 0) then
    call etsf_io_low_def_var(ncid, "exchange_potential", &
      & etsf_io_low_double, &
      & (/ pad("real_or_complex_potential"), &
      &    split_dims%number_of_grid_points_vector1, &
      &    split_dims%number_of_grid_points_vector2, &
      &    split_dims%number_of_grid_points_vector3, &
      &    split_dims%number_of_components /), &
      & lstat, ncvarid = ivar, error_data = error_data)
    ! We raise don't raise an error if a dimension is missing.
    if (.not. lstat .and. (error_data%access_mode_id /= ERROR_MODE_INQ .or. &
      & error_data%target_type_id /= ERROR_TYPE_DID)) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
    if (ivar >= 0) then
      ! Handle the units attribute.
      call etsf_io_low_write_att(ncid, ivar, &
                              & "units", &
                              & "atomic units", &
                              & lstat, error_data = error_data)
      if (.not. lstat) return
      call etsf_io_low_write_att(ncid, ivar, &
                              & "scale_to_atomic_units", &
                              & 1.0d0, &
                              & lstat, error_data = error_data)
      if (.not. lstat) then
        call etsf_io_low_error_update(error_data, my_name)
        return
      end if
    end if
  end if
  
  if (iand(my_flags, etsf_main_pot_c_only) /= 0) then
    call etsf_io_low_def_var(ncid, "correlation_potential", &
      & etsf_io_low_double, &
      & (/ pad("real_or_complex_potential"), &
      &    split_dims%number_of_grid_points_vector1, &
      &    split_dims%number_of_grid_points_vector2, &
      &    split_dims%number_of_grid_points_vector3, &
      &    split_dims%number_of_components /), &
      & lstat, ncvarid = ivar, error_data = error_data)
    ! We raise don't raise an error if a dimension is missing.
    if (.not. lstat .and. (error_data%access_mode_id /= ERROR_MODE_INQ .or. &
      & error_data%target_type_id /= ERROR_TYPE_DID)) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
    if (ivar >= 0) then
      ! Handle the units attribute.
      call etsf_io_low_write_att(ncid, ivar, &
                              & "units", &
                              & "atomic units", &
                              & lstat, error_data = error_data)
      if (.not. lstat) return
      call etsf_io_low_write_att(ncid, ivar, &
                              & "scale_to_atomic_units", &
                              & 1.0d0, &
                              & lstat, error_data = error_data)
      if (.not. lstat) then
        call etsf_io_low_error_update(error_data, my_name)
        return
      end if
    end if
  end if
  
  if (iand(my_flags, etsf_main_pot_xc) /= 0) then
    call etsf_io_low_def_var(ncid, "exchange_correlation_potential", &
      & etsf_io_low_double, &
      & (/ pad("real_or_complex_potential"), &
      &    split_dims%number_of_grid_points_vector1, &
      &    split_dims%number_of_grid_points_vector2, &
      &    split_dims%number_of_grid_points_vector3, &
      &    split_dims%number_of_components /), &
      & lstat, ncvarid = ivar, error_data = error_data)
    ! We raise don't raise an error if a dimension is missing.
    if (.not. lstat .and. (error_data%access_mode_id /= ERROR_MODE_INQ .or. &
      & error_data%target_type_id /= ERROR_TYPE_DID)) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
    if (ivar >= 0) then
      ! Handle the units attribute.
      call etsf_io_low_write_att(ncid, ivar, &
                              & "units", &
                              & "atomic units", &
                              & lstat, error_data = error_data)
      if (.not. lstat) return
      call etsf_io_low_write_att(ncid, ivar, &
                              & "scale_to_atomic_units", &
                              & 1.0d0, &
                              & lstat, error_data = error_data)
      if (.not. lstat) then
        call etsf_io_low_error_update(error_data, my_name)
        return
      end if
    end if
  end if
  
  if (iand(my_flags, etsf_main_wfs_coeff) /= 0) then
    call etsf_io_low_def_var(ncid, "coefficients_of_wavefunctions", &
      & etsf_io_low_double, &
      & (/ pad("real_or_complex_coefficients"), &
      &    split_dims%max_number_of_coefficients, &
      &    pad("number_of_spinor_components"), &
      &    split_dims%max_number_of_states, &
      &    split_dims%number_of_kpoints, &
      &    split_dims%number_of_spins /), &
      & lstat, ncvarid = ivar, error_data = error_data)
    ! We raise don't raise an error if a dimension is missing.
    if (.not. lstat .and. (error_data%access_mode_id /= ERROR_MODE_INQ .or. &
      & error_data%target_type_id /= ERROR_TYPE_DID)) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  
  if (iand(my_flags, etsf_main_wfs_rsp) /= 0) then
    call etsf_io_low_def_var(ncid, "real_space_wavefunctions", &
      & etsf_io_low_double, &
      & (/ pad("real_or_complex_wavefunctions"), &
      &    split_dims%number_of_grid_points_vector1, &
      &    split_dims%number_of_grid_points_vector2, &
      &    split_dims%number_of_grid_points_vector3, &
      &    pad("number_of_spinor_components"), &
      &    split_dims%max_number_of_states, &
      &    split_dims%number_of_kpoints, &
      &    split_dims%number_of_spins /), &
      & lstat, ncvarid = ivar, error_data = error_data)
    ! We raise don't raise an error if a dimension is missing.
    if (.not. lstat .and. (error_data%access_mode_id /= ERROR_MODE_INQ .or. &
      & error_data%target_type_id /= ERROR_TYPE_DID)) then
      call etsf_io_low_error_update(error_data, my_name)
      return
    end if
  end if
  ! If we reach the end, then it should be OK.
  lstat = .true.


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

end subroutine etsf_io_main_def