Octopus
xyzanim.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21program xyzanim
23 use global_oct_m
24 use io_oct_m
25 use ions_oct_m
27 use mpi_oct_m
29 use parser_oct_m
31 use unit_oct_m
33
34 implicit none
35
36 integer :: ierr
37
38 ! Initialize stuff
40
41 call getopt_init(ierr)
42 if (ierr == 0) call getopt_xyz_anim()
43 call getopt_end()
44
45 call parser_init()
46
47 call messages_init()
48
50
51 call io_init()
53
55
57
58 call io_end()
59 call messages_end()
60
61 call parser_end()
62 call global_end()
63
64contains
65
66 subroutine generate_xyz_anim()
67
68 character(len=256) :: coords_file, comment
69 integer :: ierr, sampling, i, coords_unit, iter, j, record_length
70 logical :: multifiles
71 real(real64) :: time
72 type(ions_t), pointer :: ions
73
74 ! Sets the filenames
75 coords_file = 'td.general/coordinates'
76
77 !%Variable AnimationSampling
78 !%Type integer
79 !%Default 100
80 !%Section Utilities::oct-xyz-anim
81 !%Description
82 !% Sampling rate of the animation. The animation will be constructed using
83 !% the iteration numbers that are multiples of <tt>AnimationSampling</tt>.
84 !%End
85 call parse_variable(global_namespace, 'AnimationSampling', 100, sampling)
86 if (sampling < 1) then
87 message(1) = 'Sampling rate (AnimationSampling) should be bigger than 0'
88 call messages_fatal(1)
89 end if
90
91 !%Variable AnimationMultiFiles
92 !%Type logical
93 !%Default false
94 !%Section Utilities::oct-xyz-anim
95 !%Description
96 !% If true, each iteration written will be in a separate file.
97 !%End
98 call parse_variable(global_namespace, 'AnimationMultiFiles', .false., multifiles)
99
101
102 record_length = 100 + ions%space%dim*ions%natoms*3*20
103
104 ! Opens the coordinates file
105 coords_unit = io_open(coords_file, ions%namespace, action='read', recl = record_length)
106
107 call io_skip_header(coords_unit)
108 ierr = 0
109 do
110 read(unit = coords_unit, iostat = ierr, fmt = *) iter, time, &
111 ((ions%pos(j, i), j = 1, ions%space%dim), i = 1, ions%natoms)
112 if (ierr < 0) exit
113 if (ierr > 0) then
114 message(1) = 'Error while reading td.general/coordinates'
115 call messages_fatal(1)
116 end if
117 ions%pos = units_to_atomic(units_out%length, ions%pos)
118 if (mod(iter, sampling) == 0) then
119 write(comment, '(i10,f20.6)') iter, time
120 if (.not. multifiles) then
121 call io_mkdir('td.general', global_namespace)
122 call ions%write_xyz('td.general/movie', append = .true., comment = trim(comment))
123 else
124 call io_mkdir('td.general/movie/', ions%namespace)
125 write(coords_file,'(i7.7)')iter
126 call ions%write_xyz('td.general/movie/geo-' // trim(coords_file), append = .false.)
127 end if
128 end if
129 end do
130
131 safe_deallocate_p(ions)
132
133 call io_close(coords_unit)
134
135 end subroutine generate_xyz_anim
136
137end program xyzanim
138
139!! Local Variables:
140!! mode: f90
141!! coding: utf-8
142!! End:
subroutine, public getopt_init(ierr)
Initializes the getopt machinery. Must be called before attempting to parse the options....
subroutine, public getopt_end
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:494
type(mpi_comm), parameter, public serial_dummy_comm
Alias MPI_COMM_UNDEFINED for the specific use case of initialising Octopus utilities with no MPI supp...
Definition: global.F90:294
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:432
Definition: io.F90:116
subroutine, public io_init(defaults)
If the argument defaults is present and set to true, then the routine will not try to read anything f...
Definition: io.F90:165
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public io_skip_header(iunit)
Definition: io.F90:646
subroutine, public io_end()
Definition: io.F90:271
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
subroutine, public messages_end()
Definition: messages.F90:273
subroutine, public messages_init(output_dir)
Definition: messages.F90:220
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
type(namespace_t), public global_namespace
Definition: namespace.F90:135
subroutine, public parser_init()
Initialise the Octopus parser.
Definition: parser.F90:410
subroutine, public parser_end()
End the Octopus parser.
Definition: parser.F90:442
subroutine, public profiling_end(namespace)
Definition: profiling.F90:415
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
Definition: profiling.F90:257
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
subroutine, public unit_system_init(namespace)
int true(void)
program xyzanim
Definition: xyzanim.F90:116
subroutine generate_xyz_anim()
Definition: xyzanim.F90:162