cdnpot_io_hdf.F90 116 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
!--------------------------------------------------------------------------------
! 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

   USE m_types
   USE m_juDFT
#ifdef CPP_HDF
   USE hdf5
   USE m_hdf_tools
#endif
   IMPLICIT NONE

   PRIVATE
#ifdef CPP_HDF
19
   PUBLIC openCDN_HDF, openPOT_HDF, closeCDNPOT_HDF
20 21
   PUBLIC writeStarsHDF, readStarsHDF, peekStarsHDF
   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 isDensityEntryPresentHDF, isPotentialEntryPresentHDF
30
   PUBLIC peekDensityEntryHDF
31 32
#endif

33
   PUBLIC DENSITY_TYPE_UNDEFINED_const
34 35 36
   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
37
   PUBLIC POTENTIAL_TYPE_IN_const, POTENTIAL_TYPE_OUT_const
38

39
   INTEGER,          PARAMETER :: DENSITY_TYPE_UNDEFINED_const = 0
40 41 42 43 44 45
   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

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

49 50
   INTEGER,          PARAMETER :: FILE_FORMAT_VERSION_const = 28

51 52 53 54
   CONTAINS

#ifdef CPP_HDF

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

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

      INTEGER(HID_T) :: generalGroupID
63
      INTEGER        :: hdfError, fileFormatVersion
64 65 66 67 68
      LOGICAL        :: l_exist

      currentStarsIndex = 0
      currentLatharmsIndex = 0
      currentStructureIndex = 0
69
      currentStepfunctionIndex = 0
70 71
      readDensityIndex = 0
      lastDensityIndex = 0
72
      fileFormatVersion = 0
73 74 75 76 77 78 79 80 81 82

      INQUIRE(FILE='cdn.hdf',EXIST=l_exist)
      IF(l_exist) THEN ! only open file
         CALL h5fopen_f('cdn.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)
83
         CALL io_read_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
84 85
         CALL io_read_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
         CALL io_read_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
86
         CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
87 88

         CALL h5gclose_f(generalGroupID, hdfError)
89 90 91 92
         IF(fileFormatVersion.NE.FILE_FORMAT_VERSION_const) THEN
            WRITE(*,'(a,i4)') 'cdn.hdf has file format version ', fileFormatVersion
            CALL juDFT_error('cdn.hdf file format not readable.' ,calledby ="openCDN_HDF")
         END IF
93 94 95 96 97 98 99 100
      ELSE ! create file
         CALL h5fcreate_f('cdn.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)
101
         CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
102 103
         CALL io_write_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
         CALL io_write_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
104
         CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
105 106 107 108 109 110

         CALL h5gclose_f(generalGroupID, hdfError)
      END IF

   END SUBROUTINE openCDN_HDF

111

112 113
   SUBROUTINE openPOT_HDF(fileID,currentStarsIndex,currentLatharmsIndex,&
                          currentStructureIndex,currentStepfunctionIndex)
114 115

      INTEGER(HID_T), INTENT(OUT) :: fileID
116 117
      INTEGER, INTENT(OUT) :: currentStarsIndex,currentLatharmsIndex
      INTEGER, INTENT(OUT) :: currentStructureIndex, currentStepfunctionIndex
118 119

      INTEGER(HID_T) :: generalGroupID
120
      INTEGER        :: hdfError, fileFormatVersion
121 122 123 124 125
      LOGICAL        :: l_exist

      currentStarsIndex = 0
      currentLatharmsIndex = 0
      currentStructureIndex = 0
126
      currentStepfunctionIndex = 0
127
      fileFormatVersion = 0
128 129 130 131 132 133 134 135 136 137

      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)
138
         CALL io_read_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
139
         CALL io_read_attint0(generalGroupID,'fileFormatVersion',fileFormatVersion)
140 141

         CALL h5gclose_f(generalGroupID, hdfError)
142 143 144 145
         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
146 147 148 149 150 151 152 153
      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)
154
         CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
155
         CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
