Fortran SFF API to data I/O streams in C++
fapidtest.f
Go to the documentation of this file.
1 c this is <fapidtest.f>
2 c ----------------------------------------------------------------------------
3 c
4 c Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
5 c
6 c this is a program to test several steps of fapid development
7 c
8 c ----
9 c This program is free software; you can redistribute it and/or modify
10 c it under the terms of the GNU General Public License as published by
11 c the Free Software Foundation; either version 2 of the License, or
12 c (at your option) any later version.
13 c
14 c This program is distributed in the hope that it will be useful,
15 c but WITHOUT ANY WARRANTY; without even the implied warranty of
16 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 c GNU General Public License for more details.
18 c
19 c You should have received a copy of the GNU General Public License
20 c along with this program; if not, write to the Free Software
21 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 c ----
23 c
24 c
25 c REVISIONS and CHANGES
26 c 17/11/2010 V1.0 Thomas Forbriger
27 c 01/04/2011 V1.1 test file writing
28 c
29 c ============================================================================
30 c
31  program fapidtest
32 c
33  character*(*) version
34  parameter(version=
35  & 'FAPIDTEST V1.1 this is a program to test libfapidxx.a')
36 c
37 c commandline
38  integer maxopt, lastarg, iargc
39  character*80 argument
40  parameter(maxopt=7)
41  character*2 optid(maxopt)
42  character*40 optarg(maxopt)
43  logical optset(maxopt), opthasarg(maxopt)
44 c debugging
45  logical debug, verbose
46  double precision dt
47 
48 c here are the keys to our commandline options
49  data optid/'-D', '-v', '-x', '-t', '-w', '-r', '-d'/
50  data opthasarg/3*.false.,4*.true./
51  data optarg/3*'-','sff','testfile.sff','junk.sff','1.e-3'/
52 c
53  character*20 formatid
54  character*40 infile, outfile
55  logical doread, dowrite
56 c
57 c------------------------------------------------------------------------------
58 c basic information
59 c
60 c
61  argument=' '
62  if (iargc().eq.1) call getarg(1, argument)
63  if ((argument(1:5).eq.'-help').or.(iargc().lt.1)) then
64  print *,version
65  print *,'Usage: fapidtest [-r file] [-w file] [-t type]'
66  print *,' [-d t]'
67  print *,' or: fapidtest -help'
68  print *,' or: fapidtest -x'
69  if (argument(1:5).ne.'-help')
70  & stop 'ERROR: wrong number of arguments'
71  print *,' '
72  print *,'-x print online help'
73  print *,'-r file test reading from file'
74  print *,'-w file test writing to file'
75  print *,'-t type select file type for input/output'
76  print *,'-d t set sampling interval to ''t'' seconds'
77  print *,' '
78  call sff_help_formats
79  stop
80  endif
81 c
82 c------------------------------------------------------------------------------
83 c read command line arguments
84 c
85  call tf_cmdline(1, lastarg, maxopt, optid,
86  & optarg, optset, opthasarg)
87 
88  if (optset(3)) then
89  call sff_help_details
90  stop
91  endif
92 
93  debug=optset(1)
94  verbose=optset(2)
95  formatid=optarg(4)
96  dowrite=optset(5)
97  outfile=optarg(5)
98  doread=optset(6)
99  infile=optarg(6)
100  read(optarg(7), *, err=99) dt
101 c
102 c------------------------------------------------------------------------------
103 c go
104 c
105  print *,'select format ',formatid
106  call sff_select_format(formatid, ierr)
107  if (ierr.ne.0) then
108  stop 'ERROR: selecting format'
109  endif
110  if (dowrite) then
111  if (verbose) then
112  print *,'write data with sampling interval ',dt,' s'
113  endif
114  call writetest(outfile, dt)
115  endif
116  if (doread) then
117  if (verbose) then
118  print *,'read data'
119  endif
120  call readtest(infile)
121  endif
122  stop
123  99 stop 'ERROR: reading command line arument'
124  end
125 
126 c======================================================================
127 c functions
128 c ---------
129 
130  subroutine writetest(filename, indt)
131 c
132  character*(*) filename
133  double precision indt
134 c
135  integer m
136  parameter(m=1024)
137  real d(m)
138  integer id(m)
139  equivalence(d,id)
140  integer n,i,j,s,k
141  real p,dx,dt,rate
142 c
143  integer lu, ierr
144  parameter(lu=10)
145  character date*7, time*12,stype*22, wid2line*132, nil*10
146  parameter(nil='NIL')
147 c
148  print *,'write test'
149  print *,'----------'
150  print *,'open ',filename(1:index(filename,' '))
151  dt=indt
152  rate=1./dt
153  dx=1.
154  n=40
155  p=(dt*m)/(dx*n)
156  stype='synthetic'
157  date='110401'
158  time='123209.012345'
159  call sff_prepwid2(m, rate, 'sta ',
160  & 2011, 04, 01, 12, 32, 'chan ', 'aux ', 'ins ',
161  & 10.023456, -1., -1., -1., -1., wid2line, ierr)
162  if (ierr.ne.0) stop 'ERROR: preparing wid2line'
163  call sff_wopens(lu, filename, stype, 'C', 0., 0., 0., date, time, ierr)
164  if (ierr.ne.0) stop 'ERROR: opening file'
165  s=int((dx*p)/dt)
166  k=s
167  do i=1,n
168  print *,'write trace #',i
169  do j=1,m
170  d(j)=0.
171  enddo
172  if (k.le.m) d(k)=1./sqrt(i*dx)
173  k=k+s
174  if (i.eq.n) then
175  call sff_wtracei(lu, wid2line, m, d, id, .true., 'C',
176  & i*dx, 0., 0., 1, ierr)
177  else
178  call sff_wtracei(lu, wid2line, m, d, id, .false., 'C',
179  & i*dx, 0., 0., 1, ierr)
180  endif
181  if (ierr.ne.0) stop 'ERROR: writing trace'
182  enddo
183 c
184  return
185  end
186 c
187 c----------------------------------------------------------------------
188 c
189  subroutine readtest(filename)
190 c
191  character*(*) filename
192  integer lu
193  parameter(lu=10)
194 c time series
195  integer maxsamp, nsamp
196  parameter(maxsamp=100000)
197  real fdata(maxsamp)
198  integer idata(maxsamp)
199  equivalence(fdata, idata)
200 
201 c sff file header
202  character code*10, timestamp*13, scs*1, date*6, time*10
203  real sffversion, sc1, sc2, sc3
204  character*20 source
205 c
206 c sff trace
207  logical last
208  character rcs*1, wid2line*132
209  real rc1, rc2, rc3, tanf, dt
210  integer nstack
211 c
212  print *,'read test'
213  print *,'---------'
214  print *,'open ',filename(1:index(filename,' '))
215  call sff_ropens(lu, filename, sffversion, timestamp, code,
216  & source, scs, sc1, sc2, sc3, date, time, ierr)
217  if (ierr.ne.0) then
218  stop 'ERROR: opening file'
219  endif
220  print *,'sffversion: ', sffversion
221  print *,'timestamp: ', timestamp
222  print *,'code: ', code
223  print *,'source: ', source
224  print *,'scs, sc1, sc2, sc3: ', scs, sc1, sc2, sc3
225  print *,'date time: ', date, ' ', time
226  last=.false.
227  do while (.not.last)
228  print *,' '
229  print *,'read next trace'
230  nsamp=maxsamp
231  call sff_rtracei(lu, tanf, dt,
232  & wid2line, nsamp, fdata,
233  & idata, code, last,
234  & rcs, rc1, rc2, rc3, nstack, ierr)
235  print *,wid2line
236  print *,'nsamp: ',nsamp
237  print *,'rcs, rc1, rc2, rc3: ',rcs, rc1, rc2, rc3
238  print *,'nstack: ',nstack
239  print *,'dt: ',dt
240  print *,'tanf: ',tanf
241  print *,'code: ',code
242  if (ierr.ne.0) then
243  stop 'ERROR: reading trace'
244  endif
245  enddo
246  return
247  end
248 c
249 c ----- END OF fapidtest.f -----
subroutine readtest(filename)
Definition: fapidtest.f:190
program fapidtest
Definition: fapidtest.f:31
subroutine writetest(filename, indt)
Definition: fapidtest.f:131