Changeset 2908

Show
Ignore:
Timestamp:
05/11/07 03:57:00 (3 years ago)
Author:
acastro
Message:

I moved the function restart_look to the states module, where
it belongs. I also collected some code that was replicated in various
places, and put it as a "restart_look_and_read" subroutine.

Location:
trunk/src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/casida.F90

    r2905 r2908  
    9090    call write_info(1) 
    9191 
    92     call restart_look(trim(tmpdir)//'restart_gs', sys%gr%m, kpoints, dim, nst, ierr) 
    93     if(ierr.ne.0) then 
    94       message(1) = 'Could not properly read wave-functions from "'//trim(tmpdir)//'restart_gs".' 
    95       call write_fatal(1) 
    96     end if 
    97  
    98     if(sys%st%d%ispin == SPINORS) then 
    99       message(1) = 'Linear response TDDFT ("Casida" mode) is not implemented for spinors-DFT.' 
    100       call write_fatal(1) 
    101     end if 
    102  
    103     sys%st%nst    = nst 
    104     sys%st%st_end = nst 
    105     deallocate(sys%st%eigenval, sys%st%occ) 
    106  
    107     call states_allocate_wfns(sys%st, sys%gr%m) 
    108  
    109     ALLOCATE(sys%st%eigenval(sys%st%nst, sys%st%d%nik), sys%st%nst*sys%st%d%nik) 
    110     ALLOCATE(sys%st%occ(sys%st%nst, sys%st%d%nik), sys%st%nst*sys%st%d%nik) 
    111  
    112     if(sys%st%d%ispin == SPINORS) then 
    113       ALLOCATE(sys%st%spin(3, sys%st%nst, sys%st%d%nik), sys%st%nst*sys%st%d%nik*3) 
    114       sys%st%spin = M_ZERO 
    115     end if 
    116     sys%st%eigenval = huge(REAL_PRECISION) 
    117     sys%st%occ      = M_ZERO 
    118  
    119     call restart_read(trim(tmpdir)//'restart_gs', sys%st, sys%gr, sys%geo, ierr) 
     92    call restart_look_and_read(trim(tmpdir)//'restart_gs', sys%st, sys%gr, sys%geo, ierr) 
    12093    if(ierr.ne.0) then 
    12194      message(1) = 'Could not properly read wave-functions from "'//trim(tmpdir)//'restart_gs".' 
  • trunk/src/em_resp.F90

    r2905 r2908  
    454454    call push_sub('em_resp.read_wfs') 
    455455 
    456     call restart_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
     456    call states_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    457457 
    458458    if(ierr.ne.0) then 
  • trunk/src/opt_control_defstates.F90

    r2905 r2908  
    5959      !They should also be isolated and taken away, since they are repeated in several places. 
    6060      tmp_st = initial_state 
    61       call restart_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    62       tmp_st%nst    = nst 
    63       tmp_st%st_end = nst 
    64       deallocate(tmp_st%eigenval) 
    65       deallocate(tmp_st%occ) 
    66       call states_allocate_wfns(tmp_st, gr%m) 
    67       ALLOCATE(tmp_st%eigenval(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    68       ALLOCATE(tmp_st%occ(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    69       if(tmp_st%d%ispin == SPINORS) then 
    70         ALLOCATE(tmp_st%spin(3, tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik*3) 
    71         tmp_st%spin = M_ZERO 
    72       end if 
    73       tmp_st%eigenval = huge(REAL_PRECISION) 
    74       tmp_st%occ      = M_ZERO 
    75       call restart_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
    76        
     61      call restart_look_and_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
     62      if(ierr.ne.0) then 
     63        write(message(1),'(a)') 'Could not read ground-state wavefunctions from '//trim(tmpdir)//'restart_gs.' 
     64        call write_fatal(1) 
     65      end if 
    7766      initial_state%zpsi(:, :, 1, 1) = tmp_st%zpsi(:, :, state, 1) 
    7867 
     
    10291 
    10392        tmp_st = initial_state 
    104         call restart_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    105         tmp_st%nst    = nst 
    106         tmp_st%st_end = nst 
    107         deallocate(tmp_st%eigenval) 
    108         deallocate(tmp_st%occ) 
    109         call states_allocate_wfns(tmp_st, gr%m) 
    110         ALLOCATE(tmp_st%eigenval(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    111         ALLOCATE(tmp_st%occ(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    112         if(tmp_st%d%ispin == SPINORS) then 
    113           ALLOCATE(tmp_st%spin(3, tmp_st%nst, tmp_st%d%nik), 3*tmp_st%nst*tmp_st%d%nik) 
    114           tmp_st%spin = M_ZERO 
     93        call restart_look_and_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
     94        if(ierr.ne.0) then 
     95          write(message(1),'(a)') 'Could not read ground-state wavefunctions from '//trim(tmpdir)//'restart_gs.' 
     96          call write_fatal(1) 
    11597        end if 
    116         tmp_st%eigenval = huge(REAL_PRECISION) 
    117         tmp_st%occ      = M_ZERO 
    118         call restart_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
    119  
    12098 
    12199        no_blk = loct_parse_block_n(blk) 
     
    241219      call write_info(1) 
    242220      call restart_read(trim(tmpdir)//'restart_gs', target_state, gr, geo, ierr) 
     221      if(ierr.ne.0) then 
     222        write(message(1),'(a)') 'Could not read ground-state wavefunctions from '//trim(tmpdir)//'restart_gs.' 
     223        call write_fatal(1) 
     224      end if 
    243225       
    244226    case(oct_tg_excited)  
     
    257239      !TODO: The following lines of code do not look too clear, and will probably break easily. 
    258240      tmp_st = target_state 
    259       call restart_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    260       tmp_st%nst    = nst 
    261       tmp_st%st_end = nst 
    262       deallocate(tmp_st%eigenval) 
    263       deallocate(tmp_st%occ) 
    264       call states_allocate_wfns(tmp_st, gr%m) 
    265       ALLOCATE(tmp_st%eigenval(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    266       ALLOCATE(tmp_st%occ(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    267       if(tmp_st%d%ispin == SPINORS) then 
    268         ALLOCATE(tmp_st%spin(3, tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik*3) 
    269         tmp_st%spin = M_ZERO 
    270       end if 
    271       tmp_st%eigenval = huge(REAL_PRECISION) 
    272       tmp_st%occ      = M_ZERO 
    273       call restart_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
     241      call restart_look_and_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
     242      if(ierr.ne.0) then 
     243        write(message(1),'(a)') 'Could not read ground-state wavefunctions from '//trim(tmpdir)//'restart_gs.' 
     244        call write_fatal(1) 
     245      end if 
    274246 
    275247      target_state%zpsi(:, :, 1, 1) = tmp_st%zpsi(:, :, state, 1) 
     
    300272 
    301273        tmp_st = target_state 
    302         call restart_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    303         tmp_st%nst    = nst 
    304         tmp_st%st_end = nst 
    305         deallocate(tmp_st%eigenval) 
    306         deallocate(tmp_st%occ) 
    307         call states_allocate_wfns(tmp_st, gr%m) 
    308         ALLOCATE(tmp_st%eigenval(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    309         ALLOCATE(tmp_st%occ(tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik) 
    310         if(tmp_st%d%ispin == SPINORS) then 
    311           ALLOCATE(tmp_st%spin(3, tmp_st%nst, tmp_st%d%nik), tmp_st%nst*tmp_st%d%nik*3) 
    312           tmp_st%spin = M_ZERO 
     274        call restart_look_and_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
     275        if(ierr.ne.0) then 
     276          write(message(1),'(a)') 'Could not read ground-state wavefunctions from '//trim(tmpdir)//'restart_gs.' 
     277          call write_fatal(1) 
    313278        end if 
    314         tmp_st%eigenval = huge(REAL_PRECISION) 
    315         tmp_st%occ      = M_ZERO 
    316         call restart_read(trim(tmpdir)//'restart_gs', tmp_st, gr, geo, ierr) 
    317279 
    318280        no_blk = loct_parse_block_n(blk) 
  • trunk/src/phonons_lr.F90

    r2905 r2908  
    297297    call push_sub('em_resp.read_wfs') 
    298298 
    299     call restart_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    300  
     299    call states_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, ierr) 
    301300    if(ierr.ne.0) then 
    302301      message(1) = 'Could not properly read wave-functions from "'//trim(tmpdir)//'restart_gs".' 
  • trunk/src/restart.F90

    r2820 r2908  
    5050    restart_read,       & 
    5151    restart_format,     & 
    52     restart_look,       & 
     52    restart_look_and_read,   & 
    5353    drestart_write_function, & 
    5454    zrestart_write_function, & 
     
    149149 
    150150  ! --------------------------------------------------------- 
    151   subroutine restart_look (dir, m, kpoints, dim, nst, ierr) 
    152     character(len=*), intent(in) :: dir 
    153     type(mesh_t),     intent(in) :: m 
    154     integer,         intent(out) :: kpoints, dim, nst, ierr 
    155  
    156     character(len=256) :: line 
    157     character(len=12)  :: filename 
    158     character(len=1)   :: char 
    159     integer :: iunit, iunit2, err, i, ist, idim, ik 
    160     FLOAT :: occ, eigenval 
    161  
    162     call push_sub('restart.restart_look') 
    163  
    164     ierr = 0 
    165     iunit  = io_open(trim(dir)//'/wfns', action='read', status='old', die=.false., is_tmp = .true., grp = m%mpi_grp) 
    166     if(iunit < 0) then 
    167       ierr = -1 
    168       return 
    169     end if 
    170     iunit2 = io_open(trim(dir)//'/occs', action='read', status='old', die=.false., is_tmp = .true., grp = m%mpi_grp) 
    171     if(iunit2 < 0) then 
    172       call io_close(iunit, grp = m%mpi_grp) 
    173       ierr = -1 
    174       return 
    175     end if 
    176  
    177     ! Skip two lines. 
    178     call iopar_read(m%mpi_grp, iunit, line, err); call iopar_read(m%mpi_grp, iunit, line, err) 
    179     call iopar_read(m%mpi_grp, iunit2, line, err); call iopar_read(m%mpi_grp, iunit2, line, err) 
    180  
    181     kpoints = 1 
    182     dim = 1 
    183     nst = 1 
    184     do 
    185       call iopar_read(m%mpi_grp, iunit, line, i) 
    186       read(line, '(a)') char 
    187       if(i.ne.0.or.char=='%') exit 
    188       read(line, *) ik, char, ist, char, idim, char, filename 
    189       if(ik > kpoints) kpoints = ik 
    190       if(idim == 2)    dim     = 2 
    191       if(ist>nst)      nst     = ist 
    192       call iopar_read(m%mpi_grp, iunit2, line, err) 
    193       read(line, *) occ, char, eigenval 
    194     end do 
    195  
    196     call io_close(iunit, grp = m%mpi_grp) 
    197     call io_close(iunit2, grp = m%mpi_grp) 
     151  subroutine restart_look_and_read(dir, st, gr, geo, ierr) 
     152    character(len=*),  intent(in)  :: dir 
     153    type(states_t), intent(inout)  :: st 
     154    type(grid_t),      intent(in)  :: gr 
     155    type(geometry_t),  intent(in)  :: geo 
     156    integer,           intent(out) :: ierr 
     157 
     158    integer :: kpoints, dim, nst, j 
     159 
     160    call push_sub('restart.restart_look_and_read') 
     161 
     162    call states_look(trim(tmpdir)//'restart_gs', gr%m, kpoints, dim, nst, j) 
     163    if(j.ne.0) then 
     164      ierr = j 
     165      call pop_sub(); return 
     166    end if 
     167 
     168    st%nst    = nst 
     169    st%st_end = nst 
     170    deallocate(st%eigenval, st%occ) 
     171 
     172    call states_allocate_wfns(st, gr%m) 
     173 
     174    ALLOCATE(st%eigenval(st%nst, st%d%nik), st%nst*st%d%nik) 
     175    ALLOCATE(st%occ(st%nst, st%d%nik), st%nst*st%d%nik) 
     176 
     177    if(st%d%ispin == SPINORS) then 
     178      ALLOCATE(st%spin(3, st%nst, st%d%nik), st%nst*st%d%nik*3) 
     179      st%spin = M_ZERO 
     180    end if 
     181    st%eigenval = huge(REAL_PRECISION) 
     182    st%occ      = M_ZERO 
     183 
     184    call restart_read(trim(tmpdir)//'restart_gs', st, gr, geo, ierr) 
     185 
    198186    call pop_sub() 
    199   end subroutine restart_look 
     187  end subroutine restart_look_and_read 
     188 
    200189 
    201190  ! --------------------------------------------------------- 
  • trunk/src/states.F90

    r2905 r2908  
    4848    states_dim_t,                     & 
    4949    states_init,                      & 
     50    states_look,                      & 
    5051    states_read_user_def_orbitals,    & 
    5152    states_densities_init,            & 
     
    18981899 
    18991900 
     1901  ! --------------------------------------------------------- 
     1902  ! Reads the state stored in directory "dir", and finds out 
     1903  ! the kpoints, dim, and nst contained in it. 
     1904  ! --------------------------------------------------------- 
     1905  subroutine states_look (dir, m, kpoints, dim, nst, ierr) 
     1906    character(len=*), intent(in) :: dir 
     1907    type(mesh_t),     intent(in) :: m 
     1908    integer,         intent(out) :: kpoints, dim, nst, ierr 
     1909 
     1910    character(len=256) :: line 
     1911    character(len=12)  :: filename 
     1912    character(len=1)   :: char 
     1913    integer :: iunit, iunit2, err, i, ist, idim, ik 
     1914    FLOAT :: occ, eigenval 
     1915 
     1916    call push_sub('states.states_look') 
     1917 
     1918    ierr = 0 
     1919    iunit  = io_open(trim(dir)//'/wfns', action='read', status='old', die=.false., is_tmp = .true., grp = m%mpi_grp) 
     1920    if(iunit < 0) then 
     1921      ierr = -1 
     1922      return 
     1923    end if 
     1924    iunit2 = io_open(trim(dir)//'/occs', action='read', status='old', die=.false., is_tmp = .true., grp = m%mpi_grp) 
     1925    if(iunit2 < 0) then 
     1926      call io_close(iunit, grp = m%mpi_grp) 
     1927      ierr = -1 
     1928      return 
     1929    end if 
     1930 
     1931    ! Skip two lines. 
     1932    call iopar_read(m%mpi_grp, iunit, line, err); call iopar_read(m%mpi_grp, iunit, line, err) 
     1933    call iopar_read(m%mpi_grp, iunit2, line, err); call iopar_read(m%mpi_grp, iunit2, line, err) 
     1934 
     1935    kpoints = 1 
     1936    dim = 1 
     1937    nst = 1 
     1938    do 
     1939      call iopar_read(m%mpi_grp, iunit, line, i) 
     1940      read(line, '(a)') char 
     1941      if(i.ne.0.or.char=='%') exit 
     1942      read(line, *) ik, char, ist, char, idim, char, filename 
     1943      if(ik > kpoints) kpoints = ik 
     1944      if(idim == 2)    dim     = 2 
     1945      if(ist>nst)      nst     = ist 
     1946      call iopar_read(m%mpi_grp, iunit2, line, err) 
     1947      read(line, *) occ, char, eigenval 
     1948    end do 
     1949 
     1950    call io_close(iunit, grp = m%mpi_grp) 
     1951    call io_close(iunit2, grp = m%mpi_grp) 
     1952    call pop_sub() 
     1953  end subroutine states_look 
     1954 
     1955 
    19001956#include "states_kpoints.F90" 
    19011957 
  • trunk/src/td_write.F90

    r2905 r2908  
    195195!!$      nullify(w%gs_st%zpsi, w%gs_st%node, w%gs_st%occ, w%gs_st%eigenval, w%gs_st%mag) 
    196196      nullify(w%gs_st%zpsi, w%gs_st%node, w%gs_st%occ, w%gs_st%eigenval) 
    197       call restart_look (trim(tmpdir)//'restart_gs', gr%m, i, i, w%gs_st%nst, ierr) 
     197      call states_look (trim(tmpdir)//'restart_gs', gr%m, i, i, w%gs_st%nst, ierr) 
    198198 
    199199      w%gs_st%st_start = 1