eig66_io.F90 6.12 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 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.
!--------------------------------------------------------------------------------

7 8
MODULE m_eig66_io
#include "juDFT_env.h"
9
  USE m_types
10 11 12
  USE m_eig66_data
  IMPLICIT NONE
  PRIVATE
13

14 15 16
  PUBLIC open_eig,close_eig
  PUBLIC read_eig, write_eig
CONTAINS
17

18
  FUNCTION open_eig(mpi_comm,nmat,neig,nkpts,jspins,&
19
                    l_noco,l_create,l_real,l_soc,l_readonly,n_size,mode_in,filename)&
20
           RESULT(id)
21 22 23 24 25
    USE m_eig66_hdf,ONLY:open_eig_hdf=>open_eig
    USE m_eig66_DA ,ONLY:open_eig_DA=>open_eig
    USE m_eig66_mem,ONLY:open_eig_mem=>open_eig
    USE m_eig66_MPI,ONLY:open_eig_mpi=>open_eig
    IMPLICIT NONE
26
    INTEGER,INTENT(IN)          :: nmat,neig,nkpts,jspins,mpi_comm
27
    LOGICAL,INTENT(IN)          :: l_noco,l_readonly,l_create,l_real,l_soc
28 29 30 31 32
    INTEGER,INTENT(IN),OPTIONAL :: n_size,mode_in
    CHARACTER(LEN=*),INTENT(IN),OPTIONAL :: filename
    INTEGER:: id,mode

    INTEGER:: neig_local,isize,err
33 34 35 36 37
    if (l_soc) THEN
       neig_local=2*neig
    else
       neig_local=neig
    endif
38
    mode=-1
39
    IF (PRESENT(mode_in)) mode=mode_in
40 41 42 43 44 45 46 47 48

    IF (mode<0) THEN
       !Use default mode
#ifdef CPP_MPI
       mode=MPI_mode
#else
       mode=MEM_mode
#endif
       !check if default was given on command-line
49 50 51 52
       IF (juDFT_was_argument("-mpi")) mode=MPI_mode
       IF (juDFT_was_argument("-mem")) mode=MEM_mode
       IF (juDFT_was_argument("-da")) mode=DA_mode
       IF (juDFT_was_argument("-hdf")) mode=HDF_mode
53 54 55
    ENDIF
    !Check if mode is available
#ifndef CPP_MPI
56
    IF (mode==MPI_mode) CALL juDFT_error("MPI-mode not available. Recompile with CPP_MPI",calledby="eig66_io")
57
#else
58 59 60
    CALL MPI_COMM_SIZE(mpi_comm,isize,err)
    IF (isize>1.AND.((mode==DA_mode.OR.mode==mem_mode))) &
         CALL juDFT_error("In a parallel calculation MEM/DA-mode are not available",calledby="eig66_io")
61 62
#endif
#ifndef CPP_HDF
63
    IF (mode==HDF_mode) CALL juDFT_error("HDF-mode not available. Recompile with CPP_HDF",calledby="eig66_io")
64 65
#endif

66
    id=eig66_data_newid(mode)
67

Daniel Wortmann's avatar
Daniel Wortmann committed
68
    !PRINT *,"open_eig:",id,mode
69

70
    CALL timestart("Open file/memory for IO of eig66")
71
    SELECT CASE (eig66_data_mode(id))
72
    CASE (DA_mode)
73
       CALL open_eig_DA(id,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,filename)
74
    CASE (hdf_mode)
75
       CALL open_eig_HDF(id,mpi_comm,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,l_readonly,filename)
76
    CASE (mem_mode)
77
       CALL open_eig_MEM(id,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,l_noco,filename)
78
    CASE (mpi_mode)
79
       CALL open_eig_MPI(id,mpi_comm,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,l_noco,n_size,filename)
80 81
    CASE DEFAULT
       CALL juDFT_error("Invalid IO-mode in eig66_io")
82
    END SELECT
83 84
    CALL timestop("Open file/memory for IO of eig66")
  END FUNCTION open_eig
85

86
  SUBROUTINE close_eig(id,filename)
87 88 89 90 91 92 93 94 95
    USE m_eig66_hdf,ONLY:close_eig_hdf=>close_eig
    USE m_eig66_DA ,ONLY:close_eig_DA=>close_eig
    USE m_eig66_mem,ONLY:close_eig_MEM=>close_eig
    USE m_eig66_MPI,ONLY:close_eig_MPI=>close_eig
    IMPLICIT NONE
    INTEGER,INTENT(IN)                   :: id
    CHARACTER(LEN=*),INTENT(IN),OPTIONAL :: filename
    INTEGER  :: mode
    mode=eig66_data_mode(id)
