changeset 2614:36848f798715

trying to merge with Andrew
author Vladimir S. FONOV <vladimir.fonov@gmail.com>
date Wed, 22 Feb 2012 13:52:48 -0500
parents 356008a3c7e6 (current diff) da1ba6dfb580 (diff)
children 40546c57c70d
files CMakeLists.txt MINC2Config.cmake.in UseMINC2.cmake.in config.h.cmake minc4itk/CMakeLists.txt
diffstat 15 files changed, 220 insertions(+), 366 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -116,6 +116,55 @@
   ENDIF(USE_ITK_HDF5)
 ENDIF(BUILD_MINC2)
 
+IF(BUILD_MINC2)
+ OPTION(USE_SYSTEM_HDF5 "Use System HDF5 > 1.8 " OFF)
+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)
 
@@ -194,6 +243,7 @@
 # netcdf and HDF5
 
 IF(BUILD_MINC2)
+  FIND_PACKAGE(ZLIB REQUIRED)
   SET(MINC2 "1")
 ELSE(BUILD_MINC2)
   SET(MINC2 "0")
@@ -238,6 +288,7 @@
    libsrc/hdf_convenience.c
    libsrc/minc_compat.c
    libsrc/minc_simple.c
+   libsrc/read_file_names.c
    )
 
 SET(minc2_LIB_SRCS
--- 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)
 
--- a/MINC2Config.cmake.in
+++ b/MINC2Config.cmake.in
@@ -14,8 +14,7 @@
 set(MINC2_LIBRARY_DIRS "@MINC2_LIBRARY_DIRS_CONFIG@")
 set(MINC2_USE_FILE     "@MINC2_USE_FILE_CONFIG@")
 set(MINC2_LIBRARIES    "@MINC2_LIBRARIES@")
-set(EZMINC_LIBRARIES   "@EZMINC_LIBRARIES@")
-set(MINC4ITK_LIBRARIES "@MINC4ITK_LIBRARIES@")
+
+set(EZMINC_LIBRARIES    "@EZMINC_LIBRARIES@")
+set(MINC4ITK_LIBRARIES  "@MINC4ITK_LIBRARIES@")
 set(VOLUME_IO_LIBRARIES "@VOLUME_IO_LIBRARY@")
-
-
--- 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
 ---------------------
--- a/UseMINC2.cmake.in
+++ b/UseMINC2.cmake.in
@@ -1,17 +1,38 @@
+<<<<<<< HEAD
 INCLUDE_DIRECTORIES(${MINC2_INCLUDE_DIRS})
 LINK_DIRECTORIES(${MINC2_LIBRARY_DIRS})
 
 INCLUDE_DIRECTORIES( ${NETCDF_INCLUDE_DIR} )
 
 if(HAVE_MINC2)
+=======
+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)
+>>>>>>> 0ec77fa9577ed217b2fa25f04b48683bafdc6fd9
 
   INCLUDE_DIRECTORIES( ${HDF5_INCLUDE_DIR} )
   
   SET(MINC2 "1")
   ADD_DEFINITIONS( -DMINC2=1 )
   
+<<<<<<< HEAD
 endif(HAVE_MINC2)
 
 if(USE_ITK_HDF5)
   LINK_DIRECTORIES(${ITK_LIBRARY_DIRS}) 
-endif(USE_ITK_HDF5)
\ No newline at end of file
+endif(USE_ITK_HDF5)
+=======
+  #SET(MINC_LIBRARIES volume_io2 minc2 netcdf hdf5 z)
+else(HAVE_MINC2)
+  #SET(MINC_LIBRARIES volume_io minc netcdf )
+endif(HAVE_MINC2)
+
+>>>>>>> 0ec77fa9577ed217b2fa25f04b48683bafdc6fd9
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -47,3 +47,6 @@
 #cmakedefine01 HAVE_ZLIB 
 #cmakedefine01 HAVE_STRINGS_H 
 #cmakedefine01 HAVE_STRING_H 
+
+#define H5Acreate_vers 2
+
--- 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)
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/minc4itk/CMakeLists.txt
+++ b/minc4itk/CMakeLists.txt
@@ -1,4 +1,3 @@
-#FIND_PACKAGE(ITK REQUIRED)
 INCLUDE(${ITK_USE_FILE})
 
 IF(NOT ITK_LIBRARIES)
--- 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;
-}
-