Waveform filter programs
xyz2uvw.f
Go to the documentation of this file.
1 c this is <xyz2uvw.f> by Thomas Forbriger 1997
2 c
3 c Copyright 1997, 2010 by Thomas Forbriger
4 c
5 c this program calculates the original components uvw from xyz for
6 c STS-2 seismometers
7 c
8 c (sff is the Stuttgart File Format as defined in sff.doc)
9 c
10 c ----
11 c XYZ2UVW is free software; you can redistribute it and/or modify
12 c it under the terms of the GNU General Public License as published by
13 c the Free Software Foundation; either version 2 of the License, or
14 c (at your option) any later version.
15 c
16 c This program is distributed in the hope that it will be useful,
17 c but WITHOUT ANY WARRANTY; without even the implied warranty of
18 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 c GNU General Public License for more details.
20 c
21 c You should have received a copy of the GNU General Public License
22 c along with this program; if not, write to the Free Software
23 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 c ----
25 c
26 c REVISIONS and CHANGES
27 c V1.0 09/01/97 first running version
28 c V1.1 18/10/00 pass maxsamples to sff library when reading
29 c V1.2 07/10/05 print more specific error message
30 c 14/12/11 checked transformation matrices and confirmed that
31 c they are correct (thof)
32 c see http://gpitrsvn.gpi.uni-karlsruhe.de:8000/TFSoftware/ticket/146
33 c
34 c======================================================================
35  program xyz2uvw
36  character*79 version
37 c dimensions
38  integer maxtraces, maxsamples, maxfree
39  parameter(maxtraces=3,maxsamples=1000000,maxfree=4)
40  integer lu
41  parameter(lu=10)
42 c common definitions
43  character*80 infile, outfile, switch
44  integer i,j, iargc
45  logical inx, debug
46 c sff specific
47  character*20 code
48  integer ierr
49  character*13 timestamp
50  character*80 free(maxfree)
51  character*132 wid2line(maxtraces)
52  integer idata(maxsamples)
53  real fdata(maxsamples)
54  equivalence(idata,fdata)
55  integer firstsamp(maxtraces)
56  real tanf(maxtraces), dt(maxtraces)
57  integer nsamp(maxtraces), sample, trace
58  logical last
59 c transform definitions
60  real t(3,3), r(3)
61  integer a(3),b(3)
62 c----------------------------------------------------------------------
63 c
64 c go on with some basic information
65 c
66  version='XYZ2UVW V1.2 calculate STS-2 components'
67  debug=.false.
68  print *,version
69  print *,'Usage: xyz2uvw -x|-u infile outfile'
70  print *,'or: xyz2uvw -help'
71  if (iargc().lt.1) stop 'ERROR: check argumemnts\n'
72 c give control-file information
73  call getarg(1, infile)
74  if (infile(1:5).eq.'-help') then
75  print *,' '
76  print *,'STS-2 output components X, Y, Z are not identical to'
77  print *,'the sensor components U, V, W. For some purposes it'
78  print *,'is desireable to have U, V, W seismograms.'
79  print *,' '
80  print *,'-x input file has components X,Y,Z'
81  print *,' trace infile outfile'
82  print *,' 1 Z = Z U'
83  print *,' 2 N = Y V'
84  print *,' 3 E = X W'
85  print *,' '
86  print *,'-u input file has components U,V,W'
87  print *,' trace infile outfile'
88  print *,' 1 U Z = Z'
89  print *,' 2 V N = Y'
90  print *,' 3 W E = X'
91  print *,' '
92  stop
93  endif
94  if (iargc().ne.3) stop 'ERROR: check argumemnts\n'
95 c----------------------------------------------------------------------
96  call getarg(1, switch)
97  call getarg(2, infile)
98  call getarg(3, outfile)
99  if (switch.eq.'-x') then
100  inx=.true.
101  elseif (switch.eq.'-u') then
102  inx=.false.
103  else
104  stop 'ERROR: wrong option (use -x or -u)\n'
105  endif
106 c----------------------------------------------------------------------
107 c read file
108  call sff_ropen(lu, infile, version, timestamp, code, ierr)
109  if (ierr.ne.0) stop 'ERROR: opening input file'
110  firstsamp(1)=1
111  do trace=1,3
112  nsamp(trace)=maxsamples
113  call sff_rtrace(lu, tanf(trace), dt(trace), wid2line(trace),
114  & nsamp(trace),
115  & fdata(firstsamp(trace)), idata(firstsamp(trace)),
116  & code, last, ierr)
117  if (ierr.ne.0) stop 'ERROR: reading trace\n'
118  if (trace.lt.3) then
119  firstsamp(trace+1)=firstsamp(trace)+nsamp(trace)
120  if ((firstsamp(trace+1)+nsamp(trace)).gt.maxsamples)
121  & stop 'ERROR: too many samples\n'
122  if (last) stop 'ERROR: less than 3 traces in file\n'
123  endif
124  if (nsamp(trace).ne.nsamp(1))
125  & stop 'ERROR: inconsistent number of samples\n'
126  if (dt(trace).ne.dt(1))
127  & stop 'ERROR: inconsistent sampling intervals\n'
128  if (tanf(trace).ne.tanf(1))
129  & stop 'ERROR: inconsistent time of first sample\n'
130  enddo
131  if (.not.(last)) close (lu)
132 c----------------------------------------------------------------------
133 c prepare transform matrix
134  if (inx) then
135  t(1,1)=-sqrt(2./3.)
136  t(1,2)=0.
137  t(1,3)=sqrt(1./3.)
138  t(2,1)=sqrt(1./6.)
139  t(2,2)=sqrt(1./2.)
140  t(2,3)=sqrt(1./3.)
141  t(3,1)=sqrt(1./6.)
142  t(3,2)=-sqrt(1./2.)
143  t(3,3)=sqrt(1./3.)
144  a(1)=firstsamp(3)-1
145  a(2)=firstsamp(2)-1
146  a(3)=firstsamp(1)-1
147  b(1)=firstsamp(1)-1
148  b(2)=firstsamp(2)-1
149  b(3)=firstsamp(3)-1
150  else
151  t(1,1)=-sqrt(2./3.)
152  t(1,2)=sqrt(1./6.)
153  t(1,3)=sqrt(1./6.)
154  t(2,1)=0.
155  t(2,2)=sqrt(1./2.)
156  t(2,3)=-sqrt(1./2.)
157  t(3,1)=sqrt(1./3.)
158  t(3,2)=sqrt(1./3.)
159  t(3,3)=sqrt(1./3.)
160  a(1)=firstsamp(1)-1
161  a(2)=firstsamp(2)-1
162  a(3)=firstsamp(3)-1
163  b(1)=firstsamp(3)-1
164  b(2)=firstsamp(2)-1
165  b(3)=firstsamp(1)-1
166  endif
167  if (debug) then
168  do i=1,3
169  write(6, '(i6,3(2x,f10.6),i6)') b(i),(t(i,j), j=1,3),a(i)
170  enddo
171  endif
172 c----------------------------------------------------------------------
173 c do transformation
174  do sample=1,nsamp(1)
175  do i=1,3
176  r(i)=0.
177  do j=1,3
178  r(i)=r(i)+(fdata(a(j)+sample)*t(i,j))
179  enddo
180  enddo
181  do i=1,3
182  fdata(b(i)+sample)=r(i)
183  enddo
184  enddo
185 c----------------------------------------------------------------------
186 c create prolog
187  write(free(1), '(a)') version
188  write(free(2), '(aa)') 'input file: ',infile(1:index(infile,' ')-1)
189  write(free(3), '(aa)') 'output file: ',outfile(1:index(outfile,' ')-1)
190  if (inx) then
191  write(free(4), '(a)') 'conversion is done from x,y,z to u,v,w'
192  else
193  write(free(4), '(a)') 'conversion is done from u,v,w to x,y,z'
194  endif
195 c----------------------------------------------------------------------
196 c modify wid2 line
197  if (inx) then
198  call modchan(wid2line(1), 'U')
199  call modchan(wid2line(2), 'V')
200  call modchan(wid2line(3), 'W')
201  else
202  call modchan(wid2line(1), 'Z/Z')
203  call modchan(wid2line(2), 'N/Y')
204  call modchan(wid2line(3), 'E/X')
205  endif
206 c----------------------------------------------------------------------
207 c write file
208  call sff_wopenf(lu, outfile, free, maxfree, ierr)
209  if (ierr.ne.0) stop 'ERROR: opening output file'
210  last=.false.
211  do trace=1,3
212  if (trace.eq.3) last=.true.
213  call sff_wtrace(lu, wid2line(trace),
214  & nsamp(trace),
215  & fdata(firstsamp(trace)), idata(firstsamp(trace)),
216  & last, ierr)
217  if (ierr.ne.0) stop 'ERROR: writing trace\n'
218  enddo
219  stop
220  end
221 c======================================================================
222 c subroutine
223 c
224 c
225  subroutine modchan(wid2line, chan)
226  character*132 wid2line
227  character*(*) chan
228  write(wid2line(36:38), '(a3)') chan
229  return
230  end
subroutine modchan(wid2line, chan)
Definition: rotate.f:168
program xyz2uvw
Definition: xyz2uvw.f:35