EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
trajectories.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:40:19 pbrowne>
3 !!!
4 !!! Subroutine to output trajectories of state variables
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 module traj_data
29  integer :: trajn
30  integer, allocatable, dimension(:) :: trajvar
31  character(28), parameter :: traj_list='traj_list.dat'
32  contains
45  subroutine setup_traj
46  use output_empire, only : unit_traj_read,emp_e
47  use comms
48  use sizes, only : state_dim_g
49  logical :: dir_e,file_e
50  integer :: i
51  integer :: counter,lowerbound,upperbound
52  integer, allocatable, dimension(:) :: tempvar
53  !first check that the traj directory exists:
54  ! a trick to be sure traj is a dir
55  inquire( file="./traj/.", exist=dir_e )
56  if ( .not. dir_e ) then
57  write(emp_e,*) 'EMPIRE ERROR -559: ./traj/ directory does not exi&
58  &st'
59  write(emp_e,*) 'Please create the directory traj/ in the folder t&
60  &hat you wish to run'
61  stop '-559'
62  end if
63 
64  !now we check to see that traj_list.dat exists:
65  inquire( file=traj_list, exist=file_e )
66  if ( .not. file_e ) then
67  write(emp_e,*) 'EMPIRE ERROR -560: file ',traj_list,' does not exi&
68  &st'
69  write(emp_e,*) 'This file should contain a list of state variable&
70  &s'
71  write(emp_e,*) 'for which you want to output trajectories'
72  stop '-560'
73  end if
74 
75  open(unit_traj_read,file=traj_list,action='read')
76  read(unit_traj_read,*) trajn
77 
78  allocate(trajvar(trajn))
79 
80  do i = 1,trajn
81  read(unit_traj_read,*) trajvar(i)
82  if(trajvar(i) .le. 0) then
83  write(emp_e,*) 'EMPIRE ERROR -561: trajectory variable ',i,' less &
84  &than 0'
85  write(emp_e,*) ' : variable read as',trajvar(i),' &
86  &STOP.'
87  stop '-561'
88  elseif(trajvar(i) .gt. state_dim_g) then
89  write(emp_e,*) 'EMPIRE ERROR -562: trajectory variable ',i,' larger &
90  &than the state dimension ',state_dim_g
91  write(emp_e,*) ' : variable read as',trajvar(i),' &
92  &STOP.'
93  stop '-562'
94  end if
95  end do
96 
97  close(unit_traj_read)
98 
99 
100  if(comm_version .eq. 3) then
101 
102  lowerbound = state_displacements(pf_member_rank+1)
103  if(pf_member_rank .eq. pf_member_size-1) then
104  upperbound = state_dim_g
105  else
106  upperbound = state_displacements(pf_member_rank+2)
107  end if
108 
109  counter = 0
110  do i = 1,trajn
111  if(trajvar(i) .gt. lowerbound .and. trajvar(i) .le.&
112  & upperbound) then
113  counter = counter + 1
114  end if
115  end do
116 
117  allocate(tempvar(trajn))
118  tempvar = trajvar
119  deallocate(trajvar)
120  allocate(trajvar(counter))
121 
122  counter = 0
123  do i = 1,trajn
124  if(tempvar(i) .gt. lowerbound .and. tempvar(i) .le.&
125  & upperbound) then
126  counter = counter + 1
127  trajvar(counter) = tempvar(i)
128  end if
129  end do
130  deallocate(tempvar)
131  trajvar = trajvar - lowerbound
132 
133  end if
134 
135  end subroutine setup_traj
136 
137  subroutine deallocate_traj
138  if(allocated(trajvar)) deallocate(trajvar)
139  end subroutine deallocate_traj
140 end module traj_data
141 
142 
145 subroutine trajectories
146  use output_empire, only : unit_traj_write
147  use traj_data
148  use pf_control
149  use sizes
150  implicit none
151  integer, parameter :: rk = kind(1.0d0)
152  integer :: particle,i,j
153  character(28) :: filename
154 
155  if(pf%timestep .eq. 0) call setup_traj
156 
157  do i = 1,pf%count
158  particle = pf%particles(i)
159 
160  do j = 1,trajn
161  if(pf%gen_data) then
162  write(filename,'(A,i7.7)') 'traj/truth_var',trajvar(j)
163  else
164  write(filename,'(A,i7.7,A,i5.5)') 'traj/var',trajvar(j),'particle',particle
165  end if
166  if(pf%timestep .eq. 0) then
167  open(unit_traj_write,file=filename,action='write',status='replace')
168  else
169  open(unit_traj_write,file=filename,action='write',status='old',position='append')
170  end if
171  write(unit_traj_write,'(es22.15)') pf%psi(trajvar(j),i)
172  close(unit_traj_write)
173 
174  end do
175  end do
176 end subroutine trajectories
Module containing EMPIRE coupling data.
Definition: comms.f90:57
Module that stores the information about the outputting from empire.
subroutine setup_traj
subroutine to read in which trajectories are required
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine trajectories
subroutine to output trajectories
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29
module to hold data for trajectories
subroutine deallocate_traj