cdnpot_io_hdf.F90 130 KB
Newer Older
1 2 3 4 5 6 7 8
!--------------------------------------------------------------------------------
! Copyright (c) 2017 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

MODULE m_cdnpot_io_hdf

9
   USE m_constants
10 11 12 13 14 15 16 17 18 19
   USE m_types
   USE m_juDFT
#ifdef CPP_HDF
   USE hdf5
   USE m_hdf_tools
#endif
   IMPLICIT NONE

   PRIVATE
#ifdef CPP_HDF
20
   PUBLIC openCDN_HDF, openPOT_HDF, closeCDNPOT_HDF
21 22
   PUBLIC writeStarsHDF, readStarsHDF, peekStarsHDF
   PUBLIC writeLatharmsHDF, readLatharmsHDF, peekLatharmsHDF
23
   PUBLIC writeStructureHDF, readStructureHDF
24
   PUBLIC writeStepfunctionHDF, readStepfunctionHDF, peekStepfunctionHDF
25
   PUBLIC writeDensityHDF, readDensityHDF
26
   PUBLIC writePotentialHDF, readPotentialHDF
27
   PUBLIC writeCoreDensityHDF, readCoreDensityHDF
28
   PUBLIC writeCDNHeaderData, writePOTHeaderData
29
   PUBLIC isCoreDensityPresentHDF, deleteDensityEntryHDF
30
   PUBLIC isDensityEntryPresentHDF, isPotentialEntryPresentHDF
31
   PUBLIC peekDensityEntryHDF
32 33
#endif

34
   PUBLIC DENSITY_TYPE_UNDEFINED_const
35 36 37
   PUBLIC DENSITY_TYPE_IN_const, DENSITY_TYPE_OUT_const
   PUBLIC DENSITY_TYPE_NOCO_IN_const, DENSITY_TYPE_NOCO_OUT_const
   PUBLIC DENSITY_TYPE_PRECOND_const
38
   PUBLIC POTENTIAL_TYPE_IN_const, POTENTIAL_TYPE_OUT_const
39

40
   INTEGER,          PARAMETER :: DENSITY_TYPE_UNDEFINED_const = 0
41 42 43 44 45 46
   INTEGER,          PARAMETER :: DENSITY_TYPE_IN_const = 1
   INTEGER,          PARAMETER :: DENSITY_TYPE_OUT_const = 2
   INTEGER,          PARAMETER :: DENSITY_TYPE_NOCO_IN_const = 3
   INTEGER,          PARAMETER :: DENSITY_TYPE_NOCO_OUT_const = 4
   INTEGER,          PARAMETER :: DENSITY_TYPE_PRECOND_const = 5

47 48 49
   INTEGER,          PARAMETER :: POTENTIAL_TYPE_IN_const = 1
   INTEGER,          PARAMETER :: POTENTIAL_TYPE_OUT_const = 2

50
   INTEGER,          PARAMETER :: FILE_FORMAT_VERSION_const = 29
51

52 53 54 55
   CONTAINS

#ifdef CPP_HDF

56
   SUBROUTINE openCDN_HDF(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
57
                          currentStepfunctionIndex,readDensityIndex,lastDensityIndex,inFilename)
58 59

      INTEGER(HID_T), INTENT(OUT) :: fileID
60
      INTEGER, INTENT(OUT) :: currentStarsIndex,currentLatharmsIndex,currentStructureIndex
61
      INTEGER, INTENT(OUT) :: currentStepfunctionIndex, readDensityIndex,lastDensityIndex
62

63 64
      CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: inFilename

65
      INTEGER(HID_T) :: generalGroupID
66
      INTEGER        :: hdfError, fileFormatVersion
67
      LOGICAL        :: l_exist
68
      CHARACTER(LEN=30) :: filename
69 70 71 72

      currentStarsIndex = 0
      currentLatharmsIndex = 0
      currentStructureIndex = 0
73
      currentStepfunctionIndex = 0
74 75
      readDensityIndex = 0
      lastDensityIndex = 0
76
      fileFormatVersion = 0
77

78 79 80 81
      filename = 'cdn.hdf'
      IF(PRESENT(inFilename)) filename = TRIM(ADJUSTL(inFilename))//'.hdf'

      INQUIRE(FILE=TRIM(ADJUSTL(filename)),EXIST=l_exist)
82
      IF(l_exist) THEN ! only open file
83
         CALL h5fopen_f(TRIM(ADJUSTL(filename)), H5F_ACC_RDWR_F, fileID, hdfError, H5P_DEFAULT_F)
84 85 86 87 88 89

         CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
         ! read in primary attributes from the header '/general'
         CALL io_read_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
         CALL io_read_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
         CALL io_read_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
90
         CALL io_read_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
91 92
         CALL io_read_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
         CALL io_read_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
93
         CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
94 95

         CALL h5gclose_f(generalGroupID, hdfError)
96
         IF(fileFormatVersion.GT.FILE_FORMAT_VERSION_const) THEN
97 98
            WRITE(*,'(a,i4)') TRIM(ADJUSTL(filename))//' has file format version ', fileFormatVersion
            CALL juDFT_error(TRIM(ADJUSTL(filename))//' file format not readable.' ,calledby ="openCDN_HDF")
99
         END IF
100
      ELSE ! create file
101
         CALL h5fcreate_f(TRIM(ADJUSTL(filename)), H5F_ACC_TRUNC_F, fileID, hdfError, H5P_DEFAULT_F, H5P_DEFAULT_F)
102 103 104 105 106 107

         CALL h5gcreate_f(fileID, '/general', generalGroupID, hdfError)
         ! write initial values to primary attributes in the header '/general'
         CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
         CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
         CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
108
         CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
109 110
         CALL io_write_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
         CALL io_write_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
111
         CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
112 113 114 115 116 117

         CALL h5gclose_f(generalGroupID, hdfError)
      END IF

   END SUBROUTINE openCDN_HDF

118

119 120
   SUBROUTINE openPOT_HDF(fileID,currentStarsIndex,currentLatharmsIndex,&
                          currentStructureIndex,currentStepfunctionIndex)
121 122

      INTEGER(HID_T), INTENT(OUT) :: fileID
123 124
      INTEGER, INTENT(OUT) :: currentStarsIndex,currentLatharmsIndex
      INTEGER, INTENT(OUT) :: currentStructureIndex, currentStepfunctionIndex
125 126

      INTEGER(HID_T) :: generalGroupID
127
      INTEGER        :: hdfError, fileFormatVersion
128 129 130 131 132
      LOGICAL        :: l_exist

      currentStarsIndex = 0
      currentLatharmsIndex = 0
      currentStructureIndex = 0
133
      currentStepfunctionIndex = 0
134
      fileFormatVersion = 0
135 136 137 138 139 140 141 142 143 144

      INQUIRE(FILE='pot.hdf',EXIST=l_exist)
      IF(l_exist) THEN ! only open file
         CALL h5fopen_f('pot.hdf', H5F_ACC_RDWR_F, fileID, hdfError, H5P_DEFAULT_F)

         CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
         ! read in primary attributes from the header '/general'
         CALL io_read_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
         CALL io_read_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
         CALL io_read_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
145
         CALL io_read_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
146
         CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
147 148

         CALL h5gclose_f(generalGroupID, hdfError)
149 150 151 152
         IF(fileFormatVersion.NE.FILE_FORMAT_VERSION_const) THEN
            WRITE(*,'(a,i4)') 'pot.hdf has file format version ', fileFormatVersion
            CALL juDFT_error('pot.hdf file format not readable.' ,calledby ="openPOT_HDF")
         END IF
153 154 155 156 157 158 159 160
      ELSE ! create file
         CALL h5fcreate_f('pot.hdf', H5F_ACC_TRUNC_F, fileID, hdfError, H5P_DEFAULT_F, H5P_DEFAULT_F)

         CALL h5gcreate_f(fileID, '/general', generalGroupID, hdfError)
         ! write initial values to primary attributes in the header '/general'
         CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
         CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
         CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
161
         CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
162
         CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
163 164 165 166 167 168 169

         CALL h5gclose_f(generalGroupID, hdfError)
      END IF

   END SUBROUTINE openPOT_HDF

   SUBROUTINE closeCDNPOT_HDF(fileID)
170 171 172 173 174 175 176

      INTEGER(HID_T), INTENT(IN) :: fileID

      INTEGER hdfError

      CALL h5fclose_f(fileID, hdfError)

177
   END SUBROUTINE closeCDNPOT_HDF
178

179
   SUBROUTINE writeCDNHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
180
                                 currentStepfunctionIndex,readDensityIndex,lastDensityIndex)
181 182 183 184 185

      INTEGER(HID_T), INTENT(IN) :: fileID
      INTEGER, INTENT(IN)        :: currentStarsIndex
      INTEGER, INTENT(IN)        :: currentLatharmsIndex
      INTEGER, INTENT(IN)        :: currentStructureIndex
186
      INTEGER, INTENT(IN)        :: currentStepfunctionIndex
187 188
      INTEGER, INTENT(IN)        :: readDensityIndex
      INTEGER, INTENT(IN)        :: lastDensityIndex
189 190 191 192 193 194 195 196 197

      INTEGER(HID_T) :: generalGroupID
      INTEGER        :: hdfError

      CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)

      CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
      CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
      CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
198
      CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
199 200
      CALL io_write_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
      CALL io_write_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
201
      CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
202 203 204

      CALL h5gclose_f(generalGroupID, hdfError)

205 206
   END SUBROUTINE writeCDNHeaderData

207 208
   SUBROUTINE writePOTHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,&
                                 currentStructureIndex,currentStepfunctionIndex)
209 210 211 212 213

      INTEGER(HID_T), INTENT(IN) :: fileID
      INTEGER, INTENT(IN)        :: currentStarsIndex
      INTEGER, INTENT(IN)        :: currentLatharmsIndex
      INTEGER, INTENT(IN)        :: currentStructureIndex
