introduce a separate set of WARNINGS for icpc to reduce noise
(remarks and parallelization stats)
and bump g++ warnings to '-W -Wall'

git-svn-id: 4e7379b20b57f8e3dde5a0b7363f233184647162@608 4e380d45-d1fd-0310-85a7-d18ec86df0ad

# This -*- Makefile -*- is intended for processing with GNU make.

TOPDIR	?= $(error TOPDIR not defined) # DO NOT CHANGE! This is set elsewhere.

# Change this file according to your paths.

# Instead of modifying this file, you could also set your modified variables
# in make.settings.local (needs to be created first).
-include $(TOPDIR)/make.settings.local

USE_BOOST	?= no	# set 'yes' to use Boost libraries or 'no' to not use Boost libraries
USE_LINUX	?= yes	# set 'yes' if you run Linux, 'no' otherwise
USE_MCSTL	?= no	# will be overriden from main Makefile
USE_ICPC	?= no	# will be overriden from main Makefile

STXXL_ROOT	?= $(HOME)/work/stxxl

ifeq ($(strip $(USE_ICPC)),yes)
COMPILER	?= icpc
ICPC_MCSTL_CPPFLAGS	?= -gcc-version=420 -cxxlib#=$(FAKEGCC)
WARNINGS	?= -Wall -w1 -openmp-report0 -vec-report0
endif

ifeq ($(strip $(USE_MCSTL)),yes)
COMPILER	?= g++-4.2
LIBNAME		?= mcstxxl
# the root directory of your MCSTL installation
MCSTL_ROOT	?= $(HOME)/work/mcstl
endif

#BOOST_ROOT	?= /usr/local/boost-1.34.1

COMPILER	?= g++
LINKER		?= $(COMPILER)
OPT		?= -O3 # compiler optimization level
WARNINGS	?= -W -Wall
DEBUG		?= # put here -g option to include the debug information into the binaries

LIBNAME		?= stxxl

#### TROUBLESHOOTING
#
# For automatical checking of order of the output elements in
# the sorters: stxxl::stream::sort, stxxl::stream::merge_runs,
# stxxl::sort, and stxxl::ksort use
#
#STXXL_SPECIFIC	+= -DSTXXL_CHECK_ORDER_IN_SORTS
#
# If your program aborts with message "read/write: wrong parameter"
# or "Invalid argument"
# this could be that your kernel does not support direct I/O
# then try to set it off recompiling the libs and your code with option
#
#STXXL_SPECIFIC	+= -DSTXXL_DIRECT_IO_OFF
#
# But for the best performance it is strongly recommended
# to reconfigure the kernel for the support of the direct I/O.
#
# FIXME: documentation needed
#
#STXXL_SPECIFIC += -DSTXXL_DEBUGMON

#### You usually shouldn't need to change the sections below #####

#### STXXL OPTIONS ###############################################

# check, whether stxxl has been configured
ifeq (,$(strip $(wildcard $(STXXL_ROOT)/include/stxxl.h)))
$(warning *** WARNING: STXXL hasn't been configured correctly) #')
$(error ERROR: could not find a STXXL installation in STXXL_ROOT=$(STXXL_ROOT))
endif

# in the top dir, check whether STXXL_ROOT points to ourselves
ifneq (,$(wildcard make.settings))
stat1	 = $(shell stat -L -c '%d:%i' ./)
stat2	 = $(shell stat -L -c '%d:%i' $(STXXL_ROOT)/)

ifneq ($(stat1),$(stat2))
$(error ERROR: STXXL_ROOT=$(STXXL_ROOT) points to a different STXXL installation)
endif
endif

PTHREAD_FLAG	?= -pthread

STXXL_SPECIFIC	+= \
	$(PTHREAD_FLAG) \
	$(CPPFLAGS_ARCH) \
	-DSORT_OPTIMAL_PREFETCHING \
	-DUSE_MALLOC_LOCK \
	-DCOUNT_WAIT_TIME \
	-I$(strip $(STXXL_ROOT))/include \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
	$(POSIX_MEMALIGN) $(XOPEN_SOURCE)

STXXL_LDFLAGS	+= $(PTHREAD_FLAG)
STXXL_LDLIBS	+= -L$(strip $(STXXL_ROOT))/lib -l$(LIBNAME)

STXXL_LIBDEPS	+= $(strip $(STXXL_ROOT))/lib/lib$(LIBNAME).$(LIBEXT)

UNAME_M		:= $(shell uname -m)
CPPFLAGS_ARCH	+= $(CPPFLAGS_$(UNAME_M))
CPPFLAGS_i686	?= -march=i686

##################################################################

#### ICPC OPTIONS ################################################

ifeq ($(strip $(USE_ICPC)),yes)

OPENMPFLAG	?= -openmp

STXXL_SPECIFIC	+= -include stxxl/bits/common/intel_compatibility.h

endif

##################################################################

#### MCSTL OPTIONS ###############################################

ifeq ($(strip $(USE_MCSTL)),yes)

OPENMPFLAG	?= -fopenmp

ifeq (,$(strip $(wildcard $(strip $(MCSTL_ROOT))/c++/mcstl.h)))
$(error ERROR: could not find a MCSTL installation in MCSTL_ROOT=$(MCSTL_ROOT))
endif

ifeq ($(strip $(USE_ICPC)),yes)
MCSTL_CPPFLAGS		+= $(ICPC_MCSTL_CPPFLAGS)
endif

MCSTL_CPPFLAGS		+= $(OPENMPFLAG) -D__MCSTL__ $(MCSTL_INCLUDES_PREPEND) -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

MCSTL_INCLUDES_PREPEND	+= $(if $(findstring 4.3,$(COMPILER)),-I$(MCSTL_ROOT)/c++/mod_stl/gcc-4.3)

endif

##################################################################

#### BOOST OPTIONS ###############################################

BOOST_COMPILER_OPTIONS	 = \
	-DSTXXL_BOOST_TIMESTAMP \
	-DSTXXL_BOOST_CONFIG \
	-DSTXXL_BOOST_FILESYSTEM \
	-DSTXXL_BOOST_THREADS \
	-DSTXXL_BOOST_RANDOM \
	$(if $(strip $(BOOST_ROOT)),-I$(strip $(BOOST_ROOT)))

BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	-lboost_thread$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_date_time$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_iostreams$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_filesystem$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX)

##################################################################

#### CPPUNIT OPTIONS ############################################

CPPUNIT_COMPILER_OPTIONS	+=

CPPUNIT_LINKER_OPTIONS		+= -lcppunit -ldl

##################################################################

#### DEPENDENCIES ################################################

HEADER_FILES_BITS	+= namespace.h noncopyable.h version.h

HEADER_FILES_COMMON	+= aligned_alloc.h mutex.h rand.h semaphore.h state.h
HEADER_FILES_COMMON	+= timer.h utils.h gprof.h rwlock.h simple_vector.h
HEADER_FILES_COMMON	+= switch.h tmeta.h log.h exceptions.h debug.h tuple.h
HEADER_FILES_COMMON	+= types.h utils_ledasm.h settings.h seed.h

HEADER_FILES_IO		+= completion_handler.h io.h iobase.h iostats.h
HEADER_FILES_IO		+= mmap_file.h simdisk_file.h syscall_file.h
HEADER_FILES_IO		+= ufs_file.h wincall_file.h wfs_file.h boostfd_file.h

HEADER_FILES_MNG	+= adaptor.h async_schedule.h block_prefetcher.h
HEADER_FILES_MNG	+= buf_istream.h buf_ostream.h buf_writer.h mng.h
HEADER_FILES_MNG	+= write_pool.h prefetch_pool.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h queue.h
HEADER_FILES_CONTAINERS	+= map.h deque.h

HEADER_FILES_CONTAINERS_BTREE	+= btree.h iterator_map.h leaf.h node_cache.h
HEADER_FILES_CONTAINERS_BTREE	+= root_node.h node.h btree_pager.h iterator.h

HEADER_FILES_ALGO	+= adaptor.h inmemsort.h intksort.h run_cursor.h sort.h
HEADER_FILES_ALGO	+= async_schedule.h interleaved_alloc.h ksort.h
HEADER_FILES_ALGO	+= losertree.h scan.h stable_ksort.h random_shuffle.h

HEADER_FILES_STREAM	+= stream.h sort_stream.h

HEADER_FILES_UTILS	+= malloc.h

###################################################################

#### MISC #########################################################

DEPEXT	 = $(LIBNAME).d # extension of dependency files
OBJEXT	 = $(LIBNAME).o	# extension of object files
LIBEXT	 = a		# static library file extension
EXEEXT	 = $(LIBNAME).bin # executable file extension
RM	 = rm -f	# remove file command
LIBGEN	 = ar cr	# library generation
OUT	 = -o		# output file option for the compiler and linker

d	?= $(strip $(DEPEXT))
o	?= $(strip $(OBJEXT))
bin	?= $(strip $(EXEEXT))

###################################################################

#### COMPILE/LINK RULES ###########################################

DEPS_MAKEFILES	:= $(wildcard ../Makefile.subdir.gnu ../make.settings ../make.settings.local GNUmakefile Makefile.local)
%.$o: %.cpp $(DEPS_MAKEFILES)
	@$(RM) $@ $*.$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $*.$dT -c $(OUTPUT_OPTION) $< && mv $*.$dT $*.$d

LINK_STXXL	 = $(LINKER) $1 $(STXXL_LINKER_OPTIONS) -o $@

%.$(bin): %.$o $(STXXL_LIBDEPS)
	$(call LINK_STXXL, $<)

###################################################################

