changeset 2626:54f9ce4d6dea

Merge remote branch 'origin/master'
author Andrew L Janke <a.janke@gmail.com>
date Mon, 12 Mar 2012 12:46:06 +1000
parents 8f04e834d667 (current diff) 55fac3cfdf48 (diff)
children 4c97972059c4
files cmake-modules/FindBISON.cmake cmake-modules/FindFLEX.cmake cmake-modules/FindMINC.cmake
diffstat 47 files changed, 832 insertions(+), 914 deletions(-) [+]
line wrap: on
line diff
--- a/.gitignore
+++ b/.gitignore
@@ -14,37 +14,7 @@
 config.h
 config.log
 config.status
-dcm2mnc
-ecattominc
-epm-header
-invert_raw_image
 libtool
-minc_modify_header
-mincaverage
-minccalc
-minccmp
-mincconcat
-mincconvert
-minccopy
-mincdump
-mincexample1
-mincexample2
-mincexpand
-mincextract
-mincgen
-mincinfo
-minclookup
-mincmakescalar
-mincmakevector
-mincmath
-mincresample
-mincreshape
-mincstats
-minctoecat
-minctoraw
-mincwindow
-mnc2nii
-nii2mnc
 progs/minccomplete/minccomplete
 progs/minccomplete/minccomplete.man1
 progs/mincgen/ncgentab.c
@@ -53,16 +23,7 @@
 progs/minchistory/minchistory
 progs/minchistory/minchistory.man1
 progs/xfm/xfmflip
-rawtominc
 stamp-h1
-transformtags
-upet2mnc
-vff2mnc
 volume_io/Testing/example_modify
 volume_io/Testing/example_tags
 volume_io/Testing/example_volume_io
-voxeltoworld
-worldtovoxel
-xfm2def
-xfmconcat
-xfminvert
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,18 +1,19 @@
 # CMakeFiles.txt for the MINC2 library
 #
 # Andrew Janke - a.janke@gmail.com
+# Vladimir S. FONOV - vladimir.fonov@gmail.com
 
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+INCLUDE(ExternalProject)
 
-PROJECT(libminc2)
+PROJECT(minc2)
 
 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")
-
+ENABLE_TESTING()
+INCLUDE(CTest)
 
-#ADD_SUBDIRECTORY( testdir )
 #ADD_SUBDIRECTORY( doc )
 
-
 # Packaging defines
 SET(CPACK_GENERATOR TGZ)
 SET(CPACK_PACKAGE_VERSION_MAJOR 2)
@@ -21,10 +22,10 @@
 INCLUDE(CPack)
 
 
-SET(PACKAGE "minc")
+SET(PACKAGE "minc2")
 SET(PACKAGE_BUGREPORT "a.janke@gmail.com")
 
-SET(PACKAGE_NAME "minc")
+SET(PACKAGE_NAME "minc2")
 SET(PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
 SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
 
@@ -32,12 +33,64 @@
 OPTION(BUILD_TOOLS      "Build minc tools (mincreshape,mincresample, etc)" ON)
 OPTION(BUILD_CONVERTERS "Build minc conversion programs (mnc2nii, nii2mnc , dcm2mnc...)" ON)
 OPTION(BUILD_EZMINC     "Build C++ interface library EZminc" ON)
+OPTION(USE_SYSTEM_NETCDF "Use System NETCDF > 3.6.3" ON)
+
 IF(BUILD_EZMINC)
 OPTION(BUILD_MINC4ITK   "Build ITK interface" ON)
 ENDIF(BUILD_EZMINC)
 
+IF(BUILD_MINC2)
+ OPTION(USE_SYSTEM_HDF5 "Use System HDF5 > 1.8 " ON)
+ENDIF(BUILD_MINC2)
+
+# external packages
+IF(USE_SYSTEM_NETCDF)
+  FIND_PACKAGE(NETCDF REQUIRED)
+  
+ELSE(USE_SYSTEM_NETCDF)
+  ExternalProject_Add(NETCDF 
+    SOURCE_DIR NETCDF
+    URL "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.0.1.tar.gz"
+    URL_MD5 "a251453c5477599f050fa4e593295186"
+    BUILD_IN_SOURCE 1
+    INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
+    BUILD_COMMAND   make 
+    INSTALL_COMMAND make install 
+    CONFIGURE_COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX} --with-pic --disable-netcdf4 --disable-hdf4 --disable-dap --disable-shared --disable-cxx --disable-f77 --disable-f90 --disable-examples --enable-v2 --disable-docs
+  )
+
+  SET(NETCDF_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libnetcdf.a )
+  SET(NETCDF_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include )
+ENDIF(USE_SYSTEM_NETCDF)
+
+
+IF(BUILD_MINC2)
+  IF(USE_SYSTEM_HDF5 )
+#     SET(HDF5_FIND_COMPONENTS "C")
+#     SET(HDF5_USE_STATIC_LIBRARIES ON)
+    FIND_PACKAGE(HDF5 REQUIRED)
+  ELSE(USE_SYSTEM_HDF5)
+
+    ExternalProject_Add(HDF5
+      SOURCE_DIR HDF5
+      URL "http://www.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8.7/src/hdf5-1.8.7.tar.gz"
+      URL_MD5 "37711d4bcb72997e93d495f97c76c33a"
+      BUILD_IN_SOURCE 1
+      INSTALL_DIR     "${CMAKE_INSTALL_PREFIX}"
+      BUILD_COMMAND   make 
+      INSTALL_COMMAND make install 
+      CONFIGURE_COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX}  --with-pic --disable-shared --disable-cxx --disable-f77 --disable-f90 --disable-examples --disable-hl --disable-docs
+    )
+
+    SET(HDF5_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include )
+    SET(HDF5_LIBRARY  ${CMAKE_INSTALL_PREFIX}/lib/libhdf5.a )
+
+  ENDIF(USE_SYSTEM_HDF5)
+ENDIF(BUILD_MINC2)
+
 
 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
+ADD_DEFINITIONS(-fPIC)
 
 # aliases
 SET(VERSION "${PACKAGE_VERSION}")
@@ -45,36 +98,98 @@
 # check for prereqs
 INCLUDE(CheckFunctionExists)
 
-CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
+CHECK_FUNCTION_EXISTS(mkstemp  HAVE_MKSTEMP)
+CHECK_FUNCTION_EXISTS(tmpnam   HAVE_TMPNAM)
+CHECK_FUNCTION_EXISTS(tempnam  HAVE_TEMPNAM)
 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
+CHECK_FUNCTION_EXISTS(popen    HAVE_POPEN)
+CHECK_FUNCTION_EXISTS(fork     HAVE_WORKING_FORK)
+CHECK_FUNCTION_EXISTS(vfork    HAVE_WORKING_VFORK)
+CHECK_FUNCTION_EXISTS(fdopen   HAVE_FDOPEN)
+CHECK_FUNCTION_EXISTS(strdup   HAVE_STRDUP)
+CHECK_FUNCTION_EXISTS(getpwnam HAVE_GETPWNAM) 
+CHECK_FUNCTION_EXISTS(select   HAVE_SELECT)
+CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR) 
+CHECK_FUNCTION_EXISTS(sysconf  HAVE_SYSCONF)
+CHECK_FUNCTION_EXISTS(system   HAVE_SYSTEM)
 
 INCLUDE(CheckIncludeFiles)
-CHECK_INCLUDE_FILES(float.h HAVE_FLOAT_H)
+CHECK_INCLUDE_FILES(float.h     HAVE_FLOAT_H)
+CHECK_INCLUDE_FILES(sys/dir.h   HAVE_SYS_DIR_H)
+CHECK_INCLUDE_FILES(sys/ndir.h  HAVE_SYS_NDIR_H)
+CHECK_INCLUDE_FILES(sys/stat.h  HAVE_SYS_STAT_H)
+CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
+CHECK_INCLUDE_FILES(sys/wait.h  HAVE_SYS_WAIT_H)
+CHECK_INCLUDE_FILES(values.h    HAVE_VALUES_H)
+CHECK_INCLUDE_FILES(unistd.h    HAVE_UNISTD_H)
+CHECK_INCLUDE_FILES(dirent.h    HAVE_DIRENT_H)
+CHECK_INCLUDE_FILES(memory.h    HAVE_MEMORY_H)
+CHECK_INCLUDE_FILES(stdlib.h    HAVE_STDLIB_H)
+CHECK_INCLUDE_FILES(fcntl.h     HAVE_FCNTL_H)
+CHECK_INCLUDE_FILES(dlfcn.h     HAVE_DLFCN_H)
+CHECK_INCLUDE_FILES(vfork.h     HAVE_VFORK_H)
+CHECK_INCLUDE_FILES(inttypes.h  HAVE_INTTYPES_H)
+CHECK_INCLUDE_FILES(string.h    HAVE_STRING_H)
+CHECK_INCLUDE_FILES(strings.h   HAVE_STRINGS_H)
+CHECK_INCLUDE_FILES(pwd.h   HAVE_PWD_H)
+
+
+
+IF(ZLIB_FOUND)
+  SET(HAVE_ZLIB 1)
+ELSE(ZLIB_FOUND)
+  FIND_PACKAGE(ZLIB)
+  IF(ZLIB_FOUND)
+    SET(HAVE_ZLIB 1)
+  ENDIF(ZLIB_FOUND)
+ENDIF(ZLIB_FOUND)
+
+IF(BUILD_EZMINC)
+  set(MINC2_INCLUDE_DIRS_CONFIG    
+    ${CMAKE_SOURCE_DIR}/ezminc
+  )
+  INCLUDE_DIRECTORIES(
+    ${CMAKE_SOURCE_DIR}/ezminc
+   )
+ENDIF(BUILD_EZMINC)
+
+IF(BUILD_MINC4ITK AND BUILD_EZMINC)
+  set(MINC2_INCLUDE_DIRS_CONFIG    
+    ${CMAKE_SOURCE_DIR}/minc4itk
+  )
+
+  INCLUDE_DIRECTORIES(
+    ${CMAKE_SOURCE_DIR}/minc4itk
+   )
+ENDIF(BUILD_MINC4ITK AND BUILD_EZMINC)
+
 
 # netcdf and HDF5
-FIND_PACKAGE(NETCDF REQUIRED)
-INCLUDE_DIRECTORIES( ${NETCDF_INCLUDE_DIR} )
 
 IF(BUILD_MINC2)
-  FIND_PACKAGE(HDF5 REQUIRED)
   FIND_PACKAGE(ZLIB REQUIRED)
   SET(MINC2 "1")
-  INCLUDE_DIRECTORIES( ${HDF5_INCLUDE_DIR} )
+ELSE(BUILD_MINC2)
+  SET(MINC2 "0")
 ENDIF(BUILD_MINC2)
 
 # config files for build
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_SOURCE_DIR}/config.h)
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h @ONLY)
 
 # others
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/epm-header.in ${CMAKE_SOURCE_DIR}/epm-header)
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/epm-header.in ${CMAKE_BINARY_DIR}/epm-header)
+
 
 # set the master INCLUDE directories
 INCLUDE_DIRECTORIES(
    ${CMAKE_CURRENT_SOURCE_DIR}
+   ${CMAKE_BINARY_DIR}
    ${CMAKE_SOURCE_DIR}/libsrc
    ${CMAKE_SOURCE_DIR}/volume_io/Include
    )
 
+INCLUDE_DIRECTORIES( ${NETCDF_INCLUDE_DIR} )
+
 IF(BUILD_MINC2)
   INCLUDE_DIRECTORIES(
    ${CMAKE_SOURCE_DIR}/libsrc2
@@ -97,6 +212,7 @@
    libsrc/hdf_convenience.c
    libsrc/minc_compat.c
    libsrc/minc_simple.c
+   libsrc/read_file_names.c
    )
 
 SET(minc2_LIB_SRCS
@@ -115,11 +231,17 @@
    libsrc2/volume.c
    )
 
-SET(minc_LIB minc)
+SET(MINC2_LIBRARY minc)
+SET(MINC2_LIBRARIES ${MINC2_LIBRARY} ${NETCDF_LIBRARY})
 
 IF(BUILD_MINC2)
