ETSF_IO library - documentation pages

### TABLE OF CONTENTS

- etsf_io_electrons_get

## etsf_io_electrons_get

[ Top ] [ etsf_electrons ] [ Methods ]

NAME

etsf_io_electrons_get

FUNCTION

Read an opened ETSF file to get data related to the given group. Only associated pointers of argument @folder will be accessed. If any accessed variable is missing, this routine returns an error (usually an access_mode_id of argument error_data set to ERROR_MODE_INQ). Any other errors implies a return with @lstat = .false..

INPUTS

- ncid = integer returned by an 'open' NetCDF call. The file can be either in define or write mode. This status can be changed by the call.
- use_atomic_units = (optional) set this flag to .true. makes the library use the value of the attribute scale_to_atomic_units to multiply the read variables (that are units dependent) by this factor (if different from 1.0d0).

OUTPUT

- lstat = return .true. if all the actions succeed, if not the status of the file is undefined.
- error_data <type(etsf_io_low_error)> = contains the details of the error is @lstat is false.

SIDE EFFECTS

- folder <type(etsf_electrons)> = an allocated structure with pointers on allocated areas in memory. These areas will be read or written if the pointer is associated, if not, the variable will be ignored. It is possible to access to specific dimensions of a variable using the <short_var_name>__kpoint_access or <short_var_name>__spin_access of this @folder structure. The <short_var_name>__number_of_<something> can also been set if only a subpart in one dimension should be accessed (this is possible when the specifications have been declared with a max_number_of_<something>.

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_electrons_get(ncid, folder, lstat, error_data, use_atomic_units)

      !Arguments ------------------------------------
      integer, intent(in) :: ncid
      type(etsf_electrons), intent(inout) :: folder
      logical, intent(out) :: lstat
      type(etsf_io_low_error), intent(out) :: error_data
      logical, optional, intent(in) :: use_atomic_units

      !Local variables-------------------------------
      character(len = *), parameter :: my_name = 'etsf_io_electrons_get'
      logical :: my_use_atomic_units
      integer,allocatable :: varid(:)
      integer,allocatable :: start(:)
      integer,allocatable :: count(:)
      integer :: len
      character(etsf_charlen) :: flag

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

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

      ! Get values for optional arguments, set default.
      if (present(use_atomic_units)) then
        my_use_atomic_units = use_atomic_units
      else
        my_use_atomic_units = .true.
      end if

      allocate(varid(9))

      if (associated(folder%number_of_electrons)) then
        call etsf_io_low_read_var(ncid, "number_of_electrons", &
                                & folder%number_of_electrons, &
                                & lstat, ncvarid = varid(1), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (associated(folder%exchange_functional)) then
        call etsf_io_low_read_var(ncid, "exchange_functional", &
                                & folder%exchange_functional, etsf_charlen, &
                                & lstat, ncvarid = varid(2), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (associated(folder%correlation_functional)) then
        call etsf_io_low_read_var(ncid, "correlation_functional", &
                                & folder%correlation_functional, etsf_charlen, &
                                & lstat, ncvarid = varid(3), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (associated(folder%fermi_energy)) then
        call etsf_io_low_read_var(ncid, "fermi_energy", &
                                & folder%fermi_energy, &
                                & lstat, ncvarid = varid(4), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (associated(folder%smearing_scheme)) then
        call etsf_io_low_read_var(ncid, "smearing_scheme", &
                                & folder%smearing_scheme, etsf_charlen, &
                                & lstat, ncvarid = varid(5), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (associated(folder%smearing_width)) then
        call etsf_io_low_read_var(ncid, "smearing_width", &
                                & folder%smearing_width, &
                                & lstat, ncvarid = varid(6), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (etsf_io_low_var_associated(folder%number_of_states)) then
        call etsf_io_low_read_var(ncid, "number_of_states", &
                                & folder%number_of_states, &
                                & lstat, ncvarid = varid(7), &
                                & error_data = error_data)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (etsf_io_low_var_associated(folder%eigenvalues)) then
        allocate(start(3), count(3))
        start(:) = 1
        count(:) = 0
        if (folder%eigenvalues__spin_access /= etsf_no_sub_access) then
          start(3) = folder%eigenvalues__spin_access
          count(3) = 1
        end if
        if (folder%eigenvalues__kpoint_access /= etsf_no_sub_access) then
          start(2) = folder%eigenvalues__kpoint_access
          count(2) = 1
        end if
        count(1) = folder%eigenvalues__number_of_states
        if (folder%eigenvalues__state_access /= etsf_no_sub_access) then
          start(1) = folder%eigenvalues__state_access
          count(1) = 1
        end if
        call etsf_io_low_read_var(ncid, "eigenvalues", &
                                & folder%eigenvalues, &
                                & lstat, ncvarid = varid(8), &
                                & error_data = error_data, start = start, count = count)
        deallocate(start, count)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      if (etsf_io_low_var_associated(folder%occupations)) then
        allocate(start(3), count(3))
        start(:) = 1
        count(:) = 0
        if (folder%occupations__spin_access /= etsf_no_sub_access) then
          start(3) = folder%occupations__spin_access
          count(3) = 1
        end if
        if (folder%occupations__kpoint_access /= etsf_no_sub_access) then
          start(2) = folder%occupations__kpoint_access
          count(2) = 1
        end if
        count(1) = folder%occupations__number_of_states
        if (folder%occupations__state_access /= etsf_no_sub_access) then
          start(1) = folder%occupations__state_access
          count(1) = 1
        end if
        call etsf_io_low_read_var(ncid, "occupations", &
                                & folder%occupations, &
                                & lstat, ncvarid = varid(9), &
                                & error_data = error_data, start = start, count = count)
        deallocate(start, count)
        if (.not. lstat) then
          call etsf_io_low_error_update(error_data, my_name)
          return
        end if
      end if

      ! Handle all attributes for the group.
      if (associated(folder%fermi_energy)) then
        ! Handle the units attribute.
        call etsf_io_low_read_att(ncid, varid(4), &
                                & "units", &
                                & etsf_charlen, folder%fermi_energy__units, &
                                & lstat, error_data = error_data)
        if (.not. lstat) return
        if (trim(folder%fermi_energy__units) /= "atomic units") then
          call etsf_io_low_read_att(ncid, varid(4), &
                                  & "scale_to_atomic_units", &
                                  & folder%fermi_energy__scale_to_atomic_units, &
                                  & lstat, error_data = error_data)
          if (.not. lstat) return
        else
          folder%fermi_energy__scale_to_atomic_units = 1.0d0
        end if
        if (my_use_atomic_units .and. &
          & folder%fermi_energy__scale_to_atomic_units /= 1.0d0) then
          folder%fermi_energy = folder%fermi_energy * &
            & folder%fermi_energy__scale_to_atomic_units
        end if
      end if

      if (associated(folder%smearing_width)) then
        ! Handle the units attribute.
        call etsf_io_low_read_att(ncid, varid(6), &
                                & "units", &
                                & etsf_charlen, folder%smearing_width__units, &
                                & lstat, error_data = error_data)
        if (.not. lstat) return
        if (trim(folder%smearing_width__units) /= "atomic units") then
          call etsf_io_low_read_att(ncid, varid(6), &
                                  & "scale_to_atomic_units", &
                                  & folder%smearing_width__scale_to_atomic_units, &
                                  & lstat, error_data = error_data)
          if (.not. lstat) return
        else
          folder%smearing_width__scale_to_atomic_units = 1.0d0
        end if
        if (my_use_atomic_units .and. &
          & folder%smearing_width__scale_to_atomic_units /= 1.0d0) then
          folder%smearing_width = folder%smearing_width * &
            & folder%smearing_width__scale_to_atomic_units
        end if
      end if

      if (etsf_io_low_var_associated(folder%eigenvalues)) then
        ! Handle the units attribute.
        call etsf_io_low_read_att(ncid, varid(8), &
                                & "units", &
                                & etsf_charlen, folder%eigenvalues__units, &
                                & lstat, error_data = error_data)
        if (.not. lstat) return
        if (trim(folder%eigenvalues__units) /= "atomic units") then
          call etsf_io_low_read_att(ncid, varid(8), &
                                  & "scale_to_atomic_units", &
                                  & folder%eigenvalues__scale_to_atomic_units, &
                                  & lstat, error_data = error_data)
          if (.not. lstat) return
        else
          folder%eigenvalues__scale_to_atomic_units = 1.0d0
        end if
        if (my_use_atomic_units .and. &
          & folder%eigenvalues__scale_to_atomic_units /= 1.0d0) then
          call etsf_io_low_var_multiply(folder%eigenvalues, &
                                      & folder%eigenvalues__scale_to_atomic_units)
        end if
      end if

      deallocate(varid)

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

    end subroutine etsf_io_electrons_get