STXXL_COMPILER_OPTIONS	+= $(STXXL_SPECIFIC)
STXXL_COMPILER_OPTIONS	+= $(OPT) $(DEBUG) $(WARNINGS)
STXXL_LINKER_OPTIONS	+= $(DEBUG)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDFLAGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS)

ifeq ($(strip $(USE_MCSTL)),yes)
STXXL_COMPILER_OPTIONS	+= $(MCSTL_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(MCSTL_LDFLAGS)
endif

ifeq ($(strip $(USE_BOOST)),yes)
STXXL_COMPILER_OPTIONS	+= $(BOOST_COMPILER_OPTIONS)
STXXL_LINKER_OPTIONS	+= $(BOOST_LINKER_OPTIONS)
endif

STXXL_COMPILER_OPTIONS	+= $(CPPFLAGS)

# vim: syn=make

# This -*- Makefile -*- is intended for processing with GNU make.

TOPDIR	?= $(error TOPDIR not defined) # DO NOT CHANGE! This is set elsewhere.

# Change this file according to your paths.

# Instead of modifying this file, you could also set your modified variables
# in make.settings.local (needs to be created first).
-include $(TOPDIR)/make.settings.local

USE_BOOST	?= no	# set 'yes' to use Boost libraries or 'no' to not use Boost libraries
USE_LINUX	?= yes	# set 'yes' if you run Linux, 'no' otherwise
USE_MCSTL	?= no	# will be overriden from main Makefile
USE_ICPC	?= no	# will be overriden from main Makefile

STXXL_ROOT	?= $(HOME)/work/stxxl

ifeq ($(strip $(USE_ICPC)),yes)
COMPILER	?= icpc
ICPC_MCSTL_CPPFLAGS	?= -gcc-version=420 -cxxlib=$(FAKEGCC)
endif

ifeq ($(strip $(USE_MCSTL)),yes)
COMPILER	?= g++-4.2
LIBNAME		?= mcstxxl
# the root directory of your MCSTL installation
MCSTL_ROOT	?= $(HOME)/work/mcstl
endif

#BOOST_ROOT	?= /usr/local/boost-1.34.1

COMPILER	?= g++
LINKER		?= $(COMPILER)
OPT		?= -O3 # compiler optimization level
WARNINGS	?= -Wall
DEBUG		?= # put here -g option to include the debug information into the binaries

LIBNAME		?= stxxl

#### TROUBLESHOOTING
#
# For automatical checking of order of the output elements in
# the sorters: stxxl::stream::sort, stxxl::stream::merge_runs,
# stxxl::sort, and stxxl::ksort use
#
#STXXL_SPECIFIC	+= -DSTXXL_CHECK_ORDER_IN_SORTS
#
# If your program aborts with message "read/write: wrong parameter"
# or "Invalid argument"
# this could be that your kernel does not support direct I/O
# then try to set it off recompiling the libs and your code with option
#
#STXXL_SPECIFIC	+= -DSTXXL_DIRECT_IO_OFF
#
# But for the best performance it is strongly recommended
# to reconfigure the kernel for the support of the direct I/O.
#
# FIXME: documentation needed
#
#STXXL_SPECIFIC += -DSTXXL_DEBUGMON

#### You usually shouldn't need to change the sections below #####

#### STXXL OPTIONS ###############################################

# check, whether stxxl has been configured
ifeq (,$(strip $(wildcard $(STXXL_ROOT)/include/stxxl.h)))
$(warning *** WARNING: STXXL hasn't been configured correctly) #')
$(error ERROR: could not find a STXXL installation in STXXL_ROOT=$(STXXL_ROOT))
endif

# in the top dir, check whether STXXL_ROOT points to ourselves
ifneq (,$(wildcard make.settings))
stat1	 = $(shell stat -L -c '%d:%i' ./)
stat2	 = $(shell stat -L -c '%d:%i' $(STXXL_ROOT)/)

ifneq ($(stat1),$(stat2))
$(error ERROR: STXXL_ROOT=$(STXXL_ROOT) points to a different STXXL installation)
endif
endif

PTHREAD_FLAG	?= -pthread

STXXL_SPECIFIC	+= \
	$(PTHREAD_FLAG) \
	$(CPPFLAGS_ARCH) \
	-DSORT_OPTIMAL_PREFETCHING \
	-DUSE_MALLOC_LOCK \
	-DCOUNT_WAIT_TIME \
	-I$(strip $(STXXL_ROOT))/include \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
	$(POSIX_MEMALIGN) $(XOPEN_SOURCE)

STXXL_LDFLAGS	+= $(PTHREAD_FLAG)
STXXL_LDLIBS	+= -L$(strip $(STXXL_ROOT))/lib -l$(LIBNAME)

STXXL_LIBDEPS	+= $(strip $(STXXL_ROOT))/lib/lib$(LIBNAME).$(LIBEXT)

UNAME_M		:= $(shell uname -m)
CPPFLAGS_ARCH	+= $(CPPFLAGS_$(UNAME_M))
CPPFLAGS_i686	?= -march=i686

##################################################################

#### ICPC OPTIONS ################################################

ifeq ($(strip $(USE_ICPC)),yes)

OPENMPFLAG	?= -openmp

STXXL_SPECIFIC	+= -include stxxl/bits/common/intel_compatibility.h

endif

##################################################################

#### MCSTL OPTIONS ###############################################

ifeq ($(strip $(USE_MCSTL)),yes)

OPENMPFLAG	?= -fopenmp

ifeq (,$(strip $(wildcard $(strip $(MCSTL_ROOT))/c++/mcstl.h)))
$(error ERROR: could not find a MCSTL installation in MCSTL_ROOT=$(MCSTL_ROOT))
endif

ifeq ($(strip $(USE_ICPC)),yes)
MCSTL_CPPFLAGS		+= $(ICPC_MCSTL_CPPFLAGS)
endif

MCSTL_CPPFLAGS		+= $(OPENMPFLAG) -D__MCSTL__ $(MCSTL_INCLUDES_PREPEND) -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

MCSTL_INCLUDES_PREPEND	+= $(if $(findstring 4.3,$(COMPILER)),-I$(MCSTL_ROOT)/c++/mod_stl/gcc-4.3)

endif

##################################################################

#### BOOST OPTIONS ###############################################

BOOST_COMPILER_OPTIONS	 = \
	-DSTXXL_BOOST_TIMESTAMP \
	-DSTXXL_BOOST_CONFIG \
	-DSTXXL_BOOST_FILESYSTEM \
	-DSTXXL_BOOST_THREADS \
	-DSTXXL_BOOST_RANDOM \
	$(if $(strip $(BOOST_ROOT)),-I$(strip $(BOOST_ROOT)))

BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	-lboost_thread$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_date_time$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_iostreams$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_filesystem$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX)

##################################################################

#### CPPUNIT OPTIONS ############################################

CPPUNIT_COMPILER_OPTIONS	+=

CPPUNIT_LINKER_OPTIONS		+= -lcppunit -ldl

##################################################################

#### DEPENDENCIES ################################################

HEADER_FILES_BITS	+= namespace.h noncopyable.h version.h

HEADER_FILES_COMMON	+= aligned_alloc.h mutex.h rand.h semaphore.h state.h
HEADER_FILES_COMMON	+= timer.h utils.h gprof.h rwlock.h simple_vector.h
HEADER_FILES_COMMON	+= switch.h tmeta.h log.h exceptions.h debug.h tuple.h
HEADER_FILES_COMMON	+= types.h utils_ledasm.h settings.h seed.h

HEADER_FILES_IO		+= completion_handler.h io.h iobase.h iostats.h
HEADER_FILES_IO		+= mmap_file.h simdisk_file.h syscall_file.h
HEADER_FILES_IO		+= ufs_file.h wincall_file.h wfs_file.h boostfd_file.h

HEADER_FILES_MNG	+= adaptor.h async_schedule.h block_prefetcher.h
HEADER_FILES_MNG	+= buf_istream.h buf_ostream.h buf_writer.h mng.h
HEADER_FILES_MNG	+= write_pool.h prefetch_pool.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h queue.h
HEADER_FILES_CONTAINERS	+= map.h deque.h

HEADER_FILES_CONTAINERS_BTREE	+= btree.h iterator_map.h leaf.h node_cache.h
HEADER_FILES_CONTAINERS_BTREE	+= root_node.h node.h btree_pager.h iterator.h

HEADER_FILES_ALGO	+= adaptor.h inmemsort.h intksort.h run_cursor.h sort.h
HEADER_FILES_ALGO	+= async_schedule.h interleaved_alloc.h ksort.h
HEADER_FILES_ALGO	+= losertree.h scan.h stable_ksort.h random_shuffle.h

HEADER_FILES_STREAM	+= stream.h sort_stream.h

HEADER_FILES_UTILS	+= malloc.h

###################################################################

#### MISC #########################################################

DEPEXT	 = $(LIBNAME).d # extension of dependency files
OBJEXT	 = $(LIBNAME).o	# extension of object files
LIBEXT	 = a		# static library file extension
EXEEXT	 = $(LIBNAME).bin # executable file extension
RM	 = rm -f	# remove file command
LIBGEN	 = ar cr	# library generation
OUT	 = -o		# output file option for the compiler and linker

d	?= $(strip $(DEPEXT))
o	?= $(strip $(OBJEXT))
bin	?= $(strip $(EXEEXT))

###################################################################

#### COMPILE/LINK RULES ###########################################

DEPS_MAKEFILES	:= $(wildcard ../Makefile.subdir.gnu ../make.settings ../make.settings.local GNUmakefile Makefile.local)
%.$o: %.cpp $(DEPS_MAKEFILES)
	@$(RM) $@ $*.$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $*.$dT -c $(OUTPUT_OPTION) $< && mv $*.$dT $*.$d

