GWtool
Gravitational-wave tool
 All Classes Files Functions Variables Pages
wf_routines.f90
Go to the documentation of this file.
1 !> \file wf_routines.f90 Routines for waveform matching
2 
3 !
4 ! GWtool: Simple tools for working with gravitational waves
5 ! http://gwtool.sourceforge.net/
6 !
7 !
8 ! Copyright 2007-2013 AstroFloyd - astrofloyd.org
9 !
10 !
11 ! This file is part of GWtool.
12 !
13 ! GWtool is free software: you can redistribute it and/or modify
14 ! it under the terms of the GNU General Public License as published by
15 ! the Free Software Foundation, either version 3 of the License, or
16 ! (at your option) any later version.
17 !
18 ! GWtool is distributed in the hope that it will be useful,
19 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ! GNU General Public License for more details.
22 !
23 ! You should have received a copy of the GNU General Public License
24 ! along with GWtool. If not, see <http://www.gnu.org/licenses/>.
25 
26 
27 
28 !***********************************************************************************************************************************
29 !> \brief Match the time-domain waveforms in two specified files
30 !!
31 !! \param ipfile1 File containing WF 1
32 !! \param ipfile2 File containing WF 2
33 !!
34 !! \retval ln Number of lines read
35 !! \retval dt Sum(t2-t1)
36 !! \retval dh Sum(h2-h1)
37 !! \retval hmax Maximum absolute strain amplitude found in h1, h2
38 !! \retval hsum1 Sum of absolute values of strain amplitude h1
39 !! \retval hsum2 Sum of absolute values of strain amplitude h1
40 !! \retval rdh Relative dh
41 !! \retval lnr Number of lines used to compute rdh
42 
43 subroutine match_wfs_file(ipfile1,ipfile2, ln, dt,dh, hmax,hsum1,hsum2, rdh,lnr)
44  use sufr_kinds, only: double
45  use sufr_system, only: find_free_io_unit, quit_program_error
46 
47  implicit none
48  character, intent(in) :: ipfile1*(*), ipfile2*(*)
49  integer, intent(out) :: ln, lnr
50  real(double), intent(out) :: dt,dh, hmax,hsum1,hsum2, rdh
51 
52  integer :: ip1,ip2, status
53  real(double) :: t1,t2, h1,h2
54 
55  call find_free_io_unit(ip1)
56  open(unit=ip1,form='formatted',status='old',action='read',position='rewind',file=trim(ipfile1),iostat=status)
57  if(status.ne.0) call quit_program_error('Error opening '//trim(ipfile1)//', aborting...', 0)
58 
59  call find_free_io_unit(ip2)
60  open(unit=ip2,form='formatted',status='old',action='read',position='rewind',file=trim(ipfile2),iostat=status)
61  if(status.ne.0) call quit_program_error('Error opening '//trim(ipfile2)//', aborting...', 0)
62 
63 
64  ln = 0
65  lnr = 0
66  dh = 0.d0
67  rdh = 0.d0
68  dt = 0.d0
69  hmax = -huge(hmax)
70  hsum1 = 0.d0
71  hsum2 = 0.d0
72  do
73  ln = ln + 1
74 
75  read(ip1,*, iostat=status) t1, h1
76  if(status.lt.0) exit
77  if(status.gt.0) then
78  write(0,'(A,I4,A,/)') ' Error reading '//trim(ipfile1)//', line',ln,' aborting...'
79  stop
80  end if
81 
82  read(ip2,*, iostat=status) t2, h2
83  if(status.lt.0) exit
84  if(status.gt.0) then
85  write(0,'(A,I4,A,/)') ' Error reading '//trim(ipfile2)//', line',ln,' aborting...'
86  stop
87  end if
88 
89  dt = dt + abs(t2-t1)
90  dh = dh + abs(h2-h1)
91  hmax = maxval( (/hmax, abs(h1), abs(h2)/) )
92  hsum1 = hsum1 + abs(h1)
93  hsum2 = hsum2 + abs(h2)
94  if(min(abs(h1),abs(h2)).gt.1.d-23) then
95  rdh = rdh + abs((h2-h1)/h1)
96  lnr = lnr + 1
97  end if
98 
99  !if(min(abs(h1),abs(h2)).gt.1.d-23 .and. mod(ln,100).eq.0) &
100  !if(mod(ln,1000).eq.0) &
101  ! write(*,'(I9,2F12.6,3ES15.5,F10.4)') ln,t1-1.d9,t2-1.d9, h1,h2,abs(h2-h1),abs((h2-h1)/h1)
102 
103  end do
104 
105  ln = ln - 1
106  close(ip1)
107  close(ip2)
108 
109 end subroutine match_wfs_file
110 !***********************************************************************************************************************************
subroutine match_wfs_file(ipfile1, ipfile2, ln, dt, dh, hmax, hsum1, hsum2, rdh, lnr)
Match the time-domain waveforms in two specified files.
Definition: wf_routines.f90:43