Makefile 11.3 KB
Newer Older
1
2
3
# this is <Makefile>
# ----------------------------------------------------------------------------
# 
4
5
6
# Copyright (c) 2019 by Thomas Forbriger (BFO Schiltach) 
# 
# compile croposp
7
8
9
10
11
12
13
14
15
16
17
18
19
# 
# ----
# 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
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22
23
# ----
#
# REVISIONS and CHANGES 
24
#    06/02/2019   V1.0   Thomas Forbriger
25
26
# 
# ============================================================================
27
#
28

29
30
31
32
PROGRAMS=croposp
SCRIPTS=croposplot.py

INSTALLEDPROGRAMS=$(addprefix $(LOCBINDIR)/,$(PROGRAMS))
33
INSTALLEDSCRIPTS=$(addprefix $(LOCSCRIPTDIR)/,$(SCRIPTS))
34
35
36
37
38
39
40
41
42
43
44
45

.PHONY: all
all: install doc

.PHONY: list-programs
list-programs:
	echo $(PROGRAMS) | tr ' ' '\n' | sort

.PHONY: doc
doc: doxydoc

.PHONY: install
46
47
install: $(INSTALLEDPROGRAMS) $(INSTALLEDSCRIPTS)

48
49
50
51
$(LOCBINDIR)/%: %
	mkdir -pv $(LOCBINDIR)
	/bin/mv -fv $< $(LOCBINDIR)

52
53
54
55
$(LOCSCRIPTDIR)/%: %
	mkdir -pv $(LOCSCRIPTDIR)
	/bin/cp -fv $< $(LOCSCRIPTDIR)

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
CHECKVAR=$(if $($(1)),,$(error ERROR: missing variable $(1)))
CHECKVARS=$(foreach var,$(1),$(call CHECKVAR,$(var)))

$(call CHECKVARS,LOCINCLUDEDIR LOCLIBDIR LOCBINDIR)
$(call CHECKVARS,TF_LINK_FORTRAN TF_LINK_PGPLOT)

# use STATIC=-static to produce statically linked binaries
STATIC=
FLAGS += $(MYFLAGS)
CPPFLAGS=$(addprefix -I,$(LOCINCLUDEDIR) $(subst :, ,$(SERVERINCLUDEDIR))) \
  $(FLAGS)
CXXFLAGS+=-Wall $(FLAGS)
LDFLAGS=$(addprefix -L,$(LOCLIBDIR) $(subst :, ,$(SERVERLIBDIR))) $(STATIC)

#----------------------------------------------------------------------
# standard edit targets
.PHONY: clean
clean: ; 
	-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
	-find . -name \*.d | xargs --no-run-if-empty /bin/rm -v
76
	-/bin/rm -vf flist *.bin *.o *.xxx *.ps *.pdf *~ $(PROGRAMS)
77
	-/bin/rm -vf *.asc
78
79
80
81
82
83
84

TESTCASEMAKE=$(filter-out %.bak,$(wildcard testcases/Makefile*))

# the frame of doxygen documentation is placed in text files
DOXYTXT=$(wildcard doxygen*.txt */doxygen*txt)  

EDITFILES=Makefile README $(wildcard *.cfg) COPYING $(DOXYTXT) \
85
86
87
88
	    $(filter-out %.bak,$(wildcard README* Makefile*))
EDITSRC=$(wildcard *.cc *.h *.py)

flist: $(EDITFILES) $(TF_EDIT) $(EDITSRC)
89
90
91
92
	echo $(filter $(EDITFILES),$^) | tr ' ' '\n' | sort > $@
	echo "---- source code ----" >> $@
	echo $(filter $(EDITSRC),$^) | tr ' ' '\n' | sort >> $@
	echo "----" >> $@
93
	echo $(filter-out $(EDITFILES) $(EDITSRC),$^) \
94
95
96
97
98
99
100
101
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
	  | tr ' ' '\n' | sort >> $@