+  INCLUDE_DIRECTORIES( ${HDF5_INCLUDE_DIR} )
+
+
   SET(minc_LIB_SRCS ${minc1_LIB_SRCS} ${minc2_LIB_SRCS})
-  SET(minc_LIB minc2)
+  SET(MINC2_LIBRARY minc2)
+  SET(MINC2_LIBRARIES ${MINC2_LIBRARY} ${HDF5_LIBRARY} ${NETCDF_LIBRARY} ${ZLIB_LIBRARIES}  m )
+
   ADD_LIBRARY(minc2 STATIC ${minc_LIB_SRCS} )
 
   TARGET_LINK_LIBRARIES(minc2 ${NETCDF_LIBRARY} ${HDF5_LIBRARY} ${ZLIB_LIBRARIES} m )
@@ -139,10 +261,13 @@
 
   SET_TARGET_PROPERTIES(minc2 PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
 
+  IF(NOT USE_SYSTEM_HDF5)
+      ADD_DEPENDENCIES(${MINC2_LIBRARY} HDF5)
+  ENDIF(NOT USE_SYSTEM_HDF5)
+
 ELSE(BUILD_MINC2)
 
     SET(minc_LIB_SRCS ${minc1_LIB_SRCS} )
-    SET(minc_LIB minc)
     ADD_LIBRARY(minc STATIC ${minc1_LIB_SRCS} )
     TARGET_LINK_LIBRARIES(minc ${NETCDF_LIBRARY} )
     INSTALL(TARGETS minc ARCHIVE DESTINATION lib)
@@ -158,8 +283,12 @@
       )
 
     SET_TARGET_PROPERTIES(minc PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
+ENDIF(BUILD_MINC2)
 
-ENDIF(BUILD_MINC2)
+IF(NOT USE_SYSTEM_NETCDF)
+    ADD_DEPENDENCIES(${MINC2_LIBRARY} NETCDF)
+ENDIF(NOT USE_SYSTEM_NETCDF)
+
 
 # build the main minc2 library
 
@@ -206,13 +335,15 @@
   ADD_LIBRARY(volume_io2 STATIC ${volume_io_LIB_SRCS})
   INSTALL(TARGETS volume_io2 ARCHIVE DESTINATION lib)
   SET_TARGET_PROPERTIES(volume_io2 PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
-  SET( volume_io_LIB volume_io2)
+  SET( VOLUME_IO_LIBRARY volume_io2)
+  ADD_DEPENDENCIES(volume_io2 ${MINC2_LIBRARY})
 
 ELSE(BUILD_MINC2)
   ADD_LIBRARY(volume_io STATIC ${volume_io_LIB_SRCS})
   INSTALL(TARGETS volume_io ARCHIVE DESTINATION lib)
   SET_TARGET_PROPERTIES(volume_io PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
-  SET( volume_io_LIB volume_io)
+  SET( VOLUME_IO_LIBRARY volume_io)
+  ADD_DEPENDENCIES(volume_io ${MINC2_LIBRARY})
 ENDIF(BUILD_MINC2)
 
 INSTALL(FILES volume_io/Include/volume_io/alloc.h
@@ -235,18 +366,70 @@
 
 IF(BUILD_TOOLS)
 # now build the progs subdir
-ADD_SUBDIRECTORY( progs )
+  ADD_SUBDIRECTORY( progs )
 ENDIF(BUILD_TOOLS)
 
 IF(BUILD_CONVERTERS)
 # and then the conversion subdir
-ADD_SUBDIRECTORY( conversion )
+  ADD_SUBDIRECTORY( conversion )
 ENDIF(BUILD_CONVERTERS)
 
 IF(BUILD_EZMINC)
-ADD_SUBDIRECTORY( ezminc )
+  ADD_SUBDIRECTORY( ezminc )
 ENDIF(BUILD_EZMINC)
 
 IF(BUILD_MINC4ITK AND BUILD_EZMINC)
-ADD_SUBDIRECTORY( minc4itk )
-ENDIF(BUILD_MINC4ITK AND BUILD_EZMINC)
\ No newline at end of file
+  ADD_SUBDIRECTORY( minc4itk )
+ENDIF(BUILD_MINC4ITK AND BUILD_EZMINC)
+
+# config for the build directory
+set(MINC2_USE_FILE_CONFIG   ${CMAKE_CURRENT_BINARY_DIR}/UseMINC2.cmake)
+
+set(MINC2_INCLUDE_DIRS_CONFIG    
+   ${CMAKE_CURRENT_SOURCE_DIR}
+   ${CMAKE_SOURCE_DIR}/libsrc
+   ${CMAKE_SOURCE_DIR}/volume_io/Include
+)
+
+IF(BUILD_MINC2)
+  set(MINC2_INCLUDE_DIRS_CONFIG
+    ${MINC2_INCLUDE_DIRS_CONFIG}
+    ${CMAKE_SOURCE_DIR}/libsrc2
+  )
+ENDIF(BUILD_MINC2)
+
+set(MINC2_LIBRARY_DIRS_CONFIG ${CMAKE_CURRENT_BINARY_DIR})
+
+configure_file(MINC2Config.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/MINC2Config.cmake @ONLY )
+
+configure_file(UseMINC2.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/UseMINC2.cmake @ONLY)
+
+# config for install dir
+set(MINC2_USE_FILE_CONFIG "${CMAKE_INSTALL_PREFIX}/lib/UseMINC2.cmake")
+
+set(MINC2_INCLUDE_DIRS_CONFIG    
+   ${CMAKE_INSTALL_PREFIX}/include
+)
+
+set(MINC2_LIBRARY_DIRS_CONFIG ${CMAKE_INSTALL_PREFIX}/lib)
+
+configure_file(MINC2Config.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MINC2Config.cmake @ONLY )
+
+configure_file(UseMINC2.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/UseMINC2.cmake @ONLY)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/UseMINC2.cmake ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MINC2Config.cmake
+  DESTINATION lib
+  COMPONENT Development)
+
+# testing
+
+IF(BUILD_TESTING)
+  ADD_SUBDIRECTORY( testdir )
+ENDIF(BUILD_TESTING)
+
+
+
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+
+-- Release of minc 2.1.10 --
+
+2012-02-22  Andrew L Janke <a.janke@gmail.com>
+   * added a patch from Steve Robbins that factors references to PATH_MAX
+      out to fix a build problem on hurd
+
 2011-12-20  Andrew L Janke <a.janke@gmail.com>
    * libsrc/netcdf_convenience.c: changed execute_decompress_command()
       to always decompress the whole file as the approach used for
@@ -44,6 +51,8 @@
      even though the acquisition is descending (version >= VA25 and
      >= VB11).
 
+-- Release of minc 2.1.00 --
+
 2010-07-27  Andrew L Janke  <a.janke@gmail.com>
    * conversion/micropet/upet2mnc.c: error bug squashed (John Cupitt)
 
new file mode 100644
--- /dev/null
+++ b/MINC2Config.cmake.in
@@ -0,0 +1,15 @@
+set(HAVE_MINC2    @BUILD_MINC2@)
+set(HAVE_EZMINC   @BUILD_EZMINC@)
+set(HAVE_MINC4ITK @BUILD_MINC4ITK@)
+
+
+set(NETCDF_INCLUDE_DIR "@NETCDF_INCLUDE_DIR@")
+set(HDF5_INCLUDE_DIR   "@HDF5_INCLUDE_DIR@")
+set(NETCDF_LIBRARY     "@NETCDF_LIBRARY@")
+set(HDF5_LIBRARY       "@HDF5_LIBRARY@")
+set(ZLIB_LIBRARIES     "@ZLIB_LIBRARIES@")
+
+set(MINC2_INCLUDE_DIRS "@MINC2_INCLUDE_DIRS_CONFIG@")
+set(MINC2_LIBRARY_DIRS "@MINC2_LIBRARY_DIRS_CONFIG@")
+set(MINC2_USE_FILE     "@MINC2_USE_FILE_CONFIG@")
+set(MINC2_LIBRARIES    "@MINC2_LIBRARIES@")
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,6 +67,7 @@
 # not part of the installation.
 #
 noinst_HEADERS = \
+	libsrc/read_file_names.h \
 	libsrc/minc_basic.h \
 	libsrc/minc_config.h \
 	libsrc/minc_error.h \
@@ -425,6 +426,7 @@
 libminc2_la_LDFLAGS = -version-info 2:3:1
 libminc2_la_SOURCES = \
 	libsrc/ParseArgv.c \
+	libsrc/read_file_names.c \
 	libsrc/dim_conversion.c \
 	libsrc/image_conversion.c \
 	libsrc/minc_convenience.c \
--- a/NEWS
+++ b/NEWS
@@ -1,15 +1,19 @@
-New in Release 
+New in Release 2.1.10
 ---------------------
+* added imin() and imax() operators to minccalc
+* added a minc_version global to files created with minc
+* Fixed a few HDF5 error output bugs
+* mincview is now coded in sh, not csh also shifted from xv to display
 * Fixed bug in dicom_to_minc.c for segmentation fault on undefined sequence
   (initialization of gi_ptr->cur_size)
-* Free some memory after usage
+* Fixed some memory leaks (thanks Jim Nikelski) 
 * Added b-matrix field for Siemens diffusion scans (version >= VB
-  only).
+  only). (thanks to Ilana Leppert)
 * Made changes to ordering of slices: e.g. a descending acquisition
   now has negative slice step. This was an issue with MOSAIC, in
   which the ordering of the slices in the MOSAIC image is ascending,
   even though the acquisition is descending (version >= VA25 and
-  >= VB11).
+  >= VB11). (thanks to Ilana Leppert)
 
 New in Release 2.1.00
 ---------------------
new file mode 100644
--- /dev/null
+++ b/UseMINC2.cmake.in
@@ -0,0 +1,21 @@
+include_directories(${MINC2_INCLUDE_DIRS})
+link_directories(${MINC2_LIBRARY_DIRS})
+
+
+#FIND_PACKAGE(NETCDF REQUIRED)
+INCLUDE_DIRECTORIES( ${NETCDF_INCLUDE_DIR} )
+
+if(HAVE_MINC2)
+  #FIND_PACKAGE(HDF5 REQUIRED)
+  #FIND_PACKAGE(ZLIB REQUIRED)
+
+  INCLUDE_DIRECTORIES( ${HDF5_INCLUDE_DIR} )
+  
+  SET(MINC2 "1")
+  ADD_DEFINITIONS( -DMINC2=1 )
+  
+  #SET(MINC_LIBRARIES volume_io2 minc2 netcdf hdf5 z)
+else(HAVE_MINC2)
+  #SET(MINC_LIBRARIES volume_io minc netcdf )
+endif(HAVE_MINC2)
+
deleted file mode 100644
--- a/cmake-modules/FindBISON.cmake
+++ /dev/null
@@ -1,162 +0,0 @@
-# - Find bison executable and provides macros to generate custom build rules
-# The module defined the following variables:
-#  BISON_EXECUTABLE - path to the bison program
-#  BISON_VERSION - version of bison
-#  BISON_FOUND - true if the program was found
-# If bison is found, the module defines the macros:
-#  BISON_TARGET(<Name> <YaccInput> <CodeOutput> [VERBOSE <file>]
-#              [COMPILE_FLAGS <string>])
-# which will create  a custom rule to generate  a parser. <YaccInput> is
-# the path to  a yacc file. <CodeOutput> is the name  of the source file
-# generated by bison.  A header file is also  be generated, and contains
-# the  token  list.  If  COMPILE_FLAGS  option is  specified,  the  next
-# parameter is  added in the bison  command line.  if  VERBOSE option is
-# specified, <file> is created  and contains verbose descriptions of the
-# grammar and parser. The macro defines a set of variables:
-#  BISON_${Name}_DEFINED - true is the macro ran successfully
-#  BISON_${Name}_INPUT - The input source file, an alias for <YaccInput>
-#  BISON_${Name}_OUTPUT_SOURCE - The source file generated by bison
-#  BISON_${Name}_OUTPUT_HEADER - The header file generated by bison
-#  BISON_${Name}_OUTPUTS - The sources files generated by bison
-#  BISON_${Name}_COMPILE_FLAGS - Options used in the bison command line
-#
-# Example:
-# FIND_PACKAGE(BISON)
-# BISON_TARGET(MyParser parser.y ${PROJECT_BINARY_DIR}/parser.cpp)
-# ADD_EXECUTABLE(Foo main.cpp ${BISON_MyParser_OUTPUTS})
-#
-
-# Copyright (c) 2006, Tristan Carel
-# All rights reserved.
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-#     * Redistributions of source code must retain the above copyright
-#       notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above copyright
-#       notice, this list of conditions and the following disclaimer in the
-#       documentation and/or other materials provided with the distribution.
-#     * Neither the name of the University of California, Berkeley nor the
-#       names of its contributors may be used to endorse or promote products
-#       derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# $Id: FindBISON.cmake,v 1.1 2007-10-16 23:21:42 rotor Exp $
-
-SET(BISON_FOUND FALSE)
-
-FIND_PROGRAM(BISON_EXECUTABLE bison DOC "path to the bison executable")
-MARK_AS_ADVANCED(BISON_EXECUTABLE)
-
-IF(BISON_EXECUTABLE)
-  SET(BISON_FOUND TRUE)
-
-  EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version
-    OUTPUT_VARIABLE BISON_version_output
-    ERROR_VARIABLE BISON_version_error
-    RESULT_VARIABLE BISON_version_result
-    OUTPUT_STRIP_TRAILING_WHITESPACE)
-  IF(NOT ${BISON_version_result} EQUAL 0)
-    MESSAGE(SEND_ERROR "Command \"${BISON_EXECUTABLE} --version\" failed with output:\n${BISON_version_error}")
-  ELSE(NOT ${BISON_version_result} EQUAL 0)
-    STRING(REGEX REPLACE "^bison \\(GNU Bison\\) ([^\n]+)\n.*" "\\1"
-      BISON_VERSION "${BISON_version_output}")
-  ENDIF(NOT ${BISON_version_result} EQUAL 0)
-
-  # internal macro
-  MACRO(BISON_TARGET_option_verbose Name BisonOutput filename)
-    LIST(APPEND BISON_TARGET_cmdopt "--verbose")
-    GET_FILENAME_COMPONENT(BISON_TARGET_output_path "${BisonOutput}" PATH)
-    GET_FILENAME_COMPONENT(BISON_TARGET_output_name "${BisonOutput}" NAME_WE)
-    ADD_CUSTOM_COMMAND(OUTPUT ${filename}
-      COMMAND ${CMAKE_COMMAND} -E copy
-      "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output"
-      "${filename}"
-      DEPENDS
-      "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output"
-      COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}"
-      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
-    SET(BISON_${Name}_VERBOSE_FILE ${filename})
-    LIST(APPEND BISON_TARGET_extraoutputs
-      "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output")
-  ENDMACRO(BISON_TARGET_option_verbose)
-
-  # internal macro
-  MACRO(BISON_TARGET_option_extraopts Options)
-    SET(BISON_TARGET_extraopts "${Options}")
-    SEPARATE_ARGUMENTS(BISON_TARGET_extraopts)
-    LIST(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts})
-  ENDMACRO(BISON_TARGET_option_extraopts)
-
-  MACRO(BISON_TARGET Name BisonInput BisonOutput)
-    SET(BISON_TARGET_output_header "")
-    SET(BISON_TARGET_command_opt "")
-    SET(BISON_TARGET_outputs "${BisonOutput}")
-    IF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)
-      MESSAGE(SEND_ERROR "Usage")
-    ELSE(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)
-      # Parsing parameters
-      IF(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5)
-	IF("${ARGV3}" STREQUAL "VERBOSE")
-	  BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV4}")
-	ENDIF("${ARGV3}" STREQUAL "VERBOSE")
-	IF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
-	  BISON_TARGET_option_extraopts("${ARGV4}")
-	ENDIF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
-      ENDIF(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5)
-      IF(${ARGC} EQUAL 7)
-	IF("${ARGV5}" STREQUAL "VERBOSE")
-	  BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV6}")
-	ENDIF("${ARGV5}" STREQUAL "VERBOSE")
-	IF("${ARGV5}" STREQUAL "COMPILE_FLAGS")
-	  BISON_TARGET_option_extraopts("${ARGV6}")
-	ENDIF("${ARGV5}" STREQUAL "COMPILE_FLAGS")
-      ENDIF(${ARGC} EQUAL 7)
-
-      # Header's name generated by bison (see option -d)
-      LIST(APPEND BISON_TARGET_cmdopt "-d")
-      STRING(REGEX REPLACE "^(.*)\\.c([^.]*)$" "\\1.h\\2"
-	BISON_${Name}_OUTPUT_HEADER "${ARGV2}")
-      LIST(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}")
-
-      ADD_CUSTOM_COMMAND(OUTPUT ${BISON_TARGET_outputs}
-	${BISON_TARGET_extraoutputs}
-	COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${ARGV2} ${ARGV1}
-	DEPENDS ${ARGV1}
-	COMMENT "[BISON][${Name}] Building parser with bison ${BISON_VERSION}"
-	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
-
-      # define target variables
-      SET(BISON_${Name}_DEFINED TRUE)
-      SET(BISON_${Name}_INPUT ${ARGV1})
-      SET(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs})
-      SET(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
-      SET(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
-
-    ENDIF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)
-  ENDMACRO(BISON_TARGET)
-
-ENDIF(BISON_EXECUTABLE)
-
-
-IF(NOT BISON_FOUND)
-  IF(NOT BISON_FIND_QUIETLY)
-    MESSAGE(STATUS "BISON was not found.")
-  ELSE(NOT BISON_FIND_QUIETLY)
-    IF(BISON_FIND_REQUIRED)
-      MESSAGE(FATAL_ERROR "BISON was not found.")
-    ENDIF(BISON_FIND_REQUIRED)
-  ENDIF(NOT BISON_FIND_QUIETLY)
-ENDIF(NOT BISON_FOUND)
-
-# FindBISON.cmake ends here
deleted file mode 100644
--- a/cmake-modules/FindFLEX.cmake
+++ /dev/null
@@ -1,134 +0,0 @@
-# - Find flex executable and provides a macro to generate custom build rules
-# The module defines the following variables:
-#  FLEX_FOUND - true is flex executable is found
-#  FLEX_VERSION - the version of flex
-# If flex is found on the system, the module provides the macro:
-#  FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS <string>])
-# which creates a custom command  to generate the <FlexOutput> file from
-# the <FlexInput> file.  If  COMPILE_FLAGS option is specified, the next
-# parameter is added to the flex  command line. Name is an alias used to
-# get  details of  this custom  command.  Indeed the  macro defines  the
-# following variables:
-#  FLEX_${Name}_DEFINED - true is the macro ran successfully
-#  FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
-#  alias for FlexOutput
-#  FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput}
-#
-# Flex scanners oftenly use tokens  defined by Bison: the code generated
-# by Flex  depends of the header  generated by Bison.   This module also
-# defines a macro:
-#  ADD_FLEX_BISON_DEPENDENCY(FlexTarget BisonTarget)
-# which  adds the  required dependency  between a  scanner and  a parser
-# where  <FlexTarget>  and <BisonTarget>  are  the  first parameters  of
-# respectively FLEX_TARGET and BISON_TARGET macros.
-#
-# Example:
-#  FIND_PACKAGE(BISON)
-#  FIND_PACKAGE(FLEX)
-#  BISON_TARGET(MyParser parser.y ${PROJECT_BINARY_DIR}/parser.cpp
-#  FLEX_TARGET(MyScanner lexer.l ${PROJECT_BINARY_DIR}/lexer.cpp)
-#  ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)
-#
-
-# Copyright (c) 2006, Tristan Carel
-# All rights reserved.
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-#     * Redistributions of source code must retain the above copyright
-#       notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above copyright
-#       notice, this list of conditions and the following disclaimer in the
-#       documentation and/or other materials provided with the distribution.
-#     * Neither the name of the University of California, Berkeley nor the
-#       names of its contributors may be used to endorse or promote products
-#       derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# $Id: FindFLEX.cmake,v 1.1 2007-10-16 23:21:42 rotor Exp $
-
-SET(FLEX_FOUND FALSE)
-
-FIND_PROGRAM(FLEX_EXECUTABLE flex DOC "path to the flex executable")
-MARK_AS_ADVANCED(FLEX_EXECUTABLE)
-
-FIND_LIBRARY(FL_LIBRARY NAMES fl
-  PATHS /usr/lib DOC "path to the fl library")
-SET(FLEX_LIBRARIES ${FL_LIBRARY})
-
-IF(FLEX_EXECUTABLE)
-  SET(FLEX_FOUND TRUE)
-
-  EXECUTE_PROCESS(COMMAND ${FLEX_EXECUTABLE} --version
-    OUTPUT_VARIABLE FLEX_version_output
-    ERROR_VARIABLE FLEX_version_error
-    RESULT_VARIABLE FLEX_version_result
-    OUTPUT_STRIP_TRAILING_WHITESPACE)
-  IF(NOT ${FLEX_version_result} EQUAL 0)
-    MESSAGE(SEND_ERROR "Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_error}")
-  ELSE(NOT ${FLEX_version_result} EQUAL 0)
-    STRING(REGEX REPLACE "^flex (.*)$" "\\1"
-      FLEX_VERSION "${FLEX_version_output}")
-  ENDIF(NOT ${FLEX_version_result} EQUAL 0)
-
-  MACRO(FLEX_TARGET Name Input Output)
-    SET(FLEX_TARGET_usage "FLEX_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
-    IF(${ARGC} GREATER 3)
-      IF(${ARGC} EQUAL 5)
-	IF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
-	  SET(FLEX_EXECUTABLE_opts  "${ARGV4}")
-	  SEPARATE_ARGUMENTS(FLEX_EXECUTABLE_opts)
-	ELSE("${ARGV3}" STREQUAL "COMPILE_FLAGS")
-	  MESSAGE(SEND_ERROR ${FLEX_TARGET_usage})
-	ENDIF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
-      ELSE(${ARGC} EQUAL 5)
-	MESSAGE(SEND_ERROR ${FLEX_TARGET_usage})
-      ENDIF(${ARGC} EQUAL 5)
-    ENDIF(${ARGC} GREATER 3)
-    ADD_CUSTOM_COMMAND(OUTPUT ${Output}
-      COMMAND ${FLEX_EXECUTABLE} ${FLEX_EXECUTABLE_opts} -o${Output} ${Input}
-      DEPENDS ${Input}
-      COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}"
-      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
-
-    SET(FLEX_${Name}_DEFINED TRUE)
-    SET(FLEX_${Name}_OUTPUTS ${Output})
-    SET(FLEX_${Name}_INPUT ${Input})
-    SET(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts})
-  ENDMACRO(FLEX_TARGET)
-
-  MACRO(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget)
-    IF(NOT FLEX_${FlexTarget}_TARGET)
-      MESSAGE(SEND_ERROR "Flex target `${FlexTarget}' does not exists.")
-    ENDIF(NOT FLEX_${FlexTarget}_TARGET)
-    IF(NOT BISON_${BisonTarget}_TARGET)
-      MESSAGE(SEND_ERROR "Bison target `${BisonTarget}' does not exists.")
-    ENDIF(NOT BISON_${BisonTarget}_TARGET)
-
-    SET_SOURCE_FILES_PROPERTIES(${FLEX_${FlexTarget}_OUTPUT}
-      PROPERTIES OBJECT_DEPENDS ${BISON_${BisonTarget}_OUTPUT_HEADER})
-  ENDMACRO(ADD_FLEX_BISON_DEPENDENCY)
-
-ENDIF(FLEX_EXECUTABLE)
-
-IF(NOT FLEX_FOUND)
-  IF(NOT FLEX_FIND_QUIETLY)
-    MESSAGE(STATUS "FLEX was not found.")
-  ELSE(NOT FLEX_FIND_QUIETLY)
-    IF(FLEX_FIND_REQUIRED)
-      MESSAGE(FATAL_ERROR "FLEX was not found.")
-    ENDIF(FLEX_FIND_REQUIRED)
-  ENDIF(NOT FLEX_FIND_QUIETLY)
-ENDIF(NOT FLEX_FOUND)
-
-# FindFLEX.cmake ends here
deleted file mode 100644
--- a/cmake-modules/FindMINC.cmake
+++ /dev/null
@@ -1,28 +0,0 @@
-# FindMINC.cmake module
-
-FIND_PACKAGE(NETCDF)
-FIND_PACKAGE(HDF5)
-
-
-FIND_PATH(MINC_INCLUDE_DIR minc2.h /usr/include /usr/local/include /usr/local/bic/include)
-FIND_LIBRARY(MINC_LIBRARY NAMES libminc2 PATHS /usr/lib /usr/local/lib /usr/local/bic/lib)
-
-
-IF (MINC_INCLUDE_DIR AND MINC_LIBRARY)
-   SET(MINC_FOUND TRUE)
-   
-   LIST(APPEND MINC_INCLUDE_DIR ${NETCDF_INCLUDE_DIR} ${HDF5_INCLUDE_DIR})
-   LIST(APPEND MINC_LIBRARY ${NETCDF_LIBRARY} ${HDF5_LIBRARY})
-   
-ENDIF (MINC_INCLUDE_DIR AND MINC_LIBRARY)
-
-
-IF (MINC_FOUND)
-   IF (NOT Minc_FIND_QUIETLY)
-      MESSAGE(STATUS "Found MINC: ${MINC_LIBRARY}")
-   ENDIF (NOT Minc_FIND_QUIETLY)
-ELSE (MINC_FOUND)
-   IF (Minc_FIND_REQUIRED)
-      MESSAGE(FATAL_ERROR "Cound not find MINC")
-   ENDIF (Minc_FIND_REQUIRED)
-ENDIF (MINC_FOUND)
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -5,10 +5,47 @@
 #define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
 #define PACKAGE_VERSION "@PACKAGE_VERSION@"
 #define PACKAGE_STRING "@PACKAGE_STRING@"
-
 #define VERSION PACKAGE_VERSION
 
-#define HAVE_MKSTEMP @HAVE_MKSTEMP@
-#define HAVE_STRERROR @HAVE_STRERROR@
+#define H5Acreate_vers 2
+
+#cmakedefine01 HAVE_MKSTEMP 
+#cmakedefine01 HAVE_STRERROR 
+#cmakedefine01 HAVE_FLOAT_H 
 
-#define HAVE_FLOAT_H @HAVE_FLOAT_H@
+#cmakedefine01 HAVE_DIRENT_H 
+#cmakedefine01 HAVE_DLFCN_H 
+#cmakedefine01 HAVE_FCNTL_H 
+#cmakedefine01 HAVE_FORK 
+#cmakedefine01 HAVE_GETPWNAM 
+#cmakedefine01 HAVE_INT16_T 
+#cmakedefine01 HAVE_INT32_T 
+#cmakedefine01 HAVE_INTTYPES_H 
+#cmakedefine01 HAVE_MEMORY_H 
+#cmakedefine01 HAVE_MKSTEMP 
+#cmakedefine01 HAVE_NDIR_H 
+#cmakedefine01 HAVE_POPEN 
+#cmakedefine01 HAVE_PWD_H 
+#cmakedefine01 HAVE_SELECT 
+#cmakedefine01 HAVE_STDINT_H 
+#cmakedefine01 HAVE_STDLIB_H 
+#cmakedefine01 HAVE_STRDUP 
+#cmakedefine01 HAVE_SYSCONF 
+#cmakedefine01 HAVE_SYSTEM 
+#cmakedefine01 HAVE_SYS_DIR_H 
+#cmakedefine01 HAVE_SYS_NDIR_H 
+#cmakedefine01 HAVE_SYS_STAT_H 
+#cmakedefine01 HAVE_SYS_TIME_H 
+#cmakedefine01 HAVE_SYS_TYPES_H 
+#cmakedefine01 HAVE_SYS_WAIT_H 
+#cmakedefine01 HAVE_TEMPNAM 
+#cmakedefine01 HAVE_TMPNAM 
+#cmakedefine01 HAVE_UNISTD_H 
+#cmakedefine01 HAVE_VALUES_H 
+#cmakedefine01 HAVE_VFORK 
+#cmakedefine01 HAVE_VFORK_H 
+#cmakedefine01 HAVE_WORKING_FORK 
+#cmakedefine01 HAVE_WORKING_VFORK 
+#cmakedefine01 HAVE_ZLIB 
+#cmakedefine01 HAVE_STRINGS_H 
+#cmakedefine01 HAVE_STRING_H 
--- a/configure.in
+++ b/configure.in
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 
-AC_INIT([minc],[2.1.01],[a.janke@gmail.com])
+AC_INIT([minc],[2.1.10],[a.janke@gmail.com])
 
 AC_CONFIG_SRCDIR([libsrc2/minc2.h])
 AC_CONFIG_AUX_DIR(ac_config_aux)
--- a/conversion/CMakeLists.txt
+++ b/conversion/CMakeLists.txt
@@ -3,11 +3,7 @@
 # Andrew Janke - a.janke@gmail.com
 
 #LINK_DIRECTORIES()
-IF(BUILD_MINC2)
-  LINK_LIBRARIES( minc2 ${NETCDF_LIBRARY} ${HDF5_LIBRARY} )
-ELSE(BUILD_MINC2)
-  LINK_LIBRARIES( minc ${NETCDF_LIBRARY} )
-ENDIF(BUILD_MINC2)
+LINK_LIBRARIES( ${MINC2_LIBRARIES} m)
 
 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
 
@@ -47,11 +43,7 @@
    minctoecat/machine_indep.c
    )
 