214
      INTEGER, INTENT(IN)        :: currentStepfunctionIndex
215 216 217 218 219 220 221 222 223

      INTEGER(HID_T) :: generalGroupID
      INTEGER        :: hdfError

      CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)

      CALL io_write_attint0(generalGroupID,'currentStarsIndex',currentStarsIndex)
      CALL io_write_attint0(generalGroupID,'currentLatharmsIndex',currentLatharmsIndex)
      CALL io_write_attint0(generalGroupID,'currentStructureIndex',currentStructureIndex)
224
      CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
225
      CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
226 227 228 229

      CALL h5gclose_f(generalGroupID, hdfError)

   END SUBROUTINE writePOTHeaderData
230

231
   SUBROUTINE writeStarsHDF(fileID, starsIndex, structureIndex, stars, l_checkBroyd)
232 233

      INTEGER(HID_T), INTENT(IN) :: fileID
234
      INTEGER,        INTENT(IN) :: starsIndex, structureIndex
235
      TYPE(t_stars),  INTENT(IN) :: stars
236
      LOGICAL,        INTENT(IN) :: l_CheckBroyd
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

      INTEGER(HID_T)            :: groupID
      INTEGER                   :: hdfError, ft2_gf_dim, dimsInt(7)
      CHARACTER(LEN=30)         :: groupName
      INTEGER(HSIZE_T)          :: dims(7)
      LOGICAL        :: l_exist

      INTEGER(HID_T)                   :: kv3SpaceID, kv3SetID
      INTEGER(HID_T)                   :: kv2SpaceID, kv2SetID
      INTEGER(HID_T)                   :: sk3SpaceID, sk3SetID
      INTEGER(HID_T)                   :: sk2SpaceID, sk2SetID
      INTEGER(HID_T)                   :: igSpaceID, igSetID
      INTEGER(HID_T)                   :: ig2SpaceID, ig2SetID
      INTEGER(HID_T)                   :: nstrSpaceID, nstrSetID
      INTEGER(HID_T)                   :: nstr2SpaceID, nstr2SetID
      INTEGER(HID_T)                   :: phi2SpaceID, phi2SetID
      INTEGER(HID_T)                   :: rgphsSpaceID, rgphsSetID
      INTEGER(HID_T)                   :: igfftSpaceID, igfftSetID
      INTEGER(HID_T)                   :: igfft2SpaceID, igfft2SetID
      INTEGER(HID_T)                   :: pgfftSpaceID, pgfftSetID
      INTEGER(HID_T)                   :: pgfft2SpaceID, pgfft2SetID
      INTEGER(HID_T)                   :: ft2_gfxSpaceID, ft2_gfxSetID
      INTEGER(HID_T)                   :: ft2_gfySpaceID, ft2_gfySetID

      WRITE(groupname,'(a,i0)') '/stars-', starsIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (l_exist) THEN
         CALL juDFT_error('stars entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeStarsHDF")
      END IF

269 270
      INQUIRE(FILE='broyd',EXIST=l_exist)
      IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
271
      IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Stars change but broyden files detected!')
272

273 274 275 276
      CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      ft2_gf_dim = SIZE(stars%ft2_gfx,1)

277 278
      CALL io_write_attint0(groupID,'structureIndex',structureIndex)

279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
      CALL io_write_attreal0(groupID,'gmax',stars%gmax)
      CALL io_write_attreal0(groupID,'gmaxInit',stars%gmaxInit)
      CALL io_write_attint0(groupID,'ng3',stars%ng3)
      CALL io_write_attint0(groupID,'ng2',stars%ng2)
      CALL io_write_attint0(groupID,'mx1',stars%mx1)
      CALL io_write_attint0(groupID,'mx2',stars%mx2)
      CALL io_write_attint0(groupID,'mx3',stars%mx3)
      CALL io_write_attint0(groupID,'kimax',stars%kimax)
      CALL io_write_attint0(groupID,'kimax2',stars%kimax2)
      CALL io_write_attint0(groupID,'kq1_fft',stars%kq1_fft)
      CALL io_write_attint0(groupID,'kq2_fft',stars%kq2_fft)
      CALL io_write_attint0(groupID,'kq3_fft',stars%kq3_fft)
      CALL io_write_attint0(groupID,'kmxq_fft',stars%kmxq_fft)
      CALL io_write_attint0(groupID,'kxc1_fft',stars%kxc1_fft)
      CALL io_write_attint0(groupID,'kxc2_fft',stars%kxc2_fft)
      CALL io_write_attint0(groupID,'kxc3_fft',stars%kxc3_fft)
      CALL io_write_attint0(groupID,'ng3_fft',stars%ng3_fft)
      CALL io_write_attint0(groupID,'kmxxc_fft',stars%kmxxc_fft)
      CALL io_write_attint0(groupID,'nxc3_fft',stars%nxc3_fft)
      CALL io_write_attint0(groupID,'ft2_gf_dim',ft2_gf_dim)

      dims(:2)=(/3,stars%ng3/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),kv3SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "kv3", H5T_NATIVE_INTEGER, kv3SpaceID, kv3SetID, hdfError)
      CALL h5sclose_f(kv3SpaceID,hdfError)
      CALL io_write_integer2(kv3SetID,(/1,1/),dimsInt(:2),stars%kv3)
      CALL h5dclose_f(kv3SetID, hdfError)

      dims(:2)=(/2,stars%ng2/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),kv2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "kv2", H5T_NATIVE_INTEGER, kv2SpaceID, kv2SetID, hdfError)
      CALL h5sclose_f(kv2SpaceID,hdfError)
      CALL io_write_integer2(kv2SetID,(/1,1/),dimsInt(:2),stars%kv2)
      CALL h5dclose_f(kv2SetID, hdfError)

      dims(:1)=(/stars%ng3/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),sk3SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "sk3", H5T_NATIVE_DOUBLE, sk3SpaceID, sk3SetID, hdfError)
      CALL h5sclose_f(sk3SpaceID,hdfError)
      CALL io_write_real1(sk3SetID,(/1/),dimsInt(:1),stars%sk3)
      CALL h5dclose_f(sk3SetID, hdfError)

      dims(:1)=(/stars%ng2/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),sk2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "sk2", H5T_NATIVE_DOUBLE, sk2SpaceID, sk2SetID, hdfError)
      CALL h5sclose_f(sk2SpaceID,hdfError)
      CALL io_write_real1(sk2SetID,(/1/),dimsInt(:1),stars%sk2)
      CALL h5dclose_f(sk2SetID, hdfError)

      dims(:3)=(/2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
      dimsInt=dims
      CALL h5screate_simple_f(3,dims(:3),igSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ig", H5T_NATIVE_INTEGER, igSpaceID, igSetID, hdfError)
      CALL h5sclose_f(igSpaceID,hdfError)
      CALL io_write_integer3(igSetID,(/1,1,1/),dimsInt(:3),stars%ig)
      CALL h5dclose_f(igSetID, hdfError)

      dims(:1)=(/stars%ng3/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),ig2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ig2", H5T_NATIVE_INTEGER, ig2SpaceID, ig2SetID, hdfError)
      CALL h5sclose_f(ig2SpaceID,hdfError)
      CALL io_write_integer1(ig2SetID,(/1/),dimsInt(:1),stars%ig2)
      CALL h5dclose_f(ig2SetID, hdfError)

      dims(:1)=(/stars%ng3/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),nstrSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "nstr", H5T_NATIVE_INTEGER, nstrSpaceID, nstrSetID, hdfError)
      CALL h5sclose_f(nstrSpaceID,hdfError)
      CALL io_write_integer1(nstrSetID,(/1/),dimsInt(:1),stars%nstr)
      CALL h5dclose_f(nstrSetID, hdfError)

      dims(:1)=(/stars%ng2/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),nstr2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "nstr2", H5T_NATIVE_INTEGER, nstr2SpaceID, nstr2SetID, hdfError)
      CALL h5sclose_f(nstr2SpaceID,hdfError)
      CALL io_write_integer1(nstr2SetID,(/1/),dimsInt(:1),stars%nstr2)
      CALL h5dclose_f(nstr2SetID, hdfError)

      dims(:1)=(/stars%ng2/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),phi2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "phi2", H5T_NATIVE_DOUBLE, phi2SpaceID, phi2SetID, hdfError)
      CALL h5sclose_f(phi2SpaceID,hdfError)
      CALL io_write_real1(phi2SetID,(/1/),dimsInt(:1),stars%phi2)
      CALL h5dclose_f(phi2SetID, hdfError)

      dims(:4)=(/2,2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
      dimsInt=dims
      CALL h5screate_simple_f(4,dims(:4),rgphsSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "rgphs", H5T_NATIVE_DOUBLE, rgphsSpaceID, rgphsSetID, hdfError)
      CALL h5sclose_f(rgphsSpaceID,hdfError)
      CALL io_write_complex3(rgphsSetID,(/-1,1,1,1/),dimsInt(:4),stars%rgphs)
      CALL h5dclose_f(rgphsSetID, hdfError)

      dims(:2)=(/stars%kimax+1,2/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),igfftSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "igfft", H5T_NATIVE_INTEGER, igfftSpaceID, igfftSetID, hdfError)
      CALL h5sclose_f(igfftSpaceID,hdfError)
      CALL io_write_integer2(igfftSetID,(/1,1/),dimsInt(:2),stars%igfft(0:stars%kimax,:))
      CALL h5dclose_f(igfftSetID, hdfError)

      dims(:2)=(/stars%kimax2+1,2/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),igfft2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "igfft2", H5T_NATIVE_INTEGER, igfft2SpaceID, igfft2SetID, hdfError)
      CALL h5sclose_f(igfft2SpaceID,hdfError)
      CALL io_write_integer2(igfft2SetID,(/1,1/),dimsInt(:2),stars%igfft2(0:stars%kimax2,:))
      CALL h5dclose_f(igfft2SetID, hdfError)

      dims(:2)=(/2,stars%kimax+1/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),pgfftSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "pgfft", H5T_NATIVE_DOUBLE, pgfftSpaceID, pgfftSetID, hdfError)
      CALL h5sclose_f(pgfftSpaceID,hdfError)
      CALL io_write_complex1(pgfftSetID,(/-1,1/),dimsInt(:2),stars%pgfft(0:stars%kimax))
      CALL h5dclose_f(pgfftSetID, hdfError)

      dims(:2)=(/2,stars%kimax2+1/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),pgfft2SpaceID,hdfError)
      CALL h5dcreate_f(groupID, "pgfft2", H5T_NATIVE_DOUBLE, pgfft2SpaceID, pgfft2SetID, hdfError)
      CALL h5sclose_f(pgfft2SpaceID,hdfError)
      CALL io_write_complex1(pgfft2SetID,(/-1,1/),dimsInt(:2),stars%pgfft2(0:stars%kimax2))
      CALL h5dclose_f(pgfft2SetID, hdfError)

      dims(:1)=(/ft2_gf_dim/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),ft2_gfxSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ft2_gfx", H5T_NATIVE_DOUBLE, ft2_gfxSpaceID, ft2_gfxSetID, hdfError)
      CALL h5sclose_f(ft2_gfxSpaceID,hdfError)
      CALL io_write_real1(ft2_gfxSetID,(/1/),dimsInt(:1),stars%ft2_gfx)
      CALL h5dclose_f(ft2_gfxSetID, hdfError)

      dims(:1)=(/ft2_gf_dim/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),ft2_gfySpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ft2_gfy", H5T_NATIVE_DOUBLE, ft2_gfySpaceID, ft2_gfySetID, hdfError)
      CALL h5sclose_f(ft2_gfySpaceID,hdfError)
      CALL io_write_real1(ft2_gfySetID,(/1/),dimsInt(:1),stars%ft2_gfy)
      CALL h5dclose_f(ft2_gfySetID, hdfError)

      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE writeStarsHDF

   SUBROUTINE readStarsHDF(fileID, starsIndex, stars)

