GWtool
Gravitational-wave tool
 All Classes Files Functions Variables Pages
gw_ligo_xml2screen.f90
Go to the documentation of this file.
1 !> \file gw_ligo_xml2screen.f90 Print the contents of a LIGO/Virgo injection.xml file to screen
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 Print the contents of a LIGO/Virgo injection.xml file to screen
30 
32  use sufr_constants, only: set_sufr_constants
33  use sufr_system, only: find_free_io_unit, quit_program_error, syntax_quit
34  use sufr_text, only: replace_substring, remove_substring
35 
36  implicit none
37  integer, parameter :: maxcol=199
38  integer :: verbose, status, ip, ln, i1,i2, coli,ncol,colnr, strlen, ntabs
39  !real :: spin1x,spin1y,spin1z, spin2x,spin2y,spin2z, a1,phi1,theta1, a2
40  character :: infile*(99), line*(999), colnames(maxcol)*(99), values(maxcol)*(99)
41  logical :: instream
42 
43  verbose = 0
44 
45  call set_sufr_constants()
46 
47  if(command_argument_count().eq.1) then
48  call get_command_argument(1, infile)
49  else
50  call syntax_quit('<xml file>', 0)
51  end if
52 
53 
54  instream = .false.
55  colnames = ' '
56  values = ' '
57 
58  call find_free_io_unit(ip)
59  open(unit=ip,form='formatted',status='old',action='read',position='rewind',file=trim(infile),iostat=status)
60  if(status.ne.0) call quit_program_error('Error opening '//trim(infile)//', aborting...', 0)
61 
62 
63  ln = 0
64  colnr = 0
65  ntabs = 0
66  do
67  ln = ln + 1
68 
69  read(ip,'(A)', iostat=status) line
70  if(status.lt.0) exit
71  if(status.gt.0) then
72  write(0,'(A,I4,A,/)') ' Error reading '//trim(infile)//', line',ln,' aborting...'
73  stop
74  end if
75 
76  line = adjustl(line) ! left-adjust line
77 
78  if(verbose.gt.0) then
79  print*
80  print*,ln,trim(line)
81  end if
82 
83  if(index(line,'</Stream>').ne.0) instream = .false.
84 
85  if(index(line,'<Table ').ne.0) then ! Print table name
86  ntabs = ntabs + 1
87  call remove_substring(line, '<Table Name="')
88  call remove_substring(line, ':table')
89  call remove_substring(line, '">')
90  call replace_substring(line, ':', ' - ')
91 
92  write(*,*)
93  write(*,*)
94  write(*,'(A)') '##########################################################################################################'
95  write(*,'(A)') ' Table: '//trim(line)
96  write(*,'(A)') '##########################################################################################################'
97  colnr = 0
98  end if
99 
100  if(index(line,'<Column').ne.0) then ! Get column title
101  call remove_substring(line, '<Column Name="')
102  call remove_substring(line, 'processgroup:process:')
103  call remove_substring(line, 'process_paramsgroup:process_params:')
104  call remove_substring(line, 'sim_inspiralgroup:sim_inspiral:')
105  i1 = index(line, '<Column Name="', back=.false.)
106  i2 = index(line, ' Type="', back=.true.) - 2
107 
108  if(verbose.gt.0) print*,i1,i2,line(1:i2)
109  colnr = colnr + 1
110  colnames(colnr) = line(1:i2)
111  end if
112 
113  if(instream) then
114  strlen = len_trim(line)
115  call replace_substring(line, ' ', '_')
116  line(strlen+1:) = ' '
117  call replace_substring(line, ',', ' ')
118 
119  if(verbose.gt.0) print*,'Stream: ',trim(line)
120  read(line,*, iostat=status) values
121  !if(status.lt.0) exit
122  if(status.gt.0) then
123  write(0,'(A,I4,A,/)') ' Error reading stream value column',coli,' aborting...'
124  stop
125  end if
126 
127  ! Print results:
128  write(*,*)
129  ncol = 0
130  do coli=1,maxcol
131  if(len_trim(values(coli)).ne.0 .or. len_trim(colnames(coli)).ne.0) then
132  ncol = ncol+1
133  if(mod(coli,10).eq.1) write(*,*)
134  write(*,'(I5,2A50)') coli,trim(colnames(coli)),trim(values(coli))
135 
136  !if(trim(colnames(coli)).eq.'spin1x') read(values(coli),*) spin1x
137  !if(trim(colnames(coli)).eq.'spin1y') read(values(coli),*) spin1y
138  !if(trim(colnames(coli)).eq.'spin1z') read(values(coli),*) spin1z
139  !if(trim(colnames(coli)).eq.'spin2x') read(values(coli),*) spin2x
140  !if(trim(colnames(coli)).eq.'spin2y') read(values(coli),*) spin2y
141  !if(trim(colnames(coli)).eq.'spin2z') read(values(coli),*) spin2z
142  end if
143  end do
144 
145  !a1 = sqrt(spin1x**2 + spin1y**2 + spin1z**2)
146  !theta1 = 0.
147  !phi1 = 0.
148  !if(a1.gt.0.) then
149  ! theta1 = acos(spin1z/a1)
150  !end if
151  !a2 = sqrt(spin2x**2 + spin2y**2 + spin2z**2)
152 
153  write(*,'(/,A,2(I0,A))') ' Found: ',colnr,' column titles, ',ncol,' column values.'
154  if(colnr.ne.ncol) write(0,'(//,A,2(I0,A),//)') ' *** Warning: the number of column titles (',colnr, &
155  ') is not equal to the number of column values (',ncol,'). Please verify the output.'
156  end if
157 
158  if(index(line,'<Stream ').ne.0) instream = .true.
159 
160  end do
161 
162 
163 
164  ln = ln - 1
165  close(ip)
166 
167  write(*,'(/,A,I0,A)') ' Found: ',ntabs,' tables.'
168 
169  write(*,*)
170 
171 end program gw_ligo_xml2screen
172 !***********************************************************************************************************************************
program gw_ligo_xml2screen
Print the contents of a LIGO/Virgo injection.xml file to screen.