-IF(BUILD_MINC2)
-  TARGET_LINK_LIBRARIES(minctoecat volume_io2 minc2)
-ELSE(BUILD_MINC2)
-  TARGET_LINK_LIBRARIES(minctoecat volume_io minc)
-ENDIF(BUILD_MINC2)
+TARGET_LINK_LIBRARIES(minctoecat ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 
 ADD_EXECUTABLE(mnc2nii
@@ -59,25 +51,29 @@
    nifti1/nifti1_io.c
    nifti1/znzlib.c
    )
+TARGET_LINK_LIBRARIES(mnc2nii ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
+
 ADD_EXECUTABLE(nii2mnc
    nifti1/nii2mnc.c
    nifti1/nifti1_io.c
    nifti1/znzlib.c
    )
-
-IF(BUILD_MINC2)
-  TARGET_LINK_LIBRARIES(nii2mnc volume_io2 minc2)
-ELSE(BUILD_MINC2)
-  TARGET_LINK_LIBRARIES(nii2mnc volume_io minc)
-ENDIF(BUILD_MINC2)
+TARGET_LINK_LIBRARIES(nii2mnc ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 ADD_EXECUTABLE(upet2mnc
    micropet/upet2mnc.c
    )
 
+IF(BUILD_MINC2)
+
 ADD_EXECUTABLE(vff2mnc
    vff2mnc/vff2mnc.c
    )
+INSTALL(TARGETS
+   vff2mnc
+   DESTINATION bin)
+
+ENDIF(BUILD_MINC2)
 
 
 # install progs
@@ -88,5 +84,4 @@
    mnc2nii
    nii2mnc
    upet2mnc
-   vff2mnc
    DESTINATION bin)
--- a/conversion/dcm2mnc/dicom_to_minc.c
+++ b/conversion/dcm2mnc/dicom_to_minc.c
@@ -891,6 +891,7 @@
     char *str_ptr2=NULL;
     int interpolation_flag;
     int enc_ix, num_encodings, num_b0; 
+    int EXT=0; /*special handling when an external diffusion vector file is used*/
 
     element = acr_find_group_element(group_list, SPI_Protocol2);
     if (element != NULL) {
@@ -1067,7 +1068,7 @@
          * assumptions:
          *
          *  - diffusion protocol indicated by sDiffusion.ulMode = 0x100
-	 *  - bvalue is in sDiffusionalBValue[0]
+	 *  - bvalue is in sDiffusion.alBValue[0]
          *  - there is 1 b=0 scans and 12 diffusion directions
          *  - b=0 scan havs sequence name "ep_b0"
          *  - encoded scans have seq names "ep_b1000#1, ep_b1000#2, ..." etc.
@@ -1082,7 +1083,7 @@
          * assumptions:
          *
          *  - diffusion protocol indicated by sDiffusion.ulMode = 0x80
-	 *  - bvalue is in sDiffusionalBValue[1]
+	 *  - bvalue is in sDiffusion.alBValue[1]
          *  - there is 1 b=0 scans and user defined number of diffusion directions
          *  - b=0 scan has sequence name "ep_b0"
          *  - encoded scans have seq names "ep_b1000#1, ep_b1000#2, ..." etc.
@@ -1100,7 +1101,7 @@
 	  /*----MGH-----*/
 	  prot_find_string(protocol,"sWiPMemBlock.alFree[8]", str_buf);
 	  if ((atoi ((char*)str_buf))!= 0 ) { /*num b0 images for MGH sequence*/
-            
+		  
 	    /* get number of b=0 images*/
             num_b0 = atoi ((char*)str_buf);
 		  
@@ -1124,16 +1125,19 @@
 		    	num_b0=1;
 	  
           	}
-	   	/*-----ICBM_WIP  with "Diffusion mode"=Free (5 b=0 scans) -----*/
+	   	/*-----ICBM_WIP  with "Diffusion mode"=Free (5 b=0 scans) or any time an external vectors file is used-----*/
 	  	else if(!strcmp(str_buf, "0x80")) {
+			EXT=1;
         	    	/* try to get b value */
             		prot_find_string(protocol, "sDiffusion.alBValue[0]", str_buf);
 	            	acr_insert_numeric(&group_list, EXT_Diffusion_b_value,
                                            (double)atoi(str_buf));
 		    	num_b0=0; 
-			/*there are 5 b=0 scans but they are not identified 
+			/*For ICBM there are 5 b=0 scans but they are not identified 
 			any differently than the diffusion weighted images, 
-			sDiffusion.lDiffDirections includes the b=0 images*/	  
+			sDiffusion.lDiffDirections includes the b=0 images. An external
+			DiffusionVectors file can include other b=0 and this messes up
+			the image count*/	  
           	}
 	   }  
 	    
@@ -1168,8 +1172,7 @@
 			}
 	    else{
 		enc_ix = atoi(str_ptr2 + 1) + num_b0; /*should be in diffusion weighted images now*/
-            }
-	  
+            }  
 	    /* however with the current sequence, we get usable
             * time indices from floor(global_image_num/num_slices)*/ /*i'm not sure that works here*/
 	    