LINK_STXXL	 = $(LINKER) $1 $(STXXL_LINKER_OPTIONS) -o $@

%.$(bin): %.$o $(STXXL_LIBDEPS)
	$(call LINK_STXXL, $<)

###################################################################

STXXL_COMPILER_OPTIONS	+= $(STXXL_SPECIFIC)
STXXL_COMPILER_OPTIONS	+= $(OPT) $(DEBUG) $(WARNINGS)
STXXL_LINKER_OPTIONS	+= $(DEBUG)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDFLAGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS)

ifeq ($(strip $(USE_MCSTL)),yes)
STXXL_COMPILER_OPTIONS	+= $(MCSTL_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(MCSTL_LDFLAGS)
endif

ifeq ($(strip $(USE_BOOST)),yes)
STXXL_COMPILER_OPTIONS	+= $(BOOST_COMPILER_OPTIONS)
STXXL_LINKER_OPTIONS	+= $(BOOST_LINKER_OPTIONS)
endif

STXXL_COMPILER_OPTIONS	+= $(CPPFLAGS)

# vim: syn=make


Got horizontal tics to work.

Got horizontal tics to work.

# BBN ratios plotter
mpl_top    = 0.4 #inch  outer top margin, title goes here
mpl_bot    = 0.7 #inch  outer bottom margin, x label goes here
mpl_left   = 0.8 #inch  outer left margin, y label goes here
mpl_right  = 0.1 #inch  outer right margin, y2 label goes here
mpl_height = 2.0 #inch  height of individual plots
mpl_width  = 3.0 #inch  width of individual plots
mpl_dx     = 0.3 #inch  inter-plot horizontal spacing
mpl_dy     = 0.2 #inch  inter-plot vertical spacing
mpl_ny     = 3   #number of rows
mpl_nx     = 1   #number of columns

# calculate full dimensions
xsize = mpl_left+mpl_right+(mpl_width*mpl_nx)+(mpl_nx-1)*mpl_dx
ysize = mpl_top+mpl_bot+(mpl_ny*mpl_height)+(mpl_ny-1)*mpl_dy

# placement functions
#   rows are numbered from bottom to top
bot(n) = (mpl_bot+(n-1)*mpl_height+(n-1)*mpl_dy)/ysize
top(n)  = 1-((mpl_top+(mpl_ny-n)*(mpl_height+mpl_dy))/ysize)
#   columns are numbered from left to right
left(n) = (mpl_left+(n-1)*mpl_width+(n-1)*mpl_dx)/xsize
right(n)  = 1-((mpl_right+(mpl_nx-n)*(mpl_width+mpl_dx))/xsize)

#set terminal latex
set terminal postscript eps enhanced color dl 2.0 size xsize,ysize "Helvetica" 14
set encoding iso_8859_1
set tics scale 1.8

set output 'bbn-fierz.eps'

set offsets
set autoscale fix
set size 1,1
set nokey

# define x-axis settings for all subplots
set xrange [ -0.2 : 0.2  ] noreverse nowriteback
set xlabel 'Fierz b'
set format x ''
set xtics 0.1
set mxtics 10

# start plotting
set multiplot

#-----------------------------------------------
# Yp
# subplot  1-3
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(3)
set bmargin at screen bot(3)

set title 'BBN from Fierz'
set xlabel ''
set format x ''

set yrange [ 0.22 : 0.27 ] noreverse nowriteback

set ylabel "Yp"
set format y "%1.2f"
set mytics 5

plot 'fierz-study.dat' using 1:2:3 with filledcurves;
#      '' u 1:3 lt -1 notitle, '' u 1:2 lt -1 notitle;
# 'fierz-study.dat' u 1:6:7 "%lf %lf %lf" w filledcu, \
#      '' u 1:6 lt -1 notitle, '' u 1:7 lt -1 notitle, \
# 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle, \
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# D/H and He3/H
# subplot  1-2
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(2)
set bmargin at screen bot(2)

set title ''

set xlabel ''
set format x ''

set ylabel "^3He/H \t\t\t\t\t\t D/H"
set yrange [ 3e-6 : 3e-4 ] noreverse nowriteback
set logscale y 10
set format y "10^{%L}"
set ytics 10
set mytics 10
plot 'fierz-study.dat' using 1:5:4 with filledcurves;
#      '' u 1:5 lt 1 notitle, '' u 1:4 lt 1 notitle;
plot 'fierz-study.dat' using 1:6:7 with filledcurves;
#      '' u 1:7 lt 2 notitle, '' u 1:6 lt 2 notitle;
#plot 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# Li7/H
# subplot  1-1
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(1)
set bmargin at screen bot(1)

set title ''
set xlabel 'Fierz b'

set ylabel "^7Li/H"
set yrange [ 5e-11 : 3e-9 ] noreverse nowriteback
set logscale y 10
set format y "10^{%L}"
set ytics 10
set mytics 10

plot 'fierz-study.dat' using 1:8:9 with filledcurves;
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
#plot 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle;
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

unset multiplot;

# BBN ratios plotter
mpl_top    = 0.4 #inch  outer top margin, title goes here
mpl_bot    = 0.7 #inch  outer bottom margin, x label goes here
mpl_left   = 0.8 #inch  outer left margin, y label goes here
mpl_right  = 0.1 #inch  outer right margin, y2 label goes here
mpl_height = 2.0 #inch  height of individual plots
mpl_width  = 3.0 #inch  width of individual plots
mpl_dx     = 0.3 #inch  inter-plot horizontal spacing
mpl_dy     = 0.3 #inch  inter-plot vertical spacing
mpl_ny     = 3   #number of rows
mpl_nx     = 1   #number of columns

# calculate full dimensions
xsize = mpl_left+mpl_right+(mpl_width*mpl_nx)+(mpl_nx-1)*mpl_dx
ysize = mpl_top+mpl_bot+(mpl_ny*mpl_height)+(mpl_ny-1)*mpl_dy

# placement functions
#   rows are numbered from bottom to top
bot(n) = (mpl_bot+(n-1)*mpl_height+(n-1)*mpl_dy)/ysize
top(n)  = 1-((mpl_top+(mpl_ny-n)*(mpl_height+mpl_dy))/ysize)
#   columns are numbered from left to right
left(n) = (mpl_left+(n-1)*mpl_width+(n-1)*mpl_dx)/xsize
right(n)  = 1-((mpl_right+(mpl_nx-n)*(mpl_width+mpl_dx))/xsize)

#set terminal latex
set terminal postscript eps enhanced color dl 2.0 size xsize,ysize "Helvetica" 14
set encoding iso_8859_1
set tics scale 1.5

set output 'bbn-fierz.eps'

set offsets
set autoscale fix
set size 1,1
set nokey

# define x-axis settings for all subplots
set xrange [ -0.2 : 0.2  ] noreverse nowriteback
#set xrange [-4:4]
set xlabel 'Fierz b'
#set format x ''
set xtics 1
set mxtics 10

# start plotting
set multiplot

#-----------------------------------------------
# Yp
# subplot  1-3
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(3)
set bmargin at screen bot(3)

set title 'BBN from Fierz'
set xlabel ''

set yrange [ 0.22 : 0.27 ] noreverse nowriteback

set ylabel "Yp"
set format y "%1.2f"
#set ytics mirror 1
#set ytics 10
set mytics 5

plot 'fierz-study.dat' u 1:3:2 "%lf %lf %lf" w filledcu, \
      '' u 1:3 lt -1 notitle, '' u 1:2 lt -1 notitle;
# 'fierz-study.dat' u 1:6:7 "%lf %lf %lf" w filledcu, \
#      '' u 1:6 lt -1 notitle, '' u 1:7 lt -1 notitle, \
# 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle, \
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# D/H and He3/H
# subplot  1-2
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(2)
set bmargin at screen bot(2)

set title ''
set xlabel ''

set yrange [ 1e-6 : 1e-4 ] noreverse nowriteback
set logscale y 10

set ylabel "He3/H\t\t\tD/H"
set format y "%1.e"
set mytics 10

plot 'fierz-study.dat' using 1:5:4 with filledcurves;
#      '' u 1:5 lt 1 notitle, '' u 1:4 lt 1 notitle;
plot 'fierz-study.dat' using 1:6:7 with filledcurves;
#      '' u 1:7 lt 2 notitle, '' u 1:6 lt 2 notitle;
#plot 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# Li7/H
# subplot  1-1
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(1)
set bmargin at screen bot(1)

set title ''
set xlabel 'Fierz b'

set yrange [ 1e-10 : 1e-9 ] noreverse nowriteback
set logscale y 10

set ylabel "Li7/H"
set format y "%1.e"
#set ytics mirror 1
#set ytics 1
set mytics 10

plot 'fierz-study.dat' using 1:8:9 with filledcurves;
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
#plot 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle;
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

unset multiplot;


Fixed typo in makefile.gnu

Fixed typo in makefile.gnu

# A simple makefile to be used on Linux, with GNU make.
# To see what it will do, without doing it, run:
# make -n -f makefile.gnu
#
# Norman Dunbar.
# January 2017.
#
# PS. It's "noisy" anyway. So you'll see what's what on the screen.
#

CPP=g++
CPPFLAGS=-std=c++11
TARGET=$(BIN)/TraceMiner2
RM=rm
BIN=./bin

SOURCES=TraceMiner2/TraceMiner2.cpp \
        TraceMiner2/tmoptions.cpp \
        TraceMiner2/tmbind.cpp \
        TraceMiner2/tmcursor.cpp \
        TraceMiner2/tmtracefile.cpp \
        TraceMiner2/utilities.cpp \
        TraceMiner2/parseExec.cpp \
        TraceMiner2/parseParsing.cpp \
        TraceMiner2/parseParse.cpp \
        TraceMiner2/parseBinds.cpp \
        TraceMiner2/parseParseError.cpp \
        TraceMiner2/parseXctend.cpp \
        TraceMiner2/parseError.cpp

OBJECTS=$(SOURCES:.cpp=.o)

all:	traceminer2 $(BIN)

traceminer2:	$(OBJECTS) $(BIN)
	$(CPP) -o $(TARGET) $(OBJECTS)

$(BIN):
	mkdir $(BIN)

clean:
	$(RM) $(OBJECTS)

distclean: clean
	$(RM) -r $(BIN)

# A simple makefile to be used on Linux, with GNU make.
# To see what it will do, without doing it, run:
# make -n -f makefile.gnu
#
# Norman Dunbar.
# January 2017.
#
# PS. It's "noisy" anyway. So you'll see what's what on the screen.
#

CPP=g++
CPPFLAGS=-std=c++11
TARGET=$(BIN)/TraceMiner2
RM=rm
BIN=./bin

SOURCES=TraceMiner2/TraceMiner2.cpp \
        TraceMiner2/tmoptions.cpp \
        TraceMiner2/tmbind.cpp \
        TraceMiner2/tmcursor.cpp \
        TraceMiner2/tmtracefile.cpp \
        TraceMiner2/utilities.cpp \
        TraceMiner2/parseExec.cpp \
        TraceMiner2/parseParsing.cpp \
        TraceMiner2/parseParse.cpp \
        TraceMiner2/parseBinds.cpp \
        TraceMiner2/parseParseError.cpp \
        TraceMiner2/parseXctend.cpp \
        TraceMiner2/parseError.cpp

OBJECTS=$(VARIABLE:.cpp=.o)

all:	traceminer2 $(BIN)

traceminer2:	$(OBJECTS) $(BIN)
	$(CPP) -o $(TARGET) $(OBJECTS)

$(BIN):
	mkdir $(BIN)

clean:
	$(RM) $(OBJECTS)

distclean: clean
	$(RM) -r $(BIN)


update

update

# Tested with gnuplot 4.6 patchlevel 6

# Tablet created/deleted events
FN_IN_CD = system("echo $FN_IN_CD")
# Tablet access counts
FN_IN_AC = system("echo $FN_IN_AC")
FN_OUT = system("echo $FN_OUT")
DESC = system("echo $DESC")

load "../conf/colorscheme.gnuplot"

# Get the plot range
set terminal unknown
set xdata time
set timefmt "%y%m%d-%H%M%S"
plot \
FN_IN_CD u 2:7:2:5:7:($7+$6) w boxxyerrorbars
X_MIN=GPVAL_DATA_X_MIN
X_MAX=GPVAL_DATA_X_MAX
Y_MIN=GPVAL_DATA_Y_MIN
Y_MAX=GPVAL_DATA_Y_MAX

# Get AC_MAX, access count max
set terminal unknown
plot \
FN_IN_AC u 3:($6+$7) w points
AC_MAX=GPVAL_DATA_Y_MAX
set print "-"
print sprintf("Max access count of all tablets: %d", AC_MAX)

set terminal pdfcairo enhanced rounded size 6, 3in
set output FN_OUT

set border (1) front lc rgb "#808080"
set xtics nomirror scale 0.5,0 tc rgb "#808080" autofreq 0,(365.25*24*3600)
unset ytics

set format x "'%y"

# Give some margin on the left and at the bottom
x0=X_MIN-(365.25/12*1.3*24*3600)
x1=X_MAX+(365.25/12*0.5*24*3600)
y0=Y_MIN-(5*1024*1024)
y1=Y_MAX

set xrange [x0:x1]
set yrange [y0:y1]

set key top left

x1p = (X_MAX - X_MIN) / 100
y1p = (Y_MAX - Y_MIN) / 100

# Desc
x0 = X_MIN
y0 = Y_MAX - 3*y1p
set label DESC at x0, y0 left tc rgb "black" font ",7"

TRANSP0=0.06

# Legend
x1 = X_MIN + 11.5*x1p
x2 = x1 + 7*x1p
y2 = y0 - 15*y1p
y1 = y2 - 10*y1p
set object rect from x1, y1 to x2, y2 fc rgb "black" fs transparent solid TRANSP0 noborder
set arrow from x1, y1 to x1, y2 lc rgb "black" nohead

y3 = (y2 + y1) / 2
y4 = y3 + 1.5*y1p
set label "sst\ngen" at x1, y4 right offset -0.5, 0 tc rgb "black" font ",8"

x3 = x1 - 5*x1p
set arrow from x3, y1 to x3, y2 lc rgb "black" nohead

set arrow from x3 - 0.2*x1p, y2 to x3 + 0.2*x1p, y2 lc rgb "black" nohead
set arrow from x3 - 0.2*x1p, y1 to x3 + 0.2*x1p, y1 lc rgb "black" nohead

set label (sprintf("%d MB", (y2 - y1)/1024/1024)) at x3, y2 right offset -0.5, 0 tc rgb "black" font ",8"
set label "0"                                     at x3, y1 right offset -0.5, 0 tc rgb "black" font ",8"

x4 = x3 - 6.5*x1p
set label "Tablet size" at x4, y3 center rotate by 90 tc rgb "black" font ",8"

y4 = y1 - 4*y1p
set arrow from x1, y1 to x1, y4 lt 0 lc rgb "black" nohead
set arrow from x2, y1 to x2, y4 lt 0 lc rgb "black" nohead

y5 = y4 - 2*y1p
set label "created" at x1, y5 center tc rgb "black" font ",8"
set label "deleted" at x2, y5 center tc rgb "black" font ",8"

legendAccesses(x) = (x1 < x) && (x < x2) && (sin(x / (x2 - x1) * pi * 150) > 0) ? \
										y1 + (y2 - y1) * (1 - sin((x - x1) / (x2 - x1) * pi / 2)) + sin(x / (x2 - x1) * pi * 20) * 0.5*y1p \
										: 1 / 0

x5 = x1 + 3*x1p
x6 = x2 + 2*x1p
set arrow from x5, y3 to x6, y3 lt 0 lc rgb "black" nohead

x7 = x6 + x1p
y6 = y3 + 2*y1p
set label "# of accesses\nper day" at x7, y6 left tc rgb "black" font ",8"

# Log scale
#   value range
#     x              : [0, AC_MAX]
#     +1             : [1, AC_MAX+1]
#     log(above)     : [0(=log(1)), log(AC_MAX+1)]
#     / log(AC_MAX+1) : [0, 1]
AccessCountHeight(x) = x == 0 ? \
											 1/0 \
											 : (log(x+1)/log(AC_MAX+1))*10000000

x8 = x7 + 11*x1p
y7 = y3 - AccessCountHeight(AC_MAX) / 2.0
y8 = y3 + AccessCountHeight(AC_MAX) / 2.0
set arrow from x8, y7 to x8, y8 lc rgb "red" nohead
set arrow from x8 - 0.2*x1p, y7 to x8 + 0.2*x1p, y7 lc rgb "red" nohead
set arrow from x8 - 0.2*x1p, y8 to x8 + 0.2*x1p, y8 lc rgb "red" nohead
set label (sprintf("%d", AC_MAX)) at x8, y8 left offset 0.4, 0.1 tc rgb "red" font ",7"
set label "0"                     at x8, y7 left offset 0.4,-0.1 tc rgb "red" font ",7"

set samples 5000

# gnuplot doesn't have a mod function
#   http://www.macs.hw.ac.uk/~ml355/lore/gnuplot.htm
mod(a, b) = a - floor(a/b) * b

color(a) = mod(a, 6)

set style fill solid TRANSP0 noborder

# x  y  xlow  xhigh  ylow  yhigh
plot \
FN_IN_CD u 2:7:2:5:7:($7+$6):(color($1)) w boxxyerrorbars lc variable not, \
FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)):(color($1)) w points pointsize 0.01 lc variable not, \
FN_IN_CD u 2:7:(0):6:(color($1)) w vectors nohead      lt 1 lc variable not, \
FN_IN_CD u 2:($7+$6/2.0):1:(color($1)) w labels right offset -0.5,0 font ",8" tc variable not, \
legendAccesses(x) w lines lc rgb "black" not

