Makefile 20.1 KB
Newer Older
1
2
3
4
5
# this is <Makefile>
# ----------------------------------------------------------------------------
# 
# Copyright (c) 2019 by Thomas Forbriger (BFO Schiltach) 
# 
6
# test suite for croposp
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 
# ----
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----
#
23
24
# run with pairwise noise signal:
#
25
26
27
28
29
#   make all PAIRWISE=yes
#
# run with seed values of publication example
#
#   make cleanseed; make all FIXEDSEED=yes
30
#
31
32
33
34
# run with all time series being white noise
#
#   make all UNIFORM=yes
#
35
36
# REVISIONS and CHANGES 
#    06/02/2019   V1.0   Thomas Forbriger
37
38
#    18/09/2019   V1.1   provide fixed seed value on request to reproduce
#                        publication example exactly
39
40
41
42
# 
# ============================================================================
#

43
44
45
46
47
all: compilation.pdf

# select sets to be analyzed
# four are available, three must be used at least
CPSD_SET=1 2 3
48
CPSD_SET=1 2 3 4
49

50
51
52
# input data
CPSD_RAWSET:=$(CPSD_SET)

53
ALLPDF=PSD.pdf PSDraw.pdf \
54
  $(addprefix coherence_,$(addsuffix .pdf,$(CPSD_SET))) \
55
56
  $(addprefix transfer_,$(addsuffix .pdf,A B)) \
  $(addprefix phase_,$(addsuffix .pdf,A B)) \
57
  $(addprefix NPSD_,$(addsuffix .pdf,$(CPSD_SET))) 
58
59
60
61
62

compilation.pdf: $(ALLPDF)
	pdfjam $^  \
	  --nup 2x2 --landscape --paper a4paper --scale 0.85 -o $@

63
64
65
npsd_compilation.pdf:  $(addprefix SNPSD_,$(addsuffix .pdf,$(CPSD_SET))) 
	pdfjam $^  \
	  --nup 1x2 --paper a4paper --scale 0.85 -o $@
66

67
68
69
70
coherence_compilation.pdf: $(addprefix coherence_,$(addsuffix .pdf,$(CPSD_SET)))
	pdfjam $^  \
	  --nup 2x2 --landscape --paper a4paper --scale 0.85 -o $@

71
72
alldata: cpsd1.bin cpsd2.bin cpsd3.bin cpsd4.bin

73
.PHONY: clean
74
clean: cleanseed ; 
75
76
77
78
	-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
	-/bin/rm -vf flist *.bin *.o *.xxx *.ps *.pdf *~ 
	-/bin/rm -vf *.asc

79
80
81
82
.PHONY: cleanseed
cleanseed: ; 
	-/bin/rm -vf *.seed

83
84
85
86
87
88
# ======================================================================
# create time series
# ==================
#
# set time series parameters
# --------------------------
89
CPSD_DT=0.01
90
CPSD_DUR=8640.065
91
#CPSD_DUR=864.
92