@@ -1206,8 +1209,15 @@
 	    else{
 		enc_ix = atoi(str_ptr2 + 1) + num_b0; /*should be in diffusion weighted images now*/
             }
-                acr_insert_numeric(&group_list, ACR_Acquisition, (double)enc_ix);
+                
+	    acr_insert_numeric(&group_list, ACR_Acquisition, (double)enc_ix);
           }
+	  if (EXT==1) {
+	  /*if an external DiffusionVectors was used, the encoding index can be wrong
+	  because it does not take into account b=0 images within the acquisition. 
+	  Have to rely on ACR_Image 0020x0013 (but this field won't work for MGH sequence)*/
+		acr_insert_numeric(&group_list, ACR_Acquisition,acr_find_int(group_list, ACR_Image, 1) );  
+	  }
 	  
 	   /* BUG! TODO! FIXME!  In dcm2mnc.c the sequence name is
              * used as one of the criteria for starting a new
@@ -2121,7 +2131,7 @@
 prot_find_string(Acr_Element elem_ptr, const char *name_str, char *value)
 {
     static const char prot_head[] = "### ASCCONV BEGIN ###";
-    long cur_offset;
+    long cur_offset,tmp_offset;
     long max_offset;
     char *field_ptr;
     int  ix1, ix2;
@@ -2131,13 +2141,19 @@
     // Scan through the element containing the protocol, to find the 
     // ASCII dump of the MrProt structure.
     //
+    /*For some reason, some dicom files have 2 "ASCCONV BEGIN" tags, this screws up the search.
+     Keep the second one we find for now, don't know if this will always work for these dual-ASCCONV
+     files. IRL*/
+    
     for (cur_offset = 0; cur_offset < max_offset; cur_offset++) {
         if (!memcmp(elem_ptr->data_pointer + cur_offset,
                     prot_head, sizeof(prot_head) - 1)) {
-            break;
+		tmp_offset = cur_offset;
         }
     }
 