434 435 436
      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: starsIndex
      TYPE(t_stars),  INTENT(INOUT) :: stars
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587

      INTEGER(HID_T)            :: groupID
      INTEGER                   :: hdfError, ft2_gf_dim
      INTEGER                   :: dimsInt(7)
      CHARACTER(LEN=30)         :: groupName
      LOGICAL                   :: l_exist

      INTEGER(HID_T)                   :: kv3SetID
      INTEGER(HID_T)                   :: kv2SetID
      INTEGER(HID_T)                   :: sk3SetID
      INTEGER(HID_T)                   :: sk2SetID
      INTEGER(HID_T)                   :: igSetID
      INTEGER(HID_T)                   :: ig2SetID
      INTEGER(HID_T)                   :: nstrSetID
      INTEGER(HID_T)                   :: nstr2SetID
      INTEGER(HID_T)                   :: phi2SetID
      INTEGER(HID_T)                   :: rgphsSetID
      INTEGER(HID_T)                   :: igfftSetID
      INTEGER(HID_T)                   :: igfft2SetID
      INTEGER(HID_T)                   :: pgfftSetID
      INTEGER(HID_T)                   :: pgfft2SetID
      INTEGER(HID_T)                   :: ft2_gfxSetID
      INTEGER(HID_T)                   :: ft2_gfySetID

      WRITE(groupname,'(a,i0)') '/stars-', starsIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('stars entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStarsHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      CALL io_read_attreal0(groupID,'gmax',stars%gmax)
      CALL io_read_attreal0(groupID,'gmaxInit',stars%gmaxInit)
      CALL io_read_attint0(groupID,'ng3',stars%ng3)
      CALL io_read_attint0(groupID,'ng2',stars%ng2)
      CALL io_read_attint0(groupID,'mx1',stars%mx1)
      CALL io_read_attint0(groupID,'mx2',stars%mx2)
      CALL io_read_attint0(groupID,'mx3',stars%mx3)
      CALL io_read_attint0(groupID,'kimax',stars%kimax)
      CALL io_read_attint0(groupID,'kimax2',stars%kimax2)
      CALL io_read_attint0(groupID,'kq1_fft',stars%kq1_fft)
      CALL io_read_attint0(groupID,'kq2_fft',stars%kq2_fft)
      CALL io_read_attint0(groupID,'kq3_fft',stars%kq3_fft)
      CALL io_read_attint0(groupID,'kmxq_fft',stars%kmxq_fft)
      CALL io_read_attint0(groupID,'kxc1_fft',stars%kxc1_fft)
      CALL io_read_attint0(groupID,'kxc2_fft',stars%kxc2_fft)
      CALL io_read_attint0(groupID,'kxc3_fft',stars%kxc3_fft)
      CALL io_read_attint0(groupID,'ng3_fft',stars%ng3_fft)
      CALL io_read_attint0(groupID,'kmxxc_fft',stars%kmxxc_fft)
      CALL io_read_attint0(groupID,'nxc3_fft',stars%nxc3_fft)
      CALL io_read_attint0(groupID,'ft2_gf_dim',ft2_gf_dim)

      IF(ALLOCATED(stars%kv3)) DEALLOCATE(stars%kv3)
      IF(ALLOCATED(stars%kv2)) DEALLOCATE(stars%kv2)
      IF(ALLOCATED(stars%sk3)) DEALLOCATE(stars%sk3)
      IF(ALLOCATED(stars%sk2)) DEALLOCATE(stars%sk2)
      IF(ALLOCATED(stars%ig)) DEALLOCATE(stars%ig)
      IF(ALLOCATED(stars%ig2)) DEALLOCATE(stars%ig2)
      IF(ALLOCATED(stars%nstr)) DEALLOCATE(stars%nstr)
      IF(ALLOCATED(stars%nstr2)) DEALLOCATE(stars%nstr2)
      IF(ALLOCATED(stars%phi2)) DEALLOCATE(stars%phi2)
      IF(ALLOCATED(stars%rgphs)) DEALLOCATE(stars%rgphs)
      IF(ALLOCATED(stars%igfft)) DEALLOCATE(stars%igfft)
      IF(ALLOCATED(stars%igfft2)) DEALLOCATE(stars%igfft2)
      IF(ALLOCATED(stars%pgfft)) DEALLOCATE(stars%pgfft)
      IF(ALLOCATED(stars%pgfft2)) DEALLOCATE(stars%pgfft2)
      IF(ALLOCATED(stars%ft2_gfx)) DEALLOCATE(stars%ft2_gfx)
      IF(ALLOCATED(stars%ft2_gfy)) DEALLOCATE(stars%ft2_gfy)

      ALLOCATE(stars%kv3(3,stars%ng3))
      ALLOCATE(stars%kv2(2,stars%ng2))
      ALLOCATE(stars%sk3(stars%ng3))
      ALLOCATE(stars%sk2(stars%ng2))
      ALLOCATE(stars%ig(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
      ALLOCATE(stars%ig2(stars%ng3))
      ALLOCATE(stars%nstr(stars%ng3))
      ALLOCATE(stars%nstr2(stars%ng2))
      ALLOCATE(stars%phi2(stars%ng2))
      ALLOCATE(stars%rgphs(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
      ALLOCATE(stars%igfft(0:stars%kimax,2))
      ALLOCATE(stars%igfft2(0:stars%kimax2,2))
      ALLOCATE(stars%pgfft(0:stars%kimax))
      ALLOCATE(stars%pgfft2(0:stars%kimax2))
      ALLOCATE(stars%ft2_gfx(0:ft2_gf_dim-1))
      ALLOCATE(stars%ft2_gfy(0:ft2_gf_dim-1))

      dimsInt(:2)=(/3,stars%ng3/)
      CALL h5dopen_f(groupID, 'kv3', kv3SetID, hdfError)
      CALL io_read_integer2(kv3SetID,(/1,1/),dimsInt(:2),stars%kv3)
      CALL h5dclose_f(kv3SetID, hdfError)

      dimsInt(:2)=(/2,stars%ng2/)
      CALL h5dopen_f(groupID, 'kv2', kv2SetID, hdfError)
      CALL io_read_integer2(kv2SetID,(/1,1/),dimsInt(:2),stars%kv2)
      CALL h5dclose_f(kv2SetID, hdfError)

      dimsInt(:1)=(/stars%ng3/)
      CALL h5dopen_f(groupID, 'sk3', sk3SetID, hdfError)
      CALL io_read_real1(sk3SetID,(/1/),dimsInt(:1),stars%sk3)
      CALL h5dclose_f(sk3SetID, hdfError)

      dimsInt(:1)=(/stars%ng2/)
      CALL h5dopen_f(groupID, 'sk2', sk2SetID, hdfError)
      CALL io_read_real1(sk2SetID,(/1/),dimsInt(:1),stars%sk2)
      CALL h5dclose_f(sk2SetID, hdfError)

      dimsInt(:3)=(/2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
      CALL h5dopen_f(groupID, 'ig', igSetID, hdfError)
      CALL io_read_integer3(igSetID,(/1,1,1/),dimsInt(:3),stars%ig)
      CALL h5dclose_f(igSetID, hdfError)

      dimsInt(:1)=(/stars%ng3/)
      CALL h5dopen_f(groupID, 'ig2', ig2SetID, hdfError)
      CALL io_read_integer1(ig2SetID,(/1/),dimsInt(:1),stars%ig2)
      CALL h5dclose_f(ig2SetID, hdfError)

      dimsInt(:1)=(/stars%ng3/)
      CALL h5dopen_f(groupID, 'nstr', nstrSetID, hdfError)
      CALL io_read_integer1(nstrSetID,(/1/),dimsInt(:1),stars%nstr)
      CALL h5dclose_f(nstrSetID, hdfError)

      dimsInt(:1)=(/stars%ng2/)
      CALL h5dopen_f(groupID, 'nstr2', nstr2SetID, hdfError)
      CALL io_read_integer1(nstr2SetID,(/1/),dimsInt(:1),stars%nstr2)
      CALL h5dclose_f(nstr2SetID, hdfError)

      dimsInt(:1)=(/stars%ng2/)
      CALL h5dopen_f(groupID, 'phi2', phi2SetID, hdfError)
      CALL io_read_real1(phi2SetID,(/1/),dimsInt(:1),stars%phi2)
      CALL h5dclose_f(phi2SetID, hdfError)

      dimsInt(:4)=(/2,2*stars%mx1+1,2*stars%mx2+1,2*stars%mx3+1/)
      CALL h5dopen_f(groupID, 'rgphs', rgphsSetID, hdfError)
      CALL io_read_complex3(rgphsSetID,(/-1,1,1,1/),dimsInt(:4),stars%rgphs)
      CALL h5dclose_f(rgphsSetID, hdfError)

      dimsInt(:2)=(/stars%kimax+1,2/)
      CALL h5dopen_f(groupID, 'igfft', igfftSetID, hdfError)
      CALL io_read_integer2(igfftSetID,(/1,1/),dimsInt(:2),stars%igfft(0:stars%kimax,:))
      CALL h5dclose_f(igfftSetID, hdfError)

      dimsInt(:2)=(/stars%kimax2+1,2/)
      CALL h5dopen_f(groupID, 'igfft2', igfft2SetID, hdfError)
      CALL io_read_integer2(igfft2SetID,(/1,1/),dimsInt(:2),stars%igfft2(0:stars%kimax2,:))
      CALL h5dclose_f(igfft2SetID, hdfError)

      dimsInt(:2)=(/2,stars%kimax+1/)
      CALL h5dopen_f(groupID, 'pgfft', pgfftSetID, hdfError)
588
      CALL io_read_complex1(pgfftSetID,(/-1,1/),dimsInt(:2),stars%pgfft(0:stars%kimax))
589 590 591 592
      CALL h5dclose_f(pgfftSetID, hdfError)

      dimsInt(:2)=(/2,stars%kimax2+1/)
      CALL h5dopen_f(groupID, 'pgfft2', pgfft2SetID, hdfError)
593
      CALL io_read_complex1(pgfft2SetID,(/-1,1/),dimsInt(:2),stars%pgfft2(0:stars%kimax2))
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
      CALL h5dclose_f(pgfft2SetID, hdfError)

      dimsInt(:1)=(/ft2_gf_dim/)
      CALL h5dopen_f(groupID, 'ft2_gfx', ft2_gfxSetID, hdfError)
      CALL io_read_real1(ft2_gfxSetID,(/1/),dimsInt(:1),stars%ft2_gfx)
      CALL h5dclose_f(ft2_gfxSetID, hdfError)

      dimsInt(:1)=(/ft2_gf_dim/)
      CALL h5dopen_f(groupID, 'ft2_gfy', ft2_gfySetID, hdfError)
      CALL io_read_real1(ft2_gfySetID,(/1/),dimsInt(:1),stars%ft2_gfy)
      CALL h5dclose_f(ft2_gfySetID, hdfError)

      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE readStarsHDF

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
   SUBROUTINE peekStarsHDF(fileID, starsIndex, structureIndex)

      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: starsIndex
      INTEGER,        INTENT(OUT)   :: structureIndex

      INTEGER(HID_T)            :: groupID
      INTEGER                   :: hdfError
      CHARACTER(LEN=30)         :: groupName
      LOGICAL                   :: l_exist

      WRITE(groupname,'(a,i0)') '/stars-', starsIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('stars entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStarsHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
      CALL io_read_attint0(groupID,'structureIndex',structureIndex)
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE peekStarsHDF

635
   SUBROUTINE writeStepfunctionHDF(fileID, stepfunctionIndex, starsIndex, structureIndex, stars, l_CheckBroyd)
636 637

      INTEGER(HID_T), INTENT(IN)    :: fileID
638
      INTEGER,        INTENT(IN)    :: stepfunctionIndex, starsIndex, structureIndex
639
      TYPE(t_stars),  INTENT(IN)    :: stars
640
      LOGICAL,        INTENT(IN)    :: l_CheckBroyd
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660

      INTEGER                   :: ifftd

      INTEGER                   :: hdfError
      INTEGER(HID_T)            :: groupID
      INTEGER(HID_T)            :: ustepSpaceID, ustepSetID
      INTEGER(HID_T)            :: ufftSpaceID, ufftSetID
      CHARACTER(LEN=30)         :: groupName
      INTEGER(HSIZE_T)          :: dims(7)
      INTEGER                   :: dimsInt(7)
      LOGICAL                   :: l_exist

      WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (l_exist) THEN
         CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeStepfunctionHDF")
      END IF

661 662
      INQUIRE(FILE='broyd',EXIST=l_exist)
      IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
663
      IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Stepfunction change but broyden files detected!')
664

665 666 667 668 669
      ifftd = size(stars%ufft)

      CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      CALL io_write_attint0(groupID,'starsIndex',starsIndex)
670
      CALL io_write_attint0(groupID,'structureIndex',structureIndex)
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
      CALL io_write_attint0(groupID,'ifftd',ifftd)
      CALL io_write_attint0(groupID,'ng3',stars%ng3)

      dims(:2)=(/2,stars%ng3/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),ustepSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ustep", H5T_NATIVE_DOUBLE, ustepSpaceID, ustepSetID, hdfError)
      CALL h5sclose_f(ustepSpaceID,hdfError)
      CALL io_write_complex1(ustepSetID,(/-1,1/),dimsInt(:2),stars%ustep)
      CALL h5dclose_f(ustepSetID, hdfError)

      dims(:1)=(/ifftd/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),ufftSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ufft", H5T_NATIVE_DOUBLE, ufftSpaceID, ufftSetID, hdfError)
      CALL h5sclose_f(ufftSpaceID,hdfError)
      CALL io_write_real1(ufftSetID,(/1/),dimsInt(:1),stars%ufft)
      CALL h5dclose_f(ufftSetID, hdfError)

      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE writeStepfunctionHDF

   SUBROUTINE readStepfunctionHDF(fileID, stepfunctionIndex, stars)

      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: stepfunctionIndex
      TYPE(t_stars),  INTENT(INOUT) :: stars

      INTEGER                   :: starsIndex, ng3Temp, ifftd, ifftdStars
701
      INTEGER                   :: structureIndex
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724

      INTEGER(HID_T)            :: groupID
      INTEGER                   :: hdfError
      INTEGER                   :: dimsInt(7)
      CHARACTER(LEN=30)         :: groupName
      LOGICAL                   :: l_exist

      INTEGER(HID_T)            :: ustepSetID
      INTEGER(HID_T)            :: ufftSetID

      WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStepfunctionHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      ifftdStars = 27*stars%mx1*stars%mx2*stars%mx3

      CALL io_read_attint0(groupID,'starsIndex',starsIndex)
725
      CALL io_read_attint0(groupID,'structureIndex',structureIndex)
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
      CALL io_read_attint0(groupID,'ng3',ng3Temp)
      CALL io_read_attint0(groupID,'ifftd',ifftd)

      IF((ng3Temp.NE.stars%ng3).OR.(ifftd.NE.ifftdStars)) THEN
         WRITE(*,'(a,i7,a,i7)') 'ng3   (stepfunction): ', ng3Temp, ' ng3   (stars) :', stars%ng3
         WRITE(*,'(a,i7,a,i7)') 'ifftd (stepfunction): ', ifftd,   ' ifftd (stars) :', ifftdStars
         CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' does not fit to stars.' ,calledby ="readStepfunctionHDF")
      END IF

      IF(ALLOCATED(stars%ustep)) DEALLOCATE(stars%ustep)
      IF(ALLOCATED(stars%ufft)) DEALLOCATE(stars%ufft)

      ALLOCATE(stars%ustep(stars%ng3))
      ALLOCATE(stars%ufft(0:ifftd-1))

      dimsInt(:2)=(/2,ng3Temp/)
      CALL h5dopen_f(groupID, 'ustep', ustepSetID, hdfError)
      CALL io_read_complex1(ustepSetID,(/-1,1/),dimsInt(:2),stars%ustep)
      CALL h5dclose_f(ustepSetID, hdfError)

      dimsInt(:1)=(/ifftd/)
      CALL h5dopen_f(groupID, 'ufft', ufftSetID, hdfError)
      CALL io_read_real1(ufftSetID,(/1/),dimsInt(:1),stars%ufft(0:ifftd-1))
      CALL h5dclose_f(ufftSetID, hdfError)

      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE readStepfunctionHDF

755
   SUBROUTINE peekStepfunctionHDF(fileID, stepfunctionIndex, starsIndex, structureIndex)
756 757 758

      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: stepfunctionIndex
759
      INTEGER,        INTENT(OUT)   :: starsIndex, structureIndex
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775

      INTEGER(HID_T)            :: groupID
      INTEGER                   :: hdfError
      CHARACTER(LEN=30)         :: groupName
      LOGICAL                   :: l_exist

      WRITE(groupname,'(a,i0)') '/stepfunction-', stepfunctionIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('stepfunction entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStepfunctionHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
      CALL io_read_attint0(groupID,'starsIndex',starsIndex)
776
      CALL io_read_attint0(groupID,'structureIndex',structureIndex)
777 778 779 780
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE peekStepfunctionHDF

781
   SUBROUTINE writeLatharmsHDF(fileID, latharmsIndex, structureIndex, latharms, l_CheckBroyd)
782 783

      INTEGER(HID_T), INTENT(IN)  :: fileID
784
      INTEGER,        INTENT(IN)  :: latharmsIndex, structureIndex
785
      TYPE(t_sphhar), INTENT(IN)  :: latharms
786
      LOGICAL,        INTENT(IN)  :: l_CheckBroyd
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807

      INTEGER                   :: hdfError
      INTEGER(HID_T)            :: groupID
      INTEGER(HID_T)            :: nlhSpaceID, nlhSetID
      INTEGER(HID_T)            :: llhSpaceID, llhSetID
      INTEGER(HID_T)            :: nmemSpaceID, nmemSetID
      INTEGER(HID_T)            :: mlhSpaceID, mlhSetID
      INTEGER(HID_T)            :: clnuSpaceID, clnuSetID
      CHARACTER(LEN=30)         :: groupName
      INTEGER(HSIZE_T)          :: dims(7)
      INTEGER                   :: dimsInt(7)
      LOGICAL                   :: l_exist

      WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (l_exist) THEN
         CALL juDFT_error('latharms entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeLatharmsHDF")
      END IF

808 809
      INQUIRE(FILE='broyd',EXIST=l_exist)
      IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
810
      IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Lattice harmonics change but broyden files detected!')
811

812 813
      CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

814
      CALL io_write_attint0(groupID,'structureIndex',structureIndex)
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
      CALL io_write_attint0(groupID,'ntypsd',latharms%ntypsd)
      CALL io_write_attint0(groupID,'memd',latharms%memd)
      CALL io_write_attint0(groupID,'nlhd',latharms%nlhd)

      dims(:1)=(/latharms%ntypsd/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),nlhSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "nlh", H5T_NATIVE_INTEGER, nlhSpaceID, nlhSetID, hdfError)
      CALL h5sclose_f(nlhSpaceID,hdfError)
      CALL io_write_integer1(nlhSetID,(/1/),dimsInt(:1),latharms%nlh)
      CALL h5dclose_f(nlhSetID, hdfError)

      dims(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),llhSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "llh", H5T_NATIVE_INTEGER, llhSpaceID, llhSetID, hdfError)
      CALL h5sclose_f(llhSpaceID,hdfError)
      CALL io_write_integer2(llhSetID,(/1,1/),dimsInt(:2),latharms%llh)
      CALL h5dclose_f(llhSetID, hdfError)

      dims(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),nmemSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "nmem", H5T_NATIVE_INTEGER, nmemSpaceID, nmemSetID, hdfError)
      CALL h5sclose_f(nmemSpaceID,hdfError)
      CALL io_write_integer2(nmemSetID,(/1,1/),dimsInt(:2),latharms%nmem)
      CALL h5dclose_f(nmemSetID, hdfError)

      dims(:3)=(/latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
      dimsInt = dims
      CALL h5screate_simple_f(3,dims(:3),mlhSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "mlh", H5T_NATIVE_INTEGER, mlhSpaceID, mlhSetID, hdfError)
      CALL h5sclose_f(mlhSpaceID,hdfError)
      CALL io_write_integer3(mlhSetID,(/1,1,1/),dimsInt(:3),latharms%mlh)
      CALL h5dclose_f(mlhSetID, hdfError)

      dims(:4)=(/2,latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
      dimsInt = dims
      CALL h5screate_simple_f(4,dims(:4),clnuSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "clnu", H5T_NATIVE_DOUBLE, clnuSpaceID, clnuSetID, hdfError)
      CALL h5sclose_f(clnuSpaceID,hdfError)
      CALL io_write_complex3(clnuSetID,(/-1,1,1,1/),dimsInt(:4),latharms%clnu)
      CALL h5dclose_f(clnuSetID, hdfError)

      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE writeLatharmsHDF

   SUBROUTINE readLatharmsHDF(fileID, latharmsIndex, latharms)

      INTEGER(HID_T), INTENT(IN)  :: fileID
      INTEGER,        INTENT(IN)  :: latharmsIndex
      TYPE(t_sphhar), INTENT(INOUT) :: latharms

      INTEGER(HID_T)            :: nlhSetID, llhSetID, nmemSetID
      INTEGER(HID_T)            :: mlhSetID, clnuSetID, groupID
      CHARACTER(LEN=30)         :: groupName
      INTEGER                   :: hdfError
      INTEGER                   :: dimsInt(7)
      LOGICAL                   :: l_exist

      WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('latharms entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readLatharmsHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      CALL io_read_attint0(groupID,'ntypsd',latharms%ntypsd)
      CALL io_read_attint0(groupID,'memd',latharms%memd)
      CALL io_read_attint0(groupID,'nlhd',latharms%nlhd)

      IF(ALLOCATED(latharms%nlh)) DEALLOCATE(latharms%nlh)
      IF(ALLOCATED(latharms%llh)) DEALLOCATE(latharms%llh)
      IF(ALLOCATED(latharms%nmem)) DEALLOCATE(latharms%nmem)
      IF(ALLOCATED(latharms%mlh)) DEALLOCATE(latharms%mlh)
      IF(ALLOCATED(latharms%clnu)) DEALLOCATE(latharms%clnu)

      ALLOCATE(latharms%clnu(latharms%memd,0:latharms%nlhd,latharms%ntypsd))
      ALLOCATE(latharms%llh(0:latharms%nlhd,latharms%ntypsd))
      ALLOCATE(latharms%mlh(latharms%memd,0:latharms%nlhd,latharms%ntypsd))
      ALLOCATE(latharms%nlh(latharms%ntypsd),latharms%nmem(0:latharms%nlhd,latharms%ntypsd))

      dimsInt(:1)=(/latharms%ntypsd/)
      CALL h5dopen_f(groupID, 'nlh', nlhSetID, hdfError)
      CALL io_read_integer1(nlhSetID,(/1/),dimsInt(:1),latharms%nlh)
      CALL h5dclose_f(nlhSetID, hdfError)

      dimsInt(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
      CALL h5dopen_f(groupID, 'llh', llhSetID, hdfError)
      CALL io_read_integer2(llhSetID,(/1,1/),dimsInt(:2),latharms%llh)
      CALL h5dclose_f(llhSetID, hdfError)

      dimsInt(:2)=(/latharms%nlhd+1,latharms%ntypsd/)
      CALL h5dopen_f(groupID, 'nmem', nmemSetID, hdfError)
      CALL io_read_integer2(nmemSetID,(/1,1/),dimsInt(:2),latharms%nmem)
      CALL h5dclose_f(nmemSetID, hdfError)

      dimsInt(:3)=(/latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
      CALL h5dopen_f(groupID, 'mlh', mlhSetID, hdfError)
      CALL io_read_integer3(mlhSetID,(/1,1,1/),dimsInt(:3),latharms%mlh)
      CALL h5dclose_f(mlhSetID, hdfError)

      dimsInt(:4)=(/2,latharms%memd,latharms%nlhd+1,latharms%ntypsd/)
      CALL h5dopen_f(groupID, 'clnu', clnuSetID, hdfError)
      CALL io_read_complex3(clnuSetID,(/-1,1,1,1/),dimsInt(:4),latharms%clnu)
      CALL h5dclose_f(clnuSetID, hdfError)

      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE readLatharmsHDF

930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
   SUBROUTINE peekLatharmsHDF(fileID, latharmsIndex, structureIndex)

      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: latharmsIndex
      INTEGER,        INTENT(OUT)   :: structureIndex

      INTEGER(HID_T)            :: groupID
      INTEGER                   :: hdfError
      CHARACTER(LEN=30)         :: groupName
      LOGICAL                   :: l_exist

      WRITE(groupname,'(a,i0)') '/latharms-', latharmsIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('latharms entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readLatharmsHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)
      CALL io_read_attint0(groupID,'structureIndex',structureIndex)
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE peekLatharmsHDF

955
   SUBROUTINE writeStructureHDF(fileID, input, atoms, cell, vacuum, oneD, sym, structureIndex, l_CheckBroyd)
956 957 958 959 960 961 962 963

      INTEGER(HID_T), INTENT(IN) :: fileID
      INTEGER, INTENT(IN)        :: structureIndex
      TYPE(t_input),INTENT(IN)   :: input
      TYPE(t_atoms), INTENT(IN)  :: atoms
      TYPE(t_cell), INTENT(IN)   :: cell
      TYPE(t_vacuum), INTENT(IN) :: vacuum
      TYPE(t_oneD),INTENT(IN)    :: oneD
964
      TYPE(t_sym),INTENT(IN)     :: sym
965
      LOGICAL, INTENT(IN)        :: l_CheckBroyd
966 967

      INTEGER(HID_T)            :: groupID
968
      INTEGER                   :: hdfError, i
969 970 971 972 973
      CHARACTER(LEN=30)         :: groupName
      INTEGER(HSIZE_T)          :: dims(7)
      INTEGER                   :: dimsInt(7)
      LOGICAL                   :: l_exist

974 975 976 977 978 979 980 981
      !LDA+U arrays (start)
      INTEGER                   :: ldau_AtomType(MAX(1,atoms%n_u))
      INTEGER                   :: ldau_l(MAX(1,atoms%n_u))
      INTEGER                   :: ldau_l_amf(MAX(1,atoms%n_u)) ! 1 = true, 0 = false
      REAL                      :: ldau_U(MAX(1,atoms%n_u))
      REAL                      :: ldau_J(MAX(1,atoms%n_u))
      !LDA+U arrays (end)

982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
      INTEGER(HID_T)                   :: amatSpaceID, amatSetID
      INTEGER(HID_T)                   :: nzSpaceID, nzSetID
      INTEGER(HID_T)                   :: neqSpaceID, neqSetID
      INTEGER(HID_T)                   :: jriSpaceID, jriSetID
      INTEGER(HID_T)                   :: lmaxSpaceID, lmaxSetID
      INTEGER(HID_T)                   :: ngoprSpaceID, ngoprSetID
      INTEGER(HID_T)                   :: ntypsySpaceID, ntypsySetID
      INTEGER(HID_T)                   :: nlhtypSpaceID, nlhtypSetID
      INTEGER(HID_T)                   :: invsatSpaceID, invsatSetID
      INTEGER(HID_T)                   :: rmtSpaceID, rmtSetID
      INTEGER(HID_T)                   :: dxSpaceID, dxSetID
      INTEGER(HID_T)                   :: volmtsSpaceID, volmtsSetID
      INTEGER(HID_T)                   :: rmshSpaceID, rmshSetID
      INTEGER(HID_T)                   :: zatomSpaceID, zatomSetID
      INTEGER(HID_T)                   :: posSpaceID, posSetID
      INTEGER(HID_T)                   :: taualSpaceID, taualSetID
998 999
      INTEGER(HID_T)                   :: mrotSpaceID, mrotSetID
      INTEGER(HID_T)                   :: tauSpaceID, tauSetID
1000

1001 1002 1003 1004 1005 1006 1007 1008
      !LDA+U IDs (start)
      INTEGER(HID_T)                   :: ldau_AtomTypeSpaceID, ldau_AtomTypeSetID
      INTEGER(HID_T)                   :: ldau_lSpaceID, ldau_lSetID
      INTEGER(HID_T)                   :: ldau_l_amfSpaceID, ldau_l_amfSetID
      INTEGER(HID_T)                   :: ldau_USpaceID, ldau_USetID
      INTEGER(HID_T)                   :: ldau_JSpaceID, ldau_JSetID
      !LDA+U IDs (end)

1009 1010 1011 1012 1013 1014 1015 1016
      WRITE(groupname,'(a,i0)') '/structure-', structureIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (l_exist) THEN
         CALL juDFT_error('structure entry '//TRIM(ADJUSTL(groupName))//' already exists.' ,calledby ="writeStructureHDF")
      END IF

1017 1018
      INQUIRE(FILE='broyd',EXIST=l_exist)
      IF (.NOT.l_exist) INQUIRE(FILE='broyd.7',EXIST=l_exist)
1019
      IF (l_exist.AND.l_CheckBroyd) CALL juDFT_warn('Structure / parameter change but broyden files detected!')
1020

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
      CALL h5gcreate_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      CALL io_write_attlog0(groupID,'l_film',input%film)

      CALL io_write_attreal0(groupID,'omtil',cell%omtil)
      CALL io_write_attreal0(groupID,'area',cell%area)
      CALL io_write_attreal0(groupID,'z1',cell%z1)
      CALL io_write_attreal0(groupID,'vol',cell%vol)
      CALL io_write_attreal0(groupID,'volint',cell%volint)

      CALL io_write_attint0(groupID,'ntype',atoms%ntype)
      CALL io_write_attint0(groupID,'nat',atoms%nat)
      CALL io_write_attint0(groupID,'lmaxd',atoms%lmaxd)
      CALL io_write_attint0(groupID,'jmtd',atoms%jmtd)
1035
      CALL io_write_attint0(groupID,'n_u',atoms%n_u)
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051

      CALL io_write_attint0(groupID,'nmz',vacuum%nmz)
      CALL io_write_attint0(groupID,'nmzd',vacuum%nmzd)
      CALL io_write_attint0(groupID,'nmzxy',vacuum%nmzxy)
      CALL io_write_attint0(groupID,'nmzxyd',vacuum%nmzxyd)
      CALL io_write_attint0(groupID,'layerd',vacuum%layerd)
      CALL io_write_attint0(groupID,'layers',vacuum%layers)
      CALL io_write_attint0(groupID,'nvac',vacuum%nvac)
      CALL io_write_attint0(groupID,'nvacd',vacuum%nvacd)
      CALL io_write_attint0(groupID,'nstars',vacuum%nstars)
      CALL io_write_attint0(groupID,'nstm',vacuum%nstm)
      CALL io_write_attreal0(groupID,'delz',vacuum%delz)
      CALL io_write_attreal0(groupID,'dvac',vacuum%dvac)

      CALL io_write_attint0(groupID,'od_nq2',oneD%odi%nq2)

1052 1053 1054 1055 1056 1057 1058 1059
      CALL io_write_attlog0(groupID,'invs2',sym%invs2)
      CALL io_write_attlog0(groupID,'invs',sym%invs)
      CALL io_write_attlog0(groupID,'zrfs',sym%zrfs)
      CALL io_write_attint0(groupID,'nop',sym%nop)
      CALL io_write_attint0(groupID,'nop2',sym%nop2)
      CALL io_write_attchar0(groupID,'latnam',sym%latnam)
      CALL io_write_attchar0(groupID,'namgrp',sym%namgrp)

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
      dims(:2)=(/3,3/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),amatSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "amat", H5T_NATIVE_DOUBLE, amatSpaceID, amatSetID, hdfError)
      CALL h5sclose_f(amatSpaceID,hdfError)
      CALL io_write_real2(amatSetID,(/1,1/),dimsInt(:2),cell%amat)
      CALL h5dclose_f(amatSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),nzSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "nz", H5T_NATIVE_INTEGER, nzSpaceID, nzSetID, hdfError)
      CALL h5sclose_f(nzSpaceID,hdfError)
      CALL io_write_integer1(nzSetID,(/1/),dimsInt(:1),atoms%nz)
      CALL h5dclose_f(nzSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),neqSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "neq", H5T_NATIVE_INTEGER, neqSpaceID, neqSetID, hdfError)
      CALL h5sclose_f(neqSpaceID,hdfError)
      CALL io_write_integer1(neqSetID,(/1/),dimsInt(:1),atoms%neq)
      CALL h5dclose_f(neqSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),jriSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "jri", H5T_NATIVE_INTEGER, jriSpaceID, jriSetID, hdfError)
      CALL h5sclose_f(jriSpaceID,hdfError)
      CALL io_write_integer1(jriSetID,(/1/),dimsInt(:1),atoms%jri)
      CALL h5dclose_f(jriSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),lmaxSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "lmax", H5T_NATIVE_INTEGER, lmaxSpaceID, lmaxSetID, hdfError)
      CALL h5sclose_f(lmaxSpaceID,hdfError)
      CALL io_write_integer1(lmaxSetID,(/1/),dimsInt(:1),atoms%lmax)
      CALL h5dclose_f(lmaxSetID, hdfError)

      dims(:1)=(/atoms%nat/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),ngoprSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ngopr", H5T_NATIVE_INTEGER, ngoprSpaceID, ngoprSetID, hdfError)
      CALL h5sclose_f(ngoprSpaceID,hdfError)
      CALL io_write_integer1(ngoprSetID,(/1/),dimsInt(:1),atoms%ngopr)
      CALL h5dclose_f(ngoprSetID, hdfError)

      dims(:1)=(/atoms%nat/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),ntypsySpaceID,hdfError)
      CALL h5dcreate_f(groupID, "ntypsy", H5T_NATIVE_INTEGER, ntypsySpaceID, ntypsySetID, hdfError)
      CALL h5sclose_f(ntypsySpaceID,hdfError)
      CALL io_write_integer1(ntypsySetID,(/1/),dimsInt(:1),atoms%ntypsy)
      CALL h5dclose_f(ntypsySetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),nlhtypSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "nlhtyp", H5T_NATIVE_INTEGER, nlhtypSpaceID, nlhtypSetID, hdfError)
      CALL h5sclose_f(nlhtypSpaceID,hdfError)
      CALL io_write_integer1(nlhtypSetID,(/1/),dimsInt(:1),atoms%nlhtyp)
      CALL h5dclose_f(nlhtypSetID, hdfError)

      dims(:1)=(/atoms%nat/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),invsatSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "invsat", H5T_NATIVE_INTEGER, invsatSpaceID, invsatSetID, hdfError)
      CALL h5sclose_f(invsatSpaceID,hdfError)
      CALL io_write_integer1(invsatSetID,(/1/),dimsInt(:1),atoms%invsat)
      CALL h5dclose_f(invsatSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),rmtSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "rmt", H5T_NATIVE_DOUBLE, rmtSpaceID, rmtSetID, hdfError)
      CALL h5sclose_f(rmtSpaceID,hdfError)
      CALL io_write_real1(rmtSetID,(/1/),dimsInt(:1),atoms%rmt)
      CALL h5dclose_f(rmtSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),dxSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "dx", H5T_NATIVE_DOUBLE, dxSpaceID, dxSetID, hdfError)
      CALL h5sclose_f(dxSpaceID,hdfError)
      CALL io_write_real1(dxSetID,(/1/),dimsInt(:1),atoms%dx)
      CALL h5dclose_f(dxSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),volmtsSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "volmts", H5T_NATIVE_DOUBLE, volmtsSpaceID, volmtsSetID, hdfError)
      CALL h5sclose_f(volmtsSpaceID,hdfError)
      CALL io_write_real1(volmtsSetID,(/1/),dimsInt(:1),atoms%volmts)
      CALL h5dclose_f(volmtsSetID, hdfError)

      dims(:2)=(/atoms%jmtd,atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),rmshSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "rmsh", H5T_NATIVE_DOUBLE, rmshSpaceID, rmshSetID, hdfError)
      CALL h5sclose_f(rmshSpaceID,hdfError)
      CALL io_write_real2(rmshSetID,(/1,1/),dimsInt(:2),atoms%rmsh)
      CALL h5dclose_f(rmshSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt = dims
      CALL h5screate_simple_f(1,dims(:1),zatomSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "zatom", H5T_NATIVE_DOUBLE, zatomSpaceID, zatomSetID, hdfError)
      CALL h5sclose_f(zatomSpaceID,hdfError)
      CALL io_write_real1(zatomSetID,(/1/),dimsInt(:1),atoms%zatom)
      CALL h5dclose_f(zatomSetID, hdfError)

      dims(:2)=(/3,atoms%nat/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),posSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "pos", H5T_NATIVE_DOUBLE, posSpaceID, posSetID, hdfError)
      CALL h5sclose_f(posSpaceID,hdfError)
      CALL io_write_real2(posSetID,(/1,1/),dimsInt(:2),atoms%pos)
      CALL h5dclose_f(posSetID, hdfError)

      dims(:2)=(/3,atoms%nat/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),taualSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "taual", H5T_NATIVE_DOUBLE, taualSpaceID, taualSetID, hdfError)
      CALL h5sclose_f(taualSpaceID,hdfError)
      CALL io_write_real2(taualSetID,(/1,1/),dimsInt(:2),atoms%taual)
      CALL h5dclose_f(taualSetID, hdfError)

