Waveform filter programs
rotate.f
Go to the documentation of this file.
1 c this is <rotate.f> by Thomas Forbriger 1997
2 c
3 c Copyright 1997, 2010 by Thomas Forbriger
4 c
5 c rotate horizontal components
6 c
7 c (sff is the Stuttgart File Format as defined in sff.doc)
8 c
9 c ----
10 c This program is free software; you can redistribute it and/or modify
11 c it under the terms of the GNU General Public License as published by
12 c the Free Software Foundation; either version 2 of the License, or
13 c (at your option) any later version.
14 c
15 c This program is distributed in the hope that it will be useful,
16 c but WITHOUT ANY WARRANTY; without even the implied warranty of
17 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 c GNU General Public License for more details.
19 c
20 c You should have received a copy of the GNU General Public License
21 c along with this program; if not, write to the Free Software
22 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 c ----
24 c
25 c REVISIONS and CHANGES
26 c V1.0 25/03/97 first running version
27 c V1.1 21/01/03 some corrections
28 c
29 c======================================================================
30  program rotate
31  character*79 version
32  parameter(version='ROTATE V1.1 rotate horizontal components')
33 c dimensions
34  integer maxtraces, maxsamples, maxfree
35  parameter(maxtraces=3,maxsamples=1000000,maxfree=6)
36  integer lu
37  parameter(lu=10)
38 c common definitions
39  character*80 infile, outfile, angle
40  integer iargc
41 c sff specific
42  character*20 code
43  real fversion
44  integer ierr
45  character*13 timestamp
46  character*80 free(maxfree)
47  character*132 wid2line(maxtraces), wid2
48  integer idata(maxsamples)
49  real fdata(maxsamples)
50  equivalence(idata,fdata)
51  integer firstsamp(maxtraces)
52  real tanf(maxtraces), dt(maxtraces)
53  integer nsamp(maxtraces), sample, trace
54  logical last
55 c else
56  integer cnsamp, cesamp
57  real vcos, vsin, pi, radial, trans, rangle
58 c----------------------------------------------------------------------
59 c
60 c go on with some basic information
61 c
62  print *,version
63  print *,'Usage: rotate infile outfile angle'
64  print *,'or: rotate -help'
65 c give control-file information
66  call getarg(1, infile)
67  if (infile(1:5).eq.'-help') then
68  print *,' '
69  print *,' Data will be read from infile an written to outfile'
70  print *,' in sff data format. The file has to consist of three'
71  print *,' traces which will be called Z, N and E component'
72  print *,' (in that order). The horizontal components will be'
73  print *,' rotated by the amount of angle. Angle is counted in'
74  print *,' degrees from north to east. Hence the input north'
75  print *,' component will be the output east component if you'
76  print *,' set angle to 90.'
77  print *,' '
78  print *,'The second trace will be ''R'' on output and the'
79  print *,'third will be ''T''.'
80  stop
81  endif
82  if (iargc().ne.3) stop 'ERROR: check argumemnts'
83 c----------------------------------------------------------------------
84  call getarg(1, infile)
85  call getarg(2, outfile)
86  call getarg(3, angle)
87  read(angle, *) rangle
88 c----------------------------------------------------------------------
89 c read file
90  print *,'open input data...'
91  call sff_ropen(lu, infile, fversion, timestamp, code, ierr)
92  if (ierr.ne.0) stop 'ERROR: opening input file'
93  print *,'read input data...'
94  firstsamp(1)=1
95  do trace=1,3
96  nsamp(trace)=maxsamples-firstsamp(trace)
97  call sff_rtrace(lu, tanf(trace), dt(trace), wid2line(trace),
98  & nsamp(trace),
99  & fdata(firstsamp(trace)), idata(firstsamp(trace)),
100  & code, last, ierr)
101  wid2=wid2line(trace)
102  print *,wid2(1:78)
103  if (ierr.ne.0) stop 'ERROR: reading trace\n'
104  if (trace.lt.3) then
105  firstsamp(trace+1)=firstsamp(trace)+nsamp(trace)
106  if ((firstsamp(trace+1)+nsamp(trace)).gt.maxsamples)
107  & stop 'ERROR: too many samples\n'
108  if (last) stop 'ERROR: less than 3 traces in file\n'
109  endif
110  if ((nsamp(trace).ne.nsamp(1)).or.
111  & (dt(trace).ne.dt(1)).or.
112  & (tanf(trace).ne.tanf(1))) stop 'ERROR: inconsistent dataset\n'
113  enddo
114  if (.not.(last)) close (lu)
115 c----------------------------------------------------------------------
116 c do transformation
117  print *,'rotate...'
118  pi=4.*atan(1.)
119  vcos=cos(pi*rangle/180.)
120  vsin=sin(pi*rangle/180.)
121  print 50, 'R', vcos, vsin
122  print 50, 'T', -vsin, vcos
123  50 format(' ',a,'=',f7.4,'*N + ',f7.4,'*E')
124  do sample=1,nsamp(1)
125  cnsamp=sample+firstsamp(2)-1
126  cesamp=sample+firstsamp(3)-1
127  radial=fdata(cnsamp)*vcos+fdata(cesamp)*vsin
128  trans=fdata(cesamp)*vcos-fdata(cnsamp)*vsin
129  fdata(cnsamp)=radial
130  fdata(cesamp)=trans
131  enddo
132 c----------------------------------------------------------------------
133 c create prolog
134  print *,'prepare comments...'
135  write(free(1), '(a)') version
136  write(free(2), '(aa)') 'input file: ',infile(1:index(infile,' ')-1)
137  write(free(3), '(aa)') 'output file: ',outfile(1:index(outfile,' ')-1)
138  write(free(4), '(af10.3)') 'angle of rotation (degrees): ',rangle
139 c----------------------------------------------------------------------
140 c modify wid2 line
141  call modchan(wid2line(1), 'Z')
142  call modchan(wid2line(2), 'R')
143  call modchan(wid2line(3), 'T')
144 c----------------------------------------------------------------------
145 c write file
146  print *,'open output data...'
147  call sff_wopenf(lu, outfile, free, maxfree, ierr)
148  if (ierr.ne.0) stop 'ERROR: opening output file'
149  print *,'write output data...'
150  last=.false.
151  do trace=1,3
152  if (trace.eq.3) last=.true.
153  wid2=wid2line(trace)
154  print *,wid2(1:78)
155  call sff_wtrace(lu, wid2line(trace),
156  & nsamp(trace),
157  & fdata(firstsamp(trace)), idata(firstsamp(trace)),
158  & last, ierr)
159  if (ierr.ne.0) stop 'ERROR: writing trace\n'
160  enddo
161  stop
162  end
163 c======================================================================
164 c subroutine
165 c
166 c
167  subroutine modchan(wid2line, chan)
168  character*132 wid2line
169  character*(*) chan
170  write(wid2line(36:38), '(a3)') chan
171  return
172  end
subroutine modchan(wid2line, chan)
Definition: rotate.f:168
program rotate
Definition: rotate.f:30