+    cur_offset = tmp_offset; /*set it to the last occurence of "ASCCONV BEGIN"*/   
+    
     /* bail if we didn't find the protocol
      */
     if (cur_offset == max_offset) {
@@ -2167,7 +2183,7 @@
     const char prot_tail[] = "### ASCCONV END ###";
     char *output = malloc(elem_ptr->data_length);
     int prot_found = FALSE;
-    long cur_offset;
+    long cur_offset, tmp_offset;
     long max_offset;
 
     CHKMEM(output);
@@ -2175,15 +2191,21 @@
     // scan throught the group containing the protocol, to find the 
     // ascii dump of the MrProt structure
     max_offset = elem_ptr->data_length - sizeof (prot_head);
-
+	   
+     /*For some reason, some dicom files have 2 "ASCCONV BEGIN" tags, this screws up the search.
+     Keep the second one we find for now, don't know if this will always work for these dual-ASCCONV
+     files. IRL*/
+    
     for (cur_offset = 0; cur_offset < max_offset; cur_offset++) {
         if (!memcmp(elem_ptr->data_pointer + cur_offset,
                     prot_head, sizeof(prot_head) - 1)) {
-            prot_found = TRUE;
-            break;
+		prot_found = TRUE;
+		tmp_offset = cur_offset;
         }
     }
 
+    cur_offset = tmp_offset; /*set it to the last occurence of "ASCCONV BEGIN"*/
+    
     if (prot_found) {
         int ix1 = 0;
         char *tmp_ptr = elem_ptr->data_pointer + cur_offset;
--- a/conversion/minctoecat/machine_indep.c
+++ b/conversion/minctoecat/machine_indep.c
@@ -61,7 +61,7 @@
 }
 
 #if defined(__alpha) || defined(_WIN32) /* LITTLE_ENDIAN : alpha, intel */
-ftovaxf(f, bufr)
+void ftovaxf(f, bufr)
 float f;
 unsigned short *bufr;
 {
@@ -84,7 +84,7 @@
 	bufr[1] =  ret >>16;
 }
 #else  /* BIG ENDIAN : sun hp sgi*/
-ftovaxf(orig,number)
+void ftovaxf(orig,number)
   unsigned short number[2];
   float orig;
 {
--- a/conversion/nifti1/mnc2nii.c
+++ b/conversion/nifti1/mnc2nii.c
@@ -2,7 +2,7 @@
 #include "config.h"
 #endif
 
-#include <minc2.h>
+#include <minc.h>
 #include <ParseArgv.h>
 
 #include "nifti1_io.h"
--- a/conversion/nifti1/znzlib.c
+++ b/conversion/nifti1/znzlib.c
@@ -244,6 +244,7 @@
 #if !defined (WIN32)
 int znzprintf(znzFile stream, const char *format, ...)
 {
+  char *tmpstr;
   int retval=0;
   va_list va;
   if (stream==NULL) { return 0; }
--- a/conversion/vff2mnc/vff2mnc.c
+++ b/conversion/vff2mnc/vff2mnc.c
@@ -125,8 +125,8 @@
 #if HAVE_DIRENT_H
       
       if (stat(G.dirname, &st) != 0 || !S_ISDIR(st.st_mode)) {
-	print("Option -addattrs requires directory as argument!!!\n");
-	exit(EXIT_FAILURE);
+        fprintf(stderr,"Option -addattrs requires directory as argument!!!\n");
+        exit(EXIT_FAILURE);
       }
 #endif 
     }
--- a/ezminc/CMakeLists.txt
+++ b/ezminc/CMakeLists.txt
@@ -1,7 +1,5 @@
 OPTION(BUILD_EZMINC_EXAMPLES   "Build EZminc examples" ON)
 
-
-
 IF(BUILD_MINC2)
   ADD_DEFINITIONS( -DMINC2 )
 ENDIF(BUILD_MINC2)
@@ -24,7 +22,7 @@
 
 
 ADD_LIBRARY( minc_io ${MINC_IO_HEADERS} ${MINC_IO_SRC})
-TARGET_LINK_LIBRARIES(minc_io ${minc_LIB})
+TARGET_LINK_LIBRARIES(minc_io ${MINC2_LIBRARIES})
 
 INSTALL(TARGETS minc_io ARCHIVE DESTINATION lib)
 INSTALL(FILES  ${MINC_IO_HEADERS} DESTINATION include)
--- a/ezminc/examples/CMakeLists.txt
+++ b/ezminc/examples/CMakeLists.txt
@@ -7,7 +7,7 @@
 ADD_EXECUTABLE(volume_similarity volume_similarity.cpp)
 
 INSTALL(TARGETS
-  fuzzy_volume_similarity
-  volume_similarity
+   fuzzy_volume_similarity
+   volume_similarity
    DESTINATION bin)
 
--- a/libsrc/netcdf_convenience.c
+++ b/libsrc/netcdf_convenience.c
@@ -249,7 +249,8 @@
 
 
 #if !(HAVE_WORKING_FORK && HAVE_SYSTEM && HAVE_POPEN)
-
+   fprintf(stderr,"Can't decompress %s because system is not available!\n",infile);
+   
    return 1;
 
 #else      /* Unix */
@@ -1940,5 +1941,4 @@
         }
     }
     return (strdup(buffer));
-}
-
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/libsrc/read_file_names.c
@@ -0,0 +1,99 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "read_file_names.h"
+
+#define FILE_NAME_ALLOC_SIZE 10
+#define FILE_PATH_MAX 2046
+
+
+
+/* ----------------------------- MNI Header -----------------------------------
+@NAME       : read_file_names
+@INPUT      : filelist - name of file from which to read names
+@OUTPUT     : num_files - number of files read in
+@RETURNS    : Pointer to a NULL-terminated array of file names
+@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
+              "-" is specified. Returns NULL if an error occurs. If
+              no error occurs, then a pointer to an empty array is 
+              returned and num_files is zero.
+@METHOD     : 
+@GLOBALS    : 
+@CALLS      : 
+@CREATED    : March 8, 1995 (Peter Neelin)
+@MODIFIED   : 
+---------------------------------------------------------------------------- */
+char **read_file_names(char *filelist, int *num_files)
+{
+   char **files;
+   int array_size;
+   int nfiles;
+   FILE *fp;
+   char line[FILE_PATH_MAX+1];
+   int length;
+
+   /* Open the file */
+   if (strcmp(filelist, "-") == 0) {
+      fp = stdin;
+   }
+   else {
+      fp = fopen(filelist, "r");
+      if (fp == NULL) {
+         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
+         return NULL;
+      }
+   }
+
+   /* Allocate an initial array and NULL-terminate it */
+   array_size = FILE_NAME_ALLOC_SIZE;
+   files = malloc(sizeof(*files) * array_size);
+   if (files == NULL) {
+      (void) fprintf(stderr, "Error allocating memory\n");
+      return NULL;
+   }
+   nfiles = 0;
+   files[nfiles] = NULL;
+
+   /* Read in file names */
+   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
+
+      /* Remove a trailing newline and check that there is a name */
+      length = strlen(line);
+      if ((length > 0) && (line[length-1] == '\n')) {
+         line[length-1] = '\0';
+         length--;
+      }
+      if (length == 0) continue;
+
+      /* Make room for names if needed */
+      while (nfiles >= array_size-1) {
+         array_size += FILE_NAME_ALLOC_SIZE;
+         files = realloc(files, sizeof(*files) * array_size);
+         if (files == NULL) {
+            (void) fprintf(stderr, "Error allocating memory\n");
+            return NULL;
+         }
+      }
+
+      /* Save the name, making sure that the list is NULL-terminated */
+      files[nfiles] = strdup(line);
+      if (files[nfiles] == NULL) {
+         (void) fprintf(stderr, "Error allocating memory\n");
+         return NULL;
+      }
+      nfiles++;
+      files[nfiles] = NULL;
+   }
+
+   /* Close the file */
+   (void) fclose(fp);
+
+   /* Return the number of files */
+   *num_files = nfiles;
+
+   return files;
+}
new file mode 100644
--- /dev/null
+++ b/libsrc/read_file_names.h
@@ -0,0 +1,18 @@
+
+
+/* ----------------------------- MNI Header -----------------------------------
+@NAME       : read_file_names
+@INPUT      : filelist - name of file from which to read names
+@OUTPUT     : num_files - number of files read in
+@RETURNS    : Pointer to a NULL-terminated array of file names
+@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
+              "-" is specified. Returns NULL if an error occurs. If
+              no error occurs, then a pointer to an empty array is 
+              returned and num_files is zero.
+@METHOD     : 
+@GLOBALS    : 
+@CALLS      : 
+@CREATED    : March 8, 1995 (Peter Neelin)
+@MODIFIED   : 
+---------------------------------------------------------------------------- */
+char **read_file_names(char *filelist, int *num_files);
--- a/libsrc/voxel_loop.c
+++ b/libsrc/voxel_loop.c
@@ -357,7 +357,7 @@
    int need_to_free_loop_options;
    int old_ncopts;
 
-   (void)fprintf(stderr, "About to loop, max_buffer is %d\n", loop_options->total_copy_space);
+   //(void)fprintf(stderr, "About to loop, max_buffer is %d\n", loop_options->total_copy_space);
    
    /* Save ncopts and set it to default value */
    old_ncopts = ncopts;
--- a/minc4itk/CMakeLists.txt
+++ b/minc4itk/CMakeLists.txt
@@ -1,4 +1,5 @@
 FIND_PACKAGE(ITK REQUIRED)
+INCLUDE(${ITK_USE_FILE})
 
 IF(NOT ITK_LIBRARIES)
   MESSAGE( FATAL_ERROR "ITK libraries are not found!")
@@ -37,8 +38,8 @@
     ${ITK_LIBRARIES}
     itkvnl_algo 
     itkvnl 
-    ${minc_LIB}
-    ${volume_io_LIB}
+    ${VOLUME_IO_LIBRARY}
+    ${MINC2_LIBRARIES}
     m 
     z )
 
new file mode 100644
--- /dev/null
+++ b/minc4itk/conversion/CMakeLists.txt
@@ -0,0 +1,6 @@
+ADD_EXECUTABLE(itk_convert itk_convert.cpp)
+TARGET_LINK_LIBRARIES(itk_convert minc4itk)
+
+INSTALL(TARGETS
+  itk_convert
+   DESTINATION bin)
--- a/minc4itk/examples/CMakeLists.txt
+++ b/minc4itk/examples/CMakeLists.txt
@@ -1,8 +1,6 @@
 LINK_LIBRARIES( minc4itk )
 
 
-
-
 ADD_EXECUTABLE(itk_convert itk_convert.cpp)
 ADD_EXECUTABLE(itk_distance itk_distance.cpp)
 ADD_EXECUTABLE(itk_dti itk_dti.cpp)
--- a/minc4itk/examples/itk_convert.cpp
+++ b/minc4itk/examples/itk_convert.cpp
@@ -6,6 +6,8 @@
 #include <itkImageIOFactory.h>
 #include <itkImageIOBase.h>
 #include <itkFlipImageFilter.h>
+#include <itkMetaDataObject.h>
+#include <itkMetaDataDictionary.h>
 
 #include "itkMincImageIOFactory.h"
 #include "itkMincImageIO.h"
@@ -22,6 +24,7 @@
       << "--inv-y invert Y axis"<<std::endl
       << "--inv-z invert Z axis"<<std::endl
       << "--center set origin to the center of the image"<<std::endl
