Makefile 10 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
154
155
156
157
158
159
160
161
162
163
164
165
166
#======================================================================
# test case
# ---------

alldata: cpsd1.bin cpsd2.bin cpsd3.bin

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
CPSD_AMP4=3.e-3
168
169
170
171
172
173
174
175
176
177
178
CPSD_AMPBG=4.e-5

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

cpsd1raw.bin:
	siggenx 12 $@ $(CPSD_SIGGENOPT) -a $(CPSD_AMP1)
cpsd2raw.bin:
	siggenx 12 $@ $(CPSD_SIGGENOPT) -a $(CPSD_AMP2)
cpsd3raw.bin:
	siggenx 12 $@ $(CPSD_SIGGENOPT) -a $(CPSD_AMP3)
179
180
cpsd4raw.bin:
	siggenx 12 $@ $(CPSD_SIGGENOPT) -a $(CPSD_AMP4)
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# create time series for common noise signal
cpsdbgraw.bin:
	siggenx 12 $@ $(CPSD_SIGGENOPT) -a $(CPSD_AMPBG)

# modify white noise to channel specific frequency characteristic
cpsd1mod.bin: cpsd1raw.bin
	printf "lpb  1.,2.\ndif  0\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd2mod.bin: cpsd2raw.bin
	printf "int  0\navg  0end\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
cpsd3mod.bin: cpsd3raw.bin
	printf "lpb  10.,2\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
195
196
197
cpsd4mod.bin: cpsd4raw.bin
	printf "lpb  10.,2\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<
198
199
200
201
202
203
204
205
206
207
208
209
210
cpsdbgmod.bin: cpsdbgraw.bin
	printf "lpb  2.,4\navg  0\nhp  200.,2\nend\n" \
	  | tidofi -type bin -Type bin -v -o -cs $@ $<

# add common noise signal to channel specific noise floor
cpsd%add.bin: cpsd%mod.bin cpsdbgraw.bin
	teseco -v -o -a -type bin -Type bin $@ $^
	
# 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
211
CPSD_DATE4=$(CPSD_DATE).010760
212
213
214
215
216
217
218
219

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
220
221
cpsd4hd.bin: cpsd4add.bin
	sehefixx $< $@ $(CPSD_HDOPTS) -st $(CPSD_DATE4) -si SYN4
222
223
224
225
226

# extract inconsistent time windows
CPSD_TOPT1=-samplesf 3 -samplesl 7
CPSD_TOPT2=-samplesf 25
CPSD_TOPT3=-samplesl 81
227
CPSD_TOPT4=-samplesl 1
228
229
230
231
232
233
234
235
236
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) $@ $<
237
238
239
cpsd4.bin: cpsd4hd.bin
	tijerasxx -verbose -overwrite -iformat bin -oformat bin \
	  $(CPSD_TOPT4) $@ $<
240

241
CPSD_NSEGMENTS=1
242
243
CPSD_OVERLAP=0.5
CPSD_DIVISOR=100
244
245
246
CPSD_PADFACTOR=1
CPSD_NLOG=20
CPSD_LOG=--log $(CPSD_NLOG)
247
248
CPSD_OPT=--DEBUG
CPSD_OPT=
249
OUTPUTS=psd npsd coherency transfer phase
250
$(addsuffix _out.xxx,$(OUTPUTS)): cpsd1.bin cpsd2.bin cpsd3.bin cpsd4.bin
251
	croposp $(CPSD_OPT) --verbose --overwrite --itype bin --trim \
252
	  $(CPSD_LOG) \
253
	  --pattern="%I" \
254
255
256
257
	  --nsegments=$(CPSD_NSEGMENTS) \
	  --divisor=$(CPSD_DIVISOR) \
	  --padfactor=$(CPSD_PADFACTOR) \
	  --overlap=$(CPSD_OVERLAP) \
258
	  --datetolerance 0.1 \
259
260
261
262
263
	  --psd psd_out.xxx \
	  --npsd npsd_out.xxx \
	  --coherency coherency_out.xxx \
	  --transfer transfer_out.xxx \
	  --phase phase_out.xxx \
264
	  $^
265

266
267
268
269
270
271
272
273
274
275
276
277
278
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
	printf "# #1: %s\n" $< > $@
	cat $< >> $@

PSD.pdf: psd_out.xxx psd1foutra.xxx psd2foutra.xxx \
  psd3foutra.xxx psd4foutra.xxx
	$(CROPOSPLOT) -v --grid -o $@ $^

279
%.pdf: %_out.xxx
280
281
	$(CROPOSPLOT) -v --grid -o $@ $<

282
%_lin.pdf: %_out.xxx
283
284
	$(CROPOSPLOT) -v --grid --nology -o $@ $<

285
286
%.pdp: %.pdf; evince $<; /bin/rm -fv $<
#
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#======================================================================
# 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)

308
DOXYWWWPATH=$(TF_WWWBASEDIR)/croposp
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

.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 -----