# dotted line doesn't work with lc variable
#FN_IN_CD u 4:7:(0):6:(color($1)) w vectors nohead lw 2 lt 0 lc variable not, \

# steps doesn't work with lc variable
#FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)):(color($1)) w steps lc variable not, \
#FN_IN_AC u 3:2:($2 + AccessCountHeight($6+$7)):(color($1)) w filledcurves lc variable not, \

# This doesn't fill the exact same area as the steps, but was the closest thing
# that I can find.
#FN_IN_AC u 3:2:($2 + AccessCountHeight($6+$7)) w filledcurves lc rgb "red" not, \

#FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)) w linespoints pt 7 pointsize 0.1 lc rgb "black" not, \

# no base y option, like y0
#FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)) w fillsteps lc rgb "red" not, \

# Tested with gnuplot 4.6 patchlevel 6

# Tablet created/deleted events
FN_IN_CD = system("echo $FN_IN_CD")
# Tablet access counts
FN_IN_AC = system("echo $FN_IN_AC")
FN_OUT = system("echo $FN_OUT")
DESC = system("echo $DESC")

load "../conf/colorscheme.gnuplot"

# Get the plot range
set terminal unknown
set xdata time
set timefmt "%y%m%d-%H%M%S"
plot \
FN_IN_CD u 2:7:2:5:7:($7+$6) w boxxyerrorbars
X_MIN=GPVAL_DATA_X_MIN
X_MAX=GPVAL_DATA_X_MAX
Y_MIN=GPVAL_DATA_Y_MIN
Y_MAX=GPVAL_DATA_Y_MAX

