changeset 1972:4cf7ce657102

Port changes from 2.0 branch
author bert <bert>
date Wed, 16 Mar 2005 19:02:49 +0000
parents a893fe459367
children 8980384efc7f
files ChangeLog Makefile.am NEWS configure.in libsrc/ParseArgv.c progs/minc_modify_header/minc_modify_header.c progs/mincaverage/mincaverage.c progs/minccalc/minccalc.c progs/mincconcat/mincconcat.c progs/minccopy/minccopy.c progs/mincexample/mincexample1.c progs/mincexample/mincexample2.c progs/mincexpand/mincexpand.c progs/mincextract/mincextract.c progs/mincinfo/mincinfo.c progs/minclookup/minclookup.c progs/mincmakescalar/mincmakescalar.c progs/mincmakevector/mincmakevector.c progs/mincmath/mincmath.c progs/mincresample/mincresample.c progs/mincresample/mincresample.h progs/mincresample/resample_volumes.c progs/mincreshape/copy_data.c progs/mincreshape/mincreshape.c progs/mincreshape/mincreshape.h progs/mincstats/mincstats.c progs/minctoraw/minctoraw.c progs/mincwindow/mincwindow.c progs/rawtominc/rawtominc.c progs/xfm/transformtags.c progs/xfm/xfmconcat.c progs/xfm/xfminvert.c
diffstat 32 files changed, 1035 insertions(+), 699 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-03-16  Bert Vincent <bert@bic.mni.mcgill.ca>
+	* Port other changes from 2.0 branch - new mincconcat bimodal
+	threshold calculations, get rid of minc_def.h for all programs.
+	* Add -dappend and -sappend operations to minc_modify_header on
+	the 1.X branch
+	* Add minctoecat to the 1.X branch	
+	
+2005-02-15  Bert Vincent <bert@bic.mni.mcgill.ca>
+	* Add conversions to the branch
+	* Add simplified interface to the branch
+	
 2004-08-11  Bert Vincent <bert@bic.mni.mcgill.ca>
 	* Fix MI_MAX_IMGDIMS at 100 to avoid netCDF 3.5.1 problem.
 	
--- a/Makefile.am
+++ b/Makefile.am
@@ -62,7 +62,15 @@
 	progs/minccalc/node.h \
 	progs/minccalc/y.tab.h \
 	progs/mincresample/mincresample.h \
-	progs/mincreshape/mincreshape.h
+	progs/mincreshape/mincreshape.h \
+	conversion/ecattominc/ecat_file.h \
+	conversion/ecattominc/machine_indep.h \
+	conversion/ecattominc/ecat_header_definition.h \
+	conversion/minctoecat/ecat_write.h \
+	conversion/minctoecat/machine_indep.h \
+	conversion/nifti1/nifti1.h \
+	conversion/nifti1/nifti1_io.h \
+	conversion/nifti1/nifti1_local.h
 
 # Libraries which must be built and installed.
 #
@@ -105,7 +113,12 @@
 	rawtominc \
 	transformtags \
 	xfmconcat \
-	xfminvert
+	xfminvert \
+	ecattominc \
+	minctoecat \
+	mnc2nii \
+	nii2mnc \
+	upet2mnc
 
 noinst_PROGRAMS = \
 	mincexample1 \
@@ -210,6 +223,28 @@
 
 xfminvert_SOURCES = progs/xfm/xfminvert.c
 
+ecattominc_SOURCES = \
+	conversion/ecattominc/ecattominc.c \
+	conversion/ecattominc/insertblood.c \
+	conversion/ecattominc/ecat_file.c \
+	conversion/ecattominc/machine_indep.c
+
+minctoecat_SOURCES = \
+	conversion/minctoecat/minctoecat.c \
+	conversion/minctoecat/ecat_write.c \
+	conversion/minctoecat/machine_indep.c
+
+nii2mnc_SOURCES = \
+	conversion/nifti1/nii2mnc.c \
+	conversion/nifti1/nifti1_io.c
+
+mnc2nii_SOURCES = \
+	conversion/nifti1/mnc2nii.c \
+	conversion/nifti1/nifti1_io.c
+
+upet2mnc_SOURCES = \
+	conversion/micropet/upet2mnc.c
+
 libminc_la_LDFLAGS = -version-info 1:0:1
 libminc_la_SOURCES = \
 	libsrc/ParseArgv.c \
@@ -293,6 +328,8 @@
 	progs/rawtominc/rawtominc.man1 \
 	progs/xfm/transformtags.man1 \
 	progs/xfm/xfmconcat.man1 \
-	progs/xfm/xfminvert.man1
+	progs/xfm/xfminvert.man1 \
+	conversion/ecattominc/ecattominc.man1 \
+	conversion/minctoecat/minctoecat.man1
 
 dist_man3_MANS = libsrc/ParseArgv.man3
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,12 @@
-                New in Release 1.4
+                New in Release 1.4-test
                 ------------------
 * New support for Windows
 
+* Added conversion programs for ecat, NIfTI-1/Analyze, and microPET
+  formats.
+
+* Added "simplified" MINC programming interface.
+
 	        New in Release 1.3
         	------------------
 
--- a/configure.in
+++ b/configure.in
@@ -1,12 +1,12 @@
 dnl Process this file with autoconf to produce a configure script.
 
-AC_INIT
+AC_INIT(minc, [1.4-test], [bert@bic.mni.mcgill.ca])
 AC_CONFIG_SRCDIR([libsrc/minc.h])
 AC_CONFIG_AUX_DIR(ac_config_aux)
-AM_INIT_AUTOMAKE(minc, 1.4)
+AM_INIT_AUTOMAKE
 AC_CONFIG_HEADERS([config.h])
 
-AC_REVISION($Revision: 6.14.2.2 $)
+AC_REVISION($Revision: 6.14.2.3 $)
 
 AC_PROG_INSTALL
 AC_PROG_LN_S
--- a/libsrc/ParseArgv.c
+++ b/libsrc/ParseArgv.c
@@ -16,13 +16,17 @@
  *
  * This file has been modified to not rely on tcl, tk or X11.
  * Based on tkArgv.c from tk2.3 : 
-static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/ParseArgv.c,v 6.4.2.1 2004-09-28 20:23:39 bert Exp $ SPRITE (Berkeley)";
+static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/ParseArgv.c,v 6.4.2.2 2005-03-16 19:02:49 bert Exp $ SPRITE (Berkeley)";
  *
  * Modifications by Peter Neelin (November 27, 1992)
  */
+#include "config.h"
 #include "minc_private.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <math.h>
-#include "ParseArgv.h"
+#include <ParseArgv.h>
 
 /*
  * Default table of argument descriptors.  These are normally available
--- a/progs/minc_modify_header/minc_modify_header.c
+++ b/progs/minc_modify_header/minc_modify_header.c
@@ -10,11 +10,8 @@
 @CREATED    : March 31, 1995 (Peter Neelin)
 @MODIFIED   : 
  * $Log: minc_modify_header.c,v $
- * Revision 6.9  2004-06-11 15:19:34  bert
- * Fix attribute append operation
- *
- * Revision 6.8  2004/05/25 21:33:51  bert
- * Add -dappend and -sappend
+ * Revision 6.7.2.1  2005-03-16 19:02:49  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.7  2004/02/02 18:27:06  bert
  * Include config.h
@@ -75,7 +72,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/minc_modify_header/minc_modify_header.c,v 6.9 2004-06-11 15:19:34 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/minc_modify_header/minc_modify_header.c,v 6.7.2.1 2005-03-16 19:02:49 bert Exp $";
 #endif
 
 #include "config.h"
@@ -86,7 +83,6 @@
 #include <math.h>
 #include <minc.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #define MINC_EXTENSION ".mnc"
@@ -204,7 +200,7 @@
       if (created_tempfile) {
          if (newfile != NULL) {
             (void) remove(newfile);
-            FREE(newfile);
+            free(newfile);
          }
          (void) fprintf(stderr, "Cannot edit file \"%s\" in place.\n",
                         filename);
@@ -325,8 +321,8 @@
          }
          else if (!done_redef && attribute_exists && (total_length > 0)) {
             if (total_length > alloc_length) {
-               if (zeros != NULL) FREE(zeros);
-               zeros = MALLOC(total_length);
+               if (zeros != NULL) free(zeros);
+               zeros = malloc(total_length);
                alloc_length = total_length;
                for (ival=0; ival < alloc_length; ival++)
                   zeros[ival] = '\0';
@@ -378,8 +374,8 @@
    (void) miclose(mincid);
 
    /* Free stuff */
-   FREE(newfile);
-   if (zeros != NULL) FREE(zeros);
+   free(newfile);
+   if (zeros != NULL) free(zeros);
 
    exit(EXIT_SUCCESS);
 }
@@ -486,7 +482,7 @@
          }
 
          /* Allocate a list */
-         dvalues = MALLOC(sizeof(*dvalues) * num_doubles);
+         dvalues = malloc(sizeof(*dvalues) * num_doubles);
 
          /* Loop over values */
          cur = value;
@@ -528,11 +524,11 @@
       attribute_list_alloc += 10;
       if (attribute_list == NULL) {
          attribute_list = 
-            MALLOC(attribute_list_alloc * sizeof(*attribute_list));
+            malloc(attribute_list_alloc * sizeof(*attribute_list));
       }
       else {
          attribute_list = 
-            REALLOC(attribute_list, 
+            realloc(attribute_list, 
                     attribute_list_alloc * sizeof(*attribute_list));
       }
    }
--- a/progs/mincaverage/mincaverage.c
+++ b/progs/mincaverage/mincaverage.c
@@ -10,7 +10,10 @@
 @CREATED    : April 28, 1995 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincaverage.c,v $
- * Revision 6.4.2.1  2004-09-28 20:22:12  bert
+ * Revision 6.4.2.2  2005-03-16 19:02:49  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.4.2.1  2004/09/28 20:22:12  bert
  * Minor portability fix for Windows
  *
  * Revision 6.4  2001/04/24 13:38:42  neelin
@@ -68,7 +71,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincaverage/mincaverage.c,v 6.4.2.1 2004-09-28 20:22:12 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincaverage/mincaverage.c,v 6.4.2.2 2005-03-16 19:02:49 bert Exp $";
 #endif
 
 #include "config.h"
@@ -82,15 +85,10 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
 /* Constants */
 
-#ifndef public
-#  define public
-#endif
-
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -126,30 +124,29 @@
 } Norm_Data;
 
 /* Function prototypes */