156 157 158 159 160 161 162

         CALL h5gclose_f(generalGroupID, hdfError)
      END IF

   END SUBROUTINE openPOT_HDF

   SUBROUTINE closeCDNPOT_HDF(fileID)
163 164 165 166 167 168 169

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

      INTEGER hdfError

      CALL h5fclose_f(fileID, hdfError)

170
   END SUBROUTINE closeCDNPOT_HDF
171

172
   SUBROUTINE writeCDNHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
173
                                 currentStepfunctionIndex,readDensityIndex,lastDensityIndex)
174 175 176 177 178

      INTEGER(HID_T), INTENT(IN) :: fileID
      INTEGER, INTENT(IN)        :: currentStarsIndex
      INTEGER, INTENT(IN)        :: currentLatharmsIndex
      INTEGER, INTENT(IN)        :: currentStructureIndex
179
      INTEGER, INTENT(IN)        :: currentStepfunctionIndex
180 181
      INTEGER, INTENT(IN)        :: readDensityIndex
      INTEGER, INTENT(IN)        :: lastDensityIndex
182 183 184 185 186 187 188 189 190

      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)
191
      CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
192 193
      CALL io_write_attint0(generalGroupID,'readDensityIndex',readDensityIndex)
      CALL io_write_attint0(generalGroupID,'lastDensityIndex',lastDensityIndex)
194
      CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
195 196 197

      CALL h5gclose_f(generalGroupID, hdfError)

198 199
   END SUBROUTINE writeCDNHeaderData

200 201
   SUBROUTINE writePOTHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,&
                                 currentStructureIndex,currentStepfunctionIndex)
202 203 204 205 206

      INTEGER(HID_T), INTENT(IN) :: fileID
      INTEGER, INTENT(IN)        :: currentStarsIndex
      INTEGER, INTENT(IN)        :: currentLatharmsIndex
      INTEGER, INTENT(IN)        :: currentStructureIndex
207
      INTEGER, INTENT(IN)        :: currentStepfunctionIndex
208 209 210 211 212 213 214 215 216

      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)
217
      CALL io_write_attint0(generalGroupID,'currentStepfunctionIndex',currentStepfunctionIndex)
218
      CALL io_write_attint0(generalGroupID,'fileFormatVersion',FILE_FORMAT_VERSION_const)
219 220 221 222

      CALL h5gclose_f(generalGroupID, hdfError)

   END SUBROUTINE writePOTHeaderData
223

224
   SUBROUTINE writeStarsHDF(fileID, starsIndex, structureIndex, stars)
225 226

      INTEGER(HID_T), INTENT(IN) :: fileID
227
      INTEGER,        INTENT(IN) :: starsIndex, structureIndex
228 229 230 231 232 233 234 235 236 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
      TYPE(t_stars),  INTENT(IN) :: stars

      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

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

      ft2_gf_dim = SIZE(stars%ft2_gfx,1)

265 266
      CALL io_write_attint0(groupID,'structureIndex',structureIndex)

267 268 269 270 271 272 273 274 275 276 277 278 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
      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)

422 423 424
      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: starsIndex
      TYPE(t_stars),  INTENT(INOUT) :: stars
425 426 427 428 429 430 431 432 433 434 435 436 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

      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)
576
      CALL io_read_complex1(pgfftSetID,(/-1,1/),dimsInt(:2),stars%pgfft(0:stars%kimax))
577 578 579 580
      CALL h5dclose_f(pgfftSetID, hdfError)

      dimsInt(:2)=(/2,stars%kimax2+1/)
      CALL h5dopen_f(groupID, 'pgfft2', pgfft2SetID, hdfError)
581
      CALL io_read_complex1(pgfft2SetID,(/-1,1/),dimsInt(:2),stars%pgfft2(0:stars%kimax2))
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
      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

598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
   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

623
   SUBROUTINE writeStepfunctionHDF(fileID, stepfunctionIndex, starsIndex, structureIndex, stars)