# Get AC_MAX, access count max
set terminal unknown
plot \
FN_IN_AC u 3:($6+$7) w points
AC_MAX=GPVAL_DATA_Y_MAX
set print "-"
print sprintf("Max access count of all tablets: %d", AC_MAX)

set terminal pdfcairo enhanced rounded size 6, 3in
set output FN_OUT

set border (1) front lc rgb "#808080"
set xtics nomirror scale 0.5,0 tc rgb "#808080" autofreq 0,(365.25*24*3600)
unset ytics

set format x "'%y"

# Give some margin on the left and at the bottom
x0=X_MIN-(365.25/12*1.3*24*3600)
x1=X_MAX+(365.25/12*0.5*24*3600)
y0=Y_MIN-(5*1024*1024)
y1=Y_MAX

set xrange [x0:x1]
set yrange [y0:y1]

set key top left

x1p = (X_MAX - X_MIN) / 100
y1p = (Y_MAX - Y_MIN) / 100

# Desc
x0 = X_MIN
y0 = Y_MAX - 3*y1p
set label DESC at x0, y0 left tc rgb "black" font ",7"

TRANSP0=0.06

# Legend
x1 = X_MIN + 11.5*x1p
x2 = x1 + 7*x1p
y2 = y0 - 15*y1p
y1 = y2 - 10*y1p
set object rect from x1, y1 to x2, y2 fc rgb "black" fs transparent solid TRANSP0 noborder
set arrow from x1, y1 to x1, y2 lc rgb "black" nohead

y3 = (y2 + y1) / 2
y4 = y3 + 1.5*y1p
set label "sst\ngen" at x1, y4 right offset -0.5, 0 tc rgb "black" font ",8"

x3 = x1 - 5*x1p
set arrow from x3, y1 to x3, y2 lc rgb "black" nohead

set arrow from x3 - 0.2*x1p, y2 to x3 + 0.2*x1p, y2 lc rgb "black" nohead
set arrow from x3 - 0.2*x1p, y1 to x3 + 0.2*x1p, y1 lc rgb "black" nohead

set label (sprintf("%d MB", (y2 - y1)/1024/1024)) at x3, y2 right offset -0.5, 0 tc rgb "black" font ",8"
set label "0"                                     at x3, y1 right offset -0.5, 0 tc rgb "black" font ",8"

x4 = x3 - 6.5*x1p
set label "Tablet size" at x4, y3 center rotate by 90 tc rgb "black" font ",8"

y4 = y1 - 4*y1p
set arrow from x1, y1 to x1, y4 lt 0 lc rgb "black" nohead
set arrow from x2, y1 to x2, y4 lt 0 lc rgb "black" nohead

y5 = y4 - 2*y1p
set label "created" at x1, y5 center tc rgb "black" font ",8"
set label "deleted" at x2, y5 center tc rgb "black" font ",8"

legendAccesses(x) = (x1 < x) && (x < x2) && (sin(x / (x2 - x1) * pi * 150) > 0) ? \
										y1 + (y2 - y1) * (1 - sin((x - x1) / (x2 - x1) * pi / 2)) + sin(x / (x2 - x1) * pi * 20) * 0.5*y1p \
										: 1 / 0

x5 = x1 + 3*x1p
x6 = x2 + 2*x1p
set arrow from x5, y3 to x6, y3 lt 0 lc rgb "black" nohead

x7 = x6 + x1p
y6 = y3 + 2*y1p
set label "# of accesses\nper day" at x7, y6 left tc rgb "black" font ",8"

# Log scale
#   value range
#     x              : [0, AC_MAX]
#     +1             : [1, AC_MAX+1]
#     log(above)     : [0(=log(1)), log(AC_MAX+1)]
#     / log(AC_MAX+1) : [0, 1]
AccessCountHeight(x) = x == 0 ? \
											 1/0 \
											 : (log(x+1)/log(AC_MAX+1))*10000000

x8 = x7 + 11*x1p
y7 = y3 - AccessCountHeight(AC_MAX) / 2.0
y8 = y3 + AccessCountHeight(AC_MAX) / 2.0
set arrow from x8, y7 to x8, y8 lc rgb "red" nohead
set arrow from x8 - 0.2*x1p, y7 to x8 + 0.2*x1p, y7 lc rgb "red" nohead
set arrow from x8 - 0.2*x1p, y8 to x8 + 0.2*x1p, y8 lc rgb "red" nohead
set label (sprintf("%d", AC_MAX)) at x8, y8 left offset 0.4, 0.1 tc rgb "red" font ",7"
set label "0"                     at x8, y7 left offset 0.4,-0.1 tc rgb "red" font ",7"

set samples 5000

# gnuplot doesn't have a mod function
#   http://www.macs.hw.ac.uk/~ml355/lore/gnuplot.htm
mod(a, b) = a - floor(a/b) * b

color(a) = mod(a, 6)

set style fill solid TRANSP0 noborder

# x  y  xlow  xhigh  ylow  yhigh
plot \
FN_IN_CD u 2:7:2:5:7:($7+$6):(color($1)) w boxxyerrorbars lc variable not, \
FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)):(color($1)) w points pointsize 0.01 lc variable not, \
FN_IN_CD u 2:7:(0):6:(color($1)) w vectors nohead      lt 1 lc variable not, \
FN_IN_CD u 4:7:(0):6:(color($1)) w vectors nohead lw 2 lt 0 lc variable not, \
FN_IN_CD u 2:($7+$6/2.0):1:(color($1)) w labels right offset -0.5,0 font ",8" tc variable not, \
legendAccesses(x) w lines lc rgb "black" not

# steps doesn't work with lc variable
#FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)):(color($1)) w steps lc variable not, \
#FN_IN_AC u 3:2:($2 + AccessCountHeight($6+$7)):(color($1)) w filledcurves lc variable not, \

# This doesn't fill the exact same area as the steps, but was the closest thing
# that I can find.
#FN_IN_AC u 3:2:($2 + AccessCountHeight($6+$7)) w filledcurves lc rgb "red" not, \

#FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)) w linespoints pt 7 pointsize 0.1 lc rgb "black" not, \

# no base y option, like y0
#FN_IN_AC u 3:($2 + AccessCountHeight($6+$7)) w fillsteps lc rgb "red" not, \


visibilize grid

visibilize grid

#!/usr/bin/env gnuplot

# graph of CPU load

# datafiles
ifnameh = "/tmp/lnxdiagd/mysql/sql12h.csv"
ifnamed = "/tmp/lnxdiagd/mysql/sql12d.csv"
ifnamew = "/tmp/lnxdiagd/mysql/sql12w.csv"
set output ofname = "/tmp/lnxdiagd/site/img/day12.png"

# ******************************************************* General settings *****
set terminal png truecolor enhanced font "Vera,9" size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput

Xh_min = X_min + utc_offset - 946684800
Xh_max = X_max + utc_offset - 946684800

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput

Xd_min = X_min + utc_offset - 946684800
Xd_max = X_max + utc_offset - 946684800

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - 946684800
Xw_max = X_max + utc_offset - 946684800

set multiplot layout 1, 3 title "CPU Usage \\& Load ".strftime("( %Y-%m-%dT%H:%M )", time(0)+utc_offset)

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Usage [%]"
set yrange [ 0 : 100 ]
set y2range [ 0 : 2 ]

# ***************************************************************** Legend *****
set key opaque box inside top left
set key samplen 0.1
set key reverse horizontal Left
set key maxcols 4

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
set style data boxes
set style fill solid noborder

plot ifnamew \
      using ($2+utc_offset):($10+$11+$12+$13) title "idle"    fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     title "waiting" fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         title "system"  fc "yellow"         \
  ,'' using ($2+utc_offset):10                title "user"    fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 title "load 5min" with lines lw 0.1 fc "black" axes x1y2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ 0 : 100 ]
set y2range [ 0 : 2 ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):($10+$11+$12+$13) fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         fc "yellow"         \
  ,'' using ($2+utc_offset):10                fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 with lines lw 0.1 fc "black" axes x1y2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ 0 : 100 ]

# **************************************************************** Y2-axis *****
set y2label "Load"
#set autoscale y2
set y2range [0:2]
set y2tics border

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):($10+$11+$12+$13) fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         fc "yellow"         \
  ,'' using ($2+utc_offset):10                fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 with lines lw 0.1 fc "black" axes x1y2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot

#!/usr/bin/env gnuplot

# graph of CPU load

# datafiles
ifnameh = "/tmp/lnxdiagd/mysql/sql12h.csv"
ifnamed = "/tmp/lnxdiagd/mysql/sql12d.csv"
ifnamew = "/tmp/lnxdiagd/mysql/sql12w.csv"
set output ofname = "/tmp/lnxdiagd/site/img/day12.png"

# ******************************************************* General settings *****
set terminal png truecolor enhanced font "Vera,9" size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput

Xh_min = X_min + utc_offset - 946684800
Xh_max = X_max + utc_offset - 946684800

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput

Xd_min = X_min + utc_offset - 946684800
Xd_max = X_max + utc_offset - 946684800

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - 946684800
Xw_max = X_max + utc_offset - 946684800

set multiplot layout 1, 3 title "CPU Usage \\& Load ".strftime("( %Y-%m-%dT%H:%M )", time(0)+utc_offset)

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Usage [%]"
set yrange [ 0 : 100 ]
set y2range [ 0 : 2 ]

# ***************************************************************** Legend *****
set key opaque box inside top left
set key samplen 0.1
set key reverse horizontal Left
set key maxcols 4

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
set style data boxes
set style fill solid noborder

