EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
pf_control.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-11-23 11:47:49 pbrowne>
3 !!!
4 !!! module to hold all the information to control the the main program
5 !!! Copyright (C) 2014 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 pf_control
30  implicit none
31  type, public :: pf_control_type
32  integer :: nens
33  real(kind=kind(1.0D0)), allocatable, dimension(:) :: weight
34  integer :: time_obs
35  integer :: time_bwn_obs
36  real(kind=kind(1.0D0)) :: nudgefac
37  logical :: gen_data
38  logical :: gen_q
40  integer :: timestep=0
41  real(kind=kind(1.0D0)), allocatable, dimension(:,:) :: psi
42  real(kind=kind(1.0D0)), allocatable, dimension(:) :: mean
43  real(kind=kind(1.0D0)) :: nfac
44  real(kind=kind(1.0D0)) :: ufac
45  real(kind=kind(1.0D0)) :: efac
46  real(kind=kind(1.0D0)) :: keep
47  real(kind=kind(1.0D0)) :: time
48  real(kind=kind(1.0D0)) :: qscale
50  real(kind=kind(1.0d0)) :: rho
53  real(kind=kind(1.0d0)) :: len
59  integer :: couple_root
60  logical :: use_talagrand
63  logical :: output_weights
65  logical :: output_forecast
67  logical :: use_mean
68  logical :: use_variance
69  logical :: use_traj
70  logical :: use_spatial_rmse
72  logical :: use_ens_rmse
75  character(250) :: rmse_filename
77  character(250) :: forecast_path
79  character(50) :: relaxation_type
91  real(kind=kind(1.0d0)) :: relaxation_freetime
93  real(kind=kind(1.0d0)) :: power_law_p
95 
96  integer, dimension(:,:), allocatable :: talagrand
97  integer :: count
98  integer,allocatable, dimension(:) :: particles
99  character(2) :: filter
113  character(1) :: init
139 
140  end type pf_control_type
141  type(pf_control_type), save :: pf
142 
143 
144 contains
146  subroutine set_pf_controls
147  use output_empire, only : emp_o
148 
149  write(emp_o,'(A)') 'Opening empire namelist file:'
150 
152 
153  pf%efac = 0.001/pf%nens
154  write(emp_o,'(A)') 'empire namelist successfully read to control pf code.'
155  call flush(emp_o)
156 
157 
158  end subroutine set_pf_controls
159 
160 
215 
217  use var_data
218  use output_empire, only : unit_nml,emp_e
219  implicit none
220  integer :: ios
221 
222  integer :: time_obs=-1
223  integer :: time_bwn_obs=-1
224  real(kind=kind(1.0D0)) :: nudgefac=-1.0d0
225  logical :: gen_data,gen_Q
226  real(kind=kind(1.0D0)) :: nfac=-1.0d0
227  real(kind=kind(1.0D0)) :: ufac=-1.0d0
228  real(kind=kind(1.0D0)) :: Qscale=-1.0d0
229  real(kind=kind(1.0D0)) :: rho=0.0d0
230  real(kind=kind(1.0d0)) :: len=-1.0d0
231  real(kind=kind(1.0D0)) :: keep
232  logical :: use_talagrand,use_mean,use_variance,use_traj&
233  &,use_spatial_rmse,use_ens_rmse,output_weights,output_forecast
234  character(2) :: filter='++'
235  character(1) :: init='+'
236  character(250) :: rmse_filename='rmse'
237  character(250) :: forecast_path='forecast/'
238  character(50) :: relaxation_type='zero_linear'
239  real(kind=kind(1.0d0)) :: power_law_p=1.0d0
240  real(kind=kind(1.0d0)) :: relaxation_freetime=0.6d0
241 
242  logical :: file_exists
243 
244  namelist/pf_params/time_obs,time_bwn_obs,&
245  &nudgefac,&
246  &gen_data,gen_q,&
247  &nfac,&
248  &keep,&
249  &ufac,&
250  &qscale,&
251  &rho,&
252  &len,&
253  &use_talagrand,use_mean,use_variance,use_traj,use_spatial_rmse,use_ens_rmse,&
254  &output_weights,&
255  &output_forecast,&
256  &filter,&
257  &init,&
258  &rmse_filename,&
259  &forecast_path,&
260  &relaxation_type,power_law_p,relaxation_freetime
261 
262 
263  gen_data = .false.
264  gen_q = .false.
265  use_talagrand = .false.
266  use_mean = .false.
267  use_variance = .false.
268  use_traj = .false.
269  use_spatial_rmse = .false.
270  use_ens_rmse = .false.
271  output_weights=.false.
272  output_forecast=.false.
273 
274 
275  inquire(file='pf_parameters.dat',exist=file_exists)
276  if(file_exists) then
277  open(unit_nml,file='pf_parameters.dat',iostat=ios,action='read'&
278  &,status='old')
279  if(ios .ne. 0) then
280  write(emp_e,*) 'Cannot open pf_parameters.dat'
281  stop
282  end if
283  else
284  inquire(file='empire.nml',exist=file_exists)
285  if(file_exists) then
286  open(unit_nml,file='empire.nml',iostat=ios,action='read'&
287  &,status='old')
288  if(ios .ne. 0) stop 'Cannot open empire.nml'
289  else
290  write(emp_e,*) 'ERROR: cannot find pf_parameters.dat or empire.nml'
291  stop '-1'
292  end if
293  end if
294 
295  read(unit_nml,nml=pf_params)
296  close(unit_nml)
297 
298  if(time_obs .gt. -1) then
299  print*,'read time_obs = ',time_obs
300  pf%time_obs = time_obs
301  end if
302  if(time_bwn_obs .gt. -1) then
303  print*,'read time_bwn_obs = ',time_bwn_obs
304  pf%time_bwn_obs = time_bwn_obs
305  end if
306  if(nudgefac .gt. -1.0d0) then
307  print*,'read nudgefac = ',nudgefac
308  pf%nudgefac = nudgefac
309  end if
310 
311  if(nfac .gt. -1.0d0) then
312  print*,'read nfac = ',nfac
313  pf%nfac = nfac
314  end if
315 
316  if(keep .gt. -1.0d0) then
317  print*,'read keep = ',keep
318  pf%keep = keep
319  end if
320 
321  if(ufac .gt. -1.0d0) then
322  print*,'read ufac = ',ufac
323  pf%ufac = ufac
324  end if
325 
326  !real(kind=kind(1.0D0)) :: ufac=-1.0d0
327  if(qscale .gt. -1.0d0) then
328  print*,'read Qscale = ',qscale
329  pf%Qscale = qscale
330  end if
331 
332 
333  if(rho .gt. 0.0d0) then
334  print*,'read rho = ',rho
335  pf%rho = rho
336  elseif(rho .lt. 0.0d0) then
337  print*,'read rho = ',rho,' WARNING ABOUT THAT ONE! rho is nor&
338  &mally positive'
339  pf%rho = rho
340  else
341  pf%rho = rho
342  end if
343 
344 
345  if(len .ge. 0.0d0) then
346  print*,'read len = ',len
347  pf%len = len
348  else
349  pf%len = len
350  end if
351 
352  if(relaxation_type .ne. 'zero_linear') then
353  print*,'read relaxation_type = ',relaxation_type
354  pf%relaxation_type = relaxation_type
355  else
356  pf%relaxation_type = relaxation_type
357  end if
358 
359  if(relaxation_freetime .ne. 0.6d0) then
360  print*,'read relaxation_freetime = ',relaxation_freetime
361  pf%relaxation_freetime = relaxation_freetime
362  else
363  pf%relaxation_freetime = relaxation_freetime
364  end if
365 
366  if(power_law_p .ne. 1.0d0) then
367  print*,'read power_law_p = ',power_law_p
368  pf%power_law_p = power_law_p
369  else
370  pf%power_law_p = power_law_p
371  end if
372 
373 
374  !logical ::
375  !use_talagrand,use_mean,use_variance,use_traj,use_spatial_rmse
376 
377  if(use_spatial_rmse) then
378  print*,'going to output spatial Root mean squared errors'
379  end if
380 
381  if(use_ens_rmse) then
382  print*,'going to output field of Root mean squared errors'
383  end if
384 
385  if(use_mean) then
386  print*,'going to output ensemble mean'
387  end if
388 
389  if(use_variance) then
390  print*,'going to output ensemble variance'
391  end if
392 
393  if(output_weights) then
394  print*,'going to output ensemble weights'
395  end if
396 
397  if(output_forecast) then
398  print*,'going to output ensemble forecasts'
399  end if
400 
401 
402  if(use_traj) then
403  print*,'going to output trajectories'
404  end if
405 
406 
407  if(rmse_filename .ne. 'rmse') then
408  print*,'read rmse_filename = ',rmse_filename
409  end if
410  pf%rmse_filename = rmse_filename
411 
412  if(forecast_path .ne. 'forecast/') then
413  print*,'read forecast_path = ',forecast_path
414  end if
415  pf%forecast_path = forecast_path
416 
417 
418  if(filter .ne. '++') then
419  print*,'read filter = ',filter
420  pf%filter = filter
421  end if
422 
423 
424  !ensure that if we are generating the data then SE is selected
425  if(gen_data) then
426  pf%filter = 'SE'
427  end if
428 
429 
430 
431  !let us verify pf%filter
432  select case(pf%filter)
433  case('EW')
434  print*,'Running the equivalent weights particle filter'
435  case('EZ')
436  print*,'Running the Zhu equal weights particle filter'
437  case('SE')
438  print*,'Running a stochastic ensemble'
439  case('DE')
440  print*,'Running a deterministic ensemble'
441  case('SI')
442  print*,'Running the SIR particle filter'
443  case('ET')
444  print*,'filter read as ET. This is depreciated. Changing to L&
445  &E'
446  pf%filter = 'LE'
447  print*,'Running the Local Ensemble Transform Kalman Filter'
448  print*,'With random noise'
449  print*,'For LETKF without random noise set filter="LD"'
450  case('EA')
451  print*,'Running the Ensemble Adjustment Kalman Filter'
452  write(emp_e,*) 'Error: The EAKF is not implemented here yet'
453  stop '-557'
454  case('LE')
455  print*,'Running the Local Ensemble Transform Kalman Filter'
456  print*,'With random noise'
457  case('LS')
458  print*,'Running the Local Ensemble Transform Kalman Smoother'
459  print*,'With random noise'
460  case('LD')
461  print*,'Running the Local Ensemble Transform Kalman Filter'
462  print*,'With NO random noise'
463  case('3D')
464  print*,'Running a stochastic ensemble and 3DVar at observatio&
465  &n times'
466  call set_var_controls
467  case default
468  write(emp_e,*) 'Error: Incorrect filter type selected:', pf%filter
469  write(emp_e,*) 'Please ensure that pf%filter in empire.nml is either:'
470  write(emp_e,*) 'EW the equivalent weights particle f&
471  &ilter'
472  write(emp_e,*) 'EZ the Zhu equal weights particle f&
473  &ilter'
474  write(emp_e,*) 'SE a stochastic ensemble'
475  write(emp_e,*) 'DE a deterministic ensemble'
476  write(emp_e,*) 'SI the SIR particle filter'
477  write(emp_e,*) 'LE the Local Ensemble Transform Kalman Filter'
478  write(emp_e,*) ' with random noise'
479  write(emp_e,*) 'LD the Local Ensemble Transform Kalman Filter'
480  write(emp_e,*) ' without random noise'
481  write(emp_e,*) 'LS the Local Ensemble Transform Kalman Smoother'
482  write(emp_e,*) ' with random noise'
483  write(emp_e,*) '3D 3DVar'
484  stop
485  end select
486 
487 
488  if(init .ne. '+') then
489  print*,'read init = ',init
490  pf%init = init
491  end if
492 
493  pf%gen_data = gen_data
494  pf%gen_Q = gen_q
495  pf%use_talagrand = use_talagrand
496  pf%use_mean = use_mean
497  pf%use_variance = use_variance
498  pf%use_traj = use_traj
499  pf%use_spatial_rmse = use_spatial_rmse
500  pf%use_ens_rmse = use_ens_rmse
501  pf%output_weights = output_weights
502  pf%output_forecast = output_forecast
503 
504  !check for specific things we can't do if running the truth
505  if(pf%gen_data) then
506  pf%gen_Q = .false.
507  pf%use_talagrand=.false.
508  pf%use_spatial_rmse = .false.
509  pf%use_ens_rmse = .false.
510  pf%output_forecast = .false.
511  end if
512 
513 
514  end subroutine parse_pf_parameters
515 
516 
517 
519  subroutine deallocate_pf
520  deallocate(pf%weight)
521  deallocate(pf%psi)
522  if(allocated(pf%talagrand)) deallocate(pf%talagrand)
523  deallocate(pf%particles)
524  end subroutine deallocate_pf
525 
526 
527 end module pf_control
subroutine parse_pf_parameters
subroutine to read the namelist file and save it to pf datatype Here we read pf_parameters.dat or empire.nml
Definition: pf_control.f90:216
subroutine deallocate_pf
subroutine to deallocate space for the filtering code
Definition: pf_control.f90:519
Module that stores the information about the outputting from empire.
subroutine set_pf_controls
subroutine to ensure pf_control data is ok
Definition: pf_control.f90:146
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29
subroutine set_var_controls
subroutine to ensure vardata is ok
Definition: var_data.f90:98
module holding data for variational problems
Definition: var_data.f90:29
subroutine output_forecast
subroutine to output forecast ensemble to forecast_path