624 625

      INTEGER(HID_T), INTENT(IN)    :: fileID
626
      INTEGER,        INTENT(IN)    :: stepfunctionIndex, starsIndex, structureIndex
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
      TYPE(t_stars),  INTENT(IN)    :: stars

      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

      ifftd = size(stars%ufft)

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

      CALL io_write_attint0(groupID,'starsIndex',starsIndex)
653
      CALL io_write_attint0(groupID,'structureIndex',structureIndex)
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
      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
684
      INTEGER                   :: structureIndex
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707

      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)
708
      CALL io_read_attint0(groupID,'structureIndex',structureIndex)
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
      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

738
   SUBROUTINE peekStepfunctionHDF(fileID, stepfunctionIndex, starsIndex, structureIndex)
739 740 741

      INTEGER(HID_T), INTENT(IN)    :: fileID
      INTEGER,        INTENT(IN)    :: stepfunctionIndex
742
      INTEGER,        INTENT(OUT)   :: starsIndex, structureIndex
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758

      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)
759
      CALL io_read_attint0(groupID,'structureIndex',structureIndex)
760 761 762 763
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE peekStepfunctionHDF

764
   SUBROUTINE writeLatharmsHDF(fileID, latharmsIndex, structureIndex, latharms)
765 766

      INTEGER(HID_T), INTENT(IN)  :: fileID
767
      INTEGER,        INTENT(IN)  :: latharmsIndex, structureIndex
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
      TYPE(t_sphhar), INTENT(IN)  :: latharms

      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

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

792
      CALL io_write_attint0(groupID,'structureIndex',structureIndex)
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 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
      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

908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
   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

933
   SUBROUTINE writeStructureHDF(fileID, input, atoms, cell, vacuum, oneD, sym, structureIndex)
934 935 936 937 938 939 940 941

      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
942
      TYPE(t_sym),INTENT(IN)     :: sym
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966

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

      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
967 968
      INTEGER(HID_T)                   :: mrotSpaceID, mrotSetID
      INTEGER(HID_T)                   :: tauSpaceID, tauSetID
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007

      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

      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)

      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)

1008 1009 1010 1011 1012 1013 1014 1015
      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)

1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 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
      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)

1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
      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)

1160 1161 1162 1163
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE writeStructureHDF

1164
   SUBROUTINE readStructureHDF(fileID, input, atoms, cell, vacuum, oneD, sym, structureIndex)
1165 1166 1167 1168 1169 1170 1171 1172

      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
1173
      TYPE(t_sym),INTENT(INOUT)     :: sym
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196

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

      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
1197 1198
      INTEGER(HID_T)                   :: mrotSetID
      INTEGER(HID_T)                   :: tauSetID
1199 1200 1201 1202 1203 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

      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)

1238 1239 1240 1241 1242 1243 1244 1245
      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)

1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
      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)
1261 1262
      IF(ALLOCATED(sym%mrot)) DEALLOCATE(sym%mrot)
      IF(ALLOCATED(sym%tau)) DEALLOCATE(sym%tau)
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278

      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))
1279 1280
      ALLOCATE(sym%mrot(3,3,sym%nop))
      ALLOCATE(sym%tau(3,sym%nop))
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297

      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/)
1298
      CALL h5dopen_f(groupID, 'jri', jriSetID, hdfError)
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 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 1354 1355 1356 1357 1358 1359 1360 1361
      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)

1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
      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)

1372 1373 1374 1375
      CALL h5gclose_f(groupID, hdfError)

   END SUBROUTINE readStructureHDF

1376
   SUBROUTINE writeDensityHDF(input, fileID, archiveName, densityType, previousDensityIndex,&
1377
                              starsIndex, latharmsIndex, structureIndex, stepfunctionIndex,&
1378 1379
                              date,time,distance,fermiEnergy,l_qfix,iter,&
                              fr,fpw,fz,fzxy,cdom,cdomvz,cdomvxy)
1380 1381

      TYPE(t_input),    INTENT(IN) :: input