plot ifnamew \
      using ($2+utc_offset):($10+$11+$12+$13) title "idle"    fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     title "waiting" fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         title "system"  fc "yellow"         \
  ,'' using ($2+utc_offset):10                title "user"    fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 title "load 5min" with lines lw 0.1 fc "black" axes x1y2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ 0 : 100 ]
set y2range [ 0 : 2 ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):($10+$11+$12+$13) fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         fc "yellow"         \
  ,'' using ($2+utc_offset):10                fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 with lines lw 0.1 fc "black" axes x1y2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ 0 : 100 ]

# **************************************************************** Y2-axis *****
set y2label "Load"
#set autoscale y2
set y2range [0:2]
set y2tics border

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):($10+$11+$12+$13) fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         fc "yellow"         \
  ,'' using ($2+utc_offset):10                fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 with lines lw 0.1 fc "black" axes x1y2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot


fix Ymin

fix Ymin

#!/usr/bin/env gnuplot

# graph of battery voltage

# datafiles
ifnameh = "/tmp/upsdiagd/mysql/upsh.csv"
ifnamed = "/tmp/upsdiagd/mysql/upsd.csv"
ifnamew = "/tmp/upsdiagd/mysql/upsw.csv"
set output "/tmp/upsdiagd/site/img/ups14.png"

# ******************************************************* General settings *****
set terminal png enhanced font "Vera,9" size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
if (GPVAL_VERSION == 4.6) {epoch_compensate = 946684800} else {if (GPVAL_VERSION == 5.0) {epoch_compensate = 0}}
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput

Xh_min = X_min + utc_offset - epoch_compensate
Xh_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnameh using 4 name "Yh" nooutput

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput

Xd_min = X_min + utc_offset - epoch_compensate
Xd_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnamed using 4 name "Yd" nooutput

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - epoch_compensate
Xw_max = X_max + utc_offset - epoch_compensate

# stats for Y-axis
stats ifnamew using 4 name "Yw" nooutput

Ymax = max(max(Yd_max, Yh_max), Yw_max)
Ymin = min(min(Yd_min, Yh_min), Yw_min)
R10 = (Ymax - Ymin) * 0.1
Ymax = Ymax + R10
# Ymin = Ymin - R10
Ymin = 0

set multiplot layout 1, 3 title "Batterij spanning ".strftime("( %Y-%m-%dT%H:%M:%S )", time(0)+utc_offset)

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Spanning [V]"
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
plot ifnamew \
      using ($2+utc_offset):4 title " Spanning [V]" with lines lw 0.1 fc rgb "#ccbb0000"
      # with points pt 5 ps 0.2 fc rgb "#ccbb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):4 with lines lw 0.1 fc rgb "#ccbb0000"
      # with points pt 5 ps 0.2 fc rgb "#ccbb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):4 with lines lw 0.1 fc rgb "#ccbb0000"
      # with points pt 5 ps 0.2 fc rgb "#ccbb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot

#!/usr/bin/env gnuplot

# graph of battery voltage

# datafiles
ifnameh = "/tmp/upsdiagd/mysql/upsh.csv"
ifnamed = "/tmp/upsdiagd/mysql/upsd.csv"
ifnamew = "/tmp/upsdiagd/mysql/upsw.csv"
set output "/tmp/upsdiagd/site/img/ups14.png"

# ******************************************************* General settings *****
set terminal png enhanced font "Vera,9" size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
if (GPVAL_VERSION == 4.6) {epoch_compensate = 946684800} else {if (GPVAL_VERSION == 5.0) {epoch_compensate = 0}}
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput

Xh_min = X_min + utc_offset - epoch_compensate
Xh_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnameh using 4 name "Yh" nooutput

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput

Xd_min = X_min + utc_offset - epoch_compensate
Xd_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnamed using 4 name "Yd" nooutput

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - epoch_compensate
Xw_max = X_max + utc_offset - epoch_compensate

# stats for Y-axis
stats ifnamew using 4 name "Yw" nooutput

Ymax = max(max(Yd_max, Yh_max), Yw_max)
Ymin = min(min(Yd_min, Yh_min), Yw_min)
R10 = (Ymax - Ymin) * 0.1
Ymax = Ymax + R10
Ymin = Ymin - R10

set multiplot layout 1, 3 title "Batterij spanning ".strftime("( %Y-%m-%dT%H:%M:%S )", time(0)+utc_offset)

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Spanning [V]"
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
plot ifnamew \
      using ($2+utc_offset):4 title " Spanning [V]" with lines lw 0.1 fc rgb "#ccbb0000"
      # with points pt 5 ps 0.2 fc rgb "#ccbb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):4 with lines lw 0.1 fc rgb "#ccbb0000"
      # with points pt 5 ps 0.2 fc rgb "#ccbb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):4 with lines lw 0.1 fc rgb "#ccbb0000"
      # with points pt 5 ps 0.2 fc rgb "#ccbb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot


update boost handling to work on Debian out-of-the-box

git-svn-id: 4e7379b20b57f8e3dde5a0b7363f233184647162@484 4e380d45-d1fd-0310-85a7-d18ec86df0ad

# This -*- Makefile -*- is intended for processing with GNU make.

# Change this file according to your paths.

# Instead of modifying this file, you could also set your modified variables
# in make.settings.local (needs to be created first).
-include $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))make.settings.local

USE_BOOST	?= no	# set 'yes' to use Boost libraries or 'no' to not use Boost libraries
USE_LINUX	?= yes	# set 'yes' if you run Linux, 'no' otherwise
USE_MCSTL	?= no	# will be overriden from main Makefile
USE_ICPC	?= no	# will be overriden from main Makefile

STXXL_ROOT	?= $(HOME)/work/stxxl

ifeq ($(strip $(USE_ICPC)),yes)
COMPILER	?= icpc
OPENMPFLAG	?= -openmp
ICPC_MCSTL_CPPFLAGS	?= -gcc-version=420 -cxxlib=$(FAKEGCC)
endif

ifeq ($(strip $(USE_MCSTL)),yes)
COMPILER	?= g++-4.2
OPENMPFLAG	?= -fopenmp
LIBNAME		?= mcstxxl
# the base directory of your MCSTL installation
MCSTL_BASE	?= $(HOME)/work/mcstl
# mcstl branch, leave empty for default branch (e.g. if installed from release tarball)
MCSTL_BRANCH	?= #branches/standalone
# only set the following variables if autodetection does not work:
#MCSTL_ROOT		?= $(MCSTL_BASE)/$(MCSTL_BRANCH)
#MCSTL_ORIGINAL_INC_CXX	?= /path/to/your/$(COMPILER)'s/include/c++
#MCSTL_ORIGINALS	?= /where/you/put/the/original/symlink
endif

BOOST_INCLUDE	?= /usr/include/boost

COMPILER	?= g++
LINKER		?= $(COMPILER)
OPT		?= -O3 # compiler optimization level
WARNINGS	?= -Wall
DEBUG		?= # put here -g option to include the debug information into the binaries

LIBNAME		?= stxxl

#### TROUBLESHOOTING
#
# For automatical checking of order of the output elements in
# the sorters: stxxl::stream::sort, stxxl::stream::merge_runs,
# stxxl::sort, and stxxl::ksort use
#
#STXXL_SPECIFIC	+= -DSTXXL_CHECK_ORDER_IN_SORTS
#
# If your program aborts with message "read/write: wrong parameter"
# or "Invalid argument"
# this could be that your kernel does not support direct I/O
# then try to set it off recompiling the libs and your code with option
#
#STXXL_SPECIFIC	+= -DSTXXL_DIRECT_IO_OFF
#
# But for the best performance it is strongly recommended
# to reconfigure the kernel for the support of the direct I/O.
#
# FIXME: documentation needed
#
#STXXL_SPECIFIC += -DSTXXL_DEBUGMON

#### You usually shouldn't need to change the sections below #####

#### STXXL OPTIONS ###############################################

STXXL_SPECIFIC	+= \
	$(CPPFLAGS_ARCH) \
	-DSORT_OPTIMAL_PREFETCHING \
	-DUSE_MALLOC_LOCK \
	-DCOUNT_WAIT_TIME \
	-I$(strip $(STXXL_ROOT))/include \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
	$(POSIX_MEMALIGN) $(XOPEN_SOURCE)

STXXL_LDLIBS	+= -L$(strip $(STXXL_ROOT))/lib -l$(LIBNAME) -lpthread

STXXL_LIBDEPS	+= $(strip $(STXXL_ROOT))/lib/lib$(LIBNAME).$(LIBEXT)

UNAME_M		:= $(shell uname -m)
CPPFLAGS_ARCH	+= $(CPPFLAGS_$(UNAME_M))
CPPFLAGS_i686	?= -march=i686

##################################################################

#### ICPC OPTIONS ################################################

ifeq ($(strip $(USE_ICPC)),yes)

endif

##################################################################

#### MCSTL OPTIONS ###############################################

ifeq ($(strip $(USE_MCSTL)),yes)

MCSTL_ROOT		?= $(strip $(MCSTL_BASE))$(if $(strip $(MCSTL_BRANCH)),/$(strip $(MCSTL_BRANCH)))

ifeq (,$(strip $(wildcard $(MCSTL_ROOT)/c++/mcstl.h)))
$(error ERROR: could not find a MCSTL installation in MCSTL_ROOT=$(MCSTL_ROOT))
endif

ifeq ($(strip $(USE_ICPC)),yes)
MCSTL_CPPFLAGS		+= $(ICPC_MCSTL_CPPFLAGS)
endif

MCSTL_CPPFLAGS		+= $(OPENMPFLAG) -D__MCSTL__ $(MCSTL_INCLUDES_PREPEND) -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

