#
# Makefile
#
# Example 1 of the Debian package diploma
#
# Copyright (C) 1999 Andreas Franzen
#
# See the file copyright for details.
#

# The final target is diploma_1.pdf.
diploma_1.pdf : diploma_1.ps
	ps2pdf diploma_1.ps

# The next target is diploma_1.ps. This depends on the
# document in dvi-format and the figures.

diploma_1.ps : diploma_1.dvi src/XRD.eps fig/salt.eps fig/salt2.eps
	dvips -o diploma_1.ps diploma_1

# These are numeric parameters which are included in the text.

parameters = min2theta.tex max2theta.tex stepnumber.tex stepsize.tex \
  lambdaKalpha1.tex lambdaKalpha2.tex lambdaKbeta.tex

# The dvi-file is generated by latex from the tex-source. The bounding boxes
# of the included figures are needed and also the data of the table.

diploma_1.dvi : diploma_1.tex src/XRD.eps fig/salt.eps fig/salt2.eps \
                  res/table1.tex res/result.tex $(parameters)
	latex diploma_1 ; latex diploma_1 ; latex diploma_1

# The program poisson2gauss converts Poisson distributed noise to
# Gaussian distributed noise.

bin/poisson2gauss : src/poisson2gauss.c
	cc -Wall -o bin/poisson2gauss src/poisson2gauss.c -lm

# res/salt1.dat is the original data set converted to Gaussian distributed
# noise and fitted with 2*Theta values to create an xy-data set.

res/salt1.dat : bin/poisson2gauss bin/addx dat/salt.dat
	bin/poisson2gauss < dat/salt.dat | bin/addx > res/salt1.dat

# res/salt2.dat is created like res/salt1.dat with an additional denoising
# stage after the conversion from Poisson distributed noise to Gaussian
# distributed noise.

res/salt2.dat : bin/poisson2gauss bin/addx dat/salt.dat
	bin/poisson2gauss < dat/salt.dat | wzip -hdn 7536 4 | \
          bin/addx > res/salt2.dat

# The program addx is used to fit the measurement data with 2*Theta values.
# It is compiled with cc and depends on its source code src/addx.c and
# an included header file inc/salt.h.

bin/addx : src/addx.c inc/salt.h
	cc -Wall -o bin/addx src/addx.c

# The figure fig/salt.eps is a simple plot of the original measurement data.
# It depends only on the measurement data set dat/salt.dat and is created
# by use of the program graph from the Debian package plotutils.

# The output of graph is piped through the stream editor "sed" to change
# every occurence of "setlinejoin" to "pop 1 setlinejoin". Same with
# "setlinecap". In the standard mode corners of the graph are ploted with
# sharp edges. With a large number of noisy measurement data, this tends
# to visually increase the amplitude of the noise. Mode 1 means rounded
# line joins and line caps.
fig/salt.eps : dat/salt.dat
	graph -T ps -f 0.06 -h 0.4 -a -X "step number" -Y "counts per step" \
          dat/salt.dat | sed -e \
  "s/setlinejoin/pop 1 setlinejoin/g;s/setlinecap/pop 1 setlinecap/g" \
  > fig/salt.eps

# fig/salt2.eps shows the processed data sets res/salt1.dat and res/salt2.dat.

fig/salt2.eps : res/salt1.dat res/salt2.dat
	graph -T ps -f 0.08 -h 0.2 -w 0.6 -u 0.6 \
          --blankout 1.0 \
          -y 0 150 50 res/salt1.dat \
          --reposition 0 -0.26 1.0 \
          -y 0 25 5 -Y "transformed counts per step" res/salt1.dat \
          --reposition 0 -0.52 1.0 \
          -X "diffraction angle 2\*H in \de" -Y "" res/salt2.dat \
          | sed -e \
  "s/setlinejoin/pop 1 setlinejoin/g;s/setlinecap/pop 1 setlinecap/g" \
          > fig/salt2.eps

# The first call of the stream editor sed converts any . into a ,. The
# second replaces any space by an invisible 0.

res/table1.tex : res/table1.dat
	sed y/./,/ < res/table1.dat | sed s/' '/'\\phantom{0}'/g \
          > res/table1.tex

res/table1.dat res/result.tex : bin/table1
	bin/table1 > res/table1.dat

bin/table1 : src/table1.c inc/salt.h
	cc -Wall -o bin/table1 src/table1.c -lm

# The program parameters.c creates files which contain the numerical
# parameters in the text.

bin/parameters : inc/salt.h src/parameters.c
	cc -Wall -o bin/parameters src/parameters.c

$(parameters) : bin/parameters
	bin/parameters
