INSTALLATION
============

General remarks:
----------------
Please check the Makefile and (un)define the corresponding defines: 

The following DEFINES are recommended and required:
 -D=WITH_CHOLMOD        used for re-referencing of data, REQUIREMENT: cholmod from libsuitesparse
 -D=WITH_ZLIB	        used to handle gzip-ped files,  REQUIREMENT: zlib (http://zlib.net/)
 -D=WITH_GSL	        provides interface to GSL, REQUIREMENT: GNU Scientific Library (GSL), 
 -D=WITH_FEF	        includes support for FEF-format from CNSystems (fails with MinGW) 
 -D=WITH_FAMOS	        includes (partial) support for FAMOS format 
 -D=__4HAERTEL__	support for special flavor of FAMOS format (experimental) 

 Other flags are used for experimental development 
 -D=WITH_DICOM, -D=WITH_GDCM 	experimental DICOM support 

If some libraries are not available on your system, remove the corresponding DEFINES in Makefile. 


Prerequisites: 
--------------
P1) for building libbiosig, save2gdf, mma (mathematica) and mex (matlab)  
	sudo apt-get install subversion libz-dev libsuitesparse-dev libcurl-dev gawk g++ gcc 
	svn co https://biosig.svn.sourceforge.net/svnroot/biosig/trunk/biosig4c++ 

        For ttl2trig, also the package 
           libasound-dev 
        is required. 

P2) for building SigViewer  
	sudo apt-get install qt4-dev-tools  libqt4-dev  libqt4-qt3support 
	svn co https://sigviewer.svn.sourceforge.net/svnroot/sigviewer/trunk sigviewer


P3) Cross-compilation on Linux for Win32-target:   
	aptitude install -R autoconf automake bash bison bzip2 \
                    cmake flex g++ intltool make sed \
                    libtool openssl libssl-dev \
                    libxml-parser-perl patch perl \
                    pkg-config scons unzip wget \
                    xz-utils yasm mercurial 
	git clone https://github.com/mxe/mxe.git
	cd mxe
	make zlib suitesparse libgomp qt 
	patch -p0 <biosig4c++/patches/patch_mingw_io_h.diff


P4) Cross-compilation on GNU/Linux for Win64-target:   
	hg clone https://bitbucket.org/tonyt/mce-w64
	cd mce-win64
	make zlib suitesparse libgomp qt 
	patch ../mce-w64/usr/x86_64-w64-mingw32/include/io.h biosig4c++/patches/patch_mce-w64_io_h.diff


P5) Host=Win32 platform (this solution is currently not maintained): 
	MinGW32 (with g++)  
	You need to use Makefile.win32 like this 
	make -f Makefile.win32  	
		

Platform specific information
-----------------------------
# Linux
You need GNU gcc, g++ (ver>4.0), make, zlib (if you do not have zlib, do not define WITH_ZLIB), 
libsuitesparse (if you do not have libsuitesparse, do not define WITH_CHOLMOD).

Running make compiles the converter.
  make 		 	# makes the file format converter
  make save2gdf 	# makes the file format converter
  make win32		# makes the file format converter for Win32
  make win64		# makes the file format converter for Win64
  make physicalunits 	# makes the en/decoder for physical units
  make libbiosig.a  	# makes a static library 
  make mex4o 		# makes mexSLOAD for Octave (requires Octave-headers2.9 or higher)
  make mex4m 		# makes mexSLOAD for Matlab (path_to_mex need to be defined in Makefile)
  make biosig4python 	# compiles the BioSig interface for Python (requires SWIG and Python)
  make all  		# all of the above
  make sigviewer 	# recompiles SigViewer (requires qmake and Qt, the sources of sigviewer must be in ../sigviewer)
  make testscp 
  make testhl7	
  make test		# tests HL7<->SCP, SCP<->GDF, GDF<->HL7 converters
  make test6		# tests bidirectional conversion between 6 differerent data formats	

# Mac OS X (tested under 10.7 Lion)
 1. First, get Xcode from the App Store. You need to create an Apple Developer Account (which is free) to install the command line tools (see next step).
 2. In Xcode, go to Preferences - Downloads - Components - Install Command Line Tools.
 3. Install MacPorts from http://www.macports.org/.
 4. In a terminal, type "sudo port install gawk".
 5. In a terminal, type "sudo port install SuiteSparse".

Optional (if you want a good IDE, this is recommended):
 6. Install Eclipse from http://www.eclipse.org/.
 7. Install CDT (in Eclipse, go to Help - Install New Software...).
    Activate the CDT repository by clicking on "Available Software Sites" and activate "CDT Juno".
    After clicking OK, select "-- All Available Sites --" and install "CDT Main Features".
 8. In Eclipse, go to Preferences - C/C++ - Build - Environment - Add...
    Enter PATH in the Name text box and /opt/local/bin:/opt/local/sbin in the Value text box.
 9. To load the project, go to File - New - Makefile Project with Existing Code.
    Fill in the name of the project (for example, biosig4c++) and enter the root folder containing the source code of biosig4c++.