.PHONY: edit
edit: flist; vim $<
#----------------------------------------------------------------------
# pattern rules

#----------------------------------------------------------------------
# description and online texts
%.cc %.h: %_help.txt
	echo "// DO NOT EDIT: this file is automatically derived from $<" \
	  > $(patsubst %.txt,%.h,$<)
	echo "extern char $(patsubst %.txt,%,$<)[];" >> $(patsubst %.txt,%.h,$<)
	echo "// DO NOT EDIT: this file is automatically derived from $<" \
	  > $(patsubst %.txt,%.cc,$<)
	echo "#include \"$(patsubst %.txt,%.h,$<)\"" >> $(patsubst %.txt,%.cc,$<)
	echo "char $(patsubst %.txt,%,$<)[]=" >> $(patsubst %.txt,%.cc,$<)
	echo "{" >> $(patsubst %.txt,%.cc,$<)
	cat $< | egrep -v '^#' | sed -e 's/"/\\"/g' \
	  | sed -e 's/$$/\\n"/' | sed -e 's/^/  "/'\
	  >> $(patsubst %.txt,%.cc,$<)
	echo "};" >> $(patsubst %.txt,%.cc,$<)

#----------------------------------------------------------------------
# dependencies
%.d: %.cc
	$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< \
      | sed '\''s,\($(notdir $*)\)\.o[ :]*,$(dir $@)\1.o $@ : ,g'\'' \
        > $@; \
      [ -s $@ ] || rm -f $@'

include $(patsubst %.txt,%.d,$(wildcard *_help.txt)) 
include $(patsubst %.cc,%.d,$(wildcard *.cc)) 

#----------------------------------------------------------------------
# typical combinations of libraries
LIBDATRWXX=-ldatrwxx -lsffxx -ltime++ -lgsexx -laff
131
132
# libgsl is required for random sequence generator in libtsxx
LIBTSIOXX=-ltsioxx -ltsxx -ltfxx $(LIBDATRWXX) -lgsl -lgslcblas
133
134
135
136
137

#----------------------------------------------------------------------
# binary executable targets
# -------------------------

138
139
OBJFILES=pairs_adapter.o \
	   pairs.o \
140
	   triples.o \
141
142
143
144
	   patsubst.o \
	   report_collection.o \
	   write_name_series.o

145
croposptest croposp: \
146
  %: %.o $(OBJFILES)
147
148
149
	$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@ \
	  -lpsdxx -lfourierxx $(LIBTSIOXX) -lfftw3 

150
151
152
153
#======================================================================
# test case
# ---------

154
alldata: cpsd1.bin cpsd2.bin cpsd3.bin cpsd4.bin
155
156
157
158
159
160
161
162
163
164
165
166

CPSD_NSAMPLESRAW=100000
#CPSD_NSAMPLESRAW=1000
CPSD_DT=0.1
CPSD_DUR=8640.
#CPSD_DUR=864.

# create raw time series
CPSD_SIGGENOPT=-v -o -n $(CPSD_NSAMPLESRAW) -d $(CPSD_DT) -T $(CPSD_DUR) -ot bin
CPSD_AMP1=1.e-3
CPSD_AMP2=1.e-4
CPSD_AMP3=3.e-3
167
168
CPSD_AMP4=5.e-5
CPSD_AMPBG=2.
169
170
171
172
173

# location of plot tool
CROPOSPLOT=./croposplot.py

cpsd1raw.bin:
174
175
176
	/bin/bash -c 'export GSL_RNG_SEED=$$(date +"%N"); \
	  siggenx 14 $@ $(CPSD_SIGGENOPT); \
	  echo seed: $$GSL_RNG_SEED'
177
cpsd2raw.bin:
178
179
180
	/bin/bash -c 'export GSL_RNG_SEED=$$(date +"%N"); \
	  siggenx 14 $@ $(CPSD_SIGGENOPT); \
	  echo seed: $$GSL_RNG_SEED'