93
# ----------------------------------------------------------------------
94
# create raw time series
95
96
97
98
99
100
# ----------------------
# Several time series of normally distributed random samples with zero mean
# are computed with siggenx. To make them incoherent, each run requires its
# own specific seed value for the random number generator. We use the
# nanosecond field of the system clock.
#
101
CPSD_SIGGENOPT=-v -o -d $(CPSD_DT) -T $(CPSD_DUR) -ot bin
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# set random number generator type
# --------------------------------
#
#  Quotation from 
#  https://www.gnu.org/software/gsl/doc/html/index.html
#  https://www.gnu.org/software/gsl/doc/html/rng.html#random-number-generator-algorithms
#
#  The following generators are recommended for use in simulation. They have
#  extremely long periods, low correlation and pass most statistical tests.
#  For the most reliable source of uncorrelated numbers, the second-generation
#  RANLUX generators have the strongest proof of randomness.
#
#  gsl_rng_ranlxd1
#  gsl_rng_ranlxd2
#
#      These generators produce double precision output (48 bits) from the
#      RANLXS generator. The library provides two luxury levels ranlxd1 and
#      ranlxd2, in increasing order of strength.
#
#  gsl_rng_ranlux
#  gsl_rng_ranlux389
#
#      The ranlux generator is an implementation of the original algorithm
#      developed by Luscher. It uses a lagged-fibonacci-with-skipping
#      algorithm to produce “luxury random numbers”. It is a 24-bit
#      generator, originally designed for single-precision IEEE floating
#      point numbers. This implementation is based on integer arithmetic,
#      while the second-generation versions RANLXS and RANLXD described
#      above provide floating-point implementations which will be faster
#      on many platforms. The period of the generator is about 10^{171}.
#      The algorithm has mathematically proven properties and it can
#      provide truly decorrelated numbers at a known level of randomness.
#      The default level of decorrelation recommended by Luscher is
#      provided by gsl_rng_ranlux, while gsl_rng_ranlux389 gives the
#      highest level of randomness, with all 24 bits decorrelated. Both
#      types of generator use 24 words of state per generator.
#
#      For more information see,
#
#      *  M. Luscher, “A portable high-quality random number generator for
#         lattice field theory calculations”, Computer Physics Communications,
#         79 (1994) 100–110.
#      *  F. James, “RANLUX: A Fortran implementation of the high-quality
#         pseudo-random number generator of Luscher”, Computer Physics
#         Communications, 79 (1994) 111–114
#
RNGTYPE=ranlux
# Choose:
RNGTYPE=ranlxd2

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# allow to reproduce publication example exactly
ifdef FIXEDSEED
cpsd1raw.seed:  ;printf "%s\n" 686293391 > $@
cpsd2raw.seed:  ;printf "%s\n" 448546898 > $@
cpsd3raw.seed:  ;printf "%s\n" 021371780 > $@
cpsd4raw.seed:  ;printf "%s\n" 559720675 > $@
cpsdbgraw.seed: ;printf "%s\n" 137374844 > $@
else
cpsd1raw.seed:  ;printf "%s\n" $$(date +"%N") > $@
cpsd2raw.seed:  ;printf "%s\n" $$(date +"%N") > $@
cpsd3raw.seed:  ;printf "%s\n" $$(date +"%N") > $@
cpsd4raw.seed:  ;printf "%s\n" $$(date +"%N") > $@
cpsdbgraw.seed: ;printf "%s\n" $$(date +"%N") > $@
endif

cpsd1raw.bin cpsd2raw.bin cpsd3raw.bin cpsd4raw.bin cpsdbgraw.bin: \
  %.bin: %.seed
	/bin/bash -c 'export GSL_RNG_SEED=$$(cat $<); \
171
	  export GSL_RNG_TYPE=$(RNGTYPE); \
172
	  siggenx 14 $@ $(CPSD_SIGGENOPT); \
173
	  echo seed: $$GSL_RNG_SEED > $(patsubst %.bin,%seed.xxx,$@)'
174
# time series for common noise signal: cpsdbgraw.bin
175

176
# provide a time series plot to confirm incoherence
177
178
179
rawsig.ps: cpsd1raw.bin cpsd2raw.bin cpsd3raw.bin cpsd4raw.bin cpsdbgraw.bin
	stuplox -d $@/cps -s x -i -ty bin $^

180
181
182
183
184
185
186
187
188
189
# ----------------------------------------------------------------------
# scale and filter time series
# ----------------------------
#
#  The raw random sequences are adjusted to represent four sets of incoherent
#  noise and one random sequence ('bg') which will be common in all final data
#  files. We understand the first four as a simulation of instrumental noise
#  and the bg-sequence as a representation of background ground noise to be
#  common in all reacordings.
#
190
191
192
193
194
195
196
197
198
199
200
201
202
203
ifdef UNIFORM
# set amplitudes
CPSD_AMP1=1.
CPSD_AMP2=0.1
CPSD_AMP3=0.01
CPSD_AMP4=0.001
CPSD_AMPBG=10.
CPSD_FILTER1=rem
CPSD_FILTER2=rem
CPSD_FILTER3=rem
CPSD_FILTER4=rem
CPSD_FILTERBG=rem
FILTERBG2=rem
else
204
# set amplitudes
205
206
207
208
209
CPSD_AMP1=0.2
CPSD_AMP2=4.
CPSD_AMP3=100.
CPSD_AMP4=1.e-2
CPSD_AMPBG=10.
210
211
212
213
214
CPSD_FILTER1=hpb  1.,2
CPSD_FILTER2=hpb 4.,4\nlpb  2.,4
CPSD_FILTER3=lpb  100.,2
CPSD_FILTER4=rem
CPSD_FILTERBG=lp1  2.\navg  0\nhpb  100.,4
215