-public int main(int argc, char *argv[]);
-public void do_normalization(void *caller_data, long num_voxels, 
+static void do_normalization(void *caller_data, long num_voxels, 
                              int input_num_buffers, int input_vector_length,
                              double *input_data[],
                              int output_num_buffers, int output_vector_length,
                              double *output_data[],
                              Loop_Info *loop_info);
-public void find_mincfile_range(int mincid, double *minimum, double *maximum);
-public void do_average(void *caller_data, long num_voxels, 
+static void find_mincfile_range(int mincid, double *minimum, double *maximum);
+static void do_average(void *caller_data, long num_voxels, 
                        int input_num_buffers, int input_vector_length,
                        double *input_data[],
                        int output_num_buffers, int output_vector_length,
                        double *output_data[],
                        Loop_Info *loop_info);
-public void start_average(void *caller_data, long num_voxels, 
+static void start_average(void *caller_data, long num_voxels, 
                           int output_num_buffers, int output_vector_length,
                           double *output_data[],
                           Loop_Info *loop_info);
-public void finish_average(void *caller_data, long num_voxels, 
+static void finish_average(void *caller_data, long num_voxels, 
                           int output_num_buffers, int output_vector_length,
                           double *output_data[],
                           Loop_Info *loop_info);
-public int get_double_list(char *dst, char *key, char *nextarg);
-public char **read_file_names(char *filelist, int *num_files);
+static int get_double_list(char *dst, char *key, char *nextarg);
+static char **read_file_names(char *filelist, int *num_files);
 
 /* Argument variables */
 int clobber = FALSE;
@@ -246,7 +243,7 @@
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    char **infiles, *outfiles[2];
    int nfiles, nout;
@@ -361,12 +358,12 @@
       /* Save the weights */
       average_data.num_weights = weights.numvalues;
       average_data.weights = 
-         MALLOC(sizeof(*average_data.weights) * average_data.num_weights);
+         malloc(sizeof(*average_data.weights) * average_data.num_weights);
       for (iweight=0; iweight < average_data.num_weights; iweight++) {
          average_data.weights[iweight] = weights.values[iweight];
       }
 
-      FREE(weights.values);
+      free(weights.values);
    }
 
    /* Check for width weighting */
@@ -414,7 +411,7 @@
          (void) ncdiminq(first_mincid, dim[0], NULL, &count);
          average_data.num_weights = count;
          average_data.weights = 
-            MALLOC(sizeof(*average_data.weights) * average_data.num_weights);
+            malloc(sizeof(*average_data.weights) * average_data.num_weights);
 
          /* Read in the widths */
          start = 0;
@@ -478,9 +475,9 @@
 
    /* Do normalization if needed */
    average_data.norm_factor = 
-      MALLOC(sizeof(*average_data.norm_factor) * nfiles);
+      malloc(sizeof(*average_data.norm_factor) * nfiles);
    if (normalize) {
-      vol_mean = MALLOC(sizeof(*vol_mean) * nfiles);
+      vol_mean = malloc(sizeof(*vol_mean) * nfiles);
       loop_options = create_loop_options();
       set_loop_verbose(loop_options, FALSE);
       set_loop_accumulate(loop_options, TRUE, 0, NULL, NULL);
@@ -538,7 +535,7 @@
                            ifile, average_data.norm_factor[ifile]);
          }
       }
-      FREE(vol_mean);
+      free(vol_mean);
    }
    else {
       for (ifile=0; ifile < nfiles; ifile++) {
@@ -567,8 +564,8 @@
    free_loop_options(loop_options);
 
    /* Free stuff */
-   FREE(average_data.weights);
-   FREE(average_data.norm_factor);
+   free(average_data.weights);
+   free(average_data.norm_factor);
 
    exit(EXIT_SUCCESS);
 }
@@ -586,7 +583,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_normalization(void *caller_data, long num_voxels, 
+static void do_normalization(void *caller_data, long num_voxels, 
                              int input_num_buffers, int input_vector_length,
                              double *input_data[],
                              int output_num_buffers, int output_vector_length,
@@ -640,7 +637,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void find_mincfile_range(int mincid, double *minimum, double *maximum)
+static void find_mincfile_range(int mincid, double *minimum, double *maximum)
 {
    int varid;
    char *varname;
@@ -715,7 +712,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_average(void *caller_data, long num_voxels, 
+static void do_average(void *caller_data, long num_voxels, 
                        int input_num_buffers, int input_vector_length,
                        double *input_data[],
                        int output_num_buffers, int output_vector_length,
@@ -799,7 +796,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void start_average(void *caller_data, long num_voxels, 
+static void start_average(void *caller_data, long num_voxels, 
                           int output_num_buffers, int output_vector_length,
                           double *output_data[],
                           Loop_Info *loop_info)
@@ -842,7 +839,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void finish_average(void *caller_data, long num_voxels, 
+static void finish_average(void *caller_data, long num_voxels, 
                           int output_num_buffers, int output_vector_length,
                           double *output_data[],
                           Loop_Info *loop_info)
@@ -909,7 +906,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_double_list(char *dst, char *key, char *nextarg)
+static int get_double_list(char *dst, char *key, char *nextarg)
 {
 #define VECTOR_SEPARATOR ','
 
@@ -958,11 +955,11 @@
          num_alloc += 20;
          if (double_list == NULL) {
             double_list = 
-               MALLOC(num_alloc * sizeof(*double_list));
+               malloc(num_alloc * sizeof(*double_list));
          }
          else {
             double_list = 
-               REALLOC(double_list, num_alloc * sizeof(*double_list));
+               realloc(double_list, num_alloc * sizeof(*double_list));
          }
       }
       double_list[num_elements-1] = dvalue;
@@ -978,7 +975,7 @@
    /* Update the global variables */
    double_array->numvalues = num_elements;
    if (double_array->values != NULL) {
-      FREE(double_array->values);
+      free(double_array->values);
    }
    double_array->values = double_list;
 
@@ -1000,7 +997,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public char **read_file_names(char *filelist, int *num_files)
+static char **read_file_names(char *filelist, int *num_files)
 {
 #define FILE_NAME_ALLOC_SIZE 10
    char **files;
@@ -1024,7 +1021,7 @@
 
    /* Allocate an initial array and NULL-terminate it */
    array_size = FILE_NAME_ALLOC_SIZE;
-   files = MALLOC(sizeof(*files) * array_size);
+   files = malloc(sizeof(*files) * array_size);
    if (files == NULL) {
       (void) fprintf(stderr, "Error allocating memory\n");
       return NULL;
@@ -1046,7 +1043,7 @@
       /* Make room for names if needed */
       while (nfiles >= array_size-1) {
          array_size += FILE_NAME_ALLOC_SIZE;
-         files = REALLOC(files, sizeof(*files) * array_size);
+         files = realloc(files, sizeof(*files) * array_size);
          if (files == NULL) {
             (void) fprintf(stderr, "Error allocating memory\n");
             return NULL;
--- a/progs/minccalc/minccalc.c
+++ b/progs/minccalc/minccalc.c
@@ -19,7 +19,10 @@
 This is predominately a rehash of mincmath by Peter Neelin
 
  * $Log: minccalc.c,v $
- * Revision 1.8.2.1  2004-06-11 21:36:53  bert
+ * Revision 1.8.2.2  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 1.8.2.1  2004/06/11 21:36:53  bert
  * Fix for nasty bug which causes lots of bogus zero values to be inserted when minccalc is used with a file with a vector_dimension
  *
  * Revision 1.8  2001/05/24 15:08:40  neelin
@@ -66,7 +69,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/minccalc/minccalc.c,v 1.8.2.1 2004-06-11 21:36:53 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/minccalc/minccalc.c,v 1.8.2.2 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -81,13 +84,9 @@
 #include <ParseArgv.h>
 #include <voxel_loop.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include "node.h"
 
 /* Constants */
-#ifndef public
-#  define public
-#endif
 
 #ifndef TRUE
 #  define TRUE 1
@@ -103,14 +102,14 @@
 #define DEFAULT_BOOL -1
 
 /* Function prototypes */
-public void do_math(void *caller_data, long num_voxels, 
+static void do_math(void *caller_data, long num_voxels, 
                     int input_num_buffers, 
                     int input_vector_length, double *input_data[],
                     int output_num_buffers, int output_vector_length,
                     double *output_data[], Loop_Info *loop_info);
-public char **read_file_names(char *filelist, int *num_files);
-public char *read_expression_file(char *filename);
-public int get_list_option(char *dst, char *key, int argc, char **argv);
+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);
 
 /* Argument variables */
 int Output_list_size = 0;
@@ -219,7 +218,7 @@
 scalar_t   *Output_values;
 
 /* Main program */
-public int main(int argc, char *argv[]){
+int main(int argc, char *argv[]){
    char **infiles, **outfiles;
    int nfiles, nout;
    char *arg_string;
@@ -245,7 +244,7 @@
 
    /* Get output file names */
    nout = (Output_list == NULL ? 1 : Output_list_size);
-   outfiles = MALLOC(nout * sizeof(*outfiles));
+   outfiles = malloc(nout * sizeof(*outfiles));
    if (Output_list == NULL) {
       outfiles[0] = argv[argc-1];
    }
@@ -333,7 +332,7 @@
       Output_values = NULL;
    }
    else {
-      Output_values = MALLOC(Output_list_size * sizeof(*Output_values));
+      Output_values = malloc(Output_list_size * sizeof(*Output_values));
       for (i=0; i < Output_list_size; i++) {
          ident = ident_lookup(Output_list[i].symbol);
          scalar = new_scalar(eval_width);
@@ -371,10 +370,10 @@
    /* Clean up */
    vector_free(A);
    sym_leave_scope(rootsym);
-   if (expr_file != NULL) FREE(expression);
-   FREE(outfiles);
-   if (Output_list != NULL) FREE(Output_list);
-   if (Output_values != NULL) FREE(Output_values);
+   if (expr_file != NULL) free(expression);
+   free(outfiles);
+   if (Output_list != NULL) free(Output_list);
+   if (Output_values != NULL) free(Output_values);
    exit(EXIT_SUCCESS);
 }
 
@@ -390,7 +389,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : Thu Dec 21 17:08:40 EST 2000 (Andrew Janke - rotor@cmr.uq.edu.au)
 ---------------------------------------------------------------------------- */
-public void do_math(void *caller_data, long num_voxels, 
+static void do_math(void *caller_data, long num_voxels, 
                     int input_num_buffers, int input_vector_length,
                     double *input_data[],
                     int output_num_buffers, int output_vector_length,
@@ -479,7 +478,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public char **read_file_names(char *filelist, int *num_files)
+static char **read_file_names(char *filelist, int *num_files)
 {
 #define FILE_NAME_ALLOC_SIZE 10
    char **files;
@@ -503,7 +502,7 @@
 
    /* Allocate an initial array and NULL-terminate it */
    array_size = FILE_NAME_ALLOC_SIZE;
-   files = MALLOC(sizeof(*files) * array_size);
+   files = malloc(sizeof(*files) * array_size);
    if (files == NULL) {
       (void) fprintf(stderr, "Error allocating memory\n");
       return NULL;
@@ -525,7 +524,7 @@
       /* Make room for names if needed */
       while (nfiles >= array_size-1) {
          array_size += FILE_NAME_ALLOC_SIZE;
-         files = REALLOC(files, sizeof(*files) * array_size);
+         files = realloc(files, sizeof(*files) * array_size);
          if (files == NULL) {
             (void) fprintf(stderr, "Error allocating memory\n");
             return NULL;
@@ -563,7 +562,7 @@
 @CREATED    : May 3, 2001 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public char *read_expression_file(char *filename)
+static char *read_expression_file(char *filename)
 {
    struct stat statbuf;
    size_t size;
@@ -604,7 +603,7 @@
    if (size == 0) size = ALLOC_SIZE;
 
    /* Get space */
-   expression = MALLOC(size * sizeof(*expression));
+   expression = malloc(size * sizeof(*expression));
 
    /* Read the expression */
    ichar = 0;
@@ -635,7 +634,7 @@
          /* Check whether we need more space */
          if (ichar >= size-1) {
             size += ALLOC_SIZE;
-            expression = REALLOC(expression, size * sizeof(expression));
+            expression = realloc(expression, size * sizeof(expression));
          }
 
          /* Save the character */
@@ -670,7 +669,7 @@
 @CREATED    : May 3, 2001 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_list_option(char *dst, char *key, int argc, char **argv)
+static int get_list_option(char *dst, char *key, int argc, char **argv)
      /* ARGSUSED */
 {
    enum {OPT_OUTPUT_SYMBOL} option_type;
@@ -708,11 +707,11 @@
       *list_alloc += 10;
       if (*list == NULL) {
          *list = 
-            MALLOC(*list_alloc * entry_size);
+            malloc(*list_alloc * entry_size);
       }
       else {
          *list = 
-            REALLOC(*list, 
+            realloc(*list, 
                     *list_alloc * entry_size);
       }
    }
--- a/progs/mincconcat/mincconcat.c
+++ b/progs/mincconcat/mincconcat.c
@@ -11,8 +11,8 @@
 @CREATED    : March 7, 1995 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincconcat.c,v $
- * Revision 6.9  2004-04-27 15:37:13  bert
- * Added -2 flag
+ * Revision 6.8.2.1  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.8  2001/09/18 15:32:39  neelin
  * Create image variable last to allow big images and to fix compatibility
@@ -94,7 +94,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincconcat/mincconcat.c,v 6.9 2004-04-27 15:37:13 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincconcat/mincconcat.c,v 6.8.2.1 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -108,7 +108,6 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
@@ -139,7 +138,7 @@
    char *output_file;
    int num_input_files;
    char *history;
-   int cflags;
+   int clobber;
    int verbose;
    nc_type output_datatype;
    int output_is_signed;
@@ -173,27 +172,26 @@
 } Sort_Element;
 
 /* Function prototypes */
-public int main(int argc, char *argv[]);
-public void get_arginfo(int argc, char *argv[],
+static void get_arginfo(int argc, char *argv[],
                         int *num_input_files, char ***input_files,
                         Concat_Info *concat_info);
-public int get_double_list(char *dst, char *key, char *nextarg);
-public void get_concat_dim_name(Concat_Info *concat_info,
+static int get_double_list(char *dst, char *key, char *nextarg);
+static void get_concat_dim_name(Concat_Info *concat_info,
                                 char *first_filename, int *first_mincid);
-public void get_input_file_info(void *caller_data, int input_mincid,
+static void get_input_file_info(void *caller_data, int input_mincid,
                                 int input_curfile, Loop_Info *loop_info);
-public int get_image_dimension_id(int input_mincid, char *dimension_name);
-public void do_concat(void *caller_data, long num_voxels, 
+static int get_image_dimension_id(int input_mincid, char *dimension_name);
+static void do_concat(void *caller_data, long num_voxels, 
                       int input_num_buffers, int input_vector_length,
                       double *input_data[],
                       int output_num_buffers, int output_vector_length,
                       double *output_data[],
                       Loop_Info *loop_info);
-public void sort_coords(Concat_Info *concat_info);
-public int sort_function(const void *value1, const void *value2);
-public void create_concat_file(int inmincid, Concat_Info *concat_info);
-private void update_history(int mincid, char *arg_string);
-public char **read_file_names(char *filelist, int *num_files);
+static void sort_coords(Concat_Info *concat_info);
+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;
@@ -201,7 +199,7 @@
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    Concat_Info *concat_info;
    Loop_Options *loop_options;
@@ -211,7 +209,7 @@
    double valid_range[2];
 
    /* Allocate the concat_info structure */
-   concat_info = MALLOC(sizeof(*concat_info));
+   concat_info = malloc(sizeof(*concat_info));
 
    /* Get argument information */
    get_arginfo(argc, argv, &num_input_files, &input_files, concat_info);
@@ -263,7 +261,7 @@
 
    /* Free stuff */
    free_loop_options(loop_options);
-   FREE(concat_info);
+   free(concat_info);
 
    exit(EXIT_SUCCESS);
 }
@@ -284,16 +282,13 @@
 @CREATED    : March 11, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_arginfo(int argc, char *argv[],
+static void get_arginfo(int argc, char *argv[],
                         int *num_input_files, char ***input_files,
                         Concat_Info *concat_info)
 {
 
    /* Argument variables */
    static int clobber = FALSE;
-#ifdef MINC2
-   static int minc2_format = FALSE;
-#endif /* MINC2 defined */
    static int verbose = TRUE;
    static nc_type datatype = MI_ORIGINAL_TYPE;
    static int is_signed = INT_MIN;
@@ -312,11 +307,6 @@
    static ArgvInfo argTable[] = {
       {NULL, ARGV_HELP, (char *) NULL, (char *) NULL, 
           "General options:"},
-
-#ifdef MINC2
-      {"-2", ARGV_CONSTANT, (char *) TRUE, (char *) &minc2_format,
-       "Produce a MINC 2.0 format output file"},
-#endif /* MINC2 defined */
       {"-clobber", ARGV_CONSTANT, (char *) TRUE, (char *) &clobber, 
           "Overwrite existing file."},
       {"-noclobber", ARGV_CONSTANT, (char *) FALSE, (char *) &clobber, 
@@ -501,17 +491,7 @@
    concat_info->output_file = output_file;
    concat_info->num_input_files = *num_input_files;
    concat_info->history = history;
-   if (clobber) {
-       concat_info->cflags = NC_CLOBBER;
-   }
-   else {
-       concat_info->cflags = NC_NOCLOBBER;
-   }
-#ifdef MINC2
-   if (minc2_format) {
-       concat_info->cflags |= MI2_CREATE_V2;
-   }
-#endif /* MINC2 defined */
+   concat_info->clobber = clobber;
    concat_info->verbose = verbose;
    concat_info->max_memory_use_in_kb = max_chunk_size_in_kb;
    concat_info->check_dim_info = check_dim_info;
@@ -529,18 +509,18 @@
    /* Fill in coordinate info. We allocate space even if coordinates
       aren't specified just in case we can't get the info from the 
       files. */
-   concat_info->num_file_coords = MALLOC(sizeof(int) * (*num_input_files));
-   concat_info->file_coords = MALLOC(sizeof(void *) * (*num_input_files));
-   concat_info->file_widths = MALLOC(sizeof(void *) * (*num_input_files));
+   concat_info->num_file_coords = malloc(sizeof(int) * (*num_input_files));
+   concat_info->file_coords = malloc(sizeof(void *) * (*num_input_files));
+   concat_info->file_widths = malloc(sizeof(void *) * (*num_input_files));
    for (ifile=0; ifile < *num_input_files; ifile++) {
       concat_info->num_file_coords[ifile] = 1;
-      concat_info->file_coords[ifile] = MALLOC(sizeof(double));
+      concat_info->file_coords[ifile] = malloc(sizeof(double));
       concat_info->file_coords[ifile][0] =
          ((dimension_coords.numvalues > 0) ?
           dimension_coords.values[ifile] : 
           dimension_start + dimension_step * ifile);
       if ((dimension_widths.numvalues > 0) || (dimension_width != DBL_MAX)) {
-         concat_info->file_widths[ifile] = MALLOC(sizeof(double));
+         concat_info->file_widths[ifile] = malloc(sizeof(double));
          concat_info->file_widths[ifile][0] =
             ((dimension_widths.numvalues > 0) ?
              dimension_widths.values[ifile] : dimension_width);
@@ -565,7 +545,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_double_list(char *dst, char *key, char *nextarg)
+static int get_double_list(char *dst, char *key, char *nextarg)
 {
 #define VECTOR_SEPARATOR ','
 
@@ -614,11 +594,11 @@
          num_alloc += 20;
          if (double_list == NULL) {
             double_list = 
-               MALLOC(num_alloc * sizeof(*double_list));
+               malloc(num_alloc * sizeof(*double_list));
          }
          else {
             double_list = 
-               REALLOC(double_list, num_alloc * sizeof(*double_list));
+               realloc(double_list, num_alloc * sizeof(*double_list));
          }
       }
       double_list[num_elements-1] = dvalue;
@@ -634,7 +614,7 @@
    /* Update the global variables */
    double_array->numvalues = num_elements;
    if (double_array->values != NULL) {
-      FREE(double_array->values);
+      free(double_array->values);
    }
    double_array->values = double_list;
 
@@ -655,7 +635,7 @@
 @CREATED    : March 16, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_concat_dim_name(Concat_Info *concat_info,
+static void get_concat_dim_name(Concat_Info *concat_info,
                                 char *first_filename, int *first_mincid)
 {
    char *filename;
@@ -670,7 +650,7 @@
    if (created_tempfile) {
       (void) remove(filename);
    }
-   FREE(filename);
+   free(filename);
    *first_mincid = input_mincid;
 
    /* Do we have to get the dimension name from the file? */
@@ -725,7 +705,7 @@
 @CREATED    : March 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_input_file_info(void *caller_data, int input_mincid,
+static void get_input_file_info(void *caller_data, int input_mincid,
                                 int input_curfile, Loop_Info *loop_info)
 {
    Concat_Info *concat_info;
@@ -757,9 +737,9 @@
       /* Allocate the arrays */
       (void) ncdiminq(input_mincid, dimid, dimname, &dimlength);
       concat_info->num_file_coords[input_curfile] = dimlength;
-      FREE(concat_info->file_coords[input_curfile]);
+      free(concat_info->file_coords[input_curfile]);
       concat_info->file_coords[input_curfile] =
-         MALLOC(sizeof(double) * dimlength);
+         malloc(sizeof(double) * dimlength);
 
       /* Set defaults */
       if (!Sort_sequential || (input_curfile < 1)) {
@@ -846,7 +826,7 @@
 
          /* Allocate space for widths */
          concat_info->file_widths[input_curfile] =
-            MALLOC(sizeof(double) * dimlength);
+            malloc(sizeof(double) * dimlength);
 
          /* Loop through indices, getting values */
          for (index=0; index < dimlength; index++) {
@@ -878,7 +858,7 @@
 @CREATED    : March 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_image_dimension_id(int input_mincid, char *dimension_name)
+static int get_image_dimension_id(int input_mincid, char *dimension_name)
 {
    int dimid, ndims, dim[MAX_VAR_DIMS], idim;
    int found;
@@ -923,7 +903,7 @@
 @CREATED    : March 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_concat(void *caller_data, long num_voxels, 
+static void do_concat(void *caller_data, long num_voxels, 
                       int input_num_buffers, int input_vector_length,
                       double *input_data[],
                       int output_num_buffers, int output_vector_length,
@@ -1058,7 +1038,7 @@
 @CREATED    : March 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void sort_coords(Concat_Info *concat_info)
+static void sort_coords(Concat_Info *concat_info)
 {
    int ifile;
    Sort_Element *sort_list;
@@ -1069,17 +1049,17 @@
 
    /* Allocate space for the ordering information */
    concat_info->file_to_dim_order = 
-      MALLOC(sizeof(void *) * (concat_info->num_input_files));
+      malloc(sizeof(void *) * (concat_info->num_input_files));
    concat_dimension_length = 0;
    for (ifile=0; ifile < concat_info->num_input_files; ifile++) {
       concat_dimension_length += concat_info->num_file_coords[ifile];
       concat_info->file_to_dim_order[ifile] = 
-         MALLOC(sizeof(int) * concat_info->num_file_coords[ifile]);
+         malloc(sizeof(int) * concat_info->num_file_coords[ifile]);
    }
    concat_info->concat_dimension_length = concat_dimension_length;
 
    /* Set up sorting stuff */
-   sort_list = MALLOC(sizeof(Sort_Element) * concat_dimension_length);
+   sort_list = malloc(sizeof(Sort_Element) * concat_dimension_length);
    index = 0;
    for (ifile=0; ifile < concat_info->num_input_files; ifile++) {
       for (icoord=0; icoord < concat_info->num_file_coords[ifile]; icoord++) {
@@ -1154,7 +1134,7 @@
 @CREATED    : March 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int sort_function(const void *value1, const void *value2)
+static int sort_function(const void *value1, const void *value2)
 {
    Sort_Element *element1, *element2;
    int return_value;
@@ -1189,7 +1169,7 @@
 @CREATED    : March 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void create_concat_file(int inmincid, Concat_Info *concat_info)
+static void create_concat_file(int inmincid, Concat_Info *concat_info)
 {
    int outmincid, outimgid, inimgid, coordid, widthid, invarid;
    int maxid, minid, icvid;
@@ -1202,7 +1182,8 @@
    double valid_range[2];
 
    /* Create the file */
-   outmincid = micreate(concat_info->output_file, concat_info->cflags);
+   outmincid = micreate(concat_info->output_file,
+                        (concat_info->clobber ? NC_CLOBBER : NC_NOCLOBBER));
 
    /* Get image variable id for input file */
    inimgid = ncvarid(inmincid, MIimage);
@@ -1393,7 +1374,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-private void update_history(int mincid, char *arg_string)
+static void update_history(int mincid, char *arg_string)
 {
    nc_type datatype;
    int att_length;
@@ -1408,7 +1389,7 @@
    att_length += strlen(arg_string) + 1;
 
    /* Allocate a string and get the old history */
-   string = MALLOC(att_length);
+   string = malloc(att_length);
    string[0] = '\0';
    (void) miattgetstr(mincid, NC_GLOBAL, MIhistory, att_length, 
                       string);
@@ -1417,7 +1398,7 @@
    /* Add the new command and put the new history. */
    (void) strcat(string, arg_string);
    (void) miattputstr(mincid, NC_GLOBAL, MIhistory, string);
-   FREE(string);
+   free(string);
 
 }
 
@@ -1436,7 +1417,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public char **read_file_names(char *filelist, int *num_files)
+static char **read_file_names(char *filelist, int *num_files)
 {
 #define FILE_NAME_ALLOC_SIZE 10
    char **files;
@@ -1460,7 +1441,7 @@
 
    /* Allocate an initial array and NULL-terminate it */
    array_size = FILE_NAME_ALLOC_SIZE;
-   files = MALLOC(sizeof(*files) * array_size);
+   files = malloc(sizeof(*files) * array_size);
    if (files == NULL) {
       (void) fprintf(stderr, "Error allocating memory\n");
       return NULL;
@@ -1482,7 +1463,7 @@
       /* Make room for names if needed */
       while (nfiles >= array_size-1) {
          array_size += FILE_NAME_ALLOC_SIZE;
-         files = REALLOC(files, sizeof(*files) * array_size);
+         files = realloc(files, sizeof(*files) * array_size);
          if (files == NULL) {
             (void) fprintf(stderr, "Error allocating memory\n");
             return NULL;
--- a/progs/minccopy/minccopy.c
+++ b/progs/minccopy/minccopy.c
@@ -11,7 +11,10 @@
 @CREATED    : May 13, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: minccopy.c,v $
- * Revision 6.1  1999-10-19 14:45:20  neelin
+ * Revision 6.1.2.1  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.1  1999/10/19 14:45:20  neelin
  * Fixed Log subsitutions for CVS
  *
  * Revision 6.0  1997/09/12 13:23:34  neelin
@@ -51,7 +54,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/minccopy/minccopy.c,v 6.1 1999-10-19 14:45:20 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/minccopy/minccopy.c,v 6.1.2.1 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -59,7 +62,6 @@
 #include <string.h>
 #include <minc.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
@@ -155,7 +157,7 @@
    }
 
    /* Allocate space */
-   data = MALLOC(size);
+   data = malloc(size);
 
    /* Set up image conversion */
    if (!copy_pixel_values) {
@@ -203,7 +205,7 @@
       (void) miicv_free(outicv);
       (void) miicv_free(inicv);
    }
-   FREE(data);
+   free(data);
 
    exit(EXIT_SUCCESS);
 }
--- a/progs/mincexample/mincexample1.c
+++ b/progs/mincexample/mincexample1.c
@@ -10,7 +10,10 @@
 @CREATED    : August 24, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincexample1.c,v $
- * Revision 6.4  2001-09-18 15:32:46  neelin
+ * Revision 6.4.2.1  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.4  2001/09/18 15:32:46  neelin
  * Create image variable last to allow big images and to fix compatibility
  * problems with 2.3 and 3.x.
  *
@@ -72,7 +75,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample1.c,v 6.4 2001-09-18 15:32:46 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample1.c,v 6.4.2.1 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -81,22 +84,7 @@
 #include <minc.h>
 #include <time_stamp.h>
 
-/* Include the standard minc definitions for cross-platform compilation
-   if we are compiling the package, otherwise, just define MALLOC,
-   FREE, EXIT_SUCCESS and EXIT_FAILURE */
-#ifdef COMPILING_MINC_PACKAGE
-#  include <minc_def.h>
-#else
-#  define MALLOC(size) ((void *) malloc(size))
-#  define FREE(ptr) free(ptr)
-#  ifndef EXIT_SUCCESS
-#    define EXIT_SUCCESS 0
-#    define EXIT_FAILURE 1
-#  endif
-#endif
-
 /* Constants */
-#define public
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -126,22 +114,22 @@
 } Volume;
 
 /* Function prototypes */
-public void load_volume(char *infile, Volume *volume);
-public void get_dimension_info(char *infile, int icvid, Volume *volume);
-public void setup_icv(int icvid);
-public void read_volume_data(int icvid, Volume *volume);
-public void save_volume(char *infile, char *outfile, char *arg_string, 
+static void load_volume(char *infile, Volume *volume);
+static void get_dimension_info(char *infile, int icvid, Volume *volume);
+static void setup_icv(int icvid);
+static void read_volume_data(int icvid, Volume *volume);
+static void save_volume(char *infile, char *outfile, char *arg_string, 
                         Volume *volume);
-public void setup_variables(int inmincid, int mincid, Volume *volume, 
+static void setup_variables(int inmincid, int mincid, Volume *volume, 
                             char *arg_string);
-public void setup_image_variables(int inmincid, int mincid, 
+static void setup_image_variables(int inmincid, int mincid, 
                                   int ndims, int dim[]);
-public void update_history(int mincid, char *arg_string);
-public void write_volume_data(int icvid, Volume *volume);
+static void update_history(int mincid, char *arg_string);
+static void write_volume_data(int icvid, Volume *volume);
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    char *infile, *outfile;
    Volume volume;
@@ -195,7 +183,7 @@
 @CREATED    : August 22, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void load_volume(char *infile, Volume *volume)
+static void load_volume(char *infile, Volume *volume)
 {
    int icvid, mincid;
 
@@ -233,7 +221,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_icv(int icvid)
+static void setup_icv(int icvid)
 {
    /* Set desired type */
    (void) miicv_setint(icvid, MI_ICV_TYPE, NC_BYTE);
@@ -274,7 +262,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_dimension_info(char *infile, int icvid, Volume *volume)
+static void get_dimension_info(char *infile, int icvid, Volume *volume)
 {
    int mincid, imgid, varid;
    int idim, ndims;
@@ -354,7 +342,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void read_volume_data(int icvid, Volume *volume)
+static void read_volume_data(int icvid, Volume *volume)
 {
    long start[MAX_VAR_DIMS], count[MAX_VAR_DIMS];
 
@@ -365,7 +353,7 @@
    count[2] = volume->ncolumns;
 
    /* Allocate space for the data */
-   volume->data = MALLOC(sizeof(*volume->data) *
+   volume->data = malloc(sizeof(*volume->data) *
                          volume->ncolumns * volume->nrows *
                          volume->nslices);
 
@@ -394,7 +382,7 @@
 @CREATED    : August 22, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void save_volume(char *infile, char *outfile, char *arg_string, 
+static void save_volume(char *infile, char *outfile, char *arg_string, 
                         Volume *volume)
 {
    int mincid, icvid, inmincid;
@@ -449,7 +437,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_variables(int inmincid, int mincid, Volume *volume, 
+static void setup_variables(int inmincid, int mincid, Volume *volume, 
                             char *arg_string)
 {
    int dim[MAX_VAR_DIMS], ndims, idim, varid;
@@ -534,7 +522,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_image_variables(int inmincid, int mincid, 
+static void setup_image_variables(int inmincid, int mincid, 
                                   int ndims, int dim[])
 {
    int imgid, maxid, minid;
@@ -580,7 +568,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void update_history(int mincid, char *arg_string)
+static void update_history(int mincid, char *arg_string)
 {
    nc_type datatype;
    int att_length;
@@ -595,7 +583,7 @@
    att_length += strlen(arg_string) + 1;
 
    /* Allocate a string and get the old history */
-   string = MALLOC(att_length);
+   string = malloc(att_length);
    string[0] = '\0';
    (void) miattgetstr(mincid, NC_GLOBAL, MIhistory, att_length, 
                       string);
@@ -604,7 +592,7 @@
    /* Add the new command and put the new history. */
    (void) strcat(string, arg_string);
    (void) miattputstr(mincid, NC_GLOBAL, MIhistory, string);
-   FREE(string);
+   free(string);
 
 }
 
@@ -621,7 +609,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void write_volume_data(int icvid, Volume *volume)
+static void write_volume_data(int icvid, Volume *volume)
 {
    int mincid;
    long start[MAX_VAR_DIMS], count[MAX_VAR_DIMS];
@@ -645,7 +633,7 @@
    (void) miicv_put(icvid, start, count, volume->data);
 
    /* Free space for the data */
-   FREE(volume->data);
+   free(volume->data);
 
 }
 
--- a/progs/mincexample/mincexample2.c
+++ b/progs/mincexample/mincexample2.c
@@ -12,7 +12,10 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincexample2.c,v $
- * Revision 6.4  2001-09-18 15:32:46  neelin
+ * Revision 6.4.2.1  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.4  2001/09/18 15:32:46  neelin
  * Create image variable last to allow big images and to fix compatibility
  * problems with 2.3 and 3.x.
  *
@@ -60,7 +63,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample2.c,v 6.4 2001-09-18 15:32:46 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexample/mincexample2.c,v 6.4.2.1 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -69,22 +72,7 @@
 #include <minc.h>
 #include <time_stamp.h>
 
-/* Include the standard minc definitions for cross-platform compilation
-   if we are compiling the package, otherwise, just define MALLOC,
-   FREE, EXIT_SUCCESS and EXIT_FAILURE */
-#ifdef COMPILING_MINC_PACKAGE
-#  include <minc_def.h>
-#else
-#  define MALLOC(size) ((void *) malloc(size))
-#  define FREE(ptr) free(ptr)
-#  ifndef EXIT_SUCCESS
-#    define EXIT_SUCCESS 0
-#    define EXIT_FAILURE 1
-#  endif
-#endif
-
 /* Constants */
-#define public
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -113,29 +101,29 @@
 } Volume_Info;
 
 /* Function prototypes */
-public int get_volume_info(char *infile, Volume_Info *volume_info);
-public void setup_input_icv(int icvid);
-public void get_dimension_info(char *infile, int icvid, 
+static int get_volume_info(char *infile, Volume_Info *volume_info);
+static void setup_input_icv(int icvid);
+static void get_dimension_info(char *infile, int icvid, 
                                Volume_Info *volume_info);
-public void close_volume(int icvid);
-public void get_volume_slice(int icvid, Volume_Info *volume_info, 
+static void close_volume(int icvid);
+static void get_volume_slice(int icvid, Volume_Info *volume_info, 
                              int slice_num, unsigned char *image);
-public int save_volume_info(int input_icvid, char *outfile, char *arg_string, 
+static int save_volume_info(int input_icvid, char *outfile, char *arg_string, 
                             Volume_Info *volume_info);
-public void setup_output_icv(int icvid);
-public void setup_variables(int inmincid, int mincid, 
+static void setup_output_icv(int icvid);
+static void setup_variables(int inmincid, int mincid, 
                             Volume_Info *volume_info, 
                             char *arg_string);
-public void setup_image_variables(int inmincid, int mincid, 
+static void setup_image_variables(int inmincid, int mincid, 
                                   int ndims, int dim[]);
-public void update_history(int mincid, char *arg_string);
-public void save_volume_slice(int icvid, Volume_Info *volume_info, 
+static void update_history(int mincid, char *arg_string);
+static void save_volume_slice(int icvid, Volume_Info *volume_info, 
                               int slice_num, unsigned char *image,
                               double slice_min, double slice_max);
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    char *infile, *outfile;
    Volume_Info volume_info;
@@ -181,7 +169,7 @@
                                    &volume_info);
 
    /* Loop through slices, copying them */
-   image = MALLOC(volume_info.nrows * volume_info.ncolumns * sizeof(*image));
+   image = malloc(volume_info.nrows * volume_info.ncolumns * sizeof(*image));
    for (islice=0; islice < volume_info.nslices; islice++) {
       get_volume_slice(input_icvid, &volume_info, islice, image);
       save_volume_slice(output_icvid, &volume_info, islice, image,
@@ -191,7 +179,7 @@
    /* Free up image and close files */
    close_volume(input_icvid);
    close_volume(output_icvid);
-   FREE(image);
+   free(image);
 
    exit(EXIT_SUCCESS);
 }
@@ -208,7 +196,7 @@
 @CREATED    : August 22, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_volume_info(char *infile, Volume_Info *volume_info)
+static int get_volume_info(char *infile, Volume_Info *volume_info)
 {
    int icvid, mincid;
 
@@ -244,7 +232,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_input_icv(int icvid)
+static void setup_input_icv(int icvid)
 {
    /* Set desired type */
    (void) miicv_setint(icvid, MI_ICV_TYPE, NC_BYTE);
@@ -286,7 +274,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_dimension_info(char *infile, int icvid, 
+static void get_dimension_info(char *infile, int icvid, 
                                Volume_Info *volume_info)
 {
    int mincid, imgid, varid;
@@ -384,7 +372,7 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void close_volume(int icvid)
+static void close_volume(int icvid)
 {
    int mincid;
 
@@ -414,7 +402,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_volume_slice(int icvid, Volume_Info *volume_info, 
+static void get_volume_slice(int icvid, Volume_Info *volume_info, 
                              int slice_num, unsigned char *image)
 {
    long start[MAX_VAR_DIMS], count[MAX_VAR_DIMS];
@@ -461,7 +449,7 @@
 @CREATED    : August 22, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int save_volume_info(int input_icvid, char *outfile, char *arg_string, 
+static int save_volume_info(int input_icvid, char *outfile, char *arg_string, 
                             Volume_Info *volume_info)
 {
    int mincid, icvid, inmincid;
@@ -500,7 +488,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_output_icv(int icvid)
+static void setup_output_icv(int icvid)
 {
    /* Set desired type */
    (void) miicv_setint(icvid, MI_ICV_TYPE, NC_BYTE);
@@ -530,7 +518,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_variables(int inmincid, int mincid, 
+static void setup_variables(int inmincid, int mincid, 
                             Volume_Info *volume_info, 
                             char *arg_string)
 {
@@ -619,7 +607,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_image_variables(int inmincid, int mincid, 
+static void setup_image_variables(int inmincid, int mincid, 
                                   int ndims, int dim[])
 {
    int imgid, maxid, minid;
@@ -665,7 +653,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void update_history(int mincid, char *arg_string)
+static void update_history(int mincid, char *arg_string)
 {
    nc_type datatype;
    int att_length;
@@ -680,7 +668,7 @@
    att_length += strlen(arg_string) + 1;
 
    /* Allocate a string and get the old history */
-   string = MALLOC(att_length);
+   string = malloc(att_length);
    string[0] = '\0';
    (void) miattgetstr(mincid, NC_GLOBAL, MIhistory, att_length, 
                       string);
@@ -689,7 +677,7 @@
    /* Add the new command and put the new history. */
    (void) strcat(string, arg_string);
    (void) miattputstr(mincid, NC_GLOBAL, MIhistory, string);
-   FREE(string);
+   free(string);
 
 }
 
@@ -711,7 +699,7 @@
 @CREATED    : August 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void save_volume_slice(int icvid, Volume_Info *volume_info, 
+static void save_volume_slice(int icvid, Volume_Info *volume_info, 
                               int slice_num, unsigned char *image,
                               double slice_min, double slice_max)
 {
--- a/progs/mincexpand/mincexpand.c
+++ b/progs/mincexpand/mincexpand.c
@@ -10,7 +10,10 @@
 @CREATED    : January 20, 1995 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincexpand.c,v $
- * Revision 6.1  1999-10-19 14:45:22  neelin
+ * Revision 6.1.2.1  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.1  1999/10/19 14:45:22  neelin
  * Fixed Log subsitutions for CVS
  *
  * Revision 6.0  1997/09/12 13:24:16  neelin
@@ -50,7 +53,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexpand/mincexpand.c,v 6.1 1999-10-19 14:45:22 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincexpand/mincexpand.c,v 6.1.2.1 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -58,7 +61,6 @@
 #include <string.h>
 #include <minc.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
@@ -122,7 +124,7 @@
    }
 
    /* Free the temporary file name string */
-   FREE(newfile);
+   free(newfile);
 
    exit(EXIT_SUCCESS);
 }
--- a/progs/mincextract/mincextract.c
+++ b/progs/mincextract/mincextract.c
@@ -10,7 +10,10 @@
 @CREATED    : June 10, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincextract.c,v $
- * Revision 6.4  2003-10-28 20:31:19  bert
+ * Revision 6.4.2.1  2005-03-16 19:02:50  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.4  2003/10/28 20:31:19  bert
  * Remove two unused variables
  *
  * Revision 6.3  2001/08/16 16:41:35  neelin
@@ -85,7 +88,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincextract/mincextract.c,v 6.4 2003-10-28 20:31:19 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincextract/mincextract.c,v 6.4.2.1 2005-03-16 19:02:50 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -96,17 +99,12 @@
 #include <float.h>
 #include <ctype.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
 #endif
-#ifndef public
-#  define public
-#  define private static
-#endif
 #define VECTOR_SEPARATOR ','
 #define TYPE_ASCII  0
 #define TYPE_BYTE   1
@@ -120,7 +118,7 @@
 };
 
 /* Function declarations */
-public int get_arg_vector(char *dst, char *key, char *nextArg);
+static int get_arg_vector(char *dst, char *key, char *nextArg);
 
 /* Variables used for argument parsing */
 int arg_odatatype = TYPE_ASCII;
@@ -374,7 +372,7 @@
    element_size = nctypelen(output_datatype);
 
    /* Allocate space */
-   data = MALLOC(element_size*nelements);
+   data = malloc(element_size*nelements);
 
    /* Loop over input slices */
 
@@ -412,7 +410,7 @@
    /* Clean up */
    (void) miclose(mincid);
    (void) miicv_free(icvid);
-   FREE(data);
+   free(data);
 
    exit(EXIT_SUCCESS);
 }
@@ -433,7 +431,7 @@
 @CREATED    : June 10, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_arg_vector(char *dst, char *key, char *nextArg)
+static int get_arg_vector(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
 
--- a/progs/mincinfo/mincinfo.c
+++ b/progs/mincinfo/mincinfo.c
@@ -10,7 +10,10 @@
 @CREATED    : May 19, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincinfo.c,v $
- * Revision 6.4  2001-10-31 19:40:21  neelin
+ * Revision 6.4.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.4  2001/10/31 19:40:21  neelin
  * Fixed bug in printing of sign for default output - this was introduced
  * in the change to miget_datatype.
  *
@@ -79,7 +82,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincinfo/mincinfo.c,v 6.4 2001-10-31 19:40:21 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincinfo/mincinfo.c,v 6.4.2.1 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -89,10 +92,8 @@
 #include <float.h>
 #include <minc.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
-#define public
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -124,12 +125,11 @@
 #define RTN_ERR(code) if ((code) == MI_ERROR) {return MI_ERROR;}
 
 /* Function prototypes */
-public int main(int argc, char *argv[]);
-public int process_file( char* filename, int header_only );
-public int get_option(char *dst, char *key, char *nextarg);
-public int report_error(void);
-public int get_attname(int mincid, char *string, int *varid, char *name);
-public int print_image_info(char *filename, int mincid);
+static int process_file( char* filename, int header_only );
+static int get_option(char *dst, char *key, char *nextarg);
+static int report_error(void);
+static int get_attname(int mincid, char *string, int *varid, char *name);
+static int print_image_info(char *filename, int mincid);
 /* Variables used for argument parsing */
 char *error_string = NULL;
 Option_type option_list[MAX_NUM_OPTIONS] = {ENDLIST};
@@ -164,7 +164,7 @@
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    int ioption, ifile, header_only;
    int ret_value = EXIT_SUCCESS;
@@ -224,7 +224,7 @@
 @CREATED    : April 25, 2000 (Steve Robbins)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int process_file( char* filename, int header_only )
+static int process_file( char* filename, int header_only )
 {
    int mincid, varid, dimid;
    int ndims, dims[MAX_VAR_DIMS];
@@ -330,23 +330,23 @@
                row_length = length;
          }
          if (datatype==NC_CHAR) {
-            cdata = MALLOC(var_length*sizeof(char));
+            cdata = malloc(var_length*sizeof(char));
             CHK_ERR(ncvarget(mincid, varid, start, count, cdata));
             for (ival=0; ival<var_length; ival++) {
                (void) putchar((int) cdata[ival]);
                if (((ival+1) % row_length) == 0)
                   (void) putchar((int)'\n');
             }
-            FREE(cdata);
+            free(cdata);
          }
          else {
-            ddata = MALLOC(var_length*sizeof(double));
+            ddata = malloc(var_length*sizeof(double));
             CHK_ERR(mivarget(mincid, varid, start, count, 
                              NC_DOUBLE, NULL, ddata));
             for (ival=0; ival<var_length; ival++) {
                (void) printf("%.20g\n", ddata[ival]);
             }
-            FREE(ddata);
+            free(ddata);
          }
          break;
       case ATTTYPE:
@@ -358,21 +358,21 @@
          CHK_ERR(get_attname(mincid, string, &varid, name));
          CHK_ERR(ncattinq(mincid, varid, name, &datatype, &att_length));
          if (datatype == NC_CHAR) {
-            cdata = MALLOC((att_length+1)*sizeof(char));
+            cdata = malloc((att_length+1)*sizeof(char));
             if (miattgetstr(mincid, varid, name, att_length+1, cdata)==NULL)
                {REPORT_ERROR}
             (void) printf("%s\n", cdata);
-            FREE(cdata);
+            free(cdata);
          }
          else {
-            ddata = MALLOC(att_length * sizeof(double));
+            ddata = malloc(att_length * sizeof(double));
             CHK_ERR(miattget(mincid, varid, name, NC_DOUBLE, att_length,
                              ddata, NULL));
             for (iatt=0; iatt<att_length; iatt++) {
                (void) printf("%.20g ", ddata[iatt]);
             }
             (void) printf("\n");
-            FREE(ddata);
+            free(ddata);
          }
          break;
       default:
@@ -402,7 +402,7 @@
 @CREATED    : May 19, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_option(char *dst, char *key, char *nextarg)
+static int get_option(char *dst, char *key, char *nextarg)
      /* ARGSUSED */
 {
    Option_code code;
@@ -454,7 +454,7 @@
 @CREATED    : May 19, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int report_error(void)
+static int report_error(void)
 {
    if (error_string == NULL) {
       (void) fprintf(stderr, "Error reading file.\n");
@@ -481,7 +481,7 @@
 @CREATED    : May 19, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_attname(int mincid, char *string, int *varid, char *name)
+static int get_attname(int mincid, char *string, int *varid, char *name)
 {
 
 #define ATT_SEP_CHAR ':'
@@ -530,7 +530,7 @@
 @CREATED    : May 19, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int print_image_info(char *filename, int mincid)
+static int print_image_info(char *filename, int mincid)
 {
    int imgid, ndims, dim[MAX_VAR_DIMS], varid;
    nc_type datatype;
--- a/progs/minclookup/minclookup.c
+++ b/progs/minclookup/minclookup.c
@@ -11,7 +11,10 @@
 @CREATED    : December 6, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: minclookup.c,v $
- * Revision 6.3.2.1  2004-09-28 20:08:14  bert
+ * Revision 6.3.2.2  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.3.2.1  2004/09/28 20:08:14  bert
  * Minor portability fix for Windows
  *
  * Revision 6.3  2001/04/24 13:38:43  neelin
@@ -66,7 +69,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/minclookup/minclookup.c,v 6.3.2.1 2004-09-28 20:08:14 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/minclookup/minclookup.c,v 6.3.2.2 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include "config.h"
@@ -79,13 +82,8 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
-#ifndef public
-#  define public
-#endif
-
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -121,21 +119,21 @@
 } Sort_Key;
 
 /* Function prototypes */
-public Lookup_Table *read_lookup_table(char *lookup_file, char *lookup_string);
-public double *get_values_from_string(char *string, int array_size,
+static Lookup_Table *read_lookup_table(char *lookup_file, char *lookup_string);
+static double *get_values_from_string(char *string, int array_size,
                                       double *array, int *nread);
-public double *get_null_value(int vector_length, char *null_value_string);
-public void get_full_range(int mincid, double lookup_range[2]);
-public void do_lookup(void *caller_data, long num_voxels,
+static double *get_null_value(int vector_length, char *null_value_string);
+static void get_full_range(int mincid, double lookup_range[2]);
+static void do_lookup(void *caller_data, long num_voxels,
                       int input_num_buffers, int input_vector_length,
                       double *input_data[],
                       int output_num_buffers, int output_vector_length,
                       double *output_data[], Loop_Info *loop_info);
-public void lookup_in_table(double index, Lookup_Table *lookup_table,
+static void lookup_in_table(double index, Lookup_Table *lookup_table,
                             int discrete_values, double null_value[],
                             double output_value[]);
-private char *get_next_line(char *line, int linelen, FILE *fp, char **string);
-private int sorting_function(const void *value1, const void *value2);
+static char *get_next_line(char *line, int linelen, FILE *fp, char **string);
+static int sorting_function(const void *value1, const void *value2);
 
 /* Lookup tables */
 static double gray_lookup_values[] = {
@@ -352,10 +350,10 @@
               do_lookup, (void *) &lookup_data);
 
    /* Free stuff */
-   if (lookup_data.null_value != NULL) FREE(lookup_data.null_value);
+   if (lookup_data.null_value != NULL) free(lookup_data.null_value);
    if (lookup_data.lookup_table->free_data) {
-      FREE(lookup_data.lookup_table->table);
-      FREE(lookup_data.lookup_table);
+      free(lookup_data.lookup_table->table);
+      free(lookup_data.lookup_table);
    }
 
    exit(EXIT_SUCCESS);
@@ -377,7 +375,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public Lookup_Table *read_lookup_table(char *lookup_filename, 
+static Lookup_Table *read_lookup_table(char *lookup_filename, 
                                        char *lookup_string)
 {
    Lookup_Table *lookup_table;
@@ -424,10 +422,10 @@
    row = get_values_from_string(line, 0, NULL, &table_nvalues);
    if (table_nvalues < 2) {
       (void) fprintf(stderr, "First line has fewer than 2 values.\n");
-      if (row != NULL) FREE(row);
+      if (row != NULL) free(row);
       exit(EXIT_FAILURE);
    }
-   table = MALLOC(sizeof(*table) * table_nvalues);
+   table = malloc(sizeof(*table) * table_nvalues);
    for (ivalue=0; ivalue < table_nvalues; ivalue++)
       table[ivalue] = row[ivalue];
    nentries++;
@@ -438,11 +436,11 @@
          (void) fprintf(stderr, 
                         "Wrong number of values on line %d.\n",
                         nentries+1);
-         FREE(row);
-         FREE(table);
+         free(row);
+         free(table);
          exit(EXIT_FAILURE);
       }
-      table = REALLOC(table, sizeof(*table) * table_nvalues * (nentries+1));
+      table = realloc(table, sizeof(*table) * table_nvalues * (nentries+1));
       for (ivalue=0; ivalue < table_nvalues; ivalue++) {
          table[ivalue + nentries*table_nvalues] = row[ivalue];
       }
@@ -464,7 +462,7 @@
    if (need_sort) {
 
       /* Set up sorting table */
-      sort_table = MALLOC(sizeof(*sort_table) * nentries);
+      sort_table = malloc(sizeof(*sort_table) * nentries);
       for (ientry=0; ientry < nentries; ientry++) {
          sort_table[ientry].key = table[ientry*table_nvalues];
          sort_table[ientry].index = ientry;
@@ -475,7 +473,7 @@
             sorting_function);
 
       /* Copy the table */
-      new_table = MALLOC(sizeof(*table) * table_nvalues * nentries);
+      new_table = malloc(sizeof(*table) * table_nvalues * nentries);
       for (ientry=0; ientry < nentries; ientry++) {
          new_offset = ientry * table_nvalues;
          old_offset = sort_table[ientry].index * table_nvalues;
@@ -483,13 +481,13 @@
             new_table[new_offset + ivalue] = table[old_offset + ivalue];
          }
       }
-      FREE(table);
+      free(table);
       table = new_table;
-      FREE(sort_table);
+      free(sort_table);
    }
 
    /* Allocate space for the lookup table and set initial values */
-   lookup_table = MALLOC(sizeof(*lookup_table));
+   lookup_table = malloc(sizeof(*lookup_table));
    lookup_table->free_data = TRUE;
    lookup_table->nentries = nentries;
    lookup_table->vector_length = table_nvalues - 1;
@@ -516,7 +514,7 @@
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
 #define LOOKUP_LINE_SEPARATOR ';'
-private char *get_next_line(char *line, int linelen, FILE *fp, char **string)
+static char *get_next_line(char *line, int linelen, FILE *fp, char **string)
 {
    int count;
 
@@ -568,7 +566,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-private int sorting_function(const void *value1, const void *value2)
+static int sorting_function(const void *value1, const void *value2)
 {
    Sort_Key *key1, *key2;
 
@@ -606,7 +604,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public double *get_values_from_string(char *string, int array_size,
+static double *get_values_from_string(char *string, int array_size,
                                       double *array, int *nread)
 {
 #define VECTOR_SEPARATOR ','
@@ -639,7 +637,7 @@
       if (cur == prev) {
          *nread = 0;
          if (array_size <= 0 && array != NULL) {
-            FREE(array);
+            free(array);
          }
          return NULL;
       }
@@ -650,10 +648,10 @@
          if (array_size <= 0) {
             num_alloc += 1;
             if (array == NULL) {
-               array = MALLOC(num_alloc * sizeof(*array));
+               array = malloc(num_alloc * sizeof(*array));
             }
             else {
-               array = REALLOC(array, num_alloc * sizeof(*array));
+               array = realloc(array, num_alloc * sizeof(*array));
             }
          }
          else {
@@ -690,7 +688,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public double *get_null_value(int vector_length, char *string)
+static double *get_null_value(int vector_length, char *string)
 {
    int num_read;
    double *values;
@@ -703,7 +701,7 @@
 
    /* Check the number of values read */
    if (num_read != vector_length) {
-      if (values != NULL) FREE(values);
+      if (values != NULL) free(values);
       (void) fprintf(stderr, 
                      "Null value does not match lookup table (%d values).\n",
                      num_read);
@@ -725,7 +723,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_full_range(int mincid, double range[2])
+static void get_full_range(int mincid, double range[2])
 {
    char *string;
    int varid;
@@ -762,7 +760,7 @@
             num_values *= length;
          }
          if (num_values > 0) {
-            values = MALLOC(num_values * sizeof(*values));
+            values = malloc(num_values * sizeof(*values));
             (void) mivarget(mincid, varid, start, count, 
                             NC_DOUBLE, NULL, values);
             *extreme = values[0];
@@ -770,7 +768,7 @@
                if ((values[ivalue] * sign) > (*extreme * sign))
                   *extreme = values[ivalue];
             }
-            FREE(values);
+            free(values);
          }
 
       }          /* If variable is found */
@@ -802,7 +800,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_lookup(void *caller_data, long num_voxels,
+static void do_lookup(void *caller_data, long num_voxels,
                       int input_num_buffers, int input_vector_length,
                       double *input_data[],
                       int output_num_buffers, int output_vector_length,
@@ -883,7 +881,7 @@
 @CREATED    : December 8, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void lookup_in_table(double index, Lookup_Table *lookup_table,
+static void lookup_in_table(double index, Lookup_Table *lookup_table,
                             int discrete_values, double null_value[],
                             double output_value[])
 {
--- a/progs/mincmakescalar/mincmakescalar.c
+++ b/progs/mincmakescalar/mincmakescalar.c
@@ -10,7 +10,10 @@
 @CREATED    : August 7, 1997 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincmakescalar.c,v $
- * Revision 6.3.2.1  2005-01-25 21:01:52  bert
+ * Revision 6.3.2.2  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.3.2.1  2005/01/25 21:01:52  bert
  * Check for proper placement of vector_dimension
  *
  * Revision 6.3  2001/04/24 13:38:43  neelin
@@ -40,7 +43,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincmakescalar/mincmakescalar.c,v 6.3.2.1 2005-01-25 21:01:52 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincmakescalar/mincmakescalar.c,v 6.3.2.2 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -52,13 +55,8 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
-#ifndef public
-#  define public
-#endif
-
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -87,13 +85,13 @@
 } Program_Data;
 
 /* Function prototypes */
-public void do_makescalar(void *caller_data, long num_voxels,
+static void do_makescalar(void *caller_data, long num_voxels,
                           int input_num_buffers, int input_vector_length,
                           double *input_data[],
                           int output_num_buffers, int output_vector_length,
                           double *output_data[], Loop_Info *loop_info);
-public int get_double_list(char *dst, char *key, char *nextarg);
-public long get_vector_length(int mincid);
+static int get_double_list(char *dst, char *key, char *nextarg);
+static long get_vector_length(int mincid);
 
 /* Argument variables */
 int clobber = FALSE;
@@ -206,7 +204,7 @@
       program_data.conversion_type = conversion_type;
       program_data.num_coefficients = linear_coefficients.numvalues;
       program_data.linear_coefficients = 
-         MALLOC(linear_coefficients.numvalues * 
+         malloc(linear_coefficients.numvalues * 
                 sizeof(*program_data.linear_coefficients));
       for (ivalue=0; ivalue < linear_coefficients.numvalues; ivalue++) {
          program_data.linear_coefficients[ivalue] =
@@ -253,10 +251,10 @@
 
    /* Free stuff */
    if (program_data.linear_coefficients != NULL) {
-      FREE(program_data.linear_coefficients);
+      free(program_data.linear_coefficients);
    }
    if (linear_coefficients.values != NULL) {
-      FREE(linear_coefficients.values);
+      free(linear_coefficients.values);
    }
 
    exit(EXIT_SUCCESS);
@@ -283,7 +281,7 @@
 @CREATED    : August 7, 1997 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_makescalar(void *caller_data, long num_voxels,
+static void do_makescalar(void *caller_data, long num_voxels,
                           int input_num_buffers, int input_vector_length,
                           double *input_data[],
                           int output_num_buffers, int output_vector_length,
@@ -387,7 +385,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_double_list(char *dst, char *key, char *nextarg)
+static int get_double_list(char *dst, char *key, char *nextarg)
 {
 #define VECTOR_SEPARATOR ','
 
@@ -436,11 +434,11 @@
          num_alloc += 20;
          if (double_list == NULL) {
             double_list = 
-               MALLOC(num_alloc * sizeof(*double_list));
+               malloc(num_alloc * sizeof(*double_list));
          }
          else {
             double_list = 
-               REALLOC(double_list, num_alloc * sizeof(*double_list));
+               realloc(double_list, num_alloc * sizeof(*double_list));
          }
       }
       double_list[num_elements-1] = dvalue;
@@ -456,7 +454,7 @@
    /* Update the global variables */
    double_array->numvalues = num_elements;
    if (double_array->values != NULL) {
-      FREE(double_array->values);
+      free(double_array->values);
    }
    double_array->values = double_list;
 
@@ -475,7 +473,7 @@
 @CREATED    : November 30, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public long get_vector_length(int mincid)
+static long get_vector_length(int mincid)
 {
    int imgid;
    int ndims;
--- a/progs/mincmakevector/mincmakevector.c
+++ b/progs/mincmakevector/mincmakevector.c
@@ -11,11 +11,8 @@
 @CREATED    : August 11, 1997 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincmakevector.c,v $
- * Revision 6.5  2004-04-30 19:53:30  bert
- * Remove unused variable
- *
- * Revision 6.4  2004/04/27 15:32:15  bert
- * Added -2 option
+ * Revision 6.3.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.3  2001/04/24 13:38:44  neelin
  * Replaced NC_NAT with MI_ORIGINAL_TYPE.
@@ -41,7 +38,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincmakevector/mincmakevector.c,v 6.5 2004-04-30 19:53:30 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincmakevector/mincmakevector.c,v 6.3.2.1 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -53,13 +50,8 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
-#ifndef public
-#  define public
-#endif
-
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -75,19 +67,16 @@
 } Program_Data;
 
 /* Function prototypes */
-public void do_makevector(void *caller_data, long num_voxels,
+static void do_makevector(void *caller_data, long num_voxels,
                           int input_num_buffers, int input_vector_length,
                           double *input_data[],
                           int output_num_buffers, int output_vector_length,
                           double *output_data[], Loop_Info *loop_info);
-public long get_vector_length(int mincid);
+static long get_vector_length(int mincid);
 
 /* Argument variables */
 int clobber = FALSE;
 int verbose = TRUE;
-#ifdef MINC2
-int v2format = FALSE;
-#endif /* MINC2 defined */
 nc_type datatype = MI_ORIGINAL_TYPE;
 int is_signed = FALSE;
 double valid_range[2] = {0.0, 0.0};
@@ -95,10 +84,6 @@
 
 /* Argument table */
 ArgvInfo argTable[] = {
-#ifdef MINC2
-    {"-2", ARGV_CONSTANT, (char *) TRUE, (char *) &v2format,
-       "Produce a MINC 2.0 format output file."},
-#endif /* MINC2 defined */
    {"-clobber", ARGV_CONSTANT, (char *) TRUE, (char *) &clobber,
        "Overwrite existing file."},
    {"-noclobber", ARGV_CONSTANT, (char *) FALSE, (char *) &clobber,
@@ -173,9 +158,6 @@
    loop_options = create_loop_options();
    set_loop_clobber(loop_options, clobber);
    set_loop_verbose(loop_options, verbose);
-#ifdef MINC2
-   set_loop_v2format(loop_options, v2format);
-#endif /* MINC2 defined */
    set_loop_datatype(loop_options, datatype, is_signed, 
                      valid_range[0], valid_range[1]);
    set_loop_output_vector_size(loop_options, num_input_files);
@@ -211,16 +193,20 @@
 @CREATED    : August 11, 1997 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_makevector(void *caller_data, long num_voxels,
+static void do_makevector(void *caller_data, long num_voxels,
                           int input_num_buffers, int input_vector_length,
                           double *input_data[],
                           int output_num_buffers, int output_vector_length,
                           double *output_data[], Loop_Info *loop_info)
      /* ARGSUSED */
 {
+   Program_Data *program_data;
    long ivoxel, ovoxel;
    int current_input_file;
 
+   /* Get pointer to lookup info */
+   program_data = (Program_Data *) caller_data;
+
    /* Check that values correspond */
    if ((input_num_buffers != 1) || (output_num_buffers != 1) ||
        (input_vector_length != 1)) {
@@ -255,7 +241,7 @@
 @CREATED    : November 30, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public long get_vector_length(int mincid)
+static long get_vector_length(int mincid)
 {
    int imgid;
    int ndims;
--- a/progs/mincmath/mincmath.c
+++ b/progs/mincmath/mincmath.c
@@ -10,7 +10,10 @@
 @CREATED    : April 28, 1995 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincmath.c,v $
- * Revision 6.5.2.1  2004-09-28 20:07:56  bert
+ * Revision 6.5.2.2  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.5.2.1  2004/09/28 20:07:56  bert
  * Minor portability fix for Windows
  *
  * Revision 6.5  2001/04/24 13:38:44  neelin
@@ -69,7 +72,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincmath/mincmath.c,v 6.5.2.1 2004-09-28 20:07:56 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincmath/mincmath.c,v 6.5.2.2 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include "config.h"
@@ -82,15 +85,10 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
 /* Constants */
 
-#ifndef public
-#  define public
-#endif
-
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -164,28 +162,27 @@
 } Math_Data;
 
 /* Function prototypes */
-public int main(int argc, char *argv[]);
-public void do_math(void *caller_data, long num_voxels, 
+static void do_math(void *caller_data, long num_voxels, 
                     int input_num_buffers, int input_vector_length,
                     double *input_data[],
                     int output_num_buffers, int output_vector_length,
                     double *output_data[],
                     Loop_Info *loop_info);
-public void accum_math(void *caller_data, long num_voxels, 
+static void accum_math(void *caller_data, long num_voxels, 
                        int input_num_buffers, int input_vector_length,
                        double *input_data[],
                        int output_num_buffers, int output_vector_length,
                        double *output_data[],
                        Loop_Info *loop_info);
-public void start_math(void *caller_data, long num_voxels, 
+static void start_math(void *caller_data, long num_voxels, 
                        int output_num_buffers, int output_vector_length,
                        double *output_data[],
                        Loop_Info *loop_info);
-public void end_math(void *caller_data, long num_voxels, 
+static void end_math(void *caller_data, long num_voxels, 
                      int output_num_buffers, int output_vector_length,
                      double *output_data[],
                      Loop_Info *loop_info);
-public char **read_file_names(char *filelist, int *num_files);
+static char **read_file_names(char *filelist, int *num_files);
 
 /* Argument variables */
 int clobber = FALSE;
@@ -350,7 +347,7 @@
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    char **infiles, **outfiles;
    int nfiles, nout;
@@ -511,7 +508,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_math(void *caller_data, long num_voxels, 
+static void do_math(void *caller_data, long num_voxels, 
                     int input_num_buffers, int input_vector_length,
                     double *input_data[],
                     int output_num_buffers, int output_vector_length,
@@ -700,7 +697,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void accum_math(void *caller_data, long num_voxels, 
+static void accum_math(void *caller_data, long num_voxels, 
                        int input_num_buffers, int input_vector_length,
                        double *input_data[],
                        int output_num_buffers, int output_vector_length,
@@ -799,7 +796,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void start_math(void *caller_data, long num_voxels, 
+static void start_math(void *caller_data, long num_voxels, 
                        int output_num_buffers, int output_vector_length,
                        double *output_data[],
                        Loop_Info *loop_info)
@@ -851,7 +848,7 @@
 @CREATED    : April 25, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void end_math(void *caller_data, long num_voxels, 
+static void end_math(void *caller_data, long num_voxels, 
                      int output_num_buffers, int output_vector_length,
                      double *output_data[],
                      Loop_Info *loop_info)
@@ -901,7 +898,7 @@
 @CREATED    : March 8, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public char **read_file_names(char *filelist, int *num_files)
+static char **read_file_names(char *filelist, int *num_files)
 {
 #define FILE_NAME_ALLOC_SIZE 10
    char **files;
@@ -925,7 +922,7 @@
 
    /* Allocate an initial array and NULL-terminate it */
    array_size = FILE_NAME_ALLOC_SIZE;
-   files = MALLOC(sizeof(*files) * array_size);
+   files = malloc(sizeof(*files) * array_size);
    if (files == NULL) {
       (void) fprintf(stderr, "Error allocating memory\n");
       return NULL;
@@ -947,7 +944,7 @@
       /* Make room for names if needed */
       while (nfiles >= array_size-1) {
          array_size += FILE_NAME_ALLOC_SIZE;
-         files = REALLOC(files, sizeof(*files) * array_size);
+         files = realloc(files, sizeof(*files) * array_size);
          if (files == NULL) {
             (void) fprintf(stderr, "Error allocating memory\n");
             return NULL;
--- a/progs/mincresample/mincresample.c
+++ b/progs/mincresample/mincresample.c
@@ -11,14 +11,8 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincresample.c,v $
- * Revision 6.15  2004-04-30 19:53:40  bert
- * Remove unused variable
- *
- * Revision 6.14  2004/04/30 18:52:49  bert
- * Remove some unused variables
- *
- * Revision 6.13  2004/04/27 15:31:20  bert
- * Added -2 option
+ * Revision 6.12.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.12  2003/09/18 15:01:33  bert
  * Removed unnecessary brackets from initializer
@@ -171,7 +165,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincresample/mincresample.c,v 6.15 2004-04-30 19:53:40 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincresample/mincresample.c,v 6.12.2.1 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -184,7 +178,6 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <volume_io.h>
-#include <minc_def.h>
 #include <convert_origin_to_start.h>
 #include "mincresample.h"
 
@@ -199,7 +192,7 @@
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    VVolume in_vol_struct, out_vol_struct;
    VVolume *in_vol = &in_vol_struct, *out_vol = &out_vol_struct;
@@ -236,7 +229,7 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_arginfo(int argc, char *argv[],
+static void get_arginfo(int argc, char *argv[],
                         Program_Flags *program_flags,
                         VVolume *in_vol, VVolume *out_vol, 
                         General_transform *transformation)
@@ -271,16 +264,10 @@
           {NULL, NULL, NULL}, /* Pointers to coordinate arrays */
           {"", "", ""},       /* units */
           {"", "", ""}        /* spacetype */
-      },
-      FALSE			/* MINC 2.0 format? */
+       }
    };
 
    static ArgvInfo argTable[] = {
-#ifdef MINC2
-       {"-2", ARGV_CONSTANT, (char *) TRUE, 
-	(char *) &args.v2format,
-       "Produce a MINC 2.0 format output file."},
-#endif /* MINC2 defined */
       {"-clobber", ARGV_CONSTANT, (char *) TRUE, 
           (char *) &args.clobber,
           "Overwrite existing file."},
@@ -430,15 +417,14 @@
 
    /* Other variables */
    int idim, index;
-   int out_vindex;              /* Volume indices (0, 1 or 2) */
-   int out_findex;              /* File indices (0 to ndims-1) */
+   int in_vindex, out_vindex;  /* Volume indices (0, 1 or 2) */
+   int in_findex, out_findex;  /* File indices (0 to ndims-1) */
    long size, total_size;
    char *infile, *outfile;
    File_Info *fp;
    char *tm_stamp, *pname;
    Volume_Definition input_volume_def, transformed_volume_def;
    General_transform input_transformation;
-   int cflags;
 
    /* Initialize the transformation to identity */
    create_linear_transform(&input_transformation, NULL);
@@ -491,7 +477,7 @@
    delete_general_transform(&input_transformation);
 
    /* Check input file for default argument information */
-   in_vol->file = MALLOC(sizeof(File_Info));
+   in_vol->file = malloc(sizeof(File_Info));
    get_file_info(infile, FALSE, &input_volume_def, in_vol->file);
    transform_volume_def((transform_input_sampling ? 
                          &args.transform_info : NULL), 
@@ -521,15 +507,15 @@
    }
 
    /* Save the voxel_to_world transformation information */
-   in_vol->voxel_to_world = MALLOC(sizeof(General_transform));
-   in_vol->world_to_voxel = MALLOC(sizeof(General_transform));
+   in_vol->voxel_to_world = malloc(sizeof(General_transform));
+   in_vol->world_to_voxel = malloc(sizeof(General_transform));
    get_voxel_to_world_transf(&input_volume_def, in_vol->voxel_to_world);
    create_inverse_general_transform(in_vol->voxel_to_world,
                                     in_vol->world_to_voxel);
 
    /* Get input volume data information */
    in_vol->slice = NULL;
-   in_vol->volume = MALLOC(sizeof(Volume_Data));
+   in_vol->volume = malloc(sizeof(Volume_Data));
    in_vol->volume->datatype = in_vol->file->datatype;
    in_vol->volume->is_signed = in_vol->file->is_signed;
    in_vol->volume->vrange[0] = in_vol->file->vrange[0];
@@ -575,14 +561,14 @@
       total_size *= size;
       in_vol->volume->size[index] = size;
    }
-   in_vol->volume->data = MALLOC((size_t) total_size * 
+   in_vol->volume->data = malloc((size_t) total_size * 
                                  nctypelen(in_vol->volume->datatype));
 
    /* Get space for slice scale and offset */
    in_vol->volume->scale = 
-      MALLOC(sizeof(double) * in_vol->volume->size[SLC_AXIS]);
+      malloc(sizeof(double) * in_vol->volume->size[SLC_AXIS]);
    in_vol->volume->offset = 
-      MALLOC(sizeof(double) * in_vol->volume->size[SLC_AXIS]);
+      malloc(sizeof(double) * in_vol->volume->size[SLC_AXIS]);
 
    /* Save the program flags */
    *program_flags = args.flags;
@@ -594,7 +580,7 @@
    /* Explicitly force output files to have regular spacing */
    for (idim=0; idim < WORLD_NDIMS; idim++) {
       if (args.volume_def.coords[idim] != NULL) {
-         FREE(args.volume_def.coords[idim]);
+         free(args.volume_def.coords[idim]);
          args.volume_def.coords[idim] = NULL;
       }
    }
@@ -622,7 +608,7 @@
    }
 
    /* Set up the file description for the output file */
-   out_vol->file = MALLOC(sizeof(File_Info));
+   out_vol->file = malloc(sizeof(File_Info));
    out_vol->file->ndims = in_vol->file->ndims;
    out_vol->file->datatype = args.datatype;
    out_vol->file->is_signed = args.is_signed;
@@ -636,14 +622,16 @@
 
    /* Get space for output slice */
    out_vol->volume = NULL;
-   out_vol->slice = MALLOC(sizeof(Slice_Data));
+   out_vol->slice = malloc(sizeof(Slice_Data));
 
    /* Loop through list of axes, getting size of volume and slice */
    total_size = 1;
    for (idim=0; idim < WORLD_NDIMS; idim++) {
       
       /* Get the index for input and output volumes */
+      in_vindex = in_vol->file->axes[idim];       /* 0, 1 or 2 */
       out_vindex = args.volume_def.axes[idim];    /* 0, 1 or 2 */
+      in_findex = in_vol->file->indices[in_vindex];     /* 0 to ndims-1 */
       out_findex = in_vol->file->indices[out_vindex];   /* 0 to ndims-1 */
       size = args.volume_def.nelements[idim];
 
@@ -659,33 +647,22 @@
          total_size *= size;
       }
    }
-   out_vol->slice->data = MALLOC((size_t) total_size * sizeof(double));
+   out_vol->slice->data = malloc((size_t) total_size * sizeof(double));
 
    /* Create the output file */
-   if (args.clobber) {
-       cflags = NC_CLOBBER;
-   }
-   else {
-       cflags = NC_NOCLOBBER;
-   }
-#ifdef MINC2
-   if (args.v2format) {
-       cflags |= MI2_CREATE_V2;
-   }
-#endif /* MINC2 defined */
-   create_output_file(outfile, cflags, &args.volume_def, 
+   create_output_file(outfile, args.clobber, &args.volume_def, 
                       in_vol->file, out_vol->file,
                       tm_stamp, &args.transform_info);
    
    /* Save the voxel_to_world transformation information */
-   out_vol->voxel_to_world = MALLOC(sizeof(General_transform));
-   out_vol->world_to_voxel = MALLOC(sizeof(General_transform));
+   out_vol->voxel_to_world = malloc(sizeof(General_transform));
+   out_vol->world_to_voxel = malloc(sizeof(General_transform));
    get_voxel_to_world_transf(&args.volume_def, out_vol->voxel_to_world);
    create_inverse_general_transform(out_vol->voxel_to_world,
                                     out_vol->world_to_voxel);
 
    /* Free the time stamp */
-   FREE(tm_stamp);
+   free(tm_stamp);
 
 }
 
@@ -704,7 +681,7 @@
 @CREATED    : August 5, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void check_imageminmax(File_Info *fp, Volume_Data *volume)
+static void check_imageminmax(File_Info *fp, Volume_Data *volume)
 {
    int ndims, idim, dim[MAX_VAR_DIMS], imgdim[MAX_VAR_DIMS];
    int ivar, varid;
@@ -767,16 +744,17 @@
 @CREATED    : February 9, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_file_info(char *filename, int initialized_volume_def, 
+static void get_file_info(char *filename, int initialized_volume_def, 
                           Volume_Definition *volume_def,
                           File_Info *file_info)
 {
-   int dim[MAX_VAR_DIMS], dimid;
+   int dim[MAX_VAR_DIMS], dimid, status, length;
    int axis_counter, idim, jdim, cur_axis;
    int varndims, vardim[MAX_VAR_DIMS];
    long varstart, varcount, dimlength;
    char attstr[MI_MAX_ATTSTR_LEN];
    char dimname[MAX_NC_NAME];
+   double vrange[2];
    enum {UNKNOWN, REGULAR, IRREGULAR} coord_spacing;
 
    /* Open the minc file */
@@ -817,7 +795,7 @@
             volume_def->dircos[idim][jdim] = 0.0;
       }
       if (initialized_volume_def && (volume_def->coords[idim] != NULL)) {
-         FREE(volume_def->coords[idim]);
+         free(volume_def->coords[idim]);
       }
       volume_def->coords[idim] = NULL;
       (void) strcpy(volume_def->units[idim], "mm");
@@ -910,14 +888,14 @@
          coord_spacing = REGULAR;
       }
       if (coord_spacing == IRREGULAR) {
-         volume_def->coords[cur_axis] = MALLOC(sizeof(double) * dimlength);
+         volume_def->coords[cur_axis] = malloc(sizeof(double) * dimlength);
          varstart = 0;
          varcount = dimlength;
          if (mivarget(file_info->mincid, dimid, &varstart, &varcount,
                       NC_DOUBLE, MI_SIGNED, volume_def->coords[cur_axis])
                    == MI_ERROR) {
             ncopts = NC_VERBOSE | NC_FATAL;
-            FREE(volume_def->coords[cur_axis]);
+            free(volume_def->coords[cur_axis]);
             volume_def->coords[cur_axis] = NULL;
             continue;
          }
@@ -960,7 +938,7 @@
 @CREATED    : November 7, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_args_volume_def(Volume_Definition *input_volume_def,
+static void get_args_volume_def(Volume_Definition *input_volume_def,
                                 Volume_Definition *args_volume_def)
 {
    int idim, jdim;
@@ -1008,7 +986,7 @@
 @CREATED    : November 7, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void transform_volume_def(Transform_Info *transform_info,
+static void transform_volume_def(Transform_Info *transform_info,
                                  Volume_Definition *input_volume_def,
                                  Volume_Definition *transformed_volume_def)
 {
@@ -1112,7 +1090,7 @@
 @CREATED    : November 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int is_zero_vector(double vector[])
+static int is_zero_vector(double vector[])
 {
    return ((vector[0] == 0.0) &&
            (vector[1] == 0.0) &&
@@ -1131,7 +1109,7 @@
 @CREATED    : November 9, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void normalize_vector(double vector[])
+static void normalize_vector(double vector[])
 {
    int idim;
    double magnitude;
@@ -1153,7 +1131,8 @@
 /* ----------------------------- MNI Header -----------------------------------
 @NAME       : create_output_file
 @INPUT      : filename - name of file to create
-              cflags - flag creation flags
+              clobber - flag indicating whether any existing file should be
+                 overwritten
               volume_def - description of volume
               in_file - description of input file
               out_file - description of output file
@@ -1169,7 +1148,7 @@
 @CREATED    : February 9, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void create_output_file(char *filename, int cflags, 
+static void create_output_file(char *filename, int clobber, 
                                Volume_Definition *volume_def,
                                File_Info *in_file,
                                File_Info *out_file,
@@ -1208,7 +1187,8 @@
    ncopts = NC_VERBOSE | NC_FATAL;
 
    /* Create the file */
-   out_file->mincid = micreate(filename, cflags);
+   out_file->mincid = micreate(filename, 
+                               (clobber ? NC_CLOBBER : NC_NOCLOBBER));
  
    /* Copy all other variable definitions */
    (void) micopy_all_var_defs(in_file->mincid, out_file->mincid, 
@@ -1221,14 +1201,14 @@
        (datatype != NC_CHAR))
       att_length = 0;
    att_length += strlen(tm_stamp) + 1;
-   string = MALLOC(att_length);
+   string = malloc(att_length);
    string[0] = '\0';
    (void) miattgetstr(out_file->mincid, NC_GLOBAL, MIhistory, att_length, 
                       string);
    ncopts=NC_VERBOSE | NC_FATAL;
    (void) strcat(string, tm_stamp);
    (void) miattputstr(out_file->mincid, NC_GLOBAL, MIhistory, string);
-   FREE(string);
+   free(string);
 
    /* Get the dimension ids from the input file */
    (void) ncvarinq(in_file->mincid, in_file->imgid, NULL, NULL, 
@@ -1273,7 +1253,7 @@
          size, then we must rename it */
       if (is_volume_dimension && dim_exists && 
           (out_file->nelements[out_index] != in_file->nelements[in_index])) {
-         string = MALLOC(MAX_NC_NAME);
+         string = malloc(MAX_NC_NAME);
          ncopts = 0;
          idim = 0;
          do {
@@ -1282,7 +1262,7 @@
          } while (ncdimid(out_file->mincid, string) != MI_ERROR);
          ncopts = NC_VERBOSE | NC_FATAL;
          (void) ncdimrename(out_file->mincid, out_dims[out_index], string);
-         FREE(string);
+         free(string);
          out_dims[out_index] = ncdimdef(out_file->mincid, dimname, 
                                         out_file->nelements[out_index]);
       }
@@ -1369,7 +1349,7 @@
       }
 
       /* Look for an unused transformation attribute */
-      string = MALLOC(MI_MAX_ATTSTR_LEN);
+      string = malloc(MI_MAX_ATTSTR_LEN);
       itrans = 0;
       do {
          (void) sprintf(string, "transformation%d-filename", itrans);
@@ -1392,7 +1372,7 @@
          (void) miattputstr(out_file->mincid, varid, string, MI_TRUE);
       }
 
-      FREE(string);
+      free(string);
 
    }         /* If transform specified on command line */
 
@@ -1445,7 +1425,7 @@
 @CREATED    : February 9, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_voxel_to_world_transf(Volume_Definition *volume_def, 
+static void get_voxel_to_world_transf(Volume_Definition *volume_def, 
                                       General_transform *voxel_to_world)
 {
    int idim, jdim, cur_dim, vol_axis;
@@ -1488,7 +1468,7 @@
    /* If we have an irregularly spaced dimension, then create the appropriate
       transform */
    if (irregular) {
-      irreg_transf_data = MALLOC(sizeof(*irreg_transf_data));
+      irreg_transf_data = malloc(sizeof(*irreg_transf_data));
 
       /* Loop through the axes */
       for (idim=0; idim < WORLD_NDIMS; idim++) {
@@ -1508,7 +1488,7 @@
             dimlength = volume_def->nelements[idim];
             irreg_transf_data->nelements[vol_axis] = dimlength;
             irreg_transf_data->coords[vol_axis] =
-               MALLOC(sizeof(double) * dimlength);
+               malloc(sizeof(double) * dimlength);
 
             /* Normalize the coordinates to give first coord 0 and
                last coord n-1 (so that we can concat with the linear
@@ -1529,7 +1509,7 @@
                             sizeof(*irreg_transf_data),
                             irregular_transform_function,
                             irregular_inverse_transform_function);
-      FREE(irreg_transf_data);
+      free(irreg_transf_data);
 
       /* Concatenate the linear transform with the irregular transform */
       copy_general_transform(voxel_to_world, &linear_transf);
@@ -1556,7 +1536,7 @@
 @CREATED    : November 4, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void irregular_transform_function(void *user_data,
+static void irregular_transform_function(void *user_data,
                                          Real x,
                                          Real y,
                                          Real z,
@@ -1618,7 +1598,7 @@
 @CREATED    : November 4, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void irregular_inverse_transform_function(void *user_data,
+static void irregular_inverse_transform_function(void *user_data,
                                                  Real x,
                                                  Real y,
                                                  Real z,
@@ -1712,7 +1692,7 @@
 @MODIFIED   : February 10, 1993 (Peter Neelin)
                  - ripped off from MINC code
 ---------------------------------------------------------------------------- */
-public double get_default_range(char *what, nc_type datatype, int is_signed)
+static double get_default_range(char *what, nc_type datatype, int is_signed)
 {
    double limit;
 
@@ -1753,7 +1733,7 @@
 @CREATED    : February 15, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void finish_up(VVolume *in_vol, VVolume *out_vol)
+static void finish_up(VVolume *in_vol, VVolume *out_vol)
 {
    File_Info *in_file, *out_file;
 
@@ -1792,7 +1772,7 @@
 @CREATED    : February 15, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_transformation(char *dst, char *key, char *nextArg)
+static int get_transformation(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Transform_Info *transform_info;
@@ -1838,14 +1818,14 @@
 
    /* Read in the file for later use */
    if (transform_info->file_contents == NULL) {
-      transform_info->file_contents = MALLOC(TRANSFORM_BUFFER_INCREMENT);
+      transform_info->file_contents = malloc(TRANSFORM_BUFFER_INCREMENT);
       transform_info->buffer_length = TRANSFORM_BUFFER_INCREMENT;
    }
    for (index = 0; (ch=getc(fp)) != EOF; index++) {
       if (index >= transform_info->buffer_length-1) {
          transform_info->buffer_length += TRANSFORM_BUFFER_INCREMENT;
          transform_info->file_contents = 
-            REALLOC(transform_info->file_contents, 
+            realloc(transform_info->file_contents, 
                     transform_info->buffer_length);
       }
       transform_info->file_contents[index] = (char) ch;
@@ -1886,7 +1866,7 @@
 @CREATED    : February 15, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_model_file(char *dst, char *key, char *nextArg)
+static int get_model_file(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Volume_Definition *volume_def;
@@ -1931,7 +1911,7 @@
 @CREATED    : November 14, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int set_standard_sampling(char *dst, char *key, char *nextArg)
+static int set_standard_sampling(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Volume_Definition *volume_def;
@@ -1967,7 +1947,7 @@
 @CREATED    : December 12, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int set_spacetype(char *dst, char *key, char *nextArg)
+static int set_spacetype(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Volume_Definition *volume_def;
@@ -2024,7 +2004,7 @@
 @CREATED    : December 12, 1995 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int set_units(char *dst, char *key, char *nextArg)
+static int set_units(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Volume_Definition *volume_def;
@@ -2067,7 +2047,7 @@
 @CREATED    : February 15, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_axis_order(char *dst, char *key, char *nextArg)
+static int get_axis_order(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Volume_Definition *volume_def;
@@ -2109,7 +2089,7 @@
 @CREATED    : February 15, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_fillvalue(char *dst, char *key, char *nextArg)
+static int get_fillvalue(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    double *dptr;
--- a/progs/mincresample/mincresample.h
+++ b/progs/mincresample/mincresample.h
@@ -7,8 +7,8 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincresample.h,v $
- * Revision 6.5  2004-04-27 15:31:20  bert
- * Added -2 option
+ * Revision 6.4.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.4  2002/11/06 13:32:23  jason
  * Fixes to mincresample: setting the interpolation type is now done
@@ -244,7 +244,6 @@
    enum Interpolant_type interpolant_type;  /* Type of interpolation */
    Transform_Info transform_info;
    Volume_Definition volume_def;
-   int v2format;                /* If non-zero, create a MINC 2.0 output */
 } Arg_Data;
 
 typedef struct {
@@ -335,69 +334,69 @@
 
 /* Function prototypes */
 
-public void get_arginfo(int argc, char *argv[],
+static void get_arginfo(int argc, char *argv[],
                         Program_Flags *program_flags,
                         VVolume *in_vol, VVolume *out_vol, 
                         General_transform *transformation);
-public void check_imageminmax(File_Info *fp, Volume_Data *volume);
-public void get_file_info(char *filename, int initialized_volume_def, 
+static void check_imageminmax(File_Info *fp, Volume_Data *volume);
+static void get_file_info(char *filename, int initialized_volume_def, 
                           Volume_Definition *volume_def,
                           File_Info *file_info);
-public void get_args_volume_def(Volume_Definition *input_volume_def,
+static void get_args_volume_def(Volume_Definition *input_volume_def,
                                 Volume_Definition *args_volume_def);
-public void transform_volume_def(Transform_Info *transform_info,
+static void transform_volume_def(Transform_Info *transform_info,
                                  Volume_Definition *input_volume_def,
                                  Volume_Definition *transformed_volume_def);
-public int is_zero_vector(double vector[]);
-public void normalize_vector(double vector[]);
-public void create_output_file(char *filename, int clobber, 
+static int is_zero_vector(double vector[]);
+static void normalize_vector(double vector[]);
+static void create_output_file(char *filename, int clobber, 
                                Volume_Definition *volume_def,
                                File_Info *in_file,
                                File_Info *out_file,
                                char *tm_stamp, 
                                Transform_Info *transform_info);
-public void get_voxel_to_world_transf(Volume_Definition *volume_def, 
+static void get_voxel_to_world_transf(Volume_Definition *volume_def, 
                                       General_transform *voxel_to_world);
-public void irregular_transform_function(void *user_data,
+static void irregular_transform_function(void *user_data,
                                          Real x,
                                          Real y,
                                          Real z,
                                          Real *x_trans,
                                          Real *y_trans,
                                          Real *z_trans);
-public void irregular_inverse_transform_function(void *user_data,
+static void irregular_inverse_transform_function(void *user_data,
                                                  Real x,
                                                  Real y,
                                                  Real z,
                                                  Real *x_trans,
                                                  Real *y_trans,
                                                  Real *z_trans);
-public double get_default_range(char *what, nc_type datatype, int is_signed);
-public void finish_up(VVolume *in_vol, VVolume *out_vol);
-public int get_transformation(char *dst, char *key, char *nextArg);
-public int get_model_file(char *dst, char *key, char *nextArg);
-public int set_standard_sampling(char *dst, char *key, char *nextArg);
-public int set_spacetype(char *dst, char *key, char *nextArg);
-public int set_units(char *dst, char *key, char *nextArg);
-public int get_axis_order(char *dst, char *key, char *nextArg);
-public int get_fillvalue(char *dst, char *key, char *nextArg);
-public void resample_volumes(Program_Flags *program_flags,
+static double get_default_range(char *what, nc_type datatype, int is_signed);
+static void finish_up(VVolume *in_vol, VVolume *out_vol);
+static int get_transformation(char *dst, char *key, char *nextArg);
+static int get_model_file(char *dst, char *key, char *nextArg);
+static int set_standard_sampling(char *dst, char *key, char *nextArg);
+static int set_spacetype(char *dst, char *key, char *nextArg);
+static int set_units(char *dst, char *key, char *nextArg);
+static int get_axis_order(char *dst, char *key, char *nextArg);
+static int get_fillvalue(char *dst, char *key, char *nextArg);
+extern void resample_volumes(Program_Flags *program_flags,
                              VVolume *in_vol, VVolume *out_vol, 
                              General_transform *transformation);
-public void load_volume(File_Info *file, long start[], long count[], 
+static void load_volume(File_Info *file, long start[], long count[], 
                         Volume_Data *volume);
-public void get_slice(long slice_num, VVolume *in_vol, VVolume *out_vol, 
+static void get_slice(long slice_num, VVolume *in_vol, VVolume *out_vol, 
                       General_transform *transformation, 
                       double *minimum, double *maximum);
-public int trilinear_interpolant(Volume_Data *volume, 
+extern int trilinear_interpolant(Volume_Data *volume, 
                                  Coord_Vector coord, double *result);
-public int tricubic_interpolant(Volume_Data *volume, 
+extern int tricubic_interpolant(Volume_Data *volume, 
                                 Coord_Vector coord, double *result);
-public int do_Ncubic_interpolation(Volume_Data *volume, 
+static int do_Ncubic_interpolation(Volume_Data *volume, 
                                    long index[], int cur_dim, 
                                    double frac[], double *result);
-public int nearest_neighbour_interpolant(Volume_Data *volume, 
+extern int nearest_neighbour_interpolant(Volume_Data *volume, 
                                          Coord_Vector coord, double *result);
-public void renormalize_slices(Program_Flags *program_flags, VVolume *out_vol,
+static void renormalize_slices(Program_Flags *program_flags, VVolume *out_vol,
                                double slice_min[], double slice_max[]);
 
--- a/progs/mincresample/resample_volumes.c
+++ b/progs/mincresample/resample_volumes.c
@@ -6,7 +6,10 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: resample_volumes.c,v $
- * Revision 6.3  2001-08-16 13:32:39  neelin
+ * Revision 6.3.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.3  2001/08/16 13:32:39  neelin
  * Partial fix for valid_range of different type from image (problems
  * arising from double to float conversion/rounding). NOT COMPLETE.
  *
@@ -84,7 +87,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincresample/resample_volumes.c,v 6.3 2001-08-16 13:32:39 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincresample/resample_volumes.c,v 6.3.2.1 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -94,7 +97,6 @@
 #include <math.h>
 #include <minc.h>
 #include <volume_io.h>
-#include <minc_def.h>
 #include "mincresample.h"
 
 /* ----------------------------- MNI Header -----------------------------------
@@ -113,9 +115,9 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void resample_volumes(Program_Flags *program_flags,
-                             VVolume *in_vol, VVolume *out_vol, 
-                             General_transform *transformation)
+void resample_volumes(Program_Flags *program_flags,
+                      VVolume *in_vol, VVolume *out_vol, 
+                      General_transform *transformation)
 {
    long in_start[MAX_VAR_DIMS], in_count[MAX_VAR_DIMS], in_end[MAX_VAR_DIMS];
    long out_start[MAX_VAR_DIMS], out_count[MAX_VAR_DIMS];
@@ -132,9 +134,9 @@
 
    /* Allocate slice min/max arrays if needed */
    if (ofp->do_slice_renormalization) {
-      slice_min = MALLOC(ofp->images_per_file * ofp->slices_per_image *
+      slice_min = malloc(ofp->images_per_file * ofp->slices_per_image *
                          sizeof(double));
-      slice_max = MALLOC(ofp->images_per_file * ofp->slices_per_image *
+      slice_max = malloc(ofp->images_per_file * ofp->slices_per_image *
                          sizeof(double));
    }
 
@@ -264,8 +266,8 @@
    /* Recompute slices and free vectors, if needed */
    if (ofp->do_slice_renormalization) {
       renormalize_slices(program_flags, out_vol, slice_min, slice_max);
-      FREE(slice_min);
-      FREE(slice_max);
+      free(slice_min);
+      free(slice_max);
    }
 
 }
@@ -285,8 +287,8 @@
 @CREATED    : February 10, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void load_volume(File_Info *file, long start[], long count[], 
-                        Volume_Data *volume)
+void load_volume(File_Info *file, long start[], long count[], 
+                 Volume_Data *volume)
 {
    long nread, islice, mm_start[MAX_VAR_DIMS], mm_count[MAX_VAR_DIMS];
    int varid, ivar, idim, ndims;
@@ -420,9 +422,9 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_slice(long slice_num, VVolume *in_vol, VVolume *out_vol, 
-                      General_transform *transformation, 
-                      double *minimum, double *maximum)
+void get_slice(long slice_num, VVolume *in_vol, VVolume *out_vol, 
+               General_transform *transformation, 
+               double *minimum, double *maximum)
 {
    Slice_Data *slice;
    Volume_Data *volume;
@@ -541,8 +543,8 @@
 @CREATED    : February 10, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int trilinear_interpolant(Volume_Data *volume, 
-                                 Coord_Vector coord, double *result)
+int trilinear_interpolant(Volume_Data *volume, 
+                          Coord_Vector coord, double *result)
 {
    long slcind, rowind, colind, slcmax, rowmax, colmax;
    long slcnext, rownext, colnext;
@@ -658,8 +660,8 @@
 @CREATED    : February 12, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int tricubic_interpolant(Volume_Data *volume, 
-                                Coord_Vector coord, double *result)
+int tricubic_interpolant(Volume_Data *volume, 
+                         Coord_Vector coord, double *result)
 {
    long slcind, rowind, colind, slcmax, rowmax, colmax, index[VOL_NDIMS];
    double frac[VOL_NDIMS];
@@ -716,9 +718,9 @@
 @CREATED    : February 12, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int do_Ncubic_interpolation(Volume_Data *volume, 
-                                   long index[], int cur_dim, 
-                                   double frac[], double *result)
+int do_Ncubic_interpolation(Volume_Data *volume, 
+                            long index[], int cur_dim, 
+                            double frac[], double *result)
 {
    long base_index;
    double v0, v1, v2, v3, u;
@@ -817,8 +819,8 @@
 @CREATED    : February 12, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int nearest_neighbour_interpolant(Volume_Data *volume, 
-                                         Coord_Vector coord, double *result)
+int nearest_neighbour_interpolant(Volume_Data *volume, 
+                                  Coord_Vector coord, double *result)
 {
    long slcind, rowind, colind, slcmax, rowmax, colmax;
 
@@ -866,7 +868,7 @@
 @CREATED    : October 29, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void renormalize_slices(Program_Flags *program_flags, VVolume *out_vol,
+static void renormalize_slices(Program_Flags *program_flags, VVolume *out_vol,
                                double slice_min[], double slice_max[])
 {
    File_Info *ofp;
@@ -899,8 +901,8 @@
    }
 
    /* Find the max/min for each image */
-   image_maximum = MALLOC( sizeof(double) * ofp->images_per_file);
-   image_minimum = MALLOC( sizeof(double) * ofp->images_per_file);
+   image_maximum = malloc( sizeof(double) * ofp->images_per_file);
+   image_minimum = malloc( sizeof(double) * ofp->images_per_file);
    for (image=0; image < ofp->images_per_file; image++) {
       image_maximum[image] = -DBL_MAX;
       image_minimum[image] =  DBL_MAX;
@@ -996,8 +998,8 @@
    }
 
    /* Free the image max/min arrays */
-   FREE(image_maximum);
-   FREE(image_minimum);
+   free(image_maximum);
+   free(image_minimum);
 
    return;
 }
--- a/progs/mincreshape/copy_data.c
+++ b/progs/mincreshape/copy_data.c
@@ -6,7 +6,10 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: copy_data.c,v $
- * Revision 6.3  2001-04-17 18:40:24  neelin
+ * Revision 6.3.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.3  2001/04/17 18:40:24  neelin
  * Modifications to work with NetCDF 3.x
  * In particular, changed NC_LONG to NC_INT (and corresponding longs to ints).
  * Changed NC_UNSPECIFIED to NC_NAT.
@@ -63,7 +66,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincreshape/copy_data.c,v 6.3 2001-04-17 18:40:24 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincreshape/copy_data.c,v 6.3.2.1 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -73,10 +76,11 @@
 #include <string.h>
 #include <math.h>
 #include <minc.h>
-#include <minc_def.h>
 #include <nd_loop.h>
 #include "mincreshape.h"
 
+#define ROUND( x ) ((long) ((x) + ( ((x) >= 0) ? 0.5 : (-0.5) ) ))
+
 /* ----------------------------- MNI Header -----------------------------------
 @NAME       : copy_data
 @INPUT      : reshape_info - information for reshaping volume
@@ -90,7 +94,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void copy_data(Reshape_info *reshape_info)
+void copy_data(Reshape_info *reshape_info)
 {
    int idim, odim, out_ndims;
    long block_begin[MAX_VAR_DIMS], block_end[MAX_VAR_DIMS];
@@ -123,7 +127,7 @@
    for (odim=0; odim < out_ndims; odim++) {
       total_size *= reshape_info->chunk_count[odim];
    }
-   chunk_data = MALLOC(total_size);
+   chunk_data = malloc(total_size);
 
    /* Get enough space for image-min and max values for a block */
    get_num_minmax_values(reshape_info, NULL, block_count, 
@@ -131,7 +135,7 @@
    num_values = ((num_min_values > num_max_values) ?
                  num_min_values : num_max_values);
    if (num_values > 0)
-      minmax_buffer = MALLOC(num_values * sizeof(double));
+      minmax_buffer = malloc(num_values * sizeof(double));
    else
       minmax_buffer = NULL;
 
@@ -195,11 +199,11 @@
    }
 
    /* Free the chunk space */
-   FREE(chunk_data);
+   free(chunk_data);
 
    /* Free minmax buffer */
    if (minmax_buffer != NULL) {
-      FREE(minmax_buffer);
+      free(minmax_buffer);
    }
 
    /* Print ending log message */
@@ -231,7 +235,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void get_num_minmax_values(Reshape_info *reshape_info,
+static void get_num_minmax_values(Reshape_info *reshape_info,
                                   long *block_start, long *block_count,
                                   long *num_min_values, long *num_max_values)
 {
@@ -315,7 +319,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void handle_normalization(Reshape_info *reshape_info,
+static void handle_normalization(Reshape_info *reshape_info,
                                  long *block_start,
                                  long *block_count,
                                  double *minmax_buffer,
@@ -413,7 +417,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void get_block_min_and_max(Reshape_info *reshape_info,
+static void get_block_min_and_max(Reshape_info *reshape_info,
                                   long *block_start,
                                   long *block_count,
                                   double *minmax_buffer,
@@ -519,7 +523,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void truncate_input_vectors(Reshape_info *reshape_info,
+static void truncate_input_vectors(Reshape_info *reshape_info,
                                    long *input_start,
                                    long *input_count)
 {
@@ -565,7 +569,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void translate_output_to_input(Reshape_info *reshape_info,
+static void translate_output_to_input(Reshape_info *reshape_info,
                                       long *output_start,
                                       long *output_count,
                                       long *input_start,
@@ -611,7 +615,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void translate_input_to_output(Reshape_info *reshape_info,
+static void translate_input_to_output(Reshape_info *reshape_info,
                                       long *input_start,
                                       long *input_count,
                                       long *output_start,
@@ -654,7 +658,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void copy_the_chunk(Reshape_info *reshape_info,
+static void copy_the_chunk(Reshape_info *reshape_info,
                            long chunk_start[],
                            long chunk_count[],
                            void *chunk_data,
@@ -772,7 +776,7 @@
 @CREATED    : October 25, 1994 (Peter Neelin)
 @MODIFIED   :
 ---------------------------------------------------------------------------- */
-public void convert_value_from_double(double dvalue, 
+static void convert_value_from_double(double dvalue, 
                                       nc_type datatype, int is_signed,
                                       void *ptr)
 {
--- a/progs/mincreshape/mincreshape.c
+++ b/progs/mincreshape/mincreshape.c
@@ -13,8 +13,8 @@
 @CREATED    : March 10, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincreshape.c,v $
- * Revision 6.9  2004-04-27 15:30:02  bert
- * Add -2 flag
+ * Revision 6.8.2.1  2005-03-16 19:02:51  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.8  2001/11/13 14:16:50  neelin
  * Get correct valid range for conversion from int to float types
@@ -92,7 +92,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincreshape/mincreshape.c,v 6.9 2004-04-27 15:30:02 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincreshape/mincreshape.c,v 6.8.2.1 2005-03-16 19:02:51 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -105,12 +105,11 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include "mincreshape.h"
 
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    Reshape_info reshape_info;
 
@@ -123,8 +122,10 @@
    /* Close the output file */
    (void) miattputstr(reshape_info.outmincid, reshape_info.outimgid,
                       MIcomplete, MI_TRUE);
+
    (void) miclose(reshape_info.outmincid);
    (void) miclose(reshape_info.inmincid);
+
    exit(EXIT_SUCCESS);
 }
 
@@ -142,7 +143,7 @@
 @CREATED    : March 11, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_arginfo(int argc, char *argv[],
+static void get_arginfo(int argc, char *argv[],
                         Reshape_info *reshape_info)
 {
 
@@ -171,10 +172,6 @@
    static long hs_count[MAX_VAR_DIMS] = {LONG_MIN};
    static double fillvalue = NOFILL;
    static int max_chunk_size_in_kb = DEFAULT_MAX_CHUNK_SIZE_IN_KB;
-#ifdef MINC2
-   static int minc2_format = 0;
-#endif /* MINC2 defined */
-   int cflags;			/* File creation flags */
 
    /* Argument table */
    static ArgvInfo argTable[] = {
@@ -191,10 +188,6 @@
       {"-max_chunk_size_in_kb", ARGV_INT, (char *) 0, 
           (char *) &max_chunk_size_in_kb,
           "Specify the maximum size of the copy buffer (in kbytes)."},
-#ifdef MINC2
-      {"-2", ARGV_CONSTANT, (char *) TRUE, (char *)&minc2_format,
-       "Produce a MINC 2.0 format output file."},
-#endif /* MINC2 defined */
 
       {NULL, ARGV_HELP, (char *) NULL, (char *) NULL, 
           "Image conversion options (pixel type and range):"},
@@ -437,18 +430,8 @@
                        ncvarid(reshape_info->inmincid, MIimage));
 
    /* Create the output file */
-   if (clobber) {
-       cflags = NC_CLOBBER;
-   }
-   else {
-       cflags = NC_NOCLOBBER;
-   }
-#ifdef MINC2
-   if (minc2_format) {
-       cflags |= MI2_CREATE_V2;
-   }
-#endif /* MINC2 defined */
-   reshape_info->outmincid = micreate(outfile, cflags);
+   reshape_info->outmincid = 
+      micreate(outfile, (clobber ? NC_CLOBBER : NC_NOCLOBBER));
    setup_output_file(reshape_info->outmincid, history, reshape_info);
 
    return;
@@ -468,7 +451,7 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_fillvalue(char *dst, char *key, char *nextArg)
+static int get_fillvalue(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    double *dptr;
@@ -503,7 +486,7 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_dimsize(char *dst, char *key, char *nextArg)
+static int get_dimsize(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Dimsize_list *dimsize_list;
@@ -589,7 +572,7 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_axis_order(char *dst, char *key, char *nextArg)
+static int get_axis_order(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    char **axis_order;
@@ -680,7 +663,7 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_axis_range(char *dst, char *key, char *nextArg)
+static int get_axis_range(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
    Axis_ranges *axis_ranges;
@@ -780,7 +763,7 @@
 @CREATED    : June 10, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public int get_arg_vector(char *dst, char *key, char *nextArg)
+static int get_arg_vector(char *dst, char *key, char *nextArg)
      /* ARGSUSED */
 {
 
@@ -855,7 +838,7 @@
 @CREATED    : March 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void get_default_datatype(int mincid, nc_type *datatype, int *is_signed,
+static void get_default_datatype(int mincid, nc_type *datatype, int *is_signed,
                                  double valid_range[2])
 {
    int imgid;
@@ -953,7 +936,7 @@
 @CREATED    : May 18, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_dim_sizes(int icvid, int mincid, Dimsize_list *dimsize_list)
+static void setup_dim_sizes(int icvid, int mincid, Dimsize_list *dimsize_list)
 {
    int ientry, idim;
    int imgid, dimid;
@@ -1023,7 +1006,7 @@
 @CREATED    : May 26, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_reshaping_info(int icvid, int mincid, 
+static void setup_reshaping_info(int icvid, int mincid, 
                                  int do_norm, double fillvalue, int do_scalar,
                                  char *axis_order[], Axis_ranges *axis_ranges,
                                  long hs_start[], long hs_count[],
@@ -1311,7 +1294,7 @@
 @CREATED    : June 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void setup_output_file(int mincid, char *history, 
+static void setup_output_file(int mincid, char *history, 
                               Reshape_info *reshape_info)
 {
    int output_ndims, output_dim[MAX_VAR_DIMS];
@@ -1439,13 +1422,13 @@
         == MI_ERROR) || (datatype != NC_CHAR))
       att_length = 0;
    att_length += strlen(history) + 1;
-   string = MALLOC(att_length);
+   string = malloc(att_length);
    string[0] = '\0';
    (void) miattgetstr(mincid, NC_GLOBAL, MIhistory, att_length, string);
    ncopts = NCOPTS_DEFAULT;
    (void) strcat(string, history);
    (void) miattputstr(mincid, NC_GLOBAL, MIhistory, string);
-   FREE(string);
+   free(string);
 
    /* Get into data mode */
    (void) ncsetfill(mincid, NC_NOFILL);
@@ -1485,7 +1468,7 @@
 @CREATED    : June 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void create_dim_var(int outmincid, int outdimid,
+static void create_dim_var(int outmincid, int outdimid,
                            int inicvid, int cur_image_dim, int inmincid, 
                            long input_start, long input_count)
 {
@@ -1598,7 +1581,7 @@
 @CREATED    : June 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void copy_dimension_values(int outmincid, int outdimid, int inmincid,
+static void copy_dimension_values(int outmincid, int outdimid, int inmincid,
                                   long input_start, long input_count)
 {
    char dimname[MAX_NC_NAME];
@@ -1637,7 +1620,7 @@
 @CREATED    : June 16, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void copy_dim_var_values(int outmincid, char *dimname, char *varname,
+static void copy_dim_var_values(int outmincid, char *dimname, char *varname,
                                 int inmincid,
                                 long input_start, long input_count)
 {
--- a/progs/mincreshape/mincreshape.h
+++ b/progs/mincreshape/mincreshape.h
@@ -7,7 +7,10 @@
 @CREATED    : March 11, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincreshape.h,v $
- * Revision 6.3  2001-12-06 14:12:45  neelin
+ * Revision 6.3.2.1  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.3  2001/12/06 14:12:45  neelin
  * Trivial change to definition of NCOPTS_DEFAULT.
  *
  * Revision 6.2  1999/10/19 14:45:29  neelin
@@ -112,66 +115,65 @@
 #define  MIN( x, y )  ( ((x) <= (y)) ? (x) : (y) )
 
 /* Function prototypes */
-public int main(int argc, char *argv[]);
-public void get_arginfo(int argc, char *argv[],
+static void get_arginfo(int argc, char *argv[],
                         Reshape_info *reshape_info);
-public int get_fillvalue(char *dst, char *key, char *nextArg);
-public int get_dimsize(char *dst, char *key, char *nextArg);
-public int get_axis_order(char *dst, char *key, char *nextArg);
-public int get_axis_range(char *dst, char *key, char *nextArg);
-public int get_arg_vector(char *dst, char *key, char *nextArg);
-public void get_default_datatype(int mincid, nc_type *datatype, int *is_signed,
+static int get_fillvalue(char *dst, char *key, char *nextArg);
+static int get_dimsize(char *dst, char *key, char *nextArg);
+static int get_axis_order(char *dst, char *key, char *nextArg);
+static int get_axis_range(char *dst, char *key, char *nextArg);
+static int get_arg_vector(char *dst, char *key, char *nextArg);
+static void get_default_datatype(int mincid, nc_type *datatype, int *is_signed,
                                  double valid_range[2]);
-public void setup_dim_sizes(int icvid, int mincid, Dimsize_list *dimsize_list);
-public void setup_reshaping_info(int icvid, int mincid, 
+static void setup_dim_sizes(int icvid, int mincid, Dimsize_list *dimsize_list);
+static void setup_reshaping_info(int icvid, int mincid, 
                                  int do_norm, double fillvalue, int do_scalar,
                                  char *axis_order[], Axis_ranges *axis_ranges,
                                  long hs_start[], long hs_count[],
                                  int max_chunk_size_in_kb,
                                  Reshape_info *reshape_info);
-public void setup_output_file(int mincid, char *history, 
+static void setup_output_file(int mincid, char *history, 
                               Reshape_info *reshape_info);
-public void create_dim_var(int outmincid, int outdimid,
+static void create_dim_var(int outmincid, int outdimid,
                            int inicvid, int cur_image_dim, int inmincid, 
                            long input_start, long input_count);
-public void copy_dimension_values(int outmincid, int outdimid, int inmincid,
+static void copy_dimension_values(int outmincid, int outdimid, int inmincid,
                                   long input_start, long input_count);
-public void copy_dim_var_values(int outmincid, char *dimname, char *varname,
+static void copy_dim_var_values(int outmincid, char *dimname, char *varname,
                                 int inmincid,
                                 long input_start, long input_count);
-public void copy_data(Reshape_info *reshape_info);
-public void get_num_minmax_values(Reshape_info *reshape_info,
+extern void copy_data(Reshape_info *reshape_info);
+static void get_num_minmax_values(Reshape_info *reshape_info,
                                   long *block_start, long *block_count,
                                   long *num_min_values, long *num_max_values);
-public void handle_normalization(Reshape_info *reshape_info,
+static void handle_normalization(Reshape_info *reshape_info,
                                  long *block_start,
                                  long *block_count,
                                  double *minmax_buffer,
                                  double *fillvalue);
-public void get_block_min_and_max(Reshape_info *reshape_info,
+static void get_block_min_and_max(Reshape_info *reshape_info,
                                   long *block_start,
                                   long *block_count,
                                   double *minmax_buffer,
                                   double *minimum,
                                   double *maximum);
-public void truncate_input_vectors(Reshape_info *reshape_info,
+static void truncate_input_vectors(Reshape_info *reshape_info,
                                    long *input_start,
                                    long *input_count);
-public void translate_output_to_input(Reshape_info *reshape_info,
+static void translate_output_to_input(Reshape_info *reshape_info,
                                       long *output_start,
                                       long *output_count,
                                       long *input_start,
                                       long *input_count);
-public void translate_input_to_output(Reshape_info *reshape_info,
+static void translate_input_to_output(Reshape_info *reshape_info,
                                       long *input_start,
                                       long *input_count,
                                       long *output_start,
                                       long *output_count);
-public void copy_the_chunk(Reshape_info *reshape_info,
+static void copy_the_chunk(Reshape_info *reshape_info,
                            long chunk_start[],
                            long chunk_count[],
                            void *chunk_data,
                            double fillvalue);
-public void convert_value_from_double(double dvalue, 
+static void convert_value_from_double(double dvalue, 
                                       nc_type datatype, int is_signed,
                                       void *ptr);
--- a/progs/mincstats/mincstats.c
+++ b/progs/mincstats/mincstats.c
@@ -5,7 +5,10 @@
  * University of Queensland, Australia
  *
  * $Log: mincstats.c,v $
- * Revision 1.14.2.2  2004-10-18 15:02:13  bert
+ * Revision 1.14.2.3  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 1.14.2.2  2004/10/18 15:02:13  bert
  * Ported AJanke's biModalT fix to 1.X branch
  *
  * Revision 1.14.2.1  2004/09/28 20:03:40  bert
@@ -103,7 +106,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
 #ifndef TRUE
@@ -207,6 +209,13 @@
 static double pctT = 0.0;
 static int Entropy = FALSE;
 
+/* Alternative methods of calculating the bimodal threshold */
+#define BMT_OTSU 1              /* Otsu algorithm (default) */
+#define BMT_KITTLER 2           /* Kittler-Illingworth algorithm */
+#define BMT_KAPUR 3             /* Kapur et al. algorithm */
+#define BMT_SIMPLE 4      /* Simple mean-of-means, citation unknown */
+static int BMTMethod = BMT_OTSU;
+
 static Double_Array vol_min = { 0, NULL };
 static Double_Array vol_max = { 0, NULL };
 static Double_Array vol_range = { 0, NULL };
@@ -345,11 +354,368 @@
     "<%> threshold at the supplied % of data."},
    {"-entropy", ARGV_CONSTANT, (char *)TRUE, (char *)&Entropy,
     "entropy of the volume."},
+   {"-otsu", ARGV_CONSTANT, (char *)BMT_OTSU, (char *)&BMTMethod,
+    "Use Otsu '97 algorithm for bimodal threshold (default)"},
+   {"-kittler", ARGV_CONSTANT, (char *)BMT_KITTLER, (char *)&BMTMethod,
+    "Use Kittler&Illingworth '86 algorithm for bimodal threshold"},
+   {"-kapur", ARGV_CONSTANT, (char *)BMT_KAPUR, (char *)&BMTMethod,
+    "Use Kapur et al. '85 algorithm for bimodal threshold"},
+   {"-simple", ARGV_CONSTANT, (char *)BMT_SIMPLE, (char *)&BMTMethod,
+    "Use simple mean-of-means algorithm for bimodal threshold"},
 
    {NULL, ARGV_HELP, NULL, NULL, ""},
    {NULL, ARGV_END, NULL, NULL, NULL}
 };
 
+/* Alternative thresholding algorithm.  This is more computationally
+ * expensive than some of the alternatives, and doesn't seem to do a 
+ * great job.  On the other hand it doesn't seem to fail like the 
+ * current algorithm.
+ */
+
+static double
+simple_threshold(float *histogram, float *hist_centre, int hist_bins)
+{
+    double sum1, sum2;
+    double mean1, mean2;
+    double testthreshold;
+    double newthreshold;
+    int newthreshold_bin;
+    double count1, count2;
+    int c;
+
+    /* Start with a guess of the bimodal threshold.
+     */
+    newthreshold = ceil(hist_centre[hist_bins / 2]);
+    newthreshold_bin = hist_bins / 2;
+
+    for (;;) {
+        sum1 = 0.0;
+        sum2 = 0.0;
+        count1 = 0.0;
+        count2 = 0.0;
+
+        /* Calculate the mean of the bins on each side of the
+         * proposed threshold.
+         */
+        for (c = 0; c < newthreshold_bin; c++) {
+            sum1 += (hist_centre[c] * histogram[c]);
+            count1 += histogram[c];
+        }
+
+        for (c = newthreshold_bin; c < hist_bins; c++) {
+            sum2 += (hist_centre[c] * histogram[c]);
+            count2 += histogram[c];
+        }
+
+        /* Avoid divide by zero 
+         */
+        if (count1 == 0.0 || count2 == 0.0) {
+            continue;
+        }
+
+        mean1 = sum1 / count1;
+        mean2 = sum2 / count2;
+
+        /* The new threshold is the mean of the means.
+         */
+        testthreshold = ceil((mean1 + mean2) / 2);
+
+        /* If the threshold is unchanged, that is our final
+         * guess.
+         */
+        if (newthreshold == testthreshold) {
+            break;              /* Return result */
+        }
+        else {
+            /* Adopt the new guess and try again until we converge.
+             */
+            newthreshold = testthreshold;
+
+            for (c = 0; c < hist_bins; c++) {
+                if (newthreshold == ceil(hist_centre[c])) {
+                    newthreshold_bin = c;
+                    break;
+                }
+            }
+        }
+    }
+    return (newthreshold);
+}
+
+/** This copyright applies to the following functions: 
+ *
+ * otsu_threshold()
+ * kittler_threshold()
+ * kapur_threshold()
+ * 
+ * These functions were extracted from the "xite" package from this
+ * source.  The functions were extensively modified, however, by me
+ * to generalize the functions for our purposes.  Any bugs are
+ * therefore my responsibility (bert 2004-12-14).
+ * 
+ * Copyright 1990, Blab, UiO
+ * Image processing lab, Department of Informatics
+ * University of Oslo
+ * E-mail: blab@ifi.uio.no
+ *________________________________________________________________
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that this copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation and that the name of B-lab,
+ * Department of Informatics or University of Oslo not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.
+ *
+ * B-LAB DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL B-LAB BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Otsu, N. "A threshold selection method from gray-level histograms",
+ * IEEE Transactions on Systems, Man, and Cybernetics, vol T-SMC 9,
+ * No 1, pp 62-66, 1979.
+ */
+static double
+otsu_threshold(float histo[], float hist_centre[], int hist_bins)
+{
+    double threshold;
+    double criterion;
+    double expr_1;              /* Temporary for common subexpression */
+    int i, k;                   /* Generic loop counters */
+    double *p = malloc(hist_bins * sizeof(double));
+    double omega_k;
+    double sigma_b_k;
+    double sigma_T;
+    double mu_T;
+    double mu_k;
+    int sum;
+    int k_low, k_high;
+    double mu_0, mu_1, mu;
+
+    /* If memory allocation fails, abandon ship!!! */
+    if (p == NULL) {
+        return (0.0);
+    }
+
+    sum = 0;
+    for (i = 0; i < hist_bins; i++)
+        sum += histo[i];
+
+    for (i = 0; i < hist_bins; i++)
+        p[i] = histo[i] * 1.0 / sum;
+
+    mu_T = 0.0;
+    for (i = 0; i < hist_bins; i++)
+        mu_T += hist_centre[i] * p[i];
+
+    sigma_T = 0.0;
+    for (i = 0; i < hist_bins; i++)
+        sigma_T += (hist_centre[i] - mu_T) * (hist_centre[i] - mu_T) * p[i];
+
+    /* Ignore outlying zero bins */
+    for (k_low = 0; (p[k_low] == 0) && (k_low < hist_bins - 1); k_low++)
+        ;
+
+    for (k_high = hist_bins - 1; (p[k_high] == 0) && (k_high > 0); k_high--)
+        ;
+
+    criterion = 0.0;
+    threshold = hist_centre[hist_bins / 2];
+    mu_0 = hist_centre[hist_bins / 2 - 1];
+    mu_1 = hist_centre[hist_bins / 2 + 1];
+
+    omega_k = 0.0;
+    mu_k = 0.0;
+    for (k = k_low; k <= k_high ; k++) {
+        omega_k += p[k];
+        mu_k += hist_centre[k] * p[k];
+
+        expr_1 = (mu_T * omega_k - mu_k);
+        sigma_b_k = expr_1 * expr_1 / (omega_k * (1 - omega_k));
+        if (criterion < sigma_b_k / sigma_T) {
+            criterion = sigma_b_k / sigma_T;
+            threshold = hist_centre[k];
+            mu_0 = mu_k / omega_k;
+            mu_1 = (mu_T - mu_k) / (1.0 - omega_k);
+        }
+    }
+    mu = mu_T;
+    free(p);
+    return threshold;
+}
+
+/* Kittler, J. & Illingworth J., "Minimum error thresholding", Pattern
+ * Recognition, vol 19, pp 41-47, 1986.
+ */
+static double 
+kittler_threshold (float hist_bin[], float hist_centre[], int hist_size)
+{
+    double threshold;
+    double criterion;
+    int g;
+    double n;
+    int T_low, T_high;
+    double P_1_T, P_2_T, P_tot;
+    double mu_1_T, mu_2_T;
+    double sum_gh_1, sum_gh_2, sum_gh_tot;
+    double sum_ggh_1, sum_ggh_2, sum_ggh_tot;
+    double sigma_1_T, sigma_2_T;
+    double J_T;
+    double mu, mu_1, mu_2;
+
+    criterion = 1e10;
+    threshold = hist_centre[hist_size / 2 + 1];
+    J_T = criterion;
+
+    T_low = 0;
+    while ((hist_bin[T_low] == 0) && (T_low < hist_size - 1)) {
+        T_low++;
+    }
+
+    T_high = hist_size - 1;
+    while ((hist_bin[T_high] == 0) && (T_high > 0)) {
+        T_high--;
+    }
+
+    n = 0;
+    for (g = T_low; g <= T_high; g++) {
+        n += hist_bin[g];
+    }
+
+    P_1_T = hist_bin[T_low];
+
+    P_tot = 0;
+    for (g = T_low; g <= T_high; g++) {
+        P_tot += hist_bin[g];
+    }
+
+    sum_gh_1 = hist_centre[T_low] * hist_bin[T_low];
+
+    sum_gh_tot = 0.0;
+    for (g = T_low; g <= T_high; g++) {
+        sum_gh_tot += hist_centre[g] * hist_bin[g];
+    }
+
+    mu = sum_gh_tot * 1.0 / n;
+
+    sum_ggh_1 = hist_centre[T_low] * hist_centre[T_low] * hist_bin[T_low];
+
+    sum_ggh_tot = 0.0;
+    for (g = T_low; g <= T_high; g++) {
+        sum_ggh_tot += hist_centre[g] * hist_centre[g] * hist_bin[g];
+    }
+
+    for (g = T_low + 1; g < T_high - 1; g++) {
+        P_1_T += hist_bin[g];
+        P_2_T = P_tot - P_1_T;
+
+        sum_gh_1 += hist_centre[g] * hist_bin[g];
+        sum_gh_2 = sum_gh_tot - sum_gh_1;
+
+        mu_1_T = sum_gh_1 / P_1_T;
+        mu_2_T = sum_gh_2 / P_2_T;
+
+        sum_ggh_1 += hist_centre[g] * hist_centre[g] * hist_bin[g];
+        sum_ggh_2 = sum_ggh_tot - sum_ggh_1;
+
+        sigma_1_T = sum_ggh_1 / P_1_T - mu_1_T * mu_1_T;
+        sigma_2_T = sum_ggh_2 / P_2_T - mu_2_T * mu_2_T;
+
+        /* Equation (15) in the article */
+        if ((sigma_1_T != 0.0) && (P_1_T != 0) &&
+            (sigma_2_T != 0.0) && (P_2_T != 0)) {
+            J_T = 1 + 2 * (P_1_T * log(sigma_1_T) + P_2_T * log(sigma_2_T))
+                - 2 * (P_1_T * log(P_1_T) + P_2_T * log(P_2_T) );
+        }
+
+        if (criterion > J_T) {
+            criterion = J_T;
+            threshold = hist_centre[g];
+            mu_1 = mu_1_T;
+            mu_2 = mu_2_T;
+        }
+    }
+    return threshold;
+}
+
+/*
+  Kapur, Sahoo & Wong "A new method for Gray-level picture
+  thresholding using the entropy of the histogram", Computer Vision,
+  Graphics, and Image Processing, vol 29, pp 273-285, 1985.
+*/
+
+#define BIN_TINY 1e-6
+
+static double
+kapur_threshold(float histo[], float hist_centre[], int hist_bins)
+{
+    double threshold;
+    double Phi, Phi_max;
+    int i, k;
+    double *p = malloc(sizeof(double) * hist_bins);
+    double *P = malloc(sizeof(double) * hist_bins);
+    double *H = malloc(sizeof(double) * hist_bins);
+    double sum;
+
+    sum = 0;
+    for (i = 0; i < hist_bins; i++) {
+        sum += histo[i];
+    }
+
+    for (i = 0; i < hist_bins; i++) {
+        p[i] = histo[i] * 1.0 / sum;
+    }
+   
+    P[0] = p[0];
+    for (i = 1; i < hist_bins; i++) {
+        P[i] = P[i - 1] + p[i];
+    }
+
+    if (histo[0] == 0) {
+        H[0] = 0;
+    }
+    else {
+        H[0] = -p[0] * log(p[0]);
+    }
+
+    for (i = 1; i < hist_bins; i++) {
+        if (histo[i] == 0) {
+            H[i] = H[i - 1];
+        }
+        else {
+            H[i] = H[i - 1] - p[i] * log(p[i]);
+        }
+    }
+
+    Phi_max = -10e10;
+    threshold = hist_centre[hist_bins / 2];
+
+    for (k = 0; k <= hist_bins - 1; k++) {
+
+        if ((P[k] > BIN_TINY) && (1 - P[k] > BIN_TINY)) {
+            Phi = log(P[k] * (1 - P[k]))
+                + H[k] / P[k]
+                + (H[hist_bins - 1] - H[k]) / (1.0 - P[k]);
+
+            if (Phi_max < Phi) {	
+                Phi_max = Phi;
+                threshold = hist_centre[k];
+            }
+        }
+    }
+    free(p);
+    free(P);
+    free(H);
+    return threshold;
+}
+
 int main(int argc, char *argv[])
 {
    char   **infiles;
@@ -538,9 +904,9 @@
    }
 
    /* Initialize the stats structure */
-   stats_info = MALLOC(num_ranges * sizeof(*stats_info));
+   stats_info = malloc(num_ranges * sizeof(*stats_info));
    for(irange = 0; irange < num_ranges; irange++) {
-      stats_info[irange] = MALLOC(num_masks * sizeof(**stats_info));
+      stats_info[irange] = malloc(num_masks * sizeof(**stats_info));
       for(imask = 0; imask < num_masks; imask++) {
          stats = &stats_info[irange][imask];
          init_stats(stats, hist_bins);
@@ -613,9 +979,9 @@
             double   max_var = 0.0;
 
             /* Allocate space for histograms */
-            hist_centre = CALLOC(hist_bins, sizeof(float));
-            pdf = CALLOC(hist_bins, sizeof(float));
-            cdf = CALLOC(hist_bins, sizeof(float));
+            hist_centre = calloc(hist_bins, sizeof(float));
+            pdf = calloc(hist_bins, sizeof(float));
+            cdf = calloc(hist_bins, sizeof(float));
             if(hist_centre == NULL || pdf == NULL || cdf == NULL) {
                (void)fprintf(stderr, "Memory allocation error\n");
                exit(EXIT_FAILURE);
@@ -647,7 +1013,7 @@
                zero_moment += pdf[c];
                first_moment += hist_centre[c] * pdf[c];
 
-               if(c > 0) {
+               if(c > 0 && zero_moment > 0.0 && zero_moment < 1.0) {
                   var = SQR((stats->mean * zero_moment) - first_moment) /
                      (zero_moment * (1 - zero_moment));
 
@@ -685,6 +1051,32 @@
                                * pdf[pctt_bin + 1]) * hist_sep;
             }
 
+            switch (BMTMethod) {
+            case BMT_KITTLER:
+                stats->biModalT = kittler_threshold(stats->histogram,
+                                                    hist_centre,
+                                                    hist_bins);
+                break;
+
+            case BMT_KAPUR:
+                stats->biModalT = kapur_threshold(stats->histogram,
+                                                  hist_centre,
+                                                  hist_bins);
+                break;
+
+            case BMT_SIMPLE:
+                stats->biModalT = simple_threshold(stats->histogram,
+                                                   hist_centre,
+                                                   hist_bins);
+                break;
+
+            default:
+                stats->biModalT = otsu_threshold(stats->histogram,
+                                                 hist_centre,
+                                                 hist_bins);
+                break;
+            }
+
             /* output the histogram */
             if(hist_file != NULL) {
 
@@ -710,9 +1102,9 @@
             }
 
             /* Free the space */
-            FREE(hist_centre);
-            FREE(pdf);
-            FREE(cdf);
+            free(hist_centre);
+            free(pdf);
+            free(cdf);
 
          }                             /* end histogram calculations */
 
@@ -844,9 +1236,9 @@
       for(imask = 0; imask < num_masks; imask++) {
          free_stats(&stats_info[irange][imask]);
       }
-      FREE(stats_info[irange]);
+      free(stats_info[irange]);
    }
-   FREE(stats_info);
+   free(stats_info);
 
    return EXIT_SUCCESS;
 }
@@ -1288,10 +1680,10 @@
       if(num_elements > num_alloc) {
          num_alloc += 20;
          if(double_list == NULL) {
-            double_list = MALLOC(num_alloc * sizeof(*double_list));
+            double_list = malloc(num_alloc * sizeof(*double_list));
          }
          else {
-            double_list = REALLOC(double_list, num_alloc * sizeof(*double_list));
+            double_list = realloc(double_list, num_alloc * sizeof(*double_list));
          }
       }
       double_list[num_elements - 1] = dvalue;
@@ -1309,7 +1701,7 @@
    /* Update the global variables */
    double_array->numvalues = num_elements;
    if(double_array->values != NULL) {
-      FREE(double_array->values);
+      free(double_array->values);
    }
    double_array->values = double_list;
 
@@ -1378,11 +1770,11 @@
    /* Allocate the space */
    if(min->numvalues <= 0) {
       min->numvalues = num_values;
-      min->values = MALLOC(num_values * sizeof(double));
+      min->values = malloc(num_values * sizeof(double));
    }
    if(max->numvalues <= 0) {
       max->numvalues = num_values;
-      max->values = MALLOC(num_values * sizeof(double));
+      max->values = malloc(num_values * sizeof(double));
    }
    if(min->values == NULL || max->values == NULL) {
       (void)fprintf(stderr, "Memory allocation error\n");
@@ -1434,7 +1826,7 @@
    stats->mask_range[0] = -DBL_MAX;
    stats->mask_range[1] = DBL_MAX;
    if(Hist && hist_bins > 0) {
-      stats->histogram = CALLOC(hist_bins, sizeof(float));
+      stats->histogram = calloc(hist_bins, sizeof(float));
       if(stats->histogram == NULL) {
          (void)fprintf(stderr, "Memory allocation error\n");
          exit(EXIT_FAILURE);
@@ -1475,5 +1867,5 @@
 void free_stats(Stats_Info * stats)
 {
    if(stats->histogram != NULL)
-      FREE(stats->histogram);
+      free(stats->histogram);
 }
--- a/progs/minctoraw/minctoraw.c
+++ b/progs/minctoraw/minctoraw.c
@@ -10,7 +10,10 @@
 @CREATED    : February 11, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: minctoraw.c,v $
- * Revision 6.7  2003-10-28 20:32:09  bert
+ * Revision 6.7.2.1  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.7  2003/10/28 20:32:09  bert
  * Get rid of a few compiler warnings
  *
  * Revision 6.6  2001/08/16 16:41:36  neelin
@@ -79,7 +82,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/minctoraw/minctoraw.c,v 6.7 2003-10-28 20:32:09 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/minctoraw/minctoraw.c,v 6.7.2.1 2005-03-16 19:02:52 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -89,7 +92,6 @@
 #include <limits.h>
 #include <float.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
@@ -228,7 +230,7 @@
    }
 
    /* Allocate space */
-   data = MALLOC(size);
+   data = malloc(size);
 
    /* Loop over input slices */
 
@@ -257,7 +259,7 @@
    /* Clean up */
    (void) miclose(mincid);
    (void) miicv_free(icvid);
-   FREE(data);
+   free(data);
 
    exit(EXIT_SUCCESS);
 }
--- a/progs/mincwindow/mincwindow.c
+++ b/progs/mincwindow/mincwindow.c
@@ -10,8 +10,8 @@
 @CREATED    : January 10, 1994 (Peter Neelin)
 @MODIFIED   : 
  * $Log: mincwindow.c,v $
- * Revision 6.2  2004-04-27 15:28:39  bert
- * Added -2 option
+ * Revision 6.1.2.1  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
  *
  * Revision 6.1  1999/10/19 14:45:30  neelin
  * Fixed Log subsitutions for CVS
@@ -64,7 +64,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincwindow/mincwindow.c,v 6.2 2004-04-27 15:28:39 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincwindow/mincwindow.c,v 6.1.2.1 2005-03-16 19:02:52 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -74,13 +74,8 @@
 #include <minc.h>
 #include <ParseArgv.h>
 #include <time_stamp.h>
-#include <minc_def.h>
 #include <voxel_loop.h>
 
-#ifndef public
-#  define public
-#endif
-
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
@@ -95,7 +90,7 @@
 } Window_Data;
 
 /* Function prototypes */
-public void do_window(void *caller_data, long num_voxels, 
+static void do_window(void *caller_data, long num_voxels, 
                       int input_num_buffers, int input_vector_length,
                       double *input_data[],
                       int output_num_buffers, int output_vector_length,
@@ -105,16 +100,9 @@
 /* Argument variables */
 int clobber = FALSE;
 int verbose = TRUE;
-#ifdef MINC2
-int v2format = FALSE;
-#endif /* MINC2 defined */
 
 /* Argument table */
 ArgvInfo argTable[] = {
-#ifdef MINC2
-    {"-2", ARGV_CONSTANT, (char *) TRUE, (char *) &v2format,
-       "Produce a MINC 2.0 format output file."},
-#endif /* MINC2 defined */
    {"-clobber", ARGV_CONSTANT, (char *) TRUE, (char *) &clobber,
        "Overwrite existing file."},
    {"-noclobber", ARGV_CONSTANT, (char *) FALSE, (char *) &clobber,
@@ -127,7 +115,7 @@
 };
 /* Main program */
 
-public int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
    char *infile, *outfile;
    char *arg_string;
@@ -177,9 +165,6 @@
    loop_options = create_loop_options();
    set_loop_verbose(loop_options, verbose);
    set_loop_clobber(loop_options, clobber);
-#ifdef MINC2
-   set_loop_v2format(loop_options, v2format);
-#endif /* MINC2 defined */
    voxel_loop(1, &infile, 1, &outfile, arg_string, loop_options,
               do_window, (void *) &window_data);
 
@@ -201,7 +186,7 @@
 @CREATED    : January 11, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void do_window(void *caller_data, long num_voxels, 
+static void do_window(void *caller_data, long num_voxels, 
                       int input_num_buffers, int input_vector_length,
                       double *input_data[],
                       int output_num_buffers, int output_vector_length,
--- a/progs/rawtominc/rawtominc.c
+++ b/progs/rawtominc/rawtominc.c
@@ -11,7 +11,10 @@
 @CREATED    : September 25, 1992 (Peter Neelin)
 @MODIFIED   : 
  * $Log: rawtominc.c,v $
- * Revision 6.13.2.1  2004-09-28 20:07:30  bert
+ * Revision 6.13.2.2  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.13.2.1  2004/09/28 20:07:30  bert
  * Minor portability fixes for Windows
  *
  * Revision 6.13  2004/02/02 18:24:58  bert
@@ -143,7 +146,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/rawtominc/rawtominc.c,v 6.13.2.1 2004-09-28 20:07:30 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/rawtominc/rawtominc.c,v 6.13.2.2 2005-03-16 19:02:52 bert Exp $";
 #endif
 
 #include "config.h"
@@ -162,7 +165,6 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <convert_origin_to_start.h>
-#include <minc_def.h>
 
 /* Some constants */
 
@@ -197,11 +199,11 @@
 #define STR_EQ(s1,s2) (strcmp(s1,s2)==0)
 
 /* Function declarations */
-void parse_args(int argc, char *argv[]);
-void usage_error(char *pname);
-int get_attribute(char *dst, char *key, char *nextarg);
-int get_times(char *dst, char *key, char *nextarg);
-int get_axis_order(char *dst, char *key, char *nextArg);
+static void parse_args(int argc, char *argv[]);
+static void usage_error(char *pname);
+static int get_attribute(char *dst, char *key, char *nextarg);
+static int get_times(char *dst, char *key, char *nextarg);
+static int get_axis_order(char *dst, char *key, char *nextArg);
 
 /* Array containing information about signs. It is subscripted by
    [signtype][type]. Note that the first row should never be used, since
@@ -703,7 +705,7 @@
       image_pix *= end[ndims-i];
    pix_size=nctypelen(datatype);
    image_size=image_pix*pix_size;
-   image=MALLOC(image_size);
+   image=malloc(image_size);
 
    /* Loop through the images */
    fastdim=ndims-image_dims-1;
@@ -882,7 +884,7 @@
    }
 
    /* Free the memory */
-   FREE(image);
+   free(image);
 
    /* Write the valid max and min */
    if (do_vrange) {
@@ -926,7 +928,7 @@
 @CREATED    : December 3, 1992
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-void parse_args(int argc, char *argv[])
+static void parse_args(int argc, char *argv[])
 {
    char *ptr;
    int time_size;
@@ -1035,7 +1037,7 @@
 @CREATED    : September 25, 1992 (Peter Neelin)
 @MODIFIED   : December 2, 1992 (P.N.)
 ---------------------------------------------------------------------------- */
-void usage_error(char *progname)
+static void usage_error(char *progname)
 {
    (void) fprintf(stderr, "\nUsage: %s [<options>] <output.mnc> ", 
                   progname);
@@ -1061,7 +1063,7 @@
 @CREATED    : May 3, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-int get_attribute(char *dst, char *key, char *nextarg)
+static int get_attribute(char *dst, char *key, char *nextarg)
      /* ARGSUSED */
 {
    int need_string, need_double;
@@ -1112,11 +1114,11 @@
       attribute_list_alloc += 10;
       if (attribute_list == NULL) {
          attribute_list = 
-            MALLOC(attribute_list_alloc * sizeof(*attribute_list));
+            malloc(attribute_list_alloc * sizeof(*attribute_list));
       }
       else {
          attribute_list = 
-            REALLOC(attribute_list, 
+            realloc(attribute_list, 
                     attribute_list_alloc * sizeof(*attribute_list));
       }
    }
@@ -1157,7 +1159,7 @@
 @CREATED    : May 3, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-int get_times(char *dst, char *key, char *nextarg)
+static int get_times(char *dst, char *key, char *nextarg)
      /* ARGSUSED */
 {
    int *num_elements_ptr;
@@ -1217,11 +1219,11 @@
          num_alloc += 20;
          if (time_list == NULL) {
             time_list = 
-               MALLOC(num_alloc * sizeof(*time_list));
+               malloc(num_alloc * sizeof(*time_list));
          }
          else {
             time_list = 
-               REALLOC(time_list, num_alloc * sizeof(*time_list));
+               realloc(time_list, num_alloc * sizeof(*time_list));
          }
       }
       time_list[num_elements-1] = dvalue;
@@ -1237,7 +1239,7 @@
    /* Update the global variables */
    *num_elements_ptr = num_elements;
    if (*time_list_ptr != NULL) {
-      FREE(*time_list_ptr);
+      free(*time_list_ptr);
    }
    *time_list_ptr = time_list;
 
@@ -1273,7 +1275,7 @@
 #define YXZ_ORIENTATION 5
 #define ZXY_ORIENTATION 6
 #define STD_ORIENTATION_COUNT 7
-public int get_axis_order(char *dst, char *key, char *nextArg)
+static int get_axis_order(char *dst, char *key, char *nextArg)
 {
     char **dim_name_array;
     char *argp;
--- a/progs/xfm/transformtags.c
+++ b/progs/xfm/transformtags.c
@@ -10,7 +10,10 @@
 @CREATED    : September 13, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: transformtags.c,v $
- * Revision 6.1  1999-10-19 14:45:31  neelin
+ * Revision 6.1.2.1  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.1  1999/10/19 14:45:31  neelin
  * Fixed Log subsitutions for CVS
  *
  * Revision 6.0  1997/09/12 13:23:28  neelin
@@ -47,7 +50,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/xfm/transformtags.c,v 6.1 1999-10-19 14:45:31 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/xfm/transformtags.c,v 6.1.2.1 2005-03-16 19:02:52 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -55,7 +58,6 @@
 #include <string.h>
 #include <volume_io.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
--- a/progs/xfm/xfmconcat.c
+++ b/progs/xfm/xfmconcat.c
@@ -10,7 +10,10 @@
 @CREATED    : August 13, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: xfmconcat.c,v $
- * Revision 6.2  2004-02-02 18:24:11  bert
+ * Revision 6.2.2.1  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.2  2004/02/02 18:24:11  bert
  * Call ParseArgv() so that version information will be available
  *
  * Revision 6.1  1999/10/19 14:45:32  neelin
@@ -60,7 +63,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/xfm/xfmconcat.c,v 6.2 2004-02-02 18:24:11 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/xfm/xfmconcat.c,v 6.2.2.1 2005-03-16 19:02:52 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -68,17 +71,12 @@
 #include <string.h>
 #include <volume_io.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
 #endif
-#ifndef public
-#  define public
-#  define private static
-#endif
 
 /* Argument table */
 ArgvInfo argTable[] = {
--- a/progs/xfm/xfminvert.c
+++ b/progs/xfm/xfminvert.c
@@ -10,7 +10,10 @@
 @CREATED    : August 13, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: xfminvert.c,v $
- * Revision 6.2  2004-02-02 18:24:11  bert
+ * Revision 6.2.2.1  2005-03-16 19:02:52  bert
+ * Port changes from 2.0 branch
+ *
+ * Revision 6.2  2004/02/02 18:24:11  bert
  * Call ParseArgv() so that version information will be available
  *
  * Revision 6.1  1999/10/19 14:45:32  neelin
@@ -60,7 +63,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/xfm/xfminvert.c,v 6.2 2004-02-02 18:24:11 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/xfm/xfminvert.c,v 6.2.2.1 2005-03-16 19:02:52 bert Exp $";
 #endif
 
 #include <stdlib.h>
@@ -68,17 +71,12 @@
 #include <string.h>
 #include <volume_io.h>
 #include <ParseArgv.h>
-#include <minc_def.h>
 
 /* Constants */
 #ifndef TRUE
 #  define TRUE 1
 #  define FALSE 0
 #endif
-#ifndef public
-#  define public
-#  define private static
-#endif
 
 /* Argument table */
 ArgvInfo argTable[] = {