1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
      dims(:3)=(/3,3,sym%nop/)
      dimsInt = dims
      CALL h5screate_simple_f(3,dims(:3),mrotSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "mrot", H5T_NATIVE_INTEGER, mrotSpaceID, mrotSetID, hdfError)
      CALL h5sclose_f(mrotSpaceID,hdfError)
      CALL io_write_integer3(mrotSetID,(/1,1,1/),dimsInt(:3),sym%mrot)
      CALL h5dclose_f(mrotSetID, hdfError)

      dims(:2)=(/3,sym%nop/)
      dimsInt = dims
      CALL h5screate_simple_f(2,dims(:2),tauSpaceID,hdfError)
      CALL h5dcreate_f(groupID, "tau", H5T_NATIVE_DOUBLE, tauSpaceID, tauSetID, hdfError)
      CALL h5sclose_f(tauSpaceID,hdfError)
      CALL io_write_real2(tauSetID,(/1,1/),dimsInt(:2),sym%tau)
      CALL h5dclose_f(tauSetID, hdfError)

1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
      !LDA+U data (start)
      IF(atoms%n_u.GT.0) THEN
         ldau_l_amf = 0
         DO i = 1, atoms%n_u
            ldau_AtomType(i) = atoms%lda_u(i)%atomType
            ldau_l(i) = atoms%lda_u(i)%l
            ldau_U(i) = atoms%lda_u(i)%u
            ldau_J(i) = atoms%lda_u(i)%j
            IF(atoms%lda_u(i)%l_amf) ldau_l_amf(i) = 1
         END DO

         dims(:1)=(/atoms%n_u/)
         dimsInt = dims
         CALL h5screate_simple_f(1,dims(:1),ldau_AtomTypeSpaceID,hdfError)
         CALL h5dcreate_f(groupID, "ldau_AtomType", H5T_NATIVE_INTEGER, ldau_AtomTypeSpaceID, ldau_AtomTypeSetID, hdfError)
         CALL h5sclose_f(ldau_AtomTypeSpaceID,hdfError)
         CALL io_write_integer1(ldau_AtomTypeSetID,(/1/),dimsInt(:1),ldau_AtomType(:atoms%n_u))
         CALL h5dclose_f(ldau_AtomTypeSetID, hdfError)

         dims(:1)=(/atoms%n_u/)
         dimsInt = dims
         CALL h5screate_simple_f(1,dims(:1),ldau_lSpaceID,hdfError)
         CALL h5dcreate_f(groupID, "ldau_l", H5T_NATIVE_INTEGER, ldau_lSpaceID, ldau_lSetID, hdfError)
         CALL h5sclose_f(ldau_lSpaceID,hdfError)
         CALL io_write_integer1(ldau_lSetID,(/1/),dimsInt(:1),ldau_l(:atoms%n_u))
         CALL h5dclose_f(ldau_lSetID, hdfError)

         dims(:1)=(/atoms%n_u/)
         dimsInt = dims
         CALL h5screate_simple_f(1,dims(:1),ldau_l_amfSpaceID,hdfError)
         CALL h5dcreate_f(groupID, "ldau_l_amf", H5T_NATIVE_INTEGER, ldau_l_amfSpaceID, ldau_l_amfSetID, hdfError)
         CALL h5sclose_f(ldau_l_amfSpaceID,hdfError)
         CALL io_write_integer1(ldau_l_amfSetID,(/1/),dimsInt(:1),ldau_l_amf(:atoms%n_u))
         CALL h5dclose_f(ldau_l_amfSetID, hdfError)

         dims(:1)=(/atoms%n_u/)
         dimsInt = dims
         CALL h5screate_simple_f(1,dims(:1),ldau_USpaceID,hdfError)
         CALL h5dcreate_f(groupID, "ldau_U", H5T_NATIVE_DOUBLE, ldau_USpaceID, ldau_USetID, hdfError)
         CALL h5sclose_f(ldau_USpaceID,hdfError)
         CALL io_write_real1(ldau_USetID,(/1/),dimsInt(:1),ldau_U(:atoms%n_u))
         CALL h5dclose_f(ldau_USetID, hdfError)

         dims(:1)=(/atoms%n_u/)
         dimsInt = dims
         CALL h5screate_simple_f(1,dims(:1),ldau_JSpaceID,hdfError)
         CALL h5dcreate_f(groupID, "ldau_J", H5T_NATIVE_DOUBLE, ldau_JSpaceID, ldau_JSetID, hdfError)
         CALL h5sclose_f(ldau_JSpaceID,hdfError)
         CALL io_write_real1(ldau_JSetID,(/1/),dimsInt(:1),ldau_J(:atoms%n_u))
         CALL h5dclose_f(ldau_JSetID, hdfError)
      END IF
      !LDA+U data (end)