10. In the Project Explorer, you can now right-click on the project and choose Clean or Build to start compiling the project.


# MinGW Crosscompiler on Debian/Ubuntu for Windows  
- aptitude install mingw32 mingw32-binutils mingw32-runtime

# mxe/mce-w64 on GNU/Linux for Windows  
Prerequisites P3) and/or P4) (see above)
- modify Makefile and set variable CROSS for Win32 (and CROSS64 for Win64) to the proper value e.g.  
   CROSS   = $(HOME)/src/mxe/usr/bin/i686-pc-mingw32
   CROSS64 = $(HOME)/src/mce-w64/usr/bin/x86_64-w64-mingw32

- run the command  
   make win32/save2gdf.exe      # converter between data formats
   make win32/libbiosig.dll     # dynamic library 
   make win32/libbiosig.a       # static library    
   make win32mma		# Win32/Mathematica interface
   make mexw32			# Win32/Matlab mex interface 
   make win32                   # all of the above
   make win64/save2gdf.exe      # converter between data formats 64bit Windows
   make mexw64			# Win64/Matlab mex interface 

# Windows + MinGW
Prerequisites P5) (see above)
Support for FEF, ZLIB, CHOLMOD is turned off, because of lack of support in MinGW. 
In general, Makefile.win32 should be used. 
- Run the make command 
   make -f Makefile.win32 libbiosig.a
   make -f Makefile.win32 save2gdf.exe
   make -f Makefile.win32 sigviewer
   make -C mma -f Makefile.win32 sload.exe	# mathematica interface

You can also start compilation of sigviewer. 
   First, you need to have the sigviewer sources in ..\sigviewer and 
   Then, you need to run once qmake in ..\sigviewer\src\ 
   make -f Makefile.win32 sigviewer 

# Matlab/Win32 using MinGW on Windows
do the steps in "Windows+MinGW"
install and configure gnumex (from http://gnumex.sf.net)  
  make libbiosig.a
  start matlab
  >> gnumex 	% configure mingw for mex
  >> mex mexSLOAD.cpp libbiosig \mingw\lib\libws2_32.a
	
# Mathematica/Win32 using MinGW on Windows
Adapt user-specified variables (directory names) in Makefile.win32 and mma/Makefile.win32	
  cd biosig4c++/mma
  make -f Makefile.win32 sload.exe
	
# Windows + Cygwin
Currently, only the file converter save2gdf is supported.
- install Cygwin
- within Cygwin install gcc4 g++4, zlib, suitesparse/cholmod and make 
- run the make command 
   make save2gdf 

# MSVC - Microsoft Visual C++
  MSVC is currently not supported. The main incompatibility is 
  the use of the typeof() operator. Since typeof() is very convinient, 
  I'm not planning to change this. However, you can easy replace 
  any typeof()-operator by the appropriate type, and the code 
  should compile on MSVC as well. 

# Other platforms (Windows+MSVC, MacOSX, Solaris, etc. )
Not tested (yet). Let me know about successful compilations, 
or tell me what changes are needed.   

	
Installation: 
-------------
run as root 
  make 
  make install 		# installs save2gdf, save2scp, save2aecg, 
  make install_octave	# installs mexSLOAD.mex in /usr/local/share/octave/site-m/
  make install_sigviewer	# installs sigviewer
 

Execution:
----------
# if test.gdf exists, some header information is displayed
save2gdf test.gdf     		

# help and usage information 
save2gdf -h

# converts a data file into a GDF format (destination
save2gdf PFE103.scp t5.gdf     		

# converts a data file into a SCP format (destination
save2scp t5.gdf t5.scp      		
save2gdf -f=SCP t5.gdf t5.scp      		

# converts a data file into a HL7aECG format (destination
save2aecg t5.gdf t5.hl7      		
save2gdf -f=HL7aECG t5.gdf t5.hl7

# load matlab into octave or matlab
start octave or matlab
addpath path_to_mexSLOAD.mex
[data,HDR] = mexSLOAD(filename); % loads data and header information 


Development & Testing:
----------------------
There are several testing functions included. 
The following commands test the converter and should finish without errors.  
	make test 
	make testhl7
	make testscp
	make test6

The Octave/Matlab script 
	test0/test01.m 
tests whether the various data formats give the same results 
or whether some conversion error has been included.  


    $Id$
    Copyright (C) 2005,2006,2007,2008,2009,2011,2012, Alois Schloegl <alois.schloegl@gmail.com>
    This function is part of the "BioSig for C/C++" repository 
    (BioSig4C++) at http://biosig.sf.net/ 