Daniel Wortmann's avatar
Daniel Wortmann committed
96
    !PRINT*,"close_eig:",id,mode
97
    SELECT CASE (mode)
98 99 100 101 102 103 104 105 106 107
    CASE (DA_mode)
       CALL close_eig_DA(id,filename)
    CASE (hdf_mode)
       CALL close_eig_HDF(id,filename)
    CASE (mem_mode)
       CALL close_eig_Mem(id,filename=filename)
    CASE (MPI_mode)
       CALL close_eig_MPI(id,filename=filename)
    CASE (-1)
       CALL juDFT_error("ID not assigned in close_eig",calledby="eig66_io")
108 109
    END SELECT

110
  END SUBROUTINE close_eig
111

112
  SUBROUTINE read_eig(id,nk,jspin,neig,eig,w_iks,n_start,n_end,zmat)
113 114 115 116 117 118 119
    USE m_eig66_hdf,ONLY:read_eig_hdf=>read_eig
    USE m_eig66_DA ,ONLY:read_eig_DA=>read_eig
    USE m_eig66_mem,ONLY:read_eig_mem=>read_eig
    USE m_eig66_MPI,ONLY:read_eig_MPI=>read_eig
    IMPLICIT NONE
    INTEGER, INTENT(IN)            :: id,nk,jspin
    INTEGER, INTENT(OUT),OPTIONAL  :: neig
Daniel Wortmann's avatar
Daniel Wortmann committed
120
    REAL,    INTENT(OUT),OPTIONAL  :: eig(:),w_iks(:)
121
    INTEGER, INTENT(IN),OPTIONAL   :: n_start,n_end
122
    TYPE(t_mat),INTENT(INOUT),OPTIONAL  :: zmat
123 124 125
    INTEGER::n
    CALL timestart("IO (read)")
    SELECT CASE (eig66_data_mode(id))
126
    CASE (DA_mode)
127
       CALL read_eig_DA(id,nk,jspin,neig,eig,w_iks,n_start,n_end,zmat)
128
    CASE (hdf_mode)
129
       CALL read_eig_hdf(id,nk,jspin,neig,eig,w_iks,n_start,n_end,zmat)
130
    CASE (mem_mode)
131
       CALL read_eig_mem(id,nk,jspin,neig,eig,w_iks,n_start,n_end,zmat)
132
    CASE (mpi_mode)
133
       CALL read_eig_mpi(id,nk,jspin,neig,eig,w_iks,n_start,n_end,zmat)
134
    CASE (-1)
135
       CALL juDFT_error("Could not read eig-file before opening", calledby = "eig66_io")
136
    END SELECT
137 138
    CALL timestop("IO (read)")
  END SUBROUTINE read_eig
139

140
  SUBROUTINE write_eig(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
141 142 143 144 145 146
    USE m_eig66_hdf,ONLY:write_eig_hdf=>write_eig
    USE m_eig66_DA ,ONLY:write_eig_DA=>write_eig
    USE m_eig66_mem,ONLY:write_eig_MEM=>write_eig
    USE m_eig66_MPI,ONLY:write_eig_MPI=>write_eig
    IMPLICIT NONE
    INTEGER, INTENT(IN) :: id,nk,jspin
147 148
    INTEGER, INTENT(IN),OPTIONAL :: neig,neig_total,n_start,n_end
    REAL,    INTENT(IN),OPTIONAL :: eig(:),w_iks(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
149
    TYPE(t_Mat),INTENT(IN),OPTIONAL :: zmat
150 151 152
    CALL timestart("IO (write)")
    SELECT CASE (eig66_data_mode(id))
    CASE (da_mode)
153
       CALL write_eig_DA(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
154
    CASE (hdf_mode)
155
       CALL write_eig_HDF(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
156
    CASE (mem_mode)
157
       CALL write_eig_Mem(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
158
    CASE (MPI_mode)
159
       CALL write_eig_MPI(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
160
    CASE (-1)
161
       CALL juDFT_error("Could not write eig-file before opening", calledby = "eig66_io")
162 163 164 165
    END SELECT
    CALL timestop("IO (write)")
  END SUBROUTINE write_eig

166
END MODULE m_eig66_io