forked from Huaguiyuan/fold2Bloch-VASP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_f2b.f90
77 lines (71 loc) · 2.62 KB
/
open_f2b.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
!!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! open_f2b
!!!
!!! It opens the file *.f2b to write output of unfolding and also
!!! checks if this file already exists. In later case add '_#' to the
!!! file name.
!!!
!!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SUBROUTINE open_f2b(idf2b, isp, spinor, & ! <- args in
f2bfile) ! -> args out
IMPLICIT NONE
INTEGER, INTENT(inout) :: idf2b ! ID for the output file
INTEGER, INTENT(in) :: isp ! spin 1 or 2
LOGICAL, INTENT(in) :: spinor ! WF spinor?
CHARACTER(len=256), INTENT(out) :: f2bfile ! name of the output file
CHARACTER(len=256) :: f2bfile1 ! name of the output file
INTEGER*4 :: digit ! to make output file unique, e.g., WAVECAR.f2b_3
CHARACTER(len=4) :: cdigit ! name of the output file
LOGICAL :: res ! used when checking the file presence
write (cdigit,'(I0)') isp
IF (spinor) THEN
f2bfile='WAVECAR_spinor' // TRIM(cdigit) // '.f2b'
ELSE
f2bfile='WAVECAR_spin' // TRIM(cdigit) // '.f2b'
ENDIF
digit=0 ! initialize
res=.True. ! assume output file is already present
f2bfile1=f2bfile
DO WHILE (res)
INQUIRE(file=f2bfile1, exist=res)
IF (res) THEN ! file exists
WRITE(6,*) 'The output file "', TRIM(f2bfile1), &
'" exists, generate an alternative name'
digit=digit+1
IF (digit .gt. 100) THEN
WRITE(6,*) 'You need to clean previous output files (>100)'
WRITE(6,*) 'Exit'
STOP
ENDIF
write (cdigit,'(I0)') digit
f2bfile1=TRIM(f2bfile) // '_' // TRIM(cdigit)
write(6,*) 'Will try the new output file name: ', TRIM(f2bfile1)
ENDIF
END DO
f2bfile=f2bfile1
OPEN(idf2b, file=f2bfile, status='new', action='write')
IF (spinor) THEN
f2bfile='WAVECAR_spinor2.f2b'
digit=digit-1 ! initialize
res=.True. ! assume output file is already present
f2bfile1=f2bfile
DO WHILE (res)
INQUIRE(file=f2bfile1, exist=res)
IF (res) THEN ! file exists
WRITE(6,*) 'The output file "', TRIM(f2bfile1), &
'" exists, generate an alternative name'
digit=digit+1
IF (digit .gt. 100) THEN
WRITE(6,*) 'You need to clean previous output files (>100)'
WRITE(6,*) 'Exit'
STOP
ENDIF
write (cdigit,'(I0)') digit
f2bfile1=TRIM(f2bfile) // '_' // TRIM(cdigit)
write(6,*) 'Will try the new output file name: ', TRIM(f2bfile1)
ENDIF
END DO
f2bfile=f2bfile1
OPEN(idf2b+1, file=f2bfile, status='new', action='write') ! 2nd spinor out file
ENDIF
END SUBROUTINE open_f2b