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
20  ! ---------------------------------------------------------
21  subroutine oct_finalcheck(sys, td)
22    type(system_t), intent(inout)      :: sys
23    type(td_t), intent(inout)          :: td
24
25    type(states_elec_t) :: psi
26    type(opt_control_state_t) :: qcpsi
27    FLOAT :: j1, jfunctional, fluence, j2
28
29    type(controlfunction_t), pointer :: par
30
31    PUSH_SUB(oct_finalcheck)
32
33    if(.not.oct%oct_double_check) then
34      POP_SUB(oct_finalcheck)
35      return
36    end if
37
38    call oct_iterator_bestpar(par, iterator)
39
40    call opt_control_state_null(qcpsi)
41    call opt_control_state_copy(qcpsi, initial_st)
42    call propagate_forward(sys, td, par, oct_target, qcpsi, write_iter = .true.)
43    call opt_control_get_qs(psi, qcpsi)
44
45    j1 = target_j1(oct_target, sys%namespace, sys%gr, qcpsi)
46    call opt_control_state_end(qcpsi)
47
48    fluence = controlfunction_fluence(par)
49    j2 = controlfunction_j2(par)
50    jfunctional = j1 + j2
51
52    write(message(1), '(a)') 'Final propagation with the best field'
53    call messages_print_stress(stdout, trim(message(1)))
54    write(message(1), '(6x,a,f12.5)') " => J1       = ", j1
55    write(message(2), '(6x,a,f12.5)') " => J        = ", jfunctional
56    write(message(3), '(6x,a,f12.5)') " => J2       = ", j2
57    write(message(4), '(6x,a,f12.5)') " => Fluence  = ", fluence
58    call messages_info(4)
59    call messages_print_stress(stdout)
60
61    call output_states(sys%outp, sys%namespace, OCT_DIR//'final', psi, sys%gr, sys%geo, sys%hm)
62
63    nullify(par)
64    call states_elec_end(psi)
65    POP_SUB(oct_finalcheck)
66  end subroutine oct_finalcheck
67
68!! Local Variables:
69!! mode: f90
70!! coding: utf-8
71!! End:
72