ifeq (,$(strip $(wildcard $(MCSTL_ROOT)/c++/bits/stl_algo.h)))
# not from libstdc++ branch, need to find the correct original symlink

ifneq (,$(strip $(wildcard $(MCSTL_ROOT)/originals)))
MCSTL_ORIG_BASE		?= $(MCSTL_ROOT)
endif
MCSTL_ORIG_BASE		?= $(MCSTL_BASE)

# find a KEY=VALUE element in WORDS and return VALUE
# usage: $(call get_value,KEY,WORDS)
get_value		 = $(subst $(1)=,,$(filter $(1)=%,$(2)))
empty			 =#
space			 = $(empty) $(empty)
gcc_version_result	:= $(shell $(COMPILER) -v 2>&1)
gcc_version		 = $(call get_value,THE_GCC_VERSION,$(subst gcc$(space)version$(space),THE_GCC_VERSION=,$(gcc_version_result)))
gcc_prefix		 = $(call get_value,--prefix,$(gcc_version_result))
gcc_gxx_incdir		 = $(call get_value,--with-gxx-include-dir,$(gcc_version_result))
MCSTL_ORIGINAL_INC_CXX	?= $(firstword $(wildcard $(gcc_gxx_incdir) $(gcc_prefix)/include/c++/$(gcc_version)) $(cxx_incdir_from_compile))
ifeq (,$(strip $(MCSTL_ORIGINAL_INC_CXX)))
# do a test compilation, generate dependencies and parse the header paths
compile_test_vector_deps:= $(shell echo -e '\043include <vector>' > cxx-header-path-test.cpp; $(COMPILER) -M cxx-header-path-test.cpp 2>/dev/null; $(RM) cxx-header-path-test.cpp)
cxx_incdir_from_compile	 = $(patsubst %/vector,%,$(firstword $(filter %/vector, $(compile_test_vector_deps))))
export cxx_incdir_from_compile
endif
MCSTL_ORIGINALS		?= $(strip $(MCSTL_ORIG_BASE))/originals/$(subst /,_,$(MCSTL_ORIGINAL_INC_CXX))

ifeq (,$(strip $(MCSTL_ORIGINAL_INC_CXX)))
$(error ERROR: could not determine MCSTL_ORIGINAL_INC_CXX, please set this variable manually, it's your compilers ($(COMPILER)) include/c++ path)
endif
ifeq (,$(strip $(wildcard $(MCSTL_ORIGINALS)/original)))
$(error ERROR: your mcstl in $(MCSTL_ORIG_BASE) is not configured properly: $(MCSTL_ORIGINALS)/original does not exist)
endif

MCSTL_CPPFLAGS		+= -I$(MCSTL_ORIGINALS)

else # from libstdc++ branch

MCSTL_INCLUDES_PREPEND	+= $(if $(findstring 4.3,$(COMPILER)),-I$(MCSTL_ROOT)/c++/mod_stl/gcc-4.3)

endif # (not) from libstdc++ branch

endif

##################################################################

#### BOOST OPTIONS ###############################################

BOOST_COMPILER_OPTIONS	 = \
	-DSTXXL_BOOST_TIMESTAMP \
	-DSTXXL_BOOST_CONFIG \
	-DSTXXL_BOOST_FILESYSTEM \
	-DSTXXL_BOOST_THREADS \
	-DSTXXL_BOOST_RANDOM \
	-I$(strip $(BOOST_INCLUDE)) \
	-pthread

BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	-lboost_thread$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_date_time$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_iostreams$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_filesystem$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX)

##################################################################

#### CPPUNIT OPTIONS ############################################

CPPUNIT_COMPILER_OPTIONS	+=

CPPUNIT_LINKER_OPTIONS		+= -lcppunit -ldl

##################################################################

#### DEPENDENCIES ################################################

HEADER_FILES_BITS	+= namespace.h version.h

HEADER_FILES_COMMON	+= aligned_alloc.h mutex.h rand.h semaphore.h state.h
HEADER_FILES_COMMON	+= timer.h utils.h gprof.h rwlock.h simple_vector.h
HEADER_FILES_COMMON	+= switch.h tmeta.h log.h exceptions.h debug.h tuple.h
HEADER_FILES_COMMON	+= types.h utils_ledasm.h settings.h

HEADER_FILES_IO		+= completion_handler.h io.h iobase.h iostats.h
HEADER_FILES_IO		+= mmap_file.h simdisk_file.h syscall_file.h
HEADER_FILES_IO		+= ufs_file.h wincall_file.h wfs_file.h boostfd_file.h

HEADER_FILES_MNG	+= adaptor.h async_schedule.h block_prefetcher.h
HEADER_FILES_MNG	+= buf_istream.h buf_ostream.h buf_writer.h mng.h
HEADER_FILES_MNG	+= write_pool.h prefetch_pool.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h queue.h
HEADER_FILES_CONTAINERS	+= map.h deque.h

HEADER_FILES_CONTAINERS_BTREE	+= btree.h iterator_map.h leaf.h node_cache.h
HEADER_FILES_CONTAINERS_BTREE	+= root_node.h node.h btree_pager.h iterator.h

HEADER_FILES_ALGO	+= adaptor.h inmemsort.h intksort.h run_cursor.h sort.h
HEADER_FILES_ALGO	+= async_schedule.h interleaved_alloc.h ksort.h
HEADER_FILES_ALGO	+= losertree.h scan.h stable_ksort.h random_shuffle.h

HEADER_FILES_STREAM	+= stream.h sort_stream.h

HEADER_FILES_UTILS	+= malloc.h

###################################################################

#### MISC #########################################################

DEPEXT	 = $(LIBNAME).d # extension of dependency files
OBJEXT	 = $(LIBNAME).o	# extension of object files
LIBEXT	 = a		# static library file extension
EXEEXT	 = $(LIBNAME).bin # executable file extension
RM	 = rm -f	# remove file command
LIBGEN	 = ar cr	# library generation
OUT	 = -o		# output file option for the compiler and linker

d	?= $(strip $(DEPEXT))
o	?= $(strip $(OBJEXT))
bin	?= $(strip $(EXEEXT))

###################################################################

#### COMPILE/LINK RULES ###########################################

%.$o: %.cpp ../make.settings
	@$(RM) $*.$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $*.$dT -c $(OUTPUT_OPTION) $< && mv $*.$dT $*.$d

LINK_STXXL	 = $(LINKER) $1 $(STXXL_LINKER_OPTIONS) -o $@

%.$(bin): %.$o $(STXXL_LIBDEPS)
	$(call LINK_STXXL, $<)

###################################################################

STXXL_COMPILER_OPTIONS	+= $(STXXL_SPECIFIC)
STXXL_COMPILER_OPTIONS	+= $(OPT) $(DEBUG) $(WARNINGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS)

ifeq ($(strip $(USE_MCSTL)),yes)
STXXL_COMPILER_OPTIONS	+= $(MCSTL_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(MCSTL_LDFLAGS)
endif

ifeq ($(strip $(USE_BOOST)),yes)
STXXL_COMPILER_OPTIONS	+= $(BOOST_COMPILER_OPTIONS)
STXXL_LINKER_OPTIONS	+= $(BOOST_LINKER_OPTIONS)
endif

STXXL_COMPILER_OPTIONS	+= $(CPPFLAGS)

# vim: syn=make

# This -*- Makefile -*- is intended for processing with GNU make.

# Change this file according to your paths.

# Instead of modifying this file, you could also set your modified variables
# in make.settings.local (needs to be created first).
-include $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))make.settings.local

USE_BOOST	?= no	# set 'yes' to use Boost libraries or 'no' to not use Boost libraries
USE_LINUX	?= yes	# set 'yes' if you run Linux, 'no' otherwise
USE_MCSTL	?= no	# will be overriden from main Makefile
USE_ICPC	?= no	# will be overriden from main Makefile

STXXL_ROOT	?= $(HOME)/work/stxxl

ifeq ($(strip $(USE_ICPC)),yes)
COMPILER	?= icpc
OPENMPFLAG	?= -openmp
ICPC_MCSTL_CPPFLAGS	?= -gcc-version=420 -cxxlib=$(FAKEGCC)
endif

ifeq ($(strip $(USE_MCSTL)),yes)
COMPILER	?= g++-4.2
OPENMPFLAG	?= -fopenmp
LIBNAME		?= mcstxxl
# the base directory of your MCSTL installation
MCSTL_BASE	?= $(HOME)/work/mcstl
# mcstl branch, leave empty for default branch (e.g. if installed from release tarball)
MCSTL_BRANCH	?= #branches/standalone
# only set the following variables if autodetection does not work:
#MCSTL_ROOT		?= $(MCSTL_BASE)/$(MCSTL_BRANCH)
#MCSTL_ORIGINAL_INC_CXX	?= /path/to/your/$(COMPILER)'s/include/c++
#MCSTL_ORIGINALS	?= /where/you/put/the/original/symlink
endif

BOOST_INCLUDE	?= /usr/include/boost-1_33

COMPILER	?= g++
LINKER		?= $(COMPILER)
OPT		?= -O3 # compiler optimization level
WARNINGS	?= -Wall
DEBUG		?= # put here -g option to include the debug information into the binaries

LIBNAME		?= stxxl

#### TROUBLESHOOTING
#
# For automatical checking of order of the output elements in
# the sorters: stxxl::stream::sort, stxxl::stream::merge_runs,
# stxxl::sort, and stxxl::ksort use
#
#STXXL_SPECIFIC	+= -DSTXXL_CHECK_ORDER_IN_SORTS
#
# If your program aborts with message "read/write: wrong parameter"
# or "Invalid argument"
# this could be that your kernel does not support direct I/O
# then try to set it off recompiling the libs and your code with option
#
#STXXL_SPECIFIC	+= -DSTXXL_DIRECT_IO_OFF
#
# But for the best performance it is strongly recommended
# to reconfigure the kernel for the support of the direct I/O.
#
# FIXME: documentation needed
#
#STXXL_SPECIFIC += -DSTXXL_DEBUGMON