1257 1258 1259 1260
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE writeStructureHDF

1261
   SUBROUTINE readStructureHDF(fileID, input, atoms, cell, vacuum, oneD, sym, structureIndex)
1262 1263 1264 1265 1266 1267 1268 1269

      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER, INTENT(IN)           :: structureIndex
      TYPE(t_input),INTENT(INOUT)   :: input
      TYPE(t_atoms), INTENT(INOUT)  :: atoms
      TYPE(t_cell), INTENT(INOUT)   :: cell
      TYPE(t_vacuum), INTENT(INOUT) :: vacuum
      TYPE(t_oneD),INTENT(INOUT)    :: oneD
1270
      TYPE(t_sym),INTENT(INOUT)     :: sym
1271

1272 1273
      INTEGER(HID_T)            :: groupID, generalGroupID
      INTEGER                   :: hdfError, fileFormatVersion, i
1274 1275 1276 1277
      CHARACTER(LEN=30)         :: groupName
      INTEGER                   :: dimsInt(7)
      LOGICAL                   :: l_exist

1278 1279 1280 1281 1282 1283 1284
      !LDA+U arrays (start)
      INTEGER, ALLOCATABLE             :: ldau_AtomType(:)
      INTEGER, ALLOCATABLE             :: ldau_l(:)
      INTEGER, ALLOCATABLE             :: ldau_l_amf(:) ! 1 = true, 0 = false
      REAL, ALLOCATABLE                :: ldau_U(:)
      REAL, ALLOCATABLE                :: ldau_J(:)