181
cpsd3raw.bin:
182
183
184
	/bin/bash -c 'export GSL_RNG_SEED=$$(date +"%N"); \
	  siggenx 14 $@ $(CPSD_SIGGENOPT); \
	  echo seed: $$GSL_RNG_SEED'
185
cpsd4raw.bin:
186
187
188
	/bin/bash -c 'export GSL_RNG_SEED=$$(date +"%N"); \
	  siggenx 14 $@ $(CPSD_SIGGENOPT); \
	  echo seed: $$GSL_RNG_SEED'
189
190
# create time series for common noise signal
cpsdbgraw.bin:
191
192
193
194
195
196
	/bin/bash -c 'export GSL_RNG_SEED=$$(date +"%N"); \
	  siggenx 14 $@ $(CPSD_SIGGENOPT); \
	  echo seed: $$GSL_RNG_SEED'

rawsig.ps: cpsd1raw.bin cpsd2raw.bin cpsd3raw.bin cpsd4raw.bin cpsdbgraw.bin
	stuplox -d $@/cps -s x -i -ty bin $^
197
198
199

# modify white noise to channel specific frequency characteristic
cpsd1mod.bin: cpsd1raw.bin
200
	printf "fac  $(CPSD_AMP1)\nlpb  1.,2.\ndif  0\nend\n" \
201
202
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd2mod.bin: cpsd2raw.bin
203
	printf "fac  $(CPSD_AMP2)\nint  0\navg  0end\n" \
204
205
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd3mod.bin: cpsd3raw.bin
206
	printf "fac  $(CPSD_AMP3)\nlpb  10.,2\nend\n" \
207
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
208
cpsd4mod.bin: cpsd4raw.bin
209
	printf "fac  $(CPSD_AMP4)\nhpb  100.0,2\nend\n" \
210
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
211
cpsdbgmod.bin: cpsdbgraw.bin
212
	printf "fac  $(CPSD_AMPBG)\nlpb  2.,4\navg  0\nhpb  200.,2\nend\n" \
213
214
215
	  | tidofi -type bin -Type bin -v -o -cs $@ $<

# add common noise signal to channel specific noise floor
216
cpsd%addraw.bin: cpsd%mod.bin cpsdbgmod.bin
217
	teseco -v -o -a -type bin -Type bin $@ $^
218
219
220
221
222
223
224
225
226
227
228
229
230
231

# modify sensor response
cpsd1add.bin: cpsd1addraw.bin
	printf "fac  1.\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd2add.bin: cpsd2addraw.bin
	printf "fac  1.\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd3add.bin: cpsd3addraw.bin
	printf "fac  1.\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd4add.bin: cpsd4addraw.bin
	printf "lpb  10.,2\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
232
233
234
235
236
237
	
# 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
238
CPSD_DATE4=$(CPSD_DATE).010760
239
240
241
242
243
244
245
246

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
247
248
cpsd4hd.bin: cpsd4add.bin
	sehefixx $< $@ $(CPSD_HDOPTS) -st $(CPSD_DATE4) -si SYN4
249
250
251
252
253

# extract inconsistent time windows
CPSD_TOPT1=-samplesf 3 -samplesl 7
CPSD_TOPT2=-samplesf 25
CPSD_TOPT3=-samplesl 81
254
CPSD_TOPT4=-samplesl 1
255
256
257
258
259
260
261
262
263
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) $@ $<
264
265
266
cpsd4.bin: cpsd4hd.bin
	tijerasxx -verbose -overwrite -iformat bin -oformat bin \
	  $(CPSD_TOPT4) $@ $<
267

268
CPSD_NSEGMENTS=1
269
270
CPSD_OVERLAP=0.5
CPSD_DIVISOR=100
271
272
273
CPSD_PADFACTOR=1
CPSD_NLOG=20
CPSD_LOG=--log $(CPSD_NLOG)
274
275
CPSD_OPT=--DEBUG
CPSD_OPT=
276
OUTPUTS=psd npsd coherency transfer phase
277
278
279
280
281
282
283
284
285
286