216
217
218
219
220
221
222
223
# test effect of pairwise coherent noise
ADDITIONAL=
FILTERBG2=dif  0
ifdef PAIRWISE
ADDITIONAL=cpsd2modX.bin
FILTERBG2=rem
CPSD_SET=1 3 4
endif
224
endif
225

226
227
# modify white noise to channel specific frequency characteristic
cpsd1mod.bin: cpsd1raw.bin
228
	printf "fac  $(CPSD_AMP1)\n$(CPSD_FILTER1)\nend\n" \
229
230
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd2mod.bin: cpsd2raw.bin
231
	printf "fac  $(CPSD_AMP2)\n$(CPSD_FILTER2)\nend\n" \
232
233
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd3mod.bin: cpsd3raw.bin
234
	printf "fac  $(CPSD_AMP3)\n$(CPSD_FILTER3)\nend\n" \
235
236
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd4mod.bin: cpsd4raw.bin
237
	printf "fac  $(CPSD_AMP4)\n$(CPSD_FILTER4)\nend\n" \
238
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
239
cpsdbg1mod.bin: cpsdbgraw.bin
240
	printf "fac  $(CPSD_AMPBG)\n$(CPSD_FILTERBG)\nend\n" \
241
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
242
cpsdbg2mod.bin: cpsdbg1mod.bin
243
	printf "$(FILTERBG2)\nend\n" \
244
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
245

246
247
248
%.ascii: %.bin
	any2any --verbose --overwrite --itype bin --otype ascii $@ $<

249
250
251
252
253
254
DISCARDS=839.
# discard transient filter response
%X.bin: %.bin
	tijerasxx --verbose --overwrite --iformat bin --oformat bin \
	  --secondsf $(DISCARDS) $@ $<

255
# add common noise signal to channel specific noise floor
256
cpsd1add.bin: cpsd1modX.bin cpsdbg1modX.bin $(ADDITIONAL)
257
	teseco -v -o -a -type bin -Type bin $@ $^
258
cpsd2add.bin: cpsd2modX.bin cpsdbg1modX.bin 
259
	teseco -v -o -a -type bin -Type bin $@ $^
260
cpsd3add.bin: cpsd3modX.bin cpsdbg1modX.bin
261
	teseco -v -o -a -type bin -Type bin $@ $^
262
cpsd4add.bin: cpsd4modX.bin cpsdbg2modX.bin $(ADDITIONAL)
263
264
	teseco -v -o -a -type bin -Type bin $@ $^
	
265
266
267
268
269
270
271
# ----------------------------------------------------------------------
# adjust time series headers
# --------------------------
#
#  recorded data is expected to be taken with slightly different sampling;
#  croposp is expected to be able to handle this
#
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# set header fields to reasonable time an channel identifiers
CPSD_DATE=2018/12/16_14:24:16
CPSD_DATE1=$(CPSD_DATE).010980
CPSD_DATE2=$(CPSD_DATE).011050
CPSD_DATE3=$(CPSD_DATE).010760
CPSD_DATE4=$(CPSD_DATE).010760

CPSD_HDOPTS=-verbose -overwrite -itype bin -otype bin -ss TST -sa XX -sc BHZ
cpsd1hd.bin: cpsd1add.bin
	sehefixx $< $@ $(CPSD_HDOPTS) -st $(CPSD_DATE1) -si SYN1