1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
      INTEGER(HID_T)                   :: amatSetID
      INTEGER(HID_T)                   :: nzSetID
      INTEGER(HID_T)                   :: neqSetID
      INTEGER(HID_T)                   :: jriSetID
      INTEGER(HID_T)                   :: lmaxSetID
      INTEGER(HID_T)                   :: ngoprSetID
      INTEGER(HID_T)                   :: ntypsySetID
      INTEGER(HID_T)                   :: nlhtypSetID
      INTEGER(HID_T)                   :: invsatSetID
      INTEGER(HID_T)                   :: rmtSetID
      INTEGER(HID_T)                   :: dxSetID
      INTEGER(HID_T)                   :: volmtsSetID
      INTEGER(HID_T)                   :: rmshSetID
      INTEGER(HID_T)                   :: zatomSetID
      INTEGER(HID_T)                   :: posSetID
      INTEGER(HID_T)                   :: taualSetID
1301 1302
      INTEGER(HID_T)                   :: mrotSetID
      INTEGER(HID_T)                   :: tauSetID
1303

1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
      !LDA+U IDs (start)
      INTEGER(HID_T)                   :: ldau_AtomTypeSetID
      INTEGER(HID_T)                   :: ldau_lSetID
      INTEGER(HID_T)                   :: ldau_l_amfSetID
      INTEGER(HID_T)                   :: ldau_USetID
      INTEGER(HID_T)                   :: ldau_JSetID
      !LDA+U IDs (end)

      CALL h5gopen_f(fileID, '/general', generalGroupID, hdfError)
      ! read in file format version from the header '/general'
      CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)