CPSD_SET=1 2 3 4
CPSD_SET=1 2 3
CPSD_BINFILES=$(addprefix cpsd,$(addsuffix .bin,$(CPSD_SET)))

CPSD_CROPOSP_OPT=--nsegments=$(CPSD_NSEGMENTS) \
		     --divisor=$(CPSD_DIVISOR) \
		     --padfactor=$(CPSD_PADFACTOR) \
		     --overlap=$(CPSD_OVERLAP) $(CPSD_LOG)
$(addsuffix _out.xxx,$(OUTPUTS)): $(CPSD_BINFILES)
287
	croposp $(CPSD_OPT) --verbose --overwrite --itype bin --trim \
288
	  --pattern="%I" \
289
	  $(CPSD_CROPOSP_OPT) \
290
	  --datetolerance 0.1 \
291
292
293
294
295
	  --psd psd_out.xxx \
	  --npsd npsd_out.xxx \
	  --coherency coherency_out.xxx \
	  --transfer transfer_out.xxx \
	  --phase phase_out.xxx \
296
	  $^
297

298
299
300
301
302
303
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 \
	  -nsegments=20 junk.xxx $^

psd%foutra.xxx: psd%.001.asc
304
	printf "# #1: foutra (reference): %s\n" $< > $@
305
306
	cat $< >> $@

307
308
309
CPSD_REFFILES=$(addprefix psd,$(addsuffix foutra.xxx,$(CPSD_SET)))
PSD.pdf: psd_out.xxx $(CPSD_REFFILES)
	$(CROPOSPLOT) --title="$@ $(CPSD_CROPOSP_OPT)" -v --grid -o $@ $^
310

311
%.pdf: %_out.xxx
312
	$(CROPOSPLOT) --title="$@ $(CPSD_CROPOSP_OPT)" -v --grid -o $@ $<
313

314
%_lin.pdf: %_out.xxx
315
316
	$(CROPOSPLOT) --title="$@ $(CPSD_CROPOSP_OPT)" -v --grid --nology -o \
	  $@ $<
317

318
%.pdp: %.pdf; evince $<; /bin/rm -fv $<
319
%.psp: %.ps; gv $<; /bin/rm -fv $<
320
#
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#======================================================================
# documentation part
# ------------------
#
# targets commonly used:
# ----------------------
#
# make doxyclean        removes all documentation
# make doxydoc          creates doxygen documentation in the DOXYWWWPATH
# make doxyview         creates doxygen documentation and launches netscape to
#                       browse in the documentation
# make doxyconf         edit the doxygen configuration file
#
# If you launch "make doxydoc" the documentation will be written to
# DOXYWWWPATH (see below). This is meant to export the documentation through
# your homepage. The doxyfull directory is just a symbolic link to this
# directory.
#

$(call CHECKVARS,TF_WWWBASEDIR TF_BROWSER)

342
DOXYWWWPATH=$(TF_WWWBASEDIR)/croposp
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

.PHONY: doxyclean doxyview doxydoc doxyconf

doxyclean: ;/bin/rm -rfv $(DOXYWWWPATH)

DOXYSRC=$(DOXYTXT) $(wildcard *.h *.cc *.f)

# create doxygen intermediate configuration
PWD=$(shell env pwd)
doxydoc.xxx: doxydoc.cfg
	sed 's,<OUTPUTDIRECTORY>,$(DOXYWWWPATH),g;s,<STRIPFROMPATH>,$(PWD),g' \
	  $< > $@
# create commented version of doxygen configuration
doxycomm.xxx: doxydoc.cfg
	/bin/cp -vf $< $@; doxygen -u $@

$(DOXYWWWPATH)/html/index.html: doxydoc.xxx $(DOXYSRC)
	mkdir -vp $(DOXYWWWPATH)
	doxygen $<

doxydoc: $(DOXYWWWPATH)/html/index.html

doxyview: $(DOXYWWWPATH)/html/index.html
	$(TF_BROWSER) file:$< &

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