cpsd2hd.bin: cpsd2add.bin
	sehefixx $< $@ $(CPSD_HDOPTS) -st $(CPSD_DATE2) -si SYN2
cpsd3hd.bin: cpsd3add.bin
	sehefixx $< $@ $(CPSD_HDOPTS) -st $(CPSD_DATE3) -si SYN3
cpsd4hd.bin: cpsd4add.bin
	sehefixx $< $@ $(CPSD_HDOPTS) -st $(CPSD_DATE4) -si SYN4

# extract inconsistent time windows
CPSD_TOPT1=-samplesf 3 -samplesl 7
CPSD_TOPT2=-samplesf 25
CPSD_TOPT3=-samplesl 81
CPSD_TOPT4=-samplesl 1
cpsd1.bin: cpsd1hd.bin
	tijerasxx -verbose -overwrite -iformat bin -oformat bin \
	  $(CPSD_TOPT1) $@ $<
cpsd2.bin: cpsd2hd.bin
	tijerasxx -verbose -overwrite -iformat bin -oformat bin \
	  $(CPSD_TOPT2) $@ $<
cpsd3.bin: cpsd3hd.bin
	tijerasxx -verbose -overwrite -iformat bin -oformat bin \
	  $(CPSD_TOPT3) $@ $<
cpsd4.bin: cpsd4hd.bin
	tijerasxx -verbose -overwrite -iformat bin -oformat bin \
	  $(CPSD_TOPT4) $@ $<

307
308
309
310
311
# ======================================================================
# analyze time series
# ===================
#
# set croposp options
312
CPSD_NSEGMENTS=20
313
314
315
CPSD_OVERLAP=0.5
CPSD_DIVISOR=100
CPSD_PADFACTOR=1
316
CPSD_AVGOUT=--avgout
317
CPSD_NLOG=20
318
CPSD_LOG=--log $(CPSD_NLOG) $(CPSD_AVGOUT)
319
320
CPSD_OPT=--DEBUG
CPSD_OPT=
321
OUTPUTS=psd npsd coherence transfer phase
322

323
324
# define string summarizing essential croposp options
# this will be included in the title of diagrams
325
326
327
CPSD_CROPOSP_OPT=--nsegments=$(CPSD_NSEGMENTS) \
		     --divisor=$(CPSD_DIVISOR) \
		     --padfactor=$(CPSD_PADFACTOR) \
328
329
		     --overlap=$(CPSD_OVERLAP) \
		     $(CPSD_LOG)
330

331
332
333
# set standard (non-processing options)
CPSD_CROPOSP_STDOPT=--verbose --overwrite --itype bin --trim \
			  --pattern="%I" --datetolerance 0.1
334
335
336
337
# compile list of file names as input to croposp
CPSD_BINFILES=$(addprefix cpsd,$(addsuffix .bin,$(CPSD_SET)))
# compile list of raw files (apparent instrumental noise and seismic
# background noise separately)
338
CPSD_RAWFILES=$(addprefix cpsd,$(addsuffix mod.bin,$(CPSD_RAWSET) bg1 bg2)) \
339
340

# run complete analysis on the apparent seismometer output
341
$(addsuffix _out.xxx,$(OUTPUTS)): $(CPSD_BINFILES)
342
	croposp $(CPSD_OPT) $(CPSD_CROPOSP_STDOPT) \
343
344
345
	  $(CPSD_CROPOSP_OPT) \
	  --psd psd_out.xxx \
	  --npsd npsd_out.xxx \
346
	  --coherence coherence_out.xxx \
347
348
349
350
	  --transfer transfer_out.xxx \
	  --phase phase_out.xxx \
	  $^

351
352
353
354
355
356
357
# run npsd analysis for selected mode
$(addprefix npsd_,$(addsuffix _out.xxx,0 1 2 3)): \
  npsd_%_out.xxx: $(CPSD_BINFILES)
	croposp $(CPSD_OPT) $(CPSD_CROPOSP_STDOPT) \
	  $(CPSD_CROPOSP_OPT) --npsdmode=$(patsubst npsd_%_out.xxx,%,$@) \
	  --npsd $@ $^

