LCOV - code coverage report
Current view: top level - io - cdnpot_io_hdf.F90 (source / functions) Hit Total Coverage
Test: FLEUR test coverage Lines: 1314 2233 58.8 %
Date: 2024-04-23 04:28:20 Functions: 18 28 64.3 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------
       2             : ! Copyright (c) 2017 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
       3             : ! This file is part of FLEUR and available as free software under the conditions
       4             : ! of the MIT license as expressed in the LICENSE file in more detail.
       5             : !--------------------------------------------------------------------------------
       6             : 
       7             : MODULE m_cdnpot_io_hdf
       8             : 
       9             :    USE m_constants
      10             :    USE m_juDFT
      11             : #ifdef CPP_HDF
      12             :    USE hdf5
      13             :    USE m_hdf_tools
      14             : #endif
      15             :    IMPLICIT NONE
      16             : 
      17             :    PRIVATE
      18             : #ifdef CPP_HDF
      19             :    PUBLIC openCDN_HDF, openPOT_HDF, closeCDNPOT_HDF
      20             :    PUBLIC writeStarsHDF, readStarsHDF, peekStarsHDF
      21             :    PUBLIC writeLatharmsHDF, readLatharmsHDF, peekLatharmsHDF
      22             :    PUBLIC writeStructureHDF, readStructureHDF
      23             :    PUBLIC writeStepfunctionHDF, readStepfunctionHDF, peekStepfunctionHDF
      24             :    PUBLIC writeDensityHDF, readDensityHDF
      25             :    PUBLIC writePotentialHDF, readPotentialHDF
      26             :    PUBLIC writeCoreDensityHDF, readCoreDensityHDF
      27             :    PUBLIC writeCDNHeaderData, writePOTHeaderData
      28             :    PUBLIC isCoreDensityPresentHDF, deleteDensityEntryHDF
      29             :    PUBLIC deleteObsoleteDensityMetadataHDF
      30             :    PUBLIC isDensityEntryPresentHDF, isPotentialEntryPresentHDF
      31             :    PUBLIC peekDensityEntryHDF
      32             : #endif
      33             : 
      34             :    PUBLIC DENSITY_TYPE_UNDEFINED_const
      35             :    PUBLIC DENSITY_TYPE_IN_const, DENSITY_TYPE_OUT_const
      36             :    PUBLIC DENSITY_TYPE_NOCO_IN_const, DENSITY_TYPE_NOCO_OUT_const
      37             :    PUBLIC DENSITY_TYPE_PRECOND_const
      38             :    PUBLIC POTENTIAL_TYPE_IN_const, POTENTIAL_TYPE_OUT_const
      39             :    PUBLIC DENSITY_TYPE_FFN_OUT_const, DENSITY_TYPE_FFN_IN_const
      40             : 
      41             :    INTEGER,          PARAMETER :: DENSITY_TYPE_UNDEFINED_const = 0
      42             :    INTEGER,          PARAMETER :: DENSITY_TYPE_IN_const = 1
      43             :    INTEGER,          PARAMETER :: DENSITY_TYPE_OUT_const = 2
      44             :    INTEGER,          PARAMETER :: DENSITY_TYPE_NOCO_IN_const = 3
      45             :    INTEGER,          PARAMETER :: DENSITY_TYPE_NOCO_OUT_const = 4
      46             :    INTEGER,          PARAMETER :: DENSITY_TYPE_PRECOND_const = 5
      47             :    INTEGER,          PARAMETER :: DENSITY_TYPE_FFN_IN_const = 6
      48             :    INTEGER,          PARAMETER :: DENSITY_TYPE_FFN_OUT_const = 7
      49             : 
      50             :    INTEGER,          PARAMETER :: POTENTIAL_TYPE_IN_const = 1
      51             :    INTEGER,          PARAMETER :: POTENTIAL_TYPE_OUT_const = 2
      52             : 
      53             :    INTEGER,          PARAMETER :: FILE_FORMAT_VERSION_const = 35
      54             : 
      55             :    CONTAINS
      56             : 
      57             : #ifdef CPP_HDF
      58             : 
      59        1541 :    SUBROUTINE openCDN_HDF(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
      60             :                           currentStepfunctionIndex,readDensityIndex,lastDensityIndex,inFilename)
      61             : 
      62             :       INTEGER(HID_T), INTENT(OUT) :: fileID
      63             :       INTEGER, INTENT(OUT) :: currentStarsIndex,currentLatharmsIndex,currentStructureIndex
      64             :       INTEGER, INTENT(OUT) :: currentStepfunctionIndex, readDensityIndex,lastDensityIndex
      65             : 
      66             :       CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: inFilename
      67             : 
      68             :       INTEGER(HID_T) :: generalGroupID
      69             :       INTEGER        :: hdfError, fileFormatVersion
      70             :       LOGICAL        :: l_exist
      71             :       CHARACTER(LEN=30) :: filename
      72             : 
      73        1541 :       currentStarsIndex = 0
      74        1541 :       currentLatharmsIndex = 0
      75        1541 :       currentStructureIndex = 0
      76        1541 :       currentStepfunctionIndex = 0
      77        1541 :       readDensityIndex = 0
      78        1541 :       lastDensityIndex = 0
      79        1541 :       fileFormatVersion = 0
      80             : 
      81        1541 :       filename = 'cdn.hdf'
      82           1 :       IF(PRESENT(inFilename)) filename = TRIM(ADJUSTL(inFilename))//'.hdf'
      83             : 
      84        1541 :       INQUIRE(FILE=TRIM(ADJUSTL(filename)),EXIST=l_exist)
      85        1541 :       IF(l_exist) THEN ! only open file
      86        1472 :          CALL h5fopen_f(TRIM(ADJUSTL(filename)), H5F_ACC_RDWR_F, fileID, hdfError, H5P_DEFAULT_F)
      87             : 
      88        1472 :          CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
      89             :          ! read in primary attributes from the header '/general'
      90        1472 :          CALL io_read_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
      91        1472 :          CALL io_read_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
      92        1472 :          CALL io_read_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
      93        1472 :          CALL io_read_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
      94        1472 :          CALL io_read_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
      95        1472 :          CALL io_read_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
      96        1472 :          CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
      97             : 
      98        1472 :          CALL h5gclose_f(generalGroupID, hdfError)
      99        1472 :          IF(fileFormatVersion.GT.FILE_FORMAT_VERSION_const) THEN
     100           0 :             WRITE(*,'(a,i4)') TRIM(ADJUSTL(filename))//' has file format version ', fileFormatVersion
     101           0 :             CALL juDFT_error(TRIM(ADJUSTL(filename))//' file format not readable.' ,calledby ="openCDN_HDF")
     102             :          END IF
     103             :       ELSE ! create file
     104          69 :          CALL h5fcreate_f(TRIM(ADJUSTL(filename)), H5F_ACC_TRUNC_F, fileID, hdfError, H5P_DEFAULT_F, H5P_DEFAULT_F)
     105             : 
     106          69 :          CALL h5gcreate_f(fileID, '/general', generalGroupID, hdfError)
     107             :          ! write initial values to primary attributes in the header '/general'
     108          69 :          CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
     109          69 :          CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
     110          69 :          CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
     111          69 :          CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
     112          69 :          CALL io_write_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
     113          69 :          CALL io_write_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
     114          69 :          CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
     115             : 
     116          69 :          CALL h5gclose_f(generalGroupID, hdfError)
     117             :       END IF
     118             : 
     119        1541 :    END SUBROUTINE openCDN_HDF
     120             : 
     121             : 
     122           0 :    SUBROUTINE openPOT_HDF(fileID,currentStarsIndex,currentLatharmsIndex,&
     123             :                           currentStructureIndex,currentStepfunctionIndex)
     124             : 
     125             :       INTEGER(HID_T), INTENT(OUT) :: fileID
     126             :       INTEGER, INTENT(OUT) :: currentStarsIndex,currentLatharmsIndex
     127             :       INTEGER, INTENT(OUT) :: currentStructureIndex, currentStepfunctionIndex
     128             : 
     129             :       INTEGER(HID_T) :: generalGroupID
     130             :       INTEGER        :: hdfError, fileFormatVersion
     131             :       LOGICAL        :: l_exist
     132             : 
     133           0 :       currentStarsIndex = 0
     134           0 :       currentLatharmsIndex = 0
     135           0 :       currentStructureIndex = 0
     136           0 :       currentStepfunctionIndex = 0
     137           0 :       fileFormatVersion = 0
     138             : 
     139           0 :       INQUIRE(FILE='pot.hdf',EXIST=l_exist)
     140           0 :       IF(l_exist) THEN ! only open file
     141           0 :          CALL h5fopen_f('pot.hdf', H5F_ACC_RDWR_F, fileID, hdfError, H5P_DEFAULT_F)
     142             : 
     143           0 :          CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
     144             :          ! read in primary attributes from the header '/general'
     145           0 :          CALL io_read_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
     146           0 :          CALL io_read_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
     147           0 :          CALL io_read_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
     148           0 :          CALL io_read_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
     149           0 :          CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
     150             : 
     151           0 :          CALL h5gclose_f(generalGroupID, hdfError)
     152           0 :          IF(fileFormatVersion.NE.FILE_FORMAT_VERSION_const) THEN
     153           0 :             WRITE(*,'(a,i4)') 'pot.hdf has file format version ', fileFormatVersion
     154           0 :             CALL juDFT_error('pot.hdf file format not readable.' ,calledby ="openPOT_HDF")
     155             :          END IF
     156             :       ELSE ! create file
     157           0 :          CALL h5fcreate_f('pot.hdf', H5F_ACC_TRUNC_F, fileID, hdfError, H5P_DEFAULT_F, H5P_DEFAULT_F)
     158             : 
     159           0 :          CALL h5gcreate_f(fileID, '/general', generalGroupID, hdfError)
     160             :          ! write initial values to primary attributes in the header '/general'
     161           0 :          CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
     162           0 :          CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
     163           0 :          CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
     164           0 :          CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
     165           0 :          CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
     166             : 
     167           0 :          CALL h5gclose_f(generalGroupID, hdfError)
     168             :       END IF
     169             : 
     170           0 :    END SUBROUTINE openPOT_HDF
     171             : 
     172        1541 :    SUBROUTINE closeCDNPOT_HDF(fileID)
     173             : 
     174             :       INTEGER(HID_T), INTENT(IN) :: fileID
     175             : 
     176             :       INTEGER hdfError
     177             : 
     178        1462 :       CALL h5fclose_f(fileID, hdfError)
     179             : 
     180        1462 :    END SUBROUTINE closeCDNPOT_HDF
     181             : 
     182         954 :    SUBROUTINE writeCDNHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
     183             :                                  currentStepfunctionIndex,readDensityIndex,lastDensityIndex)
     184             : 
     185             :       INTEGER(HID_T), INTENT(IN) :: fileID
     186             :       INTEGER, INTENT(IN)        :: currentStarsIndex
     187             :       INTEGER, INTENT(IN)        :: currentLatharmsIndex
     188             :       INTEGER, INTENT(IN)        :: currentStructureIndex
     189             :       INTEGER, INTENT(IN)        :: currentStepfunctionIndex
     190             :       INTEGER, INTENT(IN)        :: readDensityIndex
     191             :       INTEGER, INTENT(IN)        :: lastDensityIndex
     192             : 
     193             :       INTEGER(HID_T) :: generalGroupID
     194             :       INTEGER        :: hdfError
     195             : 
     196         477 :       CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
     197             : 
     198         477 :       CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
     199         477 :       CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
     200         477 :       CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
     201         477 :       CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
     202         477 :       CALL io_write_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
     203         477 :       CALL io_write_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
     204         477 :       CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
     205             : 
     206         477 :       CALL h5gclose_f(generalGroupID, hdfError)
     207             : 
     208         477 :    END SUBROUTINE writeCDNHeaderData
     209             : 
     210           0 :    SUBROUTINE writePOTHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,&
     211             :                                  currentStructureIndex,currentStepfunctionIndex)
     212             : 
     213             :       INTEGER(HID_T), INTENT(IN) :: fileID
     214             :       INTEGER, INTENT(IN)        :: currentStarsIndex
     215             :       INTEGER, INTENT(IN)        :: currentLatharmsIndex
     216             :       INTEGER, INTENT(IN)        :: currentStructureIndex
     217             :       INTEGER, INTENT(IN)        :: currentStepfunctionIndex
     218             : 
     219             :       INTEGER(HID_T) :: generalGroupID
     220             :       INTEGER        :: hdfError
     221             : 
     222           0 :       CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
     223             : 
     224           0 :       CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
     225           0 :       CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
     226           0 :       CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
     227           0 :       CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
     228           0 :       CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
     229             : 
     230           0 :       CALL h5gclose_f(generalGroupID, hdfError)
     231             : 
     232           0 :    END SUBROUTINE writePOTHeaderData
     233             : 
     234         138 :    SUBROUTINE writeStarsHDF(fileID, starsIndex, structureIndex, stars, l_checkBroyd, l_storeAddMetadata)
     235             :      use m_types_stars
     236             : 
     237             :       INTEGER(HID_T), INTENT(IN) :: fileID
     238             :       INTEGER,        INTENT(IN) :: starsIndex, structureIndex
     239             :       TYPE(t_stars),  INTENT(IN) :: stars
     240             : 
     241             :       LOGICAL,        INTENT(IN) :: l_CheckBroyd
     242             :       LOGICAL,        INTENT(IN) :: l_storeAddMetadata
     243             : 
     244             :       INTEGER(HID_T)            :: groupID
     245             :       INTEGER                   :: hdfError,  dimsInt(7)
     246             :       CHARACTER(LEN=30)         :: groupName
     247             :       INTEGER(HSIZE_T)          :: dims(7)
     248             :       LOGICAL        :: l_exist
     249             : 
     250             :       INTEGER(HID_T)                   :: kv3SpaceID, kv3SetID
     251             :       INTEGER(HID_T)                   :: kv2SpaceID, kv2SetID
     252             :       INTEGER(HID_T)                   :: sk3SpaceID, sk3SetID
     253             :       INTEGER(HID_T)                   :: sk2SpaceID, sk2SetID
     254             :       INTEGER(HID_T)                   :: igSpaceID, igSetID
     255             :       INTEGER(HID_T)                   :: ig2SpaceID, ig2SetID
     256             :       INTEGER(HID_T)                   :: nstrSpaceID, nstrSetID
     257             :       INTEGER(HID_T)                   :: nstr2SpaceID, nstr2SetID
     258             :       INTEGER(HID_T)                   :: phi2SpaceID, phi2SetID
     259             :       INTEGER(HID_T)                   :: rgphsSpaceID, rgphsSetID
     260             :       INTEGER(HID_T)                   :: igfftSpaceID, igfftSetID
     261             :       INTEGER(HID_T)                   :: igfft2SpaceID, igfft2SetID
     262             :       INTEGER(HID_T)                   :: pgfftSpaceID, pgfftSetID
     263             :       INTEGER(HID_T)                   :: pgfft2SpaceID, pgfft2SetID
     264             : 
     265          69 :       WRITE(groupname,'(a,i0)') '/stars-', starsIndex
     266             : 
     267          69 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     268             : 
     269          69 :       IF (l_exist) THEN
     270           0 :          CALL juDFT_error('stars entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeStarsHDF")
     271             :       END IF
     272             : 
     273          69 :       INQUIRE(FILE='broyd',EXIST=l_exist)
     274          69 :       IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
     275          69 :       IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Stars change but broyden files detected!')
     276             : 
     277          69 :       CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     278             : 
     279             : 
     280          69 :       CALL io_write_attint0(groupID,'structureIndex',structureIndex)
     281             : 
     282          69 :       CALL io_write_attreal0(groupID,'gmax',stars%gmax)
     283          69 :       CALL io_write_attreal0(groupID,'gmaxz',stars%gmaxz)
     284             : !      CALL io_write_attreal0(groupID,'gmaxInit',stars%gmaxInit)
     285          69 :       CALL io_write_attint0(groupID,'ng3',stars%ng3)
     286          69 :       CALL io_write_attint0(groupID,'ng2',stars%ng2)
     287          69 :       CALL io_write_attint0(groupID,'mx1',stars%mx1)
     288          69 :       CALL io_write_attint0(groupID,'mx2',stars%mx2)
     289          69 :       CALL io_write_attint0(groupID,'mx3',stars%mx3)
     290          69 :       CALL io_write_attint0(groupID,'ng3_fft',stars%ng3_fft)
     291             : 
     292          69 :       IF (l_storeAddMetadata) THEN
     293           0 :          dims(:2)=(/3,stars%ng3/)
     294           0 :          dimsInt=dims
     295           0 :          CALL h5screate_simple_f(2,dims(:2),kv3SpaceID,hdfError)
     296           0 :          CALL h5dcreate_f(groupID, "kv3", H5T_NATIVE_INTEGER, kv3SpaceID, kv3SetID, hdfError)
     297           0 :          CALL h5sclose_f(kv3SpaceID,hdfError)
     298           0 :          CALL io_write_integer2(kv3SetID,(/1,1/),dimsInt(:2),"kv3",stars%kv3)
     299           0 :          CALL h5dclose_f(kv3SetID, hdfError)
     300             : 
     301           0 :          dims(:1)=(/stars%ng3/)
     302           0 :          dimsInt=dims
     303           0 :          CALL h5screate_simple_f(1,dims(:1),sk3SpaceID,hdfError)
     304           0 :          CALL h5dcreate_f(groupID, "sk3", H5T_NATIVE_DOUBLE, sk3SpaceID, sk3SetID, hdfError)
     305           0 :          CALL h5sclose_f(sk3SpaceID,hdfError)
     306           0 :          CALL io_write_real1(sk3SetID,(/1/),dimsInt(:1),"sk3",stars%sk3)
     307           0 :          CALL h5dclose_f(sk3SetID, hdfError)
     308             : 
     309           0 :          dims(:3)=(/2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
     310           0 :          dimsInt=dims
     311           0 :          CALL h5screate_simple_f(3,dims(:3),igSpaceID,hdfError)
     312           0 :          CALL h5dcreate_f(groupID, "ig", H5T_NATIVE_INTEGER, igSpaceID, igSetID, hdfError)
     313           0 :          CALL h5sclose_f(igSpaceID,hdfError)
     314           0 :          CALL io_write_integer3(igSetID,(/1,1,1/),dimsInt(:3),"ig",stars%ig)
     315           0 :          CALL h5dclose_f(igSetID, hdfError)
     316             : 
     317           0 :          dims(:1)=(/stars%ng3/)
     318           0 :          dimsInt=dims
     319           0 :          CALL h5screate_simple_f(1,dims(:1),nstrSpaceID,hdfError)
     320           0 :          CALL h5dcreate_f(groupID, "nstr", H5T_NATIVE_INTEGER, nstrSpaceID, nstrSetID, hdfError)
     321           0 :          CALL h5sclose_f(nstrSpaceID,hdfError)
     322           0 :          CALL io_write_integer1(nstrSetID,(/1/),dimsInt(:1),"nstr",stars%nstr)
     323           0 :          CALL h5dclose_f(nstrSetID, hdfError)
     324             : 
     325           0 :          dims(:4)=(/2,2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
     326           0 :          dimsInt=dims
     327           0 :          CALL h5screate_simple_f(4,dims(:4),rgphsSpaceID,hdfError)
     328           0 :          CALL h5dcreate_f(groupID, "rgphs", H5T_NATIVE_DOUBLE, rgphsSpaceID, rgphsSetID, hdfError)
     329           0 :          CALL h5sclose_f(rgphsSpaceID,hdfError)
     330           0 :          CALL io_write_complex3(rgphsSetID,(/-1,1,1,1/),dimsInt(:4),"rgphs",stars%rgphs)
     331           0 :          CALL h5dclose_f(rgphsSetID, hdfError)
     332             : 
     333             :          !Film stuff
     334           0 :          IF (stars%ng2>0) THEN
     335           0 :             dims(:2)=(/2,stars%ng2/)
     336           0 :             dimsInt=dims
     337           0 :             CALL h5screate_simple_f(2,dims(:2),kv2SpaceID,hdfError)
     338           0 :             CALL h5dcreate_f(groupID, "kv2", H5T_NATIVE_INTEGER, kv2SpaceID, kv2SetID, hdfError)
     339           0 :             CALL h5sclose_f(kv2SpaceID,hdfError)
     340           0 :             CALL io_write_integer2(kv2SetID,(/1,1/),dimsInt(:2),"kv2",stars%kv2)
     341           0 :             CALL h5dclose_f(kv2SetID, hdfError)
     342             : 
     343           0 :             dims(:1)=(/stars%ng2/)
     344           0 :             dimsInt=dims
     345           0 :             CALL h5screate_simple_f(1,dims(:1),sk2SpaceID,hdfError)
     346           0 :             CALL h5dcreate_f(groupID, "sk2", H5T_NATIVE_DOUBLE, sk2SpaceID, sk2SetID, hdfError)
     347           0 :             CALL h5sclose_f(sk2SpaceID,hdfError)
     348           0 :             CALL io_write_real1(sk2SetID,(/1/),dimsInt(:1),"sk2",stars%sk2)
     349           0 :             CALL h5dclose_f(sk2SetID, hdfError)
     350             : 
     351           0 :             dims(:1)=(/stars%ng3/)
     352           0 :             dimsInt=dims
     353           0 :             CALL h5screate_simple_f(1,dims(:1),ig2SpaceID,hdfError)
     354           0 :             CALL h5dcreate_f(groupID, "ig2", H5T_NATIVE_INTEGER, ig2SpaceID, ig2SetID, hdfError)
     355           0 :             CALL h5sclose_f(ig2SpaceID,hdfError)
     356           0 :             CALL io_write_integer1(ig2SetID,(/1/),dimsInt(:1),"ig2",stars%ig2)
     357           0 :             CALL h5dclose_f(ig2SetID, hdfError)
     358             : 
     359           0 :             dims(:1)=(/stars%ng2/)
     360           0 :             dimsInt=dims
     361           0 :             CALL h5screate_simple_f(1,dims(:1),nstr2SpaceID,hdfError)
     362           0 :             CALL h5dcreate_f(groupID, "nstr2", H5T_NATIVE_INTEGER, nstr2SpaceID, nstr2SetID, hdfError)
     363           0 :             CALL h5sclose_f(nstr2SpaceID,hdfError)
     364           0 :             CALL io_write_integer1(nstr2SetID,(/1/),dimsInt(:1),"nstr2",stars%nstr2)
     365           0 :             CALL h5dclose_f(nstr2SetID, hdfError)
     366             : 
     367           0 :             dims(:2)=(/2*stars%mx1+1,2*stars%mx2+1/)
     368           0 :             dimsInt=dims
     369           0 :             CALL h5screate_simple_f(2,dims(:2),nstr2SpaceID,hdfError)
     370           0 :             CALL h5dcreate_f(groupID, "i2g", H5T_NATIVE_INTEGER, nstr2SpaceID, nstr2SetID, hdfError)
     371           0 :             CALL h5sclose_f(nstr2SpaceID,hdfError)
     372           0 :             CALL io_write_integer2(nstr2SetID,(/1,1/),dimsInt(:2),"i2g",stars%i2g)
     373           0 :             CALL h5dclose_f(nstr2SetID, hdfError)
     374             : 
     375             : !            dims(:1)=(/stars%ng2/)
     376             : !            dimsInt=dims
     377             : !            CALL h5screate_simple_f(1,dims(:1),phi2SpaceID,hdfError)
     378             : !            CALL h5dcreate_f(groupID, "phi2", H5T_NATIVE_DOUBLE, phi2SpaceID, phi2SetID, hdfError)
     379             : !            CALL h5sclose_f(phi2SpaceID,hdfError)
     380             : !            CALL io_write_real1(phi2SetID,(/1/),dimsInt(:1),stars%phi2)
     381             : !            CALL h5dclose_f(phi2SetID, hdfError)
     382             :          END IF
     383             :       END IF
     384          69 :       CALL h5gclose_f(groupID, hdfError)
     385             : 
     386          69 :    END SUBROUTINE writeStarsHDF
     387             : 
     388         418 :    SUBROUTINE readStarsHDF(fileID, starsIndex, stars)
     389             :       use m_types_stars
     390             : 
     391             :       INTEGER(HID_T), INTENT(IN)    :: fileID
     392             :       INTEGER,        INTENT(IN)    :: starsIndex
     393             :       TYPE(t_stars),  INTENT(INOUT) :: stars
     394             : 
     395             : 
     396             :       INTEGER(HID_T)            :: groupID, generalGroupID
     397             :       INTEGER                   :: fileFormatVersion
     398             :       INTEGER                   :: hdfError, kimax,kimax2
     399             :       INTEGER                   :: dimsInt(7)
     400             :       CHARACTER(LEN=30)         :: groupName
     401             :       LOGICAL                   :: l_exist
     402             : 
     403             :       INTEGER(HID_T)                   :: kv3SetID
     404             :       INTEGER(HID_T)                   :: kv2SetID
     405             :       INTEGER(HID_T)                   :: sk3SetID
     406             :       INTEGER(HID_T)                   :: sk2SetID
     407             :       INTEGER(HID_T)                   :: igSetID
     408             :       INTEGER(HID_T)                   :: ig2SetID
     409             :       INTEGER(HID_T)                   :: nstrSetID
     410             :       INTEGER(HID_T)                   :: nstr2SetID
     411             :       INTEGER(HID_T)                   :: phi2SetID
     412             :       INTEGER(HID_T)                   :: rgphsSetID
     413             :       INTEGER(HID_T)                   :: igfftSetID
     414             :       INTEGER(HID_T)                   :: igfft2SetID
     415             :       INTEGER(HID_T)                   :: pgfftSetID
     416             :       INTEGER(HID_T)                   :: pgfft2SetID
     417             : 
     418             : 
     419         418 :       CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
     420             :       ! read in file format version from the header '/general'
     421         418 :       CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
     422         418 :       CALL h5gclose_f(generalGroupID,hdfError)
     423             : 
     424         418 :       WRITE(groupname,'(a,i0)') '/stars-', starsIndex
     425             : 
     426         418 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     427             : 
     428         418 :       IF (.NOT.l_exist) THEN
     429           0 :          CALL juDFT_error('stars entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStarsHDF")
     430             :       END IF
     431             : 
     432         418 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     433             : 
     434         418 :       CALL io_read_attreal0(groupID,'gmax',stars%gmax)
     435         418 :       CALL io_read_attreal0(groupID,'gmaxz',stars%gmaxz)
     436             : !      CALL io_read_attreal0(groupID,'gmaxInit',stars%gmaxInit)
     437         418 :       CALL io_read_attint0(groupID,'ng3',stars%ng3)
     438         418 :       CALL io_read_attint0(groupID,'ng2',stars%ng2)
     439         418 :       CALL io_read_attint0(groupID,'mx1',stars%mx1)
     440         418 :       CALL io_read_attint0(groupID,'mx2',stars%mx2)
     441         418 :       CALL io_read_attint0(groupID,'mx3',stars%mx3)
     442         418 :       CALL io_read_attint0(groupID,'ng3_fft',stars%ng3_fft)
     443             : 
     444         418 :       kimax2= (2*stars%mx1+1)* (2*stars%mx2+1)-1
     445         418 :       kimax = (2*stars%mx1+1)* (2*stars%mx2+1)* (2*stars%mx3+1)-1
     446             : 
     447         418 :       IF(ALLOCATED(stars%kv3)) DEALLOCATE(stars%kv3)
     448         418 :       IF(ALLOCATED(stars%kv2)) DEALLOCATE(stars%kv2)
     449         418 :       IF(ALLOCATED(stars%sk3)) DEALLOCATE(stars%sk3)
     450         418 :       IF(ALLOCATED(stars%sk2)) DEALLOCATE(stars%sk2)
     451         418 :       IF(ALLOCATED(stars%ig)) DEALLOCATE(stars%ig)
     452         418 :       IF(ALLOCATED(stars%ig2)) DEALLOCATE(stars%ig2)
     453         418 :       IF(ALLOCATED(stars%i2g)) DEALLOCATE(stars%i2g)
     454         418 :       IF(ALLOCATED(stars%nstr)) DEALLOCATE(stars%nstr)
     455         418 :       IF(ALLOCATED(stars%nstr2)) DEALLOCATE(stars%nstr2)
     456         418 :       IF(ALLOCATED(stars%phi2)) DEALLOCATE(stars%phi2)
     457         418 :       IF(ALLOCATED(stars%rgphs)) DEALLOCATE(stars%rgphs)
     458             : 
     459             : 
     460        1254 :       ALLOCATE(stars%kv3(3,stars%ng3))
     461        1254 :       ALLOCATE(stars%kv2(2,stars%ng2))
     462        1254 :       ALLOCATE(stars%sk3(stars%ng3))
     463        1254 :       ALLOCATE(stars%sk2(stars%ng2))
     464        2090 :       ALLOCATE(stars%ig(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
     465        1672 :       ALLOCATE(stars%i2g(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2))
     466        1254 :       ALLOCATE(stars%ig2(stars%ng3))
     467         836 :       ALLOCATE(stars%nstr(stars%ng3))
     468        1254 :       ALLOCATE(stars%nstr2(stars%ng2))
     469         836 :       ALLOCATE(stars%phi2(stars%ng2))
     470        2090 :       ALLOCATE(stars%rgphs(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
     471             : 
     472             : 
     473             : !      dimsInt(:2)=(/3,stars%ng3/)
     474             : !      CALL h5dopen_f(groupID, 'kv3', kv3SetID, hdfError)
     475             : !      CALL io_read_integer2(kv3SetID,(/1,1/),dimsInt(:2),"kv3",stars%kv3)
     476             : !      CALL h5dclose_f(kv3SetID, hdfError)
     477             : 
     478             : !      dimsInt(:1)=(/stars%ng3/)
     479             : !      CALL h5dopen_f(groupID, 'sk3', sk3SetID, hdfError)
     480             : !      CALL io_read_real1(sk3SetID,(/1/),dimsInt(:1),"sk3",stars%sk3)
     481             : !      CALL h5dclose_f(sk3SetID, hdfError)
     482             : 
     483             : !      dimsInt(:3)=(/2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
     484             : !      CALL h5dopen_f(groupID, 'ig', igSetID, hdfError)
     485             : !      CALL io_read_integer3(igSetID,(/1,1,1/),dimsInt(:3),"ig",stars%ig)
     486             : !      CALL h5dclose_f(igSetID, hdfError)
     487             : 
     488             : !      dimsInt(:1)=(/stars%ng3/)
     489             : !      CALL h5dopen_f(groupID, 'nstr', nstrSetID, hdfError)
     490             : !      CALL io_read_integer1(nstrSetID,(/1/),dimsInt(:1),"nstr",stars%nstr)
     491             : !      CALL h5dclose_f(nstrSetID, hdfError)
     492             : 
     493             : ! I comment out reading and writing of the rgphs array because it is large and the read-in array is nowhere used.
     494             : !      dimsInt(:4)=(/2,2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
     495             : !      CALL h5dopen_f(groupID, 'rgphs', rgphsSetID, hdfError)
     496             : !      CALL io_read_complex3(rgphsSetID,(/-1,1,1,1/),dimsInt(:4),"rgphs",stars%rgphs)
     497             : !      CALL h5dclose_f(rgphsSetID, hdfError)
     498             : 
     499             :       IF (stars%ng2>0) THEN
     500             : !         dimsInt(:2)=(/2,stars%ng2/)
     501             : !         CALL h5dopen_f(groupID, 'kv2', kv2SetID, hdfError)
     502             : !         CALL io_read_integer2(kv2SetID,(/1,1/),dimsInt(:2),"kv2",stars%kv2)
     503             : !         CALL h5dclose_f(kv2SetID, hdfError)
     504             : 
     505             : !         dimsInt(:1)=(/stars%ng2/)
     506             : !         CALL h5dopen_f(groupID, 'sk2', sk2SetID, hdfError)
     507             : !         CALL io_read_real1(sk2SetID,(/1/),dimsInt(:1),"sk2",stars%sk2)
     508             : !         CALL h5dclose_f(sk2SetID, hdfError)
     509             : 
     510             : !         dimsInt(:1)=(/stars%ng3/)
     511             : !         CALL h5dopen_f(groupID, 'ig2', ig2SetID, hdfError)
     512             : !         CALL io_read_integer1(ig2SetID,(/1/),dimsInt(:1),"ig2",stars%ig2)
     513             : !         CALL h5dclose_f(ig2SetID, hdfError)
     514             : 
     515             : 
     516             : !         dimsInt(:1)=(/stars%ng2/)
     517             : !         CALL h5dopen_f(groupID, 'nstr2', nstr2SetID, hdfError)
     518             : !         CALL io_read_integer1(nstr2SetID,(/1/),dimsInt(:1),"nstr2",stars%nstr2)
     519             : !         CALL h5dclose_f(nstr2SetID, hdfError)
     520             : 
     521             : !         dimsInt(:2)=(/2*stars%mx1+1,2*stars%mx2+1/)
     522             : !         CALL h5dopen_f(groupID, 'i2g', igSetID, hdfError)
     523             : !         CALL io_read_integer2(igSetID,(/1,1/),dimsInt(:2),"i2g",stars%i2g)
     524             : !         CALL h5dclose_f(igSetID, hdfError)
     525             : 
     526             :          !dimsInt(:1)=(/stars%ng2/)
     527             :          !CALL h5dopen_f(groupID, 'phi2', phi2SetID, hdfError)
     528             :          !CALL io_read_real1(phi2SetID,(/1/),dimsInt(:1),stars%phi2)
     529             :          !CALL h5dclose_f(phi2SetID, hdfError)
     530             : 
     531             : 
     532             :       ENDIF
     533             : 
     534             : 
     535             : 
     536             : 
     537         418 :       CALL h5gclose_f(groupID, hdfError)
     538             : 
     539         836 :    END SUBROUTINE readStarsHDF
     540             : 
     541         836 :    SUBROUTINE peekStarsHDF(fileID, starsIndex, structureIndex)
     542             : 
     543             :       INTEGER(HID_T), INTENT(IN)    :: fileID
     544             :       INTEGER,        INTENT(IN)    :: starsIndex
     545             :       INTEGER,        INTENT(OUT)   :: structureIndex
     546             : 
     547             :       INTEGER(HID_T)            :: groupID
     548             :       INTEGER                   :: hdfError
     549             :       CHARACTER(LEN=30)         :: groupName
     550             :       LOGICAL                   :: l_exist
     551             : 
     552         418 :       WRITE(groupname,'(a,i0)') '/stars-', starsIndex
     553             : 
     554         418 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     555             : 
     556         418 :       IF (.NOT.l_exist) THEN
     557           0 :          CALL juDFT_error('stars entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStarsHDF")
     558             :       END IF
     559             : 
     560         418 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     561         418 :       CALL io_read_attint0(groupID,'structureIndex',structureIndex)
     562         418 :       CALL h5gclose_f(groupID, hdfError)
     563             : 
     564         418 :    END SUBROUTINE peekStarsHDF
     565             : 
     566           0 :    SUBROUTINE writeStepfunctionHDF(fileID, stepfunctionIndex, starsIndex, structureIndex, stars, l_CheckBroyd)
     567             :       use m_types_stars
     568             :       INTEGER(HID_T), INTENT(IN)    :: fileID
     569             :       INTEGER,        INTENT(IN)    :: stepfunctionIndex, starsIndex, structureIndex
     570             :       TYPE(t_stars),  INTENT(IN)    :: stars
     571             :       LOGICAL,        INTENT(IN)    :: l_CheckBroyd
     572             : 
     573             :       INTEGER                   :: ifftd
     574             : 
     575             :       INTEGER                   :: hdfError
     576             :       INTEGER(HID_T)            :: groupID
     577             :       INTEGER(HID_T)            :: ustepSpaceID, ustepSetID
     578             :       INTEGER(HID_T)            :: ufftSpaceID, ufftSetID
     579             :       CHARACTER(LEN=30)         :: groupName
     580             :       INTEGER(HSIZE_T)          :: dims(7)
     581             :       INTEGER                   :: dimsInt(7)
     582             :       LOGICAL                   :: l_exist
     583             : 
     584             : 
     585           0 :       IF(stepfunctionIndex.EQ.0) RETURN
     586             : 
     587           0 :       WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex
     588             : 
     589           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     590             : 
     591           0 :       IF (l_exist) THEN
     592           0 :          CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeStepfunctionHDF")
     593             :       END IF
     594             : 
     595           0 :       INQUIRE(FILE='broyd',EXIST=l_exist)
     596           0 :       IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
     597           0 :       IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Stepfunction change but broyden files detected!')
     598             : 
     599           0 :       ifftd = size(stars%ufft)
     600             : 
     601           0 :       CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     602             : 
     603           0 :       CALL io_write_attint0(groupID,'starsIndex',starsIndex)
     604           0 :       CALL io_write_attint0(groupID,'structureIndex',structureIndex)
     605           0 :       CALL io_write_attint0(groupID,'ifftd',ifftd)
     606           0 :       CALL io_write_attint0(groupID,'ng3',stars%ng3)
     607             : 
     608           0 :       dims(:2)=(/2,stars%ng3/)
     609           0 :       dimsInt = dims
     610           0 :       CALL h5screate_simple_f(2,dims(:2),ustepSpaceID,hdfError)
     611           0 :       CALL h5dcreate_f(groupID, "ustep", H5T_NATIVE_DOUBLE, ustepSpaceID, ustepSetID, hdfError)
     612           0 :       CALL h5sclose_f(ustepSpaceID,hdfError)
     613           0 :       CALL io_write_complex1(ustepSetID,(/-1,1/),dimsInt(:2),"ustep",stars%ustep)
     614           0 :       CALL h5dclose_f(ustepSetID, hdfError)
     615             : 
     616           0 :       dims(:1)=(/ifftd/)
     617           0 :       dimsInt=dims
     618           0 :       CALL h5screate_simple_f(1,dims(:1),ufftSpaceID,hdfError)
     619           0 :       CALL h5dcreate_f(groupID, "ufft", H5T_NATIVE_DOUBLE, ufftSpaceID, ufftSetID, hdfError)
     620           0 :       CALL h5sclose_f(ufftSpaceID,hdfError)
     621           0 :       CALL io_write_real1(ufftSetID,(/1/),dimsInt(:1),"ufft",stars%ufft)
     622           0 :       CALL h5dclose_f(ufftSetID, hdfError)
     623             : 
     624           0 :       CALL h5gclose_f(groupID, hdfError)
     625             : 
     626             :    END SUBROUTINE writeStepfunctionHDF
     627             : 
     628           0 :    SUBROUTINE readStepfunctionHDF(fileID, stepfunctionIndex, stars)
     629             :       use m_types_stars
     630             :       INTEGER(HID_T), INTENT(IN)    :: fileID
     631             :       INTEGER,        INTENT(IN)    :: stepfunctionIndex
     632             :       TYPE(t_stars),  INTENT(INOUT) :: stars
     633             : 
     634             :       INTEGER                   :: starsIndex, ng3Temp, ifftd, ifftdStars
     635             :       INTEGER                   :: structureIndex
     636             : 
     637             :       INTEGER(HID_T)            :: groupID
     638             :       INTEGER                   :: hdfError
     639             :       INTEGER                   :: dimsInt(7)
     640             :       CHARACTER(LEN=30)         :: groupName
     641             :       LOGICAL                   :: l_exist
     642             : 
     643             :       INTEGER(HID_T)            :: ustepSetID
     644             :       INTEGER(HID_T)            :: ufftSetID
     645             : 
     646           0 :       WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex
     647             : 
     648           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     649             : 
     650           0 :       IF (.NOT.l_exist) THEN
     651           0 :          CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStepfunctionHDF")
     652             :       END IF
     653             : 
     654           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     655             : 
     656           0 :       ifftdStars = 27*stars%mx1*stars%mx2*stars%mx3
     657             : 
     658           0 :       CALL io_read_attint0(groupID,'starsIndex',starsIndex)
     659           0 :       CALL io_read_attint0(groupID,'structureIndex',structureIndex)
     660           0 :       CALL io_read_attint0(groupID,'ng3',ng3Temp)
     661           0 :       CALL io_read_attint0(groupID,'ifftd',ifftd)
     662             : 
     663           0 :       IF((ng3Temp.NE.stars%ng3).OR.(ifftd.NE.ifftdStars)) THEN
     664           0 :          WRITE(*,'(a,i7,a,i7)') 'ng3   (stepfunction): ', ng3Temp, ' ng3   (stars) :', stars%ng3
     665           0 :          WRITE(*,'(a,i7,a,i7)') 'ifftd (stepfunction): ', ifftd,   ' ifftd (stars) :', ifftdStars
     666           0 :          CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' does not fit to stars.' ,calledby ="readStepfunctionHDF")
     667             :       END IF
     668             : 
     669           0 :       IF(ALLOCATED(stars%ustep)) DEALLOCATE(stars%ustep)
     670           0 :       IF(ALLOCATED(stars%ufft)) DEALLOCATE(stars%ufft)
     671             : 
     672           0 :       ALLOCATE(stars%ustep(stars%ng3))
     673           0 :       ALLOCATE(stars%ufft(0:ifftd-1))
     674             : 
     675           0 :       dimsInt(:2)=(/2,ng3Temp/)
     676           0 :       CALL h5dopen_f(groupID, 'ustep', ustepSetID, hdfError)
     677           0 :       CALL io_read_complex1(ustepSetID,(/-1,1/),dimsInt(:2),"ustep",stars%ustep)
     678           0 :       CALL h5dclose_f(ustepSetID, hdfError)
     679             : 
     680           0 :       dimsInt(:1)=(/ifftd/)
     681           0 :       CALL h5dopen_f(groupID, 'ufft', ufftSetID, hdfError)
     682           0 :       CALL io_read_real1(ufftSetID,(/1/),dimsInt(:1),"ufft",stars%ufft(0:ifftd-1))
     683           0 :       CALL h5dclose_f(ufftSetID, hdfError)
     684             : 
     685           0 :       CALL h5gclose_f(groupID, hdfError)
     686             : 
     687           0 :    END SUBROUTINE readStepfunctionHDF
     688             : 
     689           0 :    SUBROUTINE peekStepfunctionHDF(fileID, stepfunctionIndex, starsIndex, structureIndex)
     690             : 
     691             :       INTEGER(HID_T), INTENT(IN)    :: fileID
     692             :       INTEGER,        INTENT(IN)    :: stepfunctionIndex
     693             :       INTEGER,        INTENT(OUT)   :: starsIndex, structureIndex
     694             : 
     695             :       INTEGER(HID_T)            :: groupID
     696             :       INTEGER                   :: hdfError
     697             :       CHARACTER(LEN=30)         :: groupName
     698             :       LOGICAL                   :: l_exist
     699             : 
     700           0 :       WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex
     701             : 
     702           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     703             : 
     704           0 :       IF (.NOT.l_exist) THEN
     705           0 :          CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStepfunctionHDF")
     706             :       END IF
     707             : 
     708           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     709           0 :       CALL io_read_attint0(groupID,'starsIndex',starsIndex)
     710           0 :       CALL io_read_attint0(groupID,'structureIndex',structureIndex)
     711           0 :       CALL h5gclose_f(groupID, hdfError)
     712             : 
     713           0 :    END SUBROUTINE peekStepfunctionHDF
     714             : 
     715        1173 :    SUBROUTINE writeLatharmsHDF(fileID, latharmsIndex, structureIndex, latharms, l_CheckBroyd)
     716             :       use m_types_sphhar
     717             :       INTEGER(HID_T), INTENT(IN)  :: fileID
     718             :       INTEGER,        INTENT(IN)  :: latharmsIndex, structureIndex
     719             :       TYPE(t_sphhar), INTENT(IN)  :: latharms
     720             :       LOGICAL,        INTENT(IN)  :: l_CheckBroyd
     721             : 
     722             :       INTEGER                   :: hdfError
     723             :       INTEGER(HID_T)            :: groupID
     724             :       INTEGER(HID_T)            :: nlhSpaceID, nlhSetID
     725             :       INTEGER(HID_T)            :: llhSpaceID, llhSetID
     726             :       INTEGER(HID_T)            :: nmemSpaceID, nmemSetID
     727             :       INTEGER(HID_T)            :: mlhSpaceID, mlhSetID
     728             :       INTEGER(HID_T)            :: clnuSpaceID, clnuSetID
     729             :       CHARACTER(LEN=30)         :: groupName
     730             :       INTEGER(HSIZE_T)          :: dims(7)
     731             :       INTEGER                   :: dimsInt(7)
     732             :       LOGICAL                   :: l_exist
     733             : 
     734          69 :       WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex
     735             : 
     736          69 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     737             : 
     738          69 :       IF (l_exist) THEN
     739           0 :          CALL juDFT_error('latharms entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeLatharmsHDF")
     740             :       END IF
     741             : 
     742          69 :       INQUIRE(FILE='broyd',EXIST=l_exist)
     743          69 :       IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
     744          69 :       IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Lattice harmonics change but broyden files detected!')
     745             : 
     746          69 :       CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     747             : 
     748          69 :       CALL io_write_attint0(groupID,'structureIndex',structureIndex)
     749          69 :       CALL io_write_attint0(groupID,'ntypsd',latharms%ntypsd)
     750          69 :       CALL io_write_attint0(groupID,'memd',latharms%memd)
     751          69 :       CALL io_write_attint0(groupID,'nlhd',latharms%nlhd)
     752             : 
     753         138 :       dims(:1)=(/latharms%ntypsd/)
     754         552 :       dimsInt = dims
     755          69 :       CALL h5screate_simple_f(1,dims(:1),nlhSpaceID,hdfError)
     756          69 :       CALL h5dcreate_f(groupID, "nlh", H5T_NATIVE_INTEGER, nlhSpaceID, nlhSetID, hdfError)
     757          69 :       CALL h5sclose_f(nlhSpaceID,hdfError)
     758          69 :       CALL io_write_integer1(nlhSetID,(/1/),dimsInt(:1),"nlh",latharms%nlh)
     759          69 :       CALL h5dclose_f(nlhSetID, hdfError)
     760             : 
     761         207 :       dims(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
     762         552 :       dimsInt = dims
     763          69 :       CALL h5screate_simple_f(2,dims(:2),llhSpaceID,hdfError)
     764          69 :       CALL h5dcreate_f(groupID, "llh", H5T_NATIVE_INTEGER, llhSpaceID, llhSetID, hdfError)
     765          69 :       CALL h5sclose_f(llhSpaceID,hdfError)
     766          69 :       CALL io_write_integer2(llhSetID,(/1,1/),dimsInt(:2),"llh",latharms%llh)
     767          69 :       CALL h5dclose_f(llhSetID, hdfError)
     768             : 
     769         207 :       dims(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
     770         552 :       dimsInt = dims
     771          69 :       CALL h5screate_simple_f(2,dims(:2),nmemSpaceID,hdfError)
     772          69 :       CALL h5dcreate_f(groupID, "nmem", H5T_NATIVE_INTEGER, nmemSpaceID, nmemSetID, hdfError)
     773          69 :       CALL h5sclose_f(nmemSpaceID,hdfError)
     774          69 :       CALL io_write_integer2(nmemSetID,(/1,1/),dimsInt(:2),"nmem",latharms%nmem)
     775          69 :       CALL h5dclose_f(nmemSetID, hdfError)
     776             : 
     777         276 :       dims(:3)=(/latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
     778         552 :       dimsInt = dims
     779          69 :       CALL h5screate_simple_f(3,dims(:3),mlhSpaceID,hdfError)
     780          69 :       CALL h5dcreate_f(groupID, "mlh", H5T_NATIVE_INTEGER, mlhSpaceID, mlhSetID, hdfError)
     781          69 :       CALL h5sclose_f(mlhSpaceID,hdfError)
     782          69 :       CALL io_write_integer3(mlhSetID,(/1,1,1/),dimsInt(:3),"mlh",latharms%mlh)
     783          69 :       CALL h5dclose_f(mlhSetID, hdfError)
     784             : 
     785         345 :       dims(:4)=(/2,latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
     786         552 :       dimsInt = dims
     787          69 :       CALL h5screate_simple_f(4,dims(:4),clnuSpaceID,hdfError)
     788          69 :       CALL h5dcreate_f(groupID, "clnu", H5T_NATIVE_DOUBLE, clnuSpaceID, clnuSetID, hdfError)
     789          69 :       CALL h5sclose_f(clnuSpaceID,hdfError)
     790          69 :       CALL io_write_complex3(clnuSetID,(/-1,1,1,1/),dimsInt(:4),"clnu",latharms%clnu)
     791          69 :       CALL h5dclose_f(clnuSetID, hdfError)
     792             : 
     793          69 :       CALL h5gclose_f(groupID, hdfError)
     794             : 
     795          69 :    END SUBROUTINE writeLatharmsHDF
     796             : 
     797         418 :    SUBROUTINE readLatharmsHDF(fileID, latharmsIndex, latharms)
     798             :       use m_types_sphhar
     799             :       INTEGER(HID_T), INTENT(IN)  :: fileID
     800             :       INTEGER,        INTENT(IN)  :: latharmsIndex
     801             :       TYPE(t_sphhar), INTENT(INOUT) :: latharms
     802             : 
     803             :       INTEGER(HID_T)            :: nlhSetID, llhSetID, nmemSetID
     804             :       INTEGER(HID_T)            :: mlhSetID, clnuSetID, groupID
     805             :       CHARACTER(LEN=30)         :: groupName
     806             :       INTEGER                   :: hdfError
     807             :       INTEGER                   :: dimsInt(7)
     808             :       LOGICAL                   :: l_exist
     809             : 
     810         418 :       WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex
     811             : 
     812         418 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     813             : 
     814         418 :       IF (.NOT.l_exist) THEN
     815           0 :          CALL juDFT_error('latharms entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readLatharmsHDF")
     816             :       END IF
     817             : 
     818         418 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     819             : 
     820         418 :       CALL io_read_attint0(groupID,'ntypsd',latharms%ntypsd)
     821         418 :       CALL io_read_attint0(groupID,'memd',latharms%memd)
     822         418 :       CALL io_read_attint0(groupID,'nlhd',latharms%nlhd)
     823             : 
     824         418 :       IF(ALLOCATED(latharms%nlh)) DEALLOCATE(latharms%nlh)
     825         418 :       IF(ALLOCATED(latharms%llh)) DEALLOCATE(latharms%llh)
     826         418 :       IF(ALLOCATED(latharms%nmem)) DEALLOCATE(latharms%nmem)
     827         418 :       IF(ALLOCATED(latharms%mlh)) DEALLOCATE(latharms%mlh)
     828         418 :       IF(ALLOCATED(latharms%clnu)) DEALLOCATE(latharms%clnu)
     829             : 
     830        2090 :       ALLOCATE(latharms%clnu(latharms%memd,0:latharms%nlhd,latharms%ntypsd))
     831        1672 :       ALLOCATE(latharms%llh(0:latharms%nlhd,latharms%ntypsd))
     832        2090 :       ALLOCATE(latharms%mlh(latharms%memd,0:latharms%nlhd,latharms%ntypsd))
     833        2090 :       ALLOCATE(latharms%nlh(latharms%ntypsd),latharms%nmem(0:latharms%nlhd,latharms%ntypsd))
     834             : 
     835         836 :       dimsInt(:1)=(/latharms%ntypsd/)
     836         418 :       CALL h5dopen_f(groupID, 'nlh', nlhSetID, hdfError)
     837         418 :       CALL io_read_integer1(nlhSetID,(/1/),dimsInt(:1),"nlh",latharms%nlh)
     838         418 :       CALL h5dclose_f(nlhSetID, hdfError)
     839             : 
     840        1254 :       dimsInt(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
     841         418 :       CALL h5dopen_f(groupID, 'llh', llhSetID, hdfError)
     842         418 :       CALL io_read_integer2(llhSetID,(/1,1/),dimsInt(:2),"llh",latharms%llh)
     843         418 :       CALL h5dclose_f(llhSetID, hdfError)
     844             : 
     845        1254 :       dimsInt(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
     846         418 :       CALL h5dopen_f(groupID, 'nmem', nmemSetID, hdfError)
     847         418 :       CALL io_read_integer2(nmemSetID,(/1,1/),dimsInt(:2),"nmem",latharms%nmem)
     848         418 :       CALL h5dclose_f(nmemSetID, hdfError)
     849             : 
     850        1672 :       dimsInt(:3)=(/latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
     851         418 :       CALL h5dopen_f(groupID, 'mlh', mlhSetID, hdfError)
     852         418 :       CALL io_read_integer3(mlhSetID,(/1,1,1/),dimsInt(:3),"mlh",latharms%mlh)
     853         418 :       CALL h5dclose_f(mlhSetID, hdfError)
     854             : 
     855        2090 :       dimsInt(:4)=(/2,latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
     856         418 :       CALL h5dopen_f(groupID, 'clnu', clnuSetID, hdfError)
     857         418 :       CALL io_read_complex3(clnuSetID,(/-1,1,1,1/),dimsInt(:4),"clnu",latharms%clnu)
     858         418 :       CALL h5dclose_f(clnuSetID, hdfError)
     859             : 
     860         418 :       CALL h5gclose_f(groupID, hdfError)
     861             : 
     862        4180 :    END SUBROUTINE readLatharmsHDF
     863             : 
     864         836 :    SUBROUTINE peekLatharmsHDF(fileID, latharmsIndex, structureIndex)
     865             : 
     866             :       INTEGER(HID_T), INTENT(IN)    :: fileID
     867             :       INTEGER,        INTENT(IN)    :: latharmsIndex
     868             :       INTEGER,        INTENT(OUT)   :: structureIndex
     869             : 
     870             :       INTEGER(HID_T)            :: groupID
     871             :       INTEGER                   :: hdfError
     872             :       CHARACTER(LEN=30)         :: groupName
     873             :       LOGICAL                   :: l_exist
     874             : 
     875         418 :       WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex
     876             : 
     877         418 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     878             : 
     879         418 :       IF (.NOT.l_exist) THEN
     880           0 :          CALL juDFT_error('latharms entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readLatharmsHDF")
     881             :       END IF
     882             : 
     883         418 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     884         418 :       CALL io_read_attint0(groupID,'structureIndex',structureIndex)
     885         418 :       CALL h5gclose_f(groupID, hdfError)
     886             : 
     887         418 :    END SUBROUTINE peekLatharmsHDF
     888             : 
     889        3864 :    SUBROUTINE writeStructureHDF(fileID, input, atoms, cell, vacuum,   sym, structureIndex, l_CheckBroyd)
     890             :       use m_types_input
     891             :       use m_types_atoms
     892             :       use m_types_cell
     893             :       use m_types_vacuum
     894             : 
     895             :       use m_types_sym
     896             : 
     897             :       INTEGER(HID_T), INTENT(IN) :: fileID
     898             :       INTEGER, INTENT(IN)        :: structureIndex
     899             :       TYPE(t_input),INTENT(IN)   :: input
     900             :       TYPE(t_atoms), INTENT(IN)  :: atoms
     901             :       TYPE(t_cell), INTENT(IN)   :: cell
     902             :       TYPE(t_vacuum), INTENT(IN) :: vacuum
     903             : 
     904             :       TYPE(t_sym),INTENT(IN)     :: sym
     905             :       LOGICAL, INTENT(IN)        :: l_CheckBroyd
     906             : 
     907             :       INTEGER(HID_T)            :: groupID
     908             :       INTEGER                   :: hdfError, i
     909             :       INTEGER                   :: iPair, i_v, iOtherAtom ! for LDA+V
     910             :       CHARACTER(LEN=30)         :: groupName
     911             :       INTEGER(HSIZE_T)          :: dims(7)
     912             :       INTEGER                   :: dimsInt(7)
     913             :       LOGICAL                   :: l_exist
     914             : 
     915             :       !LDA+U arrays (start)
     916          69 :       INTEGER                   :: ldau_AtomType(MAX(1,atoms%n_u+atoms%n_hia))
     917          69 :       INTEGER                   :: ldau_l(MAX(1,atoms%n_u+atoms%n_hia))
     918          69 :       INTEGER                   :: ldau_l_amf(MAX(1,atoms%n_u+atoms%n_hia)) ! 1 = true, 0 = false
     919          69 :       REAL                      :: ldau_U(MAX(1,atoms%n_u+atoms%n_hia))
     920          69 :       REAL                      :: ldau_J(MAX(1,atoms%n_u+atoms%n_hia))
     921             :       !LDA+U arrays (end)
     922             : 
     923             :       !LDA+V arrays (start)
     924          69 :       INTEGER                   :: ldav_AtomIndex(MAX(1,atoms%n_v))
     925          69 :       INTEGER                   :: ldav_thisAtomL(MAX(1,atoms%n_v))
     926          69 :       INTEGER                   :: ldav_otherAtomL(MAX(1,atoms%n_v))
     927          69 :       INTEGER                   :: ldav_numOtherAtoms(MAX(1,atoms%n_v))
     928          69 :       INTEGER                   :: ldav_otherAtomIndices(MAX(1,atoms%n_vPairs))
     929          69 :       REAL                      :: ldav_V(MAX(1,atoms%n_v))
     930          69 :       REAL                      :: ldav_atomShifts(3,MAX(1,atoms%n_vPairs))
     931             :       !LDA+V arrays (end)
     932             : 
     933             :       !LDA+OP arrays (start)
     934          69 :       INTEGER                   :: ldaopc_atomType(MAX(1,atoms%n_opc))
     935          69 :       INTEGER                   :: ldaopc_l(MAX(1,atoms%n_opc))
     936          69 :       INTEGER                   :: ldaopc_n(MAX(1,atoms%n_opc)) ! 1 = true, 0 = false
     937             :       !LDA+OP arrays (end)
     938             : 
     939             :       INTEGER(HID_T)                   :: amatSpaceID, amatSetID
     940             :       INTEGER(HID_T)                   :: nzSpaceID, nzSetID
     941             :       INTEGER(HID_T)                   :: neqSpaceID, neqSetID
     942             :       INTEGER(HID_T)                   :: jriSpaceID, jriSetID
     943             :       INTEGER(HID_T)                   :: lmaxSpaceID, lmaxSetID
     944             :       INTEGER(HID_T)                   :: ngoprSpaceID, ngoprSetID
     945             :       INTEGER(HID_T)                   :: ntypsySpaceID, ntypsySetID
     946             :       INTEGER(HID_T)                   :: nlhtypSpaceID, nlhtypSetID
     947             :       INTEGER(HID_T)                   :: invsatSpaceID, invsatSetID
     948             :       INTEGER(HID_T)                   :: rmtSpaceID, rmtSetID
     949             :       INTEGER(HID_T)                   :: dxSpaceID, dxSetID
     950             :       INTEGER(HID_T)                   :: volmtsSpaceID, volmtsSetID
     951             :       INTEGER(HID_T)                   :: rmshSpaceID, rmshSetID
     952             :       INTEGER(HID_T)                   :: zatomSpaceID, zatomSetID
     953             :       INTEGER(HID_T)                   :: posSpaceID, posSetID
     954             :       INTEGER(HID_T)                   :: taualSpaceID, taualSetID
     955             :       INTEGER(HID_T)                   :: mrotSpaceID, mrotSetID
     956             :       INTEGER(HID_T)                   :: tauSpaceID, tauSetID
     957             : 
     958             :       !LDA+U IDs (start)
     959             :       INTEGER(HID_T)                   :: ldau_AtomTypeSpaceID, ldau_AtomTypeSetID
     960             :       INTEGER(HID_T)                   :: ldau_lSpaceID, ldau_lSetID
     961             :       INTEGER(HID_T)                   :: ldau_l_amfSpaceID, ldau_l_amfSetID
     962             :       INTEGER(HID_T)                   :: ldau_USpaceID, ldau_USetID
     963             :       INTEGER(HID_T)                   :: ldau_JSpaceID, ldau_JSetID
     964             :       !LDA+U IDs (end)
     965             : 
     966             :       !LDA+V IDs (start)
     967             :       INTEGER(HID_T)                   :: ldav_AtomIndexSpaceID, ldav_AtomIndexSetID
     968             :       INTEGER(HID_T)                   :: ldav_thisAtomLSpaceID, ldav_thisAtomLSetID
     969             :       INTEGER(HID_T)                   :: ldav_otherAtomLSpaceID, ldav_otherAtomLSetID
     970             :       INTEGER(HID_T)                   :: ldav_numOtherAtomsSpaceID, ldav_numOtherAtomsSetID
     971             :       INTEGER(HID_T)                   :: ldav_otherAtomIndicesSpaceID, ldav_otherAtomIndicesSetID
     972             :       INTEGER(HID_T)                   :: ldav_VSpaceID, ldav_VSetID
     973             :       INTEGER(HID_T)                   :: ldav_atomShiftsSpaceID, ldav_atomShiftsSetID
     974             :       !LDA+V IDs (end)
     975             : 
     976             :       !LDA+OP IDs (start)
     977             :       INTEGER(HID_T)                   :: ldaopc_AtomTypeSpaceID, ldaopc_AtomTypeSetID
     978             :       INTEGER(HID_T)                   :: ldaopc_lSpaceID, ldaopc_lSetID
     979             :       INTEGER(HID_T)                   :: ldaopc_nSpaceID, ldaopc_nSetID
     980             :       !LDA+OP IDs (end)
     981             : 
     982          69 :       WRITE(groupname,'(a,i0)') '/structure-', structureIndex
     983             : 
     984          69 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
     985             : 
     986          69 :       IF (l_exist) THEN
     987           0 :          CALL juDFT_error('structure entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeStructureHDF")
     988             :       END IF
     989             : 
     990          69 :       INQUIRE(FILE='broyd',EXIST=l_exist)
     991          69 :       IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
     992          69 :       IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Structure / parameter change but broyden files detected!')
     993             : 
     994          69 :       CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
     995             : 
     996          69 :       CALL io_write_attlog0(groupID,'l_film',input%film)
     997             : 
     998          69 :       CALL io_write_attreal0(groupID,'omtil',cell%omtil)
     999          69 :       CALL io_write_attreal0(groupID,'area',cell%area)
    1000          69 :       CALL io_write_attreal0(groupID,'z1',cell%z1)
    1001          69 :       CALL io_write_attreal0(groupID,'vol',cell%vol)
    1002          69 :       CALL io_write_attreal0(groupID,'volint',cell%volint)
    1003             : 
    1004          69 :       CALL io_write_attint0(groupID,'ntype',atoms%ntype)
    1005          69 :       CALL io_write_attint0(groupID,'nat',atoms%nat)
    1006          69 :       CALL io_write_attint0(groupID,'lmaxd',atoms%lmaxd)
    1007          69 :       CALL io_write_attint0(groupID,'jmtd',atoms%jmtd)
    1008          69 :       CALL io_write_attint0(groupID,'n_u',atoms%n_u+atoms%n_hia)
    1009          69 :       CALL io_write_attint0(groupID,'n_v',atoms%n_v)
    1010          69 :       CALL io_write_attint0(groupID,'n_vPairs',atoms%n_vPairs)
    1011          69 :       CALL io_write_attint0(groupID,'n_opc',atoms%n_opc)
    1012          69 :       CALL io_write_attlog0(groupID,'ldau_spinoffd',input%ldauSpinoffd)
    1013             : 
    1014          69 :       CALL io_write_attint0(groupID,'nmz',vacuum%nmz)
    1015          69 :       CALL io_write_attint0(groupID,'nmzd',vacuum%nmzd)
    1016          69 :       CALL io_write_attint0(groupID,'nmzxy',vacuum%nmzxy)
    1017          69 :       CALL io_write_attint0(groupID,'nmzxyd',vacuum%nmzxyd)
    1018             :       !CALL io_write_attint0(groupID,'layerd',banddos%layers)
    1019             :       !CALL io_write_attint0(groupID,'layers',banddos%layers)
    1020          69 :       CALL io_write_attint0(groupID,'nvac',vacuum%nvac)
    1021          69 :       CALL io_write_attint0(groupID,'nvacd',vacuum%nvacd)
    1022             :       !CALL io_write_attint0(groupID,'nstars',banddos%nstars)
    1023             :       !CALL io_write_attint0(groupID,'nstm',vacuum%nstm)
    1024          69 :       CALL io_write_attreal0(groupID,'delz',vacuum%delz)
    1025          69 :       CALL io_write_attreal0(groupID,'dvac',vacuum%dvac)
    1026             : 
    1027             : !      IO of od_nq2 has been moved to stars IO
    1028             : !      CALL io_write_attint0(groupID,'od_nq2' %odi%nq2)
    1029             : 
    1030          69 :       CALL io_write_attlog0(groupID,'invs2',sym%invs2)
    1031          69 :       CALL io_write_attlog0(groupID,'invs',sym%invs)
    1032          69 :       CALL io_write_attint0(groupID,'nop',sym%nop)
    1033          69 :       CALL io_write_attint0(groupID,'nop2',sym%nop2)
    1034             : 
    1035         207 :       dims(:2)=(/3,3/)
    1036         552 :       dimsInt = dims
    1037          69 :       CALL h5screate_simple_f(2,dims(:2),amatSpaceID,hdfError)
    1038          69 :       CALL h5dcreate_f(groupID, "amat", H5T_NATIVE_DOUBLE, amatSpaceID, amatSetID, hdfError)
    1039          69 :       CALL h5sclose_f(amatSpaceID,hdfError)
    1040          69 :       CALL io_write_real2(amatSetID,(/1,1/),dimsInt(:2),"amat",cell%amat)
    1041          69 :       CALL h5dclose_f(amatSetID, hdfError)
    1042             : 
    1043         138 :       dims(:1)=(/atoms%ntype/)
    1044         552 :       dimsInt = dims
    1045          69 :       CALL h5screate_simple_f(1,dims(:1),nzSpaceID,hdfError)
    1046          69 :       CALL h5dcreate_f(groupID, "nz", H5T_NATIVE_INTEGER, nzSpaceID, nzSetID, hdfError)
    1047          69 :       CALL h5sclose_f(nzSpaceID,hdfError)
    1048          69 :       CALL io_write_integer1(nzSetID,(/1/),dimsInt(:1),"nz",atoms%nz)
    1049          69 :       CALL h5dclose_f(nzSetID, hdfError)
    1050             : 
    1051         138 :       dims(:1)=(/atoms%ntype/)
    1052         552 :       dimsInt = dims
    1053          69 :       CALL h5screate_simple_f(1,dims(:1),neqSpaceID,hdfError)
    1054          69 :       CALL h5dcreate_f(groupID, "neq", H5T_NATIVE_INTEGER, neqSpaceID, neqSetID, hdfError)
    1055          69 :       CALL h5sclose_f(neqSpaceID,hdfError)
    1056          69 :       CALL io_write_integer1(neqSetID,(/1/),dimsInt(:1),"neq",atoms%neq)
    1057          69 :       CALL h5dclose_f(neqSetID, hdfError)
    1058             : 
    1059         138 :       dims(:1)=(/atoms%ntype/)
    1060         552 :       dimsInt = dims
    1061          69 :       CALL h5screate_simple_f(1,dims(:1),jriSpaceID,hdfError)
    1062          69 :       CALL h5dcreate_f(groupID, "jri", H5T_NATIVE_INTEGER, jriSpaceID, jriSetID, hdfError)
    1063          69 :       CALL h5sclose_f(jriSpaceID,hdfError)
    1064          69 :       CALL io_write_integer1(jriSetID,(/1/),dimsInt(:1),"jri",atoms%jri)
    1065          69 :       CALL h5dclose_f(jriSetID, hdfError)
    1066             : 
    1067         138 :       dims(:1)=(/atoms%ntype/)
    1068         552 :       dimsInt = dims
    1069          69 :       CALL h5screate_simple_f(1,dims(:1),lmaxSpaceID,hdfError)
    1070          69 :       CALL h5dcreate_f(groupID, "lmax", H5T_NATIVE_INTEGER, lmaxSpaceID, lmaxSetID, hdfError)
    1071          69 :       CALL h5sclose_f(lmaxSpaceID,hdfError)
    1072          69 :       CALL io_write_integer1(lmaxSetID,(/1/),dimsInt(:1),"lmax",atoms%lmax)
    1073          69 :       CALL h5dclose_f(lmaxSetID, hdfError)
    1074             : 
    1075         138 :       dims(:1)=(/atoms%nat/)
    1076         552 :       dimsInt = dims
    1077          69 :       CALL h5screate_simple_f(1,dims(:1),ngoprSpaceID,hdfError)
    1078          69 :       CALL h5dcreate_f(groupID, "ngopr", H5T_NATIVE_INTEGER, ngoprSpaceID, ngoprSetID, hdfError)
    1079          69 :       CALL h5sclose_f(ngoprSpaceID,hdfError)
    1080          69 :       CALL io_write_integer1(ngoprSetID,(/1/),dimsInt(:1),"ngopr",sym%ngopr)
    1081          69 :       CALL h5dclose_f(ngoprSetID, hdfError)
    1082             : 
    1083         138 :       dims(:1)=(/atoms%nat/)
    1084         552 :       dimsInt = dims
    1085          69 :       CALL h5screate_simple_f(1,dims(:1),ntypsySpaceID,hdfError)
    1086          69 :       CALL h5dcreate_f(groupID, "ntypsy", H5T_NATIVE_INTEGER, ntypsySpaceID, ntypsySetID, hdfError)
    1087          69 :       CALL h5sclose_f(ntypsySpaceID,hdfError)
    1088          69 :       CALL io_write_integer1(ntypsySetID,(/1/),dimsInt(:1),"ntypsy",sym%ntypsy)
    1089          69 :       CALL h5dclose_f(ntypsySetID, hdfError)
    1090             : 
    1091         138 :       dims(:1)=(/atoms%ntype/)
    1092         552 :       dimsInt = dims
    1093          69 :       CALL h5screate_simple_f(1,dims(:1),nlhtypSpaceID,hdfError)
    1094          69 :       CALL h5dcreate_f(groupID, "nlhtyp", H5T_NATIVE_INTEGER, nlhtypSpaceID, nlhtypSetID, hdfError)
    1095          69 :       CALL h5sclose_f(nlhtypSpaceID,hdfError)
    1096          69 :       CALL io_write_integer1(nlhtypSetID,(/1/),dimsInt(:1),"nlhtyp",atoms%nlhtyp)
    1097          69 :       CALL h5dclose_f(nlhtypSetID, hdfError)
    1098             : 
    1099         138 :       dims(:1)=(/atoms%nat/)
    1100         552 :       dimsInt = dims
    1101          69 :       CALL h5screate_simple_f(1,dims(:1),invsatSpaceID,hdfError)
    1102          69 :       CALL h5dcreate_f(groupID, "invsat", H5T_NATIVE_INTEGER, invsatSpaceID, invsatSetID, hdfError)
    1103          69 :       CALL h5sclose_f(invsatSpaceID,hdfError)
    1104          69 :       CALL io_write_integer1(invsatSetID,(/1/),dimsInt(:1),"invsat",sym%invsat)
    1105          69 :       CALL h5dclose_f(invsatSetID, hdfError)
    1106             : 
    1107         138 :       dims(:1)=(/atoms%ntype/)
    1108         552 :       dimsInt = dims
    1109          69 :       CALL h5screate_simple_f(1,dims(:1),rmtSpaceID,hdfError)
    1110          69 :       CALL h5dcreate_f(groupID, "rmt", H5T_NATIVE_DOUBLE, rmtSpaceID, rmtSetID, hdfError)
    1111          69 :       CALL h5sclose_f(rmtSpaceID,hdfError)
    1112          69 :       CALL io_write_real1(rmtSetID,(/1/),dimsInt(:1),"rmt",atoms%rmt)
    1113          69 :       CALL h5dclose_f(rmtSetID, hdfError)
    1114             : 
    1115         138 :       dims(:1)=(/atoms%ntype/)
    1116         552 :       dimsInt = dims
    1117          69 :       CALL h5screate_simple_f(1,dims(:1),dxSpaceID,hdfError)
    1118          69 :       CALL h5dcreate_f(groupID, "dx", H5T_NATIVE_DOUBLE, dxSpaceID, dxSetID, hdfError)
    1119          69 :       CALL h5sclose_f(dxSpaceID,hdfError)
    1120          69 :       CALL io_write_real1(dxSetID,(/1/),dimsInt(:1),"dx",atoms%dx)
    1121          69 :       CALL h5dclose_f(dxSetID, hdfError)
    1122             : 
    1123         138 :       dims(:1)=(/atoms%ntype/)
    1124         552 :       dimsInt = dims
    1125          69 :       CALL h5screate_simple_f(1,dims(:1),volmtsSpaceID,hdfError)
    1126          69 :       CALL h5dcreate_f(groupID, "volmts", H5T_NATIVE_DOUBLE, volmtsSpaceID, volmtsSetID, hdfError)
    1127          69 :       CALL h5sclose_f(volmtsSpaceID,hdfError)
    1128          69 :       CALL io_write_real1(volmtsSetID,(/1/),dimsInt(:1),"volmts",atoms%volmts)
    1129          69 :       CALL h5dclose_f(volmtsSetID, hdfError)
    1130             : 
    1131         207 :       dims(:2)=(/atoms%jmtd,atoms%ntype/)
    1132         552 :       dimsInt = dims
    1133          69 :       CALL h5screate_simple_f(2,dims(:2),rmshSpaceID,hdfError)
    1134          69 :       CALL h5dcreate_f(groupID, "rmsh", H5T_NATIVE_DOUBLE, rmshSpaceID, rmshSetID, hdfError)
    1135          69 :       CALL h5sclose_f(rmshSpaceID,hdfError)
    1136          69 :       CALL io_write_real2(rmshSetID,(/1,1/),dimsInt(:2),"rmsh",atoms%rmsh)
    1137          69 :       CALL h5dclose_f(rmshSetID, hdfError)
    1138             : 
    1139         138 :       dims(:1)=(/atoms%ntype/)
    1140         552 :       dimsInt = dims
    1141          69 :       CALL h5screate_simple_f(1,dims(:1),zatomSpaceID,hdfError)
    1142          69 :       CALL h5dcreate_f(groupID, "zatom", H5T_NATIVE_DOUBLE, zatomSpaceID, zatomSetID, hdfError)
    1143          69 :       CALL h5sclose_f(zatomSpaceID,hdfError)
    1144          69 :       CALL io_write_real1(zatomSetID,(/1/),dimsInt(:1),"zatom",atoms%zatom)
    1145          69 :       CALL h5dclose_f(zatomSetID, hdfError)
    1146             : 
    1147         207 :       dims(:2)=(/3,atoms%nat/)
    1148         552 :       dimsInt = dims
    1149          69 :       CALL h5screate_simple_f(2,dims(:2),posSpaceID,hdfError)
    1150          69 :       CALL h5dcreate_f(groupID, "pos", H5T_NATIVE_DOUBLE, posSpaceID, posSetID, hdfError)
    1151          69 :       CALL h5sclose_f(posSpaceID,hdfError)
    1152          69 :       CALL io_write_real2(posSetID,(/1,1/),dimsInt(:2),"pos",atoms%pos)
    1153          69 :       CALL h5dclose_f(posSetID, hdfError)
    1154             : 
    1155         207 :       dims(:2)=(/3,atoms%nat/)
    1156         552 :       dimsInt = dims
    1157          69 :       CALL h5screate_simple_f(2,dims(:2),taualSpaceID,hdfError)
    1158          69 :       CALL h5dcreate_f(groupID, "taual", H5T_NATIVE_DOUBLE, taualSpaceID, taualSetID, hdfError)
    1159          69 :       CALL h5sclose_f(taualSpaceID,hdfError)
    1160          69 :       CALL io_write_real2(taualSetID,(/1,1/),dimsInt(:2),"taual",atoms%taual)
    1161          69 :       CALL h5dclose_f(taualSetID, hdfError)
    1162             : 
    1163         276 :       dims(:3)=(/3,3,sym%nop/)
    1164         552 :       dimsInt = dims
    1165          69 :       CALL h5screate_simple_f(3,dims(:3),mrotSpaceID,hdfError)
    1166          69 :       CALL h5dcreate_f(groupID, "mrot", H5T_NATIVE_INTEGER, mrotSpaceID, mrotSetID, hdfError)
    1167          69 :       CALL h5sclose_f(mrotSpaceID,hdfError)
    1168          69 :       CALL io_write_integer3(mrotSetID,(/1,1,1/),dimsInt(:3),"mrot",sym%mrot)
    1169          69 :       CALL h5dclose_f(mrotSetID, hdfError)
    1170             : 
    1171         207 :       dims(:2)=(/3,sym%nop/)
    1172         552 :       dimsInt = dims
    1173          69 :       CALL h5screate_simple_f(2,dims(:2),tauSpaceID,hdfError)
    1174          69 :       CALL h5dcreate_f(groupID, "tau", H5T_NATIVE_DOUBLE, tauSpaceID, tauSetID, hdfError)
    1175          69 :       CALL h5sclose_f(tauSpaceID,hdfError)
    1176          69 :       CALL io_write_real2(tauSetID,(/1,1/),dimsInt(:2),"tau",sym%tau)
    1177          69 :       CALL h5dclose_f(tauSetID, hdfError)
    1178             : 
    1179             :       !LDA+U data (start)
    1180          69 :       IF(atoms%n_u+atoms%n_hia.GT.0) THEN
    1181          14 :          ldau_l_amf = 0
    1182          14 :          DO i = 1, atoms%n_u+atoms%n_hia
    1183           9 :             ldau_AtomType(i) = atoms%lda_u(i)%atomType
    1184           9 :             ldau_l(i) = atoms%lda_u(i)%l
    1185           9 :             ldau_U(i) = atoms%lda_u(i)%u
    1186           9 :             ldau_J(i) = atoms%lda_u(i)%j
    1187          14 :             IF(atoms%lda_u(i)%l_amf) ldau_l_amf(i) = 1
    1188             :          END DO
    1189             : 
    1190          10 :          dims(:1)=(/atoms%n_u+atoms%n_hia/)
    1191          40 :          dimsInt = dims
    1192           5 :          CALL h5screate_simple_f(1,dims(:1),ldau_AtomTypeSpaceID,hdfError)
    1193           5 :          CALL h5dcreate_f(groupID, "ldau_AtomType", H5T_NATIVE_INTEGER, ldau_AtomTypeSpaceID, ldau_AtomTypeSetID, hdfError)
    1194           5 :          CALL h5sclose_f(ldau_AtomTypeSpaceID,hdfError)
    1195           5 :          CALL io_write_integer1(ldau_AtomTypeSetID,(/1/),dimsInt(:1),"ldau_AtomType",ldau_AtomType(:atoms%n_u+atoms%n_hia))
    1196           5 :          CALL h5dclose_f(ldau_AtomTypeSetID, hdfError)
    1197             : 
    1198          10 :          dims(:1)=(/atoms%n_u+atoms%n_hia/)
    1199          40 :          dimsInt = dims
    1200           5 :          CALL h5screate_simple_f(1,dims(:1),ldau_lSpaceID,hdfError)
    1201           5 :          CALL h5dcreate_f(groupID, "ldau_l", H5T_NATIVE_INTEGER, ldau_lSpaceID, ldau_lSetID, hdfError)
    1202           5 :          CALL h5sclose_f(ldau_lSpaceID,hdfError)
    1203           5 :          CALL io_write_integer1(ldau_lSetID,(/1/),dimsInt(:1),"ldau_l",ldau_l(:atoms%n_u+atoms%n_hia))
    1204           5 :          CALL h5dclose_f(ldau_lSetID, hdfError)
    1205             : 
    1206          10 :          dims(:1)=(/atoms%n_u+atoms%n_hia/)
    1207          40 :          dimsInt = dims
    1208           5 :          CALL h5screate_simple_f(1,dims(:1),ldau_l_amfSpaceID,hdfError)
    1209           5 :          CALL h5dcreate_f(groupID, "ldau_l_amf", H5T_NATIVE_INTEGER, ldau_l_amfSpaceID, ldau_l_amfSetID, hdfError)
    1210           5 :          CALL h5sclose_f(ldau_l_amfSpaceID,hdfError)
    1211           5 :          CALL io_write_integer1(ldau_l_amfSetID,(/1/),dimsInt(:1),"ldau_l_amf",ldau_l_amf(:atoms%n_u+atoms%n_hia))
    1212           5 :          CALL h5dclose_f(ldau_l_amfSetID, hdfError)
    1213             : 
    1214          10 :          dims(:1)=(/atoms%n_u+atoms%n_hia/)
    1215          40 :          dimsInt = dims
    1216           5 :          CALL h5screate_simple_f(1,dims(:1),ldau_USpaceID,hdfError)
    1217           5 :          CALL h5dcreate_f(groupID, "ldau_U", H5T_NATIVE_DOUBLE, ldau_USpaceID, ldau_USetID, hdfError)
    1218           5 :          CALL h5sclose_f(ldau_USpaceID,hdfError)
    1219           5 :          CALL io_write_real1(ldau_USetID,(/1/),dimsInt(:1),"ldau_U",ldau_U(:atoms%n_u+atoms%n_hia))
    1220           5 :          CALL h5dclose_f(ldau_USetID, hdfError)
    1221             : 
    1222          10 :          dims(:1)=(/atoms%n_u+atoms%n_hia/)
    1223          40 :          dimsInt = dims
    1224           5 :          CALL h5screate_simple_f(1,dims(:1),ldau_JSpaceID,hdfError)
    1225           5 :          CALL h5dcreate_f(groupID, "ldau_J", H5T_NATIVE_DOUBLE, ldau_JSpaceID, ldau_JSetID, hdfError)
    1226           5 :          CALL h5sclose_f(ldau_JSpaceID,hdfError)
    1227           5 :          CALL io_write_real1(ldau_JSetID,(/1/),dimsInt(:1),"ldau_J",ldau_J(:atoms%n_u+atoms%n_hia))
    1228           5 :          CALL h5dclose_f(ldau_JSetID, hdfError)
    1229             :       END IF
    1230             :       !LDA+U data (end)
    1231             : 
    1232             :       !LDA+V data (start)
    1233          69 :       IF(atoms%n_v.GT.0) THEN
    1234             :          iPair = 0
    1235           0 :          DO i_v = 1, atoms%n_v
    1236           0 :             ldav_atomIndex(i_v) = atoms%lda_v(i_v)%atomIndex
    1237           0 :             ldav_thisAtomL(i_v) = atoms%lda_v(i_v)%thisAtomL
    1238           0 :             ldav_otherAtomL(i_v) = atoms%lda_v(i_v)%otherAtomL
    1239           0 :             ldav_numOtherAtoms(i_v) = atoms%lda_v(i_v)%numOtherAtoms
    1240           0 :             ldav_V(i_v) = atoms%lda_v(i_v)%V
    1241           0 :             DO iOtherAtom = 1, atoms%lda_v(i_v)%numOtherAtoms
    1242           0 :                iPair = iPair + 1
    1243           0 :                ldav_otherAtomIndices(iPair) = atoms%lda_v(i_v)%otherAtomIndices(iOtherAtom)
    1244           0 :                ldav_atomShifts(:,iPair) = atoms%lda_v(i_v)%atomShifts(:,iOtherAtom)
    1245             :             END DO
    1246             :          END DO
    1247             : 
    1248           0 :          dims(:1)=(/atoms%n_v/)
    1249           0 :          dimsInt = dims
    1250           0 :          CALL h5screate_simple_f(1,dims(:1),ldav_AtomIndexSpaceID,hdfError)
    1251           0 :          CALL h5dcreate_f(groupID, "ldav_AtomIndex", H5T_NATIVE_INTEGER, ldav_AtomIndexSpaceID, ldav_AtomIndexSetID, hdfError)
    1252           0 :          CALL h5sclose_f(ldav_AtomIndexSpaceID,hdfError)
    1253           0 :          CALL io_write_integer1(ldav_AtomIndexSetID,(/1/),dimsInt(:1),"ldav_AtomIndex",ldav_atomIndex(:atoms%n_v))
    1254           0 :          CALL h5dclose_f(ldav_AtomIndexSetID, hdfError)
    1255             : 
    1256           0 :          dims(:1)=(/atoms%n_v/)
    1257           0 :          dimsInt = dims
    1258           0 :          CALL h5screate_simple_f(1,dims(:1),ldav_thisAtomLSpaceID,hdfError)
    1259           0 :          CALL h5dcreate_f(groupID, "ldav_thisAtomL", H5T_NATIVE_INTEGER, ldav_thisAtomLSpaceID, ldav_thisAtomLSetID, hdfError)
    1260           0 :          CALL h5sclose_f(ldav_thisAtomLSpaceID,hdfError)
    1261           0 :          CALL io_write_integer1(ldav_thisAtomLSetID,(/1/),dimsInt(:1),"ldav_thisAtomL",ldav_thisAtomL(:atoms%n_v))
    1262           0 :          CALL h5dclose_f(ldav_thisAtomLSetID, hdfError)
    1263             : 
    1264           0 :          dims(:1)=(/atoms%n_v/)
    1265           0 :          dimsInt = dims
    1266           0 :          CALL h5screate_simple_f(1,dims(:1),ldav_otherAtomLSpaceID,hdfError)
    1267           0 :          CALL h5dcreate_f(groupID, "ldav_otherAtomL", H5T_NATIVE_INTEGER, ldav_otherAtomLSpaceID, ldav_otherAtomLSetID, hdfError)
    1268           0 :          CALL h5sclose_f(ldav_otherAtomLSpaceID,hdfError)
    1269           0 :          CALL io_write_integer1(ldav_otherAtomLSetID,(/1/),dimsInt(:1),"ldav_otherAtomL",ldav_otherAtomL(:atoms%n_v))
    1270           0 :          CALL h5dclose_f(ldav_otherAtomLSetID, hdfError)
    1271             : 
    1272           0 :          dims(:1)=(/atoms%n_v/)
    1273           0 :          dimsInt = dims
    1274           0 :          CALL h5screate_simple_f(1,dims(:1),ldav_numOtherAtomsSpaceID,hdfError)
    1275           0 :          CALL h5dcreate_f(groupID, "ldav_numOtherAtoms", H5T_NATIVE_INTEGER, ldav_numOtherAtomsSpaceID, ldav_numOtherAtomsSetID, hdfError)
    1276           0 :          CALL h5sclose_f(ldav_numOtherAtomsSpaceID,hdfError)
    1277           0 :          CALL io_write_integer1(ldav_numOtherAtomsSetID,(/1/),dimsInt(:1),"ldav_numOtherAtoms",ldav_numOtherAtoms(:atoms%n_v))
    1278           0 :          CALL h5dclose_f(ldav_numOtherAtomsSetID, hdfError)
    1279             : 
    1280           0 :          dims(:1)=(/atoms%n_v/)
    1281           0 :          dimsInt = dims
    1282           0 :          CALL h5screate_simple_f(1,dims(:1),ldav_VSpaceID,hdfError)
    1283           0 :          CALL h5dcreate_f(groupID, "ldav_V", H5T_NATIVE_DOUBLE, ldav_VSpaceID, ldav_VSetID, hdfError)
    1284           0 :          CALL h5sclose_f(ldav_VSpaceID,hdfError)
    1285           0 :          CALL io_write_real1(ldav_VSetID,(/1/),dimsInt(:1),"ldav_V",ldav_V(:atoms%n_v))
    1286           0 :          CALL h5dclose_f(ldav_VSetID, hdfError)
    1287             : 
    1288           0 :          dims(:1)=(/atoms%n_vPairs/)
    1289           0 :          dimsInt = dims
    1290           0 :          CALL h5screate_simple_f(1,dims(:1),ldav_otherAtomIndicesSpaceID,hdfError)
    1291           0 :          CALL h5dcreate_f(groupID, "ldav_otherAtomIndices", H5T_NATIVE_INTEGER, ldav_otherAtomIndicesSpaceID, ldav_otherAtomIndicesSetID, hdfError)
    1292           0 :          CALL h5sclose_f(ldav_otherAtomIndicesSpaceID,hdfError)
    1293           0 :          CALL io_write_integer1(ldav_otherAtomIndicesSetID,(/1/),dimsInt(:1),"ldav_otherAtomIndices",ldav_otherAtomIndices(:atoms%n_vPairs))
    1294           0 :          CALL h5dclose_f(ldav_otherAtomIndicesSetID, hdfError)
    1295             : 
    1296           0 :          dims(:2)=(/3,atoms%n_vPairs/)
    1297           0 :          dimsInt = dims
    1298           0 :          CALL h5screate_simple_f(2,dims(:2),ldav_atomShiftsSpaceID,hdfError)
    1299           0 :          CALL h5dcreate_f(groupID, "ldav_atomShifts", H5T_NATIVE_DOUBLE, ldav_atomShiftsSpaceID, ldav_atomShiftsSetID, hdfError)
    1300           0 :          CALL h5sclose_f(ldav_atomShiftsSpaceID,hdfError)
    1301           0 :          CALL io_write_real2(ldav_atomShiftsSetID,(/1,1/),dimsInt(:2),"ldav_atomShifts",ldav_atomShifts(:,:atoms%n_vPairs))
    1302           0 :          CALL h5dclose_f(ldav_atomShiftsSetID, hdfError)
    1303             :       END IF
    1304             :       !LDA+V data (end)
    1305             : 
    1306             :       !LDA+OP data (start)
    1307          69 :       IF(atoms%n_opc.GT.0) THEN
    1308           3 :          DO i = 1, atoms%n_opc
    1309           2 :             ldaopc_AtomType(i) = atoms%lda_opc(i)%atomType
    1310           2 :             ldaopc_l(i) = atoms%lda_opc(i)%l
    1311           3 :             ldaopc_n(i) = atoms%lda_opc(i)%n
    1312             :          END DO
    1313             : 
    1314           2 :          dims(:1)=(/atoms%n_opc/)
    1315           8 :          dimsInt = dims
    1316           1 :          CALL h5screate_simple_f(1,dims(:1),ldaopc_AtomTypeSpaceID,hdfError)
    1317           1 :          CALL h5dcreate_f(groupID, "ldaopc_AtomType", H5T_NATIVE_INTEGER, ldaopc_AtomTypeSpaceID, ldaopc_AtomTypeSetID, hdfError)
    1318           1 :          CALL h5sclose_f(ldaopc_AtomTypeSpaceID,hdfError)
    1319           1 :          CALL io_write_integer1(ldaopc_AtomTypeSetID,(/1/),dimsInt(:1),"ldaopc_AtomType",ldaopc_AtomType(:atoms%n_opc))
    1320           1 :          CALL h5dclose_f(ldaopc_AtomTypeSetID, hdfError)
    1321             : 
    1322           2 :          dims(:1)=(/atoms%n_opc/)
    1323           8 :          dimsInt = dims
    1324           1 :          CALL h5screate_simple_f(1,dims(:1),ldaopc_lSpaceID,hdfError)
    1325           1 :          CALL h5dcreate_f(groupID, "ldaopc_l", H5T_NATIVE_INTEGER, ldaopc_lSpaceID, ldaopc_lSetID, hdfError)
    1326           1 :          CALL h5sclose_f(ldaopc_lSpaceID,hdfError)
    1327           1 :          CALL io_write_integer1(ldaopc_lSetID,(/1/),dimsInt(:1),"ldaopc_l",ldaopc_l(:atoms%n_opc))
    1328           1 :          CALL h5dclose_f(ldaopc_lSetID, hdfError)
    1329             : 
    1330           2 :          dims(:1)=(/atoms%n_opc/)
    1331           8 :          dimsInt = dims
    1332           1 :          CALL h5screate_simple_f(1,dims(:1),ldaopc_nSpaceID,hdfError)
    1333           1 :          CALL h5dcreate_f(groupID, "ldaopc_n", H5T_NATIVE_INTEGER, ldaopc_nSpaceID, ldaopc_nSetID, hdfError)
    1334           1 :          CALL h5sclose_f(ldaopc_nSpaceID,hdfError)
    1335           1 :          CALL io_write_integer1(ldaopc_nSetID,(/1/),dimsInt(:1),"ldaopc_n",ldaopc_n(:atoms%n_opc))
    1336           1 :          CALL h5dclose_f(ldaopc_nSetID, hdfError)
    1337             :       END IF
    1338             :       !LDA+OP data (end)
    1339             : 
    1340          69 :       CALL h5gclose_f(groupID, hdfError)
    1341             : 
    1342          69 :    END SUBROUTINE writeStructureHDF
    1343             : 
    1344         507 :    SUBROUTINE readStructureHDF(fileID, input, atoms, cell, vacuum,   sym,structureIndex)
    1345             :       use m_types_input
    1346             :       use m_types_atoms
    1347             :       use m_types_cell
    1348             :       use m_types_vacuum
    1349             : 
    1350             :       use m_types_sym
    1351             : 
    1352             :       INTEGER(HID_T), INTENT(IN)    :: fileID
    1353             :       INTEGER, INTENT(IN)           :: structureIndex
    1354             :       TYPE(t_input),INTENT(INOUT)   :: input
    1355             :       TYPE(t_atoms), INTENT(INOUT)  :: atoms
    1356             :       TYPE(t_cell), INTENT(INOUT)   :: cell
    1357             :       TYPE(t_vacuum), INTENT(INOUT) :: vacuum
    1358             : 
    1359             :       TYPE(t_sym),INTENT(INOUT)     :: sym
    1360             : 
    1361             :       INTEGER(HID_T)            :: groupID, generalGroupID
    1362             :       INTEGER                   :: hdfError, fileFormatVersion, i
    1363             :       INTEGER                   :: i_v, iPair, iOtherAtom
    1364             :       CHARACTER(LEN=30)         :: groupName
    1365             :       INTEGER                   :: dimsInt(7)
    1366             :       LOGICAL                   :: l_exist
    1367             : 
    1368             :       !LDA+U arrays (start)
    1369         507 :       INTEGER, ALLOCATABLE             :: ldau_AtomType(:)
    1370         507 :       INTEGER, ALLOCATABLE             :: ldau_l(:)
    1371         507 :       INTEGER, ALLOCATABLE             :: ldau_l_amf(:) ! 1 = true, 0 = false
    1372         507 :       REAL, ALLOCATABLE                :: ldau_U(:)
    1373         507 :       REAL, ALLOCATABLE                :: ldau_J(:)
    1374             :       !LDA+U arrays (end)
    1375             : 
    1376             :       !LDA+V arrays (start)
    1377         507 :       INTEGER, ALLOCATABLE             :: ldav_AtomIndex(:)
    1378         507 :       INTEGER, ALLOCATABLE             :: ldav_thisAtomL(:)
    1379         507 :       INTEGER, ALLOCATABLE             :: ldav_otherAtomL(:)
    1380         507 :       INTEGER, ALLOCATABLE             :: ldav_numOtherAtoms(:)
    1381         507 :       INTEGER, ALLOCATABLE             :: ldav_otherAtomIndices(:)
    1382         507 :       REAL, ALLOCATABLE                :: ldav_atomShifts(:,:)
    1383         507 :       REAL, ALLOCATABLE                :: ldav_V(:)
    1384             :       !LDA+V arrays (end)
    1385             : 
    1386             :       !LDA+OP arrays (start)
    1387         507 :       INTEGER, ALLOCATABLE             :: ldaopc_AtomType(:)
    1388         507 :       INTEGER, ALLOCATABLE             :: ldaopc_l(:)
    1389         507 :       INTEGER, ALLOCATABLE             :: ldaopc_n(:)
    1390             :       !LDA+OP arrays (end)
    1391             : 
    1392             :       INTEGER(HID_T)                   :: amatSetID
    1393             :       INTEGER(HID_T)                   :: nzSetID
    1394             :       INTEGER(HID_T)                   :: neqSetID
    1395             :       INTEGER(HID_T)                   :: jriSetID
    1396             :       INTEGER(HID_T)                   :: lmaxSetID
    1397             :       INTEGER(HID_T)                   :: ngoprSetID
    1398             :       INTEGER(HID_T)                   :: ntypsySetID
    1399             :       INTEGER(HID_T)                   :: nlhtypSetID
    1400             :       INTEGER(HID_T)                   :: invsatSetID
    1401             :       INTEGER(HID_T)                   :: rmtSetID
    1402             :       INTEGER(HID_T)                   :: dxSetID
    1403             :       INTEGER(HID_T)                   :: volmtsSetID
    1404             :       INTEGER(HID_T)                   :: rmshSetID
    1405             :       INTEGER(HID_T)                   :: zatomSetID
    1406             :       INTEGER(HID_T)                   :: posSetID
    1407             :       INTEGER(HID_T)                   :: taualSetID
    1408             :       INTEGER(HID_T)                   :: mrotSetID
    1409             :       INTEGER(HID_T)                   :: tauSetID
    1410             : 
    1411             :       !LDA+U IDs (start)
    1412             :       INTEGER(HID_T)                   :: ldau_AtomTypeSetID
    1413             :       INTEGER(HID_T)                   :: ldau_lSetID
    1414             :       INTEGER(HID_T)                   :: ldau_l_amfSetID
    1415             :       INTEGER(HID_T)                   :: ldau_USetID
    1416             :       INTEGER(HID_T)                   :: ldau_JSetID
    1417             :       !LDA+U IDs (end)
    1418             : 
    1419             :       !LDA+V IDs (start)
    1420             :       INTEGER(HID_T)                   :: ldav_AtomIndexSetID
    1421             :       INTEGER(HID_T)                   :: ldav_thisAtomLSetID
    1422             :       INTEGER(HID_T)                   :: ldav_otherAtomLSetID
    1423             :       INTEGER(HID_T)                   :: ldav_numOtherAtomsSetID
    1424             :       INTEGER(HID_T)                   :: ldav_otherAtomIndicesSetID
    1425             :       INTEGER(HID_T)                   :: ldav_VSetID
    1426             :       INTEGER(HID_T)                   :: ldav_atomShiftsSetID
    1427             :       !LDA+V IDs (end)
    1428             : 
    1429             :       !LDA+OP IDs (start)
    1430             :       INTEGER(HID_T)                   :: ldaopc_AtomTypeSetID
    1431             :       INTEGER(HID_T)                   :: ldaopc_lSetID
    1432             :       INTEGER(HID_T)                   :: ldaopc_nSetID
    1433             :       !LDA+OP IDs (end)
    1434             : 
    1435         507 :       CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
    1436             :       ! read in file format version from the header '/general'
    1437         507 :       CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
    1438         507 :       CALL h5gclose_f(generalGroupID,hdfError)
    1439             : 
    1440         507 :       WRITE(groupname,'(a,i0)') '/structure-', structureIndex
    1441             : 
    1442         507 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    1443             : 
    1444         507 :       IF (.NOT.l_exist) THEN
    1445           0 :          CALL juDFT_error('structure entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStructureHDF")
    1446             :       END IF
    1447             : 
    1448         507 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    1449             : 
    1450         507 :       CALL io_read_attlog0(groupID,'l_film',input%film)
    1451             : 
    1452         507 :       CALL io_read_attreal0(groupID,'omtil',cell%omtil)
    1453         507 :       CALL io_read_attreal0(groupID,'area',cell%area)
    1454         507 :       CALL io_read_attreal0(groupID,'z1',cell%z1)
    1455         507 :       CALL io_read_attreal0(groupID,'vol',cell%vol)
    1456         507 :       CALL io_read_attreal0(groupID,'volint',cell%volint)
    1457             : 
    1458         507 :       CALL io_read_attint0(groupID,'ntype',atoms%ntype)
    1459         507 :       CALL io_read_attint0(groupID,'nat',atoms%nat)
    1460         507 :       CALL io_read_attint0(groupID,'lmaxd',atoms%lmaxd)
    1461         507 :       CALL io_read_attint0(groupID,'jmtd',atoms%jmtd)
    1462             : 
    1463         507 :       CALL io_read_attint0(groupID,'nmz',vacuum%nmz)
    1464         507 :       CALL io_read_attint0(groupID,'nmzd',vacuum%nmzd)
    1465         507 :       CALL io_read_attint0(groupID,'nmzxy',vacuum%nmzxy)
    1466         507 :       CALL io_read_attint0(groupID,'nmzxyd',vacuum%nmzxyd)
    1467             :       !CALL io_read_attint0(groupID,'layerd',banddos%layers)
    1468             :       !CALL io_read_attint0(groupID,'layers',banddos%layers)
    1469         507 :       CALL io_read_attint0(groupID,'nvac',vacuum%nvac)
    1470         507 :       CALL io_read_attint0(groupID,'nvacd',vacuum%nvacd)
    1471             :       !CALL io_read_attint0(groupID,'nstars',banddos%nstars)
    1472             :       !CALL io_read_attint0(groupID,'nstm',vacuum%nstm)
    1473         507 :       CALL io_read_attreal0(groupID,'delz',vacuum%delz)
    1474         507 :       CALL io_read_attreal0(groupID,'dvac',vacuum%dvac)
    1475             : 
    1476             : 
    1477         507 :       CALL io_read_attlog0(groupID,'invs2',sym%invs2)
    1478         507 :       CALL io_read_attlog0(groupID,'invs',sym%invs)
    1479         507 :       CALL io_read_attint0(groupID,'nop',sym%nop)
    1480         507 :       CALL io_read_attint0(groupID,'nop2',sym%nop2)
    1481             : 
    1482         507 :       IF(fileFormatVersion.GE.29) THEN
    1483         507 :          CALL io_read_attint0(groupID,'n_u',atoms%n_u)
    1484         507 :          IF(ALLOCATED(atoms%lda_u)) DEALLOCATE(atoms%lda_u)
    1485        1645 :          ALLOCATE(atoms%lda_u(atoms%n_u))
    1486             :       END IF
    1487             : 
    1488         507 :       IF(fileFormatVersion.GE.35) THEN
    1489         507 :          CALL io_read_attint0(groupID,'n_v',atoms%n_v)
    1490         507 :          CALL io_read_attint0(groupID,'n_vPairs',atoms%n_vPairs)
    1491         507 :          IF(ALLOCATED(atoms%lda_v)) DEALLOCATE(atoms%lda_v)
    1492        1521 :          ALLOCATE(atoms%lda_v(atoms%n_v))
    1493             :       END IF
    1494             : 
    1495         507 :       IF(fileFormatVersion.GE.34) THEN
    1496         507 :          CALL io_read_attint0(groupID,'n_opc',atoms%n_opc)
    1497         507 :          IF(ALLOCATED(atoms%lda_opc)) DEALLOCATE(atoms%lda_opc)
    1498        1549 :          ALLOCATE(atoms%lda_opc(atoms%n_opc))
    1499             :       END IF
    1500             : 
    1501         507 :       IF(io_attexists(groupID,'ldau_spinoffd')) THEN
    1502         507 :          CALL io_read_attlog0(groupID,'ldau_spinoffd',input%ldauSpinoffd)
    1503             :       END IF
    1504             : 
    1505         507 :       IF(ALLOCATED(atoms%nz)) DEALLOCATE(atoms%nz)
    1506         507 :       IF(ALLOCATED(atoms%neq)) DEALLOCATE(atoms%neq)
    1507         507 :       IF(ALLOCATED(atoms%jri)) DEALLOCATE(atoms%jri)
    1508         507 :       IF(ALLOCATED(atoms%lmax)) DEALLOCATE(atoms%lmax)
    1509         507 :       IF(ALLOCATED(sym%ngopr)) DEALLOCATE(sym%ngopr)
    1510         507 :       IF(ALLOCATED(sym%ntypsy)) DEALLOCATE(sym%ntypsy)
    1511         507 :       IF(ALLOCATED(atoms%nlhtyp)) DEALLOCATE(atoms%nlhtyp)
    1512         507 :       IF(ALLOCATED(sym%invsat)) DEALLOCATE(sym%invsat)
    1513         507 :       IF(ALLOCATED(atoms%rmt)) DEALLOCATE(atoms%rmt)
    1514         507 :       IF(ALLOCATED(atoms%dx)) DEALLOCATE(atoms%dx)
    1515         507 :       IF(ALLOCATED(atoms%volmts)) DEALLOCATE(atoms%volmts)
    1516         507 :       IF(ALLOCATED(atoms%rmsh)) DEALLOCATE(atoms%rmsh)
    1517         507 :       IF(ALLOCATED(atoms%zatom)) DEALLOCATE(atoms%zatom)
    1518         507 :       IF(ALLOCATED(atoms%pos)) DEALLOCATE(atoms%pos)
    1519         507 :       IF(ALLOCATED(atoms%taual)) DEALLOCATE(atoms%taual)
    1520         507 :       IF(ALLOCATED(sym%mrot)) DEALLOCATE(sym%mrot)
    1521         507 :       IF(ALLOCATED(sym%tau)) DEALLOCATE(sym%tau)
    1522             : 
    1523        1521 :       ALLOCATE(atoms%nz(atoms%ntype))
    1524        1014 :       ALLOCATE(atoms%neq(atoms%ntype))
    1525        1014 :       ALLOCATE(atoms%jri(atoms%ntype))
    1526        1014 :       ALLOCATE(atoms%lmax(atoms%ntype))
    1527        1521 :       ALLOCATE(sym%ngopr(atoms%nat))
    1528        1014 :       ALLOCATE(sym%ntypsy(atoms%nat))
    1529        1014 :       ALLOCATE(atoms%nlhtyp(atoms%ntype))
    1530        1014 :       ALLOCATE(sym%invsat(atoms%nat))
    1531        1521 :       ALLOCATE(atoms%rmt(atoms%ntype))
    1532        1014 :       ALLOCATE(atoms%dx(atoms%ntype))
    1533        1014 :       ALLOCATE(atoms%volmts(atoms%ntype))
    1534        2028 :       ALLOCATE(atoms%rmsh(atoms%jmtd,atoms%ntype))
    1535        1014 :       ALLOCATE(atoms%zatom(atoms%ntype))
    1536        1521 :       ALLOCATE(atoms%pos(3,atoms%nat))
    1537        1014 :       ALLOCATE(atoms%taual(3,atoms%nat))
    1538        1521 :       ALLOCATE(sym%mrot(3,3,sym%nop))
    1539        1521 :       ALLOCATE(sym%tau(3,sym%nop))
    1540             : 
    1541        1521 :       dimsInt(:2)=(/3,3/)
    1542         507 :       CALL h5dopen_f(groupID, 'amat', amatSetID, hdfError)
    1543         507 :       CALL io_read_real2(amatSetID,(/1,1/),dimsInt(:2),"amat",cell%amat)
    1544         507 :       CALL h5dclose_f(amatSetID, hdfError)
    1545             : 
    1546        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1547         507 :       CALL h5dopen_f(groupID, 'nz', nzSetID, hdfError)
    1548         507 :       CALL io_read_integer1(nzSetID,(/1/),dimsInt(:1),"nz",atoms%nz)
    1549         507 :       CALL h5dclose_f(nzSetID, hdfError)
    1550             : 
    1551        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1552         507 :       CALL h5dopen_f(groupID, 'neq', neqSetID, hdfError)
    1553         507 :       CALL io_read_integer1(neqSetID,(/1/),dimsInt(:1),"neq",atoms%neq)
    1554         507 :       CALL h5dclose_f(neqSetID, hdfError)
    1555             : 
    1556        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1557         507 :       CALL h5dopen_f(groupID, 'jri', jriSetID, hdfError)
    1558         507 :       CALL io_read_integer1(jriSetID,(/1/),dimsInt(:1),"jri",atoms%jri)
    1559         507 :       CALL h5dclose_f(jriSetID, hdfError)
    1560             : 
    1561        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1562         507 :       CALL h5dopen_f(groupID, 'lmax', lmaxSetID, hdfError)
    1563         507 :       CALL io_read_integer1(lmaxSetID,(/1/),dimsInt(:1),"lmax",atoms%lmax)
    1564         507 :       CALL h5dclose_f(lmaxSetID, hdfError)
    1565             : 
    1566        1014 :       dimsInt(:1)=(/atoms%nat/)
    1567         507 :       CALL h5dopen_f(groupID, 'ngopr', ngoprSetID, hdfError)
    1568         507 :       CALL io_read_integer1(ngoprSetID,(/1/),dimsInt(:1),"ngopr",sym%ngopr)
    1569         507 :       CALL h5dclose_f(ngoprSetID, hdfError)
    1570             : 
    1571        1014 :       dimsInt(:1)=(/atoms%nat/)
    1572         507 :       CALL h5dopen_f(groupID, 'ntypsy', ntypsySetID, hdfError)
    1573         507 :       CALL io_read_integer1(ntypsySetID,(/1/),dimsInt(:1),"ntypsy",sym%ntypsy)
    1574         507 :       CALL h5dclose_f(ntypsySetID, hdfError)
    1575             : 
    1576        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1577         507 :       CALL h5dopen_f(groupID, 'nlhtyp', nlhtypSetID, hdfError)
    1578         507 :       CALL io_read_integer1(nlhtypSetID,(/1/),dimsInt(:1),"nlhtyp",atoms%nlhtyp)
    1579         507 :       CALL h5dclose_f(nlhtypSetID, hdfError)
    1580             : 
    1581        1014 :       dimsInt(:1)=(/atoms%nat/)
    1582         507 :       CALL h5dopen_f(groupID, 'invsat', invsatSetID, hdfError)
    1583         507 :       CALL io_read_integer1(invsatSetID,(/1/),dimsInt(:1),"invsat",sym%invsat)
    1584         507 :       CALL h5dclose_f(invsatSetID, hdfError)
    1585             : 
    1586        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1587         507 :       CALL h5dopen_f(groupID, 'rmt', rmtSetID, hdfError)
    1588         507 :       CALL io_read_real1(rmtSetID,(/1/),dimsInt(:1),"rmt",atoms%rmt)
    1589         507 :       CALL h5dclose_f(rmtSetID, hdfError)
    1590             : 
    1591        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1592         507 :       CALL h5dopen_f(groupID, 'dx', dxSetID, hdfError)
    1593         507 :       CALL io_read_real1(dxSetID,(/1/),dimsInt(:1),"dx",atoms%dx)
    1594         507 :       CALL h5dclose_f(dxSetID, hdfError)
    1595             : 
    1596        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1597         507 :       CALL h5dopen_f(groupID, 'volmts', volmtsSetID, hdfError)
    1598         507 :       CALL io_read_real1(volmtsSetID,(/1/),dimsInt(:1),"volmts",atoms%volmts)
    1599         507 :       CALL h5dclose_f(volmtsSetID, hdfError)
    1600             : 
    1601        1521 :       dimsInt(:2)=(/atoms%jmtd,atoms%ntype/)
    1602         507 :       CALL h5dopen_f(groupID, 'rmsh', rmshSetID, hdfError)
    1603         507 :       CALL io_read_real2(rmshSetID,(/1,1/),dimsInt(:2),"rmsh",atoms%rmsh)
    1604         507 :       CALL h5dclose_f(rmshSetID, hdfError)
    1605             : 
    1606        1014 :       dimsInt(:1)=(/atoms%ntype/)
    1607         507 :       CALL h5dopen_f(groupID, 'zatom', zatomSetID, hdfError)
    1608         507 :       CALL io_read_real1(zatomSetID,(/1/),dimsInt(:1),"zatom",atoms%zatom)
    1609         507 :       CALL h5dclose_f(zatomSetID, hdfError)
    1610             : 
    1611        1521 :       dimsInt(:2)=(/3,atoms%nat/)
    1612         507 :       CALL h5dopen_f(groupID, 'pos', posSetID, hdfError)
    1613         507 :       CALL io_read_real2(posSetID,(/1,1/),dimsInt(:2),"pos",atoms%pos)
    1614         507 :       CALL h5dclose_f(posSetID, hdfError)
    1615             : 
    1616        1521 :       dimsInt(:2)=(/3,atoms%nat/)
    1617         507 :       CALL h5dopen_f(groupID, 'taual', taualSetID, hdfError)
    1618         507 :       CALL io_read_real2(taualSetID,(/1,1/),dimsInt(:2),"taual",atoms%taual)
    1619         507 :       CALL h5dclose_f(taualSetID, hdfError)
    1620             : 
    1621        2028 :       dimsInt(:3) = (/3,3,sym%nop/)
    1622         507 :       CALL h5dopen_f(groupID, 'mrot', mrotSetID, hdfError)
    1623         507 :       CALL io_read_integer3(mrotSetID,(/1,1,1/),dimsInt(:3),"mrot",sym%mrot)
    1624         507 :       CALL h5dclose_f(mrotSetID, hdfError)
    1625             : 
    1626        1521 :       dimsInt(:2) = (/3,sym%nop/)
    1627         507 :       CALL h5dopen_f(groupID, 'tau', tauSetID, hdfError)
    1628         507 :       CALL io_read_real2(tauSetID,(/1,1/),dimsInt(:2),"tau",sym%tau)
    1629         507 :       CALL h5dclose_f(tauSetID, hdfError)
    1630             : 
    1631             :       !LDA+U data (start)
    1632         507 :       IF((fileFormatVersion.GE.29).AND.(atoms%n_u.GT.0)) THEN
    1633         235 :          ALLOCATE(ldau_AtomType(atoms%n_u), ldau_l(atoms%n_u), ldau_l_amf(atoms%n_u))
    1634         188 :          ALLOCATE(ldau_U(atoms%n_u), ldau_J(atoms%n_u))
    1635             : 
    1636          94 :          dimsInt(:1)=(/atoms%n_u/)
    1637          47 :          CALL h5dopen_f(groupID, 'ldau_AtomType', ldau_AtomTypeSetID, hdfError)
    1638          47 :          CALL io_read_integer1(ldau_AtomTypeSetID,(/1/),dimsInt(:1),"ldau_AtomType",ldau_AtomType)
    1639          47 :          CALL h5dclose_f(ldau_AtomTypeSetID, hdfError)
    1640             : 
    1641          94 :          dimsInt(:1)=(/atoms%n_u/)
    1642          47 :          CALL h5dopen_f(groupID, 'ldau_l', ldau_lSetID, hdfError)
    1643          47 :          CALL io_read_integer1(ldau_lSetID,(/1/),dimsInt(:1),"ldau_l",ldau_l)
    1644          47 :          CALL h5dclose_f(ldau_lSetID, hdfError)
    1645             : 
    1646          94 :          dimsInt(:1)=(/atoms%n_u/)
    1647          47 :          CALL h5dopen_f(groupID, 'ldau_l_amf', ldau_l_amfSetID, hdfError)
    1648          47 :          CALL io_read_integer1(ldau_l_amfSetID,(/1/),dimsInt(:1),"ldau_l_amf",ldau_l_amf)
    1649          47 :          CALL h5dclose_f(ldau_l_amfSetID, hdfError)
    1650             : 
    1651          94 :          dimsInt(:1)=(/atoms%n_u/)
    1652          47 :          CALL h5dopen_f(groupID, 'ldau_U', ldau_USetID, hdfError)
    1653          47 :          CALL io_read_real1(ldau_USetID,(/1/),dimsInt(:1),"ldau_U",ldau_U)
    1654          47 :          CALL h5dclose_f(ldau_USetID, hdfError)
    1655             : 
    1656          94 :          dimsInt(:1)=(/atoms%n_u/)
    1657          47 :          CALL h5dopen_f(groupID, 'ldau_J', ldau_JSetID, hdfError)
    1658          47 :          CALL io_read_real1(ldau_JSetID,(/1/),dimsInt(:1),"ldau_J",ldau_J)
    1659          47 :          CALL h5dclose_f(ldau_JSetID, hdfError)
    1660             : 
    1661         171 :          DO i = 1, atoms%n_u
    1662         124 :             atoms%lda_u(i)%atomType = ldau_AtomType(i)
    1663         124 :             atoms%lda_u(i)%l = ldau_l(i)
    1664         124 :             atoms%lda_u(i)%u = ldau_U(i)
    1665         124 :             atoms%lda_u(i)%j = ldau_J(i)
    1666         124 :             atoms%lda_u(i)%l_amf = .FALSE.
    1667         171 :             IF(ldau_l_amf(i).EQ.1) atoms%lda_u(i)%l_amf = .TRUE.
    1668             :          END DO
    1669         517 :          DEALLOCATE(ldau_AtomType,ldau_l,ldau_U,ldau_J,ldau_l_amf)
    1670             :       END IF
    1671             :       !LDA+U data (end)
    1672             : 
    1673             :       !LDA+V data (start)
    1674         507 :       IF((fileFormatVersion.GE.35).AND.(atoms%n_v.GT.0)) THEN
    1675           0 :          ALLOCATE(ldav_AtomIndex(atoms%n_v),ldav_thisAtomL(atoms%n_v),ldav_otherAtomL(atoms%n_v),ldav_V(atoms%n_v),ldav_numOtherAtoms(atoms%n_v))
    1676           0 :          ALLOCATE(ldav_otherAtomIndices(atoms%n_vPairs),ldav_atomShifts(3,atoms%n_vPairs))
    1677             : 
    1678           0 :          dimsInt(:1)=(/atoms%n_v/)
    1679           0 :          CALL h5dopen_f(groupID, 'ldav_AtomIndex', ldav_AtomIndexSetID, hdfError)
    1680           0 :          CALL io_read_integer1(ldav_AtomIndexSetID,(/1/),dimsInt(:1),"ldav_AtomIndex",ldav_AtomIndex)
    1681           0 :          CALL h5dclose_f(ldav_AtomIndexSetID, hdfError)
    1682             : 
    1683           0 :          dimsInt(:1)=(/atoms%n_v/)
    1684           0 :          CALL h5dopen_f(groupID, 'ldav_thisAtomL', ldav_thisAtomLSetID, hdfError)
    1685           0 :          CALL io_read_integer1(ldav_thisAtomLSetID,(/1/),dimsInt(:1),"ldav_thisAtomL",ldav_thisAtomL)
    1686           0 :          CALL h5dclose_f(ldav_thisAtomLSetID, hdfError)
    1687             : 
    1688           0 :          dimsInt(:1)=(/atoms%n_v/)
    1689           0 :          CALL h5dopen_f(groupID, 'ldav_otherAtomL', ldav_otherAtomLSetID, hdfError)
    1690           0 :          CALL io_read_integer1(ldav_otherAtomLSetID,(/1/),dimsInt(:1),"ldav_otherAtomL",ldav_otherAtomL)
    1691           0 :          CALL h5dclose_f(ldav_otherAtomLSetID, hdfError)
    1692             : 
    1693           0 :          dimsInt(:1)=(/atoms%n_v/)
    1694           0 :          CALL h5dopen_f(groupID, 'ldav_numOtherAtoms', ldav_numOtherAtomsSetID, hdfError)
    1695           0 :          CALL io_read_integer1(ldav_numOtherAtomsSetID,(/1/),dimsInt(:1),"ldav_numOtherAtoms",ldav_numOtherAtoms)
    1696           0 :          CALL h5dclose_f(ldav_numOtherAtomsSetID, hdfError)
    1697             : 
    1698           0 :          dimsInt(:1)=(/atoms%n_v/)
    1699           0 :          CALL h5dopen_f(groupID, 'ldav_V', ldav_VSetID, hdfError)
    1700           0 :          CALL io_read_real1(ldav_VSetID,(/1/),dimsInt(:1),"ldav_V",ldav_V)
    1701           0 :          CALL h5dclose_f(ldav_VSetID, hdfError)
    1702             : 
    1703           0 :          dimsInt(:1)=(/atoms%n_vPairs/)
    1704           0 :          CALL h5dopen_f(groupID, 'ldav_otherAtomIndices', ldav_otherAtomIndicesSetID, hdfError)
    1705           0 :          CALL io_read_integer1(ldav_otherAtomIndicesSetID,(/1/),dimsInt(:1),"ldav_otherAtomIndices",ldav_otherAtomIndices)
    1706           0 :          CALL h5dclose_f(ldav_otherAtomIndicesSetID, hdfError)
    1707             : 
    1708           0 :          dimsInt(:2) = (/3,atoms%n_vPairs/)
    1709           0 :          CALL h5dopen_f(groupID, 'ldav_atomShifts', ldav_atomShiftsSetID, hdfError)
    1710           0 :          CALL io_read_real2(ldav_atomShiftsSetID,(/1,1/),dimsInt(:2),"ldav_atomShifts",ldav_atomShifts)
    1711           0 :          CALL h5dclose_f(ldav_atomShiftsSetID, hdfError)
    1712             : 
    1713           0 :          iPair = 0
    1714           0 :          DO i_v = 1, atoms%n_v
    1715           0 :             atoms%lda_v(i_v)%atomIndex = ldav_AtomIndex(i_v)
    1716           0 :             atoms%lda_v(i_v)%thisAtomL = ldav_thisAtomL(i_v)
    1717           0 :             atoms%lda_v(i_v)%otherAtomL = ldav_otherAtomL(i_v)
    1718           0 :             atoms%lda_v(i_v)%numOtherAtoms = ldav_numOtherAtoms(i_v)
    1719           0 :             atoms%lda_v(i_v)%V = ldav_V(i_v)
    1720           0 :             ALLOCATE(atoms%lda_v(i_v)%otherAtomIndices(ldav_numOtherAtoms(i_v)))
    1721           0 :             ALLOCATE(atoms%lda_v(i_v)%atomShifts(3,ldav_numOtherAtoms(i_v)))
    1722           0 :             DO iOtherAtom = 1, atoms%lda_v(i_v)%numOtherAtoms
    1723           0 :                iPair = iPair + 1
    1724           0 :                atoms%lda_v(i_v)%otherAtomIndices(iOtherAtom) = ldav_otherAtomIndices(iPair)
    1725           0 :                atoms%lda_v(i_v)%atomShifts(:,iOtherAtom) = ldav_atomShifts(:,iPair)
    1726             :             END DO
    1727             :          END DO
    1728           0 :          DEALLOCATE(ldav_AtomIndex,ldav_thisAtomL,ldav_otherAtomL,ldav_V,ldav_otherAtomIndices,ldav_atomShifts,ldav_numOtherAtoms)
    1729             :       END IF
    1730             :       !LDA+V data (end)
    1731             : 
    1732             :       !LDA+OP data (start)
    1733         507 :       IF((fileFormatVersion.GE.34).AND.(atoms%n_opc.GT.0)) THEN
    1734          70 :          ALLOCATE(ldaopc_AtomType(atoms%n_opc), ldaopc_l(atoms%n_opc), ldaopc_n(atoms%n_opc))
    1735             : 
    1736          28 :          dimsInt(:1)=(/atoms%n_opc/)
    1737          14 :          CALL h5dopen_f(groupID, 'ldaopc_AtomType', ldaopc_AtomTypeSetID, hdfError)
    1738          14 :          CALL io_read_integer1(ldaopc_AtomTypeSetID,(/1/),dimsInt(:1),"ldaopc_AtomType",ldaopc_AtomType)
    1739          14 :          CALL h5dclose_f(ldaopc_AtomTypeSetID, hdfError)
    1740             : 
    1741          28 :          dimsInt(:1)=(/atoms%n_opc/)
    1742          14 :          CALL h5dopen_f(groupID, 'ldaopc_l', ldaopc_lSetID, hdfError)
    1743          14 :          CALL io_read_integer1(ldaopc_lSetID,(/1/),dimsInt(:1),"ldaopc_l",ldaopc_l)
    1744          14 :          CALL h5dclose_f(ldaopc_lSetID, hdfError)
    1745             : 
    1746          28 :          dimsInt(:1)=(/atoms%n_opc/)
    1747          14 :          CALL h5dopen_f(groupID, 'ldaopc_n', ldaopc_nSetID, hdfError)
    1748          14 :          CALL io_read_integer1(ldaopc_nSetID,(/1/),dimsInt(:1),"ldaopc_n",ldaopc_n)
    1749          14 :          CALL h5dclose_f(ldaopc_nSetID, hdfError)
    1750             : 
    1751          42 :          DO i = 1, atoms%n_opc
    1752          28 :             atoms%lda_opc(i)%atomType = ldaopc_AtomType(i)
    1753          28 :             atoms%lda_opc(i)%l = ldaopc_l(i)
    1754          42 :             atoms%lda_opc(i)%n = ldaopc_n(i)
    1755             :          END DO
    1756          98 :          DEALLOCATE(ldaopc_AtomType,ldaopc_l,ldaopc_n)
    1757             :       END IF
    1758             :       !LDA+U data (end)
    1759             : 
    1760         507 :       CALL h5gclose_f(groupID, hdfError)
    1761             : 
    1762       19266 :    END SUBROUTINE readStructureHDF
    1763             : 
    1764        8279 :    SUBROUTINE writeDensityHDF(input, fileID, archiveName, densityType, previousDensityIndex,&
    1765             :                               starsIndex, latharmsIndex, structureIndex, stepfunctionIndex,&
    1766             :                               date,time,distance,fermiEnergy,mmpmatDistance,occDistance,l_qfix,iter,den,denIm)
    1767             :       use m_types_input
    1768             :       use m_types_potden
    1769             :       TYPE(t_input),    INTENT(IN) :: input
    1770             :       TYPE(t_potden),   INTENT(IN) :: den
    1771             :       INTEGER(HID_T),   INTENT(IN) :: fileID
    1772             :       INTEGER,          INTENT(IN) :: densityType, previousDensityIndex
    1773             :       INTEGER,          INTENT(IN) :: starsIndex, latharmsIndex, structureIndex
    1774             :       INTEGER,          INTENT(IN) :: stepfunctionIndex
    1775             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    1776             : 
    1777             :       INTEGER, INTENT (IN)         :: date, time, iter
    1778             :       REAL,    INTENT (IN)         :: fermiEnergy, distance
    1779             :       REAL,    INTENT (IN)         :: mmpmatDistance, occDistance
    1780             :       LOGICAL, INTENT (IN)         :: l_qfix
    1781             : 
    1782             :       TYPE(t_potden), OPTIONAL, INTENT(IN) :: denIm
    1783             : 
    1784             :       INTEGER                      :: i, iVac
    1785             :       INTEGER                      :: ntype,jmtd,nmzd,nmzxyd,nlhd,ng3,ng2
    1786             :       INTEGER                      :: nmz,nvac,od_nq2,nmzxy,n_u,n_opc
    1787             :       INTEGER                      :: n_v, n_vPairs
    1788             :       INTEGER                      :: hdfError, fileFormatVersion
    1789             :       LOGICAL                      :: l_film,l_exist,l_delete,l_spinoffd_ldau
    1790             :       INTEGER(HID_T)               :: archiveID, groupID, generalGroupID
    1791             :       CHARACTER(LEN=30)            :: groupName, densityTypeName
    1792             :       INTEGER(HSIZE_T)             :: dims(7)
    1793             :       INTEGER                      :: dimsInt(7)
    1794             :       INTEGER                      :: starsIndexTemp, latharmsIndexTemp
    1795             :       INTEGER                      :: structureIndexTemp, stepfunctionIndexTemp
    1796             :       INTEGER                      :: jspinsTemp
    1797             : 
    1798             :       INTEGER(HID_T)               :: frSpaceID, frSetID, frOffSetID, frOffSpaceID
    1799             :       INTEGER(HID_T)               :: fpwSpaceID, fpwSetID
    1800             :       INTEGER(HID_T)               :: fzSpaceID, fzSetID
    1801             :       INTEGER(HID_T)               :: fzxySpaceID, fzxySetID
    1802             :       INTEGER(HID_T)               :: fvacSpaceID, fvacSetID
    1803             :       INTEGER(HID_T)               :: cdomSpaceID, cdomSetID
    1804             :       INTEGER(HID_T)               :: cdomvzSpaceID, cdomvzSetID
    1805             :       INTEGER(HID_T)               :: cdomvxySpaceID, cdomvxySetID
    1806             :       INTEGER(HID_T)               :: cdomvacSpaceID, cdomvacSetID
    1807             :       INTEGER(HID_T)               :: mmpMatSpaceID, mmpMatSetID
    1808             :       INTEGER(HID_T)               :: nIJ_llp_mmpSpaceID, nIJ_llp_mmpSetID
    1809             :       INTEGER(HID_T)               :: frImSpaceID, frImSetID, frOffImSetID, frOffImSpaceID, cdom12SpaceID, cdom12SetID
    1810             : 
    1811             :       COMPLEX, ALLOCATABLE         :: cdomvz(:,:)
    1812             : 
    1813         487 :       CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
    1814             :       ! read in file format version from the header '/general'
    1815         487 :       CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
    1816         487 :       CALL h5gclose_f(generalGroupID,hdfError)
    1817             : 
    1818         487 :       WRITE(groupname,'(a,i0)') '/structure-', structureIndex
    1819         487 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    1820         487 :       IF(.NOT.l_exist) THEN
    1821           0 :          CALL juDFT_error("Structure entry "//TRIM(ADJUSTL(groupName))//" does not exist",calledby ="writeDensityHDF")
    1822             :       END IF
    1823         487 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    1824         487 :       CALL io_read_attlog0(groupID,'l_film',l_film)
    1825         487 :       CALL io_read_attint0(groupID,'ntype',ntype)
    1826         487 :       CALL io_read_attint0(groupID,'jmtd',jmtd)
    1827         487 :       CALL io_read_attint0(groupID,'nmzd',nmzd)
    1828         487 :       CALL io_read_attint0(groupID,'nmzxyd',nmzxyd)
    1829         487 :       CALL io_read_attint0(groupID,'nmzxy',nmzxy)
    1830         487 :       CALL io_read_attint0(groupID,'nmz',nmz)
    1831         487 :       CALL io_read_attint0(groupID,'nvac',nvac)
    1832             : 
    1833         487 :       n_u = 0
    1834         487 :       IF(fileFormatVersion.GE.29) THEN
    1835         487 :          CALL io_read_attint0(groupID,'n_u',n_u)
    1836         487 :          IF(fileFormatVersion.GE.34) THEN
    1837         487 :             CALL io_read_attint0(groupID,'n_opc',n_opc)
    1838         487 :             n_u = n_u + n_opc
    1839             :          ENDIF
    1840             :       END IF
    1841             : 
    1842         487 :       n_v = 0
    1843         487 :       n_vPairs = 0
    1844         487 :       IF(fileFormatVersion.GE.35) THEN
    1845         487 :          CALL io_read_attint0(groupID,'n_v',n_v)
    1846         487 :          CALL io_read_attint0(groupID,'n_vPairs',n_vPairs)
    1847             :       END IF
    1848             : 
    1849         487 :       l_spinoffd_ldau = .false.
    1850         487 :       IF(io_attexists(groupID,'ldau_spinoffd')) THEN
    1851         487 :          CALL io_read_attlog0(groupID,'ldau_spinoffd',l_spinoffd_ldau)
    1852             :       END IF
    1853             : 
    1854         487 :       CALL h5gclose_f(groupID, hdfError)
    1855             : 
    1856         487 :       WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex
    1857         487 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    1858         487 :       IF(.NOT.l_exist) THEN
    1859           0 :          CALL juDFT_error("Latharms entry "//TRIM(ADJUSTL(groupName))//" does not exist",calledby ="writeDensityHDF")
    1860             :       END IF
    1861         487 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    1862         487 :       CALL io_read_attint0(groupID,'nlhd',nlhd)
    1863         487 :       CALL h5gclose_f(groupID, hdfError)
    1864             : 
    1865         487 :       WRITE(groupname,'(a,i0)') '/stars-', starsIndex
    1866         487 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    1867         487 :       IF(.NOT.l_exist) THEN
    1868           0 :          CALL juDFT_error("Stars entry "//TRIM(ADJUSTL(groupName))//" does not exist",calledby ="writeDensityHDF")
    1869             :       END IF
    1870         487 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    1871         487 :       CALL io_read_attint0(groupID,'ng3',ng3)
    1872         487 :       CALL io_read_attint0(groupID,'ng2',ng2)
    1873         487 :       CALL h5gclose_f(groupID, hdfError)
    1874             : 
    1875         487 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    1876             : 
    1877         514 :       SELECT CASE (densityType)
    1878             :           CASE(DENSITY_TYPE_FFN_IN_const)
    1879          27 :              densityTypeName = '/ffn_in'
    1880             :           CASE(DENSITY_TYPE_FFN_OUT_const)
    1881           0 :              densityTypeName = '/ffn_out'
    1882             :          CASE(DENSITY_TYPE_IN_const)
    1883         359 :             densityTypeName = '/in'
    1884             :          CASE(DENSITY_TYPE_OUT_const)
    1885           0 :             densityTypeName = '/out'
    1886             :          CASE(DENSITY_TYPE_NOCO_IN_const)
    1887         101 :             densityTypeName = '/noco_in'
    1888             :          CASE(DENSITY_TYPE_NOCO_OUT_const)
    1889           0 :             densityTypeName = '/noco_out'
    1890             :          CASE(DENSITY_TYPE_PRECOND_const)
    1891           0 :             densityTypeName = '/precond'
    1892             :          CASE DEFAULT
    1893         487 :             CALL juDFT_error("Unknown density type selected",calledby ="writeDensityHDF")
    1894             :       END SELECT
    1895             : 
    1896         487 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    1897             : 
    1898         487 :       l_delete = .FALSE.
    1899         487 :       IF(l_exist) THEN
    1900          78 :          CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    1901             : 
    1902          78 :          CALL io_read_attint0(archiveID,'starsIndex',starsIndexTemp)
    1903          78 :          CALL io_read_attint0(archiveID,'latharmsIndex',latharmsIndexTemp)
    1904          78 :          CALL io_read_attint0(archiveID,'structureIndex',structureIndexTemp)
    1905          78 :          CALL io_read_attint0(archiveID,'stepfunctionIndex',stepfunctionIndexTemp)
    1906          78 :          CALL io_read_attint0(archiveID,'spins',jspinsTemp)
    1907             : 
    1908          78 :          IF (starsIndex.NE.starsIndexTemp) l_delete = .TRUE.
    1909          78 :          IF (latharmsIndex.NE.latharmsIndexTemp) l_delete = .TRUE.
    1910          78 :          IF (structureIndex.NE.structureIndexTemp) l_delete = .TRUE.
    1911          78 :          IF (stepfunctionIndex.NE.stepfunctionIndexTemp) l_delete = .TRUE.
    1912          78 :          IF (input%jspins.NE.jspinsTemp) l_delete = .TRUE.
    1913             : 
    1914          78 :          CALL h5gclose_f(archiveID, hdfError)
    1915             :       END IF
    1916             : 
    1917          78 :       IF(l_delete) THEN
    1918           1 :          CALL h5ldelete_f(fileID, archiveName, hdfError)
    1919             :          l_exist = .FALSE.
    1920             :       END IF
    1921             : 
    1922         486 :       IF(l_exist) THEN
    1923          77 :          CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    1924             : 
    1925          77 :          CALL io_write_attint0(archiveID,'previousDensityIndex',previousDensityIndex)
    1926          77 :          CALL io_write_attint0(archiveID,'starsIndex',starsIndex)
    1927          77 :          CALL io_write_attint0(archiveID,'latharmsIndex',latharmsIndex)
    1928          77 :          CALL io_write_attint0(archiveID,'structureIndex',structureIndex)
    1929          77 :          CALL io_write_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    1930          77 :          CALL io_write_attint0(archiveID,'spins',input%jspins)
    1931          77 :          CALL io_write_attint0(archiveID,'iter',iter)
    1932          77 :          IF (distance.GE.-1e-10) THEN
    1933           0 :             CALL io_write_attreal0(archiveID,'distance',distance)
    1934             :          END IF
    1935             : 
    1936          77 :          IF(n_u.GT.0) THEN
    1937           8 :             IF(mmpmatDistance.GE.-1e-10) THEN
    1938           0 :                CALL io_write_attreal0(archiveID,'mmpmatDistance',mmpmatDistance)
    1939             :             ENDIF
    1940           8 :             IF(occDistance.GE.-1e-10) THEN
    1941           0 :                CALL io_write_attreal0(archiveID,'occDistance',occDistance)
    1942             :             ENDIF
    1943             :          ENDIF
    1944             : 
    1945          77 :          l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    1946             : 
    1947          77 :          IF(l_exist) THEN
    1948             : 
    1949          60 :             CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    1950             : 
    1951          60 :             CALL io_write_attreal0(groupID,'fermiEnergy',fermiEnergy)
    1952          60 :             CALL io_write_attlog0(groupID,'l_qfix',l_qfix)
    1953             : 
    1954             :             !dimsInt(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    1955             :             !CALL h5dopen_f(groupID, 'fr', frSetID, hdfError)
    1956             :             ! Note: The last dimension of den%mt (input%jspins) is temporary to
    1957             :             ! avoid segmentation faults if l_mperp is set to true but there
    1958             :             ! already is a data set with l_mperp=false. At the moment this is ok
    1959             :             ! since the offdiagonal parts are never read.
    1960             :             !CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),den%mt(:,0:,:,:input%jspins))
    1961             :             !CALL h5dclose_f(frSetID, hdfError)
    1962             : 
    1963         240 :             dimsInt(:3)=(/2,ng3,input%jspins/)
    1964          60 :             CALL h5dopen_f(groupID, 'fpw', fpwSetID, hdfError)
    1965          60 :             CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"pw",den%pw(:,:input%jspins))
    1966          60 :             CALL h5dclose_f(fpwSetID, hdfError)
    1967             : 
    1968          60 :             IF (l_film) THEN
    1969          66 :                dimsInt(:5)=(/2,nmzd,ng2,2,input%jspins/)
    1970          11 :                CALL h5dopen_f(groupID, 'fvac', fvacSetID, hdfError)
    1971          11 :                CALL io_write_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"vac",den%vac(:,:,:,:input%jspins))
    1972          11 :                CALL h5dclose_f(fvacSetID, hdfError)
    1973             :             END IF
    1974             : 
    1975             :             IF((densityType.EQ.DENSITY_TYPE_NOCO_IN_const).OR.&
    1976          60 :                (densityType.EQ.DENSITY_TYPE_NOCO_OUT_const).OR.(densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    1977             :                   (densityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    1978             : 
    1979          21 :                dimsInt(:2)=(/2,ng3/)
    1980           7 :                CALL h5dopen_f(groupID, 'cdom', cdomSetID, hdfError)
    1981           7 :                CALL io_write_complex1(cdomSetID,(/-1,1/),dimsInt(:2),"pw",den%pw(:,3))
    1982           7 :                CALL h5dclose_f(cdomSetID, hdfError)
    1983             : 
    1984           7 :                IF (PRESENT(denIm)) THEN
    1985           0 :                   dimsInt(:2)=(/2,ng3/)
    1986           0 :                   CALL h5dopen_f(groupID, 'cdom12', cdom12SetID, hdfError)
    1987           0 :                   CALL io_write_complex1(cdom12SetID,(/-1,1/),dimsInt(:2),"pw12",den%pw(:,4))
    1988           0 :                   CALL h5dclose_f(cdom12SetID, hdfError)
    1989             :                END IF
    1990             : 
    1991           7 :                IF (l_film) THEN
    1992           0 :                   dimsInt(:4)=(/2,nmz,ng2,nvac/)
    1993           0 :                   CALL h5dopen_f(groupID, 'cdomvac', cdomvacSetID, hdfError)
    1994           0 :                   CALL io_write_complex3(cdomvacSetID,(/-1,1,1,1/),dimsInt(:4),"cdomvac",den%vac(:,:,:nvac,3))
    1995           0 :                   CALL h5dclose_f(cdomvacSetID, hdfError)
    1996             :                END IF
    1997             :             ENDIF
    1998             : 
    1999          60 :             IF ((fileFormatVersion.GE.29).AND.(n_u.GT.0)) THEN
    2000             :                IF((densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2001           7 :                   (densityType.EQ.DENSITY_TYPE_FFN_OUT_const).OR.&
    2002             :                   l_spinoffd_ldau) THEN
    2003           0 :                   dimsInt(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u,3/)
    2004           0 :                   CALL h5dopen_f(groupID, 'mmpMat', mmpMatSetID, hdfError)
    2005           0 :                   CALL io_write_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMat",den%mmpMat)
    2006           0 :                   CALL h5dclose_f(mmpMatSetID, hdfError)
    2007             :                ELSE
    2008          42 :                   dimsInt(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u,input%jspins/)
    2009           7 :                   CALL h5dopen_f(groupID, 'mmpMat', mmpMatSetID, hdfError)
    2010           7 :                   CALL io_write_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMat",den%mmpMat(:,:,:,:input%jspins))
    2011           7 :                   CALL h5dclose_f(mmpMatSetID, hdfError)
    2012             :                ENDIF
    2013             :             ENDIF
    2014             : 
    2015          60 :             IF ((fileFormatVersion.GE.35).AND.(n_v.GT.0)) THEN
    2016           0 :                   dimsInt(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_vPairs,input%jspins/)
    2017           0 :                   CALL h5dopen_f(groupID, 'nIJ_llp_mmp', nIJ_llp_mmpSetID, hdfError)
    2018           0 :                   CALL io_write_complex4(nIJ_llp_mmpSetID,(/-1,1,1,1,1/),dimsInt(:5),"nIJ_llp_mmp",den%nIJ_llp_mmp(:,:,:,:input%jspins))
    2019           0 :                   CALL h5dclose_f(nIJ_llp_mmpSetID, hdfError)
    2020             :             END IF
    2021             : 
    2022          60 :             CALL h5gclose_f(groupID, hdfError)
    2023             :          ELSE
    2024          17 :             CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2025             : 
    2026          17 :             CALL io_write_attreal0(groupID,'fermiEnergy',fermiEnergy)
    2027          17 :             CALL io_write_attlog0(groupID,'l_qfix',l_qfix)
    2028             : 
    2029             : 
    2030          85 :             dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2031         136 :             dimsInt = dims
    2032          17 :             CALL h5screate_simple_f(4,dims(:4),frSpaceID,hdfError)
    2033          17 :             CALL h5dcreate_f(groupID, "fr", H5T_NATIVE_DOUBLE, frSpaceID, frSetID, hdfError)
    2034          17 :             CALL h5sclose_f(frSpaceID,hdfError)
    2035          17 :             CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",den%mt(:,:,:,:input%jspins))
    2036          17 :             CALL h5dclose_f(frSetID, hdfError)
    2037             : 
    2038          17 :             IF (PRESENT(denIm)) THEN
    2039           0 :                dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2040           0 :                dimsInt = dims
    2041           0 :                CALL h5screate_simple_f(4,dims(:4),frImSpaceID,hdfError)
    2042           0 :                CALL h5dcreate_f(groupID, "frIm", H5T_NATIVE_DOUBLE, frImSpaceID, frImSetID, hdfError)
    2043           0 :                CALL h5sclose_f(frImSpaceID,hdfError)
    2044           0 :                CALL io_write_real4(frImSetID,(/1,1,1,1/),dimsInt(:4),"mtIm",denIm%mt(:,:,:,:input%jspins))
    2045           0 :                CALL h5dclose_f(frImSetID, hdfError)
    2046             :             END IF
    2047             : 
    2048          17 :             IF ((densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2049             :                     (densityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    2050           0 :                dims(:4)=(/jmtd,nlhd+1,ntype,2/)
    2051           0 :                dimsInt = dims
    2052           0 :                CALL h5screate_simple_f(4,dims(:4),frOffSpaceID,hdfError)
    2053           0 :                CALL h5dcreate_f(groupID, "froff", H5T_NATIVE_DOUBLE, frOffSpaceID, frOffSetID, hdfError)
    2054           0 :                CALL h5sclose_f(frOffSpaceID,hdfError)
    2055           0 :                CALL io_write_real4(frOffSetID,(/1,1,1,1/),dimsInt(:4),"mt",den%mt(:,:,:,3:4))
    2056           0 :                CALL h5dclose_f(frOffSetID, hdfError)
    2057           0 :                IF (PRESENT(denIm)) THEN
    2058           0 :                   dims(:4)=(/jmtd,nlhd+1,ntype,2/)
    2059           0 :                   dimsInt = dims
    2060           0 :                   CALL h5screate_simple_f(4,dims(:4),frOffImSpaceID,hdfError)
    2061           0 :                   CALL h5dcreate_f(groupID, "froffIm", H5T_NATIVE_DOUBLE, frOffImSpaceID, frOffImSetID, hdfError)
    2062           0 :                   CALL h5sclose_f(frOffImSpaceID,hdfError)
    2063           0 :                   CALL io_write_real4(frOffImSetID,(/1,1,1,1/),dimsInt(:4),"mtIm",denIm%mt(:,:,:,3:4))
    2064           0 :                   CALL h5dclose_f(frOffImSetID, hdfError)
    2065             :                END IF
    2066             :             END IF
    2067             : 
    2068          68 :             dims(:3)=(/2,ng3,input%jspins/)
    2069         136 :             dimsInt = dims
    2070          17 :             CALL h5screate_simple_f(3,dims(:3),fpwSpaceID,hdfError)
    2071          17 :             CALL h5dcreate_f(groupID, "fpw", H5T_NATIVE_DOUBLE, fpwSpaceID, fpwSetID, hdfError)
    2072          17 :             CALL h5sclose_f(fpwSpaceID,hdfError)
    2073          17 :             CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"pw",den%pw(:,:input%jspins))
    2074          17 :             CALL h5dclose_f(fpwSetID, hdfError)
    2075             : 
    2076          17 :             IF (l_film) THEN
    2077           0 :                dims(:5)=(/2,nmzd,ng2,2,input%jspins/)
    2078           0 :                dimsInt = dims
    2079           0 :                CALL h5screate_simple_f(5,dims(:5),fvacSpaceID,hdfError)
    2080           0 :                CALL h5dcreate_f(groupID, "fvac", H5T_NATIVE_DOUBLE, fvacSpaceID, fvacSetID, hdfError)
    2081           0 :                CALL h5sclose_f(fvacSpaceID,hdfError)
    2082           0 :                CALL io_write_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"vac",den%vac(:,:,:,:input%jspins))
    2083           0 :                CALL h5dclose_f(fvacSetID, hdfError)
    2084             :             END IF
    2085             : 
    2086             :             IF((densityType.EQ.DENSITY_TYPE_NOCO_IN_const).OR.&
    2087          17 :                (densityType.EQ.DENSITY_TYPE_NOCO_OUT_const).OR.(densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2088             :                   (densityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    2089             : 
    2090          51 :                dims(:2)=(/2,ng3/)
    2091         136 :                dimsInt = dims
    2092          17 :                CALL h5screate_simple_f(2,dims(:2),cdomSpaceID,hdfError)
    2093          17 :                CALL h5dcreate_f(groupID, "cdom", H5T_NATIVE_DOUBLE, cdomSpaceID, cdomSetID, hdfError)
    2094          17 :                CALL h5sclose_f(cdomSpaceID,hdfError)
    2095          17 :                CALL io_write_complex1(cdomSetID,(/-1,1/),dimsInt(:2),"pw",den%pw(:,3))
    2096          17 :                CALL h5dclose_f(cdomSetID, hdfError)
    2097             : 
    2098          17 :                IF (PRESENT(denIm)) THEN
    2099           0 :                   dims(:2)=(/2,ng3/)
    2100           0 :                   dimsInt = dims
    2101           0 :                   CALL h5screate_simple_f(2,dims(:2),cdom12SpaceID,hdfError)
    2102           0 :                   CALL h5dcreate_f(groupID, "cdom12", H5T_NATIVE_DOUBLE, cdom12SpaceID, cdom12SetID, hdfError)
    2103           0 :                   CALL h5sclose_f(cdom12SpaceID,hdfError)
    2104           0 :                   CALL io_write_complex1(cdom12SetID,(/-1,1/),dimsInt(:2),"pw12",den%pw(:,4))
    2105           0 :                   CALL h5dclose_f(cdom12SetID, hdfError)
    2106             :                END IF
    2107             : 
    2108          17 :                IF (l_film) THEN
    2109           0 :                   dims(:4)=(/2,nmz,ng2,nvac/)
    2110           0 :                   dimsInt = dims
    2111           0 :                   CALL h5screate_simple_f(4,dims(:4),cdomvacSpaceID,hdfError)
    2112           0 :                   CALL h5dcreate_f(groupID, "cdomvac", H5T_NATIVE_DOUBLE, cdomvacSpaceID, cdomvacSetID, hdfError)
    2113           0 :                   CALL h5sclose_f(cdomvacSpaceID,hdfError)
    2114           0 :                   CALL io_write_complex3(cdomvacSetID,(/-1,1,1,1/),dimsInt(:4),"cdomvac",den%vac(:,:,:nvac,3))
    2115           0 :                   CALL h5dclose_f(cdomvacSetID, hdfError)
    2116             :                END IF
    2117             :             ENDIF
    2118             : 
    2119          17 :             IF((fileFormatVersion.GE.29).AND.(n_u.GT.0)) THEN
    2120             :                IF ((densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2121           1 :                   (densityType.EQ.DENSITY_TYPE_FFN_OUT_const).OR.&
    2122             :                    l_spinoffd_ldau) THEN
    2123           0 :                   dims(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u,3/)
    2124           0 :                   dimsInt = dims
    2125           0 :                   CALL h5screate_simple_f(5,dims(:5),mmpMatSpaceID,hdfError)
    2126           0 :                   CALL h5dcreate_f(groupID, "mmpMat", H5T_NATIVE_DOUBLE, mmpMatSpaceID, mmpMatSetID, hdfError)
    2127           0 :                   CALL h5sclose_f(mmpMatSpaceID,hdfError)
    2128           0 :                   CALL io_write_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMat",den%mmpMat)
    2129           0 :                   CALL h5dclose_f(mmpMatSetID, hdfError)
    2130             :                ELSE
    2131           6 :                   dims(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u,input%jspins/)
    2132           8 :                   dimsInt = dims
    2133           1 :                   CALL h5screate_simple_f(5,dims(:5),mmpMatSpaceID,hdfError)
    2134           1 :                   CALL h5dcreate_f(groupID, "mmpMat", H5T_NATIVE_DOUBLE, mmpMatSpaceID, mmpMatSetID, hdfError)
    2135           1 :                   CALL h5sclose_f(mmpMatSpaceID,hdfError)
    2136           1 :                   CALL io_write_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMat",den%mmpMat(:,:,:,:input%jspins))
    2137           1 :                   CALL h5dclose_f(mmpMatSetID, hdfError)
    2138             :                END IF
    2139             :             ENDIF
    2140             : 
    2141          17 :             IF ((fileFormatVersion.GE.35).AND.(n_v.GT.0)) THEN
    2142           0 :                dims(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_vPairs,input%jspins/)
    2143           0 :                dimsInt = dims
    2144           0 :                CALL h5screate_simple_f(5,dims(:5),nIJ_llp_mmpSpaceID,hdfError)
    2145           0 :                CALL h5dcreate_f(groupID, "nIJ_llp_mmp", H5T_NATIVE_DOUBLE, nIJ_llp_mmpSpaceID, nIJ_llp_mmpSetID, hdfError)
    2146           0 :                CALL h5sclose_f(nIJ_llp_mmpSpaceID,hdfError)
    2147           0 :                CALL io_write_complex4(nIJ_llp_mmpSetID,(/-1,1,1,1,1/),dimsInt(:5),"nIJ_llp_mmp",den%nIJ_llp_mmp(:,:,:,:input%jspins))
    2148           0 :                CALL h5dclose_f(nIJ_llp_mmpSetID, hdfError)
    2149             :             END IF
    2150             : 
    2151          17 :             CALL h5gclose_f(groupID, hdfError)
    2152             :          END IF
    2153             : 
    2154          77 :          CALL h5gclose_f(archiveID, hdfError)
    2155             :       ELSE
    2156         410 :          CALL h5gcreate_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    2157             : 
    2158         410 :          CALL io_write_attint0(archiveID,'previousDensityIndex',previousDensityIndex)
    2159         410 :          CALL io_write_attint0(archiveID,'starsIndex',starsIndex)
    2160         410 :          CALL io_write_attint0(archiveID,'latharmsIndex',latharmsIndex)
    2161         410 :          CALL io_write_attint0(archiveID,'structureIndex',structureIndex)
    2162         410 :          CALL io_write_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    2163         410 :          CALL io_write_attint0(archiveID,'spins',input%jspins)
    2164         410 :          CALL io_write_attint0(archiveID,'iter',iter)
    2165         410 :          CALL io_write_attint0(archiveID,'date',date)
    2166         410 :          CALL io_write_attint0(archiveID,'time',time)
    2167         410 :          CALL io_write_attreal0(archiveID,'distance',distance)
    2168             : 
    2169         410 :          IF(n_u.GT.0) THEN
    2170          49 :             IF(mmpmatDistance.GE.-1e-10) THEN
    2171           0 :                CALL io_write_attreal0(archiveID,'mmpmatDistance',mmpmatDistance)
    2172             :             ENDIF
    2173          49 :             IF(occDistance.GE.-1e-10) THEN
    2174           0 :                CALL io_write_attreal0(archiveID,'occDistance',occDistance)
    2175             :             ENDIF
    2176             :          ENDIF
    2177             : 
    2178         410 :          CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2179             : 
    2180         410 :          CALL io_write_attreal0(groupID,'fermiEnergy',fermiEnergy)
    2181         410 :          CALL io_write_attlog0(groupID,'l_qfix',l_qfix)
    2182             : 
    2183             : 
    2184        2050 :          dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2185        3280 :          dimsInt = dims
    2186         410 :          CALL h5screate_simple_f(4,dims(:4),frSpaceID,hdfError)
    2187         410 :          CALL h5dcreate_f(groupID, "fr", H5T_NATIVE_DOUBLE, frSpaceID, frSetID, hdfError)
    2188         410 :          CALL h5sclose_f(frSpaceID,hdfError)
    2189         410 :          CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",den%mt(:,0:,:,:input%jspins))
    2190         410 :          CALL h5dclose_f(frSetID, hdfError)
    2191             : 
    2192         410 :          IF (PRESENT(denIm)) THEN
    2193           0 :             dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2194           0 :             dimsInt = dims
    2195           0 :             CALL h5screate_simple_f(4,dims(:4),frImSpaceID,hdfError)
    2196           0 :             CALL h5dcreate_f(groupID, "frIm", H5T_NATIVE_DOUBLE, frImSpaceID, frImSetID, hdfError)
    2197           0 :             CALL h5sclose_f(frImSpaceID,hdfError)
    2198           0 :             CALL io_write_real4(frImSetID,(/1,1,1,1/),dimsInt(:4),"mtIm",denIm%mt(:,0:,:,:input%jspins))
    2199           0 :             CALL h5dclose_f(frImSetID, hdfError)
    2200             :          END IF
    2201             : 
    2202         410 :          IF((densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2203             :              (densityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    2204         100 :             dims(:4)=(/jmtd,nlhd+1,ntype,2/)
    2205         160 :             dimsInt = dims
    2206          20 :             CALL h5screate_simple_f(4,dims(:4),frOffSpaceID,hdfError)
    2207          20 :             CALL h5dcreate_f(groupID, "froff", H5T_NATIVE_DOUBLE, frOffSpaceID, frOffSetID, hdfError)
    2208          20 :             CALL h5sclose_f(frOffSpaceID,hdfError)
    2209          20 :             CALL io_write_real4(frOffSetID,(/1,1,1,1/),dimsInt(:4),"mt",den%mt(:,0:,:,3:4))
    2210          20 :             CALL h5dclose_f(frOffSetID, hdfError)
    2211          20 :             IF (PRESENT(denIm)) THEN
    2212           0 :                dims(:4)=(/jmtd,nlhd+1,ntype,2/)
    2213           0 :                dimsInt = dims
    2214           0 :                CALL h5screate_simple_f(4,dims(:4),frOffImSpaceID,hdfError)
    2215           0 :                CALL h5dcreate_f(groupID, "froffIm", H5T_NATIVE_DOUBLE, frOffImSpaceID, frOffImSetID, hdfError)
    2216           0 :                CALL h5sclose_f(frOffImSpaceID,hdfError)
    2217           0 :                CALL io_write_real4(frOffImSetID,(/1,1,1,1/),dimsInt(:4),"mtIm",denIm%mt(:,0:,:,3:4))
    2218           0 :                CALL h5dclose_f(frOffImSetID, hdfError)
    2219             :             END IF
    2220             :          END IF
    2221             : 
    2222        1640 :          dims(:3)=(/2,ng3,input%jspins/)
    2223        3280 :          dimsInt = dims
    2224         410 :          CALL h5screate_simple_f(3,dims(:3),fpwSpaceID,hdfError)
    2225         410 :          CALL h5dcreate_f(groupID, "fpw", H5T_NATIVE_DOUBLE, fpwSpaceID, fpwSetID, hdfError)
    2226         410 :          CALL h5sclose_f(fpwSpaceID,hdfError)
    2227         410 :          CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"pw",den%pw(:,:input%jspins))
    2228         410 :          CALL h5dclose_f(fpwSetID, hdfError)
    2229             : 
    2230         410 :          IF (l_film) THEN
    2231         318 :             dims(:5)=(/2,nmzd,ng2,2,input%jspins/)
    2232         424 :             dimsInt = dims
    2233          53 :             CALL h5screate_simple_f(5,dims(:5),fvacSpaceID,hdfError)
    2234          53 :             CALL h5dcreate_f(groupID, "fvac", H5T_NATIVE_DOUBLE, fvacSpaceID, fvacSetID, hdfError)
    2235          53 :             CALL h5sclose_f(fvacSpaceID,hdfError)
    2236          53 :             CALL io_write_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"vac",den%vac(:,:,:,:input%jspins))
    2237          53 :             CALL h5dclose_f(fvacSetID, hdfError)
    2238             :          END IF
    2239             : 
    2240             :          IF((densityType.EQ.DENSITY_TYPE_NOCO_IN_const).OR.&
    2241         410 :             (densityType.EQ.DENSITY_TYPE_NOCO_OUT_const).OR.(densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2242             :                (densityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    2243             : 
    2244         312 :             dims(:2)=(/2,ng3/)
    2245         832 :             dimsInt = dims
    2246         104 :             CALL h5screate_simple_f(2,dims(:2),cdomSpaceID,hdfError)
    2247         104 :             CALL h5dcreate_f(groupID, "cdom", H5T_NATIVE_DOUBLE, cdomSpaceID, cdomSetID, hdfError)
    2248         104 :             CALL h5sclose_f(cdomSpaceID,hdfError)
    2249         104 :             CALL io_write_complex1(cdomSetID,(/-1,1/),dimsInt(:2),"pw",den%pw(:,3))
    2250         104 :             CALL h5dclose_f(cdomSetID, hdfError)
    2251             : 
    2252         104 :             IF (PRESENT(denIm)) THEN
    2253           0 :                dims(:2)=(/2,ng3/)
    2254           0 :                dimsInt = dims
    2255           0 :                CALL h5screate_simple_f(2,dims(:2),cdom12SpaceID,hdfError)
    2256           0 :                CALL h5dcreate_f(groupID, "cdom12", H5T_NATIVE_DOUBLE, cdom12SpaceID, cdom12SetID, hdfError)
    2257           0 :                CALL h5sclose_f(cdom12SpaceID,hdfError)
    2258           0 :                CALL io_write_complex1(cdom12SetID,(/-1,1/),dimsInt(:2),"pw12",den%pw(:,4))
    2259           0 :                CALL h5dclose_f(cdom12SetID, hdfError)
    2260             :             END IF
    2261             : 
    2262         104 :             IF (l_film) THEN
    2263           0 :                dims(:4)=(/2,nmz,ng2,nvac/)
    2264           0 :                dimsInt = dims
    2265           0 :                CALL h5screate_simple_f(4,dims(:4),cdomvacSpaceID,hdfError)
    2266           0 :                CALL h5dcreate_f(groupID, "cdomvac", H5T_NATIVE_DOUBLE, cdomvacSpaceID, cdomvacSetID, hdfError)
    2267           0 :                CALL h5sclose_f(cdomvacSpaceID,hdfError)
    2268           0 :                CALL io_write_complex3(cdomvacSetID,(/-1,1,1,1/),dimsInt(:4),"cdomvac",den%vac(:,:,:nvac,3))
    2269           0 :                CALL h5dclose_f(cdomvacSetID, hdfError)
    2270             :             END IF
    2271             :          ENDIF
    2272             : 
    2273         410 :          IF((fileFormatVersion.GE.29).AND.(n_u.GT.0)) THEN
    2274             :             IF ((densityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    2275          49 :                (densityType.EQ.DENSITY_TYPE_FFN_OUT_const).OR.&
    2276             :                l_spinoffd_ldau) THEN
    2277           0 :                dims(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u,3/)
    2278           0 :                dimsInt = dims
    2279           0 :                CALL h5screate_simple_f(5,dims(:5),mmpMatSpaceID,hdfError)
    2280           0 :                CALL h5dcreate_f(groupID, "mmpMat", H5T_NATIVE_DOUBLE, mmpMatSpaceID, mmpMatSetID, hdfError)
    2281           0 :                CALL h5sclose_f(mmpMatSpaceID,hdfError)
    2282           0 :                CALL io_write_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMat",den%mmpMat)
    2283           0 :                CALL h5dclose_f(mmpMatSetID, hdfError)
    2284             :             ELSE
    2285         294 :                dims(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u,input%jspins/)
    2286         392 :                dimsInt = dims
    2287          49 :                CALL h5screate_simple_f(5,dims(:5),mmpMatSpaceID,hdfError)
    2288          49 :                CALL h5dcreate_f(groupID, "mmpMat", H5T_NATIVE_DOUBLE, mmpMatSpaceID, mmpMatSetID, hdfError)
    2289          49 :                CALL h5sclose_f(mmpMatSpaceID,hdfError)
    2290          49 :                CALL io_write_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMat",den%mmpMat(:,:,:,:input%jspins))
    2291          49 :                CALL h5dclose_f(mmpMatSetID, hdfError)
    2292             :             END IF
    2293             :          ENDIF
    2294             : 
    2295         410 :          IF ((fileFormatVersion.GE.35).AND.(n_v.GT.0)) THEN
    2296           0 :             dims(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_vPairs,input%jspins/)
    2297           0 :             dimsInt = dims
    2298           0 :             CALL h5screate_simple_f(5,dims(:5),nIJ_llp_mmpSpaceID,hdfError)
    2299           0 :             CALL h5dcreate_f(groupID, "nIJ_llp_mmp", H5T_NATIVE_DOUBLE, nIJ_llp_mmpSpaceID, nIJ_llp_mmpSetID, hdfError)
    2300           0 :             CALL h5sclose_f(nIJ_llp_mmpSpaceID,hdfError)
    2301           0 :             CALL io_write_complex4(nIJ_llp_mmpSetID,(/-1,1,1,1,1/),dimsInt(:5),"nIJ_llp_mmp",den%nIJ_llp_mmp(:,:,:,:input%jspins))
    2302           0 :             CALL h5dclose_f(nIJ_llp_mmpSetID, hdfError)
    2303             :          END IF
    2304             : 
    2305         410 :          CALL h5gclose_f(groupID, hdfError)
    2306             : 
    2307         410 :          CALL h5gclose_f(archiveID, hdfError)
    2308             :       END IF
    2309         487 :    END SUBROUTINE writeDensityHDF
    2310             : 
    2311           0 :    SUBROUTINE writePotentialHDF(input, fileID, archiveName, potentialType,&
    2312             :                                 starsIndex, latharmsIndex, structureIndex,stepfunctionIndex,&
    2313           0 :                                 iter,pot,fpw,l_noco,l_mtNoco)
    2314             :       use m_types_input
    2315             :       use m_types_potden
    2316             : 
    2317             :       TYPE(t_input),    INTENT(IN) :: input
    2318             :       TYPE(t_potden),   INTENT(IN) :: pot
    2319             :       INTEGER(HID_T),   INTENT(IN) :: fileID
    2320             :       INTEGER,          INTENT(IN) :: potentialType
    2321             :       INTEGER,          INTENT(IN) :: starsIndex, latharmsIndex, structureIndex
    2322             :       INTEGER,          INTENT(IN) :: stepfunctionIndex
    2323             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    2324             : 
    2325             :       INTEGER, INTENT (IN)         :: iter
    2326             : 
    2327             :       COMPLEX, INTENT (IN)         :: fpw(:,:)
    2328             :       LOGICAL, INTENT (IN)         :: l_noco, l_mtNoco
    2329             :       INTEGER                      :: ntype,jmtd,nmzd,nmzxyd,nlhd,ng3,ng2
    2330             :       INTEGER                      :: nmz, nvac, nmzxy
    2331             :       INTEGER                      :: hdfError
    2332             :       LOGICAL                      :: l_film, l_exist, l_delete
    2333             :       INTEGER(HID_T)               :: archiveID, groupID
    2334             :       CHARACTER(LEN=30)            :: groupName, potentialTypeName
    2335             :       INTEGER(HSIZE_T)             :: dims(7)
    2336             :       INTEGER                      :: dimsInt(7)
    2337             : 
    2338             :       INTEGER                      :: starsIndexTemp, latharmsIndexTemp
    2339             :       INTEGER                      :: structureIndexTemp, stepfunctionIndexTemp
    2340             :       INTEGER                      :: jspinsTemp
    2341             : 
    2342             :       INTEGER(HID_T)               :: frSpaceID, frSetID
    2343             :       INTEGER(HID_T)               :: fpwSpaceID, fpwSetID
    2344             :       INTEGER(HID_T)               :: fzSpaceID, fzSetID
    2345             :       INTEGER(HID_T)               :: fzxySpaceID, fzxySetID
    2346             :       INTEGER(HID_T)               :: fvacSpaceID, fvacSetID
    2347             : 
    2348           0 :       WRITE(groupname,'(a,i0)') '/structure-', structureIndex
    2349           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2350           0 :       IF(.NOT.l_exist) THEN
    2351           0 :          CALL juDFT_error("Structure entry "//TRIM(ADJUSTL(groupName))//" does not exist",calledby ="writePotentialHDF")
    2352             :       END IF
    2353           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2354           0 :       CALL io_read_attlog0(groupID,'l_film',l_film)
    2355           0 :       CALL io_read_attint0(groupID,'ntype',ntype)
    2356           0 :       CALL io_read_attint0(groupID,'jmtd',jmtd)
    2357           0 :       CALL io_read_attint0(groupID,'nmzd',nmzd)
    2358           0 :       CALL io_read_attint0(groupID,'nmzxyd',nmzxyd)
    2359           0 :       CALL io_read_attint0(groupID,'nmzxy',nmzxy)
    2360           0 :       CALL io_read_attint0(groupID,'nmz',nmz)
    2361           0 :       CALL io_read_attint0(groupID,'nvac',nvac)
    2362           0 :       CALL h5gclose_f(groupID, hdfError)
    2363             : 
    2364           0 :       WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex
    2365           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2366           0 :       IF(.NOT.l_exist) THEN
    2367           0 :          CALL juDFT_error("Latharms entry "//TRIM(ADJUSTL(groupName))//" does not exist",calledby ="writePotentialHDF")
    2368             :       END IF
    2369           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2370           0 :       CALL io_read_attint0(groupID,'nlhd',nlhd)
    2371           0 :       CALL h5gclose_f(groupID, hdfError)
    2372             : 
    2373           0 :       WRITE(groupname,'(a,i0)') '/stars-', starsIndex
    2374           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2375           0 :       IF(.NOT.l_exist) THEN
    2376           0 :          CALL juDFT_error("Stars entry "//TRIM(ADJUSTL(groupName))//" does not exist",calledby ="writePotentialHDF")
    2377             :       END IF
    2378           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2379           0 :       CALL io_read_attint0(groupID,'ng3',ng3)
    2380           0 :       CALL io_read_attint0(groupID,'ng2',ng2)
    2381           0 :       CALL h5gclose_f(groupID, hdfError)
    2382             : 
    2383           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    2384             : 
    2385           0 :       SELECT CASE (potentialType)
    2386             :          CASE(POTENTIAL_TYPE_IN_const)
    2387           0 :             potentialTypeName = '/in'
    2388             :          CASE(POTENTIAL_TYPE_OUT_const)
    2389           0 :             potentialTypeName = '/out'
    2390             :          CASE DEFAULT
    2391           0 :             CALL juDFT_error("Unknown potential type selected",calledby ="writePotentialHDF")
    2392             :       END SELECT
    2393             : 
    2394           0 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(potentialTypeName))
    2395             : 
    2396           0 :       l_delete = .FALSE.
    2397           0 :       IF(l_exist) THEN
    2398           0 :          CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    2399             : 
    2400           0 :          CALL io_read_attint0(archiveID,'starsIndex',starsIndexTemp)
    2401           0 :          CALL io_read_attint0(archiveID,'latharmsIndex',latharmsIndexTemp)
    2402           0 :          CALL io_read_attint0(archiveID,'structureIndex',structureIndexTemp)
    2403           0 :          CALL io_read_attint0(archiveID,'stepfunctionIndex',stepfunctionIndexTemp)
    2404           0 :          CALL io_read_attint0(archiveID,'spins',jspinsTemp)
    2405             : 
    2406           0 :          IF (starsIndex.NE.starsIndexTemp) l_delete = .TRUE.
    2407           0 :          IF (latharmsIndex.NE.latharmsIndexTemp) l_delete = .TRUE.
    2408           0 :          IF (structureIndex.NE.structureIndexTemp) l_delete = .TRUE.
    2409           0 :          IF (stepfunctionIndex.NE.stepfunctionIndexTemp) l_delete = .TRUE.
    2410           0 :          IF (input%jspins.NE.jspinsTemp) l_delete = .TRUE.
    2411             : 
    2412           0 :          CALL h5gclose_f(archiveID, hdfError)
    2413             :       END IF
    2414             : 
    2415           0 :       IF(l_delete) THEN
    2416           0 :          CALL h5ldelete_f(fileID, archiveName, hdfError)
    2417             :          l_exist = .FALSE.
    2418             :       END IF
    2419             : 
    2420           0 :       IF(l_exist) THEN
    2421           0 :          CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    2422             : 
    2423           0 :          CALL io_write_attint0(archiveID,'starsIndex',starsIndex)
    2424           0 :          CALL io_write_attint0(archiveID,'latharmsIndex',latharmsIndex)
    2425           0 :          CALL io_write_attint0(archiveID,'structureIndex',structureIndex)
    2426           0 :          CALL io_write_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    2427           0 :          CALL io_write_attint0(archiveID,'spins',input%jspins)
    2428           0 :          CALL io_write_attint0(archiveID,'iter',iter)
    2429             : 
    2430           0 :          l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2431             : 
    2432           0 :          IF(l_exist) THEN
    2433           0 :             CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2434             : 
    2435           0 :             IF(.NOT.l_mtNoco) THEN
    2436           0 :                dimsInt(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2437           0 :                CALL h5dopen_f(groupID, 'fr', frSetID, hdfError)
    2438           0 :                CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",pot%mt)
    2439           0 :                CALL h5dclose_f(frSetID, hdfError)
    2440             :             ELSE
    2441           0 :                dimsInt(:4)=(/jmtd,nlhd+1,ntype,input%jspins+2/)
    2442           0 :                CALL h5dopen_f(groupID, 'fr', frSetID, hdfError)
    2443           0 :                CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",pot%mt)
    2444           0 :                CALL h5dclose_f(frSetID, hdfError)
    2445             :             END IF
    2446             : 
    2447           0 :             IF(.NOT.l_noco) THEN
    2448           0 :                dimsInt(:3)=(/2,ng3,input%jspins/)
    2449           0 :                CALL h5dopen_f(groupID, 'fpw', fpwSetID, hdfError)
    2450           0 :                CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    2451           0 :                CALL h5dclose_f(fpwSetID, hdfError)
    2452             :             ELSE
    2453           0 :                dimsInt(:3)=(/2,ng3,3/)
    2454           0 :                CALL h5dopen_f(groupID, 'fpw', fpwSetID, hdfError)
    2455           0 :                CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    2456           0 :                CALL h5dclose_f(fpwSetID, hdfError)
    2457             :             END IF
    2458             : 
    2459           0 :             IF (l_film) THEN
    2460           0 :                dimsInt(:5)=(/2,nmzd,ng2,2,input%jspins/)
    2461           0 :                CALL h5dopen_f(groupID, 'fvac', fvacSetID, hdfError)
    2462           0 :                CALL io_write_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"vac",pot%vac(:,:,:,:input%jspins))
    2463           0 :                CALL h5dclose_f(fvacSetID, hdfError)
    2464             :             END IF
    2465             : 
    2466           0 :             CALL h5gclose_f(groupID, hdfError)
    2467             :          ELSE
    2468           0 :             CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2469             : 
    2470             : 
    2471           0 :          IF (.NOT.l_mtNoco)THEN
    2472           0 :             dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2473           0 :             dimsInt = dims
    2474           0 :             CALL h5screate_simple_f(4,dims(:4),frSpaceID,hdfError)
    2475           0 :             CALL h5dcreate_f(groupID, "fr", H5T_NATIVE_DOUBLE, frSpaceID, frSetID, hdfError)
    2476           0 :             CALL h5sclose_f(frSpaceID,hdfError)
    2477           0 :             CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",pot%mt)
    2478           0 :             CALL h5dclose_f(frSetID, hdfError)
    2479             :          ELSE
    2480           0 :             dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins+2/)
    2481           0 :             dimsInt = dims
    2482           0 :             CALL h5screate_simple_f(4,dims(:4),frSpaceID,hdfError)
    2483           0 :             CALL h5dcreate_f(groupID, "fr", H5T_NATIVE_DOUBLE, frSpaceID, frSetID, hdfError)
    2484           0 :             CALL h5sclose_f(frSpaceID,hdfError)
    2485           0 :             CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",pot%mt)
    2486           0 :             CALL h5dclose_f(frSetID, hdfError)
    2487             :          END IF
    2488             : 
    2489           0 :             IF(.NOT.l_noco) THEN
    2490           0 :                dims(:3)=(/2,ng3,input%jspins/)
    2491           0 :                dimsInt = dims
    2492           0 :                CALL h5screate_simple_f(3,dims(:3),fpwSpaceID,hdfError)
    2493           0 :                CALL h5dcreate_f(groupID, "fpw", H5T_NATIVE_DOUBLE, fpwSpaceID, fpwSetID, hdfError)
    2494           0 :                CALL h5sclose_f(fpwSpaceID,hdfError)
    2495           0 :                CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    2496           0 :                CALL h5dclose_f(fpwSetID, hdfError)
    2497             :             ELSE
    2498           0 :                dims(:3)=(/2,ng3,3/)
    2499           0 :                dimsInt = dims
    2500           0 :                CALL h5screate_simple_f(3,dims(:3),fpwSpaceID,hdfError)
    2501           0 :                CALL h5dcreate_f(groupID, "fpw", H5T_NATIVE_DOUBLE, fpwSpaceID, fpwSetID, hdfError)
    2502           0 :                CALL h5sclose_f(fpwSpaceID,hdfError)
    2503           0 :                CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    2504           0 :                CALL h5dclose_f(fpwSetID, hdfError)
    2505             :             END IF
    2506             : 
    2507           0 :             IF (l_film) THEN
    2508           0 :                dims(:5)=(/2,nmzd,ng2,2,input%jspins/)
    2509           0 :                dimsInt = dims
    2510           0 :                CALL h5screate_simple_f(5,dims(:5),fvacSpaceID,hdfError)
    2511           0 :                CALL h5dcreate_f(groupID, "fvac", H5T_NATIVE_DOUBLE, fvacSpaceID, fvacSetID, hdfError)
    2512           0 :                CALL h5sclose_f(fvacSpaceID,hdfError)
    2513           0 :                CALL io_write_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"vac",pot%vac(:,:,:,:input%jspins))
    2514           0 :                CALL h5dclose_f(fvacSetID, hdfError)
    2515             :             END IF
    2516             : 
    2517           0 :             CALL h5gclose_f(groupID, hdfError)
    2518             :          END IF
    2519             : 
    2520           0 :          CALL h5gclose_f(archiveID, hdfError)
    2521             :       ELSE
    2522           0 :          CALL h5gcreate_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    2523             : 
    2524           0 :          CALL io_write_attint0(archiveID,'starsIndex',starsIndex)
    2525           0 :          CALL io_write_attint0(archiveID,'latharmsIndex',latharmsIndex)
    2526           0 :          CALL io_write_attint0(archiveID,'structureIndex',structureIndex)
    2527           0 :          CALL io_write_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    2528           0 :          CALL io_write_attint0(archiveID,'spins',input%jspins)
    2529           0 :          CALL io_write_attint0(archiveID,'iter',iter)
    2530             : 
    2531           0 :          CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2532             : 
    2533           0 :          IF (.NOT.l_mtNoco)THEN
    2534           0 :             dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins/)
    2535           0 :             dimsInt = dims
    2536           0 :             CALL h5screate_simple_f(4,dims(:4),frSpaceID,hdfError)
    2537           0 :             CALL h5dcreate_f(groupID, "fr", H5T_NATIVE_DOUBLE, frSpaceID, frSetID, hdfError)
    2538           0 :             CALL h5sclose_f(frSpaceID,hdfError)
    2539           0 :             CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",pot%mt)
    2540           0 :             CALL h5dclose_f(frSetID, hdfError)
    2541             :          ELSE
    2542           0 :             dims(:4)=(/jmtd,nlhd+1,ntype,input%jspins+2/)
    2543           0 :             dimsInt = dims
    2544           0 :             CALL h5screate_simple_f(4,dims(:4),frSpaceID,hdfError)
    2545           0 :             CALL h5dcreate_f(groupID, "fr", H5T_NATIVE_DOUBLE, frSpaceID, frSetID, hdfError)
    2546           0 :             CALL h5sclose_f(frSpaceID,hdfError)
    2547           0 :             CALL io_write_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"mt",pot%mt)
    2548           0 :             CALL h5dclose_f(frSetID, hdfError)
    2549             :          END IF
    2550             : 
    2551           0 :          IF(.NOT.l_noco) THEN
    2552           0 :             dims(:3)=(/2,ng3,input%jspins/)
    2553           0 :             dimsInt = dims
    2554           0 :             CALL h5screate_simple_f(3,dims(:3),fpwSpaceID,hdfError)
    2555           0 :             CALL h5dcreate_f(groupID, "fpw", H5T_NATIVE_DOUBLE, fpwSpaceID, fpwSetID, hdfError)
    2556           0 :             CALL h5sclose_f(fpwSpaceID,hdfError)
    2557           0 :             CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    2558           0 :             CALL h5dclose_f(fpwSetID, hdfError)
    2559             :          ELSE
    2560           0 :             dims(:3)=(/2,ng3,3/)
    2561           0 :             dimsInt = dims
    2562           0 :             CALL h5screate_simple_f(3,dims(:3),fpwSpaceID,hdfError)
    2563           0 :             CALL h5dcreate_f(groupID, "fpw", H5T_NATIVE_DOUBLE, fpwSpaceID, fpwSetID, hdfError)
    2564           0 :             CALL h5sclose_f(fpwSpaceID,hdfError)
    2565           0 :             CALL io_write_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    2566           0 :             CALL h5dclose_f(fpwSetID, hdfError)
    2567             :          END IF
    2568             : 
    2569           0 :          IF (l_film) THEN
    2570           0 :             dims(:5)=(/2,nmzd,ng2,2,input%jspins/)
    2571           0 :             dimsInt = dims
    2572           0 :             CALL h5screate_simple_f(5,dims(:5),fvacSpaceID,hdfError)
    2573           0 :             CALL h5dcreate_f(groupID, "fvac", H5T_NATIVE_DOUBLE, fvacSpaceID, fvacSetID, hdfError)
    2574           0 :             CALL h5sclose_f(fvacSpaceID,hdfError)
    2575           0 :             CALL io_write_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"vac",pot%vac(:,:,:,:input%jspins))
    2576           0 :             CALL h5dclose_f(fvacSetID, hdfError)
    2577             :          END IF
    2578             : 
    2579           0 :          CALL h5gclose_f(groupID, hdfError)
    2580             : 
    2581           0 :          CALL h5gclose_f(archiveID, hdfError)
    2582             :       END IF
    2583             : 
    2584           0 :    END SUBROUTINE writePotentialHDF
    2585             : 
    2586          80 :    SUBROUTINE readDensityHDF(fileID, input, stars, latharms, atoms, vacuum,  &
    2587             :                              archiveName, densityType,fermiEnergy,lastDistance,l_qfix,l_DimChange,den,denIm)
    2588             :       use m_types_input
    2589             :       use m_types_stars
    2590             :       use m_types_sphhar
    2591             :       use m_types_atoms
    2592             :       use m_types_vacuum
    2593             : 
    2594             :       use m_types_potden
    2595             : 
    2596             :       TYPE(t_input),INTENT(IN)     :: input
    2597             :       TYPE(t_stars),INTENT(IN)     :: stars
    2598             :       TYPE(t_sphhar),INTENT(IN)    :: latharms
    2599             :       TYPE(t_atoms),INTENT(IN)     :: atoms
    2600             :       TYPE(t_vacuum),INTENT(IN)    :: vacuum
    2601             : 
    2602             :       TYPE(t_potden),INTENT(INOUT) :: den
    2603             : 
    2604             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    2605             :       INTEGER, INTENT(IN)          :: densityType
    2606             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    2607             : 
    2608             :       REAL,    INTENT (OUT)        :: fermiEnergy
    2609             :       REAL,    INTENT (INOUT)      :: lastDistance
    2610             :       LOGICAL, INTENT (OUT)        :: l_qfix, l_DimChange
    2611             : 
    2612             :       TYPE(t_potden), OPTIONAL, INTENT(INOUT) :: denIm
    2613             : 
    2614             :       INTEGER               :: starsIndex, latharmsIndex, structureIndex, stepfunctionIndex
    2615             :       INTEGER               :: previousDensityIndex, jspins, jspinsmmp
    2616             :       INTEGER               :: ntype,jmtd,nmzd,nmzxyd,nlhd,ng3,ng2
    2617             :       INTEGER               :: nmz, nvac, od_nq2, nmzxy, n_u, n_opc, i, j
    2618             :       INTEGER               :: n_v, n_vPairs, iPair, i_v, iOtherAtom
    2619             :       INTEGER               :: localDensityType
    2620             :       LOGICAL               :: l_film, l_exist, l_mmpMatDimEquals, l_amf_Temp, FFNBool, l_spinoffd_ldau
    2621             :       LOGICAL               :: l_nIJ_llp_mmpDimEquals
    2622             :       INTEGER(HID_T)        :: archiveID, groupID, groupBID, generalGroupID
    2623             :       INTEGER               :: hdfError, fileFormatVersion
    2624             :       CHARACTER(LEN=30)     :: groupName, groupBName, densityTypeName
    2625             :       INTEGER               :: dimsInt(7)
    2626             :       INTEGER               :: jmtdOut, ntypeOut, nmzdOut, nmzxydOut, nlhdOut, ng3Out, ng2Out
    2627             :       INTEGER               :: nmzOut, nvacOut, od_nq2Out, nmzxyOut, jspinsOut
    2628             : 
    2629             :       INTEGER(HID_T)        :: frSetID, frOffSetID
    2630             :       INTEGER(HID_T)        :: fpwSetID
    2631             :       INTEGER(HID_T)        :: fzSetID
    2632             :       INTEGER(HID_T)        :: fzxySetID
    2633             :       INTEGER(HID_T)        :: fvacSetID
    2634             :       INTEGER(HID_T)        :: cdomSetID
    2635             :       INTEGER(HID_T)        :: cdomvzSetID
    2636             :       INTEGER(HID_T)        :: cdomvxySetID
    2637             :       INTEGER(HID_T)        :: cdomvacSetID
    2638             :       INTEGER(HID_T)        :: ldau_AtomTypeSetID
    2639             :       INTEGER(HID_T)        :: ldau_lSetID
    2640             :       INTEGER(HID_T)        :: ldau_l_amfSetID
    2641             :       INTEGER(HID_T)        :: ldau_USetID
    2642             :       INTEGER(HID_T)        :: ldau_JSetID
    2643             :       INTEGER(HID_T)        :: ldaopc_AtomTypeSetID
    2644             :       INTEGER(HID_T)        :: ldaopc_lSetID
    2645             :       INTEGER(HID_T)        :: ldaopc_nSetID
    2646             :       INTEGER(HID_T)        :: mmpMatSetID
    2647             :       INTEGER(HID_T)        :: frImSpaceID, frImSetID, frOffImSetID, frOffImSpaceID, cdom12SpaceID, cdom12SetID
    2648             : 
    2649             :       !LDA+V IDs (start)
    2650             :       INTEGER(HID_T)        :: ldav_AtomIndexSetID
    2651             :       INTEGER(HID_T)        :: ldav_thisAtomLSetID
    2652             :       INTEGER(HID_T)        :: ldav_otherAtomLSetID
    2653             :       INTEGER(HID_T)        :: ldav_numOtherAtomsSetID
    2654             :       INTEGER(HID_T)        :: ldav_VSetID
    2655             :       INTEGER(HID_T)        :: ldav_otherAtomIndicesSetID
    2656             :       INTEGER(HID_T)        :: ldav_atomShiftsSetID
    2657             :       INTEGER(HID_T)        :: nIJ_llp_mmpSetID
    2658             :       !LDA+V IDs (end)
    2659             : 
    2660          80 :       INTEGER, ALLOCATABLE  :: ldau_AtomType(:), ldau_l(:), ldau_l_amf(:)
    2661          80 :       INTEGER, ALLOCATABLE  :: ldaopc_AtomType(:), ldaopc_l(:), ldaopc_n(:)
    2662          80 :       REAL,    ALLOCATABLE  :: ldau_U(:), ldau_J(:)
    2663          80 :       REAL,    ALLOCATABLE  :: frTemp(:,:,:,:)
    2664             :       REAL,    ALLOCATABLE  :: fzTemp(:,:,:)
    2665          80 :       COMPLEX, ALLOCATABLE  :: fpwTemp(:,:)
    2666          80 :       COMPLEX, ALLOCATABLE  :: fzxyTemp(:,:,:,:), fvacTemp(:,:,:,:)
    2667          80 :       COMPLEX, ALLOCATABLE  :: cdomTemp(:), cdomvzTemp(:,:), cdomvxyTemp(:,:,:), cdomvacTemp(:,:,:)
    2668          80 :       COMPLEX, ALLOCATABLE  :: mmpMatTemp(:,:,:,:)
    2669             : 
    2670             :       !LDA+V arrays (start)
    2671          80 :       INTEGER, ALLOCATABLE  :: ldav_AtomIndex(:)
    2672          80 :       INTEGER, ALLOCATABLE  :: ldav_thisAtomL(:)
    2673          80 :       INTEGER, ALLOCATABLE  :: ldav_otherAtomL(:)
    2674          80 :       INTEGER, ALLOCATABLE  :: ldav_numOtherAtoms(:)
    2675          80 :       INTEGER, ALLOCATABLE  :: ldav_otherAtomIndices(:)
    2676          80 :       REAL, ALLOCATABLE     :: ldav_V(:)
    2677          80 :       REAL, ALLOCATABLE     :: ldav_atomShifts(:,:)
    2678          80 :       COMPLEX, ALLOCATABLE  :: nIJ_llp_mmpTemp(:,:,:,:)
    2679             :       !LDA+V arrays (end)
    2680             : 
    2681      688292 :       den%pw = CMPLX(0.0,0.0)
    2682     1581860 :       den%vac = CMPLX(0.0,0.0)
    2683             : 
    2684          80 :       CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
    2685             :       ! read in file format version from the header '/general'
    2686          80 :       CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
    2687             : 
    2688          80 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    2689          80 :       IF(.NOT.l_exist) THEN
    2690           0 :          CALL juDFT_error('density archive '//TRIM(ADJUSTL(archiveName))//' does not exist.' ,calledby ="readDensityHDF")
    2691             :       END IF
    2692             : 
    2693          80 :       localDensityType = densityType
    2694           9 :       SELECT CASE (densityType)
    2695             :         CASE(DENSITY_TYPE_FFN_IN_const)
    2696           9 :             densityTypeName = '/ffn_in'
    2697           9 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2698           9 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2699           9 :             IF(.NOT.l_exist) THEN
    2700           6 :                localDensityType = DENSITY_TYPE_NOCO_IN_const
    2701           6 :                densityTypeName = '/noco_in'
    2702             :             END IF
    2703           9 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2704           9 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2705           9 :             IF(.NOT.l_exist) THEN
    2706           6 :                localDensityType = DENSITY_TYPE_IN_const
    2707           6 :                densityTypeName = '/in'
    2708             :             END IF
    2709             :         CASE(DENSITY_TYPE_FFN_OUT_const)
    2710           0 :             densityTypeName = '/ffn_out'
    2711           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2712           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2713           0 :             IF(.NOT.l_exist) THEN
    2714           0 :                localDensityType = DENSITY_TYPE_NOCO_OUT_const
    2715           0 :                densityTypeName = '/noco_out'
    2716             :             END IF
    2717           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2718           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2719           0 :             IF(.NOT.l_exist) THEN
    2720           0 :                localDensityType = DENSITY_TYPE_OUT_const
    2721           0 :                densityTypeName = '/out'
    2722             :             END IF
    2723             :          CASE(DENSITY_TYPE_IN_const)
    2724          54 :             densityTypeName = '/in'
    2725             :          CASE(DENSITY_TYPE_OUT_const)
    2726           0 :             densityTypeName = '/out'
    2727             :          CASE(DENSITY_TYPE_NOCO_IN_const)
    2728          17 :             densityTypeName = '/noco_in'
    2729          17 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2730          17 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2731          17 :             IF(.NOT.l_exist) THEN
    2732          17 :                localDensityType = DENSITY_TYPE_IN_const
    2733          17 :                densityTypeName = '/in'
    2734             :             END IF
    2735             :          CASE(DENSITY_TYPE_NOCO_OUT_const)
    2736           0 :             densityTypeName = '/noco_out'
    2737           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2738           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2739           0 :             IF(.NOT.l_exist) THEN
    2740           0 :                localDensityType = DENSITY_TYPE_OUT_const
    2741           0 :                densityTypeName = '/out'
    2742             :             END IF
    2743             :          CASE(DENSITY_TYPE_PRECOND_const)
    2744           0 :             densityTypeName = '/precond'
    2745             :          CASE DEFAULT
    2746          80 :             CALL juDFT_error("Unknown density type selected",calledby ="readDensityHDF")
    2747             :       END SELECT
    2748             : 
    2749          80 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    2750          80 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    2751          80 :       IF(.NOT.l_exist) THEN
    2752           0 :          CALL juDFT_error('Density entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readDensityHDF")
    2753             :       END IF
    2754             : 
    2755          80 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    2756          80 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    2757             : 
    2758          80 :       CALL io_read_attint0(archiveID,'previousDensityIndex',previousDensityIndex)
    2759          80 :       CALL io_read_attint0(archiveID,'starsIndex',starsIndex)
    2760          80 :       CALL io_read_attint0(archiveID,'latharmsIndex',latharmsIndex)
    2761          80 :       CALL io_read_attint0(archiveID,'structureIndex',structureIndex)
    2762          80 :       CALL io_read_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    2763          80 :       CALL io_read_attint0(archiveID,'spins',jspins)
    2764          80 :       CALL io_read_attint0(archiveID,'iter',den%iter)
    2765             : 
    2766          80 :       WRITE(groupBName,'(a,i0)') '/structure-', structureIndex
    2767          80 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupBName)))
    2768          80 :       IF(.NOT.l_exist) THEN
    2769           0 :          CALL juDFT_error("Structure entry "//TRIM(ADJUSTL(groupBName))//" does not exist",calledby ="readDensityHDF")
    2770             :       END IF
    2771          80 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupBName)), groupBID, hdfError)
    2772          80 :       CALL io_read_attlog0(groupBID,'l_film',l_film)
    2773          80 :       CALL io_read_attint0(groupBID,'ntype',ntype)
    2774          80 :       CALL io_read_attint0(groupBID,'jmtd',jmtd)
    2775          80 :       CALL io_read_attint0(groupBID,'nmzd',nmzd)
    2776          80 :       CALL io_read_attint0(groupBID,'nmzxyd',nmzxyd)
    2777          80 :       CALL io_read_attint0(groupBID,'nmzxy',nmzxy)
    2778          80 :       CALL io_read_attint0(groupBID,'nmz',nmz)
    2779          80 :       CALL io_read_attint0(groupBID,'nvac',nvac)
    2780             :       !IF(io_attexists(groupBID,'od_nq2')) THEN
    2781             :       !   CALL io_read_attint0(groupBID,'od_nq2',od_nq2)
    2782             :       !END IF
    2783          80 :       IF(fileFormatVersion.GE.29) THEN
    2784          80 :          CALL io_read_attint0(groupBID,'n_u',n_u)
    2785          80 :          l_spinoffd_ldau = .false.
    2786          80 :          IF(io_attexists(groupBID,'ldau_spinoffd')) THEN
    2787          80 :             CALL io_read_attlog0(groupBID,'ldau_spinoffd',l_spinoffd_ldau)
    2788             :          ENDIF
    2789          80 :          IF(n_u.GT.0) THEN
    2790          35 :             ALLOCATE(ldau_AtomType(n_u), ldau_l(n_u), ldau_l_amf(n_u))
    2791          28 :             ALLOCATE(ldau_U(n_u), ldau_J(n_u))
    2792             : 
    2793          14 :             dimsInt(:1)=(/n_u/)
    2794           7 :             CALL h5dopen_f(groupBID, 'ldau_AtomType', ldau_AtomTypeSetID, hdfError)
    2795           7 :             CALL io_read_integer1(ldau_AtomTypeSetID,(/1/),dimsInt(:1),"ldau_AtomType",ldau_AtomType)
    2796           7 :             CALL h5dclose_f(ldau_AtomTypeSetID, hdfError)
    2797             : 
    2798          14 :             dimsInt(:1)=(/n_u/)
    2799           7 :             CALL h5dopen_f(groupBID, 'ldau_l', ldau_lSetID, hdfError)
    2800           7 :             CALL io_read_integer1(ldau_lSetID,(/1/),dimsInt(:1),"ldau_l",ldau_l)
    2801           7 :             CALL h5dclose_f(ldau_lSetID, hdfError)
    2802             : 
    2803          14 :             dimsInt(:1)=(/n_u/)
    2804           7 :             CALL h5dopen_f(groupBID, 'ldau_l_amf', ldau_l_amfSetID, hdfError)
    2805           7 :             CALL io_read_integer1(ldau_l_amfSetID,(/1/),dimsInt(:1),"ldau_l_amf",ldau_l_amf)
    2806           7 :             CALL h5dclose_f(ldau_l_amfSetID, hdfError)
    2807             : 
    2808          14 :             dimsInt(:1)=(/n_u/)
    2809           7 :             CALL h5dopen_f(groupBID, 'ldau_U', ldau_USetID, hdfError)
    2810           7 :             CALL io_read_real1(ldau_USetID,(/1/),dimsInt(:1),"ldau_U",ldau_U)
    2811           7 :             CALL h5dclose_f(ldau_USetID, hdfError)
    2812             : 
    2813          14 :             dimsInt(:1)=(/n_u/)
    2814           7 :             CALL h5dopen_f(groupBID, 'ldau_J', ldau_JSetID, hdfError)
    2815           7 :             CALL io_read_real1(ldau_JSetID,(/1/),dimsInt(:1),"ldau_J",ldau_J)
    2816          70 :             CALL h5dclose_f(ldau_JSetID, hdfError)
    2817             :          END IF
    2818             :       END IF
    2819             : 
    2820          80 :       IF(fileFormatVersion.GE.35) THEN
    2821          80 :          CALL io_read_attint0(groupBID,'n_v',n_v)
    2822          80 :          CALL io_read_attint0(groupBID,'n_vPairs',n_vPairs)
    2823             : 
    2824          80 :          IF(n_v.GT.0) THEN
    2825           0 :             ALLOCATE(ldav_AtomIndex(n_v),ldav_thisAtomL(n_v),ldav_otherAtomL(n_v),ldav_V(n_v),ldav_numOtherAtoms(n_v))
    2826           0 :             ALLOCATE(ldav_otherAtomIndices(n_vPairs),ldav_atomShifts(3,n_vPairs))
    2827             : 
    2828           0 :             dimsInt(:1)=(/n_v/)
    2829           0 :             CALL h5dopen_f(groupBID, 'ldav_AtomIndex', ldav_AtomIndexSetID, hdfError)
    2830           0 :             CALL io_read_integer1(ldav_AtomIndexSetID,(/1/),dimsInt(:1),"ldav_AtomIndex",ldav_AtomIndex)
    2831           0 :             CALL h5dclose_f(ldav_AtomIndexSetID, hdfError)
    2832             : 
    2833           0 :             dimsInt(:1)=(/n_v/)
    2834           0 :             CALL h5dopen_f(groupBID, 'ldav_thisAtomL', ldav_thisAtomLSetID, hdfError)
    2835           0 :             CALL io_read_integer1(ldav_thisAtomLSetID,(/1/),dimsInt(:1),"ldav_thisAtomL",ldav_thisAtomL)
    2836           0 :             CALL h5dclose_f(ldav_thisAtomLSetID, hdfError)
    2837             : 
    2838           0 :             dimsInt(:1)=(/n_v/)
    2839           0 :             CALL h5dopen_f(groupBID, 'ldav_otherAtomL', ldav_otherAtomLSetID, hdfError)
    2840           0 :             CALL io_read_integer1(ldav_otherAtomLSetID,(/1/),dimsInt(:1),"ldav_otherAtomL",ldav_otherAtomL)
    2841           0 :             CALL h5dclose_f(ldav_otherAtomLSetID, hdfError)
    2842             : 
    2843           0 :             dimsInt(:1)=(/n_v/)
    2844           0 :             CALL h5dopen_f(groupBID, 'ldav_numOtherAtoms', ldav_numOtherAtomsSetID, hdfError)
    2845           0 :             CALL io_read_integer1(ldav_numOtherAtomsSetID,(/1/),dimsInt(:1),"ldav_numOtherAtoms",ldav_numOtherAtoms)
    2846           0 :             CALL h5dclose_f(ldav_numOtherAtomsSetID, hdfError)
    2847             : 
    2848           0 :             dimsInt(:1)=(/n_v/)
    2849           0 :             CALL h5dopen_f(groupBID, 'ldav_V', ldav_VSetID, hdfError)
    2850           0 :             CALL io_read_real1(ldav_VSetID,(/1/),dimsInt(:1),"ldav_V",ldav_V)
    2851           0 :             CALL h5dclose_f(ldav_VSetID, hdfError)
    2852             : 
    2853           0 :             dimsInt(:1)=(/n_vPairs/)
    2854           0 :             CALL h5dopen_f(groupBID, 'ldav_otherAtomIndices', ldav_otherAtomIndicesSetID, hdfError)
    2855           0 :             CALL io_read_integer1(ldav_otherAtomIndicesSetID,(/1/),dimsInt(:1),"ldav_otherAtomIndices",ldav_otherAtomIndices)
    2856           0 :             CALL h5dclose_f(ldav_otherAtomIndicesSetID, hdfError)
    2857             : 
    2858           0 :             dimsInt(:2) = (/3,n_vPairs/)
    2859           0 :             CALL h5dopen_f(groupBID, 'ldav_atomShifts', ldav_atomShiftsSetID, hdfError)
    2860           0 :             CALL io_read_real2(ldav_atomShiftsSetID,(/1,1/),dimsInt(:2),"ldav_atomShifts",ldav_atomShifts)
    2861           0 :             CALL h5dclose_f(ldav_atomShiftsSetID, hdfError)
    2862             :          END IF
    2863             :       END IF
    2864          80 :       n_opc = 0
    2865          80 :       IF(fileFormatVersion.GE.34) THEN
    2866          80 :          CALL io_read_attint0(groupBID,'n_opc',n_opc)
    2867          80 :          IF(n_opc.GT.0) THEN
    2868           5 :             ALLOCATE(ldaopc_AtomType(n_opc), ldaopc_l(n_opc), ldaopc_n(n_opc))
    2869             : 
    2870           2 :             dimsInt(:1)=(/n_opc/)
    2871           1 :             CALL h5dopen_f(groupBID, 'ldaopc_AtomType', ldaopc_AtomTypeSetID, hdfError)
    2872           1 :             CALL io_read_integer1(ldaopc_AtomTypeSetID,(/1/),dimsInt(:1),"ldaopc_AtomType",ldaopc_AtomType)
    2873           1 :             CALL h5dclose_f(ldaopc_AtomTypeSetID, hdfError)
    2874             : 
    2875           2 :             dimsInt(:1)=(/n_opc/)
    2876           1 :             CALL h5dopen_f(groupBID, 'ldaopc_l', ldaopc_lSetID, hdfError)
    2877           1 :             CALL io_read_integer1(ldaopc_lSetID,(/1/),dimsInt(:1),"ldaopc_l",ldaopc_l)
    2878           1 :             CALL h5dclose_f(ldaopc_lSetID, hdfError)
    2879             : 
    2880           2 :             dimsInt(:1)=(/n_opc/)
    2881           1 :             CALL h5dopen_f(groupBID, 'ldaopc_n', ldaopc_nSetID, hdfError)
    2882           1 :             CALL io_read_integer1(ldaopc_nSetID,(/1/),dimsInt(:1),"ldaopc_n",ldaopc_n)
    2883           6 :             CALL h5dclose_f(ldaopc_nSetID, hdfError)
    2884             :          END IF
    2885             :       END IF
    2886          80 :       CALL h5gclose_f(groupBID, hdfError)
    2887             : 
    2888          80 :       WRITE(groupBName,'(a,i0)') '/latharms-', latharmsIndex
    2889          80 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupBName)))
    2890          80 :       IF(.NOT.l_exist) THEN
    2891           0 :          CALL juDFT_error("Latharms entry "//TRIM(ADJUSTL(groupBName))//" does not exist",calledby ="readDensityHDF")
    2892             :       END IF
    2893          80 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupBName)), groupBID, hdfError)
    2894          80 :       CALL io_read_attint0(groupBID,'nlhd',nlhd)
    2895          80 :       CALL h5gclose_f(groupBID, hdfError)
    2896             : 
    2897          80 :       WRITE(groupBName,'(a,i0)') '/stars-', starsIndex
    2898          80 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupBName)))
    2899          80 :       IF(.NOT.l_exist) THEN
    2900           0 :          CALL juDFT_error("Stars entry "//TRIM(ADJUSTL(groupBName))//" does not exist",calledby ="readDensityHDF")
    2901             :       END IF
    2902          80 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupBName)), groupBID, hdfError)
    2903          80 :       CALL io_read_attint0(groupBID,'ng3',ng3)
    2904          80 :       CALL io_read_attint0(groupBID,'ng2',ng2)
    2905             :       !IF(io_attexists(groupBID,'od_nq2')) THEN
    2906             :       !   CALL io_read_attint0(groupBID,'od_nq2',od_nq2)
    2907             :       !END IF
    2908          80 :       CALL h5gclose_f(groupBID, hdfError)
    2909             : 
    2910          80 :       CALL io_read_attreal0(groupID,'fermiEnergy',fermiEnergy)
    2911          80 :       CALL io_read_attlog0(groupID,'l_qfix',l_qfix)
    2912             : 
    2913          80 :       CALL io_read_attreal0(archiveID,'distance',lastDistance)
    2914             : 
    2915          80 :       jmtdOut = MIN(jmtd,atoms%jmtd)
    2916          80 :       ntypeOut = MIN(ntype,atoms%ntype)
    2917          80 :       nmzdOut = MIN(nmzd,vacuum%nmzd)
    2918          80 :       nmzxydOut = MIN(nmzxyd,vacuum%nmzxyd)
    2919          80 :       nlhdOut = MIN(nlhd,latharms%nlhd)
    2920          80 :       ng3Out = MIN(ng3,stars%ng3)
    2921          80 :       ng2Out = MIN(ng2,stars%ng2)
    2922          80 :       nmzOut = MIN(nmz,vacuum%nmz)
    2923          80 :       nvacOut = MIN(nvac,vacuum%nvac)
    2924          80 :       nmzxyOut = MIN(nmzxy,vacuum%nmzxy)
    2925          80 :       jspinsOut = MIN(jspins,input%jspins)
    2926             : 
    2927          80 :       l_DimChange = .FALSE.
    2928          80 :       IF(atoms%jmtd.NE.jmtd) l_DimChange = .TRUE.
    2929          80 :       IF(atoms%ntype.NE.ntype) l_DimChange = .TRUE.
    2930          80 :       IF(vacuum%nmzd.NE.nmzd) l_DimChange = .TRUE.
    2931          80 :       IF(vacuum%nmzxyd.NE.nmzxyd) l_DimChange = .TRUE.
    2932          80 :       IF(latharms%nlhd.NE.nlhd) l_DimChange = .TRUE.
    2933          80 :       IF(stars%ng3.NE.ng3) l_DimChange = .TRUE.
    2934          80 :       IF(stars%ng2.NE.ng2) l_DimChange = .TRUE.
    2935          80 :       IF(vacuum%nmz.NE.nmz) l_DimChange = .TRUE.
    2936          80 :       IF(vacuum%nvac.NE.nvac) l_DimChange = .TRUE.
    2937          80 :       IF(vacuum%nmzxy.NE.nmzxy) l_DimChange = .TRUE.
    2938          80 :       IF(input%jspins.NE.jspins) l_DimChange = .TRUE.
    2939             : 
    2940          80 :       l_mmpMatDimEquals = .TRUE.
    2941          80 :       IF(fileFormatVersion.GE.29) THEN
    2942          80 :          IF(atoms%n_u+atoms%n_hia.NE.n_u) THEN
    2943           0 :             l_DimChange = .TRUE.
    2944           0 :             l_mmpMatDimEquals = .FALSE.
    2945          80 :          ELSE IF ((densityType.EQ.DENSITY_TYPE_FFN_IN_const.OR.densityType.EQ.DENSITY_TYPE_FFN_OUT_const).AND.&
    2946             :                   (localDensityType.NE.DENSITY_TYPE_FFN_IN_const.AND.localDensityType.NE.DENSITY_TYPE_FFN_OUT_const)) THEN
    2947           6 :             l_DimChange = .TRUE.
    2948           6 :             l_mmpMatDimEquals = .FALSE.
    2949          74 :          ELSE IF (input%ldauSpinoffd .NEQV. l_spinoffd_ldau) THEN
    2950           0 :             l_DimChange = .TRUE.
    2951           0 :             l_mmpMatDimEquals = .FALSE.
    2952             :          ELSE
    2953          91 :             DO i = 1, n_u
    2954          17 :                IF (atoms%lda_u(i)%atomType.NE.ldau_AtomType(i)) l_mmpMatDimEquals = .FALSE.
    2955          17 :                IF (atoms%lda_u(i)%l.NE.ldau_l(i)) l_mmpMatDimEquals = .FALSE.
    2956          17 :                l_amf_Temp = .FALSE.
    2957          17 :                IF(ldau_l_amf(i).EQ.1) l_amf_Temp = .TRUE.
    2958          17 :                IF (atoms%lda_u(i)%l_amf.NEQV.l_amf_Temp) l_mmpMatDimEquals = .FALSE. ! Am I sure about this? parameter change => dim change?
    2959          17 :                IF (ABS(atoms%lda_u(i)%u-ldau_U(i)).GT.1.0e-10) l_mmpMatDimEquals = .FALSE. ! Am I sure about this? parameter change => dim change?
    2960          91 :                IF (ABS(atoms%lda_u(i)%j-ldau_J(i)).GT.1.0e-10) l_mmpMatDimEquals = .FALSE. ! Am I sure about this? parameter change => dim change?
    2961             :             END DO
    2962          74 :             IF (.NOT.l_mmpMatDimEquals) l_DimChange = .TRUE.
    2963             :          END IF
    2964             :       END IF
    2965          80 :       l_nIJ_llp_mmpDimEquals = .TRUE.
    2966          80 :       IF(fileFormatVersion.GE.35) THEN
    2967          80 :          IF ((atoms%n_v.NE.n_v).OR.(atoms%n_vPairs.NE.n_vPairs)) THEN
    2968           0 :             l_DimChange = .TRUE.
    2969           0 :             l_nIJ_llp_mmpDimEquals = .FALSE.
    2970             :          ELSE
    2971             :             iPair = 0
    2972          80 :             DO i_v = 1, n_v
    2973             :                IF ((atoms%lda_v(i_v)%numOtherAtoms.NE.ldav_numOtherAtoms(i_v)).OR.&
    2974           0 :                    (atoms%lda_v(i_v)%thisAtomL.NE.ldav_thisAtomL(i_v)).OR.&
    2975          80 :                    (atoms%lda_v(i_v)%otherAtomL.NE.ldav_otherAtomL(i_v))) THEN
    2976           0 :                   l_DimChange = .TRUE.
    2977           0 :                   l_nIJ_llp_mmpDimEquals = .FALSE.
    2978             :                   ! At the moment I don't issue a dim change if the V changes.
    2979             :                ELSE
    2980           0 :                   DO iOtherAtom = 1, ldav_numOtherAtoms(i_v)
    2981           0 :                      iPair = iPair + 1
    2982           0 :                      IF ((atoms%lda_v(i_v)%otherAtomIndices(iOtherAtom).NE.ldav_otherAtomIndices(iPair)).OR.&
    2983           0 :                          ANY(ABS(atoms%lda_v(i_v)%atomShifts(:,iOtherAtom)-ldav_atomShifts(:,iPair)).GT.1.0e-10)) THEN
    2984           0 :                         l_DimChange = .TRUE.
    2985           0 :                         l_nIJ_llp_mmpDimEquals = .FALSE.
    2986             :                      END IF
    2987             :                   END DO
    2988             :                END IF
    2989             :             END DO
    2990             :          END IF
    2991             :       END IF
    2992          80 :       IF(fileFormatVersion.GE.34) THEN
    2993          80 :          IF(atoms%n_opc.NE.n_opc) THEN
    2994           0 :             l_DimChange = .TRUE.
    2995           0 :             l_mmpMatDimEquals = .FALSE.
    2996             :          ELSE
    2997          82 :             DO i = 1, n_opc
    2998           2 :                IF (atoms%lda_opc(i)%atomType.NE.ldaopc_AtomType(i)) l_mmpMatDimEquals = .FALSE.
    2999           2 :                IF (atoms%lda_opc(i)%l.NE.ldaopc_l(i)) l_mmpMatDimEquals = .FALSE.
    3000          82 :                IF (atoms%lda_opc(i)%n.NE.ldaopc_n(i)) l_mmpMatDimEquals = .FALSE.
    3001             :             END DO
    3002          80 :             IF (.NOT.l_mmpMatDimEquals) l_DimChange = .TRUE.
    3003             :          END IF
    3004             :       END IF
    3005             : 
    3006     9867516 :       den%mt = 0.0
    3007         480 :       ALLOCATE(frTemp(jmtd,1:nlhd+1,ntype,1:jspins))
    3008         400 :       dimsInt(:4)=(/jmtd,nlhd+1,ntype,jspins/)
    3009          80 :       CALL h5dopen_f(groupID, 'fr', frSetID, hdfError)
    3010          80 :       CALL io_read_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"frTemp",frTemp(:,:,:,:))
    3011          80 :       CALL h5dclose_f(frSetID, hdfError)
    3012             :       den%mt(1:jmtdOut,0:nlhdOut,1:ntypeOut,1:jspinsOut) =&
    3013     6931444 :       frTemp(1:jmtdOut,1:nlhdOut+1,1:ntypeOut,1:jspinsOut)
    3014          80 :       DEALLOCATE(frTemp)
    3015             : 
    3016          80 :       IF (PRESENT(denIm)) THEN
    3017           0 :          denIm%mt = 0.0
    3018           0 :          ALLOCATE(frTemp(jmtd,1:nlhd+1,ntype,1:jspins))
    3019           0 :          dimsInt(:4)=(/jmtd,nlhd+1,ntype,jspins/)
    3020           0 :          CALL h5dopen_f(groupID, 'frIm', frImSetID, hdfError)
    3021           0 :          CALL io_read_real4(frImSetID,(/1,1,1,1/),dimsInt(:4),"frImTemp",frTemp(:,:,:,:))
    3022           0 :          CALL h5dclose_f(frImSetID, hdfError)
    3023             :          denIm%mt(1:jmtdOut,0:nlhdOut,1:ntypeOut,1:jspinsOut) =&
    3024           0 :          frTemp(1:jmtdOut,1:nlhdOut+1,1:ntypeOut,1:jspinsOut)
    3025           0 :          DEALLOCATE(frTemp)
    3026             :       END IF
    3027             : 
    3028          80 :       IF ((localDensityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.(localDensityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    3029          18 :          ALLOCATE(frTemp(jmtd,1:nlhd+1,ntype,1:2))
    3030          15 :          dimsInt(:4)=(/jmtd,nlhd+1,ntype,2/)
    3031           3 :          CALL h5dopen_f(groupID, 'froff', frOffSetID, hdfError)
    3032           3 :          CALL io_read_real4(frOffSetID,(/1,1,1,1/),dimsInt(:4),"frTemp",frTemp(:,:,:,1:2))
    3033           3 :          CALL h5dclose_f(frOffSetID, hdfError)
    3034             :          den%mt(1:jmtdOut,0:nlhdOut,1:ntypeOut,3:4) =&
    3035      491201 :             frTemp(1:jmtdOut,1:nlhdOut+1,1:ntypeOut,1:2)
    3036           3 :          DEALLOCATE(frTemp)
    3037           9 :          IF (PRESENT(denIm)) THEN
    3038           0 :             ALLOCATE(frTemp(jmtd,1:nlhd+1,ntype,1:2))
    3039           0 :             dimsInt(:4)=(/jmtd,nlhd+1,ntype,2/)
    3040           0 :             CALL h5dopen_f(groupID, 'froffIm', frOffImSetID, hdfError)
    3041           0 :             CALL io_read_real4(frOffImSetID,(/1,1,1,1/),dimsInt(:4),"frImTemp",frTemp(:,:,:,1:2))
    3042           0 :             CALL h5dclose_f(frOffImSetID, hdfError)
    3043             :             denIm%mt(1:jmtdOut,0:nlhdOut,1:ntypeOut,3:4) =&
    3044           0 :                frTemp(1:jmtdOut,1:nlhdOut+1,1:ntypeOut,1:2)
    3045           0 :             DEALLOCATE(frTemp)
    3046             :          END IF
    3047             :       END IF
    3048             : 
    3049      688292 :       den%pw = CMPLX(0.0,0.0)
    3050         320 :       ALLOCATE(fpwTemp(ng3,jspins))
    3051         320 :       dimsInt(:3)=(/2,ng3,jspins/)
    3052          80 :       CALL h5dopen_f(groupID, 'fpw', fpwSetID, hdfError)
    3053          80 :       CALL io_read_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpwTemp",fpwTemp(:,:jspins))
    3054          80 :       CALL h5dclose_f(fpwSetID, hdfError)
    3055      500829 :       den%pw(1:ng3Out,1:jspinsOut) = fpwTemp(1:ng3Out,1:jspinsOut)
    3056          80 :       DEALLOCATE(fpwTemp)
    3057             : 
    3058          80 :       IF (l_film) THEN
    3059     1581362 :          den%vac = CMPLX(0.0,0.0)
    3060          66 :          ALLOCATE(fvacTemp(nmzd,ng2,2,jspins))
    3061          66 :          dimsInt(:5)=(/2,nmzd,ng2,2,jspins/)
    3062          11 :          CALL h5dopen_f(groupID, 'fvac', fvacSetID, hdfError)
    3063          11 :          CALL io_read_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"fvacTemp",fvacTemp(:,:,:,:jspins))
    3064          11 :          CALL h5dclose_f(fvacSetID, hdfError)
    3065             :          den%vac(1:nmzdOut,1:ng2Out,1:2,1:jspinsOut) =&
    3066     1581362 :             fvacTemp(1:nmzdOut,1:ng2Out,1:2,1:jspinsOut)
    3067          33 :          DEALLOCATE(fvacTemp)
    3068             :       END IF
    3069             : 
    3070             :       IF((localDensityType.EQ.DENSITY_TYPE_NOCO_IN_const).OR.&
    3071          80 :          (localDensityType.EQ.DENSITY_TYPE_NOCO_OUT_const).OR.(localDensityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    3072             :             (localDensityType.EQ.DENSITY_TYPE_FFN_OUT_const)) THEN
    3073             : 
    3074       26340 :          den%pw(:,3) = CMPLX(0.0,0.0)
    3075           9 :          ALLOCATE(cdomTemp(ng3))
    3076           9 :          dimsInt(:2)=(/2,ng3/)
    3077           3 :          CALL h5dopen_f(groupID, 'cdom', cdomSetID, hdfError)
    3078           3 :          CALL io_read_complex1(cdomSetID,(/-1,1/),dimsInt(:2),"cdomTemp",cdomTemp)
    3079           3 :          CALL h5dclose_f(cdomSetID, hdfError)
    3080       26340 :          den%pw(1:ng3Out,3) = cdomTemp(1:ng3Out)
    3081           3 :          DEALLOCATE(cdomTemp)
    3082             : 
    3083           3 :          IF (PRESENT(denIm)) THEN
    3084           0 :             den%pw(:,4) = CMPLX(0.0,0.0)
    3085           0 :             ALLOCATE(cdomTemp(ng3))
    3086           0 :             dimsInt(:2)=(/2,ng3/)
    3087           0 :             CALL h5dopen_f(groupID, 'cdom12', cdom12SetID, hdfError)
    3088           0 :             CALL io_read_complex1(cdom12SetID,(/-1,1/),dimsInt(:2),"cdom12Temp",cdomTemp)
    3089           0 :             CALL h5dclose_f(cdom12SetID, hdfError)
    3090           0 :             den%pw(1:ng3Out,4) = cdomTemp(1:ng3Out)
    3091           0 :             DEALLOCATE(cdomTemp)
    3092             :          END IF
    3093             : 
    3094           9 :          IF (l_film) THEN
    3095           0 :             den%vac(:,:,:,3) = CMPLX(0.0,0.0)
    3096             :             ! No change in od_nq2 allowed at the moment!
    3097           0 :             ALLOCATE(cdomvacTemp(nmz,ng2,nvac))
    3098           0 :             dimsInt(:4)=(/2,nmz,ng2,nvac/)
    3099           0 :             CALL h5dopen_f(groupID, 'cdomvac', cdomvacSetID, hdfError)
    3100           0 :             CALL io_read_complex3(cdomvacSetID,(/-1,1,1,1/),dimsInt(:4),"cdomvacTemp",cdomvacTemp)
    3101           0 :             CALL h5dclose_f(cdomvacSetID, hdfError)
    3102             :             den%vac(1:nmzOut,1:ng2Out,1:nvacOut,3) =&
    3103           0 :                cdomvacTemp(1:nmzOut,1:ng2Out,1:nvacOut)
    3104           0 :             DEALLOCATE(cdomvacTemp)
    3105             :          END IF
    3106             :       END IF
    3107             : 
    3108          80 :       IF((fileFormatVersion.GE.29).AND.(n_u+n_opc.GT.0)) THEN
    3109             :          IF((localDensityType.EQ.DENSITY_TYPE_FFN_IN_const).OR.&
    3110           8 :             (localDensityType.EQ.DENSITY_TYPE_FFN_OUT_const).OR.&
    3111             :             l_spinoffd_ldau) THEN
    3112           0 :             ALLOCATE (mmpMatTemp(-lmaxU_const:lmaxU_const,-lmaxU_const:lmaxU_const,n_u+n_opc,3))
    3113           0 :             dimsInt(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u+n_opc,3/)
    3114           0 :             jspinsmmp = 3
    3115             :          ELSE
    3116          32 :             ALLOCATE (mmpMatTemp(-lmaxU_const:lmaxU_const,-lmaxU_const:lmaxU_const,n_u+n_opc,jspins))
    3117          48 :             dimsInt(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_u+n_opc,jspins/)
    3118           8 :             jspinsmmp = jspins
    3119             :          END IF
    3120           8 :          CALL h5dopen_f(groupID, 'mmpMat', mmpMatSetID, hdfError)
    3121           8 :          CALL io_read_complex4(mmpMatSetID,(/-1,1,1,1,1/),dimsInt(:5),"mmpMatTemp",mmpMatTemp)
    3122           8 :          CALL h5dclose_f(mmpMatSetID, hdfError)
    3123             : 
    3124        1503 :          den%mmpMat = cmplx_0
    3125           8 :          IF(l_mmpMatDimEquals) THEN
    3126        1503 :             den%mmpMat(:,:,:,1:jspinsmmp) = mmpMatTemp(:,:,:,1:jspinsmmp)
    3127             :          ELSE
    3128           0 :             DO i = 1, n_u
    3129           0 :                DO j = 1, atoms%n_u+atoms%n_hia
    3130           0 :                   IF (atoms%lda_u(j)%atomType.NE.ldau_AtomType(i)) CYCLE
    3131           0 :                   IF (atoms%lda_u(j)%l.NE.ldau_l(i)) CYCLE
    3132           0 :                   den%mmpMat(:,:,j,1:jspinsmmp) = mmpMatTemp(:,:,i,1:jspinsmmp)
    3133             :                END DO
    3134             :             END DO
    3135           0 :             DO i = 1, n_opc
    3136           0 :                DO j = 1, atoms%n_opc
    3137           0 :                   IF (atoms%lda_opc(j)%atomType.NE.ldaopc_AtomType(i)) CYCLE
    3138           0 :                   IF (atoms%lda_opc(j)%l.NE.ldaopc_l(i)) CYCLE
    3139           0 :                   den%mmpMat(:,:,j+atoms%n_u+atoms%n_hia,1:jspinsmmp) = mmpMatTemp(:,:,i+n_u,1:jspinsmmp)
    3140             :                END DO
    3141             :             END DO
    3142             :          END IF
    3143             : 
    3144           8 :          DEALLOCATE (mmpMatTemp)
    3145             :       END IF
    3146             : 
    3147          80 :       IF((fileFormatVersion.GE.35).AND.(n_v.GT.0)) THEN
    3148           0 :          ALLOCATE (nIJ_llp_mmpTemp(-lmaxU_const:lmaxU_const,-lmaxU_const:lmaxU_const,n_vPairs,jspins))
    3149           0 :          dimsInt(:5)=(/2,2*lmaxU_const+1,2*lmaxU_const+1,n_vPairs,jspins/)
    3150           0 :          CALL h5dopen_f(groupID, 'nIJ_llp_mmp', nIJ_llp_mmpSetID, hdfError)
    3151           0 :          CALL io_read_complex4(nIJ_llp_mmpSetID,(/-1,1,1,1,1/),dimsInt(:5),"nIJ_llp_mmpTemp",nIJ_llp_mmpTemp)
    3152           0 :          CALL h5dclose_f(nIJ_llp_mmpSetID, hdfError)
    3153           0 :          den%nIJ_llp_mmp = cmplx_0
    3154           0 :          IF(l_nIJ_llp_mmpDimEquals) THEN
    3155           0 :             den%nIJ_llp_mmp(:,:,:,:) = nIJ_llp_mmpTemp(:,:,:,:)
    3156             :          ELSE
    3157           0 :             WRITE(*,*) "Dimension change for nIJ_llp_mmp not implemented!"
    3158             :          END IF
    3159           0 :          DEALLOCATE (nIJ_llp_mmpTemp)
    3160             :       END IF
    3161             : 
    3162          80 :       CALL h5gclose_f(groupID, hdfError)
    3163          80 :       CALL h5gclose_f(archiveID, hdfError)
    3164             : 
    3165         960 :    END SUBROUTINE readDensityHDF
    3166             : 
    3167           0 :    SUBROUTINE readPotentialHDF(fileID, archiveName, potentialType,&
    3168           0 :                                iter,fr,fpw,fz,fzxy,fvac,l_mtnoco)
    3169             : 
    3170             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    3171             :       INTEGER, INTENT(IN)          :: potentialType
    3172             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    3173             :       LOGICAL , INTENT(IN)         :: l_mtNoco
    3174             : 
    3175             :       INTEGER, INTENT (OUT)        :: iter
    3176             : 
    3177             :       REAL,    INTENT (OUT)        :: fr(:,:,:,:)
    3178             :       REAL,    INTENT (OUT)        :: fz(:,:,:)
    3179             :       COMPLEX, INTENT (OUT)        :: fpw(:,:)
    3180             :       COMPLEX, INTENT (OUT)        :: fzxy(:,:,:,:),fvac(:,:,:,:)
    3181             : 
    3182             :       INTEGER              :: starsIndex, latharmsIndex, structureIndex, stepfunctionIndex
    3183             :       INTEGER              :: jspins
    3184             :       INTEGER              :: ntype,jmtd,nmzd,nmzxyd,nlhd,ng3,ng2
    3185             :       INTEGER              :: nmz, nvac, nmzxy
    3186             :       LOGICAL              :: l_film, l_exist
    3187             :       INTEGER(HID_T)       :: archiveID, groupID, groupBID
    3188             :       INTEGER              :: hdfError
    3189             :       CHARACTER(LEN=30)    :: groupName, groupBName, potentialTypeName
    3190             :       INTEGER              :: dimsInt(7)
    3191             : 
    3192             :       INTEGER(HID_T)              :: frSetID
    3193             :       INTEGER(HID_T)              :: fpwSetID
    3194             :       INTEGER(HID_T)              :: fzSetID
    3195             :       INTEGER(HID_T)              :: fzxySetID
    3196             :       INTEGER(HID_T)              :: fvacSetID
    3197             : 
    3198           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    3199           0 :       IF(.NOT.l_exist) THEN
    3200           0 :          CALL juDFT_error('density archive '//TRIM(ADJUSTL(archiveName))//' does not exist.' ,calledby ="readPotentialHDF")
    3201             :       END IF
    3202             : 
    3203           0 :       SELECT CASE (potentialType)
    3204             :          CASE(POTENTIAL_TYPE_IN_const)
    3205           0 :             potentialTypeName = '/in'
    3206             :          CASE(POTENTIAL_TYPE_OUT_const)
    3207           0 :             potentialTypeName = '/out'
    3208             :          CASE DEFAULT
    3209           0 :             CALL juDFT_error("Unknown potential type selected",calledby ="readPotentialHDF")
    3210             :       END SELECT
    3211             : 
    3212           0 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(potentialTypeName))
    3213           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3214           0 :       IF(.NOT.l_exist) THEN
    3215           0 :          CALL juDFT_error('Potential entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readPotentialHDF")
    3216             :       END IF
    3217             : 
    3218           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    3219           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    3220             : 
    3221           0 :       CALL io_read_attint0(archiveID,'starsIndex',starsIndex)
    3222           0 :       CALL io_read_attint0(archiveID,'latharmsIndex',latharmsIndex)
    3223           0 :       CALL io_read_attint0(archiveID,'structureIndex',structureIndex)
    3224           0 :       CALL io_read_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    3225           0 :       CALL io_read_attint0(archiveID,'spins',jspins)
    3226           0 :       CALL io_read_attint0(archiveID,'iter',iter)
    3227             : 
    3228           0 :       WRITE(groupBName,'(a,i0)') '/structure-', structureIndex
    3229           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupBName)))
    3230           0 :       IF(.NOT.l_exist) THEN
    3231           0 :          CALL juDFT_error("Structure entry "//TRIM(ADJUSTL(groupBName))//" does not exist",calledby ="readPotentialHDF")
    3232             :       END IF
    3233           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupBName)), groupBID, hdfError)
    3234           0 :       CALL io_read_attlog0(groupBID,'l_film',l_film)
    3235           0 :       CALL io_read_attint0(groupBID,'ntype',ntype)
    3236           0 :       CALL io_read_attint0(groupBID,'jmtd',jmtd)
    3237           0 :       CALL io_read_attint0(groupBID,'nmzd',nmzd)
    3238           0 :       CALL io_read_attint0(groupBID,'nmzxyd',nmzxyd)
    3239           0 :       CALL io_read_attint0(groupBID,'nmzxy',nmzxy)
    3240           0 :       CALL io_read_attint0(groupBID,'nmz',nmz)
    3241           0 :       CALL io_read_attint0(groupBID,'nvac',nvac)
    3242           0 :       CALL h5gclose_f(groupBID, hdfError)
    3243             : 
    3244           0 :       WRITE(groupBName,'(a,i0)') '/latharms-', latharmsIndex
    3245           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupBName)))
    3246           0 :       IF(.NOT.l_exist) THEN
    3247           0 :          CALL juDFT_error("Latharms entry "//TRIM(ADJUSTL(groupBName))//" does not exist",calledby ="readPotentialHDF")
    3248             :       END IF
    3249           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupBName)), groupBID, hdfError)
    3250           0 :       CALL io_read_attint0(groupBID,'nlhd',nlhd)
    3251           0 :       CALL h5gclose_f(groupBID, hdfError)
    3252             : 
    3253           0 :       WRITE(groupBName,'(a,i0)') '/stars-', starsIndex
    3254           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupBName)))
    3255           0 :       IF(.NOT.l_exist) THEN
    3256           0 :          CALL juDFT_error("Stars entry "//TRIM(ADJUSTL(groupBName))//" does not exist",calledby ="readPotentialHDF")
    3257             :       END IF
    3258           0 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupBName)), groupBID, hdfError)
    3259           0 :       CALL io_read_attint0(groupBID,'ng3',ng3)
    3260           0 :       CALL io_read_attint0(groupBID,'ng2',ng2)
    3261           0 :       CALL h5gclose_f(groupBID, hdfError)
    3262             : 
    3263           0 :       IF (.NOT.l_mtNoco) THEN
    3264           0 :       dimsInt(:4)=(/jmtd,nlhd+1,ntype,jspins/)
    3265           0 :       CALL h5dopen_f(groupID, 'fr', frSetID, hdfError)
    3266           0 :       CALL io_read_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"fr",fr)
    3267           0 :       CALL h5dclose_f(frSetID, hdfError)
    3268             :       ELSE
    3269           0 :       dimsInt(:4)=(/jmtd,nlhd+1,ntype,jspins+2/)
    3270           0 :       CALL h5dopen_f(groupID, 'fr', frSetID, hdfError)
    3271           0 :       CALL io_read_real4(frSetID,(/1,1,1,1/),dimsInt(:4),"fr",fr)
    3272           0 :       CALL h5dclose_f(frSetID, hdfError)
    3273             :       END IF
    3274             : 
    3275             : 
    3276           0 :       dimsInt(:3)=(/2,ng3,jspins/)
    3277           0 :       CALL h5dopen_f(groupID, 'fpw', fpwSetID, hdfError)
    3278           0 :       CALL io_read_complex2(fpwSetID,(/-1,1,1/),dimsInt(:3),"fpw",fpw)
    3279           0 :       CALL h5dclose_f(fpwSetID, hdfError)
    3280             : 
    3281           0 :       IF (l_film) THEN
    3282           0 :          dimsInt(:3)=(/nmzd,2,jspins/)
    3283           0 :          CALL h5dopen_f(groupID, 'fz', fzSetID, hdfError)
    3284           0 :          CALL io_read_real3(fzSetID,(/1,1,1/),dimsInt(:3),"fz",fz)
    3285           0 :          CALL h5dclose_f(fzSetID, hdfError)
    3286             : 
    3287           0 :          dimsInt(:5)=(/2,nmzxyd,ng2-1,2,jspins/)
    3288           0 :          CALL h5dopen_f(groupID, 'fzxy', fzxySetID, hdfError)
    3289           0 :          CALL io_read_complex4(fzxySetID,(/-1,1,1,1,1/),dimsInt(:5),"fzxy",fzxy)
    3290           0 :          CALL h5dclose_f(fzxySetID, hdfError)
    3291             : 
    3292           0 :          dimsInt(:5)=(/2,nmzd,ng2,2,jspins/)
    3293           0 :          CALL h5dopen_f(groupID, 'fvac', fvacSetID, hdfError)
    3294           0 :          CALL io_read_complex4(fvacSetID,(/-1,1,1,1,1/),dimsInt(:5),"fvac",fvac)
    3295           0 :          CALL h5dclose_f(fvacSetID, hdfError)
    3296             :       END IF
    3297             : 
    3298           0 :       CALL h5gclose_f(groupID, hdfError)
    3299           0 :       CALL h5gclose_f(archiveID, hdfError)
    3300             : 
    3301           0 :    END SUBROUTINE readPotentialHDF
    3302             : 
    3303             : 
    3304         339 :    SUBROUTINE peekDensityEntryHDF(fileID, archiveName, densityType,&
    3305             :                                   iter, starsIndex, latharmsIndex, structureIndex,&
    3306             :                                   stepfunctionIndex, previousDensityIndex, jspins,&
    3307             :                                   date, time, distance, fermiEnergy,l_qfix, mmpmatDistance,&
    3308             :                                   occDistance)
    3309             : 
    3310             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    3311             :       INTEGER, INTENT(IN)          :: densityType
    3312             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    3313             : 
    3314             :       INTEGER, INTENT(OUT),OPTIONAL          :: date, time, iter
    3315             :       INTEGER, INTENT(OUT),OPTIONAL          :: starsIndex, latharmsIndex, structureIndex, stepfunctionIndex
    3316             :       INTEGER, INTENT(OUT),OPTIONAL          :: previousDensityIndex, jspins
    3317             :       REAL,    INTENT(OUT),OPTIONAL          :: fermiEnergy, distance
    3318             :       REAL,    INTENT(OUT),OPTIONAL          :: mmpmatDistance, occDistance
    3319             :       LOGICAL, INTENT(OUT),OPTIONAL          :: l_qfix
    3320             : 
    3321             :       INTEGER              :: localDensityType
    3322             :       LOGICAL              :: l_exist
    3323             :       INTEGER(HID_T)       :: archiveID, groupID
    3324             :       INTEGER              :: hdfError
    3325             :       CHARACTER(LEN=30)    :: groupName, densityTypeName
    3326             : 
    3327         113 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    3328         113 :       IF(.NOT.l_exist) THEN
    3329           0 :          CALL juDFT_error('density archive '//TRIM(ADJUSTL(archiveName))//' does not exist.' ,calledby ="peekDensityEntryHDF")
    3330             :       END IF
    3331             : 
    3332         113 :       localDensityType = densityType
    3333          78 :       SELECT CASE (densityType)
    3334             :          CASE(DENSITY_TYPE_UNDEFINED_const)
    3335          78 :             densityTypeName = ''
    3336             :          CASE(DENSITY_TYPE_IN_const)
    3337           9 :             densityTypeName = '/in'
    3338             :          CASE(DENSITY_TYPE_OUT_const)
    3339           0 :             densityTypeName = '/out'
    3340             :          CASE(DENSITY_TYPE_NOCO_IN_const)
    3341           0 :             densityTypeName = '/noco_in'
    3342           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3343           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3344           0 :             IF(.NOT.l_exist) THEN
    3345           0 :                localDensityType = DENSITY_TYPE_IN_const
    3346           0 :                densityTypeName = '/in'
    3347             :             END IF
    3348             :          CASE(DENSITY_TYPE_NOCO_OUT_const)
    3349           0 :             densityTypeName = '/noco_out'
    3350           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3351           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3352           0 :             IF(.NOT.l_exist) THEN
    3353           0 :                localDensityType = DENSITY_TYPE_OUT_const
    3354           0 :                densityTypeName = '/out'
    3355             :             END IF
    3356             :          CASE(DENSITY_TYPE_FFN_IN_const)
    3357          26 :             densityTypeName = '/ffn_in'
    3358          26 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3359          26 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3360          26 :             IF(.NOT.l_exist) THEN
    3361          26 :                localDensityType = DENSITY_TYPE_NOCO_IN_const
    3362          26 :                densityTypeName = '/noco_in'
    3363             :             END IF
    3364          26 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3365          26 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3366          26 :             IF(.NOT.l_exist) THEN
    3367          21 :                localDensityType = DENSITY_TYPE_IN_const
    3368          21 :                densityTypeName = '/in'
    3369             :             END IF
    3370             :          CASE(DENSITY_TYPE_FFN_OUT_const)
    3371           0 :             densityTypeName = '/ffn_out'
    3372           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3373           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3374           0 :             IF(.NOT.l_exist) THEN
    3375           0 :                localDensityType = DENSITY_TYPE_NOCO_OUT_const
    3376           0 :                densityTypeName = '/noco_out'
    3377             :             END IF
    3378           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3379           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3380           0 :             IF(.NOT.l_exist) THEN
    3381           0 :                localDensityType = DENSITY_TYPE_OUT_const
    3382           0 :                densityTypeName = '/out'
    3383             :             END IF
    3384             :          CASE(DENSITY_TYPE_PRECOND_const)
    3385           0 :             densityTypeName = '/precond'
    3386             :          CASE DEFAULT
    3387         113 :             CALL juDFT_error("Unknown density type selected",calledby ="peekDensityEntryHDF")
    3388             :       END SELECT
    3389             : 
    3390         113 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3391         113 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3392         113 :       IF(.NOT.l_exist) THEN
    3393           0 :          CALL juDFT_error('density entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="peekDensityEntryHDF")
    3394             :       END IF
    3395             : 
    3396         113 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(archiveName)), archiveID, hdfError)
    3397         113 :       CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
    3398             : 
    3399         113 :       IF (PRESENT(previousDensityIndex)) CALL io_read_attint0(archiveID,'previousDensityIndex',previousDensityIndex)
    3400         113 :       IF (PRESENT(starsIndex)) CALL io_read_attint0(archiveID,'starsIndex',starsIndex)
    3401         113 :       IF (PRESENT(latharmsIndex)) CALL io_read_attint0(archiveID,'latharmsIndex',latharmsIndex)
    3402         113 :       IF (PRESENT(structureIndex)) CALL io_read_attint0(archiveID,'structureIndex',structureIndex)
    3403         113 :       IF (PRESENT(stepfunctionIndex)) CALL io_read_attint0(archiveID,'stepfunctionIndex',stepfunctionIndex)
    3404         113 :       IF (PRESENT(jspins)) CALL io_read_attint0(archiveID,'spins',jspins)
    3405         113 :       IF (PRESENT(iter)) CALL io_read_attint0(archiveID,'iter',iter)
    3406         113 :       IF (PRESENT(date)) CALL io_read_attint0(archiveID,'date',date)
    3407         113 :       IF (PRESENT(time)) CALL io_read_attint0(archiveID,'time',time)
    3408         113 :       IF (PRESENT(distance)) CALL io_read_attreal0(archiveID,'distance',distance)
    3409             : 
    3410         113 :       IF(PRESENT(mmpmatDistance)) THEN
    3411           0 :          IF(io_attexists(archiveID,'mmpmatDistance')) THEN
    3412           0 :             CALL io_read_attreal0(archiveID,'mmpmatDistance',mmpmatDistance)
    3413             :          ELSE
    3414           0 :             mmpmatDistance = -1.0
    3415             :          ENDIF
    3416             :       ENDIF
    3417         113 :       IF(PRESENT(occDistance)) THEN
    3418           0 :          IF(io_attexists(archiveID,'occDistance')) THEN
    3419           0 :             CALL io_read_attreal0(archiveID,'occDistance',occDistance)
    3420             :          ELSE
    3421           0 :             occDistance = -1.0
    3422             :          ENDIF
    3423             :       ENDIF
    3424             : 
    3425         113 :       IF (densityType.NE.DENSITY_TYPE_UNDEFINED_const) THEN
    3426          35 :          IF (PRESENT(fermiEnergy)) CALL io_read_attreal0(groupID,'fermiEnergy',fermiEnergy)
    3427          35 :          IF (PRESENT(l_qfix)) CALL io_read_attlog0(groupID,'l_qfix',l_qfix)
    3428             :       END IF
    3429             : 
    3430         113 :       CALL h5gclose_f(groupID, hdfError)
    3431         113 :       CALL h5gclose_f(archiveID, hdfError)
    3432             : 
    3433         113 :    END SUBROUTINE peekDensityEntryHDF
    3434             : 
    3435         336 :    SUBROUTINE writeCoreDensityHDF(fileID,input,atoms,rhcs,tecs,qints)
    3436             :       use m_types_atoms
    3437             :       use m_types_input
    3438             :       TYPE(t_atoms),    INTENT(IN) :: atoms
    3439             :       TYPE(t_input),    INTENT(IN) :: input
    3440             : 
    3441             : 
    3442             :       INTEGER(HID_T), INTENT(IN) :: fileID
    3443             :       REAL,           INTENT(IN) :: rhcs(:,:,:)!(atoms%msh,atoms%ntype,input%jspins)
    3444             :       REAL,           INTENT(IN) :: tecs(:,:)!(atoms%ntype,input%jspins)
    3445             :       REAL,           INTENT(IN) :: qints(:,:)!(atoms%ntype,input%jspins)
    3446             : 
    3447             :       INTEGER hdfError
    3448             :       INTEGER(HID_T) cdncGroupID, rhcsSpaceID, rhcsSetID
    3449             :       INTEGER(HID_T) tecsSpaceID, tecsSetID, qintsSpaceID, qintsSetID
    3450             :       INTEGER jspdTemp, ntypeTemp, jmtdTemp
    3451             :       LOGICAL l_exist, l_delete
    3452             :       INTEGER(HSIZE_T) :: dims(7)
    3453             :       INTEGER          :: dimsInt(7)
    3454             : 
    3455         336 :       l_delete = .FALSE.
    3456         336 :       l_exist = io_groupexists(fileID,'/cdnc')
    3457             : 
    3458         336 :       IF(l_exist) THEN
    3459         272 :          CALL h5gopen_f(fileID, '/cdnc', cdncGroupID, hdfError)
    3460             : 
    3461         272 :          CALL io_read_attint0(cdncGroupID,'jspd',jspdTemp)
    3462         272 :          CALL io_read_attint0(cdncGroupID,'ntype',ntypeTemp)
    3463         272 :          CALL io_read_attint0(cdncGroupID,'jmtd',jmtdTemp)
    3464             : 
    3465         272 :          CALL h5gclose_f(cdncGroupID, hdfError)
    3466             : 
    3467         272 :          IF (jspdTemp.NE.input%jspins) l_delete = .TRUE.
    3468         272 :          IF (ntypeTemp.NE.atoms%ntype) l_delete = .TRUE.
    3469         272 :          IF (jmtdTemp.NE.atoms%jmtd) l_delete = .TRUE.
    3470             : 
    3471         272 :          IF(l_delete) THEN
    3472           1 :             CALL h5ldelete_f(fileID, '/cdnc', hdfError)
    3473             :             l_exist = .FALSE.
    3474             :          END IF
    3475             :       END IF
    3476             : 
    3477        2883 :       IF(l_exist) THEN ! replace current core density
    3478         271 :          CALL h5gopen_f(fileID, '/cdnc', cdncGroupID, hdfError)
    3479             : 
    3480         271 :          CALL io_write_attint0(cdncGroupID,'jspd',input%jspins)
    3481         271 :          CALL io_write_attint0(cdncGroupID,'ntype',atoms%ntype)
    3482         271 :          CALL io_write_attint0(cdncGroupID,'jmtd',atoms%jmtd)
    3483             : 
    3484        1084 :          dimsInt(:3)=(/atoms%jmtd,atoms%ntype,input%jspins/)
    3485         271 :          CALL h5dopen_f(cdncGroupID, 'rhcs', rhcsSetID, hdfError)
    3486         271 :          CALL io_write_real3(rhcsSetID,(/1,1,1/),dimsInt(:3),"rhcs",rhcs(:dimsInt(1),:dimsInt(2),:dimsInt(3)))
    3487         271 :          CALL h5dclose_f(rhcsSetID, hdfError)
    3488             : 
    3489         813 :          dimsInt(:2)=(/atoms%ntype,input%jspins/)
    3490         271 :          CALL h5dopen_f(cdncGroupID, 'tecs', tecsSetID, hdfError)
    3491         271 :          CALL io_write_real2(tecsSetID,(/1,1/),dimsInt(:2),"tecs",tecs)
    3492         271 :          CALL h5dclose_f(tecsSetID, hdfError)
    3493             : 
    3494         813 :          dimsInt(:2)=(/atoms%ntype,input%jspins/)
    3495         271 :          CALL h5dopen_f(cdncGroupID, 'qints', qintsSetID, hdfError)
    3496         271 :          CALL io_write_real2(qintsSetID,(/1,1/),dimsInt(:2),"qints",qints)
    3497         271 :          CALL h5dclose_f(qintsSetID, hdfError)
    3498             : 
    3499         271 :          CALL h5gclose_f(cdncGroupID, hdfError)
    3500             :       ELSE ! write new core density
    3501          65 :          CALL h5gcreate_f(fileID, '/cdnc', cdncGroupID, hdfError)
    3502             : 
    3503          65 :          CALL io_write_attint0(cdncGroupID,'jspd',input%jspins)
    3504          65 :          CALL io_write_attint0(cdncGroupID,'ntype',atoms%ntype)
    3505          65 :          CALL io_write_attint0(cdncGroupID,'jmtd',atoms%jmtd)
    3506             : 
    3507         260 :          dims(:3)=(/atoms%jmtd,atoms%ntype,input%jspins/)
    3508         520 :          dimsInt = dims
    3509          65 :          CALL h5screate_simple_f(3,dims(:3),rhcsSpaceID,hdfError)
    3510          65 :          CALL h5dcreate_f(cdncGroupID, "rhcs", H5T_NATIVE_DOUBLE, rhcsSpaceID, rhcsSetID, hdfError)
    3511          65 :          CALL h5sclose_f(rhcsSpaceID,hdfError)
    3512          65 :          CALL io_write_real3(rhcsSetID,(/1,1,1/),dimsInt(:3),"rhcs",rhcs(:dimsInt(1),:dimsInt(2),:dimsInt(3)))
    3513          65 :          CALL h5dclose_f(rhcsSetID, hdfError)
    3514             : 
    3515         195 :          dims(:2)=(/atoms%ntype,input%jspins/)
    3516         520 :          dimsInt = dims
    3517          65 :          CALL h5screate_simple_f(2,dims(:2),tecsSpaceID,hdfError)
    3518          65 :          CALL h5dcreate_f(cdncGroupID, "tecs", H5T_NATIVE_DOUBLE, tecsSpaceID, tecsSetID, hdfError)
    3519          65 :          CALL h5sclose_f(tecsSpaceID,hdfError)
    3520          65 :          CALL io_write_real2(tecsSetID,(/1,1/),dimsInt(:2),"tecs",tecs)
    3521          65 :          CALL h5dclose_f(tecsSetID, hdfError)
    3522             : 
    3523         195 :          dims(:2)=(/atoms%ntype,input%jspins/)
    3524         520 :          dimsInt = dims
    3525          65 :          CALL h5screate_simple_f(2,dims(:2),qintsSpaceID,hdfError)
    3526          65 :          CALL h5dcreate_f(cdncGroupID, "qints", H5T_NATIVE_DOUBLE, qintsSpaceID, qintsSetID, hdfError)
    3527          65 :          CALL h5sclose_f(qintsSpaceID,hdfError)
    3528          65 :          CALL io_write_real2(qintsSetID,(/1,1/),dimsInt(:2),"qints",qints)
    3529          65 :          CALL h5dclose_f(qintsSetID, hdfError)
    3530             : 
    3531          65 :          CALL h5gclose_f(cdncGroupID, hdfError)
    3532             :       END IF
    3533         336 :    END SUBROUTINE writeCoreDensityHDF
    3534             : 
    3535         948 :    SUBROUTINE readCoreDensityHDF(fileID,input,atoms,rhcs,tecs,qints)
    3536             :       use m_types_atoms
    3537             :       use m_types_input
    3538             : 
    3539             :       TYPE(t_atoms),    INTENT(IN) :: atoms
    3540             :       TYPE(t_input),    INTENT(IN) :: input
    3541             : 
    3542             : 
    3543             :       INTEGER(HID_T), INTENT(IN) :: fileID
    3544             :       REAL,    INTENT(OUT)       :: rhcs(atoms%jmtd,atoms%ntype,input%jspins)
    3545             :       REAL,    INTENT(OUT)       :: tecs(atoms%ntype,input%jspins)
    3546             :       REAL,    INTENT(OUT)       :: qints(atoms%ntype,input%jspins)
    3547             : 
    3548             :       INTEGER hdfError
    3549             :       INTEGER(HID_T) cdncGroupID, rhcsSetID, tecsSetID, qintsSetID
    3550             :       INTEGER jspdTemp, ntypeTemp, jmtdTemp
    3551             :       LOGICAL l_exist
    3552             :       INTEGER :: dimsInt(7)
    3553             : 
    3554          79 :       l_exist = io_groupexists(fileID,'/cdnc')
    3555          79 :       IF(.NOT.l_exist) THEN
    3556           0 :          CALL juDFT_error("no core density found",calledby ="readCoreDensityHDF")
    3557             :       END IF
    3558             : 
    3559          79 :       CALL h5gopen_f(fileID, '/cdnc', cdncGroupID, hdfError)
    3560             : 
    3561          79 :       CALL io_read_attint0(cdncGroupID,'jspd',jspdTemp)
    3562          79 :       CALL io_read_attint0(cdncGroupID,'ntype',ntypeTemp)
    3563          79 :       CALL io_read_attint0(cdncGroupID,'jmtd',jmtdTemp)
    3564             : 
    3565          79 :       IF(jspdTemp.NE.input%jspins) CALL juDFT_error("jspd is inconsistent",calledby ="readCoreDensityHDF")
    3566          79 :       IF(ntypeTemp.NE.atoms%ntype) CALL juDFT_error("ntype is inconsistent",calledby ="readCoreDensityHDF")
    3567          79 :       IF(jmtdTemp.NE.atoms%jmtd) CALL juDFT_error("jmtd is inconsistent",calledby ="readCoreDensityHDF")
    3568             : 
    3569         316 :       dimsInt(:3)=(/atoms%jmtd,atoms%ntype,input%jspins/)
    3570          79 :       CALL h5dopen_f(cdncGroupID, 'rhcs', rhcsSetID, hdfError)
    3571          79 :       CALL io_read_real3(rhcsSetID,(/1,1,1/),dimsInt(:3),"rhcs",rhcs)
    3572          79 :       CALL h5dclose_f(rhcsSetID, hdfError)
    3573             : 
    3574         237 :       dimsInt(:2)=(/atoms%ntype,input%jspins/)
    3575          79 :       CALL h5dopen_f(cdncGroupID, 'tecs', tecsSetID, hdfError)
    3576          79 :       CALL io_read_real2(tecsSetID,(/1,1/),dimsInt(:2),"tecs",tecs)
    3577          79 :       CALL h5dclose_f(tecsSetID, hdfError)
    3578             : 
    3579         237 :       dimsInt(:2)=(/atoms%ntype,input%jspins/)
    3580          79 :       CALL h5dopen_f(cdncGroupID, 'qints', qintsSetID, hdfError)
    3581          79 :       CALL io_read_real2(qintsSetID,(/1,1/),dimsInt(:2),"qints",qints)
    3582          79 :       CALL h5dclose_f(qintsSetID, hdfError)
    3583             : 
    3584          79 :       CALL h5gclose_f(cdncGroupID, hdfError)
    3585             : 
    3586          79 :    END SUBROUTINE readCoreDensityHDF
    3587             : 
    3588           0 :    LOGICAL FUNCTION deleteDensityEntryHDF(fileID,archiveName)
    3589             : 
    3590             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    3591             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    3592             : 
    3593             :       INTEGER                      :: hdfError
    3594             :       LOGICAL                      :: l_exist
    3595             : 
    3596           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    3597           0 :       IF(.NOT.l_exist) THEN
    3598           0 :          deleteDensityEntryHDF = .FALSE.
    3599             :          RETURN
    3600             :       END IF
    3601             : 
    3602           0 :       CALL h5ldelete_f(fileID, archiveName, hdfError)
    3603             : 
    3604           0 :       deleteDensityEntryHDF = .TRUE.
    3605             : 
    3606           0 :    END FUNCTION deleteDensityEntryHDF
    3607             : 
    3608           0 :    SUBROUTINE deleteObsoleteDensityMetadataHDF(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
    3609             :                                                currentStepfunctionIndex,lastDensityIndex)
    3610             : 
    3611             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    3612             :       INTEGER, INTENT(IN)          :: currentStarsIndex, currentLatharmsIndex
    3613             :       INTEGER, INTENT(IN)          :: currentStructureIndex, currentStepfunctionIndex
    3614             :       INTEGER, INTENT(IN)          :: lastDensityIndex
    3615             : 
    3616             :       INTEGER                      :: iDen
    3617             :       INTEGER                      :: starsIndex, latharmsIndex
    3618             :       INTEGER                      :: structureIndex, stepfunctionIndex
    3619             :       INTEGER                      :: hdfError
    3620             :       LOGICAL                      :: l_exist
    3621             :       CHARACTER(LEN=30)            :: archiveName, groupname
    3622             : 
    3623           0 :       LOGICAL                      :: neededStars(currentStarsIndex)
    3624           0 :       LOGICAL                      :: neededLatharms(currentLatharmsIndex)
    3625           0 :       LOGICAL                      :: neededStructures(currentStructureIndex)
    3626           0 :       LOGICAL                      :: neededStepfunctions(currentStepfunctionIndex)
    3627             : 
    3628           0 :       neededStars(:) = .FALSE.
    3629           0 :       neededLatharms(:) = .FALSE.
    3630           0 :       neededStructures(:) = .FALSE.
    3631           0 :       neededStepfunctions(:) = .FALSE.
    3632             : 
    3633           0 :       DO iDen = 1, lastDensityIndex
    3634           0 :          archiveName = ''
    3635           0 :          WRITE(archiveName,'(a,i0)') '/cdn-', iDen
    3636             : 
    3637           0 :          l_exist = isDensityEntryPresentHDF(fileID,archiveName,DENSITY_TYPE_UNDEFINED_const)
    3638           0 :          IF(.NOT.l_exist) THEN
    3639             :             CYCLE
    3640             :          END IF
    3641             : 
    3642             :          CALL peekDensityEntryHDF(fileID, archiveName, DENSITY_TYPE_UNDEFINED_const,&
    3643             :                                   starsIndex=starsIndex, latharmsIndex=latharmsIndex, &
    3644           0 :                                   structureIndex=structureIndex,stepfunctionIndex=stepfunctionIndex)
    3645           0 :          neededStars(starsIndex) = .TRUE.
    3646           0 :          neededLatharms(latharmsIndex) = .TRUE.
    3647           0 :          neededStructures(structureIndex) = .TRUE.
    3648           0 :          neededStepfunctions(stepfunctionIndex) = .TRUE.
    3649             :       END DO
    3650             : 
    3651           0 :       DO starsIndex = 1, currentStarsIndex
    3652           0 :          IF (neededStars(starsIndex)) CYCLE
    3653           0 :          groupname = ''
    3654           0 :          WRITE(groupname,'(a,i0)') '/stars-', starsIndex
    3655           0 :          l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3656           0 :          IF (l_exist) THEN
    3657           0 :             CALL h5ldelete_f(fileID, groupname, hdfError)
    3658             :          END IF
    3659             :       END DO
    3660             : 
    3661           0 :       DO latharmsIndex = 1, currentLatharmsIndex
    3662           0 :          IF (neededLatharms(latharmsIndex)) CYCLE
    3663           0 :          groupname = ''
    3664           0 :          WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex
    3665           0 :          l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3666           0 :          IF (l_exist) THEN
    3667           0 :             CALL h5ldelete_f(fileID, groupname, hdfError)
    3668             :          END IF
    3669             :       END DO
    3670             : 
    3671           0 :       DO structureIndex = 1, currentStructureIndex
    3672           0 :          IF (neededStructures(structureIndex)) CYCLE
    3673           0 :          groupname = ''
    3674           0 :          WRITE(groupname,'(a,i0)') '/structure-', structureIndex
    3675           0 :          l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3676           0 :          IF (l_exist) THEN
    3677           0 :             CALL h5ldelete_f(fileID, groupname, hdfError)
    3678             :          END IF
    3679             :       END DO
    3680             : 
    3681           0 :       DO stepfunctionIndex = 1, currentStepfunctionIndex
    3682           0 :          IF (neededStepfunctions(stepfunctionIndex)) CYCLE
    3683           0 :          groupname = ''
    3684           0 :          WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex
    3685           0 :          l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3686           0 :          IF (l_exist) THEN
    3687           0 :             CALL h5ldelete_f(fileID, groupname, hdfError)
    3688             :          END IF
    3689             :       END DO
    3690             : 
    3691           0 :    END SUBROUTINE deleteObsoleteDensityMetadataHDF
    3692             : 
    3693         158 :    LOGICAL FUNCTION isCoreDensityPresentHDF()
    3694             : 
    3695             :       INTEGER(HID_T) :: fileID
    3696             :       INTEGER        :: currentStarsIndex,currentLatharmsIndex
    3697             :       INTEGER        :: currentStructureIndex, currentStepfunctionIndex
    3698             :       INTEGER        :: readDensityIndex, lastDensityIndex
    3699             :       LOGICAL        :: l_exist
    3700             : 
    3701          79 :       INQUIRE(FILE='cdn.hdf',EXIST=l_exist)
    3702          79 :       IF(.NOT.l_exist) THEN
    3703          79 :          isCoreDensityPresentHDF = .FALSE.
    3704             :          RETURN
    3705             :       END IF
    3706             :       CALL openCDN_HDF(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
    3707          79 :                        currentStepfunctionIndex,readDensityIndex,lastDensityIndex)
    3708          79 :       isCoreDensityPresentHDF = io_groupexists(fileID,'/cdnc')
    3709          79 :       CALL closeCDNPOT_HDF(fileID)
    3710          79 :    END FUNCTION
    3711             : 
    3712         159 :    LOGICAL FUNCTION isDensityEntryPresentHDF(fileID,archiveName,densityType)
    3713             : 
    3714             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    3715             :       INTEGER , INTENT(IN)         :: densityType
    3716             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    3717             : 
    3718             :       INTEGER                      :: localDensityType
    3719             :       CHARACTER(LEN=30)            :: groupName, densityTypeName
    3720             :       LOGICAL                      :: l_exist
    3721             : 
    3722         159 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    3723         159 :       IF(.NOT.l_exist) THEN
    3724         159 :          isDensityEntryPresentHDF = .FALSE.
    3725             :          RETURN
    3726             :       END IF
    3727             : 
    3728         158 :       localDensityType = densityType
    3729           9 :       SELECT CASE (densityType)
    3730             :          CASE(DENSITY_TYPE_FFN_IN_const)
    3731           9 :             densityTypeName = '/ffn_in'
    3732           9 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3733           9 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3734           9 :             IF(.NOT.l_exist) THEN
    3735           6 :                localDensityType = DENSITY_TYPE_NOCO_IN_const
    3736           6 :                densityTypeName = '/noco_in'
    3737             :             END IF
    3738           9 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3739           9 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3740           9 :             IF(.NOT.l_exist) THEN
    3741           6 :                localDensityType = DENSITY_TYPE_IN_const
    3742           6 :                densityTypeName = '/in'
    3743             :             END IF
    3744             :          CASE(DENSITY_TYPE_FFN_OUT_const)
    3745           0 :             densityTypeName = '/ffn_out'
    3746           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3747           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3748           0 :             IF(.NOT.l_exist) THEN
    3749           0 :                localDensityType = DENSITY_TYPE_NOCO_OUT_const
    3750           0 :                densityTypeName = '/noco_out'
    3751             :             END IF
    3752           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3753           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3754           0 :             IF(.NOT.l_exist) THEN
    3755           0 :                localDensityType = DENSITY_TYPE_OUT_const
    3756           0 :                densityTypeName = '/out'
    3757             :             END IF
    3758             :          CASE(DENSITY_TYPE_UNDEFINED_const)
    3759          78 :             densityTypeName = ''
    3760             :          CASE(DENSITY_TYPE_IN_const)
    3761          54 :             densityTypeName = '/in'
    3762             :          CASE(DENSITY_TYPE_OUT_const)
    3763           0 :             densityTypeName = '/out'
    3764             :          CASE(DENSITY_TYPE_NOCO_IN_const)
    3765          17 :             densityTypeName = '/noco_in'
    3766          17 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3767          17 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3768          17 :             IF(.NOT.l_exist) THEN
    3769          17 :                localDensityType = DENSITY_TYPE_IN_const
    3770          17 :                densityTypeName = '/in'
    3771             :             END IF
    3772             :          CASE(DENSITY_TYPE_NOCO_OUT_const)
    3773           0 :             densityTypeName = '/noco_out'
    3774           0 :             groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3775           0 :             l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3776           0 :             IF(.NOT.l_exist) THEN
    3777           0 :                localDensityType = DENSITY_TYPE_OUT_const
    3778           0 :                densityTypeName = '/out'
    3779             :             END IF
    3780             :          CASE(DENSITY_TYPE_PRECOND_const)
    3781           0 :             densityTypeName = '/precond'
    3782             :          CASE DEFAULT
    3783         158 :             CALL juDFT_error("Unknown density type selected",calledby ="isDensityEntryPresentHDF")
    3784             :       END SELECT
    3785             : 
    3786         158 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(densityTypeName))
    3787         158 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3788             : 
    3789         158 :       isDensityEntryPresentHDF = l_exist
    3790         159 :    END FUNCTION
    3791             : 
    3792           0 :    LOGICAL FUNCTION isPotentialEntryPresentHDF(fileID,archiveName,potentialType)
    3793             : 
    3794             :       INTEGER(HID_T), INTENT(IN)   :: fileID
    3795             :       INTEGER , INTENT(IN)         :: potentialType
    3796             :       CHARACTER(LEN=*), INTENT(IN) :: archiveName
    3797             : 
    3798             :       CHARACTER(LEN=30)            :: groupName, potentialTypeName
    3799             :       LOGICAL                      :: l_exist
    3800             : 
    3801           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(archiveName)))
    3802           0 :       IF(.NOT.l_exist) THEN
    3803           0 :          isPotentialEntryPresentHDF = .FALSE.
    3804             :          RETURN
    3805             :       END IF
    3806             : 
    3807           0 :       SELECT CASE (potentialType)
    3808             :          CASE(POTENTIAL_TYPE_IN_const)
    3809           0 :             potentialTypeName = '/in'
    3810             :          CASE(POTENTIAL_TYPE_OUT_const)
    3811           0 :             potentialTypeName = '/out'
    3812             :          CASE DEFAULT
    3813           0 :             CALL juDFT_error("Unknown potential type selected",calledby ="isPotentialEntryPresentHDF")
    3814             :       END SELECT
    3815             : 
    3816           0 :       groupName = TRIM(ADJUSTL(archiveName))//TRIM(ADJUSTL(potentialTypeName))
    3817           0 :       l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))
    3818             : 
    3819           0 :       isPotentialEntryPresentHDF = l_exist
    3820           0 :    END FUNCTION
    3821             : 
    3822             : #endif
    3823             : 
    3824             : END MODULE m_cdnpot_io_hdf

Generated by: LCOV version 1.14