1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
      WRITE(groupname,'(a,i0)') '/structure-', structureIndex

      l_exist = io_groupexists(fileID,TRIM(ADJUSTL(groupName)))

      IF (.NOT.l_exist) THEN
         CALL juDFT_error('structure entry '//TRIM(ADJUSTL(groupName))//' does not exist.' ,calledby ="readStructureHDF")
      END IF

      CALL h5gopen_f(fileID, TRIM(ADJUSTL(groupName)), groupID, hdfError)

      CALL io_read_attlog0(groupID,'l_film',input%film)

      CALL io_read_attreal0(groupID,'omtil',cell%omtil)
      CALL io_read_attreal0(groupID,'area',cell%area)
      CALL io_read_attreal0(groupID,'z1',cell%z1)
      CALL io_read_attreal0(groupID,'vol',cell%vol)
      CALL io_read_attreal0(groupID,'volint',cell%volint)

      CALL io_read_attint0(groupID,'ntype',atoms%ntype)
      CALL io_read_attint0(groupID,'nat',atoms%nat)
      CALL io_read_attint0(groupID,'lmaxd',atoms%lmaxd)
      CALL io_read_attint0(groupID,'jmtd',atoms%jmtd)

      CALL io_read_attint0(groupID,'nmz',vacuum%nmz)
      CALL io_read_attint0(groupID,'nmzd',vacuum%nmzd)
      CALL io_read_attint0(groupID,'nmzxy',vacuum%nmzxy)
      CALL io_read_attint0(groupID,'nmzxyd',vacuum%nmzxyd)
      CALL io_read_attint0(groupID,'layerd',vacuum%layerd)
      CALL io_read_attint0(groupID,'layers',vacuum%layers)
      CALL io_read_attint0(groupID,'nvac',vacuum%nvac)
      CALL io_read_attint0(groupID,'nvacd',vacuum%nvacd)
      CALL io_read_attint0(groupID,'nstars',vacuum%nstars)
      CALL io_read_attint0(groupID,'nstm',vacuum%nstm)
      CALL io_read_attreal0(groupID,'delz',vacuum%delz)
      CALL io_read_attreal0(groupID,'dvac',vacuum%dvac)

      CALL io_read_attint0(groupID,'od_nq2',oneD%odi%nq2)

1354 1355 1356 1357 1358 1359 1360 1361
      CALL io_read_attlog0(groupID,'invs2',sym%invs2)
      CALL io_read_attlog0(groupID,'invs',sym%invs)
      CALL io_read_attlog0(groupID,'zrfs',sym%zrfs)
      CALL io_read_attint0(groupID,'nop',sym%nop)
      CALL io_read_attint0(groupID,'nop2',sym%nop2)
      CALL io_read_attchar0(groupID,'latnam',sym%latnam)
      CALL io_read_attchar0(groupID,'namgrp',sym%namgrp)

1362 1363 1364 1365 1366 1367
      IF(fileFormatVersion.GE.29) THEN
         CALL io_read_attint0(groupID,'n_u',atoms%n_u)
         IF(ALLOCATED(atoms%lda_u)) DEALLOCATE(atoms%lda_u)
         ALLOCATE(atoms%lda_u(atoms%n_u))
      END IF

1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
      IF(ALLOCATED(atoms%nz)) DEALLOCATE(atoms%nz)
      IF(ALLOCATED(atoms%neq)) DEALLOCATE(atoms%neq)
      IF(ALLOCATED(atoms%jri)) DEALLOCATE(atoms%jri)
      IF(ALLOCATED(atoms%lmax)) DEALLOCATE(atoms%lmax)
      IF(ALLOCATED(atoms%ngopr)) DEALLOCATE(atoms%ngopr)
      IF(ALLOCATED(atoms%ntypsy)) DEALLOCATE(atoms%ntypsy)
      IF(ALLOCATED(atoms%nlhtyp)) DEALLOCATE(atoms%nlhtyp)
      IF(ALLOCATED(atoms%invsat)) DEALLOCATE(atoms%invsat)
      IF(ALLOCATED(atoms%rmt)) DEALLOCATE(atoms%rmt)
      IF(ALLOCATED(atoms%dx)) DEALLOCATE(atoms%dx)
      IF(ALLOCATED(atoms%volmts)) DEALLOCATE(atoms%volmts)
      IF(ALLOCATED(atoms%rmsh)) DEALLOCATE(atoms%rmsh)
      IF(ALLOCATED(atoms%zatom)) DEALLOCATE(atoms%zatom)
      IF(ALLOCATED(atoms%pos)) DEALLOCATE(atoms%pos)
      IF(ALLOCATED(atoms%taual)) DEALLOCATE(atoms%taual)
1383 1384
      IF(ALLOCATED(sym%mrot)) DEALLOCATE(sym%mrot)
      IF(ALLOCATED(sym%tau)) DEALLOCATE(sym%tau)
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400

      ALLOCATE(atoms%nz(atoms%ntype))
      ALLOCATE(atoms%neq(atoms%ntype))
      ALLOCATE(atoms%jri(atoms%ntype))
      ALLOCATE(atoms%lmax(atoms%ntype))
      ALLOCATE(atoms%ngopr(atoms%nat))
      ALLOCATE(atoms%ntypsy(atoms%nat))
      ALLOCATE(atoms%nlhtyp(atoms%ntype))
      ALLOCATE(atoms%invsat(atoms%nat))
      ALLOCATE(atoms%rmt(atoms%ntype))
      ALLOCATE(atoms%dx(atoms%ntype))
      ALLOCATE(atoms%volmts(atoms%ntype))
      ALLOCATE(atoms%rmsh(atoms%jmtd,atoms%ntype))
      ALLOCATE(atoms%zatom(atoms%ntype))
      ALLOCATE(atoms%pos(3,atoms%nat))
      ALLOCATE(atoms%taual(3,atoms%nat))
1401 1402
      ALLOCATE(sym%mrot(3,3,sym%nop))
      ALLOCATE(sym%tau(3,sym%nop))
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419

      dimsInt(:2)=(/3,3/)
      CALL h5dopen_f(groupID, 'amat', amatSetID, hdfError)
      CALL io_read_real2(amatSetID,(/1,1/),dimsInt(:2),cell%amat)
      CALL h5dclose_f(amatSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'nz', nzSetID, hdfError)
      CALL io_read_integer1(nzSetID,(/1/),dimsInt(:1),atoms%nz)
      CALL h5dclose_f(nzSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'neq', neqSetID, hdfError)
      CALL io_read_integer1(neqSetID,(/1/),dimsInt(:1),atoms%neq)
      CALL h5dclose_f(neqSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
1420
      CALL h5dopen_f(groupID, 'jri', jriSetID, hdfError)
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
      CALL io_read_integer1(jriSetID,(/1/),dimsInt(:1),atoms%jri)
      CALL h5dclose_f(jriSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'lmax', lmaxSetID, hdfError)
      CALL io_read_integer1(lmaxSetID,(/1/),dimsInt(:1),atoms%lmax)
      CALL h5dclose_f(lmaxSetID, hdfError)

      dimsInt(:1)=(/atoms%nat/)
      CALL h5dopen_f(groupID, 'ngopr', ngoprSetID, hdfError)
      CALL io_read_integer1(ngoprSetID,(/1/),dimsInt(:1),atoms%ngopr)
      CALL h5dclose_f(ngoprSetID, hdfError)

      dimsInt(:1)=(/atoms%nat/)
      CALL h5dopen_f(groupID, 'ntypsy', ntypsySetID, hdfError)
      CALL io_read_integer1(ntypsySetID,(/1/),dimsInt(:1),atoms%ntypsy)
      CALL h5dclose_f(ntypsySetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'nlhtyp', nlhtypSetID, hdfError)
      CALL io_read_integer1(nlhtypSetID,(/1/),dimsInt(:1),atoms%nlhtyp)
      CALL h5dclose_f(nlhtypSetID, hdfError)

      dimsInt(:1)=(/atoms%nat/)
      CALL h5dopen_f(groupID, 'invsat', invsatSetID, hdfError)
      CALL io_read_integer1(invsatSetID,(/1/),dimsInt(:1),atoms%invsat)
      CALL h5dclose_f(invsatSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'rmt', rmtSetID, hdfError)
      CALL io_read_real1(rmtSetID,(/1/),dimsInt(:1),atoms%rmt)
      CALL h5dclose_f(rmtSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'dx', dxSetID, hdfError)
      CALL io_read_real1(dxSetID,(/1/),dimsInt(:1),atoms%dx)
      CALL h5dclose_f(dxSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'volmts', volmtsSetID, hdfError)
      CALL io_read_real1(volmtsSetID,(/1/),dimsInt(:1),atoms%volmts)
      CALL h5dclose_f(volmtsSetID, hdfError)

      dimsInt(:2)=(/atoms%jmtd,atoms%ntype/)
      CALL h5dopen_f(groupID, 'rmsh', rmshSetID, hdfError)
      CALL io_read_real2(rmshSetID,(/1,1/),dimsInt(:2),atoms%rmsh)
      CALL h5dclose_f(rmshSetID, hdfError)

      dimsInt(:1)=(/atoms%ntype/)
      CALL h5dopen_f(groupID, 'zatom', zatomSetID, hdfError)
      CALL io_read_real1(zatomSetID,(/1/),dimsInt(:1),atoms%zatom)
      CALL h5dclose_f(zatomSetID, hdfError)

      dimsInt(:2)=(/3,atoms%nat/)
      CALL h5dopen_f(groupID, 'pos', posSetID, hdfError)
      CALL io_read_real2(posSetID,(/1,1/),dimsInt(:2),atoms%pos)
      CALL h5dclose_f(posSetID, hdfError)

      dimsInt(:2)=(/3,atoms%nat/)
      CALL h5dopen_f(groupID, 'taual', taualSetID, hdfError)
      CALL io_read_real2(taualSetID,(/1,1/),dimsInt(:2),atoms%taual)
      CALL h5dclose_f(taualSetID, hdfError)

1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
      dimsInt(:3) = (/3,3,sym%nop/)
      CALL h5dopen_f(groupID, 'mrot', mrotSetID, hdfError)
      CALL io_read_integer3(mrotSetID,(/1,1,1/),dimsInt(:3),sym%mrot)
      CALL h5dclose_f(mrotSetID, hdfError)

      dimsInt(:2) = (/3,sym%nop/)
      CALL h5dopen_f(groupID, 'tau', tauSetID, hdfError)
      CALL io_read_real2(tauSetID,(/1,1/),dimsInt(:2),sym%tau)
      CALL h5dclose_f(tauSetID, hdfError)

1494 1495
      !LDA+U data (start)
      IF((fileFormatVersion.GE.29).AND.(atoms%n_u.GT.0)) THEN
1496 1497
         ALLOCATE(ldau_AtomType(atoms%n_u), ldau_l(atoms%n_u), ldau_l_amf(atoms%n_u))
         ALLOCATE(ldau_U(atoms%n_u), ldau_J(atoms%n_u))
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535

         dimsInt(:1)=(/atoms%n_u/)
         CALL h5dopen_f(groupID, 'ldau_AtomType', ldau_AtomTypeSetID, hdfError)
         CALL io_read_integer1(ldau_AtomTypeSetID,(/1/),