358
359
# compute PSD for raw files (apparent instrumental noise and seismic
# background noise separately)
360
361
362
363
364
365
366
psdraw.xxx: $(CPSD_RAWFILES)
	croposp $(CPSD_OPT) --verbose --overwrite --itype bin --trim \
	  --pattern="%F" \
	  $(CPSD_CROPOSP_OPT) \
	  --datetolerance 0.1 \
	  --psd $@ $^

367
368
# compute PSD with foutra, which is used as a reference to confirm correct
# calibration of algorithms
369
370
371
psd%.001.asc: cpsd%.bin
	foutra -v -o -type bin -ASCII=$(patsubst cpsd%.bin,psd%,$<) \
	  -power -rbw=0.1 -demean -detrend -logascii=0.1 -avgascii \
372
	  -nsegments=$(CPSD_NSEGMENTS) junk.xxx $^
373

374
# convert foutra output to the file format expected by croposplot.py
375
376
377
378
psd%foutra.xxx: psd%.001.asc
	printf "# #1: foutra (reference): %s\n" $< > $@
	cat $< >> $@

379
380
381
382
383
384
385
# ======================================================================
# display results
# ===============
#
# location of plot tool
CROPOSPLOT=../croposplot.py

386
# common options
387
388
CROPOSPLOT_MATCH=.
CROPOSPLOT_OPT=--usemarkers --match='$(CROPOSPLOT_MATCH)'
389

390
391
392
393
394
395
396
# ----------------------------------------------------------------------
# reference plots
# ---------------
#
#  Display PSD together with results from foutra. 
#
# compile list of file names as analyzed with foutra
397
CPSD_REFFILES=$(addprefix psd,$(addsuffix foutra.xxx,$(CPSD_SET)))
398
399
# compile list of raw files (apparent instrumental noise and seismic
# background noise separately) analyzed with foutra
400
CPSD_RAWREFFILES=$(addprefix psd,$(addsuffix modfoutra.xxx,$(CPSD_SET) bg1 bg2))
401

402
PSD_RANGE=1.e-14:100.
403
404
# display PSD of raw data (apparent instrumental noise and seismic
# background noise separately)
405
406
PSDraw.pdf: psdraw.xxx $(CPSD_RAWREFFILES)
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
407
	  --ylim=$(PSD_RANGE) \
408
	  $(CROPOSPLOT_OPT) \
409
	  --titfontsize='small' -v --grid -o $@ $^
410

411
412
# display PSD of apparent seismometer output in comparison with foutra
# analysis
413
PSD.pdf: psd_out.xxx $(CPSD_REFFILES)
414
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
415
	  $(CROPOSPLOT_OPT) \
416
	  --titfontsize='small' -v --grid -o $@ $^
417

418
419
# display signal specific coherence
coherence_%.pdf: coherence_out.xxx
420
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
421
422
	  $(CROPOSPLOT_OPT) --nology --ylabel="coherence" \
	  --match='SYN$(patsubst coherence_%.pdf,%,$@)' \
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
	  --titfontsize='small' -v --grid -o $@ $^

# display signal specific transfer factor
transfer_A.pdf: transfer_out.xxx
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --ylabel="ratio" \
	  --match='SYN(1|2|3)/SYN(1|2|3)' \
	  --titfontsize='small' -v --grid -o $@ $^
transfer_B.pdf: transfer_out.xxx
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --ylabel="ratio" \
	  --match='SYN4/|/SYN4' \
	  --titfontsize='small' -v --grid -o $@ $^

# display signal specific phase difference
phase_A.pdf: phase_out.xxx
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --nology --ylabel="difference / rad" \
	  --match='SYN(1|2|3)-SYN(1|2|3)' \
	  --titfontsize='small' -v --grid -o $@ $^
phase_B.pdf: phase_out.xxx
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --nology --ylabel="difference / rad" \
	  --match='SYN4-|-SYN4' \
	  --titfontsize='small' -v --grid -o $@ $^

