-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCDFiles.f90
63 lines (43 loc) · 1.53 KB
/
DCDFiles.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
MODULE DCDFiles
IMPLICIT NONE
INTEGER, PARAMETER :: dcdUnit = 14
PRIVATE
PUBLIC :: ReadDCD, CountAtoms
CONTAINS
SUBROUTINE CountAtoms(fileName,nAtoms)
USE DCDHeader, ONLY : parseHeader
IMPLICIT NONE
CHARACTER(*), INTENT(IN) :: fileName
INTEGER, INTENT(OUT) :: nAtoms
LOGICAL, PARAMETER :: debug = .FALSE.
INTEGER :: nTimesteps
OPEN(UNIT=dcdUnit,FILE=fileName,STATUS='old',FORM='unformatted',ACTION='read')
CALL parseHeader(dcdUnit,debug,nAtoms,nTimesteps)
CLOSE(dcdUnit)
END SUBROUTINE CountAtoms
!*
SUBROUTINE ReadDCD(fileName,coordinates)
USE DCDHeader, ONLY : parseHeader
IMPLICIT NONE
CHARACTER(*), INTENT(IN) :: fileName
REAL(4), INTENT(OUT) :: coordinates(:,:,:)
LOGICAL, PARAMETER :: debug = .FALSE.
INTEGER :: nAtoms, nTimesteps, ios
INTEGER :: timestep, axis
REAL(4), ALLOCATABLE :: data(:,:,:) ! 3 x nAtoms x nTimesteps
OPEN(UNIT=dcdUnit,FILE=fileName,STATUS='old',FORM='unformatted',ACTION='read',IOSTAT=ios)
IF (ios /= 0) STOP "Failed to open unformatted trajectory file"
CALL parseHeader(dcdUnit,debug,nAtoms,nTimesteps)
nTimesteps = nTimesteps - 1
ALLOCATE(data(3,nAtoms,nTimesteps))
DO timestep = 1, nTimesteps
DO axis = 1, 3
READ(dcdUnit,IOSTAT=ios) data(axis,1:nAtoms,timestep)
IF (ios /= 0) STOP "Error reading coordinate line"
ENDDO
ENDDO
coordinates(:,:,:) = data(:,:,:)
IF (ALLOCATED(data)) DEALLOCATE(data)
CLOSE(dcdUnit)
END SUBROUTINE ReadDCD
END MODULE DCDFiles