+      << "--show-meta show meta information (if present)"<<std::endl
 ;
 }
 typedef itk::ImageIOBase IOBase;
@@ -33,22 +36,39 @@
                     bool inv_y=false,
                     bool inv_z=false,
                     bool center=false,
-                    bool verbose=false)
+                    bool verbose=false,
+                    bool show_meta=false)
 {
   typename itk::ImageFileReader<ImageType >::Pointer reader = itk::ImageFileReader<ImageType >::New();
   typename itk::FlipImageFilter<ImageType >::Pointer flip=itk::FlipImageFilter<ImageType >::New();
+  
   reader->SetImageIO(base);
   reader->SetFileName(base->GetFileName());
   reader->Update();
   
   typename ImageType::Pointer img=reader->GetOutput();
-     
+  
+  if(show_meta)
+  {
+    itk::MetaDataDictionary &thisDic=img->GetMetaDataDictionary();
+    
+    //let's write some meta information if there is any 
+    for(itk::MetaDataDictionary::ConstIterator it=thisDic.Begin();it!=thisDic.End();++it)
+    {
+			itk::MetaDataObjectBase *bs=(*it).second;
+			itk::MetaDataObject<std::string> * str=dynamic_cast<itk::MetaDataObject<std::string> *>(bs);
+			if(str)
+				std::cout<<(*it).first.c_str()<<" = "<< str->GetMetaDataObjectValue().c_str()<<std::endl;
+			else
+				std::cout<<(*it).first.c_str()<<" type: "<< typeid(*bs).name()<<std::endl;
+		}
+  }
+
+  //TODO: convert metadata to and from minc format for DTI 
   /* WRITING */
   if(verbose)
     std::cout<<"Writing "<<fname<<"..."<<std::endl;
   
-
-  
   if(inv_x||inv_y||inv_z)
   {
     typename itk::FlipImageFilter<ImageType >::FlipAxesArrayType arr;
@@ -64,7 +84,7 @@
   if(center)//move origin to the center of the image
   {
     typename ImageType::RegionType r=img->GetLargestPossibleRegion();
-    std::vector<double> corner[3];
+    //std::vector<double> corner[3];
     
     typename ImageType::IndexType idx;
     typename ImageType::PointType c;
@@ -95,6 +115,7 @@
 {
   int verbose=0;
   int clobber=0;
+  int show_meta=0;
   int inv_x=0,inv_y=0,inv_z=0,center=0;
   //char *history = time_stamp(argc, argv); //maybe we should free it afterwards
 
@@ -106,6 +127,7 @@
     {"inv-y", no_argument,  &inv_y, 1},
     {"inv-z", no_argument,  &inv_z, 1},
     {"center", no_argument, &center, 1},
+    {"show-meta", no_argument, &show_meta, 1},
     {0, 0, 0, 0}
   };
     
@@ -149,8 +171,8 @@
  
   try
   {
-    //registering the MINC_IO factory
-    itk::ObjectFactoryBase::RegisterFactory(itk::MincImageIOFactory::New());
+    itk::RegisterMincIO();
+    
     /* READING */
     if(verbose) 
       std::cout<<"Reading "<<input.c_str()<<"..."<<std::endl;
@@ -172,69 +194,69 @@
     if(verbose)
     {
       std::cout<<"dimensions:"<<nd<<std::endl
-          <<"components:"<<nc<<std::endl
-          <<"type:"<<ct_s.c_str()<<std::endl;
+               <<"components:"<<nc<<std::endl
+               <<"type:"<<ct_s.c_str()<<std::endl;
     }
     
     if(nd==3 && nc==1)
     {
       if(verbose) std::cout<<"Writing 3D image..."<<std::endl;
-        switch(ct)
-        {
-          case itk::ImageIOBase::UCHAR :
-            load_and_save_image<itk::Image<unsigned char, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break;
-          case itk::ImageIOBase::CHAR :
-            load_and_save_image<itk::Image<char, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break;
-          case itk::ImageIOBase::USHORT :
-            load_and_save_image<itk::Image<unsigned short, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break;
-          case itk::ImageIOBase::SHORT :
-            load_and_save_image<itk::Image<short, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break;
-          case itk::ImageIOBase::INT :
-            load_and_save_image<itk::Image<int, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break; 
-          case itk::ImageIOBase::UINT:
-            load_and_save_image<itk::Image<unsigned int, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break; 
-          case itk::ImageIOBase::FLOAT :
-            load_and_save_image<itk::Image<float, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break; 
-          case itk::ImageIOBase::DOUBLE:
-            load_and_save_image<itk::Image<double, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
-            break; 
-          default:
-            itk::ExceptionObject("Unsupported component type");
-        }
+      switch(ct)
+      { 
+        case itk::ImageIOBase::UCHAR :
+          load_and_save_image<itk::Image<unsigned char, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break;
+        case itk::ImageIOBase::CHAR :
+          load_and_save_image<itk::Image<char, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break;
+        case itk::ImageIOBase::USHORT :
+          load_and_save_image<itk::Image<unsigned short, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break;
+        case itk::ImageIOBase::SHORT :
+          load_and_save_image<itk::Image<short, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break;
+        case itk::ImageIOBase::INT :
+          load_and_save_image<itk::Image<int, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break; 
+        case itk::ImageIOBase::UINT:
+          load_and_save_image<itk::Image<unsigned int, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+           break; 
+        case itk::ImageIOBase::FLOAT :
+          load_and_save_image<itk::Image<float, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break; 
+        case itk::ImageIOBase::DOUBLE:
+          load_and_save_image<itk::Image<double, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
+          break; 
+        default:
+          itk::ExceptionObject("Unsupported component type");
+      }
     } else if((nd==4 && nc==1)) {
       if(verbose) std::cout<<"Writing 4D image..."<<std::endl;
         switch(ct)
         {
           case itk::ImageIOBase::UCHAR:
-            load_and_save_image<itk::Image<unsigned char, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<unsigned char, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::CHAR:
-            load_and_save_image<itk::Image<char, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<char, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::USHORT:
-            load_and_save_image<itk::Image<unsigned short, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<unsigned short, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::SHORT:
-            load_and_save_image<itk::Image<short, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<short, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::INT:
-            load_and_save_image<itk::Image<int, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<int, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           case itk::ImageIOBase::UINT:
-            load_and_save_image<itk::Image<unsigned int, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<unsigned int, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           case itk::ImageIOBase::FLOAT:
-            load_and_save_image<itk::Image<float, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<float, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           case itk::ImageIOBase::DOUBLE:
-            load_and_save_image<itk::Image<double, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::Image<double, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           default:
             itk::ExceptionObject("Unsupported component type");
@@ -245,28 +267,28 @@
         switch(ct)
         {
           case itk::ImageIOBase::UCHAR:
-            load_and_save_image<itk::VectorImage<unsigned char, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<unsigned char, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::CHAR:
-            load_and_save_image<itk::VectorImage<char, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<char, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::USHORT:
-            load_and_save_image<itk::VectorImage<unsigned short, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<unsigned short, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::SHORT:
-            load_and_save_image<itk::VectorImage<short, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<short, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break;
           case itk::ImageIOBase::INT:
-            load_and_save_image<itk::VectorImage<int, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<int, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           case itk::ImageIOBase::UINT:
-            load_and_save_image<itk::VectorImage<unsigned int, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<unsigned int, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           case itk::ImageIOBase::FLOAT:
-            load_and_save_image<itk::VectorImage<float, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<float, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           case itk::ImageIOBase::DOUBLE:
-            load_and_save_image<itk::VectorImage<double, 4> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose);
+            load_and_save_image<itk::VectorImage<double, 3> >(io,output.c_str(),inv_x,inv_y,inv_z,center,verbose,show_meta);
             break; 
           default:
             itk::ExceptionObject("Unsupported component type");
--- a/minc4itk/itkMincImageIO.cxx
+++ b/minc4itk/itkMincImageIO.cxx
@@ -421,6 +421,7 @@
       bool is_signed=false;
       bool have_vectors=false;
       bool have_time=false;
+      int dim_no=GetNumberOfDimensions();
       
       switch(GetComponentType())
       {
@@ -474,18 +475,24 @@
       std::vector<int> dimmap(5,-1);
       minc_info info;
       
-      if(GetNumberOfComponents()>1 && GetNumberOfComponents()<=3 ) 
+      if(GetNumberOfComponents()>1)
       {
-        have_vectors=true;
-        have_time=false;
-      } else if(GetNumberOfComponents()>3||GetNumberOfDimensions()>3) {
-        have_vectors=false;
-        have_time=true;
+	if(GetNumberOfComponents()<=3 ) 
+	{
+	  have_vectors=true;
+	  have_time=false;
+	} else if(GetNumberOfComponents()>3) {
+	  have_vectors=false;
+	  have_time=true;
+	}
+	dim_no++;
+      } else if(GetNumberOfDimensions()>3) {
+	have_vectors=false;
+	have_time=true;
       }
       
       if(itk::ExposeMetaData(thisDic,"dimorder",dimorder))
       {
-        //dimmap.resize(dimorder.size());
         for(int i=0,j=0;i<dimorder.size();i++)
         {
           if(dimorder[i]==MIvector_dimension && have_vectors)
@@ -507,29 +514,28 @@
         if(have_vectors)
         {
           dimmap[0]=0;
-        } else if(have_time) {
-          have_vectors=false;
-          have_time=true;
-          dimmap[GetNumberOfDimensions()+1]=GetNumberOfDimensions();
-        }
-        dimmap[1]=(have_vectors?1:0)+0;
-        dimmap[2]=(have_vectors?1:0)+1;
-        dimmap[3]=(have_vectors?1:0)+2;
+        } 
+        for(int i=0;i<dim_no-(have_vectors?1:0);i++)
+	  dimmap[1+i]=(have_vectors?1:0)+i;
       }
       
-      int dim_no=GetNumberOfDimensions()+(have_vectors||have_time?1:0);
       info.resize(dim_no);
       
-/*      std::cout<<"dimmap:";
+      #ifdef _DEBUG
+      std::cout<<"Number of components:"<<GetNumberOfComponents()<<std::endl;
+      std::cout<<"Number of dimensions:"<<GetNumberOfDimensions()<<std::endl;
+      std::cout<<"info.size()="<<info.size()<<std::endl;
+      std::cout<<"dimmap:";
       for(int i=0;i<5;i++)
       {
         std::cout<<dimmap[i]<<",";
       }
-      std::cout<<std::endl;*/
+      std::cout<<std::endl;
+      #endif  //_DEBUG
       
       for(int i=0;i<GetNumberOfDimensions();i++)
       {
-        int _i=dimmap[i+1];//GetNumberOfDimensions()-i-1+(have_vectors?1:0);
+        int _i=dimmap[i+1];
         if(_i<0) 
         {
           throw ExceptionObject(__FILE__, __LINE__,"Internal error");
@@ -555,6 +561,7 @@
             break;
         }
       }
+      
       if(GetNumberOfDimensions()==3) //we are only rotating 3D volumes
       {
         vnl_vector< double> start(3);
@@ -572,7 +579,24 @@
           int _i=dimmap[i+1];
           info[_i].start=start[i];
         }
+      } else {
+	std::cout<<"Warning: maging rotation matrix for "<<GetNumberOfDimensions()<<"D volume"<<std::endl;
+	std::cout<<"Origin:";
+	for(int i=0;i<GetNumberOfDimensions();i++)
+	  std::cout<<GetOrigin(i)<<",";
+	std::cout<<std::endl;
+	
+	std::cout<<"Rotation matrix:"<<std::endl;
+	for(int i=0;i<GetNumberOfDimensions();i++)
+	{
+	  std::cout<<"\t"<<i<<":";
+	  for(int j=0;j<GetNumberOfDimensions();j++)
+	    std::cout<<GetDirection(i)[j]<<",";
+	  std::cout<<std::endl;
+	}
+	std::cout<<std::endl;
       }
+      
       //here we assume that we had a grid file
       if(have_vectors)
       {
@@ -584,36 +608,50 @@
         info[_i].have_dir_cos=false;
       } else if(have_time){
         int _i=dimmap[4];
-        info[_i].length=GetNumberOfComponents();
+        info[_i].length=(GetNumberOfComponents()==1)?GetDimensions(3):GetNumberOfComponents();
         double tstep=1;
         double tstart=0;
-        itk::ExposeMetaData(thisDic,"tstep",tstep);
-        itk::ExposeMetaData(thisDic,"tstart",tstart);
-        
-        info[_i].step=tstep;
-        info[_i].start=tstart;
+	
+	if( itk::ExposeMetaData(thisDic,"tstep",tstep) &&
+	    itk::ExposeMetaData(thisDic,"tstart",tstart) )
+	{
+	  info[_i].step=tstep;
+	  info[_i].start=tstart;
+	} else if( GetNumberOfComponents()==1 ) {
+	  info[_i].step=GetSpacing(3);
+	  info[_i].start=GetOrigin(3);
+	} else {
+	  info[_i].step=1.0; //TODO: show somehow differently that we don't have info?
+	  info[_i].start=0;
+	}
+	
         info[_i].dim=dim_info::DIM_TIME;
-        info[_i].have_dir_cos=false;
+        info[_i].have_dir_cos=false; //TODO: what to do here?
       }
       
-/*      std::cout<<"info:";
+      #ifdef _DEBUG
+      std::cout<<"info:";
       for(int i=0;i<info.size();i++)
       {
         switch(info[i].dim)
         {
           case dim_info::DIM_VEC:
-            std::cout<<"vector_dimension,";break;
+            std::cout<<"vector_dimension";break;
           case dim_info::DIM_Z:
-            std::cout<<"zspace,";break;
+            std::cout<<"zspace";break;
           case dim_info::DIM_Y:
-            std::cout<<"yspace,";break;
+            std::cout<<"yspace";break;
           case dim_info::DIM_X:
-            std::cout<<"xspace,";break;
-          default: std::cout<<"Unknown! ";break;
-            
+            std::cout<<"xspace";break;
+	  case dim_info::DIM_TIME:
+	    std::cout<<"time";break;
+          default: 
+	    std::cout<<"unknown";break;
         }
+        std::cout<<"("<<info[i].length<<"),";
       }
-      std::cout<<std::endl;      */
+      std::cout<<std::endl;
+      #endif //_DEBUG
       
       //TODO:  shuffle info based on the dimnames
       _wrt=new minc_1_writer;
--- a/minc4itk/itkMincImageIOFactory.cxx
+++ b/minc4itk/itkMincImageIOFactory.cxx
@@ -3,6 +3,12 @@
 #include "itkMincImageIO.h"
 #include <itkVersion.h>
 #include <iostream>
+
+#if ( ITK_VERSION_MAJOR > 3 ) 
+//TODO:
+#include <itkHDF5ImageIOFactory.h>
+#endif //( ITK_VERSION_MAJOR > 3 ) 
+
 namespace itk
 {
   void MincImageIOFactory::PrintSelf(std::ostream&, Indent) const
@@ -36,5 +42,28 @@
     return "Minc ImageIO Factory, allows the loading of Minc images into insight";
   }
 
+  static bool MincImageIOFactoryHasBeenRegistered=false;
+  
+  void RegisterMincIO(void)
+  {
+    if( ! MincImageIOFactoryHasBeenRegistered )
+    {
+      MincImageIOFactoryHasBeenRegistered = true;
+      MincImageIOFactory::RegisterOneFactory();
+    }
+    //TODO: deregister HDF IO
+  }
+
+#if ( ITK_VERSION_MAJOR > 3 ) 
+// Undocumented API used to register during static initialization.
+// DO NOT CALL DIRECTLY.
+
+
+  void MincImageIOFactoryRegister__Private(void)
+  {
+    RegisterMincIO();
+  }
+  
+#endif   //( ITK_VERSION_MAJOR > 3 ) 
 } // end namespace itk
 
--- a/minc4itk/itkMincImageIOFactory.h
+++ b/minc4itk/itkMincImageIOFactory.h
@@ -51,7 +51,13 @@
   static void RegisterOneFactory(void)
   {
     MincImageIOFactory::Pointer metaFactory = MincImageIOFactory::New();
+    
+#if ( ITK_VERSION_MAJOR > 3 )
+    //try to be higher priority then built-in HDF5 IO class
+    ObjectFactoryBase::RegisterFactory(metaFactory, ObjectFactoryBase::INSERT_AT_FRONT );
+#else
     ObjectFactoryBase::RegisterFactory(metaFactory);
+#endif 
   }
 
 protected:
@@ -62,9 +68,9 @@
 private:
   MincImageIOFactory(const Self&); //purposely not implemented
   void operator=(const Self&); //purposely not implemented
-
 };
 
+void RegisterMincIO(void);
 
 } // end namespace itk
 
--- a/minc4itk/minc_general_transform.h
+++ b/minc4itk/minc_general_transform.h
@@ -48,7 +48,10 @@
     typedef typename itk::Transform < TScalarType, NInputDimensions, NOutputDimensions> Superclass;
     typedef typename itk::SmartPointer< Self >   Pointer;
     typedef typename itk::SmartPointer< const Self >  ConstPointer;
-    
+
+#if ( ITK_VERSION_MAJOR > 3 ) 
+    typedef typename Superclass::NumberOfParametersType  NumberOfParametersType;
+#endif // ( ITK_VERSION_MAJOR > 3 ) 
     
     /** New method for creating an object using a factory. */
     itkNewMacro(Self);
--- a/minc4itk/minc_helpers.cxx
+++ b/minc4itk/minc_helpers.cxx
@@ -201,9 +201,9 @@
   static void split_string(char *str,std::vector<std::string>& lst,const char *delim=" ")
   {
     lst.clear();
-    char *str2, *token;
+    char *str2;
     char *saveptr;
-    while(str2=strtok_r(str,delim,&saveptr))
+    while( (str2=strtok_r(str,delim,&saveptr)) )
     {
       str=NULL;
       lst.push_back(str2);
@@ -481,7 +481,6 @@
         tag_point tag;
 
         split_string(tmp,lst," ");
-        int skip=0;
         
         if(lst.size()<3) continue;
         
@@ -528,11 +527,11 @@
     if(p.empty()) // probably this is not right!
       REPORT_ERROR("Can't read parameters!");
     param.SetSize(p.size());
-    for(int i=0;i<p.size();i++)
+    for(size_t i=0;i<p.size();i++)
       param[i]=p[i];
   }
   
-  void load_parameters(const char *file,itk::Array<double> &param,int n)
+  void load_parameters(const char *file,itk::Array<double> &param,size_t n)
   {
     std::vector<double> p;
     ifstream in(file);
@@ -544,7 +543,7 @@
     param.SetSize(n);
     param.Fill(0);
     
-    for(int i=0;i<p.size() && i<n;i++)
+    for(size_t i=0;i<p.size() && i<n;i++)
       param[i]=p[i];
   }
 
@@ -555,7 +554,7 @@
     if(!out.good())
       REPORT_ERROR("Can't open the file for writing!");
     out.precision(40);
-    for(int i=0;i<param.Size();i++)
+    for(size_t i=0;i<param.Size();i++)
       out<<param[i]<<endl;
   }
   
--- a/minc4itk/minc_helpers.h
+++ b/minc4itk/minc_helpers.h
@@ -321,7 +321,7 @@
   //! save array to the text file
   void save_parameters(const char *file,const itk::Array<double> &param);
   //! read array from the text file, up to components
-  void load_parameters(const char *file,itk::Array<double> &param,int no);
+  void load_parameters(const char *file,itk::Array<double> &param,size_t no);
   //! make sure that all voxels are 0 or 1
   void normalize_mask(mask3d::Pointer img);
   
new file mode 100644
--- /dev/null
+++ b/minc4itk/tools/CMakeLists.txt
@@ -0,0 +1,11 @@
+LINK_LIBRARIES( minc4itk )
+
+
+ADD_EXECUTABLE(itk_distance itk_distance.cpp)
+ADD_EXECUTABLE(itk_resample itk_resample.cpp)
+
+
+INSTALL(TARGETS
+  itk_distance
+  itk_resample
+   DESTINATION bin)
--- a/progs/CMakeLists.txt
+++ b/progs/CMakeLists.txt
@@ -7,7 +7,7 @@
 #LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/..)
 INCLUDE_DIRECTORIES(Proglib)
 
-LINK_LIBRARIES( ${minc_LIB} )
+LINK_LIBRARIES( ${MINC2_LIBRARIES} )
 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
 
 #SET(BISON_FIND_REQUIRED)
@@ -19,6 +19,7 @@
 # all the progs
 ADD_EXECUTABLE(invert_raw_image mincview/invert_raw_image.c)
 ADD_EXECUTABLE(mincaverage mincaverage/mincaverage.c)
+TARGET_LINK_LIBRARIES(mincaverage m)
 
 IF(BISON_FOUND AND FLEX_FOUND)
   include_directories(${CMAKE_CURRENT_BINARY_DIR} minccalc)
@@ -40,14 +41,13 @@
                   ${BISON_gram_OUTPUTS}
                  )
 
-  TARGET_LINK_LIBRARIES(minccalc ${FLEX_LIBRARIES})
+  TARGET_LINK_LIBRARIES(minccalc ${FLEX_LIBRARIES} m)
 
   INSTALL( TARGETS minccalc  DESTINATION bin)
 
   include_directories(${CMAKE_CURRENT_BINARY_DIR} mincgen)
   BISON_TARGET(ncgentab ${CMAKE_CURRENT_SOURCE_DIR}/mincgen/ncgentab.y ${CMAKE_CURRENT_BINARY_DIR}/ncgentab.c)
   FLEX_TARGET(ncgenyy ${CMAKE_CURRENT_SOURCE_DIR}/mincgen/ncgenyy.l ${CMAKE_CURRENT_BINARY_DIR}/ncgenyy.c)
-  #ADD_FLEX_BISON_DEPENDENCY(ncgenyy ncgentab)
 
   ADD_EXECUTABLE(mincgen mincgen/main.c
                             ${BISON_ncgentab_OUTPUTS}
@@ -77,41 +77,51 @@
 ADD_EXECUTABLE(mincextract mincextract/mincextract.c)
 ADD_EXECUTABLE(mincinfo mincinfo/mincinfo.c)
 ADD_EXECUTABLE(minclookup minclookup/minclookup.c)
+TARGET_LINK_LIBRARIES(minclookup m)
+
 ADD_EXECUTABLE(mincmakescalar mincmakescalar/mincmakescalar.c)
+TARGET_LINK_LIBRARIES(mincmakescalar m)
+
 ADD_EXECUTABLE(mincmakevector mincmakevector/mincmakevector.c)
 ADD_EXECUTABLE(mincmath mincmath/mincmath.c)
+TARGET_LINK_LIBRARIES(mincmath m)
+
 ADD_EXECUTABLE(minc_modify_header minc_modify_header/minc_modify_header.c)
 
 ADD_EXECUTABLE(mincresample mincresample/mincresample.c
                                mincresample/resample_volumes.c
                                Proglib/convert_origin_to_start.c)
-TARGET_LINK_LIBRARIES(mincresample ${volume_io_LIB} ${minc_LIB})
+TARGET_LINK_LIBRARIES(mincresample ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 ADD_EXECUTABLE(mincreshape mincreshape/mincreshape.c
                               mincreshape/copy_data.c)
 
 ADD_EXECUTABLE(mincstats mincstats/mincstats.c)
+TARGET_LINK_LIBRARIES(mincstats m)
+
 ADD_EXECUTABLE(minctoraw minctoraw/minctoraw.c)
 ADD_EXECUTABLE(mincwindow mincwindow/mincwindow.c)
 
 ADD_EXECUTABLE(rawtominc rawtominc/rawtominc.c
                             Proglib/convert_origin_to_start.c)
+TARGET_LINK_LIBRARIES(rawtominc m)
+
 
 ADD_EXECUTABLE(voxeltoworld coordinates/voxeltoworld.c)
-TARGET_LINK_LIBRARIES(voxeltoworld ${volume_io_LIB} ${minc_LIB})
+TARGET_LINK_LIBRARIES(voxeltoworld ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 ADD_EXECUTABLE(worldtovoxel coordinates/worldtovoxel.c)
-TARGET_LINK_LIBRARIES(worldtovoxel ${volume_io_LIB} ${minc_LIB})
+TARGET_LINK_LIBRARIES(worldtovoxel ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 
 ADD_EXECUTABLE(transformtags xfm/transformtags.c)
-TARGET_LINK_LIBRARIES(transformtags ${volume_io_LIB} ${minc_LIB})
+TARGET_LINK_LIBRARIES(transformtags ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 ADD_EXECUTABLE(xfmconcat xfm/xfmconcat.c)
-TARGET_LINK_LIBRARIES(xfmconcat ${volume_io_LIB} ${minc_LIB})
+TARGET_LINK_LIBRARIES(xfmconcat ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 ADD_EXECUTABLE(xfminvert xfm/xfminvert.c)
-TARGET_LINK_LIBRARIES(xfminvert ${volume_io_LIB} ${minc_LIB})
+TARGET_LINK_LIBRARIES(xfminvert ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
 
 # install progs
 INSTALL(TARGETS
--- a/progs/mincaverage/mincaverage.c
+++ b/progs/mincaverage/mincaverage.c
@@ -105,6 +105,7 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
+#include "read_file_names.h"
 
 /* Constants */
 
@@ -165,7 +166,6 @@
                           double *output_data[],
                           Loop_Info *loop_info);
 static int get_double_list(char *dst, char *key, char *nextarg);
-static char **read_file_names(char *filelist, int *num_files);
 
 /* Argument variables */
 static int clobber = FALSE;
@@ -1010,91 +1010,3 @@
 
    return TRUE;
 }
-
-/* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
--- a/progs/minccalc/minccalc.c
+++ b/progs/minccalc/minccalc.c
@@ -121,6 +121,7 @@
 #include <voxel_loop.h>
 #include <time_stamp.h>
 #include "node.h"
+#include "read_file_names.h"
 
 /* Constants */
 
@@ -143,7 +144,6 @@
                     int input_vector_length, double *input_data[],
                     int output_num_buffers, int output_vector_length,
                     double *output_data[], Loop_Info *loop_info);
-static char **read_file_names(char *filelist, int *num_files);
 static char *read_expression_file(char *filename);
 static int get_list_option(char *dst, char *key, int argc, char **argv);
 
@@ -521,93 +521,6 @@
 }
 
 /* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
-/* ----------------------------- MNI Header -----------------------------------
 @NAME       : read_expression_file
 @INPUT      : filename - Name of file from which to read expression
 @OUTPUT     : (none)
--- a/progs/mincconcat/mincconcat.c
+++ b/progs/mincconcat/mincconcat.c
@@ -129,6 +129,7 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
+#include "read_file_names.h"
 
 /* Constants */
 #ifndef TRUE
@@ -213,7 +214,6 @@
 static int sort_function(const void *value1, const void *value2);
 static void create_concat_file(int inmincid, Concat_Info *concat_info);
 static void update_history(int mincid, char *arg_string);
-static char **read_file_names(char *filelist, int *num_files);
 
 /* Globals */
 static int Sort_ascending = TRUE;
@@ -1457,91 +1457,3 @@
    free(string);
 
 }
-
-/* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
--- a/progs/mincmath/mincmath.c
+++ b/progs/mincmath/mincmath.c
@@ -123,6 +123,7 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
+#include "read_file_names.h"
 
 /* Constants */
 
@@ -219,7 +220,6 @@
                      int output_num_buffers, int output_vector_length,
                      double *output_data[],
                      Loop_Info *loop_info);
-static char **read_file_names(char *filelist, int *num_files);
 
 /* Argument variables */
 static int clobber = FALSE;
@@ -929,91 +929,3 @@
 
    return;
 }
-
-/* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
new file mode 100644
--- /dev/null
+++ b/testdir/CMakeLists.txt
@@ -0,0 +1,54 @@
+
+LINK_LIBRARIES(${MINC2_LIBRARIES})
+
+ADD_EXECUTABLE(minc_tst minc.c)
+ADD_EXECUTABLE(icv icv.c)
+
+ADD_EXECUTABLE(icv_dim1 icv_dim1.c)
+ADD_EXECUTABLE(icv_dim icv_dim.c)
+ADD_EXECUTABLE(icv_fillvalue icv_fillvalue.c)
+ADD_EXECUTABLE(icv_range icv_range.c)
+ADD_EXECUTABLE(mincapi mincapi.c)
+ADD_EXECUTABLE(minc_types minc_types.c)
+ADD_EXECUTABLE(test_arg_parse test_arg_parse.c)
+ADD_EXECUTABLE(test_mconv test_mconv.c)
+ADD_EXECUTABLE(test_speed test_speed.c)
+ADD_EXECUTABLE(test_xfm test_xfm.c)
+
+ADD_EXECUTABLE(create_grid_xfm create_grid_xfm.c)
+TARGET_LINK_LIBRARIES(create_grid_xfm ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
+
+MACRO(minc_test cmd)
+  # minc 1 version
+  add_test(${cmd}-1 ${CMAKE_CURRENT_SOURCE_DIR}/run_test_cmake.sh ${CMAKE_CURRENT_BINARY_DIR}/${cmd} ${CMAKE_CURRENT_SOURCE_DIR}/${cmd}.out)
+  IF(BUILD_MINC2)
+  # minc 2 version
+  add_test(${cmd}-2 ${CMAKE_CURRENT_SOURCE_DIR}/run_test2_cmake.sh ${CMAKE_CURRENT_BINARY_DIR}/${cmd} ${CMAKE_CURRENT_SOURCE_DIR}/${cmd}.out)
+  ENDIF(BUILD_MINC2)
+
+ENDMACRO(minc_test)
+
+
+
+# running tests
+minc_test(minc_types)
+minc_test(icv_dim1)
+minc_test(icv_dim)
+minc_test(icv_fillvalue)
+minc_test(icv_range)
+
+
+add_test(arg_parse ${CMAKE_CURRENT_SOURCE_DIR}/run_test_arg_parse_cmake.sh ${CMAKE_CURRENT_BINARY_DIR}/test_arg_parse)
+add_test(icv icv)
+add_test(minc minc_tst)
+
+add_test(mincapi mincapi)
+add_test(test_arg_parse test_arg_parse)
+add_test(test_mconv test_mconv)
+
+# TODO port these test to cmake
+#add_test(create_grid_xfm create_grid_xfm)
+#add_test(test_speed test_speed)
+#add_test(test_xfm test_xfm)
+
+TARGET_LINK_LIBRARIES(test_xfm ${VOLUME_IO_LIBRARY} ${MINC2_LIBRARIES} m)
new file mode 100755
--- /dev/null
+++ b/testdir/run_test2_cmake.sh
@@ -0,0 +1,2 @@
+# /bin/sh
+$1 -2 |diff - $2
new file mode 100755
--- /dev/null
+++ b/testdir/run_test_arg_parse_cmake.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+
+#set -e
+
+CMD=$1
+fail=no
+
+check() { #args expected
+    out=`$CMD $1`
+    leftovers=`echo $out | sed "/^$2\$/d"`
+    test -z "$leftovers" && return
+    fail=yes
+}
+
+
+check ''                   'const_a:0 const_b:0 int_a:0 int_b:0 long_a:0 long_b:0'
+check '-const_a'           'const_a:1 const_b:0 int_a:0 int_b:0 long_a:0 long_b:0'
+check '-const_b'           'const_a:0 const_b:1 int_a:0 int_b:0 long_a:0 long_b:0'
+check '-const_a -const_b'  'const_a:1 const_b:1 int_a:0 int_b:0 long_a:0 long_b:0'
+check '-const_b -const_a'  'const_a:1 const_b:1 int_a:0 int_b:0 long_a:0 long_b:0'
+
+check '-int_a 33'          'const_a:0 const_b:0 int_a:33 int_b:0 long_a:0 long_b:0'
+check '-int_a -3'          'const_a:0 const_b:0 int_a:-3 int_b:0 long_a:0 long_b:0'
+check '-int_b 22'          'const_a:0 const_b:0 int_a:0 int_b:22 long_a:0 long_b:0'
+check '-int_b -2'          'const_a:0 const_b:0 int_a:0 int_b:-2 long_a:0 long_b:0'
+check '-int_a -1 -int_b 3' 'const_a:0 const_b:0 int_a:-1 int_b:3 long_a:0 long_b:0'
+check '-int_b -1 -int_a 3' 'const_a:0 const_b:0 int_a:3 int_b:-1 long_a:0 long_b:0'
+
+check '-long_a 12'            'const_a:0 const_b:0 int_a:0 int_b:0 long_a:12 long_b:0'
+check '-long_a -99'           'const_a:0 const_b:0 int_a:0 int_b:0 long_a:-99 long_b:0'
+check '-long_b -12'           'const_a:0 const_b:0 int_a:0 int_b:0 long_a:0 long_b:-12'
+check '-long_b 99'            'const_a:0 const_b:0 int_a:0 int_b:0 long_a:0 long_b:99'
+check '-long_a 3 -long_b -9'  'const_a:0 const_b:0 int_a:0 int_b:0 long_a:3 long_b:-9'
+check '-long_b 3 -long_a -9'  'const_a:0 const_b:0 int_a:0 int_b:0 long_a:-9 long_b:3'
+
+check '-long_a -99 -int_b 3 -const_b'  'const_a:0 const_b:1 int_a:0 int_b:3 long_a:-99 long_b:0'
+
+check '-nonsense'          'const_a:0 const_b:0 int_a:0 int_b:0 long_a:0 long_b:0'
+
+test $fail = yes && exit 1
+exit 0
+
new file mode 100755
--- /dev/null
+++ b/testdir/run_test_cmake.sh
@@ -0,0 +1,2 @@
+# /bin/sh
+$1 |diff - $2
--- a/volume_io/Prog_utils/files.c
+++ b/volume_io/Prog_utils/files.c
@@ -13,6 +13,10 @@
 ---------------------------------------------------------------------------- */
 
 #include  <internal_volume_io.h>
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
 #if HAVE_PWD_H
 #include  <pwd.h>
 #endif /* HAVE_PWD_H */
@@ -20,6 +24,7 @@
 #if HAVE_UNISTD_H
 #include  <unistd.h>
 #endif /* HAVE_UNISTD_H */
+
 #include  <errno.h>
 
 
@@ -533,8 +538,8 @@
 static  STRING  get_user_home_directory(
     STRING   user_name )
 {
-#if HAVE_GETPWNAM
-    struct   passwd  *p;
+#if HAVE_GETPWNAM 
+    struct passwd  *p;
 
     p = getpwnam( user_name );
 
--- a/volume_io/Volumes/input_mnc.c
+++ b/volume_io/Volumes/input_mnc.c
@@ -598,7 +598,7 @@
           file->n_slab_dims++;  /* integral number of complete dimensions */
         } else {
           slab_size *= MIN( file->sizes_in_file[d],
-                            (hsize_t)( MI_MAX_VAR_BUFFER_SIZE / ( slab_size * unit_size ) ) );
+                            (size_t)( MI_MAX_VAR_BUFFER_SIZE / ( slab_size * unit_size ) ) );
           full_dim = 0;
         }
       }
--- a/volume_io/Volumes/output_mnc.c
+++ b/volume_io/Volumes/output_mnc.c
@@ -1430,7 +1430,7 @@
           file->n_slab_dims++;  /* integral number of complete dimensions */
         } else {
           count[d] = MIN( volume_count[to_volume_index[d]], 
-                          (hsize_t)( MI_MAX_VAR_BUFFER_SIZE / ( slab_size * unit_size ) ) );
+                          (size_t)( MI_MAX_VAR_BUFFER_SIZE / ( slab_size * unit_size ) ) );
           n_steps *= (int)( ( volume_count[to_volume_index[d]] + count[d] - 1 ) / count[d] );
         }
         slab_size *= count[d];