# display signal specific npsd
NPSD_%.pdf: psdraw.xxx psd_out.xxx \
  npsd_0_out.xxx npsd_1_out.xxx npsd_2_out.xxx npsd_3_out.xxx
	/bin/bash -c 'SIG=$(patsubst NPSD_%.pdf,%,$@); \
	  echo signal: $$SIG; \
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --ylabel="PSD" --ylim=$(PSD_RANGE) \
	  --match="(cpsd$$SIG)|(^PSD SYN$$SIG)|(NPSD SYN$$SIG)" \
	  --titfontsize="small" -v --grid -o $@ $^'

459
460
461
462
463
464
465
466
467
468
# display signal specific npsd (just one case)
SNPSD_%.pdf: psdraw.xxx psd_out.xxx \
  npsd_0_out.xxx npsd_3_out.xxx
	/bin/bash -c 'SIG=$(patsubst SNPSD_%.pdf,%,$@); \
	  echo signal: $$SIG; \
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --ylabel="PSD" --ylim=$(PSD_RANGE) \
	  --match="(cpsd$$SIG)|(^PSD SYN$$SIG)|(NPSD SYN$$SIG)" \
	  --titfontsize="small" -v --grid -o $@ $^'

469
470
# ======================================================================
# cross correlation
471
CROSS_OPT=
472
cross%.bin: $(addprefix cpsd,$(addsuffix mod.bin,$(CPSD_SET) bg1)) 
473
	cross -v -o --itype bin --otype bin $(CROSS_OPT) \
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
	  $(patsubst cross%.bin,cpsd%mod.bin,$@) $^ $@
#
cross%psd.xxx: cross%.bin
	croposp $(CPSD_OPT) --verbose --overwrite --itype bin --trim \
	  --pattern="%F_%NT" \
	  $(CPSD_CROPOSP_OPT) \
	  --datetolerance 0.1 \
	  --psd $@ $^

cross%psd.pdf: cross%psd.xxx
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
	  --ylim=$(PSD_RANGE) \
	  $(CROPOSPLOT_OPT) \
	  --titfontsize='small' -v --grid -o $@ $^

crosscompilation.pdf: $(addprefix cross,$(addsuffix psd.pdf,$(CPSD_SET)))
	pdfjam $^  \
	  --nup 2x2 --landscape --paper a4paper --scale 0.85 -o $@
#
# ======================================================================
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# coherence computation
# ---------------------
#
white1.seed:  ;printf "%s\n" 686293391 > $@
white2.seed:  ;printf "%s\n" 448546898 > $@
WHITEN=100
white1.bin white2.bin: \
  %.bin: %.seed
	/bin/bash -c 'export GSL_RNG_SEED=$$(cat $<); \
	  export GSL_RNG_TYPE=$(RNGTYPE); \
	  siggenx 14 RAW$@ -a 7.07 -v -o -d $(CPSD_DT) -T $(WHITEN) -ot bin; \
	  echo seed: $$GSL_RNG_SEED > $(patsubst %.bin,%seed.xxx,$@)'
	sehefixx RAW$@ $@ \
	  -verbose -overwrite -itype bin -otype bin -ss WHI \
	  -sc $(patsubst white%.bin,%,$@) -si $(WHITEN)


white%_100.bin:
	/bin/rm -fv $(patsubst white%_100.bin,white%.bin,$@)
	$(MAKE) $(patsubst white%_100.bin,white%.bin,$@) WHITEN=100
	/bin/mv -fv $(patsubst white%_100.bin,white%.bin,$@) $@

white%_1000.bin:
	/bin/rm -fv $(patsubst white%_1000.bin,white%.bin,$@)
	$(MAKE) $(patsubst white%_1000.bin,white%.bin,$@) WHITEN=1000
	/bin/mv -fv $(patsubst white%_1000.bin,white%.bin,$@) $@

