41 &
'EVELO V1.7 calculate EnVELOpe of time series')
43 integer maxsamples,nsamp,nspa,i, npow, limit
44 parameter(maxsamples=310000)
46 real fdata(maxsamples)
48 integer idata(maxsamples)
49 equivalence(fdata,idata)
50 double complex ftarray(maxsamples)
51 parameter(pi=3.14159265358979311)
58 parameter(luin=10, luout=11)
60 logical last, hilbert, realspec, imagspec, ampspec, phasespec
61 logical envelope, pi4shift
64 real c1,c2,c3,readversion
67 character*14 timestamp
69 character*132 wid2line
74 character*80 inputformat, outputformat
76 integer maxfree, maxreadfree, nfree, lenmax
77 parameter(maxfree=200, maxreadfree=maxfree-1)
78 character*80 free(maxfree)
80 integer maxopt, lastarg, iargc
83 character*3 optid(maxopt)
84 character*40 optarg(maxopt)
85 logical optset(maxopt), opthasarg(maxopt)
87 logical debug, verbose
89 data optid/
'-d',
'-v',
'-H',
'-R',
'-I',
'-A',
'-P',
'-4',
90 &
'-ty',
'-it',
'-ot'/
91 data opthasarg/8*.false.,3*.true./
92 data optarg/8*
'-',3*
'sff'/
99 if (iargc().eq.1)
call getarg(1, argument)
100 if ((argument(1:5).eq.
'-help').or.(iargc().lt.2))
then 102 print *,
'Usage: evelo infile outfile [-H|-R|-I|-A|-P|-4]' 103 print *,
' [-ty f] [-it f] [-ot f]' 104 print *,
' or: evelo -help' 105 if (argument(1:5).ne.
'-help') stop
'ERROR: wrong number of arguments' 107 print *,
'calculate EnVELOpe of time series' 109 print *,
'-H Calculate Hilbert transform of input' 110 print *,
' signal rather than envelope.' 111 print *,
'-R calculate real part of Fourier spectrum' 112 print *,
'-I calculate imaginary part of Fourier spectrum' 113 print *,
'-A calculate Fourier amplitude spectrum' 114 print *,
'-P calculate Fourier phase spectrum' 115 print *,
'-4 phase shift by pi/4' 117 print *,
'-ty f choose file format ''f'' instead of SFF' 118 print *,
' for input and output files' 119 print *,
'-it f choose input file format ''f'' instead of SFF' 120 print *,
'-ot f choose output file format ''f'' instead of SFF' 122 print *,
'The switches are exclusive with priority in the order' 123 print *,
'listed above.' 125 print *,
'In case of Fourier output one second means one Hertz.' 127 print *,
'The output Fourier spectrum is normalized to be' 128 print *,
'equivalent to the corresponding integral transform.' 129 print *,
'Thus Fourier coeffients and spectral amplitudes are' 130 print *,
'given in [amplitude]/Hz, where [amplitude] is' 131 print *,
'the unit of the input samples.' 133 call sff_help_formats
140 call tf_cmdline(3, lastarg, maxopt, optid,
141 & optarg, optset, opthasarg)
153 if (.not.(hilbert))
then 155 if (.not.(realspec))
then 157 if (.not.(imagspec))
then 159 if (.not.(ampspec))
then 161 if (.not.(phasespec))
then 163 if (.not.(pi4shift)) envelope=.true.
169 inputformat=optarg(9)
170 outputformat=optarg(9)
171 if (optset(10)) inputformat=optarg(10)
172 if (optset(11)) outputformat=optarg(11)
175 call getarg(1, infile)
176 call getarg(2, outfile)
178 call sff_select_input_format(inputformat, ierr)
179 if (ierr.ne.0) stop
'ERROR: selected input format is not supported' 180 call sff_select_output_format(outputformat, ierr)
181 if (ierr.ne.0) stop
'ERROR: selected output format is not supported' 186 call sff_ropenfs(luin, infile, readversion, timestamp, code,
187 & nfree, free, lenmax, maxreadfree,
188 & srctype, cs, c1, c2, c3, srcdate, srctime, ierr)
189 if (ierr.ne.0) stop
'ERROR: opening input file' 191 nfree=min(nfree+1, maxfree)
193 comment=
'ERROR in algorithm selection code' 194 if (envelope) comment=
'calculate envelope' 195 if (hilbert) comment=
'calculate Hilbert transform' 196 if (pi4shift) comment=
'shift by pi/4' 197 if (realspec) comment=
'calculate real part of Fourier spectrum' 198 if (imagspec) comment=
199 &
'calculate imaginary part of Fourier spectrum' 200 if (ampspec) comment=
'calculate Fourier amplitude spectrum' 201 if (phasespec) comment=
'calculate Fourier phase spectrum' 203 if (comment(1:6).eq.
'ERROR ') stop
204 nfree=min(nfree+1, maxfree)
207 if (envelope) print *,
'envelop option (default) is selected' 208 if (hilbert) print *,
'hilbert option -H is selected' 209 if (pi4shift) print *,
'pi4shift option -4 is selected' 210 if (realspec) print *,
'realspec option -R is selected' 211 if (imagspec) print *,
'imagspec option -I is selected' 212 if (ampspec) print *,
'ampspec option -A is selected' 213 if (phasespec) print *,
'phasespec option -P is selected' 215 call sff_wopenfs(luout, outfile,
216 & free, nfree, srctype, cs, c1, c2, c3, srcdate, srctime, ierr)
217 if (ierr.ne.0) stop
'ERROR: opening output file' 220 do while(.not.(last))
222 call sff_rtracefi(luin, tanf, dt,
223 & wid2line, nsamp, fdata, idata, code, last,
224 & nfree, free, maxreadfree, lenmax,
225 & cs, c1, c2, c3, nstack, ierr)
226 if (ierr.ne.0) stop
'ERROR: reading input file' 228 nfree=min(nfree+1, maxfree)
230 nfree=min(nfree+1, maxfree)
235 do while (nspa.lt.nsamp)
239 if (nspa.gt.maxsamples) stop
'ERROR: too many samples' 242 ftarray(i)=(0.d0,0.d0)
243 if (i.le.nsamp) ftarray(i)=cmplx(fdata(i), 0.)
246 call tf_dfork(nspa, ftarray, -1.d0)
251 ftarray(i)=(0.d0,1.d0)*ftarray(i)
253 ftarray(limit)=(0.d0,0.d0)
255 ftarray(i)=(0.d0,-1.d0)*ftarray(i)
257 elseif (pi4shift)
then 260 ftarray(i)=sqrt(1/2.)*(1.d0,1.d0)*ftarray(i)
262 ftarray(limit)=(0.d0,0.d0)
264 ftarray(i)=sqrt(1/2.)*(1.d0,-1.d0)*ftarray(i)
266 elseif (envelope)
then 269 ftarray(i)=(0.d0,0.d0)
273 if ((envelope).or.(hilbert).or.(pi4shift))
274 &
call tf_dfork(nspa, ftarray, 1.d0)
276 scalefact=dt*sqrt(float(nspa))
277 if (hilbert.or.pi4shift)
then 279 fdata(i)=sngl(
real(ftarray(i)))
281 elseif (envelope)
then 283 fdata(i)=sngl(2.d0*abs(ftarray(i)))
285 elseif (realspec)
then 288 fdata(i)=sngl(scalefact*
real(ftarray(i)))
290 elseif (imagspec)
then 293 fdata(i)=sngl(scalefact*imag(ftarray(i)))
295 elseif (ampspec)
then 298 fdata(i)=sngl(scalefact*abs(ftarray(i)))
300 elseif (phasespec)
then 303 fdata(i)=sngl(atan2(imag(ftarray(i)),
real(ftarray(i))))*
307 stop
'ERROR in selection code' 310 if ((phasespec).or.(ampspec).or.(realspec).or.(imagspec))
then 311 call sff_modwid2samps(wid2line,nsamp)
312 if ((nsamp*dt).lt.1.e3)
then 313 call sff_modwid2samprat(wid2line, (nsamp*dt))
315 write(wid2line(58:68),
'(e11.6)') (nsamp*dt)
319 call sff_wtracefi(luout,
320 & wid2line, nsamp, fdata, idata, last,
321 & nfree, free, cs, c1, c2, c3, nstack, ierr)
322 if (ierr.ne.0) stop
'ERROR: writing output file'