EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
diagnostics.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:36:44 pbrowne>
3 !!!
4 !!! Subroutine to give output diagnositics such as rank histograms
5 !!! and trajectories
6 !!! Copyright (C) 2014 Philip A. Browne
7 !!!
8 !!! This program is free software: you can redistribute it and/or modify
9 !!! it under the terms of the GNU General Public License as published by
10 !!! the Free Software Foundation, either version 3 of the License, or
11 !!! (at your option) any later version.
12 !!!
13 !!! This program is distributed in the hope that it will be useful,
14 !!! but WITHOUT ANY WARRANTY; without even the implied warranty of
15 !!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 !!! GNU General Public License for more details.
17 !!!
18 !!! You should have received a copy of the GNU General Public License
19 !!! along with this program. If not, see <http://www.gnu.org/licenses/>.
20 !!!
21 !!! Email: p.browne @ reading.ac.uk
22 !!! Mail: School of Mathematical and Physical Sciences,
23 !!! University of Reading,
24 !!! Reading, UK
25 !!! RG6 6BB
26 !!!
27 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 
31 subroutine diagnostics
32  use output_empire, only : unit_hist_write,unit_hist_readt&
33  &,unit_hist_readp,emp_e
34  use timestep_data
35  use pf_control
36  use sizes
37  use comms
38  use histogram_data
39  implicit none
40  integer, parameter :: rk = kind(1.0d0)
41  real(kind=rk), dimension(rhl_n,pf%nens) :: HHpsi
42  real(kind=rk), dimension(pf%nens) :: bin_marker
43  real(kind=rk), dimension(rhl_n) :: y
44  integer :: particle,time,i,j,mpi_err,lb,length
45  logical :: placed
46  character(32) :: filename
47  integer, dimension(rhn_n,pf%nens+1) :: reduced_talagrand
48  include 'mpif.h'
49 
50  if(.not. pf%gen_data) then
51  if(pf%use_talagrand) then
52 
53  inquire(iolength=length) pf%psi(1,1)
54 
55  do particle = 1,pf%count
56  !write(filename,'(A,i6.6,A,i5.5)') 'hist/timestep',((pf%timestep)/pf&
57  ! &%time_bwn_obs) ,'particle',pf%particles(particle)
58  if(comm_version .eq. 1 .or. comm_version .eq. 2) then
59  write(filename,'(A,i7.7,A,i5.5)') 'hist/timestep',&
60  &pf%timestep,'particle',pf%particles(particle)
61  else
62  write(filename,'(A,i7.7,A,i5.5,A,i0)') 'hist/timestep',&
63  &pf%timestep,'particle',pf%particles(particle),'.',pf_member_rank
64  end if
65  open(unit_hist_write,file=filename,action='write',status='replace',form='unforma&
66  &tted',access='direct',recl=length)
67 
68  do i = 1,rhl_n
69  write(unit_hist_write,rec=i) pf%psi(rank_hist_list(i),particle)
70  end do
71  close(unit_hist_write)
72  end do
73 
74 
75 ! if(pf%timestep .eq. pf%time_obs*pf%time_bwn_obs) then
76  if(tsdata%completed_timesteps .eq. tsdata%total_timesteps) then
77  pf%talagrand = 0
78  call mpi_barrier(pf_mpi_comm,mpi_err)
79 
80  do time = 1,pf%time_obs
81  ! print*,'time = ',time
82  if(mod(time,npfs) .eq. pf_ens_rank) then
83  !cock cock cock adjusted the below to make it sensible
84  !pf%timestep = time*pf%time_bwn_obs
85  pf%timestep = tsdata%obs_times(time)
86 ! print*,'pfrank = ',pfrank,'picking up truth at ',pf%timestep
87 
88  !write(filename,'(A,i6.6,A,i5.5)') 'hist/timestep',((pf%timestep)/pf&
89  ! &%time_bwn_obs) ,'truth'
90  if(comm_version .eq. 1 .or. comm_version .eq. 2) then
91  write(filename,'(A,i7.7,A)') 'hist/timestep',&
92  &pf%timestep,'truth'
93  else
94  write(filename,'(A,i7.7,A,i0)') 'hist/timestep',&
95  &pf%timestep,'truth.',pf_member_rank
96  end if
97 
98  open(unit_hist_readt,file=filename,action='read',status='old',form='unforma&
99  &tted',access='direct',recl=length)
100 
101  do i = 1,rhl_n
102 
103  read(unit_hist_readt,rec=i) y(i)
104 
105  end do
106  close(unit_hist_readt)
107 
108  do particle = 1,pf%nens
109 
110  if(comm_version .eq. 1 .or. comm_version .eq. 2) then
111  write(filename,'(A,i7.7,A,i5.5)') 'hist/timestep',&
112  &pf%timestep,'particle',pf%particles(particle)
113  else
114  write(filename,'(A,i7.7,A,i5.5,A,i0)') 'hist/timestep',&
115  &pf%timestep,'particle',pf&
116  &%particles(particle),'.',pf_member_rank
117  end if
118 
119  open(unit_hist_readp, file=filename,action='read',status='old',&
120  form='unformatted',access='direct',recl=length)
121  do i = 1,rhl_n
122  read(unit_hist_readp,rec=i) hhpsi(i,particle)
123  end do
124  close(unit_hist_readp)
125  end do
126 
127 
128 
129  do j = 1,rhn_n !for each histogram we want to make
130  if( j .eq. 1) then
131  lb = 1
132  else
133  lb = sum(rank_hist_nums(1:j-1)) + 1
134  end if
135  do i = lb,sum(rank_hist_nums(1:j))
136 
137  do particle = 1,pf%nens
138  bin_marker(particle) = hhpsi(i,particle)
139  end do
140 
141  call quicksort_d(bin_marker,pf%nens)
142 
143 
144  ! print*,'quicksorted'
145  placed = .false.
146  do particle = 1,pf%nens
147  if(y(i) .lt. bin_marker(particle)) then
148  pf%talagrand(j,particle) = pf&
149  &%talagrand(j,particle)&
150  & + 1
151  placed = .true.
152  exit
153  end if
154  end do
155 
156 
157  if(.not. placed) then
158  if(y(i) .ge. bin_marker(pf%nens)) then
159  pf%talagrand(j,pf%nens+1) = pf&
160  &%talagrand(j,pf%nens+1) + 1
161  else
162  write(emp_e,*) 'There was an error in the calculation of the p&
163  &lacement &
164  &in the rank histogram. Bums.'
165  stop
166  end if
167  end if
168 
169  end do
170  end do
171 
172  end if !end of mpi splitting by timestep
173  end do !end of the timestep
174  ! print*,'end of all the timesteps'
175 
176  !now let us reduce the information to the master processor:
177  call mpi_reduce(pf%talagrand,reduced_talagrand,rhn_n*(pf%nens+1)&
178  &,mpi_integer,mpi_sum,0,pf_mpi_comm,mpi_err)
179 
180  ! print*,'some reduction just happened'
181 
182  if(pfrank .eq. 0) then
183  do i = 1,rhn_n
184  write(filename,'(A,i0)') 'histogram_',i
185  open(unit_hist_write,file=filename,action='write',status='replace')
186  do j = 1,pf%nens+1
187  write(unit_hist_write,'(i8.8)') reduced_talagrand(i,j)
188  end do
189  close(unit_hist_write)
190  end do
191  !now output the image
192  end if
193  !pf%timestep = pf%time_obs*pf%time_bwn_obs
194  pf%timestep = tsdata%total_timesteps
195  end if !end of if we are the last step in the pf
196 
197  end if
198 
199 
200  else
201  if(pf%use_talagrand) then
202  ! print*,'in diagnostics at timestep ',pf%timestep
203  inquire(iolength=length) pf%psi(1,1)
204 
205  do particle = 1,pf%count
206  !write(filename,'(A,i6.6,A)') 'hist/timestep',((pf%timestep)/pf&
207  ! &%time_bwn_obs) ,'truth'
208  if(comm_version .eq. 1 .or. comm_version .eq. 2) then
209  write(filename,'(A,i7.7,A)') 'hist/timestep',pf&
210  &%timestep,'truth'
211  else
212  write(filename,'(A,i7.7,A,i0)') 'hist/timestep',pf&
213  &%timestep,'truth.',pf_member_rank
214  end if
215  open(unit_hist_write,file=filename,action='write',status='replace',form='unforma&
216  &tted',access='direct',recl=length)
217 
218  do i = 1,rhl_n
219  write(unit_hist_write,rec=i) pf%psi(rank_hist_list(i),particle)
220  end do
221  close(unit_hist_write)
222  end do
223  end if
224  end if
225 end subroutine diagnostics
226 
Module containing EMPIRE coupling data.
Definition: comms.f90:57
Module that stores the information about the outputting from empire.
Module that stores the information about the timestepping process.
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine diagnostics
Subroutine to give output diagnositics such as rank histograms.
Definition: diagnostics.f90:31
Module to control what variables are used to generate rank histograms.
Definition: histogram.f90:29
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29
recursive subroutine quicksort_d(a, na)
subroutine to sort using the quicksort algorithm
Definition: quicksort.f90:9