mirror of https://gitlab.com/QEF/q-e.git
added interface for logical attributes in hdf5 files, modified the interface for chararters. Logical attributes are now written directly without translation to integers
git-svn-id: http://qeforge.qe-forge.org/svn/q-e/trunk/espresso@13402 c92efa57-630b-4861-b058-cf58834340f0
This commit is contained in:
parent
dc74716e8b
commit
af63d37fc6
|
@ -8,7 +8,7 @@
|
|||
module hdf5_qe
|
||||
!
|
||||
USE HDF5
|
||||
!USE, intrinsic :: ISO_C_binding
|
||||
USE, intrinsic :: ISO_C_binding
|
||||
USE Kinds, ONLY : DP
|
||||
!
|
||||
implicit none
|
||||
|
@ -46,11 +46,12 @@ module hdf5_qe
|
|||
|
||||
INTERFACE add_attributes_hdf5
|
||||
MODULE PROCEDURE add_attributes_hdf5_i, add_attributes_hdf5_r, &
|
||||
add_attributes_hdf5_c
|
||||
add_attributes_hdf5_c, add_attributes_hdf5_boolean
|
||||
END INTERFACE
|
||||
|
||||
INTERFACE read_attributes_hdf5
|
||||
MODULE PROCEDURE read_attributes_hdf5_i, read_attributes_hdf5_r
|
||||
MODULE PROCEDURE read_attributes_hdf5_i, read_attributes_hdf5_r, read_attributes_hdf5_c, &
|
||||
read_attributes_hdf5_boolean
|
||||
END INTERFACE
|
||||
|
||||
|
||||
|
@ -751,58 +752,105 @@ module hdf5_qe
|
|||
END SUBROUTINE add_attributes_hdf5_r
|
||||
|
||||
SUBROUTINE add_attributes_hdf5_c(hdf5desc, attr_data, attr_name, kpoint)
|
||||
implicit none
|
||||
IMPLICIT NONE
|
||||
TYPE(HDF5_type), intent(inout) :: hdf5desc
|
||||
integer, intent(in), optional :: kpoint
|
||||
!LOGICAL, intent(in) :: attr_data
|
||||
CHARACTER(LEN=*), intent(in) :: attr_data
|
||||
INTEGER, INTENT(IN), OPTIONAL :: kpoint
|
||||
CHARACTER(LEN=*),TARGET, INTENT(IN) :: attr_data
|
||||
CHARACTER(LEN=*), intent(in) :: attr_name
|
||||
character*100 kstring
|
||||
integer :: error
|
||||
CHARACTER*100 kstring
|
||||
INTEGER :: error
|
||||
INTEGER :: arank = 1 ! Attribure rank
|
||||
INTEGER(HID_T) :: aspace_id ! Attribute Dataspace identifier
|
||||
INTEGER(HSIZE_T), DIMENSION(1) :: adims = (/1/) ! Attribute dimension
|
||||
INTEGER(SIZE_T) :: attrlen ! Length of the attribute string
|
||||
INTEGER(HSIZE_T) :: attrlen ! Length of the attribute string
|
||||
INTEGER(HID_T) :: atype_id ! Attribute Dataspace identifier
|
||||
INTEGER(HID_T) :: attr_id ! Attribute Dataspace identifier
|
||||
INTEGER(HSIZE_T), DIMENSION(1) :: data_dims
|
||||
|
||||
!data_dims(1) = 1
|
||||
data_dims(1) = len(attr_data)
|
||||
|
||||
if(present(kpoint)) then
|
||||
write(kstring,'(I0)') kpoint
|
||||
TYPE(C_PTR) :: buf
|
||||
!
|
||||
buf = C_LOC(attr_data)
|
||||
attrlen = LEN(TRIM(attr_data) )
|
||||
CALL H5Screate_f( H5S_SCALAR_F, aspace_id, error)
|
||||
CALL H5Tcopy_f ( H5T_FORTRAN_S1, atype_id, error )
|
||||
CALL H5Tset_size_f( atype_id, attrlen, error)
|
||||
|
||||
IF(PRESENT(kpoint)) THEN
|
||||
WRITE(kstring,'(I0)') kpoint
|
||||
kstring='KPOINT'//kstring
|
||||
!write(attrdata,'(I0)') attr_data
|
||||
|
||||
CALL h5tcopy_f(H5T_NATIVE_CHARACTER, atype_id, error)
|
||||
CALL h5gopen_f(hdf5desc%file_id,kstring,hdf5desc%group_id,error)
|
||||
CALL h5screate_simple_f(arank, adims, aspace_id, error)
|
||||
CALL h5acreate_f(hdf5desc%group_id, attr_name, H5T_NATIVE_CHARACTER, aspace_id, attr_id, error)
|
||||
CALL h5awrite_f(attr_id, H5T_NATIVE_CHARACTER, attr_data, data_dims, error)
|
||||
CALL h5acreate_f(hdf5desc%group_id, attr_name, atype_id, aspace_id, attr_id, error)
|
||||
CALL h5awrite_f(attr_id, atype_id, buf, error)
|
||||
CALL h5aclose_f(attr_id, error)
|
||||
!
|
||||
! Terminate access to the data space.
|
||||
!
|
||||
CALL h5sclose_f(aspace_id, error)
|
||||
!
|
||||
! End access to the dataset and release resources used by it.
|
||||
!
|
||||
CALL h5gclose_f(hdf5desc%group_id, error)
|
||||
else
|
||||
ELSE
|
||||
!write(attrdata,'(I0)') attr_data
|
||||
CALL h5tcopy_f(H5T_NATIVE_CHARACTER, atype_id, error)
|
||||
CALL h5screate_simple_f(arank, adims, aspace_id, error)
|
||||
CALL h5acreate_f(hdf5desc%file_id, attr_name, H5T_NATIVE_CHARACTER, aspace_id, attr_id, error)
|
||||
CALL h5awrite_f(attr_id, H5T_NATIVE_CHARACTER, attr_data, data_dims, error)
|
||||
CALL h5acreate_f(hdf5desc%file_id, attr_name, atype_id, aspace_id, attr_id, error)
|
||||
CALL h5awrite_f(attr_id, atype_id, buf, error)
|
||||
CALL h5aclose_f(attr_id, error)
|
||||
!
|
||||
! Terminate access to the data space.
|
||||
!
|
||||
CALL h5sclose_f(aspace_id, error)
|
||||
endif
|
||||
|
||||
ENDIF
|
||||
CALL H5Sclose_f(aspace_id, error)
|
||||
CALL H5Tclose_f(atype_id, error )
|
||||
END SUBROUTINE add_attributes_hdf5_c
|
||||
!
|
||||
SUBROUTINE add_attributes_hdf5_boolean(hdf5desc, attr_data, attr_name, kpoint)
|
||||
IMPLICIT NONE
|
||||
TYPE(HDF5_type), intent(inout) :: hdf5desc
|
||||
INTEGER, INTENT(IN), OPTIONAL :: kpoint
|
||||
LOGICAL,INTENT(IN) :: attr_data
|
||||
CHARACTER(LEN=*), intent(in) :: attr_name
|
||||
CHARACTER*100 kstring
|
||||
INTEGER :: error
|
||||
INTEGER :: arank = 1 ! Attribure rank
|
||||
INTEGER(HID_T) :: aspace_id ! Attribute Dataspace identifier
|
||||
INTEGER(HSIZE_T) :: attrlen ! Length of the attribute string
|
||||
INTEGER(HID_T) :: atype_id ! Attribute Dataspace identifier
|
||||
INTEGER(HID_T) :: attr_id ! Attribute Dataspace identifier
|
||||
CHARACTER(LEN=7),TARGET :: string_data
|
||||
TYPE(C_PTR) :: buf
|
||||
!
|
||||
IF (attr_data) THEN
|
||||
string_data = '.TRUE.'
|
||||
ELSE
|
||||
string_data ='.FALSE.'
|
||||
END IF
|
||||
buf = C_LOC(string_data)
|
||||
attrlen = LEN(TRIM(string_data) )
|
||||
CALL H5Screate_f( H5S_SCALAR_F, aspace_id, error)
|
||||
CALL H5Tcopy_f ( H5T_FORTRAN_S1, atype_id, error )
|
||||
CALL H5Tset_size_f( atype_id, attrlen, error)
|
||||
|
||||
IF(PRESENT(kpoint)) THEN
|
||||
WRITE(kstring,'(I0)') kpoint
|
||||
kstring='KPOINT'//kstring
|
||||
!write(attrdata,'(I0)') attr_data
|
||||
|
||||
CALL h5gopen_f(hdf5desc%file_id,kstring,hdf5desc%group_id,error)
|
||||
CALL h5acreate_f(hdf5desc%group_id, attr_name, atype_id, aspace_id, attr_id, error)
|
||||
CALL h5awrite_f(attr_id, atype_id, buf, error)
|
||||
CALL h5aclose_f(attr_id, error)
|
||||
!
|
||||
! End access to the dataset and release resources used by it.
|
||||
!
|
||||
CALL h5gclose_f(hdf5desc%group_id, error)
|
||||
ELSE
|
||||
!write(attrdata,'(I0)') attr_data
|
||||
CALL h5acreate_f(hdf5desc%file_id, attr_name, atype_id, aspace_id, attr_id, error)
|
||||
CALL h5awrite_f(attr_id, atype_id, buf, error)
|
||||
CALL h5aclose_f(attr_id, error)
|
||||
!
|
||||
! Terminate access to the data space.
|
||||
!
|
||||
ENDIF
|
||||
CALL H5Sclose_f(aspace_id, error)
|
||||
CALL H5Tclose_f(atype_id, error )
|
||||
END SUBROUTINE add_attributes_hdf5_boolean
|
||||
|
||||
|
||||
|
||||
SUBROUTINE read_attributes_hdf5_i(hdf5desc, attr_data, attr_name, kpoint, debug)
|
||||
|
@ -840,6 +888,77 @@ module hdf5_qe
|
|||
|
||||
END SUBROUTINE read_attributes_hdf5_i
|
||||
|
||||
SUBROUTINE read_attributes_hdf5_c(hdf5desc, attr_data, attr_name, kpoint, debug)
|
||||
implicit none
|
||||
TYPE(HDF5_type), intent(inout) :: hdf5desc
|
||||
integer, intent(in), optional :: kpoint, debug
|
||||
CHARACTER(LEN=*),INTENT(OUT) :: attr_data
|
||||
CHARACTER(LEN=*), intent(in) :: attr_name
|
||||
character*12 kstring
|
||||
integer :: error
|
||||
INTEGER(HID_T) :: aspace_id ! Attribute Dataspace identifier
|
||||
INTEGER(HSIZE_T) :: attrlen ! Length of the attribute string
|
||||
INTEGER(HID_T) :: atype_id ! Attribute Dataspace identifier
|
||||
INTEGER(HID_T) :: attr_id ! Attribute Dataspace identifier
|
||||
CHARACTER,TARGET,ALLOCATABLE :: chars(:)
|
||||
TYPE(C_PTR) :: buf
|
||||
|
||||
IF(PRESENT( kpoint )) THEN
|
||||
WRITE(kstring,'(I0)') kpoint
|
||||
kstring='KPOINT'//kstring
|
||||
CALL H5Gopen_f(hdf5desc%file_id,kstring,hdf5desc%group_id,error)
|
||||
CALL H5Aopen_by_name_f(hdf5desc%group_id,'.', TRIM(attr_name) , attr_id, error)
|
||||
CALL extract_string
|
||||
CALL H5Aclose_f(attr_id, error)
|
||||
CALL H5Gclose_f(hdf5desc%group_id, error)
|
||||
ELSE
|
||||
CALL h5aopen_by_name_f(hdf5desc%file_id,'.',TRIM(attr_name), attr_id, error)
|
||||
CALL extract_string
|
||||
CALL h5aclose_f(attr_id, error)
|
||||
ENDIF
|
||||
CALL H5Tclose_f( atype_id, error )
|
||||
CONTAINS
|
||||
SUBROUTINE extract_string
|
||||
IMPLICIT NONE
|
||||
INTEGER :: i
|
||||
CALL H5Aget_type_f (attr_id , atype_id, error )
|
||||
CALL H5Tget_size_f (atype_id, attrlen, error )
|
||||
IF ( attrlen .GT. LEN(attr_data) ) CALL infomsg ('read_attributes_hdf5',&
|
||||
'string attribute on file too long, it will be truncated on reading')
|
||||
ALLOCATE ( chars(attrlen) )
|
||||
buf = C_LOC (chars)
|
||||
CALL H5Aread_f( attr_id, atype_id, buf, error )
|
||||
DO i =1, attrlen
|
||||
IF ( i .GT. LEN( attr_data) ) EXIT
|
||||
attr_data(i:i) = chars(i)
|
||||
END DO
|
||||
DEALLOCATE(chars)
|
||||
buf = C_NULL_PTR
|
||||
END SUBROUTINE extract_string
|
||||
END SUBROUTINE read_attributes_hdf5_c
|
||||
|
||||
SUBROUTINE read_attributes_hdf5_boolean( hdf5desc, attr_data, attr_name, kpoint, debug)
|
||||
IMPLICIT NONE
|
||||
TYPE(HDF5_type), intent(inout) :: hdf5desc
|
||||
INTEGER, INTENT(IN), OPTIONAL :: kpoint, debug
|
||||
LOGICAL,INTENT(OUT) :: attr_data
|
||||
CHARACTER(LEN=*), intent(in) :: attr_name
|
||||
!
|
||||
CHARACTER(LEN=10) :: attr_string
|
||||
CALL read_attributes_hdf5_c( hdf5desc, attr_string, attr_name, kpoint, debug)
|
||||
SELECT CASE (TRIM( attr_string) )
|
||||
CASE ('.TRUE.' )
|
||||
attr_data = .TRUE.
|
||||
CASE ('.FALSE.')
|
||||
attr_data = .FALSE.
|
||||
CASE DEFAULT
|
||||
attr_data = .FALSE.
|
||||
CALL infomsg ( 'read_attributes_hdf5' , 'error reading attribute '//TRIM(attr_name)//' value set to .FALSE.')
|
||||
END SELECT
|
||||
END SUBROUTINE read_attributes_hdf5_boolean
|
||||
|
||||
|
||||
|
||||
SUBROUTINE read_attributes_hdf5_r(hdf5desc, attr_data, attr_name, kpoint)
|
||||
implicit none
|
||||
TYPE(HDF5_type), intent(inout) :: hdf5desc
|
||||
|
@ -889,10 +1008,8 @@ module hdf5_qe
|
|||
LOGICAL, INTENT(IN) :: gamma_only
|
||||
INTEGER, INTENT(IN) :: nbnd, ngw, igwx
|
||||
TYPE(HDF5_type), intent(inout) :: hdf5desc
|
||||
integer :: gammaonly = 0
|
||||
CALL add_attributes_hdf5(hdf5desc,ngw,"ngw",ik)
|
||||
IF ( gamma_only) gammaonly = 1
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,gammaonly,"gamma_only",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,gamma_only,"gamma_only",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,igwx,"igwx",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,nbnd,"nbnd",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,ik,"ik",ik)
|
||||
|
|
|
@ -63,7 +63,6 @@ MODULE io_base
|
|||
INTEGER :: me_in_group, nproc_in_group, my_group
|
||||
COMPLEX(DP), ALLOCATABLE :: wtmp(:)
|
||||
!
|
||||
INTEGER :: gammaonly
|
||||
#if defined(__HDF5)
|
||||
TYPE (hdf5_type),ALLOCATABLE :: h5_write_desc
|
||||
!
|
||||
|
@ -86,9 +85,7 @@ MODULE io_base
|
|||
CALL prepare_for_writing_final ( h5_write_desc, 0, &
|
||||
TRIM(filename)//'.hdf5',ik, ADD_GROUP = .false.)
|
||||
CALL add_attributes_hdf5(h5_write_desc, ngw,"ngw",ik)
|
||||
gammaonly = 0
|
||||
IF (gamma_only) gammaonly = 1
|
||||
CALL add_attributes_hdf5(h5_write_desc, gammaonly,"gamma_only",ik)
|
||||
CALL add_attributes_hdf5(h5_write_desc, gamma_only,"gamma_only",ik)
|
||||
CALL add_attributes_hdf5(h5_write_desc, igwx,"igwx",ik)
|
||||
CALL add_attributes_hdf5(h5_write_desc, nbnd,"nbnd",ik)
|
||||
CALL add_attributes_hdf5(h5_write_desc, ik,"ik",ik)
|
||||
|
|
|
@ -1078,8 +1078,6 @@ CONTAINS
|
|||
CHARACTER(*), INTENT(in) :: cutoff_units
|
||||
#if defined __HDF5
|
||||
CHARACTER(LEN=256) :: filename_hdf5
|
||||
CHARACTER :: gammaonly
|
||||
!integer :: gammaonly, ierr
|
||||
integer :: ierr
|
||||
#endif
|
||||
|
||||
|
@ -1091,12 +1089,7 @@ CONTAINS
|
|||
CALL add_attributes_hdf5(g_hdf5_write,ecutwfc,"WFC_CUTOFF")
|
||||
CALL add_attributes_hdf5(g_hdf5_write,ecutrho,"RHO_CUTOFF")
|
||||
CALL add_attributes_hdf5(g_hdf5_write,npwx,"MAX_NUMBER_OF_GK-VECTORS")
|
||||
IF ( gamma_only) THEN
|
||||
write(gammaonly,'(I1)') 1
|
||||
ELSE
|
||||
write(gammaonly,'(I1)') 0
|
||||
END IF
|
||||
CALL add_attributes_hdf5(g_hdf5_write,gammaonly,"GAMMA_ONLY")
|
||||
CALL add_attributes_hdf5(g_hdf5_write,gamma_only,"GAMMA_ONLY")
|
||||
CALL add_attributes_hdf5(g_hdf5_write,trim(cutoff_units),"UNITS_FOR_CUTOFF")
|
||||
CALL add_attributes_hdf5(g_hdf5_write,nr1,"nr1")
|
||||
CALL add_attributes_hdf5(g_hdf5_write,nr2,"nr2")
|
||||
|
|
|
@ -763,7 +763,6 @@ MODULE xml_io_base
|
|||
INTEGER :: me_in_group, nproc_in_group, io_in_parent, nproc_in_parent, me_in_parent, my_group, io_group
|
||||
#if defined __HDF5
|
||||
CHARACTER(LEN=256) :: filename_hdf5
|
||||
INTEGER :: gammaonly = 0
|
||||
#endif
|
||||
COMPLEX(DP), ALLOCATABLE :: wtmp(:)
|
||||
!
|
||||
|
@ -795,8 +794,7 @@ MODULE xml_io_base
|
|||
filename_hdf5=trim(tmp_dir) //"evc.hdf5"
|
||||
CALL prepare_for_writing_final(evc_hdf5_write,inter_pool_comm,filename_hdf5,ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,ngw,"ngw",ik)
|
||||
IF ( gamma_only ) gammaonly = 1
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,gammaonly,"gamma_only",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,gamma_only,"gamma_only",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,igwx,"igwx",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,nbnd,"nbnd",ik)
|
||||
CALL add_attributes_hdf5(evc_hdf5_write,ik,"ik",ik)
|
||||
|
|
|
@ -266,6 +266,7 @@ MODULE pw_restart_new
|
|||
CALL qexsd_init_symmetries(output%symmetries, nsym, nrot, spacegroup,&
|
||||
s, ft, sname, t_rev, nat, irt,symop_2_class(1:nrot), verbosity, &
|
||||
noncolin)
|
||||
output%symmetries_ispresent=.TRUE.
|
||||
!
|
||||
!-------------------------------------------------------------------------------
|
||||
! ... BASIS SET
|
||||
|
@ -649,10 +650,8 @@ MODULE pw_restart_new
|
|||
INTEGER,INTENT(IN) :: nr1, nr2, nr3, ngm, mill(:,:)
|
||||
LOGICAL,INTENT(IN) :: gamma_only
|
||||
!
|
||||
INTEGER :: gammaonly_ = 0
|
||||
CALL prepare_for_writing_final(h5_desc,0,filename)
|
||||
IF ( gamma_only) gammaonly_ =1
|
||||
CALL add_attributes_hdf5(h5_desc, gammaonly_, "gamma_only")
|
||||
CALL prepare_for_writing_final(h5_desc,0,filename)
|
||||
CALL add_attributes_hdf5(h5_desc, gamma_only, "gamma_only")
|
||||
CALL add_attributes_hdf5(h5_desc, nr1, "nr1s")
|
||||
CALL add_attributes_hdf5(h5_desc, nr2, "nr2s")
|
||||
CALL add_attributes_hdf5(h5_desc, nr3, "nr3s")
|
||||
|
@ -677,7 +676,7 @@ MODULE pw_restart_new
|
|||
!
|
||||
INTEGER, ALLOCATABLE :: igwk(:)
|
||||
INTEGER, ALLOCATABLE :: itmp(:)
|
||||
INTEGER :: ierr, gammaonly_ = 0
|
||||
INTEGER :: ierr
|
||||
#if defined (__HDF5)
|
||||
TYPE (hdf5_type),ALLOCATABLE :: h5_desc
|
||||
!
|
||||
|
@ -716,9 +715,8 @@ MODULE pw_restart_new
|
|||
CALL prepare_for_writing_final ( h5_desc, 0,&
|
||||
TRIM(filename)//'.hdf5',ik_g, ADD_GROUP = .false.)
|
||||
CALL add_attributes_hdf5(h5_desc, ngk_g(ik_g), "number_of_gk_vectors")
|
||||
CALL add_attributes_hdf5(h5_desc, npwx_g, "max_number_of_gk_vectors")
|
||||
IF (gamma_only) gammaonly_ = 1
|
||||
CALL add_attributes_hdf5(h5_desc, gammaonly_, "gamma_only")
|
||||
CALL add_attributes_hdf5(h5_desc, npwx_g, "max_number_of_gk_vectors")
|
||||
CALL add_attributes_hdf5(h5_desc, gamma_only, "gamma_only")
|
||||
CALL add_attributes_hdf5(h5_desc, "2pi/a", "units")
|
||||
CALL write_gkhdf5(h5_desc,xk(:,ik),igwk(1:ngk_g(ik)), &
|
||||
mill_g(1:3,igwk(1:ngk_g(ik_g))),ik_g)
|
||||
|
|
Loading…
Reference in New Issue