atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
c3d.F90
Go to the documentation of this file.
1! This file is part of the 'atomes' software.
2!
3! 'atomes' is free software: you can redistribute it and/or modify it under the terms
4! of the GNU Affero General Public License as published by the Free Software Foundation,
5! either version 3 of the License, or (at your option) any later version.
6!
7! 'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8! without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9! See the GNU General Public License for more details.
10!
11! You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12! If not, see <https://www.gnu.org/licenses/>
13!
14! Copyright (C) 2022-2024 by CNRS and University of Strasbourg
15!
20
21INTEGER (KIND=c_int) FUNCTION read_c3d (c3d_f, lc3d) bind (C,NAME='read_c3d_')
22
23!
24! Lecture of atom types and coordinates - C3D files
25!
26
27USE parameters
28
29IMPLICIT NONE
30
31LOGICAL :: isok
32INTEGER (KIND=c_int), INTENT(IN) :: lc3d
33CHARACTER (KIND=c_char), DIMENSION(*), INTENT(IN) :: c3d_f
34CHARACTER (LEN=lc3d) :: c3d_file
35INTERFACE
36INTEGER FUNCTION test_length(UNITFILE, NATL)
37 INTEGER, INTENT(IN) :: unitfile, natl
38END FUNCTION
39END INTERFACE
40
41do i=1, lc3d
42 c3d_file(i:i) = c3d_f(i)
43enddo
44
46
47inquire (file=c3d_file, exist=isok)
48if (isok) then
49
50 open (unit=20, file=c3d_file, action='read', status='old', err=001)
51 ns=0
52 read (20, *, err=002) na
53 ns = test_length(20, na+1)
54 if (ns .eq. 1) then
55 rewind(20)
56 if (allocated(fullpos)) deallocate(fullpos)
57 allocate (fullpos(na,3,ns), stat=err)
58 if (err .ne. 0) then
59 call show_error ("Impossible to allocate memory"//char(0), &
60 "Function: read_c3d"//char(0), "Table: FULLPOS"//char(0))
61 endif
62 if (allocated(tab_of_type)) deallocate(tab_of_type)
63 allocate (tab_of_type(na), stat=err)
64 if (err .ne. 0) then
65 call show_error ("Impossible to allocate memory"//char(0), &
66 "Function: read_c3d"//char(0), "Table: TAB_OF_TYPE"//char(0))
67 endif
68 do i=1, ns
69 read (20, *, err=002)
70 do j=1, na
71 read (20, *, err=002) tab_of_type(j), k, fullpos(j,1,i), fullpos(j,2,i), fullpos(j,3,i)
72 enddo
73 enddo
74 read_c3d=0
75 else
76 read_c3d=2
77 endif
78
79 002 continue
80
81 close (20)
82
83 001 continue
84
85endif
86
87END FUNCTION
88
89INTEGER (KIND=c_int) FUNCTION write_c3d (c3d_f, lc3d, fc3d, tc3d) bind (C,NAME='write_c3d_')
90
91!
92! output of atom types and coordinates - Chem3D files
93!
94
95USE parameters
96
97IMPLICIT NONE
98
99INTEGER (KIND=c_int), INTENT(IN) :: lc3d, fc3d, tc3d
100CHARACTER (KIND=c_char), DIMENSION(*), INTENT(IN) :: c3d_f
101DOUBLE PRECISION, DIMENSION(3) :: savep
102CHARACTER (LEN=lc3d) :: c3d_file
103INTERFACE
104INTEGER FUNCTION test_length(UNITFILE, NATL)
105 INTEGER, INTENT(IN) :: unitfile, natl
106END FUNCTION
107END INTERFACE
108
109do i=1, lc3d
110 c3d_file(i:i) = c3d_f(i)
111enddo
112
113write_c3d=1
114open (unit=20, file=c3d_file, action='write', status='unknown', err=001)
115
116do i=1, ns
117 write (20, '(i10)') na
118 write (20, *)
119 do j=1, na
120 if (fc3d .eq. 1) then
121 if (ncells .gt. 1) then
122 nbox => the_box(i)
123 else
124 nbox => the_box(1)
125 endif
126 savep = matmul(fullpos(j,:,i),nbox%carttofrac)
127 else
128 savep = fullpos(j,:,i)
129 if (tc3d .eq. 1) then
130 savep(:) = savep(:)/angtobohr
131 endif
132 endif
133 write (20, '(a2,3x,i2,3(3x,f15.10))', err=002) tl(lot(j)), 0, savep
134 enddo
135enddo
136write_c3d=0
137
138002 continue
139
140close (20)
141
142001 continue
143
144END FUNCTION
integer(kind=c_int) function read_c3d(c3d_f, lc3d)
Definition c3d.F90:22
integer(kind=c_int) function write_c3d(c3d_f, lc3d, fc3d, tc3d)
Definition c3d.F90:90
action
Definition glview.h:189
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
double precision, dimension(:,:,:), allocatable fullpos
double precision, parameter angtobohr
integer ncells
character(len=2), dimension(:), allocatable tab_of_type
character(len=2), dimension(:), allocatable tl
type(lattice), pointer nbox
integer err
type(lattice), dimension(:), allocatable, target the_box
integer, dimension(:), allocatable lot
integer function test_length(unitfile, natl)
Definition xyz.F90:95