white%_10000.bin:
	/bin/rm -fv $(patsubst white%_10000.bin,white%.bin,$@)
	$(MAKE) $(patsubst white%_10000.bin,white%.bin,$@) WHITEN=10000
	/bin/mv -fv $(patsubst white%_10000.bin,white%.bin,$@) $@

WHITE_LOG=--log 20
WHITE_CROPOSP_OPT=--nsegments=$(CPSD_NSEGMENTS) \
		     --divisor=$(CPSD_DIVISOR) \
		     --padfactor=$(CPSD_PADFACTOR) \
		     --overlap=$(CPSD_OVERLAP) \
		     $(WHITE_LOG)
whitepsd%.xxx whitecoherence%.xxx: white1_%.bin white2_%.bin
	croposp $(WHITE_CROPOSP_OPT) \
	  --verbose --overwrite --itype bin \
	  --psd $(patsubst white1_%.bin,whitepsd%.xxx,$<) \
	  --pattern="%S_%C_%I" \
	  --coherence $(patsubst white1_%.bin,whitecoherence%.xxx,$<) \
	  $^

# display signal specific coherence
whitecoherence.pdf: $(foreach N,10000 1000 100,whitecoherence$(N).xxx)
	$(CROPOSPLOT) --title="$@ \n $(WHITE_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --ylabel="coherence" \
	  --titfontsize='small' -v --grid -o $@ $^

# display signal specific coherence
whitepsd.pdf: $(foreach N,10000 1000 100,whitepsd$(N).xxx)
	$(CROPOSPLOT) --title="$@ \n $(WHITE_CROPOSP_OPT)" \
	  $(CROPOSPLOT_OPT) --ylabel="PSD" \
	  --titfontsize='small' -v --grid -o $@ $^
#
# ======================================================================
553
# pattern rules for display
554
555
556
# ----------------------------------------------------------------------
# pattern rules for quick plots
# -----------------------------
557
%.pdf: %_out.xxx
558
	$(CROPOSPLOT) --title='$@ \n $(CPSD_CROPOSP_OPT)' \
559
	  $(CROPOSPLOT_OPT) \
560
	  --titfontsize='small' -v --grid -o $@ $<
561
562

%_lin.pdf: %_out.xxx
563
	$(CROPOSPLOT) --title="$@ \n $(CPSD_CROPOSP_OPT)" \
564
	  $(CROPOSPLOT_OPT) \
565
	  --titfontsize='small' -v --grid --nology -o \
566
567
	  $@ $<

568
569
570
# ----------------------------------------------------------------------
#  previewer commands
#  ------------------
571
572
573
%.pdp: %.pdf; evince $<; /bin/rm -fv $<
%.psp: %.ps; gv $<; /bin/rm -fv $<

574
575
576
REPORTVAR=echo $(1)=$($(1));
REPORTVARS=$(foreach var,$(1),$(call REPORTVAR,$(var)))

577
578
579
580
581
582
CPSDSEEDFILES=$(addprefix cpsd,$(addsuffix rawseed.xxx,$(CPSD_SET) bg))
CPSDASCIIFILES=$(addprefix cpsd,$(addsuffix modhd.xxx,$(CPSD_SET) bg1 bg2))

%hd.xxx: %.ascii
	egrep -n '^#' $< > $@

583
.PHONY: report
584
report: $(CPSD_BINFILES) $(CPSDSEEDFILES) $(CPSDASCIIFILES)
585
	sigval -type bin \
586
	  -format "File %F: %NS samples, duration: %L" $(CPSD_BINFILES)
587
588
589
590
	@$(call REPORTVARS,CPSD_NSEGMENTS CPSD_DIVISOR CPSD_OVERLAP)
	@$(call REPORTVARS,CPSD_PADFACTOR CPSD_AVGOUT CPSD_NLOG)
	@$(call REPORTVARS,CPSD_LOG)
	@$(call REPORTVARS,CPSD_DT CPSD_DUR RNGTYPE DISCARDS)
591
592
	@tail -n 999 $(CPSDSEEDFILES)
	@tail -n 999 $(CPSDASCIIFILES)
593

594
# ----- END OF Makefile -----