EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
matrix_pf.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:31:47 pbrowne>
3 !!!
4 !!! module to deal with generating and outputting pf matrix
5 !!! Copyright (C) 2015 Philip A. Browne
6 !!!
7 !!! This program is free software: you can redistribute it and/or modify
8 !!! it under the terms of the GNU General Public License as published by
9 !!! the Free Software Foundation, either version 3 of the License, or
10 !!! (at your option) any later version.
11 !!!
12 !!! This program is distributed in the hope that it will be useful,
13 !!! but WITHOUT ANY WARRANTY; without even the implied warranty of
14 !!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 !!! GNU General Public License for more details.
16 !!!
17 !!! You should have received a copy of the GNU General Public License
18 !!! along with this program. If not, see <http://www.gnu.org/licenses/>.
19 !!!
20 !!! Email: p.browne @ reading.ac.uk
21 !!! Mail: School of Mathematical and Physical Sciences,
22 !!! University of Reading,
23 !!! Reading, UK
24 !!! RG6 6BB
25 !!!
26 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 
29 module matrix_pf
30  implicit none
31  type, public :: matrix_pf_data
32 
35  character(30) :: prefix
37  integer :: k
38  logical :: analysis
39  logical :: frequency
41  integer :: output_type
52 
53  end type matrix_pf_data
54  type(matrix_pf_data), save :: matpf
59 contains
62  use output_empire, only : unit_nml,emp_e
63  implicit none
64  character(30) :: prefix
65  integer :: k=0
66  logical :: analysis=.false.
67  logical :: frequency=.false.
68  integer :: output_type=0
69  logical :: file_exists
70  integer :: ios
71  namelist/mat_pf/k,analysis,frequency,prefix,output_type
72 
73  inquire(file='pf_parameters.dat',exist=file_exists)
74  if(file_exists) then
75  open(unit_nml,file='pf_parameters.dat',iostat=ios,action='read'&
76  &,status='old')
77  if(ios .ne. 0) then
78  write(emp_e,*) 'Cannot open pf_parameters.dat'
79  stop
80  end if
81  else
82  inquire(file='empire.nml',exist=file_exists)
83  if(file_exists) then
84  open(unit_nml,file='empire.nml',iostat=ios,action='read'&
85  &,status='old')
86  if(ios .ne. 0) then
87  write(emp_e,*) 'Cannot open empire.nml'
88  stop
89  end if
90  else
91  write(emp_e,*) 'ERROR: cannot find pf_parameters.dat or empire.nml'
92  stop '-1'
93  end if
94  end if
95 
96  read(unit_nml,nml=mat_pf,iostat=ios)
97  close(unit_nml)
98 
99  if(ios .ne. 0) then
100  print*,'mat_pf not found in namelist file.'
101  print*,'no matrix_pf information will be computed'
102  else
103 
104  matpf%prefix=trim(prefix)
105  matpf%analysis = analysis
106  matpf%frequency= frequency
107  matpf%output_type=output_type
108 
109  if(k.gt.0) then
110  matpf%k=k
111  else
112  write(emp_e,*) 'ERROR: k in matrix_pf_data read in less than 1'
113  write(emp_e,*) 'ERROR: k should be a natural number'
114  write(emp_e,*) 'STOPPING'
115  stop '-1'
116  end if
117  end if
118 
119  print*,'matpf=',matpf
120  call flush(6)
121  end subroutine read_matrix_pf_information
122 
124  subroutine matrix_pf_output(root,comm,n,m,x,time,is_analysis)
125  implicit none
126  include 'mpif.h'
127  integer, parameter :: rk = kind(1.0d0)
128  integer, intent(in) :: root
129  integer, intent(in) :: comm
131  integer, intent(in) :: n
132  integer, intent(in) :: m
133  real(kind=rk), dimension(n,m) :: x
134  integer, intent(in) :: time
135  logical, intent(in) :: is_analysis
136 
137  character(40) :: filename
138  logical :: actually_output=.false.
139  real(kind=rk), dimension(n*(n+1)/2) :: pf
140  integer :: rank,mpi_err
141 
142  actually_output = .false.
143 
144  !check if we should output:
145  if(matpf%analysis .and. is_analysis) actually_output = .true.
146 
147  if(matpf%frequency .and. mod(time,matpf%k) .eq. 0) actually_output=.true.
148 
149  if(matpf%k .gt. 0) print*,'hello: mod(time,matpf%k) = ',mod(time,matpf%k)
150 
151  if(actually_output) then
152 
153  write(filename,'(A,i10.10)') trim(matpf%prefix),time
154 
155  call generate_pf(n,m,comm,x,pf)
156 
157  call mpi_comm_rank(comm,rank,mpi_err)
158  if(rank .eq. root) call output_mat_tri(n,pf,filename,matpf%output_type)
159 
160  end if
161 
162  end subroutine matrix_pf_output
163 end module matrix_pf
module to deal with generating and outputting pf matrix
Definition: matrix_pf.f90:29
Module that stores the information about the outputting from empire.
subroutine read_matrix_pf_information
subroutine to read namelist to control this output
Definition: matrix_pf.f90:61
subroutine matrix_pf_output(root, comm, n, m, x, time, is_analysis)
subroutine to generate and output matrix Pf
Definition: matrix_pf.f90:124
subroutine output_mat_tri(n, A, filename, output_type)
subroutine to output triangluar matrix various formats
subroutine generate_pf(stateDim, cnt, comm, x, pf)
subroutine to generate Pf matrix given ensemble members on a communicator
Definition: generate_pf.f90:31
subroutine k(y, x)
Subroutine to apply to a vector y in observation space where .