#### You usually shouldn't need to change the sections below #####

#### STXXL OPTIONS ###############################################

STXXL_SPECIFIC	+= \
	$(CPPFLAGS_ARCH) \
	-DSORT_OPTIMAL_PREFETCHING \
	-DUSE_MALLOC_LOCK \
	-DCOUNT_WAIT_TIME \
	-I$(strip $(STXXL_ROOT))/include \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
	$(POSIX_MEMALIGN) $(XOPEN_SOURCE)

STXXL_LDLIBS	+= -L$(strip $(STXXL_ROOT))/lib -l$(LIBNAME) -lpthread

STXXL_LIBDEPS	+= $(strip $(STXXL_ROOT))/lib/lib$(LIBNAME).$(LIBEXT)

UNAME_M		:= $(shell uname -m)
CPPFLAGS_ARCH	+= $(CPPFLAGS_$(UNAME_M))
CPPFLAGS_i686	?= -march=i686

##################################################################

#### ICPC OPTIONS ################################################

ifeq ($(strip $(USE_ICPC)),yes)

endif

##################################################################

#### MCSTL OPTIONS ###############################################

ifeq ($(strip $(USE_MCSTL)),yes)

MCSTL_ROOT		?= $(strip $(MCSTL_BASE))$(if $(strip $(MCSTL_BRANCH)),/$(strip $(MCSTL_BRANCH)))

ifeq (,$(strip $(wildcard $(MCSTL_ROOT)/c++/mcstl.h)))
$(error ERROR: could not find a MCSTL installation in MCSTL_ROOT=$(MCSTL_ROOT))
endif

ifeq ($(strip $(USE_ICPC)),yes)
MCSTL_CPPFLAGS		+= $(ICPC_MCSTL_CPPFLAGS)
endif

MCSTL_CPPFLAGS		+= $(OPENMPFLAG) -D__MCSTL__ $(MCSTL_INCLUDES_PREPEND) -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

ifeq (,$(strip $(wildcard $(MCSTL_ROOT)/c++/bits/stl_algo.h)))
# not from libstdc++ branch, need to find the correct original symlink

ifneq (,$(strip $(wildcard $(MCSTL_ROOT)/originals)))
MCSTL_ORIG_BASE		?= $(MCSTL_ROOT)
endif
MCSTL_ORIG_BASE		?= $(MCSTL_BASE)

# find a KEY=VALUE element in WORDS and return VALUE
# usage: $(call get_value,KEY,WORDS)
get_value		 = $(subst $(1)=,,$(filter $(1)=%,$(2)))
empty			 =#
space			 = $(empty) $(empty)
gcc_version_result	:= $(shell $(COMPILER) -v 2>&1)
gcc_version		 = $(call get_value,THE_GCC_VERSION,$(subst gcc$(space)version$(space),THE_GCC_VERSION=,$(gcc_version_result)))
gcc_prefix		 = $(call get_value,--prefix,$(gcc_version_result))
gcc_gxx_incdir		 = $(call get_value,--with-gxx-include-dir,$(gcc_version_result))
MCSTL_ORIGINAL_INC_CXX	?= $(firstword $(wildcard $(gcc_gxx_incdir) $(gcc_prefix)/include/c++/$(gcc_version)) $(cxx_incdir_from_compile))
ifeq (,$(strip $(MCSTL_ORIGINAL_INC_CXX)))
# do a test compilation, generate dependencies and parse the header paths
compile_test_vector_deps:= $(shell echo -e '\043include <vector>' > cxx-header-path-test.cpp; $(COMPILER) -M cxx-header-path-test.cpp 2>/dev/null; $(RM) cxx-header-path-test.cpp)
cxx_incdir_from_compile	 = $(patsubst %/vector,%,$(firstword $(filter %/vector, $(compile_test_vector_deps))))
export cxx_incdir_from_compile
endif
MCSTL_ORIGINALS		?= $(strip $(MCSTL_ORIG_BASE))/originals/$(subst /,_,$(MCSTL_ORIGINAL_INC_CXX))

ifeq (,$(strip $(MCSTL_ORIGINAL_INC_CXX)))
$(error ERROR: could not determine MCSTL_ORIGINAL_INC_CXX, please set this variable manually, it's your compilers ($(COMPILER)) include/c++ path)
endif
ifeq (,$(strip $(wildcard $(MCSTL_ORIGINALS)/original)))
$(error ERROR: your mcstl in $(MCSTL_ORIG_BASE) is not configured properly: $(MCSTL_ORIGINALS)/original does not exist)
endif

MCSTL_CPPFLAGS		+= -I$(MCSTL_ORIGINALS)

else # from libstdc++ branch

MCSTL_INCLUDES_PREPEND	+= $(if $(findstring 4.3,$(COMPILER)),-I$(MCSTL_ROOT)/c++/mod_stl/gcc-4.3)

endif # (not) from libstdc++ branch

endif

##################################################################

#### BOOST OPTIONS ###############################################

BOOST_COMPILER_OPTIONS	 = \
	-DSTXXL_BOOST_TIMESTAMP \
	-DSTXXL_BOOST_CONFIG \
	-DSTXXL_BOOST_FILESYSTEM \
	-DSTXXL_BOOST_THREADS \
	-DSTXXL_BOOST_RANDOM \
	-I$(strip $(BOOST_INCLUDE)) \
	-pthread

BOOST_LINKER_OPTIONS	 = \
	-lboost_thread-gcc-mt \
	-lboost_date_time-gcc-mt \
	-lboost_iostreams-gcc-mt \
	-lboost_filesystem-gcc-mt

##################################################################

#### CPPUNIT OPTIONS ############################################

CPPUNIT_COMPILER_OPTIONS	+=

CPPUNIT_LINKER_OPTIONS		+= -lcppunit -ldl

##################################################################

#### DEPENDENCIES ################################################

HEADER_FILES_BITS	+= namespace.h version.h

HEADER_FILES_COMMON	+= aligned_alloc.h mutex.h rand.h semaphore.h state.h
HEADER_FILES_COMMON	+= timer.h utils.h gprof.h rwlock.h simple_vector.h
HEADER_FILES_COMMON	+= switch.h tmeta.h log.h exceptions.h debug.h tuple.h
HEADER_FILES_COMMON	+= types.h utils_ledasm.h settings.h

HEADER_FILES_IO		+= completion_handler.h io.h iobase.h iostats.h
HEADER_FILES_IO		+= mmap_file.h simdisk_file.h syscall_file.h
HEADER_FILES_IO		+= ufs_file.h wincall_file.h wfs_file.h boostfd_file.h

HEADER_FILES_MNG	+= adaptor.h async_schedule.h block_prefetcher.h
HEADER_FILES_MNG	+= buf_istream.h buf_ostream.h buf_writer.h mng.h
HEADER_FILES_MNG	+= write_pool.h prefetch_pool.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h queue.h
HEADER_FILES_CONTAINERS	+= map.h deque.h

HEADER_FILES_CONTAINERS_BTREE	+= btree.h iterator_map.h leaf.h node_cache.h
HEADER_FILES_CONTAINERS_BTREE	+= root_node.h node.h btree_pager.h iterator.h

HEADER_FILES_ALGO	+= adaptor.h inmemsort.h intksort.h run_cursor.h sort.h
HEADER_FILES_ALGO	+= async_schedule.h interleaved_alloc.h ksort.h
HEADER_FILES_ALGO	+= losertree.h scan.h stable_ksort.h random_shuffle.h

HEADER_FILES_STREAM	+= stream.h sort_stream.h

HEADER_FILES_UTILS	+= malloc.h

###################################################################

#### MISC #########################################################

DEPEXT	 = $(LIBNAME).d # extension of dependency files
OBJEXT	 = $(LIBNAME).o	# extension of object files
LIBEXT	 = a		# static library file extension
EXEEXT	 = $(LIBNAME).bin # executable file extension
RM	 = rm -f	# remove file command
LIBGEN	 = ar cr	# library generation
OUT	 = -o		# output file option for the compiler and linker

d	?= $(strip $(DEPEXT))
o	?= $(strip $(OBJEXT))
bin	?= $(strip $(EXEEXT))

###################################################################

#### COMPILE/LINK RULES ###########################################

%.$o: %.cpp ../make.settings
	@$(RM) $*.$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $*.$dT -c $(OUTPUT_OPTION) $< && mv $*.$dT $*.$d

LINK_STXXL	 = $(LINKER) $1 $(STXXL_LINKER_OPTIONS) -o $@

%.$(bin): %.$o $(STXXL_LIBDEPS)
	$(call LINK_STXXL, $<)

###################################################################

STXXL_COMPILER_OPTIONS	+= $(STXXL_SPECIFIC)
STXXL_COMPILER_OPTIONS	+= $(OPT) $(DEBUG) $(WARNINGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS)

ifeq ($(strip $(USE_MCSTL)),yes)
STXXL_COMPILER_OPTIONS	+= $(MCSTL_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(MCSTL_LDFLAGS)
endif

ifeq ($(strip $(USE_BOOST)),yes)
STXXL_COMPILER_OPTIONS	+= $(BOOST_COMPILER_OPTIONS)
STXXL_LINKER_OPTIONS	+= $(BOOST_LINKER_OPTIONS)
endif

STXXL_COMPILER_OPTIONS	+= $(CPPFLAGS)

# vim: syn=make