read_upf_tofile.f90 2.71 KB
Newer Older
1
!
giannozz's avatar
giannozz committed
2
! Copyright (C) 2006 Quantum ESPRESSO group
3 4 5 6 7 8
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!---------------------------------------------------------------------
9
PROGRAM read_upf_tofile
10 11
  !---------------------------------------------------------------------
  !
12
  !   This small program reads the pseudopotential in the Unified
13 14 15 16 17 18 19 20 21 22 23
  !   Pseudopotential Format and writes three files
  !   in a format which can be plotted. The files are:
  !
  !   filewfc    with the pseudo-wavefunctions
  !   filebeta   with the beta functions
  !   filepot    with the local potential, the valence and core charge.
  !
  !
  ! PWSCF modules
  !
  !
24
  USE constants, ONLY : fpi
dalcorso's avatar
dalcorso committed
25 26 27
  USE pseudo_types, ONLY : pseudo_upf, nullify_pseudo_upf, &
                           deallocate_pseudo_upf
  USE upf_module, ONLY : read_upf
28
  USE radial_grids, ONLY : radial_grid_type, nullify_radial_grid
29 30 31 32 33 34 35 36 37 38 39
  !
  IMPLICIT NONE
  !
  INTEGER :: iunps, ierr
  !
  CHARACTER(30) :: file_pseudo
  !
  !     Local variables
  !
  INTEGER :: ios, n, j
  TYPE (pseudo_upf) :: upf
40
  TYPE (radial_grid_type) :: grid
41
  !
42
  WRITE(6,'("Name of the upf file > ")', advance="NO")
43
  READ(5,'(a)') file_pseudo
44

45
  !  nullify objects as soon as they are instantiated
46

47 48 49
  CALL nullify_pseudo_upf( upf )
  CALL nullify_radial_grid( grid )

50 51 52 53 54
  iunps=2
  OPEN(UNIT=iunps,FILE=file_pseudo,STATUS='old',FORM='formatted', &
       ERR=100, IOSTAT=ios)
100   CALL errore('read_upf_tofile','open error on file '//file_pseudo,ios)

55
  CALL read_upf(upf, grid, ierr, unit=iunps)
56
  !
57
  IF (ierr /= 0 .AND. ierr /=-1) &
58
     CALL errore('read_upf_tofile','reading pseudo upf', abs(ierr))
59 60 61 62 63
  !
  CLOSE(iunps)
  !
  OPEN(UNIT=iunps,FILE='filewfc',STATUS='unknown',FORM='formatted', &
       ERR=200, IOSTAT=ios)
64
200   CALL errore('read_upf_tofile','open error on file filewfc',abs(ios))
65 66 67

  DO n=1,upf%mesh
     WRITE(iunps,'(30f12.6)') upf%r(n), (upf%chi(n,j), j=1,upf%nwfc)
68
  ENDDO
69 70 71 72 73

  CLOSE(iunps)

  OPEN(UNIT=iunps,FILE='filebeta',STATUS='unknown',FORM='formatted', &
       ERR=300, IOSTAT=ios)
74
300   CALL errore('read_upf_tofile','open error on file filebeta',abs(ios))
75 76 77

  DO n=1,upf%mesh
     WRITE(iunps,'(30f12.6)') upf%r(n), (upf%beta(n,j), j=1,upf%nbeta)
78
  ENDDO
79 80 81 82 83

  CLOSE(iunps)

  OPEN(UNIT=iunps,FILE='filepot',STATUS='unknown',FORM='formatted', &
       ERR=400, IOSTAT=ios)
84
400   CALL errore('read_upf_tofile','open error on file filepot',abs(ios))
85 86

  DO n=1,upf%mesh
dalcorso's avatar
dalcorso committed
87
     WRITE(iunps,'(4f12.6)') upf%r(n), upf%vloc(n), &
88 89
               upf%rho_at(n), upf%rho_atc(n)*fpi*upf%r(n)**2
  ENDDO
90 91 92 93 94 95

  CLOSE(iunps)

  CALL deallocate_pseudo_upf( upf )

END PROGRAM read_upf_tofile